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

$nopos=$_POST['nopos'];
 
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
$sql3="select * from toko_profile";
$res3 = mysqli_query($conn, $sql3);
$row3 = mysqli_fetch_row($res3);

$sql = "SELECT item_code,item_desc,harga_jual,qty,disc_val,custname FROM Trans1sub where notrans_link='".$nopos."'"." order by idno desc" ;

$sql2 = "SELECT sum(harga_jual*qty)-sum(disc_val) as totrp,sum(disc_val) as discount,sum(qty) as totqty,sum(harga_jual) as totharga,sum(qty*harga_jual) as subtotal FROM Trans1sub where notrans_link='".$nopos."'"." order by idno desc" ;

$res2 = mysqli_query($conn, $sql2);
$row2 = mysqli_fetch_row($res2);
//customer from transaksi
$cust=mysqli_query($conn,"select custname,custid from Trans1sub where notrans_link='".$nopos."'");
$rowcust = mysqli_fetch_row($cust);
//customer from tbcustomer
$cust2=mysqli_query($conn,"select nohp,alamat from TbCustomer where custid='".$rowcust[1]."'");
$rowcust2 = mysqli_fetch_row($cust2);



$res = mysqli_query($conn, $sql);


if($res === false) {
  echo "error while executing mysql: " . mysqli_error($conn);
}
 
 $items=array();
 while($row = mysqli_fetch_object($res))
 
 {

 array_push($items,$row);
 $result['data']=$items;

     
 }
 $result['totrp']=$row2[0];
 $result['totdisc']=$row2[1];
 $result['totqty']=$row2[2];
 $result['totharga']=$row2[3];
 $result['subtotal']=$row2[4];
 $result['namatoko']=$row3[3];
 $result['alamattoko']=$row3[4];
 $result['nohptoko']=$row3[5];

  echo json_encode($result);

   
   
 
 

 
mysqli_close($conn);
 
?>
