/var/www/enzatesting.onesolution.hk/ajax_json_material_detail.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
<?php 
$formid
=$_REQUEST['formid'];
require_once 
"inc/configure.php";

if(
havePermission("DCr")==false
/*|| havePermission("DPr")==false*/){

    
myerror(INVALID.WS.PERMISSION);    
}

$bomcategy=$_REQUEST['bomcategy'];
$refid=(int)$_REQUEST['refid'];

$output=0;

if( 
$_REQUEST['supplier_code'] ){
    
$sql "SELECT
            dbo.master_supplier.*
            FROM
            dbo.master_supplier
            WHERE
            dbo.master_supplier.code = :code"
;
    
$sth $dbh->prepare($sql);
    
$sth->execute( array(':code'=>$_REQUEST['supplier_code']) );
    
//echo $sth->getSQL();
    
if( $row $sth->fetch(PDO::FETCH_ASSOC) ){
        
$supplier_refid $row['refid'];
    }    
    
$byfactory = ($_REQUEST['supplier_code']=='EZH') ? 0;
}else{
    
$supplier_refid=(int)$_REQUEST['supplier_refid'];
    
$byfactory = ($_REQUEST['buyer']=='EZN') ? 0;    
}


//vdump($bomcategy, $refid, $supplier_refid, $byfactory);
if($bomcategy && $refid && $supplier_refid){
    
    
$table inv_getBomcategyTablename($bomcategy);

    
$sql "SELECT
dbo.
$table.*,
dbo.master_supplier_item.uom_cy as supplier_uomcy,
dbo.master_supplier_item.supplier_ref,
dbo.master_supplier_item.price as supplier_price

FROM
dbo.
$table
INNER JOIN dbo.master_supplier_item ON dbo.master_supplier_item.itemnoid = dbo.
$table.refid
WHERE
dbo.master_supplier_item.mastersupplier_refid = :supplier_refid AND
dbo.master_supplier_item.bomcategy = '
$bomcategy' AND
dbo.master_supplier_item.itemnoid = :refid AND
dbo.master_supplier_item.byfactory = :byfactory
"
;

    
$sth $dbh->prepare($sql);
    
$sth->execute(array(':refid'=>$refid':supplier_refid'=>$supplier_refid':byfactory'=>$byfactory));
    
//echo $sth->getSQL(array(':refid'=>$refid, ':supplier_refid'=>$supplier_refid, ':byfactory'=>$byfactory));
    
if($row $sth->fetch(PDO::FETCH_ASSOC) ){
    
        
$output++;
        
        
$row['readyOrder'] = 1;
        
        
$row['bomcategy'] = $bomcategy;
        
$row['price'] = numf($row['supplier_price']);
        
$row['weight'] = numf($row['weight'], 3);
        
$row['href'] = 'inv_'.$bomcategy.'_modifyform.php?refid='.$row['refid'];
        
        if(
$bomcategy=="material"){
            
$mat getDB("inv_material"$refid);
            
$row['price'] = numf(materialCost($mat['mattype']) ,2);    
            
$row['uom_price'] = "gr";
        }
        
/*        if($bomcategy=="accessory"){
            $row['price'] = numf(accessoryUnitPrice($refid));
                //get accessory BOM
            $sql = "SELECT * FROM inv_accessory_bom WHERE inv_acc_refid=:refid";
            $sth = $dbh->prepare($sql);
            $sth->execute(  array(':refid' => $refid) );
            if($abom = $sth->fetch()){
                //$abom_enable = 1;
                $row['price'] = mattypeCost($abom['mattype'], 1.0, $abom['uom_wt'], $abom['uom_unitwt']) + $abom['labor_price'];
            }
        
        }*/

        
print json_encode($row);
    }else{
        print 
json_encode("ERROR");    //return something to the client
    
}
    unset(
$sth);
    
//vdump($abom);
}

if(
$output==0){
    print 
json_encode("ERROR");    //return something to the client
}
//http://localhost/enza/ajax_json_product_detail.php?formid=Order&refid=387
?>