<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();

include("connect.php");
	$pddid=(int)mysqli_real_escape_string($conn,$_GET['id']);
	$_SESSION['pddid']=$pddid;
	
	$eve55 = "select * from res_setting_master where settingmid=1";
		$re55 = mysqli_query($conn, $eve55);
		while($rt55 = mysqli_fetch_assoc($re55))
		{
			$_SESSION['smcmpname']='Future Link';
			
			$_SESSION['smcmpheaderimg']=$rt55['headerimg'];
			$_SESSION['smcmpfooterimg']=$rt55['footerimg'];
		}	
	
require('fpdf.php');

class PDF_MC_Table extends FPDF
{
	var $widths;
	var $aligns;

	function SetWidths($w)
	{
		//Set the array of column widths
		$this->widths=$w;
	}

	function SetAligns($a)
	{
		//Set the array of column alignments
		$this->aligns=$a;
	}

	function Row($data)
	{
		//Calculate the height of the row
		$nb=0;
		for($i=0;$i<count($data);$i++)
			$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
		$h=5*$nb;
		//Issue a page break first if needed
		$this->CheckPageBreak($h);
		//Draw the cells of the row
		for($i=0;$i<count($data);$i++)
		{
			$w=$this->widths[$i];
			$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
			//Save the current position
			$x=$this->GetX();
			$y=$this->GetY();
			//Draw the border
			$this->Rect($x,$y,$w,$h);
			//Print the text
			$this->MultiCell($w,5,$data[$i],0,$a);
			//Put the position to the right of the cell
			$this->SetXY($x+$w,$y);
		}
		//Go to the next line
		$this->Ln($h);
	}

	function CheckPageBreak($h)
	{
		//If the height h would cause an overflow, add a new page immediately
		if($this->GetY()+$h>$this->PageBreakTrigger)
			$this->AddPage($this->CurOrientation);
	}

	function NbLines($w,$txt)
	{
		//Computes the number of lines a MultiCell of width w will take
		$cw=&$this->CurrentFont['cw'];
		if($w==0)
			$w=$this->w-$this->rMargin-$this->x;
		$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
		$s=str_replace("\r",'',$txt);
		$nb=strlen($s);
		if($nb>0 and $s[$nb-1]=="\n")
			$nb--;
		$sep=-1;
		$i=0;
		$j=0;
		$l=0;
		$nl=1;
		while($i<$nb)
		{
			$c=$s[$i];
			if($c=="\n")
			{
				$i++;
				$sep=-1;
				$j=$i;
				$l=0;
				$nl++;
				continue;
			}
			if($c==' ')
				$sep=$i;
			$l+=$cw[$c];
			if($l>$wmax)
			{
				if($sep==-1)
				{
					if($i==$j)
						$i++;
				}
				else
					$i=$sep+1;
				$sep=-1;
				$j=$i;
				$l=0;
				$nl++;
			}
			else
				$i++;
		}
		return $nl;
	}
}
function GenerateWord()
{
    //Get a random word
    $nb=rand(3,10);
    $w='';
    for($i=1;$i<=$nb;$i++)
        $w.=chr(rand(ord('a'),ord('z')));
    return $w;
}

function GenerateSentence()
{
    //Get a random sentence
    $nb=rand(1,10);
    $s='';
    for($i=1;$i<=$nb;$i++)
        $s.=GenerateWord().' ';
    return substr($s,0,-1);
}

/*
$pdf=new PDF_MC_Table();
$pdf->AddPage();
$pdf->SetFont('Arial','',14);
$pdf->SetWidths(array(30,50,30,40));
srand(microtime()*1000000);
for($i=0;$i<20;$i++)
    $pdf->Row(array(GenerateSentence(),GenerateSentence(),GenerateSentence(),GenerateSentence()));
$pdf->Output();

return;
*/


class PDF extends FPDF
{


var $widths;
	var $aligns;

	function SetWidths($w)
	{
		//Set the array of column widths
		$this->widths=$w;
	}

	function SetAligns($a)
	{
		//Set the array of column alignments
		$this->aligns=$a;
	}

