/var/www/enzatesting.onesolution.hk/ivc_cus_index.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
<?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;
}
?>
<!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>
        $(document).ready(function() {
            $("#launchdate_start").datepicker({
                dateFormat: "yy-mm-dd",
                showOn: "both",
                /*        buttonImage: "images/calendar.gif",
                        buttonImageOnly: true,*/
                defaultDate: "<?= $_REQUEST['launchdate_start'?>"
            });

            $("#launchdate_end").datepicker({
                dateFormat: "yy-mm-dd",
                showOn: "both",
                /*        buttonImage: "images/calendar.gif",
                        buttonImageOnly: true,*/
                defaultDate: "<?= $_REQUEST['launchdate_end'?>"
            });

            $("#deliverydate_start").datepicker({
                dateFormat: "yy-mm-dd",
                showOn: "both",
                /*        buttonImage: "images/calendar.gif",
                        buttonImageOnly: true,*/
                defaultDate: "<?= $_REQUEST['deliverydate_start'?>"
            });

            $("#deliverydate_end").datepicker({
                dateFormat: "yy-mm-dd",
                showOn: "both",
                /*        buttonImage: "images/calendar.gif",
                        buttonImageOnly: true,*/
                defaultDate: "<?= $_REQUEST['deliverydate_end'?>"
            });

            function updateCustomerOptions() {
                // Get the selected status
                var status = $('select[name="status"]').val();

                // Make an AJAX request to get the updated customer options
                $.ajax({
                    url: 'ajax_cus_status.php', // The URL of your PHP script that calls customer_option_with_status
                    type: 'GET',
                    data: {
                        status: status
                    }, // Pass the selected status to your PHP script
                    success: function(data) {
                        // Add an empty option to the beginning of the response
                        data = '<option value=""></option>' + data;
                        // Replace the options in the customer select with the response from your PHP script
                        $('select[name="customer"]').html(data);
                    }
                });
            }

            updateCustomerOptions();


            // When the status select changes
            $('select[name="status"]').change(function() {
                updateCustomerOptions();
            });


        });
    </script>

