<?php
 
include 'dbconfig.php';
 
$item_code=$_POST['item_code'];
$item_desc=$_POST['item_desc'];
$notrans= $_POST['notrans'];
$kodecab= $_POST['kodecab'];
$typetrans= 'OT';
$custid= $_POST['custid'];
$custname= $_POST['custname'];
$u_name= $_POST['u_name'];
$harga_jual= $_POST['harga_jual'];
$harga_beli= $_POST['harga_beli'];
$disc_val= $_POST['disc_val'];
$idno_link= $_POST['idno_link'];
$qty= $_POST['qty']*-1;
$return_no= $_POST['return_no'];
$nohp= $_POST['nohp'];

//$qty= 1;
//$disc_val= 0;

//$qty=1;
 
 
// Create connection
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}

//echo $item_code;

/*GET ITEM_DESC  
$querydesc="select nama,harga,disc_val,harga_beli from tbl_barang where kode='".$item_code."'";
$descexec = mysqli_query($conn, $querydesc);
$row=mysqli_fetch_row($descexec);
$item_desc=$row[0];
$harga_jual=$row[1];
$harga_beli=$row[3];

 
 
$querydesc2=mysqli_query($conn,"select * from tbl_barang where kode='".$item_code."'");
$checkbarcode=mysqli_num_rows($querydesc2);
if ($checkbarcode==0)
{
 $result["errormsg"]="none";
 $result["item_code"]=$item_code;
 //$result["hit"]=$checkbarcode;
 echo json_encode($result);
 return;

} 
*/
 


if (strlen($item_desc)>0)
{
$query = "insert into Trans1sub (typetrans,kode_cabang,notrans_link,item_code, item_desc, harga_jual,qty,disc_val,harga_beli,custid,custname,user_name,idno_link,return_no,nohp,noposlink) values('".$typetrans."','".$kodecab."','".$notrans."','".$item_code."','".$item_desc."','".$harga_jual."','".$qty."','".$disc_val."','".$harga_beli."','".$custid."','".$custname."','".$u_name."','".$idno_link."','".$return_no."','".$nohp."','".$return_no."')";
$response = mysqli_query($conn, $query) or die('Error query:  '.$query);
}
 
//$query = "insert into Trans1sub (typetrans,kode_cabang,notrans_link,item_code, item_desc, harga_jual,qty,disc_val,harga_beli,custid,custname,user_name,nohp) values('".$typetrans."','".$kodecab."','".$notrans."','".$item_code."','".$item_desc."','".$harga_jual."','".$qty."','".$disc_val."','".$harga_beli."','".$custid."','".$custname."','".$u_name."','".$nohp."')";
 
if ($response==1){
    
     $result["errormsg"]="ok";  
 
    echo json_encode($result);
 
}
 
else{
 
    $result["errormsg"]="failed";
 
    echo json_encode($result);
 
}
 
?>
