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
|
<?php $formid=$_REQUEST['formid']; require_once "inc/configure.php";
if(havePermission("RTr")==false){ myerror("Invalid Permission"); }
if(havePermission("RTu")==false){ $RT_readonly = ' readonly="readonly" '; }
//preload description of operation and workplace for translate function $sql = "SELECT code, codedesc_en, codedesc_sc from master_operation"; $sth = $dbh->prepare($sql); $sth->execute(); $m_opr = $sth->fetchAll(); //vdump($m_opr);
$sql = "SELECT codeid, codedesc_en, codedesc_sc from master_type_code where typeid = :typeid"; $sth = $dbh->prepare($sql); $sth->execute( array(':typeid'=>"WORKPLACE") ); $m_wp = $sth->fetchAll(); //vdump($m_wp);
function get_master_opr_name($code, $lang=SYS_LANG){ global $m_opr; if(empty($code)){ return; } foreach($m_opr as $key=>$value) { if(array_search($code, $value)) { return $code ." - " .$m_opr[$key]['codedesc_'.$lang]; } } return $code; }
function get_master_wp_name($code, $lang=SYS_LANG){ global $m_wp; if(empty($code)){ return; } foreach($m_wp as $key=>$value) { if(array_search($code, $value)) { return $code ." - " .$m_wp[$key]['codedesc_'.$lang]; } } return $code; }
//---------------------------------------------------------
$totalcost=0;
$mold_refid = $_REQUEST['mold_refid']; $edit=$_REQUEST['edit'];
//check any existed operation of the BOM $sql = "SELECT count(*) as opcount FROM dgn_master_route WHERE dgn_master_route.mold_refid = :mold_refid"; $sth = $dbh->prepare($sql); $sth->execute( array(':mold_refid'=>$mold_refid) ); //echo $sth->getSQL( array(':mold_refid'=>$mold_refid) ); $c = $sth->fetch(); unset($sth); $count = $c['opcount'];
if(empty($mold_refid)){ myerror("Invalid Request"); exit; }
//route $sql = "SELECT * FROM dgn_master_route WHERE dgn_master_route.mold_refid = :mold_refid ORDER BY opr_nbr ASC"; $sth = $dbh->prepare($sql);
$sql2 = "SELECT * FROM dgn_master_subroute WHERE dgn_master_subroute.route_refid = :route_refid ORDER BY dgn_master_subroute.opr_nbr ASC"; $sth2 = $dbh->prepare($sql2);
$sql3 = "SELECT * FROM dgn_master_subsubroute WHERE dgn_master_subsubroute.subroute_refid = :subroute_refid ORDER BY dgn_master_subsubroute.opr_nbr ASC"; $sth3 = $dbh->prepare($sql3);
$entry=1; ?> <p>
<?php if(havePermission("RTu")){ //RT-------------------------------?> <?php if ($edit==1){ ?>
<?php //if($count==0){ if(false){ $editdisplay = ($count==0)? "none":"block"; ?> <a href="dgn_master_route_init.php?mold_refid=<?=$mold_refid?>" onclick="newROUTE()" id="newROUTE" class="newwinbtn fbox"><?=NEW_.WS.ROUTE?></a> <?php } ?> <a href="dgn_master_route_modifyform.php?mold_refid=<?=$mold_refid?>" id="editROUTE" class="newwinbtn fbox" style="display:<?=$editdisplay?>;"><?=EDIT.WS.ROUTE?></a> <a onclick="refreshROUTE()" id="refreshROUTE" class="uibutton pressnhide"><?=REFRESH?></a>
<?php } ?> <?php } // end of RT------------------------------------------------?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tablelist" id="route_table"> <tr> <th>OP#</th> <th><?=OPERATION?></th> <th><?=ITEMNO?></th> <th><?=WORKPLACE?></th> <th><?=QTY?></th> <?php if(havePermission("RPr")){ //RP-------------------------------?> <th><?=UNITPRICE?></th> <th><?=TOTAL?></th> <?php } // end of RP------------------------------------------------?> <!--<th><?=DELETE?></th>--> </tr> <?php
//-----------------------------------------------Execute SQL
$sth->execute( array(':mold_refid'=>$mold_refid) ); //echo $sth->getSQL( array(':mold_refid'=>$mold_refid) ); while($opr = $sth->fetch() ){ $rate=getOprRate($opr['opr_code']); $totalcost += $opr['opr_svc']*$rate['unit_price']; $entry++; ?> <tr class="opr"> <td><?=$opr['opr_nbr']?></td> <td><?=get_master_opr_name($opr['opr_code'])?></td> <td class="code"><?=$opr['itemno']?></td> <td><?=get_master_wp_name($opr['workplace_code'])?></td> <td><?=qtyf($opr['opr_svc'])?><?=$opr['uom_svc']?></td> <?php if(havePermission("RPr")){ //RP-------------------------------?> <td><?=numf($rate['unit_price'])?>/<?=$rate['uom_svc']?></td> <td><input type="text" name="opr[<?=$entry?>][opr_cost]" value="<?=numf($opr['opr_svc']*$rate['unit_price'])?>" class="positive minifield subtotal" readonly="readonly" /></td> <?php } // end of RP------------------------------------------------?> <!--<td><a href="#" class="deleteRowButton uibutton"><?=X?></a></td>--> </tr>
<?php //suboperation $sth2->execute( array(':route_refid'=>$opr['refid']) ); //echo $sth2->getSQL( array(':route_refid'=>$opr['refid']) ); while($subopr = $sth2->fetch() ){ $rate=getOprRate($subopr['opr_code']); $totalcost += $subopr['opr_svc']*$rate['unit_price']; $entry++; ?> <tr class="subopr" style="background-color:#CCC"> <td><?=$opr['opr_nbr']?>.<?=$subopr['opr_nbr']?></td> <td><?=get_master_opr_name($subopr['opr_code'])?></td> <td class="code"><?=$subopr['itemno']?></td> <td><?=get_master_wp_name($subopr['workplace_code'])?></td> <td><?=qtyf($subopr['opr_svc'])?><?=$subopr['uom_svc']?></td> <?php if(havePermission("RPr")){ //RP-------------------------------?> <td><?=numf($rate['unit_price'])?>/<?=$rate['uom_svc']?></td> <td><input type="text" name="subopr[<?=$entry?>][opr_cost]" value="<?=numf($subopr['opr_svc']*$rate['unit_price'])?>" class="positive minifield subtotal" readonly="readonly" /></td> <?php } // end of RP------------------------------------------------?> <!--<td><a href="#" class="deleteRowButton uibutton"><?=X?></a></td>--> </tr> <?php //subsuboperation $sth3->execute( array(':subroute_refid'=>$subopr['refid']) ); //echo $sth->getSQL( ); while($subsubopr = $sth3->fetch() ){ $rate=getOprRate($subsubopr['opr_code']); $totalcost += $subsubopr['opr_svc']*$rate['unit_price']; $entry++; ?> <tr class="subopr" style="background-color:#AAA"> <td><?=$opr['opr_nbr']?>.<?=$subopr['opr_nbr']?>.<?=$subsubopr['opr_nbr']?></td> <td><?=get_master_opr_name($subsubopr['opr_code'])?></td> <td class="code"><?=$subsubopr['itemno']?></td> <td><?=get_master_wp_name($subsubopr['workplace_code'])?></td> <td><?=qtyf($subsubopr['opr_svc'])?><?=$subsubopr['uom_svc']?></td> <?php if(havePermission("RPr")){ //RP-------------------------------?> <td><?=numf($rate['unit_price'])?>/<?=$rate['uom_svc']?></td> <td><input type="text" name="subsubopr[<?=$entry?>][opr_cost]" value="<?=numf($subsubopr['opr_svc']*$rate['unit_price'])?>" class="positive minifield subtotal" readonly="readonly" /></td> <?php } // end of RP------------------------------------------------?> <!--<td><a href="#" class="deleteRowButton uibutton"><?=X?></a></td>--> </tr> <?php } ?> <?php } ?> <?php } ?> </table><br />
<?php if(havePermission("RPr")){ //RP-------------------------------?> <?=TOTAL?>:<input type="text" name="route_total" value="<?=numf($totalcost)?>" id="route_total" class="positive" readonly="readonly" /></p> <?php } // end of RP------------------------------------------------?>
|