<?php
	ob_start();
	session_start();
?>

<?php
//echo $_SESSION["adminname"];
	if(!isset($_SESSION["adminname"]))
	{
		header("Location: index.php");
	}
?>
<html>
<head><title>BM BIO ENERGY</title>
  
	
<style type="text/css">

.view
{
padding: 2px;
font-weight: bold;
width: 11%;
background: #5CB85C none repeat scroll 0% 0%;
font-size: 24px;
color: #FFF;
text-decoration: none;
border: 1px solid #FFF;
text-align: center;
border-radius: 4px;
height: 27px;
position: absolute;
right: 516px;
top: 566px;
}
.pdf
{
padding: 2px;
font-weight: bold;
width: 11%;
background: #5CB85C none repeat scroll 0% 0%;
font-size: 24px;
color: #FFF;
text-decoration: none;
border: 1px solid #FFF;
text-align: center;
border-radius: 4px;
height: 27px;
position: absolute;
right: 350px;
top: 566px;
}
.box1
{
margin-top: -36px;
width: 97%;

}
.box2
{
width: 60%;
float: left;
margin-top: 30px;
}
.box22
{
width: 67%;
float: left;
margin-top: -311px;
margin-left: 418px;
}
.box33
{
width: 26%;
float: right;
margin-top: -357px;
margin-right: 73px;
}
.box44
{
width: 60%;
float: left;
margin-top: -212px;
margin-left: 1061px;
}
.box3
{
width: 15%;
float: left;
font-size: 24px;
}
.seae
{
width: 7%;
float: left;
font-size: 18px;
font-weight: bold;
}
.box4
{
width: 85%;
float: left;
margin-top: 13px;
}
.don
{
width: 100%;
float: left;
}
.inpu
{ 
width: 43%;
border: 1px solid #000;
height: 35px;
font-size: 18px;
border-radius: 4px;
margin-top: 8px;
}

.inpu1
{ 
width: 100%;
}
table, tr, td {
border: 1px solid white;
border-collapse: collapse;
padding: 8px;
font-size: 19px;
}
table  input[type=text]
{
height: 33px;
border: 1px solid #000;
border-radius: 4px;
font-size: 15px;
padding: 9px;
}
table {
width: 100%;
}
.table
{
margin: 29px;
width: 90%;
font-size: 23px;
}
.fool
{
width: 60%;
float: left;
margin-left: 12%;
}
.thala 
{
width: 100%;
color: #FFF;
margin-top: 0px;
}
.bo
{
margin-top: 12px;
width: 99%;
margin-left: 23px;
}
.se
{
margin-top: 11px;
width: 38%;
}
.out
{
background-color: #5CB85C;
text-decoration: none;
width: 12%;
height: 28px;
float: right;
text-align: center;
color: #FFF;
border-radius: 4px;
border: 1px solid #FFF;
top: 0px !important;
position: absolute;
margin-left: 40px;
}
.voice
{
width: 20%;
height: 28px;
border-radius: 4px;
border: 1px solid black;
font-size: 18px;
}
.sub
{
font-weight: bold;
width: 11%;
background: #5CB85C none repeat scroll 0% 0%;
font-size: 24px;
color: #FFF;
text-decoration: none;
border: 1px solid #FFF;
text-align: center;
border-radius: 4px;
height: 33px;
position: absolute;
right: 684px;
top: 566px;
font-family: times new;

}
.ser
{
width: 100%;
}
</head>
</style>


