<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$tyrenum_veh='';

include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();

//$tablename='cf_client';

			 $acc_ref=mysql_query("select max(account_reference) as account_reference  from cf_purchase_account");
			 $acc_refrow=mysql_fetch_array($acc_ref);
			 if(mysql_num_rows($acc_ref) >0)
			 {
			 	$acc_reference=$acc_refrow['account_reference'];
			 }
			 else
			 {
			 	$acc_reference=0;
			 }

		if(isset($_POST['boxsubmit'])){
			
			
			if(isset($_POST['group1'])){
			$salestype =addslashes($_POST['group1']);
			}
			
			if(isset($_POST['fromdate'])){
			$from_date=addslashes($_POST['fromdate']);
			$from_date = date('Y-m-d', strtotime($from_date));
			}
			
			if(isset($_POST['salescode'])){
			$salescode=addslashes($_POST['salescode']);
			}
			
			if(isset($_POST['clientbox_id'])){
			$clientid=addslashes($_POST['clientbox_id']);
			}
			
			if(isset($_POST['qty_total_bx'])){
			$packageqty=addslashes($_POST['qty_total_bx']);
			}
			
			$addate = date('Y-m-d');
			
			$sql2 = mysql_query("insert into cf_sales (sales_type,sales_clientid,sales_code,sales_tot,sales_receivable,sales_date,add_date) values ('$salestype','$clientid','$salescode','$packageqty','$packageqty','$from_date','$addate')");			
			$lastid = mysql_insert_id();
			
			$cnt = $_POST['totcnt_box'];
			
			for($i=1;$i<=$cnt;$i++)
			{
				
				if(isset($_POST['product_ids'.$i])){
				$productid=addslashes($_POST['product_ids'.$i]);
				}
				else
				{$productid='';
				}
				
				if(isset($_POST['branch'.$i])){
				$branchid=addslashes($_POST['branch'.$i]);
				}
				else
				{$branchid='';
				}
				
				if(isset($_POST['literqty'.$i])){
				$literqty=addslashes($_POST['literqty'.$i]);
				}else
				{$literqty='';
				}
		
				if(isset($_POST['kg_liter'.$i])){
				$kgliter=addslashes($_POST['kg_liter'.$i]);
				}else
				{$kgliter='';
				}
				
				if(isset($_POST['boxqty'.$i])){
				$boxqty=addslashes($_POST['boxqty'.$i]);
				}else
				{$boxqty='';
				}
				
				if(isset($_POST['rateboxs'.$i])){
				$ratebox=addslashes($_POST['rateboxs'.$i]);
				}else
				{$ratebox='';
				}
				
				if(isset($_POST['damagereturn_qty'.$i])){
				$damagereturnqty=addslashes($_POST['damagereturn_qty'.$i]);
				}else
				{$damagereturnqty='';
				}
				
				if(isset($_POST['linetot'.$i])){
				$linetot=addslashes($_POST['linetot'.$i]);
				}else
				{$linetot='';
				}
				
				if(isset($_POST['narration_box'.$i])){
				$narration_box=addslashes($_POST['narration_box'.$i]);
				}else
				{$narration_box='';
				}
				
				
				if($linetot!='')
				{
				
							
				//echo "<br/>";
				$sql2 = mysql_query("insert into cf_sales_sub (sale_id,prd_id,branch_id,liter_id,sale_no_tin_kg,sale_rate,sale_damage_qty,sale_date,sale_line_tot) values ('$lastid','$productid','$branchid','$literqty','$boxqty','$ratebox','$damagereturnqty','$addate','$linetot')");
				
				
				$result = mysql_query("select * from cf_liter where liter_id = '$literqty' ");
				$rw = mysql_fetch_array($result);
				$liter_box = $rw['liter_boxno'];
				//$kgliter
				/*echo "Literbox".$liter_box;
				echo "<br/>";
				echo "BoxQty".$boxqty;*/
				
				$packqty = $liter_box*$boxqty;
				$qty_kg = $packqty*$kgliter;
				//$demagepackqty = $liter_box*$damagereturnqty;				
				//$qtypack = $packqty+$demagepackqty;
				
				//$qtybox_damage  = $boxqty + $damagereturnqty;
				
				if($productid == 1)
		   		 {
		   			mysql_query("update cf_stock set `stock_palmoil`=`stock_palmoil`-$qty_kg");
		   		 }
				 else if($productid == 2)
				 {
				 	mysql_query("update cf_stock set `stock_coconutoil`=`stock_coconutoil`-$qty_kg");
				 }
				
				$reclientres = mysql_query("select * from cf_ledger where ledgertype = 'clientledger' and empid = '$clientid'");
		    	$clientrw = mysql_fetch_array($reclientres);
		    	$ledgerids = $clientrw['ledgerid'];
				
				$acc_reference=$acc_reference+1;
				$sql31 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type,purpose) values ('$lastid','$linetot','1','1005','$from_date','$addate','$acc_reference','$productid','$narration_box')");
			
			   
			$sql32 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type) values ('$lastid','$linetot','2','$ledgerids','$from_date','$addate','$acc_reference','$productid')");
				
				/*$sqlsku = mysql_query("select * from cf_sku_stock where brnd_id = '$branchid' and ltre_id = '$literqty'");
				$rwsku = mysql_fetch_array($sqlsku);
				if(mysql_num_rows($sqlsku) > 0)
				{
					$skupackqty = $rwsku['packqty'];
					$skupackbox = $rwsku['packbox'];
					$updtpackqty = $skupackqty - $qtypack;
					$updtpackbox = $skupackbox - $qtybox_damage;
					//echo "update cf_sku_stock set packqty = '$updtpackqty',packbox='$updtpackbox' where brnd_id = '$branchid' and ltre_id = '$literqty'";
					mysql_query("update cf_sku_stock set packqty = '$updtpackqty',packbox='$updtpackbox' where brnd_id = '$branchid' and ltre_id = '$literqty'");
					//echo "<br/>";
				}*/
				
				}
					
				}
			
			
			//header("location:sales-list.php");
}

		if(isset($_POST['tinsubmit'])){
		
			if(isset($_POST['group1'])){
			$salestype =addslashes($_POST['group1']);
			}
			
			if(isset($_POST['fromdate1'])){
			$from_date=addslashes($_POST['fromdate1']);
			$from_date = date('Y-m-d', strtotime($from_date));
			}
			
			if(isset($_POST['salescode'])){
			$salescode=addslashes($_POST['salescode']);
			}
			
			if(isset($_POST['clientin_id'])){
			$clientid=addslashes($_POST['clientin_id']);
			}
			
			if(isset($_POST['qty_tin_total'])){
			$qty_tintotal=addslashes($_POST['qty_tin_total']);
			}
			
			/*if(isset($_POST['qty_total'])){
			$packageqty=addslashes($_POST['qty_total']);
			}*/
			
			$addate = date('Y-m-d');
			
			//echo "insert into cf_sales (sales_type,sales_code,sales_date,add_date) values ('$salestype','$salescode','$from_date','$addate')";
			//exit;
			
			$sql2 = mysql_query("insert into cf_sales (sales_type,sales_clientid,sales_code,sales_tot,sales_receivable,sales_date,add_date) values ('$salestype','$clientid','$salescode','$qty_tintotal','$qty_tintotal','$from_date','$addate')");
				$lastid = mysql_insert_id();
				// nithya	
				  
				  mysql_query("update  cf_accountsreceivable set `receiveamount`=`receiveamount`+$qty_tintotal where clientid=$clientid"); 
				  
			//end
				
						
			
			$grand_totin=0;
			$cnt = $_POST['totcntw_tin'];
			for($i=1;$i<=$cnt;$i++)
			{
				
				if(isset($_POST['product_id'.$i])){
				$productid=addslashes($_POST['product_id'.$i]);
				}
				else
				{$productid='';
				}
				
				if(isset($_POST['no_tin'.$i])){
				$notin=addslashes($_POST['no_tin'.$i]);
				}
				else
				{$notin=0;
				}
				
				if(isset($_POST['kg_tin_rate'.$i])){
				$kgtinrate=addslashes($_POST['kg_tin_rate'.$i]);
				}else
				{$kgtinrate='';
				}
		
				if(isset($_POST['tin_damage_return'.$i])){
				$tindamagereturn=addslashes($_POST['tin_damage_return'.$i]);
				}else
				{$tindamagereturn='';
				}
				
				if(isset($_POST['tin_per_rs'.$i])){
				$tinper_rs=addslashes($_POST['tin_per_rs'.$i]);
				}else
				{$tinper_rs='';
				}
								
				if(isset($_POST['tot_tin_line'.$i])){
				$totinline=addslashes($_POST['tot_tin_line'.$i]);
				}else
				{$totinline='';
				}
				
				if(isset($_POST['narration_tin'.$i])){
				$narration_tin=addslashes($_POST['narration_tin'.$i]);
				}else
				{$narration_tin='';
				}
				
				if($totinline!='')
				{
				$tin_sql=mysql_query("select * from cf_tin where status=1");
				  if($tin_sql && mysql_num_rows($tin_sql)>0)
				  {
				  while($tin_row=mysql_fetch_array($tin_sql))
				  {
				  $tin_kg=$tin_row['kg_val'];
				  }
				  }
				  else
				  {
				  $tin_kg=0;
				  }
				
				$tin_tot=$tin_kg*($notin+$tindamagereturn);
				$sql2 = mysql_query("insert into cf_sales_sub (sale_id,prd_id,sale_no_tin_kg,sale_rate,sale_pertin_rs,sale_damage_qty,sale_date,sale_line_tot) values ('$lastid','$productid','$notin','$kgtinrate','$tinper_rs','$tindamagereturn','$addate','$totinline')");
				
				if($productid == 1)
		   		 {
		   			mysql_query("update cf_stock set `stock_palmoil`=`stock_palmoil`-$tin_tot");
		   		 }
				 else if($productid == 2)
				 {
				 	mysql_query("update cf_stock set `stock_coconutoil`=`stock_coconutoil`-$tin_tot");
				 }
					
							
				mysql_query("update cf_stock set `stock_tin`=`stock_tin`-$notin");
				
				 
				//----Tin Sales------------------- 
				
				$reclientres = mysql_query("select * from cf_ledger where ledgertype = 'clientledger' and empid = '$clientid'");
		    	$clientrw = mysql_fetch_array($reclientres);
		    	$ledgerids = $clientrw['ledgerid'];
				
				$acc_reference=$acc_reference+1;
				$sql31 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type,purpose) values ('$lastid','$qty_tintotal','1','1006','$from_date','$addate','$acc_reference','$productid','$narration_tin')");
			
			   
			$sql32 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type) values ('$lastid','$qty_tintotal','2','$ledgerids','$from_date','$addate','$acc_reference','$productid')");
				
				//----End Tin Sales------------------- 
					
				}
				
				}
			
			
			header("location:sales-list.php");
}

		if(isset($_POST['jarsubmit'])){
		
			if(isset($_POST['group1'])){
			$salestype =addslashes($_POST['group1']);
			}
			
			if(isset($_POST['fromdate3'])){
			$from_date=addslashes($_POST['fromdate3']);
			$from_date = date('Y-m-d', strtotime($from_date));
			}
			
			if(isset($_POST['salescode'])){
			$salescode=addslashes($_POST['salescode']);
			}
			
			if(isset($_POST['clientjar_id'])){
			$clientid=addslashes($_POST['clientjar_id']);
			}
			
			if(isset($_POST['qty_jar_total'])){
			$qty_jartotal=addslashes($_POST['qty_jar_total']);
			}
			
			/*if(isset($_POST['qty_total'])){
			$packageqty=addslashes($_POST['qty_total']);
			}*/
			
			$addate = date('Y-m-d');
			
			//echo "insert into cf_sales (sales_type,sales_code,sales_date,add_date) values ('$salestype','$salescode','$from_date','$addate')";
			//exit;
			
			$sql2 = mysql_query("insert into cf_sales (sales_type,sales_clientid,sales_code,sales_tot,sales_receivable,sales_date,add_date) values ('$salestype','$clientid','$salescode','$qty_jartotal','$qty_jartotal','$from_date','$addate')");
				
			$lastid = mysql_insert_id();	
			// nithya	
				  
				  mysql_query("update  cf_accountsreceivable set `receiveamount`=`receiveamount`+$qty_jartotal where clientid=$clientid"); 
				  
			//end	
						
			
			$grand_totin=0;
			$cnt = $_POST['totcntw_jar'];
			for($i=1;$i<=$cnt;$i++)
			{
			
				if(isset($_POST['product_jarid'.$i])){
				$product_jarid=addslashes($_POST['product_jarid'.$i]);
				}
				else
				{$product_jarid='';
				}			
				
				if(isset($_POST['no_jar'.$i])){
				$nojar=addslashes($_POST['no_jar'.$i]);
				}
				else
				{$nojar=0;
				}
				
				if(isset($_POST['kg_jar_rate'.$i])){
				$kgjarrate=addslashes($_POST['kg_jar_rate'.$i]);
				}else
				{$kgjarrate='';
				}
		
				if(isset($_POST['jar_damage_return'.$i])){
				$jardamagereturn=addslashes($_POST['jar_damage_return'.$i]);
				}else
				{$jardamagereturn='';
				}
				
				if(isset($_POST['jar_per_rs'.$i])){
				$jarper_rs=addslashes($_POST['jar_per_rs'.$i]);
				}else
				{$jarper_rs='';
				}
				
				if(isset($_POST['narration_jar'.$i])){
				$narration_jar=addslashes($_POST['narration_jar'.$i]);
				}else
				{$narration_jar='';
				}
								
				if(isset($_POST['tot_jar_line'.$i])){
				$totjarline=addslashes($_POST['tot_jar_line'.$i]);
				}else
				{$totjarline='';
				}
				
				if($totjarline!='')
				{
				$jar_sql=mysql_query("select * from cf_jar where status=1");
				  if($jar_sql && mysql_num_rows($jar_sql)>0)
				  {
				  while($jar_row=mysql_fetch_array($jar_sql))
				  {
				  $jar_kg=$jar_row['jar_kg'];
				  }
				  }
				  else
				  {
				  $jar_kg=0;
				  }
				
				$jar_tot=$jar_kg*($nojar+$jardamagereturn);
				$sql2 = mysql_query("insert into cf_sales_sub (sale_id,prd_id,sale_no_tin_kg,sale_rate,sale_pertin_rs,sale_damage_qty,sale_date,sale_line_tot) values ('$lastid','$product_jarid','$nojar','$kgjarrate','$jarper_rs','$jardamagereturn','$addate','$totjarline')");
				
				mysql_query("update cf_stock set `stock_jar`=`stock_jar`-$nojar");
				
				if($product_jarid == 1)
		   		 {
		   			mysql_query("update cf_stock set `stock_palmoil`=`stock_palmoil`-$jar_tot");
		   		 }
				 else if($product_jarid == 2)
				 {
				 	mysql_query("update cf_stock set `stock_coconutoil`=`stock_coconutoil`-$jar_tot");
				 }
				 
				 //----Jar Sales------------------- 
				
				$reclientres = mysql_query("select * from cf_ledger where ledgertype = 'clientledger' and empid = '$clientid'");
		    	$clientrw = mysql_fetch_array($reclientres);
		    	$ledgerids = $clientrw['ledgerid'];
				
				$acc_reference=$acc_reference+1;
				$sql31 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type,purpose) values ('$lastid','$qty_jartotal','1','1007','$from_date','$addate','$acc_reference','$product_jarid','$narration_jar')");
			
			   
			$sql32 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type) values ('$lastid','$qty_jartotal','2','$ledgerids','$from_date','$addate','$acc_reference','$product_jarid')");
				
				//----End Jar Sales------------------- 
				
					
				}
				
				}
			
			
			header("location:sales-list.php");
}

		if(isset($_POST['kgsubmit'])){
		
			
			if(isset($_POST['group1'])){
			$salestype =addslashes($_POST['group1']);
			}
			
			if(isset($_POST['fromdate2'])){
			$from_date=addslashes($_POST['fromdate2']);
			$from_date = date('Y-m-d', strtotime($from_date));
			}
			
			if(isset($_POST['salescode'])){
			$salescode=addslashes($_POST['salescode']);
			}
			
			if(isset($_POST['clientkg_id'])){
			$clientid=addslashes($_POST['clientkg_id']);
			}
			
			if(isset($_POST['qty_kg_total'])){
			$qty_kgtotal=addslashes($_POST['qty_kg_total']);
			}
			
			/*if(isset($_POST['qty_total'])){
			$packageqty=addslashes($_POST['qty_total']);
			}*/
			
			$addate = date('Y-m-d');
			
			
			$sql2 = mysql_query("insert into cf_sales (sales_type,sales_clientid,sales_code,sales_tot,sales_receivable,sales_date,add_date) values ('$salestype','$clientid','$salescode','$qty_kgtotal','$qty_kgtotal','$from_date','$addate')");			
			$lastid = mysql_insert_id();
			// nithya	
				  
				  mysql_query("update  cf_accountsreceivable set `receiveamount`=`receiveamount`+$qty_kgtotal where clientid=$clientid"); 
				  
			//end
			$cnt = $_POST['totcnt_kg'];
			for($i=1;$i<=$cnt;$i++)
			{
				if(isset($_POST['product_kgid'.$i])){
				$product_kgid=addslashes($_POST['product_kgid'.$i]);
				}
				else
				{$product_kgid='';
				}
				
				if(isset($_POST['qtykg'.$i])){
				$qtykg=addslashes($_POST['qtykg'.$i]);
				}
				else
				{$qtykg=0;
				}
				
				if(isset($_POST['kgrate'.$i])){
				$kgrate=addslashes($_POST['kgrate'.$i]);
				}else{
				$kgrate='';}
				
				if(isset($_POST['narration_kg'.$i])){
				$narration_kg=addslashes($_POST['narration_kg'.$i]);
				}else{
				$narration_kg='';}
		
				if(isset($_POST['linetotkg'.$i])){
				$linetotkg=addslashes($_POST['linetotkg'.$i]);
				}else{
				$linetotkg='';}
				
				if($linetotkg!='')
				{
				$sql2 = mysql_query("insert into cf_sales_sub (sale_id,prd_id,sale_no_tin_kg,sale_rate,sale_date,sale_line_tot) values ('$lastid','$product_kgid','$qtykg','$kgrate','$addate','$linetotkg')");
					
					//mysql_query("update cf_stock set `stock_oil`=`stock_oil`-$qtykg");
					
					if($product_kgid == 1)
		   		 	{
		   				mysql_query("update cf_stock set `stock_palmoil`=`stock_palmoil`-$qtykg");
					 }
					 else if($product_kgid == 2)
					 {
						mysql_query("update cf_stock set `stock_coconutoil`=`stock_coconutoil`-$qtykg");
					 }
					 
					//----Kg Sales------------------- 
				
					$reclientres = mysql_query("select * from cf_ledger where ledgertype = 'clientledger' and empid = '$clientid'");
					$clientrw = mysql_fetch_array($reclientres);
					$ledgerids = $clientrw['ledgerid'];
					
					$acc_reference=$acc_reference+1;
					$sql31 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type,purpose) values ('$lastid','$qty_kgtotal','1','1008','$from_date','$addate','$acc_reference','$product_kgid','$narration_kg')");
				
				   
				$sql32 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type) values ('$lastid','$qty_kgtotal','2','$ledgerids','$from_date','$addate','$acc_reference','$product_kgid')");
					
					//----End Kg Sales------------------- 
					
				}
				}
			header("location:sales-list.php");
			
			//header("location:package-list.php");
			
}

		if(isset($_POST['barrelsubmit'])){
		
			if(isset($_POST['group1'])){
			$salestype =addslashes($_POST['group1']);
			}
			
			if(isset($_POST['fromdate4'])){
			$from_date=addslashes($_POST['fromdate4']);
			$from_date = date('Y-m-d', strtotime($from_date));
			}
			
			if(isset($_POST['salescode'])){
			$salescode=addslashes($_POST['salescode']);
			}
			
			if(isset($_POST['clientbarrel_id'])){
			$clientid=addslashes($_POST['clientbarrel_id']);
			}
			
			if(isset($_POST['qty_barrel_total'])){
			$qty_barreltotal=addslashes($_POST['qty_barrel_total']);
			}
			
			/*if(isset($_POST['qty_total'])){
			$packageqty=addslashes($_POST['qty_total']);
			}*/
			
			$addate = date('Y-m-d');
			
			//echo "insert into cf_sales (sales_type,sales_code,sales_date,add_date) values ('$salestype','$salescode','$from_date','$addate')";
			//exit;
			
			$sql2 = mysql_query("insert into cf_sales (sales_type,sales_clientid,sales_code,sales_tot,sales_receivable,sales_date,add_date) values ('$salestype','$clientid','$salescode','$qty_barreltotal','$qty_barreltotal','$from_date','$addate')");
				
			$lastid = mysql_insert_id();	
			// nithya	
				  
				  mysql_query("update  cf_accountsreceivable set `receiveamount`=`receiveamount`+$qty_barreltotal where clientid=$clientid"); 
				  
			//end	
						
			
			$grand_totin=0;
			$cnt = $_POST['totcntw_barrel'];
			for($i=1;$i<=$cnt;$i++)
			{
			
				
				if(isset($_POST['product_barrelid'.$i])){
				$product_barrelid=addslashes($_POST['product_barrelid'.$i]);
				}
				else
				{$product_barrelid='';
				}			
				
				if(isset($_POST['no_barrel'.$i])){
				$nobarrel=addslashes($_POST['no_barrel'.$i]);
				}
				else
				{$nobarrel=0;
				}
				
				if(isset($_POST['kg_barrel_rate'.$i])){
				$kgbarrelrate=addslashes($_POST['kg_barrel_rate'.$i]);
				}else
				{$kgbarrelrate='';
				}
		
				/*if(isset($_POST['jar_damage_return'.$i])){
				$jardamagereturn=addslashes($_POST['jar_damage_return'.$i]);
				}else
				{$jardamagereturn='';
				}*/
				
				if(isset($_POST['barrel_per_rs'.$i])){
				$barrelper_rs=addslashes($_POST['barrel_per_rs'.$i]);
				}else
				{$barrelper_rs='';
				}
								
				if(isset($_POST['tot_barrel_line'.$i])){
				$totbarrelline=addslashes($_POST['tot_barrel_line'.$i]);
				}else
				{$totbarrelline='';
				}
				
				if(isset($_POST['narration_barrel'.$i])){
				$narration_barrel=addslashes($_POST['narration_barrel'.$i]);
				}else
				{$narration_barrel='';
				}
				
				if($totbarrelline!='')
				{
				$barrel_sql=mysql_query("select * from cf_barrel where status=1");
				  if($barrel_sql && mysql_num_rows($barrel_sql)>0)
				  {
				  while($barrel_row=mysql_fetch_array($barrel_sql))
				  {
				  $barrel_kg=$barrel_row['barrel_kg'];
				  }
				  }
				  else
				  {
				  $barrel_kg=0;
				  }
				
				$barrel_tot=$barrel_kg*$nobarrel;
				
				/*echo "insert into cf_sales_sub (sale_id,prd_id,sale_no_tin_kg,sale_rate,sale_pertin_rs,sale_date,sale_line_tot) values ('$lastid','$product_barrelid','$nobarrel','$kgbarrelrate','$barrelper_rs','$addate','$totbarrelline')";*/
				$sql2 = mysql_query("insert into cf_sales_sub (sale_id,prd_id,sale_no_tin_kg,sale_rate,sale_pertin_rs,sale_date,sale_line_tot) values ('$lastid','$product_barrelid','$nobarrel','$kgbarrelrate','$barrelper_rs','$addate','$totbarrelline')");
				
				mysql_query("update cf_stock set `stock_barrel`=`stock_barrel`-$nobarrel");
				
				if($product_barrelid == 1)
		   		 {
		   			mysql_query("update cf_stock set `stock_palmoil`=`stock_palmoil`-$barrel_tot");
		   		 }
				 else if($product_barrelid == 2)
				 {
				 	mysql_query("update cf_stock set `stock_coconutoil`=`stock_coconutoil`-$barrel_tot");
				 }
				 
				  //----Barrel Sales------------------- 
				
				$reclientres = mysql_query("select * from cf_ledger where ledgertype = 'clientledger' and empid = '$clientid'");
		    	$clientrw = mysql_fetch_array($reclientres);
		    	$ledgerids = $clientrw['ledgerid'];
				
				$acc_reference=$acc_reference+1;
				$sql31 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type,purpose) values ('$lastid','$qty_barreltotal','1','1009','$from_date','$addate','$acc_reference','$product_barrelid','$narration_barrel')");
			
			   
			$sql32 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type) values ('$lastid','$qty_barreltotal','2','$ledgerids','$from_date','$addate','$acc_reference','$product_barrelid')");
				
				//----End Barrel Sales------------------- 
				
					
				}
				
				}
			
			
			//header("location:sales-list.php");
		}