</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></tr>
                                <tr>
                                    <td class="c1_bg">
                                        <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"><?= ORDER ?>:<br />
                                                        <span class="stext1"><?= CUSTOMER ?><?= WS ?><?= INVOICE ?>:</span>
                                                    </td>
                                                    <td valign="top">

                                                        <table>
                                                            <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"><?= STATUS ?></td>
                                                                <td class="stext2" colspan="2">
                                                                    <select name="status">
                                                                        <option value="2">All</option>
                                                                        <option value="1" selected>Active</option>
                                                                        <option value="0">Inactive</option>
                                                                    </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>&nbsp;</td>
                                                                <td>&nbsp;</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>&nbsp;</td>
                                                                <td>&nbsp;</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>&nbsp;</td>
                                                                <td>&nbsp;</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>
                                                                <td>&nbsp;</td>
                                                                <td>&nbsp;</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>&nbsp;</td>
                                                                <td>&nbsp;</td>
                                                            </tr>

                                                        </table>
                                                    </td>
                                                    <td align="right" valign="top"><input type="image" src="image/btn_search.jpg" width="64" height="20" />&nbsp; <a href="ivc_cus_addform.php"><img src="image/btn_new.jpg" width="52" height="20" /></a>&nbsp;<a href="<?= basename($_SERVER['PHP_SELF']) ?>" title="<?= CLEAR ?>"><img src="image/icon_close.jpg" width="20" height="20" align="top" alt="<?= CLEAR ?>" /></a><?php if (haveMenuPermission("Usr")) { ?> <br /><br />
                                                            <span class="mod_menu"><a href="cn_cus_index.php?act=resume" class="uibutton"><?= CUSTOMER WS CREDIT_NOTE ?></a></span><? ?>
                                                    </td>
                                                </tr>
                                                <!--              <tr>
                <td height="25" colspan="3" valign="bottom" class="stext2">        </td>
                </tr>-->
                                            </table>
                                        </form>
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top" class="c2_bg">
                                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td valign="top">
                                                    <table width="100%" id="product_table" border="0" cellpadding="0" cellspacing="0" class="tablelist floathead">
                                                        <thead>
                                                            <tr>
                                                                <th><?= ID ?></th>
                                                                <th><?= INVOICE ?><?= WS ?><?= NUMBER ?></th>
                                                                <th><?= VENDOR ?></th>
                                                                <th><?= CUSTOMER ?></th>
                                                                <th><?= LAUNCH_DATE ?></th>
                                                                <th><?= DUE ?><?= WS ?><?= DATE ?></th>
                                                                <th><?= INVOICE ?><?= WS ?><?= QTY ?></th>
                                                                <th><?= METAL ?><?= WS ?><?= WEIGHT ?></th>
                                                                <th><?= DIAMOND ?><?= WS ?><?= WEIGHT ?></th>
                                                                <th><?= STONE ?><?= WS ?><?= WEIGHT ?></th>
                                                                <th><?= PRODUCT ?><?= WS ?><?= WEIGHT ?></th>

                                                                <?php if (havePermission("DCr")) { //DC-------------------------------
                                                                
?>
                                                                    <th><?= TOTAL ?><?= WS ?><?= INVOICE ?><?= WS ?><?= COST ?></th>
                                                                    <th><?= TOTAL ?><?= WS ?><?= FACTORY ?><?= WS ?><?= COST ?></th>
                                                                <?php //end of DC-------------------------------------------------
                                                                
?>

                                                                <?php if (havePermission("DPr")) { //DR-------------------------------
                                                                
?>
                                                                    <?php if ($showUSD) { ?>
                                                                        <th><?= TOTAL ?><?= WS ?><?= ORDER ?><?= WS ?><?= AMOUNT ?> (<?= USD ?>)</th>
                                                                    <?php ?>
                                                                    <?php if ($showCNY) { ?>
                                                                        <th><?= TOTAL ?><?= WS ?><?= ORDER ?><?= WS ?><?= AMOUNT ?> (<?= CNY ?>)</th>
                                                                    <?php ?>


                                                                <?php //end of DP-------------------------------------------------
                                                                
?>

                                                                <?php if (havePermission("DCr") && havePermission("DPr")) { //DCDP-------------------------------
                                                                
?>
                                                                    <th><?= MARGIN ?></th>
                                                                    <th><?= COEF ?></th>
                                                                <?php //end of DCDP -------------------------------------------------
                                                                
?>
                                                                <th><?= STATUS ?></th>
                                                                <!--<th><?= SENT ?></th>
                        <th><?= RECEIVED ?></th>-->
                                                            </tr>
                                                        </thead>

                                                        <?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) { //remove first "AND"
                                                            //$sql_clause = substr($sql_clause, 3);    
                                                            //$sql_clause = preg_replace('/AND/', '', $sql_clause, 1);
                                                        
}

                                                        
$sql "SELECT
dbo.ivc_cus.*,
dbo.master_customer.companyname_en,
dbo.master_customer.companyname_sc,
dbo.master_customer.custname_en,
dbo.master_customer.custname_sc

FROM
dbo.ivc_cus
INNER JOIN dbo.master_customer ON dbo.master_customer.custcode = dbo.ivc_cus.ivc_customer
WHERE 
$sql_clause
--ORDER BY refid ASC
ORDER BY SUBSTRING(ivc_nbr,5,2)+SUBSTRING(ivc_nbr,2,2)+SUBSTRING(ivc_nbr,7,3) ASC"
;

                                                        
$sth $dbh->prepare($sql);
                                                        
$q $sth->execute($sql_param);
                                                        
//echo $sth->getSQL( $sql_param ) . HTML_EOL;
                                                        
pdo_showerror($sth$q);

                                                        while (
$row $sth->fetch()) {
                                                            
$ttl['ttl_cost'] += $row['ttl_cost'];
                                                            
$ttl['ttl_ftycost'] += $row['ttl_ftycost'];
                                                            
$ttl['ttl_price'] += $row['ttl_price'];
                                                            
$ttl['ttl_metalwt'] += $row['ttl_metalwt'];
                                                            
$ttl['ttl_diawt'] += $row['ttl_diawt'];
                                                            
$ttl['ttl_stonewt'] += $row['ttl_stonewt'];
                                                            
$ttl['ttl_productwt'] += $row['ttl_productwt'];
                                                            
$ttl['ttl_ivcqty'] += $row['ttl_ivcqty'];
                                                            
$usdPrice USD_CNY::getUSDAmount($row['uom_cy'], $row['ttl_price']);
                                                            
$cnyPrice USD_CNY::getCNYAmount($row['uom_cy'], $row['ttl_price']);
                                                            
$ttl['ttl_usd_price'] += $usdPrice;
                                                            
$ttl['ttl_cny_price'] += $cnyPrice?>
                                                            <tr>
                                                                <td><a href="ivc_cus_modifyform.php?refid=<?= $row['refid'?>"><?= generateCusivcTMP($row['refid']) ?></a></td>
                                                                <td><a href="ivc_cus_modifyform.php?refid=<?= $row['refid'?>"><?= $row['ivc_nbr'?></a></td>
                                                                <td><?= $row['vendor'?></td>
                                                                <td><?= $row['custname_' SYS_LANG?></td>
                                                                <td><?= datef($row['launch_date']) ?></td>
                                                                <td><?= datef($row['due_date']) ?></td>
                                                                <td class="tdalignright"><?= numf($row['ttl_ivcqty']) ?> pcs</td>
                                                                <td class="tdalignright"><?= numf($row['ttl_metalwt']) ?> gr</td>
                                                                <td class="tdalignright"><?= numf($row['ttl_diawt'], 3?> ct</td>
                                                                <td class="tdalignright"><?= numf($row['ttl_stonewt'], 3?> ct</td>
                                                                <td class="tdalignright"><?= numf($row['ttl_productwt']) ?> gr</td>

                                                                <?php if (havePermission("DCr")) { //DC-------------------------------
                                                                
?>
                                                                    <td class="tdalignright"><?= numfs($row['ttl_cost']) ?></td>
                                                                    <td class="tdalignright"><?= numfs($row['ttl_ftycost']) ?></td>
                                                                <?php //end of DC-------------------------------------------------
                                                                
?>

                                                                <?php if (havePermission("DPr")) { //DP-------------------------------
                                                                
?>
                                                                    <?php if ($showUSD) { ?>
                                                                        <td class="tdalignright"><?= numfs($usdPrice?></td>
                                                                    <?php ?>
                                                                    <?php if ($showCNY) { ?>
                                                                        <td class="tdalignright"><?= numfs($cnyPrice?></td>
                                                                    <?php ?>

                                                                <?php //end of DP-------------------------------------------------
                                                                
?>

                                                                <?php if (havePermission("DCr") && havePermission("DPr")) { //DCDP-------------------------------
                                                                
?>
                                                                    <td class="tdalignright"><?= numf(calcMargin($usdPrice$row['ttl_cost'])) ?>%</td>
                                                                    <td class="tdalignright"><?= numf(calcMarginNew($usdPrice$row['ttl_cost'])) ?></td>
                                                                <?php //end of DCDP-------------------------------------------------
                                                                
?>


                                                                <td class="tdalignmid"><?= resolveCode_master_type_code("INVOICE_STATUS"$row['status']) ?></td>
                                                                <!-- <td class="tdalignright">&nbsp;</td>
                        <td class="tdalignright">&nbsp;</td>-->
                                                            </tr>
                                                        <?php ?>
                                                        <tfoot>
                                                            <tr>
                                                                <td><?= TOTAL ?></td>
                                                                <td>&nbsp;</td>
                                                                <td>&nbsp;</td>
                                                                <td>&nbsp;</td>
                                                                <td>&nbsp;</td>
                                                                <td>&nbsp;</td>
                                                                <td class="tdalignright"><?= numf($ttl['ttl_ivcqty']) ?></td>
                                                                <td class="tdalignright"><?= numfs($ttl['ttl_metalwt']) ?></td>
                                                                <td class="tdalignright"><?= numfs($ttl['ttl_diawt']) ?></td>
                                                                <td class="tdalignright"><?= numfs($ttl['ttl_stonewt']) ?></td>
                                                                <td class="tdalignright"><?= numfs($ttl['ttl_productwt']) ?></td>

                                                                <?php if (havePermission("DCr")) { //DC-------------------------------
                                                                
?>
                                                                    <td class="tdalignright"><?= numfs($ttl['ttl_cost']) ?></td>
                                                                    <td class="tdalignright"><?= numfs($ttl['ttl_ftycost']) ?></td>
                                                                <?php //end of DC-------------------------------------------------
                                                                
?>

                                                                <?php if (havePermission("DPr")) { //DP-------------------------------
                                                                
?>

                                                                    <?php if ($showUSD) { ?>
                                                                        <td class="tdalignright"><?= numfs($ttl['ttl_usd_price']) ?></td>
                                                                    <?php ?>
                                                                    <?php if ($showCNY) { ?>
                                                                        <td class="tdalignright"><?= numfs($ttl['ttl_cny_price']) ?></td>
                                                                    <?php ?>
                                                                <?php //end of DP-------------------------------------------------
                                                                
?>

                                                                <?php if (havePermission("DCr") && havePermission("DPr")) { //DCDP-------------------------------
                                                                
?>
                                                                    <td class="tdalignright"><?= numf(calcMargin($ttl['ttl_usd_price'], $ttl['ttl_cost'])) ?>%</td>
                                                                    <td class="tdalignright"><?= numf(calcMarginNew($ttl['ttl_usd_price'], $ttl['ttl_cost'])) ?></td>
                                                                <?php //end of DCDP-------------------------------------------------
                                                                
?>


                                                                <td>&nbsp;</td>
                                                                <!-- <td class="tdalignright">&nbsp;</td>
                        <td class="tdalignright">&nbsp;</td>-->
                                                            </tr>
                                                        </tfoot>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

</body>

</html>