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

function 
copy_dgn_master_BOM($last_refid$new_refid){
    global 
$dbh;
    
//copy info from last version
    
$sql "insert into dgn_master_bom(
                mold_refid, bomcategy, itemnoid, qty, uom_qty, price, uom_price, unitprice, createby, createdate, lastupby, lastupdate)
            select :new_refid as mold_refid, bomcategy, itemnoid, qty, uom_qty, price, uom_price, unitprice, createby, createdate, lastupby, lastupdate
             from dgn_master_bom
            where mold_refid = :last_refid"
;
    
$sth $dbh->prepare($sql);
    
$q$sth->execute(  array(':new_refid' => $new_refid,
                            
':last_refid' => $last_refid) );
/*    echo $sth->getSQL(  array(':new_refid' => $new_refid,
                            ':last_refid' => $last_refid) );*/
    
pdo_showerror($sth$q);
}

function 
copy_dgn_master_submold($last_refid$new_refid){
    global 
$dbh;
    
//copy info from last version
    
$sql "insert into dgn_master_submold(
                mold_refid, mold_no, mold_subno, version, qty, img_src, img_path, createby, createdate, lastupby, lastupdate)
            select :new_refid as mold_refid, mold_no, mold_subno, version, qty, img_src, img_path, createby, createdate, lastupby, lastupdate
             from dgn_master_submold
            where mold_refid = :last_refid"
;
    
$sth $dbh->prepare($sql);
    
$q $sth->execute(  array(':new_refid' => $new_refid,
                            
':last_refid' => $last_refid) );
/*    echo $sth->getSQL(  array(':new_refid' => $new_refid,
                            ':last_refid' => $last_refid) );*/
    
pdo_showerror($sth$q);
}

/*
copy_dgn_master_submold(6709, 99);
exit;
*/

function copy_dgn_master_moldimg($last_refid$new_refid){
    global 
$dbh;
    
//copy info from last version
    
$sql "INSERT INTO dgn_master_moldimg(
                mold_refid, img_type, img_src, img_path, createby, createdate, lastupby, lastupdate)
            SELECT :new_refid as mold_refid, img_type, img_src, img_path, createby, createdate, lastupby, lastupdate
             FROM dgn_master_moldimg
            WHERE mold_refid = :last_refid"
;
    
$sth $dbh->prepare($sql);
    
$q $sth->execute(  array(':new_refid' => $new_refid,
                            
':last_refid' => $last_refid) );
/*    echo $sth->getSQL(  array(':new_refid' => $new_refid,
                            ':last_refid' => $last_refid) );*/
    
pdo_showerror($sth$q);    
}

function 
copy_dgn_techdrawing_img($last_refid$new_refid){
    global 
$dbh;
    
//copy info from last version
    
$sql "INSERT INTO dgn_techdrawing_img(
                mold_refid, img_src, img_path, createby, createdate, lastupby, lastupdate)
            SELECT :new_refid as mold_refid, img_src, img_path, createby, createdate, lastupby, lastupdate
             FROM dgn_techdrawing_img
            WHERE mold_refid = :last_refid"
;
    
$sth $dbh->prepare($sql);
    
$q $sth->execute(  array(':new_refid' => $new_refid,
                            
':last_refid' => $last_refid) );
/*    echo $sth->getSQL(  array(':new_refid' => $new_refid,
                            ':last_refid' => $last_refid) );*/
    
pdo_showerror($sth$q);        
}

function 
copy_dgn_techdrawing_pdf($last_refid$new_refid){
    global 
$dbh;
    
//copy info from last version
    
$sql "INSERT INTO dgn_techdrawing_pdf(
                mold_refid, img_src, img_path, createby, createdate, lastupby, lastupdate)
            SELECT :new_refid as mold_refid, img_src, img_path, createby, createdate, lastupby, lastupdate
             FROM dgn_techdrawing_pdf
            WHERE mold_refid = :last_refid"
;
    
$sth $dbh->prepare($sql);
    
$q $sth->execute(  array(':new_refid' => $new_refid,
                            
':last_refid' => $last_refid) );
/*    echo $sth->getSQL(  array(':new_refid' => $new_refid,
                            ':last_refid' => $last_refid) );*/
    
pdo_showerror($sth$q);        
}

function 
copy_dgn_master_mold($refid){
    
    global 
$dbh;
    
//copy info from last version
    
$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,
                qtn_price, est_price, remark, client_remark, fmproduct,
                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, wax_wt, uom_waxwt, formolding,
                companyid, finished,
                silver_wt, uom_silverwt, remark_mold, target_wt_ref, productsize, 
                mastersize, isproductsize_range, productsize_fm, productsize_to,
                createby, createdate, lastupby, lastupdate)
            select         
                status, response_date, launch_date, model_maker_name, pdt_type,
                custcode, request_origine, target_wt, uom_wt, target_price,
                qtn_price, est_price, remark, client_remark, fmproduct,
                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, wax_wt, uom_waxwt, formolding,
                companyid, finished,
                silver_wt, uom_silverwt, remark_mold, target_wt_ref, productsize, 
                mastersize, isproductsize_range, productsize_fm, productsize_to,
                createby, createdate, lastupby, lastupdate from dgn_master_mold where             
            refid = :refid"