$literqty='';		

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<!--<script src="js/driverdrop.js"></script>-->
<script src="js/addmoresales.js"></script>
<script src="js/addmoretin.js"></script>
<script src="js/addmorekg.js"></script>

<!--<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>-->
<script src="js/jqmin1.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>

<script type="text/javascript" src="scripts_date/jquery.js"></script>
<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<script>$(document).ready(function(){
$('#fromdate').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});

$('#fromdate1').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});

$('#fromdate2').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});

$('#fromdate3').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});

$('#fromdate4').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});

});

/*function drivername()
{
	alert(document.frmname.clientid.value);
}*/



</script>

<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
function validation_box(){

if(document.getElementById('fromdate').value==''){
alert("Enter the Date");
document.getElementById('fromdate').focus();
return false;
}

if(document.getElementById('clientbox_id').value==''){
alert("Enter the Client Name");
document.getElementById('clientbox_id').focus();
return false;
}

var cnt = document.getElementById('totcnt_box').value;

for(i=1;i<=cnt;i++){

	if(document.getElementById('branch'+i).value==''){
			alert("Select the Brand");
			document.getElementById('branch'+i).focus();
			return false;
	}
			
	if(document.getElementById('literqty'+i).value==''){
		alert("Enter the liter");
		document.getElementById('literqty'+i).focus();
		return false;
	}
			
	if(document.getElementById('kg_liter'+i).value==''){
		alert("Enter the Kg");
		document.getElementById('kg_liter'+i).focus();
		return false;
	}
	
	if(document.getElementById('boxqty'+i).value==''){
		alert("Enter the Box Quantity");
		document.getElementById('boxqty'+i).focus();
		return false;
	}
	
	if(document.getElementById('ratebox'+i).value==''){
		alert("Enter the Rate");
		document.getElementById('ratebox'+i).focus();
		return false;
	}
			
}

}

