<link rel="stylesheet" href="css/new_mxerp.css">
<?php
$PageSecurity = 1;
include('includes/DefinePaymentClass.php');
$title = _('Invoice');
include('includes/SQL_CommonFunctions.inc');
$exciserate=$s->getField('excise_tax','label','Excise','def_rate');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;

$getLastId=DB_query("Select invoiceNo from invoice order by invoice_id DESC LIMIT 1",$db);
$getLastIdResult=DB_fetch_array($getLastId);
$NewID=$getLastIdResult['invoiceNo']+1;

$time=date('h:i', time());
$period=date(A);
$timestamp = date("H:i", time());

function convertTime($time,$period)
{
	$timeBRK=explode(':',$time);
	if($period=='PM' && $timeBRK[0]!='12')
	{
		$time=$timeBRK[0]+12;
	}
	else 
	{
		$time=$timeBRK[0];
	}
	return $time.":".$timeBRK[1];
}

if($_REQUEST['Save_invoice'])
{
  $fstatus=true;
  if($_REQUEST['branch_name']=='000')
  {
  	  $msgErr[]="Please Select Branch Name"	;
      $fstatus=false;
  }
  if($_REQUEST['voucher_no']=='')
  {
  	  $msgErr[]="Please Enter Voucher no"	;
      $fstatus=false;
  }
   if($_REQUEST['Dates']=='')
  {
  	  $msgErr[]="Please Enter Date"	;
      $fstatus=false;
  }
  
  if($_REQUEST['Ref_no']=='')
  {
  	  $msgErr[]="Please Enter Reference No"	;
      $fstatus=false;
  }
  if(count($_SESSION['ACGLedgerId'])==0 && $_REQUEST['action']!='Edit')
  {
      	  $msgErr[]="Please Select DR/CR Amount "	;
     	 $fstatus=false;
   }

}

function number_to_words ($x)
{
	$nwords = array("","one","two","three","four","five","six", 
	"seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", 
	"fourteen", "fifteen", "sixteen", "seventeen", "eightteen", 
	"nineteen", "twenty", 30 => "thirty", 40 => "fourty",
	50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eigthy",
	90 => "ninety" );
     if(!is_numeric($x))
     {
         $w = '#';
     }else if(fmod($x, 1) != 0)
     {
         $w = '#';
     }else{
         if($x < 0)
         {
             $w = 'minus ';
             $x = -$x;
         }else{
             $w = '';
         }
         if($x < 21)
         {
             $w .= $nwords[$x];
         }else if($x < 100)
         {
             $w .= $nwords[10 * floor($x/10)];
             $r = fmod($x, 10);
             if($r > 0)
             {
                 $w .= ' '. $nwords[$r];
             }
         } else if($x < 1000)
         {
                
                $w .= $nwords[floor($x/100)] .' hundred';
             $r = fmod($x, 100);
             if($r > 0)
             {
                 $w .= ' '. number_to_words($r);
             }
         } else if($x < 1000000)
         {
                $w .= number_to_words(floor($x/1000)) .' thousand';
             $r = fmod($x, 1000);
             if($r > 0)
             {
                 $w .= ' ';
                 if($r < 100)
                 {
                     $w .= ' ';
                 }
                 $w .= number_to_words($r);
             }
         } else {
             $w .= number_to_words(floor($x/1000000)) .' million';
             $r = fmod($x, 1000000);
             if($r > 0)
             {
                 $w .= ' ';
                 if($r < 100)
                 {
                     $word .= ' ';
                 }
                 $w .= number_to_words($r);
             }
         }
     }
     return $w;}

