<?php
session_start();
unset($_SESSION['tclass']);
include("../connect.php");
include("../removespecial.php");
	$jobworkmid1=$_GET['jobworkmid'];
	$cmpmid=$_SESSION['linkarisecmpmid'];

	$eve = "select * from res_jobwork_master where jobworkmid=$jobworkmid1";
	$re = mysqli_query($conn, $eve);
	while($rt = mysqli_fetch_assoc($re))
	{
		$_SESSION['jobworkdate']=implode('-', array_reverse(explode('-', $rt['jobworkdate'])));
		$_SESSION['jobno']=$rt['jobworknofordisplay'];
		$_SESSION['jobno1']=$rt['jobworknofordisplay'];
		//$_SESSION['qpdf']=$rt['qpdf'];
		$_SESSION['jobmno']=$rt['jobworknumber'];
		$_SESSION['disc1']="";
		$_SESSION['disc2']="";
		$_SESSION['dispatchedby']=$rt['dispatchedby'];
		
		$cmpnymid=$rt['tocompanymid'];
		$eve1 = "select * from res_company_master where companymid=$cmpnymid";
			$re1 = mysqli_query($conn, $eve1);
			while($rt1 = mysqli_fetch_assoc($re1))
			{
				$_SESSION['cmpname']=$rt1['companyname'];
				$_SESSION['cmpaddress']=$rt1['companyaddress'];
				$_SESSION['cmpmobile']=$rt1['companycontectno'];
			
			}
	$eve_display= "select * from res_company_master where companymid=$cmpmid";
			$re_display = mysqli_query($conn, $eve_display);
			while($rt_display = mysqli_fetch_assoc($re_display))
			{
		 

				$_SESSION['cmpname1']=$rt_display['companyname'];
				$_SESSION['cmpaddress1']=$rt_display['companyaddress'];
				$_SESSION['cmpmobile1']=$rt_display['companycontectno'];
				$_SESSION['cmpprefix']=$rt_display['companyprefix'];
			$_SESSION['headerimg']="iwashlogo.jpg";
				$_SESSION['footerimg']="";
				
			}
		$eve11 = "select * from res_user_master where usermid=".$_SESSION['dispatchedby'];
			$re11 = mysqli_query($conn, $eve11);
			while($rt11 = mysqli_fetch_assoc($re11))
			{
				$_SESSION['dispatchedbyname']=$rt11['username'];
				
			
			}
		
		
	}
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(strlen($headerimg)>5){
		$header = "../images/$headerimg";
		$this->Image("$header",8,6,194,30);
	}
	$this->Ln(30);
}

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


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()
{
	include "../connect.php";
	$w = array(15,20,40,20,15,20,20,20,20);

		$this->SetWidths(array(10,30,75,15,20,20,20));
		$this->SetAligns(array('C','C','C','C','C','C','C'));
		//$this->SetFillColor(128, 0, 0);
		$this->SetFont('Arial','B',10);
		$this->Row(array('SR. No.','Trolley No.','Items','Trolley Item','Gross Weight (Kg)','Tare Weight (Kg)','Net Weight (Kg)'));
		$this->SetFont('Arial','',10);

		$this->SetAligns(array('C','L','L','R','R','R','R','R','R'));
		
	$subtotal="0";

		$eve2 = "select * from res_jobwork_detail where jobworkmid=".$_GET['jobworkmid'];
		$re2 = mysqli_query($conn, $eve2);
		while($rt2 = mysqli_fetch_assoc($re2))
		{
			$ccount++;
			$jobworkdid=$rt2['jobworkdid'];
			$trolleymid=$rt2['trolleymid'];
			$trolleyqrcode=$rt2['trolleyqrcode'];
			$trolleytareweight=$rt2['trolleytareweight'];
			$trolleygrossweight=$rt2['trolleygrossweight'];
			$trolleytareweight=number_format($trolleytareweight,2,'.','');
			$trolleygrossweight=number_format($trolleygrossweight,2,'.','');
			$trolleynetweight=$rt2['trolleynetweight'];
			$trolleynetweight=number_format($trolleynetweight,2,'.','');
			
			$query11 = "select count(jobworkdid) as cc from res_jobworkitem_detail where jobworkdid=$jobworkdid";
															$stmt11=mysqli_query($conn,$query11);
															
															$totalitem="";
															
															if(mysqli_num_rows($stmt11) > 0)
															{
																while($rt11 = mysqli_fetch_assoc($stmt11))
																{
																	$totalitem=$rt11['cc'];
																	
																}
															}
															$eve22 = "select itemname,itemqty from res_jobworkitem_detail where jobworkdid=$jobworkdid";
				$re22= mysqli_query($conn, $eve22);
				$itemname="";
				$itemqty="";
				if(mysqli_num_rows($re22) > 0)
				{
					$t1=1;
					while($rt22 = mysqli_fetch_assoc($re22))
					{
						/* $ufullname=$rt22['ufullname']; */
						
						if($t1==1)
						{
							$itemname = $itemname.$rt22['itemname']."-".$rt22['itemqty'];
							$t1=0;
						}
						else
						{
							$itemname = $itemname."\n".$rt22['itemname']."-".$rt22['itemqty'];
						}
					}
				}
			
			$subtotal = $subtotal + $trolleynetweight;
			
			//setlocale(LC_MONETARY, 'en_IN');			
			//$itemamount = money_format('%!i', $itemamount);

			
				$this->Row(array($ccount,$trolleyqrcode,$itemname,$totalitem,$trolleygrossweight,$trolleytareweight,$trolleynetweight));
		
		}
		
	
	$_SESSION['subtotal'] = $subtotal;
	$_SESSION['grandtotal'] = $subtotal;
    $this->Cell(array_sum($w),0,'','T');
	$this->Ln();
}
function ImprovedTable_2()
{
	$jobworkdate = $_SESSION['jobworkdate'];
	$jobno = $_SESSION['jobno'];
	$cmpname = $_SESSION['cmpname'];
	$cmpaddress  = $_SESSION['cmpaddress'];
	$cmpmobile = $_SESSION['cmpmobile'];
	
	$pdfheaderline1 = "";
	$pdfheaderline2 = "";
	
	//$cmpperson = "";
	$line1="";
	if (preg_match('/^.{1,70}\b/s', $cmpaddress, $match))
	{
		$line1=$match[0];
	}
	$tt = strlen($line1);
	$linesub = substr($cmpaddress,$tt);
	$line2="";
	if (preg_match('/^.{1,70}\b/s', $linesub, $match2))
	{
		$line2=$match2[0];
	}
	$line3="";
	$line3 = substr($cmpaddress,strlen($line1)+strlen($line2),50);
$address2 = $line2;
    $w = array(120,70);
	$this->SetFont('Arial','B',10);
	$this->SetLineWidth(.3);
	$this->Cell($w[0],6,"To,",'LRT');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Date: $jobworkdate",'LRT');
	
	$this->Ln();
	$this->SetFont('Arial','',10);
	
	$this->Cell($w[0],6,"$cmpname",'LR');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Job Work Number: $jobno",'LR');

	$this->Ln();
	$this->SetFont('Arial','',10);
	$this->Cell($w[0],6,"$line1",'LR');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6," ",'LR');
	
	$this->SetFont('Arial','',10);
	$this->Ln();
	$this->Cell($w[0],6,"$address2",'LR');
	$this->Cell($w[1],6,"",'LR');
	$this->Ln();
	$this->Cell($w[0],6,"Mobile No: $cmpmobile",'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(137,30,23);

		$amount = $_SESSION['subtotal'];
		$amount = number_format($amount,2,'.','');
		$cmpdetail5="";
		//setlocale(LC_MONETARY, 'en_IN');
		//$amount = money_format('%!i', $amount);
		$this->SetFont('Arial','',10);
		$this->SetLineWidth(.3);
        $this->Cell($w[0],6,"$cmpdetail5",'L');
		$this->Cell($w[1],6,"Total",'LRTB',0,'R');
		$this->Cell($w[2],6,"$amount",'LRTB',0,'R');
        $this->Ln();
}

