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

$refid                 filter_var($_REQUEST['refid'], FILTER_SANITIZE_NUMBER_INT);

//(int)$_REQUEST['productID'];
//vdump($_REQUEST);
if( $_REQUEST['action']=="stone_modifyform" && !empty($refid) ){
    
$dbh->beginTransaction();
    
$itemgp             filter_var($_REQUEST['itemgp'], FILTER_SANITIZE_STRING);    
    
//$itemno             = filter_var($_REQUEST['itemno'], FILTER_SANITIZE_STRING);    
    //$parentBOM             = filter_var($_REQUEST['parentBOM'], FILTER_SANITIZE_STRING);    
    
$name                 filter_var($_REQUEST['name'], FILTER_SANITIZE_STRING);    
    
$cname                 filter_var($_REQUEST['cname'], FILTER_SANITIZE_STRING);
    
$stonetype             filter_var($_REQUEST['stonetype'], FILTER_SANITIZE_STRING);    
    
$stoneqlty             filter_var($_REQUEST['stoneqlty'], FILTER_SANITIZE_STRING);    
    
$stonecolor         filter_var($_REQUEST['stonecolor'], FILTER_SANITIZE_STRING);    
    
$stoneshape            filter_var($_REQUEST['stoneshape'], FILTER_SANITIZE_STRING);    
    
$stonesize             filter_var($_REQUEST['stonesize'], FILTER_SANITIZE_STRING);
    
$ss2d                = (float) filter_var($_REQUEST['ss2d'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);    
    
$verified             filter_var($_REQUEST['verified'], FILTER_SANITIZE_STRING);
    
$stonefragility        filter_var($_REQUEST['stonefragility'], FILTER_SANITIZE_STRING);
            
    
$weight             = (float) filter_var($_REQUEST['weight'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_wt             filter_var($_REQUEST['uom_wt'], FILTER_SANITIZE_STRING);
    
$price                 = (float) filter_var($_REQUEST['price'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$supplier_price    = (float) filter_var($_REQUEST['supplier_price'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);        
    
$uom_price             filter_var($_REQUEST['uom_price'], FILTER_SANITIZE_STRING);    
    
$unitprice             = (float) filter_var($_REQUEST['unitprice'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_cy                filter_var($_REQUEST['uom_cy'], FILTER_SANITIZE_STRING);    
    
$thickness            = (float) filter_var($_REQUEST['thickness'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);    
    
$uom_di                filter_var($_REQUEST['uom_di'], FILTER_SANITIZE_STRING);    
    
$owner                filter_var($_REQUEST['owner'], FILTER_SANITIZE_STRING);    
    
$mastersupplier_refid filter_var($_REQUEST['default_mastersupplier_refid'], FILTER_SANITIZE_NUMBER_INT);
    
$mastervendor_refid filter_var($_REQUEST['mastervendor_refid'], FILTER_SANITIZE_NUMBER_INT);
    
$min_inventory         = (float) filter_var($_REQUEST['min_inventory'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$min_wt                = (float) filter_var($_REQUEST['min_wt'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
    
$createby            filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$lastupby            filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);

    
$itemno getStoneNo($stonetype$stoneqlty$stonecolor$stoneshape$stonesize$ss2d    );
    
    
getStoneName($name$cname$stonetype$stoneqlty$stonecolor$stoneshape$stonesize$ss2d);
    
calc_unitprice($price$uom_price$unitprice$uom_inventory$weight$uom_wt);
    
    
//exit;
    // check existance of itemno before insert    
    
$sql "SELECT count(*) as count from inv_stone where itemno=:itemno AND refid!=:refid ";
    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':itemno'=> $itemno,
                            
':refid'=> $refid) );
    
$row $sth->fetch(); 
    if( 
$row['count']>){
        
$msg="Item Number already existed";
        
header("Location: inv_stone_index.php?error=$msg");
        exit;    
    }        
    unset(
$sth);
    
    
$sql_param = array(':itemgp' => $itemgp
                            
':itemno' => $itemno,
                            
':name' => $name,
                            
':cname' => $cname,
                            
':stonetype' => $stonetype,
                            
':stoneqlty' => $stoneqlty
                            
':stonecolor' => $stonecolor,
                            
':stoneshape' => $stoneshape
                            
':stonesize' => $stonesize,
                            
':ss2d' => $ss2d,
                            
':verified' => $verified,
                            
':stonefragility' => $stonefragility,                            
                            
':weight' => $weight
                            
':uom_wt' => $uom_wt,
                            
':thickness' => $thickness
                            
':uom_di' => $uom_di,
                            
':owner' => $owner,
                            
':mastersupplier_refid' => $mastersupplier_refid,
                            
':mastervendor_refid' => $mastervendor_refid,
                            
':min_inventory' => $min_inventory,
                            
':min_wt' => $min_wt
                            
':lastupby' => $lastupby,
                            
':refid' => $refid);
    
    if(
havePermission("GPu")){ 
        
$sql_GPu_field="price = :price,
                        supplier_price = :supplier_price,
                        uom_price = :uom_price, 
                        unitprice = :unitprice,
                        uom_inventory = :uom_inventory,
                        uom_cy = :uom_cy, "
;

        
$sql_param[':price'] = $price;
        
$sql_param[':supplier_price'] = $supplier_price;
        
$sql_param[':uom_price'] = $uom_price;
        
$sql_param[':unitprice'] = $unitprice;
        
$sql_param[':uom_inventory'] = $uom_inventory;
        
$sql_param[':uom_cy'] = $uom_cy;                                
    }
        
    
//modify stone
    
$sql "UPDATE inv_stone SET 
                itemgp = :itemgp,
                itemno = :itemno, 
                name_en = :name,
                name_sc = :cname,
                stonetype = :stonetype, 
                stoneqlty = :stoneqlty,
                stonecolor = :stonecolor, 
                stoneshape = :stoneshape,
                stonesize = :stonesize, 
                stonesize2 = :ss2d, 
                verified = :verified,                 
                stonefragility = :stonefragility,
                weight = :weight,
                uom_wt = :uom_wt, 
                
                
$sql_GPu_field
                
                thickness = :thickness,
                uom_di = :uom_di, 
                owner = :owner,                
                mastersupplier_refid = :mastersupplier_refid,
                mastervendor_refid = :mastervendor_refid,
                min_inventory = :min_inventory,
                min_wt = :min_wt,                
                lastupby = :lastupby, 
                lastupdate = GETDATE()
            WHERE refid = :refid"
;
                
    
$sth $dbh->prepare($sql);
    
$q $sth->execute$sql_param );
    
pdo_showerror($sth$q);
/*echo $sth->getSQL( $sql_param) . HTML_EOL."";
        
exit;    */

    //remove rows form supplier_item where itemnoid=40 and bomcategy=diamond
    
$sql "DELETE from master_supplier_item WHERE itemnoid=:itemnoid AND bomcategy=:bomcategy";
    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':itemnoid'=> $refid,
                            
':bomcategy'=> 'stone') );
/*    echo $sth->getSQL( array(':itemnoid'=> $refid,
                            ':bomcategy'=> 'stone') );*/    
    
    
if(is_array($_REQUEST['supplier'])){
        foreach((array)
$_REQUEST['supplier'] as $key=>$supplier){
            
//insert rows
            
if($key>0){
                
//vdump($supplier);
                // check existance of itemno before insert    
                
$sql "INSERT into master_supplier_item (
                    mastersupplier_refid, itemnoid, itemno, bomcategy,
                    price, uom_cy, uom_qty, supplier_ref, byfactory,
                    createby, createdate, lastupby, lastupdate
                ) VALUES(
                    :mastersupplier_refid, :itemnoid, :itemno, :bomcategy,
                    :price, :uom_cy, :uom_qty, :supplier_ref, :byfactory,
                    :createby, GETDATE(), :lastupby, GETDATE()
                )"
;
                
$sth $dbh->prepare($sql);
                
$byfactory = ($supplier['byfactory']==1)? 1:0;
                
$sth->execute( array(':mastersupplier_refid'=> $supplier['mastersupplier_refid'],
                                        
':byfactory'=> $byfactory,
                                        
':itemnoid'=> $refid,
                                        
':itemno'=> $itemno,
                                        
':bomcategy'=> 'stone',
                                        
':price'=> (float) filter_var($supplier['price'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION),
                                        
':uom_cy'=> filter_var($supplier['uom_cy'], FILTER_SANITIZE_STRING),
                                        
':uom_qty'=> filter_var($supplier['uom_qty'], FILTER_SANITIZE_STRING),
                                        
':supplier_ref'=> filter_var($supplier['supplier_ref'], FILTER_SANITIZE_STRING),
                                        
':createby'=> $createby,
                                        
':lastupby'=> $lastupby) );
/*                echo $sth->getSQL( array(':mastersupplier_refid'=> $supplier['mastersupplier_refid'],
                                        ':itemnoid'=> $refid,
                                        ':itemno'=> $itemno,
                                        ':bomcategy'=> 'stone',
                                        ':price'=> (float) filter_var($supplier['price'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION),
                                        ':uom_cy'=> $supplier['uom_cy'],
                                        ':uom_qty'=> $supplier['uom_qty'],
                                        ':createby'=> $createby,
                                        ':lastupby'=> $lastupby) );*/
            
}
        }
    }
    
    
$dbh->commit();        
    
form_dest($_REQUEST['godest'], $_REQUEST['formdest']);    
    
//header("Location: inv_stone_index.php?act=resume&refid=$refid&msg=Saved."); 
    
header("Location: inv_stone_modifyform.php?refid=$refid&msg=Saved.");
    print 
"Saved.";
    exit;
    
    
}
print 
"Invaild request";


?>