/var/www/enzatesting.onesolution.hk/ajax_ord_item_route.php


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
<?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;
}

function 
calOprUnitcost($cost$q){
    
$qty = (float)$q;
    if(empty(
$qty)){
        return 
0;
    }
    return 
numf($cost/$qty);
}

//---------------------------------------------------------

$totalcost=0;

$bom=$_REQUEST['bom'];
$prod_qty = (float)$_REQUEST['qty'];

//check any existed operation of the BOM
$sql "SELECT
count(*) as opcount
FROM
ord_route
WHERE
ord_route.orddtl_refid = :bom"
;        
$sth $dbh->prepare($sql);
$sth->execute( array(':bom'=>$bom)  );
$c $sth->fetch();
//unset($sth);
$count $c['opcount'];

if(empty(
$bom)){
    echo 
$sth->getSQL( array(':bom'=>$bom)  );
    
//myerror("Invalid Request");
    
exit;    
}

//route
$sql "SELECT
*
FROM
ord_route
WHERE
ord_route.orddtl_refid = :bom
ORDER BY
opr_nbr ASC"
;        
$sth $dbh->prepare($sql);

$sql2 "SELECT
*
FROM
ord_subroute
WHERE
ord_subroute.ordroute_refid = :route_refid
ORDER BY
ord_subroute.opr_nbr ASC"
;        
$sth2 $dbh->prepare($sql2);

$sql3 "SELECT
*
FROM
ord_subsubroute
WHERE
ord_subsubroute.ordsubroute_refid = :subroute_refid
ORDER BY
ord_subsubroute.opr_nbr ASC"
;        
$sth3 $dbh->prepare($sql3);

$entry=1;
 
?><p>

<?php if(havePermission("RTu")){ //RT-------------------------------?>   
        <?php 
        
if($count==0){ 
        
$editdisplay = ($count==0)? "none":"block";
        
?>
            <a href="ord_dtl_product_route_init.php?jc=<?=$bom?>" onclick="newROUTE()" id="newROUTE" class="newwinbtn fbox"><?=NEW_.WS.ROUTE?></a>&nbsp;
        <?php ?>
            <a href="ord_dtl_product_route_modifyform.php?jc_refid=<?=$bom?>" id="editROUTE" class="newwinbtn fbox" style="display:<?=$editdisplay?>;"><?=EDIT.WS.ROUTE?></a>&nbsp;            
            <a onclick="refreshROUTE()" id="refreshROUTE" class="uibutton pressnhide"><?=REFRESH?></a>
<?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><?=STANDARD?><?=WS?><?=QTY?></th>
        <th><?=ACTUAL?><?=WS?><?=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(':bom'=>$bom)  );
    
//echo $sth->getSQL(  );
    
while($opr $sth->fetch() ){
        
//$rate=getOprRate($opr['opr_code']);
        
$totalcost += numf(itemRouteCost($opr['opr_svc']*$prod_qty$opr['act_opr_svc'], $opr['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']*$prod_qty)?><?=$opr['uom_svc']?></td>
    <td><?=qtyf($opr['act_opr_svc'])?><?=$opr['uom_svc']?></td>
<?php if(havePermission("RPr")){ //RP-------------------------------?>     
    <td><?=numf($opr['unit_price'])?>/<?=$opr['uom_svc']?></td>
    <td><input type="text" name="opr[<?=$entry?>][opr_cost]" value="<?=numf(itemRouteCost($opr['opr_svc']*$prod_qty$opr['act_opr_svc'], $opr['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 += numf(itemRouteCost($subopr['opr_svc']*$prod_qty$subopr['act_opr_svc'], $subopr['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']*$prod_qty)?><?=$subopr['uom_svc']?></td>
        <td><?=qtyf($subopr['act_opr_svc'])?><?=$subopr['uom_svc']?></td>
<?php if(havePermission("RPr")){ //RP-------------------------------?>         
        <td><?=numf($subopr['unit_price'])?>/<?=$subopr['uom_svc']?></td>
        <td><input type="text" name="subopr[<?=$entry?>][opr_cost]" value="<?=numf(itemRouteCost($subopr['opr_svc']*$prod_qty$subopr['act_opr_svc'], $subopr['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 += numf(itemRouteCost($subsubopr['opr_svc']*$prod_qty$subsubopr['act_opr_svc'], $subsubopr['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']*$prod_qty)?><?=$subsubopr['uom_svc']?></td>
        <td><?=qtyf($subsubopr['act_opr_svc'])?><?=$subsubopr['uom_svc']?></td>
<?php if(havePermission("RPr")){ //RP-------------------------------?>         
        <td><?=numf($subsubopr['unit_price'])?>/<?=$subsubopr['uom_svc']?></td>
        <td><input type="text" name="subsubopr[<?=$entry?>][opr_cost]" value="<?=numf(itemRouteCost($subsubopr['opr_svc']*$prod_qty$subsubopr['act_opr_svc'], $subsubopr['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------------------------------------------------------?>