/var/www/enzatesting.onesolution.hk/01_20240711_full_backup/ord_poset_submitformEUR.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
<?php 
$formid 
"Order";
require_once 
"inc/configure.php";
require_once 
"inc/ord_po_func.php";
function 
getDB_rawmat($podtl_refid){
    global 
$dbh;
    
$sql "SELECT
            dbo.ivc_rawmat_dtl.*,
            dbo.ivc_rawmat_main.ivc_nbr
            
            FROM
            dbo.ivc_rawmat_dtl
            INNER JOIN dbo.ivc_rawmat_main ON dbo.ivc_rawmat_dtl.ivcrawmatmain_refid = dbo.ivc_rawmat_main.refid
            WHERE
            dbo.ivc_rawmat_dtl.ordpodtl_refid = :refid AND
            dbo.ivc_rawmat_main.status NOT IN ('FINISHED','COMP','CAN')
            ORDER BY
            dbo.ivc_rawmat_dtl.refid DESC"
;     
    
$sth $dbh->prepare($sql);
    
$q $sth->execute(  array(':refid' => $podtl_refid) );    
    
//echo $sth->getSQL( array(':refid' => $podtl_refid) );    
    
pdo_showerror($sth$q);
    
$row $sth->fetch(PDO::FETCH_ASSOC);
    return 
$row;    
}

$editable true;
$refid = (int)setDefaultReqVar("refid"'');

if( 
$refid && $row=getDB("ord_podtl" ,$refid) ){
    
$pomain getDB("ord_pomain"$row['pomain_refid']);
    
$supplier getDB("master_supplier"$pomain['supplier_refid']);
    
$supplier_price $row['unit_price'];
    
$supplier_uomcy $row['uom_cy'];    //vdump($supplier['code'],$system_var['COMPANY_FACTORY'],$system_var['COMPANY_OVERSEA']);
    
if($supplier['code']==$system_var['COMPANY_FACTORY'] || $supplier['code']==$system_var['COMPANY_OVERSEA']){
        
$isInternalOrder true;
        
//get the last internal invoice
        
if( $ivc_rawmat_dtl getDB_rawmat($row['refid']) ){
            
$supplier_price $ivc_rawmat_dtl['unit_price'];
            
$supplier_uomcy $ivc_rawmat_dtl['uom_cy'];        
            
//vdump($supplier_price, $supplier_uomcy);
        
}
        else{ 
//required an internal invoice
            //$editable = false; (uncomment this line to activate internal material ivc control)
        
}        
    }
    
    if(
abs($pomain['cy_cy2_rate'])>0.01){ //has valid exchange rate
        
if($pomain['uom_cy']=='CNY'){
            
$supplierUsdPrice $supplier_price*$pomain['cy_cy2_rate'];
            
$supplierCnyPrice $supplier_price;
        }else{
            
$supplierUsdPrice $supplier_price;
            
$supplierCnyPrice $supplier_price*$pomain['cy_cy2_rate'];
        }    
    }
    else{ 
//current exchange rate
        
if($supplier_uomcy=='CNY'){
            
$supplierUsdPrice USD_CNY::getUSDAmount('CNY'$supplier_price);
            
$supplierCnyPrice $supplier_price;    
        }else{
            
$supplierUsdPrice $supplier_price;
            
$supplierCnyPrice USD_CNY::getCNYAmount('USD'$supplier_price);
        }
    }
    
    if(
abs($pomain['cy_cy3_rate'])>0.01){ //has valid exchange rate
        
if($pomain['uom_cy']=='EUR'){
            
$supplierUsdPrice $supplier_price*$pomain['cy_cy3_rate'];
            
$supplierEurPrice $supplier_price;
        }else{
            
$supplierUsdPrice $supplier_price;
            
$supplierEurPrice $supplier_price*$pomain['cy_cy3_rate'];
        }    
    }
    else{ 
//current exchange rate
        
if($supplier_uomcy=='EUR'){
            
$supplierUsdPrice USD_EUR::getUSDAmount('EUR'$supplier_price);
            
$supplierEurPrice $supplier_price;    
        }else{
            
$supplierUsdPrice $supplier_price;
            
$supplierEURPrice USD_EUR::getEURAmount('USD'$supplier_price);
        }
    }
    
} else {
    
myerror("Invalid Request");
    exit;
}
//vdump($refid, $ivc_rawmat_dtl['refid']);

if( $row['status']=="FINISHED" ){
    
$editable false;
}
//vdump($row);
$sth=null;