	function Row($data)
	{
		//Calculate the height of the row
		$nb=0;
		for($i=0;$i<count($data);$i++)
			$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
		$h=5*$nb;
		//Issue a page break first if needed
		$this->CheckPageBreak($h);
		//Draw the cells of the row
		for($i=0;$i<count($data);$i++)
		{
			$w=$this->widths[$i];
			$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
			//Save the current position
			$x=$this->GetX();
			$y=$this->GetY();
			//Draw the border
			$this->Rect($x,$y,$w,$h);
			//Print the text
			$this->MultiCell($w,5,$data[$i],0,$a);
			//Put the position to the right of the cell
			$this->SetXY($x+$w,$y);
		}
		//Go to the next line
		$this->Ln($h);
	}

	function CheckPageBreak($h)
	{
		//If the height h would cause an overflow, add a new page immediately
		if($this->GetY()+$h>$this->PageBreakTrigger)
			$this->AddPage($this->CurOrientation);
	}

	function NbLines($w,$txt)
	{
		//Computes the number of lines a MultiCell of width w will take
		$cw=&$this->CurrentFont['cw'];
		if($w==0)
			$w=$this->w-$this->rMargin-$this->x;
		$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
		$s=str_replace("\r",'',$txt);
		$nb=strlen($s);
		if($nb>0 and $s[$nb-1]=="\n")
			$nb--;
		$sep=-1;
		$i=0;
		$j=0;
		$l=0;
		$nl=1;
		while($i<$nb)
		{
			$c=$s[$i];
			if($c=="\n")
			{
				$i++;
				$sep=-1;
				$j=$i;
				$l=0;
				$nl++;
				continue;
			}
			if($c==' ')
				$sep=$i;
			$l+=$cw[$c];
			if($l>$wmax)
			{
				if($sep==-1)
				{
					if($i==$j)
						$i++;
				}
				else
					$i=$sep+1;
				$sep=-1;
				$j=$i;
				$l=0;
				$nl++;
			}
			else
				$i++;
		}
		return $nl;
	}


function LoadData($file)
{
    // Read file lines
    $lines = file($file);
    $data = array();
    foreach($lines as $line)
        $data[] = explode(';',trim($line));
    return $data;
}
// Page header
function Header()
{
	
	/* $headerimg=$_SESSION['headerimg']; */
	if ($this->page > 1)
	{
		$this->Ln(1);
	}
	else
	{
		$headerimg='images/'.$_SESSION['smcmpheaderimg'];
	if(strlen($headerimg)>5){
		$header = "$headerimg";
		$this->Image("$header",8,6,194,30);
	}
	}
}

// Page footer
function Footer()
{
	/* $footerimg=$_SESSION['footerimg']; */
	$footerimg='images'.$_SESSION['smcmpfooterimg'];
	$footerimg='';
	if(strlen($footerimg)>5){
		$footer = "$footerimg";
		$this->Image("$footer",10,270,190,15);
 	}
}


function ImprovedTable_3()
{
	$kindatten="";
		$w = array(95,95);
		$this->Ln(0);
		$this->SetFont('Arial','',12);
		if($kindatten=='')
		{
		}
		else
		{
			$this->Cell(190,5,"Kind Attn. $kindatten",0,0,'C');
		}
		$_SESSION['disc1']="";
		$disc1=strip_tags($_SESSION['disc1']);
		if($disc1=="")
		{
		}
		else
		{
			$this->SetFont('Arial','B',10);
			$this->Cell(10,5,'',0,0,'L');
			$this->Ln();
			$this->SetFont('Arial','',10);
			$this->MultiCell(0,5,"$disc1");
			$this->SetLineWidth(.3);
			$this->Ln();
		}
}

function ImprovedTable2_9()
{



	

		$qterms="I Fully Understand That:
1) It's My Duty to Understand the Charges and Payment at The Time of Enrolment.
2) The Fees Can Be Paid Either Partially or Fully.
3) If Part Payment Is Made, Remaining Amount Should Be Cleared in Next Seven (7) Days Immediately. Otherwise
Consultancy Has A Right to Cancel My Process.
4) If Part Payment Is Made the Amount Will Not Be Refunded Under Any Circumstances.
5) Consulting Fee Paid by One Client Cannot Be Transferred to Another Client Neither Partially nor Fully.
6) Consultancy fees Will Not Be Re Refunded After 3 Days of Payment.
* Refund Policy: Deduction Of 20% Admin Charges Up to 72hrs
7) Fees Will Be Charged Extra If Any Other Service Is Requested by The Candidate Except Those Stated in The
 Contract / Receipt.
