-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDashboard.php
640 lines (593 loc) · 27.9 KB
/
Dashboard.php
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<?php
/* Display outstanding debtors, creditors, etc */
include('includes/session.php');
$Title = _('Dashboard');
$ViewTopic = 'GeneralLedger';// RChacon: You should be in this topic ?
$BookMark = 'Dashboard';
include('includes/header.php');
echo '<div class="block-header"><a href="" class="header-title-link"><h1>',// Icon title.
$Title, '</h1></a></div><div class="row gutter30">';// Page title.
$Sql = "SELECT pagesecurity
FROM scripts
WHERE scripts.script = 'AgedDebtors.php'";
$ErrMsg = _('The security for Aging Debtors cannot be retrieved because');
$DbgMsg = _('The SQL that was used and failed was');
$Security1Result = DB_query($Sql, $ErrMsg, $DbgMsg);
$MyUserRow = DB_fetch_array($Security1Result);
$DebtorSecurity = $MyUserRow['pagesecurity'];
$Sql = "SELECT pagesecurity
FROM scripts
WHERE scripts.script = 'SuppPaymentRun.php'";
$ErrMsg = _('The security for upcoming payments cannot be retrieved because');
$DbgMsg = _('The SQL that was used and failed was');
$Security2Result = DB_query($Sql, $ErrMsg, $DbgMsg);
$MyUserRow = DB_fetch_array($Security2Result);
$PayeeSecurity = $MyUserRow['pagesecurity'];
$Sql = "SELECT pagesecurity
FROM scripts
WHERE scripts.script = 'GLAccountInquiry.php'";
$ErrMsg = _('The security for G/L Accounts cannot be retrieved because');
$DbgMsg = _('The SQL that was used and failed was');
$Security2Result = DB_query($Sql, $ErrMsg, $DbgMsg);
$MyUserRow = DB_fetch_array($Security2Result);
$CashSecurity = $MyUserRow['pagesecurity'];
$Sql = "SELECT pagesecurity
FROM scripts
WHERE scripts.script = 'SelectSalesOrder.php'";
$ErrMsg = _('The security for Aging Debtors cannot be retrieved because');
$DbgMsg = _('The SQL that was used and failed was');
$Security1Result = DB_query($Sql, $ErrMsg, $DbgMsg);
$MyUserRow = DB_fetch_array($Security1Result);
$OrderSecurity = $MyUserRow['pagesecurity'];
if(in_array($DebtorSecurity, $_SESSION['AllowedPageSecurityTokens']) OR !isset($DebtorSecurity)) {
echo ' <div class="col-md-12"><div class="block">
<div class="block-title"><h2>', _('Overdue Customer Balances'), '</h2></div>
<div class="table-responsive">
<table id="general-table" class="table table-bordered">
<thead>
<tr>
<th>', _('Customer'), '</th>
<th>', _('Reference'), '</th>
<th>', _('Trans Date'), '</th>
<th>', _('Due Date'), '</th>
<th>', _('Balance'), '</th>
<th>', _('Current'), '</th>
<th>', _('Due Now'), '</th>
<th>', '> ', $_SESSION['PastDueDays1'], ' ', _('Days Over'), '</th>
<th>', '> ', $_SESSION['PastDueDays2'], ' ', _('Days Over'), '</th>
</tr>
</thead><tbody>';
$j = 1;
$TotBal = 0;
$TotCurr = 0;
$TotDue = 0;
$TotOD1 = 0;
$TotOD2 = 0;
$CurrDecimalPlaces = 2;//By default.
if(!isset($_POST['Salesman'])) {
$_POST['Salesman'] = '';
}
if($_SESSION['SalesmanLogin'] != '') {
$_POST['Salesman'] = $_SESSION['SalesmanLogin'];
}
if(trim($_POST['Salesman']) != '') {
$SalesLimit = " AND debtorsmaster.debtorno IN (SELECT DISTINCT debtorno FROM custbranch WHERE salesman = '".$_POST['Salesman']."') ";
} else {
$SalesLimit = '';
}
$Sql = "SELECT debtorsmaster.debtorno,
debtorsmaster.name,
currencies.currency,
currencies.decimalplaces,
paymentterms.terms,
debtorsmaster.creditlimit,
holdreasons.dissallowinvoices,
holdreasons.reasondescription,
SUM(
debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
) AS balance,
SUM(
CASE WHEN (paymentterms.daysbeforedue > 0)
THEN
CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) >= paymentterms.daysbeforedue
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
ELSE 0 END
ELSE
CASE WHEN TO_DAYS(Now()) - TO_DAYS(ADDDATE(last_day(debtortrans.trandate), paymentterms.dayinfollowingmonth)) >= 0
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END
END
) AS due,
SUM(
CASE WHEN (paymentterms.daysbeforedue > 0)
THEN
CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays1'] . ")
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END
ELSE
CASE WHEN TO_DAYS(Now()) - TO_DAYS(ADDDATE(last_day(debtortrans.trandate), paymentterms.dayinfollowingmonth)) >= " . $_SESSION['PastDueDays1'] . "
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
ELSE 0 END
END
) AS overdue1,
SUM(
CASE WHEN (paymentterms.daysbeforedue > 0)
THEN
CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays2'] . ")
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END
ELSE
CASE WHEN TO_DAYS(Now()) - TO_DAYS(ADDDATE(last_day(debtortrans.trandate), paymentterms.dayinfollowingmonth)) >= " . $_SESSION['PastDueDays2'] . "
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
ELSE 0 END
END
) AS overdue2
FROM debtorsmaster,
paymentterms,
holdreasons,
currencies,
debtortrans
WHERE debtorsmaster.paymentterms = paymentterms.termsindicator
AND debtorsmaster.currcode = currencies.currabrev
AND debtorsmaster.holdreason = holdreasons.reasoncode
AND debtorsmaster.debtorno = debtortrans.debtorno
" . $SalesLimit . "
GROUP BY debtorsmaster.debtorno,
debtorsmaster.name,
currencies.currency,
paymentterms.terms,
paymentterms.daysbeforedue,
paymentterms.dayinfollowingmonth,
debtorsmaster.creditlimit,
holdreasons.dissallowinvoices,
holdreasons.reasondescription
HAVING
ROUND(ABS(SUM(debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc)),currencies.decimalplaces) > 0";
$CustomerResult = DB_query($Sql, '', '', False, False); /*dont trap errors handled below*/
if(DB_error_no() != 0) {
echo prnMsg(_('The customer details could not be retrieved by the SQL because') . ' ' . DB_error_msg(),'error');
echo '<div class="row">
<div class="col-xs-4"><a href="' . $RootPath . '/menu_data.php?Application=Sales" class="btn btn-default">' . _('Back to Menu') . '</a></div></div>';
if($debug==1) {
echo '<br />', $Sql;
}
//include('includes/footer.php');
exit;
}
while($AgedAnalysis = DB_fetch_array($CustomerResult)) {
$CurrDecimalPlaces = $AgedAnalysis['decimalplaces'];
$DisplayDue = locale_number_format($AgedAnalysis['due']-$AgedAnalysis['overdue1'],$CurrDecimalPlaces);
$DisplayCurrent = locale_number_format($AgedAnalysis['balance']-$AgedAnalysis['due'],$CurrDecimalPlaces);
$DisplayBalance = locale_number_format($AgedAnalysis['balance'],$CurrDecimalPlaces);
$DisplayOverdue1 = locale_number_format($AgedAnalysis['overdue1']-$AgedAnalysis['overdue2'],$CurrDecimalPlaces);
$DisplayOverdue2 = locale_number_format($AgedAnalysis['overdue2'],$CurrDecimalPlaces);
if($DisplayDue <> 0 OR $DisplayOverdue1 <> 0 OR $DisplayOverdue2 <> 0) {
$TotBal += $AgedAnalysis['balance'];
$TotCurr += ($AgedAnalysis['balance']-$AgedAnalysis['due']);
$TotDue += ($AgedAnalysis['due']-$AgedAnalysis['overdue1']);
$TotOD1 += ($AgedAnalysis['overdue1']-$AgedAnalysis['overdue2']);
$TotOD2 += $AgedAnalysis['overdue2'];
echo '<tr class="striped_row">
<td class="text" colspan="4"><a href="CustomerInquiry.php?CustomerID=', $AgedAnalysis['debtorno'],'" class="btn btn-info"><strong>',
$AgedAnalysis['debtorno'], ' - ', $AgedAnalysis['name'], '</strong></a></td>
<td class="number"><strong>', $DisplayBalance, '</strong></td>
<td class="number"><strong>', $DisplayCurrent, '</strong></td>
<td class="number"><strong>', $DisplayDue, '</strong></td>
<td class="number" style="color:#ff0000;"><strong>', $DisplayOverdue1, '</strong></td>
<td class="number" style="color:#ff0000;"><strong>', $DisplayOverdue2, '</strong></td>
</tr>';
$Sql = "SELECT systypes.typename,
debtortrans.transno,
debtortrans.trandate,
daysbeforedue,
dayinfollowingmonth,
(debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc) as balance,
(CASE WHEN (paymentterms.daysbeforedue > 0)
THEN
(CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) >= paymentterms.daysbeforedue
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
ELSE 0 END)
ELSE
(CASE WHEN TO_DAYS(Now()) - TO_DAYS(ADDDATE(ADDDATE(last_day(debtortrans.trandate), 1), paymentterms.dayinfollowingmonth)) >= 0
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
ELSE 0 END)
END) AS due,
(CASE WHEN (paymentterms.daysbeforedue > 0)
THEN
(CASE WHEN TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays1'] . ") THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END)
ELSE
(CASE WHEN (TO_DAYS(Now()) - TO_DAYS(ADDDATE(ADDDATE(last_day(debtortrans.trandate), 1), paymentterms.dayinfollowingmonth)) >= " . $_SESSION['PastDueDays1'] . ")
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
ELSE 0 END)
END) AS overdue1,
(CASE WHEN (paymentterms.daysbeforedue > 0)
THEN
(CASE WHEN TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays2'] . ")
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
ELSE 0 END)
ELSE
(CASE WHEN (TO_DAYS(Now()) - TO_DAYS(ADDDATE(ADDDATE(last_day(debtortrans.trandate), 1), paymentterms.dayinfollowingmonth)) >= " . $_SESSION['PastDueDays2'] . ")
THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc
ELSE 0 END)
END) AS overdue2
FROM debtorsmaster,
paymentterms,
debtortrans,
systypes
WHERE systypes.typeid = debtortrans.type
AND debtorsmaster.paymentterms = paymentterms.termsindicator
AND debtorsmaster.debtorno = debtortrans.debtorno
AND debtortrans.debtorno = '" . $AgedAnalysis['debtorno'] . "'
AND ABS(debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc)>0.004
ORDER BY debtortrans.trandate";
if($_SESSION['SalesmanLogin'] != '') {
$Sql .= " AND debtortrans.salesperson='" . $_SESSION['SalesmanLogin'] . "'";
}
$DetailResult = DB_query($Sql,'','',False,False);
if(DB_error_no() !=0) {
echo prnMsg(_('The details of outstanding transactions for customer') . ' - ' . $AgedAnalysis['debtorno'] . ' ' . _('could not be retrieved because') . ' - ' . DB_error_msg(),'error');
echo '<div class="row">
<div class="col-xs-4"><a href="' . $RootPath . '/menu_data.php?Application=Sales" class="btn btn-default">' . _('Back to Menu') . '</a></div></div>';
if($debug==1) {
echo '<br />' . _('The SQL that failed was') . '<br />' . $Sql;
}
//include('includes/footer.php');
exit;
}
while($DetailTrans = DB_fetch_array($DetailResult)) {
$DisplayTranDate = ConvertSQLDate($DetailTrans['trandate']);
$DisplayBalance = locale_number_format($DetailTrans['balance'], $CurrDecimalPlaces);
$DisplayCurrent = locale_number_format($DetailTrans['balance']-$DetailTrans['due'], $CurrDecimalPlaces);
$DisplayDue = locale_number_format($DetailTrans['due']-$DetailTrans['overdue1'], $CurrDecimalPlaces);
$DisplayOverdue1 = locale_number_format($DetailTrans['overdue1']-$DetailTrans['overdue2'], $CurrDecimalPlaces);
$DisplayOverdue2 = locale_number_format($DetailTrans['overdue2'], $CurrDecimalPlaces);
$DisplayDueDate = CalcDueDate($DisplayTranDate, $DetailTrans['dayinfollowingmonth'], $DetailTrans['daysbeforedue']);
echo '<tr class="striped_row">
<td class="centre">', _($DetailTrans['typename']), '</td>',// Should it be left (text field) ?
'<td class="number">', $DetailTrans['transno'], '</td>
<td class="centre">', $DisplayTranDate, '</td>
<td class="centre">', $DisplayDueDate, '</td>
<td class="number">', $DisplayBalance, '</td>
<td class="number">', $DisplayCurrent, '</td>
<td class="number">', $DisplayDue, '</td>
<td class="number" style="color:#ff0000;">', $DisplayOverdue1, '</td>
<td class="number" style="color:#ff0000;">', $DisplayOverdue2, '</td>
</tr>';
} //end while there are detail transactions to show
} //has Due now or overdue
} //end customer aged analysis while loop
// Print totals of 'Overdue Customer Balances':
echo '<tr class="striped_row">
<td class="text"><strong>', _('Totals'), '</strong></td>
<td> </td>
<td> </td>
<td> </td>
<td class="number"><strong>', locale_number_format($TotBal, $CurrDecimalPlaces), '</strong></td>
<td class="number"><strong>', locale_number_format($TotCurr, $CurrDecimalPlaces), '</strong></td>
<td class="number"><strong>', locale_number_format($TotDue, $CurrDecimalPlaces), '</strong></td>
<td class="number" style="color:#ff0000;"><strong>', locale_number_format($TotOD1, $CurrDecimalPlaces), '</strong></td>
<td class="number" style="color:#ff0000;"><strong>', locale_number_format($TotOD2, $CurrDecimalPlaces), '</strong></td>
</tr>
</tbody></table></div></div></div>';
} //DebtorSecurity
if(in_array($OrderSecurity, $_SESSION['AllowedPageSecurityTokens']) OR !isset($OrderSecurity)) {
echo '
<div class="col-md-12"><div class="block">
<div class="block-title"><h2>', _('Outstanding Orders'), '</h2></div>
<div class="table-responsive">
<table id="general-table" class="table table-bordered">
<thead>',
'<tr>
<th>', _('View Order'), '</th>
<th>', _('Customer'), '</th>
<th>', _('Branch'), '</th>
<th>', _('Cust Order'), ' #</th>
<th>', _('Order Date'), '</th>
<th>', _('Req Del Date'), '</th>
<th>', _('Delivery To'), '</th>
<th>', _('Order Total'), ' ', _('in'), ' ', $_SESSION['CompanyRecord']['currencydefault'], '</th>
</tr>
</thead><tbody>';
$Sql = "SELECT salesorders.orderno,
debtorsmaster.name,
custbranch.brname,
salesorders.customerref,
salesorders.orddate,
salesorders.deliverto,
salesorders.deliverydate,
salesorders.printedpackingslip,
salesorders.poplaced,
SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)/currencies.rate) AS ordervalue
FROM salesorders INNER JOIN salesorderdetails
ON salesorders.orderno = salesorderdetails.orderno
INNER JOIN debtorsmaster
ON salesorders.debtorno = debtorsmaster.debtorno
INNER JOIN custbranch
ON debtorsmaster.debtorno = custbranch.debtorno
AND salesorders.branchcode = custbranch.branchcode
INNER JOIN currencies
ON debtorsmaster.currcode = currencies.currabrev
WHERE salesorderdetails.completed=0
AND salesorders.quotation =0
GROUP BY salesorders.orderno,
debtorsmaster.name,
custbranch.brname,
salesorders.customerref,
salesorders.orddate,
salesorders.deliverto,
salesorders.deliverydate,
salesorders.printedpackingslip
ORDER BY salesorders.orddate DESC, salesorders.orderno";
$ErrMsg = _('No orders or quotations were returned by the SQL because');
$SalesOrdersResult = DB_query($Sql,$ErrMsg);
/*show a table of the orders returned by the SQL */
if(DB_num_rows($SalesOrdersResult)>0) {
$OrdersTotal = 0;
$FontColor = '';
while($MyRow=DB_fetch_array($SalesOrdersResult)) {
$OrderDate = ConvertSQLDate($MyRow['orddate']);
$FormatedDelDate = ConvertSQLDate($MyRow['deliverydate']);
$FormatedOrderValue = locale_number_format($MyRow['ordervalue'],$_SESSION['CompanyRecord']['decimalplaces']);
if(DateDiff(Date($_SESSION['DefaultDateFormat']), $OrderDate, 'd') > 5) {
$FontColor = ' style="color:green; font-weight:bold"';
}
echo '<tr class="striped_row">
<td class="number"><a href="', $RootPath, '/OrderDetails.php?OrderNumber=', $MyRow['orderno'], '" target="_blank" class="btn btn-info">', $MyRow['orderno'], '</a></td>
<td>', $MyRow['name'], '</td>
<td>', $MyRow['brname'], '</td>
<td>', $MyRow['customerref'], '</td>
<td>', $OrderDate, '</td>
<td>', $FormatedDelDate, '</td>
<td>', html_entity_decode($MyRow['deliverto'], ENT_QUOTES, 'UTF-8'), '</td>
<td>', $FormatedOrderValue, '</td>
</tr>';
$OrdersTotal += $MyRow['ordervalue'];
}// END while($MyRow=DB_fetch_array($SalesOrdersResult))
echo '<tr>
<td class="number" colspan="7"><strong>', _('Total Order(s) Value in'), ' ', $_SESSION['CompanyRecord']['currencydefault'], ' :</strong></td>
<td class="number"><strong>', locale_number_format($OrdersTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</strong></td>
</tr>';
} //rows > 0
echo '</tbody></table></div></div></div>';
} //OrderSecurity
if(in_array($PayeeSecurity, $_SESSION['AllowedPageSecurityTokens']) OR !isset($PayeeSecurity)) {
echo '
<div class="col-md-6"><div class="block">
<div class="block-title"><h2>', _('Supplier Invoices Due within 1 Month'), '</h2></div>
<div class="table-responsive">
<table id="general-table" class="table table-bordered">
<thead>
<tr>
<th>', _('Supplier'), '</th>
<th>', _('Invoice Date'), '</th>
<th>', _('Invoice'), '</th>
<th>', _('Amount Due'), '</th>
<th>', _('Due Date'), '</th>
</tr>
</thead><tbody>';
$SupplierID = '';
$TotalPayments = 0;
$TotalAccumDiffOnExch = 0;
$AccumBalance = 0;
$Sql = "SELECT suppliers.supplierid,
currencies.decimalplaces AS currdecimalplaces,
SUM(supptrans.ovamount + supptrans.ovgst - supptrans.alloc) AS balance
FROM suppliers INNER JOIN paymentterms
ON suppliers.paymentterms = paymentterms.termsindicator
INNER JOIN supptrans
ON suppliers.supplierid = supptrans.supplierno
INNER JOIN systypes
ON systypes.typeid = supptrans.type
INNER JOIN currencies
ON suppliers.currcode=currencies.currabrev
WHERE supptrans.ovamount + supptrans.ovgst - supptrans.alloc !=0
AND supptrans.hold=0
GROUP BY suppliers.supplierid,
currencies.decimalplaces
HAVING SUM(supptrans.ovamount + supptrans.ovgst - supptrans.alloc) <> 0
ORDER BY supptrans.duedate, suppliers.supplierid";
$SuppliersResult = DB_query($Sql);
while($SuppliersToPay = DB_fetch_array($SuppliersResult)) {
$CurrDecimalPlaces = $SuppliersToPay['currdecimalplaces'];
$Sql = "SELECT suppliers.supplierid,
suppliers.suppname,
systypes.typename,
paymentterms.terms,
supptrans.suppreference,
supptrans.trandate,
supptrans.rate,
supptrans.transno,
supptrans.type,
supptrans.duedate,
(supptrans.ovamount + supptrans.ovgst - supptrans.alloc) AS balance,
(supptrans.ovamount + supptrans.ovgst ) AS trantotal,
supptrans.diffonexch,
supptrans.id
FROM suppliers
INNER JOIN paymentterms ON suppliers.paymentterms = paymentterms.termsindicator
INNER JOIN supptrans ON suppliers.supplierid = supptrans.supplierno
INNER JOIN systypes ON systypes.typeid = supptrans.type
WHERE supptrans.supplierno = '" . $SuppliersToPay['supplierid'] . "'
AND supptrans.ovamount + supptrans.ovgst - supptrans.alloc !=0
AND supptrans.duedate <='" . Date('Y-m-d', mktime(0,0,0, Date('n'),Date('j')+30,date('Y'))) . "'
AND supptrans.hold = 0
ORDER BY supptrans.supplierno,
supptrans.type,
supptrans.transno";
$TransResult = DB_query($Sql,'','',false,false);
if(DB_error_no() !=0) {
echo prnMsg(_('The details of supplier invoices due could not be retrieved because') . ' - ' . DB_error_msg(),'error');
echo '<div class="row">
<div class="col-xs-4"><a href="' . $RootPath . '/menu_data.php?Application=PO" class="btn btn-default">' . _('Back to Menu') . '</a></div></div>';
if($debug==1) {
echo '<br />' . _('The querry that failed was') . ' ' . $Sql;
}
//include('includes/footer.php');
exit;
}
unset($Allocs);
$Allocs = array();
$AllocCounter =0;
while($DetailTrans = DB_fetch_array($TransResult)) {
if($DetailTrans['supplierid'] != $SupplierID) { /*Need to head up for a new suppliers details */
$SupplierID = $DetailTrans['supplierid'];
$SupplierName = $DetailTrans['suppname'];
//$AccumBalance = 0;
$AccumDiffOnExch = 0;
echo '<tr class="striped_row">
<td class="text" colspan="5"><strong>', $DetailTrans['supplierid'], ' - ', $DetailTrans['suppname'], ' - ', $DetailTrans['terms'], '</strong></td>
</tr>';
}
$DisplayFormat = '';
if((time()-(60*60*24)) > strtotime($DetailTrans['duedate'])) {
$DisplayFormat = ' style="color:red;"';
}
$DislayTranDate = ConvertSQLDate($DetailTrans['trandate']);
$AccumBalance += $DetailTrans['balance'];
if($DetailTrans['type'] == 20) {// If Purchase Invoice:
echo '<tr class="striped_row">
<td class="centre">', _($DetailTrans['typename']), '</td>
<td class="centre">', $DislayTranDate, '</td>
<td class="text"><a href="', $RootPath, '/Payments.php?&SupplierID=', $SupplierID, '&Amount=', $DetailTrans['balance'], '&BankTransRef=', $DetailTrans['suppreference'], '" class="btn btn-info">', $DetailTrans['suppreference'], '</a></td>
<td class="number"', $DisplayFormat, '>', locale_number_format($DetailTrans['balance'], $CurrDecimalPlaces), '</td>
<td class="centre"', $DisplayFormat, '>', ConvertSQLDate($DetailTrans['duedate']), '</td>
</tr>';
} else {// If NOT Purchase Invoice (Creditors Payment):
echo '<tr class="striped_row">
<td class="centre">', _($DetailTrans['typename']), '</td>
<td class="centre">', $DislayTranDate, '</td>
<td class="text"><a href="', $RootPath, '/SupplierAllocations.php?AllocTrans=', $DetailTrans['id'], '" class="btn btn-info">', $DetailTrans['suppreference'], '</a></td>
<td class="number"', $DisplayFormat, '>', locale_number_format($DetailTrans['balance'], $CurrDecimalPlaces), '</td>
<td class="centre"', $DisplayFormat, '>', ConvertSQLDate($DetailTrans['duedate']), '</td>
</tr>';
}
} /*end while there are detail transactions to show */
} /* end while there are suppliers to retrieve transactions for */
echo '<tr class="striped_row">
<td class="number">', _('Grand Total Payments Due'), '</td>
<td> </td>
<td> </td>
<td class="number"><strong>', locale_number_format($AccumBalance, $CurrDecimalPlaces), '</strong></td>
<td> </td>
</tr>
</tbody>
</table></div></div></div>';
} //PayeeSecurity
if(in_array($CashSecurity, $_SESSION['AllowedPageSecurityTokens']) OR !isset($CashSecurity)) {
include('includes/GLPostings.inc');
echo '
<div class="col-md-6"><div class="block">
<div class="block-title"><h2>', _('Bank Balances'), '</h2></div>
<div class="table-responsive">
<table id="general-table" class="table table-bordered">
<thead>
<tr>
<th class="ascending">', _('GL Account'), '</th>
<th class="ascending">', _('Account Name'), '</th>
<th class="ascending">', _('Balance'), '</th>
</tr>
</thead>
<tbody>';
$FirstPeriodSelected = GetPeriod(date($_SESSION['DefaultDateFormat']));
$LastPeriodSelected = GetPeriod(date($_SESSION['DefaultDateFormat']));
$SelectedPeriod=$LastPeriodSelected;
$Sql = "SELECT bankaccounts.accountcode,
bankaccounts.bankaccountcode,
chartmaster.accountname,
bankaccountname
FROM bankaccounts
INNER JOIN chartmaster
ON bankaccounts.accountcode = chartmaster.accountcode
INNER JOIN bankaccountusers
ON bankaccounts.accountcode=bankaccountusers.accountcode
AND userid='" . $_SESSION['UserID'] . "'";
$ErrMsg = _('The bank accounts set up could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the bank account details was') . '<br />' . $Sql;
$result1 = DB_query($Sql,$ErrMsg,$DbgMsg);
while($myrow = DB_fetch_array($result1)) {
/*Is the account a balance sheet or a profit and loss account */
$result = DB_query("SELECT pandl
FROM accountgroups
INNER JOIN chartmaster ON accountgroups.groupname=chartmaster.group_
WHERE chartmaster.accountcode='" . $myrow['accountcode'] ."'");
$PandLRow = DB_fetch_row($result);
if($PandLRow[0]==1) {
$PandLAccount = True;
} else {
$PandLAccount = False; /*its a balance sheet account */
}
$Sql= "SELECT counterindex,
type,
typename,
gltrans.typeno,
trandate,
narrative,
amount,
periodno,
gltrans.tag,
tagdescription
FROM gltrans INNER JOIN systypes
ON systypes.typeid=gltrans.type
LEFT JOIN tags
ON gltrans.tag = tags.tagref
WHERE gltrans.account = '" . $myrow['accountcode'] . "'
AND posted=1
AND periodno>='" . $FirstPeriodSelected . "'
AND periodno<='" . $LastPeriodSelected . "'
ORDER BY periodno, gltrans.trandate, counterindex";
$TransResult = DB_query($Sql,$ErrMsg);
if($PandLAccount==True) {
$RunningTotal = 0;
} else {// added to fix bug with Brought Forward Balance always being zero
$Sql = "SELECT bfwd,
actual,
period
FROM chartdetails
WHERE chartdetails.accountcode='" . $myrow['accountcode'] . "'
AND chartdetails.period='" . $FirstPeriodSelected . "'";
$ErrMsg = _('The chart details for account') . ' ' . $myrow['accountcode'] . ' ' . _('could not be retrieved');
$ChartDetailsResult = DB_query($Sql,$ErrMsg);
$ChartDetailRow = DB_fetch_array($ChartDetailsResult);
$RunningTotal = $ChartDetailRow['bfwd'];
}
$PeriodTotal = 0;
$PeriodNo = -9999;
while($myrow2=DB_fetch_array($TransResult)) {
if($myrow2['periodno']!=$PeriodNo) {
if($PeriodNo!=-9999) { //ie its not the first time around
/*Get the ChartDetails balance b/fwd and the actual movement in the account for the period as recorded in the chart details - need to ensure integrity of transactions to the chart detail movements. Also, for a balance sheet account it is the balance carried forward that is important, not just the transactions*/
$Sql = "SELECT bfwd,
actual,
period
FROM chartdetails
WHERE chartdetails.accountcode='" . $myrow['accountcode'] . "'
AND chartdetails.period='" . $PeriodNo . "'";
$ErrMsg = _('The chart details for account') . ' ' . $myrow['accountcode'] . ' ' . _('could not be retrieved');
$ChartDetailsResult = DB_query($Sql,$ErrMsg);
$ChartDetailRow = DB_fetch_array($ChartDetailsResult);
if($PeriodTotal < 0 ) { //its a credit balance b/fwd
if($PandLAccount==True) {
$RunningTotal = 0;
}
} else { //its a debit balance b/fwd
if($PandLAccount==True) {
$RunningTotal = 0;
}
}
}
$PeriodNo = $myrow2['periodno'];
$PeriodTotal = 0;
}
$RunningTotal += $myrow2['amount'];
$PeriodTotal += $myrow2['amount'];
}
$DisplayBalance=locale_number_format(($RunningTotal),$_SESSION['CompanyRecord']['decimalplaces']);
echo '<tr class="striped_row">
<td class="text">', $myrow['accountcode'], ' - ', $myrow['accountname'], '</td>
<td class="text">', $myrow['bankaccountname'], '</td>
<td class="number">', $DisplayBalance, '</td>
</tr>';
} //each bank account
echo '</tbody>
</table></div></div></div>';
} //CashSecurity
echo '</div><br />';
include('includes/footer.php');
?>