/var/www/enzatesting.onesolution.hk/ivc_fty_addform.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<?php 
$formid 
"Order";
require_once 
"inc/configure.php";

//calculate due date (30days)
$default_duedate = new DateTime("now");
$default_duedate->add(new DateInterval('P30D'));
//echo $default_duedate->format('Y-m-d') . "\n";

if(true){ //allow add product in this status
    
$refid = -9999;
    
$sql_clause " OR (dbo.ord_txpako.status = 'PACKED' AND
(dbo.ord_txpako.direct_sales IS NULL OR dbo.ord_txpako.direct_sales = 0)) "
;
    
$sql_clause_rm " OR (dbo.ord_txpako_rm.status = 'PACKED' AND
(dbo.ord_txpako_rm.direct_sales IS NULL OR dbo.ord_txpako_rm.direct_sales = 0)) "
;
    
$sql_clause_extra " OR (dbo.ord_dtl_extra.pack_status = 'PACKED' AND
(dbo.ord_dtl_extra.direct_sales IS NULL OR dbo.ord_dtl_extra.direct_sales = 0)) "
;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ENZA</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<?php require_once "inc/jsheader.php"?>

<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
    
    $("table.jexpand").jExpand();

    $( "#launch_date" ).datepicker({
        dateFormat: "yy-mm-dd",
        defaultDate: "<?=date("Y-m-d")?>"
    });
                
    $( "#del_date" ).datepicker({
        dateFormat: "yy-mm-dd",
        defaultDate: "<?=$default_duedate->format('Y-m-d')?>"
    });

    $(".submitform").on("click", function(e) {
         $( "#tabs" ).tabs('select', 0);  //goto first tab
    });    
        
    $("input.invoice_checkall").on('change', function(){
        //console.log('checkall');
        var table = $(this).closest(".tablelist");
        var c = this.checked;
        table.find("input.invoice_check").each(function(){
            $(this).prop("checked", c); //apply to all child
            $(this).change();
        });
    });
    
    $("input.invoice_check").on('change', function(){
        //console.log($(this));
        var table = $(this).closest(".tablelist");
        var refid = $(this).prop("name").replace(/[^0-9]+/g, '');  //get orderID in name
        var c = this.checked;
        table.find("input.invoice_check_"+refid).each(function(){
            $(this).prop("checked", c); //apply to all child
            $(this).change();
        });
    });    
    $("input.iv_check").on("change", function(e){
        calculateTotal();
    });
    calculateTotal();
});    

