<?php 
if(isset($_POST['type'])){
    require_once('../../assets/config/config.php');
    $obj=new Database();
    $batch_no=$_POST['type'];
    $id1=date("d-M-Y",strtotime($_POST['s_date']));
    $id2=date("d-M-Y",strtotime($_POST['e_date']));
    $id='';
    if($batch_no==''){
      $id="date BETWEEN '".$id1."' AND '".$id2."'";
    }
    else{
      $id="particular='".$batch_no."' and "."date BETWEEN '".$id1."' AND '".$id2."'";
    }
    $obj->select('inventory','*',null,$id,null,null);
    $result=$obj->getResult();

    $obj->select('organization','*',null," id=1",null,null);
    $result2=$obj->getResult();

    $GLOBALS['date_se']="Statement (".$id1." to ".$id2.")";
    $GLOBALS['org']=$result2[0]["organization"];
    $GLOBALS['batch_no']=$batch_no;
    require ("../../assets/fpdf/fpdf.php");

    //customer and invoice details
    $info=[

    
    ];
    class PDF extends FPDF
    {
      
      function Header(){
        
        //Display Company Info
        $this->SetFont('Arial','B',10);
        $this->Cell(50,10,$GLOBALS['org'],0,1);
        $this->SetFont('Arial','',9);
        $this->Cell(50,7,$GLOBALS['date_se'],0,1);
  
        
        //Display INVOICE text
        $this->SetY(15);
        $this->SetX(-60);
        $this->SetFont('Arial','B',14);
        $this->Cell(50,10,"Inventory History",0,1);
        
        //Display Horizontal line
        //$this->Line(0,48,210,48);
      }
      
      function body($info,$result){
        
      
        //Display Table headings
        $this->SetY(30);
        $this->SetX(10);
        $this->SetFont('Arial','B',8);
        $this->Cell(40,9,"Particular",1,0,"L");
        $this->Cell(70,9,"Description",1,0,"L");
        $this->Cell(40,9,"Amount",1,0,"C");
        $this->Cell(40,9,"Date",1,1,"C");
        $this->SetFont('Arial','',7);
        $c=0;
        //Display table product rows
        foreach($result as $row){
          $this->Cell(40,9,$row["particular"],"LR",0,"L");
          $this->Cell(70,9,$row["description"],"R",0,"L");
          $this->Cell(40,9,$row["amount"],"R",0,"C");
          $this->Cell(40,9,$row["date"],"R",1,"C");
        
            $c=$c+$row["amount"];
          }
    
        
      
        //Display table total row
        $this->SetFont('Arial','B',8);
        $this->Cell(110,9,'',1,0,"C");
        $this->Cell(40,9,'Total',1,0,"C");
        $this->Cell(40,9,$c,1,1,"C");
        
        //Display amount in words

        
      }

    }
    //Create A4 Page with Portrait 
    $pdf=new PDF("P","mm","A4");
    $pdf->AddPage();
    $pdf->body($info,$result);
    $pdf->Output();
  }

?>