<?php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include("connect.php");
	$coursemid="1,2";
	$eve_header="select * from res_setting_master";
	$re_header = mysqli_query($conn, $eve_header);
	while($rt_header = mysqli_fetch_assoc($re_header))
	{
		$headerimg=$rt_header['headerimg'];
		$footerimg=$rt_header['footerimg'];
		$pdfheaderline1=$rt_header['pdfheaderline1'];
		$footertext=$rt_header['footertext'];
		
	}
	$_SESSION['headerimg']=$headerimg;
	$_SESSION['footerimg']=$footerimg;
	$_SESSION['pdfheaderline1']=$pdfheaderline1;
	$_SESSION['footertext']=$footertext;
	
	
require('fpdf/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);
		 $this->Ln(30);
	}

	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(strlen($headerimg)>5){
		$header = "images/$headerimg";
		$this->Image("$header",8,6,194,30);
	}
	$this->Ln(30);
}

// Page footer
function Footer()
{
	$this->Ln(50);
	$footerimg=$_SESSION['footerimg'];
	
	if(strlen($footerimg)>5){
		$footer = "images/$footerimg";
		$this->Image("$footer",10,270,190,15);
 	}
}
function ImprovedTable_1()
{
	$pdfheaderline1=$_SESSION['pdfheaderline1'];
	 
	$this->SetFont('Arial','B',15);
	$this->Cell(190,5,$pdfheaderline1,0,0,'C');
    $this->Ln(6);
	global $conn;
	$ccount=1;
		$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('L','L'));
		$coursemid = $_SESSION['scoursemid'];
		$placeholders = implode(',', $coursemid);
		$eve = "select * from res_course_master where coursemid in ($placeholders)";
		$re = mysqli_query($conn, $eve);
		while($rt = mysqli_fetch_assoc($re))
		{
			$coursemid=$rt['coursemid'];
				$cnmid=$rt['cnmid'];
				
				$cprogramcode=$rt['cprogramcode'];
				$cprogramcategory=$rt['cprogramcategory'];
				$losmid=$rt['levelofstudy'];
				$cprogramlength=$rt['cprogramlength'];
				$cprogramlanguage=$rt['cprogramlanguage'];
				$cprogramtype=$rt['cprogramtype'];
				$cprogramdelivery=$rt['cprogramdelivery'];
				$programurl=$rt['programurl'];
				$costofliving=$rt['costofliving'];
				$cprogramavailibilty=$rt['cprogramavailibilty'];
				
				$cappurllink=$rt['cappurllink'];
				$cconditionalacceptence=$rt['cconditionalacceptence'];
				$chighlycompetitive=$rt['chighlycompetitive'];
				$cmdesc=$rt['cmdesc'];
				$cpercentage=$rt['cpercentage'];
				$cbacklogaccepted=$rt['cbacklogaccepted'];
				$cedugapaccepted=$rt['cedugapaccepted'];
				$captitudeeligibilty=$rt['captitudeeligibilty'];
				$captitudescore=$rt['captitudescore'];
				$feesin=$rt['feesin'];
				$capplicationfee=$rt['capplicationfee'];
				$cregifees1=$rt['cregifees1'];
				$cregifees=$rt['cregifees'];
				$ctutionfees=$rt['ctutionfees'];
				$ctutionfeesin=$rt['ctutionfeesin'];
				$cgrossfees=$rt['cgrossfees'];
				$cscholorship=$rt['cscholorship'];
				$csubmissiondeadline=$rt['csubmissiondeadline'];
				$cjobprospect=$rt['cjobprospect'];
				$cavgannualsalary=$rt['cavgannualsalary'];
				$countrymid=$rt['countrymid'];
				$campusmid=$rt['campusmid'];
				$cprocessingtime =$rt['cprocessingtime'];
				$cedugapaccepted =$rt['cedugapaccepted'];
				
				
				$countryname='';
				
				$eve2 = "select * from res_country_master where countrymid ='$countrymid'";
				
				$re2 = mysqli_query($conn, $eve2);
				
				if(mysqli_num_rows($re2) > 0)
				{
					
					while($rt2 = mysqli_fetch_assoc($re2))
					{
							$countryname=$rt2['countryname'];
					}
				}
				$collegemid=$rt['collegemid'];
				
				$sname='';
				
				$eve2 = "select * from res_college_master where collegemid ='$collegemid'";
				
				$re2 = mysqli_query($conn, $eve2);
				
				if(mysqli_num_rows($re2) > 0)
				{
					
					while($rt2 = mysqli_fetch_assoc($re2))
					{
							$cmname=$rt2['cmname'];
					}
				}
				$campusname='';
				
				
				
				$eve2 = "select * from res_collegecampus_master where ccampusmid ='$campusmid'";
				
				$re2 = mysqli_query($conn, $eve2);
				
				if(mysqli_num_rows($re2) > 0)
				{
					
					while($rt2 = mysqli_fetch_assoc($re2))
					{
							$campusname=$rt2['campusname'];
					}
				}
				
				
				
				$coursename='';
				
				$eve2 = "select * from res_coursename_master where cnmid ='$cnmid'";
				
				$re2 = mysqli_query($conn, $eve2);
				
				if(mysqli_num_rows($re2) > 0)
				{
					
					while($rt2 = mysqli_fetch_assoc($re2))
					{
							$coursename=$rt2['coursename'];
					}
				}
				$levelofstudy = '';
			   $eve2 = "select * from res_levelofstudy_master where losmid ='$losmid'";
				
				$re2 = mysqli_query($conn, $eve2);
				
				if(mysqli_num_rows($re2) > 0)
				{
					
					while($rt2 = mysqli_fetch_assoc($re2))
					{
							$levelofstudy=$rt2['levelofstudy'];
					}
				}
				
				$language = '';
				$eve11 = "select * from res_courselanguage_detail where coursemid=$coursemid and clangtype='Language'";
				$re11 = mysqli_query($conn, $eve11);
				while($rt11 = mysqli_fetch_assoc($re11))
				{
					
					$clangeligibility=$rt11['clangeligibility'];
					$clangscore=$rt11['clangscore'];
					$clangminscore=$rt11['clangminscore'];
					$language1 = $clangeligibility." (".$clangscore.")";
					
					if($language != '')
						{
						$language = $language.",".$language1;
						}else{
							$language = $language1;
						}
				}
				
				$alanguage = '';
				$eve11 = "select * from res_courselanguage_detail where coursemid=$coursemid and clangtype='Aptitude'";
				$re11 = mysqli_query($conn, $eve11);
				while($rt11 = mysqli_fetch_assoc($re11))
				{
					
					$clangeligibility=$rt11['clangeligibility'];
					$clangscore=$rt11['clangscore'];
					$clangminscore=$rt11['clangminscore'];
					$language1 = $clangeligibility." (".$clangscore.")";
					
					if($alanguage != '')
						{
						$alanguage = $alanguage.",".$alanguage1;
						}else{
							$alanguage = $alanguage1;
						}
				}
				
				$intake = '';
				$eve11 = "select * from res_courseintaketerm_detail where coursemid=$coursemid";
				$re11 = mysqli_query($conn, $eve11);
				while($rt11 = mysqli_fetch_assoc($re11))
				{
					
					$ctermmonth=$rt11['ctermmonth'];
					$ctermyear=$rt11['ctermyear'];
					$intake1 = $ctermmonth." - ".$ctermyear;
					
					if($intake != '')
						{
						$intake = $intake.",".$intake1;
						}else{
							$intake = $intake1;
						}
				}
					
					
			
		
		$this->Row(array("Program Name",$coursename));
		$this->Row(array("Program Code",$cprogramcode));
		$this->Row(array("Country",$countryname));
		$this->Row(array("Institute",$cmname));
		$this->Row(array("Campus",$campusname));
		$this->Row(array("Discipline",$cprogramcategory));
		$this->Row(array("Credentials",$levelofstudy));
		$this->Row(array("Description",$cmdesc));
		$this->Row(array("Program Length",$cprogramlength));
		$this->Row(array("Program language",$cprogramlanguage));
		$this->Row(array("Program Type",$cprogramtype));
		$this->Row(array("Program Delivery Mode",$cprogramdelivery));
		$this->Row(array("Program URL",$programurl));
		$this->Row(array("Monthly living cost",$costofliving));
		$this->Row(array("Program Availability",$cprogramavailibilty));
		$this->Row(array("Application URL link",$cappurllink));
		$this->Row(array("Conditional acceptance",$cconditionalacceptence));
		$this->Row(array("Competitiveness",$chighlycompetitive));
		$this->Row(array("Language",$language));
		$this->Row(array("Aptitude",$alanguage));
		$this->Row(array("Intake",$intake));
		$this->Row(array("Percentage",$cpercentage));
		$this->Row(array("Number of Backlogs accepted",$cbacklogaccepted));
		$this->Row(array("Education Gap allowed",$cedugapaccepted));
		$this->Row(array("Currency",$feesin));
		$this->Row(array("Application Fees",$capplicationfee));
		$this->Row(array("Deposit  Required",$cregifees1));
		$this->Row(array("Deposit amount ",$cregifees));
		$this->Row(array("Net tuition fees ",$ctutionfeesin));
		$this->Row(array("Tuition Fees Amount",$ctutionfees));
		$this->Row(array("Gross Annual Tuition fees",$cgrossfees));
		$this->Row(array("Scholarship",$cscholorship));
		$this->Row(array("Submission Deadline",$csubmissiondeadline));
		$this->Row(array("Processing Time",$cprocessingtime));
		$this->Row(array("Job Prospects",$cjobprospect));
		$this->Row(array("Average annual salary",$cavgannualsalary));
		$this->Ln();
		$this->Ln();
		}	
    $footertext=$_SESSION['footertext'];
	$this->Ln(6);
	$this->SetFont('Arial','B',15);
	$this->Cell(190,5,$footertext,0,0,'C');
	$this->Ln();

}

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

		$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 ImprovedTable_9()
{

	$w = array(95,95);
	$disc2=strip_tags($_SESSION['disc2']);
	if($disc2=="")
	{
	}
	else
	{
		$this->SetFont('Arial','',10);
		$this->MultiCell(0,5,"$disc2");
		$this->SetLineWidth(.3);
	}
}
function ImprovedTable_4()
{
	$w = array(15,20,40,20,15,20,20,20,20);
	 global $conn;
	if($_SESSION['tdiscamt']>0)
	{
		$this->SetWidths(array(10,18,70,10,15,15,17,12,23));
		$this->SetAligns(array('C','C','C','C','C','C','C','C','C'));
		//$this->SetFillColor(128, 0, 0);
		$this->SetFont('Arial','B',10);
		$this->Row(array('SR. No.','HSN CODE ','PRODUCT DISCRIPTION','GST (%)','RATE','QTY','UNIT','DISC (%)','AMOUNT'));
		$this->SetFont('Arial','',10);

		$this->SetAligns(array('C','L','L','R','R','R','R','R','R'));
		}
		else{
		$this->SetWidths(array(10,18,80,10,20,14,15,23));
		$this->SetAligns(array('C','C','C','C','C','C','C','C'));
		//$this->SetFillColor(128, 0, 0);
		$this->SetFont('Arial','B',10);
		$this->Row(array('SR. No.','HSN CODE ','PRODUCT DISCRIPTION','GST (%)','RATE','QTY','UNIT','AMOUNT'));
		$this->SetFont('Arial','',10);
		$this->SetAligns(array('C','L','L','R','R','R','R','R'));
		}
		$prefinalamount=0;
		$ccount="0";
		$subtotal="0";
		$extra1charges="0";
		$extra2charges="0";
		$extra3charges="0";
		$taxtotal="0";
		$grandtotal="0";

		$eve2 = "select * from res_quotation_detail where qmid=".$_GET['qmid'];
		$re2 = mysqli_query($conn, $eve2);
		while($rt2 = mysqli_fetch_assoc($re2))
		{
			$ccount++;
			$itemid=$rt2['itemid'];
			$itemname=$rt2['itemname'];
			$itemhsncode=$rt2['itemhsncode'];
			$itemiprice=$rt2['itemiprice'];
			$itemamount=$rt2['itemamount'];
			$itemqty=$rt2['itemqty'];
			$itemdesc=$rt2['itemdesc'];
			$itemunit=$rt2['itemunit'];
			$itemdiscper=$rt2['itemdiscper'];
			$itemtotalamount=$rt2['itemtotalamount'];
			$itemgstper=$rt2['itemgstper'];
			$gst=$rt2['itemgstper'];
			$itemgstamount=$rt2['itemgstamount'];
			
			if($itemgstper>0)
			{
				if (empty($tclass["$gst"]))
				{
					$tclass["$gst"]=0;
					$evetaxclass = "select tcper from res_taxclass_master";
					$retaxclass = mysqli_query($conn, $evetaxclass);
					while($rttaxclass = mysqli_fetch_assoc($retaxclass))
					{
						if($gst==$rttaxclass['tcper'])
						{
							$tclass["$gst"]=$tclass["$gst"]+($itemgstamount);
						}
					}
				}
				else
				{
					$tclass["$gst"]=$tclass["$gst"]+($itemgstamount);
				}
			}
			$subtotal = $subtotal + $itemamount;
			if(strlen($itemdesc)>0)
			{
				$itemname=$itemname."\n".$itemdesc;
			}
			setlocale(LC_MONETARY, 'en_IN');			
			//$itemamount = money_format('%!i', $itemamount);

			if($_SESSION['tdiscamt']>0)
			{
				$this->Row(array($ccount,$itemhsncode,$itemname,$gst,$itemiprice,$itemqty,$itemunit,$itemdiscper,$itemamount));
			}
			else{
				$this->Row(array($ccount,$itemhsncode,$itemname,$gst,$itemiprice,$itemqty,$itemunit,$itemamount));
			}
		}
		$tgst=0;
		foreach($tclass as $key => $value) {
			$tgst=$tgst+$value;
	}
	$_SESSION['tclass'] = $tclass;
	$_SESSION['subtotal'] = $subtotal;
	$_SESSION['grandtotal'] = $subtotal +$tgst ;
    $this->Cell(array_sum($w),0,'','T');
	$this->Ln();
}
function ImprovedTable_2()
{
	$qrefno = $_SESSION['qrefno'];
	$cgstno = $_SESSION['cgstno'];
	$quodate = $_SESSION['qdate'];
	$cname  = $_SESSION['cname'];
	$customercmpname  = $_SESSION['cname'];
	$cmpname = $_SESSION['cmpname'];
	$customeremail  = $_SESSION['email'];
	$customerid = $_SESSION['qno'];
	$city = $_SESSION['city'];
	$cstate = $_SESSION['cstate'];
	$address = $_SESSION['address'];
	$address2 = $city.'-'.$cstate;
	$mobile = $_SESSION['mobile'];
	$customercontactpersonname = $_SESSION['cname'];
	$pdfheaderline1 = $_SESSION['pdfheaderline1'];
	$pdfheaderline2 = $_SESSION['pdfheaderline2'];
	$qdate=$_SESSION['qdate'];
	$qno=$_SESSION['qno'];
	//$cmpperson = "";

	if (preg_match('/^.{1,50}\b/s', $address, $match))
	{
		$line1=$match[0];
	}
	$tt = strlen($line1);
	$linesub = substr($address,$tt);
	$line2="";
	if (preg_match('/^.{1,50}\b/s', $linesub, $match2))
	{
		$line2=$match2[0];
	}
	$line3="";
	$line3 = substr($address,strlen($line1)+strlen($line2),50);

    $w = array(95,95);
	$this->SetFont('Arial','B',10);
	$this->SetLineWidth(.3);
	$this->Cell($w[0],6,"$cname",'LRT');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Quotation Number: $qno      Date: $qdate",'LRT');

	$this->Ln();
	$this->SetFont('Arial','',10);
	$this->Cell($w[0],6,"$line1",'LR');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Reference Number: $qrefno",'LR');
	$this->SetFont('Arial','',10);
	$this->Ln();
	$this->Cell($w[0],6,"$address2",'LR');
	$this->Cell($w[1],6,"$pdfheaderline1",'LR');
	$this->Ln();
	$this->Cell($w[0],6,"GSTN: $cgstno",'LR');
	$this->Cell($w[1],6,"$pdfheaderline2",'LR');
	$this->Ln(6);

    $this->Cell(array_sum($w),0,'','T');
	$this->Ln();
}
function ImprovedTable_5()
{ $w = array(138,29,23);

		$amount = $_SESSION['subtotal'];
		$cmpdetail5="";
		setlocale(LC_MONETARY, 'en_IN');
		//$pckamt = money_format('%!i', $amount);
		$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,"$amount",'LRTB',0,'R');
        $this->Ln();
}

