1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
|
<?php
/**
*
* Class ki skrbi za pregled, dodajanje, urejanje placil uporabnika
*
*/
class UserPlacila{
function __construct(){
}
// Dobimo array placil (vseh oz. za dolocen id)
private function getPlacila(){
global $admin_type;
$placila = array();
// Loop po vseh placilih v sistemu
$sqlPlacilo = sisplet_query("SELECT * FROM user_access_placilo ORDER BY id DESC");
while($rowPlacilo = mysqli_fetch_array($sqlPlacilo)){
$placila[$rowPlacilo['id']] = $rowPlacilo;
// Dobimo se podatke narocila, ce imamo id
if($rowPlacilo['narocilo_id'] > 0){
$sqlNarocilo = sisplet_query("SELECT n.*, u.name, u.surname, u.email
FROM user_access_narocilo n, users u
WHERE n.usr_id=u.id AND n.id='".$rowPlacilo['narocilo_id']."'
");
$rowNarocilo = mysqli_fetch_array($sqlNarocilo);
$placila[$rowPlacilo['id']]['narocilo'] = $rowNarocilo;
}
}
return $placila;
}
// Dobimo podatke placila dolocen id
private function getPlacilo($placilo_id){
global $admin_type;
$placilo = array();
// Loop po vseh placilih v sistemu
$sqlPlacilo = sisplet_query("SELECT * FROM user_access_placilo WHERE id='".$placilo_id."'");
$placilo = mysqli_fetch_array($sqlPlacilo);
// Dobimo se podatke narocila, ce imamo id
if($placilo['narocilo_id'] > 0){
$sqlNarocilo = sisplet_query("SELECT n.*, u.name, u.surname, u.email
FROM user_access_narocilo n, users u
WHERE n.usr_id=u.id AND n.id='".$placilo['narocilo_id']."'
");
$rowNarocilo = mysqli_fetch_array($sqlNarocilo);
$placilo['narocilo'] = $rowNarocilo;
}
return $placilo;
}
// Ustvarimo placilo iz narocila
public function createPlacilo($narocilo, $eracun=false){
// Preverimo, ce slucajno se obstaja placilo za to narocilo - vrnemo error
$sqlPlaciloCheck = sisplet_query("SELECT id FROM user_access_placilo WHERE narocilo_id='".$narocilo['id']."'");
if(mysqli_num_rows($sqlPlaciloCheck) > 0){
echo 'Napaka! Plačilo za to naročilo že obstaja.';
return;
}
$note = 'Plačilo naročila '.$narocilo['id'];
// Dobimo ceno glede na narocilo in paket
$sqlPackage = sisplet_query("SELECT name FROM user_access_paket WHERE id='".$narocilo['package_id']."'");
$rowPackage = mysqli_fetch_array($sqlPackage);
$UA = new UserNarocila();
$cena = $UA->getPrice($rowPackage['name'], $narocilo['trajanje'], $narocilo['discount'], $narocilo['time']);
// Zavezanec iz tujine je placal brez ddv
$cena_placano = ($UA->isWithoutDDV($narocilo['id'])) ? $cena['final_without_tax'] : $cena['final'];
// Ce je placilo eracuna, bo placano sele cez 30 dni
$time = ($eracun) ? 'NOW() + INTERVAL 1 MONTH': 'NOW()';
$sqlPlacilo = sisplet_query("INSERT INTO user_access_placilo
(narocilo_id, note, time, price, payment_method)
VALUES
('".$narocilo['id']."', '".$note."', ".$time.", '".$cena_placano."', '".$narocilo['payment_method']."')
");
if (!$sqlPlacilo)
echo mysqli_error($GLOBALS['connect_db']);
}
// Izpisemo podatke o placilih
public function displayPlacila(){
global $lang, $global_user_id;
// Tabela vseh placil
$this->displayPlacilaTable();
// Gumb za dodajanje placila
/*echo '<div class="buttons_holder">';
echo ' <div class="buttonwrapper floatLeft"><a class="ovalbutton ovalbutton_orange btn_savesettings" href="#" onclick="displayPlaciloPopup();"><span>'.$lang['srv_placila_create'].'</span></a></div>';
echo '</div>';*/
// Izracun zasluzka in provizij po mesecih - samo Goran
if(AppSettings::getInstance()->getSetting('app_settings-app_name') == 'www.1ka.si' && $global_user_id == '112696')
$this->displayPlacilaPovzetek();
}
// Izpisemo seznam vseh placil
public function displayPlacilaTable(){
global $lang, $global_user_id;
// Admini vidijo vsa placila
$data = $this->getPlacila();
echo '<table id="user_placila" class="dataTable user_placila_admin" style="width:100%">';
// Glava tabele
echo ' <thead>';
echo ' <tr>';
echo ' <th>'.$lang['srv_placilo_narocilo'].'</th>';
echo ' <th>'.$lang['srv_placilo_note'].'</th>';
echo ' <th>'.$lang['srv_placilo_time'].'</th>';
echo ' <th>'.$lang['srv_placilo_price'].'</th>';
echo ' <th>'.$lang['srv_narocilo_ddv'].'</th>';
echo ' <th>'.$lang['srv_placilo_payment_method'].'</th>';
echo ' <th>'.$lang['srv_placilo_stornirano'].'</th>';
echo ' <th>'.$lang['srv_placilo_drzava'].'</th>';
echo ' <th>'.$lang['srv_placilo_paket'].'</th>';
echo ' <th>'.$lang['srv_placilo_trajanje'].'</th>';
echo ' <th>'.$lang['edit2'].'</th>';
echo ' </tr>';
echo ' </thead>';
// Vsebina tabele
echo ' <tbody>';
foreach($data as $placilo_id => $data_row){
echo '<tr>';
// Narocilo
if(isset($data_row['narocilo'])){
echo '<td>'.$data_row['narocilo']['id'].' ('.$data_row['narocilo']['email'].')</td>';
}
else{
echo '<td>/</td>';
}
// Note
echo '<td>'.$data_row['note'].'</td>';
// Time
echo '<td data-order="'.date("Y-n-j", strtotime($data_row['time'])).'">'.date( 'd.m.Y G:i', strtotime($data_row['time'])).'</td>';
// Price
echo '<td>'.$data_row['price'].'</td>';
// Brez ddv (zavezanec iz tujine)
$UA = new UserNarocila();
echo '<td>'.($UA->isWithoutDDV($data_row['narocilo']['id']) ? $lang['no'] : $lang['yes']).'</td>';
// Payment method
echo '<td>'.$lang['srv_narocilo_nacin_placila_'.$data_row['payment_method']].'</td>';
// Stornirano method
echo '<td>'.($data_row['canceled'] == '1' ? $lang['yes'] : $lang['no']).'</td>';
// Država
echo '<td>'.$data_row['narocilo']['podjetje_drzava'].'</td>';
// Paket
echo '<td>'.$data_row['narocilo']['package_id'].'KA</td>';
// Trajanje
echo '<td>'.$data_row['narocilo']['trajanje'].'</td>';
// Edit / delete
echo '<td>';
// Na www.1ka.si lahko placilo ureja samo Goran
if(AppSettings::getInstance()->getSetting('app_settings-app_name') != 'www.1ka.si' || $global_user_id == '112696'){
// Uredi
echo '<a href="#" onClick="displayPlaciloPopup(\''.$data_row['id'].'\')" title="'.$lang['srv_placila_edit'].'"><i class="fa fa-pencil-alt link-sv-moder"></i></a> <span class="no-print"> | </span>';
// Brisi
echo '<a href="#" onClick="brisiPlacilo(\''.$data_row['id'].'\')" title="'.$lang['srv_placila_delete'].'"><i class="fa fa-times link-sv-moder"></i></a>';
// Storniraj
if($data_row['canceled'] != '1')
echo ' <span class="no-print"> | </span><a href="#" onClick="stornirajPlacilo(\''.$data_row['id'].'\')" title="'.$lang['srv_placila_storniraj'].'">Storniraj</a>';
}
else{
echo '/';
}
echo '</td>';
echo '</tr>';
}
echo ' </tbody>';
echo '</table>';
// Se inicializiramo dataTable jquery
echo '<script> preparePlacilaTableAdmin(); </script>';
}
// Prikazemo popup za dodajanje novega placila
private function displayPlaciloCreate(){
global $lang;
echo '<h2>'.$lang['srv_placila_create'].'</h2>';
echo '<div class="edit_placilo_content">';
echo '<div class="form_holder"><form name="create_placilo" id="create_placilo">';
// Podatki narocnika
echo '<div class="edit_placilo_segment">';
// Note
echo '<div class="edit_placilo_line">';
echo '<span class="nastavitveSpan5">'.$lang['srv_placilo_note'].':</span> ';
//echo '<input type="text" name="note">';
echo '<textarea name="note"></textarea>';
echo '</div>';
// Time
echo '<div class="edit_placilo_line">';
echo '<span class="nastavitveSpan5">'.$lang['srv_placilo_time'].':</span> ';
echo '<input type="text" name="time">';
echo '</div>';
// Price
echo '<div class="edit_placilo_line">';
echo '<span class="nastavitveSpan5">'.$lang['srv_placilo_price'].':</span> ';
echo '<input type="text" name="price">';
echo '</div>';
// Payment method
echo '<div class="edit_placilo_line">';
echo '<span class="nastavitveSpan5">'.$lang['srv_placilo_payment_method'].':</span> ';
echo '<input type="text" name="payment_method">';
echo '</div>';
echo '</div>';
echo '</form></div>';
// Gumbi na dnu
echo '<div class="buttons_holder">';
echo ' <div class="buttonwrapper floatRight"><a class="ovalbutton ovalbutton_orange btn_savesettings" href="#" onclick="createPlaciloSave();"><span>'.$lang['edit1337'].'</span></a></div>';
echo ' <div class="buttonwrapper floatRight spaceRight"><a class="ovalbutton ovalbutton_gray" href="#" onclick="urediPlaciloClose();"><span>'.$lang['srv_zapri'].'</span></a></div>';
echo '</div>';
echo '</div>';
}
// Prikazemo popup za pregled in urejanje placila - TODO
private function displayPlaciloEdit($placilo_id){
global $lang;
// Dobimo podatke placila
$placilo = $this->getPlacilo($placilo_id);
echo '<h2>'.$lang['srv_placila_create'].'</h2>';
echo '<div class="edit_placilo_content">';
echo '<div class="form_holder"><form name="edit_placilo" id="edit_placilo">';
// Podatki narocnika
echo '<div class="edit_placilo_segment">';
// Input za id porocila
echo '<input type="hidden" name="placilo_id" value="'.$placilo_id.'">';
// Note
echo '<div class="edit_placilo_line">';
echo '<span class="nastavitveSpan5">'.$lang['srv_placilo_note'].':</span> ';
//echo '<input type="text" name="note" value="'.$placilo['note'].'">';
echo '<textarea name="note">'.$placilo['note'].'</textarea>';
echo '</div>';
// Time
echo '<div class="edit_placilo_line">';
echo '<span class="nastavitveSpan5">'.$lang['srv_placilo_time'].':</span> ';
echo '<input type="text" name="time" value="'.$placilo['time'].'">';
echo '</div>';
// Price
echo '<div class="edit_placilo_line">';
echo '<span class="nastavitveSpan5">'.$lang['srv_placilo_price'].':</span> ';
echo '<input type="text" name="price" value="'.$placilo['price'].'">';
echo '</div>';
// Payment method
echo '<div class="edit_placilo_line">';
echo '<span class="nastavitveSpan5">'.$lang['srv_placilo_payment_method'].':</span> ';
echo '<input type="text" name="payment_method" value="'.$placilo['payment_method'].'">';
echo '</div>';
echo '</div>';
echo '</form></div>';
// Gumbi na dnu
echo '<div class="buttons_holder">';
echo ' <div class="buttonwrapper floatRight"><a class="ovalbutton ovalbutton_orange btn_savesettings" href="#" onclick="urediPlaciloSave();"><span>'.$lang['edit1337'].'</span></a></div>';
echo ' <div class="buttonwrapper floatRight spaceRight"><a class="ovalbutton ovalbutton_gray" href="#" onclick="urediPlaciloClose();"><span>'.$lang['srv_zapri'].'</span></a></div>';
echo '</div>';
echo '</div>';
}
// Prikazemo popup za pregled in urejanje placila
private function displayPlacilaPovzetek(){
global $lang;
/*
TRR: 0,12 €
EU kartica 1,4% + 0,25 €
Non-EU kartica: 2,9% + 0,25 €
PayPal: 3,4% + 0,35 €
*/
echo '<div style="clear:both; margin: 50px 0;">';
echo '<fieldset><legend>Izračun po mesecih</legend>';
$sqlPlacilo = sisplet_query("SELECT *, MONTH(time) as month, YEAR(time) as year
FROM user_access_placilo
");
while($rowPlacilo = mysqli_fetch_array($sqlPlacilo)){
// Paypal
if($rowPlacilo['payment_method'] == '2'){
$placila[$rowPlacilo['year']][$rowPlacilo['month']]['sum_paypal'] += $rowPlacilo['price'];
$placila[$rowPlacilo['year']][$rowPlacilo['month']]['provizija_paypal'] += ($rowPlacilo['price'] * 0.34) + 0.35;
}
// Kartica
elseif($rowPlacilo['payment_method'] == '3'){
$placila[$rowPlacilo['year']][$rowPlacilo['month']]['sum_kartica'] += $rowPlacilo['price'];
$placila[$rowPlacilo['year']][$rowPlacilo['month']]['provizija_kartica'] += ($rowPlacilo['price'] * 0.014) + 0.25;
}
// TRR
else{
$placila[$rowPlacilo['year']][$rowPlacilo['month']]['sum_trr'] += $rowPlacilo['price'];
$placila[$rowPlacilo['year']][$rowPlacilo['month']]['provizija_trr'] += 0.12;
}
// Suma placil za mesec
$placila[$rowPlacilo['year']][$rowPlacilo['month']]['sum'] += $rowPlacilo['price'];
}
foreach($placila as $year => $placila_leto){
foreach($placila_leto as $month => $placila_mesec){
echo '<br>';
$month_name = date("F", mktime(0, 0, 0, $month, 10));
echo '<span class="bold">'.$month_name.' '.$year.'</span>';
echo '<br>';
echo 'Vsota plačil na TRR: '.$placila_mesec['sum_trr'];
echo '<br>TRR provizija: '.$placila_mesec['provizija_trr'];
echo '<br><br>';
echo 'Vsota plačil s kartico: '.$placila_mesec['sum_kartica'];
echo '<br>Kartica provizija: '.$placila_mesec['provizija_kartica'];
echo '<br><br>';
echo 'Vsota plačil s paypal: '.$placila_mesec['sum_paypal'];
echo '<br>Paypal provizija: '.$placila_mesec['provizija_paypal'];
echo '<br><br>';
echo 'Vsota plačil: '.$placila_mesec['sum'];
echo '<br><br>';
}
}
echo '</fieldset>';
echo '</div>';
}
// Ajax klici
public function ajax(){
$placilo_id = (isset($_POST['placilo_id'])) ? $_POST['placilo_id'] : 0;
// Prikazemo popup z urejanjem posameznega narocila
if($_GET['a'] == 'displayPlaciloPopup') {
if($placilo_id > 0){
$this->displayPlaciloEdit($placilo_id);
}
else{
$this->displayPlaciloCreate();
}
}
// Urejamo narocilo
if($_GET['a'] == 'editPlacilo') {
if($placilo_id > 0){
$update = '';
$update .= (isset($_POST['narocilo_id'])) ? " narocilo_id='".$_POST['narocilo_id']."'," : "";
$update .= (isset($_POST['note'])) ? " note='".$_POST['note']."'," : "";
$update .= (isset($_POST['time'])) ? " time='".$_POST['time']."'," : "";
$update .= (isset($_POST['price'])) ? " price='".$_POST['price']."'," : "";
$update .= (isset($_POST['payment_method'])) ? " payment_method='".$_POST['payment_method']."'," : "";
if($update != ''){
$update = substr($update, 0, -1);
$sqlPlacilo = sisplet_query("UPDATE user_access_placilo SET ".$update." WHERE id='".$placilo_id."'");
if (!$sqlPlacilo)
echo mysqli_error($GLOBALS['connect_db']);
}
}
// Na novo izrisemo tabelo z narocili
$this->displayPlacila();
}
// Urejamo narocilo
if($_GET['a'] == 'createPlacilo') {
$narocilo_id = (isset($_POST['narocilo_id'])) ? $_POST['narocilo_id'] : 0;
$note = (isset($_POST['note'])) ? $_POST['note'] : '';
$time = (isset($_POST['time'])) ? $_POST['time'] : '';
$price = (isset($_POST['price'])) ? $_POST['price'] : 0;
$payment_method = (isset($_POST['payment_method'])) ? $_POST['payment_method'] : '';
if($price != '' && $price != 0){
// Preverimo, ce slucajno se obstaja placilo za to narocilo - vrnemo error
if($narocilo_id != 0){
$sqlPlaciloCheck = sisplet_query("SELECT id FROM user_access_placilo WHERE narocilo_id='".$narocilo_id."'");
if(mysqli_num_rows($sqlPlaciloCheck) > 0){
echo 'Napaka! Plačilo za to naročilo že obstaja.';
// Na novo izrisemo tabelo z narocili
$this->displayPlacila();
return;
}
}
$sqlPlacilo = sisplet_query("INSERT INTO user_access_placilo
(narocilo_id, note, time, price, payment_method)
VALUES
('".$narocilo_id."', '".$note."', '".$time."', '".$price."', '".$payment_method."')
");
if (!$sqlPlacilo)
echo mysqli_error($GLOBALS['connect_db']);
}
else{
echo 'Napaka! Cana za plačilo ne sme biti 0.';
}
// Na novo izrisemo tabelo z narocili
$this->displayPlacila();
}
// Brisemo narocilo
if($_GET['a'] == 'deletePlacilo') {
if($placilo_id > 0){
$sqlPlacilo = sisplet_query("DELETE FROM user_access_placilo WHERE id='".$placilo_id."'");
}
// Na novo izrisemo tabelo z narocili
$this->displayPlacila();
}
// Storniramo narocilo
if($_GET['a'] == 'stornirajPlacilo') {
if($placilo_id > 0){
// Nastavimo se status narocila na storniran
$sqlPlacilo = sisplet_query("SELECT p.*, n.usr_id
FROM user_access_placilo p, user_access_narocilo n
WHERE p.id='".$placilo_id."' AND p.narocilo_id=n.id
");
if(mysqli_num_rows($sqlPlacilo) > 0){
$rowPlacilo = mysqli_fetch_array($sqlPlacilo);
// Nastavimo status originalnega placila na stornirano
$sqlPlaciloStatus = sisplet_query("UPDATE user_access_placilo SET canceled='1' WHERE id='".$placilo_id."'");
// Nastavimo status narocila na stornirano
$sqlNarociloStatus = sisplet_query("UPDATE user_access_narocilo SET status='2' WHERE id='".$rowPlacilo['narocilo_id']."'");
// Negativni znesek
$znesek = number_format((-1) * $rowPlacilo['price'], 2, '.', '');
// Ustvarimo kopijo placila z negativnim zneskom
$sqlStorniranoPlacilo = sisplet_query("INSERT INTO user_access_placilo
(narocilo_id, note, time, price, payment_method, canceled)
VALUES
('".$rowPlacilo['narocilo_id']."', '".$rowPlacilo['note']."', NOW(), '".$znesek."', '".$rowPlacilo['payment_method']."', '1')
");
// Stranki deaktiviramo paket
$sqlNarociloStatus = sisplet_query("UPDATE user_access SET package_id='1' WHERE usr_id='".$rowPlacilo['usr_id']."'");
}
}
// Na novo izrisemo tabelo s placili
$this->displayPlacila();
}
}
}
|