<?php
session_name('CAKEPHP'); session_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');

$taxpar_array=array("I"=>"Insurance","E"=>"Excise Duty","F"=>"Freight And P&S","V"=>"Input Tax","M"=>"Miscellaneous","R"=>"Round Off","G"=>"Grand Total");
$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
  $sqlres = DB_query($sql1,$db);
  $companyRow = DB_fetch_array($sqlres);

$sql_compertive=DB_query("select * from comprative where id='".$_REQUEST['id']."'",$db);
$row=DB_fetch_array($sql_compertive);
extract($row);


$sql_mapped=DB_query("select ItemID,mappedQty,mapped_vendor from indentpr_mapping where indentPrno='".$indentprno."'",$db);
$row_mapped=DB_fetch_array($sql_mapped);
$mapitemid=$row_mapped['ItemID']; 
$mapqty1=$row_mapped['mappedQty']; 
$vendor1=$row_mapped['mapped_vendor'];
$itemArrays=explode(',', $mapitemid); 
$mapQty=$mapqty1;
$mapQtyArrays=explode(',', $mapQty);
$mapvendorArrays=explode(',', $vendor1);
      
$numRows=$s->GetFieldValue("venderquotations","mapid='".$mapid."'","count(*)");
 
 function convertDate($Dt)
{
  $dateBRK=explode('-',$Dt);
  $newFormat=$dateBRK[2]."/".$dateBRK[1]."/".$dateBRK[0];
  return $newFormat;
}

$site_sql=DB_query("Select * from locations where loccode='".$site."'",$db);
$site_row=DB_fetch_array($site_sql);
$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  <title>Compertive Statements</title>
<style type="text/css"> 
@print {size:A4; margin:20px 20px;}

