<style>
.font12{
font-size:12px;
}
.font10{
font-size:11px;
}
</style>
<?php //error_reporting(0);
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('./includes/fun-php.php');
include('./includes/fun-HRClass.php');

     ?>
   
     
     
<?php
$select1=DB_query("select * from requisitionorderdetails where requsitionno='".$_REQUEST['RequisitionNo']."'",$db);
	while($row1=DB_fetch_array($select1))
	{
	$itemid[]=$row1['mst_itemid'];
}

  $dataarray=array();
  $mrn=array();
   $party1=array();
  for($i=0;$i<count($itemid);$i++)
  {

   $addmrn=DB_query("SELECT itemprice,val_after_disc,MRNNo,MRNDate
    FROM addmrnqty INNER JOIN addmrn ON addmrn.id=addmrnqty.issue_id 
    WHERE mst_itemid='".$itemid[$i]."' order by MRNDate desc limit 0,1",$db);
	while($addmrndata=DB_fetch_array($addmrn))
	{
	$mrn[]=array('mrnno'=> $addmrndata['MRNNo'], 'basic' => $addmrndata['itemprice'],'total' => $addmrndata['val_after_disc'],'MRNDate'=>$addmrndata['MRNDate']);
	}
    $vender_id1=DB_query("select * from venderquotations where indent_prno='".$_REQUEST['RequisitionNo']."' ",$db);
	while($vend1=DB_fetch_array($vender_id1))
	{ 
	//echo "SELECT  sub_total AS basic,total_amount AS total 
    //FROM vendorquotationdetails  WHERE quotation_no='".$vend1['id']."' and mst_productid='".$itemid[$i]."'";
	
   $item1=DB_query("SELECT  NetRate AS basic,basic_Amt AS total 
    FROM vendorquotationdetails  WHERE parant_id='".$vend1['id']."' and mst_itemid='".$itemid[$i]."'",$db);
   $vender=DB_fetch_array($item1);
  
   $dataarray[]=array('mst_supplierno'=> $vend1['mst_supplierno'], 'basic' => $vender['basic'],'total' => $vender['total'],'quotations'=>$vend1['id']);
  
   }
  } 
 
  foreach ($dataarray as $key => $row1) {
    $volume[$key]  = $row1['basic'];
    $edition[$key] = $row1['quotations'];
	 $edition1[$key] = $row1['mst_supplierno'];
}

array_multisort($volume, $edition1,$edition ,SORT_ASC,$dataarray);
//print_r($dataarray);
for($k=0;$k<count($dataarray);$k++)
{
  if(count($dataarray)>0)
  {
 
    if(!in_array($dataarray[$k]['mst_supplierno'],$party1))
	{
    $party1[]=$dataarray[$k]['mst_supplierno'];
     $vendorid[]=$dataarray[$k]['quotations'];
   
      
  }
  }
  }

  ?>
<?php 
$data_arr=array();
$v=count($vendorid);
if($v>4){
$set=4;
}else{
$set=$v;
}
for($a=0;$a<$set;$a++)
  {
$sr=DB_query("SELECT vendor_name,vendor_code,address3 FROM suppliers WHERE id  ='".$party1[$a]."'",$db);
$rr=DB_fetch_array($sr);
$data_arr[$a]['vendor_name']=$rr['vendor_name'];
$data_arr[$a]['vendor_code']=$rr['vendor_code'];
$data_arr[$a]['address3']=$rr['basic_amt'];
  }
?>

 <h2> 
 <center><?php echo  $s->getField('companies','CompanyId',$_SESSION['ACGCompanyId'],'CompanyName');  ?></center>

</h2>
<h4><center>Quotation Comparative Statement</center></h4>

<form action="" method="post">
<div style="width:910px; overflow:auto; margin-left:auto; margin-right:auto;">

	<table border="1" cellpadding="3" cellspacing="0"  width="100%">
	<tr>
		
<td width="17%" class="font12"><strong>Purchase Requiestion No.:</strong></td>
		 

		
		
		
		<td  width="21%" class="font10"><?php echo $s->getField('materialrequisitions','requisitionno',$_REQUEST['RequisitionNo'],'Reqno'); ?> </td> 
 <td  width="4%" class="font12"><strong>Date:</strong><br />
 
	  </td> 
  <td  width="21%" class="font10"><?php echo ConvertSQLDate($s->getField('materialrequisitions','requisitionno',$_REQUEST['RequisitionNo'],'prdate')); ?> </td>
   <td width="17%" class="font12"><strong>Date:(Report Printing date)</strong><br />
 
	  </td>
	  <td class="font10"><?php  echo date('d/m/Y'); ?> </td>       
</tr></table>

  </div>
</form>

 
<table cellpadding="0" cellspacing="0" border="1" width="100%">
  <tr>
    <th  align="left" valign="bottom" style="padding:0px; margin:0px;"><table width="100%" border="1" cellspacing="0" cellpadding="3">
      <tr>
        <td width="10%" class="font12"><strong>S.No.</strong></td>
        <td width="30%" class="font12"><strong>Item Code</strong></td>
        <td valign="bottom" class="font12"><strong>Item Name</strong></td>
      </tr>
    </table></th>
	
	<?php 
	
	for($a=0;$a<$set;$a++)
       { 
	   ?>
	  
    <th align="left" valign="top" style="padding:0px;"><table width="100%%" height="86" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center" style="border-bottom:#333333 1px solid;" class="pad font12"><strong><?php echo $data_arr[$a]['vendor_name'];?></strong></td>
      </tr>
      <tr>
        <td align="center" style="border-bottom:#333333 1px solid;" class="pad font12"><strong><?php echo $data_arr[$a]['vendor_code'];?></strong></td>
      </tr>
      <tr>
        <td align="center" class="pad font12"><strong><?php echo $data_arr[$a]['address3'];?></strong></td>
      </tr>
      <tr>
        <td height="48" align="center" valign="bottom"><table width="100%" border="1" cellspacing="0" cellpadding="3">
          <tr>
            <td width="50%" align="left" valign="top" class="pad font12">Basic</td>
            <td align="left" valign="top" class="pad font12">Landed</td>
          </tr>
        </table></td>
      </tr>
    </table></th>
	<?php } ?>
    <th align="left" valign="top" style="padding:0px; margin:0px;"><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td class="font12" align="center"><strong>Previous Purchase Rate</strong></td>
      </tr>
      <tr>
        <td height="42"></td>
      </tr>
      <tr>
        <td align="left"><table width="100%" border="1" cellspacing="0" cellpadding="3">
          <tr>
            <td width="15%"  align="left" valign="top" class="pad font12">Basic</td>
            <td width="18%" align="left" valign="top" class="pad font12">Landed</td>
            <td width="46%" align="left" valign="top" class="pad font12">MRN No.</td>
            <td width="21%" align="left" valign="top" class="pad font12">Date</td>
          </tr>
        </table></td>
      </tr>
    </table></th>
  </tr>
  <tr>
    <td  align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" border="1" cellspacing="0" cellpadding="2">
      <?php
$i=1;
    $select=DB_query("select * from requisitionorderdetails where requsitionno='".$_REQUEST['RequisitionNo']."'",$db);
	while($row=DB_fetch_array($select))
	{
	

 ?>
      <tr bgcolor="#FFFFFF">
        <td width="10%" class="pad font10"><?php echo $i; ?></td>
        <td width="30%" class="pad font10"><?php echo $s->getField('item_master','id',$row['mst_itemid'],'StockID'); ?></td>
        <td class="pad font10"><?php echo $s->getField('item_master','id',$row['mst_itemid'],'item_name'); ?></td>
      </tr>
      <?php $i++; } ?>
    </table></td>
	<?php
	$data_arr=array();
	$v=count($vendorid);
	if($v>4){
	$set=4;
	}else{
	$set=$v;
	}

 
?>
<?php 
 for($j=0;$j<$set;$j++)
{
?>
  
    <td align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" border="1" cellpadding="2" cellspacing="0"  style="border-top:none; border-left:none; border-right:none; border-bottom:none; border-color:#333333">
    
<?php 
  for($b=0;$b<count($itemid);$b++)
  {
   //echo "select rate AS basic,ExcisePercentage
  // from  vendorquotationdetails where parant_id='".$vendorid[$j]."' and mst_itemid='".$itemid[$b]."'";
  $vendor1=DB_query("select rate AS basic,ExcisePercentage
   from  vendorquotationdetails where parant_id='".$vendorid[$j]."' and mst_itemid='".$itemid[$b]."'",$db);
   $vendor1_row=DB_fetch_array($vendor1);
  if($vendor1_row['basic']=='')
  {
  $data_ar[$b]['basic']=0; 
  $data_ar[$b]['total']=0;
  } else{
   $data_ar[$b]['basic']=$vendor1_row['basic'];
   $data_ar[$b]['total']= $data_ar[$b]['basic']+( $data_ar[$b]['basic']* $data_ar[$j]['basic']/100);
  
 // $total=$rate+($rate*$vendor1_row['basic']/100);
  }
  ?>	  
  <tr>
        <td width="50%" align="left" valign="top" class="font10"><?php echo $data_ar[$b]['basic']; ?></td>
        <td align="left" valign="top" class="font10"><?php echo $data_ar[$b]['total']; ?></td>
      </tr>
    <?php  }     ?>
    </table></td> <?php } ?> 
    <td align="left" valign="top"><table width="100%" border="1" cellpadding="2" cellspacing="0"  style="border-top:none; border-left:none; border-right:none; border-bottom:none; border-color:#333333">
      <?php 
 
 for($k2=0;$k2<count($itemid);$k2++)
 {
  $addmrn=DB_query("SELECT itemprice,val_after_disc,MRNNo,MRNDate,excise_perc
    FROM addmrnqty INNER JOIN addmrn ON addmrn.id=addmrnqty.issue_id 
    WHERE mst_itemid='".$itemid[$k2]."' order by MRNDate desc limit 0,1",$db);
	$addmrndata=DB_fetch_array($addmrn);
 if($addmrndata['itemprice']=='')
  {
  $rate3=0; 
  $total3=0;
  $mrn='';
  $mrndate='';
  } else{ 
  $rate3=$addmrndata['itemprice']; 
  $total3=(($addmrndata['itemprice']*$addmrndata['excise_perc'])/100)+$addmrndata['itemprice'];
  
  $addmrndata['val_after_disc'];
  $mrn=$addmrndata['MRNNo'];
  $mrndate=$addmrndata['MRNDate'];
  }
 ?>
      <tr>
        <td width="15%" align="left" valign="top" class="pad font10"><?php echo $rate3; ?></td>
        <td width="18%" align="left" valign="top" class="pad font10"><?php echo  $total3;?></td>
        <td width="46%" align="left" valign="top" class="pad font10"><?php  echo  $mrn;?></td>
        <td width="21%" align="left" valign="top" class="pad font10"><?php echo  ConvertSQLDate($mrndate); ?></td>
      </tr>
      <?php } ?>
    </table></td>
  </tr>
</table>
<p ></p>

<?php 
$data=array();
$v=count($vendorid);
if($v>4){
$set=4;
}else{
$set=$v;
}
for($p=0;$p<$set;$p++)
  {
$s=DB_query("SELECT quotation_no,Quotation_Date,basic_amt,pkg_charges,taxvalue,surcharge_amt,Freight,PaymentTerm,Remarks,add_charges,grand_total,terms_condition FROM `venderquotations` WHERE id  ='".$vendorid[$p]."'",$db);
$r=DB_fetch_array($s);
$data[$p]['quotation_no']=$r['quotation_no'];
$data[$p]['Quotation_Date']=$r['Quotation_Date'];
$data[$p]['basic_amt']=$r['basic_amt'];
$data[$p]['pkg_charges']=$r['pkg_charges'];
$data[$p]['taxvalue']=$r['taxvalue'];
$data[$p]['surcharge_amt']=$r['surcharge_amt'];
$data[$p]['Freight']=$r['Freight'];
$data[$p]['PaymentTerm']=$r['PaymentTerm'];
$data[$p]['Remarks']=$r['Remarks'];
$data[$p]['add_charges']=$r['add_charges'];
$data[$p]['grand_total']=$r['grand_total'];
$data[$p]['terms_condition']=$r['terms_condition'];

$sd=DB_query("SELECT SUM(discounted_amount) AS discounted_amount,SUM(ExciseValue)AS ExciseValue FROM `vendorquotationdetails` WHERE parant_id='".$vendorid[$p]."'",$db);
$rd=DB_fetch_array($sd);
$data[$p]['discounted_amount']=$rd['discounted_amount'];
$data[$p]['ExciseValue']=$rd['ExciseValue'];

  }
?>
 <table width="100%%"  cellpadding="3" cellspacing="0" border="1">
 
  <tr>
    <td width="25%" class="font12"><strong>Quotation No.</strong></td>
<?php for($p=0;$p<$set;$p++){?>
    <td width="23%" class="font10"><?php echo $data[$p]['quotation_no'];?></td><?php } ?>
  </tr>
   <tr>
    <td width="25%" class="font12"><strong> Date</strong></td>
<?php for($p=0;$p<$set;$p++){?>
 <td width="23%" class="font10"><?php echo ConvertSQLDate($data[$p]['Quotation_Date']);?></td> <?php } ?>
   </tr>
   <tr>
    <td width="25%" class="font12"><strong> Basic Amount</strong></td>
	<?php for($p=0;$p<$set;$p++){?>
    <td width="23%" class="font10"><?php echo $data[$p]['basic_amt'];?></td><?php } ?>
   
   </tr>
  <tr>
    <td class="font12"><strong>Discount</strong></td>
    <?php for($p=0;$p<$set;$p++){?><td class="font10"><?php //if(!empty($dis1)){
	echo  $data[$p]['discounted_amount'];
	//}?></td><?php } ?>
  </tr>
  <tr>
    <td class="font12"><strong>Packing Charges</strong></td>
   <?php for($p=0;$p<$set;$p++){?> <td class="font10"><?php echo $data[$p]['pkg_charges'];?></td><?php } ?>
  
  </tr>
  <tr>
    <td class="font12"><strong>Excise Duty+Cess</strong></td>
   <?php for($p=0;$p<$set;$p++){?> <td class="font10"><?php //if(!empty($ex1)){
  echo  $data[$p]['ExciseValue'];
   //}?></td><?php } ?>
  </tr>
  <tr>
    <td class="font12"><strong>Purchase Tax</strong></td>
   <?php for($p=0;$p<$set;$p++){?> <td class="font10"><?php echo $data[$p]['taxvalue'];?></td><?php } ?>
  </tr>
  <tr>
    <td class="font12"><strong>Surcharge</strong></td>
      <?php for($p=0;$p<$set;$p++){?><td class="font10"><?php echo $data[$p]['surcharge_amt'];?></td><?php } ?>
  </tr>
  
  <tr>
    <td class="font12"><strong>Freight</strong></td>
  <?php for($p=0;$p<$set;$p++){?> <td class="font10"><?php echo $data[$p]['Freight'];?></td><?php } ?>
  </tr>
  
  <tr>
    <td class="font12"><strong>Payment Terms</strong></td>
     <?php for($p=0;$p<$set;$p++){?> <td class="font10"><?php echo $data[$p]['PaymentTerm'];?> Days</td><?php } ?>
    
  </tr>
  <tr>
    <td class="font12"><strong>Addtional Charges</strong></td>
   <?php for($p=0;$p<$set;$p++){?><td class="font10"><?php echo $data[$p]['add_charges'];?></td><?php } ?>
    
  </tr>
  <tr>
    <td class="font12"><strong>Grand Total</strong></td>
     <?php for($p=0;$p<$set;$p++){?><td class="font10"><?php echo $data[$p]['grand_total'];?></td><?php } ?>
    
  </tr>
  <tr>
    <td class="font12"><strong>Remarks</strong></td>
     <?php for($p=0;$p<$set;$p++){?><td class="font10"><?php echo $data[$p]['Remarks'];?></td><?php } ?>
  </tr>
  <tr>
    <td class="font12"><strong>Terms And Conditions</strong></td>
     <?php for($p=0;$p<$set;$p++){?><td class="font10"><?php echo $data[$p]['terms_condition'];?></td><?php } ?>
  </tr>
</table>
<p id="foo" style="width:155px;" align="center"><a href="#" id="fis" onClick="javascript:toggle_visibility('foo');">Print</a> </p>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
       var e = document.getElementById(id);
	      e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
  
</script>
