<?
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';

		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_date,add_date) values ('$salestype','$clientid','$salescode','$packageqty','$from_date','$addate')");			
			$lastid = mysql_insert_id();
			
			$cnt = $_POST['totcnt_box'];
			for($i=1;$i<=$cnt;$i++)
			{
				
				if(isset($_POST['branch'.$i])){
				$branchid=addslashes($_POST['branch'.$i]);
				}
				
				if(isset($_POST['literqty'.$i])){
				$literqty=addslashes($_POST['literqty'.$i]);
				}
		
				if(isset($_POST['kg_liter'.$i])){
				$kgliter=addslashes($_POST['kg_liter'.$i]);
				}
				
				if(isset($_POST['boxqty'.$i])){
				$boxqty=addslashes($_POST['boxqty'.$i]);
				}
				
				if(isset($_POST['ratebox'.$i])){
				$ratebox=addslashes($_POST['ratebox'.$i]);
				}
				
				if(isset($_POST['damagereturn_qty'.$i])){
				$damagereturnqty=addslashes($_POST['damagereturn_qty'.$i]);
				}
				
				if(isset($_POST['linetot'.$i])){
				$linetot=addslashes($_POST['linetot'.$i]);
				}
				
				
				$sql2 = mysql_query("insert into cf_sales_sub (sale_id,branch_id,liter_id,sale_box,sale_rate,sale_damage_qty,sale_date,sale_line_tot) values ('$lastid','$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'];
				
				
				$packqty = $liter_box*$boxqty;
				$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 - $packqty;
					$updtpackbox = $skupackbox - $boxqty;
					//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'");
				}
					
				}
			
			
			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_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_date,add_date) values ('$salestype','$clientid','$salescode','$from_date','$addate')");			
			$lastid = mysql_insert_id();
			
			$cnt = $_POST['totcntw_tin'];
			for($i=1;$i<=$cnt;$i++)
			{
				
				if(isset($_POST['no_tin'.$i])){
				$notin=addslashes($_POST['no_tin'.$i]);
				}
				
				if(isset($_POST['kg_tin_rate'.$i])){
				$kgtinrate=addslashes($_POST['kg_tin_rate'.$i]);
				}
		
				if(isset($_POST['tin_damage_return'.$i])){
				$tindamagereturn=addslashes($_POST['tin_damage_return'.$i]);
				}
				
				if(isset($_POST['tot_tin_line'.$i])){
				$totinline=addslashes($_POST['tot_tin_line'.$i]);
				}
				
				
				$sql2 = mysql_query("insert into cf_sales_sub (sale_id,sale_no_tin_kg,sale_rate,sale_damage_qty,sale_date,sale_line_tot) values ('$lastid','$notin','$kgtinrate','$tindamagereturn','$addate','$totinline')");
					
				}
			
			
			//header("location:package-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_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_date,add_date) values ('$salestype','$clientid','$salescode','$from_date','$addate')");			
			$lastid = mysql_insert_id();
			
			$cnt = $_POST['totcnt_kg'];
			for($i=1;$i<=$cnt;$i++)
			{
				
				if(isset($_POST['qtykg'.$i])){
				$qtykg=addslashes($_POST['qtykg'.$i]);
				}
				
				if(isset($_POST['kgrate'.$i])){
				$kgrate=addslashes($_POST['kgrate'.$i]);
				}
		
				if(isset($_POST['linetotkg'.$i])){
				$linetotkg=addslashes($_POST['linetotkg'.$i]);
				}
				
				$sql2 = mysql_query("insert into cf_sales_sub (sale_id,sale_no_tin_kg,sale_rate,sale_date,sale_line_tot) values ('$lastid','$qtykg','$kgrate','$addate','$linetotkg')");
					
				}
			
			
			//header("location:package-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'
});


});

