<?php
require('../config/dbcon.php');
$output = '';
if (isset($_POST["query"])) {
	$query = "Select noofrow from noofrow_mst where description='noofrow'";
	$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
	while ($row = mysqli_fetch_assoc($rs)) {
		$noofrow     = $row['noofrow'];
	}

	$search = mysqli_escape_string($connect, $_POST["query"]);
	$query = "Select * from bill_mst where Lower(party_name) LIKE Lower('%" . $search . "%') or Lower(truck_number) LIKE Lower('%" . $search . "%') or Lower(bill_number) LIKE Lower('%" . $search . "%') or Lower(placefrom) LIKE Lower('%" . $search . "%') or Lower(destination) LIKE Lower('%" . $search . "%') order by id,bill_number limit $noofrow";
} else {
	$query = "Select noofrow from noofrow_mst where description='noofrow'";
	$rs = mysqli_query($connect, $query) or die("Cannot execute query: $query\n");
	while ($row = mysqli_fetch_assoc($rs)) {
		$noofrow     = $row['noofrow'];
	}
	$query = "Select * from bill_mst order by id,bill_number";
}
$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
	$output .= '
    <div class="table-responsive" style="width: 150%; overflow:auto; height: 100%;">
    	<table id="tblexportData" style="font-size:18px;" class="table table bordered">
    		<tr>
    			<th width="80px" style=" text-align: center">Print-1</th>
    			<th width="80px" style=" text-align: center">Print-2</th>
    			<th style = "width:120px; text-align: left">bill_date</th>
    			<th style = "width:80px; text-align: left">bill_number</th>
    			<th style = "width:400px; text-align: left">party_name</th>
    			<th style = "width:100px; text-align: left">truck_number</th>
    			<th style = "width:100px; text-align: left">placefrom</th>
    		    <th style = "width:500px; text-align: left">destination</th>
    			<th style = "width:100px; text-align: right">booking_rate</th>
    			<th style = "width:100px; text-align: right">Others</th>
    			<th style = "width:100px; text-align: right">lorry_freight</th>
    			<th style = "width:100px; text-align: left">delivery_date</th>
    			<th style = "width:100px; text-align: left">acc_rec_date</th>
    			<th style = "width:100px; text-align: left">driver_name</th>
    			<th style = "width:100px; text-align: left">driver_mob_no</th>
    			<th style = "width:100px; text-align: left">loading_code</th>
    			<th style = "width:100px; text-align: left">loading_date</th>
    			<th style = "width:500px; text-align: left">Rupees_In_Words</th>
    		</tr>';
	while ($row = mysqli_fetch_array($result)) {
	    $orgDate = $row["bill_date"]; 
    	$newDate = date("d-m-Y", strtotime($orgDate));
    	$inv_date=$newDate;
    	
    	$orgDate1 = $row["date_one"]; 
    	$newDate1 = date("d-m-Y", strtotime($orgDate1));
    	$inv_date1=$newDate1;
		$output .= '
			<tr>
			    <!--td><a class="float-right btn btn-primary btn-xs" style=" text-align: center;" href="invprt? bill_number=' . $row['bill_number'] . '">Print</a></td-->
				<td style="text-align: center"><a style="width:60px; height:25px; text-align: center;"  href="invprt1? bill_number=' . $row['bill_number'] . '" class="float-right btn btn-primary btn-xs">Print-1</a></td>
				<td style="text-align: center"><a style="width:60px; height:25px; text-align: center;"  href="invprt2? bill_number=' . $row['bill_number'] . '" class="float-right btn btn-primary btn-xs">Print-2</a></td>
				<td style="text-align: left">' . $inv_date . '</td>
				<td style="text-align: left">' . $row["bill_number"] . '</td>
				<td style="text-align: left">' . $row["party_name"] . '</td>
				<td style="text-align: left">' . $row["truck_number"] . '</td>
				<td style="text-align: left">' . $row["placefrom"] . '</td>
				<td style="text-align: left">' . $row["destination"] . '</td>
				<td style="text-align: right">' . $row["booking_rate"] . '</td>
				<td style="text-align: right">' . $row["extra"] . '</td>
				<td style="text-align: right">' . $row["lorry_freight"] . '</td>
				<td style="text-align: left">' . $row["delivery_date"] . '</td>
				<td style="text-align: left">' . $row["acc_rec_date"] . '</td>
				<td style="text-align: left">' . $row["driver_name"] . '</td>
				<td style="text-align: left">' . $row["driver_mob_no"] . '</td>
				<td style="text-align: left">' . $row["id"] . '</td>
				<td style="text-align: left">' . $inv_date1 . '</td>
				<td style="text-align: left">' . $row["rupeesinwords"] . '</td>
			</tr>
		';
	}
	echo $output;
} else {
    echo '<div style="font-size:24px; font-weight:bold;  color: #000066;">Data Not Found</div>';
}