<?php 
$PageSecurity = 11;
include('includes/session.inc');
include('includes/function_lib.php');
$data1="";
$data2="";
$SQLCom=DB_query("SELECT *FROM comprative where id='".$_REQUEST['parentid']."' ",$db);
$Comparative=DB_fetch_array($SQLCom);
extract($Comparative);
if($_REQUEST['OrderType']=='DO'){


$data1.="<table border='1' cellpadding='3' cellspacing='0' width='100%' style='border:1px #333333 solid;'>";
				$data1.="<tr bgcolor='#d4d4d4'>";
					$data1.="<td class='tabledata'>SrNo.</td>";
					$data1.="<td class='tabledata'>Item Name</td>";
					$data1.="<td class='tabledata'>UOM</td>";
					$data1.="<td class='tabledata'>Qty</td>";
					$data1.="<td class='tabledata'>Quoted Rate </td>";
					$data1.="<td class='tabledata'>Total Price</td>";
					$data1.="<td class='tabledata'>Discount Type</td>";
					$data1.="<td class='tabledata'>Discount Amt</td>";
					$data1.="<td class='tabledata'>Discounted Amount</td>";
					$data1.="<td class='tabledata'>Sub Total</td>";
					$data1.=" <td class='tabledata'>Basic Amount</td>";				 
					$data1.="<td class='tabledata'>Excise flag</td>";
					$data1.="<td class='tabledata'>Excise</td>";
					$data1.="<td class='tabledata'>E-Cess</td>";
					$data1.="<td class='tabledata'>SAH-E Cess</td>";
					$data1.="<td class='tabledata'>Excise<br />Amt.</td>";
					$data1.="<td class='tabledata'>Total<br /> Amt.</td>";
					$data1.="</tr>";
 $i=0; 
$SQLPoA=DB_query("SELECT * FROM comprative_detail where sppliersId='".$_REQUEST['supplierid']."' AND parant_id='".$_REQUEST['parentid']."'",$db);
while($InPrDetails=DB_fetch_array($SQLPoA)){ 
$ItemName=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'item_name');
$ItemCode=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'StockID');
$UnitId=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'mst_unitid');
$UnitName=$s->GetFieldValue('unitsofmeasure',"unitid='".$UnitId."'",'unitname');

$SQLQuotation=DB_query("select * from vendorquotationdetails where id='".$InPrDetails['quotation_details_id']."'",$db);
$QuotaionDetails=DB_fetch_array($SQLQuotation);

$totalPrice=$InPrDetails['assign_qty']*$QuotaionDetails['Rate'];
if($QuotaionDetails['DiscountType']=='Amount')
{
	$discountedAmt=$QuotaionDetails['Discount'];
	
}
else if($QuotaionDetails['DiscountType']=='PercentAmt')
{
	$discountedAmt=($totalPrice*$QuotaionDetails['Discount'])/100;
}


$subtotal=$totalPrice-$discountedAmt;


if($QuotaionDetails['SpecialDicount_Type']=='Amount')
{
	$SpecialdiscountedAmt=$QuotaionDetails['SpecialDiscount'];
	
}
else if($QuotaionDetails['SpecialDicount_Type']=='PercentAmt')
{
	$SpecialdiscountedAmt=($subtotal*$QuotaionDetails['SpecialDiscount'])/100;
}

$basicAMt=$subtotal-$SpecialdiscountedAmt;


