<?php
 
include 'dbconfig.php';
 
// Create connection
$nopos=$_POST['nopos'];
//$kodecab=$_POST['kodecab'];
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
//$result["errorcode"]="0";

//echo $cari."<br>";



 
 

 
//$sql = "SELECT idno,item_code,item_desc,harga_jual,harga_beli,qty,disc_val,custid,custname FROM Trans1sub where typetrans='OT' and  notrans_link like '%$nopos%'  order by idno desc";
//$sql = "SELECT a.idno,a.item_code,a.item_desc,a.harga_jual,a.harga_beli,(a.qty-(IFNULL(b.qtyret,0))) as qty_pos,a.disc_val,a.custid,a.custname,a.nohp FROM Trans1sub a left join (select sum(qty) as qtyret,idno_link,item_code from Trans1ret group by idno_link,item_code ) b on a.idno=b.idno_link and a.item_code=b.item_code  where a.typetrans='OT'  and  a.notrans_link='$nopos'  and (a.qty-(IFNULL(b.qtyret,0)))>0"; 
$sql = "SELECT max(a.idno) as idno,a.item_code,a.item_desc,a.harga_jual,a.harga_beli,sum(a.qty) as qty_pos,a.disc_val,max(a.custid) as custid,max(a.custname) as custname,max(a.nohp) as nohp FROM Trans1sub a   where a.typetrans='OT'  and  noposlink like '%$nopos%' group by a.item_code,a.item_desc,a.harga_jual,a.harga_beli,a.disc_val having sum(a.qty)>0"; 

$res = mysqli_query($conn, $sql);
 
$items = array();
 
if (mysqli_num_rows($res) > 0) {
 
    while($row = mysqli_fetch_object($res)){
 
        array_push($items, $row);
 
//$result["errorcode"] = "1";
 
    $result["data"] = $items;
 
}}
else
{
 
       $result["data"] = "failed";
 
}
 
echo json_encode($result);
 
 
 
mysqli_close($conn);
 
?>