function validation_tin(){

if(document.getElementById('fromdate1').value==''){
alert("Enter the Date");
document.getElementById('fromdate1').focus();
return false;
}

if(document.getElementById('clientin_id').value==''){
alert("Enter the Client Name");
document.getElementById('clientin_id').focus();
return false;
}

var cnt = document.getElementById('totcntw_tin').value;

for(i=1;i<=cnt;i++){

	if(document.getElementById('no_tin'+i).value==''){
			alert("Enter the No of Tins");
			document.getElementById('no_tin'+i).focus();
			return false;
	}
			
	if(document.getElementById('kg_tin_rate'+i).value==''){
		alert("Enter the Kg Rate");
		document.getElementById('kg_tin_rate'+i).focus();
		return false;
	}
			
}

}

function validation_jar(){

if(document.getElementById('fromdate3').value==''){
alert("Enter the Date");
document.getElementById('fromdate3').focus();
return false;
}

if(document.getElementById('clienjar_id').value==''){
alert("Enter the Client Name");
document.getElementById('clienjar_id').focus();
return false;
}

var cnt = document.getElementById('totcntw_jar').value;

for(i=1;i<=cnt;i++){

	if(document.getElementById('no_jar'+i).value==''){
			alert("Enter the No of Jar");
			document.getElementById('no_jar'+i).focus();
			return false;
	}
			
	if(document.getElementById('kg_jar_rate'+i).value==''){
		alert("Enter the Kg Rate");
		document.getElementById('kg_jar_rate'+i).focus();
		return false;
	}
			
}

}

