<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['hrm_id'])):
header('Location:../index.php');
endif;

include 'fpdf.php';
include 'exfpdf.php';
include 'easyTable.php';
//if(isset($_POST['submit'])){ //check if form was submitted
  $fdate = $_POST['fdate'];
  $tdate = $_POST['tdate'];
  $cus_id = $_POST['cus_id'];
  $emp_id= $_POST['emp_id'];


    if ($cus_id==0){  $fcus=0; $tcus='99999999'; }
    else {  $fcus=$cus_id ; $tcus=$cus_id ; }



$pp='Invox ' ;
$pdf=new exFPDF();
$pdf->AliasNbPages();
$pdf->addPage('L');

$pdf->SetFont('helvetica','',10);

$table1=new easyTable($pdf, 2);
$table1->easyCell($pp, 'font-size:20; font-style:B; font-color:#00bfff;');

$table1->printRow();

 $table1->rowStyle('font-size:12; ');
 $table1->easyCell("<b>Daily Sales</b> ");

 $table1->printRow();
 $fdate1=date("Y-m-d",strtotime($fdate));
 $tdate1=date("Y-m-d",strtotime($tdate));
 $table1->rowStyle('font-size:12; ','align:L;');
 $table1->easyCell("<b>From Date:</b> $fdate1"); 


 $table1->printRow();
 $table1->rowStyle('font-size:12; ','align:L;');
 $table1->easyCell("<b>To Date:</b> $tdate1"); 
 $table1->printRow();


  $table1->endTable(5);
 $table=new easyTable($pdf, '{5,30,40,15,15,30,80,30}','align:C{LLLLLLLR};border:1; border-color:#a1a1a1; ');

 $table->rowStyle('align:{CCCC};valign:M;bgcolor:#2D4F85; font-color:#ffffff; font-family:times; font-style:B;');

 $table->easyCell('#');
 $table->easyCell('Date');
 $table->easyCell('Invoice No');
 $table->easyCell('type');
 $table->easyCell('Sales type');
 $table->easyCell('Rep');
 $table->easyCell('Customer');
 $table->easyCell('Amount'); 
 
 $table->printRow();


$rcount=0;
$tot=0;

 $query=mysqli_query($con,"SELECT inv_id,inv_date ,customer_master.cus_name,stock_locations.loc_name,
seheader.amount,invoice_types.des,employee_master.emp_name,salestype.sdes
FROM inv_header
LEFT JOIN customer_master ON customer_master.cus_id=inv_header.cus_id
LEFT JOIN stock_locations ON stock_locations.loc_id=inv_header.loc_id
LEFT JOIN seheader ON inv_header.inv_id=seheader.docid 
LEFT JOIN invoice_types ON inv_header.invtype_id=invoice_types.invtype_id
LEFT JOIN employee_master ON employee_master.emp_id=inv_header.emp_id
LEFT JOIN salestype ON inv_header.inv_type=salestype.sid
where inv_date between '$fdate' and '$tdate' and inv_header.cus_id between $fcus and $tcus ")or die(mysqli_error()); 

 while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
             
                $inv_id=$row['inv_id'];
                $inv_date=$row['inv_date']; 
                $loc_name=$row['loc_name'];
                $cus_name=$row['cus_name'];
                $invtype=$row['des'];

                $tot=$tot + $row['amount'] ;

      $inv_date=date("Y-m-d",strtotime($row['inv_date']));
        
          $table->easyCell($rcount);
            $table->easyCell($inv_date);
               $table->easyCell($inv_id);
                $table->easyCell($row['des']);  
                $table->easyCell($row['sdes']);  
                 $table->easyCell($row['emp_name']); 
          $table->easyCell($row['cus_name']);  
           $table->easyCell($row['amount']); 
              
        
                               
          $table->printRow();
          }



$table->rowStyle('align:{RRRR};');
$table->easyCell(' ');
$table->easyCell('Totals', 'font-style:B;','align:L;');
$table->easyCell(' ');
$table->easyCell(' ');
$table->easyCell(' ');
$table->easyCell(' ');
$table->easyCell(' ');
$table->easyCell(number_format($tot,2),'align:R;');

$table->printRow(); 









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