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
|
<?php $formid = "Stone"; require_once "inc/configure.php"; require_once "inc/ord_dtl_func.php";
$bomrefid = filter_var($_REQUEST['bomrefid'], FILTER_SANITIZE_NUMBER_INT); $act = filter_var($_REQUEST['act'], FILTER_SANITIZE_STRING); $ordbom = getDB("ord_item_bom", $bomrefid); $jc = getDB("ord_dtl", $ordbom['orddtl_refid']);
//vdump($ordbom); //vdump($_REQUEST); if( $_POST['action']=="ord_exchange_replace" && !empty($ordbom) && !empty($jc) ){
$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(); //vdump($ordbom['orddtl_refid'], $txmain['refid']);
$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']);
$param['src_bomcategy'] = $ordbom['bomcategy']; $param['src_itemnoid'] = $ordbom['itemnoid']; $param['src_uom_qty'] = $ordbom['uom_inventory']; $param['src_uom_wt'] = $ordbom['uom_wt']; $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['input_bomcategy'] = $ordbom['bomcategy']; $param['input_itemnoid'] = (float) filter_var($_REQUEST['input_itemnoid'], FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); $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);
$param['worker'] = filter_var($_REQUEST['worker'], FILTER_SANITIZE_STRING); $param['repick_reason'] = filter_var($_REQUEST['repick_reason'], FILTER_SANITIZE_STRING); $param['user'] = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); //vdump($param);
if( $param['src_qty']<=0 || $param['src_wt']<=0 ){ myerror(INVALID.WS.INPUT); exit; } if($param['input_qty']<=0 || $param['input_wt']<=0){ $param['repick_reason'] = 'LOSS'; }
//calculation for modify bom
$mat_qty = $ordbom['qty'] * $jc['qty']; $actual_per_qty = $ordbom['actual_qty'] / $mat_qty;
$damaged_actual = $actual_per_qty * $param['src_qty'];
$new_actual = $ordbom['actual_qty'] - $damaged_actual + $param['src_wt'];
/*vdump($mat_qty, $actual_per_qty, $ordbom['actual_qty'], $damaged_actual, $param['src_wt'], $new_actual); exit;*/
$dbh->beginTransaction();
//repick item (src)
$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, repick_reason, createby, createdate, lastupby, lastupdate ) VALUES ( :txmain_refid, :ordbom_refid, :txqty, :txwt, :uom_qty, :uom_wt, :checkinby, GETDATE(), :checkoutby, GETDATE(), :status, :bomcategy, :itemnoid, :worker, :repick_reason, :createby, GETDATE(), :lastupby, GETDATE() )"; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':txmain_refid' => $txmain['refid'], ':ordbom_refid' => $ordbom['refid'], ':txqty' => $param['src_qty'], ':txwt' => $param['src_wt'], ':uom_qty' => $param['src_uom_qty'], ':uom_wt' => $param['src_uom_wt'], ':checkinby' => $param['user'], ':checkoutby' => $param['user'], ':bomcategy' => $param['src_bomcategy'], ':itemnoid' => $param['src_itemnoid'], ':worker' => $param['worker'], ':repick_reason' => $param['repick_reason'], ':status' => 'PICK', ':createby' => $param['user'], ':lastupby' => $param['user']) ); /* echo $sth->getSQL( array(':txmain_refid' => $txmain['refid'], ':ordbom_refid' => $ordbom['refid'], ':txqty' => $param['src_qty'], ':txwt' => $param['src_wt'], ':uom_qty' => $param['src_uom_qty'], ':uom_wt' => $param['src_uom_wt'], ':checkinby' => $param['checkinby'], ':checkoutby' => $param['checkoutby'], ':worker' => $param['worker'], ':status' => 'RETURN', ':createby' => $param['user'], ':lastupby' => $param['user']) );*/ $ordtxpick_refid = $dbh->lastInsertId();
//return (damaged) 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' => $param['src_uom_qty'], ':uom_wt' => $param['src_uom_wt'], ':checkinby' => $param['user'], ':checkoutby' => $param['user'], ':bomcategy' => $param['input_bomcategy'], ':itemnoid' => $param['input_itemnoid'], ':worker' => $param['worker'], ':repick_reason' => null, ':status' => 'DAMAGE', ':createby' => $param['user'], ':lastupby' => $param['user']) ); /* echo $sth->getSQL( array(':txmain_refid' => $txmain['refid'], ':ordbom_refid' => $ordbom['refid'], ':txqty' => $param['input_qty'], ':txwt' => $param['input_wt'], ':uom_qty' => $param['src_uom_qty'], ':uom_wt' => $param['src_uom_wt'], ':checkinby' => $param['user'], ':checkoutby' => $param['user'], ':bomcategy' => $param['input_bomcategy'], ':itemnoid' => $param['input_itemnoid'], ':worker' => $param['worker'], ':status' => 'PICK', ':createby' => $param['user'], ':lastupby' => $param['user']) ); */ $ordtxpick_return_refid = $dbh->lastInsertId();
//deduct returned qty from actual weight $sql = "UPDATE ord_item_bom SET actual_qty = :actual_qty, lastupby = :lastupby, lastupdate = GETDATE() WHERE refid = :refid"; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':actual_qty' => (float)($ordbom['actual_qty'] - $damaged_actual), //deduct ':lastupby' => $param['user'], ':refid' => $ordbom['refid']) ); pdo_showerror($sth, $q); //exit;
$param['related_oprcode'] = ($_REQUEST['opr_code']=="WHOO")?"":$_REQUEST['opr_code'];
$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' => $param['input_bomcategy'], 'itemnoid' => $param['input_itemnoid'], 'createby' => $param['user'], 'lastupby' => $param['user'], ); txpending_checkin($ordtxpick_return_refid, $opr_param, 'RECEIVED'); //return
$opr_param = array( 'oprcode_fm' => 'WHOO', 'oprcode_to' => $param['related_oprcode'], 'txqty' => (float)$mat_qty, 'txwt' => (float)$new_actual, 'indqty' => (float)$param['src_qty'], 'indwt' => (float)$param['src_wt'], 'orddtl_refid' => $jc['refid'], 'ordbom_refid' => $ordbom['refid'], 'uom_qty' => $ordbom['uom_qty'], 'uom_wt' => $ordbom['uom_wt'], 'bomcategy' => $param['src_bomcategy'], 'itemnoid' => $param['src_itemnoid'], 'createby' => $param['user'], 'lastupby' => $param['user'], ); txpending_checkin($ordtxpick_refid, $opr_param); //picking
//mark there is tx in the new material inv_disableNoStocktake($param['src_bomcategy'], $param['src_itemnoid']); inv_disableNoStocktake($param['input_bomcategy'], $param['input_itemnoid']); //vdump($param['input_bomcategy'], $param['src_itemnoid']); //exit; $dbh->commit(); print SAVED; exit; header("Location: ord_exchange_doneform.php"); print "Saved."; exit;
} myerror(INVALID.WS.REQUEST); exit;
?>
|