<?php
 
include 'dbconfig.php';
 
$item_code= $_POST['item_code'];
$notrans= $_POST['notrans'];
$qty= $_POST['qty'];
$disc_val= $_POST['discount'];
$kodecab= $_POST['kodecab'];
$typetrans= $_POST['typetrans'];
$custid= $_POST['custid'];
$custname= $_POST['custname'];
 

//$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];

 

//echo 'para'.$item_desc.'--'.$harga_jual;
 
/* grab the posts from the db */
if (strlen($item_code)>0)
{
$query = "insert into Trans1sub (typetrans,kode_cabang,notrans_link,item_code, item_desc, harga_jual,qty,disc_val,harga_beli,custid,custname) values('".$typetrans."','".$kodecab."','".$notrans."','".$item_code."','".$item_desc."','".$harga_jual."','".$qty."','".$disc_val."','".$harga_beli."','".$custid."','".$custname."')";
$response = mysqli_query($conn, $query) or die('Error query:  '.$query);
}
 /*
if ($id != "0"){
 
$query = "update tbl_barang set nama='".$nama."',kode='".$kode."',harga='".$harga."',harga_beli='".$harga_beli."' where id=".$id;
 
}*/
 

 
$lid = mysqli_insert_id($conn);
 
$result["errormsg"]="okmanualsave";
 
//$result["lid"]="$lid";
 
if ($response == 1){
 
    echo json_encode($result);
 
}
 
else{
 
    $result["errormsg"]="failed";
 
    echo json_encode($result);
 
}
 
?>