$mat getDB_inv($row['bomcategy'], $row['itemnoid']);
//vdump($mat);
?>
<!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/SpryValidationTextField.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
    
    <?php //if(!$isInternalOrder){ ?>
    $('#input_wt').on("change blur", function(){
        if($('#input_qty').val()==''){
            var std_wt = parseFloat( "<?=numf($mat['weight'], 3)?>" );
            var input_wt = parseFloat( $('#input_wt').val() );
            var approx_qty = Math.round(input_wt / std_wt);
            $('#input_qty').val(approx_qty);
            //console.log(std_wt, input_wt, approx_qty);
        }
    });
    <?php //} ?>
    
    $('form#validateForm').submit(function(event) {      
        //console.log($('#input_wt').val(), $('#input_qty').val());
        var std_wt = parseFloat( "<?=numf($mat['weight'], 3)?>" );
        var input_wt = parseFloat( $('#input_wt').val() );
        var input_qty = parseFloat( $('#input_qty').val() );
        //console.log(input_wt, input_qty);
        var diff = (input_wt)/(input_qty*std_wt);
        //alert( diff );
        if( diff<parseFloat("<?=$system_var['STOCKTAKETORR_LOW']?>") || diff>parseFloat("<?=$system_var['STOCKTAKETORR_UPP']?>") ){
            var sbt = confirm("<?=ARE_YOU_SURE_YOU_WANT_TO_?><?=SUBMIT?>? ("+round2d(diff*100)+"%)");
            if(sbt==false){
                event.preventDefault();
            }
        }
        if(isNaN(input_wt) || isNaN(input_qty) ||input_wt<=0 || input_qty<=0){
            alert('<?=INVALID?><?=WS?><?=VALUE?>');
            event.preventDefault();
        }
    });

    
    $("#ivcrawmatdtl_refid").on("change, blur", function(e){
        //alert(1);
        var refid = parseInt($("#ivcrawmatdtl_refid").val());
        if(refid>0){
            $.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_json_poset_ivcrawmat.php",{  
                      formid: "<?=$formid?>",
                      action: "ord_poset_ivcrawmat",
                      ivcrawmatdtl_refid: refid
                  },
                  function(data){
                    data = JSON.parse(data);
                    //console.log(data);
                    $("#supplierivc_ref").val(data.ivc_nbr);
                    $("#input_qty").val(round2d(data.expected_qty));
                    $("#input_wt").val(round2d(data.expected_wt));
                    //check currecny
                    if(data.uom_cy=='USD'){
                        $("#input_price").val(round2d(data.unit_price)).change();
                    }else if(data.uom_cy=='CNY'){
                        $("#input_price2").val(round2d(data.unit_price)).change();
                    }
                    if(data.uom_cy=='USD'){
                        $("#input_price").val(round2d(data.unit_price)).change();
                    }else if(data.uom_cy=='EUR'){
                        $("#input_price3").val(round2d(data.unit_price)).change();
                    }else {
                        alert('<?=CURRENCY_MISMATCH?>');
                    }
                    
                    //fill by ajax ajax_json_poset_ivcrawmat.php
                    //supplierivc_ref, input_wt, input_qty, input_price
                });  
            $.unblockUI();
        }
        else{
            $("#supplierivc_ref").val('');
            $("#input_qty").val('');
            $("#input_wt").val('');
            $("#input_price").val('<?=numf($supplierUsdPrice)?>');
            $("#input_price2").val('<?=numf($supplierCnyPrice)?>');
            $("#input_price3").val('<?=numf($supplierEurPrice)?>');            
        }
        
        
    });
    
    $( "#input_price" ).on("change", function(){
        altPrice = $(this).val() * getPoCurrencyRateFrom();
        $("#input_price2").val(altPrice.toFixed(2));
    });
    $( "#input_price2" ).on("change", function(){
        altPrice = $(this).val() * 1.0/getPoCurrencyRateFrom();
        $("#input_price").val(altPrice.toFixed(2));
    });    
    $( "#input_price3" ).on("change", function(){
        altPrice = $(this).val() * 1.0/getPoCurrencyRateFrom();
        $("#input_price").val(altPrice.toFixed(2));
    });    
    
});

/*
* use currecny rate in PO header for conversion
*/
function getPoCurrencyRateFrom(){
    var rate = parseFloat('<?=numf($pomain['cy_cy2_rate'], 4)?>');
    var rate = parseFloat('<?=numf($pomain['cy_cy3_rate'], 4)?>');
    if(Math.abs(rate)>0.01){
        return rate;
    }
    else{
        return getCurrencyRateFrom('USD');
    }
}

