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
|
<?php $formid = "Order"; require_once "inc/configure.php";
function splitFinishedCheckout($orddtl_refid){ global $dbh; $sql = "SELECT Count(dbo.ord_txseto.refid) as counter FROM dbo.ord_txmain INNER JOIN dbo.ord_txseto ON dbo.ord_txseto.txmain_refid = dbo.ord_txmain.refid WHERE dbo.ord_txmain.orddtl_refid = :refid AND dbo.ord_txmain.opr_code = 'SETO' AND (dbo.ord_txseto.checkout_time IS NULL OR dbo.ord_txseto.checkout_time = '')"; $sth = $dbh->prepare($sql); $q = $sth->execute( array( ':refid' => $orddtl_refid) ); /*echo $sth->getSQL( array( ':refid' => $orddtl_refid) ).HTML_EOL; */ $row = $sth->fetch(); return $row['counter']==0; }
function seto_finalCheckout($refid, $opr_param){ global $dbh; $txseto = seto_getTxsetoSummary($refid, $opr_param); //update txmain $sql = "UPDATE ord_txmain SET checkoutby = :checkoutby, checkout_time = GETDATE(), ttlwt = :ttlwt, ttlwt_metal = :ttlwt_metal, uom_wt = 'gr', act_svc_duration = :act_svc_duration, lastupby = :lastupby, lastupdate = GETDATE() WHERE refid = :refid AND checkout_time is NULL "; $sth = $dbh->prepare($sql); $q = $sth->execute( array( ':checkoutby' => $opr_param['lastupby'], ':ttlwt' => $txseto['checkout_wt'], ':ttlwt_metal' => $txseto['ttlwt_metal'], ':act_svc_duration' => $txseto['act_svc_duration'], ':lastupby' => $opr_param['lastupby'], ':refid' => $opr_param['txmain_refid']) ); /* echo $sth->getSQL( array( ':checkoutby' => $opr_param['lastupby'], ':ttlwt' => $txseto['checkout_wt'], ':ttlwt_metal' => $txseto['ttlwt_metal'], ':act_svc_duration' => $txseto['act_svc_duration'], ':lastupby' => $opr_param['lastupby'], ':refid' => $opr_param['txmain_refid']) ).HTML_EOL; */
//write #settings to the route for cost reference $sql = "UPDATE ord_route SET act_opr_svc=:act_opr_svc, lastupby = :lastupby, lastupdate = GETDATE(), checkout_time = GETDATE() where (act_opr_svc is NULL OR act_opr_svc=0) AND checkout_time is NULL AND ordtxmain_refid=:txmain_refid"; $sth = $dbh->prepare($sql); $q = $sth->execute( array(':act_opr_svc' => $txseto['ttl_qty'], ':lastupby' => $opr_param['lastupby'], ':txmain_refid' => $opr_param['txmain_refid']) ); /* echo $sth->getSQL( array(':act_opr_svc' => $txseto['ttl_qty'], ':lastupby' => $opr_param['lastupby'], ':txmain_refid' => $opr_param['txmain_refid']) ).HTML_EOL; */ pdo_showerror($sth, $q); }
function seto_getTxsetoSummary($refid, $opr_param){ global $dbh; // get the split weight from subtable /* $sql = "SELECT Sum(dbo.ord_txseto.checkout_wt) AS ttl_wt, Sum(dbo.ord_txseto.act_svc_duration) AS ttl_duration, Sum(dbo.ord_txseto.txqty) as ttl_qty FROM dbo.ord_txseto WHERE dbo.ord_txseto.txmain_refid = :refid ";*/ $sql = "SELECT DISTINCT dbo.ord_txseto.moldno FROM dbo.ord_txseto WHERE dbo.ord_txseto.txmain_refid = :refid "; $sth = $dbh->prepare($sql); $q = $sth->execute( array( ':refid' => $opr_param['txmain_refid']) ); $summary['checkinst_wt'] = 0; $summary['checkout_wt'] = 0; $summary['act_svc_duration'] = 0; while($row=$sth->fetch()){ $sql2 = "SELECT dbo.ord_txseto.worker, dbo.ord_txseto.groupsig, SUM (dbo.ord_txseto.txqty) AS txqty, AVG ( dbo.ord_txseto.act_svc_duration ) AS act_svc_duration, SUM ( dbo.ord_txseto.checkinst_wt ) AS checkinst_wt, MAX ( dbo.ord_txseto.checkout_time ) AS checkout_time, MAX ( dbo.ord_txseto.checkin_time ) AS checkin_time, MAX (dbo.ord_txseto.checkout_wt) AS checkout_wt FROM dbo.ord_txseto WHERE dbo.ord_txseto.txmain_refid = :refid AND dbo.ord_txseto.moldno = :moldno GROUP BY dbo.ord_txseto.groupsig, dbo.ord_txseto.worker ORDER BY checkout_time DESC "; $sth2 = $dbh->prepare($sql2); $q = $sth2->execute( array( ':refid' => $opr_param['txmain_refid'], ':moldno' => $row['moldno']) ); //echo $sth2->getSQL( array( ':refid' => $opr_param['txmain_refid'], ':moldno' => $row['moldno']) ); $row_checkout_wt = 0; while($row2=$sth2->fetch()){ //vdump($row2); $summary['checkinst_wt'] += $row2['checkinst_wt']; $summary['act_svc_duration'] += $row2['act_svc_duration']; if($row_checkout_wt==0 && $row2['checkout_wt']>0){ $row_checkout_wt = $row2['checkout_wt']; } } $summary['checkout_wt'] += $row_checkout_wt; } $summary['ttlwt_metal'] = $summary['checkout_wt'] - $summary['checkinst_wt']; //vdump($summary); return $summary; }
function getTxseto($refid){ global $dbh; $sql = "SELECT * FROM dbo.ord_txseto WHERE refid = :refid"; $sth = $dbh->prepare($sql); $q = $sth->execute( array( ':refid' => $refid) ); $row=$sth->fetch(); return $row; }
$refid = (int) filter_var($_REQUEST['refid'], FILTER_SANITIZE_STRING); //$txmain_refid = (int) filter_var($_REQUEST['txmain_refid'], FILTER_SANITIZE_STRING); //if(true){ if( $_REQUEST['action']=="ord_setd_split_defcheckout" && !empty($refid) ){ //vdump($_REQUEST); $opr_param['opr_code'] = "SETO"; //check the job card status to ensure the JC is ready to checkin $opr = oprReadyForCheckout($refid, $opr_param, $status); //vdump($opr); exit; $opr_param['subtable'] = "ord_txseto"; //$opr_param['php_function'] = "seto_checkin"; $opr_param['moldno'] = $_REQUEST['submold']; //array $opr_param['checkout_wt'] = (float)filter_var($_REQUEST['checkout_wt'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $opr_param['createby'] = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); $opr_param['lastupby'] = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); $opr_param['txmain_refid'] = (int) filter_var($opr['ordtxmain_refid'], FILTER_SANITIZE_STRING); if($status=="OK"){ echo"checkout now"; //update some submold details $dbh->beginTransaction(); //if all submold is already checked out, then checkout the filling operation if(splitFinishedCheckout($refid)){ seto_finalCheckout($refid, $opr_param); } //exit; $dbh->commit(); form_dest($_REQUEST['godest'], $_REQUEST['formdest']); header("Location: ord_setd_index.php?refid=$refid&msg=Saved."); print "Saved."; exit; } if($opr === false){ myerror("Unable to checkout: " . $msg); exit; header("Location: ord_setd_index.php?refid=$refid"); } } myerror("Invalid Request");
?>
|