<?php
error_reporting("E_ALL");
$PageSecurity = 5;

if(isset($_POST['Save']))
{
     $sitename=$s->GetFieldValue('locations',"loccode='".$_REQUEST['mst_branchid']."'",'prefix');
	$sqlqut=DB_query("select * from quotation where site='".$_REQUEST['mst_branchid']."'",$db);
	if(DB_num_rows($sqlqut)>0)
	{
	$SQLMax=DB_query("select MAX(pr_no) as QutNo from direct_po where site='".$_REQUEST['mst_branchid']."'",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$MXNo=substr($MaxQut['QutNo'],-2);
	$FinMx=$MXNo+1;
	$FinalCode=$sitename."/"."DPO"."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$sitename."/"."DPO"."/".'00001';
	}
	
	$data['site']=$_REQUEST['mst_branchid'];
	$data['pr_no']=$FinalCode;
	$data['pr_date']=FormatDateForSQL($_REQUEST['prdate']);
	$data['vender_id']=$_REQUEST['mst_supplierno'];
	$data['contact_person']=$_REQUEST['contact_name'];
	$data['delivery_date']=ConvertSQLDate($_REQUEST['delivery_date']);
	$data['delivery_place']=$_REQUEST['delivery_place'];
	$data['payment_mode']=$_REQUEST['PayMode'];
	$data['sop_no']=$_REQUEST['against_wo'];
	$data['sop_mst_itemid']=$_REQUEST['itemdetail'];
	$data['quotation_no']=$_REQUEST['party_no'];
	$data['quotation_date']=FormatDateForSQL($_REQUEST['party_date']);
	$data['basic_amt']=$_REQUEST['basicAmount'];
	$data['pkg_charge']=$_REQUEST['pkg_charges1'];
	$data['excise_id']=$_REQUEST['EDBillRate'];
	$data['excise_value']=$_REQUEST['totalDiscountedPrice'];
	$data['ecess_per']=$_REQUEST['ECessPercentage'];
	$data['ecess_amt']=$_REQUEST['ECessValue'];
	$data['sah_per']=$_REQUEST['SAHCessValue'];
	$data['sah_amt']=$_REQUEST['SAHCessValue'];
	$data['total_excise_amt']=$_REQUEST['total_item_amount1'];  
	$data['total_taxable_amt']=$_REQUEST['total_item_amount'];  
	$data['vat_cst']=$_REQUEST['taxname'];  
	$data['vat_amt']=$_REQUEST['taxvalue']; 
	$data['sur_per']=$_REQUEST['sur_oct_per']; 
	$data['sur_amt']=$_REQUEST['sur_oct_amt']; 
	$data['freight']=$_REQUEST['TotalCharge']; 
	$data['add_charges']=$_REQUEST['add_charges']; 
	$data['freight1']=$_REQUEST['freight1'];
	$data['mode_transport']=$_REQUEST['mode_transport'];
	$data['grand_total']=$_REQUEST['GrandTotal'];	 
	$data['createdBy']=$_SESSION['UserID'];  
	$data['createdDate']=date('Y-m-d');
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$s->RecordInsert('direct_po', $data);
    $masterId=DB_Last_Insert_ID($db,'direct_po','id');
	 
	if($masterId!='')
	{
	for($cnt=0;$cnt<count($_REQUEST['item_code']);$cnt++)
	{
	if($_REQUEST['item_code'][$cnt]!=''){
	 $insert2="Insert into direct_po_details set
	  parent_id='".$masterId."',  
	 mst_itemid='".$_REQUEST['item_code'][$cnt]."',  
	 qty='".$_REQUEST['stock_qty'][$cnt]."',   
	 rate='".$_REQUEST['stock_price'][$cnt]."',
	 amt ='".$_REQUEST['stock_value'][$cnt]."', 
	 dis_type='".$_REQUEST['PerAmo'][$cnt]."', 
	 dis_per='".$_REQUEST['Discount'][$cnt]."',
	 dis_price='".$_REQUEST['perc'][$cnt]."',
	 net_amt='".$_REQUEST['value_dis'][$cnt]."',
	 delivery_date='".FormatDateForSQL($_REQUEST['delivery_date1'][$cnt])."' ";
	$result2=DB_query($insert2,$db);
					
	}	
	}
	}
	$s->pageLocation("index.php?route=POModule/direct_po_index".$rurl);
	
}






?>
<link rel="stylesheet" href="css/new_mxerp.css">

<link rel="stylesheet" href="css/jquery.ui.all.css" />
<script src="js/jquery-1.5.1.js"></script>
<script src="ui/jquery.ui.core.js"></script>
<script src="ui/jquery.ui.widget.js"></script>



<script>
$(function() {
$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
		changeYear: true,
		yearRange: '-80:+20'});
});
</script>
<script language="javascript" type="text/javascript">
function open_items()
{
window.open("crmquotes1.php?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");
}
function generate_reqno(str)
{
	if (str.length==0)
  {
  document.getElementById("reqno").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("reqno").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_reqno.php?site="+str,true);
xmlhttp.send();
}
function check_approveqty(str,j)
{
	var req_qty=document.getElementById("req_qty_"+j).value;
	if(str>req_qty)
	{
		alert("Quantity to approve cannot be greater than requsition quantity");
		document.getElementById("app_qty_"+j).value='';
		document.getElementById("app_qty_"+j).focus();
		}
}
</script>

	
			<form action="" method="post">
				<div style="width:auto; margin-left:auto; margin-right:auto;">


					<table width="96%" border="1" cellpadding="3" cellspacing="0">
			 <tr> <?php 
				  $sql="SELECT sitecode, requisition_site, prdate FROM materialrequisitions WHERE requisitionno='".$reqno."' and status='1'";
				  $result=DB_query($sql,$db);
				  $myrow = DB_fetch_array($result);
				  ?>
		<th width="11%"><strong>Branch Code</strong></th>
		<td width="17%"><?php  	 
			
		$sql_state=DB_query("SELECT loccode,locationname FROM  locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."') ",$db);?> 
		<select name="mst_branchid" id="mst_branchid" style="width:100%;" onchange="showstorecode(this.value)">
			<option value="000">Select Branch</option>
			<?php while($SiteName=DB_fetch_array($sql_state)) {?>]
			<option value="<?php echo $SiteName['loccode']; ?>"><?php echo $SiteName['locationname']; ?></option>
			<?php }?>
		</select></td>
		<th width="14%"><strong>PO Number</strong></th>
		<td width="16%"> <input type="text" name="prno" value="Auto Generated" style="width:100%;" readonly="readonly" ></td>
		<th width="15%" nowrap="nowrap"><strong>PO Date</strong></th>
		<td width="27%"><input type="text" name="prdate" value="" style="width:100%;"  class="datepicker" /></td>
			 </tr>
			 <tr>
			<th><strong>Vendor Name</strong></th>
			<td> 
			<select name="mst_supplierno" id="mst_supplierno" style="width:100%" onchange="showvendor(this.value);"  >
			<option value="0">Select</option>
			<?php
			$sql="select id  ,vendor_code, vendor_name from suppliers";
			$result = DB_query($sql, $db);
			while($myrow = DB_fetch_array($result))
			{ 
			$p='';
			if($vendor==$myrow['id'])
			$p="selected";
			?>
			 <option  value="<?php echo $myrow['id']; ?>"<?php echo $p;?> ><?php echo str_replace(array("M/s ","M/S"),'',$myrow['vendor_name']); ?></option>
		<?php }
			?>
			</select>			</td>
			<th><strong>Vendor Code</strong></th>
			<td><div id="vendor">
			<input type="text" name="VenderCode" value="" style="width:100%;"; readonly>
			</div>			</td>
			
			
			<th><strong>Mobile No </strong></th>
			<td><div id="mob">
              <input type="text" name="mobile" id="mobile" value="" style="width:100%"/>
            </div></td></tr>
			  <tr>
				<th height="31" nowrap="nowrap"><strong>Address1</strong></th>
				<td><div id="add1">
				<input type="text" name="address1" value="" style="width:100%;"; readonly></div></td>
			<th nowrap="nowrap"><strong>Address2</strong></th>
            <td><div id="add2"><input type="text" name="address2" value="" style="width:100%;" readonly></div></td>
<th><strong>Contact Person</strong></th>
<td><input type="text" name="contact_name" id="contact_name" value="" style="width:100%"/></td>
             </tr>
			 <tr>
				<th nowrap="nowrap"><strong>Delivery Date</strong></th>
				<td><input type="text" name="delivery_date" value="" style="width:100%;"  class="datepicker"></td>
			<th nowrap="nowrap"><strong>Delivery Place</strong></th>
            <td><input type="text" name="delivery_place" value="" style="width:100%;" ></td>
<th><strong>Payment Mode</strong></th>
<td><select name="PayMode" id="PayMode" style="width:100%;">
  <option value="000">---Select Payment Mode---</option>
  <?php 
					$sql='SELECT paymentmethods.paymentid, paymentmethods.paymentname FROM paymentmethods';
					$result=DB_query($sql, $db);
					while($myrow = DB_fetch_array($result))
						{ 
							$p='';
							if($_POST['PayMode'] == $myrow['paymentid'])
							$p="selected";
						?>
  <option value="<?php echo $myrow['paymentid'];?>"<?php echo $p;?>><?php echo $myrow['paymentname'];?></option>
  <?php 	} ?>
</select></td>
             </tr>
			 <tr>
				<th nowrap="nowrap">Against  WO </th>
				<td><div id="agnstwo">
				<select name="against_wo" id="against_wo" style="width:100%">
				<option value="">Select</option>				<?php
				$sql=DB_query("select * from salesorder",$db);
				while($row1=DB_fetch_array($sql))
				{
				 ?>
				 <option value="<?php echo $row1['id']; ?>"><?php echo $row1['orderNo']; ?></option>
				
				<?php } ?>
				</select></div>				</td>
			<th nowrap="nowrap"><strong>Item Details</strong></th>
            <td><div id="item1">
              <select  id="itemdetail" name="itemdetails" style="width:100%;">
                <option value="000">---Select Item---</option>
              </select>
            </div></td>
            <th>Freight</th>
<td><input type="text" name="freight1" id="freight1" style="width:100%" /></td>
             </tr>
			  <tr>
			    <th ><strong>Quotation No</strong></th>
			    <td><input type="text" name="party_no" value="<?php echo $party_no;?>" style="width:100%;" /></td>
			    <th><strong> Quotation Date</strong></th>
			    <td ><input type="text" name="party_date" id="party_date" value="<?php echo ConvertSQLDate($party_date);?>" class="datepicker" style="width:100%;"; readonly /></td>
			    <th><strong>Mode Of Transport</strong></th>
				<td><input type="text" name="mode_transport" id="mode_transport" style="width:100%" /></td>
			      </table>
				   
									
				
				</div>
				   <br />
				 
<p align="left">				 
<input type="button" onClick="addRow('dataTable')" value="Add Rows" accesskey="A" 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>				 
<h3><center>Item Details</center></h4>

<div style="width:auto; margin-left:auto; margin-right:auto;"> 
<div style="width:900px; overflow:auto">    			 
<table align='center' width='100%;' border='1' cellpadding='3' cellspacing='0'>
<tr class='row1'><td class='tabledata' style='text-align:center;' colspan='22'>Item Details</td></tr>
<tr class='row1'>
<td class='tabledata'>Sr. No.</td>
<td class='tabledata'>&nbsp;</td>
<td class='tabledata'>Item Code</td>
 <td class='tabledata'>Item Name</td>
 <td class='tabledata'>Qty.</td>
<td class='tabledata'>Price</td>
<td class='tabledata'>Value</td>
<td class='tabledata'>Discount Type</td>
<td class='tabledata'>Discount ( %)</td>
<td class='tabledata'>Discount Amount </td>
<td class='tabledata'>Discounted Amount </td>
<td class='tabledata'>Excise flag</td>
<td class='tabledata'>Excise</td>
<td class='tabledata'>E-Cess</td>
<td class='tabledata'>SAH-E Cess</td>
<td class='tabledata'>Excise<br />  Amt. </td>
<td class='tabledata'>VAT/CST</td>
<td class='tabledata'>VAT/CST Amount</td>
<td class='tabledata'>Sur Per</td>
<td class='tabledata'>Sur Amount</td>
<td class='tabledata'>Total<br /> Amt.</td>
<td class='tabledata'>Delivery Date</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' value='' /></td>
<td class='tabledata'><input type='text' name='' id='itemcode' value='' /></td>
<td class='tabledata' style='white-space:nowrap'><input type='text' name='item_name[]' id='itemname' value='' /></td>
<td class='tabledata'><input type='text' name='stock_qty[]'  id='stockqty' size='9' onkeyup='calcValue1(this.value,this.id)'  /></td>
<td class='tabledata'><input type='text' name='stock_price[]'  id='stock_price' size='6'/></td>
<td class='tabledata'><input type='text' name='stock_value[]'  id='stock_value' size='9' onfocus='CalculateTotalLeadAmt(this.value,this.id)'/></td>
<td class='tabledata'><select style='width:80px;' name='PerAmo[]' id='PerAmo' >
                     <option value='Amount' >Amount</option>
                    <option value='PercentAmt'>Percent Amt</option>
          </select></td>
<td class='tabledata'><input type='text' style='width:90px' name='Discount[]' id='Discount' onkeyup='DiscountAmount1(this.value,this.id)' /></td>
<td class='tabledata'><input type='text' style='width:90px' name='perc[]' id='perc'  readonly='true'  /></td>
<td class='tabledata'><input type='text' style='width:90px' name='value_dis[]' id='value_dis'  readonly='true'  /></td>
<td class="tabledata"><select name="hid_billing_type[]" style="width:85px" id="hidbillingtype"  onchange="checkExcisable(this.value,this.id)">
	<option value="">Select</option>
	<option value="NonExcisable">NonExcisable</option>
	<option value="Excisable">Excisable</option>
	<option value="IncludeTax">IncludeTax</option>
	
</select></td>
<td class='tabledata'><select name="exciseDuty[]" id="exciseDuty" style="width:120px;"    onchange="claculateExcise(this.id,this.value)" onfocus="checkexiseflag(this.id,this.value)">
    	    <option value="">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Purchase'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
			<option value="<?php echo $excise_row['id'];?>"><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select>
  	      <div id="exciseId"></div>
  	      </td>
		  
		  <?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++;
			 } 
    	     ?>  	      

