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

$nopos=$_GET['nopos'];
//echo $notrans;
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
$sql3="select nama_toko,alamat_toko,no_hp_toko 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,notrans_link 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 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);
$reshit=mysqli_num_rows($res);
$item=array();
while($row = mysqli_fetch_object($res)){
 
        array_push($item, $row);
    }
 $result['data']=$item;
 $result['hit']=$reshit;
 $result['ntoko']=$row3[0];
 $result['atoko']=$row3[1];
 $result['hptoko']=$row3[2];
 $result['total']=$row2[0];
 $result['disc']=$row2[1];

 echo json_encode($result);

mysqli_close($conn);
?>