/var/www/enzatesting.onesolution.hk/dgn_master_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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php $formid "Master";
require_once 
"inc/configure.php";

if(
havePermission("GNu")==false){
    
myerror("Invalid Permission");
}
/*
$refid                 = filter_var($_REQUEST['refid'], FILTER_SANITIZE_NUMBER_INT);
$mold_refid         = $refid;
vdump($_REQUEST);
vdump($_FILES);
exit;*/
$drawing_no setDefaultReqVar("drawing_no"'');
$ref         filter_var($_REQUEST['ref'], FILTER_SANITIZE_NUMBER_INT);

if( 
$_REQUEST['action']=="dgn_master_addform" && !empty($drawing_no)){

    if(
$ref){
        
markDwgFinished($ref);
    }

    
//get the source drawing data
    
if( $drawing_no){
        
$sql "SELECT * FROM dgn_drawing WHERE drawing_no=:drawing_no order by refid DESC";
        
$sth $dbh->prepare($sql);
        
$sth->execute(  array(':drawing_no' => $drawing_no) );
    } else {
        
myerror("Invalid Request");
    }
    
$row $sth->fetch();
    
$drawing_refid    $row['refid'];
    
$request_no        $row['req_no'];
    unset(
$sth);

    
//get the request data
    
if($request_no){
        
$sql "SELECT * FROM dgn_request WHERE request_no=:request_no order by refid DESC";
        
$sth $dbh->prepare($sql);
        
$sth->execute(  array(':request_no' => $request_no) );
        
//echo $sth->getSQL(  array(':request_no' => $request_no) );
    
} else {
        
myerror("Invalid Request");
    }
    
//echo $sql;
    
$req $sth->fetch();
    unset(
$sth);

    
//generals
    //$drawing_refid        = filter_var($_REQUEST['drawing_refid'], FILTER_SANITIZE_STRING);
    
if($row['status']=="MQT-WTD"){
        
$status             "MQT-WTD";
    }elseif(
$row['status']=="CAD-MTD"){
        
$status             "CAD-MTD";
    }else{
        
$status             "NMS";
    }
    
$last_status         "";

    
$response_date        date("Y-m-d");
    
$launch_date        date("Y-m-d");

    
$model_maker_name     filter_var($_REQUEST['model_maker_name'], FILTER_SANITIZE_STRING);
    
$pdt_type             filter_var($row['pdt_type'], FILTER_SANITIZE_STRING);

    
$custcode             filter_var($row['custcode'], FILTER_SANITIZE_STRING);
    
$request_origine    filter_var($row['request_origine'], FILTER_SANITIZE_STRING);
    
$target_wt             = (float)filter_var($row['target_wt'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_wt                 filter_var($row['uom_wt'], FILTER_SANITIZE_STRING);
    
$target_price         = (float)filter_var($req['target_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_cy                 filter_var($req['uom_cy'], FILTER_SANITIZE_STRING);
    
$target_date         filter_var($row['target_date'], FILTER_SANITIZE_STRING);
    
$est_price             = (float)filter_var($row['est_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$remark             filter_var($row['remark'], FILTER_SANITIZE_STRING);
    
$client_remark         filter_var($row['client_remark'], FILTER_SANITIZE_STRING);

    
$request_approval_date     filter_var(datef($row['req_approval_date']), FILTER_SANITIZE_STRING);
    
$drawing_approval_date     filter_var(datef($row['response_date']), FILTER_SANITIZE_STRING);
    if(
$drawing_approval_date=="0000-00-00" or $drawing_approval_date==""){
        
$drawing_approval_date=datef($row['createdate']);
    }
    
$req_no                filter_var($row['req_no'], FILTER_SANITIZE_STRING);
    
$drawing_no            filter_var($row['drawing_no'], FILTER_SANITIZE_STRING);
    
$designer_name         filter_var($row['designer_name'], FILTER_SANITIZE_STRING);

    
//$producttype         = filter_var($_REQUEST['producttype'], FILTER_SANITIZE_STRING);
    //segments
    // switch ($pdt_type) {
 //    case "Ring":
 //        $producttype = "R";
 //        break;
 //    case "Earring":
 //        $producttype = "E";
 //        break;
 //    case "Pendant":
 //        $producttype = "P";
 //        break;
 //    case "Necklace":
 //        $producttype = "N";
 //        break;
 //    case "Bracelet":
 //        $producttype = "B";
 //        break;
 //    case "Clip":
 //        $producttype = "X";
 //        break;
 //    case "Cufflink":
 //        $producttype = "C";
 //        break;
 //    case "Other":
    // default:
 //        $producttype = "X";
 //        break;
    // }
    
$sql "SELECT * FROM master_type_code WHERE typeid='PRODTYPE' AND codedesc_en=:codedesc_en";
    
$sth $dbh->prepare($sql);
    
$q$sth->execute( array(':codedesc_en'=> $pdt_type) );
    
pdo_showerror($sth$q);
    
$mtc $sth->fetch();

    if(
$mtc['id']){
        
$producttype $mtc['codeid'];
    }else{
        
$producttype "X";
    }


    
//$moldno             = filter_var($_REQUEST['moldno'], FILTER_SANITIZE_STRING);
    
$mattype            filter_var("X"FILTER_SANITIZE_STRING);
    
$matcolor             filter_var("X"FILTER_SANITIZE_STRING);
    
$finishing             filter_var("X"FILTER_SANITIZE_STRING);
    
$diatype            filter_var("X"FILTER_SANITIZE_STRING);
    
$stonetype             filter_var("XX"FILTER_SANITIZE_STRING);
    
$productstonecolor    filter_var("X"FILTER_SANITIZE_STRING);
    
$size                 trim(filter_var($_REQUEST['size'], FILTER_SANITIZE_STRING));

    if(
$_REQUEST['manualMoldno']=="true"){
        
$producttype     filter_var($_REQUEST['producttype'], FILTER_SANITIZE_STRING);
        
$moldno            = (int)filter_var($_REQUEST['moldno'], FILTER_SANITIZE_STRING);
        
$size            trim(filter_var($_REQUEST['size'], FILTER_SANITIZE_STRING));

        
//vdump("moldnoAndSizeIsValid($producttype, $moldno, $size)");
        //check moldno and size exist in master
        
if(moldnoAndSizeIsValid($producttype$moldno$size)){
        }else{
            
myerror(USED.WS.MOLDNO);
            exit;
        }

    }else{
        
$moldno        getNextMoldnoByPdt($producttype);
    }
    
$moldno            = (string)str_pad($moldno4'0'STR_PAD_LEFT);

    
$pdt_moldno     $producttype $moldno;
    
$itemno         getItemNo($producttype$moldno$mattype$matcolor$finishing$diatype$stonetype$productstonecolor$size);
/*    if(empty($pdt_moldno)){
        $pdt_moldno = $producttype . $moldno;
    }
        */
    
$createby            filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$lastupby            filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);

    
$version             1;

    
//vdump($row);
    //vdump($req);
    //exit;
    // check existance of moldno before insert
/*    if( pdtmold_exist($producttype, $moldno) ){
        $msg="$producttype$moldno is already existed";
        header("Location: dgn_master_addform.php?drawing_no=$drawing_no&error=$msg");
        exit;
    }*/


    //new request record with same request_no
    
$sql "INSERT INTO dgn_master_mold (
        status,
        response_date,
        launch_date,
        model_maker_name,
        pdt_type,
        custcode,
        request_origine,
        target_wt,
        uom_wt,
        target_price,
        est_price,
        remark,
        client_remark,
        uom_cy,
        target_date,
        request_approval_date,
        drawing_approval_date,
        req_no,
        drawing_no,
        designer_name,
        producttype,
        moldno,
        mattype,
        matcolor,
        finishing,
        diatype,
        stonetype,
        productstonecolor,
        size,
        version,
        pdt_moldno,
        itemno,
        createby,
        createdate,
        lastupby,
        lastupdate
    ) VALUES (
        :status ,
        :response_date ,
        :launch_date ,
        :model_maker_name ,
        :pdt_type ,
        :custcode ,
        :request_origine ,
        :target_wt ,
        :uom_wt ,
        :target_price ,
        :est_price ,
        :remark ,
        :client_remark ,
        :uom_cy ,
        :target_date ,
        :request_approval_date ,
        :drawing_approval_date ,
        :req_no ,
        :drawing_no ,
        :designer_name ,
        :producttype ,
        :moldno ,
        :mattype ,
        :matcolor ,
        :finishing ,
        :diatype ,
        :stonetype ,
        :productstonecolor ,
        :size ,
        :version ,
        :pdt_moldno ,
        :itemno ,
        :createby ,
        getdate(),
        :lastupby ,
        getdate()
    )"
;

    
$sth $dbh->prepare($sql);
    
$q $sth->execute( array(':status' => $status,
                            
':response_date' => $response_date,
                            
':launch_date' => $launch_date,
                            
':model_maker_name' => $model_maker_name,
                            
':pdt_type' => $pdt_type,
                            
':custcode' => $custcode,
                            
':request_origine' => $request_origine,
                            
':target_wt' => $target_wt,
                            
':uom_wt' => $uom_wt,
                            
':target_price' => $target_price,
                            
':est_price' => $est_price,
                            
':remark' => $remark,
                            
':client_remark' => $client_remark,
                            
':uom_cy' => $uom_cy,
                            
':target_date' => $target_date,
                            
':request_approval_date' => $request_approval_date,
                            
':drawing_approval_date' => $drawing_approval_date,
                            
':req_no' => $req_no,
                            
':drawing_no' => $drawing_no,
                            
':designer_name' => $designer_name,
                            
':producttype' => $producttype,
                            
':moldno' => $moldno,
                            
':mattype' => $mattype,
                            
':matcolor' => $matcolor,
                            
':finishing' => $finishing,
                            
':diatype' => $diatype,
                            
':stonetype' => $stonetype,
                            
':productstonecolor' => $productstonecolor,
                            
':size' => $size,
                            
':itemno' => $itemno,
                            
':version' => $version,
                            
':pdt_moldno' => $pdt_moldno,
                            
':createby' => $createby,
                            
':lastupby' => $lastupby) );
    
pdo_showerror($sth$q);
/*
echo $sth->getSQL( array(':status' => $status,
                            ':response_date' => $response_date,
                            ':launch_date' => $launch_date,
                            ':model_maker_name' => $model_maker_name,
                            ':pdt_type' => $pdt_type,
                            ':custcode' => $custcode,
                            ':request_origine' => $request_origine,
                            ':target_wt' => $target_wt,
                            ':uom_wt' => $uom_wt,
                            ':target_price' => $target_price,
                            ':uom_cy' => $uom_cy,
                            ':target_date' => $target_date,
                            ':request_approval_date' => $request_approval_date,
                            ':drawing_approval_date' => $drawing_approval_date,
                            ':req_no' => $req_no,
                            ':drawing_no' => $drawing_no,
                            ':designer_name' => $designer_name,
                            ':producttype' => $producttype,
                            ':moldno' => $moldno,
                            ':mattype' => $mattype,
                            ':matcolor' => $matcolor,
                            ':finishing' => $finishing,
                            ':diatype' => $diatype,
                            ':stonetype' => $stonetype,
                            ':productstonecolor' => $productstonecolor,
                            ':size' => $size,
                            ':version' => $version,
                            ':pdt_moldno' => $pdt_moldno,
                            ':createby' => $createby,
                            ':lastupby' => $lastupby) ) . HTML_EOL;*/

//$last_refid = $refid;
$refid $dbh->lastInsertId();
$mold_refid $refid;

//todo: create the default first submold using generated moldno


//update tmp BOM
$sql "DELETE from dgn_master_bom WHERE mold_refid=:mold_refid";
$sth $dbh->prepare($sql);
$q$sth->execute( array(':mold_refid'=> $refid) );
pdo_showerror($sth$q);

$sql "INSERT INTO dgn_master_bom (mold_refid, bomcategy, itemnoid, qty, uom_qty, price, uom_price, unitprice, createby, createdate, lastupby, lastupdate)
        Values(:mold_refid, :bcategy, :itemnoid, :qty, :uom_qty, :price, :uom_price, :unitprice, :createby, GETDATE(), :lastupby, GETDATE())"
;
$sth $dbh->prepare($sql);

//copy drawing bom to mastermold bom
$sql "Select * from dgn_item_bom Where drawing_refid = :drawing_refid";
$sth_sele $dbh->prepare($sql);
$q$sth_sele->execute( array(':drawing_refid'=> $drawing_refid) );
pdo_showerror($sth$q);
while(
$bom_item $sth_sele->fetch()){
    
//vdump($bom_item);
    
$q$sth->execute( array(':mold_refid' => $refid,
                            
':bcategy' => $bom_item['bomcategy'],
                            
':itemnoid' => $bom_item['itemnoid'],
                            
':qty' => (float)$bom_item['qty'],
                            
':uom_qty' => $bom_item['uom_qty'],
                            
':price' => (float)$bom_item['price'],
                            
':uom_price' => $bom_item['uom_price'],
                            
':unitprice' => (float)$bom_item['unitprice'],
                            
':createby' => $createby,
                            
':lastupby' => $lastupby) );
    
pdo_showerror($sth$q);
/*        echo $sth->getSQL( array(':mold_refid' => $refid,
                            ':bcategy' => $bom_item['bomcategy'],
                            ':itemnoid' => $bom_item['itemnoid'],
                            ':qty' => $bom_item['qty'],
                            ':uom_qty' => $bom_item['uom_qty'],
                            ':price' => $bom_item['price'],
                            ':uom_price' => $bom_item['uom_price'],
                            ':unitprice' => $bom_item['unitprice'],
                            ':createby' => $createby,
                            ':lastupby' => $lastupby) ) . HTML_EOL;*/
}

//--copy drawing route to master route
require_once "dgn_master_route_init.php";
master_route_init($refid$drawing_refid);

    
form_dest($_REQUEST['godest'], $_REQUEST['formdest']);
    
header("Location: dgn_master_modifyform.php?edit=1&refid=$refid&msg=Saved.");
    print 
"Saved.";
    exit;


}
myerror("Invaild request");


?>