/var/www/enzatesting.onesolution.hk/01_20240711_full_backup/inv_stone_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
<?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_addform"){
    
// && !empty($refid) ){
    
    
$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);
    
$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);    
    
    
$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);
        
    
// check existance of itemno before insert    
    
$sql "SELECT count(*) as count from inv_stone 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_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
                            
':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_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, 
                weight = :weight,
                uom_wt = :uom_wt, 
                price = :price,
                uom_price = :uom_price, 
                unitprice = :unitprice,
                uom_inventory = :uom_inventory,
                uom_cy = :uom_cy, 
                thickness = :thickness,
                uom_di = :uom_di, 
                owner = :owner,
                createby = :createby, 
                createdate = NOW(),
                lastupby = :lastupby, 
                lastupdate = NOW()";*/
                
    
if (defined("MSSQL")) {
        
$sql "INSERT INTO inv_stone ( 
                itemgp,
                itemno, 
                name_en,
                name_sc,
                stonetype, 
                stoneqlty,
                stonecolor, 
                stoneshape,
                stonesize, 
                stonesize2, 
                verified, 
                stonefragility,
                weight,
                uom_wt, 
                
                
$sql_GPu_field
                
                thickness,
                uom_di, 
                owner,
                createby, 
                createdate,
                lastupby, 
                lastupdate 
            ) Values (
                :itemgp,
                :itemno, 
                :name,
                :cname,
                :stonetype, 
                :stoneqlty,
                :stonecolor, 
                :stoneshape,
                :stonesize, 
                :ss2d, 
                :verified, 
                :stonefragility,
                :weight,
                :uom_wt, 
                
                
$sql_GPu_val
                 
                :thickness,
                :uom_di, 
                :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;
        
    exit;*/            
    
form_dest($_REQUEST['godest'], $_REQUEST['formdest']);    
    
//header("Location: inv_stone_index.php?act=resume&msg=Saved."); 
    
header("Location: inv_stone_modifyform.php?refid=$refid&msg=Saved.");
    print 
"Saved.";
    exit;
    
    
}
print 
"Invalid Request";