function ImprovedTable_6()
{ $w = array(137,30,23);
	if($_SESSION['cstate']==$_SESSION['cmpstate'])
	{
		
		$tclass1=$_SESSION['tclass'];
		foreach($tclass1 as $key => $value) {
			$key2=$key/2;
			$value1=$value/2;
			$value1=number_format($value1,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
	{
		if(isset($_SESSION['tclass']))
		{
			$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');
			//$value = 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(130,40,20);

		
		$trolleynetweight= $_SESSION['trolleynetweight'];
		setlocale(LC_MONETARY, 'en_IN');
		//$gt1 = money_format('%!i', $invoicenetamount);
		$gt1 = number_format($_SESSION['subtotal'],2,'.','');
		//$qroundoffamount = money_format('%!i', $qroundoffamount);
		$qroundoffamount = $qroundoffamount;
		$amountinwords =  convert_number_to_words($trolleynetweight);
		
		/* if($qroundoffamount<>0)
		{
			if($qroundoffamount>0)
			{
				$qroundoffamount= "Rs.".'+'.number_format($qroundoffamount,2,'.','');
			}
			$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 Net Weight",'LRTB',0,'R');
		$this->Cell($w[2],6,"$gt1",'LRTB',0,'R');
		$this->SetFont('Arial','',10);
		$this->Ln();
		
		$w = array(190,0);

		
		
		$this->SetFont('Arial','',10);
		$this->Cell($w[0],4,"",'LR');
		$this->Ln();
		
		$w = array(100,90);
		
		$cmpname1=$_SESSION['cmpname1'];
		$cmpaddress1=$_SESSION['cmpaddress1'];
		$cmpmobile1=$_SESSION['cmpmobile1'];
		$sentoutby=$_SESSION['dispatchedbyname'];
		$cmpprefix=$_SESSION['cmpprefix'];
		
		$createdby="";
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"Sent Out By: $cmpprefix-$sentoutby",'L',0,'L');
		$this->Cell($w[1],6,"",'R',0,'L');
		$this->Ln();
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"Company: $cmpname1",'L',0,'L');
		$this->Cell($w[1],6,"",'R',0,'L');
		$this->Ln();
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"Address: $cmpaddress1",'L',0,'L');
		$this->Cell($w[1],6,"",'R',0,'L');
		$this->Ln();
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"Mobile No: $cmpmobile1",'L',0,'L');
		$this->Cell($w[1],6,"",'R',0,'L');
		$this->Ln();
		
		
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"",'L',0,'L');
		$this->Cell($w[1],6,"",'R',0,'L');
		$this->Ln();
		
		$invremarks=$_SESSION['disc2'];
		$qterms=$_SESSION['qterms'];
			//$w = array(95,95);
		
//		$w = array(190,0);
	
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"",'L',0,'L');
		$this->Cell($w[1],6,"For, $cmpname1",'R',0,'L');
		$this->Ln();
		 
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"",'L',0,'L');
		$this->Cell($w[1],6,"Authorized Signature",'R',0,'L');
		$this->Ln();
		 
		
		
		
		
		/* if($invremarks=="")
		{
		}
		else
		{
			$this->SetFont('Arial','B',10);
			$this->SetLineWidth(.3);
			$this->Cell($w[0],6,"Declaration:",'L',0,'L');
			$this->Cell($w[1],6,"",'R',0,'L');
			$this->Ln();
			
			$this->SetFont('Arial','',10);
			$this->SetLineWidth(.3);
			$this->Cell($w[0],6,"$invremarks",'L',0,'L');
			$this->Cell($w[1],6,"",'R',0,'L');
			$this->Ln();
		} */
	

		//$w = array(95,95);
		
		$w = array(190,0);
		//$w = array(150,40);
		//$this->SetFont('Arial','B',10);
		//$this->SetLineWidth(.3);
        //$this->Cell($w[0],6,"Company GST No: 24ALIPV8745J1ZE",'L',0,'L');
		//$this->Cell($w[0],6,"",'LR',0,'R');
		//$this->Cell($w[1],6,"Round Off",'R',0,'R');
		//$this->Ln();
		
		
		$this->SetFont('Arial','',10);
		$this->Cell($w[0],4,"",'LRB');
		$this->Ln();
}
function ImprovedTable_1()
{
	 
	$this->SetFont('Arial','B',15);
	$this->Cell(190,5,"Linen Job Work",0,0,'C');
    $this->Ln(6);

}
function ImprovedTable_8()
{
    $w = array(95,95);
	
	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);
$jobworkdate = $_SESSION['jobworkdate'];
	$jobno = $_SESSION['jobno'];
//$pdf->Output();
$jobpdf = $jobno."_".$jobworkdate.".pdf";
$qmid2 = $_GET['jobworkmid'];
$pdf->Output('F',"../download/$jobpdf");

//return;

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




?>
