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

$bomcategy "material";

if(
havePermission("STu")==false){
    
myerror(INVALID.WS.PERMISSION);    
}

$refid             filter_var($_REQUEST['refid'], FILTER_SANITIZE_NUMBER_INT);
$act             filter_var($_REQUEST['act'], FILTER_SANITIZE_STRING);
$companyid        filter_var($_REQUEST['companyid'], FILTER_SANITIZE_STRING);
//(int)$_REQUEST['productID'];
//vdump($_REQUEST); //exit;
if( $_POST['action']=="inv_stocktake_material_modifyform" && !empty($refid) && ($act=="ADD" || $act=="REPLACE")){
    
$inv_item getDB("inv_material"$refid);
    
    
$dbh->beginTransaction();
    
    
$itemid            filter_var($inv_item['refid'], FILTER_SANITIZE_NUMBER_INT);
    
$itemno            filter_var($inv_item['itemno'], FILTER_SANITIZE_STRING);
    
$invno             filter_var($_REQUEST['invno'], FILTER_SANITIZE_STRING);
    
$location        filter_var($_REQUEST['location'], FILTER_SANITIZE_STRING);        
    
$input_qty         = (float) filter_var($_REQUEST['input_qty'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_qty        filter_var($_REQUEST['uom_qty'], FILTER_SANITIZE_STRING);
    
$input_wt         = (float) filter_var($_REQUEST['input_wt'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_wt            filter_var($_REQUEST['uom_wt'], FILTER_SANITIZE_STRING);
    if(
$location=="EZH"){
        
$price         = (float) filter_var($inv_item['supplier_price'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    }else{
        
$price        = (float) filter_var($inv_item['price'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    }
    
    
$uom_price        =  filter_var($inv_item['uom_price'], FILTER_SANITIZE_STRING);
    
$uom_cy            =  filter_var($inv_item['uom_cy'], FILTER_SANITIZE_STRING);
    
$createby        filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$lastupby        filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
    if(
$act=="REPLACE"){ //delete existing records
        
$sql "DELETE from inv_stocktake_raw
                WHERE invno=:invno AND 
                        location=:location AND
                        bomcategy=:bomcategy AND
                        itemid=:itemid AND
                        invstocktake_refid=:invstocktake_refid"
;
        
$sth $dbh->prepare($sql);
        
$q $sth->execute( array(':invno'=> $invno,
                                
':location'=> $location,
                                
':bomcategy'=> $bomcategy,
                                
':itemid'=> $refid,
                                
':invstocktake_refid'=> inv_getCurrentStocktakeID($companyid)) );    
/*        echo $sth->getSQL( array(':invno'=> $invno,
                                ':location'=> $location,
                                ':bomcategy'=> $bomcategy,
                                ':itemid'=> $refid,
                                ':invstocktake_refid'=> inv_getCurrentStocktakeID()) );*/    
        
pdo_showerror($sth$q);                                    
    }    

        
    
//add record
    
$sql "INSERT into inv_stocktake_raw(
                invno, location, bomcategy, itemid, itemno,
                input_qty, uom_qty, input_wt, uom_wt, invstocktake_refid,
                price, uom_price, uom_cy,
                createby, createdate, lastupby, lastupdate
            ) VALUES (
                :invno, :location, :bomcategy, :itemid, :itemno,
                :input_qty, :uom_qty, :input_wt, :uom_wt, :invstocktake_refid,
                :price, :uom_price, :uom_cy,
                :createby, GETDATE(), :lastupby, GETDATE()
            )"
;
                
    
$sth $dbh->prepare($sql);
    
$q $sth->execute( array(':invno'=> $invno,
                            
':location'=> $location,
                            
':bomcategy'=> $bomcategy,
                            
':itemid'=> $itemid,
                            
':itemno'=> $itemno,
                            
':input_qty'=> $input_qty,
                            
':uom_qty'=> $uom_qty,
                            
':input_wt'=> $input_wt,
                            
':uom_wt'=> $uom_wt,
                            
':createby'=> $createby,
                            
':lastupby'=> $lastupby,
                            
':price'=> $price,
                            
':uom_price'=> $uom_price,
                            
':uom_cy'=> $uom_cy,
                            
':invstocktake_refid'=> inv_getCurrentStocktakeID($companyid)) );    
/*    echo $sth->getSQL( array(':invno'=> $invno,
                            ':location'=> $location,
                            ':bomcategy'=> $bomcategy,
                            ':itemid'=> $refid,
                            ':input_qty'=> $input_qty,
                            ':uom_qty'=> $uom_qty,
                            ':input_wt'=> $input_wt,
                            ':uom_wt'=> $uom_wt,
                            ':createby'=> $createby,
                            ':lastupby'=> $lastupby,
                            ':invstocktake_refid'=> inv_getCurrentStocktakeID()) );*/    
    
pdo_showerror($sth$q);
    
    
inv_disableNoStocktake($bomcategy$refid);
//    exit;
    
    
$dbh->commit();             
    
header("Location: invstocktake_material_modifyform.php?companyid=$companyid&refid=$refid&msg=Saved.");
    print 
"Saved.";
    exit;
    
    
}
myerror(INVALID.WS.REQUEST);
exit;    


?>