<?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);
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$address3=$_POST['address3'];
$address4=$_POST['address4'];
$lrno=$_POST['lrno'];
$invoiceno=$_POST['invoiceno'];
$orderno=$_POST['orderno'];
$dcno=$_POST['dcno'];
$tinno=$_POST['tinno'];
$remarks=$_POST['remarks'];
$date=$_POST['date'];
$dat1=$_POST['dat1'];
$dat2=$_POST['dat2'];
$transport=$_POST['transport'];
$adescription=$_POST['adescription'];
$a1l=$_POST['a1l'];
$a5l=$_POST['a5l'];
$a50l=$_POST['a50l'];
$aquantity=$_POST['aquantity'];
$aunitprice=$_POST['aunitprice'];
$aamount=$_POST['aamount'];
 $sql="insert into report set address1='{$address1}',address2='{$address2}',address3='{$address3}',address4='{$address4}',lrno='{$lrno}',invoiceno='{$invoiceno}',orderno='{$orderno}',dcno='{$dcno}',tinno='{$tinno}',remarks='{$remarks}',date='{$date}',dat1='{$dat1}',dat2='{$dat2}',transport='{$transport}',adescription='{$adescription}',a1l='{$a1l}',a5l='{$a5l}',a50l='{$a50l}',aquantity='{$aquantity}',aunitprice='{$aunitprice}',aamount='{$aamount}'";
 mysql_query($sql)or die (mysql_error());
 if($sql)
  {
	//header("Location: viewreport.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>title</title>
<style>
.box2
{
position: absolute;
width: 100%;
left:100px;
top:90px;
font-size: 18px;
line-height:28px;
}
.box3
{
position: absolute;
width: 100%;
left:510px;
top:120px;
font-size: 18px;
line-height:30px;
}
.box4
{
position: absolute;
width: 100%;
left:670px;
top:90px;
font-size: 18px;
line-height:30px;
}
.box5
{
position: absolute;
width: 100%;
left:15px;
top:310px;
font-size: 14px;
line-height:27px;
}
.box6
{
position: absolute;
width: 100%;
left:60px;
top:645px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box7
{
position: absolute;
width: 100%;
left:145px;
top:780px;
font-size: 11px;	
line-height:40px;
}
.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;	
}

</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>"; 
										echo "select * from report where invoiceno='$invoiceno'";
											$q1=mysql_query("select * from report where invoiceno='$invoiceno'");
											$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 class='don'>".$q1res['address4']."</div><div class='don'>".$q1res['lrnno']."</div></div>";
											
											$html.="<div class='box22' ><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 class='don'>".$q1res['remarks']."</div></div>";
											
											$html.="<div class='box33'><div class='don' >".$q1res['date']."</div><div class='don' >".$q1res['dat1']."</div><div class='don' >".$q1res['dat2']."</div><div class='don' >".$q1res['transport']."</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['aamount']."</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='box7' style='font-weight: bold;'>".convert_number_to_words($aamount)."</div>";
											

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


$val='pdf/'.$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);
?>