if($QuotaionDetails['Excise_type']=='Excisable')
{
	$Excise=$QuotaionDetails['Excise_Duty'];
	$Exicename=$s->GetFieldValue('excise_tax',"id='".$Excise."'",'caption');
	$ExcisePerc=$s->GetFieldValue('excise_tax',"id='".$Excise."'",'def_rate');
	//$ExcisePerc=$QuotaionDetails['ExcisePercentage'];
	$ExciseVal=$QuotaionDetails['ExciseValue'];
	
	
	$Cess_ID=$QuotaionDetails['Cess_ID'];
	$CessName=$s->GetFieldValue('excise_tax',"id='".$Cess_ID."'",'caption');
	$CessPerc=$s->GetFieldValue('excise_tax',"id='".$Cess_ID."'",'def_rate');
	//$CessPerc=$QuotaionDetails['ECessPercentage'];
	$CessValue=$QuotaionDetails['ECessValue'];
	
	$SHECess_ID=$QuotaionDetails['SHECess_ID'];
	$SHECessName=$s->GetFieldValue('excise_tax',"id='".$SHECess_ID."'",'caption');
	//$SHECessPerc=$QuotaionDetails['SAHCessPercentage'];
	$SHECessPerc=$s->GetFieldValue('excise_tax',"id='".$SHECess_ID."'",'def_rate');
	$SHECessValue=$QuotaionDetails['SAHCessValue'];
	
	$TaxableAmt=$ExciseVal+$CessValue+$SHECessValue;
}
else if($QuotaionDetails['Excise_type']=='NonExcisable' || $QuotaionDetails['Excise_type']=='IncludeTax')
{
	$Excise=0;
	$Exicename=0;
	$ExcisePerc=0;
	$ExciseVal=0;
	
	
	$Cess_ID=0;
	$CessName=0;
	$CessPerc=0;
	$CessValue=0;
	
	$SHECess_ID=0;
	$SHECessName=0;
	$SHECessPerc=0;
	$SHECessValue=0;
	
	$TaxableAmt=0;
}




$TotalAmout=$basicAMt+$TaxableAmt;


$data1.="<tr class='rowdata'>";
$data1.="<td>".($i+1)."</td>";
$data1.="<td>".$ItemName."<input type='hidden' name='mst_itemid[]'  value='".$InPrDetails['mst_itemid']."'></td>";
$data1.="<td>".$UnitName."</td>";
$data1.="<td>".$InPrDetails['assign_qty']."<input type='hidden' name='Quantity[]'  value='".$InPrDetails['assign_qty']."'/></td>";
$data1.="<td>".$QuotaionDetails['Rate']."<input   type='hidden' name='Rate[]' value='".$QuotaionDetails['Rate']."'  /></td>";
$data1.="<td>".$totalPrice."<input  type='hidden' name='totalPrice[]'  value='".$totalPrice."'/></td>";
$data1.="<td>".$QuotaionDetails['DiscountType']."<input type='hidden'  name='DiscountType[]' value='".$QuotaionDetails['DiscountType']."'></td>";
$data1.="<td>".$QuotaionDetails['Discount']."<input type='hidden' style='width:70px' name='Discount[]' value='".$QuotaionDetails['Discount']."' /></td>";
$data1.="<td>".$discountedAmt."<input type='hidden' name='discounted_amount[]' value='".$discountedAmt."' /></td>";
$data1.="<td>".$subtotal."<input type='hidden' name='NetRate[]' value='".$subtotal."'  /></td>";
$data1.="<td>".$basicAMt."<input type='hidden' name='basic_Amt[]' value='".$basicAMt."' /></td>";
$data1.="<td>".$QuotaionDetails['Excise_type']."<input type='hidden' name='Excise_type[]' value='".$QuotaionDetails['Excise_type']."' /></td>";
$data1.="<td>".$Exicename.'<br>'.$ExcisePerc.'<br>'.$ExciseVal."<input type='hidden' name='Excise_Duty[]' value='".$Excise."'>
<input name='ExcisePercentage[]' type='hidden' value='".$ExcisePerc."'  />
<input name='exciseValue[]' type='hidden'  value='".$ExciseVal."' /></td>";
$data1.="<td>".$CessName.'<br>'.$CessPerc.'<br>'.$CessValue."<input type='hidden' name='Cess_ID[]' value='".$Cess_ID."' >
<input name='ECessPercentage[]'  type='hidden' value=".$CessPerc."   />
<input name='ECessValue[]'  type='hidden' value=".$CessValue." /></td>";
$data1.="<td>".$SHECessName.'<br>'.$SHECessPerc.'<br>'.$SHECessValue."<input type='hidden' name='SHECess_ID[]' value='".$SHECess_ID."' >
<input name='SAHCessPercentage[]' type='hidden' value='".$SHECessPerc."'  />
<input name='SAHCessValue[]' type='hidden' value='".$SHECessValue."'/></td>";
$data1.="<td>".$TaxableAmt."<input type='hidden' name='taxable_amt[]' value='".$TaxableAmt."'/></td>";
$data1.="<td>".$TotalAmout."<input type='hidden'  name='TotalAmount[]' id='total_amt_".$i."' value='".$TotalAmout."'/></td>";
$data1.="</tr>";
 $i++;
 }