<td class='tabledata'><input name="ECessPercentage[]" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" style="width:35px;" readonly onfocus="caldata(this.id,this.value)"  /><input name="ECessValue[]" id="ECessValue" type="text" value=""  style="width:70px;" readonly onfocus="calculateECess(this.id,this.value)"/></td>
<td class='tabledata'><input name="SAHCessPercentage[]" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" style="width:35px;" readonly/><input name="SAHCessValue[]" id="SAHCessValue" type="text" value=""  style="width:65px;" readonly onfocus="calculateSAHCess(this.id,this.value)"/></td>
<td class='tabledata'><input type="text" name="taxable_amt[]" id="taxable_amt" value="" style="width:70px;" onfocus="calculateTaxable(this.id,this.value)" readonly/></td>
           <?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	    ?>
             <td class='tabledata'>
	<select id="taxname" name="taxname[]" onchange="tax_rate(this.id,this.value)" style="width:100%;">
	<option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['id']; ?>"<?php echo ($myrow4_req['taxnameid']==$Taxmyrow['id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 <?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td class='tabledata'><div id="taxval">
                  <input type="text" name="taxvalue[]" id="taxvalue" style="width:100%;" value="" readonly="true"/>
              </div>
<input type="hidden" name="hidden_suroct[]" id="hidden_suroct" value="SUR" />
	</td>
	<td class="tabledata"><input type="text" name="surper[]" id="surper" style="width:100%" /></td>
	<td class="tabledata"><input type="text" name="suramt[]" id="suramt" style="width:100%" /></td>
			<td class='tabledata'><input type="text" id="TotalSpecial" name="TotalSpecial[]" size="8" style="width:70px;" readonly  onfocus="cal_grandtotal(this.id,this.value);" value="0"/></td>

