<link rel="stylesheet" href="css/new_mxerp.css">
<?php  
include('Class_Party.php');

//*******************SERVER SIDE VALIDATION*************AMIT SINGH***************27-10-2012*******************************

if($_REQUEST['Save']!='' && $_REQUEST['action']=='Edit')
{
	$fstatus=true;
	if($_REQUEST['site']=='0')
	{
	$msgErr[]="Please Select The Branch";
	$fstatus=false;
	}
	if($_REQUEST['quotationNo']=='')
	{
	$msgErr[]="Please Enter The Quotation No";
	$fstatus=false;
	}
	if($_REQUEST['quotationDate']=='')
	{
	$msgErr[]="Please Enter The Quotation Date";
	$fstatus=false;
	}
	if($_REQUEST['party']=='0')
	{
	$msgErr[]="Please Select The Party ";
	$fstatus=false;
	}
	if($_REQUEST['quotationType']=='0')
	{
	$msgErr[]="Please Select The Quotation Type ";
	$fstatus=false;
	}
	/*if($_REQUEST['enquiryNo']=='')
	{
	$msgErr[]="Please Enter The Enquiry No ";
	$fstatus=false;
	}*/
	if($_REQUEST['validTill']=='')
	{
	$msgErr[]="Please Enter The Valid Date ";
	$fstatus=false;
	}
	if($_REQUEST['basicAmount']=='')
	{
	$msgErr[]="Please Enter The Basic Amount   ";
	$fstatus=false;
	}
	if($_REQUEST['totalDiscountedPrice']=='')
	{
	$msgErr[]="Please Enter The Total Discount Price   ";
	$fstatus=false;
	}
	if($_REQUEST['taxableAmount']=='')
	{
	$msgErr[]="Please Enter The Taxable Amount ";
	$fstatus=false;
	}
	if($_REQUEST['grandTotal']=='')
	{
	$msgErr[]="Please Enter The Grand Total ";
	$fstatus=false;
	}
}

//*******************SERVER SIDE VALIDATION*************AMIT SINGH***************27-10-2012*******************************



//*******************DELETE ITEMS*************AMIT SINGH***************START HERE******************************************


