/var/www/enzatesting.onesolution.hk/ord_po_addform.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
<?php 
$formid 
"Order";
require_once 
"inc/configure.php";
//vdump($permissionstr); 
if(
//havePermission("DCu")==false|| 
havePermission("RCu")==false){
//vdump($permissionstr); 
//exit;
    
myerror(INVALID.WS.PERMISSION);    
}

$refid = (int)setDefaultReqVar("refid"'');
$so_refid = (int)setDefaultReqVar("so_refid"'');

if(
$_REQUEST['layout']=='min'){
    
$showHeader false;
    
$showMenu false;
}else{
    
$showHeader true;
    
$showMenu true;    
}

//auto fill in information based on referred PO
if($so_refid){
    
$so getDB('ord_pomain'$so_refid);
    
$buyer getDB('master_supplier'$so['supplier_refid']);

    
$row['bomcategy'] = $so['bomcategy'];
    
$row['buyer'] = $buyer['code'];
    
$row['supplier_refid'] = $_REQUEST['supplier_refid'];
    
$row['remark'] = $_REQUEST['remark'];
    
    if(
$items=explode(','$_REQUEST['items'])){
        if(empty(
$row['supplier_refid'])){
            
//use the first item default supplier
            
$podtl getDB('ord_podtl', (int)$items['0']);
            
$row['supplier_refid'] = po_getdefaultsupplier($row['buyer'], $podtl['bomcategy'], $podtl['itemnoid']);
        }
        
//vdump($row['buyer'], $row['bomcategy'], $items);
        //vdump($items['0'], $row['supplier_refid']);
        
        
foreach($items as $k=>$i){
            
$items_q[$k] = $dbh->quote((int)$i);    
        }
        
$items_str implode(','$items_q);
        if(
$items_str){
            
$fetchPOitems true;    
        }
        else{
            
$fetchPOitems false;
        }
        
//vdump($items_str);
    
}
}

/*if($row['status']=="APPROVED"){
    $ui_width = "100%";    
}
else{*/
    //$ui_width = "1600px";    
    
$ui_width "100%";    
//}

?>
<!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 src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<script>

