/var/www/enzatesting.onesolution.hk/ivc_cus_modifyformEUR.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
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
790
791
792
793
794
795
<?php 
$formid 
"Order";
require_once 
"inc/configure.php";
$refid = (int)setDefaultReqVar("refid"'');

if(
$refid){
    
$sql "SELECT * from ivc_cus WHERE refid = :refid";
    
$sth $dbh->prepare($sql);
    
$sth->execute(  array(':refid' => $refid) );
            
} else {
    
//vdump($_REQUEST);
    
myerror(INVALID.WS.REQUESET); 
    exit;
}
$row $sth->fetch();
$ivc $row;
//vdump($row, $row['status']);
$sth=null;

$customer getCustomerByCode($row['ivc_customer']);

if( empty(
$row) ){
    
myerror(INVALID.WS.REQUESET); 
    exit;    
}

$sql_param[':ivccus_refid_1'] = $refid;
$sql_param[':ivccus_refid_2'] = $refid;
$sql_param[':ivccus_refid_3'] = $refid;
                                    
if(
$row['ivc_customer']){
    
$sql_customer " (dbo.ord_main.custcode = ".$dbh->quote($row['ivc_customer']).") AND"    ;
    
$sql_customer_rm " (dbo.ord_main.custcode = ".$dbh->quote($row['ivc_customer']).") AND"    ;
    
$sql_customer_extra " (dbo.ord_main.custcode = ".$dbh->quote($row['ivc_customer']).") AND"    ;
}

//vdump($row);
if($row['status']=="INPROGRESS"){ //allow add product in this status
    
$sql_clause "
OR (
    
$sql_customer (
        (
            dbo.ord_txpako.status = 'PACKED'
            AND dbo.ord_txpako.direct_sales = 1
        )
        OR (
            dbo.ord_txpako.status = 'RECEIVED'
        )
    )
)"
;
    
    
$sql_clause_rm "
OR (
    
$sql_customer_rm (
        (
            dbo.ord_txpako_rm.status = 'PACKED'
            AND dbo.ord_txpako_rm.direct_sales = 1
        )
        OR (
            dbo.ord_txpako_rm.status = 'RECEIVED'
        )
    )
)"
;
    
    
$sql_clause_extra "
OR (
    
$sql_customer_extra (
        (
            dbo.ord_dtl_extra.pack_status = 'PACKED'
            AND dbo.ord_dtl_extra.direct_sales = 1
        )
        OR (
            dbo.ord_dtl_extra.pack_status = 'RECEIVED'
        )
    )
)"
;
}



//$sql_param[':ivccus_refid'] = $refid;
//$sql_param2[':ivccus_refid'] = $refid;

//vdump($sql_clause2);
?>
<!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><?=$system_var['COMPANY_NAME']?></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<?php require_once "inc/jsheader.php"?>

<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script>
$(document).ready(function() {

    //dialog for printing selection    
    $( "#dialog-print" ).dialog({
        width: 400,
        autoOpen: false,
        modal: true,     
        buttons: {
            '<?=CANCEL?>': function() {
              $( this ).dialog( "close" );
            },            
            '<?=PRINT_?>': function() {
              $("#print_form").submit();
            }
          }
    });
    $( "#print_trig" ).on("click", function() {
        $( "#dialog-print" ).dialog( "open" );
        return false;
    });
        
    $("table.jexpand").jExpand();

    $( "#launch_date" ).datepicker({
        dateFormat: "yy-mm-dd",
        defaultDate: "<?=date("Y-m-d")?>"
    });
                
    $( "#del_date" ).datepicker({
        dateFormat: "yy-mm-dd",
        defaultDate: "<?=datef($row['due_date'])?>"
    });
    
    $(".submitform").on("click", function(e) {
         $( "#tabs" ).tabs('select', 0);  //goto first tab
    });    
    
    $("select#vendor").on('change', function(){
        //reload customer option
        //alert($("select#vendor").val());
        $.get("ajax_master_customer_option.php",{
            formid: "<?=$formid?>",
            vendor: $("select#vendor").val(),
            format: "json"
        },
          function(data)
        {    
            //alert(data);
            //console.log($("select#ivc_customer"));
            $("select#ivc_customer").html(data);
            
        });        
    });
    
    $("select#vendor").change();
    
    $("select#ivc_customer").on('change', function(){
        //reset all items
        $("input.invoice_checkall").prop("checked", false);
        $("input.invoice_check").prop("checked", false);
        $("input.iv_check").prop("checked", false);
    });
    
    $("input.invoice_checkall").on('change', function(){
        //console.log('checkall');
        var c = this.checked;
        $("input.invoice_check").each(function(){
            $(this).prop("checked", c); //apply to all child
            $(this).change();
        });
    });
    
    $("input.invoice_check").on('change', function(){
        //console.log($(this));
        var refid = $(this).prop("name").replace(/[^0-9]+/g, '');  //get orderID in name
        var c = this.checked;
        $("input.invoice_check_"+refid).each(function(){
            $(this).prop("checked", c); //apply to all child
            $(this).change();
        });
    });    
    
    //init parent checkbox depends on child checkbox state 
    $("input.iv_check:checked").each(function(){
        var row = $(this).closest("tr.sublevel").prev();
        var found = false;
        //console.log( row );
        while( row.length ){//is not empty
            row = row.prev();
            if(row.hasClass("mainlevel")){
                found = true;
                //console.log( "found", row );    
                break;
            }
            //console.log( "trav", row );    
        }
        if( found ){
            //console.log( "find", row );
            row.find("input.invoice_check").prop("checked", true);
        }
    });    
    
    $("#print_form").on("submit", function(e){
        $( "#dialog-print" ).dialog( "close" );
    });
    $("input.iv_check").on("change", function(e){
        calculateTotal();
    });
    calculateTotal();
});    

