<?php 
session_start();
include "../../../config/database.php";
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
include "../../../config/function.php";
$take_action1   = new actionDo();

ini_set('max_input_vars',10000);
ini_set('max_post_vars',10000);
ini_set('max_request_vars',10000);

$month		= $_SESSION['att_month']		= $_POST['month'];
$year		= $_SESSION['att_year']			= $_POST['year'];
$_SESSION['att_state']     =  $state	 	= $_POST['state'];
$invoice_dt	 = $_POST['invoice_dt'];
$person		 = mysql_real_escape_string($_POST['person']);
$total		 = $_POST['total'];
$bill_mode	 = $_POST['bill_mode'];

if($bill_mode !='SALARY')
{
	$month		= $_POST['quarter'];
}
$invoice_no 	= 0;
$invoice_prefix	= "RHLLP/2018-2019/";
$sql_no			= mysql_query("select max(`invoice_no`) from `tbl_invoice` where `invoice_prefix`='$invoice_prefix' ")or die(" line no 28".mysql_error());
$data_no		= mysql_fetch_array($sql_no);
if( ($data_no['max(`invoice_no`)']=='') || ($data_no['max(`invoice_no`)']=='NULL') )
{
	$invoice_no	 = 1001;
}
else
{
	$invoice_no	 = $data_no['max(`invoice_no`)']+1;
}
$excel_type		 = $_POST['excel_type'];
if($excel_type  =='With Excel')
{
	if($_FILES["file"]["size"] > 0)
	 {
		 	$total				= 0;
			$filename 			= $_FILES["file"]["tmp_name"];
			$file 				= fopen($filename, "r");
			$j					= 0;
			while (($emapData   = fgetcsv($file, 10000, ",")) !== FALSE)
			{
				if($j>0)
				{
					$staff_name		= mysql_real_escape_string($emapData[0]);
					$amt			= mysql_real_escape_string($emapData[1]);
					$total			= $total + $amt;
					$sql			= mysql_query(" insert into `tbl_isr_details` set `emp_id`='0', `emp_name`='$staff_name', `state_name`='$state',`invoice_no`='$invoice_no', `invoice_prefix`='$invoice_prefix', `amt`='$amt' ")or die(" line no 54".mysql_error());
				}
				$j++;
			}
	 }
}
else
{
	for($i=0;$i<count($_POST['staff_name']);$i++)
	{
		$sql	 = mysql_query(" insert into `tbl_isr_details` set `emp_id`='0', `emp_name`='".mysql_real_escape_string($_POST['staff_name'][$i])."', `state_name`='$state',`invoice_no`='$invoice_no', `invoice_prefix`='$invoice_prefix', `amt`='".$_POST['staff_amt'][$i]."' ")or die(" line no 64".mysql_error());
	}
}
$calculation_type   		 = 0;
if(isset($_POST['checkbox_val'])&&($_POST['checkbox_val']==1))
{
	$calculation_type   	 = 1;	
}
mysql_query(" insert into `tbl_invoice` SET `invoice_no`='$invoice_no', `invoice_prefix`='$invoice_prefix', `state`='$state',`heading`='$person',`month`='$month',`year`='$year',`amt`='$total',`date`='".date("Y-m-d",strtotime($invoice_dt))."',`bill_type`='Multiple',`calculation_type`='$calculation_type',`bill_mode`='$bill_mode' ")or die(" line no 72".mysql_error());
$print_val		= 1;

?>
<a href="print_invoice.php?invoice_no=<?php echo $invoice_no;?>&invoice_prefix=<?php echo $invoice_prefix;?>">Print Invoice</a>
