
<?php //error_reporting(0);
include('./includes/fun-php.php');
include('./includes/fun-HRClass.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];



     ?>
   
     
     
<?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 mst_requisition_no='".$_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  sub_total AS basic,total_amount AS total 
    FROM vendorquotationdetails  WHERE quotation_no='".$vend1['id']."' and mst_productid='".$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'];
   
      
  }
  }
  }
 
  ?>


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

</h2>
<h3 style="margin:0px; padding:0px; border-bottom:none;"><?php echo $_REQUEST['site']; ?>, <?php echo $s->getField('locations','loccode',$_REQUEST['site'],'locationname'); ?></h3>
<h3>Quotation Comparative Statement</h3>

<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%" bgcolor="#e2e2e2"><strong>Purchase Requiestion No.:</strong></td>
		 

		
		
		
		<td  width="21%"><?php echo $s->getField('materialrequisitions','requisitionno',$_REQUEST['RequisitionNo'],'Reqno'); ?> </td> 
 <td  width="4%" bgcolor="#e2e2e2"><strong>Date:</strong><br />
 
	  </td> 
  <td  width="21%"><?php echo ConvertSQLDate($s->getField('materialrequisitions','requisitionno',$_REQUEST['RequisitionNo'],'prdate')); ?> </td>
   <td width="17%" bgcolor="#e2e2e2"><strong>Date:(Report Printing date)</strong><br />
 
	  </td>
	  <td><?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%" bgcolor="#e2e2e2"><strong>S.No.</strong></td>
        <td width="30%" bgcolor="#e2e2e2"><strong>Item Code</strong></td>
        <td valign="bottom" bgcolor="#e2e2e2" ><strong>Item Name</strong></td>
      </tr>
    </table></th>
    <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"><strong><?php echo $s->getField('suppliers','id',$party1[0],'vendor_name'); ?></strong></td>
      </tr>
      <tr>
        <td align="center" style="border-bottom:#333333 1px solid;" class="pad"><strong><?php echo $s->getField('suppliers','id',$party1[0],'vendor_code'); ?></strong></td>
      </tr>
      <tr>
        <td align="center" class="pad"><strong><?php echo $s->getField('suppliers','id',$party1[0],'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" bgcolor="#e2e2e2" class="pad">Basic</td>
            <td align="left" valign="top" bgcolor="#e2e2e2" class="pad">Landed</td>
          </tr>
        </table></td>
      </tr>
    </table></th>
    <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"><strong><?php echo $s->getField('suppliers','id',$party1[1],'vendor_name'); ?></strong></td>
      </tr>
      <tr>
        <td align="center" style="border-bottom:#333333 1px solid;" class="pad"><strong><?php echo $s->getField('suppliers','id',$party1[1],'vendor_code'); ?></strong></td>
      </tr>
      <tr>
        <td align="center" class="pad"><strong><?php echo $s->getField('suppliers','id',$party1[1],'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" bgcolor="#e2e2e2" class="pad">Basic</td>
            <td align="left" valign="top" bgcolor="#e2e2e2" class="pad">Landed</td>
          </tr>
        </table></td>
      </tr>
    </table></th>
    <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><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" bgcolor="#e2e2e2" class="pad">Basic</td>
            <td width="18%" align="left" valign="top" bgcolor="#e2e2e2"  class="pad">Landed</td>
            <td width="46%" align="left" valign="top" bgcolor="#e2e2e2" class="pad">MRN No.</td>
            <td width="21%" align="left" valign="top" bgcolor="#e2e2e2"  class="pad">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"><?php echo $i; ?></td>
        <td width="30%" class="pad"><?php echo $s->getField('item_master','id',$row['mst_itemid'],'StockID'); ?></td>
        <td class="pad"><?php echo $s->getField('item_master','id',$row['mst_itemid'],'item_name'); ?></td>
      </tr>
      <?php $i++; } ?>
    </table></td>
    <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($k1=0;$k1<count($itemid);$k1++)
  {
 // echo "select rate AS basic,ExcisePercentage
  // from  vendorquotationdetails where quotation_no='".$vendorid[0]."' and mst_productid='".$itemid[$k1]."'";
  
  $vendor1=DB_query("select rate AS basic,ExcisePercentage
   from  vendorquotationdetails where quotation_no='".$vendorid[0]."' and mst_productid='".$itemid[$k1]."'",$db);
   $vendor1_row=DB_fetch_array($vendor1);
  if($vendor1_row['basic']=='')
  {
  $rate=0; 
  $total=0;
  } else{
   $rate=$vendor1_row['basic'];
  
  $total=$rate+($rate*$vendor1_row['basic']/100);
  }
  
?>
      <tr>
        <td width="50%" align="left" valign="top" ><?php echo $rate; ?></td>
        <td align="left" valign="top" ><?php echo $total; ?></td>
      </tr>
      <?php  } ?>
    </table></td>
    <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($k=0;$k<count($itemid);$k++)
  {
  $vendor21=DB_query("select rate AS basic,ExcisePercentage
   from  vendorquotationdetails where quotation_no='".$vendorid[1]."' and mst_productid='".$itemid[$k]."' ",$db);
 $vendor2_row=DB_fetch_array($vendor21);
  if($vendor2_row['basic']=='')
  {
  $rate1=0; 
  $total1=0;
  } else{ $rate1=$vendor2_row['basic'];
  $total1=$rate1+($rate*$vendor2_row['basic']/100);

  }
  
?>
      <tr>
        <td width="50%" align="left" valign="top" ><?php echo $rate1; ?></td>
        <td align="left" valign="top" ><?php echo $total1; ?></td>
      </tr>
      <?php  } ?>
    </table></td>
    <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"><?php echo $rate3; ?></td>
        <td width="18%" align="left" valign="top" class="pad"><?php echo  $total3;?></td>
        <td width="46%" align="left" valign="top" class="pad"><?php  echo  $mrn;?></td>
        <td width="21%" align="left" valign="top" class="pad"><?php echo  ConvertSQLDate($mrndate); ?></td>
      </tr>
      <?php } ?>
    </table></td>
  </tr>
</table>
<p ></p>
 <table width="100%%"  cellpadding="3" cellspacing="0" border="1">
  <tr>
    <td width="33%" bgcolor="#e2e2e2"><strong>Quotation No. and Date</strong></td>
    <td width="18%"><?php echo $s->getField('venderquotations','id',$vendorid[0],'vernder_quotation');?></td>
    <td width="13%"><?php echo $s->getField('venderquotations','id',$vendorid[1],'vernder_quotation');?></td>
    <td colspan="2" align="center" bgcolor="#b7b7b7" style="text-align:center;"><strong>Action Recommended</strong></td>
   </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Discount</strong></td>
    <td><?php
	$discount=DB_query("select sum(discount_amount) as dis ,sum(specialdiscount_amount) as spdis
	 from vendorquotationdetails where quotation_no='".$vendorid[0]."'",$db);
	$discountamt=DB_fetch_array($discount);
	echo ($discountamt['dis']+$discountamt['spdis']); 
	 
	?>
	</td>
    <td><?php
	$discount1=DB_query("select sum(discount_amount) as dis ,sum(specialdiscount_amount) as spdis
	 from vendorquotationdetails where quotation_no='".$vendorid[1]."'",$db);
	$discountamt1=DB_fetch_array($discount1);
	echo ($discountamt1['dis']+$discountamt1['spdis']); 
	 
	?></td>
    <td>a)  Place Order on</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Packing Charges</strong></td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[0],'pkg_charges');	?></td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[1],'pkg_charges');	?></td>
    <td>b) Negotiated with</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Excise Duty+Cess</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>c) Order No./ Date</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>VAT/CST + Surcharge</strong></td>
   <td><?php echo $s->getField('venderquotations','id',$vendorid[0],'vat_cst_amount');	?></td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[1],'vat_cst_amount');	?></td>

    <td>   P.O. No. </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Insurance</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td> Date:</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Forwarding</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><table width="100%%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="50%">Prepared by  </td>
    <td>Checked by</td>
    </tr>
</table></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Freight</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Other Charges</strong></td>
     <td><?php echo $s->getField('venderquotations','id',$vendorid[0],'totalcharge');	?></td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[1],'totalcharge');	?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Payment Terms</strong></td>
     <td><?php echo $s->getField('venderquotations','id',$vendorid[0],'payment_term');	?> Days</td>
    <td><?php echo $s->getField('venderquotations','id',$vendorid[1],'payment_term');	?> Days</td>
    <td>&nbsp;</td>
    <td>Approved By</td>
  </tr>
  <tr>
    <td bgcolor="#e2e2e2"><strong>Delivery Status</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  <tr>
    <td bgcolor="#e2e2e2"><strong>Remarks</strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<p align="center"><a href="purchase_comparative_statement-print.php?site=<?php echo $_REQUEST['site'];?>&RequisitionNo=<?php echo $_REQUEST['RequisitionNo']; ?>" target="_blank">Print</a>
</p>
