<?php  
require "commonincludefiles.php";

if($_SESSION['cCompany_id']!="" && isset($_SESSION['cCompany_id']))
{
	$objlms_customerbillMgmt= new lms_customerbillMgmt();

//$objnews_releaseorderMgmt->nro_id=$_POST['nro_id'];
$objlms_customerbillMgmt->invoice_id=$_POST['invoice_id'];
$objlms_customerbillMgmt->invoice_no=$_POST['invoice_no'];
$objlms_customerbillMgmt->billdate = $_POST['billdate'];
$objlms_customerbillMgmt->operator_id=$_POST['operator_idhedden'];


/*$objlms_customerbillMgmt->product_name=$_POST['product_name'];
$objlms_customerbillMgmt->qty=$_POST['qty'];
$objlms_customerbillMgmt->rate=$_POST['rate'];
$objlms_customerbillMgmt->vat=$_POST['vat'];
$objlms_customerbillMgmt->discount=$_POST['discount'];
$objlms_customerbillMgmt->tamount=$_POST['tamount'];*/




	///
	

	
	
/*	$product_name=json_decode(stripslashes($_REQUEST['product_name']));
    $qty=json_decode(stripslashes($_REQUEST['qty']));
   
	$rate=json_decode(stripslashes($_REQUEST['rate']));
	$vat=json_decode(stripslashes($_REQUEST['vat']));
    $discount=json_decode(stripslashes($_REQUEST['discount']));
	$tamount=json_decode(stripslashes($_REQUEST['tamount']));*/
 	
	
 	
	 if($_REQUEST['act'] == "del")
						     {
						  
						         $objlms_customerbillMgmt->deleteinvoice(); 
							 }
	else
	  {						 
	
					 
					/* 	$objlms_customerbillMgmt->product_name=$product_name[$i];
						$objlms_customerbillMgmt->qty=$qty[$i];
						
     					$objlms_customerbillMgmt->rate=$rate[$i];
						$objlms_customerbillMgmt->vat=$vat[$i];
						$objlms_customerbillMgmt->discount=$discount[$i];
						$objlms_customerbillMgmt->tamount=$tamount[$i];*/
					
					 if (isset($_POST["griddata"]))
	  {
				$griddata= stripcslashes( $_POST["griddata"]);
				
	  }
	
	$arr = array();
    $arr = json_decode($griddata,true);	 // without sort
	
	foreach($arr as $key => $value)
		{						
						$objlms_customerbillMgmt->invoice_id=$value['invoice_id'];
						$objlms_customerbillMgmt->product_name=$value['product_name'];
						$objlms_customerbillMgmt->qty=$value['qty'];
     					$objlms_customerbillMgmt->rate=$value['rate'];
						$objlms_customerbillMgmt->vat=$value['vat'];
						$objlms_customerbillMgmt->discount=$value['discount'];
						$total=$value['qty']*$value['rate'];
						$objlms_customerbillMgmt->tamount=$total+($total*$value['vat']/100)-($total*$value['discount']/100);
	 
						   
					if($_REQUEST['hidden_invoice_num']== "0" || $_REQUEST['hidden_invoice_num']== ""){ 
	                              
						  
						    $objlms_customerbillMgmt->addoperatorinvoice(); 
								  }
					else
					   {					 
					        $objlms_customerbillMgmt->editoperatorinvoice();
						 
					   }
		}
						
					
	  }
	 
	/*else{
		
		if($_REQUEST['act'] == "del")
		 {
			 $objnews_releaseorderMgmt->delete();
		 }
		 else
		 {
			 $objnews_releaseorderMgmt->edit();
		  }
	 }*/

	
	echo '{"success":"true","msg":""}';
}
else {
	echo '{"success":"false","msg":"session expiry"}';
}	         
?>