<td class='tabledata'><input type='text' style='width:90px' name='delivery_date1[]' id='delivery_data1'  class="datepicker"/></td>
 </tr>
</tbody>			
			</table>
			</div>
			<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
 <input type="hidden" name="" value="" id="edit_cnt" />
			
	</div>
	<br />	
<div align="right">			
			<table width="40%" border="0">
			
			<tr><td>
		      <table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr>
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input name="basicAmount" type="text" value=""  onfocus="calculateBasic()" id="afterdiscountprice" style="width:100%" ></td>
               </tr>
              
				<tr>
					<td><strong>Excise</strong></td>
					<td>
				  <select name="EDBillRate" id="EDRate" style="width:100%" onchange="calculateBillExcise(this.value)"  >
				<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 $ServiceRow['caption']?></option>
				<?php	
				}
				
				?>
				</select>
				
				<input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:100%;" onfocus="calculateTotalExcise()"/>
				</td>
				   </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>
					<td><strong>E-Cess</strong></td>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" style="width:60px;" readonly />
						<input name="ECessValue" id="ECessValue" type="text" value="<?php echo $ECessValue?>" style="width:176px;" readonly onfocus="calculateECess()"/></td>
					</tr>
			<tr >
					<td><strong>SAH-E Cess</strong> </td>
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" style="width:60px;" readonly/>
						<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:176px;" readonly onfocus="calculateSAHCess()"/></td>
					</tr>
					<tr>
					<td><strong>Total Excise Amount</strong></td>
					<td><input type="text" name="total_item_amount" id="total_item_amount1" style="width:100%" onfocus="showexiseamt()" /></td>
					
					</tr>
					<tr>
					<td><strong>Taxable Amount</strong></td>
					<td><input type="text" name="total_item_amount" id="total_item_amount" style="width:100%" onfocus="showexiseamt1()" /></td>
					
					</tr>
                <tr>
                  <td><strong>Vat/Cst(discription) </strong> </td>
                  <?php
				$Taxsql='SELECT salestax_id,tax_code, taxrate FROM sales_tax_master';
				$Taxresult=DB_query($Taxsql,$db);
     	?>
              <td><select id="taxname" name="taxname" onchange="tax_rate1(this.value)" style="width:100%;">
	          <option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['salestax_id']; ?>"<?php echo ($myrow4_req['taxnameid']==$Taxmyrow['id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 
              </tr>
              <tr>
              	<td><strong>Tax Value</strong></td>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="" readonly="true"/>
              </div>	</td>
                </tr>
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per"  size="10" onchange="calsuroctamt(this.value)"/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="" style="width:72%;" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" style="width:100%;"/></td>
                </tr>
				<tr>
                  <td><strong>Pkg Charges</strong> </td>
                  <td><input name="pkg_charges1" id="pkg_charges1" type="text" value="" size="42" /></td>
                </tr>
                
                <tr>
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="" size="25" style="width:100%;" /></td>
                </tr>
							
                <tr>
				<td><strong>Grand Total</strong></td>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" onfocus="cal_grandamount()"  size="12"/></td>
                </tr>
              </table></td></tr>
		 
			</table>
