<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];

mysqli_set_charset($conn,"utf8mb4");

$salevouch = $_REQUEST["salevouch"];
$purvouch = $_REQUEST["purvouch"];
$supplier = $_REQUEST["supplier"];
$billno = $_REQUEST["invno"];
$billdate = $_REQUEST["invdt"];
$recdqty = $_REQUEST["recdqty"];
$recdsqft = $_REQUEST["recdsqft"];
$calby = $_REQUEST["calby"];
$purcost = $_REQUEST["purcost"];
$itemname = trim($_REQUEST["item"]);
$srno = $_REQUEST["srno"];
$complete = $_REQUEST["complete"];
$size = mysqli_real_escape_string($conn,$_REQUEST["size"]);


$date = date("Y-m-d");
if ($complete == "1") {
//    mysqli_query($conn, "Update `saletran` set delvdate='$date' WHERE `vouchno` = '$salevouch' and itemname = '$itemname' ") OR die(mysqli_error($conn));
}

if ($recdqty > 0) {
    mysqli_query($conn, "DELETE FROM `salepurchtemp` WHERE `salevouch` = '$salevouch' AND `purvouch` = '$purvouch' and itemname = '$itemname' and size = '$size' ") OR die(mysqli_error($conn));
//    browse($size);


    mysqli_query($conn, "INSERT INTO `salepurchtemp`(`salevouch`, recdsqft, recdcalby, `supplier`, `billno`, `billdate`, `recdqty`, `purcost`, `itemname`, size, `purvouch`,complete)
                                    VALUES('$salevouch', '$recdsqft', '$calby', '$supplier', '$billno', '$billdate', '$recdqty', '$purcost', '$itemname', '$size', '$purvouch','$complete')") or die(mysqli_error($conn));
}
?>
