<?php 
$SQLCom=DB_query("SELECT *FROM comprative where id='".$_REQUEST['CPID']."'",$db);
$Comparative=DB_fetch_array($SQLCom);
extract($Comparative);
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Purchase Order Approval</h1>	
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td class="tabledata1">Comparative No</td>
	<td><?php echo $comparative_no; ?></td>
	<td class="tabledata1">Comparative Date</td>
	<td><?php echo ConvertSQLDate($comparative_date); ?></td>
</tr>
<tr class="row1">
	<td class="tabledata1">Indent/PR No</td>
	<td><?php echo $s->GetFieldValue('materialrequisitions',"requisitionno='".$indentprno."'",'Reqno'); ?></td>
	<td class="tabledata1">Indent/PR Date</td>
	<td><?php echo ConvertSQLDate($s->GetFieldValue('materialrequisitions',"requisitionno='".$indentprno."'",'prdate')); ?></td>
</tr>
<tr class="row1">
	<td class="tabledata1" colspan="4"><h3>Items Details</h3></td>
</tr>
<tr class="row1">
	<td class="tabledata1" colspan="4">
		<div style="width:947px; overflow:auto;">
			<table width="100%" cellpadding="3" cellspacing="0" border="1">
				<tr class="row1">
					<td class="tabledata">SrNo.</td>
					<td class="tabledata">Item Name</td>
					<td class="tabledata">UOM</td>
					<td class="tabledata">Qty</td>
					<td class="tabledata">Quoted Rate </td>
					<td class="tabledata">Total Price</td>
					<td class="tabledata">Discount Type</td>
					<td class="tabledata">Discount Amt</td>
					<td class="tabledata">Discounted Amount</td>
					<td class="tabledata">Sub Total</td>
					<td class="tabledata">Special Discount Type</td>
					<td class="tabledata">Special Discount Amt</td>
					<td class="tabledata">Special Discounted Amt</td>
					<td class="tabledata">Basic Amount</td>
					<td class="tabledata">Excise flag</td>
					<td class="tabledata">Excise</td>
					<td class="tabledata">E-Cess</td>
					<td class="tabledata">SAH-E Cess</td>
					<td class="tabledata">Excise<br />Amt.</td>
					<td class="tabledata">Total<br /> Amt.</td>
				</tr>
<?php $i=0; 
$SQLPoA=DB_query("SELECT * FROM comprative_detail where sppliersId='".$_REQUEST['SupplierId']."' AND parant_id='".$_REQUEST['CPID']."'",$db);
while($InPrDetails=DB_fetch_array($SQLPoA)){ 
$ItemName=$s->GetFieldValue('item_master',"id='".$InPrDetails['mst_itemid']."'",'item_name');
$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;



?>
<tr class="row1">
<td><?php echo $i+1; ?></td>
<td><?php echo $ItemName; ?><input type="hidden" name="mst_itemid[<?php echo $i;?>]"  value="<?php echo $InPrDetails['mst_itemid'];?>"></td>
<td><?php echo $UnitName; ?></td>
<td><?php echo $InPrDetails['assign_qty'];?>
<input type="hidden" name="Quantity[<?php echo $i;?>]"  value="<?php echo $InPrDetails['assign_qty'];?>"
/></td>
<td><?php echo $QuotaionDetails['Rate']; ?>
<input   type="hidden" name="Rate[<?php echo $i;?>]"  /></td>
<td>
<?php echo  $totalPrice;?>
<input  type="hidden" name="totalPrice[<?php echo $i;?>]"  value="<?php echo $totalPrice; ?>"/></td>
<td>
<?php  echo $QuotaionDetails['DiscountType']; ?>
<input type="hidden"  name="DiscountType[<?php echo $i;?>]" value="<?php echo $QuotaionDetails['DiscountType'];?>">

</td>
<td><?php echo $QuotaionDetails['Discount']; ?>
<input type="hidden" style="width:70px" name="Discount[<?php echo $i;?>]" value="<?php echo $QuotaionDetails['Discount']; ?>" /></td>
<td><?php echo $discountedAmt; ?>
<input type="hidden" name="discounted_amount[<?php echo $i;?>]" value="<?php echo $discountedAmt; ?>" /></td>
<td><?php echo $subtotal; ?>
<input type="hidden" name="NetRate[<?php echo $i;?>]" value="<?php echo $subtotal; ?>"  /></td>
<td><?php echo $QuotaionDetails['SpecialDicount_Type']; ?>
<input type="hidden"  name="SpecialDicount_Type[<?php echo $i; ?>]" value="<?php echo $QuotaionDetails['SpecialDicount_Type']; ?>" />
</td>
<td><?php echo $QuotaionDetails['SpecialDiscount']; ?>
<input type="hidden" name="SpecialDiscount[<?php echo $i; ?>]" value="<?php echo $QuotaionDetails['SpecialDiscount']; ?>" /></td>
<td><?php echo $SpecialdiscountedAmt; ?>
<input type="hidden" name="SpecialDiscounted_Amt[<?php echo $i; ?>]" value="<?php echo $SpecialdiscountedAmt; ?>"/></td>
<td><?php echo $basicAMt; ?>
<input type="hidden" name="basic_Amt[<?php echo $i; ?>]" value="<?php echo $basicAMt; ?>" /></td>
<td><?php echo $QuotaionDetails['Excise_type']; ?>
<input type="hidden" name="Excise_type[<?php echo $i;?>]" />
</td>
<td><select name="Excise_Duty[<?php echo $i; ?>]" id="exciseDuty_<?php echo $i; ?>" style="width:100px;" onchange="claculateExcise(<?php echo $i; ?>,this.value)" onfocus="checkexiseflag(<?php echo $i; ?>)">
<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))
{
$g='';
if($Excise_Duty==$excise_row['id'])
{$g='selected';}	?>
 <option value="<?php echo $excise_row['id']; ?>"><?php echo $excise_row['caption']; ?></option>
<?php }?>

