<?php
	ob_start();
	session_start();
?>
<?php
	if(!isset($_SESSION["adminname"]) && !isset($_SESSION["username"]))
	{
		header("Location: index.php");
	}
?>
<?php
include("config.php");

 function convert_number_to_words($num) 
{
	$number =(float)number_format($num, 2, '.', '');echo '<br>';
	 $no = (float)number_format($number, 2, '.', '');echo '<br>';
	$pos=strrpos($number,'.');
	$type='';
	if($pos)
	{
	$type=substr($number,$pos+1);
	}
	$point = $type ;
	$hundred = null;
	$digits_1 = strlen($no);
	$digits_2 = strlen($point);
	$i = 0;
    $j = 0;
    $str = array();
    $str1 = 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);
  while ($j < $digits_2) {
     $divider = ($j == 2) ? 10 : 100;
     $number1= floor($point % $divider);
     $point = floor($point / $divider);
     $j += ($divider == 10) ? 1 : 2;
     if ($number1) {
        $plural = (($counter = count($str1)) && $number1> 9) ? 's' : null;
        $hundred = ($counter == 1 && $str1[0]) ? ' and ' : null;
        $str1 [] = ($number1 < 21) ? $words[$number1] .
            " " . $digits[$counter] . $plural . " " . $hundred
            :
            $words[floor($number1 / 10) * 10]
            . " " . $words[$number1 % 10] . " "
            . $digits[$counter] . $plural . " " . $hundred;
     } else $str1[] = null;
  }
  $result1 = implode('', $str1);
   if($result1!='')
   {
	 $result1 ='And '. $result1.'Paise';
   }
   else
   {
	 $result1 ='';
	 
   }
  $string=$result . "Rupees  " .$result1. " Only";
  
    return strtoupper($string);
}
 
