<?php //    error_reporting("E_ALL");
	$PageSecurity = 5;
	$PageName ='Quotation';	
	//include('includes/session.inc');
	$Prefix_SQL = "Select prefix_id,prefix_code,prefix_name from prefix_tbl Where prefix_name ='".$PageName."'";
	$Prefix_Result = DB_query($Prefix_SQL,$db);
	$Prefix_Row = DB_fetch_array($Prefix_Result);
	$Prefix_code = $Prefix_Row['prefix_code'];
	$Prefix_date = date("y");
	$Prefix_date++;
	$CurrentFinancialYear = date("y")."-".$Prefix_date; 

$_SESSION['frmid']=$_REQUEST['frmid'];
///get form permissions///
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'], $_SESSION['ACGRoleId']);
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];
$formId=$px->GetFormId('MR_SelectOSMaterialRequi.php');

?>
<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("VenderQutation_TermCondition.php?action=edit&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&RequisitionNo=<?php  echo $_REQUEST['RequisitionNo'];?>&Vid=<?php echo $_REQUEST['Vid']?>","item_popup_window","height=500,width=500,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
	$title = _('Vendor Quotation');
	//include('includes/header.inc');
	include('includes/SQL_CommonFunctions.inc');
	//include('includes/function_lib.php');
	$val=$_GET[RequisitionNo];
	$type="paging";
	$rowsPerPage = 10;
	$pageNum = 1;
	if(isset($_GET['page']))
	{
		$pageNum = $_GET['page'];
	}
	$offset = ($pageNum - 1) * $rowsPerPage;

  
if(isset($_POST['submit']))
{
 	
	
	$data['date1']=FormatDateForSQL($_POST['Date1']);
	$data['date2']=FormatDateForSQL($_POST['Date2']);	
	$data['basis']=$_REQUEST['Basis'];	
	$data['deliveryterms']=$_REQUEST['DeliveryTerms'];
	$data['remarks']=$_REQUEST['Remarks'];
	$data['payment_term']=$_REQUEST['PaymentTerm'];
	$data['payment_mode']=$_REQUEST['PayMode'];
	$data['party_no']=$_REQUEST['party_no'];
	$data['party_date']=FormatDateForSQL($_POST['party_date']);	
	if(isset($_SESSION['VenderQutation_TermCondition']))
	$data['VenderQutation_TermCondition']=$_SESSION['VenderQutation_TermCondition'];
	else
	$data['VenderQutation_TermCondition']=$_REQUEST['VenderQutation_TermCondition'];
	$data['grand_total']=$_REQUEST['GrandTotal'];
	$data['total_amt']=$_POST['total_item_amount'];  
	$data['sur_oct_amt']=$_POST['sur_oct_amt'];
	$data['totalcharge']=$_POST['TotalCharge'];
	$data['pkg_per']=$_POST['pkg_per']; 
	$data['pkg_charges']=$_POST['pkg_charges']; 
	$data['vat_cst_per']=$_POST['taxname'];
	$data['vat_cst_amount']=$_POST['taxvalue'];
	$data['sur_oct_per']=$_POST['sur_oct_per']; 
	$data['add_charges']=$_POST['add_charges'];
	$cond="id='".$_REQUEST['Vid']."'";
    $s->RecordEdit('venderquotations', $data, $cond);
			
	
				 	
				for($i=1;$i<=count($_REQUEST['Quantity']);$i++)
				{					  
					$dataVQT['quantity']=$_POST['Quantity'][$i];
					$dataVQT['rate']=$_POST['Rate'][$i];
					$dataVQT['discount_type']=$_POST['PerAmo'][$i];
					$dataVQT['discount']=$_POST['Discount'][$i];
					$dataVQT['discount_amount']=$_POST['perc'][$i];
					$dataVQT['sub_total']=$_POST['NetRate'][$i];
					$dataVQT['specialdis_type']=$_POST['Perspc'][$i];
					$dataVQT['specialdiscount']=$_POST['SpecialDiscount'][$i];
					$dataVQT['specialdiscount_amount']=$_POST['Specialperc'][$i];
					$dataVQT['totalamount']=$_POST['TotalSpecial'][$i];
					$dataVQT['basic_amt']=$_POST['basic'][$i];
					$dataVQT['tax_type']=$_POST['hid_billing_type'][$i];
	                $dataVQT['Excise_Duty']=$_POST['exciseDuty'][$i];
				    $dataVQT['ExcisePercentage']=$_POST['ExcisePercentage'][$i];
					$dataVQT['Excise_Duty_value']=$_POST['exciseValue'][$i];
					$dataVQT['Edu_Cess_perc']=$_POST['ECessPercentage'][$i];
					$dataVQT['Edu_Cess']=$_POST['ECessValue'][$i];
					$dataVQT['SHE_Cess_perc']=$_POST['SAHCessPercentage'][$i] ;
					$dataVQT['SHE_Cess']= $_POST['SAHCessValue'][$i]; 
					$dataVQT['taxable_amt']= $_POST['taxable_amt'][$i];
					//$dataVQT['taxname']= $_POST['taxname'][$i]; 
					//$dataVQT['taxvalue']= $_POST['taxvalue'][$i]; 
					$dataVQT['total_amount']=$_POST['TotalSpecial'][$i];
								  		 
		 
					 $cond="quotation_id='".$_REQUEST['venderid'][$i]."'";
					   $s->RecordEdit('vendorquotationdetails', $dataVQT, $cond);
					
				
  	
					}
			   $rurls="&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'";
	//	$s->pageLocation("index.php?route=POModule/DispVendor_Quotes&Vid=".$_REQUEST['Vid']."&RequisitionNo=".$_REQUEST['RequisitionNo'].$rurls."&daction=updated");
	 unset($_SESSION['VenderQutation_TermCondition']);
    $_SESSION['success_msg']="Update Successfully";
echo "<script>location.href='index.php?route=POModule/QuotationList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
 
}

  

		  $sql="SELECT id,vendor_code , vendor_name FROM suppliers WHERE id='".$_REQUEST['Vid']."'";
		  $result=DB_query($sql,$db);
		  $vendor=DB_fetch_array($result);
		  $VendorName = $vendor['vendor_name'];
		  $mst_supplierno= $vendor['id'];
		  $sql1 = "SELECT materialrequisitions.Reqno,materialrequisitions.prdate FROM materialrequisitions WHERE requisitionno='".$_REQUEST['RequisitionNo']."' and status='1'";
		  $ReqResult= DB_query($sql1,$db);
		  $result1 = DB_fetch_array($ReqResult);
		 
		  $Reqno = $result1['Reqno'];
		  $ReqDate = $result1['prdate'];
	  
	  
	   if($_GET[RequisitionNo]!='')
		   { 
			echo '<p class="page_title_text">' . ' ' . $title;
			echo "<br/>";
			 $reqno=$_GET['RequisitionNo'];
			
			 echo "<form name='VenderQuotation' action='' method='post' >";
			 
 
if(isset($msgerr ) && count($msgerr)>0)
 {
 echo '<div class="error"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr>';

  for($kp=0,$j=0;$kp<count($msgerr);$kp++)
  {
     if($j%4==0){
	   echo " </tr><tr><td>";
	   $j=0;
	 }
	
	echo '<td>'.$msgerr[$kp].'</td>';
	 $j++;
  }
  echo '</table></div>';
}

if($_REQUEST['daction'])
{
  echo '<div class="success"> Record '.$_REQUEST['daction'].' Successfully</div>';
}		
			$QuerVenderQuot="SELECT  * from venderquotations where id='".$_REQUEST['Vid']."'";
			$Result_VenderQuot =DB_query($QuerVenderQuot,$db );
			$RowVenderQuot = DB_fetch_array($Result_VenderQuot);		  
			$sitecode=$RowVenderQuot['sitecode'];
			$site=$RowVenderQuot['site'];
			$QuotesDate= $RowVenderQuot['date1'];
			$vernder_quotations= $RowVenderQuot['vernder_quotation'];
			$venderid=$RowVenderQuot['mst_supplierno'];
			$Reqno= $s->GetFieldValue('materialrequisitions',"requisitionno='".$RowVenderQuot['mst_requisition_no']."'",'Reqno');
			$ReqDate= $s->GetFieldValue('materialrequisitions',"requisitionno='".$RowVenderQuot['mst_requisition_no']."'",'prdate');
			//Get Data From Supplier
			$vendorcode=$s->GetFieldValue('suppliers',"id='".$venderid."'",'vendor_code');
			$VendorName=$s->GetFieldValue('suppliers',"id='".$venderid."'",'vendor_name');
			$billingType  =$RowVenderQuot['billingType'];
			$vernder_quotation=$RowVenderQuot['vernder_quotation'];
			$basis=$RowVenderQuot['basis'];
			$quotationcategory=$RowVenderQuot['quotationcategory'];
			$warramtydetails=$RowVenderQuot['warramtydetails'];
			$validtill=$RowVenderQuot['validtill'];
			$deliveryterms=$RowVenderQuot['deliveryterms'];
			$payment_term=$RowVenderQuot['payment_term'];
			$remarks=$RowVenderQuot['remarks'];
			$payment_mode=$RowVenderQuot['payment_mode'];
			$party_no=$RowVenderQuot['party_no'];
			$party_date=$RowVenderQuot['party_date'];
			$event=$RowVenderQuot['event'];
			$basic_amt=$RowVenderQuot['basic_amt'];
			$Excise_Duty=$RowVenderQuot['Excise_Duty'];
			$ExcisePercentage=$RowVenderQuot['ExcisePercentage'];
			$Excise_Duty_perc=$RowVenderQuot['Excise_Duty_perc'];
			$Excise_Duty_value=$RowVenderQuot['Excise_Duty_value'];
			$Edu_Cess_perc=$RowVenderQuot['Edu_Cess_perc'];
			$Edu_Cess=$RowVenderQuot['Edu_Cess'];
			$SHE_Cess_perc=$RowVenderQuot['SHE_Cess_perc'];
			$SHE_Cess=$RowVenderQuot['SHE_Cess'];
			$taxable_amt=$RowVenderQuot['taxable_amt'];
			$taxname=$RowVenderQuot['taxname'];
			$taxvalue=$RowVenderQuot['taxvalue'];
			$tot_tax_amount=$RowVenderQuot['tot_tax_amount'];
			$total_tax=$RowVenderQuot['total_tax'];
			$total_amt=$RowVenderQuot['total_amt'];
			$sur_oct=$RowVenderQuot['sur_oct'];
			$sur_oct_perc=$RowVenderQuot['sur_oct_perc'];
			$sur_oct_amt=$RowVenderQuot['sur_oct_amt'];
			$total_amt=$RowVenderQuot['total_amt'];
			$totalcharge=$RowVenderQuot['totalcharge'];
			$pkg_charges=$RowVenderQuot['pkg_charges'];
			$add_charges=$RowVenderQuot['add_charges'];
			$pkg_charges=$RowVenderQuot['pkg_charges']; 
			$grand_total=$RowVenderQuot['grand_total'];						
			$VenderQutation_TermCondition=$RowVenderQuot['VenderQutation_TermCondition'];	
				   ?>
			 <table border="0" width="100%" cellpadding="2">
			 <tr>
			 <td><table width="100%" border="0" cellpadding="1" cellspacing="2" style="background-color: #FFFFFF; border: solid 1px #CCC">
			 <tr>  <input name="VenderQutation_TermCondition" type="hidden" value="<?php echo $VenderQutation_TermCondition?>" />
		<th width="15%"><strong>Site Code</strong></th>
		<td width="22%"><input type="text" name="SiteCode" value="<?php echo $sitecode;?>" style="width: 100%"; readonly></td>
		<th width="14%"><strong>Site Name</strong></th>
		<td width="19%">
		  <input type="text" name="Site" value="<?php echo $site;?>" style="width: 100%"; readonly></td>
		<th width="14%" nowrap="nowrap"><strong>Quotation Date</strong></th>
		<td width="16%">
		  <input type="text" name="Date1" size="10" value="<?php echo ConvertSQLDate($QuotesDate);?>" style="width: 100%"; readonly   class="datepicker">
		   <input type="text" name="vernder_quotations" size="10" value="<?php echo $vernder_quotations;?>" style="width: 100%"; readonly></td>
			</tr>
			 <tr>
			<th><strong>Vendor Code</strong></th>
			<td> 			
			<input name="mst_supplierno" type="hidden" value="<?php  echo $venderid?>" />
			<input type="text" name="VenderCode" size="10" value="<?php echo $vendorcode;?>" style="width: 100%"; readonly></td>
			<th><strong>Vendor Name</strong></th>
			<td><input type="text" name="VenderName" size="10" value="<?php echo $VendorName;?>" style="width: 100%"; readonly></td>
			<th><strong>Basis</strong></th>
			<td><select name="Basis" id="Basis">
			  <option value="000">---Select Basis---</option>
			  <option value="CREDIT"<?php echo ($basis=='CREDIT'?'selected':'');?>>CREDIT</option>
			  <option value="CASH"<?php echo ($basis=='CASH'?'selected':'');?>>CASH</option>
			  </select></td>
			 <tr>
			  


				<th nowrap="nowrap"><strong>Requisition Number</strong></th>
				<td><input type="text" name="" size="10" value="<?php echo $Reqno;?>" style="width: 100%"; readonly></td>
			<th nowrap="nowrap"><strong>Requisition Date</strong></th>
<td><input type="text" name="Date2" size="10" value="<?php echo ConvertSQLDate( $ReqDate);?>" style="width: 100%"; readonly></td>
<th><strong>Remarks</strong></th>
<td><input type="text" name="Remarks" id="Remarks" size="25" value="<?php echo $remarks;?>" style="width: 100%";/></td>
             </tr>
			  <tr>
			    <th ><strong>Pay Terms</strong></th>
			    <td><select name="PaymentTerm" id="PaymentTerm">
			      <option value="000">---Select Payment Terms---</option>
			      <?php 
			// $sql='SELECT suppliers.payterms, paymentterms.terms FROM suppliers 
//INNER JOIN paymentterms ON suppliers.payterms=paymentterms.termsindicator WHERE suppliers.supplierid="'.$VendorCode.'"';
				 	$sql="select * from paymentterms";
					$result=DB_query($sql, $db);
					while($myrow = DB_fetch_array($result))
						{ 
							$p='';
							if($payment_term==$myrow['termsindicator'])
							$p="selected";
						?>
			      <option value="<?php echo $myrow['termsindicator'];?>"<?php echo $p; ?>><?php echo $myrow['terms'];?></option>
			      <?php } ?>
			      </select></td>
			    <th><strong>Payment Mode</strong></th>
			    <td><select name="PayMode" id="PayMode">
			      <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($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"><strong>Party Number</strong></th>
				<td><input type="text" name="party_no" size="10" value="<?php echo $party_no;?>" style="width: 100%"; ></td>
			<th nowrap="nowrap"><strong>Party Date</strong></th>
<td><input type="text" name="party_date" size="10" value="<?php echo ConvertSQLDate($party_date);?>" class="datepicker" style="width: 100%"; readonly></td>
	 </tr> 
			   
			    
		     
				   </table>
				   
				    
				   <div align="center"><input type="button" name="item_popup" value="Terms &amp; Conditions" id="item_popup"  onclick="open_items();" /></div>
				   <br />
				   <div align="center">
				   <fieldset style="width: 790px"><legend><h3><strong>Item Details</strong></h3></legend>
				   <div style="overflow:auto; width:790px; height:auto">
				   <table border="0" width="2500" cellpadding="1" cellspacing="2">
				   <tr>
				   <th ><strong>Item Code</strong></th>
				   <th ><strong>Item Name</strong></th>
				   <th ><strong>Item No</strong></th>
				   <th ><strong>Make</strong></th>
				   <th ><strong>Color</strong></th>
				   <th ><strong>Grade</strong></th>
				   <th ><strong>UOM</strong></th>
				   <th ><strong>Qty</strong></th>
				   <th ><strong>Rate</strong></th>
				   <th ><strong>Total Price</strong></th>
				   <th ><strong>Discount Percent</strong></th>
				   <th ><strong>Discount</strong></th>
				   <th ><strong>Discount Amount</strong></th>
				   <th ><strong>Sub Total</strong></th>
				   	<TH><strong>SPECIAL DISCOUNT Type</strong></TH>
				   	<TH><strong>SPECIAL DISCOUNT</strong></TH>
					<TH><strong>SPECIAL DISCOUNT AMOUNT</strong></TH>
					<th ><strong>BASIC AMOUNT</strong></th>
					<th ><strong>Excise flag</strong></th>
					<th><strong>Excise</strong></th>
					<th><strong>E-Cess</strong></th>
					
					<th><strong>SAH-E Cess</strong></th>
					
					<th><strong>Taxable Amount </strong></th>
					<!--<th><strong>VAT/CST</strong></th>
					<th><strong>VAT/CST Amount</strong></th>-->
					
					
					<TH><strong>TOTAL AMOUNT</strong></TH>
 				   </tr>
				   <?php $prid=array();
				   $val=$_GET['RequisitionNo']; 
 				
			  
			 	    	 //$sql="SELECT mst_itemid, id, item_no, product_id, product_description,make,color,grade ,App_quantity, delivery_by FROM requisitionorderdetails WHERE requsitionno='".$val."'";
			
				 $sql="SELECT * from vendorquotationdetails where quotation_no='".$_REQUEST['Vid']."'";
				
				  $ErrMsg="Requisition Details Don't Exist";
				  $result_req =DB_query($sql,$db,$ErrMsg);
				  $i=1;
				  while($myrow_req = DB_fetch_array($result_req))
				  {
							$proid=$myrow_req['prod_id'];
							$prid=$myrow_req['mst_productid'];
							$proname=$myrow_req['prod_dec'];
							$make=$myrow_req['make'];
							$color=$myrow_req['color'];
							$grade=$myrow_req['grade'];
						//	$uom=$unit_row['unitname'];
							$quantity=$myrow_req['quantity'];
							$rate=$myrow_req['rate'];
							$deliverby=$myrow_req['delivery_by'];
							$discount_type=$myrow_req['discount_type'];
							
							$discount=$myrow_req['discount'];
							$discount_amount=$myrow_req['discount_amount'];
							$sub_total=$myrow_req['sub_total'];
							$specialdiscount=$myrow_req['specialdiscount'];
							$specialdiscount_amount=$myrow_req['specialdiscount_amount'];
							$totalamount=$myrow_req['totalamount'];

 ?>	
	<tr bgcolor="#FFFFFF">
	<td><?php echo $proid;?>
	<input type="hidden" name="mst_productid[<?php echo $i;?>]"  value="<?php echo
	$s->GetFieldValue('item_master',"StockID='".$proid."'" ,'id'); ?>"   />
	<input type="hidden" name="venderid[<?php echo $i;?>]" value="<?php echo $myrow_req['quotation_id'] ?>">
	
	<input type="hidden" name="ProductID[<?php echo $i;?>]" style="width: 100%" value="<?php echo $proid;?>" readonly></td>
	<td><?php echo $proname;?><input type="hidden" name="ProductDes[<?php echo $i;?>]" style="width: 100%"  value="<?php echo $proname;?>" readonly></td>
	<td><?php echo $myrow_req['item_no']; ?><input type="hidden" name="item_no[]" value="<?php echo $myrow_req['item_no']; ?>" /></td>
	<td> 
	<?php echo $makename=$s->getField('product_manufacture','id',$make,'manufacturer');?>
	<input type="hidden" Name="Make[<?php echo $i;?>]" value="<?php echo $makename;?>" readonly>
	</td>
	<td><?php 

	$colorname=$s->getField('product_color','id',$color,'color');
	echo $colorname;?><input type="hidden" Name="Color[<?php echo $i;?>]" value="<?php echo $color;?>" readonly>	</td>
	<td><?php 
	$gradename=$s->getField('product_grade','id',$grade,'grade');
	echo $gradename;?><input type="hidden" Name="Grade[<?php echo $i;?>]" value="<?php echo $grade;?>" readonly>	</td>
	<td><?php 
	
	$unit1=DB_query("Select * from item_master where id='".$prid."' || StockID='".$proid."'",$db);
	$unit=DB_fetch_array($unit1);
	//echo $unit=$s->getField('item_master','id',$prid,'unit');
		$unitname=$s->getField('unitsofmeasure','unitid',$unit['unit'],'unitname');
	echo $unitname;?><input type="hidden" name="UOM[<?php echo $i;?>]" style="width: 100%"  value="<?php echo $unit;?>" readonly></td>
            <?php $query =DB_query("select * from item_master", $db);
				$quer_row=DB_fetch_array($query);
			?> 
<td><?php echo $quantity;?><input type="hidden" name="Quantity[<?php echo $i;?>]" id="Quantity_<?php echo $i;?>" style="width: 100%"  value="<?php echo $quantity;?>"
	/></td>
<td><input style="width:100%;"  type="text" name="Rate[<?php echo $i;?>]" id="Rate_<?php echo $i;?>"    value="<?php echo $myrow_req['rate'];?>"/></td>
		  
		  <td><input style="width:100%;" type="text" name="totalValue[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" value="<?php echo $quantity*$myrow_req['rate'];?>" onfocus="calculateTotalPrice(<?php echo $i;?>)" readonly="true"/></td>
		   <td><select style="width:100%;" name="PerAmo[<?php echo $i;?>]" id="PerAmo_<?php echo $i;?>">
            <option value="Amount" <?php echo ($_POST['PerAmo']=='Amount'|| $myrow_req['discount_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt" <?php echo ($_POST['PerAmo']=='PercentAmt' || $myrow_req['discount_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>

<td><?php echo '<input type="text" name="Discount['.$i.']" id="Discount_'.$i.'" onblur="DiscountAmount(this.value,'.$i.')" style="width:100%;"  value="'.$myrow_req['discount'].' "/>';?>
</td>
<td><?php echo '<input type="text" name="perc['.$i.']" id="perc_'.$i.'"  readonly="true" style="width:100%;" value="'.$myrow_req['discount_amount'].' "/>';?></td>
<td><?php echo '<input type="text" id="NetRate_'.$i.'" name="NetRate['.$i.']" style="width:100%;" readonly value="'.$myrow_req['sub_total'].' "/>';?></td>
 <td><select style="width:100%;" name="Perspc[<?php echo $i;?>]" id="Perspc_<?php echo $i;?>">
            <option value="Amount" <?php echo ($_POST['Perspc']=='Amount'|| $myrow_req['specialdis_type']=='Amount')?'selected':''?>>Amount</option>
            <option value="PercentAmt" <?php echo ($_POST['Perspc']=='PercentAmt' || $myrow_req['specialdis_type']=='PercentAmt')?'selected':''?>>Percent Amt</option>
          </select></td>
<td><?php echo '<input type="text" name="SpecialDiscount['.$i.']" id="SpecialDiscount_'.$i.'" size="10" style="width:100%;"  onblur="DiscountAmountdpc(this.value,'.$i.')" value="'.$myrow_req['specialdiscount'].' " />';?>
</td>
<td><?php echo '<input type="text" name="Specialperc['.$i.']" id="Specialperc_'.$i.'"  style="width:100%;" size="10"  value="'.$myrow_req['specialdiscount_amount'].' "  />';?></td>
<td><?php echo '<input type="text" id="basic_'.$i.'" name="basic['.$i.']" size="8" style="width:100%;"  value="'.$myrow_req['basic_amt'].' " readonly/>';?></td>
<td><select name="hid_billing_type[<?php echo $i;?>]" style="width: 100%" id="hid_billing_type_<?php echo $i;?>"  onblur="hid_billing_typecheck(<?php echo $i; ?>,this.value)"  onchange="checkExcisable(this.value,<?php echo $i; ?>,this.value)">
	<option value="0">Select</option>
	<option value="NonExcisable" <?php if($myrow_req['tax_type']=='NonExcisable'){ ?> selected="selected"; <?php } ?>>NonExcisable</option>
	<option value="Excisable"<?php if($myrow_req['tax_type']=='Excisable'){ ?> selected="selected"; <?php } ?>>Excisable</option>
	<option value="IncludeTax"<?php if($myrow_req['tax_type']=='IncludeTax'){ ?> selected="selected"; <?php } ?>>IncludeTax</option>
</select></td>
<td><select name="exciseDuty[<?php echo $i;?>]" id="exciseDuty_<?php echo $i;?>" style="width:80%;" onchange="claculateExcise(<?php echo $i; ?>,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))
			{
			$c='';
			if($myrow_req['Excise_Duty']==$excise_row['id'])
			{
			$c="selected";	
			}
				
				?>
				<option value="<?php echo $excise_row['id'];?>"<?php echo $c; ?>><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select>
  	      <div id="exciseId_<?php echo $i; ?>"><input name="ExcisePercentage[<?php echo $i;?>]" id="ExcisePercentage_<?php echo $i;?>" type="text" value="<?php echo $myrow_req['ExcisePercentage']; ?>"  style="width:20%;" readonly /> <input name="exciseValue[<?php echo $i; ?>]" id="exciseValue_<?php echo $i; ?>" type="text" value="<?php echo $myrow_req['Excise_Duty_value']; ?>" style="width:70%;" onfocus="calculateExciseDuty(<?php echo $i; ?>)" /></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><input name="ECessPercentage[<?php echo $i;?>]" id="ECessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[1];?>" style="width:25%;" readonly /><input name="ECessValue[<?php echo $i; ?>]" id="ECessValue_<?php echo $i;?>" type="text" value="<?php echo $myrow_req['Edu_Cess']; ?>" size="25" style="width:75%;" readonly onfocus="calculateECess(<?php echo $i; ?>)"/></td>

<td><input name="SAHCessPercentage[<?php echo $i;?>]" id="SAHCessPercentage_<?php echo $i;?>" type="text" value="<?php echo $rate[2];?>" style="width:25%;" readonly/><input name="SAHCessValue[<?php echo $i;?>]" id="SAHCessValue_<?php echo $i;?>" type="text" value="<?php echo $myrow_req['SHE_Cess']; ?>" size="25" style="width:75%;" readonly onfocus="calculateSAHCess(<?php echo $i; ?>)"/></td>
<td><input type="text" name="taxable_amt[<?php echo $i;?>]" id="taxable_amt_<?php echo $i;?>" value="<?php echo $myrow_req['taxable_amt']; ?>" style="width:100%;" onfocus="calculateTaxable(<?php echo $i; ?>)" readonly/></td>
<?php
				//$Taxsql='SELECT id,tax_code, taxrate FROM service_tax_master';
				//$Taxresult=DB_query($Taxsql,$db);
     	?>
              <!--<td>
	<select id="taxname_<?php echo $i;?>" name="taxname[<?php echo $i;?>]" onchange="tax_rate(this.value,<?php echo $i; ?>)" style="width:100%;">
	<option value="0">---Select---</option>
                  <?php 
			while($Taxmyrow=DB_fetch_array($Taxresult)){
			?>
                  <option  value="<?php echo $Taxmyrow['id']; ?>"<?php echo ($myrow_req['taxname']==$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><div id="taxval_<?php echo $i; ?>">
                  <input type="text" name="taxvalue[<?php echo $i;?>]" id="taxvalue_<?php echo $i;?>" style="width:100%;" value="<?php echo $myrow_req['taxvalue']; ?>" readonly="true"/>
              </div></td>-->


    	    
<td><?php echo '<input type="text" id="TotalSpecial_'.$i.'" name="TotalSpecial['.$i.']" size="8" style="width:100%;" readonly  onfocus="cal_grandtotal('.$i.');" value="'.$myrow_req['total_amount'].' "/>';?></td>


</tr>
		<?php 		  $i++;
				 }	?>	  
			<input type="hidden" name="count" id="count" value="<?php echo $i;?>" size="10" /> 
			</table>
			</div>
			</fieldset></div>
			<br />	
			<table width="40%" align="right">
		
			<tr><td>
			<table width="100%" border="0" cellspacing="2" cellpadding="2">
                <tr>
                  <td><strong>TOTAL AMOUNT</strong> </td>
                  <td ><input type="text" name="total_item_amount" id="total_item_amount" value="<?php echo $total_amt;?>" style="width:100%;" onfocus="cal_totalamount()" readonly="readonly" /></td>
                </tr>
               <tr>
                  <td><strong>Pkg Charges</strong> </td>
                   <td><input type="text" name="pkg_per" id="pkg_perc" value="" size="5" onkeyup="calcPackaging(this.value)" /><input name="pkg_charges1" id="pkg_charges1" type="text" value="<?php echo $pkg_charges; ?>" size="28" /></td>
              
                  <!--<td><input name="pkg_charges" id="pkg_charges1" type="text" value="<?php echo $pkg_charges; ?>" size="25" style="width:100%;" /></td>-->
                </tr>               
                <tr>
                  <td><strong>Vat/Cst(discription) </strong> </td>
                  <?php
				$Taxsql='SELECT id,tax_code, taxrate FROM service_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['id']; ?>"<?php echo ($RowVenderQuot['vat_cst_per']==$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="<?php echo $RowVenderQuot['vat_cst_amount']; ?>" readonly="true" />
              </div>

	</td>
                   </tr>
                <tr>
                  <td><strong>Surcharge Amount</strong> </td>
                  <td><input type="text" name="sur_oct_per" id="sur_oct_per" value="<?php echo $RowVenderQuot['sur_oct_per']; ?>"  size="10" /><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo $RowVenderQuot['sur_oct_amt']; ?>" style="width:60%;" onblur="calsuroctamt(this.value)" /></td>
                </tr>
                <tr>
                  <td><strong>Freight</strong> </td>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" value="<?php echo $totalcharge; ?>" style="width:100%;"/></td>
                </tr>
                
                <tr>
                  <td><strong>Additional Charges</strong> </td>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $add_charges; ?>" size="25" style="width:100%;" /></td>
                </tr>
				<!--<tr>
					<td><strong>Round Off</strong></td>
					<td><input type="text" name="round_off" id="round_off" style="width:100%;"/></td>
				</tr>-->
				
                <tr>
                	<td><strong>Grand Total</strong> </td>
                 <td><input type="text" name="GrandTotal" id="GrandTotal" value="<?php  echo $grand_total; ?>" style="width:100%;" readonly="readonly" onfocus="cal_grandamount();" /></td>
                </tr>
              </table>
		     </td>
		     <tr>	
		
				
			</table>
			
	
		</tr>
				
			</table>
		</td>
		</tr>
		</table>		 
	<p align="center"><input type="Submit" name="submit" VALUE="Vendor Quotation" onclick="return checkvalid()">
	</form><!--onclick="return checkvalid()"-->
<?php 		   }
 
include('includes/footer.inc');
?>
<script type="text/javascript">
function calculateExciseDuty(i)
{
	var basic=document.getElementById("basic_"+i).value;
	var ExcisePercentage=document.getElementById("ExcisePercentage_"+i).value;
	
	var exciseVal=basic*(ExcisePercentage/100);
	document.getElementById("exciseValue_"+i).value=exciseVal.toFixed(2);
}

function hid_billing_typecheck(i,str){

	//alert(str);
	//var type= document.getElementById("ExcisePercentage_"+i).value;
	if(str=='')
	{
		alert("Select Tax Type");
	}

}
function checkExcisable(str,i)
{
 	
	if(str=='NonExcisable')
	{
		
		
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+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("exciseDuty_"+i).value='';
		//document.getElementById("exciseValue_"+i).value='';
		document.getElementById("ExcisePercentage_"+i).disabled=true;
		//document.getElementById("ECessValue_"+i).value='';
		//document.getElementById("SAHCessPercentage_"+i).value='';
		//document.getElementById("SAHCessValue_"+i).value='';
		//document.getElementById("taxable_amt_"+i).value='';
		//document.getElementById("ExcisePercentage_"+i).value='';
	//	document.getElementById("taxvalue").disabled=true;
		//document.getElementById("sur_oct_perc").disabled=true;
		//document.getElementById("sur_oct_amt").disabled=true;
	}
	else if(str=='Excisable' || str==0)
	{
		document.getElementById("exciseDuty_"+i).disabled=false;
		document.getElementById("exciseValue_"+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("sur_oct_perc_"+i).disabled=false;
		document.getElementById("sur_oct_amt_"+i).disabled=false;
		
		document.getElementById("TotalCharge_"+i).disabled=false;
		//document.getElementById("packagingCharges_"+i).disabled=false;
		//document.getElementById("additionalCharges_"+i).disabled=false;
		//document.getElementById("roundOff_"+i).disabled=false;	
		
		
	}
	else{
		document.getElementById("exciseDuty_"+i).disabled=true;
		document.getElementById("exciseValue_"+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("ExcisePercentage_"+i).disabled=true;
		//document.getElementById("taxvalue_"+i).disabled=true;
		document.getElementById("sur_oct_perc_"+i).disabled=true;
		document.getElementById("sur_oct_amt_"+i).disabled=true;
		document.getElementById("TotalCharge_"+i).disabled=true;
		//document.getElementById("packagingCharges_"+i).disabled=true;
		//document.getElementById("additionalCharges_"+i).disabled=true;
		//document.getElementById("roundOff_"+i).disabled=true;

		document.getElementById("exciseDuty_"+i).value='';
		document.getElementById("exciseValue_"+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("sur_oct_perc_"+i).value='';
		document.getElementById("sur_oct_amt_"+i).value='';
		document.getElementById("TotalCharge_"+i).value='';
		//document.getElementById("packagingCharges_"+i).value='';
		//document.getElementById("additionalCharges_"+i).value='';
		//document.getElementById("roundOff_"+i).value='';


	
	}
	document.getElementById("hid_billing_type_"+i).value=str;
}
function calculateECess(i)
{
	
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessPercentage=document.getElementById("ECessPercentage_"+i).value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("ECessValue_"+i).value=total.toFixed(2);
}
function calculateSAHCess(i)
{
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var SAHCessPercentage=document.getElementById("SAHCessPercentage_"+i).value;
	var total=exciseValue*(SAHCessPercentage/100);
	document.getElementById("SAHCessValue_"+i).value=total.toFixed(2);
}
function claculateExcise(i,str)
{
	
	var discounted=document.getElementById("basic_"+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?quotTaxId="+str+"&data="+i,true);
		xmlhttp.send();
}

function calculateTotalPrice(i)
{
	Quantity = document.getElementById("Quantity_"+i).value;
	Rate= document.getElementById("Rate_"+i).value;
	var Total=Quantity*Rate;
	document.getElementById("totalValue_"+i).value=Total.toFixed(2);
}



function calculateTaxable(i)
{
	//var totalDiscountedPrice=document.getElementById("basic_"+i).value;
	var exciseValue=document.getElementById("exciseValue_"+i).value;
	var ECessValue=document.getElementById("ECessValue_"+i).value;
	var SAHCessValue=document.getElementById("SAHCessValue_"+i).value;
	
	//if(totalDiscountedPrice==''){totalDiscountedPrice=0;}
	if(exciseValue==''){exciseValue=0;}
	if(ECessValue==''){ECessValue=0;}
	if(SAHCessValue==''){SAHCessValue=0;}
	var TOTAL=parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	//var TOTAL=parseFloat(totalDiscountedPrice)+parseFloat(exciseValue)+parseFloat(ECessValue)+parseFloat(SAHCessValue);
	document.getElementById("taxable_amt_"+i).value=TOTAL.toFixed(2);
}




function calc_tax_amount()
{
	var taxable=document.getElementById("taxable_amt").value;
	var taxval=document.getElementById("taxvalue").value;
	var final=taxable*(taxval/100);
	document.getElementById("tot_tax_amount").value=final.toFixed(2);
}

function get_charge(str)
{
	document.getElementById("hidden_suroct").value=str
}

function cal_suroct(i,str)
{
	
	var total_tax=document.getElementById("taxvalue_"+i).value;
	
	var final_sur=total_tax*(str/100);
	document.getElementById("sur_oct_amt_"+i).value=final_sur.toFixed(2);
}

function calsuroctamt(str)
{
var amt=parseFloat(document.getElementById("taxvalue").value);
var	suroctper=document.getElementById("sur_oct_per").value;
if(suroctper!='')
var amount=(amt*parseFloat(suroctper))/100;
else
var amount=0;
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_val.php?taxid="+str+"&amt="+taxableAmount2,true);
xmlhttp.send();
}








function tax_rate(str,i)
{

var billing_type=document.getElementById("hid_billing_type_"+i).value;

if(billing_type=='NonExcisable')
{
var taxableAmount=document.getElementById("basic_"+i).value;}
else if(billing_type=='Excisable')
{
var taxableAmount=document.getElementById("taxable_amt_"+i).value;}
//alert(taxableAmount);
if (str.length==0)
  {
  document.getElementById("taxval_"+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("taxval_"+i).innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_tax_val.php?taxid="+str+"&amt="+taxableAmount+"&data="+i,true);
xmlhttp.send();
}
function getdata(str)
{
	
	if (str.length==0)
  		{
  			document.getElementById("PaymentTerm").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("PaymentTerm").innerHTML=xmlhttp.responseText;
    		}
  		}
		xmlhttp.open("GET","paytermsdata.php?site="+str,true);
		xmlhttp.send();
}
function checkvalid()
{
	var count = document.getElementById("count").value;
	var cnt_charge = document.getElementById("countcharges").value;
	if(document.getElementById("QuotationCategory").value == '000')
	{
		alert("Please Select Quotation Category");
		document.getElementById("QuotationCategory").focus();
		return false;
	}
	if(document.getElementById("Basis").value == '000')
	{
		alert("Please Select Basis");
		document.getElementById("Basis").focus();
		return false;
	}
	if(document.getElementById("PaymentTerm").value == '000')
	{
		alert("Please Select Payment Term");
		document.getElementById("PaymentTerm").focus();
		return false;
	}
	if(document.getElementById("PayMode").value == '000')
	{
		alert("Please Select Pay Mode");
		document.getElementById("PayMode").focus();
		return false;
	}
	
	if(document.getElementById("Event").value == '000')
	{
		alert("Please Select Event");
		document.getElementById("Event").focus();
		return false;
	}
	
	for(var i=1; i<count; i++)
	{
		if(document.getElementById("Rate_"+i).value == '')
		{
			alert("Please Enter Rate Of Item");
			document.getElementById("Rate_"+i).focus();
			return false;
		}
		
	}
	
	if(document.getElementById("Total") == '')
	{
		alert("Please Press The Button Which Would calculate The Total Material Cost With Taxes");
		document.getElementById("Total").focus();
		return false;
	}
	for(var k=1; k<cnt_charge; k++)
	{
		var inclusive = document.getElementById("Charge_"+k).value;
		var actual = document.getElementById("actual_"+k).value;
		var desc = document.getElementById("desc_"+k).value;
		if(inclusive=='NO' && actual=='')
		{
			alert("Please Enter Some Value For "+desc+" Since It Is Not Inclusive");
			document.getElementById("actual_"+k).focus();
			return false;
		}
		
		
	}
	//return false;
}
//////////////////////////////////////////////////Charges Details Some Hint By Amit Kumar /////////////////////////////////////////////
// As Per Actual- Amount = Amount                                                                                                    //
// As Per Actual- Amt    = Persent Amt                                                                                               //
// Total Charges Cost    = All Charges Amount Add                                                                                    //
// Grand Total           = Total Charges  + Material Cost With Taxes                                                                //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function cal_roundamt()
{
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").value;
	var TotalCharge=document.getElementById("TotalCharge").value;
	var packagingCharges=document.getElementById("packagingCharges").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;}
	var roundOffVal=document.getElementById("round_off").value;
	var grand=document.getElementById("GrandTotal").value;
	
	grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges);
	if(roundOffVal==''){roundOffVal='-.0';}
	
	var test=roundOffVal.split(".");
	
	 if(test[0]=='-')
	 {
		var dot=".";
		var roundval=dot + test[1];
		
		 document.getElementById("GrandTotal").value=parseFloat(grandtotal) - parseFloat(roundval);
	 }
	 else
	 {
	 	var dot=".";
		var roundval=dot + test[1];
	 	document.getElementById("GrandTotal").value=parseFloat(grandtotal) + parseFloat(roundval);	
	 }
	
}
function cal_grandamount()
{
	
	var total=document.getElementById("total_item_amount").value;
	var sur_oct_amt=document.getElementById("sur_oct_amt").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;
	var grandtotal=parseFloat(total)+parseFloat(sur_oct_amt)+parseFloat(TotalCharge)+parseFloat(packagingCharges)+parseFloat(additionalCharges)+parseFloat(taxamt);
		
	
	
document.getElementById("GrandTotal").value=grandtotal.toFixed(2);	

}


function calc_basicamt()
{
	var total_basic=0;
	var cnt=document.getElementById("count").value
	for(var j=1;j<cnt;j++)
	{
		var netrate=document.getElementById("TotalSpecial_"+j).value;
		if(netrate==''){netrate=0;}
		total_basic=parseFloat(total_basic)+parseFloat(netrate);
	}
	document.getElementById("basic").value=total_basic.toFixed(2);
}
function calc_totaltax()
{
	var total_tax=0;
	var cnt=document.getElementById("count").value
	for(var j=1;j<cnt;j++)
	{
		var taxamt=document.getElementById("totaltaxamount_"+j).value;
		total_tax=parseFloat(total_tax)+parseFloat(taxamt);
	}
	document.getElementById("total_tax").value=total_tax.toFixed(2);
}
function cal_totalcharge()
{
	var total=0;
	var count=document.getElementById("countcharges").value;
	for(var i=1; i<count;i++)
	{
		var actualamt=document.getElementById("actual_"+i).value;
		if(actualamt!='')
		{
		total=parseFloat(total)+parseFloat(actualamt);
		}
	}
	document.getElementById("TotalCharge").value=total.toFixed(2);
}
function cal_totalamount()
{
	
	var total=0;
var t=document.getElementById("count").value;

for(var i=1;i<t;i++)
{
var amt=parseFloat(document.getElementById("TotalSpecial_"+i).value);
total=parseFloat(total)+amt;	
}	
document.getElementById("total_item_amount").value=total.toFixed(2);	
}

function cal_grandtotal(i)
{
	var type_of_bill=document.getElementById("hid_billing_type_"+i).value;
	var basic=document.getElementById("basic_"+i).value;
	//alert(basic);
	var Totaltaxable=document.getElementById("taxable_amt_"+i).value;
	//var vatcstAmt=document.getElementById("taxvalue_"+i).value;
	

	//var roundOffVal=document.getElementById("roundOff_").value;
	
	//if(roundOffVal==''){roundOffVal='-.0';}
	
	//var test=roundOffVal.split(".");
	
	//alert(test[0]);
	
	if(basic==''){basic=0;}
	if(Totaltaxable==''){Totaltaxable=0;}
	//if(vatcstAmt==''){vatcstAmt=0;}
	
	
	
	
	if(document.getElementById("hid_billing_type_"+i).value=='NonExcisable')
	{
	
		//var grand_tot1=parseFloat(basic)+parseFloat(vatcstAmt);
		var grand_tot1=parseFloat(basic);
		var grand_tot=grand_tot1.toFixed(2);
		
	}	
	
	
else if(document.getElementById("hid_billing_type_"+i).value=='IncludeTax'){

var grand_tot1= parseFloat(basic) ;
var grand_tot=grand_tot1.toFixed(2);
}
	else{
	//var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable)+parseFloat(vatcstAmt);
	var grand_tot1= parseFloat(basic)+parseFloat(Totaltaxable);
		//var grand_tot1= parseFloat(Totaltaxable)+parseFloat(vatcstAmt);
			var grand_tot=grand_tot1.toFixed(2);
		
		 }
	  //alert(	document.getElementById("TotalSpecial_"+i).value);
	 	//alert(grand_tot);
	 	document.getElementById("TotalSpecial_"+i).value=grand_tot ;	
		//alert(	document.getElementById("TotalSpecial_"+i).value);
	
}

function checkstatus(str)
{
	var Charge = document.getElementById("Charge_"+str).value;
	var actual = document.getElementById("actual_"+str).value;
	if(Charge == 'NO' && actual == '')
	{
		alert("Please Enter Some Value Since It Is Not Inclusive");
		return false;
	}
}
var TotalPercent=0;
var TotalAmnt=0;
var finalAmount=0;

function ChargeCalculater(Amt,Amtid)
  {
	 var AsPerActual=document.getElementById(Amtid).value;
	 var ActualType=document.getElementById("AsPerActual_" +Amtid).value;
	 
	 if(AsPerActual !='')
	 {
	 if(ActualType=='PercentAmt')
	   {
	     var Total= document.getElementById("Total").value;
		 var charge= parseFloat(Total) * parseFloat(AsPerActual)/100;
		 document.getElementById("actual_"+Amtid).value = charge;
		 TotalPercent= parseFloat(TotalPercent) + parseFloat(charge);
	   }
	 else
	   {
	     document.getElementById("actual_"+Amtid).value=AsPerActual; 
		 TotalAmnt=parseFloat(TotalAmnt) + parseFloat(AsPerActual);
	   }
	}
	return true;
  }
////////////////////////////////////// Some Hint By Amit Kumar ////////////////////////////////////////
// Total Charges Cost    = All Charges Amount Add                                                    //
// Grand Total           = Total Charges  + Material Cost With Taxes                                 //
//////////////////////////////////////////////////////////////////////////////////////////////////////  

function FinalGrandTotal(A)
   {
	  var Total=document.getElementById("Total").value;
	  var FinalGT= parseFloat(Total) + parseFloat(A);
	  
	  /*if(A == '')
	  {*/
	  if(isNaN(FinalGT))
		{
		  document.getElementById("GrandTotal").value=parseFloat(Total);
		}
		else
		{
		  document.getElementById("GrandTotal").value=parseFloat(FinalGT);
		}
		  
   }
   
////////////////////////////////////// Some Hint By Amit Kumar ////////////////////////////////////////
//As Per Requirment Inclusive Option Yes -> Hide As Per Actual                                       //
//As Per Requirment Inclusive Option NO ->  Show As Per Actual                                       //
//////////////////////////////////////////////////////////////////////////////////////////////////////  

function ChargeAmount(CA,ID)
 {
   if (CA=='NO')
     {
		document.getElementById(ID).disabled=false;
		document.getElementById("actual_"+ID).disabled=false;
		document.getElementById("AsPerActual_"+ID).disabled=false;
	 }
	else if (CA!='NO')
	 {
		document.getElementById(ID).disabled=true;
		document.getElementById("AsPerActual_"+ID).disabled=true; 
		document.getElementById("actual_"+ID).disabled=true;
		document.getElementById(ID).value='';
		document.getElementById("actual_"+ID).value='';
	 }    
  }
var Total=0;
 function DiscountAmount(DA,i)
{
	var discount_percent = document.getElementById("PerAmo_"+i).value;
	var rate = document.getElementById("Rate_"+i).value;
	var discount = document.getElementById("Discount_"+i).value;
	var quantity = document.getElementById("Quantity_"+i).value;
	var totalPrice = quantity*rate;
	if(discount_percent=='PercentAmt')
	{
		if(discount==''){discount=0;}
		var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{
		var percent = parseFloat(document.getElementById("Discount_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	document.getElementById("perc_"+i).value=percent.toFixed(2);
	document.getElementById("NetRate_"+i).value=subTotal.toFixed(2);
	
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	return true;
}	


/****************************************/
function DiscountAmountdpc(DA,i)
{
	var discount_percent = document.getElementById("Perspc_"+i).value;
	var totalPrice = document.getElementById("NetRate_"+i).value;
	var discount = document.getElementById("SpecialDiscount_"+i).value;
	if(discount_percent=='PercentAmt')
	{
		
		if(discount==''){discount=0;}
		var percent = parseFloat(totalPrice) * parseFloat(discount)/100;
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	else if(discount_percent=='Amount')
	{
		var percent = parseFloat(document.getElementById("SpecialDiscount_"+i).value);
		if(isNaN(percent)){percent=0;}
		var subTotal = parseFloat(totalPrice)-parseFloat(percent);
	}
	document.getElementById("Specialperc_"+i).value=percent.toFixed(2);
	document.getElementById("basic_"+i).value=subTotal.toFixed(2);
	
	/*Total=parseFloat(Total) + parseFloat(subTotal);
	document.getElementById("Total").value=Total;*/
	return true;
}	
/*************************************




function DiscountAmountspe(DA,i)
{
	var total1=document.getElementById("NetRate_"+i).value;
	
	var discount1 = document.getElementById("SpecialDiscount_"+i).value;
	var Specialperc=document.getElementById("Specialperc_"+i).value;
	
	if(discount1=='' && Specialperc=='')
	{
		var total1=document.getElementById("NetRate_"+i).value;
		
		document.getElementById("basic_"+i).value=total1;
	
	}
	else
	{
		if(discount1=='' && Specialperc!='')
		{
			var elx=document.getElementById("Specialperc_"+i).value;
			var total1=document.getElementById("NetRate_"+i).value;
			
			var TotalAmount2 = total1-parseFloat(elx);
			
			document.getElementById("basic_"+i).value=TotalAmount2.toFixed(2);
		}
		else
		{
			var percent1 = total1 * parseFloat(discount1)/100;
			var TotalAmount2 = total1-parseFloat(percent1);
	
			document.getElementById("Specialperc_"+i).value=percent1.toFixed(2);
			document.getElementById("basic_"+i).value=TotalAmount2.toFixed(2);
		}
	
	}
}***/
 
</script>

<script>
 var TotalAmount=0;
function AmountWithtax(AWT, i ,j)
{
	//alert("manvi");
    var NetRate = document.getElementById("NetRate_"+i).value;
   	var TaxValue = document.getElementById("taxvalue_"+i).value;
	var TotalAmountWithTax = (parseFloat(NetRate) * parseFloat(TaxValue))/100;
	if(isNaN(TotalAmountWithTax)){
	document.getElementById("totaltaxamount_"+i).value=parseFloat(0);
	document.getElementById("TotalAmountWirhTaxAmount_"+i).value = NetRate;
	}else{
	var TotalTaxAmount = document.getElementById("totaltaxamount_"+i).value=parseFloat(TotalAmountWithTax);
	var TotalTaxAmount = document.getElementById("totaltaxamount_"+i).value=parseFloat(TotalAmountWithTax);
	if(isNaN(TotalTaxAmount)){
	var TotalCostWithTax  = document.getElementById("TotalAmountWirhTaxAmount_"+i).value= parseFloat(0);
	}else{	
	var TotalCostWithTax  = document.getElementById("TotalAmountWirhTaxAmount_"+i).value= parseFloat(TotalTaxAmount) + parseFloat(NetRate);
	}
	}	
	TotalAmount=parseFloat(TotalAmount) + parseFloat(TotalCostWithTax);
		//document.getElementById("Total").value=TotalAmount;
	return true;
}
function totalGetvalue()
	{
		//alert("manvi");
		var amount=0; 
		var ob;
		var count = document.getElementById("count").value;
		for(i=1;i<count;i++)
		{
			ob=document.getElementById("TotalAmountWirhTaxAmount_"+i);
			if(ob.value!='')
			{
				amount +=parseFloat(ob.value);
			}
	    }
		document.getElementById("Total").value=amount;
	}
function openPopUp(i)
{
	window.open("Search_Vendor.php?rowcount="+i,"Search_Vendor_window","height=425,width=400,toolbar=no,menubar=no,dependent=yes,resizable=yes,scrollbars=yes");
}

function Newvendor()
{
	window.redirect("POModule/MR_SelectOSMaterialRequi.php");
}

function check1(Ta1,i)
{
var total1=parseFloat(document.getElementById("NetRate_"+i).value);	
var Specialperc=parseFloat(document.getElementById("Specialperc_"+i).value);
if(total1<Specialperc)	
{
alert("Special Discount Amount Not Greater then Sub Total");
	document.getElementById("SpecialDiscount_"+i).value='';
	document.getElementById("Specialperc_"+i).value='';	
	document.getElementById("SpecialDiscount_"+i).focus();	
}
}
function calcPackaging(str)
{
	if(str!='')
	{
		var tota_amt=document.getElementById("total_item_amount").value;
		var pckgng_val=(str/100)*tota_amt;
		document.getElementById("pkg_charges1").value=pckgng_val.toFixed(2);
	}
}


/*function valid()
{
	if(document.getElementById("VendorCodeSearch").value == '')
	{
		alert("Please Choose A Vendor Code From The Pop UP");
		document.getElementById("VendorCodeSearch").focus();
		return false;
	}
	return true;
}*/
/*function display(x)
{
	var code = document.getElementById("VendorCodeSearch").value;
	if(code != "")
	{
}	*/	
</script>