</select>
<div id="exciseId_<?php echo $i; ?>" style="width: 100px;">
<input name="ExcisePercentage[<?php echo $i; ?>]" id="ExcisePercentage_<?php echo $i; ?>" type="text" style="width:100px;"  />
<input name="exciseValue[<?php echo $i; ?>]" id="exciseValue_<?php echo $i; ?>" type="text" style="width:100px;" 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++;
} 	

$cessLedgerSql1=DB_query("Select * from excise_tax where ledgertype='cess' LIMIT 0,1",$db);	 
$cessLedgerSql2=DB_query("Select * from excise_tax where ledgertype='cess' LIMIT 1,1",$db);	 	 

?>
<td><select name="Cess_ID[<?php echo $i; ?>]" id="cess_ID1_<?php echo $i; ?>" >
<?php while($cessLedger1=DB_fetch_array($cessLedgerSql1)){?>
<option value="<?php echo $cessLedger1['id'];?>"><?php echo $cessLedger1['caption'];?></option>
<?php }?>
</select>
<input name="ECessPercentage[<?php echo $i; ?>]" id="ECessPercentage_<?php echo $i; ?>" type="text" value="<?php echo $rate[1]; ?>"   />
<input name="ECessValue[<?php echo $i; ?>]" id="ECessValue_<?php echo $i; ?>" type="text"   onfocus="calculateECess(<?php echo $i; ?>)"/></td>
<td><select name="SHECess_ID[<?php echo $i; ?>]" id="cess_ID2_<?php echo $i; ?>" >
<?php while($cessLedger2=DB_fetch_array($cessLedgerSql2)){?>
<option value="<?php echo $cessLedger2['id'];?>"><?php echo $cessLedger2['caption'];?></option>
<?php }?>
</select>
<input name="SAHCessPercentage[<?php echo $i; ?>]"  />
<input name="SAHCessValue[<?php echo $i; ?>]"/></td>
<td><input type="text" name="taxable_amt[<?php echo $i; ?>]"/></td>
<td><input type="text"  name="TotalAmount[<?php echo $i;?>]"/></td>
</tr>
<?php $i++;}?>

<input type="hidden" name="count" id="count" value="<?php echo $i;?>" style="width:70px" /> 
			</table>
		</div>
	</td>
</tr>


