<?php 
if(isset($_GET['f_id'])){
  require_once('../../assets/config/config.php');
  $obj=new Database();
  $id=" f_id='".$_GET['f_id']."'";
  $obj->select('students_fee','*',null,$id,null,null);
  $result=$obj->getResult();

  $obj->select('organization','*',null," id=1",null,null);
  $result2=$obj->getResult();
 
  $id="batch_no='".$result[0]['batch_no']."'";
  $paid=$obj->Amount_Count('txn_details',$id,'credit');
  $fee=$obj->Amount_Count('txn_details',$id,'debit');
  $fee=$fee-$paid;

  $obj->select('students_course','*',null,$id,null,null);
  $result1=$obj->getResult();

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

  //customer and invoice details
  $info=[
    "student_name"=>$result[0]['student_name'], 
    "s_id"=>$result[0]['student_id'],
    "batch_no"=>$result[0]['batch_no'],
    "id"=>$result[0]['id'],
    "p_date"=>$result[0]['payment_date'],
    "p_mode"=>$result[0]['payment_mode'],
    "desc"=>$result[0]['description'],
    "amount"=>$result[0]['amount'], 
    "p_amount"=>$fee,
    "course"=>$result1[0]['course_name'], 
  ];
  $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(-60);
      $this->SetFont('Arial','B',20);
      $this->Cell(40,10,"FEE RECIEPT",0,1);
      
      //Display Horizontal line
      $this->Line(0,40,210,40); $this->Line(0,41,210,41);
    }
    
    function body($info,$result2){
     
      //Billing Details
      $this->SetY(44);
      $this->SetX(10);
      $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);
      $this->Cell(50,7,"Batch No   : ".$info["batch_no"],0,1);
      $this->Cell(50,7,"Course Name  : ".$info["course"],0,1);

      
      //Display Invoice no
      $this->SetY(44);
      $this->SetX(-65);
      $this->Cell(50,7,"Reciept No      : ".$info["id"],0,1);

      //Display Invoice date
      $this->SetY(51);
      $this->SetX(-65);
      $this->Cell(50,7,"Payment Date : ".$info["p_date"],0,1);

      $this->SetY(58);
      $this->SetX(-65);
      $this->Cell(50,7,"Due Amount    : ".$info["p_amount"]+$info["amount"],0,1);

      $this->SetY(65);
      $this->SetX(-65);
      $this->Cell(50,7,"Paid Amount   : ".$info["amount"],0,1);
       
      //Display Table headings
      $this->SetDrawColor(20,20,20);
      $this->SetTextColor(20,20,20);
      $this->SetY(75);
      $this->SetX(10);
      $this->SetFont('Arial','B',9);
      $this->Cell(48,9,"Payment Mode",1,0,'C');
      $this->Cell(50,9,"Description",1,0,'C');
      $this->Cell(45,9,"Paid Amount",1,0,'C');
      $this->Cell(47,9,"Due Amount",1,1,'C');

      $this->SetFont('Arial','',8);
      $this->SetX(10);
      $this->Cell(48,9,$info["p_mode"],1,0,'C');
      $this->Cell(50,9,$info["desc"],1,0,'C');
      $this->Cell(45,9,$info["amount"],1,0,'C');
      $this->Cell(47,9,$info["p_amount"],1,1,'C');
      
      //Display amount in words
      $this->SetY(98);
      $this->SetX(10);
      $this->SetFont('Arial','B',10);
      $this->Cell(0,9,"Notice ",0,1);
      $this->SetFont('Arial','',9); $this->SetX(10);
      $this->Cell(0,9,'1. No refund Payment',0,1); $this->SetX(10);

     
    }
      
    function Footer(){
      
      //set footer position
      $this->SetY(100);
      $this->SetFont('Arial','B',10);
      $this->Cell(0,10,"for ".$GLOBALS['org'],0,1,"R");
      $this->Ln(10);
      $this->SetFont('Arial','',10);
      $this->Cell(0,10,"Authorized Signature",0,1,"R");
      $this->SetFont('Arial','',10);
      

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