<?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;
$username=$_SESSION["username"];
$userid=$_SESSION["userid"];
$expdate=$_POST["expdate"];
$v_no=$_POST["vno"];
$acc_name_dr=$_POST["acc_name_dr"];
$disc=$_POST["disc"];
$sqlexp = "SELECT * FROM chartofaccounts where acc_name = '$acc_name_dr' and user_id = '$userid'";
$resultexp=$conn->query($sqlexp);
$rowexp = $resultexp->fetch_assoc();

$acc_symbdr=$rowexp['acc_symb'] ;
$acc_typedr=$rowexp['acc_type'] ;
$size = count($_POST['sale_qty']);

$i = 0;
while ($i < $size) {
	$sale_qty= $_POST['sale_qty'][$i];
	$acc_name = $_POST['acc_name'][$i];
	
	 $acc_type = $_POST['acc_type'][$i];
	  $acc_symb = $_POST['acc_symb'][$i];
	  
   
	// $tamount=$sale_qty * $product_sale;
	 
							
							
							
							
							
	$ledger_amount=$ledger_amount + $sale_qty;

if($sale_qty > 0)
{
	$sql = "Insert into expense_voucher (id,date,month_name,tr_no,acc_name_dr,acc_name_cr,discription,amount,user_id,v_type,mtype,stype,username,yr) values (null,'$expdate','$my','$v_no','$acc_name_dr','$acc_name','$disc','$sale_qty','$userid','Cash Receipt Voucher','$acc_type','$acc_symb','$username','$year')";
$conn->query($sql);

$sql1 = "Insert into acc_ledger (id,date,month_name,tr_no,acc_name,discription,acc_type,dr_amount,cr_amount,balance,user_id,acc_symb) values (null,'$expdate','$my','$v_no','$acc_name','$disc','$acc_type','0','$sale_qty','0','$userid','$acc_symb')";
$conn->query($sql1);

 
		}					


	++$i;

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


} 
//$sql11 = "Insert into expense_voucher (id,date,tr_no,acc_name_dr,discription,amount,user_id,v_type) values (null,'$today','$v_no','$acc_name_dr','$disc','$ledger_amount','$userid','$v_type')";
//mysql_query($sql11) or die("Error : " . mysql_error());

$sql122 = "Insert into acc_ledger (id,date,month_name,tr_no,acc_name,discription,acc_type,dr_amount,cr_amount,balance,user_id,acc_symb) values (null,'$expdate','$my','$v_no','$acc_name_dr','$disc','$acc_typedr','$ledger_amount','0','0','$userid','$acc_symbdr')";
$conn->query($sql122);
echo "Record Update";
//echo"<td> <a href ='open_customers.php?areaname=$party_area'>Click to Main Dashboard</a>";
echo"<td> <a href ='Voucher_Entry.php'>Back</a>";
?>