<tr class="row1">
<td class="tabledata1" colspan="4">
	<table border="0" width="100%" cellpadding="3" cellspacing="0">
	<tr class="row1">
		<td width="50%">
		<table width="100%" border="0"  cellpadding="3" cellspacing="0">
		<tr class="row1">
		<td class="tabledata1" rowspan="2">Delivery Place</td><td>
		<input type="text" name="delivery_place1" id="delivery_place1" value="<?php echo $branch_data['deladd1'];?>" style="width:100%" />
		</td>
		</tr>
		<tr class="row1">
		<td id="divdata" style="display: none;"></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Mode Of Transport</td>
		<td>
		<select name="mode_of_transport" id="mode_of_transport" style="width:100%">
		<option value="By Road" <?php if($mode_of_transport=='By Road') echo "selected";?>>By Road</option>
		<option value="By Air" <?php if($mode_of_transport=='By Air') echo "selected";?>>By Air</option>
		<option value="By Sea" <?php if($mode_of_transport=='By Sea') echo "selected";?>>By Sea</option>
		</select></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Freight</td>
		<td><input type="text" name="freight_details" id="freight_details" value="<?php echo $freight_details;?>" style="width:100%"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Transit Insurance</td>
		<td><input type="text" name="transit_insurance" id="transit_insurance" value="<?php echo $transit_insurance;?>" style="width:100%"/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Delivery Date</td>
		<td><input type="text" name="delivery_date" id="delivery_date" value="<?php echo ConvertSQLDate($delivery_date);?>" style="width:100%" class="datepicker"  onchange="checkvalidate()"   /></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1">Delivery Time</td>
		<td>
		<select name="delivery_time" id="delivery_time" style="width:100%">
		<option value="">Select Delivery Time</option>	
		<option value="9 am to 9 pm">9 am to 9 pm</option>
		<option value="9 pm to 9am">9 pm to 9am</option>
		<option value="Any time">Any time</option>
		
		</select>	
		</td></tr>
		<tr class="row1">
		<td class="tabledata1">Contact Person</td>
		<td><input type="text" name="contact_person" id="contact_person" value="<?php echo $contact_person;?>" style="width:100%"/></td></tr>
		<tr class="row1">
		<td class="tabledata1">Valid Till</td>
		<td><input type="text"  class="datepicker" name="valid_till" id="valid_till" value="<?php echo ConvertSQLDate($valid_till);?>" style="width:100%"  onchange="checktilldate()"   /></td></tr>
		</table>
		</td>
		<td width="50%">
		<table width="100%" border="0" cellspacing="0" cellpadding="3">
		<tr class="row1">
		<td class="tabledata1"><strong>TOTAL AMOUNT</strong> </td>
		<td><input type="text" name="total_item_amount" id="total_item_amount" value="<?php echo round($totalamount,2);?>" style="width:100%;" onfocus="cal_totalamount()" readonly=""/></td>
		</tr>
		<tr class="row1">
		<?php $pkg_charges=($totalamount*$pkg_per)/100; ?>	
		<td class="tabledata1"><strong>Pkg Charges</strong> </td>
		<td><input type="text"name="pkg_per" value="<?php echo $pkg_per; ?>" />
		<input name="pkg_charges" id="packagingCharges" type="text" value="<?php echo round($pkg_charges,2); ?>" size="25" style="width:100%;" readonly=""/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1"><strong>Vat(description)</strong></td>		
		<td>
		<?php $val1=$s->getField('sales_tax_master','salestax_id',$vat_cst_per,'tax_code');
		$val2= $s->getField('sales_tax_master','salestax_id',$vat_cst_per,'taxrate');
		$dataval= $val1 ."---".$val2."%"; ?>	
		<input type="text" name="vatcst_code" value="<?php echo $dataval; ?>" style="width:100%;" />
		<input type="hidden" name="vat_cst_per" value="<?php echo $vat_cst_per; ?>" />
		</td>
		</tr>
		<tr class="row1">
		<?php
		$vat_cst_amount=(($totalamount+$pkg_charges)*$val2)/100;
		
		?>
		<td class="tabledata1"><strong>Vat/Cst Amount</strong></td>
		<td><input type="text" name="vat_cst_amount" value="<?php echo $vat_cst_amount; ?>" style="width:100%;"> </td>	
		</tr>	
		<tr class="row1">
		<td class="tabledata1"><strong>Surcharge Amount</strong> </td>
		<td><input type="hidden" name="sur_oct_per" value="<?php echo $sur_oct_perc; ?>" />
		<?php
		
		$sur_oct_amt=($vat_cst_amount*$sur_oct_perc)/100;
		
		?>
		<input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo round($sur_oct_amt,2); ?>" style="width:100%;" readonly=""/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1"><strong>Freight</strong> </td>
		<td><input type="text" name="TotalCharge" id="TotalCharge" value="<?php echo round($totalcharge,2); ?>" style="width:100%;" readonly=""/></td>
		</tr>
		<tr class="row1">
		<td class="tabledata1"><strong>Additional Charges</strong> </td>
		<td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo round($add_charges,2); ?>" size="25" style="width:100%;" readonly=""/></td>
		</tr>	
		<?php  $grand_total=$totalamount+$sur_oct_amt+$totalcharge+$pkg_charges+$add_charges+$vat_cst_amount; ?> 			
		<tr class="row1">
		<td class="tabledata1"><strong>GrandTotal</strong></td>
		<td><input type="text" name="GrandTotal" id="GrandTotal" value="<?php  echo round($grand_total,2); ?>" style="width:100%;" readonly="" /></td>
		</tr>
		</table>
		</td>
	</tr>
	</table>