$data1.="<input type='hidden' name='count' id='count' value='".$i."' style='width:70px' /></table>";
				
			$pkg_charges=($totalamount*$pkg_per)/100;	
				
				
		$data2.="<table width='81%' border='0' cellspacing='0' cellpadding='3'>";
		$data2.="<tr class='row1'>";
		$data2.="<td width='49%' class='tabledata1'><strong>TOTAL AMOUNT</strong> </td>";
		$data2.="<td width='51%'><input type='text' name='total_amount' id='total_item_amount' onfocus='caltotalAmt()' readonly='' style='width:150px;'/></td>";
		$data2.="</tr>";
		$data2.="<tr class='row1'>";
		$pkg_charges=($totalamount*$pkg_per)/100; 	
		$data2.="<td class='tabledata1'><strong>Pkg Charges</strong> </td>";
		$data2.="<td><input type='text' name='pkg_per' id='pkg_per' value='".$pkg_per."' style='width:75px;' />";
		$data2.="<input name='pkg_charges' id='packagingCharges' type='text' onfocus='calcPackaging()' style='width:75px;' readonly=''/></td>";
		$data2.="</tr>";
		$data2.="<tr class='row1'>";
		$data2.="<td class='tabledata1'><strong>Vat(description)</strong></td>";		
		$data2.="<td><select name='vatcst' id='vatcst' style='width:100%' onchange='tax_rate1(this.value)'>
		<option value='0'>Select</option>";
		$vat_sql=DB_query("select * from  sales_tax_master",$db);
		while($vat_row=DB_fetch_array($vat_sql))
		{	
		$p='';
		if($vatcst==$vat_row['salestax_id'])	
		{
		$p="selected";
		}
		
		$data2.="<option value=".$vat_row['salestax_id']."".$p.">".$vat_row['tax_code']."</option>";
		 } 	
		$data2.="</select>
		<input type='hidden' name='vat_cst_per' id='vat_cst_per' value=".$val2." />
		<input type='hidden' name='' id='' value=".$val1." style='width:150px;'/></td></tr>";
		$data2.="<tr class='row1'>";
		$data2.="<td class='tabledata1'><strong>Vat/Cst Amount</strong></td>";
		$data2.="<td><div id='taxval'><input type='text' name='vatcstvalue' id='vatcstvalue' value='' style='width:150px;' onfocus='calvatcst();'/></div> </td>	
		</tr>";	
		$data2.="<tr class='row1'>
          <td class='tabledata1'><strong>Surcharge Amount</strong> </td>";
                  $data2.="<td><input type='text' name='surcharge_per' id='sur_oct_per' style='width:50px;' value='".$surcharge_per."' />
				  <input name='surcharge_amt' onfocus='calsurchrg()' type='text' id='sur_oct_amt' style='width:100px;' /></td></tr>";
       $data2.="<tr class='row1'>
              <td class='tabledata1'><strong>Freight</strong> </td>";
                  $data2.="<td><input type='text' name='Freight' id='TotalCharge' value='".$Freight."' style='width:150px;'/></td>
       </tr>";
       $data2.="<tr class='row1'>
            <td class='tabledata1'><strong>Additional Charges</strong> </td>";
             $data2.="<td><input name='add_charges' id='additionalCharges' value='".$add_charges."' type='text' style='width:150px;' /></td>
      </tr>";
		  $grand_total=$totalamount+$sur_oct_amt+$totalcharge+$pkg_charges+$add_charges+$vat_cst_amount; 
		$data2.="<tr class='row1'>
		<td class='tabledata1'><strong>GrandTotal</strong></td>";
		$data2.="<td><input type='text' name='GrandTotal' id='GrandTotal' onfocus='calgrandTotal()' style='width:150px;' readonly='' /></td>
		</tr></table>";
}

//**********************************************************************************************************************