function calculateTotal(){
    var totalcost=0;
    var totalfcost=0;
    var totalprice_usd=0;
    var totalprice_cny=0;
    var totalprice_eur=0;
    
    $("input.iv_check:checked").each(function(i, ele){
        var row = $(ele).closest("tr.sublevel");
        totalcost += parseFloat(row.find(".rowcost_td").html().replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
        totalfcost += parseFloat(row.find(".rowfcost_td").html().replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
        totalprice_usd += parseFloat(row.find(".rowprice_usd_td").html().replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
        totalprice_cny += parseFloat(row.find(".rowprice_cny_td").html().replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
        totalprice_eur += parseFloat(row.find(".rowprice_eur_td").html().replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
    });
    //console.log(totalcost.toFixed(2), totalfcost.toFixed(2), totalprice.toFixed(2));
    $("input.totalcost").val(totalcost.toFixed(2));    
    $("input.totalfcost").val(totalfcost.toFixed(2));    
    $("input#totalprice_usd").val(totalprice_usd.toFixed(2));
    $("input#totalprice_cny").val(totalprice_cny.toFixed(2));
    $("input#totalprice_eur").val(totalprice_eur.toFixed(2));        
}

function confirm_missing_tracking(){
    return confirm("<?=MISSING.WS.TRACKING.WS.NUMBER?>");    
}

function localbind(){}
</script>
<script src="js/jexpand/jExpand.js"></script>
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="ivc_cus_modify.php" name="myform" id="myform" method="post" enctype="multipart/form-data">
  <input type="hidden" name="action" value="ivc_cus_modifyform" />
  <input type="hidden" name="refid" value="<?=$refid?>" />
  <input type="hidden" name="last_status" value="<?=$row['status']?>" />
  <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 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="c3_bg"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                      <tr>

                        <td width="20" class="separator"><input type="image" src="image/icon_save.jpg" class="submitform" width="20" height="20" /></td>
                        <td width="20" class="separator"><a href="<?=basename($_SERVER['REQUEST_URI'])?>"><img src="image/icon_undo.jpg" width="20" height="20" /></a></td>

                        <!--<td width="20" class="separator"><img src="image/icon_redo.jpg" width="20" height="20" /></td>
                <td width="20" class="separator"><img src="image/icon_delete.jpg" width="20" height="20" /></td>--> 
                        <?php if(empty($row['tracking_nbr'])){
                            
$onprint 'onclick="return confirm_missing_tracking();"';    
                        }
?>
                        <td width="20" class="separator"><a href="javascript:;" id="print_trig" ><span class="ui-icon0 ui-icon-print" ><?=PRINT_?></span></a></td>
                        <!--<td width="20" class="separator"><a href="#" id="download_trig"><span class="ui-icon0 ui-icon-circle-triangle-s" ></span>
                          <?=FILES?>
                          </a></td>-->
                        <!--<td width="20" class="separator"><a href="dgn_drawing_print.php?refid=<?=$row['refid']?>" target="_new"><?=PRINT_?></a></td>-->
                        <td class="separator stext1"><?=CUSTOMER?><?=WS?><?=INVOICE?>
                          - <span>
                          <?=MODIFY?>
                          </span></td>
                        <td class="separator etext1"><?=$row['ivc_customer']?>
                          - <span>
                          <?=empty($row['ivc_nbr'])? generateCusivcTMP($row['refid']) : $row['ivc_nbr']?>
                          </span></td>
                        <td width="200" align="right" class="separator etext2"><?=LAST_MODIFY?>:
                          <?=lastUpdate($row)?></td>
                        <td width="80" align="right" class="separator etext2"><a href="ivc_cus_index.php?act=resume" onclick="return ConfirmSave('myform')" class="closebtn"><?=CLOSE?></a>
                        <input type="hidden" name="godest" id="godest" />
  <input type="hidden" name="formdest" value="ivc_cus_index.php?act=resume" /></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td valign="top" class="c2_bg"><!--main form--> 
                    
                    <!--editable-->
                    
                    <div id="tabs" class="ui-tabs">
                      <ul>
                        <li><a href="#tabs-2">
                          <?=GENERAL?>
                          </a></li>
                        <li><a href="#tabs-4">
                          <?=DETAIL?>
                          </a></li>
                      </ul>
                      <div id="scontent">
                        <div id="tabs-2">
                          <p>
                          <table>
                            <tr>
                              <td ><?=CUSTOMER?></td>
                              <td ><select name="ivc_customer" disabled="disabled">
                                  <option value=""></option>
                                  <?=customer_option($row['ivc_customer'], true)?>
                                </select></td>
                            </tr>
                            <tr>
                              <td ><?=VENDOR?></td>
                              <td ><select name="vendor" id="vendor"  disabled="disabled">
                                  <option value=""></option>
                                  <?=vendor_option($row['vendor'])?>
                                </select></td>
                            </tr>                            
                        <?php if( false && havePermission("DCr") && havePermission("DPr")) { ?>
                            <tr>
                                <td><?=MARKUP?></td>
                                <td><?=numfs($customer['markup'], 2)?></td>
                            </tr>
                        <?php ?>
                            <tr>
                              <td ><?=STATUS?></td>
                              <td ><select name="status">
                                  <?=master_option("INVOICE_STATUS"$row['status'], true)?>
                                </select></td>
                            </tr>      
                            
                            <?php if( empty($row['ivc_nbr']) ) {?>
                            <tr>
                              <td ><?=ISSUE?><?=WS?><?=INVOICE?><?=WS?><?=NUMBER?></td>
                              <td ><input type="checkbox" name="issue_ivcnbr"/></td>
                            </tr>                            
                            <?php ?>                            
                            
                            <tr>
                              <td ><?=LAUNCH_DATE?></td>
                              <td ><input type="text" name="launch_date" id="launch_date_d" value="<?=date("Y-m-d")?>" readonly="readonly" /></td>
                            </tr>
                            <tr>
                              <td ><?=DUE?><?=WS?><?=DATE?></td>
                              <td ><span id="sprytextfield1">
                                <input name="due_date" value="<?=datef($row['due_date'])?>" id="del_date" />
                              </span></td>
                            </tr>   
                            <tr>
                              <td ><?=TRACKING?><?=WS?><?=NUMBER?></td>
                              <td ><input name="tracking_nbr" value="<?=$row['tracking_nbr']?>" id="tracking_nbr" /></td>
                            </tr>
                            <tr>
                              <td ><?=CUSTOMER.WS.SPECIAL_MARKUP?></td>
                              <td ><input name="markup" value="<?=numf($row['markup'] ,2)?>" id="markup" class="positive" /></td>
                            </tr>                                                                                  
                          </table>
                          </p>
                        </div>


                        <div id="tabs-4">
                          <p><table width="100%" id="product_table" border="0" cellpadding="0" cellspacing="0" class="jexpand tablelist nocss floathead">
                  <tr>
                          <th><?=INVOICE?><input type="checkbox" name="invoice_checkall" class="invoice_checkall" /></th>
                        <th><?=ORDER?><?=WS?><?=NUMBER?></th>
                        <th><?=CUSTOMER?><?=WS?><?=NAME?></th>
                        <th><?=LAUNCH_DATE?></th>                        
                        <th><?=DELIVERY?><?=WS?><?=DATE?></th>
                        <th><?=CONFIRM?><?=WS?><?=DATE?></th>
                        <th><?=ORDER?><?=WS?><?=QTY?></th>
                        <th><?=QTY?><?=WS?><?=READY?></th>
                        
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <th><?=TOTAL?><?=WS?><?=ORDER?><?=WS?><?=COST?></th>
                        <th><?=TOTAL?><?=WS?><?=FACTORY?><?=WS?><?=COST?></th>
                        <?php //end of DC-------------------------------------------------?>
                        
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <th><?=TOTAL?><?=WS?><?=ORDER?><?=WS?><?=AMOUNT?> (<?=USD?>)</th>
                        <th class="cnycol"><?=TOTAL?><?=WS?><?=ORDER?><?=WS?><?=AMOUNT?> (<?=CNY?>)</th>
                        <th class="eurcol"><?=TOTAL?><?=WS?><?=ORDER?><?=WS?><?=AMOUNT?> (<?=EUR?>)</th>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <th><?=COEF?></th>
                        <?php //end of DC DP--------------------------------------------?>
<!--                        <th><?=CUSTOMER?><?=WS?><?=ORDER?><?=WS?><?=REFERENCE?></th>-->
                        <!--<th><?=STATUS?></th>-->
                    </tr>
                                                        
<?php
    
$sql 
"SELECT
    tmp_ord.main_refid AS refid,
    dbo.ord_main.custcode,
    dbo.ord_main.order_nbr,
    dbo.ord_main.custorder_ref,
    dbo.ord_main.launch_date,
    dbo.ord_main.del_date,
    dbo.ord_main.confirm_date,
    dbo.ord_main.remark,
    dbo.ord_main.ttl_qty,
    dbo.ord_main.uom_cy,
    dbo.master_customer.custname_en,
    dbo.master_customer.custname_sc,
    SUM (tmp_ord.qty_ready) AS qty_ready,
    SUM (tmp_ord.ttlcost) AS ttlcost,
    SUM (tmp_ord.ttlfactcost) AS ttlfactcost,
    SUM (tmp_ord.ttlprice) AS ttlprice
FROM
    (
        (
            SELECT
                dbo.ord_dtl.main_refid,
                dbo.ord_txpako.txqty AS qty_ready,
                dbo.ord_txpako.unitcost AS ttlcost,
                dbo.ord_txpako.unitfactcost AS ttlfactcost,
                (
                    dbo.ord_txpako.unitprice * isnull(dbo.ord_txpako.discount, 1)
                ) AS ttlprice
            FROM
                dbo.ord_txpako
            INNER JOIN dbo.ord_dtl ON dbo.ord_txpako.orddtl_refid = dbo.ord_dtl.refid
            INNER JOIN dbo.ord_main ON dbo.ord_dtl.main_refid = dbo.ord_main.refid
            WHERE
                dbo.ord_txpako.deleted=0 AND 
                ( dbo.ord_txpako.ivccus_refid = :ivccus_refid_1 
$sql_clause )
        )
        UNION ALL
            (
                SELECT
                    dbo.ord_dtl_extra.main_refid,
                    dbo.ord_dtl_extra.qty AS qty_ready,
                    0 AS ttlcost,
                    0 AS ttlfactcost,
                    (
                        dbo.ord_dtl_extra.unitprice * dbo.ord_dtl_extra.qty * dbo.ord_dtl_extra.discount
                    ) AS ttlprice
                FROM
                    dbo.ord_dtl_extra
                INNER JOIN dbo.ord_main ON dbo.ord_dtl_extra.main_refid = dbo.ord_main.refid
                WHERE
                    dbo.ord_dtl_extra.ivccus_refid = :ivccus_refid_2
                
$sql_clause_extra
            )
        UNION ALL
            (
                SELECT
                    dbo.ord_dtl_rm.main_refid,
                    dbo.ord_txpako_rm.txqty AS qty_ready,
                    qtyofprice * dbo.ord_txpako_rm.unitcost AS ttlcost,
                    qtyofprice * dbo.ord_txpako_rm.unitfactcost AS ttlfactcost,
                    (
                        qtyofprice * dbo.ord_txpako_rm.unitprice * isnull(dbo.ord_txpako_rm.discount, 1)
                    ) AS ttlprice
                FROM
                    dbo.ord_txpako_rm
                INNER JOIN dbo.ord_dtl_rm ON dbo.ord_txpako_rm.orddtlrm_refid = dbo.ord_dtl_rm.refid
                INNER JOIN dbo.ord_main ON dbo.ord_dtl_rm.main_refid = dbo.ord_main.refid
                WHERE
                    dbo.ord_txpako_rm.ivccus_refid = :ivccus_refid_3
                
$sql_clause_rm
            )
    ) AS tmp_ord
INNER JOIN dbo.ord_main ON tmp_ord.main_refid = dbo.ord_main.refid
INNER JOIN dbo.master_customer ON dbo.ord_main.custcode = dbo.master_customer.custcode
GROUP BY
    tmp_ord.main_refid,
    dbo.ord_main.custcode,
    dbo.ord_main.order_nbr,
    dbo.ord_main.custorder_ref,
    dbo.ord_main.launch_date,
    dbo.ord_main.del_date,
    dbo.ord_main.confirm_date,
    dbo.ord_main.remark,
    dbo.ord_main.ttl_qty,
    dbo.ord_main.uom_cy,
    dbo.master_customer.custname_en,
    dbo.master_customer.custname_sc
ORDER BY dbo.ord_main.order_nbr ASC    "
;
    
        
    
$sth $dbh->prepare($sql);
    
$q $sth->execute$sql_param );
//echo $sth->getSQL( $sql_param ) . HTML_EOL;
    
pdo_showerror($sth$q);
    
//exit;
/*
    $gttl_qty=0;
    $gttl_ordercost=0;
    $gttl_factorycost=0;
    $gttl_orderprice=0;            
*/            
    
while($row $sth->fetch()) {    
/*
        if($row['ttl_orderprice']>0){
            $row['margin']=($row['ttl_orderprice']-$row['ttl_ordercost'])*100/$row['ttl_orderprice'];
        }else{
            $row['margin']=0;
        }
*/
/*
        $gttl_qty += numf($row['ttl_qty']);
        $gttl_ordercost += numf($row['ttl_ordercost']);
        $gttl_factorycost += numf($row['ttl_factcost']);
        $gttl_orderprice += numf($row['ttl_orderprice']);    
*/        
        
$row['ttlprice_usd'] = USD_CNY::getUSDAmount($row['uom_cy'], $row['ttlprice']);
        
$row['ttlprice_cny'] = USD_CNY::getCNYAmount($row['uom_cy'], $row['ttlprice']);
        
$row['ttlprice_usd'] = USD_EUR::getUSDAmount($row['uom_cy'], $row['ttlprice']);
        
$row['ttlprice_eur'] = USD_EUR::getEURAmount($row['uom_cy'], $row['ttlprice']);
        
?>
                  <tr class="mainlevel">
                          <td class="tdalignmid"><input type="checkbox" name="invoice_group[<?=$row['refid']?>]" class="invoice_check" /><input type="hidden" name="invoice_group[<?=$row['refid']?>]" value="<?=$row['custcode']?>" class="custcode microfield" /></td>
                        <td class="code"><a href="javascript:;" class="jexpand_trigger xfont">+</a> <a href="ord_dtl_modifyform.php?refid=<?=$row['refid']?>#tabs-4" class="fbox" ><?=$row['order_nbr']?></a></td>
                        <td><?=$row['custname_'.SYS_LANG]?></td>
                        <td><?=datef($row['launch_date'])?></td>
                        <td><?=datef($row['del_date'])?></td>
                        <td><?=datef($row['confirm_date'])?></td>
                        <td align="right"><?=numf($row['ttl_qty'])?></td>
                        <td align="right"><?=numf($row['qty_ready'])?></td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td align="right"><?=numfs($row['ttlcost'])?></td>
                        <td align="right"><?=numfs($row['ttlfactcost'])?></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td align="right" style="color:#636"><b><?=numfs($row['ttlprice_usd'])?></b></td>
                        <td align="right" style="color:#636" class="cnycol"><b><?=numfs($row['ttlprice_cny'])?></b></td>
                        <td align="right" style="color:#636" class="eurcol"><b><?=numfs($row['ttlprice_eur'])?></b></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <td align="right"><?=numfscalcMarginNew($row['ttlprice_usd'], $row['ttlcost']) )?></td>
                        <?php //end of DC DP--------------------------------------------?>
<!--                        <td><?=$row['custorder_ref']?></td>-->
                        <!--<td>&nbsp;</td>-->

                  </tr>

                <tr class="sublevel tdevencolor" style="display: none;">
                          <td>&nbsp;</td>
                        <th>S/N</th>
                        <th><?=ITEMNO?></th>    
                        <th><?=WEIGHT?></th>
                        <th><?=METAL?><?=WS?><?=WEIGHT?></th>                        
                        <th><?=DIAMOND?><?=WS?><?=WEIGHT?></th>
                        <th><?=STONE?><?=WS?><?=WEIGHT?></th>
                        <th><?=QTY?></th>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <th><?=UNIT?><?=WS?><?=COST?></th>
                        <th><?=FACTORY?><?=WS?><?=COST?></th>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <th><?=PRICE?> (<?=USD?>)</th>
                        <th class="cnycol"><?=PRICE?> (<?=CNY?>)</th>
                        <th class="eurcol"><?=PRICE?> (<?=EUR?>)</th>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <th><?=COEF?></th>
                        <?php //end of DC DP-------------------------------------------?>
<!--                        <th>&nbsp;</th>-->
                        <!--<th>&nbsp;</th>-->
                  </tr>
                  
                <?php 
                    $sql2 
"SELECT DISTINCT
dbo.ord_txpako.*,
dbo.ord_dtl.itemno,
dbo.ord_dtl.product_refid,
dbo.ord_dtl.refid as orddtl_refid,
dbo.ord_main.custcode
FROM
dbo.ord_main
INNER JOIN dbo.ord_dtl ON dbo.ord_dtl.main_refid = dbo.ord_main.refid
INNER JOIN dbo.ord_txmain ON dbo.ord_txmain.orddtl_refid = dbo.ord_dtl.refid
INNER JOIN dbo.ord_txpako ON dbo.ord_txpako.txmain_refid = dbo.ord_txmain.refid
WHERE
(dbo.ord_txpako.deleted=0) AND
(dbo.ord_txpako.ivccus_refid = :ivccus_refid 
$sql_clause) AND
dbo.ord_main.refid = :refid"
;
                    
$sth2 $dbh->prepare($sql2);
                    
$q $sth2->execute( array(':refid' => $row['refid'], ':ivccus_refid' => $refid) );
                while( 
$row2 $sth2->fetch() ) {        
                    
$discount_price discountPrice($row2['unitprice'], $row2['discount']);
                    
$checked = ($row2['ivccus_refid']==$refid) ? 'checked="checked"' '';
                    
$row2['price_usd'] = USD_CNY::getUSDAmount($row['uom_cy'], $discount_price);
                    
$row2['price_cny'] = USD_CNY::getCNYAmount($row['uom_cy'], $discount_price);
                    
$row2['price_usd'] = USD_EUR::getUSDAmount($row['uom_cy'], $discount_price);
                    
$row2['price_eur'] = USD_EUR::getEURAmount($row['uom_cy'], $discount_price);
                    
$row2['highlight_class'] = (productIsFirstInvoice($row2['product_refid']))? "ui-state-error" "";
                
?>
                <tr class="<?=$row2['highlight_class']?> sublevel productrow tdevencolor" style="display: none;">
                        <td class="tdalignmid"><input type="hidden" name="custcode[<?=$row2['refid']?>]" value="<?=$row2['custcode']?>" class="custcode microfield" />
                        <input type="checkbox" name="invoice_check[<?=$row2['refid']?>]" class="invoice_check_<?=$row['refid']?> iv_check" <?=$checked?> <?=$onclick?> /></td>
                        
                        <td class="code"><?=generateSN($row2['refid'])?></a></td>
                        <td class="code"><?=ord_htmllink_jobcard($row2['orddtl_refid'], $row2['itemno'], 'class="ctip fbox" ctip="ajax_thumb_inv_product.php?itemno='.$row2['itemno'].'&formid='.$formid.'"')?></td>
                        <td align="right"><?=numf($row2['product_wt'])?>gr</td>                        
                        <td align="right"><?=numf($row2['metal_wt'])?>gr</td>
                        <td align="right"><?=numf($row2['dia_wt'])?><?=$row2['uom_stonewt']?></td>
                        <td align="right"><?=numf($row2['stone_wt'])?><?=$row2['uom_stonewt']?></td>                        
                        <td align="right"><?=numf($row2['txqty'])?></td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td align="right" class="rowcost_td"><?=numfs($row2['unitcost'])?></td>
                        <td align="right" class="rowfcost_td"><?=numfs($row2['unitfactcost'])?></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td align="right" style="color:#636"><b class="rowprice_usd_td"><?=numfs($row2['price_usd'])?></b></td>
                        <td align="right" style="color:#636" class="cnycol <?=$row2['highlight_class']?>"><b class="rowprice_cny_td"><?=numfs($row2['price_cny'])?></b></td>
                        <td align="right" style="color:#636" class="eurcol <?=$row2['highlight_class']?>"><b class="rowprice_eur_td"><?=numfs($row2['price_eur'])?></b></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <td align="right"><?=numfs(calcMarginNew($row2['price_usd'], $row2['unitcost']))?></td>
                        <?php //end of DC DP--------------------------------------------?>
                        <!--<td align="right"><?=$row2['status']?></td>-->
                  </tr>
                  <?php ?>  
                
                                  <?php 
                    $sql2 
"
SELECT
dbo.ord_dtl_rm.itemno,
dbo.ord_dtl_rm.itemnoid,
dbo.ord_dtl_rm.bomcategory,
dbo.ord_txpako_rm.*
FROM
dbo.ord_txpako_rm
INNER JOIN dbo.ord_dtl_rm ON dbo.ord_txpako_rm.orddtlrm_refid = dbo.ord_dtl_rm.refid
INNER JOIN dbo.ord_main ON dbo.ord_dtl_rm.main_refid = dbo.ord_main.refid
WHERE
(dbo.ord_txpako_rm.ivccus_refid = :ivccus_refid 
$sql_clause_rm) AND
main_refid = :refid
ORDER BY
dbo.ord_txpako_rm.refid ASC"
;
                    
$sth2 $dbh->prepare($sql2);
                    
$q $sth2->execute( array(':refid' => $row['refid'], ':ivccus_refid' => $refid) );
                    
//echo $sth2->getSQL( array(':refid' => $row['refid'], ':ivccus_refid' => $refid) );
                
while( $row2 $sth2->fetch() ) {
                        
$discount_price discountPrice($row2['unitprice'], $row2['discount']);
                        
$row2['qty'] = $row2['qtyofprice'];
                        
$table inv_getBomcategyTablename($row2['bomcategory']);
                        
$item getDB($table$row2['itemnoid']);
                        
$checked = ($row2['ivccus_refid']==$refid) ? 'checked="checked"' '';
                        
$row2['price_usd'] = USD_CNY::getUSDAmount($row2['uom_cy'], $discount_price);
                        
$row2['price_cny'] = USD_CNY::getCNYAmount($row2['uom_cy'], $discount_price);
                        
$row2['price_usd'] = USD_EUR::getUSDAmount($row2['uom_cy'], $discount_price);
                        
$row2['price_eur'] = USD_EUR::getEURAmount($row2['uom_cy'], $discount_price);
                
?>
                <tr class="sublevel productrow tdevencolor" style="display: none;">
                        <td class="tdalignmid"><input type="hidden" name="custcode[<?=$row2['refid']?>]" value="<?=$row2['custcode']?>" class="custcode microfield" />
                        <input type="checkbox" name="material_check[<?=$row2['refid']?>]" class="invoice_check_<?=$row['refid']?> iv_check" <?=$checked?> <?=$onclick?> /></td>
                        <td class="code"><?=generateRMSN($row2['refid'])?></a></td>
                        <td class="code"><?=ord_htmllink_jobcard($row2['orddtl_refid'], $row2['itemno'], 'class="ctip fbox" ctip="ajax_thumb_inv_product.php?itemno='.$row2['itemno'].'&formid='.$formid.'"')?></td>
                        <td align="right"><?=numf($row2['rm_wt'])?> <?=$row2['uom_wt']?></td>                        
                        <td colspan="3"><?=$item['name_'.SYS_LANG]?></td>                        
                        <td align="right"><?=numf($row2['qty'])?></td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td align="right" class="rowcost_td"><?=numfs($row2['unitcost'])?></td>
                        <td align="right" class="rowfcost_td"><?=numfs($row2['unitfactcost'])?></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td align="right" style="color:#636"><b class="rowprice_usd_td"><?=numfs($row2['qty']*$row2['price_usd'])?></b></td>
                        <td align="right" style="color:#636" class="cnycol"><b class="rowprice_cny_td"><?=numfs($row2['qty']*$row2['price_cny'])?></b></td>
                        <td align="right" style="color:#636" class="eurcol"><b class="rowprice_eur_td"><?=numfs($row2['qty']*$row2['price_eur'])?></b></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <td align="right"><?=numfs(calcMarginNew($row2['price_usd'], $row2['unitcost']))?></td>
                        <?php //end of DC DP--------------------------------------------?>
                        <!--<td align="right"><?=$row2['status']?></td>-->
                  </tr>
                  <?php ?> 
                    
                  
                <?php 
                    $sql2 
"SELECT
dbo.ord_dtl_extra.*

FROM
dbo.ord_dtl_extra
INNER JOIN dbo.ord_main ON dbo.ord_dtl_extra.main_refid = dbo.ord_main.refid
WHERE
(dbo.ord_dtl_extra.ivccus_refid = :ivccus_refid 
$sql_clause_extra) AND
main_refid = :refid
ORDER BY
dbo.ord_dtl_extra.refid ASC"
;
                    
$sth2 $dbh->prepare($sql2);
                    
$q $sth2->execute( array(':refid' => $row['refid'], ':ivccus_refid' => $refid) );
                    
//echo $sth2->getSQL( array(':refid' => $row['refid'], ':ivccus_refid' => $refid) ).HTML_EOL;
                
while( $row2 $sth2->fetch() ) {
                        
$discount_price discountPrice($row2['unitprice'], $row2['discount']);
                        
$checked = ($row2['ivccus_refid']==$refid) ? 'checked="checked"' '';
                        
$row2['price_usd'] = USD_CNY::getUSDAmount($row['uom_cy'], $discount_price);
                        
$row2['price_cny'] = USD_CNY::getCNYAmount($row['uom_cy'], $discount_price);
                        
$row2['price_usd'] = USD_EUR::getUSDAmount($row['uom_cy'], $discount_price);
                        
$row2['price_eur'] = USD_EUR::getEURAmount($row['uom_cy'], $discount_price);
                
?>
                <tr class="sublevel extrarow tdevencolor" style="display: none;">
                        <td class="tdalignmid">
                        <input type="hidden" name="custcode[<?=$row2['refid']?>]" value="<?=$row2['custcode']?>" class="custcode microfield" />
                        <?php if($row2['status']=='RECEIVED') { ?>
                            <input type="hidden" name="extra_check[<?=$row2['refid']?>]" value="on" readonly="readonly" /><?=RECEIVED?>
                        <?php } else { ?> 
                            <input type="checkbox" name="extra_check[<?=$row2['refid']?>]" class="invoice_check_<?=$row['refid']?> iv_check" <?=$checked?> <?=$onclick?> />
                        <?php ?></td>
                        <td class="code"><?=generateExtraSN($row2['refid'])?></a></td>
                        <td class="code"><?=OTHER?></td>
                        <!--<td align="right"><?=numf($row2['product_wt'])?>gr</td>                        
                        <td align="right"><?=numf($row2['metal_wt'])?>gr</td>
                        <td align="right"><?=numf($row2['dia_wt'])?><?=$row2['uom_stonewt']?></td>
                        <td align="right"><?=numf($row2['stone_wt'])?><?=$row2['uom_stonewt']?></td>    -->  
                        <td>&nbsp;</td>
                        <td colspan="3"><?=$row2['desc']?></td>                    
                        <td align="right"><?=numf($row2['qty'])?></td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td align="right" class="rowcost_td"><?=numfs($row2['unitcost'])?></td>
                        <td align="right" class="rowfcost_td"><?=numfs($row2['unitfactcost'])?></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>                        
                        <td align="right" style="color:#636"><b class="rowprice_usd_td"><?=numfs($row2['price_usd'])?></b></td>
                        <td align="right" style="color:#636" class="cnycol"><b class="rowprice_cny_td"><?=numfs($row2['price_cny'])?></b></td>
                        <td align="right" style="color:#636" class="eurcol"><b class="rowprice_eur_td"><?=numfs($row2['price_eur'])?></b></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <td align="right"><?=numfs(calcMarginNew($row2['price_usd'], $row2['unitcost']))?></td>
                        <?php //end of DC DP--------------------------------------------?>
                        <!--<td align="right"><?=$row2['status']?></td>-->
                  </tr>
                  <?php ?>
                                 
<?php 
        
?>
      
                   <tfoot><tr>
                        <td class="tdbotborder"><?=TOTAL?></td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td class="tdbotborder tdalignright"><input type="text" id="totalcost" class="totalcost shortfield" readonly="readonly" /></td>
                        <td class="tdbotborder tdalignright"><input type="text" id="totalfcost" class="totalfcost shortfield" readonly="readonly" /></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td class="tdbotborder tdalignright"><input type="text" id="totalprice_usd" class="totalprice shortfield" readonly="readonly" /></td>
                        <td class="tdbotborder tdalignright cnycol"><input type="text" id="totalprice_cny" class="totalprice shortfield" readonly="readonly" /></td>
                        <td class="tdbotborder tdalignright eurcol"><input type="text" id="totalprice_eur" class="totalprice shortfield" readonly="readonly" /></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------?>
                        <td class="tdbotborder">&nbsp;</td>
                        <?php //end of DC DP----------------------------------------------?>
                        <!--<td class="tdbotborder">&nbsp;</td>-->
                  </tr></tfoot>  
                </table>                  
                        </p>
                        </div>

                      </div>
                      <!--end scontent-->
                      <input type="hidden" name="refid" value="<?=$refid?>" id="refid" />
                    </div>
                    
                    <!--end of readonly--> 
                    
                    <!-- end of mainform--></td>
                  <td valign="top"></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
  </table>
</form>
<!--print selection dialog-->
<div class="dialog-print" id="dialog-print" title="<?=PRINT_?>">
<p>
<form action="ivc_cus_printinvoice.php" id="print_form" method="get" target="_blank">
<select name="tid"><option value=""><?=DEFAULT_?></option><?=ivcrpt_template_option($row['ivcrpttemplate_refid'])?></select>
<input type="hidden" name="refid" value="<?=$refid?>" />
<!--<input type="submit" value="<?=PRINT_?><?=$onprint?> />-->
</p>
</form>
</div>
<?php //vdump($customer); markup?>
<script>
var ent = Number(<?=$i?>)+1;

var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
</script>
</body>
</html>