</td>
</tr>

<tr class="row1">
<td class="tabledata1"><strong>Remarks</strong> </td>
<td colspan="3"><textarea  name="remarks" id="remarks" style="width:100%;" ></textarea></td>
</tr>

<tr class="row1">
<td colspan="4"  style="text-align:center;" class="tabledata1"><input name="Order" type="submit" value="Process Order" class="search"  onclick="return validate();"/></td>
</tr>
</table>
 </form>
 </div>
 </div>
 
<script language="JavaScript">
	
function checkvalidate()
{
	
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);
var del=document.getElementById("delivery_date").value;	
if(del<datedat)
{
alert("Delivery  Date Not less then current  Date");
//document.getElementById("delivery_date").value='';
document.getElementById("delivery_date").focus;	
return false;	
}


}
function checktilldate()
{
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}	
var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);
var del1=document.getElementById("valid_till").value;	
if(del1<datedat)
{
alert("Valid Till Date Not less then current  Date");
//document.getElementById("valid_till").value='';
document.getElementById("valid_till").focus;	
return false;	
}	
	
	
}	
	
	
	
	
function validate()
{
var curr_date2='';	
var curr_month2='';
var d = new Date();
//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();
var curr_month1 = d.getMonth();
var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);

if(document.getElementById("delivery_place1").value=='')
{
alert("Must Enter Delivery Place");
document.getElementById("delivery_place1").focus();
return false;	
}
if(document.getElementById("delivery_date").value=='')
{
alert("Must Enter Delivery Date");
document.getElementById("delivery_date").focus();
return false;	
}
if(document.getElementById("delivery_date").value!='')
{

var del=document.getElementById("delivery_date").value;	
}
if(del<datedat)
{
alert("Delivery  Date Not less then current  Date");
document.getElementById("delivery_date").focus();	
return false;	
}
if(document.getElementById("delivery_time").value=='')
{
alert("Must Enter Delivery Time");
document.getElementById("delivery_time").focus();
return false;	
}
if(document.getElementById("contact_person").value=='')
{
alert("Must Enter Contact Person Name");
document.getElementById("contact_person").focus();
return false;	
}
var del1=document.getElementById("valid_till").value;	
if(del1<datedat)
{
alert("Valid Till Date Not less then current  Date");
//document.getElementById("valid_till").value='';
document.getElementById("valid_till").focus;	
return false;	
}	
return true;		
}	
	
function showdata(str)
{
if (str=='')
  {
  document.getElementById("divdata").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("divdata").style.display='block';
    document.getElementById("divdata").innerHTML=xmlhttp.responseText;
      }
  }
 
xmlhttp.open("GET","geteditdatapo.php?site="+str,true);
xmlhttp.send();
}	
</script>