<?php
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 3;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('Account/fun-Trial.php');
 ?>
 <?php 
   $sql=$_SESSION['POorderRegPrnt'];
   $date_year=$_SESSION['date_year1'];
?>
<style type="text/css">
.f12{font-family:Arial; font-size:12px; font-weight:bold;}
.f11{font-family:Arial; font-size:11px; font-weight:normal;}
</style>
<link href="css/purchses1.css" rel="stylesheet" type="text/css" />
<?php 
$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
$sqlres = DB_query($sql1,$db);
$companyRow = DB_fetch_array($sqlres);
?>	
<table width="100%" cellpadding="3" cellpadding="0" border="0">
<tr>
<td  colspan="16" align="center">    <h3>Item Price Details</h3></td></tr>
<tr>
<td colspan="16"><strong><?php echo $_SESSION['mess']; ?></strong></td>
</tr>
</table>

<?php if($_REQUEST['ven']!=''){?>
<div style="text-align:center; color:#006699; margin:0px; border:#000000 solid 0px;">
<table border="0" width="10%" cellpadding="0" cellspacing="0" align="center" >
  <tr>
  <td style="text-align:center; color:#006699; margin:0px; border:#000000 solid 0px;"><font size="5">Vendor</font></td>
  <td  style="text-align:center; color:#006699; margin:0px; border:#000000 solid 0px;"><font size="4"><?php echo $s->getField('suppliers','id',$_REQUEST['ven'],'vendor_name');?></font></td>
  </tr>
</table>
</div>
<?php } ?>
  <table width="100%" cellpadding="3" cellspacing="0" border="1" style="border-collapse:collapse;">
  <tr >
    <td class="f9">Sr. No.</td> 
    <td colspan="2" class="f9">Item Code</td>
  <td  colspan="3" class="f9">Item Name</td>
  <td  class="f9">Unit</td>
    <?php for($i=1;$i<32;$i++){ ?><td class="f9"><div style="width:26px;"><?php echo $i;?></div></td>
    <?php } ?>
    </tr>
<?php
$k=1;
$res = DB_query($sql,$db);
while($row = DB_fetch_array($res))
{ ?>
<tr >
<td align="center"><?php echo $k; ?></td>
<td colspan="16" class="f9"><?php echo $s->getField('suppliers','id',$row['vendorid'],'vendor_name'); ?></td>
</tr>
<tr>
        <td></td>
      <td colspan="34" style="padding:0px;">
      <table width="100%" border="0" cellpadding="1" cellspacing="0">
        <?php 
          if($_REQUEST['item']!='')
             $cond=" and b.mst_itemid='".$_REQUEST['item']."'";
          else
          $cond="";

           $query="SELECT b.mst_itemid FROM purchorders a,purchorderdetails b WHERE  a.id=b.parantId AND MONTH(po_date)='".$date_year[0]."' AND YEAR(po_date)='".$date_year[1]."' AND a.site='".$_REQUEST['site']."' and a.vendorId='".$row['vendorid']."'".$cond." GROUP BY b.mst_itemid";
              //$query=$_SESSION['POorderRegPrnt1'];
                $j=1; $result = DB_query($query,$db);
        $num=DB_num_rows($result);

                while($rows = DB_fetch_array($result)){
        
          $a=$s->getField('item_master','id',$rows['mst_itemid'],'mst_unitid'); 
        if($j!=$num)
        $style1="border-bottom:#808080 1px solid;";
        else
        $style1="border-bottom:none;";
        ?>
        
      <tr style=" <?php echo $style1; ?>">
              <td colspan="2" align="left" style="border-right:#808080 1px solid;" class="f8"><?php echo $s->getField('item_master','id',$rows['mst_itemid'],'StockID'); ?></td>
              <td colspan="3" align="left" style="border-right:#808080 1px solid;" class="f8"><?php echo $s->getField('item_master','id',$rows['mst_itemid'],'item_name'); ?></td>
              <td width="39" align="left" style="border-right:#808080 1px solid;" class="f8"><?php echo $s->getField('unitsofmeasure','unitid',$a,'unitname'); ?></td>
        
          <?php
          $rate_res1=array();
            //$rate_sql=$_SESSION['POorderRegPrnt2']; 
          $rate_sql="SELECT DAYOFMONTH(a.po_date) as day1,b.Rate FROM purchorders a,purchorderdetails b WHERE a.id=b.parantId AND a.vendorId='".$row['vendorid']."' AND b.mst_itemid='".$rows['mst_itemid']."' AND MONTH(po_date)='".$date_year[0]."' AND YEAR(po_date)='".$date_year[1]."'"; 
                      $rate_sql1=DB_query($rate_sql,$db);
            $p=1;
          $num1=DB_num_rows($rate_sql1);
            
                      while($rate_res=DB_fetch_assoc($rate_sql1))
                      {
                        $rate_res1[$rate_res['day1']]=$rate_res;
                      } // echo "<pre>"; print_r($rate_res1); ?>

        
            <?php for($i=1;$i<32;$i++){
              if($i==31) {  $style="border-right:none;";   } else { $style="border-right:1px solid #808080;width:30px;"; } 
             
             ?>
                            <td  style="<?php echo $style; ?>" class="f8">  
                                <?php 
                                if(array_key_exists($i,$rate_res1))
                                {
                                  echo $rate_res1[$i]['Rate'];
                                }
                                else
                                {
                                  echo " ";
                                }
                                ?></td>
                             <?php } ?>
                      
                
          </tr>
        <?php $j++;} ?>  
      </table></td>
</tr>
<?php $k++;} ?>   
</div>
<?php
//echo $data;
$header='';  	
header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=item_price_exl.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
print "$header\n$data"; 
?>