if($_REQUEST['Save_invoice'])
{

   $sitename=$s->GetFieldValue('locations',"loccode='".$_REQUEST['branch_name']."'",'prefix');
	$sqlqut=DB_query("select * from invoice where branch_name='".$_REQUEST['branch_name']."'",$db);
	if(DB_num_rows($sqlqut)>0)
	{
	$SQLMax=DB_query("select invoiceNo as QutNo from invoice where branch_name='".$_REQUEST['branch_name']."' 
	order by invoice_id desc limit 0,1",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$MXNo=substr($MaxQut['QutNo'],-2);
	$FinMx=$MXNo+1;
	$FinalCode=$sitename."/"."INV"."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$sitename."/"."INV"."/".'00001';
	}




	$data['branch_name']=$_REQUEST['branch_name'];
	$data['invoiceType']=$_REQUEST['invoiceType'];
	$data['invoiceNo']=$FinalCode;
	$data['invoiceDate']=FormatDateForSQL($_REQUEST['invoiceDate']);
	$data['invoiceTime']=$_REQUEST['invoiceTime'];
	$data['invoiceAMPM']=$_REQUEST['invoiceTime'];
	$data['removalDate']=FormatDateForSQL($_REQUEST['removalDate']);
	$data['removalTime']=$_REQUEST['removalTime'];
	$data['removalAMPM']=$_REQUEST['invoiceTime'];
	$data['documentType']=$_REQUEST['documentType'];
	$data['consignee']=$_REQUEST['consignee'];
	$data['lrNo']=$_REQUEST['grNo'];
	$data['lrDate']=$_REQUEST['grDate'];
	$data['client_id']=$_REQUEST['client_id'];
	$data['partyPO']=$_REQUEST['partyPO'];
	$data['cuurentBalance']=$_REQUEST['cuurentBalance'];
	$data['dispatchThrough']=$_REQUEST['dispatchThrough'];
	$data['excisableComm']=$_REQUEST['excisableComm'];
	$data['transportMode']=$_REQUEST['transportMode'];
	$data['transporter']=$_REQUEST['transporter'];
	$data['vehicleNo']=$_REQUEST['vehicleNo'];
	$data['formType']=$_REQUEST['formType'];
	$data['formNo']=$_REQUEST['formNo'];
	$data['payTerms']=$_REQUEST['payTerms'];
	$data['challanNo']=$_REQUEST['challanNo'];
	$data['basicAmount']=$_REQUEST['basicAmount'];
	$data['totalDiscountedPrice']=$_REQUEST['totalDiscountedPrice'];
	$data['exciseDuty']=$_REQUEST['exciseDuty'];
	$data['exciseValue']=$_REQUEST['exciseValue'];
	$data['ECessPercentage']=$_REQUEST['ECessPercentage'];
	$data['Ecess_ledger']=$_REQUEST['Ecess_ledger'];
	$data['ECessValue']=$_REQUEST['ECessValue'];
	$data['SAHCessPercentage']=$_REQUEST['SAHCessPercentage'];
	$data['SCess_ledger']=$_REQUEST['SCess_ledger'];
	$data['SAHCessValue']=$_REQUEST['SAHCessValue'];
	$data['taxableAmount']=$_REQUEST['taxableAmount'];
	$data['VatCst']=$_REQUEST['VatCst'];
	$data['VatCst_ledger']=$_REQUEST['VatCst_ledger'];
	$data['VatCstValue']=$_REQUEST['VatCstValue'];
	$data['freightValue']=$_REQUEST['freightValue'];
	$data['packagingCharges']=$_REQUEST['packagingCharges'];
	$data['roundOff']=$_REQUEST['roundOff'];
	$data['grandTotal']=$_REQUEST['grandTotal'];
	$data['excise_duty_inwords']=$_REQUEST['excise_duty_inwords'];
	$data['Excise_Effect']=$_REQUEST['Excise_Effect'];
	$data['ledger_id']=$_REQUEST['ledger_id'];
	$data['invoice_status']=$_REQUEST['invoice_status'];
	$data['pending_amount']=$_REQUEST['pending_amount'];
	$data['created_by']=$_SESSION['IserID'];
	$data['CompanyId']=$_REQUEST['ACGCompanyId'];
	$data['invoicemode']='Direct';
	$data['created_date']=date('Y/m/d');
	$row= $s->RecordInsert('invoice', $data);
	$lastid=DB_Last_Insert_ID($db,'invoice', 'invoice_id');
	
	
	
	for($i=0;$i<count($_REQUEST['item_code']);$i++)
			{
				$data_arr['invoiceid']= $lastid;
				$data_arr['ItemCode']= $_POST['item_code'][$i];
				$data_arr['store']=$_REQUEST['store'][$i];
				$data_arr['PackageDesc']= $_POST['desc_pkg'][$i];
				$data_arr['Quantity']= $_REQUEST['qty'][$i];
				$data_arr['RatePerThousand']= $_POST['rate'][$i];
				$data_arr['Amount']= $_POST['amt'][$i];
				$data_arr['discountType']= $_REQUEST['discount_type'][$i];
				$data_arr['discount']= $_REQUEST['discount'][$i];
				$data_arr['discount']= $_REQUEST['discount'][$i];
				$data_arr['EdRate']= $_REQUEST['EDRate'][$i];
				$data_arr['EdAmount']= $_REQUEST['ED_Amt'][$i];
				$data_arr['valueAfterDisc']= $_REQUEST['disc_value'][$i];
				$data_arr['otherSpecs']= $_REQUEST['otherSpecs'][$i];
				$data_arr['ExpireDate']=FormatDateForSQL($_REQUEST['Exp_date'][$i]);
				$row= $s->RecordInsert('invoice_details', $data_arr);
			}
	
	
	
	
			
			
			
	$s->pageLocation("index.php?route=ViewInvoice".$rurl);
	//echo "<pre>";
	//print_r($data);
	//exit;
}
 ?>
<!---------------------AJAX FILE-----------------STRAT HERE-------------30-01-2013---------------------------------------->
<script language="javascript" type="text/javascript">
function GetURL(str)
{
	var branch_name=document.getElementById("branch_name").value;
	var client=document.getElementById("client_id").value;
	location.replace("index.php?route=invoice&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=addnew&po_no="+str+"&branch_name="+branch_name+"&client_id="+client);
}


function calculateAmount(j)
{
	var qty=document.getElementById("Quantity_"+j).value;
	var rate=document.getElementById("RatePerThousand_"+j).value;
	var rateperthousand=rate/1;
	var total=qty*rateperthousand;
	document.getElementById("Amount_"+j).value=total.toFixed(2);
}


function showclient111(str)
{
	var branch=document.getElementById("branch_name").value;
	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)
	{
	var data=xmlhttp.responseText.split("__");
	
	document.getElementById("Address").innerHTML=data[0];
	
	//document.getElementById("dispatchNo").innerHTML=data[1];
	document.getElementById("consignee").innerHTML=data[2];
	}
	}
	xmlhttp.open("GET","GetClientAddress.php?ClientID="+str,true);
	xmlhttp.send();
}


function showconsigneeeaddress(str)
{

	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)
	{
	var data=xmlhttp.responseText.split("__");
	
	document.getElementById("consigneeaddress").innerHTML=data[0];
		}
	}
	xmlhttp.open("GET","GetClientconsigneeAddress.php?ClientID="+str,true);
	xmlhttp.send();
}


function showtransportercode(str)
{
   if(str=='')
   {
   document.getElementById("transportercode").value='';
   }
	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("transportercode").value=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","Gettransportercode.php?ClientID="+str,true);
	xmlhttp.send();
}


function showDispatchDetails(str)
{
	if (str=="")
	{
	document.getElementById("productId").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(xmlhttp.responseText);
	document.getElementById("productId").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","getDispatchItems.php?dispatchNum="+str,true);
	xmlhttp.send();
}




function calculateBasic()
{

if(document.getElementById("rowcount"))
{
var first_row=0;
var totalBasic=0;
var  totalBasic111=0;
var first_row1=0;
var newcount=document.getElementById("rowcount").value;
for(var i=0;i<newcount;i++)
	{
	   
	 	var totalBasic1=document.getElementById("Amount_"+i).value;
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
	}

}
else
{

var  totalBasic111=0;
var first_row1=0;
	var totalBasic=0;
	if(document.getElementById("amt"))
	var first_row=document.getElementById("amt").value;
	else
	var first_row=0;
	
	if(document.getElementById("excisevalue1"))
	var first_row1=document.getElementById("excisevalue1").value;
	else
	var first_row1=0;
	
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	    if(document.getElementById("amt_"+i))
	 	var totalBasic1=document.getElementById("amt_"+i).value;
		else
		var totalBasic1=0;
	 	var totalBasic=(parseFloat(totalBasic)+parseFloat(totalBasic1)).toFixed(2);
		
		
		if(document.getElementById("excisevalue1_"+i))
	 	var totalBasic11=document.getElementById("excisevalue1_"+i).value;
		else
		var totalBasic11=0;
	 	var totalBasic111=(parseFloat(totalBasic111)+parseFloat(totalBasic11)).toFixed(2);
		
		
		
	}
}
	  document.getElementById("basicAmount").value=parseFloat(totalBasic)+parseFloat(first_row);
	  document.getElementById("totalDiscountedPrice").value=parseFloat(totalBasic)+parseFloat(first_row);
	  document.getElementById("exciseValue").value=parseFloat(totalBasic111)+parseFloat(first_row1);
	  if(totalBasic111!=0)
	   document.getElementById("exdut").disabled=true;
}

