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

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

//(int)$_REQUEST['productID'];
//vdump($_REQUEST);
if( $_REQUEST['action']=="accessory_addform"){
    
// && !empty($refid) ){
    
    
$itemgp             filter_var($_REQUEST['itemgp'], FILTER_SANITIZE_STRING);    
    
//$itemno             = filter_var($_REQUEST['itemno'], FILTER_SANITIZE_STRING);    
    
$name                 filter_var($_REQUEST['name'], FILTER_SANITIZE_STRING);
    
$cname                 filter_var($_REQUEST['cname'], FILTER_SANITIZE_STRING);
    
$bom                 filter_var($_REQUEST['bom'], FILTER_SANITIZE_STRING);    //$parentBOM             = filter_var($_REQUEST['parentBOM'], FILTER_SANITIZE_STRING);        
    
$accstype             filter_var($_REQUEST['accstype'], FILTER_SANITIZE_STRING);    
    
$accscategy         filter_var($_REQUEST['accscategy'], FILTER_SANITIZE_STRING);    
    
$mattype             filter_var($_REQUEST['mattype'], FILTER_SANITIZE_STRING);    
    
$matcolor             filter_var($_REQUEST['matcolor'], FILTER_SANITIZE_STRING);    
    
$finishing            filter_var($_REQUEST['finishing'], FILTER_SANITIZE_STRING);    
    
$accssize             filter_var($_REQUEST['accssize'], FILTER_SANITIZE_STRING);
    
$as2d                 = (float) filter_var($_REQUEST['accssize2d'],  FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$verified             filter_var($_REQUEST['verified'], 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);
    
$uom_unitwt            filter_var($_REQUEST['uom_unitwt'], FILTER_SANITIZE_STRING);
    
$price                 = (float) filter_var($_REQUEST['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);
    
$owner                filter_var($_REQUEST['owner'], FILTER_SANITIZE_STRING);    
    
    
$createby            filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$lastupby            filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);

    
$itemno getAccessoryNo($accstype$accscategy$mattype$matcolor$finishing$accssize$as2d);
    
    
getAccessoryName($name$cname$accstype$accscategy$mattype$matcolor$finishing$accssize$as2d);
    
getAccessoryUnit($price$uom_price$unitprice$uom_inventory$weight$uom_wt$uom_unitwt);
        
    
// check existance of itemno before insert    
    
$sql "SELECT count(*) as count from inv_accessory where itemno=:itemno ";
    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':itemno'=> $itemno) );
    
$row $sth->fetch(); 
    if( 
$row['count']>){
        
$msg="Item Number already existed";
        
header("Location: inv_accessory_index.php?error=$msg");
        exit;    
    }
    unset(
$sth);

    
$sql_param = array(':itemgp' => $itemgp
                            
':itemno' => $itemno,
                            
':name' => $name,
                            
':cname' => $cname
                            
':bom'=> $bom,
                            
':accstype' => $accstype,
                            
':accscategy' => $accscategy
                            
':mattype' => $mattype,
                            
':matcolor' => $matcolor
                            
':finishing' => $finishing,
                            
':accssize' => $accssize,
                            
':as2d' => $as2d,
                            
':verified' => $verified,
                            
':weight' => $weight
                            
':uom_wt' => $uom_wt,
                            
':uom_unitwt' => $uom_unitwt,
                            
':owner' => $owner
                            
':createby' => $createby,
                            
':lastupby' => $lastupby);
    
    if(
havePermission("GPu")){ 
        
$sql_GPu_field="price,
                    uom_price, 
                    unitprice,
                    uom_inventory,
                    uom_cy, "
;

        
$sql_GPu_val=":price,
                    :uom_price, 
                    :unitprice,
                    :uom_inventory,
                    :uom_cy, "
;
                    
        
$sql_param[':price'] = $price;
        
$sql_param[':uom_price'] = $uom_price;
        
$sql_param[':unitprice'] = $unitprice;
        
$sql_param[':uom_inventory'] = $uom_inventory;
        
$sql_param[':uom_cy'] = $uom_cy;
    }
    
//add stone
/*    $sql = "INSERT INTO inv_accessory SET 
                itemgp = :itemgp,
                itemno = :itemno, 
                name_en = :name,
                name_sc = :cname,
                bom = :bom,
                accstype = :accstype, 
                accscategy = :accscategy,
                mattype = :mattype, 
                matcolor = :matcolor,
                finishing = :finishing, 
                accssize = :accssize,
                accssize2 = :as2d,  
                verified = :verified,
                weight = :weight,
                uom_wt = :uom_wt, 
                uom_unitwt = :uom_unitwt, 
                price = :price,
                uom_price = :uom_price, 
                unitprice = :unitprice,
                uom_inventory = :uom_inventory,
                uom_cy = :uom_cy, 
                owner = :owner,
                createby = :createby, 
                createdate = GETDATE(),
                lastupby = :lastupby, 
                lastupdate = GETDATE()";*/
    
if (defined("MSSQL")) {
        
$sql "INSERT INTO inv_accessory (
                    itemgp, 
                    itemno, 
                    name_en, 
                    name_sc, 
                    bom, 
                    accstype, 
                    accscategy, 
                    mattype, 
                    matcolor, 
                    finishing, 
                    accssize, 
                    accssize2, 
                    verified, 
                    weight, 
                    uom_wt, 
                    uom_unitwt, 
                    
                    
$sql_GPu_field
                    
                    owner, 
                    createby, 
                    createdate, 
                    lastupby, 
                    lastupdate 
                ) Values (
                    :itemgp, 
                    :itemno, 
                    :name, 
                    :cname, 
                    :bom, 
                    :accstype, 
                    :accscategy,
                    :mattype, 
                    :matcolor,
                    :finishing, 
                    :accssize,
                    :as2d,  
                    :verified,
                    :weight,
                    :uom_wt, 
                    :uom_unitwt, 
                    
                    
$sql_GPu_val
                     
                    :owner,
                    :createby, 
                    GETDATE(),
                    :lastupby, 
                    GETDATE() )"
;
    }
                
    
