<?php
session_start();
unset($_SESSION['tclass']);
include("../connect.php");
include("../removespecial.php");
	$challanmid1=$_GET['id'];
	$_SESSION['challanmid']=$_GET['id'];
	$cmpmid=$_SESSION['linkarisecmpmid'];
$eve2 = "select * from res_challan_detail where challanmid=$challanmid1";
		$re2 = mysqli_query($conn, $eve2);
		while($rt2 = mysqli_fetch_assoc($re2))
		{
			
			$vehicleqrcode=$rt2['vehicleqrcode'];
			$_SESSION['vehicleqrcode']=$vehicleqrcode;
		}
	$eve = "select * from res_challan_master where challanmid=$challanmid1";
	$re = mysqli_query($conn, $eve);
	while($rt = mysqli_fetch_assoc($re))
	{
		$_SESSION['challandate']=date("d-m-y H:i",strtotime($rt['addedon']));;
		$_SESSION['jobno']=$rt['challannofordisplay'];
		$_SESSION['challantype']=$rt['challantype'];
		$_SESSION['jobno1']=$rt['challannofordisplay'];
		//$_SESSION['qpdf']=$rt['qpdf'];
		$_SESSION['jobmno']=$rt['challannumber'];
		$_SESSION['remarks']=$rt['jobremarks'];
	
		$_SESSION['disc1']="";
		$_SESSION['disc2']="";
		$_SESSION['challandispatchedby']=$rt['addedby'];
		$_SESSION['addedon3']=$rt['addedon'];		
		$_SESSION['receivedon5']=$rt['challanreceivedon'];
		
		$driverid=$rt['driverid'];
          
          $_SESSION['challanweighttype']=$rt['challanweighttype'];
          
						$dr1 = "select * from res_driver_master where driverid=".$driverid;
		$rd1 = mysqli_query($conn, $dr1);
		while($dt1 = mysqli_fetch_assoc($rd1))
		{
            $_SESSION['dname']=$dt1['dname'];
            $_SESSION['dnric']=$dt1['dnric'];

		}
		$party=$rt['partymid'];
		$eve1 = "select * from res_party_master where partymid=$party";
			$re1 = mysqli_query($conn, $eve1);
			while($rt1 = mysqli_fetch_assoc($re1))
			{
				$_SESSION['partyname']=$rt1['partyname'];
				$_SESSION['partyaddress']=$rt1['partyaddress'];
				$_SESSION['partymobile']=$rt1['partycontectno'];
			
			}
	$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['gst']=$rt_display['gst_rate'];
			$_SESSION['headerimg']="header.png";
				$_SESSION['footerimg']="";
				
			}
		$eve11 = "select * from res_user_master where usermid=".$_SESSION['challandispatchedby'];
			$re11 = mysqli_query($conn, $eve11);
			while($rt11 = mysqli_fetch_assoc($re11))
			{
				$_SESSION['challandispatcedbyname']=$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()
{
	$this->SetFont('Arial','B',32);
	$this->Cell(190,5,"ISVASIA WEIGHING",0,0,'C');
    $this->Ln(6);
	
	
	$this->SetFont('Arial','',10);
	$this->Cell(190,14,"No,23 Tuas Avenue 13,",0,0,'C');
    $this->Ln(6);
	$this->SetFont('Arial','',10);
	$this->Cell(190,10,"#01-08-Singapore b38990",0,0,'C');
    $this->Ln(6);
	$this->SetFont('Arial','',10);
	$this->Cell(190,6,"UEN: 201422733Z",0,0,'C');
    $this->Ln(6);
	$this->SetFont('Arial','',10);
	$this->Cell(190,1,"Tel: 62505355",0,0,'C');
    $this->Ln(6);
	$headerimg=$_SESSION['headerimg'];
	if(strlen($headerimg)>5){
		//$header = "../images/$headerimg";
		//$this->Image("$header",8,6,194,30);
	}
	$this->Ln(6);
}

// Page footer


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,26,26,20,24,24,20,20,20));
		$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.','Items',"Initial Wt\n(kg)","Deducted Wt\n(kg)","Final Wt after deduct\n(kg)","Net Wt\n(kg)","Item Price\n($/kg)","Deduct Price\n($)","Item Price after deduct\n($)"));
		$this->SetFont('Arial','',10);

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

		$eve2 = "select * from res_challan_detail where challanmid=".$_GET['id'];
		$re2 = mysqli_query($conn, $eve2);
		while($rt2 = mysqli_fetch_assoc($re2))
		{
			$ccount++;
			$challandid=$rt2['challandid'];
			$itemmid=$rt2['itemmid'];
			$vehicleqrcode=$rt2['vehicleqrcode'];
			
			$vehicletareweight=$rt2['vehicletareweight'];
			$vehiclegrossweight=$rt2['vehiclegrossweight'];
			$vehicletareweight=number_format($vehicletareweight,2,'.','');
			$vehiclegrossweight=number_format($vehiclegrossweight,2,'.','');
			$vehiclenetweight=$rt2['vehiclenetweight'];
			$itemprice=number_format($rt2['totalitemprice'],2,'.','');
			$itemPrice=number_format($rt2['itemPrice'],2,'.','');
			    $reductiontype2 = $rt2['reductiontype'];
				$itemdeduction2=$rt2['itemdeduction'];
				$itemdeduction=0;
				$itemdeductionwt=0;
					if($reductiontype2 == 'Payment')
						{
							$itemdeduction = $itemdeduction2;
						}
						else if($reductiontype2 == 'Percentage')
						{
							$itemdeductionwt = $vehiclenetweight * 0.5;
						}
						else
						{
							$itemdeductionwt = $itemdeduction2;
						
						}
						$itemdeduction11=number_format($itemdeduction,2,'.','');
						$itemdeductionwt11=number_format($itemdeductionwt,2,'.','');
			$vehiclenetweight=number_format($vehiclenetweight,2,'.','');
			$addedon3=date("H:i",strtotime($_SESSION['addedon3']));
			$receivedon5=date("H:i",strtotime($_SESSION['receivedon5']));
			$_SESSION['vehiclenetweight']=$vehiclenetweight;
			
							$eve22 = "select itemname from res_item_master where itemmid=$itemmid";
				$re22= mysqli_query($conn, $eve22);
				$itemname="";
				$itemunit="";
				if(mysqli_num_rows($re22) > 0)
				{
					$t1=1;
					while($rt22 = mysqli_fetch_assoc($re22))
					{
						/* $ufullname=$rt22['ufullname']; */
						
						
							$itemname = $rt22['itemname'];
							
							
					}
				}
			
		//	$subtotal = $subtotal + $totalitemprice;
			$subtotal2 = $subtotal2 + $vehiclenetweight;
			
			//setlocale(LC_MONETARY, 'en_IN');			
			//$itemamount = money_format('%!i', $itemamount);
$minus="";
$minus2="";
if($itemdeductionwt11!=0){
    $minus="- ";
}
if($itemdeduction11!=0){
    $minus2="- ";
}
	
				$this->Row(array($ccount,$itemname,$vehicletareweight,$minus.$itemdeductionwt11,$vehiclegrossweight,$vehiclenetweight,$itemPrice,$minus2.$itemdeduction11,$itemprice));
		
		
		}
		
	
	$_SESSION['subtotal'] = $subtotal;
	$_SESSION['subtotal2'] = $subtotal2;
	$_SESSION['grandtotal'] = $subtotal;
	$_SESSION['grandtotal2'] = $subtotal2;
	
    $this->Cell(array_sum($w),0,'','T');
	$this->Ln();
}
function ImprovedTable_2()
{
	$challandate = $_SESSION['challandate'];
	$jobno = $_SESSION['jobno'];
	
	$partyname = $_SESSION['partyname'];
	$partyaddress  = $_SESSION['partyaddress'];
	$partymobile = $_SESSION['partymobile'];
	
	
	 $challantype=$_SESSION['challantype'];
     $challanweighttype=$_SESSION['challanweighttype'];
	
	$dname=$_SESSION['dname'];
    $dnric=$_SESSION['dnric'];
    $dnric='*****'.substr($dnric,-4);
    $vehnumber=$_SESSION['vehicleqrcode'];
	
	
	$pdfheaderline1 = "";
	$pdfheaderline2 = "";
	
	//$cmpperson = "";
	$line1="";
	if (preg_match('/^.{1,70}\b/s', $partyaddress, $match))
	{
		$line1=$match[0];
	}
	$tt = strlen($line1);
	$linesub = substr($partyaddress,$tt);
	$line2="";
	if (preg_match('/^.{1,70}\b/s', $linesub, $match2))
	{
		$line2=$match2[0];
	}
	$line3="";
	$line3 = substr($partyaddress,strlen($line1)+strlen($line2),50);
$address2 = $line2;
    $w = array(108,82);
	$this->SetFont('Arial','B',10);
	$this->SetLineWidth(.3);
	$this->Cell($w[0],6,"Ticket No: $jobno",'LRT');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Date & Time: $challandate",'LRT');
	
	$this->Ln();
	$this->SetFont('Arial','B',10);
	
	$this->Cell($w[0],6,"Customer Name: $partyname",'LR');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Vehicle No: $vehnumber",'LR');

	$this->Ln();
	$this->SetFont('Arial','B',10);
	$this->Cell($w[0],6,"Customer Tel: $partymobile",'LR');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Driver Name: $dname",'LR');
	
	$this->SetFont('Arial','B',10);
	$this->Ln();
	$this->Cell($w[0],6,"Trans. Type: $challantype",'LR');
	$this->SetFont('Arial','B',10);
	$this->Cell($w[1],6,"Driver NRIC: $dnric",'LR');
	$this->Ln();
	$this->Cell($w[0],6,"Trans. Mode: $challanweighttype",'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'];
		$amount2 = $_SESSION['subtotal2'];
		
		$amount = number_format($amount,2,'.','');
		$amount2 = number_format($amount2,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 Footer()
{
	include "../connect.php";
	//$samid=$_SESSION['samid'];
	
	
	
$challanmid11 = $_SESSION['challanmid'];
		$eve7="select challanimagename from res_challanimage_detail where challanmid=$challanmid11";
					$re7 = mysqli_query($conn, $eve7);
					$challanimagename=" ";
					if(mysqli_num_rows($re7) > 0)
					{
					 
					$repeat="0";
					$paddingleft=10;
					$paddingtop=200;
					while($rt7 = mysqli_fetch_assoc($re7))
					{
					   
						    
					 $challanimagename = $rt7['challanimagename'];
					 
$repeat++;
						
				

	$footer = "../images/$challanimagename";
	
	
	if(strlen($challanimagename)>5)
	{
	    
		if($repeat>1){
		    $paddingleft =$paddingleft+41;
		}
		if($paddingleft>133)
		{
		    
		    $paddingleft = 10;
		    $paddingtop = $paddingtop+41;
		}
		$this->Image("$footer",$paddingleft,$paddingtop,40,40);
 	}
					}
					}
					
}

function ImprovedTable_7()
{ 
    include "../connect.php";
    $w = array(95,35,26,34);

		
		$vehiclenetweight= $_SESSION['vehiclenetweight'];
		setlocale(LC_MONETARY, 'en_IN');
		//$gt1 = money_format('%!i', $invoicenetamount);
		$gt1 = number_format($_SESSION['subtotal'],2,'.','');
		$dn2 = number_format($_SESSION['subtotal2'],2,'.','');
			

		//$qroundoffamount = money_format('%!i', $qroundoffamount);
		//$qroundoffamount = $qroundoffamount;
		$amountinwords =  convert_number_to_words($vehiclenetweight);
		
		/* 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();
		} */

	$gst=$_SESSION['gst'];
			
		$totalitprice="0";
					$eve72="select SUM(totalitemprice) as cc from res_challan_detail where challanmid	=".$_GET['id'];
					$re72 = mysqli_query($conn, $eve72);
					while($rt72 = mysqli_fetch_assoc($re72))
					{
						$totalitprice=number_format($rt72['cc'],2,'.',',');
						$totaliprice11 = $rt72['cc']*($gst/100);
						$totaliprice110=number_format($totaliprice11,2,'.',',');
						$finaltotal= $totaliprice11 + $rt72['cc'];
						$dhw11=number_format($finaltotal,2,'.',',');
					}
		
		 $this->SetFont('Arial','',9);
		$this->SetLineWidth(.3);
		$this->SetFont('Arial','B',10);
		$this->Cell($w[0],6,"Overall Net Weight",'LRB',0,'R');
		$this->Cell($w[1],6,"$dn2",'LRB',0,'R');
		
		
		$this->Cell($w[2],6,"SubTotal ($)",'LRB',0,'R');
		$this->Cell($w[3],6,"$totalitprice",'LRB',0,'R');
		
		
		$this->SetFont('Arial','',10);
		$this->Ln();
	
	
			$w = array(75,33,22,26,34);

	
			
		
		
		 $this->SetFont('Arial','',9);
		$this->SetLineWidth(.3);
		$this->SetFont('Arial','B',10);
		$this->Cell($w[0],6,"",'LB',0,'R');
		$this->Cell($w[1],6,"",'B',0,'R');
		$this->Cell($w[2],6,"",'B',0,'R');
		
		$this->Cell($w[3],6,"GST $gst% ($)",'LRB',0,'R');
		$this->Cell($w[4],6,"$totaliprice110",'LRB',0,'R');
		
		
		$this->SetFont('Arial','',10);
		$this->Ln();
		
		$w = array(75,33,22,26,34);

	
			
		
		
		 $this->SetFont('Arial','',9);
		$this->SetLineWidth(.3);
		$this->SetFont('Arial','B',10);
		$this->Cell($w[0],6,"",'LB',0,'R');
		$this->Cell($w[1],6,"",'B',0,'R');
		$this->Cell($w[2],6,"",'B',0,'R');
		
		$this->Cell($w[3],6,"Total Price ($)",'LRB',0,'R');
		$this->Cell($w[4],6,"$dhw11",'LRB',0,'R');
		
		
		$this->SetFont('Arial','',10);
		$this->Ln();
		
		$w = array(190,0);

		
		
		$this->SetFont('Arial','',10);
		$this->Cell($w[0],4,"",'LR');
		$this->Ln();
		
		$remarks=$_SESSION['remarks'];
		$w = array(190,0);

		
		
		$this->SetFont('Arial','',10);
		$this->Cell($w[0],4,"Remarks:"." "."$remarks",'LR');
		$this->Ln();
		
		
					
				/*	$w = array(190,0);

		
		
		$this->SetFont('Arial','',10);
		$this->Cell($w[0],4,$challanimagename,'LR');
		$this->Ln();*/
		
		
		$w = array(140,50);
		
	
		
		
		
		$cmpname1=$_SESSION['cmpname1'];
		$cmpaddress1=$_SESSION['cmpaddress1'];
		$cmpmobile1=$_SESSION['cmpmobile1'];
		$sentoutby=$_SESSION['challandispatcedbyname'];
		$cmpprefix=$_SESSION['cmpprefix'];
		$createdby="";
		/*
		 $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();
		
		$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'];
		
			//$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,"",'R',0,'L');
		$this->Ln();
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"Issued by: ____________",'L',0,'L');
		$this->Cell($w[1],6,"Received by: ____________",'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,"Job Details / Invoice",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);
		$partyname=$_SESSION['partyname'];
		$createdby=$_SESSION['createdby'];
		$this->SetFont('Arial','B',10);
		$this->Cell(190,5,"For: $partyname",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_7();
//$pdf->ImprovedTable_8();
$pdf->SetFont('Times','',12);
$challandate = $_SESSION['challandate'];
	$jobno = $_SESSION['jobno'];
$pdf->Output();
$jobpdf = $jobno."_".$challandate.".pdf";
$qmid2 = $_GET['id'];
$pdf->Output('F',"../download/$jobpdf");

//return;

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




?>