/*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_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(){
var $this = $(this);
var str = $this.val();
	$this.parent().parent().find('.kg_ltr').val('');
// document.getElementById("kg_liter"+i).value = '';
var xmlhttp;    
if (str=="")
  {
 // document.getElementById("txtLiter"+i).innerHTML="";
 $this.parent().parent().find('.kg_ltr').parent('.liter-size').html('');
  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)
    {
		$this.parent().parent().find('.kg_ltr').parent('.liter-size').html(xmlhttp.responseText);
	  // document.getElementById("txtLiter"+i).innerHTML=xmlhttp.responseText;
    }
  }
   i=0;
xmlhttp.open("GET","package_ajax.php?str="+str+"&cnt="+i,true);
xmlhttp.send();
}

function showKg(){
//alert('aa');
var $this = $(this);
val = $this.val();
var userid = $(this).attr('data-id');
//var brand = document.getElementById('branch'+i).value;
var brand = $this.parent().parent().parent().find('.brand-list').val();
console.log($this.parent().parent().parent().find('.brand-list'));
var xmlhttp;    
if (val=="")
  {
 // document.getElementById('txtKglitre'+i).innerHTML="";
  $this.parent().parent().find('.kg_ltr').parent().html('');
  
  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)
    {
	    $this.parent().parent().parent().find('.kg_ltr').parent().html(xmlhttp.responseText);
    }
  }
  i=0;
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); 
	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 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('ratebox'+j).value;
		
		totltr = parseFloat(literboxqty)*parseFloat(kglt)*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 tinsaletotal=0;
	//alert(cnts);
	
	for(k=1;k<=cnts;k++){		
		notin = document.getElementById('no_tin'+k).value;
		
		kgtinrate = document.getElementById('kg_tin_rate'+k).value;
		
		tot_tin = parseFloat(notin)*parseFloat(kgtinrate)*100;
		
		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);
		
}

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(){

$this = $(this);
var literid = '';
//var cnt = document.getElementById('totcntw_tin').value;
literid = $this.parent().parent().find('.liter-size').val(); //document.getElementById('literqty'+cnt).value;
//var brandid = document.getElementById('branch'+cnt).value
brandid = $this.parent().parent().find('.brand-list').val(); 
val = $(this).val();


//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 = '';
			$this.val('');
		}
	   //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();
    }); 
	
	jQuery('.add-new').live('click',addNewRow);
	jQuery('.remove-row').live('click',removeRow);
	jQuery('.brand-list').live('click',showLiter);
	jQuery('.liter-size').live('click',showKg);
});




function addNewRow(){
	$this = $(this);
	var row = $this.parent().parent();
	var table = row.parent();
	cloneRow = row.clone();
	cloneRow.find('.add-new').attr({'class':'remove-row','src':'images/minus.jpg'});
	table.append(cloneRow);
}
function removeRow(){
	$this = $(this);
	var row = $this.parent().parent();
	row.remove();
}





</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="74%" align="left" valign="top"><label>
          <input type="radio" name="group1" value="kg">
          Kg</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;">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;">Damage Return</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 fxwidth brand-list" name="branch1" id="branch1">
     			<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 liter-size" name="literqty1" id="literqty1">
     			<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 kg_ltr" value=""    ></div></td>      
                     
              <td class="tdItem">
			  <input type="text" name="boxqty1" id="boxqty1" class="input1 input3 fxwidth box-qty" value="" onKeyUp="qtytotal();chkboxqty(this.value,<?=$div?>);"></td>   
              <td class="tdItem">
			  <input type="text" name="ratebox1" id="ratebox1" class="input1 input3 fxwidth rate-box" data-id="1" value="" onKeyUp="qtytotal()" ></td>      
              <td class="tdItem">
			  <input type="text" name="damagereturn_qty1" id="damagereturn_qty1" class="input1 input3 fxwidth dmg-qty" value=""  ></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;">
	  		 <img style="cursor:pointer;" class="add-new" src="images/addmore.jpg" /> </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="44%">
                <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 
	                //$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;">No of Tins</td>
              <td class="tdItem" style="font-weight:bold;">Kg Rate</td>
              <td class="tdItem" style="font-weight:bold;">Damage Return</td>
              <td class="tdItem" style="font-weight:bold;">Total</td>
              <td class="rightTd" style="width:5%; font-weight:bold;">Add</td>
            </tr>
            <tr>
              
              
              <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="tot_tin_line1" id="tot_tin_line1" 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="minmore('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">Total</td>
                  <td width="44%">
                <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="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;">Qty</td>
              <td class="tdItem" style="font-weight:bold;">Kg Rate</td>
              <td class="tdItem" style="font-weight:bold;">Total</td>
              <td class="rightTd" style="font-weight:bold;">Add</td>
              
            </tr>
           
            <tr>
              <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 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="minmore('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="44%">
                <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>
    </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>


		






