/var/www/enzatesting.onesolution.hk/ajax_dgn_item_bom.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php 
$formid
=$_REQUEST['formid'];
require_once 
"inc/configure.php";

if(
havePermission("BMr")==false){
    
myerror("Invalid Permission");    
}

if(
havePermission("BMu")==false){
    
$BM_readonly ' readonly="readonly" ';
}

$product['refid']=(int)$_REQUEST['refid'];
$editable =(int)$_REQUEST['edit'];
if(empty(
$product['refid'])){
    
myerror("Invalid Request");
    exit;    
}

$custcode setDefaultReqVar('custcode''');

 
//get customer material loss from $system_var['LOSS'] to $customer['loss']
$customer getDB_where'master_customer''custcode=:custcode', array( ':custcode'=>$custcode ) );
$a_mat_loss getCustomerMetalLoss$customer );

?><p>

<?php if($editable){ ?>

<?php if(havePermission("BMu")){ //BM-----------------------------?>  
<table width="100%" border="0">
    <tr>
    <td><a id="add_bom_item_button" class="uibutton">+<?=ADD?><?=WS?><?=ITEM?></a></td>
    <td align="right"><a id="refreshtab6" onclick="refreshtab6()" class="uibutton pressnhide"><?=REFRESH?></a></td>
    </tr>
</table>
<?php //BM---------------------------------------------------------?>     

<?php } else{ $readatt'readonly="readonly"';} ?>

    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tablelist" id="bom_table">
    <tr>
        <th><?=BOMCATEGY?></th>
        <th><?=ITEMNO?></th>
        <th style="width:80px"><?=QTY?></th>
<?php if(havePermission("BPr")){ //BP-----------------------------?>     
        <th style="width:80px"><?=UNITPRICE?></th>
        <th><?=TOTAL?><?=WS?><?=PRICE?></th>
<?php //BP---------------------------------------------------------?>     
        <th><?=NAME?></th>
        <th><?=VERIFIED?></th>
        <!--<th>Edit</th>-->
<?php if(havePermission("BMu")){ //BP-----------------------------?>         
        <?php if($editable){ ?><th><?=DELETE?></th><?php ?>
<?php 
//BP---------------------------------------------------------?>              
    </tr>
<?php
$entry
=0;

    
$sql "SELECT
inv_stone.name_en,
inv_stone.name_sc,
inv_stone.refid,
inv_stone.itemno,
inv_stone.uom_cy,
dgn_item_bom.itemnoid,
dgn_item_bom.bomcategy,
dgn_item_bom.qty,
dgn_item_bom.weight,
dgn_item_bom.uom_wt,
dgn_item_bom.price,
inv_stone.uom_inventory as uom_price,
dgn_item_bom.uom_qty,
inv_stone.unitprice,
master_type_code.codedesc_en,
master_type_code.codedesc_sc
FROM
dgn_item_bom
INNER JOIN inv_stone ON dgn_item_bom.itemnoid = inv_stone.refid
INNER JOIN master_type_code ON master_type_code.codeid = inv_stone.verified
WHERE
master_type_code.typeid = 'VERIFIED' AND
dgn_item_bom.bomcategy = 'stone' AND
dgn_item_bom.drawing_refid = :refid
order by inv_stone.itemno"
;        //20210509

// TODO: remove inv_product from sql

//echo $sql;    
    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':refid'=>$product['refid'])  );
    
//echo $sth->getSQL( array(':refid'=>$product['refid'])  );
    
while($row $sth->fetch() ){
        
$row['unitprice']=USD_CNY::getUSDAmount($row['uom_cy'], $row['unitprice']);
        
$entry++; ?>
    <tr class="bomrow">
        <td><?=STONE?><input type="hidden" name="bom_detail[<?=$entry?>][bomcategy]" value="<?=$row['bomcategy']?>" /></td>
        <td class="code"><a href="inv_<?=$row['bomcategy']?>_modifyform.php?refid=<?=$row['refid']?>&act=edit#tabs-2" target="_new" class="fbox"><?=$row['itemno']?></a><input type="hidden" name="bom_detail[<?=$entry?>][itemnoid]" value="<?=$row['itemnoid']?>" /></td>
        <td><input type="text" name="bom_detail[<?=$entry?>][qty]" value="<?=numf($row['qty'])?>" class="positive bomqty minifield" <?=$readatt?> /><?=$row['uom_qty']?><input type="hidden" name="bom_detail[<?=$entry?>][uom_qty]" value="<?=$row['uom_qty']?>"/></td>
<?php if(havePermission("BPr")){ //BP-------------------------------?>         
        <td><input type="text" name="bom_detail[<?=$entry?>][unitprice]" value="<?=numf($row['unitprice'])?>" class="positive bomunitprice minifield" readonly="readonly" />/<?=$row['uom_price']?><input type="hidden" name="bom_detail[<?=$entry?>][uom_price]" value="<?=$row['uom_price']?>" /></td>
        <td><input type="text" name="bom_detail[<?=$entry?>][subtotal]" value="<?=numf(round($row['qty']*$row['unitprice'],2))?>" class="positive bomsubtotal minifield" readonly /></td>
<?php //BP---------------------------------------------------------?>              
        <!--<td><?=$row['weight']?><?=$row['uom_wt']?></td>-->
        <td><?=$row['name_'.SYS_LANG]?></td>
        <td><?=$row['codedesc_'.SYS_LANG]?></td>
        <!--<td><a href="stone_index.php?refid=<?=$row['refid']?>&act=edit#tabs-2" target="_new" class="fbox">Edit</a></td>-->
<?php if(havePermission("BMu")){ //BP-----------------------------?>         
        <?php if($editable){ ?><td><a href="#" class="deleteRowButton uibutton"><?=X?></a></td><?php ?>
<?php 
//BP---------------------------------------------------------?>            
    </tr>
    <?php }    unset($sth);?>
    
<?php
    $sql 
"SELECT
inv_diamond.name_en,
inv_diamond.name_sc,
inv_diamond.refid,
inv_diamond.itemno,
inv_diamond.uom_cy,
dgn_item_bom.itemnoid,
dgn_item_bom.bomcategy,
dgn_item_bom.qty,
dgn_item_bom.weight,
dgn_item_bom.uom_wt,
dgn_item_bom.price,
inv_diamond.uom_inventory as uom_price,
dgn_item_bom.uom_qty,
inv_diamond.unitprice,
master_type_code.codedesc_en,
master_type_code.codedesc_sc
FROM
dgn_item_bom
INNER JOIN inv_diamond ON dgn_item_bom.itemnoid = inv_diamond.refid
INNER JOIN master_type_code ON master_type_code.codeid = inv_diamond.verified
WHERE
master_type_code.typeid = 'VERIFIED' AND
dgn_item_bom.bomcategy = 'diamond' AND
dgn_item_bom.drawing_refid = :refid
order by inv_diamond.itemno"
;        //20210509
//echo $sql;    
    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':refid'=>$product['refid'])  );
    
//echo $sth->getSQL( array(':refid'=>$product['refid'])  );
    
while($row $sth->fetch() ){ 
        
$row['unitprice']=USD_CNY::getUSDAmount($row['uom_cy'], $row['unitprice']);
        
$entry++;?>
    <tr class="bomrow">
        <td><?=DIAMOND?><input type="hidden" name="bom_detail[<?=$entry?>][bomcategy]" value="<?=$row['bomcategy']?>" /></td>
        <td class="code"><a href="inv_<?=$row['bomcategy']?>_modifyform.php?refid=<?=$row['refid']?>&act=edit#tabs-2" target="_new" class="fbox"><?=$row['itemno']?></a><input type="hidden" name="bom_detail[<?=$entry?>][itemnoid]" value="<?=$row['itemnoid']?>" /></td>
        <td><input type="text" name="bom_detail[<?=$entry?>][qty]" value="<?=numf($row['qty'])?>" class="positive bomqty minifield" <?=$readatt?> /><?=$row['uom_qty']?><input type="hidden" name="bom_detail[<?=$entry?>][uom_qty]" value="<?=$row['uom_qty']?>"/></td>
<?php if(havePermission("BPr")){ //BP-------------------------------?>        
        <td><input type="text" name="bom_detail[<?=$entry?>][unitprice]" value="<?=numf($row['unitprice'])?>" class="positive bomunitprice minifield" readonly="readonly"  />/<?=$row['uom_price']?><input type="hidden" name="bom_detail[<?=$entry?>][uom_price]" value="<?=$row['uom_price']?>" /></td>
        <td><input type="text" name="bom_detail[<?=$entry?>][subtotal]" value="<?=numf(round($row['qty']*$row['unitprice'],2))?>" class="positive bomsubtotal minifield" readonly /></td>
<?php //BP---------------------------------------------------------?>              
        <!--<td><?=$row['weight']?><?=$row['uom_wt']?></td>-->
        <td><?=$row['name_'.SYS_LANG]?></td>
        <td><?=$row['codedesc_'.SYS_LANG]?></td>
        <!--<td><a href="stone_index.php?refid=<?=$row['refid']?>&act=edit#tabs-2" target="_new" class="fbox">Edit</a></td>-->
<?php if(havePermission("BMu")){ //BP-----------------------------?>         
        <?php if($editable){ ?><td><a href="#" class="deleteRowButton uibutton"><?=X?></a></td><?php ?>
<?php 
//BP---------------------------------------------------------?>            
        
    </tr>
    <?php }    unset($sth);?>

<?php
    $sql 
"SELECT
inv_accessory.name_en,
inv_accessory.name_sc,
inv_accessory.refid,
inv_accessory.itemno,
inv_accessory.uom_cy,
dgn_item_bom.itemnoid,
dgn_item_bom.bomcategy,
dgn_item_bom.qty,
dgn_item_bom.weight,
dgn_item_bom.uom_wt,
dgn_item_bom.price,
inv_accessory.uom_inventory as uom_price,
dgn_item_bom.uom_qty,
inv_accessory.unitprice,
master_type_code.codedesc_en,
master_type_code.codedesc_sc
FROM
dgn_item_bom
INNER JOIN inv_accessory ON dgn_item_bom.itemnoid = inv_accessory.refid
INNER JOIN master_type_code ON master_type_code.codeid = inv_accessory.verified
WHERE
master_type_code.typeid = 'VERIFIED' AND
dgn_item_bom.bomcategy = 'accessory' AND
dgn_item_bom.drawing_refid = :refid
order by inv_accessory.itemno"
;        //20210509
//echo $sql;    
    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':refid'=>$product['refid'])  );
    
//echo $sth->getSQL( array(':refid'=>$product['refid'])  );
    
while($row $sth->fetch() ){ 
        
$row['unitprice']=USD_CNY::getUSDAmount($row['uom_cy'], accessoryUnitPrice($row['refid']));
        
$entry++;?>
    <tr class="bomrow">
        <td><?=ACCESSORY?><input type="hidden" name="bom_detail[<?=$entry?>][bomcategy]" value="<?=$row['bomcategy']?>" /></td>
        <td class="code"><a href="inv_<?=$row['bomcategy']?>_modifyform.php?refid=<?=$row['refid']?>&act=edit#tabs-2" target="_new" class="fbox"><?=$row['itemno']?></a><input type="hidden" name="bom_detail[<?=$entry?>][itemnoid]" value="<?=$row['itemnoid']?>" /></td>
        <td><input type="text" name="bom_detail[<?=$entry?>][qty]" value="<?=numf($row['qty'])?>" class="positive bomqty minifield" <?=$readatt?> /><?=$row['uom_qty']?><input type="hidden" name="bom_detail[<?=$entry?>][uom_qty]" value="<?=$row['uom_qty']?>"/></td>
<?php if(havePermission("BPr")){ //BP-------------------------------?>        
        <td><input type="text" name="bom_detail[<?=$entry?>][unitprice]" value="<?=numf($row['unitprice'])?>" class="positive bomunitprice minifield" readonly="readonly"  />/<?=$row['uom_price']?><input type="hidden" name="bom_detail[<?=$entry?>][uom_price]" value="<?=$row['uom_price']?>" /></td>
        <td><input type="text" name="bom_detail[<?=$entry?>][subtotal]" value="<?=numf(round($row['qty']*$row['unitprice'],2))?>" class="positive bomsubtotal minifield"  readonly /></td>
<?php //BP---------------------------------------------------------?>              
        <!--<td><?=$row['weight']?><?=$row['uom_wt']?></td>-->
        <td><?=$row['name_'.SYS_LANG]?></td>
        <td><?=$row['codedesc_'.SYS_LANG]?></td>
        <!--<td><a href="stone_index.php?refid=<?=$row['refid']?>&act=edit#tabs-2" target="_new" class="fbox">Edit</a></td>-->
<?php if(havePermission("BMu")){ //BP-----------------------------?>         
        <?php if($editable){ ?><td><a href="#" class="deleteRowButton uibutton"><?=X?></a></td><?php ?>
<?php 
//BP---------------------------------------------------------?>            
    </tr>
    <?php }    unset($sth);?>    

<?php
    $sql 
"SELECT
inv_material.name_en,
inv_material.name_sc,
inv_material.refid,
inv_material.itemno,
dgn_item_bom.itemnoid,
dgn_item_bom.bomcategy,
dgn_item_bom.qty,
dgn_item_bom.weight,
dgn_item_bom.uom_wt,
dgn_item_bom.price,
inv_material.uom_inventory as uom_price,
dgn_item_bom.uom_qty,
dgn_item_bom.unitprice,
master_type_code.codedesc_en,
master_type_code.codedesc_sc
FROM
dgn_item_bom
INNER JOIN inv_material ON dgn_item_bom.itemnoid = inv_material.refid
INNER JOIN master_type_code ON master_type_code.codeid = inv_material.verified
WHERE
master_type_code.typeid = 'VERIFIED' AND
dgn_item_bom.bomcategy = 'material' AND
dgn_item_bom.drawing_refid = :refid
order by inv_material.itemno"
;        //20210509
//echo $sql;    
    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':refid'=>$product['refid'])  );
    while(
$row $sth->fetch() ){ 
        
$entry++;?>
    <tr class="bomrow">
        <td><?=MATERIAL?><input type="hidden" name="bom_detail[<?=$entry?>][bomcategy]" value="<?=$row['bomcategy']?>" /></td>
        <td class="code"><a href="inv_<?=$row['bomcategy']?>_modifyform.php?refid=<?=$row['refid']?>&act=edit#tabs-2" target="_new" class="fbox"><?=$row['itemno']?></a><input type="hidden" name="bom_detail[<?=$entry?>][itemnoid]" value="<?=$row['itemnoid']?>" /></td>
        <td><input type="text" name="bom_detail[<?=$entry?>][qty]" value="<?=numf($row['qty'])?>" class="positive bomqty minifield" <?=$readatt?> /><?=$row['uom_qty']?><input type="hidden" name="bom_detail[<?=$entry?>][uom_qty]" value="<?=$row['uom_qty']?>"/></td>
<?php if(havePermission("BPr")){ //BP-------------------------------?>        
        <td><input type="text" name="bom_detail[<?=$entry?>][unitprice]" value="<?=numf(materialUnitPrice($row['refid'], $a_mat_loss))?>" class="positive bomunitprice minifield" readonly="readonly"  />/<?=$row['uom_price']?><input type="hidden" name="bom_detail[<?=$entry?>][uom_price]" value="<?=$row['uom_price']?>" /></td>
        <td><input type="text" name="bom_detail[<?=$entry?>][subtotal]" value="<?=numf(round($row['qty']*materialUnitPrice($row['refid'], $a_mat_loss),2))?>" class="isMaterial positive bomsubtotal minifield"  readonly /></td>
<?php //BP---------------------------------------------------------?>              
        <!--<td><?=$row['weight']?><?=$row['uom_wt']?></td>-->
        <td><?=$row['name_'.SYS_LANG]?></td>
        <td><?=$row['codedesc_'.SYS_LANG]?></td>
        <!--<td><a href="stone_index.php?refid=<?=$row['refid']?>&act=edit#tabs-2" target="_new" class="fbox">Edit</a></td>-->
<?php if(havePermission("BMu")){ //BP-----------------------------?>         
        <?php if($editable){ ?><td><a href="#" class="deleteRowButton uibutton"><?=X?></a></td><?php ?>
<?php 
//BP---------------------------------------------------------?>              
        
    </tr>
    <?php }    unset($sth);?>    
</table>

<?php if(havePermission("BPr")){ //BP-------------------------------?>
<table width="100%">    
    </tr>
        <td>18K <?=LOSS?>:</td>
        <td><input type="text" name="loss_18k" value="<?=numf($a_mat_loss['loss_18k'])?>" id="loss_18k" class="mat_loss shortfield" readonly="readonly" /></td>
        <td>14K <?=LOSS?>:</td>
        <td><input type="text" name="loss_14k" value="<?=numf($a_mat_loss['loss_14k'])?>" id="loss_14k" class="mat_loss shortfield" readonly="readonly" /></td>
        <td>9K & 10K <?=LOSS?>:</td>
        <td><input type="text" name="loss_9_10k" value="<?=numf($a_mat_loss['loss_9_10k'])?>" id="loss_9_10k" class="mat_loss shortfield" readonly="readonly" /></td>
        <td><?=SILVER.WS.LOSS?>:</td>
        <td><input type="text" name="loss_silver" value="<?=numf($a_mat_loss['loss_silver'])?>" id="loss_silver" class="mat_loss shortfield" readonly="readonly" /></td>
    <tr>
    <tr>
        <td><?=BOM?><?=WS?><?=COST?>:</td>
        <td><input type="text" name="bomcost" id="bomcost" class="bomcost shortfield" readonly="readonly" /></td>
        <td><?=MATERIAL?><?=WS?><?=COST?>:</td>
        <td><input type="text" name="matcost" id="matcost" class="matcost shortfield" readonly="readonly" /></td>    
        <td><?=TOTAL?>:</td>
        <td><input type="text" name="grandtotal" id="grandtotal" class="grandtotal shortfield" readonly="readonly" /></td>
        <td><?=MATERIAL?><?=WS?><?=LOSS?>:</td>
        <td><input type="text" name="mat_loss" value="<?=numf($system_var['LOSS'])?>" id="mat_loss" class="mat_loss shortfield" readonly="readonly" /></td>
    </tr>    
</table>
<?php //BP---------------------------------------------------------?>      
<!--<em>*Please use the refresh button the to view modified master</em>--><br/>
<input type="hidden" name="entry" id="entry" value="<?=++$entry?>" size="5"/>
<!--<input type="submit" name="submit" value="Save"/>--></p>