$(document).ready(function() {
    
    $( "#launch_date" ).datepicker({
        dateFormat: "yy-mm-dd",
        defaultDate: "<?=datef(date("Y-m-d"))?>"
    });
                
    $( "#del_date" ).datepicker({
        dateFormat: "yy-mm-dd",
        defaultDate: "<?=datef($row['del_date'])?>"
    });
    
    $( "#confirm_date" ).datepicker({
        dateFormat: "yy-mm-dd",
        defaultDate: "<?=datef($row['confirm_date'])?>"
    });
            
    $( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 340,
        width: 400,
        modal: true,
        buttons: {
            "<?=ADD?>": function() {
                var bValid = $('#new_enable').val();
                
                if($('#dialog_refid').val()==""){
                    bValid = false;
                }
    
                if ( bValid==1 ) {
                    
                    var formdata = parseform();
                    //console.log(formdata);
                    addmaterial( formdata  );

                    rebind();
                    $( this ).dialog( "close" );
                } else {
                }
            },
            "<?=CANCEL?>": function() {
                $( this ).dialog( "close" );
            }
        },
        close: function() {
            //clear dialog
            $("#dialog_refid").children().first().attr('selected', 'selected'); //pick first selection
            //empty form input
            $("#newprod_form :input").val('');
            $("#newprod_form span.uom").html(' ');
            $("#dialog_link").attr('href', 'error.php');

        }
    });
    
    $(".submitform").on("click", function(e) {
         $( "#tabs" ).tabs('select', 0);  //goto first tab
    });    
    
    $( "#add_material_button" ).click(function() {
        $( "#dialog-form" ).dialog( "open" );
    });
    
    $( "#dialog_refresh" ).click(function() {
        $( "#dialog_refid" ).change();
    });
    
    $( "#dialog_refid" ).change(function() {
        //console.log($("#dialog_bomcategy").val(), $("#dialog_refid").val())
        $.blockUI({  theme:     true,
                title:    'ENZA', 
                message:  '<p><?=LOADING?>...<br/><br/><span style="float:right;" ><input type="button" name="<?=CLOSE?>" value="<?=CLOSE?>" onclick="$.unblockUI();" /></span></p>', 
                baseZ: 2000     }); 

        //show item of detail 
        $.getJSON("ajax_json_material_detail.php",{
            formid: "<?=$formid?>",            
            supplier_refid: $("#supplier").val(),
            bomcategy: $("#dialog_bomcategy").val(),
            refid: $("#dialog_refid").val(),
            buyer: $("#buyer").val(),
            format: "json"
        },
          function(data)
        {
            //console.log(data);
            //alert(data.itemno);
            // copy data to dialog
            if(typeof(data.price) !== 'undefined' && data.price != null) {
                //alert('weight='+data.weight+''+data.uom_wt);
                $("#dialog_price").val(data.price);
            }
            else{
                $("#dialog_price").val('0.00');
            }
            
            if(typeof(data.weight) !== 'undefined' && data.weight != null) {
                //alert('weight='+data.weight+''+data.uom_wt);
                $("#dialog_stdweight").val(data.weight);
            }
            else{
                $("#dialog_stdweight").val('0.00');
            }            

            
            $("#dialog_name").val(data.itemname);
            $("#dialog_itemno").val(data.itemno);
            $("#dialog_desc").val(data.name_<?=SYS_LANG?>);
            $("#dialog_refid").val(data.refid);
            $("#dialog_bomcat").val(data.bomcategy);
            $("#dialog_href").val(data.href);
            
            $("#dialog_uom_cy").val(data.uom_cy);
            $("span.uom_cy").html(data.uom_cy);
            $("#dialog_uom_price").val(data.uom_price);
            $("span.dialog_uom_price").html(data.uom_price);
            //alert(data.uom_inventory);
            $("#dialog_uom_poqty").val(data.uom_inventory);
            $("span.dialog_uom_poqty").html(data.uom_inventory);
            
            $("#dialog_uom_cy").val(data.uom_cy);
            $("span.dialog_uom_cy").html(data.uom_cy);
            //$("#dialog_uom_qty").html(data.uom_price);
            $('#dialog_supplier_ref').val(data.supplier_ref);
            $('#new_enable').val(data.readyOrder);
            if(data.readyOrder != 1){ //disable add function          
  
              setTimeout( //wait unblockui
                function() 
                {
                  alert(data.msg_out);
                }, 500);
            }
            
            $.unblockUI();
        });
        
        $("#dialog_qty").change();
    });    

        
    $( "#dialog_refid" ).combobox();
    
    $( "#supplier" ).on("change", function() {
        var extra = $(this).find('option:selected').data('uom_cy');
        $("#uom_cy").val(extra);
    });
    
    $( "#dialog_bomcategy, #supplier" ).on("change", function() {
        //alert($('#supplier').val()+ $('#dialog_bomcategy').val());
        $.blockUI({  theme:     true,
                title:    'ENZA', 
                message:  '<p><?=LOADING?>...<br/><br/><span style="float:right;" ><input type="button" name="<?=CLOSE?>" value="<?=CLOSE?>" onclick="$.unblockUI();" /></span></p>', 
                baseZ: 2000     }); 
        
        $.get("ajax_inv_po_item_option.php",{  
                  formid: "<?=$formid?>",
                  buyer: $("#buyer").val(),
                  supplier_refid: $('#supplier').val(),
                  bomcategy: $('#dialog_bomcategy').val()
              },
              function(data){
                 // alert(data);
                 $('#dialog_refid').html(data);
                 
                 setTimeout( //wait combobox
                    function() 
                    {
                      $.unblockUI();
                      //alert(1);
                    }, 500); 
                  clearMaterialDetails();
        });  
        //$.unblockUI();
    });    
    $( "#dialog_bomcategy" ).change();
    
    $("#dialog_poqty").on("change blur", function(){
        //alert(2);
        
        if( $("#dialog_qty").val().length=0 || $("#dialog_qty").val()==0 ){
            var std_wt = parseFloat($("#dialog_stdweight").val());
            var qty = parseFloat($("#dialog_poqty").val());
            var weight = std_wt * qty;
            $("#dialog_qty").val( weight.toFixed(2) );
            $("#dialog_qty").change();
        }
        
    });
    
    $("#dialog_price, #dialog_qty").on("change blur", function(){
        var price = parseFloat($("#dialog_price").val());
        var qty = parseFloat($("#dialog_qty").val());
        var amount = price * qty;
        $("#dialog_amount").val( amount.toFixed(2) );
        
    });
    
});    