include("MPDF/mpdf.php");
//require_once("numberinword.php");
$mpdf=new mPDF(''); 
$mpdf=new mPDF('c','A4','','',0,0,0,0,0,0); 
//$mpdf=new mPDF('c','A4','','',10,15,50,35,10,10); 
$mpdf->useOnlyCoreFonts = true;    // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("");
$mpdf->SetAuthor("");
$mpdf->SetWatermarkText("");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
//$mpdf->mirrorMargins = 1;
$html = '
<html>
<head>
<title>BM BIO ENERGY</title>
<style>
.box2
{
position: absolute;
width: 100%;
left:77px;
top:137px;
font-size: 18px;
line-height:28px;
}
.box3
{
position: absolute;
width: 100%;
left:503px;
top:133px;
font-size: 18px;
line-height:30px;
}
.box4
{
position: absolute;
width: 100%;
left:682px;
top:129px;
font-size: 18px;
line-height:30px;
}
.box5
{
position: absolute;
width: 100%;
left:22px;
top:362px;
font-size: 14px;
line-height:27px;
}
.box6
{
position: absolute;
width: 100%;
left:60px;
top:793px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box7
{
position: absolute;
width: 100%;
left:145px;
top:879px;
font-size: 11px;	
line-height:40px;
}
.box8
{
position: absolute;
width: 100%;
left:18px;
top:393px;
font-size: 14px;
line-height:27px;
}
.box9
{
position: absolute;
width: 100%;
left:500px;
top:787px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box10
{
position: absolute;
width: 100%;
left:500px;
top:817px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box11
{
position: absolute;
width: 100%;
left:500px;
top:844px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box12
{
position: absolute;
width: 100%;
left:580px;
top:787px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box13
{
position: absolute;
width: 100%;
left:700px;
top:787px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box14
{
position: absolute;
width: 100%;
left:580px;
top:817px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box15
{
position: absolute;
width: 100%;
left:700px;
top:817px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box16
{
position: absolute;
width: 100%;
left:580px;
top:845px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box17
{
position: absolute;
width: 100%;
left:700px;
top:845px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.don1
{
position: absolute;	
margin-left:15px !important;
margin-top: -13px !important;	
}
.don2
{
position: absolute;
margin-left:358px !important;
margin-top: -35px !important;	
}
.don3
{
position: absolute;
margin-left:395px !important;
margin-top: -28px !important;	
}
.don4
{
position: absolute;
margin-left: 426px !important;
margin-top: -24px !important;	
}
.don5
{
position: absolute;
margin-left: 473px !important;
margin-top: -23px !important;	
	
}
.don6
{
position: absolute;
margin-left: 575px !important;
margin-top: -25px !important;	
}
.don7
{
position: absolute;
margin-left: 675px !important;
margin-top: -25px !important;	
}
.don8
{
position: absolute;	
margin-left:35px !important;
margin-top: -8px !important;	
}
.don9
{
position: absolute;	
margin-left:35px !important;
margin-top: -10px !important;	
}
.don10
{
position: absolute;
margin-left: 500px !important;
margin-top: 795px !important;		
}
.don11
{
position: absolute;
margin-left: 575px !important;
margin-top: -75px !important;	
}
</style>
</head>
<body>
<!--mpdf

<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />';
										
									//	$html.="<div class=''><img src='img/vetri.jpg' width='100%' height='100%'></img></div>"; 
										
											$q1=mysql_query("select * from report where invoiceno='184' and cdate='2018-02-28'");
											$q1res=mysql_fetch_assoc($q1);
											$html.="<div class='box2' ><div class='don'>".$q1res['address1']."</div><div class='don'>".$q1res['address2']."</div><div class='don'>".$q1res['address3']."</div><div class='don'>".$q1res['address4']."</div></div>";
											
											$html.="<div class='box3'><div class='don' >".$q1res['invoiceno']."</div><div class='don' >".$q1res['orderno']."</div><div class='don' >".$q1res['dcno']."</div><div class='don'>".$q1res['tinno']."</div></div>";
											
											$html.="<div class='box4'><div class='don' >".$q1res['date']."</div><div class='don'>".$q1res['dat1']."</div><div class='don'>".$q1res['dat2']."</div></div>";
											
											
										$html.="<div class='box5'><div class='don don1' ></div><div class='don don2' >".$q1res['a1l']."</div><div class='don don3' >".$q1res['a5l']."</div><div class='don don4' >".$q1res['a50l']."</div><div class='don don5' >".$q1res['aquantity']."</div><div class='don don6' >".$q1res['aunitprice']."</div><div class='don don7' style='font-weight: bold;font-size:15px' >".$q1res['aamount1']."</div></div><br>";
										$html.="<div class='box5'><div class='don don8'> GST No   : 34AAMFB9946N1ZO</div></div> <br>";
										$html.="<div class='box8'><div class='don don9' >HSN Code:38081011</div></div><br>";
											
											//$html.="<div class='box6'>ALWAYS DILUTE ONE LITRE OF AGRITONE 4.5 WITH 50 TIMES OF WATER.</div><br>";
											$html.="<div class='box6'><b>Remarks :</b>".$q1res['remarks']."</div><br><div class='box9' >SGST</div><div class='box12' >".$q1res['sgst']."</div><div class='box13' >".$q1res['sgstamount']."</div>";
											$html.="<div class='box10' >CGST</div><div class='box14' >".$q1res['cgst']."</div><div class='box15' >".$q1res['cgstamount']."</div>";
											$html.="<div class='box11' >IGST</div><div class='box16' >".$q1res['igst']."</div><div class='box17' >".$q1res['igstamount']."</div>";
											
											$html.="<div class='box7' style='font-weight: bold;' >".convert_number_to_words($taxamount)."<div style='margin-top:-47;margin-left: 555px !important;font-weight: bold;font-size:15px' >".$q1res['taxamount']."</div></div>";

$mpdf->useAdobeCJK = true;
$mpdf->SetAutoFont(AUTOFONT_ALL);
$mpdf->WriteHTML($html);

$date="28-02-2018";
$val='pdf/'.$date.'-184.pdf'; 
$mpdf->Output($val, 'F');
//$up=mysql_query("update report set pdf='$val' where invoiceno='$invoiceno'");
?>