8) Consulting Fee Will Not Be Refunded in Case of Any Visa / Admission Rejection.
";
		if($qterms=="")
			{

			}
			else
			{
$w = array(15,20,20,20,40,20,15,20,20);
$this->Ln(6);
$this->SetWidths(array(190));
		$this->SetAligns(array('C'));
		$this->SetFont('Arial','B',10);
		$this->Cell(10,5,'Terms & Conditions',0,0,'L');
		$this->Ln();
		$this->SetFont('Arial','',10);
		$this->MultiCell(0,5,"$qterms");
		$this->SetLineWidth(.3);
        $this->Ln();
		$this->Cell(array_sum($w),0,'','T');
	$this->Ln();
			}




    //}
    // Closing line

}

function ImprovedTable_4()
{
	include "connect.php";
	$w = array(15,20,20,20,40,20,15,20,20);
	
	$this->Ln(30);
		$this->SetWidths(array(50,140));
		$this->SetAligns(array('C','C'));
		//$this->SetFillColor(128, 0, 0);
		$this->SetFont('Arial','B',10);
		
		$this->SetFont('Arial','',10);
		$this->SetAligns(array('C','L','R','R','L','L','R','R'));
		$pddid = $_SESSION['pddid'];
		$eve = "SELECT * from res_payments_detail WHERE pddid=$pddid";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		while($rtpay = mysqli_fetch_assoc($re))
		{
			$pddid=$rtpay['pddid'];
															$isdid=$rtpay['isdid'];
															$paycurrency=$rtpay['paycurrency'];
															$imid=$rtpay['imid'];
															$_SESSION['imid']=$rtpay['imid'];
															$companymid=$rtpay['companymid'];
															$bankmid=$rtpay['bankmid'];
															$pddocname=$rtpay['pddocname'];
															$paymode=$rtpay['paymode'];
															$paidamount=$rtpay['paidamount'];
															if($rtpay['paydate'] == '0000-00-00')
															{
																$paydate='';
															}else{
															$paydate=date("d-m-Y", strtotime($rtpay['paydate']));
															}
															 $eve25 = "select *  from res_inquiry_master where imid='$imid'";
															$re25 = mysqli_query($conn, $eve25);
															
															while($rt26 = mysqli_fetch_assoc($re25))
															{
															$ipname=$rt26['ipname'];
				$ipmiddlename=$rt26['ipmiddlename'];
				$ipsurname=$rt26['ipsurname'];
				$name=$ipname." ".$ipmiddlename." ".$ipsurname;
				$ipaddress=$rt26['ipaddress'];
				$ipostcode=$rt26['ipostcode'];
				$ipemail=$rt26['ipemail'];
				$inqbranch=$rt26['inqbranch'];
				$ipmobile=$rt26['ipmobile'];
				$ipbirthcountry=$rt26['ipbirthcountry'];
				$ibirthstate=$rt26['ibirthstate'];
				$ipbirthcity=$rt26['ipbirthcity'];
				$ipcouncellor=$rt26['ipcouncellor'];
				$address = $ipaddress.",".$ipbirthcity."-".$ipostcode.",".$ibirthstate.",".$ipbirthcountry;
				$eve3 = "select * from res_branch_master  where branchmid=$inqbranch";
				$re3 = mysqli_query($conn, $eve3);
				if(mysqli_num_rows($re3)>0)
				{
					while($rt3 = mysqli_fetch_assoc($re3))
				{
					
					$branchname=$rt3['branchname'];
				}
				}
				else
				{
					$branchname="";
				}
				$tt1='';
				$eve1 = "select * from res_user_master  where umid=$ipcouncellor";
				$re1 = mysqli_query($conn, $eve1);
				while($rt1 = mysqli_fetch_assoc($re1))
				{
					$tt1=$rt1['ufullname'];										
				}
				
															}
															 $eve25 = "select *  from res_paymentmode_master where paymentmodemid='$paymode'";
															$re25 = mysqli_query($conn, $eve25);
															$paymentmodename='';
															$pmodechargetype='';
															$pmodecharge='';
															while($rt25 = mysqli_fetch_assoc($re25))
															{
															$paymentmodename=$rt25['paymentmodename'];
															 $pmodechargetype=$rt25['pmodechargetype'];
															$pmodecharge=$rt25['pmodecharge'];
															}
															$paymodec = $pmodecharge ." (".$pmodechargetype.")";
															$pfinalpayamount=$rtpay['pfinalpayamount'];
															
															
															
															$payremark=$rtpay['payremark'];
															$pdaddedon=date("d-m-Y",strtotime($rtpay['pdaddedon']));
$pdaddedby=$rtpay['pdaddedby'];
$pdupdatedon=date("d-m-Y",strtotime($rtpay['pdupdatedon']));
$pdupdatedby=$rtpay['pdupdatedby'];

$ufullname='';
$utype='';
$evea1 = "select ufullname,utype from res_user_master where umid=$pdaddedby";
$rea1 = mysqli_query($conn, $evea1);
if(mysqli_num_rows($rea1) > 0)
{
	while($rta1 = mysqli_fetch_assoc($rea1))
	{
		$ufullname=$rta1['ufullname'];
		$utype=$rta1['utype'];
	}
}

$ufullname1='';
$utype1='';
if($pdupdatedby != 0)
{
$evea1 = "select ufullname,utype from res_user_master where umid=$pdupdatedby";
$rea1 = mysqli_query($conn, $evea1);
if(mysqli_num_rows($rea1) > 0)
{
	while($rta1 = mysqli_fetch_assoc($rea1))
	{
		$ufullname1=$rta1['ufullname'];
		$utype1=$rta1['utype'];
	}
}
}else{
$pdupdatedon='';
}
															$total=0;
															
															
															$companyname='';
															$eve22 = "select companyname  from res_company_master where companymid=$companymid";
															$re22 = mysqli_query($conn, $eve22);
															
															while($rt22 = mysqli_fetch_assoc($re22))
															{
															$companyname=$rt22['companyname'];
															}
															
															$eve23 = "select bankname  from res_bank_master where bankmid=$bankmid";
															$re23= mysqli_query($conn, $eve23);
															$bankname='';
															while($rt23 = mysqli_fetch_assoc($re23))
															{
															$bankname=$rt23['bankname'];
															}
															
															
															$eve212="select * from res_inquiryservice_detail where  res_inquiryservice_detail.isdid=$isdid";
															$re212=mysqli_query($conn,$eve212);
															$servicename="";
															while($rt212= mysqli_fetch_assoc($re212))
															{
																$ptype=$rt212['ptype'];
															$packagename='';
								if($ptype == 'Branch' || $ptype == 'Country')
								{
									$packagemid=$rt212['packagemid'];
									 $evea3 = "select packagename from res_package_master where packagemid=$packagemid";
									$rea3 = mysqli_query($conn, $evea3);
									if(mysqli_num_rows($rea3) > 0)
									{
									while($rta3 = mysqli_fetch_assoc($rea3))
									{
										$packagename=$rta3['packagename'];
										
									}
									}
								}else if($ptype == 'Application'){
									$clgappmid=$rt212['linkmid'];
									$eve23 = "select * from res_course_master,res_collegeapp_master where res_collegeapp_master.coursemid = res_course_master.coursemid  and  res_collegeapp_master.imid=$imid and  res_collegeapp_master.clgappmid=$clgappmid";
$cmname='';
$coursename="";
									$re23 = mysqli_query($conn, $eve23);

									while($rt23 = mysqli_fetch_assoc($re23))

									{

									$collegemid=$rt23['collegemid'];
									$collegemid=$rt23['collegemid'];
									$cnmid=$rt23['cnmid'];
									$clgappmid=$rt23['clgappmid'];
									
					$eve55= "select * from   res_coursename_master where cnmid=$cnmid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$coursename=$rt55['coursename'];
						
					}
					
						$eve55= "select * from   res_college_master where collegemid=$collegemid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$cmname=$rt55['cmname'];
						
					}
									

								}
								$packagename = $cmname."-".$coursename." application";
								}else if($ptype == 'Book Lost'){
									$bookmid=$rt212['linkmid'];
									$eve78 = "select bookname,bookprice from res_book_master where  bookmid=$bookmid";
									$re78 = mysqli_query($conn, $eve78);
									if(mysqli_num_rows($re78) > 0)
									{
										while($rt78 = mysqli_fetch_assoc($re78))
										{
											$bookname=$rt78['bookname'];
											
											
										}
									}
									$packagename = $bookname." Lost";
								}else if($ptype == 'College Admission'){
									$admid=$rt212['linkmid'];
										$eve23 = "select * from res_course_master,res_admission_master where res_admission_master.coursemid = res_course_master.coursemid  and  res_admission_master.imid=$imid and  res_admission_master.admid=$admid";

									$re23 = mysqli_query($conn, $eve23);

									while($rt23 = mysqli_fetch_assoc($re23))

									{

									$collegemid=$rt23['collegemid'];
									$collegemid=$rt23['collegemid'];
									$cnmid=$rt23['cnmid'];
									$admid=$rt23['admid'];
									$coursename="";
					$eve55= "select * from   res_coursename_master where cnmid=$cnmid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$coursename=$rt55['coursename'];
						
					}
						$eve55= "select * from   res_college_master where collegemid=$collegemid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$cmname=$rt55['cmname'];
						
					}
									

								}
								$packagename = $cmname."-".$coursename." Admission";
								}
								
															}
															$evepd = "select *, sum(servicefees) as totalamount from res_inquiryservice_detail where imid=$imid";
															$repd = mysqli_query($conn, $evepd);
															$servicefees=0;
															$totalamount=0;
															while($rtpd = mysqli_fetch_assoc($repd))
															{
															$servicefees=$rtpd['servicefees'];
															$totalamount=$rtpd['totalamount'];
															}
															
															$payrecived='';
															if($rtpay['pdstatus'] != 'Recevied')
															{
															$payrecived = ' <a href="#" data-bs-toggle="modal" data-bs-target="#view-modal2" class="badge badge-primary"  data-id="'.$pddid.'" id="getUser2">Pending</a>';
															}
										$this->Row(array("Date",$pdaddedon));
		$this->Row(array("Receipt NO",$pddid));
		$this->Row(array("Name",$ipname));
		$this->Row(array("address",$address));
		$this->Row(array("Mobile No",$ipmobile));
		$this->Row(array("Email ID",$ipemail));
		$this->Row(array("Branch",$branchname));
		$this->Row(array("Concelor Name",$tt1));
		$this->Row(array("Package",$packagename));
		$this->Row(array("Company",$companyname));
		$this->Row(array("Bank",$bankname));
		$this->Row(array("Amount",$paidamount));
		$this->Row(array("Currency",$paycurrency));
		$this->Row(array("Mode of Payment",$paymentmodename));
		$this->Row(array("Payment Mode Charge",$paymodec));
		$this->Row(array("Final Payment Amount",$pfinalpayamount));
		$this->Row(array("Recevied By",$ufullname1));
		
		
		
	}
	}
		
    $this->Cell(array_sum($w),0,'','T');
	$this->Ln();
}
function ImprovedTable_2()
{
	
	include('connect.php');
		$campusmid1 = $_SESSION['campusmid'];;
		$invoiceno = $_SESSION['invoiceno'];;
		$invoicemid = $_GET['id'];;
	$eve22 = "select campusname,cmname,countryname from res_collegecampus_master,res_college_master,res_country_master where res_collegecampus_master.collegemid = res_college_master.collegemid and res_college_master.countrymid = res_country_master.countrymid and res_collegecampus_master.ccampusmid = $campusmid1";
											$re22 = mysqli_query($conn, $eve22);
											while($rt22 = mysqli_fetch_assoc($re22))
										{
											$campusname = $rt22['campusname'];
											$cmname = $rt22['cmname'];
											$countryname = $rt22['countryname'];
										}
	
	$invoicedate = $_SESSION['imaddedon'];
	$invoicecurrency = $_SESSION['invoicecurrency'];
	$this->Ln(35);
    $w = array(95,95);
	$this->SetFont('Arial','B',10);
	$this->SetLineWidth(.3);
	$this->Cell($w[0],6,"$campusname",'LRT');
	$this->SetFont('Arial','B',10);
	/* $this->Cell($w[1],6,"Invoice Number: $invoicefordisplay      Date: $invoicedate",'LRT'); */
	$this->Cell($w[1],6,"Invoice Number: $invoiceno",'LRT');

	$this->Ln();
	$this->SetFont('Arial','',10);
	$this->Cell($w[0],6,"College: $cmname",'LR');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Invoice Date: $invoicedate",'LR');
	$this->SetFont('Arial','',10);
	
	$this->Ln();
	$this->Cell($w[0],6,"Country: $countryname",'LRB');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Currency: $invoicecurrency",'LRB');
	$this->SetFont('Arial','B',10);
	
	$this->Ln();
	
	$this->Ln(6);
	/* $this->Ln(15); */
	
    $this->Cell(array_sum($w),0,'','T');
	$this->Ln();
}
function ImprovedTable_5()
{ $w = array(136,31,23);
		
		/* $amount = $_SESSION['omamount'];
		$_SESSION['cmpdetail5']="";
		$cmpdetail5=$_SESSION['cmpdetail5'];
		setlocale(LC_MONETARY, 'en_IN');
		//$pckamt = money_format('%!i', $amount);
		$pckamt = number_format($amount,2,'.','');
		$this->SetFont('Arial','',10);
		$this->SetLineWidth(.3);
        $this->Cell($w[0],6,"$cmpdetail5",'L');
		$this->Cell($w[1],6,"Sub-Total",'LRTB',0,'R');
		$this->Cell($w[2],6,"$pckamt",'LRTB',0,'R');
        $this->Ln(); */
}

