Issues (1369)

admin/admin_analyze_matter.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * Created by Gorlum 18.02.2017 19:37
4
 */
5
6
define('INSIDE', true);
7
define('INSTALL', false);
8
define('IN_ADMIN', true);
9
10
require('../common.' . substr(strrchr(__FILE__, '.'), 1));
11
12
global $lang, $user;
13
14
SnTemplate::messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR);
15
16
$constants = get_defined_constants(true);
17
$rpgConstants = array();
18
foreach($constants['user'] as $constantName => $constantValue) {
19
  if(substr($constantName, 0, 4) == 'RPG_') {
20
    $rpgConstants[$constantValue] = $constantName;
21
  }
22
}
23
24
$spent = array();
25
26
$result = SN::$db->doquery(
27
  "SELECT
28
    CONCAT(log_dark_matter_reason, '_', IF(sign(sum(log_dark_matter_amount)) > 0, 1, -1)) as `BALANCE`,
29
    log_dark_matter_reason as `REASON`,
30
    sum(log_dark_matter_amount) as `DM_AMOUNT`,
31
    count(log_dark_matter_amount) as `DM_COUNT`,
32
    sign(sum(log_dark_matter_amount)) as `SIGN`
33
  FROM `{{log_dark_matter}}`
34
  GROUP BY log_dark_matter_reason, IF(sign((log_dark_matter_amount)) > 0, 1, -1) ORDER BY sum(log_dark_matter_amount) DESC;"
35
);
36
37
while($row = SN::$db->db_fetch($result)) {
0 ignored issues
show
It seems like $result can also be of type true; however, parameter $query_result of DBAL\db_mysql::db_fetch() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
while($row = SN::$db->db_fetch(/** @scrutinizer ignore-type */ $result)) {
Loading history...
38
  $row['CONSTANT'] = $rpgConstants[$row['REASON']];
39
40
  $row['DM_AMOUNT_TEXT'] = HelperString::numberFloorAndFormat($row['DM_AMOUNT']);
41
42
//  $row['TOTAL_AMOUNT'] = $row['DM_AMOUNT'];
43
//  $row['TOTAL_COUNT'] = $row['DM_COUNT'];
44
//  $row['TOTAL_AMOUNT_TEXT'] = pretty_number($row['TOTAL_AMOUNT']);
45
46
  $spent[$row['BALANCE']] = $row;
47
}
48
49
$result = SN::$db->doquery(
50
  "SELECT
51
    CONCAT(reason, '_', IF(sign(sum(amount)) > 0, 1, -1)) as `BALANCE`,
52
    reason as `REASON`,
53
    sum(amount) as `MM_AMOUNT`,
54
    count(amount) as `MM_COUNT`,
55
    sign(sum(amount)) as `SIGN`
56
  FROM `{{log_metamatter}}`
57
  GROUP BY reason, if(sign((amount)) > 0, 1, -1) ORDER BY sum(amount) DESC;"
58
);
59
60
while($row = SN::$db->db_fetch($result)) {
61
  if(empty($spent[$row['BALANCE']])) {
62
    $spent[$row['BALANCE']] = array();
63
  }
64
65
  $row['CONSTANT'] = $rpgConstants[$row['REASON']];
66
  $row['MM_AMOUNT_TEXT'] = HelperString::numberFloorAndFormat($row['MM_AMOUNT']);
67
68
  $spent[$row['BALANCE']] = array_merge_recursive_numeric($spent[$row['BALANCE']], $row);
69
}
70
71
foreach($spent as &$row) {
72
  @$row['TOTAL_COUNT'] = $row['MM_COUNT'] + $row['DM_COUNT'];
73
  @$row['TOTAL_AMOUNT'] = $row['MM_AMOUNT'] + $row['DM_AMOUNT'];
74
  @$row['TOTAL_AMOUNT_TEXT'] = HelperString::numberFloorAndFormat($row['TOTAL_AMOUNT']);
75
  @$row['TOTAL_COUNT_TEXT'] = HelperString::numberFloorAndFormat($row['TOTAL_COUNT']);
76
}
77
78
usort($spent, function ($a, $b) {
79
  return $a['TOTAL_AMOUNT'] < $b['TOTAL_AMOUNT'] ? -1 :
80
    ($a['TOTAL_AMOUNT'] > $b['TOTAL_AMOUNT'] ? 1 : 0);
81
});
82
83
84
$template = SnTemplate::gettemplate("admin/admin_analyze_matter", true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

84
$template = SnTemplate::gettemplate("admin/admin_analyze_matter", /** @scrutinizer ignore-type */ true);
Loading history...
85
foreach ($spent as $row) {
86
  $template->assign_block_vars('spent', $row);
87
}
88
$fromDate = SN::$db->doQueryAndFetch("SELECT min(log_dark_matter_timestamp) FROM `{{log_dark_matter}}`;");
89
$template->assign_var("MIN_DATE", reset($fromDate));
90
91
92
SnTemplate::display($template, '{Анализ расхода и прихода материи}');
93