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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
|
<?php $formid = "Order"; require_once "inc/configure.php";
$_REQUEST['vendor'] = setDefaultReqVar("vendor", $_SESSION['defaultcompany']);
search_orderField($_REQUEST['act'], $_REQUEST['customer'], $_REQUEST['launchdate_start'], $_REQUEST['launchdate_end'], $_REQUEST['deliverydate_start'], $_REQUEST['deliverydate_end'], $_REQUEST['finished'], $_REQUEST['status'], $_REQUEST['vendor']); search_miscField($_REQUEST['act'], $_REQUEST['uom_cy']);
$currency = $_REQUEST['uom_cy']; $showUSD = true; $showCNY = true; if ($currency == 'USD') { $showCNY = false; } elseif ($currency == 'CNY') { $showUSD = false; }
// Retrieve the selected type (Invoice or Credit Note) $dataType = isset($_REQUEST['data_type']) && ($_REQUEST['data_type'] === "CreditNote") ? "Credit Note" : "Invoice";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ENZA</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> <?php require_once "inc/jsheader.php"; ?> <script lang="javascript" src="https://cdn.sheetjs.com/xlsx-0.20.0/package/dist/xlsx.full.min.js"></script> <?php echo '<script>var dataType = "' . $dataType . '";</script>'; ?> <!-- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> --> <!-- <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> --> <!-- <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> --> <script> $(document).ready(function() {
// Declare the selectedClients variable var selectedClients = [];
// Restore selected clients from localStorage var storedSelectedClients = localStorage.getItem('selectedClients'); if (storedSelectedClients) { selectedClients = JSON.parse(storedSelectedClients); updateCheckedStatus(); updateTotal();
}
// Function to update the checked status based on selectedClients array function updateCheckedStatus() { $('input[type="checkbox"]').each(function() { if ($.inArray($(this).data('id'), selectedClients) !== -1) { $(this).prop('checked', true); } else { $(this).prop('checked', false); } }); }
// Function to store selected clients in localStorage function storeSelectedClients() { selectedClients = []; $('input[type="checkbox"]').each(function() { if ($(this).is(':checked')) { selectedClients.push($(this).data('id')); } }); localStorage.setItem('selectedClients', JSON.stringify(selectedClients)); }
$("#launchdate_start").datepicker({ dateFormat: "yy-mm-dd", showOn: "both", defaultDate: "<?= $_REQUEST['launchdate_start'] ?>" });
$("#launchdate_end").datepicker({ dateFormat: "yy-mm-dd", showOn: "both", defaultDate: "<?= $_REQUEST['launchdate_end'] ?>" });
$("#deliverydate_start").datepicker({ dateFormat: "yy-mm-dd", showOn: "both", defaultDate: "<?= $_REQUEST['deliverydate_start'] ?>" });
$("#deliverydate_end").datepicker({ dateFormat: "yy-mm-dd", showOn: "both", defaultDate: "<?= $_REQUEST['deliverydate_end'] ?>" });
// Initialize jQuery UI Tabs $("#tabs").tabs({ activate: function(event, ui) { // Save the selected tab's index in localStorage localStorage.setItem('selectedTab', ui.newTab.index()); } });
// Retrieve the previously selected tab from localStorage and activate it var selectedTabIndex = localStorage.getItem('selectedTab'); if (selectedTabIndex !== null) { $("#tabs").tabs("option", "active", parseInt(selectedTabIndex)); }
// Event listener for the checkboxes of the clients. $('input[name="invoice_checkall"]').change(function() { var isChecked = $(this).is(':checked'); $('input[name="invoice_group[]"]').prop('checked', isChecked); updateTotal();
storeSelectedClients(); });
$('input[name="invoice_group[]"]').on('change', function() { updateTotal(); storeSelectedClients(); });
function formatNumberWithCommas(number) { return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
function updateTotal() { //console.log("updateTotal"); var totalcost = 0; var totalfcost = 0; var totalprice_usd = 0; var totalprice_cny = 0;
var totalMargin = 0; var totalCoef = 0;
$("input.invoice_check:checked").each(function(i, ele) { var row = $(ele).closest("tr.sublevel"); var totalcostField = row.find(".rowcost_td").text(); var totalfcostField = row.find(".rowfcost_td").text(); var totalprice_usdField = row.find(".rowprice_usd_td").text(); var totalprice_cnyField = row.find(".rowprice_cny_td").text();
//console.log(totalcostField, totalfcostField, totalprice_usdField, totalprice_cnyField);
totalcost += parseFloat(totalcostField.replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0; totalfcost += parseFloat(totalfcostField.replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0; totalprice_usd += parseFloat(totalprice_usdField.replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0; totalprice_cny += parseFloat(totalprice_cnyField.replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
//console.log(totalcostField, totalfcostField, totalprice_usdField, totalprice_cnyField); });
totalMargin = calcMargin(totalprice_usd, totalcost); totalCoef = calcCoef(totalprice_usd, totalcost);
// Update the JSON object with the totals. var totalData = { totalcost: totalcost.toFixed(2), totalfcost: totalfcost.toFixed(2), totalprice_usd: totalprice_usd.toFixed(2), totalMargin: totalMargin.toFixed(2) + '%', totalCoef: totalCoef.toFixed(2) };
$("td.totalcost_td").text(formatNumberWithCommas(totalcost.toFixed(2))); $("td.totalfcost_td").text(formatNumberWithCommas(totalfcost.toFixed(2))); $("td.totalprice_usd_td").text(formatNumberWithCommas(totalprice_usd.toFixed(2))); $("td.totalprice_cny_td").text(formatNumberWithCommas(totalprice_cny.toFixed(2))); $("td.totalmargin_td").text(totalMargin.toFixed(2) + '%'); var totalMarginValue = totalMargin.toFixed(2); $("td.totalcoef_td").text(totalCoef.toFixed(2));
return totalData; // Return the JSON object of the totals.
}
}); </script> <style> .c1_bg { display: flex; height: 100%; margin-right: 20px; }
.c1_bg_Content { position: relative; top: 0; }
/* Style pour la div qui englobe le tableau et permet le défilement */ .scrollable-table { max-height: 500px; overflow-y: scroll; }
.scrollable-tableOutStanding { max-height: 805px; overflow-y: scroll; display: block; margin-right: 20px;
}
/* Style pour le tableau */ .scrollable-table table { width: 100%; border-collapse: collapse; }
.scrollable-tableOutStanding table { width: 100%; border-collapse: collapse; }
/* Style pour l'en-tête du tableau */ .scrollable-table thead { background-color: #f0f0f0; /* Couleur de fond de l'en-tête, personnalisez-la selon vos préférences */ }
.scrollable-tableOutStanding thead { background-color: #f0f0f0; /* Couleur de fond de l'en-tête, personnalisez-la selon vos préférences */ }
/* Style pour les cellules de l'en-tête */ .scrollable-table th { position: sticky; top: 0; background-color: #f0f0f0; /* Couleur de fond de l'en-tête, assortie à celle de thead */ z-index: 2; /* Pour s'assurer que l'en-tête reste au-dessus du contenu lors du défilement */ }
.scrollable-tableOutStanding th { position: sticky; top: 0; background-color: #f0f0f0; /* Couleur de fond de l'en-tête, assortie à celle de thead */ z-index: 2; /* Pour s'assurer que l'en-tête reste au-dessus du contenu lors du défilement */ }
.scrollable-tableOutStanding tfoot { position: sticky; bottom: 0; background-color: #f0f0f0; /* Couleur de fond de l'en-tête, assortie à celle de thead */ z-index: 2; /* Pour s'assurer que l'en-tête reste au-dessus du contenu lors du défilement */ }
/* Style pour les cellules du corps du tableau */ .scrollable-table td { /* Vos styles de cellules ici */ }
/* Style pour la partie fixe en haut de la page */ #fixed-section {
position: sticky; top: 0; z-index: 3; }
.custom-link { color: #333; /* Couleur du texte du lien, par exemple, gris foncé (#333) */ text-decoration: none; /* Supprime le soulignement du lien */ font-weight: bold; /* Met en gras le texte du lien (facultatif) */ text-decoration: underline; }
.alignInvoiceTabs { display: flex; justify-content: center; }
.td-align-right { text-align: right; }
.td-align-right-bold { text-align: right; font-weight: bold; } </style>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" class="top"><?php require "mod_webhead.php"; ?></td> </tr> <tr> <td>
<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="200" valign="top" class="menu_bg"><?php require "mod_menu.php"; ?></td> <td valign="top" class="padding1">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<?php if (in_array($_SESSION['user'], array('jmcenza', 'Linda', 'Patrick', 'Pascal', 'ITDept'))) { ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <!-- c'est elle la colonne principale --> <td valign="top" class="padding1">
<table width="100%" border="0" cellpadding="0" cellspacing="0"> <!-- c'est elle la table 1 -->
<td class="c1_bg"> <div class="c1_bg_Content"> <form action="<?= realbasename($_SERVER['REQUEST_URI']) ?>" method="post"> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="search"> <tr> <td width="120" valign="top"><?= BALANCE ?>:<br /> <span class="stext1"><?= CONCOLIDATED ?> <?= BALANCE ?>:</span> </td> <td valign="top">
<table> <?php /* <!-- <tr> <td class=" stext2"><?= INVOICE ?>/<?= CREDIT_NOTE ?> </td> <td class="stext2" colspan="2"> <select name="data_type" id="data_type"> <option value="Invoice" <?= isset($_REQUEST['data_type']) && $_REQUEST['data_type'] === 'Invoice' ? 'selected' : '' ?>><?= INVOICE ?></option> <option value="CreditNote" <?= isset($_REQUEST['data_type']) && $_REQUEST['data_type'] === 'CreditNote' ? 'selected' : '' ?>><?= CREDIT_NOTE ?></option> </select>
</td> </tr> --> <!-- <td class="stext2"><?= CUSTOMER ?></td> <td class="stext2" colspan="2"> <select name="customer"> <option value=""></option> <?= customer_option($_REQUEST['customer'], true) ?> </select> </td> <td class="stext2"><?= CURRENCY ?></td> <td class="stext2"> <select name="uom_cy"> <option value=""></option> <?= master_option("UOM_CY", $_REQUEST['uom_cy'], true) ?> </select> </td> </tr> <tr> <td class="stext2"><?= VENDOR ?></td> <td class="stext2" colspan="2"> <select name="vendor"> <option value=""></option> <?= vendor_option($_REQUEST['vendor'], true) ?> </select> </td> <td> </td> <td> </td> </tr> <tr> <td class="stext2"><?= STATUS ?></td> <td class="stext2" colspan="2"> <select name="status"> <option value=""></option> <?= master_option("INVOICE_STATUS", $_REQUEST['status'], true) ?> </select> </td> <td> </td> <td> </td> </tr> --> */ ?> <tr> <td class="stext2"><?= LAUNCH_DATE ?></td> <td class="stext2"><input type="text" name="launchdate_start" id="launchdate_start" value="<?= $_REQUEST['launchdate_start'] ?>" class="shortfield" /> </td> <td class="stext2"><input type="text" name="launchdate_end" id="launchdate_end" value="<?= $_REQUEST['launchdate_end'] ?>" class="shortfield" /> </td> <td> </td> <td> </td> </tr> <tr> <td class="stext2"><?= DUE ?><?= WS ?><?= DATE ?></td> <td class="stext2"><input type="text" name="deliverydate_start" id="deliverydate_start" value="<?= $_REQUEST['deliverydate_start'] ?>" class="shortfield" /> </td> <td class="stext2"><input type="text" name="deliverydate_end" id="deliverydate_end" value="<?= $_REQUEST['deliverydate_end'] ?>" class="shortfield" /> </td>
</tr> <? /*<tr> <!-- <td class="stext2"><?= FINISHED ?></td> <td class="stext2" colspan="2"><input type="checkbox" name="finished" <?= empty($_REQUEST['finished']) ? '' : 'checked="checked"' ?> /> </td> --> <td> </td> <td> </td> </tr>*/ ?> </table> </td> <td align="right" valign="top"> <input type="image" src="image/btn_search.jpg" width="64" height="20" /> <!-- <a href="<?= basename($_SERVER['PHP_SELF']) ?>" title="<?= CLEAR ?>"><img src="image/icon_close.jpg" width="20" height="20" align="top" alt="<?= CLEAR ?>"/></a> --> <br /><br /> <!-- <span class="mod_menu"><a href="#" id="exportToExcel" class="uibutton"><?= EXPORT ?> <?= TO ?> <?= EXCEL ?></a></span> --> </td> </tr> </table> </form> </div>
</td> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="alignInvoiceTabs"> <!-- Tableau pour afficher les factures échues --> <!-- <tr>--> <!-- <td class="c1_bg">--> <!-- <div class="c1_bg_Content">--> <!-- <h2 style="color:white">Overdue invoices</h2>--> <!-- <div class="scrollable-table"--> <!-- ">--> <!-- <table width=" 100%" border="0" cellpadding="0"--> <!-- cellspacing="0" class="tablelist">--> <!-- <thead>--> <!-- <tr>--> <!-- <th>Invoice Number</th>--> <!-- <th>Customer</th>--> <!-- <th>Customer name</th>--> <!-- <th>Amount</th>--> <!-- <th>Due Date</th>--> <!-- </tr>--> <!-- </thead>--> <!-- <tbody>--> <!-- --><?php // // Your SQL query to retrieve invoices here // $sql = "SELECT // ic.refid as invoice_refid, // ic.ivc_nbr as invoice_number, // ic.ivc_customer as customer, // mc.custname_en as customer_name, // ic.ttl_price as amount, // ic.due_date as due_date // FROM // dbo.ivc_cus ic // INNER JOIN // dbo.master_customer mc ON ic.ivc_customer = mc.custcode // WHERE // ic.due_date <= GETDATE() // AND ic.status <> 'finished' // AND ic.status <> 'paid' // AND ic.ivc_nbr IS NOT NULL // ORDER BY // ic.due_date DESC; // "; // $result = $dbh->prepare($sql); // $resultquerytest = $result->execute(); // // // Execute the query for outstanding invoices // pdo_showerror($result, $resultquerytest); // // while ($row = $result->fetch()) { // echo '<tr>'; // if ($row['invoice_number'] !== null) { ?> <!-- <td><a style="color:blue;"--> <!-- href="ivc_cus_modifyform.php?refid=--><?php //echo $row['invoice_refid']; ?><!--">--><?php //echo $row['invoice_number']; ?><!--</a>--> <!-- </td>--> <!-- Add here the link or additional information about the invoice if necessary --> <!-- --><?php // // } else { ?> <!-- <td><a style="color:blue;"--> <!-- href="ivc_cus_modifyform.php?refid=--><?php //echo $row['invoice_refid']; ?><!--">Invoice--> <!-- details</a></td>--> <!-- Add here the link or additional information about the invoice if necessary, even if there is no invoice number. --> <!-- --><?php // } // echo '<td>' . $row['customer'] . '</td>'; // echo '<td>' . $row['customer_name'] . '</td>'; // echo '<td>' . numfs($row['amount']) . '</td>'; // echo '<td>' . $row['due_date'] . '</td>'; // echo '</tr>'; // } // ?> <!-- </tbody>--> <!-- </table>--> <!-- </div>--> <!----> <!-- </div>--> <!-- </td>--> <!-- </tr>-->
<!-- c'est elle la table 2 -->
<?php $sql_clause = ''; $sql_param = array();
// if (!empty($_REQUEST['finished'])) { // $sql_clause .= 'finished = :finished '; // $sql_param[':finished'] = '1'; // } else { // $sql_clause .= '( finished <> :finished OR finished IS NULL )'; // $sql_param[':finished'] = '1'; // }
if (!empty($_REQUEST['status'])) { $sql_clause .= 'AND (status=:status) '; $sql_param[':status'] = $_REQUEST['status']; }
if (!empty($_REQUEST['customer'])) { $sql_clause .= 'AND (ivc_customer=:ivc_customer) '; $sql_param[':ivc_customer'] = $_REQUEST['customer']; }
// if (!empty($_REQUEST['vendor'])) { // $sql_clause .= 'AND (vendor=:vendor) '; // $sql_param[':vendor'] = $_REQUEST['vendor']; // }
if (!empty($_REQUEST['launchdate_start'])) { $sql_clause .= 'AND launch_date>=:launchdate_start '; $sql_param[':launchdate_start'] = $_REQUEST['launchdate_start']; }
if (!empty($_REQUEST['launchdate_end'])) { $sql_clause .= 'AND launch_date<=:launchdate_end '; $sql_param[':launchdate_end'] = $_REQUEST['launchdate_end']; }
if (!empty($_REQUEST['deliverydate_start'])) { $sql_clause .= 'AND due_date>=:due_date_start '; $sql_param[':due_date_start'] = $_REQUEST['deliverydate_start']; }
if (!empty($_REQUEST['deliverydate_end'])) { $sql_clause .= 'AND due_date<=:due_date_end '; $sql_param[':due_date_end'] = $_REQUEST['deliverydate_end']; }
if (!empty($_REQUEST['uom_cy'])) { $sql_clause .= " AND (ivc_cus.uom_cy = :uom_cy) "; $sql_param[':uom_cy'] = $_REQUEST['uom_cy']; }
if ($sql_clause) { //$sql_clause = substr($sql_clause, 3); //$sql_clause = preg_replace('/AND/', '', $sql_clause, 1); }
// Initialize arrays to store outstanding and overdue invoice amounts $outstandingInvoices = array(); $overdueInvoices = array(); ?>
<td> <h2>Global Outstanding Invoices</h2>
<?php
// SQL Query for Global Outstanding Invoices $sqlOutstandingInvoices = "SELECT mc.custcode, mc.custname_en, mc.refid, oi.total_invoice_price FROM dbo.master_customer mc LEFT JOIN ( SELECT ic.ivc_customer, SUM(COALESCE(ic.remaining_balance, ic.ttl_price)) AS total_invoice_price FROM dbo.ivc_cus ic WHERE ic.status <> 'finished' AND ic.status <> 'paid' $sql_clause GROUP BY ic.ivc_customer ) oi ON mc.custcode = oi.ivc_customer WHERE mc.custvendor = 'EZH'";
// Execute the query for outstanding invoices $resultOutstanding = $dbh->prepare($sqlOutstandingInvoices); $q_second_query = $resultOutstanding->execute($sql_param);
// print($sql_second_query);
pdo_showerror($resultOutstanding, $q_second_query);
while ($rowOutstanding = $resultOutstanding->fetch()) { $custcode = $rowOutstanding['custcode']; $custName_en = $rowOutstanding['custname_en']; $redifCustomer = $rowOutstanding['refid'];
$total_invoice_price = $rowOutstanding['total_invoice_price'];
// Store custName_en and outstanding invoice amount in the array $outstandingInvoices[$custcode] = array( 'custName_en' => $custName_en, 'total_invoice_price' => $total_invoice_price, 'redifCustomer' => $redifCustomer ); }
$totalOutstanding = 0; foreach ($outstandingInvoices as $custcode => $data) { $totalOutstanding += $data['total_invoice_price']; }
echo '<div class="table-container">'; // Start a container div for the first table echo '<table border="0" cellpadding="0" cellspacing="0" class="tablelist scrollable-tableOutStanding" style="width: auto;">'; echo '<thead>'; echo '<tr><th>Customer ID</th><th>Customer</th><th>Outstanding Invoice Amount</th></tr>'; echo '</thead>'; echo '<tbody>'; foreach ($outstandingInvoices as $custcode => $data) { echo '<tr>'; echo '<td>' . $custcode . '</td>'; echo '<td><a href="finances_individual_cus1.php?refid=' . $data['redifCustomer'] . '"class="custom-link">' . $data['custName_en'] . '</td>'; // Access custName_en from the data array echo '<td class="td-align-right">' . numfs($data['total_invoice_price']) . '</td>'; // Access total_invoice_price from the data array echo '</tr>'; } echo '</tbody>'; echo '<tfoot>'; echo '<tr><td colspan="2"><strong>Total</strong></td><td class="td-align-right-bold">' . numfs($totalOutstanding) . '</td></tr>'; echo '</tfoot>'; echo '</table>'; echo '</div>'; // Close the container div for the first table
?>
</td> <td>
<h2>Global Overdue Invoices</h2> <?php // SQL Query for Global Overdue Invoices $sqlOverdueInvoices = "SELECT mc.custcode, mc.custname_en, mc.refid, oi.total_invoice_price FROM dbo.master_customer mc LEFT JOIN ( SELECT ic.ivc_customer, SUM(COALESCE(ic.remaining_balance, ic.ttl_price)) AS total_invoice_price FROM dbo.ivc_cus ic WHERE ic.status <> 'finished' AND ic.status <> 'paid' $sql_clause AND ic.due_date <= GETDATE() GROUP BY ic.ivc_customer ) oi ON mc.custcode = oi.ivc_customer WHERE mc.custvendor = 'EZH'"; // Execute the query for overdue invoices $resultOverdue = $dbh->prepare($sqlOverdueInvoices); $resultOverdue->execute($sql_param);
while ($rowOverdue = $resultOverdue->fetch()) { $custcodeOverdue = $rowOverdue['custcode']; $custName_enOverdue = $rowOverdue['custname_en']; $total_invoice_priceOverdue = $rowOverdue['total_invoice_price']; $redifCustomer = $rowOverdue['refid']; // Store overdue invoice amount in the array $overdueInvoices[$custcodeOverdue] = array( 'custName_enOverdue' => $custName_enOverdue, 'total_invoice_priceOverdue' => $total_invoice_priceOverdue, 'redifCustomer' => $redifCustomer ); }
$totalOverdue = 0; foreach ($overdueInvoices as $custcode => $dataOverdue) { $totalOverdue += $dataOverdue['total_invoice_priceOverdue']; }
echo '<div class="table-container">'; // Start a container div for the second table echo '<table border="0" cellpadding="0" cellspacing="0" class="tablelist scrollable-tableOutStanding">'; echo '<thead>'; echo '<tr><th>Customer ID</th><th>Customer</th><th>Overdue Invoice Amount</th></tr>'; echo '</thead>'; echo '<tbody>'; foreach ($overdueInvoices as $custcode => $dataOverdue) { echo '<tr>'; echo '<td>' . $custcode . '</td>'; echo '<td><a href="finances_individual_cus1.php?refid=' . $dataOverdue['redifCustomer'] . '"class="custom-link">' . $dataOverdue['custName_enOverdue'] . '</td>'; // Access custName_en from the data array echo '<td class="td-align-right">' . numfs($dataOverdue['total_invoice_priceOverdue']) . '</td>'; // Access total_invoice_price from the data array echo '</tr>'; } echo '</tbody>'; echo '<tfoot>'; echo '<tr><td colspan="2"><strong>Total</strong></td><td class="td-align-right-bold">' . numfs($totalOverdue) . '</td></tr>'; echo '</tfoot>'; echo '</table>'; echo '</div>'; // Close the container div for the second table
?>
</td> </table>
</table>
</td> </tr>
</table>
<?php } ?>
</tr>
</table>
</td> </tr> </table> </td> </tr> </table> </body>
</html>
|