function ImprovedTable_6()
{ $w = array(138,29,23);
	
	$_SESSION['cmpstate']="";

	
}

function ImprovedTable_7()
{ $w = array(136,31,23);


			$invoiceamount =$_SESSION['invoiceamount'];
			$itaxincexc =$_SESSION['itaxincexc'];
			$itaxname =$_SESSION['itaxname'];
			$itaxpercent =$_SESSION['itaxpercent'];
			$invoicetotalamount =$_SESSION['invoicetotalamount'];
			

		
		setlocale(LC_MONETARY, 'en_IN');
		//$gt1 = money_format('%!i', $invoicenetamount);
		$gt1 = number_format($invoicetotalamount,2,'.','');
		
		//$qroundoffamount = money_format('%!i', $qroundoffamount);
		$qroundoffamount = 0;
		$amountinwords =  convert_number_to_words($gt1);
		
		$this->SetFont('Arial','',7);
		$this->SetLineWidth(.3);
		$this->SetFont('Arial','B',9);
		$this->Cell($w[0],6,"",'LRB',0,'R');
		$this->Cell($w[1],6,"Total Amount",'LRTB',0,'R');
		$this->Cell($w[2],6,"$invoiceamount",'LRTB',0,'R');
		$this->SetFont('Arial','',9);
		$this->Ln();
		if($itaxincexc == 'Excluded')
		{
		$this->Cell($w[0],6,"",'LRB',0,'R');
		$this->Cell($w[1],6,"$itaxname",'LRTB',0,'R');
		$this->Cell($w[2],6,"$itaxpercent %",'LRTB',0,'R');
		$this->SetFont('Arial','',10);
		$this->Ln();
		}
		
		$this->Cell($w[0],6,"",'LRB',0,'R');
		$this->Cell($w[1],6,"Final Comission",'LRTB',0,'R');
		$this->Cell($w[2],6,"$invoicetotalamount ",'LRTB',0,'R');
		$this->SetFont('Arial','',10);
		$this->Ln();
		
		$w = array(190,0);

		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
        $this->Cell($w[0],6,"Amount In Words",'LRT');
		$this->Ln();
		$this->SetFont('Arial','',10);
		$this->Cell($w[0],4,"$amountinwords",'LR');
		$this->Ln();
		
		$this->SetFont('Arial','',10);
		$this->Cell($w[0],4,"",'LR');
		$this->Ln();
		
		
		
}
function ImprovedTable_1()
{
	 $this->Ln(30);
	$this->SetFont('Arial','B',15);
	$this->Cell(190,5,"Order Invoice",0,0,'C');
    $this->Ln(6);

}
function ImprovedTable_8()
{
  
}