function calculateDiscounted()
{
if(document.getElementById("rowcount"))
   {
   var totalDiscounted=0;
   var first_row=0;
   
   var newcount=document.getElementById("rowcount").value;
      for(var i=0;i<newcount;i++)
	{
	 	var totaldisc=document.getElementById("valueAfterDisc_"+i).value;
	 	var totalDiscounted=(parseFloat(totalDiscounted)+parseFloat(totaldisc)).toFixed(2);
	}
   
   
   }
  else
  {
	var totalDiscounted=0;
	var first_row=document.getElementById("disc_value").value;
	//if(first_row==''){first_row=0;}
	var cnt=document.getElementById("hiditemcount").value;
	var newcount=parseInt(cnt)+1;
	for(var i=1;i<newcount;i++)
	{
	var totaldisc=document.getElementById("disc_value_"+i).value;
	totalDiscounted=parseFloat(totalDiscounted)+parseFloat(totaldisc);	
	}
}
	document.getElementById("totalDiscountedPrice").value=parseFloat(totalDiscounted)+parseFloat(first_row);
}

function claculateExcise(str)
{
	var discounted=document.getElementById("amt").value;
	if (str.length==0)
	{
	document.getElementById("exciseId").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("exciseId").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?taxId="+str+"&discounted="+discounted,true);
	xmlhttp.send();
}

function calculateVATCST(str)
{
	if (str.length==0)
	{
	document.getElementById("vat_rate").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("vat_rate").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?salesId1="+str,true);
	xmlhttp.send();
}

function CalculateVatCstValue()
{
	var taxableammount12=document.getElementById("taxableAmount").value;
	var str=document.getElementById("vat_rate").value;
	var VAtCst1= parseFloat(str)*parseFloat(taxableammount12)*.01;
	document.getElementById("VatCstValue").value=VAtCst1.toFixed(2);
}

function calculateECess()
{
	var exciseValue=document.getElementById("exciseValue").value;
	var ECessPercentage=document.getElementById("ECessPercentage").value;
	var total=(exciseValue*(ECessPercentage/100)).toFixed(2);
	document.getElementById("ECessValue").value=total;
}

function calculateSAHCess()
{
	var exciseValue=document.getElementById("exciseValue").value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage").value;
	var total=exciseValue*(SAHCessPercentage/100).toFixed(2);
	document.getElementById("SAHCessValue").value=total;
}

function calculateTaxable()
{
	var totalDiscountedPrice=document.getElementById("totalDiscountedPrice").value;
	var exciseValue=document.getElementById("exciseValue").value;
	var ECessValue=document.getElementById("ECessValue").value;
	var SAHCessValue=document.getElementById("SAHCessValue").value;
	if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(exciseValue==''){exciseValue=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxableAmount").value=TOTAL.toFixed(2);
}

function calculateGrand()
{
	var a=document.getElementById("basicAmount").value;
	var b=document.getElementById("totalDiscountedPrice").value;
	var c=document.getElementById("taxableAmount").value;
	var d=document.getElementById("VatCstValue").value;
	var e=document.getElementById("ECessValue").value;
	var f=document.getElementById("SAHCessValue").value;
	var g=document.getElementById("value2").value;
	var h=document.getElementById("value1").value;
	var i=document.getElementById("value4").value;
	if(a==''){a=0;}
	if(b==''){b=0;}
	if(c==''){c=0;}
	if(d==''){d=0;}
	if(e==''){e=0;}
	if(f==''){f=0;}
	if(g==''){g=0;}
	if(h==''){h=0;}
	if(i==''){i=0;}
	var GRAND=parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e)+parseFloat(f)+parseFloat(g)+parseFloat(h)+parseFloat(i);
	//alert(GRAND.toFixed(2));
	grandBrk=GRAND.toFixed(2).split('.');
	grandA=grandBrk[0];
	grandB=grandBrk[1];
	//alert(grandA);
	//alert(grandB);
	if(grandB>'50' || grandB=='50')
	{
	GRAND11=parseInt(GRAND)+1;
	}
	else
	if(grandB<'50')
	{
	GRAND11=parseInt(GRAND);
	}	
	document.getElementById("grandTotal").value=GRAND11.toFixed(2);
	var data=toWords(GRAND11);
	document.getElementById("roundOff").value="."+grandB;
}


function calculateDiscount(str,a)
{
	var discType=document.getElementById("discountType_"+a).value;
	var value=document.getElementById("Amount_"+a).value;
	if(str==''){str=0;}
	if(discType=='A') 
	{
	var discount=str;
	}
	else
	if(discType=='P') 
	{
	var discount=value*(str/100);	
	}
	document.getElementById("valueAfterDisc_"+a).value=(parseFloat(value)-parseFloat(discount)).toFixed(2);
}

function getTarrifHeading(str)
{
	if (str.length==0)
	{
	document.getElementById("commID").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("commID").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","get_category.php?comm="+str,true);
	xmlhttp.send();
}


var th = ['','Thousand','Million', 'Billion','Trillion'];
var dg = ['Zero','One','Two','Three','Four', 'Five','Six','Seven','Eight','Nine']; var tn = ['Ten','Eleven','Twelve','Thirteen', 'Fourteen','Fifteen','Sixteen', 'Seventeen','Eighteen','Nineteen']; var tw = ['Twenty','Thirty','Forty','Fifty', 'Sixty','Seventy','Eighty','Ninety']; 

function toWords(st)
{
	s=st;
	s = s.toString(); s = s.replace(/[\, ]/g,'');  if (s != parseFloat(s)) return 'not a number'; var x = s.indexOf('.'); if (x == -1) x = s.length; if (x > 15) return 'too big'; var n = s.split(''); var str = ''; var sk = 0; for (var i=0; i < x; i++) {if ((x-i)%3==2) {if (n[i] == '1') {str += tn[Number(n[i+1])] + ' '; i++; sk=1;} else if (n[i]!=0) {str += tw[n[i]-2] + ' ';sk=1;}} else if (n[i]!=0) {str += dg[n[i]] +' '; if ((x-i)%3==0) str += 'hundred ';sk=1;} if ((x-i)%3==1) {if (sk) str += th[(x-i-1)/3] + ' ';sk=0;}} 
	if (x != s.length) {var y = s.length; str += 'point '; for (var i=x+1; i<y; i++) str += dg[n[i]] +' ';} 
	document.getElementById("lable1").value=str;
	//return str.replace(/\s+/g,' ');
}

function tonumber()
{
	var s=document.getElementById("exciseValue").value;
	var s1=document.getElementById("ECessValue").value;
	var s2=document.getElementById("SAHCessValue").value;
	var s3=parseFloat(s)+parseFloat(s1)+parseFloat(s2);
	document.getElementById("total_excise_duty").value=s3.toFixed(2);
}

function invoiceCode(str)
{
	if (str.length==0)
	{
	document.getElementById("invoiceDiv").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("invoiceDiv").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","generateInvoiceNo.php?site="+str,true);
	xmlhttp.send();
}

function calculateedamount()
{	
	var cnt=document.getElementById("rowcount").value;
	var tataledamount=0;
	for(var i=0;i<cnt;i++)
	{
	var EDAmount=document.getElementById("EDAmt_"+i).value;
	tataledamount=parseFloat(tataledamount)+parseFloat(EDAmount);
	}
	if(tataledamount!='0')
	{
	document.getElementById("exciseValue").value=tataledamount.toFixed(2);
	}
}

function calculateExcise(str,id)
{

	var id_brk=id.split('_');
	var i=id_brk[1];
	if(id_brk.length>1)
	{
		divid="excisevalue1_"+i;
		var amount=document.getElementById("amt_"+i).value;
	}
	else
	{
		divid="excisevalue1";
		var amount=document.getElementById("amt").value;
	}
	if(str.length==0)
	{
		document.getElementById(divid).value="";
		return;
	}
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		xmlhttp	=new ActiveXobject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById(divid).value=xmlhttp.responseText;
		
	}
	
}
xmlhttp.open("GET","calculateExcise.php?type=TELORD&amount="+amount+"&q="+str,true);
xmlhttp.send();	
	
} 




function showstorecode(str)
{
	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)
	{
	
	var data=xmlhttp.responseText.split("__");	
	
	document.getElementById("store").innerHTML=data[0];
	
	}
	}
	xmlhttp.open("GET","invoice_direct_store.php?site="+str,true);
	xmlhttp.send();
}