$sth $dbh->prepare($sql);
    
$q $sth->execute$sql_param );
    
pdo_showerror($sth$q);
    
$refid $dbh->lastInsertId();
/*echo $sth->getSQL( $sql_param ) . HTML_EOL;
    */            

    
if(havePermission("BMu")){ 
        
$abom=$_REQUEST['abom'];
        
//delete old record
        
$sql "DELETE from inv_accessory_bom WHERE inv_acc_refid=:refid";
        
$sth $dbh->prepare($sql);
        
$q$sth->execute( array(':refid'=> $refid) );
        
pdo_showerror($sth$q);
        
        if(
$abom['enable']){
            
//vdump($abom);    
            
            
$sql "INSERT INTO inv_accessory_bom (inv_acc_refid, labor_price, uom_cy, uom_labor, weight, uom_wt, uom_unitwt, mattype)
                        Values(:inv_acc_refid, :labor_price, :uom_cy, :uom_labor, :weight, :uom_wt, :uom_unitwt, :mattype)"
;
                
$sth $dbh->prepare($sql);    
        
                
$q$sth->execute( array(':inv_acc_refid' => $refid,
                                            
':labor_price' => $abom['labor_price'],
                                            
':uom_cy' => $abom['uom_cy'], 
                                            
':uom_labor' => $abom['uom_labor'], 
                                            
':weight' => $abom['weight'],
                                            
':uom_wt' => $abom['uom_wt'], 
                                            
':uom_unitwt' => $abom['uom_unitwt'],
                                            
':mattype' => $abom['mattype']) );
                    
pdo_showerror($sth$q);                        
            
/*        echo $sth->getSQL( ) ) . HTML_EOL;*/
        
        
}    
    }
    
    
form_dest($_REQUEST['godest'], $_REQUEST['formdest']);
    
header("Location: inv_accessory_modifyform.php?refid=$refid&msg=Saved."); 
    print 
"Saved.";
    exit;
    
    
}
print 
"Invalid Request";