function ImprovedTable_10()
{
    $w = array(95,95);
	$cmpname=$_SESSION['smcmpname'];
	$createdby="";
	$this->SetFont('Arial','B',10);
	$this->Cell(190,5,"For: $cmpname",'LR',0,'R');
	$this->Ln();
	
	$this->SetFont('Arial','B',10);
	$this->Cell(190,5,"$createdby",'LR',0,'R');
	$this->Ln();
	
	$this->SetFont('Arial','B',10);
	//$this->Cell(190,5,"$createdby",'LRB',0,'R');
	$this->Cell(190,5,"AUTHORISED SIGNATURE",'LRB',0,'R');
	$this->SetLineWidth(.3);		
		
}
}

function convert_number_to_words($myno,$part2=1)
{
   $number = $myno;
   $no = (int)($number);
   $point = round($number - $no, 2) * 100;
   $point = number_format($point, 2);;
   $hundred = null;
   $digits_1 = strlen($no);
   $i = 0;
   $str = array();
   $words = array('0' => '',
   '1' => 'One',
   '2' => 'Two',
    '3' => 'Three',
	'4' => 'Four',
	'5' => 'Five',
	'6' => 'Six',
    '7' => 'Seven',
	'8' => 'Eight',
	'9' => 'Nine',
    '10' => 'Ten',
	'11' => 'Eleven',
	'12' => 'Twelve',
    '13' => 'Thirteen',
	'14' => 'Fourteen',
    '15' => 'Fifteen',
	'16' => 'Sixteen',
	'17' => 'Seventeen',
    '18' => 'Eighteen',
	'19' =>'Nineteen',
	'20' => 'Twenty',
    '30' => 'Thirty',
	'40' => 'Forty',
	'50' => 'Fifty',
    '60' => 'Sixty',
	'70' => 'Seventy',
    '80' => 'Eighty',
	'90' => 'Ninety');
   $digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
   while ($i < $digits_1) {
     $divider = ($i == 2) ? 10 : 100;
     $number = floor($no % $divider);
     $no = floor($no / $divider);
     $i += ($divider == 10) ? 1 : 2;
     if ($number) {
        $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
        $str [] = ($number < 21) ? $words[$number] .
            " " . $digits[$counter] . $plural . " " . $hundred
            :
            $words[floor($number / 10) * 10]
            . " " . $words[$number % 10] . " "
            . $digits[$counter] . $plural . " " . $hundred;
     } else $str[] = null;
  }
  $str = array_reverse($str);
  $result = implode('', $str);
  /* $points = ($point) ?"." . $words[$point / 10] . " " .
          $words[$point = $point % 10] : '';
 */

	$tnumber = $myno;

	$whole = floor($tnumber);
	$fraction = ($tnumber - $whole)*100;
	$currency = $_SESSION['invoicecurrency'];

	if($fraction>0.00)
	{
		$pointvalue = convert_number_to_words( (int)$fraction,-7);

		return $result . ".".$pointvalue." ".$currency;
	}
	else if($part2==-7)
	{
		return $result." ".$currency;
	}
	else
	{
		return $result.".";

	}
}

