<?php
session_start();
include 'dbc.php';
date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");
$month = date("m",strtotime($today));
		$year = date("Y",strtotime($today));
		 $month_name = date("F", mktime(0, 0, 0, $month, 10));
		 $my=$month_name . " " . $year;


$userid=$_SESSION["userid"];
$username=$_SESSION["username"];
$acc_name_dr=$_POST["acc_name_dr"];
$size = count($_POST['sale_qty']);

$i = 0;
while ($i < $size) {
	$sale_qty= $_POST['sale_qty'][$i];
	
	$id = $_POST['id'][$i];
	$cname = $_POST['cname'][$i];
	$date = $_POST['date'][$i];
	$netamount= $_POST['netamount'][$i];
	$st= $_POST['st'][$i];
	$stamount= $_POST['stamount'][$i];
	$tnetamount= $_POST['tnetamount'][$i];
	
	$wh_tax= $_POST['wh_tax'][$i];
	
	$status= $_POST['status'][$i];
	$chequeno= $_POST['chequeno'][$i];
	$bankname= $_POST['bankname'][$i];
	
	
	 $whamount=$sale_qty * $wh_tax / 100;
	 $netrecamount=$sale_qty - $whamount;
$balamount=$tnetamount - ($netrecamount + $whamount);

if($sale_qty > 0)
{
	
	$sql2 = "UPDATE invoice_st SET status='$status',cashrec='$netrecamount',balret='$balamount',wh_tax='$wh_tax',whamount='$whamount' WHERE id='$id'";
$conn->query($sql2);
 	
	$sql = "Insert into cashrec (id,date,month_name,ven_name,username,user_id,netamount,venid,disc,wh_tax,whamount,chequeno,bankname,remarks) values (null,'$today','$my','$cname','$username','$userid','$netrecamount','$acc_name_dr','$id','$wh_tax','$whamount','$chequeno','$bankname','No')";
$conn->query($sql);
	}
	++$i;

// do the update and print out some info just to provide some visual feedback



} 
header("location:Receipt_Dashboard.php");

?>