function localbind(){

}


</script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php 
if($editable){ 
    
$formdest "ord_poset_submit.php";
}
?>
<form action="<?=$formdest?>" name="myform" id="validateForm" method="post" enctype="multipart/form-data">
  <input type="hidden" name="action" value="ord_poset_submit" />
  <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>
                  <td class="c3_bg"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <?php if($editable){ ?>
                        <td width="20" class="separator"><input type="image" src="image/icon_save.jpg" width="20" height="20" class="pressnhide2" /></td>
                        <?php ?>
                        <td width="20" class="separator"><a href="<?=basename($_SERVER['REQUEST_URI'])?>"><img src="image/icon_undo.jpg" width="20" height="20" /></a></td>

                        <td class="separator stext1"><?=PURCHASE_ORDER?>
                          - <span>
                          <?=CONFIRM?>
                          </span></td>
                        <td class="separator etext1"><a href="inv_<?=$row['bomcategy']?>_modifyform.php?refid=<?=$mat['refid']?>" class="fbox"><?=$mat['itemno']?></a> - <span><?=$mat['name_'.SYS_LANG]?></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="#" onclick="fbox_close()" class="closebtn" ><?=CLOSE?></a>
  <input type="hidden" name="godest" id="godest" />
  <input type="hidden" name="formdest" value="sys_fbox_close.php" /></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>
                      </ul>
                      <div id="scontent">
                        <div id="tabs-2">
                          <p>
                          <table width="100%" border="0">
    <tr>
        <td width="60px"><?=DATE?>:</td>
        <td><?=date("Y-m-d")?></td>
        <td></td>
    </tr>
    <tr>
        <td width="60px"><?=ITEMNO?>:</td>
        <td><?=$mat['itemno']?></td>
        <td></td>
    </tr>
    <tr>
        <td width="60px"><?=NAME?>:</td>
        <td><?=$mat['name_'.SYS_LANG]?></td>
        <td></td>
    </tr> 
    
    <?php if($editable){ 
/*    if($mat['uom_inventory']==$ivc_rawmat_dtl['uom_qty']){
        $expected_qty = $ivc_rawmat_dtl['qty'];    
    }
    else{
        $expected_wt = $ivc_rawmat_dtl['qty'];    
    }*/
    
$master_supplier_item getMasterSupplierItem($pomain['buyer'], $pomain['supplier_refid'], $row['bomcategy'], $row['itemnoid']);
    
//vdump($master_supplier_item);
    
?>
    <tr>
        <td width="120px"><?=SUPPLIER.WS.INVOICE.WS.REFERENCE?>:</td>
        <td>
        <?php if($isInternalOrder){ ?>
            <select name="ivcrawmatdtl_refid" id="ivcrawmatdtl_refid"><option value=""></option><?=ivcrawmatdtl_option($row['refid'])?></select>
        <?php ?>
        <input type="text" name="supplierivc_ref" value="<?=$ivc_rawmat_main['ivc_nbr']?>" id="supplierivc_ref" /></td>
    </tr>  
    <tr>
        <td width="60px"><?=QTY?>:</td>
        <td><span id="sprytextfield1">
        <input type="text" name="actqty" value="<?=numf($expected_qty ,3)?>" id="input_qty" class="positive shortfield" min="0" /></span>
            <?=$mat['uom_inventory']?><input type="hidden" name="uom_qty" value="<?=$mat['uom_inventory']?>" /></td>
        <td></td>
    </tr> 
    <tr>
        <td width="60px"><?=WEIGHT?>:</td>
        <td><span id="sprytextfield2">
        <input type="text" name="wt" value="<?=numf($expected_wt ,3)?>" id="input_wt" class="positive shortfield" /></span>
            <?=evl($mat['uom_wt'],$mat['uom_inventory'])?><input type="hidden" name="uom_wt" value="<?=evl($mat['uom_wt'],$mat['uom_inventory'])?>" /></td>
    </tr>
    <tr>
        <td class="tdvaligntop" width="60px"><?=PRICE?>:</td>
        <td><span id="sprytextfield3">
        <input type="text" name="unit_price" value="<?=numf($supplierUsdPrice ,3)?>" id="input_price" class="positive shortfield" /></span><?=USD?>/<?=$row['uom_qty']?>&nbsp;&nbsp;
        <input type="text" name="unit_price2" value="<?=numf($supplierCnyPrice ,3)?>" id="input_price2" class="positive shortfield" /></span><?=CNY?>/<?=$row['uom_qty']?>
        <input type="text" name="unit_price3" value="<?=numf($supplierEurPrice ,3)?>" id="input_price2" class="positive shortfield" /></span><?=EUR?>/<?=$row['uom_qty']?>            
            <input type="hidden" name="uom_unitprice" value="<?=$mat['uom_price']?>" /><br />
        <?php if( $row['bomcategy']!='material'){ ?>
        
        <input type="checkbox" name="updateInvPrice" /><?=UPDATE.WS.$pomain['buyer'].WS.COST?> (<?=CURRENT.WS.COST?><?=numfs($mat[inv_costfieldname($pomain['buyer'])] ,2)?> <?=$mat['uom_cy']?>/<?=$mat['uom_price']?>)<br />
        <input type="checkbox" name="updateSupplierPrice" /><?=UPDATE.WS.SUPPLIER.WS.PRICE?> (<?=CURRENT.WS.PRICE?><?=numfs($master_supplier_item['price'] ,2)?> <?=$mat['uom_cy']?>/<?=$mat['uom_price']?>)
        <?php ?></td>
    </tr>    
   
    <tr>
        <td width="60px"><?=REMARKS?>:</td>
        <td><textarea name="remark" rows="3" cols="60"  ></textarea></td>
    </tr>          
    <?php ?>    
</table>
<!--                          </p>
                        </div>


                        <div id="tabs-4">
                            <p>-->
                         

<table width="100%" class="tablelist" border="0">
<tr>
<th class="title1"><?=DATE?></th>
<th class="title1" colspan="2"><?=QTY?></th>
<th class="title1" colspan="2"><?=WEIGHT?></th>
<th class="title1" colspan="2"><?=PRICE?> (<?=USD?>)</th>
<th class="title1" colspan="2"><?=PRICE?> (<?=CNY?>)</th>
<th class="title1" colspan="2"><?=PRICE?> (<?=EUR?>)</th>
<th class="title1"><?=SUPPLIER?><?=WS?><?=INVOICE?><?=WS?><?=REFERENCE?></th>
<th class="title1"><?=REMARKS?></th>
</tr>

<?php 
    $sql 
"SELECT
*
FROM
dbo.ord_poset
WHERE
dbo.ord_poset.podtl_refid = :refid"
;


    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':refid'=>$refid)  );
    
/*echo $sth->getSQL( array(':refid'=>$refid)  );*/
    
while( $settle $sth->fetch() ){
        
$ttl_qty += $settle['actqty'];
        
$ttl_wt += $settle['wt'];        
    
?>
    <tr>
    <td width="160px"><?=datef($settle['recdate'])?></td>
    <td width="100px" class="tdalignright"><?=numf($settle['actqty'])?></td>
    <td width="60px"><?=$settle['uom_qty']?></td>
    <td width="100px" class="tdalignright"><?=numf($settle['wt'])?></td>
    <td width="60px"><?=$settle['uom_wt']?></td>
    <td class="tdalignright"><?=numf($settle['unit_price'])?></td>
    <td >/<?=$settle['uom_unitprice']?></td>
    <td class="tdalignright"><?=numf($settle['unit_price']*$settle['cy_cy2_rate'])?></td>
    <td class="tdalignright"><?=numf($settle['unit_price']*$settle['cy_cy3_rate'])?></td>
    <td >/<?=$settle['uom_unitprice']?></td>
    <td><?=$settle['supplierivc_ref']?></td>
    <td><?=$settle['remark']?></td>
    </tr>
<?php ?>
    <tr class="xfont">
    <th width="160px"><?=TOTAL?></th>
    <th width="100px" class="tdalignright"><?=numf($ttl_qty)?></th>
    <th width="60px" class="tdalignleft"><?=$mat['uom_inventory']?></th>
    <th width="100px" class="tdalignright"><?=numf($ttl_wt)?></th>
    <th width="60px" class="tdalignleft"><?=$mat['uom_wt']?></th>
    <th class="tdalignright">&nbsp;</th>
    <th>&nbsp;</th>
    <th class="tdalignright">&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th class="tdalignright">&nbsp;</th>
    </tr>
</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>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "real", {validateOn:["blur", "change"], minValue:0.001});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "real", {validateOn:["blur", "change"], minValue:0.001});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "real", {validateOn:["blur", "change"], minValue:0});
</script>
</body>
</html>