function convert_number_to_words2($number) {

    $hyphen      = '-';
    $conjunction = ' and ';
    $separator   = ' ';
    $negative    = 'negative ';
    $decimal     = ' and ';
    $dictionary  = array(
        0                   => 'Zero',
        1                   => 'One',
        2                   => 'Two',
        3                   => 'Three',
        4                   => 'Four',
        5                   => 'Five',
        6                   => 'Six',
        7                   => 'Seven',
        8                   => 'Eight',
        9                   => 'Nine',
        10                  => 'Ten',
        11                  => 'Eleven',
        12                  => 'Twelve',
        13                  => 'Thirteen',
        14                  => 'Fourteen',
        15                  => 'Fifteen',
        16                  => 'Sixteen',
        17                  => 'Seventeen',
        18                  => 'Eighteen',
        19                  => 'Nineteen',
        20                  => 'Twenty',
        30                  => 'Thirty',
        40                  => 'Fourty',
        50                  => 'Fifty',
        60                  => 'Sixty',
        70                  => 'Seventy',
        80                  => 'Eighty',
        90                  => 'Ninety',
        100                 => 'Hundred',
        1000                => 'Thousand',
        1000000             => 'Million',
        1000000000          => 'Billion',
        1000000000000       => 'Trillion',
        1000000000000000    => 'Quadrillion',
        1000000000000000000 => 'Quintillion'
    );

    if (!is_numeric($number)) {
        return false;
    }

    if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
        // overflow
        trigger_error(
            'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
            E_USER_WARNING
        );
        return false;
    }

    if ($number < 0) {
        return $negative . convert_number_to_words2(abs($number));
    }

    $string = $fraction = null;

    if (strpos($number, '.') !== false) {
        list($number, $fraction) = explode('.', $number);
    }

    switch (true) {
        case $number < 21:
            $string = $dictionary[$number];
            break;
        case $number < 100:
            $tens   = ((int) ($number / 10)) * 10;
            $units  = $number % 10;
            $string = $dictionary[$tens];
            if ($units) {
                $string .= $hyphen . $dictionary[$units];
            }
            break;
        case $number < 1000:
            $hundreds  = $number / 100;
            $remainder = $number % 100;
            $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
            if ($remainder) {
                $string .= $conjunction . convert_number_to_words2($remainder);
            }
            break;
        default:
            $baseUnit = pow(1000, floor(log($number, 1000)));
            $numBaseUnits = (int) ($number / $baseUnit);
            $remainder = $number % $baseUnit;
            $string = convert_number_to_words2($numBaseUnits) . ' ' . $dictionary[$baseUnit];
            if ($remainder) {
                $string .= $remainder < 100 ? $conjunction : $separator;
                $string .= convert_number_to_words2($remainder);
            }
            break;
    }

    if (null !== $fraction && is_numeric($fraction)) {
        $string .= $decimal;
        $words = array();
        foreach (str_split((string) $fraction) as $number) {
            $words[] = $dictionary[$number];
        }
        $string .= implode(' ', $words);
    }

    return $string;
}


// Instanciation of inherited class
$pdf = new PDF();
$header = array();
$pdf->AliasNbPages();
$pdf->AddPage();

//$pdf->ImprovedTable_2();

$pdf->ImprovedTable_4();
$pdf->ImprovedTable2_9();


//$pdf->ImprovedTable_7();

//$pdf->ImprovedTable_9();
$pdf->ImprovedTable_10();
$pdf->SetFont('Times','',12);
//$pdf->Output();
//$settingtype = $_SESSION['settingtype'];
$_SESSION['pddid'] = $_GET['id'];
$pddid = $_SESSION['pddid'];

$imid = $_SESSION['imid'];

$pdf->Output('F',"paymentreceipt/$pddid.pdf");

//return;

header("Location: paymentlist.php");
?>
