/var/www/enzatesting.onesolution.hk/ord_poset_submit.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
<?php 
$formid 
"Stone";
require_once 
"inc/configure.php";
require_once 
"inc/ord_po_func.php";

$refid             filter_var($_REQUEST['refid'], FILTER_SANITIZE_NUMBER_INT);
//vdump($_REQUEST); //exit;
if( $_POST['action']=="ord_poset_submit" && !empty($refid) ){

    
$dbh->beginTransaction();    
    
    
$actqty         = (float) filter_var($_REQUEST['actqty'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_qty        filter_var($_REQUEST['uom_qty'], FILTER_SANITIZE_STRING);
    
$wt             = (float) filter_var($_REQUEST['wt'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_wt            filter_var($_REQUEST['uom_wt'], FILTER_SANITIZE_STRING);
    
$unit_price        = (float)filter_var($_REQUEST['unit_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$unit_price2        = (float)filter_var($_REQUEST['unit_price2'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_cy            filter_var("USD"FILTER_SANITIZE_STRING);
    
$uom_unitprice    filter_var($_REQUEST['uom_unitprice'], FILTER_SANITIZE_STRING);
    
    
$supplierivc_reffilter_var($_REQUEST['supplierivc_ref'], FILTER_SANITIZE_STRING);
    
$ivcrawmatdtl_refidfilter_var($_REQUEST['ivcrawmatdtl_refid'], FILTER_SANITIZE_STRING); 
    
$remark            filter_var($_REQUEST['remark'], FILTER_SANITIZE_STRING);
    
$createby        filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$lastupby        filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$podtl getDB("ord_podtl"$refid);
    
$pomain getDB("ord_pomain"$podtl['pomain_refid']);
    
$material getDB_inv($podtl['bomcategy'], $podtl['itemnoid']);
    
//vdump($material['itemno']);
    //receiving
    
$sql "UPDATE ord_podtl SET
            status = :status,
            lastupby = :lastupby,
            lastupdate = GETDATE()
            WHERE refid = :refid"
;
                
    
$sth $dbh->prepare($sql);
    
$q $sth->execute( array(':status'=> 'RECEIVED',
                            
':lastupby'=> $lastupby,
                            
':refid'=> $refid) );    

    
//add record
    
$sql "INSERT into ord_poset (
                podtl_refid, recdate, supplierivc_ref,
                actqty, uom_qty, wt, uom_wt, remark,
                unit_price, uom_cy, uom_unitprice, ivcrawmatdtl_refid,
                uom_cy2, cy_cy2_rate,
                createby, createdate, lastupby, lastupdate
            ) VALUES (
                :podtl_refid, GETDATE(), :supplierivc_ref,
                :actqty, :uom_qty, :wt, :uom_wt, :remark,
                :unit_price, :uom_cy, :uom_unitprice, :ivcrawmatdtl_refid,
                :uom_cy2, :cy_cy2_rate,
                :createby, GETDATE(), :lastupby, GETDATE()
            )"
;
                
    
$sth $dbh->prepare($sql);
/*
    echo $sth->getSQL( array(':podtl_refid'=> $refid,
                            ':actqty'=> $actqty,
                            ':uom_qty'=> $uom_qty,
                            ':wt'=> $wt,
                            ':uom_wt'=> $uom_wt,
                            ':unit_price'=> $unit_price,
                            ':uom_cy2'=> 'CNY',
                            ':uom_cy'=> $uom_cy,
                            ':cy_cy2_rate'=> (float)USD_CNY::getCurrencyRateFrom('USD'),
                            ':uom_unitprice'=> $uom_unitprice,
                            ':ivcrawmatdtl_refid'=> $ivcrawmatdtl_refid,
                            ':createby'=> $createby,
                            ':lastupby'=> $lastupby,
                            ':remark'=> $remark,
                            ':supplierivc_ref'=>$supplierivc_ref) );
*/    
    
$q $sth->execute( array(':podtl_refid'=> $refid,
                            
':actqty'=> $actqty,
                            
':uom_qty'=> $uom_qty,
                            
':wt'=> $wt,
                            
':uom_wt'=> $uom_wt,
                            
':unit_price'=> $unit_price,
                            
':uom_cy2'=> 'CNY',
                            
':uom_cy'=> $uom_cy,
                            
':cy_cy2_rate'=> (float)USD_CNY::getCurrencyRateFrom('USD'),
                            
':uom_unitprice'=> $uom_unitprice,
                            
':ivcrawmatdtl_refid'=> $ivcrawmatdtl_refid,
                            
':createby'=> $createby,
                            
':lastupby'=> $lastupby,
                            
':remark'=> $remark,
                            
':supplierivc_ref'=>$supplierivc_ref) );    
    
pdo_showerror($sth$q);

    
inv_disableNoStocktake($podtl['bomcategy'], $podtl['itemnoid']);

    
    
$dbh->commit();    
    
    if(
$podtl['uom_qty']==$material['uom_wt']){
        
$received poset_getReceivedPOWt($podtl['refid']);
        
//vdump("wt");
    
} else {
        
$received poset_getReceivedPOQty($podtl['refid']); 
        
//vdump("qty");
    
}
    
//vdump($podtl['status'], $podtl['qty'], $received, poset_getSupplierRemaining($podtl['status'], $podtl['qty'], $received));
    
    
if( poset_getSupplierRemaining($podtl['status'], $podtl['qty'], $received)<=){
        
//finished receive
        
$sql "UPDATE ord_podtl SET
                status = :status,
                lastupby = :lastupby,
                lastupdate = GETDATE()
                WHERE refid = :refid"
;
                    
        
$sth $dbh->prepare($sql);
        
$q $sth->execute( array(':status'=> 'FINISHED',
                                
':lastupby'=> $lastupby,
                                
':refid'=> $podtl['refid']) );    
/*        echo $sth->getSQL( array(':status'=> 'FINISHED',
                                ':lastupby'=> $lastupby,
                                ':refid'=> $podtl['refid'])  );    */
        
pdo_showerror($sth$q);
         
        if(
poset_dtlAllFinished($pomain['refid'])){
            
poset_mainAsFinished($pomain['refid']);    
        }
    }

    if( 
$podtl['bomcategy']!='material'){
        if(!empty(
$_REQUEST['updateInvPrice']) ){
            
//update general price
            //TODO: select a correct currency to update
            
updateInvPrice($pomain['buyer'], $podtl['bomcategy'], $podtl['itemnoid'], $unit_price$unit_price2);
        }
        
        if(!empty(
$_REQUEST['updateSupplierPrice'])){
            
//update supplier price    
            //TODO: select a correct currency to update
            
updateSupplierPrice($pomain['buyer'], $pomain['supplier_refid'], $podtl['bomcategy'], $podtl['itemnoid'], $unit_price$unit_price2);
        }
    }

    
//update po status to FINISHED for all po dtl remaining <=0
    
list($po['remain_qty'], $po['remain_amt']) = getPoRemaining($pomain['refid']);
    if(
$po['remain_qty']<=0){
        
//exit('remain:'.$po['remain_qty']);
        
poset_mainAsFinished($pomain['refid']);        
    }
    
    
form_dest($_REQUEST['godest'], $_REQUEST['formdest']);
    
header("Location: ord_poset_submitform.php?refid=$refid&msg=Saved.");
    print 
"Saved.";
    exit;
    
    
}
myerror(INVALID.WS.REQUEST);
exit;    


?>