function validation_kg(){

if(document.getElementById('fromdate2').value==''){
alert("Enter the Date");
document.getElementById('fromdate2').focus();
return false;
}

if(document.getElementById('clientkg_id').value==''){
alert("Enter the Client Name");
document.getElementById('clientkg_id').focus();
return false;
}

var cnt = document.getElementById('totcntw_tin').value;

for(i=1;i<=cnt;i++){

	if(document.getElementById('qtykg'+i).value==''){
			alert("Enter the Quantity");
			document.getElementById('qtykg'+i).focus();
			return false;
	}
			
	if(document.getElementById('kgrate'+i).value==''){
		alert("Enter the Kg Rate");
		document.getElementById('kgrate'+i).focus();
		return false;
	}
			
}

}


</script>

<script>
function showLiter(str,i){

 document.getElementById("kg_liter"+i).value = '';
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtLiter"+i).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtLiter"+i).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","package_ajax.php?str="+str+"&cnt="+i,true);
xmlhttp.send();
}

function showKg(val,i){
//alert('aa');
var userid = $(this).attr('data-id');
var brand = document.getElementById('branch'+i).value;

var xmlhttp;    
if (val=="")
  {
  document.getElementById('txtKglitre'+i).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	//alert(responseText);
	   document.getElementById('txtKglitre'+i).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_kgajax.php?brand_id="+brand+"&ltr="+val+"&cnt="+i,true);
xmlhttp.send();
}

function showDealer(str,i){

//alert(i);

var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtDealer"+i).innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtDealer"+i).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","testdealer.php?str="+str+"&vals="+i,true);
xmlhttp.send();
}

function sel(val,value){
var strURL="ajax/getVal.php?name="+value;
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 
		//alert(req.responseText);
		var x=req.responseText;
		x=x.split('@@');
		//alert(x);
		
		if(x[1] == '')
		{
		x[1] = 0;
		}
	    document.getElementById('i'+val).value=x[0];
	    document.getElementById('d'+val).value=x[1];
		
		
	   //document.getElementById('i'+val).value=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }

//document.getElementById('i'+val).value=value;

}

function change_service(value,cnt){
var strURL="php/addmore.php?value="+value+"&cnt="+cnt;
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 

	    var txtData="div"+cnt;
		document.getElementById(txtData).innerHTML=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }

}

function selchnge(val,value){
var strURL="ajax/getVal.php?name="+value;
//alert(strURL);
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{
		
		
	   document.getElementById('i'+val).value=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }

//document.getElementById('i'+val).value=value;

}

function minmore(cnt){

	
	var k = parseInt(cnt);
	var j = parseInt(cnt)-parseInt(1); 
	var rmvtot=document.getElementById('linetot'+k).value;
	var grandtot=document.getElementById('boxsaletot').value;
	grandtot=parseInt(grandtot)-parseInt(rmvtot);
	document.getElementById('boxsaletot').value=grandtot;
	if(document.getElementById('hidediv'+k)){
	document.getElementById('hidediv'+k).innerHTML='';
	}if(document.getElementById('min'+j)){
	document.getElementById('min'+j).style.display='block';
	}if(document.getElementById('max'+j)){
	document.getElementById('max'+j).style.display='none';
	}	
	grandT()
}
function minmoretin(cnt){

	
	var k = parseInt(cnt);
	var j = parseInt(cnt)-parseInt(1); 
	var rmvtot=document.getElementById('tot_tin_line'+k).value;
	var grandtot=document.getElementById('qty_tin_total').value;
	grandtot=parseInt(grandtot)-parseInt(rmvtot);
	document.getElementById('qty_tin_total').value=grandtot;
	if(document.getElementById('hidedivtin'+k)){
	document.getElementById('hidedivtin'+k).innerHTML='';
	}if(document.getElementById('mintin'+j)){
	document.getElementById('mintin'+j).style.display='block';
	}if(document.getElementById('maxtin'+j)){
	document.getElementById('maxtin'+j).style.display='none';
	}	
	grandT()
}
function minmorekg(cnt){

	
	var k = parseInt(cnt);
	var j = parseInt(cnt)-parseInt(1); 
	var rmvtot=document.getElementById('linetotkg'+k).value;
	var grandtot=document.getElementById('qty_kg_total').value;
	grandtot=parseInt(grandtot)-parseInt(rmvtot);
	document.getElementById('qty_kg_total').value=grandtot;
	if(document.getElementById('hidedivkg'+k)){
	document.getElementById('hidedivkg'+k).innerHTML='';
	}if(document.getElementById('minkg'+j)){
	document.getElementById('minkg'+j).style.display='block';
	}if(document.getElementById('maxkg'+j)){
	document.getElementById('maxkg'+j).style.display='none';
	}	
	grandT()
}
function test1(){
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","testajax.php?str="+str,true);
xmlhttp.send();
}

function test(){

	var str = document.getElementById('clientname').value;
	if (str.length>2)
	{
		var lower = str.substring(0,4);
		var upper = lower.toUpperCase();
		
 		document.getElementById('clientcode').value = upper;
	}
}	

function qtytotal(){		
	
	var cnt = document.getElementById('totcnt_box').value;
	var literboxqty='';
	var numbx='';
	var ratebx='';
	var kglt='';
	var totltr=''; 	
	var boxsaletotal=0;
	//alert(cnt);
	for(j=1;j<=cnt;j++){
		
		literboxqty = $("#literqty"+j+" option:selected").attr("data-id");
		//alert(literboxqty);		
		kglt = document.getElementById('kg_liter'+j).value;
		numbx = document.getElementById('boxqty'+j).value;
		ratebx = document.getElementById('rateboxs'+j).value;
		
		//totltr = parseFloat(literboxqty)*parseFloat(kglt)*parseFloat(numbx)*parseFloat(ratebx);
		totltr = parseFloat(numbx)*parseFloat(ratebx);
		
		//alert(isNaN(totltr));
		//totltr;
		/*if(document.getElementById('packqty'+j).value == '')
		{
			document.getElementById('packqty'+j).value = 0;	
		}
		str = parseInt(document.getElementById('packqty'+j).value) + parseInt(str);*/
		
		if(isNaN(totltr) == false)
		{
		
		document.getElementById('linetot'+j).value= totltr.toFixed(2);
		boxsaletotal = parseFloat(boxsaletotal) + parseFloat(totltr.toFixed(2));
		}
		
	}
	document.getElementById('boxsaletot').value= boxsaletotal.toFixed(2);
	
}

function tin_total(){
	
	var cnts = document.getElementById('totcntw_tin').value;
	var kgtinrate='';
	var notin='';
	var tot_tin='';
	var tinper_rs='';
	var tinsaletotal=0;
	//alert(cnts);
	var tin_kg = document.getElementById('tin_kg').value;
	for(k=1;k<=cnts;k++){	
		var per_tinrs = document.getElementById('pertin_rs'+k).value;	
		notin = document.getElementById('no_tin'+k).value;
		
		tinper_rs = per_tinrs*notin;
		document.getElementById('tin_per_rs'+k).value = tinper_rs;
	
		kgtinrate = document.getElementById('kg_tin_rate'+k).value;
		
		tot_tin = parseFloat(notin)*parseFloat(kgtinrate);
		
		if(isNaN(tot_tin) == false)
		{
			document.getElementById('tot_tin_line'+k).value= tot_tin.toFixed(2);
			tinsaletotal = parseFloat(tinsaletotal) + parseFloat(tot_tin.toFixed(2));
		}
		
	}
	//document.getElementById('qty_tin_total').value= parseFloat(tinsaletotal);
	document.getElementById('qty_tin_total').value= parseFloat(tinsaletotal)+parseFloat(tinper_rs);  //nithya
		
}

function jar_total(){
	
	var cnts = document.getElementById('totcntw_jar').value;
	var kgjarrate='';
	var nojar='';
	var tot_jar='';
	var jarper_rs='';
	var jarsaletotal=0;
	//alert(cnts);
	var jar_kg = document.getElementById('jar_kg').value;	
	for(k=1;k<=cnts;k++){	
	
		var per_jarrs = document.getElementById('perjar_rs'+k).value;
		//alert(per_jarrs);
		
		
		nojar = document.getElementById('no_jar'+k).value;
		
		jarper_rs = per_jarrs*nojar;
		document.getElementById('jar_per_rs'+k).value = jarper_rs;
		
		kgjarrate = document.getElementById('kg_jar_rate'+k).value;
		
		tot_jar = parseFloat(nojar)*parseFloat(kgjarrate);
		
		if(isNaN(tot_jar) == false)
		{
			document.getElementById('tot_jar_line'+k).value= tot_jar.toFixed(2);
			jarsaletotal = parseFloat(jarsaletotal) + parseFloat(tot_jar.toFixed(2));
		}
		
	}
	document.getElementById('qty_jar_total').value= parseFloat(jarsaletotal) + parseFloat(jarper_rs); //nithya
		
}

