<?php
session_start();
ob_start();
require "../model/configuration.php";
/* @var $sion type */
$sion = $_POST['sion'];

if (isset($_POST['save_purchase'])) 
{
    if (isset($_SESSION['purchase']) && $_SESSION['purchase'] == 'Purchase') 
	{
        $result = $db->execute("SELECT * FROM transaction_number");
        $row = $result->fetch_assoc();
        $trno = $row['trnno'];
        $nwtnno = $trno + 1;
        $db->execute("update transaction_number set trnno='$nwtnno'");
        $date = date("Y-m-d");
        $prdqty = $db->execute("select * from purchase_temp where permission='".$sion."'");
        while ($tqty = $prdqty->fetch_assoc()) 
		{
  $db->execute("INSERT INTO master_purchase(vendr_id,invoice_date,invoice_no,product_code,product_name,gsm,width,length,price,quantity,discount,tax,permission,entrydate,trnno,user) VALUES('" . $tqty['vendr_id'] . "','" . $tqty['invoice_date'] . "','" . $tqty['invoice_no'] . "','" . $tqty['product_code'] . "','" . $tqty['product_name'] . "','" . $tqty['gsm'] . "','" . $tqty['width'] . "','" . $tqty['length'] . "','" . $tqty['price'] . "','" . $tqty['quantity'] . "','" . $tqty['discount'] . "','" . $tqty['tax'] . "','" . $tqty['permission'] . "','" . $tqty['entrydate'] . "','" . $trno . "','".$_SESSION['UNAME']."')");
        }
        
        $db->execute("delete from purchase_temp where permission='$sion'");
    }
    unset($_SESSION['purchase']);
}
header("location:../Pages/purchase_page.php");
?>