</div>
<p align="center"><input type="submit" name="Save" value="Save" /></p>




<script type="text/javascript">
function DiscountAmountvalue(DA)
{

var discount_percent = document.getElementById("PerAmount").value;
	var discount = document.getElementById("Discount_amount").value;
	var total = document.getElementById("basicAmount").value;
	
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0;
	var percent=0;
	}
	else
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}		
	document.getElementById("discountperc").value=percent.toFixed(2);
	document.getElementById("afterdiscountprice").value=subTotal.toFixed(2);
	
}
function CalculateTotalLeadAmt(val,id)
{
	var id_brk=id.split('_');
	var i=id_brk[2];

	
	if(id_brk.length>2)
	{
	var stock_price = document.getElementById("stock_price_"+i).value;
	var stock_qty = document.getElementById("stockqty_"+i).value;
	document.getElementById("stock_value_"+i).value=(stock_price*stock_qty );
	//document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
	}
	else
	{
	
	var stock_price = document.getElementById("stock_price").value;
	var stock_qty = document.getElementById("stockqty").value;
	document.getElementById("stock_value").value=(stock_price*stock_qty );
	//document.getElementById("total_stock").value=document.getElementById("stock_qty").value;
	}
	
	
	
	
}
function DiscountAmount1(DA,str)
{
  var k=str.split("_");
  
  if(k[1]==undefined)
  {
   
	var discount_percent = document.getElementById("PerAmo").value;
	var discount = document.getElementById("Discount").value;
	var total = document.getElementById("stock_value").value;
	}
	else
	{
	var i=k[1];
	
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;
	var total = document.getElementById("stock_value_"+i).value;
	}
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0; var percent=0;}
		else
		{
		var percent = parseFloat(DA) * parseFloat(total)/100;
		}
		var subTotal = parseFloat(total)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{ 
	
	if(discount==''){discount=0; var percent=0;}
	else
	{
	var percent = parseFloat(DA);
	}
	var subTotal = parseFloat(total)-percent;
	
	}	
	if(k[1]==undefined)
	{
	document.getElementById("perc").value=percent.toFixed(2);
	document.getElementById("value_dis").value=subTotal.toFixed(2);
	}
	else
	{
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("value_dis_"+i).value=subTotal.toFixed(2);
	}
	
}
 