if($_REQUEST['OrderType']=='IO'){
	$data1.="<table width='100%' cellpadding='3' cellspacing='0' border='1' style='border:#333333 1px solid;'>";
		$data1.="<tr bgcolor='#d4d4d4'>";
			$data1.="<td class='tabledata'>Sr. No.</td>";
			$data1.="<td class='tabledata'>&nbsp;</td>";
			$data1.="<td class='tabledata'>Part Code</td>";
			$data1.="<td class='tabledata'>Part Name</td>";
			$data1.="<td class='tabledata'>Qty</td>";
			$data1.="<td class='tabledata'>Rate</td>";
			$data1.="<td class='tabledata'>Currency</td>";
			$data1.="<td class='tabledata'>Total Price</td>";
			$data1.="<td class='tabledata'>Discount Type</td>";
			$data1.="<td class='tabledata'>Discount Amt</td>";
			$data1.="<td class='tabledata'>Discounted Amount</td>";
			$data1.="<td class='tabledata'>Sub Total</td>";
			$data1.="<td class='tabledata'>Basic Amount</td>";
			$data1.="<td class='tabledata'>Total<br /> Amt.</td>";
		$data1.="</tr>"; 
		$i=0;
		$SQLPoA=DB_query("SELECT * FROM comprative_detail where sppliersId='".$_REQUEST['supplierid']."' AND parant_id='".$_REQUEST['parentid']."'",$db);
while($InPrDetails=DB_fetch_array($SQLPoA)){ 
$ItemName=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'item_name');
$ItemCode=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'StockID');
$UnitId=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'mst_unitid');
$UnitName=$s->GetFieldValue('unitsofmeasure',"unitid='".$UnitId."'",'unitname');
	$SQLQuotation=DB_query("select * from vendorquotationdetails where id='".$InPrDetails['quotation_details_id']."'",$db);
$QuotaionDetails=DB_fetch_array($SQLQuotation);

$totalPrice=$InPrDetails['assign_qty']*$QuotaionDetails['Rate'];
if($QuotaionDetails['DiscountType']=='Amount')
{
	$discountedAmt=$QuotaionDetails['Discount'];
	
}
else if($QuotaionDetails['DiscountType']=='PercentAmt')
{
	$discountedAmt=($totalPrice*$QuotaionDetails['Discount'])/100;
}

$subtotal=$totalPrice-$discountedAmt;
$basicAMt=$subtotal-$SpecialdiscountedAmt;

$TotalAmout=$basicAMt+$TaxableAmt;
		
				$data1.="<tr bgcolor='#c1c1c1'>";
					$data1.="<td>".($i+1)."</td>";
					$data1.="<td><input type='hidden' name='mst_itemid[]'  value='".$InPrDetails['mst_itemid']."'></td>";
					$data1.="<td>".$ItemCode."</td>";
					$data1.="<td>".$ItemName."</td>";
$data1.="<td>".$InPrDetails['assign_qty']."<input style='width:100%;'  type='hidden' name='Quantity[]' id='Quantity' value='".$InPrDetails['assign_qty']."' /></td>";
$data1.="<td>".$QuotaionDetails['Rate']."<input style='width:100%;'  type='hidden' name='Rate[]' id='Rate' onKeyUp='calculateTotalPrice(this.id)' 
					value='".$QuotaionDetails['Rate']."'  /></td>";
					$data1.="<td><select name='currency[]' id='currency' style='width:100%;' >"; 
					         $sql_currency=DB_query("select * from currency_master where id='".$InPrDetails['currency']."'",$db);
							while($row_currency=DB_fetch_array($sql_currency))
	                       {	
	$data1.="<option value='".$row_currency['id']."'>".$row_currency['abbreviation']."</option>";
	}
							 $data1.="</select></td>";
		$data1.="<td>".$totalPrice."<input style='width:100%;' type='hidden' name='totalPrice[]' id='totalValue' readonly='true' value='".$totalPrice."' /></td>";
					$data1.="<td>".$QuotaionDetails['DiscountType']."<input type='hidden'  name='DiscountType[]' value='".$QuotaionDetails['DiscountType']."'></td>";