;
    
$sth $dbh->prepare($sql);
    
$q $sth->execute(  array(':refid' => $refid) );    
    
//echo $sth->getSQL(  array(':refid' => $refid) );    

    
pdo_showerror($sth$q);
    
$new_refid $dbh->lastInsertId();
    
    
copy_dgn_master_BOM($refid$new_refid);
    
copy_dgn_master_submold($refid$new_refid);
    
//copy route
    
bnr_copyRoute('MASTER'$refid$new_refid);
    
    
//copy drawing, technical drawing, td pdf
    
copy_dgn_master_moldimg($refid$new_refid);
    
copy_dgn_techdrawing_img($refid$new_refid);
    
copy_dgn_techdrawing_pdf($refid$new_refid);

    return 
$new_refid;
}

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

if( 
$_POST['action']=="dgn_master_copyform" && !empty($refid) && $row=getDB("dgn_master_mold"$refid) ){

    
$size                 filter_var($_REQUEST['size'], FILTER_SANITIZE_STRING);
    
    
//generals
    
$status             filter_var($row['status'], FILTER_SANITIZE_STRING);    
    
$last_status         filter_var($row['last_status'], FILTER_SANITIZE_STRING);    
    
    
$response_date         filter_var($row['response_date'], FILTER_SANITIZE_STRING);
        
    
$launch_date         filter_var($row['launch_date'], FILTER_SANITIZE_STRING);            
    
$model_maker_name     filter_var($row['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                 = (float)filter_var($row['uom_wt'], FILTER_SANITIZE_STRING);    
    
$target_price         = (float)filter_var($row['target_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);    
    
$est_price             = (float)filter_var($row['est_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);    
    
$qtn_price             = (float)filter_var($row['qtn_price'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);    
    
    
$createby            filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
$lastupby            filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
    
    
//changed to english remark
    
$remark                filter_var($row['remark'], FILTER_SANITIZE_STRING);    
    
//changed to chinese remark    
    
$client_remark        filter_var($row['client_remark'], FILTER_SANITIZE_STRING);
    
    
$uom_cy                 filter_var($row['uom_cy'], FILTER_SANITIZE_STRING);    
    
$target_date         filter_var($row['target_date'], FILTER_SANITIZE_STRING);    
    
    
$request_approval_date     filter_var($row['request_approval_date'], FILTER_SANITIZE_STRING);    
    
$drawing_approval_date     filter_var($row['drawing_approval_date'], FILTER_SANITIZE_STRING);    
    
$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);
    
    
$wax_wt                 = (float)filter_var($row['wax_wt'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_waxwt             filter_var($row['uom_waxwt'], FILTER_SANITIZE_STRING);    
    
$formolding            = empty($row['formolding'])?"false":"true";    
    
$silver_wt             = (float)filter_var($row['silver_wt'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
    
$uom_silverwt        filter_var($row['uom_silverwt'], FILTER_SANITIZE_STRING);
    
$remark_mold        filter_var($row['remark_mold'], FILTER_SANITIZE_STRING);    
    
    
//segments
    
$producttype         filter_var($row['producttype'], FILTER_SANITIZE_STRING);    
    
$moldno             filter_var($row['moldno'], FILTER_SANITIZE_STRING);
    
$moldno                substrstr_pad$moldno    4'0'STR_PAD_LEFT) , 04);    
    
$mattype            filter_var($row['mattype'], FILTER_SANITIZE_STRING);    
    
$matcolor             filter_var($row['matcolor'], FILTER_SANITIZE_STRING);    
    
$finishing             filter_var($row['finishing'], FILTER_SANITIZE_STRING);    
    
$diatype            filter_var($row['diatype'], FILTER_SANITIZE_STRING);    
    
$stonetype             filter_var($row['stonetype'], FILTER_SANITIZE_STRING);
    
$productstonecolor    filter_var($row['productstonecolor'], FILTER_SANITIZE_STRING);    
        
    
$itemno             getItemNo($producttype$moldno$mattype$matcolor$finishing$diatype$stonetype$productstonecolor$size);    
    
    
$pdt_moldno            filter_var($row['pdt_moldno'], FILTER_SANITIZE_STRING);

    
$fmproduct             filter_var($row['fmproduct'], FILTER_SANITIZE_STRING);    
    
$productrefid         filter_var($row['productrefid'], FILTER_SANITIZE_STRING);    
        
    
$target_wt_ref         filter_var($row['target_wt_ref'], FILTER_SANITIZE_STRING);
    
$productsize         filter_var($row['productsize'], FILTER_SANITIZE_STRING);
    
$mastersize         filter_var($row['mastersize'], FILTER_SANITIZE_STRING);
    
$isproductsize_range = empty($row['isproductsize_range'])? '0''1';
    
$productsize_fm        filter_var($row['productsize_fm'], FILTER_SANITIZE_STRING);
    
$productsize_to        filter_var($row['productsize_to'], FILTER_SANITIZE_STRING);
    
//echo "pdt_moldno = $pdt_moldno";
    //echo "<br/> new = $producttype, $moldno";
    // check existance of moldno before insert    
    
if( $pdt_moldno != $producttype $moldno){
        if( 
pdtmold_exist($producttype$moldno$size$drawing_no) ){
            
$msg="$producttype$moldno ($size) is already existed";
            
header("Location: dgn_master_modifyform.php?refid=$refid&edit=1&error=$msg");
            print 
$msg;
            exit;    
        }
    }
    
    
//check size is not exist for the moldno
    
if( moldno_count_mastermold($producttype$moldno$size) > 0){
            
$msg="$producttype$moldno ($size) is already existed";
            
header("Location: dgn_master_modifyform.php?refid=$refid&edit=1&error=$msg");
            print 
$msg;
            exit;    
    }

$dbh->beginTransaction();
    
    
$last_refid $refid;    
    
$refid copy_dgn_master_mold($last_refid);
    
    
//if(empty($pdt_moldno)){
    
$pdt_moldno $producttype $moldno;
    
//}
    

    
$version                 = (int)filter_var($row['version'], FILTER_SANITIZE_NUMBER_INT);

    
    
$sql_param = 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,
                            
                            
':uom_wt' => $uom_wt,
                            
':target_price' => $target_price,
                            
                            
':client_remark' => $client_remark,
                            
':fmproduct' => $fmproduct,
                            
':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,
                            
':wax_wt' => $wax_wt,
                            
':uom_waxwt' => $uom_waxwt,
                            
':formolding' => $formolding,
                            
':silver_wt' => $silver_wt,
                            
':uom_silverwt' => $uom_silverwt,
                            
':remark_mold' => $remark_mold,
                            
':version' => $version,
                            
':pdt_moldno' => $pdt_moldno,
                            
':target_wt_ref' => $target_wt_ref,                            
                            
':isproductsize_range' => $isproductsize_range,
                            
':productsize_fm' => $productsize_fm,
                            
':productsize_to' => $productsize_to,                            
                            
':createby' => $createby,
                            
':lastupby' => $lastupby,
                            
':refid' => $refid,                            
                            
':target_wt' => $target_wt,
                            
':productsize' => $productsize,
                            
':mastersize' => $mastersize,
                            
':remark' => $remark);
    
    if(
havePermission("PPu")){ 
        
$sql_PPu_field="qtn_price = :qtn_price,
                        est_price = :est_price,"
;
                                            
        
$sql_param[':est_price'] = $est_price;
        
$sql_param[':qtn_price'] = $qtn_price;
    }
    
    
//new request record with same request_no
    
$sql "UPDATE dgn_master_mold SET
                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,
                
                
$sql_PPu_field
                
                remark = :remark,
                client_remark = :client_remark,
                fmproduct = :fmproduct,
                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,
                itemno = :itemno,
                wax_wt = :wax_wt,
                uom_waxwt = :uom_waxwt,
                formolding = :formolding,
                silver_wt = :silver_wt, 
                uom_silverwt = :uom_silverwt,
                remark_mold = :remark_mold,
                target_wt_ref = :target_wt_ref,
                productsize = :productsize,
                mastersize = :mastersize,
                isproductsize_range = :isproductsize_range,
                productsize_fm = :productsize_fm,
                productsize_to = :productsize_to,
                createby = :createby,
                createdate = getdate(),
                lastupby = :lastupby,
                lastupdate = getdate()
        WHERE refid = :refid "
;

    
$sth $dbh->prepare($sql);
    
$q $sth->execute$sql_param );                    
    echo 
$sth->getSQL$sql_param  ) . HTML_EOL;        
    
pdo_showerror($sth$q);                


$dbh->commit();
    
    
//header("Location: dgn_master_index.php?act=resume&refid=$refid&msg=Saved.");
            
    
form_dest($row['godest'], $row['formdest']);
    
header("Location: dgn_master_modifyform.php?edit=1&refid=$refid&fmproduct=$fmproduct&productrefid=$productrefid&msg=Saved."); 
    print 
"Saved.";
    exit;
    
    
}
myerror("Invaild request");


?>