<?php

include("dbconnect.php");
require("pdf_gen/fpdf.php");
require("word2.php");
class PDF extends FPDF {
	function vcell($c_width,$c_height,$x_axis,$text){
$w_w=$c_height/3;
$w_w_1=$w_w+2;
$w_w1=$w_w+$w_w+$w_w+3;
$len=strlen($text);// check the length of the cell and splits the text into 7 character each and saves in a array 
if($len>113){
$w_text=str_split($text,113);
$this->SetX($x_axis);
$this->Cell($c_width,$w_w_1,$w_text[0],'','','');
$this->SetX($x_axis);
$this->Cell($c_width,$w_w1,$w_text[1],'','','');
$this->SetX($x_axis);
$this->Cell($c_width,$c_height,'','',0,'L',0);
}
else{
    $this->SetX($x_axis);
    $this->Cell($c_width,$c_height,$text,'0',0,'L',0);}
    }
		function vcell1($c_width,$c_height,$x_axis,$text){
$w_w=$c_height/3;
$w_w_1=$w_w+2;
$w_w1=$w_w+$w_w+$w_w+3;
$len=strlen($text);// check the length of the cell and splits the text into 7 character each and saves in a array 
if($len>40){
$w_text=str_split($text,40);
$this->SetX($x_axis);
$this->Cell($c_width,$w_w_1,$w_text[0],'','','');
$this->SetX($x_axis);
$this->Cell($c_width,$w_w1,$w_text[1],'','','');
$this->SetX($x_axis);
$this->Cell($c_width,$c_height,'','',0,'L',0);
}
else{
    $this->SetX($x_axis);
    $this->Cell($c_width,$c_height,$text,'0',0,'L',0);}
    }
	function Header() {
		$y = 47;
            $x = 10;  
            //$this->setXY($x, $y);
            //$pdf->setFont("Arial","I","8");
            $x_axis=100;
            $c_width=60;// cell width 
            $c_height=6;// cell height
include("dbconnect.php");
     	$sql1 = 'SELECT * FROM school_info';

		$result1 = mysqli_query($con,$sql1) or die( "Could not execute sql: $sql");


// build the data array from the database records.

		While($row1 = mysqli_fetch_array($result1)) {

        $data1= $row1['school_name'];
		$data2='P.O BOX '.$row1['address'].' '.$row1['city'];
		$data3='Mobile No: '.$row1['mobile'];
		$data4='Email:'.$row1['email'];
		$data5=$row1['logo'];
		$signa=$row1['signature'];
		$ttype=$row1['type'];
		$dat=date('d-m-Y');
		$data6='LIST OF SUPPLIERS NAMES';
		$data7='----------------------------------------------------------------------------------------------------------------------';

		}
$vrno=@$_GET['trans'];
 $DB="SELECT *,(SELECT academicyear FROM academicyears WHERE academicyears.id=cus_trans.academicyear) AS academicyears,(SELECT fullname FROM customers WHERE customers.cusno=cus_trans.customerrno) AS customername,(SELECT bankname FROM banks WHERE banks.id=cus_trans.bank) AS bankname,(SELECT mode FROM pmodes WHERE pmodes.id=cus_trans.mode) AS mode,(SELECT fullname FROM finance_users WHERE finance_users.id=cus_trans.`user_id`) AS users FROM cus_trans WHERE transid='$vrno'";
$hgghquuery=mysqli_query($con,$DB);
$rooowasss=mysqli_fetch_array($hgghquuery);
$scursno=$rooowasss['customerrno'];
$sasss="SELECT * FROM customers WHERE cusno='$scursno'";
$quuery=mysqli_query($con,$sasss);
$rooow=mysqli_fetch_array($quuery);
        $this->SetFont('Times','',11);

        $w = $this->GetStringWidth($this->title)+150;
		$this->SetFillColor(976,245,458);
		$this->Rect(0, 0, 300, 500, 'F');
        $this->SetTextColor(0);
		//$this->Image($data5,10,15,15,'L');
		$this->Image($data5,75,20,32,'R');
		$this->SetFont('Times','B',18);
       $this->Cell($w,9,$this->title,0,0,'C');
	    $this->Ln(5);
		//$this->SetFillColor(200,120,400);
		//$this->Rect(10, 37, 130, 15, 'F');
       $this->Cell(170,0,$data1 ,0 ,0 ,'C');
	    $this->Ln(15);
		$this->SetFont('Times','',11);
		///$this->Cell(115,0,'Our Ref  ........................' ,0 ,0 ,'L');
	   $this->Cell(110,0,'' ,0 ,0 ,'L');
	    $this->Ln(7);
		$this->Cell(115,0,'' ,0 ,0 ,'L');
	   $this->Cell(170,0,'' ,0 ,0 ,'L');
	    $this->Ln(12);
		//$this->Cell(115,0,'Your Ref   ....................' ,0 ,0 ,'L');
	   $this->Cell(170,0,$data2.', '.$data3.', '.$data4 ,0 ,0 ,'C');
        $this->Ln(4);
		 $this->Cell(-10,1,'',1 ,0 ,'C',1);
		 $this->Cell(210,1,'',1 ,0 ,'C',1);
        $this->Ln(5);
		$this->Cell(115,0,'' ,0 ,0 ,'L');
	   //$this->Cell(170,0,'VOUCHER NO:        #'.$vrno ,0 ,0 ,'L');
		$this->Ln(6);
		$this->Cell(180,0,'RECEIPT OF FUNDS FROM :'.$rooowasss['customername'] ,0 ,0 ,'L');
        $this->Ln(7);
		$ddate=strtotime($rooowasss['created_at']);
		$this->Cell(180,0,'DATE RECEIBED :'.date("Y-m-d",$ddate) ,0 ,0 ,'L');
        $this->Ln(7);
		$this->Cell(180,0,'PAYMENT METHOD :'.$rooowasss['mode'] ,0 ,0 ,'L');
        $this->Ln(7);
		$this->Cell(180,0,'CHEQUE OR REFERENCE NUMBER :'.$rooowasss['code'] ,0 ,0 ,'L');
        $this->Ln(7);
		$this->Cell(180,0,'PAYMENT AMOUNT: '.number_format($rooowasss['amount'],2) ,0 ,0 ,'L');
        $this->Ln(7);
		$this->Cell(180,0,'AMOUNT IN WORDS:' ,0 ,0 ,'L');
        $this->Ln(2);
		$anmmmt=$rooowasss['amount'];
		$this->Cell(180,7,'        #'.convert_number_to_words($anmmmt).' shillings only.#',0 ,0 ,'L');
		$this->Ln(6);
		$this->cell(180,0,'      ..............................................................................................', 0, 1,'L',0);
		$this->Ln(7);
		$this->Cell(180,4,'ACCOUNTS PAID:' ,0 ,0 ,'L');
        $this->Ln(4);
		$this->Cell(60,6,'Account' ,1 ,0 ,'C');
		$this->Cell(60,6,'Votehead' ,1 ,0 ,'C');
		$this->Cell(30,6,'SHS' ,1 ,0 ,'C');
		$this->Cell(30,6,'CTS' ,1 ,0 ,'C');
        $this->Ln(6);
		$totalaa=0;
		$centtotals=0;
		$resqlty=mysqli_query($con,"SELECT *,(SELECT accountname FROM apecialaccounts WHERE apecialaccounts.id=ccustomerslists.main) as maintypename,(SELECT votehead FROM voteheads WHERE voteheads.id=ccustomerslists.votehead) as voteheadname FROM ccustomerslists WHERE trans_id='$vrno'");
		while($rrrowser=mysqli_fetch_array($resqlty)){
			if(substr(($rrrowser['amount']-(int)$rrrowser['amount']),2,2)==""){
			$valluee="00";
			}
			else{
			$valluee=substr(($rrrowser['amount']-(int)$rrrowser['amount']),2,2);
			}
		$val=(int)$rrrowser['amount'];
		$totalaa=$totalaa+$val;
		$centtotals=$centtotals+$valluee;
		$this->Cell(60,7,$rrrowser['maintypename'] ,1 ,0 ,'L');
		$this->Cell(60,7,$rrrowser['voteheadname'] ,1 ,0 ,'L');
		$this->Cell(30,7,number_format((int)$rrrowser['amount'],0) ,1 ,0 ,'R');
		$this->Cell(30,7,$valluee ,1 ,0 ,'C');
        $this->Ln(7);
		}
		$vallll=number_format(((int)$centtotals/100),0);
		$totalscents=(($centtotals/100)-$vallll)*100;
		$tooooottt=$vallll+$totalaa;
		if($totalscents<10){
			$totalscents='0'.$totalscents;
		}
		$this->SetFont('Times','B',11);
		$this->Cell(120,7,'Totals' ,1 ,0 ,'L');
		$this->Cell(30,7,number_format((int)$tooooottt,0) ,1 ,0 ,'R');
		$this->Cell(30,7,$totalscents ,1 ,0 ,'C');
        $this->Ln(7);
        $this->Ln(15);
		$this->Cell(180,6,'RECEIPT PREPARED BY:' ,0 ,0 ,'L');
        $this->Ln(6);
		$this->SetFont('Times','',11);
		$this->Cell(180,6,'Name       '.$rooowasss['users'].'                 Date..................    Sign............' ,0 ,0 ,'L');
        $this->Ln(8);
		$this->SetFont('Times','B',11);
		$this->Cell(180,6,'RECEIPT VERIFIED BY:' ,0 ,0 ,'L');
        $this->Ln(6);
		$this->SetFont('Times','',11);
		$this->Cell(180,6,'Name      .................................................             Date..................    Sign............' ,0 ,0 ,'L');
        $this->Ln(6);

}
}
$pdf = new PDF();
$pdf->SetFont('Arial','',11);
$pdf->setTitle("");
$pdf->AddPage();
$pdf->Output();
?>