function calcValue1(str,id)
{
	var brk=id.split('_');
	if(brk.length==1)
	{
	  // if(parseFloat(str)>parseFloat(document.getElementById("total_stock").value))
//	   {
//	   alert("Qty Should be less or equal then Stock Qty");
//	   document.getElementById("qty").value='';
//	   return false;
//	   }
       //else
	   {	
		var price=document.getElementById("stock_price").value;
		if(price!=''){
		var perunit=document.getElementById("stock_perunit").value;
		var tot=str*(price/perunit);
		document.getElementById("stock_value").value=tot;}
		}
	}
	else
	{
	 // if(parseFloat(str)>parseFloat(document.getElementById("total_stock_"+brk[1]).value))
//	   {
//	   alert("Qty Should be less or equal then Stock Qty");
//	   document.getElementById("qty_"+brk[1]).value='';
//	   return false;
//	   }
		var price=document.getElementById("stock_price_"+brk[2]).value;
		if(price!=''){
		var perunit=document.getElementById("stock_perunit_"+brk[2]).value;
		var tot=str*(price/perunit);
		document.getElementById("stock_value_"+brk[2]).value=tot;}
	}
}

function calcValue2(str,id)
{
	var brk=id.split('_');
	if(brk.length==1)
	{
		var qty=document.getElementById("qty").value;
		if(qty!=''){
		var perunit=document.getElementById("rate").value;
		var tot=qty*perunit;
		document.getElementById("amt").value=tot;}
	}
	else
	{
		var qty=document.getElementById("qty_"+brk[1]).value;
		if(qty!=''){
		var perunit=document.getElementById("rate_"+brk[1]).value;
		var tot=qty*perunit;
		document.getElementById("amt_"+brk[1]).value=tot;}
	}
}

function discountvalue(str,id)
{
	var brk=id.split('_');
	if(brk.length==1)
	{
		var Discount_type=document.getElementById("discount_type").value;
		if(Discount_type=='Amount')
		{
		if(document.getElementById("amt").value!='')
		var amt=parseFloat(document.getElementById("amt").value);
		else
		var amt=0;
		if(amt!=''){
		if(document.getElementById("discount").value!='')
		var discount=parseFloat(document.getElementById("discount").value);
		else
		var discount=0;
		var totaldis=amt-discount;
		document.getElementById("disc_value").value=totaldis;}
		
		}
		else
		{
		if(document.getElementById("amt").value!='')
		var amt=parseFloat(document.getElementById("amt").value);
		else
		var amt=0;
		if(amt!=''){
		if(document.getElementById("discount").value!='')
		var discount=parseFloat(document.getElementById("discount").value);
		else
		var discount=0;
		
		var totaldis=amt*(discount/100);
		document.getElementById("disc_value").value=totaldis;}	
		
		}
		
	}
	else
	{
		var Discount_type=document.getElementById("discount_type_"+brk[1]).value;
		if(Discount_type=='Amount')
		{
		
		if(document.getElementById("amt_"+brk[1]).value!='')
		var amt=parseFloat(document.getElementById("amt_"+brk[1]).value);
		else
		var amt=0;
		
		if(amt!=''){
		if(document.getElementById("discount_"+brk[1]).value!='')
		var discount=parseFloat(document.getElementById("discount_"+brk[1]).value);
		else
		var discount=0;		
		var totaldis=amt-discount;
		document.getElementById("disc_value_"+brk[1]).value=totaldis;}
		
		}
		else
		{
		if(document.getElementById("amt_"+brk[1]).value!='')
		var amt=parseFloat(document.getElementById("amt_"+brk[1]).value);
		else
		var amt=0;
		if(amt!=''){
		if(document.getElementById("discount_"+brk[1]).value!='')
		var discount=parseFloat(document.getElementById("discount_"+brk[1]).value);
		else
		var discount=0;
		var totaldis=amt*(discount/100);
		document.getElementById("disc_value_"+brk[1]).value=totaldis;}
			
		}
	}
}