</script>

<script>

function showvendor(str)
{
if (str.length==0)
  		{
  			document.getElementById("vendor").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)
    		{
			  var data=xmlhttp.responseText.split("__");
    			document.getElementById("vendor").innerHTML=data[0];
				document.getElementById("add1").innerHTML=data[1];
				document.getElementById("add2").innerHTML=data[2];
				document.getElementById("mob").innerHTML=data[3];
    		}
  		}
		xmlhttp.open("GET","vendorshow_direct.php?site="+str,true);
		xmlhttp.send();



}

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


}

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


}

function addRow(tableID) 
{
	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.style.background='#e7e7e7';
	newcell.className='tabledata';
	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;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	document.getElementById("stock_perunit_"+rowCount).value='1';
}
	
function deleteRowOrder(tableID) 
{
		try 
		{
			var table = document.getElementById(tableID);
			//alert(table);
			var rowCount = table.rows.length;
			//alert(rowCount);
			for(var i=0; i<rowCount; i++) 
				{
					var row = table.rows[i];
					var chkbox = row.cells[0].childNodes[0];
					if(null != chkbox && true == chkbox.checked) 
					{
						if(rowCount <= 1) 
						{
							alert("Cannot delete all the rows.");
							break;
						}
					table.deleteRow(i);
					rowCount--;
					i--;
					}
					
				}
		document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
		}
		catch(e) 
		{
			alert(e);
		}

	}	
