<?php
 
include 'dbconfig.php';
 
// Create connection

$nopos=$_POST['nopos'];
$kodecab=$_POST['kodecab'];

//echo $notrans;
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
//$result["errorcode"]="0";
 
$sql = "SELECT idno,item_code,item_desc,harga_jual,qty,disc_val,(harga_jual*qty)-IFNULL(disc_val,0) as subtot,qtyreturn FROM Trans1sub where notrans_link='".$nopos."' and kode_cabang='".$kodecab."' order by idno desc" ;

//$sql = "SELECT item_desc,harga_jual,qty,disc_val FROM Trans1sub order by idno //desc";


//TotSubTot
$subtot = "SELECT sum((harga_jual*qty)-IFNULL(disc_val,0)) as subtot2 FROM Trans1sub where notrans_link='".$nopos."' and kode_cabang='".$kodecab."' " ;
$ressubtot = mysqli_query($conn, $subtot);
$ressubtot2=mysqli_fetch_row($ressubtot);
$numrows=mysqli_query($conn,$sql); 
$numrows2=mysqli_num_rows($numrows);

$ressubtot22=$ressubtot2[0];
 

$res = mysqli_query($conn, $sql);
 
$items = array();
 
 
 
    while($row = mysqli_fetch_object($res)){
 
        array_push($items, $row);
    }
      $result["hit"] = $numrows2;        
      $result["subtot"] = $ressubtot22;  
     $result["errorcode"] = $nopos;
 
    $result["data"] = $items;
   
 
 
echo json_encode($result);
 
mysqli_close($conn);
 
?>
