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

if(isset($_POST['Save']))
{
     $del=DB_query("delete from direct_po_details where parent_id='".$_REQUEST['SID']."'",$db);
	
	$data['site']=$_REQUEST['mst_branchid'];
	$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_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'];	
	$condition="id='".$_REQUEST['SID']."'"; 
	$s->RecordEdit('direct_po', $data, $condition);
  	 
	if($_REQUEST['SID']!='')
	{
	for($cnt=0;$cnt<count($_REQUEST['item_code']);$cnt++)
	{
	if($_REQUEST['item_code'][$cnt]!=''){
	 $insert2="Insert into direct_po_details set
	  parent_id='".$_REQUEST['SID']."',  
	  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("crmquotesedit1.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>


<?php
$sql=DB_query("select * from direct_po where id='".$_REQUEST['SID']."'",$db);
$myrow1=DB_fetch_array($sql);

 
?>
	
			<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 ='".$myrow1['site']."' ",$db);?> 
		<select name="mst_branchid" id="mst_branchid" style="width:100%;" >
			<?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>PR Number</strong></th>
		<td width="16%"> <input type="text" name="prno" value="<?php echo $myrow1['pr_no']; ?>" style="width:100%;" readonly="readonly" ></td>
		<th width="15%" nowrap="nowrap"><strong>PR Date</strong></th>
		<td width="27%"><input type="text" name="prdate" value="<?php echo ConvertSQLDate($myrow1['pr_date']); ?>" 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($myrow1['vender_id']==$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">
			<?php $vencode=$s->getField('suppliers','id',$myrow1['vender_id'],'vendor_code');?>
			<input type="text" name="VenderCode" value="<?php echo $vencode; ?>" style="width:100%;" readonly ></div>			</td>
			
			
			<th><strong>Mobile No </strong></th>
			<td><div id="mob">
			<?php $vencode1=$s->getField('suppliers','id',$myrow1['vender_id'],'mobile');?>
              <input type="text" name="mobile" id="mobile" value="<?php echo $vencode1; ?>" style="width:100%"/>
            </div></td></tr>
			  <tr>
				<th height="31" nowrap="nowrap"><strong>Address1</strong></th>
				<td><div id="add1">
				<?php $venadd=$s->getField('suppliers','id',$myrow1['vender_id'],'adrress1');?>
				<input type="text" name="address1" value="<?php echo $venadd; ?>" style="width:100%;"; readonly></div></td>
			<th nowrap="nowrap"><strong>Address2</strong></th>
			<?php $venadd1=$s->getField('suppliers','id',$myrow1['vender_id'],'adrress2');?>
            <td><div id="add2"><input type="text" name="address2" value="<?php echo $venadd1; ?>" style="width:100%;" readonly></div></td>
<th><strong>Contact Person</strong></th>
<td><input type="text" name="contact_name" id="contact_name" value="<?php echo $myrow1['contact_person']; ?>" style="width:100%"/></td>
             </tr>
			 <tr>
				<th nowrap="nowrap"><strong>Delivery Date</strong></th>
				<td><input type="text" name="delivery_date" value="<?php echo ConvertSQLDate($myrow1['delivery_date']); ?>" style="width:100%;"  class="datepicker"></td>
			<th nowrap="nowrap"><strong>Delivery Place</strong></th>
            <td><input type="text" name="delivery_place" value="<?php echo $myrow1['delivery_place']; ?>" 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($myrow1['payment_mode'] == $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))
				{
				             $p='';
							if($myrow1['sop_no'] == $row1['id'])
							$p="selected";
				 ?>
				 <option value="<?php echo $row1['id']; ?>" <?php echo $p; ?>><?php echo $row1['orderNo']; ?></option>
				
				<?php } ?>
				</select></div>				</td>
			<th nowrap="nowrap"><strong>Item Details</strong></th>
            <td><div id="item1">
             <?php echo $s->getField('item_master','id',$myrow1['sop_mst_itemid'],'item_name');?>
            </div></td>
            <th>Freight</th>
<td><input type="text" name="freight1" id="freight1" style="width:100%" value="<?php echo $myrow1['freight1']; ?>" /></td>
             </tr>
			  <tr>
			    <th ><strong>Quotation No</strong></th>
			    <td><input type="text" name="party_no" value="<?php echo $myrow1['quotation_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($myrow1['quotation_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%" value="<?php echo $myrow1['mode_transport']; ?>" /></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="deleteRowOrder('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='13'>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 Per</td>
<td class='tabledata'>Discount Price</td>
<td class='tabledata'>Net Discount</td>
<td class='tabledata'>Delivery Date</td>
</tr>
<tbody id='dataTable'>
<?php 
$i=1;
$sql2=DB_query("select * from direct_po_details where parent_id='".$_REQUEST['SID']."'",$db);
while($row2=DB_fetch_array($sql2))
{
$itemcode=$s->getField('item_master','id',$row2['mst_itemid'],'StockID'); 
$itemname=$s->getField('item_master','id',$row2['mst_itemid'],'item_name'); 
?>
 <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_<?php echo $i; ?>' value='<?php echo $row2['mst_itemid'];?>' /></td>
<td class='tabledata'><input type='text' name='' id='itemcode_<?php echo $i; ?>' value='<?php echo $itemcode;?>' /></td>
<td class='tabledata' style='white-space:nowrap'><input type='text' name='item_name[]' id='itemname_<?php echo $i; ?>' value='<?php echo $itemname;?>' /></td>
<td class='tabledata'><input type='text' name='stock_qty[]'  id='stockqty_<?php echo $i; ?>' size='9' onkeyup='calcValue1(this.value,this.id)'  value="<?php echo $row2['qty'];?>" /></td>
<td class='tabledata'><input type='text' name='stock_price[]'  id='stockprice_<?php echo $i; ?>' size='6' value='<?php echo $row2['rate'];?>'/></td>
<td class='tabledata'><input type='text' name='stock_value[]'  id='stockvalue_<?php echo $i; ?>' size='9' onfocus='CalculateTotalLeadAmt(this.value,this.id)' value='<?php echo $row2['amt'];?>'/></td>
<td class='tabledata'><select style='width:80px;' name='PerAmo[]' id='PerAmo_<?php echo $i; ?>' >
                     <option value='Amount' <?php if($row2['dis_type']=='Amount') { ?> selected="selected" <?php } ?> >Amount</option>
                    <option value='PercentAmt' <?php if($row2['dis_type']=='PercentAmt') { ?> selected="selected" <?php } ?>>Percent Amt</option>
          </select></td>
<td class='tabledata'><input type='text' style='width:90px' name='Discount[]' id='Discount_<?php echo $i; ?>' onkeyup='DiscountAmount1(this.value,this.id)'  value='<?php echo $row2['dis_per']; ?>'/></td>
<td class='tabledata'><input type='text' style='width:90px' name='perc[]' id='perc_<?php echo $i; ?>'  readonly='true' value='<?php echo $row2['dis_price']; ?>' /></td>
<td class='tabledata'><input type='text' style='width:90px' name='value_dis[]' id='valuedis_<?php echo $i; ?>'
value='<?php echo $row2['net_amt']; ?>'  readonly='true'  /></td>
<td class='tabledata'><input type='text' style='width:90px' name='delivery_date1[]' id='deliverydata1_<?php echo $i; ?>' 
value='<?php echo $row2['delivery_date']; ?>'  class="datepicker"/></td>
 </tr>
<?php 
 $i++; }
 
 ?>
  <input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
</tbody>
			
			</table>
			</div>
			<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />

			
	</div>
	<br />	
<div align="right">			
			<table width="40%" border="0">
			
			<tr><td>
		      <table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr>
                  <th><strong>TOTAL AMOUNT</strong> </th>
                  <td ><input name="basicAmount" type="text"   onfocus="calculateBasic()" id="afterdiscountprice" style="width:100%" value="<?php echo $myrow1['basic_amt']; ?>" ></td>
               </tr>
              <tr>
                  <th><strong>Pkg Charges</strong> </th>
                  <td><input name="pkg_charges1" id="pkg_charges1" type="text" value="<?php echo $myrow1['pkg_charge']; ?>" size="42" /></td>
                </tr>
				<tr>
					<th><strong>Excise</strong></th>
					<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))
				{
				$c='';
				if($ServiceRow['id']==$myrow1['excise_id'])
				$c="selected";
				?>
				<option value="<?php echo $ServiceRow['id']?>" <?php echo $c; ?>><?php echo $ServiceRow['caption']?></option>
				<?php	
				}
				
				?>
				</select>
				
				<input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:100%;" onfocus="calculateTotalExcise()" value="<?php echo $myrow1['excise_value']; ?>" />
				</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>
					<th><strong>E-Cess</strong></th>
					<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 $myrow1['ecess_amt']; ?>" style="width:176px;" readonly onfocus="calculateECess()"/></td>
					</tr>
			<tr >
					<th><strong>SAH-E Cess</strong> </th>
					<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 $myrow1['sah_amt']; ?>" style="width:176px;" readonly onfocus="calculateSAHCess()"/></td>
					</tr>
					<tr>
					<th><strong>Total Excise Amount</strong></th>
					<td><input type="text" name="total_item_amount" id="total_item_amount" style="width:100%" onfocus="showexiseamt()" value="<?php echo $myrow1['total_excise_amt']; ?>"/></td>
					
					</tr>
                <tr>
                  <th><strong>Vat/Cst(discription) </strong> </th>
                  <?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 ($myrow1['vat_cst']==$Taxmyrow['salestax_id']?'selected':'')?>><?php echo $Taxmyrow['tax_code']." --- ".$Taxmyrow['taxrate']."%"; ?></option>
                  <?php } ?>
              </select></td>
 
              </tr>
              <tr>
              	<th><strong>Tax Value</strong></th>
              <td><div id="taxval">
                  <input type="text" name="taxvalue" id="taxvalue" style="width:100%;" value="<?php echo $myrow1['vat_amt']; ?>" readonly="true"/>
              </div>	</td>
                </tr>
                <tr>
                  <th><strong>Surcharge Amount</strong> </th>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per"  size="10" onchange="calsuroctamt(this.value)" value="<?php echo $myrow1['sur_per']; ?>"/><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo $myrow1['sur_amt']; ?>" style="width:72%;" /></td>
                </tr>
                <tr>
                  <th><strong>Freight</strong> </th>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" style="width:100%;" value="<?php echo $myrow1['freight']; ?>"/></td>
                </tr>
                
                <tr>
                  <th><strong>Additional Charges</strong> </th>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $myrow1['add_charges']; ?>" size="25" style="width:100%;" /></td>
                </tr>
							
                <tr>
				<th><strong>Grand Total</strong></th>
                  <td><input type="text" name="GrandTotal" id="GrandTotal" onfocus="cal_grandamount()"  size="12" value="<?php echo $myrow1['grand_total']; ?>"/></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[1];
   if(id_brk[1]!=undefined)
    {
   
	var stock_price = document.getElementById("stockprice_"+i).value;
	var stock_qty = document.getElementById("stockqty_"+i).value;
	document.getElementById("stockvalue_"+i).value=(stock_price*stock_qty );
	//document.getElementById("total_stock_"+i).value=document.getElementById("stock_qty_"+i).value;
	}
	else
	{
	
	var stock_price = document.getElementById("stockprice").value;
	var stock_qty = document.getElementById("stockqty").value;
	document.getElementById("stockvalue").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("stockvalue").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("stockvalue_"+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("valuedis").value=subTotal.toFixed(2);
	}
	else
	{
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("valuedis_"+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;
	r = rowCount+1;
	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.innerHTML = table.rows[0].cells[i].innerHTML;
		switch(newcell.childNodes[0].type) 
		{
			case "text":
			newcell.childNodes[0].value = "";
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;

			case "hidden":
			newcell.childNodes[0].value = "";
			var nod_id_hidden = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id =nod_id_hidden[0]+'_'+r;
			break;

			case "button":
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;

			case "checkbox":
			newcell.childNodes[0].checked = false;
			var nod_id_chk = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id_chk[0]+'_'+r;
			break;

			case "select-one":
			newcell.childNodes[0].selectedIndex = 0;
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;	
			
			case "textarea":
			newcell.childNodes[0].value = "";
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;
		}
	}
}
	
function deleteRowOrder(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length - 1;
		if(rowCount==0){
			alert("You Not delete First row.");
		}else{
			table.deleteRow(rowCount);
		}

	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}
	
function calculateBasic()
{
       
	var totalBasic=0;
	var totalBasic2=0;
	if(document.getElementById("hiditemcount").value!='')
	var cnt=parseInt(document.getElementById("hiditemcount").value)-1;
	else
	var cnt=0;
	if(document.getElementById("edit_cnt").value!='')
	var cnt1=parseInt(document.getElementById("edit_cnt").value)-1;
	else
	var cnt1=0;
	
	var totalBasic4=0;
	var cnt2=cnt1+cnt;
	
	for(var i=1;i<=cnt2;i++)
	{	
	var totalBasic1=document.getElementById("valuedis_"+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_amount").value=amount;

}

</script>