function calculateBasic()
{
	var totalBasic=0;
	var totalBasic2=0;
	var cnt=document.getElementById("hiditemcount").value;
	var totalBasic4=document.getElementById("value_dis").value;
	
	
	for(var i=1;i<=cnt;i++)
	{	
	var totalBasic1=document.getElementById("value_dis_"+i).value;
	var totalBasic=parseFloat(totalBasic)+parseFloat(totalBasic1);
	}
	var totalBasic3=parseFloat(totalBasic)+parseFloat(totalBasic2)+parseFloat(totalBasic4);	
	document.getElementById("afterdiscountprice").value=totalBasic3;
}
function calculateBillExcise(str)
{
	var value=document.getElementById("afterdiscountprice").value;
	if(str.length==0)
	{
	document.getElementById("totalDiscountedPrice").innerHTML="";
	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("totalDiscountedPrice").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?type=bill&id="+str+"&value="+value,true);
	xmlhttp.send();	
}


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

function calsuroctamt(str)
{
var amt=parseFloat(document.getElementById("taxvalue").value);
var	suroctper=parseFloat(document.getElementById("sur_oct_per").value);
var amount=(amt*suroctper)/100;
document.getElementById("sur_oct_amt").value=amount.toFixed(2);	
}
function tax_rate1(str)
{

var taxableAmount=document.getElementById("total_item_amount").value;
var taxableAmount1=document.getElementById("pkg_charges1").value;
if(taxableAmount1==''){taxableAmount1=0;}
var taxableAmount2=parseFloat(taxableAmount)+parseFloat(taxableAmount1);
if (str.length==0)
  {
  document.getElementById("taxval").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("taxval").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_tax_valdata.php?taxid="+str+"&amt="+taxableAmount2,true);
xmlhttp.send();
}
function cal_grandamount()
{
	var total=document.getElementById("afterdiscountprice").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var totalitemamt=document.getElementById("total_item_amount").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var taxamt=document.getElementById("taxvalue").value;
	var packagingCharges=document.getElementById("pkg_charges1").value;
	var additionalCharges=document.getElementById("additionalCharges").value;	
	if(total==''){total=0;}
	if(sur_oct_amt==''){sur_oct_amt=0;}
	if(TotalCharge==''){TotalCharge=0;}
	if(packagingCharges==''){packagingCharges=0;}
	if(additionalCharges==''){additionalCharges=0;}
	if(taxamt==''){taxamt=0;}
	var grand=document.getElementById("GrandTotal").value;
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(     additionalCharges)+parseFloat(taxamt);

document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	
document.getElementById("orig_grand_tot").value=grandtotal.toFixed(2);	
}

function showexiseamt()
{
if(document.getElementById("totalDiscountedPrice").value!='')
var amt1=document.getElementById("totalDiscountedPrice").value;
else
var amt1=0;
if(document.getElementById("ECessValue").value!='')
var amt2=document.getElementById("ECessValue").value;
else
var amt2=0;
if(document.getElementById("SAHCessValue").value!='')
var amt3=document.getElementById("SAHCessValue").value;
else
var amt3=0;
var amount=parseFloat(amt1)+parseFloat(amt2)+parseFloat(amt3);
document.getElementById("total_item_amount1").value=amount.toFixed(2);

}
function showexiseamt1()
{
if(document.getElementById("totalDiscountedPrice").value!='')
var amt1=document.getElementById("totalDiscountedPrice").value;
else
var amt1=0;
if(document.getElementById("total_item_amount1").value!='')
var amt2=document.getElementById("total_item_amount1").value;
else
var amt2=0;

var amount=parseFloat(amt1)+parseFloat(amt2);
document.getElementById("total_item_amount").value=amount.toFixed(2);

}

function checkExcisable(str,t)
{
var k=t.split("_");
if(k[1]==undefined)
{
 if(str=='NonExcisable')
	{
		
		
		document.getElementById("exciseDuty").disabled=true;
		document.getElementById("ECessPercentage").disabled=true;
		document.getElementById("ECessValue").disabled=true;
		document.getElementById("SAHCessPercentage").disabled=true;
		document.getElementById("SAHCessValue").disabled=true;
		document.getElementById("taxable_amt").disabled=true;
		document.getElementById("taxname").disabled=false;
		document.getElementById("taxvalue").disabled=false;
		document.getElementById("surper").disabled=false;
		document.getElementById("suramt").disabled=false;
		
	}
	else if(str=='Excisable' || str==0)
	{

	    document.getElementById("exciseDuty").disabled=false;
		document.getElementById("ECessPercentage").disabled=false;
		document.getElementById("ECessValue").disabled=false;
		document.getElementById("SAHCessPercentage").disabled=false;
		document.getElementById("SAHCessValue").disabled=false;
		document.getElementById("taxable_amt").disabled=false;
		document.getElementById("taxname").disabled=false;
		document.getElementById("taxvalue").disabled=false;
		document.getElementById("surper").disabled=false;
		document.getElementById("suramt").disabled=false;
		
		
		
		
	}
	else
	{
				
		 document.getElementById("exciseDuty").disabled=true;
		document.getElementById("ECessPercentage").disabled=true;
		document.getElementById("ECessValue").disabled=true;
		document.getElementById("SAHCessPercentage").disabled=true;
		document.getElementById("SAHCessValue").disabled=true;
		document.getElementById("taxable_amt").disabled=true;
		document.getElementById("taxname").disabled=true;
		document.getElementById("taxvalue").disabled=true;
		document.getElementById("surper").disabled=true;
		document.getElementById("suramt").disabled=true;
		
		
		
		 document.getElementById("exciseDuty").value='';
		document.getElementById("ECessPercentage").value='';
		document.getElementById("ECessValue").value='';
		document.getElementById("SAHCessPercentage").value='';
		document.getElementById("SAHCessValue").value='';
		document.getElementById("taxable_amt").value='';
		document.getElementById("taxname").value='';
		document.getElementById("taxvalue").value='';
		document.getElementById("surper").value='';
		document.getElementById("suramt").value='';
		

		


	
	}
	document.getElementById("hidbillingtype").value=str;
	}
	else
	{
		var i=k[1];

	if(str=='NonExcisable')
	{
		
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		document.getElementById("taxname_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;
		document.getElementById("surper_"+i).disabled=false;
		document.getElementById("suramt_"+i).disabled=false;
				
		}
	else if(str=='Excisable' || str==0)
	{
	
	
		document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("ECessPercentage_"+i).disabled=false;
		document.getElementById("ECessValue_"+i).disabled=false;		
		document.getElementById("SAHCessPercentage_"+i).disabled=false;	
		document.getElementById("SAHCessValue_"+i).disabled=false;
		document.getElementById("taxable_amt_"+i).disabled=false;
		document.getElementById("taxname_"+i).disabled=false;
		document.getElementById("taxvalue_"+i).disabled=false;
		document.getElementById("surper_"+i).disabled=false;
		document.getElementById("suramt_"+i).disabled=false;
		
		
	}
	else
	{
	
	   document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("ECessPercentage_"+i).disabled=true;
		document.getElementById("ECessValue_"+i).disabled=true;
		document.getElementById("SAHCessPercentage_"+i).disabled=true;
		document.getElementById("SAHCessValue_"+i).disabled=true;
		document.getElementById("taxable_amt_"+i).disabled=true;
		document.getElementById("taxname_"+i).disabled=true;
		document.getElementById("taxvalue_"+i).disabled=true;
		document.getElementById("surper_"+i).disabled=true;
		document.getElementById("suramt_"+i).disabled=true;
				
		
		 document.getElementById("exciseDuty_"+i).value='';
		document.getElementById("ECessPercentage_"+i).value='';
		document.getElementById("ECessValue_"+i).value='';
		document.getElementById("SAHCessPercentage_"+i).value='';
		document.getElementById("SAHCessValue_"+i).value='';
		document.getElementById("taxable_amt_"+i).value='';
		document.getElementById("taxname_"+i).value='';
		document.getElementById("taxvalue_"+i).value='';
		document.getElementById("surper_"+i).value='';
		document.getElementById("suramt_"+i).value='';
	
	}
	
	
	document.getElementById("hid_billing_type_"+i).value=str;
	}
	
}

function claculateExcise(t,str)
{
  var k=t.split("_");
if(k[1]==undefined)
{	
var i=0;
	var discounted=document.getElementById("value_dis").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?caltaxdata="+str+"&data="+i,true);
		xmlhttp.send();
}
else
{
var i=k[1];
var discounted=document.getElementById("value_dis_"+i).value;
	if (str.length==0)
  		{
  			document.getElementById("exciseId_"+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("exciseId_"+i).innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","calculateExcise.php?caltaxdata="+str+"&data="+i,true);
		xmlhttp.send();


}
}

</script>