$data1.="<td>".$QuotaionDetails['Discount']."<input type='hidden' style='width:70px' name='Discount[]' value='".$QuotaionDetails['Discount']."' /></td>";
$data1.="<td>".$discountedAmt."<input type='hidden' name='discounted_amount[]' value='".$discountedAmt."' /></td>";
$data1.="<td>".$subtotal."<input type='hidden' name='NetRate[]' value='".$subtotal."'  /></td>";
$data1.="<td>".$basicAMt."<input type='hidden' name='basic_Amt[]' value='".$basicAMt."' /></td>";
							$data1.="<td>".$TotalAmout."<input type='hidden'  name='TotalAmount[]' id='total_amt_".$i."' value='".$TotalAmout."'/></td>";
		$data1.="</tr>"; 
	$i++;	}
		
		$data1.="</table>";
		
		$data1.="<input type='hidden' name='count' id='conterimp' value='".$i."' style='width:70px' /></table>";

		
		
		
	$data2.="<table width='100%' border='0' cellspacing='0' cellpadding='3'>";
	$data2.="<tr class='row1'>";
	$data2.="<td class='tabledata1'><strong>Basic Amount</strong></td>";
	$data2.="<td><input name='total_amount' id='total_item_amount' style='width:100%;' readonly onfocus='cal_totalamount()'></td>";
	$data2.="</tr>";	
	$data2.="<tr class='row1'>";
	$data2.="<td class='tabledata1'><strong>Insurance charges</strong></td>";
	$data2.="<td><input type='text' name='insurancecharges' id='insurancecharges' style='width:100%;'   onblur='calsuroctamtipm(this.value)'/>
	<input name='insurancecharges_amt' type='text'  onkeyup='reversecalsuroctamt(this.value);' id='insurancecharges_amt' value='' style='width:100px;' /></td>";
	$data2.="</tr>";
	$data2.="<tr class='row1'>";
	$data2.="<td class='tabledata1'><strong>Overseas Freight</strong></td>";
	$data2.="<td><input type='text' name='overseasfrieght' id='overseasfrieght'  style='width:100%;' onBlur='caloverfreight(this.value)'/>
	<input name='overseasfrieght_amt' type='text' onkeyup='reversecaloverfreight(this.value);' id='overseasfrieght_amt' value='' style='width:100px;' /></td>";
	$data2.="</tr>";
	$data2.="<tr class='row1'>";
	$data2.="<td class='tabledata1'><strong>Local Freight</strong></td>";
	$data2.="<td><input type='text' name='localfreight' id='localfreight'  style='width:100%;' onBlur='callocalfreight(this.value)'/>
	<input name='localfreight_amt' type='text'  onkeyup='reversecallocalfreight(this.value);'  id='localfreight_amt' style='width:100px;' /></td>";
	$data2.="</tr>";
	$data2.="<tr class='row1'>";
	$data2.="<td class='tabledata1'><strong>Clearing & Forwarding</strong> </td>";
	$data2.="<td><input type='text' name='clearingforwarding' id='clearingforwarding'  style='width:100%;' onBlur='calclearingforwarding(this.value)'/>
	<input name='calclearingforwarding_amt' type='text' onkeyup='reversecalclearingforwarding(this.value);' id='calclearingforwarding_amt' style='width:100px;' /></td>";
	$data2.="</tr>";
	
	$data2.="<tr class='row1'>";
	$data2.="<td class='tabledata1'><strong>Detetion Charges</strong> </td>";
	$data2.="<td><input type='text' name='detetioncharges' id='detetioncharges'  style='width:100%;' onBlur='caldetetioncharges(this.value)'/>
	<input name='detetioncharges_amt' type='text' onkeyup='reversecaldetetioncharges(this.value);' id='detetioncharges_amt'style='width:100px;' /></td>";
	$data2.="</tr>";
	$data2.="<tr class='row1'>";
	$data2.="<td class='tabledata1'><strong>Other charges</strong></td>";
	$data2.="<td><input type='text' name='othercharges' id='othercharges'  style='width:150px;margin-left:18px;'/></td>";
	$data2.="</tr>";		
	
	$data2.="<tr class='row1'>";
	$data2.="<td class='tabledata1'><strong>Grand Total</strong></td>";
	$data2.="<td><input type='text' name='GrandTotal' id='GrandTotal' onFocus='cal_grandamountimp()'  style='width:100%;'/></td>";
	$data2.="</tr>";
	$data2.="</table>";
}
echo $data=$data1."__".$data2;