function calculateTotal(){
    var totalcost=0;
    var totalfcost=0;
    var totalprice=0;
    
    $("input.iv_check:checked").each(function(i, ele){
        var row = $(ele).closest("tr.sublevel");
        totalcost += parseFloat(row.find(".rowcost_td").html().replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
        totalfcost += parseFloat(row.find(".rowfcost_td").html().replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
        totalprice += parseFloat(row.find(".rowprice_td").html().replace(/(\d+),(?=\d{3}(\D|$))/g, "$1")) || 0;
    });
    //console.log(totalcost.toFixed(2), totalfcost.toFixed(2), totalprice.toFixed(2));
    $("input.totalcost").val(totalcost.toFixed(2));    
    $("input.totalfcost").val(totalfcost.toFixed(2));    
    $("input.totalprice").val(totalprice.toFixed(2));        
}
function localbind(){}
</script>
<script src="js/jexpand/jExpand.js"></script>
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="ivc_fty_add.php" name="myform" id="myform" method="post" enctype="multipart/form-data">
  <input type="hidden" name="action" value="ivc_fty_addform" />
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td valign="top" class="top"><?php require"mod_webhead.php"?></td>
    </tr>
    <tr>
      <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td valign="top" class="menu_bg"><?php require"mod_menu.php"?></td>
            <td valign="top" class="padding1"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr></tr>
                <tr>
                  <td class="c3_bg"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                      <tr>

                        <td width="20" class="separator"><input type="image" src="image/icon_save.jpg" class="submitform pressnhide2" width="20" height="20" /></td>
                        <td width="20" class="separator"><a href="<?=basename($_SERVER['REQUEST_URI'])?>"><img src="image/icon_undo.jpg" width="20" height="20" /></a></td>

                        <!--<td width="20" class="separator"><img src="image/icon_redo.jpg" width="20" height="20" /></td>
                <td width="20" class="separator"><img src="image/icon_delete.jpg" width="20" height="20" /></td>--> 
                        <!--<td width="20" class="separator"><a href0="pdf_ivc_fty_cdn.php?delnote_nbr=<?=$delnote_nbr?>" id="print_trig" target="_blank"><span class="ui-icon0 ui-icon-print" ><?=PRINT_?></span></a></td>-->
                        <!--<td width="20" class="separator"><a href="#" id="download_trig"><span class="ui-icon0 ui-icon-circle-triangle-s" ></span>
                          <?=FILES?>
                          </a></td>-->
                        <!--<td width="20" class="separator"><a href="dgn_drawing_print.php?refid=<?=$row['refid']?>" target="_new"><?=PRINT_?></a></td>-->
                        <td class="separator stext1"><?=FACTORY?><?=WS?><?=INVOICE?>
                          - <span>
                          <?=ADD?>
                          </span></td>
                        <td class="separator etext1"><?=$row['customer']?>
                          - <span>
                          <?=$row['ivc_nbr']?>
                          </span></td>
                        <td width="200" align="right" class="separator etext2"><?=LAST_MODIFY?>:
                          <?=lastUpdate($row)?></td>
                        <td width="80" align="right" class="separator etext2"><a href="ivc_fty_index.php?act=resume" onclick="return ConfirmSave('myform')" class="closebtn"><?=CLOSE?></a>
                        <input type="hidden" name="godest" id="godest" />
  <input type="hidden" name="formdest" value="ivc_fty_index.php?act=resume" /></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td valign="top" class="c2_bg"><!--main form--> 
                    
                    <!--editable-->
                    
                    <div id="tabs" class="ui-tabs">
                      <ul>
                        <li><a href="#tabs-2">
                          <?=GENERAL?>
                          </a></li>
                        <li><a href="#tabs-4">
                          <?=PRODUCT?>
                          </a></li>
                      </ul>
                      <div id="scontent">
                        <div id="tabs-2">
                          <p>
                          <table>
                            <tr>
                              <td ><?=CUSTOMER?></td>
                              <td ><span id="spryselect1">
                                <select name="ivc_customer">
                                  <option value=""></option>
                                  <?=master_option("COMPANY"$row['ivc_customer'], true)?>
                                </select>
                              </span></td>
                            </tr>
                            <tr>
                              <td ><?=STATUS?></td>
                              <td ><select name="status">
                                  <?=master_option("INVOICE_STATUS"$row['status'], true)?>
                                </select></td>
                            </tr>           
                            <?php if( empty($row['ivc_nbr']) ) {?>
                            <tr>
                              <td ><?=ISSUE?><?=WS?><?=INVOICE?><?=WS?><?=NUMBER?></td>
                              <td ><input type="checkbox" name="issue_ivcnbr"/></td>
                            </tr>                            
                            <?php ?>                                             
                            <tr>
                              <td ><?=LAUNCH_DATE?></td>
                              <td ><input type="text" name="launch_date" id="launch_date_d" value="<?=date("Y-m-d")?>" readonly="readonly" /></td>
                            </tr>
                            <tr>
                              <td ><?=DUE?><?=WS?><?=DATE?></td>
                              <td ><span id="sprytextfield1">
                                <input name="due_date" value="<?=$default_duedate->format('Y-m-d')?>" id="del_date" />
                              </span></td>
                            </tr>                         
                          </table>
                          </p>
                        </div>


                        <div id="tabs-4">
                          <p><table width="100%" id="product_table" border="0" cellpadding="0" cellspacing="0" class="jexpand tablelist nocss floathead">
                  <thead><tr>
                          <th><?=INVOICE?><input type="checkbox" name="invoice_checkall" class="invoice_checkall" /></th>
                        <th><?=ORDER?><?=WS?><?=NUMBER?></th>
                        <th><?=CUSTOMER?><?=WS?><?=NAME?></th>
                        <th><?=LAUNCH_DATE?></th>                        
                        <th><?=DELIVERY?><?=WS?><?=DATE?></th>
                        <th><?=CONFIRM?><?=WS?><?=DATE?></th>
                        <th><?=ORDER?><?=WS?><?=QTY?></th>
                        <th><?=QTY?><?=WS?><?=READY?></th>
                        
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <th><?=TOTAL?><?=WS?><?=ORDER?><?=WS?><?=COST?></th>
                        <th><?=TOTAL?><?=WS?><?=FACTORY?><?=WS?><?=COST?></th>
                        <?php //end of DC-------------------------------------------------?>
                        
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        
                        <th><?=TOTAL?><?=WS?><?=ORDER?><?=WS?><?=AMOUNT?></th>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <th><?=COEF?></th>
                        <?php //end of DC DP--------------------------------------------?>
<!--                        <th><?=CUSTOMER?><?=WS?><?=ORDER?><?=WS?><?=REFERENCE?></th>-->
                        <!--<th><?=STATUS?></th>-->
                    </tr></thead>
                                                        
<?php

    $sql 
"SELECT
    tmp_ord.main_refid AS refid,
    dbo.ord_main.order_nbr,
    dbo.ord_main.custorder_ref,
    dbo.ord_main.launch_date,
    dbo.ord_main.del_date,
    dbo.ord_main.confirm_date,
    dbo.ord_main.remark,
    dbo.ord_main.ttl_qty,
    dbo.master_customer.custname_en,
    dbo.master_customer.custname_sc,
    SUM (tmp_ord.qty_ready) AS qty_ready,
    SUM (tmp_ord.ttlcost) AS ttlcost,
    SUM (tmp_ord.ttlfactcost) AS ttlfactcost,
    SUM (tmp_ord.ttlprice) AS ttlprice
FROM
    (
        (
            SELECT
                dbo.ord_dtl.main_refid,
                dbo.ord_txpako.txqty AS qty_ready,
                dbo.ord_txpako.unitcost AS ttlcost,
                dbo.ord_txpako.unitfactcost AS ttlfactcost,
                (
                    dbo.ord_txpako.unitprice * isnull(dbo.ord_txpako.discount, 1)
                ) AS ttlprice
            FROM
                dbo.ord_txpako
            INNER JOIN dbo.ord_dtl ON dbo.ord_txpako.orddtl_refid = dbo.ord_dtl.refid
            WHERE
            ( dbo.ord_txpako.deleted=0 ) AND
            ( dbo.ord_txpako.ivcfty_refid = :ivcfty_refid_1 
$sql_clause )
        )
        UNION ALL
            (
                SELECT
                    dbo.ord_dtl_extra.main_refid,
                    dbo.ord_dtl_extra.qty AS qty_ready,
                    0 AS ttlcost,
                    0 AS ttlfactcost,
                    (
                        dbo.ord_dtl_extra.unitprice * dbo.ord_dtl_extra.qty * dbo.ord_dtl_extra.discount
                    ) AS ttlprice
                FROM
                    dbo.ord_dtl_extra
                WHERE
                    dbo.ord_dtl_extra.ivcfty_refid = :ivcfty_refid_2
                
$sql_clause_extra
            )
        UNION ALL
            (
                SELECT
                    dbo.ord_dtl_rm.main_refid,
                    dbo.ord_txpako_rm.txqty AS qty_ready,
                    qtyofprice * dbo.ord_txpako_rm.unitcost AS ttlcost,
                    qtyofprice * dbo.ord_txpako_rm.unitfactcost AS ttlfactcost,
                    (
                        qtyofprice * dbo.ord_txpako_rm.unitprice * isnull(dbo.ord_txpako_rm.discount, 1)
                    ) AS ttlprice
                FROM
                    dbo.ord_txpako_rm
                INNER JOIN dbo.ord_dtl_rm ON dbo.ord_txpako_rm.orddtlrm_refid = dbo.ord_dtl_rm.refid
                WHERE
                    dbo.ord_txpako_rm.ivcfty_refid = :ivcfty_refid_3
                
$sql_clause_rm
            )
    ) AS tmp_ord
INNER JOIN dbo.ord_main ON tmp_ord.main_refid = dbo.ord_main.refid
INNER JOIN dbo.master_customer ON dbo.ord_main.custcode = dbo.master_customer.custcode
GROUP BY
    tmp_ord.main_refid,
    dbo.ord_main.order_nbr,
    dbo.ord_main.custorder_ref,
    dbo.ord_main.launch_date,
    dbo.ord_main.del_date,
    dbo.ord_main.confirm_date,
    dbo.ord_main.remark,
    dbo.ord_main.ttl_qty,
    dbo.master_customer.custname_en,
    dbo.master_customer.custname_sc
ORDER BY dbo.ord_main.order_nbr ASC"
;
    
        
    
$sth $dbh->prepare($sql);
    
$q $sth->execute( array(':ivcfty_refid_1'=>$refid
                                
':ivcfty_refid_2'=>$refid
                                
':ivcfty_refid_3'=>$refid) );
//echo $sth->getSQL( array(':ivcfty_refid'=>$refid) ) . HTML_EOL;
    
pdo_showerror($sth$q);
    
$gttl_qty=0;
    
$gttl_ordercost=0;
    
$gttl_factorycost=0;
    
$gttl_orderprice=0;                        
    while(
$row $sth->fetch()) {    
        if(
$row['ttl_orderprice']>0){
            
$row['margin']=($row['ttl_orderprice']-$row['ttl_ordercost'])*100/$row['ttl_orderprice'];
        }else{
            
$row['margin']=0;
        }
        
//$checked = ($row['checkeditem']>0)? 'checked="checked"' : '';
        
$gttl_qty += numf($row['ttl_qty']);
        
$gttl_ordercost += numf($row['ttl_ordercost']);
        
$gttl_factorycost += numf($row['ttl_factcost']);
        
$gttl_orderprice += numf($row['ttl_orderprice']);            
        
        
?>
                  <tr class="mainlevel">
                          <td class="tdalignmid"><input type="checkbox" name="invoice_group[<?=$row['refid']?>]" class="invoice_check" /></td>
                        <td class="code"><a href="javascript:;" class="jexpand_trigger xfont">+</a> <a href="ord_dtl_modifyform.php?refid=<?=$row['refid']?>#tabs-4" class="fbox" ><?=$row['order_nbr']?></a></td>
                        <td><?=$row['custname_'.SYS_LANG]?></td>
                        <td><?=datef($row['launch_date'])?></td>
                        <td><?=datef($row['del_date'])?></td>
                        <td><?=datef($row['confirm_date'])?></td>
                        <td align="right"><?=numf($row['ttl_qty'])?></td>
                        <td align="right"><?=numf($row['qty_ready'])?></td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td align="right"><?=numfs($row['ttlcost'])?></td>
                        <td align="right"><?=numfs($row['ttlfactcost'])?></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td align="right" style="color:#636"><b><?=numfs($row['ttlprice'])?></b></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <td align="right"><?=numfscalcMarginNew($row['ttlprice'], $row['ttlcost']) )?></td>
                        <?php //end of DC DP---------------------------------------------?>
<!--                        <td><?=$row['custorder_ref']?></td>-->
                        <!--<td>&nbsp;</td>-->

                  </tr>

                <tr class="sublevel tdevencolor" style="display: none;">
                          <td>&nbsp;</td>
                        <th>S/N</th>
                        <th><?=ITEMNO?></th>    
                        <th><?=WEIGHT?></th>
                        <th><?=METAL?><?=WS?><?=WEIGHT?></th>                        
                        <th><?=DIAMOND?><?=WS?><?=WEIGHT?></th>
                        <th><?=STONE?><?=WS?><?=WEIGHT?></th>
                        <th><?=QTY?></th>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <th><?=UNIT?><?=WS?><?=COST?></th>
                        <th><?=FACTORY?><?=WS?><?=COST?></th>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <th><?=PRICE?></th>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <th><?=COEF?></th>
                        <?php //end of DC DP----------------------------------------------?>
<!--                        <th>&nbsp;</th>-->
                        <!--<th>&nbsp;</th>-->
                  </tr>
                  
                <?php 
                    $sql2 
"SELECT DISTINCT
dbo.ord_txpako.*,
dbo.ord_dtl.itemno,
dbo.ord_dtl.refid as orddtl_refid
FROM
dbo.ord_main
INNER JOIN dbo.ord_dtl ON dbo.ord_dtl.main_refid = dbo.ord_main.refid
INNER JOIN dbo.ord_txmain ON dbo.ord_txmain.orddtl_refid = dbo.ord_dtl.refid
INNER JOIN dbo.ord_txpako ON dbo.ord_txpako.txmain_refid = dbo.ord_txmain.refid
WHERE
( dbo.ord_txpako.deleted=0 ) AND
(dbo.ord_txpako.ivcfty_refid = :ivcfty_refid 
$sql_clause) AND
(dbo.ord_txpako.direct_sales IS NULL OR dbo.ord_txpako.direct_sales = 0) AND
dbo.ord_main.refid = :refid"
;
                    
$sth2 $dbh->prepare($sql2);
                    
$q $sth2->execute( array(':refid' => $row['refid'], ':ivcfty_refid' => $refid) );
                while( 
$row2 $sth2->fetch() ) {
                        
$discount_price discountPrice($row2['unitprice'], $row2['discount']);
                        
$checked = ($row2['ivcfty_refid']==$refid) ? 'checked="checked"' '';
                
?>
                <tr class="sublevel productrow tdevencolor" style="display: none;">
                        <td class="tdalignmid">
                        <?php if($row2['status']=='RECEIVED') { ?>
                            <input type="hidden" name="invoice_check[<?=$row2['refid']?>]" value="on" readonly="readonly" /><?=RECEIVED?>
                        <?php } else { ?> 
                            <input type="checkbox" name="invoice_check[<?=$row2['refid']?>]" class="invoice_check_<?=$row['refid']?> iv_check" <?=$checked?> <?=$onclick?> />
                        <?php ?></td>
                        <td class="code"><?=generateSN($row2['refid'])?></a></td>
                        <td class="code"><?=ord_htmllink_jobcard($row2['orddtl_refid'], $row2['itemno'], 'class="ctip fbox" ctip="ajax_thumb_inv_product.php?itemno='.$row2['itemno'].'&formid='.$formid.'"')?></td>
                        <td align="right"><?=numf($row2['product_wt'])?>gr</td>                        
                        <td align="right"><?=numf($row2['metal_wt'])?>gr</td>
                        <td align="right"><?=numf($row2['dia_wt'])?><?=$row2['uom_stonewt']?></td>
                        <td align="right"><?=numf($row2['stone_wt'])?><?=$row2['uom_stonewt']?></td>                        
                        <td align="right"><?=numf($row2['txqty'])?></td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td align="right" class="rowcost_td"><?=numfs($row2['unitcost'])?></td>
                        <td align="right" class="rowfcost_td"><?=numfs($row2['unitfactcost'])?></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td align="right" style="color:#636"><b class="rowprice_td"><?=numfs($discount_price)?></b></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <td align="right"><?=numfs(calcMarginNew($discount_price$row2['unitcost']))?></td>
                        <?php //end of DC DP--------------------------------------------?>
                        <!--<td align="right"><?=$row2['status']?></td>-->
                  </tr>
                  <?php ?>  
                  
                                  <?php 
                    $sql2 
"
SELECT
dbo.ord_dtl_rm.itemno,
dbo.ord_dtl_rm.itemnoid,
dbo.ord_dtl_rm.bomcategory,
dbo.ord_txpako_rm.*
FROM
dbo.ord_txpako_rm
INNER JOIN dbo.ord_dtl_rm ON dbo.ord_txpako_rm.orddtlrm_refid = dbo.ord_dtl_rm.refid
WHERE
(dbo.ord_txpako_rm.ivcfty_refid = :ivcfty_refid 
$sql_clause_rm) AND
(dbo.ord_txpako_rm.direct_sales IS NULL OR dbo.ord_txpako_rm.direct_sales = 0) AND
main_refid = :refid
ORDER BY
dbo.ord_txpako_rm.refid ASC"
;
                    
$sth2 $dbh->prepare($sql2);
/*
                    if($row['refid']==684)
                    echo $sth2->getSQL( array(':refid' => $row['refid'], ':ivcfty_refid' => $refid) ).HTML_EOL;
*/
                    
$q $sth2->execute( array(':refid' => $row['refid'], ':ivcfty_refid' => $refid) );
                while( 
$row2 $sth2->fetch() ) {
                        
$discount_price discountPrice($row2['unitprice'], $row2['discount']);
                        
$checked = ($row2['ivcfty_refid']==$refid) ? 'checked="checked"' '';
                        
$table inv_getBomcategyTablename($row2['bomcategory']);
                        
$item getDB($table$row2['itemnoid']);
                
?>
                <tr class="sublevel materialrow tdevencolor" style="display: none;">
                        <td class="tdalignmid">
                        <?php if($row2['status']=='RECEIVED') { ?>
                            <input type="hidden" name="material_check[<?=$row2['refid']?>]" value="on" readonly="readonly" /><?=RECEIVED?>
                        <?php } else { ?> 
                            <input type="checkbox" name="material_check[<?=$row2['refid']?>]" class="invoice_check_<?=$row['refid']?> iv_check" <?=$checked?> <?=$onclick?> />
                        <?php ?></td>
                        <td class="code"><?=generateRMSN($row2['refid'])?></a></td>
                        <td class="code"><?=$row2['itemno']?></td>
                        <!--<td align="right"><?=numf($row2['product_wt'])?>gr</td>                        
                        <td align="right"><?=numf($row2['metal_wt'])?>gr</td>
                        <td align="right"><?=numf($row2['dia_wt'])?><?=$row2['uom_stonewt']?></td>
                        <td align="right"><?=numf($row2['stone_wt'])?><?=$row2['uom_stonewt']?></td>    -->  
                        <td class="tdalignright"><?=numf($row2['rm_wt'] ,3)?> <?=$row2['uom_wt']?></td> 
                        <td colspan="3"><?=$item['name_'.SYS_LANG]?></td>                   
                        <td align="right"><?=numf($row2['txqty'])?> <?=$row2['uom_qty']?></td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td align="right" class="rowcost_td"><?=numfs($row2['unitcost'])?></td>
                        <td align="right" class="rowfcost_td"><?=numfs($row2['unitfactcost'])?></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td align="right" style="color:#636"><b class="rowprice_td"><?=numfs($discount_price)?></b></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <td align="right"><?=numfs(calcMarginNew($discount_price$row2['unitcost']))?></td>
                        <?php //end of DC DP--------------------------------------------?>
                        <!--<td align="right"><?=$row2['status']?></td>-->
                  </tr>
                  <?php ?>
                  
                  
                <?php 
                    $sql2 
"SELECT
dbo.ord_dtl_extra.*

FROM
dbo.ord_dtl_extra
WHERE
(dbo.ord_dtl_extra.ivcfty_refid = :ivcfty_refid 
$sql_clause_extra) AND
(dbo.ord_dtl_extra.direct_sales IS NULL OR dbo.ord_dtl_extra.direct_sales = 0) AND
main_refid = :refid
ORDER BY
dbo.ord_dtl_extra.refid ASC"
;
                    
$sth2 $dbh->prepare($sql2);
                    
$q $sth2->execute( array(':refid' => $row['refid'], ':ivcfty_refid' => $refid) );
                while( 
$row2 $sth2->fetch() ) {
                        
$discount_price discountPrice($row2['unitprice'], $row2['discount']);
                        
$checked = ($row2['ivcfty_refid']==$refid) ? 'checked="checked"' '';
                
?>
                <tr class="sublevel extrarow tdevencolor" style="display: none;">
                        <td class="tdalignmid">
                        <?php if($row2['status']=='RECEIVED') { ?>
                            <input type="hidden" name="extra_check[<?=$row2['refid']?>]" value="on" readonly="readonly" /><?=RECEIVED?>
                        <?php } else { ?> 
                            <input type="checkbox" name="extra_check[<?=$row2['refid']?>]" class="invoice_check_<?=$row['refid']?> iv_check" <?=$checked?> <?=$onclick?> />
                        <?php ?></td>
                        <td class="code"><?=generateExtraSN($row2['refid'])?></a></td>
                        <td class="code"><?=OTHER?></td>
                        <!--<td align="right"><?=numf($row2['product_wt'])?>gr</td>                        
                        <td align="right"><?=numf($row2['metal_wt'])?>gr</td>
                        <td align="right"><?=numf($row2['dia_wt'])?><?=$row2['uom_stonewt']?></td>
                        <td align="right"><?=numf($row2['stone_wt'])?><?=$row2['uom_stonewt']?></td>    -->  
                        <td>&nbsp;</td>
                        <td colspan="3"><?=$row2['desc']?></td>                    
                        <td align="right"><?=numf($row2['qty'])?></td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td align="right" class="rowcost_td"><?=numfs($row2['unitcost'])?></td>
                        <td align="right" class="rowfcost_td"><?=numfs($row2['unitfactcost'])?></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td align="right" style="color:#636"><b class="rowprice_td"><?=numfs($row2['qty']*$discount_price)?></b></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------------?>
                        <td align="right"><?=numfs(calcMarginNew($discount_price$row2['unitcost']))?></td>
                        <?php //end of DC DP--------------------------------------------?>
                        <!--<td align="right"><?=$row2['status']?></td>-->
                  </tr>
                  <?php ?>                  
                             
<?php 

        if(
$gttl_orderprice>0){
            
$gmargin = ($gttl_orderprice-$gttl_ordercost)*100/$gttl_orderprice;
        }else{
            
$gmargin 0;
        }
        
?>
                   <tfoot><tr>
                        <td class="tdbotborder"><?=TOTAL?></td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <td class="tdbotborder">&nbsp;</td>
                        <?php if(havePermission("DCr")){ //DC-------------------------------?>
                        <td class="tdbotborder tdalignright"><input type="text" id="totalcost" class="totalcost shortfield" readonly="readonly" /></td>
                        <td class="tdbotborder tdalignright"><input type="text" id="totalfcost" class="totalfcost shortfield" readonly="readonly" /></td>
                        <?php //end of DC-------------------------------------------------?>
                        <?php if(havePermission("DPr")){ //DP-------------------------------?>
                        <td class="tdbotborder tdalignright"><input type="text" id="totalprice" class="totalprice shortfield" readonly="readonly" /></td>
                        <?php //end of DP-------------------------------------------------?>
                        <?php if(havePermission("DCr") && havePermission("DPr")){ //DC DP--------------------?>
                        <td class="tdbotborder">&nbsp;</td>
                        <?php //end of DC DP----------------------------------------------?>
                        <!--<td class="tdbotborder">&nbsp;</td>-->
                  </tr></tfoot>        
                   </table>
                          </p>
                        </div>
                        
                        

                      </div>
                      <!--end scontent-->
                      <input type="hidden" name="refid" value="<?=$refid?>" id="refid" />
                    </div>
                    
                    <!--end of readonly--> 
                    
                    <!-- end of mainform--></td>
                  <td valign="top"></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
  </table>
</form>

<script>
var ent = Number(<?=$i?>)+1;
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
</script>
</body>
</html>