function ImprovedTable_6()
{ $w = array(138,29,23);
	if($_SESSION['cstate']==$_SESSION['cmpstate'])
	{
		$tclass1=$_SESSION['tclass'];
		foreach($tclass1 as $key => $value) {
			$key2=$key/2;
			$value1=$value/2;
			$this->SetFont('Arial','',10);
			$this->SetLineWidth(.3);
			$this->Cell($w[0],6,"",'L');
			//setlocale(LC_MONETARY, 'en_IN');
			//$value1 = money_format('%!i', $value1);
			$this->Cell($w[1],6,"CGST $key2%",'LRTB',0,'R');
			$this->Cell($w[2],6,"$value1",'LRTB',0,'R');
			$this->Ln();
			$this->SetFont('Arial','',10);
			$this->SetLineWidth(.3);
			$this->Cell($w[0],6,"",'L');
			$this->Cell($w[1],6,"SGST $key2%",'LRTB',0,'R');
			$this->Cell($w[2],6,"$value1",'LRTB',0,'R');
			$this->Ln();
		}
	}
	else
	{
		$tclass1=$_SESSION['tclass'];
		foreach($tclass1 as $key => $value) {
		$this->SetFont('Arial','',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"",'L');
		setlocale(LC_MONETARY, 'en_IN');
		//$value1 = money_format('%!i', $value);
		$this->Cell($w[1],6,"IGST $key%",'LRTB',0,'R');
		$this->Cell($w[2],6,"$value",'LRTB',0,'R');
		$this->Ln();
		}
	}
}

