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
|
<?php $formid = "Stone"; require_once "inc/configure.php"; require_once "inc/ord_dtl_func.php";
//todo: permission check
function findItemIn_jobcard($orddtl_refid, $bomcategy, $itemnoid){ global $dbh; //$bomtable = inv_getBomcategyTablename($bomcategy); $sql="SELECT TOP(1) * from ord_item_bom where orddtl_refid=:orddtl_refid AND bomcategy=:bomcategy AND itemnoid=:itemnoid "; $sth = $dbh->prepare($sql); $sth->execute( array(':orddtl_refid' => $orddtl_refid, ':bomcategy' => $bomcategy, ':itemnoid' => $itemnoid) ); /* echo $sth->getSQL( array(':orddtl_refid' => $orddtl_refid, ':bomcategy' => $bomcategy, ':itemnoid' => $itemnoid) ).HTML_EOL; */ $row = $sth->fetch(); $sth->closeCursor(); return $row; }
$bomrefid = filter_var($_REQUEST['bomrefid'], FILTER_SANITIZE_NUMBER_INT);
//vdump($_REQUEST); //exit; if( $_POST['action']=="ord_exchange_exchange" && !empty($bomrefid) && $ordbom=getDB("ord_item_bom", $bomrefid) ){
$act = filter_var($_REQUEST['act'], FILTER_SANITIZE_STRING); $bomcategy = filter_var($_REQUEST['bomcategy'], FILTER_SANITIZE_STRING); $bomtable = inv_getBomcategyTablename($bomcategy); $jc = getDB("ord_dtl", $ordbom['orddtl_refid']);
// new txpick to be attached to this txmain $sql="SELECT * from ord_txmain where orddtl_refid=:refid AND opr_code='PICK' "; $sth = $dbh->prepare($sql); $sth->execute( array(':refid' => $ordbom['orddtl_refid']) ); $txmain = $sth->fetch(); $sth->closeCursor();
/* $sql="SELECT * from ord_txpick where ordbom_refid=:refid"; $sth = $dbh->prepare($sql); $sth->execute( array(':refid' => $bomrefid) ); $txpick = $sth->fetch(); $sth->closeCursor(); //vdump($txpick['refid']); */ //old item to safe $param['input_itemnoid'] = $ordbom['itemnoid']; $param['input_uom_qty'] = $ordbom['uom_inventory']; $param['input_uom_wt'] = $ordbom['uom_wt']; $param['input_qty'] = (float) filter_var($_REQUEST['input_qty'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); $param['input_wt'] = (float) filter_var($_REQUEST['input_wt'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
//new item to worker $param['src_itemnoid'] = (float) filter_var($_REQUEST['src_itemnoid'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); $param['src_qty'] = (float) filter_var($_REQUEST['src_qty'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); $param['src_wt'] = (float) filter_var($_REQUEST['src_wt'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
$param['worker'] = filter_var($_REQUEST['worker'], FILTER_SANITIZE_STRING); $param['user'] = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); //vdump($param); $param['related_oprcode'] = ($_REQUEST['opr_code']=="WHOO")?"":$_REQUEST['opr_code'];
if( $param['src_qty']<=0 || $param['src_wt']<=0 ){ myerror(INVALID.WS.INPUT); exit; }
//check item is not ord_txpending.status=='PENDING' $sql = "SELECT count(*) AS cnt FROM ord_txpending WHERE status='PENDING' AND orddtl_refid=:refid"; $sth = $dbh->prepare($sql); // echo $sth->getSQL( array(':refid'=> $jc['refid']) ); $q= $sth->execute( array(':refid'=> $jc['refid']) ); $cnt = $sth->fetch(PDO::FETCH_ASSOC); if($cnt['cnt']>0){ print PLEASE_CONFIRM_RECEIVED_MATERIAL_IN_RETRANSMISSION; exit; }
$dbh->beginTransaction();
//retrun-------------------------------------------------------
$old_qty = ($ordbom['actual_qty']*$jc['qty']) - $param['input_qty']; //vdump($newordbom_refid);
$ordbom = getDB("ord_item_bom", $bomrefid); //get lastest bom values $return_bomqty_change = $ordbom['qty'] - ($param['input_qty'] / $jc['qty']);
//if ord_item_bom qty>0, update //else delete this itembom if( $return_bomqty_change>0 ){ $old_actual = $ordbom['actual_qty'] - $param['input_wt'];
//update (-) BOM actual weight and QTY $sql = "UPDATE ord_item_bom SET qty = :qty, actual_qty = :actual_qty, lastupby = :lastupby, lastupdate = GETDATE() WHERE refid = :refid"; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':qty' => $return_bomqty_change, ':actual_qty' => $old_actual, ':lastupby' => $param['user'], ':refid' => $ordbom['refid']) ); /* echo $sth->getSQL( array(':qty' => $return_bomqty_change, ':actual_qty' => $old_actual, ':lastupby' => $param['user'], ':refid' => $ordbom['refid']) ).HTML_EOL;*/ pdo_showerror($sth, $q);
} else{ $sql = "DELETE FROM ord_item_bom WHERE refid = :refid"; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':refid' => $ordbom['refid']) ); //echo $sth->getSQL( array(':refid' => $ordbom['refid']) ).HTML_EOL; pdo_showerror($sth, $q); } $table = inv_getBomcategyTablename($ordbom['bomcategy']); $item = getDB($table, $ordbom['itemnoid']); bnr_CmpUpdateRouteQty('Order', $ordbom['orddtl_refid'], $ordbom['bomcategy'], $item['itemno'], $return_bomqty_change, $ordbom['qty']);
//return old item $sql = "INSERT into ord_txpick ( txmain_refid, ordbom_refid, txqty, txwt, uom_qty, uom_wt, checkinby, checkin_time, checkoutby, checkout_time, status, bomcategy, itemnoid, worker, createby, createdate, lastupby, lastupdate ) VALUES ( :txmain_refid, :ordbom_refid, :txqty, :txwt, :uom_qty, :uom_wt, :checkinby, GETDATE(), :checkoutby, GETDATE(), :status, :bomcategy, :itemnoid, :worker, :createby, GETDATE(), :lastupby, GETDATE() )"; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':txmain_refid' => $txmain['refid'], ':ordbom_refid' => $ordbom['refid'], ':txqty' => $param['input_qty'], ':txwt' => $param['input_wt'], ':uom_qty' => $ordbom['uom_inventory'], ':uom_wt' => $ordbom['uom_wt'], ':checkinby' => $param['user'], ':checkoutby' => $param['user'], ':bomcategy' => $bomcategy, ':itemnoid' => $param['input_itemnoid'], ':worker' => $param['worker'], ':status' => 'RETURN', ':createby' => $param['user'], ':lastupby' => $param['user']) );
/* echo $sth->getSQL( ).HTML_EOL; */ pdo_showerror($sth, $q);
$ordtxpick_return_refid = $dbh->lastInsertId();
$opr_param = array( 'oprcode_fm' => $param['related_oprcode'], 'oprcode_to' => 'WHOO', 'txqty' => (float)$param['input_qty'], 'txwt' => (float)$param['input_wt'], 'indqty' => (float)$param['input_qty'], 'indwt' => (float)$param['input_wt'], 'orddtl_refid' => $jc['refid'], 'ordbom_refid' => $ordbom['refid'], 'outby' => $param['user'], 'outtime' => date('Y-m-d H:i:s'), 'uom_qty' => $ordbom['uom_qty'], 'uom_wt' => $ordbom['uom_wt'], 'bomcategy' => $bomcategy, 'itemnoid' => $param['input_itemnoid'], 'createby' => $param['user'], 'lastupby' => $param['user'], ); txpending_checkin($ordtxpick_return_refid, $opr_param, 'RECEIVED'); //return
// pick---------------------------------------------------------------------------------------
//find the new item to worker is in the bom list $newitem = getDB($bomtable, $param['src_itemnoid']); $new_ordbom = findItemIn_jobcard($jc['refid'], $bomcategy, $param['src_itemnoid']); $new_item_in_bom = empty($new_ordbom)? false : true; //vdump($bomtable, $newitem);
if($new_ordbom){ $new_actual = $new_ordbom['actual_qty'] + $param['src_wt']; $new_bomqty_change = $new_ordbom['qty'] + ($param['src_qty'] / $jc['qty']);
// use ord_txpending instead //update (+) BOM actual weight and QTY // $sql = "UPDATE ord_item_bom SET // qty = :qty, // actual_qty = :actual_qty, // lastupby = :lastupby, // lastupdate = GETDATE() // WHERE refid = :refid"; // $sth = $dbh->prepare($sql); // $q = $sth->execute( array(':qty' => $new_bomqty_change, // ':actual_qty' => $new_actual, // ':lastupby' => $param['user'], // ':refid' => $new_ordbom['refid']) ); // /* echo $sth->getSQL( array(':qty' => $new_bomqty_change, // ':actual_qty' => $new_actual, // ':lastupby' => $param['user'], // ':refid' => $new_ordbom['refid']) ).HTML_EOL; */ // pdo_showerror($sth, $q);
$newordbom_refid = $new_ordbom['refid'];
} else{ $new_actual = $param['src_wt']; $new_bomqty_change = $param['src_qty'] / $jc['qty'];
//prepare item price for order bom if($bomcategy=='accessory'){ if($newitem['weight']>0){ $newitem['unitprice'] = accessoryUnitPrice($newitem['refid'])/$newitem['weight']; } else{ $newitem['unitprice'] = 0; } $newitem['uom_price'] = $newitem['uom_wt']; } elseif($bomcategy=='material'){ $newitem['unitprice'] = materialUnitPrice($newitem['refid']); $newitem['price'] = $newitem['unitprice']; $newitem['uom_cy'] = "USD"; $newitem['uom_wt'] = "gr"; $newitem['weight'] = 1.0; $newitem['uom_price'] = $newitem['uom_inventory']; } else{ $newitem['unitprice'] = $newitem['price']; } // end of preparation---------------------
$sql = "INSERT INTO ord_item_bom ( orddtl_refid, itemno, qty, actual_qty, weight, uom_wt, price, uom_price, uom_cy, unitprice, bom, itemnoid, bomcategy, uom_qty, createby, createdate, lastupby, lastupdate, uom_actualqty, uom_inventory ) VALUES ( :orddtl_refid, :itemno, :qty, :actual_qty, :weight, :uom_wt, :price, :uom_price, :uom_cy, :unitprice, :bom, :itemnoid, :bomcategy, :uom_qty, :createby, GETDATE(), :lastupby, GETDATE(), :uom_actualqty, :uom_inventory )"; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':orddtl_refid' => $jc['refid'], ':actual_qty' => 0, //use ord_txpending to write the actual qty ':weight' => $newitem['weight'], ':uom_wt' => $newitem['uom_wt'], ':uom_price' => $newitem['uom_price'], ':uom_cy' => $newitem['uom_cy'], ':unitprice' => $newitem['unitprice'], ':itemnoid' => $newitem['refid'], ':bomcategy' => $bomcategy, ':uom_qty' => $newitem['uom_inventory'], ':createby' => $param['user'], ':lastupby' => $param['user'], ':uom_actualqty' => $newitem['uom_price'], ':uom_inventory' => $newitem['uom_inventory'], ':itemno' => $newitem['itemno'], ':bom' => $ordbom['bom'], ':qty' => $new_bomqty_change, ':price' => $newitem['price']) ); /* echo $sth->getSQL( ).HTML_EOL; */ pdo_showerror($sth, $q); $newordbom_refid = $dbh->lastInsertId();
}
$sql = "INSERT into ord_txpick ( txmain_refid, ordbom_refid, txqty, txwt, uom_qty, uom_wt, checkinby, checkin_time, checkoutby, checkout_time, status, bomcategy, itemnoid, worker, createby, createdate, lastupby, lastupdate ) VALUES ( :txmain_refid, :ordbom_refid, :txqty, :txwt, :uom_qty, :uom_wt, :checkinby, GETDATE(), :checkoutby, GETDATE(), :status, :bomcategy, :itemnoid, :worker, :createby, GETDATE(), :lastupby, GETDATE() )"; $sth = $dbh->prepare($sql);
//pick new item $q = $sth->execute( array(':txmain_refid' => $txmain['refid'], ':ordbom_refid' => $newordbom_refid, ':txqty' => $param['src_qty'], ':txwt' => $param['src_wt'], ':uom_qty' => $newitem['uom_inventory'], ':uom_wt' => $newitem['uom_wt'], ':checkinby' => $param['user'], ':checkoutby' => $param['user'], ':bomcategy' => $bomcategy, ':itemnoid' => $newitem['refid'], ':worker' => $param['worker'], ':status' => 'PICK', ':createby' => $param['user'], ':lastupby' => $param['user']) ); /* echo $sth->getSQL( ).HTML_EOL; */ pdo_showerror($sth, $q); $ordtxpick_refid = $dbh->lastInsertId();
$opr_param = array( 'oprcode_fm' => 'WHOO', 'oprcode_to' => $param['related_oprcode'], 'txqty' => (float)$new_bomqty_change*$jc['qty'], 'txwt' => (float)$new_actual, 'indqty' => (float)$param['src_qty'], 'indwt' => (float)$param['src_wt'], 'orddtl_refid' => $jc['refid'], 'ordbom_refid' => $newordbom_refid, 'uom_qty' => $ordbom['uom_qty'], 'uom_wt' => $ordbom['uom_wt'], 'bomcategy' => $bomcategy, 'itemnoid' => $newitem['refid'], 'createby' => $param['user'], 'lastupby' => $param['user'], ); txpending_checkin($ordtxpick_refid, $opr_param);
//todo: update order price ord_updateOrderPureMaterial( ord_getOrdmain_refid($jc['refid']) ); ordmain_markIfFinishedPicking( ord_getOrdmain_refid($jc['refid']) ); updateDtlValue($refid);
//mark there is tx in the old, new material inv_disableNoStocktake($bomcategy, $newitem['refid']); inv_disableNoStocktake($bomcategy, $param['input_itemnoid']);
//exit; $dbh->commit(); print SAVED; exit; header("Location: ord_exchange_doneform.php"); print "Saved."; exit;
} myerror(INVALID.WS.REQUEST); exit;
?>
|