function barrel_total(){
	
	var cnts = document.getElementById('totcntw_barrel').value;
	var kgbarrelrate='';
	var nobarrel='';
	var tot_barrel='';
	var barrelper_rs='';
	var barrelsaletotal=0;
	//alert(cnts);
	var barrel_kg = document.getElementById('barrel_kg').value;	
	for(k=1;k<=cnts;k++){	
	
		var per_barrel_rate = document.getElementById('barrel_per_rs'+k).value;
		nobarrel = document.getElementById('no_barrel'+k).value;		
		barrelper_rs = per_barrel_rate*nobarrel;
		
		kgbarrelrate = document.getElementById('kg_barrel_rate'+k).value;		
		tot_barrel_rate = parseFloat(nobarrel)*parseFloat(kgbarrelrate);
		barreltot = tot_barrel_rate+barrelper_rs;
				
		if(isNaN(tot_barrel) == false)
		{
			
			document.getElementById('tot_barrel_line'+k).value= barreltot.toFixed(2);
		}
		
	}
	document.getElementById('qty_barrel_total').value= barreltot.toFixed(2); //nithya
		
}

function kg_total(){
	var cntkg = document.getElementById('totcnt_kg').value;
	var noqtykg='';
	var kgrate='';
	var tot_kg='';
	var kgsaletotal=0;
	//alert(cnts);
	
	for(k=1;k<=cntkg;k++){		
		noqtykg = document.getElementById('qtykg'+k).value;
		
		kgrate = document.getElementById('kgrate'+k).value;
		
		tot_kg = parseFloat(noqtykg)*parseFloat(kgrate);
		
		if(isNaN(tot_kg) == false)
		{
			document.getElementById('linetotkg'+k).value= tot_kg.toFixed(2);
			kgsaletotal = parseFloat(kgsaletotal) + parseFloat(tot_kg.toFixed(2));
		}
		
	}
	document.getElementById('qty_kg_total').value= parseFloat(kgsaletotal);
}

function boxqty(){
var literid = '';
var cnt = document.getElementById('totcntw').value;
literid = document.getElementById('literqty'+cnt).value;
var boxqty = document.getElementById('boxqty'+cnt).value

var xmlhttp;    
if (str=="")
  {
  document.getElementById("boxqty1").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	   document.getElementById("boxqty1").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","php/boxajax.php?value="+literid+"&cnt="+cnt,true);
xmlhttp.send();
}

function chkboxqty(val,cnt){


var literid = '';
//var cnt = document.getElementById('totcntw_tin').value;
literid = document.getElementById('literqty'+cnt).value;
var brandid = document.getElementById('branch'+cnt).value
//alert(literid);
//alert(brandid);

var xmlhttp;    

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		if(xmlhttp.responseText == 'false')
		{
			alert('Quantity not available');
			document.getElementById('boxqty'+cnt).value = '';
		}
	   //document.getElementById("boxqty1").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","php/get_boxqty.php?liter_id="+literid+"&brandid="+brandid+"&boxqty="+val,true);
xmlhttp.send();

}

$(document).ready(function(){ 
	
    $("input[name$='group1']").click(function() {
        var test = $(this).val();
		if(test != 'box')
		{
			$("div.descbox").hide();
		}
        $("div.desc").hide();
        $("#"+test).show();
    }); 
});
</script>

<style>
.lableentrytext{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
}

body {
	padding:0px;
	margin:0px;
	font-family:Arial, Helvetica, sans-serif;
	color:#000000;
}
.div01 {
	width:80%;
		margin:0 70px;
	padding-bottom:15px;
}
.ptForm {
	/*border:1px solid #000000;*/
	width:100%;
	margin:0 auto;
	padding:4px;
}
.ptText01 {
	font-size:20px;
	font-weight:bold;
}
.ptText02 {
	font-size:12px;
}
.ptText03 {
	font-size:16px;
	font-weight:bold;
}
.ptText04 {
	font-size:16px;
	font-weight:bold;
	border-left:solid 1px #000000;
	border-right:solid 1px #000000;
	border-top:solid 1px #000000;
}
.ptText05 {
	font-size:14px;
	font-weight:bold;
}
.field01 {
	border-bottom:#333333 dotted 1px;
	border-left:none;
	border-top:none;
	border-right:none;
	color:#000000;
	font-size:12px;
	font-weight:bold;
	background-color:#f1f1f1;
}
.field02 {
	border:none;
	color:#000000;
	font-size:12px;
	font-weight:bold;
	background-color:#f1f1f1;
}
.ptText06 {
	font-size:12px;
	font-weight:bold;
}
.rightTd {
	border-bottom:solid 1px #000000;
}
.leftTd {
	border-bottom:solid 1px #000000;
	border-right:solid 1px #000000;
	padding:4px;
}
.tdItem {
	border-bottom:solid 1px #000000;
	border-right:solid 1px #000000;
	padding:4px;
}
.rightTd {
	border-bottom:solid 1px #000000;
	padding:4px;
}
/*.rightTdBtm {
	border:none;
	padding:4px;
}
.leftTdBtm {
	border-right:solid 1px #000000;
	padding:4px;
}*/
.tdItemBtm {
	
	padding:4px;
}

#adv{

	display:none;
	
}
 .desc { display: none; }
 
  .descbox { display: block; }
</style>

</head>

