
<?php 
  require ("fpdf.php");

error_reporting(E_ALL);
ini_set('display_errors', 1);

  class PDF extends FPDF
  {
    function Header(){
    // Logo
    $this->Image('logo_bpms.jpg',85,2,40);
    //Display Company Info
      $this->SetFont('Arial','B',10);
      $this->Cell(30, 7, "", 0, 1);
      $this->Cell(50,7,"BAASHYAAM CONSTRUCTIONS PVT. LTD.",0,1);
      $this->SetFont('Arial','',10);
      $this->Cell(50,7,"No 87 G.N.Chetty Road, 3rd & 4th Floor,",0,1);
      $this->Cell(50,7,"T.Nagar, Chennai, 600 017.",0,1);
      $this->Cell(50,7,"Near Accord Metropolitan Hotel",0,1);
    //Display INVOICE text
      $this->SetY(15);
      $this->SetX(-40);
      $this->SetFont('Arial','B',18);
      $this->Cell(50,10,"INVOICE",0,1);
      //Display Horizontal line
      $this->Line(0,48,210,48);
    }
    function body($info,$products_info){
      //Billing Details
      $this->SetY(55);
      $this->SetX(10);
      $this->SetFont('Arial','B',12);
      $this->Cell(50,10,"Bill To: ",0,1);
      $this->SetFont('Arial','',10);
      $this->Cell(50,7,$info["customer"],0,1);
      $this->Cell(50,7,$info["address1"],0,1);
      $this->Cell(50,7,$info["address2"],0,1);
      $this->Cell(50,7,$info["mobno"],0,1);
      //Display Invoice no
      $this->SetY(55);
      $this->SetX(-70);
      $this->SetFont('Arial','B',11);
      $this->Cell(50,7,"SRQ ID : ".$info["invoice_no"]);
      //Display Invoice date
      $this->SetFont('Arial','',11);
      $this->SetY(63);
      $this->SetX(-70);
      $this->Cell(50,7,"Date    : ".$info["date"]);
      $this->SetFont('Arial','B',11);
      $this->SetY(71);
      $this->SetX(-70);
      $this->Cell(50,7,"Service Request : ".$info["service_request"]);
      //Display Table headings
      $this->SetY(95);
      $this->SetX(10);
      $this->SetFont('Arial','B',12);
      $this->Cell(100,9,"DESCRIPTION",1,0,'C');
      $this->Cell(90,9,"TOTAL",1,1,"C");
      $this->SetFont('Arial','',12);
    foreach ($products_info as $row) {
        // Extract product information dynamically
        $this->SetFont('Arial','',10);
        foreach ($row as $name => $total) {
            $this->Cell(100, 9, $name, "LR", 0);
            $this->Cell(90, 9, $total, "R", 1, "C");
        }
    }
      //Display table empty rows
      for($i=0;$i<4-count($products_info);$i++)
      {
        $this->Cell(100,9,"","LR",0);
        $this->Cell(90,9,"","R",1,"R");
      }
      //Display table total row
      $this->SetFont('Arial','B',12);
      $this->Cell(150,9,"TOTAL",1,0,"R");
      $this->Cell(40,9,$info["total_amt"],1,1,"R");
    }
    function Footer(){
      //set footer position
      $this->SetY(-50);
      $this->Ln(15);
      $this->SetFont('Arial','',10);
      //Display Footer Text
      $this->Cell(0,10,"This is a computer generated invoice",0,1,"C");
      
    }
    
  }
?> 
  
  