1 | <?php |
||||
2 | /** |
||||
3 | * Created by Gorlum 05.03.2018 12:57 |
||||
4 | */ |
||||
5 | |||||
6 | namespace Pages\Deprecated; |
||||
7 | |||||
8 | use SN; |
||||
9 | use DBAL\DbSqlPaging; |
||||
10 | use General\Helpers\PagingRenderer; |
||||
11 | use SnTemplate; |
||||
12 | |||||
13 | class PageAdminPayment extends PageDeprecated { |
||||
14 | |||||
15 | public static function viewStatic() { |
||||
16 | define('INSIDE', true); |
||||
17 | define('INSTALL', false); |
||||
18 | define('IN_ADMIN', true); |
||||
19 | |||||
20 | global $lang; |
||||
21 | |||||
22 | SnTemplate::messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR); |
||||
23 | |||||
24 | $template = SnTemplate::gettemplate('admin/admin_payment', true); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
25 | |||||
26 | |||||
27 | $flt_payer = sys_get_param_int('flt_payer', -1); |
||||
28 | $flt_module = sys_get_param_str('flt_module'); |
||||
29 | $flt_status = sys_get_param_int('flt_status', PAYMENT_STATUS_ALL); |
||||
30 | $flt_test = sys_get_param_int('flt_test', PAYMENT_TEST_REAL); |
||||
31 | $flt_currency = sys_get_param_int('flt_currency', -1); |
||||
32 | $flt_stat = sys_get_param_int('flt_stat', PAYMENT_FILTER_STAT_NORMAL); |
||||
33 | $flt_stat_type = sys_get_param_int('flt_stat_type', -1); |
||||
0 ignored issues
–
show
|
|||||
34 | |||||
35 | |||||
36 | // TODO - remove debug |
||||
37 | // $flt_stat = PAYMENT_FILTER_STAT_YEAR; |
||||
38 | // $flt_stat = PAYMENT_FILTER_STAT_MONTH; |
||||
39 | |||||
40 | $stats = [ |
||||
41 | PAYMENT_FILTER_STAT_NORMAL => [ |
||||
42 | 'sql_fields' => [], |
||||
43 | ], |
||||
44 | PAYMENT_FILTER_STAT_MONTH => [ |
||||
45 | 'sql_fields' => [ |
||||
46 | 'payment_status', |
||||
47 | // 'payment_user_id', |
||||
48 | // 'payment_user_name', |
||||
49 | 'sum(if(payment_currency = "UAH", payment_amount / 11, payment_amount)) as payment_amount', |
||||
50 | 'if(payment_currency = "UAH", "USD", payment_currency) as payment_currency', |
||||
51 | 'sum(payment_dark_matter_paid) as payment_dark_matter_paid', |
||||
52 | 'sum(payment_dark_matter_gained) as payment_dark_matter_gained', |
||||
53 | 'date_format(payment_date, "%Y-%m") as payment_date', |
||||
54 | 'payment_comment', |
||||
55 | 'payment_module_name', |
||||
56 | 'payment_external_id', |
||||
57 | 'payment_external_date', |
||||
58 | 'payment_external_lots', |
||||
59 | 'sum(payment_external_amount) as payment_external_amount', |
||||
60 | 'payment_external_currency', |
||||
61 | 'payment_test', |
||||
62 | ], |
||||
63 | 'sql_group' => [ |
||||
64 | 'date_format(payment_date, "%Y-%m")', |
||||
65 | 'if(payment_currency = "UAH", "USD", payment_currency)', |
||||
66 | 'payment_external_currency', |
||||
67 | 'payment_test', |
||||
68 | 'payment_status', |
||||
69 | ], |
||||
70 | 'sql_order' => 'date_format(payment_date, "%Y-%m") desc', |
||||
71 | ], |
||||
72 | PAYMENT_FILTER_STAT_YEAR => [ |
||||
73 | 'sql_fields' => [ |
||||
74 | 'payment_status', |
||||
75 | // 'payment_user_id', |
||||
76 | // 'payment_user_name', |
||||
77 | 'sum(if(payment_currency = "UAH", payment_amount / 11, payment_amount)) as payment_amount', |
||||
78 | 'if(payment_currency = "UAH", "USD", payment_currency) as payment_currency', |
||||
79 | 'payment_dark_matter_paid', |
||||
80 | 'payment_dark_matter_gained', |
||||
81 | 'date_format(payment_date, "%Y") as payment_date', |
||||
82 | 'payment_comment', |
||||
83 | 'payment_module_name', |
||||
84 | 'payment_external_id', |
||||
85 | 'payment_external_date', |
||||
86 | 'payment_external_lots', |
||||
87 | 'sum(payment_external_amount) as payment_external_amount', |
||||
88 | 'payment_external_currency', |
||||
89 | 'payment_test', |
||||
90 | ], |
||||
91 | 'sql_group' => [ |
||||
92 | 'date_format(payment_date, "%Y")', |
||||
93 | 'if(payment_currency = "UAH", "USD", payment_currency)', |
||||
94 | 'payment_external_currency', |
||||
95 | 'payment_test', |
||||
96 | 'payment_status', |
||||
97 | ], |
||||
98 | 'sql_order' => 'date_format(payment_date, "%Y") desc', |
||||
99 | ], |
||||
100 | PAYMENT_FILTER_STAT_ALL => [ |
||||
101 | 'sql_fields' => [ |
||||
102 | 'payment_status', |
||||
103 | // 'payment_user_id', |
||||
104 | // 'payment_user_name', |
||||
105 | 'sum(if(payment_currency = "UAH", payment_amount / 11, payment_amount)) as payment_amount', |
||||
106 | 'if(payment_currency = "UAH", "USD", payment_currency) as payment_currency', |
||||
107 | 'payment_dark_matter_paid', |
||||
108 | 'payment_dark_matter_gained', |
||||
109 | // 'date_format(payment_date, "%Y") as payment_date', |
||||
110 | 'payment_comment', |
||||
111 | 'payment_module_name', |
||||
112 | 'payment_external_id', |
||||
113 | 'payment_external_date', |
||||
114 | 'payment_external_lots', |
||||
115 | 'sum(payment_external_amount) as payment_external_amount', |
||||
116 | 'payment_external_currency', |
||||
117 | 'payment_test', |
||||
118 | ], |
||||
119 | 'sql_group' => [ |
||||
120 | // 'date_format(payment_date, "%Y")', |
||||
121 | 'if(payment_currency = "UAH", "USD", payment_currency)', |
||||
122 | 'payment_external_currency', |
||||
123 | 'payment_test', |
||||
124 | 'payment_status', |
||||
125 | ], |
||||
126 | 'sql_order' => 'date_format(payment_date, "%Y") desc', |
||||
127 | ], |
||||
128 | ]; |
||||
129 | |||||
130 | |||||
131 | if (!isset($stats[$flt_stat])) { |
||||
132 | $flt_stat = PAYMENT_FILTER_STAT_NORMAL; |
||||
133 | } |
||||
134 | |||||
135 | $theStat = $stats[$flt_stat]; |
||||
136 | |||||
137 | if (!empty($theStat['sql_fields']) && $flt_payer != -1) { |
||||
138 | $theStat['sql_fields'] = array_merge($theStat['sql_fields'], [ |
||||
139 | 'payment_user_id', |
||||
140 | 'payment_user_name', |
||||
141 | ]); |
||||
142 | } |
||||
143 | |||||
144 | $query = new \DBAL\DbSqlPaging( |
||||
145 | "SELECT " . |
||||
146 | (!empty($theStat['sql_fields']) ? implode(',', $theStat['sql_fields']) : '*') . |
||||
147 | " FROM `{{payment}}` WHERE 1 " . |
||||
148 | ($flt_payer > 0 ? "AND payment_user_id = {$flt_payer} " : '') . |
||||
149 | ($flt_status >= 0 ? "AND payment_status = {$flt_status} " : '') . |
||||
150 | ($flt_test >= 0 ? "AND payment_test = {$flt_test} " : '') . |
||||
151 | ($flt_module ? "AND payment_module_name = '{$flt_module}' " : '') . |
||||
152 | |||||
153 | (!empty($theStat['sql_group']) ? ' GROUP BY ' . implode(',', $theStat['sql_group']) : '') . |
||||
154 | ' ORDER BY ' . (!empty($theStat['sql_order']) ? $theStat['sql_order'] : 'payment_id desc') |
||||
155 | , |
||||
156 | PAGING_PAGE_SIZE_DEFAULT_PAYMENTS, |
||||
157 | sys_get_param_int(PagingRenderer::KEYWORD) |
||||
158 | ); |
||||
159 | |||||
160 | $pager = new PagingRenderer($query, 'index.php?' . $_SERVER['QUERY_STRING']); |
||||
161 | $pager->setDelta(10); |
||||
162 | |||||
163 | foreach ($query as $row) { |
||||
164 | $row2 = array(); |
||||
165 | foreach ($row as $key => $value) { |
||||
166 | $row2[strtoupper($key)] = $value; |
||||
167 | } |
||||
168 | $template->assign_block_vars('payment', $row2); |
||||
169 | } |
||||
170 | |||||
171 | SnTemplate::tpl_assign_select($template, 'payer', self::getPayers()); |
||||
172 | SnTemplate::tpl_assign_select($template, 'module', self::getUsedModules()); |
||||
173 | SnTemplate::tpl_assign_select($template, 'status', SN::$lang['adm_pay_filter_status']); |
||||
174 | SnTemplate::tpl_assign_select($template, 'test', SN::$lang['adm_pay_filter_test']); |
||||
175 | SnTemplate::tpl_assign_select($template, 'flt_stat', SN::$lang['adm_pay_filter_stat']); |
||||
176 | SnTemplate::tpl_assign_select($template, 'flt_currency', self::getCurrencies()); |
||||
177 | |||||
178 | $template->assign_vars(array( |
||||
179 | 'FLT_PAYER' => $flt_payer, |
||||
180 | 'FLT_STATUS' => $flt_status, |
||||
181 | 'FLT_TEST' => $flt_test, |
||||
182 | 'FLT_MODULE' => $flt_module, |
||||
183 | 'FLT_CURRENCY' => $flt_currency, |
||||
184 | 'FLT_STAT' => $flt_stat, |
||||
185 | |||||
186 | 'PAGER_PAYMENTS' => $pager->render(), |
||||
187 | )); |
||||
188 | |||||
189 | SnTemplate::display($template, $lang['adm_pay_stats']); |
||||
190 | } |
||||
191 | |||||
192 | /** |
||||
193 | * @return array |
||||
194 | */ |
||||
195 | protected static function getUsedModules() { |
||||
196 | $module_list = array( |
||||
197 | '' => SN::$lang['adm_pay_filter_all'], |
||||
198 | ); |
||||
199 | $query = doquery("SELECT distinct payment_module_name FROM `{{payment}}` ORDER BY payment_module_name"); |
||||
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
200 | while ($row = db_fetch($query)) { |
||||
0 ignored issues
–
show
The function
db_fetch() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
201 | $module_list[$row['payment_module_name']] = $row['payment_module_name']; |
||||
202 | } |
||||
203 | |||||
204 | return $module_list; |
||||
205 | } |
||||
206 | |||||
207 | /** |
||||
208 | * @return array |
||||
209 | */ |
||||
210 | protected static function getPayers() { |
||||
211 | $payer_list = array( |
||||
212 | -1 => SN::$lang['adm_pay_filter_all'], |
||||
213 | ); |
||||
214 | $query = doquery("SELECT payment_user_id, payment_user_name FROM `{{payment}}` GROUP BY payment_user_id ORDER BY payment_user_name"); |
||||
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
215 | while ($row = db_fetch($query)) { |
||||
0 ignored issues
–
show
The function
db_fetch() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
216 | $payer_list[$row['payment_user_id']] = '[' . $row['payment_user_id'] . '] ' . $row['payment_user_name']; |
||||
217 | } |
||||
218 | |||||
219 | return $payer_list; |
||||
220 | } |
||||
221 | |||||
222 | /** |
||||
223 | * @return array |
||||
224 | */ |
||||
225 | protected static function getCurrencies() { |
||||
226 | $payer_list = array( |
||||
227 | -1 => SN::$lang['adm_pay_filter_all'], |
||||
228 | ); |
||||
229 | $query = doquery("SELECT distinct payment_external_currency FROM `{{payment}}`"); |
||||
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
230 | while ($row = db_fetch($query)) { |
||||
0 ignored issues
–
show
The function
db_fetch() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
231 | $payer_list[$row['payment_external_currency']] = $row['payment_external_currency']; |
||||
232 | } |
||||
233 | |||||
234 | return $payer_list; |
||||
235 | } |
||||
236 | |||||
237 | } |
||||
238 |