<?php 

  include '../assets/config/config.php';
  $obj=new Database();
  $id=" batch_no='".$_GET['batch_no']."'";
  $obj->select('students_course','*',null,$id,null,null);
  $result=$obj->getResult();

  $id1=" course_name='".$result[0]['course_name']."'";
  $obj->select('fee','*',null,$id1,null,null);
  $result1=$obj->getResult();
  
  $obj->select('organization','*',null," id=1",null,null);
  $result2=$obj->getResult();


  require ("../assets/fpdf/fpdf.php");

  //customer and invoice details
  $info=[
    "student_name"=>$result[0]['student_name'],
    "address"=>"4th cross,Car Street,",
    "id"=>$result[0]['student_id'],
    "batch_no"=>$result[0]['batch_no'],
    "course_name"=>$result[0]['course_name'],
    "date"=>$result[0]['date'],
    
  ];
  $GLOBALS['org']=$result2[0]['organization'];
 


  $GLOBALS['add']=$result2[0]['address'];
  $GLOBALS['email']=$result2[0]['email'];
  $GLOBALS['mob']=$result2[0]['mob_no'];
  
  class PDF extends FPDF
  {
       
    function Header(){
      $this->SetTextColor(5,76,220);
      //Display Company Info
      $this->SetFont('Arial','B',15);
      $this->Cell(50,10,$GLOBALS['org'],0,1);
      $this->SetFont('Arial','',9);  $this->SetTextColor(5,16,115);
      $this->Cell(50,7,$GLOBALS['add'],0,1);
      $this->Cell(50,7,"PH : ".$GLOBALS['mob']." | Mail : ".$GLOBALS['email'],0,1);
      $this->Cell(50,7,'',0,1);
      
      $this->SetTextColor(45,22,225);
      //Display INVOICE text
      $this->SetY(15);
      $this->SetX(-40);
      $this->SetFont('Arial','B',20);
      $this->Cell(40,10,"INVOICE",0,1);
      
      //Display Horizontal line
      $this->Line(0,48,210,48);
    }
    
    function body($info,$result1){
      
      //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,"Student ID      : ".$info["id"],0,1);
      $this->Cell(50,7,"Student Name : ".$info["student_name"],0,1);

      
      //Display Invoice no
      $this->SetY(55);
      $this->SetX(-65);
      $this->Cell(50,7,"Batch No   : ".$info["batch_no"]);
      
      //Display Invoice date
      $this->SetY(63);
      $this->SetX(-65);
      $this->Cell(50,7,"Course Name : ".$info["course_name"]);

      $this->SetY(71);
      $this->SetX(-65);
      $this->Cell(50,7,"Registration Date : ".$info["date"]);
      $this->SetDrawColor(20,20,20);
      $this->SetTextColor(20,20,20);
      
      //Display Table headings
      $this->SetY(95);
      $this->SetX(20);
      $this->SetFont('Arial','B',9);
      $this->Cell(10,9,"S.N.",1,0);
      $this->Cell(120,9,"Descriptions",1,0);
      $this->Cell(40,9,"Amount",1,1,"C");
      $this->SetFont('Arial','',9);
      $c=0;$count=0;
      
      //Display table product rows
      foreach($result1 as $row){
        $c=$c+1;
        $this->SetX(20);
        $this->Cell(10,9,$c,"LR",0,"C");
        $this->Cell(120,9,$row["fee_type"],"LR",0);
        $this->Cell(40,9,$row["amount"],"R",1,"C");
        $count=$count+$row["amount"];
      }
      //Display table empty rows
       
      for($i=0;$i<12-count($result1);$i++)
      {  
        $this->SetX(20);
        $this->Cell(10,9,"","LR",0);
        $this->Cell(120,9,"","LR",0);
        $this->Cell(40,9,"","R",1,"R");
      }
      //Display table total row
      $this->SetX(20);
      $this->SetFont('Arial','B',9);
      $this->Cell(130,9,"Total",1,0,"R");
      $this->Cell(40,9,$count,1,1,"C");
      
      //Display amount in words
      $this->SetY(225);
      $this->SetX(15);
      $this->SetFont('Arial','B',10);
      $this->Cell(0,9,"Notice ",0,1);
      $this->SetFont('Arial','',9); $this->SetX(15);
      $this->Cell(0,9,'1. Payment Terms Advanced',0,1); $this->SetX(15);
      $this->Cell(0,9,'2. No Refund',0,1);
      
    }
    function Footer(){
      
      //set footer position
      $this->SetY(-50);
      $this->SetFont('Arial','B',10);
      $this->Cell(0,10,"for ".$GLOBALS['org'],0,1,"R");
      $this->Ln(15);
      $this->SetFont('Arial','',10);
      $this->Cell(0,10,"Authorized Signature",0,1,"R");
      $this->SetFont('Arial','',10);
      
      //Display Footer Text
      $this->Cell(0,10,"*This is a computer generated invoice*",0,1,"C");
      
    }
    
  }
  //Create A4 Page with Portrait 
  $pdf=new PDF("P","mm","A4");
  $pdf->AddPage();
  $pdf->body($info,$result1);
  $pdf->Output();
?>