<?php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include("connect.php");
include("removespecial.php");
 global $conn;
 	$cmpmid=$_SESSION['linkarisecmpmid'];

	$pomid=$_GET['pomid'];
	$eve = "select * from res_po_master where pomid=$pomid";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		while($rt = mysqli_fetch_assoc($re))
		{
			$_SESSION['invoicedate']=date("d-m-Y", strtotime($rt['podate']));
			$_SESSION['invoicefordisplay']=$rt['pofordisplay'];
			$_SESSION['invoicemno']=$rt['pomno'];
			$pomno=$rt['pomno'];
			$_SESSION['invoicerefno']=$rt['porefno'];
			$_SESSION['popdf']=$rt['popdf'];
			$_SESSION['invoicegrossamount']=$rt['pogrossamount'];
			$_SESSION['invoiceroundoffamount']=$rt['poroundoffamount'];
			$_SESSION['invoicenetamount']=$rt['ponetamount'];
			$_SESSION['invoiceterms']=$rt['poterms'];
			$_SESSION['createdby']="";
			$_SESSION['kindatten']="";
			$suppliermid=$rt['suppliermid'];
			$eve1 = "select * from res_party_master where partymid=$suppliermid";
			$re1 = mysqli_query($conn, $eve1);
			while($rt1 = mysqli_fetch_assoc($re1))
			{
				$_SESSION['cgstno']=$rt1['partygstno'];
				$_SESSION['cname']=removespecialchar($rt1['partyname']);
				$_SESSION['email']=$rt1['partyemail'];
				$_SESSION['mobile']=$rt1['partymobile'];
				$_SESSION['address']=$rt1['partyaddress'];
				$_SESSION['city']=$rt1['partycity'];
				$_SESSION['cstate']=$rt1['partystate'];
			}
			 $evechk1 = "select sum(itemdiscamt) as tdiscamt from res_po_detail where pomid=$pomid";
			$rechk11 = mysqli_query($conn, $evechk1);
			while($rtchk11 = mysqli_fetch_assoc($rechk11))
			{
				$_SESSION['tdiscamt']=$rtchk11['tdiscamt'];
			}
			$eve_display= "select * from res_company_master where cmpmid=$cmpmid";
			$re_display = mysqli_query($conn, $eve_display);
			while($rt_display = mysqli_fetch_assoc($re_display))
			{
				$_SESSION['headerimg']=$rt_display['cmpheaderimg'];
				$_SESSION['footerimg']=$rt_display['cmpfooterimg'];
				$_SESSION['cmpstate']=$rt_display['cmpstate'];
				$_SESSION['cmpname']=$rt_display['cmpname'];
				
				$_SESSION['accountname']=$rt_display['accountname'];
				$_SESSION['accountno']=$rt_display['accountno'];
				$_SESSION['ifsccode']=$rt_display['ifsccode'];
				$_SESSION['bankbranchname']=$rt_display['bankbranchname'];
				$_SESSION['gstno']=$rt_display['cmpdetail2'];
				$_SESSION['panno']=$rt_display['cmpdetail1'];
			}
			
		}
	}
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="";
		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="";
	if($disc2=="")
	{
	}
	else
	{
		$this->SetFont('Arial','',10);
		$this->MultiCell(0,5,"$disc2");
		$this->SetLineWidth(.3);
	}
}
function ImprovedTable_4()
{
//	include("../connect.php");
 global $conn;
	$w = array(15,20,40,20,15,20,20,20,20);
	//$tclass="";
	if($_SESSION['tdiscamt']>0)
	{
		$this->SetWidths(array(10,18,70,15,17,15,10,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','QTY','UNIT','RATE','GST (%)','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,14,15,20,10,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','QTY','UNIT','RATE','GST (%)','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_po_detail where pomid=".$_GET['pomid'];
		$re2 = mysqli_query($conn, $eve2);
		while($rt2 = mysqli_fetch_assoc($re2))
		{
			$ccount++;
			$itemid=$rt2['itemid'];
			$itemname=removespecialchar($rt2['itemname']);
			$itemhsncode=$rt2['itemhsncode'];
			$itemiprice=$rt2['itemiprice'];
			$itemamount=$rt2['itemamount'];
			$itemqty=$rt2['itemqty'];
			$itemdesc=removespecialchar($rt2['itemdesc']);
			$itemunit=$rt2['itemunit'];
			$itemdiscper=$rt2['itemdiscper'];
			$itemtotalamount=$rt2['itemtotalamount'];
			$itemgstper=$rt2['itemgstper'];
			$gst=$rt2['itemgstper'];
			$itemgstamount=$rt2['itemgstamount'];
			if($itemgstper>0)
			{	$gstflag=0;
				if(isset($taxper))
				{
					for($j=0;$j<sizeof($taxper);$j++)
					{
						if($taxper[$j]==$itemgstper)
						{
							$gstflag=1;
							$taxvalue[$j]=$taxvalue[$j]+$itemgstamount;
						}
						
					}
				}
				if($gstflag==0)
				{
					$taxper[]=$itemgstper;
					$taxvalue[]=$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,$itemqty,$itemunit,$itemiprice,$gst,$itemdiscper,$itemamount));
			}
			else{
				$this->Row(array($ccount,$itemhsncode,$itemname,$itemqty,$itemunit,$itemiprice,$gst,$itemamount));
			}
		}
		$tgst=0;
		if(isset($taxper))
		{
		for($k=0;$k<sizeof($taxper);$k++)
		{
			$tgst=$tgst+$taxvalue[$k];									
		}}
	
	
	$_SESSION['itemdiscper'] = 0;
	$_SESSION['taxper'] = $taxper;
	$_SESSION['taxvalue'] = $taxvalue;
	$_SESSION['subtotal'] = $subtotal;
	$_SESSION['grandtotal'] = $subtotal +$tgst ;
    $this->Cell(array_sum($w),0,'','T');
	$this->Ln();
}
function ImprovedTable_2()
{
	$cgstno = $_SESSION['cgstno'];
	$cname  = $_SESSION['cname'];
	$customercmpname  = $_SESSION['cname'];
	$cmpname = $_SESSION['cmpname'];
	$customeremail  = $_SESSION['email'];
	//$customerid = $_SESSION['qno'];
	$city = $_SESSION['city'];
	$cstate = $_SESSION['cstate'];
	$address = "";
	$address2 = $city.'-'.$cstate;
	$mobile = $_SESSION['mobile'];
	$customercontactpersonname = $_SESSION['cname'];
	$pdfheaderline1 = "";
	$pdfheaderline2 = "";
	$invoicedate=$_SESSION['invoicedate'];
	$invoicefordisplay=$_SESSION['invoicefordisplay'];
	$invoicerefno=$_SESSION['invoicerefno'];
	//$cmpperson = "";
$line1="";
	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,"PO Number: $invoicefordisplay      Date: $invoicedate",'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: $invoicerefno",'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');
		//$amount = 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'])
	{
		
		$taxper=$_SESSION['taxper'];
		$taxvalue=$_SESSION['taxvalue'];
		if(isset($taxper))
		{
		for($k=0;$k<sizeof($taxper);$k++)
		{
			$key2=$taxper[$k]/2;
			$value1=$taxvalue[$k]/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
	{
		$taxper=$_SESSION['taxper'];
		$taxvalue=$_SESSION['taxvalue'];
		if(isset($taxper))
		{
			for($k=0;$k<sizeof($taxper);$k++)
			{
		
			$key=$taxper[$k];
			$value=$taxvalue[$k];
			$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(138,29,23);

		$qroundoffamount= $_SESSION['invoiceroundoffamount'];
		
		$invoicenetamount= $_SESSION['invoicenetamount'];
		setlocale(LC_MONETARY, 'en_IN');
		//$gt1 = money_format('%!i', $invoicenetamount);
		//$qroundoffamount = money_format('%!i', $qroundoffamount);
		$amountinwords =  convert_number_to_words($invoicenetamount);
		
		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,"$invoicenetamount",'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();
		$w = array(130,60);
		
		$cmpname=$_SESSION['cmpname'];
		$cmpname=$_SESSION['cmpname'];
		$accountno=$_SESSION['accountno'];
		$accountname=$_SESSION['accountname'];
		$ifsccode=$_SESSION['ifsccode'];
		$bankbranchname=$_SESSION['bankbranchname'];
		$createdby=$_SESSION['createdby'];
			$gstno=$_SESSION['gstno'];
		$panno=$_SESSION['panno'];
		
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"GST No: $gstno",'L',0,'L');
		$this->Cell($w[1],6,"Account No: $accountno",'R',0,'L');
		$this->Ln();
		
		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"PAN No: $panno",'L',0,'L');
		$this->Cell($w[1],6,"Account Name: $accountname",'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,"IFSC Code: $ifsccode",'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,"Bank Name: $bankbranchname",'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();
		
		
		$invoiceterms=$_SESSION['invoiceterms'];

		if($invoiceterms==""){
		
		}
		else{
		$this->SetFont('Arial','B',10);
		$this->Cell(190,5,'Terms & Conditions','LR',0,'L');
		$this->Ln();
		$this->SetFont('Arial','',10);
		$this->MultiCell(0,5,"$invoiceterms",'LR');
		$this->SetLineWidth(.3);
		$this->SetFont('Arial','B',10);
		$this->Cell(190,5,'','LR',0,'C');
		$this->Ln();
		}
        $this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
		$this->Cell($w[0],6,"",'L',0,'L');
		$this->Cell($w[1],6,"For, $cmpname",'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);
		$this->SetFont('Arial','B',10);
		$this->Cell(190,5,'Declaration','LR',0,'L');
		$this->Ln();
		$this->SetFont('Arial','',10);
		$this->MultiCell(0,5,"$invremarks",'LR');
		$this->SetLineWidth(.3);
		$this->SetFont('Arial','B',10);
		$this->Cell(190,5,'','LR',0,'C');
		$this->Ln(); */
		$w = array(190,0);

		$this->SetFont('Arial','B',10);
		$this->SetLineWidth(.3);
        $this->Cell($w[0],6,"",'LR');
		$this->Ln();
		
		//$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,"Purchase Order",0,0,'C');
    $this->Ln(6);

}
function ImprovedTable_8()
{
    $w = array(95,95);
	$invoiceterms=$_SESSION['invoiceterms'];
	if($invoiceterms=="")
	{
	}
	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,"$invoiceterms");
		$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();
//$settingtype = $_SESSION['settingtype'];
$popdf = $_SESSION['popdf'];
$pomid = $_GET['pomid'];
$pdf->Output('F',"download/$popdf");

//return;

header("Location: purchaseorderstatus.php?id=$pomid");




?>