function clearMaterialDetails(){
    //$('.ui-combobox-input').val('');
    //empty form input
    $("#newprod_form input").val('');
    $("#newprod_form span.uom").html(' ');
}


function updatePrices(){}

function approxQty(input, std){
    return;
    if(std>0){
        return input/std;
    }
    else{
        return '';    
    }
}

function CalcSubtotal()
{
    //var row = $(this).parents('tr');
    var row = $(this).parent().parent(); //tr>td>input
    var qty = parseFloat( row.find(".qty").val());

    var unitcost = parseFloat( row.find(".cost").val());
    var subtotal = round2d(qty*unitcost);
    row.find(".amount").val(subtotal.toFixed(2));

    CalculateGrandtotal();
}

function CalculateGrandtotal(){
    
    var gt=new Number(0);
 
    $( ".amount" ).each( function() {
        
        var num = new Number($(this).val());
        gt = gt + num;
    } );
    $("#totalamount").val(gt.toFixed(2));




function updateEntry(){}

function addmaterial(data){ //copy default row

    var material_table = $("#material_table >tbody >tr").length;
    //copy hidden row template
    var mt_row = $("#material_table tbody>tr:nth-child(2)")
                                                .clone(true)
                                                .show()
                                                .css({backgroundColor: '#ccc'});

    
    mt_row.find("a, input, textarea, span").each(function() {
        var n = $(this).attr("name");
        //alert(ent+' nam'+n);
        if(typeof(n) !== 'undefined'){
            $(this).attr({
                'name': function(_, name) { 
                    return name.replace(/\d+/,ent) 
                }          
            });
        }
        
        var n = $(this).attr("id");
        //alert(ent+' nam'+n);
        if(typeof(n) !== 'undefined'){
            $(this).attr({
                'id': function(_, id) { 
                    return id.replace(/\d+/,ent) 
                }          
            });
        }        
    });
    
    mt_row.find("select").each(function() {
        $(this).children().first().attr('selected', 'selected'); //pick first selection
        var n = $(this).attr("name");
        //alert(ent+' nam'+n);
        if(typeof(n) !== 'undefined'){
            $(this).attr({
                'name': function(_, name) { 
                    return name.replace(/\d+/,ent) 
                }          
            });
        }
    });
    $('#material_table tr:last').after(mt_row);
//console.log(data);
    mt_row.find("a[name='material["+ent+"][href]']").prop('href', data.href);
    mt_row.find("a[name='material["+ent+"][href]']").html(data.itemno);
    
    mt_row.find("input[name='material["+ent+"][refid]']").val('new_'+ent);
    mt_row.find("input[name='material["+ent+"][bomcategy]']").val(data.bomcat);
    mt_row.find("input[name='material["+ent+"][itemnoid]']").val(data.refid);
    mt_row.find("input[name='material["+ent+"][supplier_ref]']").val(data.supplier_ref);
    mt_row.find("a[name='material["+ent+"][desc]']").html(data.desc);
    mt_row.find("input[name='material["+ent+"][poqty]']").val(data.poqty);
    mt_row.find("input[name='material["+ent+"][qty]']").val(data.qty);
    mt_row.find("input[name='material["+ent+"][unit_price]']").val(data.unit_price);
    mt_row.find("input[name='material["+ent+"][uom_poqty]']").val(data.uom_poqty);
    mt_row.find("span[name='material["+ent+"][uom_poqty]']").html(data.uom_poqty);
    mt_row.find("input[name='material["+ent+"][uom_qty]']").val(data.uom_price);
    mt_row.find("span[name='material["+ent+"][uom_qty]']").html(data.uom_price);
    mt_row.find("input[name='material["+ent+"][uom_cy]']").val(data.uom_cy);
    mt_row.find("span[name='material["+ent+"][uom_cy]']").html(data.uom_cy);
    //console.log($("span[name='material["+ent+"][uom_qty]']"));
    
    mt_row.find("input[name='material["+ent+"][amount]']").val(data.amount);
    
    ent++;  //alert(ent);
}

function parseform(){

    formDataFirst = $("#newprod_form").toObject({mode: 'first'});
    //$('#testArea').html(JSON.stringify(formDataFirst, null, '\t'));
    //alert(formDataFirst);
    return formDataFirst;

}

function localbind(){
    //calculate prices
    $('.qty, .cost').unbind("change, blur");
    $('.qty, .cost').bind("change, blur", CalcSubtotal);

}

</script>
<style>
    .ui-autocomplete {
        max-height: 200px;
        overflow-y: auto;
        /* prevent horizontal scrollbar */
        overflow-x: hidden;
        /* add padding to account for vertical scrollbar */
        padding-right: 20px;
    }
    /* IE 6 doesn't support max-height
     * we use height instead, but this forces the menu to always be this tall
     */
    * html .ui-autocomplete {
        height: 200px;
    }
    </style>
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="ord_po_add.php" name="myform" id="myform" method="post" enctype="multipart/form-data">
  <input type="hidden" name="action" value="po_addform" />
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td valign="top" class="top" <?=($showHeader)?'':'style="display:none;"'?> ></td>
    </tr>
    <tr>
      <td><table width="<?=$ui_width?>" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td valign="top" class="menu_bg" <?=($showMenu)?'':'style="display:none;"'?> ><?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>
                        <?php if(($row['status']!="CANCEL" && $row['status']!="PIP") || $isadmin==true){
                            
$onCloseForm 'onclick="return ConfirmSave(\'myform\')"';?>
                        <td width="20" class="separator"><input type="image" src="image/icon_save.jpg" width="20" height="20" class="submitform pressnhide2" /></td>
                        <td width="20" class="separator"><a href="<?=basename($_SERVER['REQUEST_URI'])?>"><img src="image/icon_undo.jpg" width="20" height="20" /></a></td>
                        <?php ?>
                        <!--<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>--> 
                        <!--<td width="20" class="separator"><a href="#" 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="xls_ord_po.php?refid=<?=$row['refid']?>" target="_new"><?=PRINT_?></a></td>-->
                        <td class="separator stext1"><?=PO?>
                          - <span>
                          <?=ADD?>
                          </span></td>
                        <td class="separator etext1"><table border="0" width="600px">
                        <tr><td colspan="2" align="center"><?=$row['companyname_'.SYS_LANG]?> - <span> <?=$row['pono']?> </span></td></tr>
                        <tr><td align="center"><?=LAUNCH_DATE?><?=datef($row['launch_date'])?></td>
                            <td align="center"><?=DELIVERY?><?=WS?><?=DATE?><?=datef($row['del_date'])?></td>
                            <!--<td align="center"><?=CONFIRM?><?=WS?><?=DATE?><?=datef($row['confirm_date'])?></td>--></tr>
                        </table></td>
                        <td width="200" align="right" class="separator etext2"><?=LAST_MODIFY?>:
                          <?=lastUpdate($row)?></td>
                        <td width="80" align="right" class="separator etext2"><a href="ord_po_index.php?act=resume"  <?=$onCloseForm?> class="closebtn"><?=CLOSE?></a>
  <input type="hidden" name="godest" id="godest" />
  <input type="hidden" name="formdest" value="ord_po_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 ><?=SUPPLIER?></td>
                              <td >
                              <?php if(!empty($_REQUEST['supplier_refid'])) {
                                 
$supplier getDB('master_supplier'$row['supplier_refid']);
                                 
//show supplier name and hide selection
                                 
print $supplier['code'] .' - '.$supplier['companyname_'.SYS_LANG];
                                 
$supplier_select_style 'style="display:none"'
                              }
?>
                              
                              <span id="spryselect1">
                                <select name="supplier" id="supplier" <?=$supplier_select_style?> >
                                  <option value=""></option>
                                  <?=supplier_option($row['supplier_refid'], 'uom_cy')?>
                                </select>
                              </span></td>
                            </tr>
                            <tr>
                              <td ><?=BOMCATEGY?></td>
                              <td ><span id="spryselect3"><select name="bomcategy" id="dialog_bomcategy" /><option value=""></option><?=master_option("BOMCATEGY"$row['bomcategy'], true)?></select>
                              </span></td>
                            </tr>
                            <tr>
                              <td ><?=BUYER?></td>
                              <td ><span id="spryselect2">
                                <select name="buyer" id="buyer">
                                  <option value=""></option>
                                  <?=master_company_option(evl($row['buyer'], $_SESSION['defaultcompany']), true)?>
                                </select></span></td>
                            </tr>
                            <tr>
                              <td ><?=CURRENCY?></td>
                              <td ><input name="uom_cy" id="uom_cy" value="<?=$row['uom_cy']?>" readonly="readonly" /></td>
                            </tr>
                            <tr>
                              <td ><?=CUSTOMER?><?=WS?><?=ORDER?><?=WS?><?=REFERENCE?></td>
                              <td ><input name="poreference" value="<?=$row['poreference']?>" /></td>
                            </tr>                            
                            <tr>
                              <td ><?=LAUNCH_DATE?></td>
                              <td ><input name="launch_date" value="<?=date("Y-m-d")?>" readonly="readonly" /></td>
                            </tr>
                         

                            <tr>
                              <td ><?=PAYMETHOD?></td>
                              <td ><select name="paymethod" id="paymethod">
                                  <option value=""></option>
                                  <?=master_option("PAYMETHOD"$row['paymethod'], true)?>
                                </select></td>
                            </tr>
                            
                            <tr>
                              <td colspan="2">&nbsp;</td>
                            </tr>
                            <tr>
                              <td ><?=STATUS?></td>
                              <td><select name="status" id="status">
                                  <?=master_option("PO_STATUS""NEW"true)?>
                                </select></td>
                            </tr>
                            <tr>
                              <td ><?=DELIVERY?><?=WS?><?=DATE?></td>
                              <td ><input name="del_date" value="<?=datef($row['del_date'])?>" id="del_date" /></td>
                            </tr>
                            <!--<tr>
                              <td ><?=CONFIRM?><?=WS?><?=DATE?></td>
                              <td ><input name="confirm_date" id="confirm_date" value="<?=datef($row['confirm_date'])?>" /></td>
                            </tr> -->  
                            <tr>
                              <td ><?=REMARKS?></td>
                              <td ><textarea name="remark" cols="40" rows="5"><?=$row['remark']?></textarea></td>
                            </tr>
                            
                          </table>
                          </p>
                        </div>
             
                        <div id="tabs-4">
                          <p> 
                          <?php if($row['status']!="CANCEL" && $row['status']!="PIP"){?>
                          <a id="add_material_button" class="mod_menu uibutton">+<?=ADD?><?=WS?><?=MATERIAL?></a>
                          <?php ?>
                          <table width="100%" id="material_table" border="0" cellpadding="0" cellspacing="0" class="tablelist">
                            <tr>
                              <th><?=ITEMNO?></th>
                              <th><?=NAME?></th>
                              <!--<th width="150px"><?=DESC?></th>-->
                              <th><?=ORDER.WS.QTY?></th>
                              <th><?=SUPPLIER.WS.QTY?></th>
                              <!--<th><?=WEIGHT?></th>-->

<?php if(havePermission("DCr")){ //DP-------------------------------?>
                              <th><?=PRICE?></th>
                              <th><?=AMOUNT?></th>
<?php //end of DP-------------------------------------------------?>

                             <th><?=SUPPLIER?><?=WS?><?=REFERENCE?></th>
   
                              <th><?=DELETE?></th>
                            </tr>
                            
                            <!-- material row template-->
                            <?php $i="0";?>
                            <tr style="display:none; backgroundColor:#ccc;">
                            <td class="code"><a href="error.php" class="fbox" name="material[<?=$i?>][href]" ><?=$material['itemno']?></a>
                                <input name="material[<?=$i?>][bomcategy]" value="<?=$row1['bomcategy']?>" type="hidden" />
                                <input name="material[<?=$i?>][itemnoid]" value="<?=$row1['itemnoid']?>" type="hidden" />
                                <input name="material[<?=$i?>][refid]" value="<?=$row1['refid']?>" type="hidden" class="refid" />
                                <input name="material[<?=$i?>][uom_cy]" value="<?=$row1['uom_cy']?>" type="hidden" />
                                <input name="material[<?=$i?>][uom_qty]" value="<?=$row1['uom_qty']?>" type="hidden" />
                                <input name="material[<?=$i?>][uom_poqty]" value="<?=$row1['uom_poqty']?>" type="hidden" /></td>
                              <!--<td><a name="material[<?=$i?>][itemname]" id="material[<?=$i?>][itemname]" ><?=$material['itemno']?></a></td>-->
                              <td><a name="material[<?=$i?>][desc]" id="material[<?=$i?>][desc]" ><?=$material['name_'.SYS_LANG]?></a></td>
                              <td><input type="text" name="material[<?=$i?>][poqty]" value="<?=numf($row1['poqty'])?>" class="minifield positive poqty" /><span name="material[<?=$i?>][uom_poqty]">&nbsp;</span></td>
                              
                              <td><input type="text" name="material[<?=$i?>][qty]" value="<?=numf($row1['qty'])?>" class="minifield positive qty" /><span name="material[<?=$i?>][uom_qty]">&nbsp;</span></td>
                              <!--<td><input type="text" name="material[<?=$i?>][remainqty]" value="<?=$row1['remainqty']?>" class="minifield positive" /></td>
                              <td><input type="text" name="material[<?=$i?>][weight]" value="<?=$row1['weight']?>" class="minifield" /></td>-->
                              
 <?php if(havePermission("DCr")){ //DC-------------------------------?>
                              <td><input type="text" name="material[<?=$i?>][unit_price]" value="<?=numf($row1['unit_price'])?>" class="minifield positive cost" /><!--<span name="material[<?=$i?>][uom_cy]">&nbsp;</span>-->/<span name="material[<?=$i?>][uom_qty]">&nbsp;</span></td>
                              <td><input type="text" name="material[<?=$i?>][amount]" value="<?=numf($row1['unit_price'] * $row1['qty'])?>" class="minifield positive amount"  readonly="readonly" /><!--<span name="material[<?=$i?>][uom_cy]">&nbsp;</span>--></td>
<?php //end of DC------------------------------------------------------?>

                              <td><input type="text" name="material[<?=$i?>][supplier_ref]" value="<?=$row1['supplier_ref']?>" /></td>
                              <td><a href="javascript:;" class="deleteRowButton uibutton"><?=X?></a></td>
                            </tr>
                            <?php
    $sql_clause
='';
    
    if(
$fetchPOitems) {
        
//auto create PO items based on referenced SO
        
$sql "SELECT 
                dbo.ord_podtl.*
                FROM
                dbo.ord_podtl
                WHERE refid in (
$items_str)";    
    
        
$sth $dbh->prepare($sql);
        
$q $sth->execute( );
    
//echo $sth->getSQL(  ) . HTML_EOL;
        
pdo_showerror($sth$q);        
    }    
                
    while(
$fetchPOitems && $row1 $sth->fetch()) {
        
$material getDB_inv($row1['bomcategy'], $row1['itemnoid']);
        
//try to get unitprice from the default supplier
        
$supplieritem po_getSupplierPriceAndRef($row['buyer'], $row['supplier_refid'], $row1['bomcategy'], $row1['itemnoid']);
        
//vdump($supplieritem);
        
if(empty($supplieritem)){ 
            
$itemnotfound['itemno'][] = $row1['itemnoid']; 
            
$itemnotfound['podtl_refid'][] = $row1['refid']; 
            continue;
        } 
//supplier item not found
        
$row1['unit_price'] = $supplieritem['price'];    
        
$row1['supplier_ref'] = $supplieritem['supplier_ref'];
        
$i++; ?>
                            <tr class="itemrow">
                              <td class="code"><a href="inv_<?=$row1['bomcategy']?>_modifyform.php?refid=<?=$row1['itemnoid']?>" class="fbox" ><?=$material['itemno']?></a>
                                <input name="material[<?=$i?>][bomcategy]" value="<?=$row1['bomcategy']?>" type="hidden" />
                                <input name="material[<?=$i?>][itemnoid]" value="<?=$row1['itemnoid']?>" type="hidden" />
                                <input name="material[<?=$i?>][refid]" value="<?=$row1['refid']?>" type="hidden" class="refid" />
                                <input name="material[<?=$i?>][uom_cy]" value="<?=$row1['uom_cy']?>" type="hidden" />
                                <input name="material[<?=$i?>][uom_qty]" value="<?=$row1['uom_qty']?>" type="hidden" />
                                <input name="material[<?=$i?>][uom_poqty]" value="<?=$row1['uom_poqty']?>" type="hidden" /></td>
                              <!--<td><a name="material[<?=$i?>][itemname]" id="material[<?=$i?>][itemname]" ><?=$material['itemno']?></a></td>-->
                              <td><a name="material[<?=$i?>][desc]" id="material[<?=$i?>][desc]" ><?=$material['name_'.SYS_LANG]?></a></td>
                              
                              <td><input type="text" name="material[<?=$i?>][poqty]" value="<?=numf($row1['poqty'])?>" class="minifield positive poqty" /><span name="material[<?=$i?>][uom_poqty]"><?=$row1['uom_poqty']?></span></td>
                              
                              <td><input type="text" name="material[<?=$i?>][qty]" value="<?=numf($row1['qty'])?>" class="minifield positive qty" /><span name="material[<?=$i?>][uom_qty]"><?=$row1['uom_qty']?></span></td>
                              <!--<td><input type="text" name="material[<?=$i?>][remainqty]" value="<?=$row1['remainqty']?>" class="minifield positive" /></td>
                              <td><input type="text" name="material[<?=$i?>][weight]" value="<?=$row1['weight']?>" class="minifield" /></td>-->
                              
 <?php if(havePermission("DCr")){ //DC-------------------------------?>
                              <td><input type="text" name="material[<?=$i?>][unit_price]" value="<?=numf($row1['unit_price'])?>" class="minifield positive cost"  />/<span name="material[<?=$i?>][uom_qty]"><?=$row1['uom_qty']?></span></td>
                              <td><input type="text" name="material[<?=$i?>][amount]" value="<?=numf($row1['unit_price'] * $row1['qty'])?>" class="minifield positive amount" readonly="readonly" /></td>
<?php //end of DC------------------------------------------------------?>

                              <td><input type="text" name="material[<?=$i?>][supplier_ref]" value="<?=$row1['supplier_ref']?>" /></td>
                              <td><a href="javascript:;" class="deleteRowButton uibutton"><?=X?></a></td>
                            </tr>
                            <?php ?>
                          </table>
                          
                         <?=TOTAL?>: <input type="number" id="totalamount" readonly="readonly" />
                          <div align="left">
                          </div>
                          </p>
                        </div>
                      
                        
                      </div>
                      <!--end scontent-->
                      <input type="hidden" name="last_status" value="<?=$row['status']?>" />
                      <input type="hidden" name="refid" value="<?=$refid?>" id="refid" />
                      <input type="hidden" name="edit" value="<?=$editable?>" id="edit" />
                    </div>
                    
                    <!--end of readonly--> 
                    
                    <!-- end of mainform--></td>
                  <td valign="top"></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
  </table>
</form>
<div id="dialog-form" title="<?=ADD?><?=WS?><?=MATERIAL?>">
  <form name="dialog-form" id="newprod_form">
    <table>
<!--      <tr>
        <td><?=CATEGORY?></td>
        <td id="dialog_categy_td"><select name="bomcategy" id="dialog_bomcategy0" />
          <option value=""></option><?=bomcategy_option()?></select></td>
      </tr>-->
      
          
      <tr>
        <td><?=ITEMNO?></td>
        <td id="dialog_itemno_td" class="white_smooth"><select name="refid" id="dialog_refid" class2="ui-widget-content ui-corner-all" style="width:150px" >
            <option value="">Loading...</option>
          </select></td>
      </tr>
          
      <tr>
        <td><?=ORDER.WS.QTY?></td>
        <td id="dialog_poqty_td"><input type="text" name="poqty" id="dialog_poqty" class="text ui-widget-content ui-corner-all"  style="width:60px" /><span name="dialog_uom_poqty" class="dialog_uom_poqty uom"></span>
          </select></td>
      </tr>      
      <tr>
        <td><?=SUPPLIER.WS.QTY?></td>
        <td id="dialog_qty_td"><input type="text" name="qty" id="dialog_qty" class="text ui-widget-content ui-corner-all positive" min="0"  style="width:60px" /><span name="dialog_uom_qty" class="dialog_uom_price uom"></span></td>
      </tr>
      
      <?php if(havePermission("DCr")){ //DP-------------------------------?>
      <tr>
        <td><?=PRICE?></td>
        <td id="dialog_price_td"><input type="text" name="unit_price" id="dialog_price" class="text ui-widget-content ui-corner-all positive" style="width:60px" /><input type="hidden" name="uom_cy" id="dialog_uom_cy" class="text ui-widget-content ui-corner-all uom_cy" style="width:30px" readonly="readonly" /><!--<span name="uom_cy" class="uom_cy uom"></span>-->/<span name="dialog_uom_price" class="dialog_uom_price uom"></span>
          </td>
      </tr>
      <?php //end of DP------------------------------------------------------?>  
            
      <tr>
        <td><?=AMOUNT?></td>
        <td id="dialog_amount_td"><input type="text" name="amount" id="dialog_amount" class="text ui-widget-content ui-corner-all positive"  style="width:60px" readonly="readonly" /><!--<span name="uom_cy" class="uom_cy uom"></span>--></td>
      </tr>      
      <tr>
        <td><?=SUPPLIER?><?=WS?><?=REFERENCE?></td>
        <td id="dialog_supplier_ref_td"><input type="text" name="supplier_ref" id="dialog_supplier_ref" class="text ui-widget-content ui-corner-all" /></td>
      </tr>


    </table>
        <!--<input type="text" name="name" id="dialog_name" class="text ui-widget-content ui-corner-all"  style="width:60px" />-->
          <input type="hidden" name="enable" id="new_enable" readonly="readonly" style="width:60px" />
          <input type="hidden" name="desc" id="dialog_desc" class="text ui-widget-content ui-corner-all"  style="width:60px" />
          <input type="hidden" name="itemno" id="dialog_itemno" class="text ui-widget-content ui-corner-all"  style="width:60px" />
          <input type="hidden" name="uom_price" id="dialog_uom_price" class="text ui-widget-content ui-corner-all uom_price uom"  style="width:60px" />
          <input type="hidden" name="uom_poqty" id="dialog_uom_poqty" class="text ui-widget-content ui-corner-all uom_poqty uom"  style="width:60px" />
          <input type="hidden" name="uom_cy" id="dialog_uom_cy" class="text ui-widget-content ui-corner-all uom_cy uom"  style="width:60px" />
          <input type="hidden" name="href" id="dialog_href" class="text ui-widget-content ui-corner-all"  style="width:60px" /> 
          <input type="hidden" name="stdweight" id="dialog_stdweight" class="text ui-widget-content ui-corner-all"  style="width:60px" />
          <input type="hidden" name="bomcat" id="dialog_bomcat" class="text ui-widget-content ui-corner-all"  style="width:60px" />
    <!--<a id="toggle" class="uibutton">UPDATE</a>-->
  </form>
</div>
<script>
var ent = Number(<?=$i?>)+1;
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2");
var spryselect3 = new Spry.Widget.ValidationSelect("spryselect3", {validateOn:["blur", "change"]});

$(document).ready(function() {
//show item not found warning and uncheckparent checkboxes
<?php if(!empty($itemnotfound['itemno'])){
    
//vdump($itemnotfound);
    
$table inv_getBomcategyTablename($row['bomcategy']);
    
$itemnos '';
    foreach(
$itemnotfound['itemno'] as $i){
        
$item getDB($table$i);
        
//vdump($item, $table, $i);
        
$itemnos .= $item['itemno'].', ';
    }
    
//$itemnos = substr($itemnos, 0, -2);
    
print "alert('".SUPPLIER.WS.ITEM.WS.NOT_FOUND.": ".substr($itemnos0, -2)."');";
    
    foreach(
$itemnotfound['podtl_refid'] as $podtlrefid){
?>
//uncheck invalid items in PO
parent.$(".newpoitem_refid[value=<?=$podtlrefid?>]").prop('checked', false);
    <?php ?>
<?php 
?>
});
</script>    
</body>
</html>