<?php 
if(isset($_POST['s_date'])){
      require_once('../../assets/config/config.php');
      $obj=new Database();
      $id1=date("d-M-Y",strtotime($_POST['s_date']));
      $id2=date("d-M-Y",strtotime($_POST['e_date']));
      $id='';
      if($_POST['type']=='Credit')
      {
        $id="debit='' and date BETWEEN '".$id1."' AND '".$id2."'";
      }
      elseif($_POST['type']=='Debit'){
      
            $id="credit='' and date BETWEEN '".$id1."' AND '".$id2."'";
      }
      elseif($_POST['type']=='')
      {
        $id="date BETWEEN '".$id1."' AND '".$id2."'";
        
      }
      $obj->select('txn_details','*',null,$id,'id DESC',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"];
      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(-40);
          $this->SetFont('Arial','B',14);
          $this->Cell(50,10,"Txn 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,"Date",1,0,"L");
          $this->Cell(70,9,"Description",1,0,"L");
          $this->Cell(40,9,"Credit",1,0,"C");
          $this->Cell(40,9,"Debit",1,1,"C");
          $this->SetFont('Arial','',7);
          $c=0;$d=0;
          //Display table product rows
          foreach($result as $row){
            $this->Cell(40,9,$row["date"],"LR",0,"L");
            $this->Cell(70,9,$row["voucher_type"],"R",0,"L");
            $this->Cell(40,9,$row["credit"],"R",0,"C");
            $this->Cell(40,9,$row["debit"],"R",1,"C");
            if($row["credit"]!=='')
            {
              $c=$c+$row["credit"];
            }
            if($row["debit"]!=='')
            {
              $d=$d+$row["debit"];
            }
          }    
          //Display table total row
          $this->SetFont('Arial','B',8);
          $this->Cell(110,9,"TOTAL",1,0,"R");
          $this->Cell(40,9,$c,1,0,"C");
          $this->Cell(40,9,$d,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();
}
?>