<body style="background-color: rgb(0, 150, 136);">
<div class="thala">
<center><h1>BM BIO ENERGY</h1></center><h2 style="margin-left:85%; ">
<a class="out" href="logout.php">Logout</a></h2>
</div>
<form method="post" enctype="multipart/form-data">
		<div class="box1">
				<div class="box2">
					<div class="don">
					<p class="box3">Address 1</p><div class="box4"><input type="text" class="inpu" name="address1" id="address1"  required maxlength=30/></div>
					<div style="clear:both;"></div>
					</div>
					<div class="don">
						<p class="box3">Address 2</p><div class="box4"><input type="text" class="inpu" name="address2" id="address2"  required maxlength=30 /></div>
						<div style="clear:both;"></div>
					</div>	
					<div class="don">
						<p class="box3">Address 3</p><div class="box4"><input type="text" class="inpu" name="address3" id="address3" required maxlength=30 /></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
						<p class="box3">Address 4</p><div class="box4"><input type="text" class="inpu" name="address4" id="address4" required maxlength=30/></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
					<p class="box3">LR No</p><div class="box4"><input type="text" class="inpu" name="lrno" id="lrno" required maxlength=30/></div>
						<div style="clear:both;"></div>
					</div>
				</div>
			<div style="clear:both;">
				</div>
				<div class="box22">
				 <div class="don">
						<p class="box3">Invoice No</p> <div class="box4"><input type="text" class="inpu se" name="invoiceno" id="invoiceno" value="<?php echo $invoiceno;?>" required readonly /></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
						<p class="box3">Your Order No</p> <div class="box4"><input type="text" class="inpu se" name="orderno" id="orderno"  maxlength=10></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
						<p class="box3">Our D.C No</p> <div class="box4"><input type="text" class="inpu se " name="dcno" id="dcno"  maxlength=10/></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
						<p class="box3">Party's TIN No</p> <div class="box4"><input type="text" class="inpu se" name="tinno" id="tinno"  maxlength=15/></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
						<p class="box3">Remarks</p><div class="box4"><input type="text" class="inpu se" name="remarks" id="remarks"  maxlength=15/></div>
						<div style="clear:both;"></div>
					</div>
				
				</div>
			<div class="box33">
				<div class="don">
						<p class="box3">Date</p> <div class="box4"><input type="text" class="inpu bo" name="date" id="date" onmouseover='datepickvals(this.id);'  /></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
						<p class="box3">Date1</p> <div class="box4"><input type="text" class="inpu bo" name="dat1" id="dat1"  onmouseover='datepickvals(this.id);'/></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
						<p class="box3">Date2</p> <div class="box4"><input type="text" class="inpu bo" name="dat2" id="dat2" onmouseover='datepickvals(this.id);'/></div>
						<div style="clear:both;"></div>
					</div>
					<div class="don">
					 <p class="box3">Transport</p><div class="box4"><input type="text" class="inpu bo" name="transport" id="transport" maxlength=30>
						</div>
						<div style="clear:both;"></div>
					</div>
				</div>
			</div>
			<table>
			<tbody>
			<tr><td>Description</td><td>1L</td><td>5L</td><td>50L</td><td>Quantity</td><td>Unit Price</td><td>Amount</td></tr>
			<tr><td><input type="text" class="inpu1" name="adescription"   id="adescription" value="AGRITONE 4.5" readonly /></td>
			<td><input type="text" class="inpu1" name="a1l" id="a1l" value="0"   onblur="vetri();" onKeyUp="this.value=this.value.replace(/[^0-9,\.]/g,'');" ></td>
			<td><input type="text" class="inpu1" name="a5l" id="a5l" value="0"   onblur="vetri();" onKeyUp="this.value=this.value.replace(/[^0-9,\.]/g,'');"></td>
			<td><input type="text" class="inpu1" name="a50l" id="a50l" value="0"  onblur="vetri();" onKeyUp="this.value=this.value.replace(/[^0-9,\.]/g,'');"></td>
			<td><input type="text" class="inpu1" name="aquantity" id="aquantity" value="" readonly /></td>
			<td><input type="text" class="inpu1" name="aunitprice" id="aunitprice" value="0"  onblur="selvan();" onKeyUp="this.value=this.value.replace(/[^0-9,\.]/g,'');"/></td>
			<td><input type="text" class="inpu1" name="aamount" value="" readonly id="aamount"/></td></tr>
			</tbody>
			</table>
		    <div class="fool">
			<center>
			<input type="submit" name="submit" id="submit" class="sub"  value="Save">
			</center>	
			<a href="viewreport.php" class="view">Bill View</a>
			</div>
			<?php
			if(isset($val))
			{
				?>
			<a href="<?php echo $val; ?>" class="pdf">Print PDF</a>
			<?php
			}
	?>
			</form>	

</body>
</html>
<script type="text/javascript">
	function vetri()
{
		var a1l=document.getElementById('a1l').value;
		var a5l=document.getElementById('a5l').value;
		var a50l=document.getElementById('a50l').value;
		if(a1l=='')
		{
			var a1l='0';
		}
		if(a5l=='')
		{
			var a5l='0';
		}
		if(a50l=='')
		{
			var a50l='0';
		}
		var aquantity= parseInt(a1l)+(parseInt(a5l)*5)+(parseInt(a50l)*50);
		document.getElementById('aquantity').value=aquantity;
		selvan();
}
	function selvan()
{
		var aquantity=document.getElementById('aquantity').value;
		var aunitprice=document.getElementById('aunitprice').value;
		if(aquantity=='')
		{
			var aquantity='0';
		}
		if(aunitprice=='')
		{
			var aunitprice='0';
		}
		var aamount= parseInt(aquantity)*parseInt(aunitprice);
		document.getElementById('aamount').value=aamount;
		cal();
}

</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="dp/js/jquery.timepicker.js"></script>
<script src="dp/lib/bootstrap-datepicker.js"></script>
 <link rel="stylesheet" type="text/css" href="dp/lib/bootstrap-datepicker.css" />
		<script>
			function datepickvals(a)
		{
			$('#'+a).datepicker({
				'format': 'dd-mm-yyyy',
				'autoclose': true
			});
		}
		</script>
		 <script>
                $('#basicExample .time').timepicker({
                    'showDuration': true,
                    'timeFormat': 'g:ia'
                });

                $('#basicExample .date').datepicker({
							'minDate': '0',
							'numberOfMonths': '1',
                    'format': 'dd-mm-yyyy',
                    'autoclose': true
                });

        </script>