$db, "UID"=>$un, "PWD"=>$pass); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { // echo "Connection established.
"; $v1=$_REQUEST['empresa']; $v2=$_REQUEST['bodega']; $v3=$_REQUEST['id']; $v4=$_REQUEST['equipo']; $tsql = " select max(wms.ShipmentId) as 'UID', wms.ItemID as 'itemID', avg(wms.Qty) as 'qty', max(id.configid) as 'type', id.wMSLocationID as 'location', max(id.INVENTSERIALID) as 'country' ,max(bar.ItemBarCode) as 'barcode',max(it.itemname) as 'Description' ,max(wms.ORDERID) as 'ORDERID',max(WMS.ROUTEID) AS 'ROUTEID',max(WMS.INVENTTRANSID) AS 'INVENTRANSID',max(WMS.INVENTDIMID) AS 'INVENTDIMID',avg(unit.factor) as 'factor' from dbo.WMSOrderTrans wms inner join dbo.InventDim id on wms.InventDimid = id.InventDimid and wms.dataareaid = id.dataareaid left join dbo.InventItemBarcode bar on wms.Itemid = bar.Itemid and wms.dataareaid = bar.dataareaid LEFT JOIN INVENTTABLE it ON it.dataareaid=wms.DATAAREAID and it.itemid=wms.ITEMID left JOIN UNITCONVERT unit on id.configid=unit.FROMUNIT and unit.TOUNIT='und' and id.DATAAREAID=unit.dataareaid and unit.ITEMID=wms.ITEMID where wms.SHIPMENTID = $v3 and id.inventlocationid = $v2 and wms.dataareaid = $v1 and WMS.EQUIPO=$v4 group by WMSLOCATIONID,wms.itemid,ORDERID,ROUTEID,wms.INVENTTRANSID order by WMSLOCATIONID asc"; if($v1 == "'top'"){ $tsql = " select max(wms.ShipmentId) as 'UID', wms.ItemID as 'itemID', avg(wms.Qty) as 'qty', max(id.configid) as 'type', id.wMSLocationID as 'location', max(id.INVENTSERIALID) as 'country' ,max(bar.ItemBarCode) as 'barcode',max(it.itemname) as 'Description' ,max(wms.ORDERID) as 'ORDERID',max(WMS.ROUTEID) AS 'ROUTEID',max(WMS.INVENTTRANSID) AS 'INVENTRANSID',max(WMS.INVENTDIMID) AS 'INVENTDIMID',avg(unit.factor) as 'factor' from dbo.WMSOrderTrans wms inner join dbo.InventDim id on wms.InventDimid = id.InventDimid and wms.dataareaid = id.dataareaid left join dbo.InventItemBarcode bar on wms.Itemid = bar.Itemid and wms.dataareaid = bar.dataareaid LEFT JOIN INVENTTABLE it ON it.dataareaid=wms.DATAAREAID and it.itemid=wms.ITEMID left JOIN UNITCONVERT unit on id.configid=unit.FROMUNIT and unit.TOUNIT='und' and id.DATAAREAID=unit.dataareaid and unit.ITEMID=wms.ITEMID where wms.SHIPMENTID = $v3 and id.inventlocationid = $v2 and wms.dataareaid = $v1 group by WMSLOCATIONID,wms.itemid,ORDERID,ROUTEID,wms.INVENTTRANSID order by WMSLOCATIONID asc"; if($v4 == "'Todo'"){ $tsql = " select max(wms.ShipmentId) as 'UID', wms.ItemID as 'itemID', avg(wms.Qty) as 'qty', max(id.configid) as 'type', id.wMSLocationID as 'location', max(id.INVENTSERIALID) as 'country' ,max(bar.ItemBarCode) as 'barcode',max(it.itemname) as 'Description' ,max(wms.ORDERID) as 'ORDERID',max(WMS.ROUTEID) AS 'ROUTEID',max(WMS.INVENTTRANSID) AS 'INVENTRANSID',max(WMS.INVENTDIMID) AS 'INVENTDIMID',avg(unit.factor) as 'factor' from dbo.WMSOrderTrans wms inner join dbo.InventDim id on wms.InventDimid = id.InventDimid and wms.dataareaid = id.dataareaid left join dbo.InventItemBarcode bar on wms.Itemid = bar.Itemid and wms.dataareaid = bar.dataareaid LEFT JOIN INVENTTABLE it ON it.dataareaid=wms.DATAAREAID and it.itemid=wms.ITEMID left JOIN UNITCONVERT unit on id.configid=unit.FROMUNIT and unit.TOUNIT='und' and id.DATAAREAID=unit.dataareaid and unit.ITEMID=wms.ITEMID where wms.SHIPMENTID = $v3 and id.inventlocationid = $v2 and wms.dataareaid = $v1 group by WMSLOCATIONID,wms.itemid,ORDERID,ROUTEID,wms.INVENTTRANSID order by WMSLOCATIONID asc"; } } else if($v4 == "'Todo'"){ $tsql = " select max(wms.ShipmentId) as 'UID', wms.ItemID as 'itemID', avg(wms.Qty) as 'qty', max(id.configid) as 'type', id.wMSLocationID as 'location', max(id.INVENTSERIALID) as 'country' ,max(bar.ItemBarCode) as 'barcode',max(it.itemname) as 'Description' ,max(wms.ORDERID) as 'ORDERID',max(WMS.ROUTEID) AS 'ROUTEID',max(WMS.INVENTTRANSID) AS 'INVENTRANSID',max(WMS.INVENTDIMID) AS 'INVENTDIMID',avg(unit.factor) as 'factor' from dbo.WMSOrderTrans wms inner join dbo.InventDim id on wms.InventDimid = id.InventDimid and wms.dataareaid = id.dataareaid left join dbo.InventItemBarcode bar on wms.Itemid = bar.Itemid and wms.dataareaid = bar.dataareaid LEFT JOIN INVENTTABLE it ON it.dataareaid=wms.DATAAREAID and it.itemid=wms.ITEMID left JOIN UNITCONVERT unit on id.configid=unit.FROMUNIT and unit.TOUNIT='und' and id.DATAAREAID=unit.dataareaid and unit.ITEMID=wms.ITEMID where wms.SHIPMENTID = $v3 and id.inventlocationid = $v2 and wms.dataareaid = $v1 group by WMSLOCATIONID,wms.itemid,ORDERID,ROUTEID,wms.INVENTTRANSID order by WMSLOCATIONID asc"; } $stmt = sqlsrv_query( $conn, $tsql); if( $stmt === false ) { echo "Error in executing query.
"; die( print_r( sqlsrv_errors(), true)); } /* Process results */ $json = array(); do { while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $json[] = $row; } } while ( sqlsrv_next_result($stmt) ); print(json_encode($json)); sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn); }else{ echo "Connection could not be established.
"; die( print_r( sqlsrv_errors(), true)); } ?>