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

<?php

/*$_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: 2px;
top: 52px;
}
.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;
}
table  input[type=text]
{
height: 33px;
border: 1px solid #000;
border-radius: 4px;
font-size: 15px;
padding: 9px;
}
.inpu1
{ 
width: 100%;
}
table, tr, td {
border: 1px solid white;
border-collapse: collapse;
padding: 8px;
font-size: 19px;
}

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: 79%;
height: 28px;
float: right;
margin: -79px -6px;
text-align: center;
color: #FFF;
border-radius: 4px;
border: 1px solid white;
}
.voice
{
width: 20%;
height: 28px;
border-radius: 4px;
border: 1px solid black;
font-size: 18px;
}
.sub
{
width: 15%;
height: 29px;
background-color: #5CB85C;
border-radius: 4px;
border: 1px solid #FFF;
font-size: 20px;
color: #FFF;
}
.ser
{
width: 100%;
}

</style>
</head>

<body>
<?php
include("config.php");

	$id=$_GET['id'];
	$sql="select * from report where id='$id'";
	$sqle=mysql_query($sql);
	$row=mysql_fetch_array($sqle);
	?>
	<body style="background-color: rgb(0, 150, 136); color: white;">
<div class="thala">
<center><h1>BM BIO ENERGY</h1></center>
</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" value="<?php echo $row['address1']?>" required maxlength=30/>
					<input type="hidden" class="inpu" name="id1" id="id1" value="<?php echo $_GET['id']?>" maxlength=20/>
					</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" value="<?php echo $row['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" value="<?php echo $row['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" value="<?php echo $row['address4']?>" required maxlength=30/></div>
						<div style="clear:both;"></div>
					</div>
				</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 $row['invoiceno'] ?>"  maxlength=10/></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" value="<?php echo $row['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" value="<?php echo $row['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" value="<?php echo $row['tinno']?>"  maxlength=10/></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" readonly  value="<?php echo $row['date']?>" /></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" readonly  value="<?php echo $row['dat1']?>" /></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" readonly  value="<?php echo $row['dat2']?>" /></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" readonly /></td>
			<td><input type="text" class="inpu1" name="a1l" id="a1l" value="<?php echo $row['a1l']?>" onblur="vetri();" onKeyUp="this.value=this.value.replace(/[^0-9,\.]/g,'');" ></td>
			<td><input type="text" class="inpu1" name="a5l" id="a5l" value="<?php echo $row['a5l']?>"   onblur="vetri();" onKeyUp="this.value=this.value.replace(/[^0-9,\.]/g,'');"></td>
			<td><input type="text" class="inpu1" name="a50l" id="a50l" value="<?php echo $row['a50l']?>"  onblur="vetri();" onKeyUp="this.value=this.value.replace(/[^0-9,\.]/g,'');"></td>
			<td><input type="text" class="inpu1" name="aquantity" id="aquantity" value="<?php echo $row['aquantity']?>" value="0" readonly /></td>
			<td><input type="text" class="inpu1" name="aunitprice" id="aunitprice" value="<?php echo $row['aunitprice']?>"  onblur="selvan();" onKeyUp="this.value=this.value.replace(/[^0-9,\.]/g,'');"/></td>
			<td><input type="text" class="inpu1" name="aamount" value="<?php echo $row['aamount']?>" readonly id="aamount"/></td></tr>
			
		
			</tbody>
			</table>
				<div class="fool">
				
			<center><input type="submit" class="sub" name="update" id="Update" style="margin-top: 19px;" value="Save"></center>	
			<?php
			if(isset($_POST['update']))
{
$id=$_POST['id1'];
$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'];
$cdate=date('Y-m-d');
$created_date=date('Y-m-d H:i:s');
if($address1!="" && $date!="" && $orderno!="" && ($a1l!='' || $a5l!='' || $a50l!='')  )
{
  $sql="UPDATE report set cdate='{$cdate}',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}',created_date='{$created_date}',updated_date='{$created_date}' Where id='$id'";
  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>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:149px;
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:795px;
font-size: 15px;	
line-height:40px;
font-weight: bold;
}
.box7
{
position: absolute;
width: 100%;
left:145px;
top:892px;
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>"; 
										
											$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['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['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='box6'><b>Remarks :</b>".$q1res['remarks']."</div><br>";
											
											$html.="<div class='box7' style='font-weight: bold;' >".convert_number_to_words($aamount)."<div style='margin-top:-35;margin-left: 555px !important;font-weight: bold;font-size:15px' >".$q1res['aamount']."</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
 }
			if(isset($val))
			{
				?>
	<center><a href="<?php echo $val ?>" style="text-decoration: none; font-weight: bold; font-size: 22px; color: red;" target="_blank">CLICK HERE TO VIEW PDF</a></center>	

	<?php
			}
	?>
	</div>
	
		
		
	
	
		
		
</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>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#date" ).datepicker();
    $( "#dat1" ).datepicker();
    $( "#dat2" ).datepicker();
  });
  </script>

