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
|
<?php $formid = "Master"; require_once "inc/configure.php";
if(havePermission("RTu")==false){ myerror("Invalid Permission"); }
// this file is called by dgn_master_add.php to initialize route for mastermold
$createby = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING); $lastupby = filter_var($_SESSION['user'], FILTER_SANITIZE_STRING);
//not used, we can find suboperaton directly function findOperation($mold_refid, $opr_code, $occurence=1){ global $dbh; $sql_sele = "SELECT * FROM dgn_master_route WHERE mold_refid = :mold_refid AND opr_code = :opr_code"; $sth_sele = $dbh->prepare($sql_sele); $q= $sth_sele->execute( array(':mold_refid' => $mold_refid, ':opr_code' => $opr_code) ); pdo_showerror($sth, $q); $row = $sth_sele->fetch(); //vdump($row); return $row['refid']; }
function findSuboperation($mold_refid, $opr_code, $occurence=1){ global $dbh; $sql_sele = "SELECT * FROM dgn_master_subroute WHERE mold_refid = :mold_refid AND opr_code = :opr_code"; $sth_sele = $dbh->prepare($sql_sele); $q= $sth_sele->execute( array(':mold_refid' => $mold_refid, ':opr_code' => $opr_code) ); pdo_showerror($sth, $q); $row = $sth_sele->fetch(); //vdump($row); return $row['refid']; }
function insert_MODStoWAXI($caso_id, $opr_nbr=0){ global $dbh; $nbr = $opr_nbr; //get all material $material_list = getMaterialList(); foreach ($material_list as $material){ insert_MELT_subop($caso_id, $material, $nbr+=10); } }
function removeAllOperation($mold_refid){ global $dbh; $sql = "DELETE from dgn_master_route WHERE mold_refid = :mold_refid"; $sth = $dbh->prepare($sql); $q= $sth->execute( array(':mold_refid' => $mold_refid) ); }
//---copy functions------------------------------------------------- function copyRouteFromDrawing($mold_refid, $drawing_refid){ global $dbh, $createby, $lastupby; //echo "insert operation from $drawing_refid to $mold_refid"; $sql_sele = "SELECT * FROM dgn_route WHERE drawing_refid = :drawing_refid"; $sth_sele = $dbh->prepare($sql_sele); $q= $sth_sele->execute( array(':drawing_refid' => $drawing_refid) ); pdo_showerror($sth, $q); // insert $sql_ins = "INSERT INTO dgn_master_route (opr_nbr, opr_code, workplace_code, mold_refid, opr_svc, uom_svc, itemno, createby, createdate, lastupby, lastupdate) VALUES (:opr_nbr, :opr_code, :workplace_code, :mold_refid, :opr_svc, :uom_svc, :itemno, :createby, getdate(), :lastupby, getdate())"; $sth_ins = $dbh->prepare($sql_ins);
while($row = $sth_sele->fetch()){ $q= $sth_ins->execute( array(':opr_nbr' => (int)$row['opr_nbr'], ':opr_code' => $row['opr_code'], ':workplace_code' => $row['workplace_code'], ':opr_svc' => (float)$row['opr_svc'], ':uom_svc' => $row['uom_svc'], ':itemno' => $row['itemno'], ':mold_refid' => (int)$mold_refid, ':createby' => $createby, ':lastupby' => $lastupby) ); /* echo $sth_ins->getSQL( array(':opr_nbr' => $row['opr_nbr'], ':opr_code' => $row['opr_code'], ':workplace_code' => $row['workplace_code'], ':opr_svc' => $row['opr_svc'], ':uom_svc' => $row['uom_svc'], ':itemno' => $row['itemno'], ':mold_refid' => $mold_refid, ':createby' => $createby, ':lastupby' => $lastupby) ).HTML_EOL; */ pdo_showerror($sth, $q); $moldroute_refid = $dbh->lastInsertId(); copySubrouteFromDrawing($mold_refid, $moldroute_refid, $drawing_refid, $row['refid']); } }
function copySubrouteFromDrawing($mold_refid, $moldroute_refid, $drawing_refid, $drawingroute_refid){ global $dbh, $createby, $lastupby; //echo "insert operation from $drawing_refid to $mold_refid"; $sql_sele = "SELECT * FROM dgn_subroute WHERE drawing_refid = :drawing_refid and route_refid = :route_refid"; $sth_sele = $dbh->prepare($sql_sele); $q= $sth_sele->execute( array(':drawing_refid' => $drawing_refid, ':route_refid' => $drawingroute_refid) ); /* echo $sth_sele->getSQL( array(':drawing_refid' => $drawing_refid, ':route_refid' => $drawingroute_refid) ).HTML_EOL;*/ pdo_showerror($sth, $q); // insert $sql_ins = "INSERT INTO dgn_master_subroute (opr_nbr, opr_code, workplace_code, mold_refid, opr_svc, uom_svc, itemno, route_refid, createby, createdate, lastupby, lastupdate) VALUES (:opr_nbr, :opr_code, :workplace_code, :mold_refid, :opr_svc, :uom_svc, :itemno, :route_refid, :createby, getdate(), :lastupby, getdate())"; $sth_ins = $dbh->prepare($sql_ins);
while($row = $sth_sele->fetch()){ $q= $sth_ins->execute( array(':opr_nbr' => $row['opr_nbr'], ':opr_code' => $row['opr_code'], ':workplace_code' => $row['workplace_code'], ':opr_svc' => $row['opr_svc'], ':uom_svc' => $row['uom_svc'], ':itemno' => $row['itemno'], ':mold_refid' => $mold_refid, ':route_refid' => $moldroute_refid, ':createby' => $createby, ':lastupby' => $lastupby) ); //pdo_showerror($sth, $q); /* echo $sth_ins->getSQL( array(':opr_nbr' => $row['opr_nbr'], ':opr_code' => $row['opr_code'], ':workplace_code' => $row['workplace_code'], ':opr_svc' => $row['opr_svc'], ':uom_svc' => $row['uom_svc'], ':itemno' => $row['itemno'], ':mold_refid' => $mold_refid, ':route_refid' => $moldroute_refid, ':createby' => $createby, ':lastupby' => $lastupby)).HTML_EOL;*/ $moldsubroute_refid = $dbh->lastInsertId(); copySubsubrouteFromDrawing($mold_refid, $moldsubroute_refid, $drawing_refid, $row['refid']); } }
function copySubsubrouteFromDrawing($mold_refid, $moldroute_refid, $drawing_refid, $drawingroute_refid){ global $dbh, $createby, $lastupby; //echo "insert operation from $drawing_refid to $mold_refid"; $sql_sele = "SELECT * FROM dgn_subsubroute WHERE drawing_refid = :drawing_refid and subroute_refid = :subroute_refid"; $sth_sele = $dbh->prepare($sql_sele); $q= $sth_sele->execute( array(':drawing_refid' => $drawing_refid, ':subroute_refid' => $drawingroute_refid) ); /* echo $sth_sele->getSQL( array(':drawing_refid' => $drawing_refid, ':subroute_refid' => $drawingroute_refid) ).HTML_EOL;*/ pdo_showerror($sth, $q); // insert $sql_ins = "INSERT INTO dgn_master_subsubroute (opr_nbr, opr_code, workplace_code, mold_refid, opr_svc, uom_svc, itemno, subroute_refid, createby, createdate, lastupby, lastupdate) VALUES (:opr_nbr, :opr_code, :workplace_code, :mold_refid, :opr_svc, :uom_svc, :itemno, :subroute_refid, :createby, getdate(), :lastupby, getdate())"; $sth_ins = $dbh->prepare($sql_ins);
while($row = $sth_sele->fetch()){ $q= $sth_ins->execute( array(':opr_nbr' => (int)$row['opr_nbr'], ':opr_code' => $row['opr_code'], ':workplace_code' => $row['workplace_code'], ':opr_svc' => (float)$row['opr_svc'], ':uom_svc' => $row['uom_svc'], ':itemno' => $row['itemno'], ':mold_refid' => (int)$mold_refid, ':subroute_refid' => (int)$moldroute_refid, ':createby' => $createby, ':lastupby' => $lastupby) ); pdo_showerror($sth, $q); /* echo $sth_ins->getSQL( array(':opr_nbr' => $row['opr_nbr'], ':opr_code' => $row['opr_code'], ':workplace_code' => $row['workplace_code'], ':opr_svc' => $row['opr_svc'], ':uom_svc' => $row['uom_svc'], ':itemno' => $row['itemno'], ':subroute_refid' => $mold_refid, ':route_refid' => $moldroute_refid, ':createby' => $createby, ':lastupby' => $lastupby)).HTML_EOL;*/ } }
function copyAllOprFromDrawing($mold_refid, $drawing_refid){ copyRouteFromDrawing($mold_refid, $drawing_refid); }
//------------MAIN-----------------------------------------------------------
function master_route_init($mold_refid, $drawing_refid){ if( !empty($mold_refid) && !empty($drawing_refid)){ $opr_nbr=0; //todo: copy drawing route to master route, insert MODS operation for molds removeAllOperation($mold_refid); copyAllOprFromDrawing($mold_refid, $drawing_refid); //$opid = findOperation($mold_refid, "WAXO"); //$subopid = findSuboperation($mold_refid, "WAXI", $opid); //insert_MODStoWAXI($subopid); } }
?>
|