<?php
session_start();
include 'fpdf.php';
include 'exfpdf.php';
include 'easyTable.php';

include('../includes/dbcon.php');


if (isset($_GET['grn_no'])) { 
 $grn_no= trim($_GET['grn_no']);
}  //// if is set
//$tran_no=4;

if (isset($_POST['grn_no'])) { 
$tran_no= trim($_POST['grn_no']);
}
$userid=$_SESSION['hrm_id'];
 $user_name=$_SESSION['hrm_name'];

//$t=time();
////!!!!!!!!!!!!!!!!!!  Open stock_trans_header   !!!!!!!!!!!!!!!!!!!!!!!!!!!!
$query=mysqli_query($con," SELECT grn_no,grn_date,refnote,invoice_no,stock_locations.loc_name
 FROM grn_header
LEFT JOIN stock_locations ON stock_locations.loc_id=grn_header.gran_loc_id
 where grn_header.grn_no='$grn_no'  ")or die(mysqli_error($con));
$count=mysqli_num_rows($query);

if ($count>0)
{

  while($rowsp=mysqli_fetch_array($query)){     
    
    $grn_date=$rowsp['grn_date'];
    $loc_name=$rowsp['loc_name'];
    $note=$rowsp['refnote'];
    //$sup_name=$rowsp['sup_name'];

//$t=date("h:m:s",strtotime(  $inv_date)) ;
  
  } ////  while($rowsp=mysqli_fetch_array($query)){ 



}
  

$pp='GRN' ;
$pdf=new exFPDF();
$pdf->AliasNbPages();
$pdf->AddPage(); 
$pdf->SetFont('helvetica','',10);

$table1=new easyTable($pdf, 2);
$table1->easyCell($pp, 'font-size:16; font-style:B; font-color:#000000;');
//$table1->easyCell('', 'img:../dist/img/anura_logo1.jpg, w20; align:R;');
$table1->printRow();


 $table1->rowStyle('font-size:12; ');
 $table1->easyCell("<b>Document No :</b> $grn_no");
 $table1->easyCell("<b>Location :</b> $loc_name",'align:R;'); 
 $table1->printRow();
 
 
 $reqdate=date("Y-m-d",strtotime($grn_date));
 $table1->rowStyle('font-size:12; ','align:L;');
 $table1->easyCell("<b>GRN Date:</b> $reqdate"); 
  $table1->easyCell("<b>Note:</b> $note",'align:R;'); 
 //$table1->easyCell("<b>Time :</b> $t",'align:R;');
 $table1->printRow();

 $table1->rowStyle('font-size:12; ');
 $table1->easyCell("<b>User :</b> $user_name");
 
  //$table1->easyCell("<b>Supplier:</b> $sup_name",'align:R;'); 
 $table1->printRow();



 $table1->endTable(5);


 $table=new easyTable($pdf, '{20,150,40,40}','align:L{LLRR;border:1; border-color:#a1a1a1; ');


 $table->rowStyle('align:{LLRR};valign:M;bgcolor:#ffffff; font-color:#000000; font-family:times; font-style:B;');
 $table->easyCell('#');
 $table->easyCell('Item');
 $table->easyCell('Price');
 $table->easyCell('Qty');
 
 $table->printRow();

          $total_qty=0;
          $ncount=0;
          $queryd=mysqli_query($con," SELECT grn_detail.issue_qty,
grn_detail.cost_price,item_master.item_name,item_master.sku,item_master.qoh
 FROM grn_detail
LEFT JOIN item_master ON item_master.item_id=grn_detail.item_id where grn_detail.grn_no='$grn_no' order by se ")or die(mysqli_error($con));
          while($row=mysqli_fetch_array($queryd)){               
              //$rcount = $rcount + 1;
              $item_name=$row['item_name'];
              $issue_qty=$row['issue_qty'];
              $cost_price=$row['cost_price'];
              $total_qty=$total_qty + $issue_qty ;
      
          $ncount=$ncount+1;

          $bgcolor='';
          if($ncount%2)
          {
            $bgcolor='bgcolor:#ffffff;';
          }
  
          $table->rowStyle('valign:M;border:LR;paddingY:2;' . $bgcolor);
          $table->easyCell($ncount);
          $table->easyCell($item_name,'font-size:12;');
           $table->easyCell($cost_price);
          $table->easyCell($issue_qty);       
        
          $table->printRow();
    
          }

 $table->rowStyle('align:{LLRR};');
// $table->easyCell(' ', 'border:T;colspan:1'); 
 //$table->easyCell(' ', 'border:T;colspan:1');
  $table->easyCell(' ');  
 $table->easyCell('TOTAL', 'font-style:B;');
 $table->easyCell(' ');  
 $table->easyCell($total_qty,'font-style:B;','align:R;');

 $table->printRow();        
 $table->endTable(10);



$sig1='Store Keeper';
$sig2='Received By';
$sig3='Security Officer';

 $table2=new easyTable($pdf, '{50,50,50}','align:C{LLL;border:0; border-color:#ffffff; ');
//$table2=new easyTable($pdf, 2);
$table2->easyCell('..........................', 'font-size:12; font-style:B; font-color:#000000;');
$table2->easyCell('..........................', 'font-size:12; font-style:B; font-color:#000000;');
$table2->easyCell('..........................', 'font-size:12; font-style:B; font-color:#000000;');
$table2->printRow();

$table2->easyCell($sig1, 'font-size:12; font-style:B; font-color:#000000;');
$table2->easyCell($sig2, 'font-size:12; font-style:B; font-color:#000000;');
$table2->easyCell($sig3, 'font-size:12; font-style:B; font-color:#000000;');
$table2->printRow();



 $table2->endTable(5);


$pdf->Cell(0,10,'Page '.$pdf->PageNo().'/{nb}',0,0,'C');
$pdf->Output(); 
?>