function ImprovedTable_7()
{ $w = array(138,29,23);

		$qroundoffamount= $_SESSION['qroundoffamount'];
		
		$qnetamount= $_SESSION['qnetamount'];
		setlocale(LC_MONETARY, 'en_IN');
		//$gt1 = money_format('%!i', $qnetamount);
		//$qroundoffamount = money_format('%!i', $qroundoffamount);
		$amountinwords =  convert_number_to_words($qnetamount);
		
		if($qroundoffamount<>0)
		{
			if($qroundoffamount>0)
			{
				$qroundoffamount= '+'.$qroundoffamount;
			}
			$this->SetFont('Arial','',10);
			$this->SetLineWidth(.3);
			$this->Cell($w[0],6,"",'LR',0,'R');
			$this->Cell($w[1],6,"Round Off",'LRTB',0,'R');
			$this->Cell($w[2],6,"$qroundoffamount",'LRTB',0,'R');
			$this->Ln();
		}
		 $this->SetFont('Arial','',9);
		$this->SetLineWidth(.3);
		$this->SetFont('Arial','B',10);
		$this->Cell($w[0],6,"",'LRB',0,'R');
		$this->Cell($w[1],6,"Total Amount",'LRTB',0,'R');
		$this->Cell($w[2],6,"$qnetamount",'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",'LRB');
        $this->Ln();
        $this->Ln();
	$this->Ln();
}

function ImprovedTable_8()
{
    $w = array(95,95);
	$qterms=$_SESSION['qterms'];
	if($qterms=="")
	{
	}
	else
	{
		$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();
	}
}

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

function convert_number_to_words($myno,$part2=1)
{
   $number = $myno;
   $no = (int)($number);
   $point = round($number - $no, 2) * 100;
   $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;

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

		return $result . "Rupees and ".$pointvalue."Paisa Only.";
	}
	else if($part2==-7)
	{
		return $result;
	}
	else
	{
		return $result."Rupees Only.";

	}
}

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_1();
/* $pdf->ImprovedTable_2();
$pdf->ImprovedTable_3();
$pdf->ImprovedTable_4();
$pdf->ImprovedTable_5();
$pdf->ImprovedTable_6();
$pdf->ImprovedTable_7();
$pdf->ImprovedTable_8();
$pdf->ImprovedTable_9();
$pdf->ImprovedTable_10(); */
$pdf->SetFont('Times','',12);
$pdf->Output();
$quono1 = $_SESSION['quono1'];
$qmid2 = $_GET['qmid'];
//$pdf->Output('F',"../download/$quono1.pdf");

//return;

//header("Location: ../quotationmasterstatus.php?id=$qmid2");


?>