@media print{
body{ margin:0px; padding:0px;  font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}

h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

h1{
  font-size: 20px; line-height: 24px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
  color:#006699;  
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
thead{display: table-header-group;}
.wrapper{width:100%; height: auto; float:left; border:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left; position: relative;
}
 .div_first .left
        {
          width:10%; text-align:left; height:auto; vertical-align:middle; height:auto; padding: 10px; position: absolute; left: 0; top: 0;
        }
        .div_first .middle
        {
          width:60%; text-align:center; padding: 10px; margin:0 auto; position: relative;
        }
        .div_first .right
        {
          width:20%;text-align:right; padding: 10px; position: absolute; right: 0; top: 0;
        }

.div_first .full{text-align: center; border: 0;}
.div_second, .div_third, .div_forth{
  width: 100%;
  height:auto;
  border-top: #000000 1px solid;
  /*border-bottom: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{text-align: left; border-top:#000 1px solid;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
.div_second table tr:last-child td{border-bottom:0;}
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color:transparent; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
.div_third table tr:last-child td, .div_third table tr:last-child th{border-bottom:none;}

.f12{ font-weight: bold; color:#000; font-size:12px;}
.f11{color:#000; font-size:12px; line-height:18px;}
.f14{color:#000; font-size:18px;}
.mt26{margin-top:0px; width:86%;}
.mt27{margin-top:0px; width:42%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:8%;}
.wdt2{width:100px;}
.wdt3{width: 66px;}
.wdt4{width: 80px;}
.wdt5{width: 52px;}
.wdt6{width: 60px;}
}

@media screen{
/* CSS Document */
body{ margin:0px; padding:0px; background-color:#fff; font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}
h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

#foo{width:1070px; height: auto; margin:0px auto;}
.wrapper{width:1070px; height: auto; margin:10px auto; border-top:#000000 1px solid;}

h1{
  font-size: 24px; line-height: 28px;
  font-weight:bold;
  font-family:Arial, Helvetica, sans-serif !important;
  color:#006699;  
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;  
}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left; position: relative; display: table;
}
.div_first .full{text-align: center; border: 0; margin:10px 0 0;}
.div_first .left, .div_first .middle, .div_first .right{float: left; display: table-cell; vertical-align: middle;}
.div_first .left
        {
          width:8%; text-align:center; height:auto; vertical-align:middle; padding: 1%; 
        }
        .div_first .middle
        {
          width:78%; text-align:center; padding: 1%; position: relative; margin:0 auto;
        }
        .div_first .right
        {
          width:8%; text-align:center; padding:1%; 
        }
.div_second, .div_third, .div_forth{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;*/
  border-top: #000000 1px solid;
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left;
}
.div_forth{border-bottom:#000000 1px solid;}
.div_second table tr th, .div_second table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{background-color: #ccc; text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
.div_second table tr:last-child td{border-bottom:0;}
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color: #ccc; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:0;}
.div_third table tr:last-child td, .div_third table tr:last-child th{border-bottom:0;}

.f12{font-weight: bold; color:#000; font-size:12px;}
.f11{ color:#000; font-size:12px; line-height:18px;}
.f14{ color:#000; font-size:18px;}
.mt26{margin-top:4px; width:86%;}
.mt27{margin-top:0px; width:42%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:10%;}
.wdt2{width:180px;}
.wdt3{width: 66px;}
.wdt4{width: 120px;}
.wdt5{width: 52px;}
.wdt6{width: 70px;}
}
</style>

 </head>
 <body>
<div id="foo">
  <p style="text-align:right;"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>
<div class="wrapper">

<div class="div_first">
    <?php $logoImage=($CompamiesRow['CompanyLogo']=='')?'Final_Logo_RM.png':$CompamiesRow['CompanyLogo']; ?>
      <div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage;  ?>" class="mt26" /></div>
      <div class="middle"><h1><?php if($site_row['locationname']!="") {echo "<h2>".$site_row['locationname']."</h2>"; } else { echo "";} ?></h1>
      <span class="f12"><?php  if($site_row['deladd1']!='') { echo $site_row['deladd1']; }
                     if($site_row['deladd2']!='') { echo ",".$site_row['deladd2']; }   
                     if($site_row['deladd3']!='') { echo ",".$site_row['deladd3']; } 
                   $cityid=$site_row['city'];
            $stateid=$site_row['state'];
            $countryid=$site_row['country'];
            $citys = $s->getField('city_master','id',$cityid,'city');
            $states = $s->getField('state_master','id',$stateid,'state');
            $country=$s->getField('country_master','id',$countryid,'country');

                      ?></span> <br>
       <span class="f12"><?php echo $citys.",".$states.",".$country; ?></span>
       <div class="full"><h2>Comparative Statement</h2>
        <span class="f11"><?php echo "<span class='f12'>Phone No.:</span> ".$site_row['phone1'].", <span class='f12'>Fax No.:</span> ".$site_row['fax'].", <span class='f12'>Email ID.:</span> ".$site_row['email']; ?><br>
  <?php  echo $_SESSION['mess']; ?>
  </span>
  </div>
      </div>
      <div class="right"><img src="images/eye-logo-blue.png" vspace="10" width="100%" /></div>
</div>

<div class="div_first">

    <table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td width="13%" nowrap="nowrap" class="f12">No. of Quatations Received :</td>
    <td width="20%" class="f11"><?php echo $numRows; ?></td>
    <td width="33%" colspan="2" align="left" class="f11"><strong>C.P.=></strong>Calulated Price with all Taxes & Expenses etc. </td>
    <td class="f11" colspan="2"style="text-align:right"><strong>B.P.=></strong>Basic Price</td>
      </tr>
  </table>
</div>
<div class="div_second">
 
    <table width="100%" border="0" cellspacing="0" cellpadding="3" style="border-collapse:collapse;">
  <tr>
    <td class="f12">Sr. No.</td>
    <td class="f12">Vendor</td>
    <td class="f12">Quote No:</td>
     <td class="f12">Date</td>
      <td class="f12">Payment Terms</td>
       <td class="f12">Amount</td>
       <td class="f12">Confirmed Quote</td>
  </tr>
  <?php
     

   $v=0;
     $noQuoQry="select id, mst_supplierno,party_Quo_no,party_Quo_date,PaymentTerm,grand_total
    from venderquotations where indent_prno='".$indentprno."' 
              and CompanyId='".$_SESSION['ACGCompanyId']."'";

      
   $noQuoQryExec = DB_query($noQuoQry, $db);            
   while($supp=DB_fetch_array($noQuoQryExec))
   {
    $quoteid[$supp['mst_supplierno']]=$supp['id'];
    $suppid[$supp['mst_supplierno']]=$s->getField('suppliers','id',$supp['mst_supplierno'],'vendor_name');
    $suppyes=$s->GetFieldValue("comprative_detail","parant_id='".$id."'   and sppliersId='".$supp['mst_supplierno']."'","id");
    if($suppyes!='') $status='<img src="images/aTexx6RT4.gif" width="20px;"  >'; else $status='<img src="images/Icon_Delete3.gif"></img>';

   ?>
  <tr>
    <td class="f11"><?php echo ($v+1); ?></td>
    <td class="f11"><?php echo $s->getField('suppliers','id',$supp['mst_supplierno'],'vendor_name'); ?></td>
    <td class="f11"><?php echo $supp['party_Quo_no']; ?></td>
    <td class="f11"><?php echo convertDate($supp['party_Quo_date']); ?></td>
    <td class="f11"><?php echo $s->getField('paymentterms','termsindicator',$supp['PaymentTerm'],'terms'); ?></td>
    <td class="f11"><?php echo $supp['grand_total']; ?></td> 
    <td class="f11"><?php echo $status; ?></td>
  </tr>
  <?php $v++; }  ?>
</table>
</div>
<div class="div_third">
<table width="100%" border="0" cellspacing="0" cellpadding="3" style="border-collapse:collapse;" align="left">
  <tbody>
  <tr>
    <th rowspan="3">Sr. No.</th>
    <th rowspan="3">Items Descriptions</th>
    <th rowspan="3">Qty.</th>
    <th colspan="<?php echo count($suppid)*2; ?>">Quote Descriptions</th>
    <th colspan="2">Approved</th>
    </tr>
  <tr>
    <?php foreach($suppid as $key=>$value) { ?>
    <th colspan="2"><?php echo $value;  ?></th>     
    <?php } ?>     
    <th colspan="2">&nbsp;</th>   
    </tr>  
    <tr>
     <?php for($v1=0;$v1<count($suppid);$v1++) {?> 
    <th>B.P. <hr/>C.P.</th>
    <th>Order <br> Qty</th>
    <?php } ?>        
    <th colspan="2">Total Order value</th>
   
    </tr>
    <?php
    $j=1;
     foreach($itemArrays as $ky=>$val1)
     {      
     ?>
    <tr>
       <td class="f11"><?php echo $j; ?></td>
       <td class="f11"><?php echo $s->getField('item_master','id',$val1,'item_name'); ?></td>
      <td class="f11"><?php echo $mapQtyArrays[$ky]; ?></td>
       <?php foreach($suppid as $sup=>$supval)
        {
          $supid=$sup;
          $vendor_type=$s->getField('suppliers','id',$supid,'vendor_type');   
          $assisnqty=$s->GetFieldValue("comprative_detail","parant_id='".$id."' 
        and mst_itemid='".$val1."' and quotationid='".$quoteid[$supid]."'","assign_qty");      
     
         $totalamt1=DB_fetch_array(DB_query("SELECT TotalAmount,A.basic_Amt as basic_Amt,Quantity FROM vendorquotationdetails A 
              INNER JOIN `venderquotations` B ON A.parant_id=B.id WHERE A.mst_itemid='".$val1."' 
              AND B.id='".$quoteid[$supid]."' AND B.mst_supplierno='".$supid."'",$db));
         $totalamt=$totalamt1['TotalAmount'];
         $basicamt=$totalamt1['basic_Amt'];
         $quantity=$totalamt1['Quantity'];
         
           $cpvalue=round($totalamt/$mapQtyArrays[$ky],2);

           if($quantity!='')
           {
             $bpvalue=round($basicamt/$quantity,2);
           }  
           $total_order_value=$assisnqty*$bpvalue;
           $total_order_array[$j][]=$total_order_value;
           if($vendor_type=='International')
           $cpvalue=$bpvalue;
        ?> 
       <td class="f11"><?php echo $bpvalue;    ?><hr/><?php echo  $cpvalue;?></td>
       <td class="f11"><?php echo $assisnqty; ?></td>
      <?php } ?>     
      
       <th class="f11" colspan="2"><?php echo $total_order[]=array_sum($total_order_array[$j]); ?></th>
      
      
    </tr> 
    <?php $j++; } ?>
    <tr>
       <th class="f12"></th>
      <th class="f12">Basic</th>
      <th class="f12"></th>     
      <?php
       foreach($suppid as $sup=>$supval) 
       {
            $supid=$sup;
        ?> 
      <th class="f11" colspan="2"><?php echo $bas=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","basic_amt"); $bas1[]= $bas;  ?></th>
          <?php } ?>
      <th class="f12" >Total</th>
     <th class="f12"><?php echo array_sum($total_order); ?></th>      
    </tr>
    <?php foreach($taxpar_array as $taxkey=>$taxvalue)
    {
      ?>
     <tr>
       <th class="f12"></th>
      <th class="f12"><?php echo $taxvalue; ?></th>
      <th class="f12"></th>
      <?php
      $exciseamt=0;
       foreach($suppid as $sup=>$supval) 
       {
        $supid=$sup;
     
        $exiceamt=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","tot_exise_amt");
        $ecess=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","tot_ecess_amt");
        $shecess=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","tot_shcess_amt");
        $insurance=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","insurance");
        $freight=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","Freight");
        $vatamt=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","taxvalue");
        $Miscellaneous=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","miss_amt");
        $roundoff=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","roundVal");
        $grandtotal=$s->GetFieldValue("venderquotations","id='".$quoteid[$supid]."'","grand_total");
        if($taxkey=='I')  $exciseamt=$insurance;   
        else if($taxkey=='E') $exciseamt=$exiceamt+$ecess+$shecess;
        else if($taxkey=='F') $exciseamt=$freight;  
        else if($taxkey=='V') $exciseamt=$vatamt;   
        else if($taxkey=='M') $exciseamt=$Miscellaneous;    
        else if($taxkey=='R') $exciseamt=$roundoff;  
        else if($taxkey=='G') $exciseamt=$grandtotal;  
        ?> 
      <th class="f11" colspan="2"><?php echo $exciseamt; ?></th>
          <?php } ?>
      <th class="f12"   ></th>
      <th class="f12"></th>      
    </tr>
    <?php } ?>     
  </tbody>
</table>
</div>

<div class="div_forth">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
    <td class="f12">&nbsp;</td>
    <td class="f12" align="center">&nbsp;</td>
    <td class="f12" align="right">&nbsp;</td>
    <td class="f12" align="right">&nbsp;</td>
  </tr>
  <tr>
    <td class="f12" width="25%">Prepared By</td>
    <td class="f12" width="25%" align="center">DGM (PP)</td>
    <td width="25%" align="center" class="f12">CFO</td>
    <td class="f12" align="right">Executive Director</td>
  </tr>
</table>
</div>

</div>
<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>
</body>
</html>