if($_REQUEST['act']=='delitem' && $_REQUEST['id']!='')
{
	$condition="id='".$_REQUEST['id']."'";
	$s->DeleteRecord('quotation_details',  $condition);
	echo "<script>location.href='index.php?route=CRM/CRM_Dir_Quotes_Edit&action=Edit&QID=".$_REQUEST['QID']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

//*******************DELETE ITEMS*************AMIT SINGH***************END HERE******************************************



//*******************FETCH DATA FROM PARANT TABLE*************AMIT SINGH***************START HERE************************


if($_REQUEST['action']=='Edit')
{ 
	$sql1=DB_query("Select * from quotation where id='".$_REQUEST['QID']."'",$db);
	$result1=DB_fetch_array($sql1);
	$site= $result1['site']; 
	$quotationNo=$result1['quotationNo'];  
	$quotationDate=ConvertSqlDate($result1['quotationDate']);  
	$party=$result1['party'];   
	$quotationType=$result1['quotationType'];
	$quotationSubject=$result1['quotationSubject'];
	$quotation_funnel=$result1['quotation_funnel'];
	$quotation_stage=$result1['quotation_stage'];
	$order_type=$result1['order_type'];
	$enquiryNo=$result1['enquiryNo'];
	$source=$result1['source1']; 
	$contactPerson=$result1['contactPerson']; 
	$partyContact=$result1['partyContact'];
	$quotationSite=$result1['quotationSite'];  
	$validTill=ConvertSQLDate($result1['validTill']);
	$quotationMailDate=ConvertSQLDate($result1['quotationMailDate']);
	$pack_forward=$result1['pack_forward'];  
	$freight=$result1['freight']; 
	$payTerms=$result1['payTerms'];  
	$salesTax=$result1['salesTax'];  
	$Excise=$result1['Excise'];  
	$type=$result1['type'];  
	$insurance=$result1['insurance'];  
	$basicAmount=$result1['basicAmount'];  
	$totalDiscountedPrice=$result1['totalDiscountedPrice'];  
	$exciseDuty=$result1['exciseDuty'];  
	$exciseValue=$result1['exciseValue'];
	$Ecessid=$result1['ECessId'];
	$ECessValue=$result1['ECessValue'];  
	$SAHCessid=$result1['SAHCessId'];
	$SAHCessValue=$result1['SAHCessValue'];  
	$taxableAmount=$result1['taxableAmount'];
	$hrdtotalAmt=$result1['hrdtotalAmt'];
	$VatCst=$result1['VatCst'];  
	$VatCstValue=$result1['VatCstValue'];  
	$against=$result1['against'];
	$VatCst1=$result1['VatCst_hrd'];  
	$VatCstValue1=$result1['VatCstValue_hrd']; 
	
	$sales_tax_taxabelamt=$result1['sales_tax_taxabelamt'];  
	$sales_tax_hrdamt=$result1['sales_tax_hrdamt'];
	$discounttype=$result1['discounttype'];
	$discountper=$result1['discountper'];
	$discountamount=$result1['discountamount'];
	$afterdiscount=$result1['afterdiscount'];
	$freightValue=$result1['freightValue'];  
	$packagingCharges=$result1['packagingCharges'];  
	$additionalCharges=$result1['additionalCharges'];  
	$roundOff=$result1['roundOff'];  
	$grandTotal=$result1['grandTotal'];  
	$createdBy=$_SESSION['UserID'];  
	$ConvertIntoSales=$result1['ConvertIntoSales'];  
	$SalesOrderNo=$result1['SalesOrderNo']; 
	$ContactPerson=$result1['contactPerson'];
	$OrderType=$result1['order_type'];
	$our_ref_no=$result1['our_ref_no'];
	$subject=$result1['subject'];
	$billing_address=$result1['billing_address'];
	$billing_city=$result1['billing_city'];
	$billing_state=$result1['billing_state'];
	$billing_country=$result1['billing_country'];
	$shipping_address=$result1['shipping_address'];
	$shipping_city=$result1['shipping_city'];
	$shipping_state=$result1['shipping_state'];
	$shipping_country=$result1['shipping_country'];
	$delivery=$result1['delivery'];
	$validity=$result1['validity'];
	$basicAmount=$result1['basicAmount'];
	$totalDiscountedPrice=$result1['totalDiscountedPrice'];
	$exciseDuty=$result1['exciseDuty'];
}

//*******************FETCH DATA FROM PARANT TABLE*************AMIT SINGH***************END HERE************************



//*******************UPADET RECORDS*************AMIT SINGH***************START HERE************************************

if($_REQUEST['Save']!='' && $_REQUEST['action']=='Edit' && $fstatus)
{




	date_default_timezone_set('Asia/Kolkata');
	$data['basicAmount']=$_REQUEST['basicAmount'];
	$data['exciseDuty']=$_REQUEST['EDBillRate'];
	$data['totalDiscountedPrice']=$_REQUEST['totalDiscountedPrice'];
	$data['ECessPercentage']=$_REQUEST['ECessPercentage'];
	$data['ECessValue']=$_REQUEST['ECessValue'];
	$data['SAHCessPercentage']=$_REQUEST['SAHCessPercentage'];
	$data['SAHCessValue']=$_REQUEST['SAHCessValue'];
	$data['taxableAmount']=$_REQUEST['taxableAmount'];
	$data['VatCst']=$_REQUEST['VatCst'];  
	$data['VatCstValue']=$_REQUEST['VatCstValue'];  
	$data['VatCst_hrd']=$_REQUEST['VatCst_hrd'];  
	$data['VatCstValue_hrd']=$_REQUEST['VatCstValu1e1'];
	$data['sales_tax_taxabelamt']=$_REQUEST['total_taxable_amt'];
	$data['sales_tax_hrdamt']=$_REQUEST['total_taxable_hrd'];
	$data['freight']=$_REQUEST['freight'];
	$data['hrdtotalAmt']=$_REQUEST['hrdtotalAmt'];
	$data['grandTotal']=$_REQUEST['grandTotal'];  
	$data['billing_address']=$_REQUEST['address1']; 
	$data['billing_city']=$_REQUEST['city']; 
	$data['billing_state']=$_REQUEST['zipcode']; 
	$data['billing_country']=$_REQUEST['country']; 
	$data['shipping_address']=$_REQUEST['Shipping_address']; 
	$data['shipping_city']=$_REQUEST['Shipping_city']; 
	$data['shipping_state']=$_REQUEST['Shipping_zipcode']; 
	$data['shipping_country']=$_REQUEST['Shipping_country']; 
	
	$data['discounttype']=$_REQUEST['PerAmount']; 
	$data['discountper']=$_REQUEST['Discount_amount']; 
	$data['discountamount']=$_REQUEST['discountperc'];
	$data['afterdiscount']=$_REQUEST['afterdiscountprice'];
	
	$data['process_quote_type']='Process';
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['quotationSubject']=htmlspecialchars($_REQUEST['quotationSubject'],ENT_QUOTES);
	$mail = str_replace('/', '-',$_REQUEST['quotationMailDate']);
	$data['quotationMailDate']=date('Y-m-d', strtotime($mail));
	$data['quotationSite']=$_REQUEST['Consignee'];
	$data['quotation_stage']=htmlspecialchars($_REQUEST['quotation_stage'],ENT_QUOTES);
	$data['contactPerson']=$_REQUEST['ContactPerson'];
	$data['partyContact']=$_REQUEST['partyContact2'];
	$valid = str_replace('/', '-', $_REQUEST['validTill']);
	$data['validTill']=date('Y-m-d', strtotime($valid));
	$data['quotationType']=$_REQUEST['quotationType'];
	//$s->RecordInsert('quotation', $data);
	//$masterId=DB_Last_Insert_ID($db,'quotation','id');
	$data['modified_id']=$_SESSION['UserID'];
	$data['modified_date']=date("Y-m-d H:i:s");
	
	$cond1="id='".$_REQUEST['QID']."'";
	$s->RecordEdit('quotation', $data, $cond1);// UPDATE ON PARANT TABLE

	$type_str=implode("=",$_REQUEST[qtytype]);
	$type_arr=explode("=",$type_str);
   $del=DB_query("delete from quotation_details where parentId='".$_REQUEST['QID']."'",$db);
	for($cnt=0;$cnt<count($_REQUEST['item_code']);$cnt++)
	{	
		if($_REQUEST['item_code'][$cnt]!=''){
		$dataArr['parentId']=$_REQUEST['QID'];
		$dataArr['itemCode']=$_REQUEST['item_code'][$cnt];
		$dataArr['sizeid']=$_REQUEST['size'][$cnt];
		$dataArr['quantity']=$_REQUEST['stock_qty'][$cnt];
		$dataArr['price']=$_REQUEST['stock_price'][$cnt];
		$dataArr['PerUnits']=$_REQUEST['stock_perunit'][$cnt];
		$dataArr['totalValue']=$_REQUEST['stock_value'][$cnt];
		$dataArr['discount_type']=$_REQUEST['PerAmo'][$cnt];
		$dataArr['discount_per']=$_REQUEST['Discount'][$cnt];
		$dataArr['after_dis']=$_REQUEST['perc'][$cnt];
		$dataArr['stock_value']=$_REQUEST['value_dis'][$cnt];
		$dataArr['requisitionDate']=date('Y-m-d');
		$dataArr['secondary_qty']=$_REQUEST['secondary_qty'][$cnt];
		
		$select_item=explode("-",$type_arr[$cnt]);
		$dataArr['est_qty_prm_sec']=$select_item[0];
		$dataArr['unit']=$select_item[1];
		$dataArr['secondary_unit']=$select_item[2];
		
		if($select_item[3]==1)
		$dataArr['est_unit_prm_sec']=$select_item[1];
		else
		$dataArr['est_unit_prm_sec']=$select_item[2];		
		$s->RecordInsert('quotation_details',$dataArr);
		}
	}
	
	 $del1=DB_query("delete from quotation_hardware_items where parant_id='".$_REQUEST['QID']."'",$db);
	for($z=0; $z<count($_REQUEST['hrditemid']);$z++)
	{
		$cnt=$_REQUEST['addhrditem'][$z];		
		$hrddata['parant_id']=$_REQUEST['QID'];
		$hrddata['hardwarepart']=$_REQUEST['hardwarepart'][$z];
		$hrddata['itemCode']=$_REQUEST['hrditemid'][$z];
		$hrddata['quantity']=$_REQUEST['hrd_qty'][$z];
		$hrddata['price']=$_REQUEST['hrd_price'][$z];
		$hrddata['PerUnits']=$_REQUEST['hrd_perunit'][$z];
		$hrddata['totalValue']=$_REQUEST['hrd_value'][$z];
		$hrddata['discount_type']=$_REQUEST['hrdPerAmo'][$z];
		$hrddata['discount_per']=$_REQUEST['hrdDiscount'][$z];
		$hrddata['after_dis']=$_REQUEST['hrdperc'][$z];
		$hrddata['stock_value']=$_REQUEST['hrdvalue_dis'][$z];
		$hrddata['isChecked']=$cnt;
		//echo "<pre>";
		//print_r($hrddata);
		$s->RecordInsert('quotation_hardware_items',$hrddata);
	}
	$delquot=DB_query("delete from quotation_terms_cond where parant_id='".$_REQUEST['QID']."' and frm_id='".$_REQUEST['frmid']."'and company_id='".$_SESSION['ACGCompanyId']."' and type='quotation'  ",$db);
	for($k=0;$k<count($_REQUEST['terms']);$k++)
	{
		$dataterm['parant_id']=$_REQUEST['QID'];
		$dataterm['termsid']=$_REQUEST['terms'][$k];
		$dataterm['condid']=$_REQUEST['Terms_Condition'][$k];
		$dataterm['frm_id']=$_REQUEST['frmid'];
		$dataterm['company_id']=$_SESSION['ACGCompanyId'];
		$dataterm['type']="quotation";
		$s->RecordInsert('quotation_terms_cond', $dataterm);
	}
	
	
	
	$_SESSION['success_msg']="UPDATED Successfully";
	$s->pageLocation("index.php?route=CRM/ViewQuotes".$rurl);
}

//*******************UPADET RECORDS*************AMIT SINGH***************END HERE************************************



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

<?php //echo $ConvertIntoSales;?>
	<!--<table border="0">
<tr>
    <td>	
	<?php  if( $ConvertIntoSales=='N'){?>
		<a href="index.php?route=CRM/CRMSalesOrder&QID=<?php  echo $_REQUEST['QID'].$rurl;?>">
	<input type="button" name="Create" value="Convert into Sales Order" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a>
	
	<?php } elseif($_REQUEST['action']!='AddNew'){?>
		<a href="index.php?route=CRM/CRMSalesOrder&action=Edit&SID=<?php echo $SalesOrderNo?>&QID=<?php  echo $_REQUEST['QID'].$rurl;?>">
	<input type="button" name="ViewSaleOrder" value="View Sales Order" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a>
	
	
	<?php }
	if($_REQUEST['action']=='Edit'){
	?>
	 <a href="CRM/tcpdf/PDFQuotes.php?record=<?php echo $_REQUEST['QID'].$rurl;?>">
	 <input type="button" name=" Export to PDF" value=" Export to PDF" style=" background-image:
	 url(images/PDF.gif)background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px; " />
</a><?php } ?>
	 
</td></tr></table>-->
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Quote Management</h1>
 <form action="" method="post"  name="frm1" id="frm1">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
    <td colspan="4"><h3 style="color:#003399">Direct Quote Offer To Customer</h3></td>
 </tr>
<?php


if(count($msgErr>0))
{
?>
<tr><td colspan="4">
<?php
for($k=0;$k<count($msgErr);$k++) 
{
echo "<div class='error'>".$msgErr[$k]."</div>";
}
?>	
</td></tr>	
<?php	
} 
?>	


	 
  <tr class="row1">
  	<td colspan="4" style="padding:0px;"><table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr class="row1">
    <td width="13%" align="left" valign="top">Branch<font color="#FF0000">*</font></td>
    <td width="20%" align="left" valign="top"><!--<select name="site"   id="site" style="width:150px;">
	<option value="0">Select</option>
	<?php 
	//$site_sql=DB_query("Select loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
	//while($site_row=DB_fetch_array($site_sql)) {?>
	<option value="<?php // echo $site_row['loccode']?>"<?php // echo($site==$site_row['loccode']?'selected':'')?>><?php // echo $site_row['locationname']?></option>-->
	<?php 	
	//}
	?>
	<?php $site_query=DB_fetch_array(DB_query("SELECT locationname FROM `locations`,`quotation` WHERE loccode=site AND quotation.id='".$_REQUEST['QID']."'",$db)); ?>
	</select> <input type="text" readonly name="site" value="<?php echo $site_query['locationname']; ?>" style="width:100%;" /></td>
    <td width="13%" align="left" valign="top">Quotation No.	</td>
    <td width="20%" align="left" valign="top" id="CODE"><input name="quotationNo" type="text" value="<?php echo $quotationNo; ?>" readonly="" style="width:100%;"/></td>
    <td width="15%" align="left" valign="top">Date<font color="#FF0000">*</font></td>
    <td align="left" valign="top"><input type="text" name="quotationDate" value="<?php if(isset($quotationDate)){echo $quotationDate;}?>" style="width:100%;" readonly id="quotationDate" /></td>
  </tr>
  <tr class="row1">
    <td align="left" valign="top">Client<font color="#FF0000">*</font></td>
    <td align="left" valign="top"><!--<select name="party" style="width:150px;"  id="party" onchange="showalldata(this.value);">
	<option value="000">Select</option>
	<?php
	   /*	$client_sql=DB_query("Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'  
		and  Site in('".$_SESSION['AssignedBranch']."') and Zone in(".$_SESSION['AssignedSites'].")",$db);
		  while($client_row=DB_fetch_array($client_sql)) {*/?>
			<option value="<?php // echo $client_row['id'];?>"<?php // echo($party==$client_row['id']?'selected':'')?>>
			<?php // echo $client_row['c_name'];?></option>
						  <?php // } ?>
	</select> -->
	<?php $client_name=DB_fetch_array(DB_query("SELECT c_name,clientmaster.id FROM `clientmaster`,`quotation` WHERE quotation.party=clientmaster.id AND quotation.id='".$_REQUEST['QID']."'",$db)) ?>
	<input type="text" style="width:100%;" name="party" value="<?php echo $client_name['c_name']; ?>" readonly  /> </td>
    <td align="left" valign="top">Against<font color="#FF0000">*</font></td>
    <td align="left" valign="top"><input type="text" style="width:100%;" readonly name="against" value="<?php if($against=='Enquiry') echo 'Lead'; elseif($against=='Estimation') echo 'Estimation'; else echo 'Estimation Against Bom'; ?>" /></td>
    <td align="left" valign="top">Lead/Estimation No.<font color="#FF0000">*</font></td>
    <td align="left" valign="top"><div id='hid_Leads'>
	<input type="hidden"  id="leadid" value="<?php echo $result1['enquiryNo']; ?>" />
	
		<?php 
	
	$enquery_leadid=$s->GetFieldValue('cstest_estimation_bom',"id='".$result1['enquiryNo']."'",'sheet_no');
	
	//echo $enquery_leadid;
	?>
	
	
	<input type="text" name="enquiryNo" readonly style="width:100%;" value="<?php  echo $enquery_leadid;?>" /></div></td>
  </tr>
  <tr class="row1">
    <td align="left" valign="top">Format<font color="#FF0000">*</font></td>
    <td align="left" valign="top"><select name="format" style="width:100%;">
	<option value="Standard">Standard</option>
	</select></td>
    <td align="left" valign="top">Type</td>
    <td align="left" valign="top"  id="typeid"><?php   
	$type_name=DB_fetch_array(DB_query("SELECT * FROM type_master where id='".$type."'",$db));
		
	?>
	<input type="text" name="type" readonly style="width:100%;" value="<?php echo $type_name['name']; ?>"  />	</td>
    <td align="left" valign="top">Quote Type<font color="#FF0000">*</font></td>
    <td align="left" valign="top"><select name="quotationType" style="width:100%;">
	<option value="Material"<?php echo($quotationType=='Material'?'selected':'')?>>Material</option>
	<option value="Supply"<?php echo($quotationType=='Supply'?'selected':'')?>>Supply</option>
	<option value="Composite"<?php echo($quotationType=='Composite'?'selected':'')?>>Composite</option>
	</select></td>
  </tr>
  
  <tr class="row1">
    <td align="left" valign="top">Consignee<font color="#FF0000">*</font></td>
    <td align="left" valign="top"><select name="Consignee" id="Consignee" style="width:100%;">
	<?php $consignee=DB_query("SELECT * FROM `clientmaster_consignee_address` where client_id='".$client_name['id']."'",$db);
	while($consignee_row=DB_fetch_array($consignee))
	{
	?>
	<option value="<?php echo $consignee_row['id']; ?>" <?php if($quotationSite==$consignee_row['id']) { echo "selected";}?> ><?php echo $consignee_row['consignee_name']; ?></option>
	<?php } ?>
	</select></td>
    <td align="left" valign="top">Quote Stage</td>
    <td align="left" valign="top"><input type="text" style="width:100%;"  name="quotation_stage" value="<?php  echo $quotation_stage;?>"/></td>
    <td align="left" valign="top">Valid Till</td>
    <td align="left" valign="top"><input name="validTill" type="text" value="<?php if(isset($validTill)){echo $validTill;} ?>" style="width:100%;" class="datepicker" id="validTill" onchange="return selectDate();"/></td>
  </tr>
  <tr class="row1">
    <td align="left" valign="top">Contact Person</td>
    <td align="left" valign="top"><select name="ContactPerson" id="ContactPerson" style="width:100%;" onchange="javascript:get_mobilenumber(this.value);">
		<option value="0" <?php if($contactPerson==0){ echo "selected";}?>>Select</option>
		<?php  
		$contact_person=DB_query("select * from contact_information_master where master_code='".$client_name['id']."'",$db);
while($contact_person_row=DB_fetch_array($contact_person))
{ ?>
		<option value="<?php echo $contact_person_row['id'];?>" <?php if($contactPerson==$contact_person_row['id']){ echo "selected";}?>><?php echo $contact_person_row['person']; ?> </option>
		<?php }?>
	</select></td>
    <td align="left" valign="top">Mobile No.</td>
    <td align="left" valign="top"><div id="mobile_check">
	<input type="text" name="partyContact2" id="partyContact2" readonly  style="width:100%;" value="<?php echo $partyContact;?>" /></div></td>
    <td align="left" valign="top">Mail Date</td>
    <td align="left" valign="top"><input type="text" name="quotationMailDate" id="quotationMailDate" style="width:100%;" value="<?php if(isset($quotationMailDate)){echo $quotationMailDate;} else { echo $_REQUEST['quotationMailDate'];}?>" class="datepicker" /></td>
  </tr>
  
  <tr class="row1">
    <td align="left" valign="top">Subject</td>
    <td colspan="5" align="left" valign="top"><textarea name="quotationSubject" id="quotationSubject" style="width:100%;"><?php echo $quotationSubject; ?></textarea></td>
    </tr>
</table></td>
	</tr>
<tr class="row1">
    <td colspan="6"><h3 style="color:#003399">Account  Billing  &  shipping  Address  Information <span style="color:#000;">(Check if Same)</span> <input type="checkbox" name="check" id="check"  onclick="showdatashipping()"
	<?php if($shipping_address!='') { ?> checked="checked" <?php } ?>
	/></h3></td>
  </tr>



<tr class="row1">
    <td class="tabledata1" >Billing Address</td>
    <td>
    <input type="text" name="address1" style="width:150px;" id="address1"   value="<?php  echo $billing_address;?>"/></td>
    <td class="tabledata1" >Shipping Address</th>
    <td id="CODE"><input type="text" name="Shipping_address" style="width:150px;" id="shipping_address1"   value="<?php  echo $shipping_address;?>"/></td>
  </tr>
<tr class="row1">
    <td class="tabledata1" >Billing city</td>
    <td><input name="city" type="text" id="city"  style="width:150px;" value="<?php  echo $s->getField('city_master','id',$billing_city,'city');?>"/></td>
    <td class="tabledata1" >shipping City</td>
    <td><input name="Shipping_city" type="text" id="ship_city"  style="width:150px;" value="<?php  echo $shipping_city?>"/></td>
  </tr>
<tr class="row1">
    <td class="tabledata1" >Billing State</td>
    <td>
    <input type="text" name="zipcode" style="width:150px;" id="state"  value="<?php  echo $billing_state?>" /></td>
    <td class="tabledata1" >Shipping State</td>
    <td><input type="text" name="Shipping_zipcode" id="ship_state" style="width:150px;"  value="<?php  echo $shipping_state?>" /></td>
    </tr>
<tr class="row1">
    <td class="tabledata1" >Billing Country</td>
    <td><input name="country" type="text" id="country"  style="width:150px;" value="<?php  echo $s->getField('country_master','id',$billing_country,'country');?>"/></td>
    <td class="tabledata1" >Shipping Country</td>
    <td><input name="Shipping_country" type="text" id="ship_country"  style="width:150px;" value="<?php  echo $shipping_country;?>"/></td>
    </tr>
<tr class="row1">
    <td colspan="6"><h3 style="color:#003399">Item Details</h3></td>
  </tr>
</table>
 
<div id="ITEMSDETAILS" style="width:947px; overflow:auto;">
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border:#666666 solid 1px;">
             
		<!-------------Add ITEMS IN THE ITEM LIST AT TIME OF EDIT----------------------->
<tr bgcolor="<?php //echo $bg;?>"  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">Size</td>
<td colspan='7' style='text-align:center' class="tabledata">Qty.</td>
<td class="tabledata">Price</td>
<td class="tabledata">Per Unit</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">Value After Discount</td>
</tr>
<?php 
 $i=0;
 //echo "Select * from quotation_details where parentId='".$_REQUEST['QID']."'";
  $ItemSQL=DB_query("Select * from quotation_details where parentId='".$_REQUEST['QID']."'",$db);
  while($item_row1=DB_fetch_array($ItemSQL))
  {
 
	//echo "select * from item_master where id='".$item_row1[ItemCode]."'";
	 $itemquery=DB_query("select * from item_master where id='".$item_row1['itemCode']."'" , $db);
	$item_row=DB_fetch_array($itemquery);
	 //echo "select StockID,item_name,unit, make ,grade, color from item_master where StockID='".$itemlist[$i]."'" ;
	
		if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";
		
		
			$item_Codeas=$s->GetFieldValue('item_master',"id='".$item_row1['itemCode']."'",'StockID');
			$item_names=$s->GetFieldValue('item_master',"id='".$item_row1['itemCode']."'",'item_name');
			$unit=$s->GetFieldValue('item_master',"id='".$item_row1['itemCode']."'",'mst_unitid');
			$conv_unit=$s->GetFieldValue('item_master',"id='".$item_row1['itemCode']."'",'conv_unit');
			$confac=$s->GetFieldValue('item_master',"id='".$item_row1['itemCode']."'",'conv_factor');
			
			$confac_qty=$s->GetFieldValue('cstest_estimation_bom_details',"mst_itemid='".$item_row1['itemCode']."' 
						and master_id='".$enquiryNo."' and    item_size='".$item_row1['sizeid']."'  ",'item_sec_qty');
						
						
			/*********************  Getting  All Id from  Estimation Sheet_details  *************/		
			
			$items=DB_query("select * from cstest_estimation_bom_details
			 where master_id='".$enquiryNo."' ",$db);
 						while($item1=DB_fetch_array($items)) 	
						  {	  $item2[]=$item1['id']; 	  }   $itemsdata=implode("','",$item2);
   
              
			  
			
			
			/*********************  End  *********************************************************/			
						
			
			$SqlHRdQty=DB_query("SELECT * FROM cstest_estimation_bom_details_asmbly 
			where mst_itemid='".$item_row1['mst_itemid']."' and details_mst_id='".$GetEsti['id']."'",$db);
			$arr='';
			
			
			$amt=0;
			$itemid1='';
			while($hrdQty=DB_fetch_array($SqlHRdQty))   {	$arr[]=$hrdQty['asmbly_item_qty'];	
			$amt=$amt+$hrdQty['asmbly_item_amt'];	}

?>
<tr class="row1" id="hide_<?php echo $i; ?>">
<td style="white-space:nowrap;" class="tabledata"><div id="deactive_<?php echo $i; ?>" style='display:block;'>
		<a href="#"   onclick="deactivate("<?php echo $i; ?>")"><img src="images/delete1.gif" /></a>
		</div></td>
<td class="tabledata"><input type="hidden" name="item_code[]" id="itemid1_<?php echo $i; ?>" value="<?php echo $item_row1['itemCode']; ?>" /><input type="hidden" id="hrdqty1A_<?php echo $i; ?>" value="<?php echo $qtyhrd; ?>"></td>
<td class="tabledata"><?php echo $item_Codeas; ?></td>
<td class="tabledata" style='white-space:nowrap'><?php echo  $item_names; ?></td>
<td class="tabledata" style"white_space:nowrap">
<select style="width:100px;" name="size[]" id="size">
<option>--Select--</option>
<?php 
$SQLSize=DB_query("SELECT * FROM size_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	while($sizeid=DB_fetch_array($SQLSize)){
	$selsize='';
	if($item_row1['sizeid']==$sizeid['id'])
	$selsize='selected';
	?>
<option value="<?php echo $sizeid['id']; ?>" <?php echo $selsize; ?>><?php echo $sizeid['size']; ?></option>
<?php } ?>
</select>
</td>



<?php $primary=DB_fetch_array(DB_query("select * from unitsofmeasure where unitid='".$unit."'",$db));
	  $secon=DB_fetch_array(DB_query("select * from unitsofmeasure where unitid='".$conv_unit."'",$db));?>

<td class="tabledata"><input name="qtytype[<?php echo $i; ?>]" type="radio" id="qtyprim_<?php echo $i; ?>" value="<?php echo $item_row1['quantity']."-".$primary['unitid']."-".$secon['unitid']."-1"; ?>"  onclick="showqty2(this.id)" <?php if($item_row1['quantity']==$item_row1['est_qty_prm_sec']) { ?> checked="checked" <?php } ?> /></td>

<td class="tabledata"><?php echo $primary['unitname'];//$s->getField('unitsofmeasure','unitid',$unit,'unitname'); ?></td>

<td class="tabledata"><input type="text" name="stock_qty[]" readonly  id="stockqty_<?php echo $i; ?>" style="width:50px;"
 onkeyup="calcValue1(this.value,this.id)" value="<?php echo $item_row1['quantity']; ?>"  /></td>

<td class="tabledata"><input name="qtytype[<?php echo $i; ?>]" type="radio" value="<?php echo $item_row1['secondary_qty']."-".$primary['unitid']."-".$secon['unitid']."-2"; ?>" id="qtysec_<?php echo $i; ?>" onclick="showqty4(this.id)" <?php if($item_row1['secondary_qty']==$item_row1['est_qty_prm_sec']) { ?> checked="checked" <?php } ?>  /></td>

<td class="tabledata"><?php   echo $secon['unitname'];//echo $s->getField('unitsofmeasure','unitid',$conv_unit,'unitname'); ?></td>

<td class="tabledata"><input type="text" name="secondary_qty[]" readonly  id="secondary_<?php echo $i; ?>" style="width:50px;"
 onkeyup="calcValue1(this.value,this.id)" value="<?php echo $confac_qty; ?>"  /></td>

<td class="tabledata"><input type="hidden" name="convfac[]"  id="confac_<?php echo $i; ?>" style="width:50px;"
 value="<?php echo $confac; ?>"  /></td>

<td class="tabledata"><input type="text" name="stock_price[]" value="<?php echo $item_row1['price'] ; ?>"  id="stock_price_<?php echo $i; ?>" style="width:50px;"/></td>

<td class="tabledata"><input type="text" name="stock_perunit[]" onfocus="filldefaultAmt(this.value,this.id)" id="stock_perunit_<?php echo $i; ?>" style="width:30px;" value="1" /></td>
<?php 
$total_amt=round(($item_row1['quantity']*$item_row1['price'])/1,3);
?>

<td class="tabledata"><input type="text" name="stock_value[]"  id="stock_value_<?php echo $i; ?>" style="width:60px;" 
onfocus="CalculateTotalLeadAmt(this.value,this.id)" value="<?php echo $total_amt; ?>"/></td>

<td class="tabledata">
<select style="width:80px;" name="PerAmo[]" id="PerAmo_<?php echo $i; ?>"> 
<option value='Amount' >Amount</option>  
<option value='PercentAmt'>Percent Amt</option>  
</select>   
</td> 
<?php
$totalvalueamt=$total_amt;
?>
<td class="tabledata"><input type="text" style="width:50px;" name="Discount[]" id="Discount_<?php echo $i; ?>"
 onkeyup="DiscountAmount1(this.value,this.id)" value='0'
 /></td>
<td class="tabledata"><input type="text" style="width:50px;" name="perc[]" id="perc_<?php echo $i; ?>"  readonly='true' value='0'  /></td>
<td class="tabledata"><input type="text" style="width:70px;" name="value_dis[]" id="value_dis_<?php echo $i; ?>"  readonly="true" value="<?php echo $totalvalueamt; ?>"  /></td>
    	
  </tr>
  <?php  $i++;
   }  ?>	
  <input type="hidden" name="" value="<?php echo $i;?>" id="edit_cnt" /> 
 
</table>
 </div>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
 <input type="hidden" name="" value="" id="edit_cnt" />


<div style="overflow: auto; width:956px;">
<table  width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
<td class="tabledata1" colspan="15"><strong>Assembly & Sub Assembly Details</strong></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">Total Qty.</td>
<td class="tabledata">Unit.</td>
<td class="tabledata">Price</td>
<td class="tabledata">Per Unit</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">Value After Discount</td>
<td class="tabledata">Add</td>
</tr
><?php 
$k=$i;
$z=0;
$qty=0;
$totalproductqty=0;
$totalexciableamt=0;
$totalnonexciableamt=0;
$SQLhrd=DB_query("select * from quotation_hardware_items where parant_id='".$_REQUEST['QID']."'  ",$db);
while($GetHard=DB_fetch_array($SQLhrd))
{
$itemidcode='';
$totaproductqty=0;

            $itemid=$GetHard['itemCode'];
            //$item_names=$s->GetFieldValue('item_master',"id='".$GetHard['hardwarepart']."'",'item_name');            
		$unit1=$s->getField('item_master','id',$itemid,'mst_unitid');		
		
		
		
		$itemiddata=DB_query("select id  from cstest_estimation_bom_details_asmbly 
                   where details_mst_id in('".$itemsdata."')
				    and mst_asmbly_item_id='".$GetHard['itemCode']."' ",$db);				   
					while($row1=DB_fetch_array($itemiddata))
					{
					$itemidcode[]=$row1['id'];
					}	
					  $assemblyid=implode(",",$itemidcode);	
			
			    
		$hardware_flag=$s->GetFieldValue('cstest_estimation_bom_details_asmbly',"details_mst_id in('".$itemsdata."')
				    and mst_asmbly_item_id='".$GetHard['itemCode']."'",'hardware_flag');		
				   
		
				   
		?>		

<tr class="row1" >
<td style="white-space:nowrap;" class="tabledata"><input name="delitem[]" type="checkbox" value="" /></td>
<td class="tabledata"><input type="hidden" value="<?php echo $assemblyid; ?>" name="hrdid[]" id="hrdid_<?php echo $z; ?>"  />
<input type="hidden" name="hardwarepart[]" id="hardwarepart" value="<?php echo $GetHard['hardwarepart'] ; ?>" />
<input type="hidden" name="hrditemid[]" id="itemid" value="<?php echo $GetHard['itemCode']; ?>" /></td>
<td class='tabledata'><?php echo $s->getField('item_master','id',$itemid,'StockID'); ?></td>
<td class='tabledata' style="white-space:nowrap"><?php echo $s->getField('item_master','id',$itemid,'item_name'); ?></td>


<td class='tabledata'><input type='text' name="hrd_qty[]"  id="hrdstock_qty2_<?php echo $z; ?>" 
style="width:50px;" onkeyup="calcValue(this.value,<?php echo $z; ?>)" value="<?php echo $GetHard['quantity']; ?>"  /></td>
<td class='tabledata'><?php echo $s->getField('unitsofmeasure','unitid',$unit1,'unitname'); ?></td>


<td class='tabledata'><input type="text" name='hrd_price[]'  id="hrdstock_price1_<?php echo $z; ?>" value="<?php echo $GetHard['price']; ?>" style="width:50px;"/></td>
<td class='tabledata'><input type="text" name="hrd_perunit[]" onfocus="filldefaultAmt(this.value,this.id)" id="hrdstock_perunit1_<?php echo $z; ?>" style="width:30px;" value="1" /></td>
<?php 
$total_amt=round(($GetHard['quantity']*$GetHard['price'])/1,3);
?>

<td class='tabledata'><input type='text' name="hrd_value[]"  id="hrdstock_value1_<?php echo $z; ?>" style="width:60px;"
 onfocus="CalculateTotalLeadAmt2(this.value,<?php echo $z; ?>)"  value="<?php echo $total_amt; ?>" /></td>
<td class='tabledata'>
<select style="width:80px;" name="hrdPerAmo[]" id="hrdPerAmo1_<?php echo $z; ?>" > 
<option value='Amount' >Amount</option> 
<option value='PercentAmt'>Percent Amt</option> 
</select>
</td>
<?php 
$discountTotal_amt=$total_amt;

$exciable_amt=$s->getField('item_master','id',$GetHard['itemCode'],'item_exciable');
if($exciable_amt=='Y')
{
$totalexciableamt=$totalexciableamt+$discountTotal_amt;
}
else
{
$totalnonexciableamt=$totalnonexciableamt+$discountTotal_amt;
}
?>

<td class='tabledata'><input type='text' style='width:50px;' name="hrdDiscount[]" id="hrdDiscount1_<?php echo $z; ?>" onkeyup="DiscountAmount2(this.value,<?php echo $z; ?>)" value="<?php echo $GetHard['discount_per']; ?>" />
<input type='hidden' name='itemtye[]' id="itemtype_<?php echo $z; ?>" value="<?php echo $exciable_amt; ?>" ></td>
<td class='tabledata'><input type='text' style='width:50px;' name='hrdperc[<?php echo $z; ?>]' id="hrdperc1_<?php echo $z; ?>"  value="<?php echo $GetHard['after_dis']; ?>" readonly='true'  /></td>
<td class='tabledata'><input type='text' style='width:70px;' name='hrdvalue_dis[]' id="hrdvalue_dis1_<?php echo $z; ?>"  readonly='true' value="<?php echo $discountTotal_amt; ?>"  /></td>

<td class='tabledata'><input type='checkbox' name='addhrdAmt[]' value="<?php echo $GetHard['isChecked'];  ?>" id="addhrdAmt_<?php echo $z; ?>" onclick="showrecordsdata(<?php echo $z; ?>)" <?php if($hardware_flag==0) { ?>  disabled="disabled" <?php } else  if($GetHard['isChecked']==1) { ?> checked="checked" <?php  } ?> />
<input type="hidden" name="addhrditem[]" value="<?php echo $GetHard['isChecked']; ?>" id="addhrditem_<?php echo $z; ?>" />


</td>
</tr>
 <?php 
 $k++;$z++;}  ?>
</table>
<input type='hidden' name='hrdcount1' id='hrdcount1' value="<?php echo $z; ?>">
 </div>


<table width="100%" border="1"  cellpadding="3" cellspacing="0">
	<tr class="row1">
		<td valign="top" width="50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left">
			<tr class="row1">
				<td class="tabledata1" style="text-align:center;" colspan="2">Terms And Conditions</td>
			</tr>
<?php 
$data_quotes=array();
$sql_quotes=DB_query("select * from  quotation_terms_cond where parant_id='".$_REQUEST['QID']."'",$db);
while($sql_row_quotes=DB_fetch_array($sql_quotes))
{
$data_quotes[]=$sql_row_quotes['condid'];
}
$data11=implode("','",$data_quotes);





$i=0;
 $SQLTerms=DB_query("SELECT * FROM terms_condition where parant_id=0 and frm_id='".$_REQUEST['frmid']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
while($TermsAndCond=DB_fetch_array($SQLTerms)){



?>
			<tr class="row1">
				<td class="tabledata1"><?php echo $TermsAndCond['terms_conditions']; ?>
				<input type="hidden" name="terms[]" id="terms" value="<?php echo $TermsAndCond['id']; ?>" />
				</td>
				<td><select name="Terms_Condition[]" id="Terms_Condition" style="width:100%;">
						<option value="">Select</option>
						<?php $SQLCond=DB_query("SELECT * FROM terms_condition where parant_id='".$TermsAndCond['id']."'and frm_id='".$_REQUEST['frmid']."'and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
						while($GetCond=DB_fetch_array($SQLCond)){
						$d-'';
						if(in_array($GetCond['id'],$data_quotes))
						$d="selected='selected'";
						else
						$d='';	
						
						?>
						<option value="<?php echo $GetCond['id']; ?>" <?php echo $d; ?>  ><?php echo $GetCond['terms_conditions']; ?></option>
						<?php }?>
				</select></td>
			</tr>
<?php $i++;}?>
		</table>	
		</td>
		<td valign="top" width="50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="3" align="right">
			<tr class="row1">
				<td class="tabledata1" style="text-align:center;" colspan="4">Amount And Taxes</td>
			</tr>
			
			
			
			
			<tr class="row1">
					<td class="tabledata1">Basic Amount<label><font color="#FF0000">*</font></label></td>
					<td colspan="3"><input name="basicAmount" type="text" value="<?php echo $basicAmount; ?>" style="width:150px;" onfocus="calculateBasic_estimation()" id="basicAmount"   /></td>
			  </tr>
			<!--	  <tr class="row1">
					<td class="tabledata1" >Discounted Price<label><font color="#FF0000">*</font></label></td>
					<td><input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="<?php echo $totalDiscountedPrice;?>" style="width:150px;" onfocus ="calculateDiscounted()"/>
					
					
					</td>
					
				</tr>-->
			<tr class="row1">
			<td>Discount Type</td>
			<td><select  name='PerAmount' id='PerAmount' style="width:150px;" >
            <option value="Amount" <?php if($discounttype=='Amount') { ?> selected="selected" <?php } ?> >Amount</option>
            <option value="PercentAmt" <?php if($discounttype=='PercentAmt') { ?> 
			selected="selected" <?php } ?>>Percent Amt</option>
          </select></td>
			<td><input type="text" style="width:35px" name="Discount_amount" id="Discount_amount" 
onkeyup="DiscountAmountvalue(this.value)" value="<?php echo $discountper; ?>" /></td>
			<td>&nbsp;</td>
			</tr>
		  <tr class="row1">
<td>Discount Amt</td><td><input type="text" style="width:150px" name="discountperc" id="discountperc"  readonly="true" value="<?php echo $discountamount; ?>"  /></td>
			<td>Discounted Amt</td>
			<td><input type="text" style="width:150px" name="afterdiscountprice" id="afterdiscountprice"  readonly="true" 
			value="<?php echo $afterdiscount; ?>" /></td>
		  </tr>	
			
			<tr class="row1">
					<td class="tabledata1">Excise Duty</td>
					<td>
				  <select name="EDBillRate" id="EDRate" style="width:150px" 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($exciseDuty==$ServiceRow['id']?'selected':''); ?>>
		  <?php echo $ServiceRow['caption']?></option>
          <?php	
			}
    		
    		?>
				</select>							</td>
				    <td>Excise Amt </td>
				    <td><input name="totalDiscountedPrice" id="totalDiscountedPrice" 
				type="text"  style="width:150px;" onfocus="calculateTotalExcise()" value="<?php echo $totalDiscountedPrice; ?>"/>	</td>
			</tr>
	
	
	

			<tr class="row1">
					<td class="tabledata1">E-Cess</td>
					<?php $caption_ecess=DB_fetch_array(DB_query("select caption,def_rate from  excise_tax WHERE id='".$Ecessid."'",$db)); ?>
					<td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $caption_ecess['def_rate'];  ?>" style="width:150px;" readonly />						</td>
					<td><span class="tabledata1">E-Cess</span> Amt </td>
					<td><input name="ECessValue" id="ECessValue" type="text" value="<?php echo $ECessValue?>" style="width:150px;"readonly onfocus="calculateECess()"/></td>
			</tr>
			<tr class="row1">
					<td class="tabledata1" >SAH-E Cess </td>
					<?php $caption_sahecess=DB_fetch_array(DB_query("select caption,def_rate from  excise_tax WHERE id='".$SAHCessid."'",$db)); ?> 
					<td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $caption_sahecess['def_rate'];?>" style="width:150px;" readonly/>						</td>
					<td><span class="tabledata1">SAH-E Cess</span> Amt </td>
					<td><input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:150px;" readonly onfocus="calculateSAHCess()"/></td>
			</tr>
			<tr class="row1">
			<td class="tabledata1">Taxable Amount<label><font color="#FF0000">*</font></label></td>
			<td><input name="taxableAmount" id="taxableAmount" type="text" value="<?php echo $taxableAmount?>" style="width:150px;" onfocus="calculateTaxable()"/>			</td>
		    <td><span class="tabledata1">HardWare Amt</span></td>
		    <td><input type="text" name="hrdtotalAmt" id="hrdtotalAmt" style="width:150px;" value="<?php echo $hrdtotalAmt?>"  /></td>
			</tr>
		 
			<tr class="row1">
					<td class="tabledata1">Sales Tax (Taxable Amt) </td>
					<td>
					<select name="VatCst" id="value3" style="width:150px;" onchange="calculateVATCST(this.value)">
				<option value="" >Select</option>
				<?php 
				$salesSql=DB_query("Select * from sales_tax_master",$db);
				while($salesRow=DB_fetch_array($salesSql))
				{?>
				<option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
				<?php 	
				}
				?>
				</select>
				<div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:150px;" readonly  onfocus="calculateEditVATCST()" /></div>
				
			<?php $rate22=$s->getField('sales_tax_master','salestax_id',$VatCst,'taxrate');  ?>	
				<input type="hidden" name="" id="rate" value="<?php echo $rate22; ?>" /></td>
				    <td><span class="tabledata1">Sales Tax (H/w Amt) </span></td>
				    <td><select name="VatCst_hrd" id="value4" style="width:150px;" onchange="calculateVATCST_hrd(this.value)">
				<option value="" >Select</option>
				<?php 
				$salesSql1=DB_query("Select * from sales_tax_master",$db);
				while($salesRow1=DB_fetch_array($salesSql1))
				{?>
				<option value="<?php echo $salesRow1['salestax_id'];?>" <?php echo $VatCst1==$salesRow1['salestax_id']?'selected':''?>><?php echo $salesRow1['tax_code'];?></option>
				<?php 	
				}
				?>
				</select>
				<div id="VATId1"><input name="VatCstValu1e1" id="VatCstValue1" type="text" value="<?php echo $VatCstValue1?>" style="width:150px;" readonly  onfocus="calculateEditVATCST_hrd()" /></div>
					<?php $rate23=$s->getField('sales_tax_master','salestax_id',$VatCst1,'taxrate');  ?>	
				<input type="hidden" name="" id="rate1" value="<?php echo $rate23; ?>" /></td>
			</tr>
				
				<tr class="row1">
					<td class="tabledata1">Total Amt I </td>
					<td ><input type="text" name="total_taxable_amt" id="total_taxable_amt" style="width:150px;" onfocus="calculatetaxable_tax()"  value="<?php echo $sales_tax_taxabelamt; ?>" /></td>
					<td class="tabledata1">Total Amt II </td>
					<td ><input type="text" name="total_taxable_hrd" id="total_taxable_hrd" style="width:150px;" onfocus="calculatetaxable_hrd()"   value="<?php echo $sales_tax_hrdamt; ?>" /></td>
				</tr>
				
				<tr class="row1">
					<td class="tabledata1">Freight Amt </td>
					<td colspan="3"><input type="text" name="freight" id="freight" value="<?php echo $freight; ?>"  style="width:150px;" /></td>
				</tr>
				
				
		 <!--   	  <tr class="row1">
					<td class="tabledata1">Freight</td>
					<td><input name="freightValue" id="value2" type="text" value="<?php echo $freightValue?>" style="width:150px;" /></td>
					
				</tr>
				  <tr class="row1">
					<td class="tabledata1">Pkg Charges</td>
					<td><input name="packagingCharges" id="value1" type="text" value="<?php echo $packagingCharges;?>" style="width:150px;" /></td>
					
				</tr>
				<tr class="row1">
					<td class="tabledata1">Additional Charges</td>
					<td><input name="additionalCharges" id="value4" type="text" value="<?php  echo $additionalCharges;?>" style="width:150px;" /></td>
					
				</tr>
				  <tr class="row1">
					<td class="tabledata1">Round Off</td>
					<td><input name="roundOff" id="roundOff" type="text" value="<?php echo $roundOff;?>" readonly="true" style="width:150px;" /></td>
					
				</tr>-->
			<tr class="row1">
					<td class="tabledata1">Grand Total<label><font color="#FF0000">*</font></label></td>
					<td colspan="3"><input name="grandTotal" id="grandTotal" type="text"  style="width:150px;" onfocus="calculateGrand()" readonly="readonly" value="<?php echo $grandTotal  ;?>" /></td>
			  </tr>
			</table>
		</td>
	</tr>
</table>


<p align="center"><input type="submit" name="Save" value="Save" class="search"  /></p>

</form>
</div>
</div>
<script>
	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 calculatetaxable_tax()
{
var salestaxamt=document.getElementById("VatCstValue").value;
var taxableamt=document.getElementById("taxableAmount").value;
	if(salestaxamt==''){salestaxamt=0;}
	if(taxableamt==''){taxableamt=0;}
	
var totalamt=parseFloat(salestaxamt)+parseFloat(taxableamt);	
document.getElementById("total_taxable_amt").value=totalamt.toFixed(2);
}

function calculatetaxable_hrd()
{
var salestaxamt_hrd=document.getElementById("VatCstValue1").value;
var taxableamt_hrd=document.getElementById("hrdtotalAmt").value;
	if(salestaxamt_hrd==''){salestaxamt_hrd=0;}
	if(taxableamt_hrd==''){taxableamt_hrd=0;}
	
var totalamt=parseFloat(salestaxamt_hrd)+parseFloat(taxableamt_hrd);	
document.getElementById("total_taxable_hrd").value=totalamt.toFixed(2);

}

function calculateVATCST(str)
{
	if (str=='')
	{
	document.getElementById("rate").innerHTML="";
	return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("rate").value=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET","calculateExcise.php?salesId="+str,true);
	xmlhttp.send();
}


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

function calculateEditVATCST()
{
	//if(document.getElementById("hrdtotalAmt").value!='')
	//{
	//var hrdamt=parseFloat(document.getElementById("hrdtotalAmt").value);
	//}
	//else
	//{
		hrdamt=0;
	//}
	
	var rate=document.getElementById("rate").value;
	if(document.getElementById("taxableAmount").value!='')
	{
	var taxableAmount=parseFloat(document.getElementById("taxableAmount").value);
	}
	else
	{
		taxableAmount=0;
	}
	
	if(rate=='') { rate=0; }
	var fintotal=taxableAmount+hrdamt;
	var vat_cst=fintotal*(rate/100);
	document.getElementById("VatCstValue").value=vat_cst.toFixed(2);
}



function calculateEditVATCST_hrd()
{
	if(document.getElementById("hrdtotalAmt").value!='')
	{
	var hrdamt=parseFloat(document.getElementById("hrdtotalAmt").value);
	}
	else
	{
		hrdamt=0;
	}
	
	var rate=document.getElementById("rate1").value;
	
	if(rate=='') { rate=0; }
	
	var fintotal=hrdamt;
	var vat_cst=fintotal*(rate/100);
	document.getElementById("VatCstValue1").value=vat_cst.toFixed(2);
}



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

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

















	


	
























function showqty2(id)
{
var k=id.split("_");
var amt=document.getElementById("stockqty_"+k[1]).value;
if(amt=='') { amt=0; } 
var totalamt=document.getElementById("stock_value_"+k[1]).value;
if(totalamt=='') { totalamt=0; } 

var price=parseFloat(totalamt)/parseFloat(amt);
document.getElementById("stock_price_"+k[1]).value=price.toFixed(2);

}
function showqty4(id)
{
var k=id.split("_");
var amt=document.getElementById("secondary_"+k[1]).value;
if(amt=='') { amt=0; } 
var totalamt=document.getElementById("stock_value_"+k[1]).value;
if(totalamt=='') { totalamt=0; } 

var price=parseFloat(totalamt)/parseFloat(amt);
document.getElementById("stock_price_"+k[1]).value=price.toFixed(2);

}



function showrecordsdata(j)
{


    var data=calculateBasic_estimation();
   if(document.getElementById("addhrdAmt_"+j).checked==true)
   {
   document.getElementById("addhrditem_"+j).value=1;
   document.getElementById("addhrdAmt_"+j).value=1;
   }
   else
   {
   document.getElementById("addhrditem_"+j).value=0;
    document.getElementById("addhrdAmt_"+j).value=0;
   
   }
   
	        var size_array= new Array();
			//var item_array=new Array();
myCheckboxArray = document.frm1.elements["addhrdAmt[]"];
var t=myCheckboxArray.length;
if(t!=undefined)
{
	for(var i=0;i<=t+1;i++)
	{
	   if(document.getElementById("addhrdAmt_"+i))
	   {
		if(document.getElementById("addhrdAmt_"+i).checked==true)
		{
		size_array[i]=document.getElementById("hrdid_"+i).value;
		}
		}
	}
}	
else
{
 if(document.getElementById("addhrdAmt_"+j).checked==true)
		{
        size_array[0]=document.getElementById("hrdid_"+j).value;
        }
}	
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("ITEMSDETAILS").innerHTML=xmlhttp.responseText;
	//document.getElementById("HARDWAREDETAILS").innerHTML=data[2];
	
	}
	}
	var leadid=document.getElementById("leadid").value;
	xmlhttp.open("GET","crm_getEstimationrecord_hardware_remove1.php?estimationid="+size_array+"&estid="+leadid,true);
	xmlhttp.send();

}

function calculateBasic_estimation()
{
	var totalBasic_excise=0;
	var totalBasic2_nonexciseble=0;
	
	var fincount=document.getElementById("hrdcount1").value;
	for(var i=0;i<fincount;i++)
	{	
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{
	if(document.getElementById("itemtype_"+i).value=='Y')
	{  
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{	
	var totalBasic1=document.getElementById("hrdvalue_dis1_"+i).value;
	}
	else
	{
	var totalBasic1=0;
	}
	var totalBasic_excise=parseFloat(totalBasic_excise)+parseFloat(totalBasic1);
	}
	else
	{
	if(document.getElementById("addhrdAmt_"+i).checked==true)
	{
	if(document.getElementById("hrdvalue_dis1_"+i).value!='')
	{	
	var totalBasic2=document.getElementById("hrdvalue_dis1_"+i).value;
	}
	else
	{
	var totalBasic2=0;
	}
	
	var totalBasic2_nonexciseble=parseFloat(totalBasic2_nonexciseble)+parseFloat(totalBasic2);
	}
	}
	}
	}
	
	//var totalBasic3=parseFloat(totalBasic)+parseFloat(totalBasic4);	
	
	document.getElementById("basicAmount").value=totalBasic_excise;
	document.getElementById("hrdtotalAmt").value=totalBasic2_nonexciseble;
}

function DiscountAmount2(DA,i)
{
	var discount_percent = document.getElementById("hrdPerAmo1_"+i).value;
	var discount = document.getElementById("hrdDiscount1_"+i).value;
	var total = document.getElementById("hrdstock_value1_"+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
	{
	 percent = parseFloat(DA);
	 }
	var subTotal = parseFloat(total)-percent;
	
	}	
	var data=calculateBasic_estimation();
	
	document.getElementById("hrdperc1_"+i).value=percent.toFixed(2);
	document.getElementById("hrdvalue_dis1_"+i).value=subTotal.toFixed(2);
	
	
}

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 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);
	}
}

function get_mobilenumber(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
	xmlhttp.onreadystatechange=function()
  	{
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
	
			document.getElementById("partyContact2").value=xmlhttp.responseText;			
		}
	}
	//var order=document.getElementById("order_id").value;
	xmlhttp.open("POST","getPhone.php?Contact="+str,true);
	xmlhttp.send();
}
</script>