<?php
	ob_start();
	session_start();
?>
<?php
	if(!isset($_SESSION["adminname"]) && !isset($_SESSION["username"]))
	{
		header("Location: index.php");
	}
?>
<html>
<head><title>BM BIO ENERGY</title>



<?php
include("config.php");
if(isset($_POST['submit']))
{
$sqry=mysql_query("select * from report order by id desc limit 0,1");
$srw=mysql_fetch_array($sqry);
$rr=mysql_num_rows($sqry);	
$ss=1;
$d=date("d");
$m=date("m");
if($m=='04' )
{
	$dbd=$srw['date'];
	$rcindate_array=explode("-",$dbd);
	$dbdate=$rcindate_array[0];
	$dbmnth=$rcindate_array[1];
	if($d!=$dbdate && $m!=$dbmnth)
	{
		$ss=0;
	}
	else
	{
		$ss=1;
	}
}

if($rr==0 || $ss==0)
{
	$invoiceno=1;
}
else
{
	$dcn=$srw['invoiceno'];
	$invoiceno=$dcn+1;
}
$in=3;
$invoiceno = str_pad($invoiceno, $in, "0", STR_PAD_LEFT);

$dcno = str_pad($dcno, $in, "0", STR_PAD_LEFT);

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:110px;
top:137px;
font-size: 18px;
line-height:28px;
}
.box3
{
position: absolute;
width: 100%;
left:517px;
top:147px;
font-size: 18px;
line-height:30px;
}
.box4
{
position: absolute;
width: 100%;
left:682px;
top:137px;
font-size: 18px;
line-height:30px;
}
.box5
{
position: absolute;
width: 100%;
left:18px;
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:872px;
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:793px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box10
{
position: absolute;
width: 100%;
left:500px;
top:823px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box11
{
position: absolute;
width: 100%;
left:500px;
top:850px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box12
{
position: absolute;
width: 100%;
left:580px;
top:793px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box13
{
position: absolute;
width: 100%;
left:700px;
top:793px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box14
{
position: absolute;
width: 100%;
left:580px;
top:823px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box15
{
position: absolute;
width: 100%;
left:700px;
top:823px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box16
{
position: absolute;
width: 100%;
left:580px;
top:850px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box17
{
position: absolute;
width: 100%;
left:700px;
top:850px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.don1
{
position: absolute;	
margin-left:15px !important;
margin-top: -8px !important;	
}
.don2
{
position: absolute;
margin-left:352px !important;
margin-top: -25px !important;	
}
.don3
{
position: absolute;
margin-left:389px !important;
margin-top: -27px !important;	
}
.don4
{
position: absolute;
margin-left: 420px !important;
margin-top: -26px !important;	
}
.don5
{
position: absolute;
margin-left: 473px !important;
margin-top: -25px !important;	
	
}
.don6
{
position: absolute;
margin-left: 575px !important;
margin-top: -27px !important;	
}
.don7
{
position: absolute;
margin-left: 675px !important;
margin-top: -28px !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" />';
										
						$q1=mysql_query("select * from report where invoiceno='$invoiceno' and cdate='$cdate'");
						$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   : 33ACPFS7383DIZS</div></div> <br>";
						$html.="<div class='box8'><div class='don don9' >HSM Code:38081011</div></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:-30;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=date('d-m-Y');
$val='pdf/'.$date.'-'.$invoiceno.'.pdf'; 
$mpdf->Output($val, 'F');
$up=mysql_query("update report set pdf='$val' where invoiceno='$invoiceno'");
if($up){
	$_SESSION['s_msg']="Sales Order Status Updated Successfully!!!";
	?>
		<!--<script type="text/javascript">window.location.href="viewreport";</script>-->
		<?php
}

	?>
		<!--<script type="text/javascript">window.location.href="report1";</script>-->
		<?php
 }
$sqry=mysql_query("select * from report order by id desc limit 0,1");
$srw=mysql_fetch_array($sqry);
$rr=mysql_num_rows($sqry);	
	$ss=1;
	$d=date("d");
	$m=date("m");
	if($m=='04' )
	{
		$dbd=$srw['date'];
		$rcindate_array=explode("-",$dbd);
		$dbdate=$rcindate_array[0];
		$dbmnth=$rcindate_array[1];
		if($d!=$dbdate && $m!=$dbmnth)
		{
			$ss=0;
		}
		else
		{
			$ss=1;
		}
	}

	if($rr==0 || $ss==0)
	{
		$invoiceno=1;
	}
	else
	{
		$dcn=$srw['invoiceno'];
		$invoiceno=$dcn+1;
	}
	$in=3;
	$invoiceno = str_pad($invoiceno, $in, "0", STR_PAD_LEFT);
if($rr==0 || $ss==0)
{
	$dcno=001;
}
else
{
	$dcnum=$srw['dcno'];
	$dcno=$dcnum+1;
}
$dcno = str_pad($dcno, $in, "0", STR_PAD_LEFT);
	
?>


<body style="background-color: rgb(0, 150, 136);">

<?php
if(isset($val))
{
?>
	<center><a target="_blank" href="<?php echo $val; ?>" class="pdf">Print PDF</a></center>
<?php
}
?>

</body>
</html>