<body onLoad="">
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 
<div class="tabbedArea">
<?php
	$div=1;	
	?>
    <input type="hidden" id="divcnt" name="divcnt" value="<?=$div?>"/>
  <div class="tabBody">
  <?php 
		if(empty($_REQUEST['clientsubid']))
		{ ?>
		  <h1>Add Sales</h1>
		<?php } else { ?>
		  <h1>Edit Sales</h1>
	  <?php }
  ?>
   
   <div class="div01">
    <form name="clientform" id="clientform" method="post" >
  <div class="ptForm">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="9%" height="36" align="left" valign="top"><label>
          <input type="radio" name="group1" value="box" checked="checked">
          Box</label></td>
        <td width="10%" align="left" valign="top"><label>
          <input type="radio" name="group1" value="tin">
          Tin</label></td>
        <td width="10%" align="left" valign="top"><label>
          <input type="radio" name="group1" value="kg">
          Kg</label></td>
		 <td width="10%" align="left" valign="top"><label>
          <input type="radio" name="group1" value="jar">
          Jar</label></td>
		  <td width="94%" align="left" valign="top"><label>
          <input type="radio" name="group1" value="barrel">
          Barrel</label></td>
        <td width="7%" align="left" valign="top">&nbsp;</td>
      </tr>
    </table>
 
  <div>
    <label></label>
  </div>  
  <div>
    <label></label>
  </div>  
  <div>
    <label></label>
  </div> 
  <!--<input type="radio" name="sales" value="sales">Sales
  <input type="radio" name="sales" value="tin">Tin
  <input type="radio" name="sales" value="kg">Kg-->
  
  	<div id="box" class="descbox">
    <table width="100%" border="0" cellspacing="5" cellpadding="2"  style="border:1px solid #000000; padding:4px;">
           
      <input type="hidden" name="totcnt_box" id="totcnt_box" value="<?=$div?>">
   
          <tr>
        <td  colspan="4"  class="ptText02" style="">         </td>
        </tr>
          <tr>
                <td  colspan="4"  class="ptText02" style="">
                <table style="width:100%;">
                  <tr>
                    <td width="4%">No:</td>
                    <?php 
	                //$clientaut = $rws['client_newcode'];
					$arr_code=mysql_query("select * from cf_sales order by sales_id desc limit 1");
					$rw=mysql_fetch_array($arr_code);
					$packcode = $rw['sales_code'] + 1;
					
				    ?>
                    <input type="hidden" name="salescode" id="salescode" class="input1 input6"  value="<?=$packcode?>" style="float:left;" >
                    <td width="10%">SL-<?=$packcode?></td>
                    <td width="5%" align="right">Date:</td>
                    <td width="20%">
                      <input type="text" name="fromdate" id="fromdate" class="input1 input6"  style="float:left;" >
                    </span></td>
                    
                    <td width="10%">Client Name:</td>
                    <td >
                     <select class="input1 " name="clientbox_id" id="clientbox_id" >
                        <option value="">-Select Client-</option>
                        <?php 
                            $sq_client="select * from cf_client";
                            $arrclient=mysql_query($sq_client);
                            while($res1=mysql_fetch_array($arrclient))
                            {
                            ?>  <option value="<?=$res1['client_id']?>"><?=$res1['client_name']?></option>
                            <?php
                            }
                            ?>
                    </select>  
                    </td>
                    <td width="14%">&nbsp;</td>
                  </tr>
                </table>              </td>
          </tr>                  
      <tr>
        <td  colspan="5"  class="ptText02" style="width:70%;">
        <div id="list">
        <table width="100%"  cellspacing="0" cellpadding="0"   class="List" align="center" style="border-top:solid 1px #000000; border-bottom:none; border-left:solid 1px #000000; border-right:solid 1px #000000;" >
            
            <tr>
			  <td width="16%" class="tdItem" style="font-weight:bold;">Product</td>	
              <td width="16%" class="tdItem" style="font-weight:bold;">Brand</td>
              <td width="19%" class="tdItem" style="font-weight:bold;">Liters</td>
              <td width="5%" class="tdItem" style="font-weight:bold;">Kg</td>
              <td width="19%" class="tdItem" style="font-weight:bold;">Box Quantity</td>
              <td width="41%" class="tdItem" style="font-weight:bold;">Rate</td>
              <td width="41%" class="tdItem" style="font-weight:bold;">Total</td>
              <td class="rightTd" style="width:5%; font-weight:bold;">Add</td>
              
            </tr>
            <tr>
			  <td class="tdItem">
              <select class="input1" name="product_ids1" id="product_ids1" >
     			<option value="">Select Product</option>
     			<?php 
					$sq_product="select * from cf_open_oil";
					$array1=mysql_query($sq_product);
					while($resprd=mysql_fetch_array($array1))
					{
					?>     	
        				<option value="<?=$resprd['open_stock_id']?>" ><?=$resprd['item_name']?></option>
               		<?php
					}
	 				?>
     		</select>   	 </td>
              <td class="tdItem">
              <select class="input1 fxwidth" name="branch1" id="branch1" onChange="showLiter(this.value,'<?=$div?>')">
     			<option value="">-Select Brand-</option>
                <?php 
					$sq_brand="select * from cf_brand";
					$array1=mysql_query($sq_brand);
					while($res=mysql_fetch_array($array1))
					{
					?>     	
        				<option value="<?=$res['brand_id']?>"><?=$res['brand_name']?></option>
               		<?php
					}
	 				?>
     		</select>    	 </td>
              
               <td class="tdItem"><div id="txtLiter<?=$div?>">
               <select class="input1 fxwidth" name="literqty1" id="literqty1" onChange="showKg(this.value,'<?=$div?>')">
     			<option value="">-Select Liter-</option>
     			 <?php 
                            $sq_liter1="select * from cf_liter";
                            $arr1=mysql_query($sq_liter1);
                            while($resliter1=mysql_fetch_array($arr1))
                            {
                        ?>
                            <option value="<?=$resliter1['liter_id']?>" data-id="<?=$resliter1['liter_boxno']?>" <? if($resliter1['liter_id']==$literqty) {?>selected<? }?> ><?=$resliter1['liter_qty']?></option>
                        <?php
                            }
                     ?>
     		</select>
            
            
            </div>            </td>
              <td class="tdItem" width="5%"><div id="txtKglitre1" style="float:left;"><input type="text" name="kg_liter1" id="kg_liter1" class="input1 input3 fxwidth" value=""    ></div></td>    
			  
			  <?php 
			  $tin_sql=mysql_query("select * from cf_tin where status=1");
			  if($tin_sql && mysql_num_rows($tin_sql)>0)
			  {
			  while($tin_row=mysql_fetch_array($tin_sql))
			  {
			  $tin_kg=$tin_row['kg_val'];
			  }
			  }
			  else
			  {
			  $tin_kg=0;
			  }
			  ?>  <input type="hidden" name="tin_kg" id="tin_kg" value="<?=$tin_kg?>" >
                     
              <td class="tdItem"><input type="text" name="boxqty1" id="boxqty1" class="input1 input3 fxwidth" value="" onKeyUp="qtytotal();"></td>1
              <td class="tdItem"><input type="text" name="rateboxs1" id="rateboxs1" class="input1 input3 fxwidth" data-id="1" value="" onKeyUp="qtytotal()" ></td>      
              <td class="tdItem"><input type="text" name="linetot1" id="linetot1" class="input1 input3 fxwidth" value=""  ></td>  
              <td width="5%" align="center" class="tr_td rightTd" style="border-right:#6b6b6b solid 1px;">
			  
	  			<a style="cursor:pointer;" onClick="addmoresales('2')"><span id="min1"><img src="images/addmore.jpg" /></span></a>
					  
	   <span id="max1" style="display:none;" onClick="minmore('2');"><img src="images/minus.jpg" /></span>	  </td>
            </tr>
            
           
          </table> 
          </div>
        
        <div id="div2"></div>
         <div id="div3"></div>         </td>
      </tr>
      
      <tr>
              <td colspan="5" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td colspan="2" align="right">Total</td>
                  <td width="15%">
                <input type="text" name="qty_total_bx" id="boxsaletot"  class="input9"  value="" >              </td>
              </tr>

              </table></td>
              </tr>
        
            
            <tr>
            	<td width="19%">
                 	<input type="submit" name="boxsubmit" value="Box Submit" class="submit-btn" onClick="return validation_box()"  >
                </td>
            </tr>    
    </table>
    </div>
    
   
	<div id="tin" class="desc">
    <table width="100%" border="0" cellspacing="5" cellpadding="2"  style="border:1px solid #000000; padding:4px;">
           
      <input type="hidden" name="totcntw_tin" id="totcntw_tin" value="<?=$div?>">
   
          <tr>
        <td  colspan="4"  class="ptText02" style="">         </td>
        </tr>
          <tr>
                <td  colspan="4"  class="ptText02" style="">
                <table style="width:100%;">
                  <tr>
                    <td width="4%">No:</td>
                    <?php 
					 $sq_tins=mysql_query("select * from cf_tin");
                     $restin1=mysql_fetch_array($sq_tins);
					 $restin1['tin_rate'];
					
	                //$clientaut = $rws['client_newcode'];
					$arr_code=mysql_query("select * from cf_sales order by sales_id desc limit 1");
					$rw=mysql_fetch_array($arr_code);
					$packcode = $rw['sales_code'] + 1;
				    ?>
                    <input type="hidden" name="salescode" id="salescode" class="input1 input6"  value="<?=$packcode?>" style="float:left;" >
                    <td width="10%">SL-<?=$packcode?></td>
                    <td width="5%" align="right">Date:</td>
                    <td width="20%">
                      <input type="text" name="fromdate1" id="fromdate1" class="input1 input6"  value="" style="float:left;" >
                    </span></td>
                    
                    <td width="10%">Client Name:</td>
                    <td >
                     <select class="input1 " name="clientin_id" id="clientin_id" >
                        <option value="">-Select Client-</option>
                        <?php 
                            $sq_client="select * from cf_client";
                            $arrclient=mysql_query($sq_client);
                            while($res1=mysql_fetch_array($arrclient))
                            {
                            ?>  <option value="<?=$res1['client_id']?>"><?=$res1['client_name']?></option>
                            <?php
                            }
                            ?>
                    </select>  
                    </td>
                    <td width="14%">&nbsp;</td>
                  </tr>
                </table>              </td>
          </tr>                  
      <tr>
        <td  colspan="5"  class="ptText02" style="width:70%;">
        <div id="list">
        <table width="100%"  cellspacing="0" cellpadding="0"   class="List" align="center" style="border-top:solid 1px #000000; border-bottom:none; border-left:solid 1px #000000; border-right:solid 1px #000000;" >
            
            <tr>
			  <td class="tdItem" style="font-weight:bold;">Product</td>
              <td class="tdItem" style="font-weight:bold;">No of Tins</td>
              <td class="tdItem" style="font-weight:bold;">Tin Rate (Oil)</td>
              <td class="tdItem" style="font-weight:bold;">Damage Return</td>
			  <td class="tdItem" style="font-weight:bold;">Rate of Tin</td>			  
              <td class="tdItem" style="font-weight:bold;">Total</td>
			  <td class="tdItem" style="font-weight:bold;">Narration</td>
              <!--<td class="rightTd" style="width:5%; font-weight:bold;">Add</td>-->
            </tr>
            <tr>
              
              <td class="tdItem"><select class="input1" name="product_id1" id="product_id1" >
     			<option value="">Select Product</option>
     			<?php 
					$sq_product="select * from cf_open_oil";
					$array1=mysql_query($sq_product);
					while($resprd=mysql_fetch_array($array1))
					{
					?>     	
        				<option value="<?=$resprd['open_stock_id']?>" ><?=$resprd['item_name']?></option>
               		<?php
					}
	 				?>
     		</select></td>
              <td class="tdItem"><input type="text" name="no_tin1" id="no_tin1" class="input1 input3 fxwidth" value="" onKeyUp="tin_total()" ></td>
              <td class="tdItem"><input type="text" name="kg_tin_rate1" id="kg_tin_rate1" class="input1 input3 fxwidth" value="" onKeyUp="tin_total()" ></td>  
              <td class="tdItem"><input type="text" name="tin_damage_return1" id="tin_damage_return1" class="input1 input3 fxwidth" value=""  ></td>  
			  <td class="tdItem"><input type="text" name="tin_per_rs1" id="tin_per_rs1" class="input1 input3 fxwidth" value=""  >
			  <input type="hidden" name="pertin_rs1" id="pertin_rs1" class="input1 input3 fxwidth" value="<?=$restin1['tin_rate']?>"  >
			  </td> 			  
              <td class="tdItem"><input type="text" name="tot_tin_line1" id="tot_tin_line1" class="input1 input3 fxwidth" value=""  ></td>  
			  <td class="tdItem"><input type="text" name="narration_tin1" id="narration_tin1" class="input1 input3 fxwidth" value=""  ></td>
             <!-- <td width="5%" align="center" class="tr_td rightTd" style="border-right:#6b6b6b solid 1px;">
	  			<a style="cursor:pointer;" onClick="addmoretin('2')"><span id="mintin1"><img src="images/addmore.jpg" /></span></a>	  
	   <span id="maxtin1" style="display:none;" onClick="minmoretin('2');"><img src="images/minus.jpg" /></span>	  </td>-->
            </tr>
                        
          </table> 
          </div>
        
        <div id="divtin2"></div>
         <div id="div3"></div>         </td>
      </tr>
      
        <tr>
              <td colspan="5" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
				  <td  colspan="2" align="right">Grand Total</td>
                 
                  
                  <td colspan="2" width="13%"><input type="text" name="qty_tin_total" id="qty_tin_total"  class="input9"  value="" ></td>
                </tr>
              </table>
			  </td>
			  
           </tr>
         
            <tr>
            	<td width="19%">
              	  <input type="submit" name="tinsubmit" value="Tin Submit" class="submit-btn" onClick="return validation_tin()"  >
                </td>
            </tr>    
    </table>
    </div>
	
	<div id="jar" class="desc">
    <table width="100%" border="0" cellspacing="5" cellpadding="2"  style="border:1px solid #000000; padding:4px;">
           
      <input type="hidden" name="totcntw_jar" id="totcntw_jar" value="<?=$div?>">
   
          <tr>
        <td  colspan="4"  class="ptText02" style="">         </td>
        </tr>
          <tr>
                <td  colspan="4"  class="ptText02" style="">
                <table style="width:100%;">
                  <tr>
                    <td width="4%">No:</td>
                    <?php 
					 $sq_jars=mysql_query("select * from cf_jar");
                     $resjar1=mysql_fetch_array($sq_jars);
					 $resjar1['jar_rate'];
					
	                //$clientaut = $rws['client_newcode'];
					$arr_code=mysql_query("select * from cf_sales order by sales_id desc limit 1");
					$rw=mysql_fetch_array($arr_code);
					$packcode = $rw['sales_code'] + 1;
				    ?>
                    <input type="hidden" name="salescode" id="salescode" class="input1 input6"  value="<?=$packcode?>" style="float:left;" >
                    <td width="10%">SL-<?=$packcode?></td>
                    <td width="5%" align="right">Date:</td>
                    <td width="20%">
                      <input type="text" name="fromdate3" id="fromdate3" class="input1 input6"  value="" style="float:left;" >
                    </span></td>
                    
                    <td width="10%">Client Name:</td>
                    <td >
                     <select class="input1 " name="clientjar_id" id="clientjar_id" >
                        <option value="">-Select Client-</option>
                        <?php 
                            $sq_client="select * from cf_client";
                            $arrclient=mysql_query($sq_client);
                            while($res1=mysql_fetch_array($arrclient))
                            {
                            ?>  <option value="<?=$res1['client_id']?>"><?=$res1['client_name']?></option>
                            <?php
                            }
                            ?>
                    </select>  
                    </td>
                    <td width="14%">&nbsp;</td>
                  </tr>
                </table>              </td>
          </tr>                  
      <tr>
        <td  colspan="5"  class="ptText02" style="width:70%;">
        <div id="list">
        <table width="100%"  cellspacing="0" cellpadding="0"   class="List" align="center" style="border-top:solid 1px #000000; border-bottom:none; border-left:solid 1px #000000; border-right:solid 1px #000000;" >
            
            <tr>
			  <td class="tdItem" style="font-weight:bold;">Product</td>
              <td class="tdItem" style="font-weight:bold;">No of Jar</td>
              <td class="tdItem" style="font-weight:bold;">Jar Rate (Oil)</td>
              <td class="tdItem" style="font-weight:bold;">Damage Return</td>
			  <td class="tdItem" style="font-weight:bold;">Rate of Jar</td>
              <td class="tdItem" style="font-weight:bold;">Total</td>
			  <td class="tdItem" style="font-weight:bold;">Narration</td>
              <!--<td class="rightTd" style="width:5%; font-weight:bold;">Add</td>-->
            </tr>
            <tr>
			
			 <?php 
			  $jar_sql=mysql_query("select * from cf_jar where status=1");
			  if($jar_sql && mysql_num_rows($jar_sql)>0)
			  {
			  while($jar_row=mysql_fetch_array($jar_sql))
			  {
			  $jar_kg=$jar_row['jar_kg'];
			  }
			  }
			  else
			  {
			  $jar_kg=0;
			  }
			  ?>  <input type="hidden" name="jar_kg" id="jar_kg" value="<?=$jar_kg?>" >
			
              
               <td class="tdItem"><select class="input1" name="product_jarid1" id="product_jarid1" >
     			<option value="">Select Product</option>
     			<?php 
					$sq_product="select * from cf_open_oil";
					$array1=mysql_query($sq_product);
					while($resprd=mysql_fetch_array($array1))
					{
					?>     	
        				<option value="<?=$resprd['open_stock_id']?>" ><?=$resprd['item_name']?></option>
               		<?php
					}
	 				?>
     		</select></td>
              <td class="tdItem"><input type="text" name="no_jar1" id="no_jar1" class="input1 input3 fxwidth" value="" onKeyUp="jar_total()" ></td>
              <td class="tdItem"><input type="text" name="kg_jar_rate1" id="kg_jar_rate1" class="input1 input3 fxwidth" value="" onKeyUp="jar_total()" ></td>  
              <td class="tdItem"><input type="text" name="jar_damage_return1" id="jar_damage_return1" class="input1 input3 fxwidth" value=""  ></td>  
			  <td class="tdItem"><input type="text" name="jar_per_rs1" id="jar_per_rs1" class="input1 input3 fxwidth" value=""  >
			  <input type="hidden" name="perjar_rs1" id="perjar_rs1" class="input1 input3 fxwidth" value="<?=$resjar1['jar_rate']?>"  >
			  </td>  
              <td class="tdItem"><input type="text" name="tot_jar_line1" id="tot_jar_line1" class="input1 input3 fxwidth" value=""  ></td>
			  <td class="tdItem"><input type="text" name="narration_jar1" id="narration_jar1" class="input1 input3 fxwidth" value=""  ></td>   
              <!--<td width="5%" align="center" class="tr_td rightTd" style="border-right:#6b6b6b solid 1px;">
	  			<a style="cursor:pointer;" onClick="addmorejar('2')"><span id="minjar1"><img src="images/addmore.jpg" /></span></a>	  
	   <span id="maxtin1" style="display:none;" onClick="minmorejar('2');"><img src="images/minus.jpg" /></span>	  </td>-->
            </tr>
                        
          </table> 
          </div>
        
        <div id="divtin2"></div>
         <div id="div3"></div>         </td>
      </tr>
      
      <tr>
              <td colspan="5" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
				  <td  colspan="2" align="right">Grand Total</td>
                  
                  <td width="13%"><input type="text" name="qty_jar_total" id="qty_jar_total"  class="input9"  value="" ></td>
              </tr>

              </table></td>
              </tr>
        
            
            <tr>
            	<td width="19%">
              	  <input type="submit" name="jarsubmit" value="Jar Submit" class="submit-btn" onClick="return validation_jar()"  >
                </td>
            </tr>    
    </table>
    </div>
        
    
    <div id="kg" class="desc">
    <table width="100%" border="0" cellspacing="5" cellpadding="2"  style="border:1px solid #000000; padding:4px;">
           
      <input type="hidden" name="totcnt_kg" id="totcnt_kg" value="<?=$div?>">
   
          <tr>
        <td  colspan="4"  class="ptText02" style="">         </td>
        </tr>
          <tr>
                <td  colspan="4"  class="ptText02" style="">
                <table style="width:100%;">
                  <tr>
                    <td width="4%">No:</td>
                    <?php 
	                //$clientaut = $rws['client_newcode'];
					$arr_code=mysql_query("select * from cf_sales order by sales_id desc limit 1");
					$rw=mysql_fetch_array($arr_code);
					$packcode = $rw['sales_code'] + 1;
				    ?>
                    <input type="hidden" name="salescode" id="salescode" class="input1 input6"  value="<?=$packcode?>" style="float:left;" >
                    <td width="10%">SL-<?=$packcode?></td>
                    <td width="5%" align="right">Date:</td>
                    <td width="20%">
                      <input type="text" name="fromdate2" id="fromdate2" class="input1 input6"  value="" style="float:left;" >
                    </span></td>
                    
                    <td width="10%">Client Name:</td>
                    <td >
                     <select class="input1 " name="clientkg_id" id="clientkg_id" >
                        <option value="">-Select Client-</option>
                        <?php 
                            $sq_client="select * from cf_client";
                            $arrclient=mysql_query($sq_client);
                            while($res1=mysql_fetch_array($arrclient))
                            {
                            ?>  <option value="<?=$res1['client_id']?>"><?=$res1['client_name']?></option>
                            <?php
                            }
                            ?>
                    </select>  
                    </td>
                    <td width="14%">&nbsp;</td>
                  </tr>
                </table>              </td>
          </tr>                  
      <tr>
        <td  colspan="5"  class="ptText02" >
        <div id="list">
        <table width="100%"  cellspacing="0" cellpadding="0"   class="List" align="center" style="border-top:solid 1px #000000; border-bottom:none; border-left:solid 1px #000000; border-right:solid 1px #000000;" >
            
            <tr>
			  <td class="tdItem" style="font-weight:bold;">Product</td>
              <td class="tdItem" style="font-weight:bold;">Qty (kg)</td>
              <td class="tdItem" style="font-weight:bold;">Kg Rate</td>
              <td class="tdItem" style="font-weight:bold;">Total</td>
			  <td class="tdItem" style="font-weight:bold;">Narration</td>
              <td class="rightTd" style="font-weight:bold;">Add</td>
              
            </tr>
           
            <tr>
			  <td class="tdItem"><select class="input1" name="product_kgid1" id="product_kgid1" >
     			<option value="">Select Product</option>
     			<?php 
					$sq_product="select * from cf_open_oil";
					$array1=mysql_query($sq_product);
					while($resprd=mysql_fetch_array($array1))
					{
					?>     	
        				<option value="<?=$resprd['open_stock_id']?>" ><?=$resprd['item_name']?></option>
               		<?php
					}
	 				?>
     		</select></td>
              <td class="tdItem"><input type="text" name="qtykg1" id="qtykg1" class="input1 input3 fxwidth" value=""  onKeyUp="kg_total()"></td>  
              <td class="tdItem"><input type="text" name="kgrate1" id="kgrate1" class="input1 input3 fxwidth" value=""  onKeyUp="kg_total()"></td>  
              <td class="tdItem"><input type="text" name="linetotkg1" id="linetotkg1" class="input1 input3 fxwidth" value=""  ></td>  
			  <td class="tdItem"><input type="text" name="narration_kg1" id="narration_kg1" class="input1 input3 fxwidth" value=""  ></td> 
              <td align="center" class="tr_td rightTd" style="border-right:#6b6b6b solid 1px;">
	  			<a style="cursor:pointer;" onClick="addmorekg('2')"><span id="minkg1"><img src="images/addmore.jpg" /></span></a>	  
	   <span id="maxkg1" style="display:none;" onClick="minmorekg('2');"><img src="images/minus.jpg" /></span>	  </td>
            </tr>
                       
          </table> 
          </div>
        
        <div id="divkg2"></div>
         <div id="div3"></div>         </td>
      </tr>
      
      <tr>
              <td colspan="5" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td colspan="2" align="right">Total</td>
            
              <td width="35%">
                <input type="text" name="qty_kg_total" id="qty_kg_total"  class="input9"  value="" > </td>
              </tr>

              </table></td>
              </tr>
        
            
            <tr>
            	<td width="19%">
               	  <input type="submit" name="kgsubmit" value="Kg Submit" class="submit-btn" onClick="return validation_kg()"  >
                </td>
            </tr>    
    </table>
    </div>
	
	<div id="barrel" class="desc">
    <table width="100%" border="0" cellspacing="5" cellpadding="2"  style="border:1px solid #000000; padding:4px;">
           
      <input type="hidden" name="totcntw_barrel" id="totcntw_barrel" value="<?=$div?>">
   
          <tr>
        <td  colspan="4"  class="ptText02" style="">         </td>
        </tr>
          <tr>
                <td  colspan="4"  class="ptText02" style="">
                <table style="width:100%;">
                  <tr>
                    <td width="4%">No:</td>
                    <?php 
					 $sq_jars=mysql_query("select * from cf_jar");
                     $resjar1=mysql_fetch_array($sq_jars);
					 $resjar1['jar_rate'];
					
	                //$clientaut = $rws['client_newcode'];
					$arr_code=mysql_query("select * from cf_sales order by sales_id desc limit 1");
					$rw=mysql_fetch_array($arr_code);
					$packcode = $rw['sales_code'] + 1;
				    ?>
                    <input type="hidden" name="salescode" id="salescode" class="input1 input6"  value="<?=$packcode?>" style="float:left;" >
                    <td width="10%">SL-<?=$packcode?></td>
                    <td width="5%" align="right">Date:</td>
                    <td width="20%">
                      <input type="text" name="fromdate4" id="fromdate4" class="input1 input6"  value="" style="float:left;" >
                    </span></td>
                    
                    <td width="10%">Client Name:</td>
                    <td >
                     <select class="input1 " name="clientbarrel_id" id="clientbarrel_id" >
                        <option value="">-Select Client-</option>
                        <?php 
                            $sq_client="select * from cf_client";
                            $arrclient=mysql_query($sq_client);
                            while($res1=mysql_fetch_array($arrclient))
                            {
                            ?>  <option value="<?=$res1['client_id']?>"><?=$res1['client_name']?></option>
                            <?php
                            }
                            ?>
                    </select>  
                    </td>
                    <td width="14%">&nbsp;</td>
                  </tr>
                </table>              </td>
          </tr>                  
      <tr>
        <td  colspan="5"  class="ptText02" style="width:70%;">
        <div id="list">
        <table width="100%"  cellspacing="0" cellpadding="0"   class="List" align="center" style="border-top:solid 1px #000000; border-bottom:none; border-left:solid 1px #000000; border-right:solid 1px #000000;" >
            
            <tr>
			  <td class="tdItem" style="font-weight:bold;">Product</td>
              <td class="tdItem" style="font-weight:bold;">No of Barrel</td>
			  <td class="tdItem" style="font-weight:bold;">Rate of Barrel</td>
              <td class="tdItem" style="font-weight:bold;">Barrel Oil Rate (Per Barrel)</td>
			  <!--<td class="tdItem" style="font-weight:bold;">Damage Return</td>-->
			  <td class="tdItem" style="font-weight:bold;">Total</td>
			  <td class="tdItem" style="font-weight:bold;">Narration</td>
              <!--<td class="rightTd" style="width:5%; font-weight:bold;">Add</td>-->
            </tr>
            <tr>
			
			 <?php 
			  $barrel_sql=mysql_query("select * from cf_barrel where status=1");
			  if($barrel_sql && mysql_num_rows($barrel_sql)>0)
			  {
			  while($barrel_row=mysql_fetch_array($barrel_sql))
			  {
			  $barrel_kg=$barrel_row['barrel_kg'];
			  $barrel_rate=$barrel_row['barrel_rate'];
			  }
			  }
			  else
			  {
			  $barrel_kg=0;
			  }
			  ?>  <input type="hidden" name="barrel_kg" id="barrel_kg" value="<?=$barrel_kg?>" >
			
              
               <td class="tdItem"><select class="input1" name="product_barrelid1" id="product_barrelid1" >
     			<option value="">Select Product</option>
     			<?php 
					$sq_product="select * from cf_open_oil";
					$array1=mysql_query($sq_product);
					while($resprd=mysql_fetch_array($array1))
					{
					?>     	
        				<option value="<?=$resprd['open_stock_id']?>" ><?=$resprd['item_name']?></option>
               		<?php
					}
	 				?>
     		</select></td>
              <td class="tdItem"><input type="text" name="no_barrel1" id="no_barrel1" class="input1 input3 fxwidth" value="" onKeyUp="barrel_total()" ></td>
			  <td class="tdItem"><input type="text" name="barrel_per_rs1" id="barrel_per_rs1" class="input1 input3 fxwidth" value="<?=$barrel_rate?>" readonly="readonly"  >
			  <input type="hidden" name="perbarrel_kg1" id="perbarrel_kg1" class="input1 input3 fxwidth" value="<?=$barrel_kg?>"  >
			  </td>  
              <td class="tdItem"><input type="text" name="kg_barrel_rate1" id="kg_barrel_rate1" class="input1 input3 fxwidth" value="" onKeyUp="barrel_total()" ></td> 			   
              <!--<td class="tdItem"><input type="text" name="jar_damage_return1" id="jar_damage_return1" class="input1 input3 fxwidth" value=""  ></td> --> 
			  
              <td class="tdItem"><input type="text" name="tot_barrel_line1" id="tot_barrel_line1" class="input1 input3 fxwidth" value=""  ></td> 
			  <td class="tdItem"><input type="text" name="narration_barrel1" id="narration_barrel1" class="input1 input3 fxwidth" value="" ></td> 
              <!--<td width="5%" align="center" class="tr_td rightTd" style="border-right:#6b6b6b solid 1px;">
	  			<a style="cursor:pointer;" onClick="addmorejar('2')"><span id="minjar1"><img src="images/addmore.jpg" /></span></a>	  
	   <span id="maxtin1" style="display:none;" onClick="minmorejar('2');"><img src="images/minus.jpg" /></span>	  </td>-->
            </tr>
                        
          </table> 
          </div>
        
        <div id="divtin2"></div>
         <div id="div3"></div>         </td>
      </tr>
      
      <tr>
              <td colspan="5" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
				  <td  colspan="2" align="right">Grand Total</td>
                  
                  <td width="13%"><input type="text" name="qty_barrel_total" id="qty_barrel_total"  class="input9"  value="" ></td>
              </tr>

              </table></td>
              </tr>
        
            
            <tr>
            	<td width="19%">
              	  <input type="submit" name="barrelsubmit" value="Barrel Submit" class="submit-btn" onClick="return validation_barrel()"  >
                </td>
            </tr>    
    </table>
    </div>
    </form>
    
  </div>
  <div style="text-align:center;">
    
  </div>
</div>
   </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
  <?php 
	include("leftlink.php");
?>

</div>
</body>
</html>


		