function open_items()
{
var site=document.getElementById("branch_name").value;
if(site!=0)
{
window.open("TelephonicItems_direct.php?site="+site+"&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
else
{
alert("Must Select Branch First");
}
}
<!---------------------AJAX FILE-----------------END HERE-------------30-01-2013---------------------------------------->
</script>   
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>                            
<div class="body_contain">
<div class="tab_div">
<h1>INVOICE</h1>
<form name="invoice" action="" method="post">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td>Branch Name<label><font color="#FF0000">*</font></label><br /></td>
	<td class="tabledata1"><?php  
	$SQL_client=DB_query("SELECT * from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
	?>
	<select name="branch_name" id="branch_name" style="width:160px;" tabindex="1"  onchange="showstorecode(this.value)">
<!--	<option value="0">Select</option>-->
	<?php
	while($row_client=DB_fetch_array($SQL_client))
	{
	?>
	<option value="<?php  echo $row_client['loccode']?>" <?php echo ($branch_name==$row_client['loccode']?'selected':''); ?> >
	<?php  echo $row_client['locationname']?>
	</option>
	<?php }?>
	</select></td>
	<td class="tabledata1">Invoice Type
	  <label><font color="#FF0000">*</font></label></td>
	<td class="tabledata1"><select name="invoiceType" style="width:160px;">
      <option value="0">Select</option>
      <option value="Retail" <?php if($invoiceType=='Retail') echo "selected";?>>Retail</option>
      <option value="Tax" <?php if($invoiceType=='Tax') echo "selected";?>>Tax</option>
    </select></td>
	<td><label>Invoice No.<font color="#FF0000">*</font></label></td>
	<td class="tabledata1"><input type="text" name="invoiceNo" id="invoiceNo" value="<?php echo "Auto Generate";?>" readonly="true" style="width:160px;" /></td>
</tr>
<tr class="row1">
	<td><label>Removal Date/Time<font color="#FF0000">*</font></label></td>
	<td class="tabledata1" id="invoiceDiv"><input type="text" name="removalDate" id="removalDate" value="<?php echo date('d/m/Y');?>" class="datepicker"  style="width:95px;"  />
      <input type="text" name="removalTime" id="removalTime" value="<?php echo $timestamp;?>" style="width:55px;" /></td>
	<td class="tabledata1" id="invoiceDiv">Invoice Date/Time
	  <label><font color="#FF0000">*</font></label></td>
	<td class="tabledata1" id="invoiceDiv"><input type="text" name="invoiceDate" class="datepicker" id="invoiceDate" value="<?php echo date('d/m/Y');?>" style="width:95px;"  />
      <input type="text" name="invoiceTime" id="invoiceTime" value="<?php echo $timestamp;?>"  style="width:55px;" /></td>
	<td><label>Document Type<font color="#FF0000">*</font></label></td>
	<td class="tabledata1"><select  name="documentType" id="documentType" style="width:160px;">
      <option value="0">Select</option>
      <option value="Bill"<?php echo ($documentType=='Bill'?'selected':'')?>>Bill</option>
      <option value="Challan"<?php echo ($documentType=='Challan'?'selected':'')?>>Challan</option>
      <option value="Cash"<?php echo ($documentType=='Cash'?'selected':'')?>>Cash</option>
      <option value="Rejection"<?php echo ($documentType=='Rejection'?'selected':'')?>>Rejection Party</option>
    </select></td>
</tr>

<tr class="row1">
	<td>Party Name<label><font color="#FF0000">*</font></label></td>
	<td>
	<?php
	$ClientSQL=DB_query("Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' order by c_name",$db);?>
	<select name="client_id" id="client_id" style="width:160px;" onChange="showclient111(this.value)" >
		<option value="0">Select</option>
		<?php while($ClientName=DB_fetch_array($ClientSQL)){?>
		<option value="<?php echo $ClientName['id'];?>"<?php echo($client_id==$ClientName['id'] ? 'selected':'');?>><?php echo $ClientName['c_name'];?></option>
		<?php }?>
	</select></td>
	
	
	
	<td>Transporter </td>
	<td ><span class="tabledata1">
	  <select name="transporter" id="transporter" style="width:56px;" onchange="showtransportercode(this.value)">
        <option value="0">Select</option>
        <?php
	//$transSql=DB_query("Select id,vendor_name from suppliers where vendor_type='Transporter'",$db);
	$transSql=DB_query("Select * from transport_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($transRow=DB_fetch_array($transSql))
	{
	?>
        <option value="<?php  echo $transRow['id']?>"<?php echo ($transporter==$transRow['id']?'selected':'')?>>
        <?php  echo $transRow['TransportName']?>
        </option>
        <?php }?>
      </select>
      <input type="text" name="transportercode" id="transportercode" style="width:95px;">
	</span></td>
	<td>Consignee<label><font color="#FF0000">*</font></label></td>
	<td class="tabledata1">
	<select name="consignee" id="consignee" style="width:160px;" >
	
	</select>	</td>	
</tr>
<tr class="row1">
	<td>Party PO No.
	  <label><font color="#FF0000">*</font></label></td>
	<td class="tabledata1" ><input type="text" name="partyPO" id="partyPO" value="<?php echo $SOPList; ?>"   style="width:160px;" /></td>
	<td class="tabledata1" >Current Balance</td>
	<td class="tabledata1"><input type="text" name="cuurentBalance" id="cuurentBalance" value="<?php echo $cuurentBalance;?>"  style="width:160px;" /></td>
	<td>Dispatch AD No.</td>
	<td class="tabledata1" id="consigneeaddress"><select name="dispatchNo" id="dispatchNo" style="width:160px;" onchange="showDispatchDetails(this.value);showDispatchDetails1(this.value)">
      <option value="">Select</option>
    </select></td>
</tr>
<tr class="row1">
<td><label>Dispatch Through</label></td>
	<td class="tabledata1"><input type="text" name="dispatchThrough" id="dispatchThrough" value="<?php echo $dispatchThrough;?>" style="width:160px;" /></td>



    <td class="tabledata1">Credit Limit</td>
    <td class="tabledata1"><input type="text" name="creditLimit" id="creditLimit" value="<?php echo $creditLimit;?>"  style="width:160px;" /></td>
    <td>Form No.</td>
	<td class="tabledata1"><input type="text" name="formNo" id="formNo" style="width:160px;" />
      <?php /*?><?php
	//echo "Select * from party_form_master where party='".$client_id."'";
	$form_no=DB_query("Select * from party_form_master",$db);
	?>	
	<select name="formNo" style="width:160px;">
	<?php 
	while($form_row=DB_fetch_array($form_no))
	{?>
		<option value="<?php echo $form_row['id'];?>"<?php if($formNo==$form_row['id']) echo "selected";?>><?php echo $form_row['formNo'];?></option>
	<?php 	
	}
	?>
	</select><?php */?></td>
	</tr>
<tr class="row1">
	<td>Excisable Commodity
	  <label><font color="#FF0000">*</font></label></td>
	<td class="tabledata1"><select name="excisableComm" style="width:160px;" onchange="getTarrifHeading(this.value)">
      <option value="">Select</option>
      <?php 
		$excisableSql=DB_query("Select * from excisable_commodity_master",$db);
		while($excisableRow=DB_fetch_array($excisableSql))
		{?>
      <option value="<?php echo $excisableRow['id']?>"<?php echo ($excisableComm==$excisableRow['id']?'selected':'')?>><?php echo $excisableRow['commodityName']?></option>
      <?php 	
		}
		?>
    </select></td>
	<td class="tabledata1">Tarrif Heading</td>
	<td class="tabledata1" id="commID"><input type="text" name="tarrifHeading" value="<?php echo $tariffRow['tarrifHeading']?>" style="width:160px;"/>	</td>
	
	<td>Vehicle No.</td>
	<td class="tabledata1"><input type="text" name="vehicleNo" id="vehicleNo" value="<?php echo $vehicleNo;?>"  style="width:160px;" /></td>
</tr>
<tr class="row1">
	<td>LR. No.</td>
	<td><span class="tabledata1">
	  <input type="text" name="grNo" id="grNo" value="<?php echo $grNo;?>" style="width:160px;" />
	</span></td>
	<td>LR. Date</td>
	<td><span class="tabledata1">
	  <input type="text" name="grDate" id="grDate" value="<?php echo $grDate;?>"  style="width:160px;" class="datepicker"/>
	</span></td>
	<td>Mode Of Transport</td>
	<td class="tabledata1"><select name="transportMode" id="transportMode"  style="width:160px;">
      <option value="Road"<?php echo ($transportMode=='Road'?'selected':'')?>>By Road</option>
      <option value="Air"<?php echo ($transportMode=='Air'?'selected':'')?>>By Air</option>
      <option value="Sea"<?php echo ($transportMode=='Sea'?'selected':'')?>>By Sea</option>
    </select></td>
</tr>
<tr class="row1">
	<td><label>Form Type</label></td>
	<td class="tabledata1"><select  name="formType" id="formType" style="width:160px;">
      <option value="0">Select</option>
      <?php
	 $formSql=DB_query("Select * from form_type_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($formRow=DB_fetch_array($formSql))
	{
	?>
      <option value="<?php  echo $formRow['id']?>"<?php echo ($formType==$formRow['id']?'selected':'')?>>
        <?php  echo $formRow['form_name']?>
        </option>
      <?php }?>
    </select></td>
				<td class="tabledata1">Challan No.</td>
				<td class="tabledata1"><input type="text" name="challanNo" id="challanNo" value="<?php echo $challanNo;?>" style="width:160px;"  /></td>
				<?php 
	$tariffSql=DB_query("Select tarrifHeading from excisable_commodity_master where id='".$excisableComm."'",$db);
	$tariffRow=DB_fetch_array($tariffSql);
		?>
	<td>Payment Terms</td>
	<td class="tabledata1"><select  name="payTerms" id="payTerms" style="width:160px;">
      <?php
	$paySql=DB_query("Select termsindicator,terms from paymentterms",$db);
	while($payRow=DB_fetch_array($paySql)){?>
      <option value="<?php  echo $payRow['termsindicator']?>"<?php echo ($payTerms==$payRow['termsindicator']?'selected':'')?>>
        <?php  echo $payRow['terms']?>
        </option>
      <?php }?>
    </select></td>
	</tr>
	<tr class="row1">
	<td>Party Address </td>
	<td id="Address"><textarea name="address1"   id=""  style="width:160px;" rospan="5" /></textarea></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td class="tabledata1">&nbsp;</td>
	</tr>

<tr class="row1">
	<td class="tabledata1" colspan="6"><h3 align="center">Product Details</h3></td>
</tr>
<tr class="row1">
<td colspan="6" style="background-color:#e7e7e7"><p align="left" style="padding-top:5px; padding-bottom:5px;">
<input type="button" onClick="addRow('dataTable')" value="Add Rows" class="search" />&nbsp;
<input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="open_items()" class="search" />
<input type="button" class="search"  onclick="deleteRow('dataTable')" value="Delete" />
</p></td></tr>
<tr class="row1">
<td class="tabledata1" colspan="6">
<div style="width:946px; overflow:auto" id="productId">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
    <tr class="row1">
      <td class="tabledata">SNo. </td>
      <td class="tabledata"></td>
      <td class="tabledata">Item Code<label><font color="#FF0000">*</font></label> </td>
      <td class="tabledata" nowrap="nowrap"> Description </td>
      <td class="tabledata">No of Packaging Box</td>
      <td class="tabledata"> Quantity</td>
	 <!-- <td class="tabledata">Stock</td>-->
      <td class="tabledata">Rate</td>
      <td class="tabledata">Amount  </td>
	   <td class="tabledata">EDRate</td>
      <td class="tabledata">EDAmount</td>
	  <td class="tabledata">Warrantee Expiry Date </td>
	  <td class="tabledata">Store </td>
     </tr>
	<tbody id="dataTable">
	<tr class="row1">
	<td style="white-space:nowrap;" class="tabledata"><input name="delitem[]" type="checkbox" value="" />	</td>	
	<td class="tabledata"><input type="hidden" name="item_code[]" id="itemid" /></td>
	<td class="tabledata"><input type="text" name="" value="" id="itemcode" size="14" /></td>
	<td class="tabledata" style="white-space:nowrap"><input type="text" name="" value="" id="itemname" size="14" /></td>
	<td class="tabledata"><input type="text" name="desc_pkg[]" id="desc_pkg" size="9" onkeyup="calcValue3(this.value,this.id)"/></td>
	<td class="tabledata"><input type="text" name="qty[]"  id="qty" size="8" onkeyup="calcValue1(this.value,this.id)" /></td>
	<!--<td class="tabledata"><input type="text" name="total_stock[]" value="" id="total_stock" readonly="" size="7"/></td>-->
	<td class="tabledata"><input type="text" name="rate[]" value="" id="rate" size="9" onkeyup="calcValue2(this.value,this.id)"/></td>
	<td class="tabledata"><input type="text" name="amt[]" value="" id="amt" size="9"/>	</td>
	<td class="tabledata"><select name="EDRate[]" id="exciserate" style="width:107px" 
	onchange="calculateExcise(this.value,this.id)">
	<option value="0">--Select--</option>
	<?php
	$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
	$ServiceRes=DB_query($ServiceSql,$db);
	while($ServiceRow=DB_fetch_array($ServiceRes))
	{
	?>
	<option value="<?php echo $ServiceRow['id']?>" <?php echo($edit_EDRate==$ServiceRow['id']?'selected':'') ?>><?php echo $ServiceRow['caption'];?></option>
	<?php	
	}
	?>
	</select></td>
	
	<td class="tabledata"><input type="text" name="ED_Amt[]" id="excisevalue1" size="14"  readonly="true" /></td>
	<td class="tabledata"><input type="text" name="Exp_date[]" id="Exp_date" onclick="javascript:NewCal(this.id,'ddmmyyyy')" size="14"  readonly="true" /></td>
	<td class="tabledata"><select name="store[]" id="store"   style="width:40px;" >
	<option value="0">Select</option>
	<?php $Sql_store=DB_query("select * from storetype where CompanyId='".$_SESSION['ACGCompanyId']."' and Store_Site in('".$_SESSION['AssignedBranch']."')",$db);
	while($row_store=DB_fetch_array($Sql_store))
	{
	?>
	<option value="<?php echo $row_store['id']; ?>"><?php echo $row_store['StoreName']; ?></option>
	<?php } ?>
	</select>	</td>
	</tr>
	</tbody>
  </table>
</div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
 <input type="hidden" name="" value="" id="edit_cnt" /> </td>
</tr>
<tr class="row1">
	<td colspan="6">
		<table width="100%" cellpadding="3" cellspacing="0">
			<tr>
			<td valign="top" width="50%">
			<table width="100%" border="1" cellpadding="3" cellspacing="0">
<?php /*?><tr class="row1">
	<td>Total Excise Duty Payable (Rs)</td>
	<td class="tabledata1"> 
		<input name="total_excise_duty" id="total_excise_duty" type="text" value="<?php echo $invoiceRow['excise_duty']?>" style="width:160px;" onfocus="tonumber()"/><!-- onblur="toWords(this.value)"  -->
		 </td>
</tr>
<tr class="row1">
	<td>Excise Duty in words Rupees.</td>
	<td class="tabledata1"><input name="excise_duty_inwords" id="excise_duty_inwords" type="text" value="<?php echo $invoiceRow['excise_duty_inwords']?>"  onfocus="toWords()" style="width:160px;" />	</td>
</tr><?php */?>

<tr class="row1">
    <td>Ledger:<label><font color="#FF0000">*</font></label></td>
    <td valign="top" class="tabledata1"><?php echo $UnderLedger;
		$result_ledger = DB_query("SELECT AccountsID,AccountName FROM accountledger
		                          inner join accountgroupmaster on accountgroupmaster.GroupId
								  =accountledger.UnderGroup where GroupName like '%Sales%'",$db);
	?>
      <select name="ledger_id" style="width:160px;">
        <option value="000">Please select Ledger</option>
        <?php 			
	while($myrow_ledger = DB_fetch_row($result_ledger))
	{
	  $p='';
	  if($myrow_ledger[0]==$_REQUEST['ledger_id'] )
	  $p="selected";
	?>
        <option value="<?php echo $myrow_ledger[0]; ?>"<?php echo $p; ?>><?php echo $myrow_ledger[1]; ?></option>
        <?php }?>
        </select>            </td>
</tr>
<tr class="row1">
    <td>Excise Effect<label><font color="#FF0000">*</font></label></td>
    <td valign="top" class="tabledata1">
	<select name="Excise_Effect" style="width:160px;">
		<option value="0">---</option>
		<option value="RG-1"  <?php echo($invoiceRow['Excise_Effect']=='RG-1')?'selected':''?>>RG-1</option>
		<option value="Supplementry"<?php echo($invoiceRow['Excise_Effect']=='Supplementry')?'selected':''?>>Supplementry</option>
	</select>	</td>
</tr>
<tr class="row1">
    <td colspan="2"><font color="#993300" style="font:Arial, Helvetica, sans-serif; font-size:12px;"><div id="lable1"></div></font></td>
</tr>
</table>			</td>
			<td valign="top" width="50%">
			<table width="100%" cellpadding="3" cellspacing="0">
				<tr class="row1">  
					<td style="text-align:center;" colspan="2"><strong>Amount And Taxes</strong></td>
				</tr>
				<tr class="row1">
					<td>Basic Amount<label><font color="#FF0000">*</font></label></td>
					<td class="tabledata1"><input name="basicAmount" type="text" value="<?php echo $invoiceRow['basicAmount'];?>" style="width:150px;" onfocus="calculateBasic()" id="basicAmount" readonly /></td>
				</tr>
<tr class="row1">
	<td>Discounted Price<label><font color="#FF0000">*</font></label></td>
	<td class="tabledata1"><input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="<?php echo $invoiceRow['totalDiscountedPrice']?>" style="width:150px;" onfocus="calculateDiscounted()" /></td>
</tr>
<tr class="row1">
	<td>Excise<label><font color="#FF0000">*</font></label></td>
	<td class="tabledata1">
	<select name="exciseDuty" style="width:150px;" id="exdut" onchange="claculateExcise(this.value)">
	<option value="0">Select</option>
	<?php 
	$excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' ",$db);
	while($excise_row=DB_fetch_array($excise_sql))
	{
	$ee='';
	if($excise_row['id']==$invoiceRow['exciseDuty'])
	{
	$ee="selected";
	}
	
	?>
	<option value="<?php echo $excise_row['id'];?>"<?php echo $ee; ?>><?php echo $excise_row['caption'];?></option>
	<?php 	
	}
	?> 
	</select>
	<div id="exciseId"><input name="exciseValue" id="exciseValue" type="text" value="<?php echo $invoiceRow['exciseValue']; ?>" size="25" style="width:150px;" onfocus="calculateedamount()" /></div></tr>
    	     
<?php 
$cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
$k=1;
while($cessRow=DB_fetch_array($cessSql))
{
$caption[$k]=$cessRow['caption']; 

$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
while($rate_row=DB_fetch_array($rate_sql))
{
$rate[$k]=$rate_row['def_rate'];
}
$k++;
} 
?>
<tr class="row1">
	<td>E-Cess</td>
	<td class="tabledata1"><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php if(!empty($invoiceRow['ECessPercentage'])){echo $invoiceRow['ECessPercentage']; ?><?php }else { echo $rate[1]; } ?>" style="width:40px;"  />
	<input name="ECessValue" id="ECessValue" type="text" value="<?php echo $invoiceRow['ECessValue']; ?>" style="width:100px;" readonly onfocus="calculateECess()"/></td>
</tr>
<tr class="row1">
	<td>SAH-E Cess </td>
	<td class="tabledata1"><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php if(!empty($invoiceRow['SAHCessPercentage'])){echo $invoiceRow['SAHCessPercentage']; ?><?php }else {  echo $rate[2]; }?>" style="width:40px;" />
	<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $invoiceRow['SAHCessValue']; ?>" style="width:100px;" readonly onfocus="calculateSAHCess()"/></td>
</tr>
<tr class="row1">
	<td>Taxable Amount</td>
	<td class="tabledata1"><input name="taxableAmount" id="taxableAmount" type="text" value="<?php echo $invoiceRow['taxableAmount']; ?>" style="width:150px;" onfocus="calculateTaxable()"/></td>
</tr>
<tr class="row1">
	<td>VAT/CST</td>
	<td class="tabledata1">
	<?php
	$editsalid=$s->GetFieldValue('sales_tax_master',"salestax_id='".$invoiceRow['VatCst']."'" ,'taxrate');
	?>
	<select name="VatCst" id="value3" style="width:150px;" onchange="calculateVATCST(this.value)">
	<option value="">Select</option>
	<?php 
	$salesSql=DB_query("Select * from sales_tax_master",$db);
	while($salesRow=DB_fetch_array($salesSql))
	{ $aa='';
	if($salesRow['salestax_id']==$invoiceRow['VatCst'])
	{
	$aa="selected";	
	}
	?>
	<option value="<?php echo $salesRow['salestax_id'];?>"<?php echo $aa; ?>><?php echo $salesRow['tax_code'];?></option>
	<?php 	
	}
	?>
	</select>
	<input type="text" name="" id="vat_rate" value="<?php echo $editsalid;?>" /> 
	<div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $invoiceRow['VatCstValue']; ?>" size="25" onfocus="CalculateVatCstValue()" style="width:150px;" readonly /></div></td>
</tr>
<tr class="row1">
	<td>Freight</td>
	<td class="tabledata1"><input name="freightValue" id="value2" type="text" value="<?php echo $invoiceRow['freightValue']; ?>" style="width:150px;" /></td>
</tr>
<tr class="row1">
	<td>Pkg Charges</td>
	<td class="tabledata1"><input name="packagingCharges" id="value1" type="text" value="<?php echo $invoiceRow['packagingCharges']; ?>" style="width:150px;" /></td>
</tr>
<tr class="row1">
	<td>Additional Charges</td>
	<td class="tabledata1"><input name="additionalCharges" id="value4" type="text" value="<?php echo $invoiceRow['additionalCharges']; ?>" style="width:150px;" /></td>
</tr>
<tr class="row1">
	<td>Rounded Off Value</td>
	<td class="tabledata1"><input name="roundOff" id="roundOff" type="text" value="<?php echo $invoiceRow['roundOff']; ?>" style="width:150px;" readonly="true" /></td>
</tr>
<tr class="row1">
	<td>Grand Total<label><font color="#FF0000">*</font></label></td>
	<td class="tabledata1"><input name="grandTotal" id="grandTotal" type="text" value="<?php echo $invoiceRow['grandTotal']; ?>" style="width:150px;" onfocus="calculateGrand()" /></td>
</tr>
</table>			</td>
			</tr>
		</table>	</td>
</tr>
<tr class="row1">
<td colspan="6"><center>
  <input name="Save_invoice"  value="Save" type="submit" class="search" onclick="return validate_invoice()" />
  <a href="index.php?route=ViewInvoice<?php  echo $rurl; ?>"><input name="Cancel" type="button" value="Cancel"  class="search" /></a>
</center></td>
</tr>
</table>
</form>
</div>
</div>
<script language="javascript"  type="text/javascript">
function validate_invoice()
{
	if(document.invoice.invoiceType.value=='0')
	{
	alert("Please Select Invoice Type First");
	return false;
	}
	else if(document.invoice.branch_name.value=='0')
	{
	alert("Please Select Branch First");
	return false;
	}
	else if(document.invoice.invoiceNo.value=='')
	{
	alert("Please Enter The Invoice No.");
	return false;
	}
	else if(document.invoice.invoiceDate.value=='')
	{
	alert("Please Enter The Invoice Date");
	return false;
	}
	else if(document.invoice.invoiceTime.value=='')
	{
	alert("Please Enter The Invoice Time");
	return false;
	}
	else if(document.invoice.removalDate.value=='')
	{
	alert("Please Enter The Removal Date");
	return false;
	}
	else if(document.invoice.removalTime.value=='')
	{
	alert("Please Enter The Removal Time");
	return false;
	}
	else if(document.invoice.documentType.value=='0')
	{
	alert("Please Select The Document Type");
	return false;
	}
	else if(document.invoice.client_id.value=='0')
	{
	alert("Please Select The Party");
	return false;
	}
	else if(document.invoice.partyPO.value=='')
	{
	alert("Please Enter The Party PO No");
	return false;
	}
	else if(document.invoice.excisableComm.value=='')
	{
	alert("Please Enter The Excisable Commodity");
	return false;
	}
	var counter=document.getElementById("rowcount").value;
	for(var x=0;x<counter;x++)
	{
	if(document.getElementById("ItemCode_"+x).value=='')
	{
	alert("Please Enter The Item Code");
	return false;
	}
	else if(document.getElementById("PackageDesc_"+x).value=='')
	{
	alert("Please Enter The Package Description");
	return false;
	}
	else if(document.getElementById("Quantity_"+x).value=='')
	{
	alert("Please Enter The Quantity");
	return false;
	}
	}
	if(document.invoice.ledger_id.value=='000')
	{
	alert("Please Enter the Ledger");
	return false;
	}
	else if(document.invoice.Excise_Effect.value=='0')
	{
	alert("Please Enter The Excise Effect");
	return false;
	}
	else if(document.invoice.basicAmount.value=='')
	{
	alert("Please Enter The basic Ammount");
	return false;
	}
	else if(document.invoice.totalDiscountedPrice.value=='')
	{
	alert("Please Enter The Discount Price");
	return false;
	}
	else if(document.invoice.exciseDuty.value=='0' && document.invoice.exciseValue.value=='')
	{
	alert("Please Enter The Excise Duty");
	return false;
	}
	else if(document.invoice.grandTotal.value=='')
	{
	alert("Please Enter the Grand Total Ammount");
	return false;
	}
	return true;
}

function addRow(tableID) 
{
if(document.getElementById("branch_name").value!='0')
{
if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
            
			var newcell = row.insertCell(i);
			newcell.className='tabledata';
           			// newcell.style.background='#ffffff';
			
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
			 

				//alert(newcell.childNodes[0].type);
				switch(newcell.childNodes[0].type) {

				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
					
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	

			}
			
			

		}
	}
	else
	{
	alert("Must Select Branch First");
	document.getElementById("branch_name").focus();
	}
		//document.getElementById(countid).innerHTML=rowCount;

	}

</script>