<?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 audit_mst where Lower(party_name) LIKE Lower('%" . $search . "%') or Lower(truck_number) LIKE Lower('%" . $search . "%') or Lower(bill_number) LIKE Lower('%" . $search . "%') or Lower(supp_name) 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 audit_mst order by id,bill_number limit $noofrow";
}

$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
	$output .= '
	<div class="table-responsive" style="width: 310%; overflow:auto; height: 100%;">
		<table id="tblexportData" style="font-size:18px;" class="table table bordered" >
			<tr>
				<th width="80px" style=" text-align: center">Edit</th>
				<th width="80px" style=" text-align: center">Print</th>
				<th style = "width:100px; text-align: left">loading_number</th>
				<th style = "width:100px; text-align: left">loading_date</th>
				<th style = "width:100px; text-align: left">bill_number</th>
				<th style = "width:100px; text-align: left">bill_date</th>
				<th style = "width:300px; text-align: left">party_name</th>
				<th style = "width:100px; text-align: left">party_place</th>
				<th style = "width:100px; text-align: left">truck_number</th>
				<th style = "width:100px; text-align: left">truck_owner_name</th>
				<th style = "width:300px; text-align: left">supp_name</th>
				<th style = "width:200px; text-align: left">supp_place</th>
				<th style = "width:100px; text-align: left">inv_number</th>
				<th style = "width:200px; text-align: left">lchno</th>
				<th style = "width:100px; text-align: left">lrno</th>				
				<th style = "width:100px; text-align: left">placefrom</th>
				<th style = "width:300px; text-align: left">destination</th>
				<th style = "width:100px; text-align: left">weight</th>
				<th style = "width:100px; text-align: right">booking_rate</th>
				<th style = "width:100px; text-align: right">lorry_freight</th>
				<th style = "width:100px; text-align: right">advance</th>
				<th style = "width:100px; text-align: right">cash_advance</th>
				<th style = "width:100px; text-align: right">diesel</th>
				<th style = "width:100px; text-align: right">neft_amount</th>
				<th style = "width:100px; text-align: right">neft_date</th>
				<th style = "width:100px; text-align: right">others</th>
				<th style = "width:100px; text-align: right">extra</th>
				<th style = "width:100px; text-align: right">mamul_charges</th>
				<th style = "width:100px; text-align: right">balance</th>
				<th style = "width:100px; text-align: right">total_paid</th>
				<th style = "width:100px; text-align: right">profit</th>
				<th style = "width:100px; text-align: right">payment_amount</th>
				<th style = "width:350px; text-align: left">rupeesinwords</th>
			</tr>';
	while ($row = mysqli_fetch_array($result)) {
	    $orgDate = $row["date_one"]; 
    	$newDate = date("d-m-Y", strtotime($orgDate));
    	$date_one=$newDate;
    	
    	$orgDate1 = $row["bill_date"]; 
    	$newDate1 = date("d-m-Y", strtotime($orgDate1));
    	$bill_date=$newDate1;
		$output .= '
			<tr>
				<td style="text-align: center"><button type="button" style="width:60px; height:25px;" name="update" id="' . $row["id"] . '" class="update btn btn-success btn-xs">Edit</button></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</a></td>
				<td style="text-align: left">' . $row["id"] . '</td>
				<td style="text-align: left">' . $date_one . '</td>
				<td style="text-align: left">' . $row["bill_number"] . '</td>
				<td style="text-align: left">' . $bill_date . '</td>
				<td style="text-align: left">' . $row["party_name"] . '</td>
				<td style="text-align: left">' . $row["party_place"] . '</td>
				<td style="text-align: left">' . $row["truck_number"] . '</td>
				<td style="text-align: left">' . $row["truck_owner_name"] . '</td>
				<td style="text-align: left">' . $row["supp_name"] . '</td>
				<td style="text-align: left">' . $row["supp_place"] . '</td>
				<td style="text-align: left">' . $row["inv_number"] . '</td>
				<td style="text-align: left">' . $row["lchno"] . '</td>
				<td style="text-align: left">' . $row["lrno"] . '</td>				
				<td style="text-align: left">' . $row["placefrom"] . '</td>
				<td style="text-align: left">' . $row["destination"] . '</td>
				<td style="text-align: left">' . $row["weight"] . '</td>
				<td style="text-align: right">' . $row["booking_rate"] . '</td>
				<td style="text-align: right">' . $row["lorry_freight"] . '</td>
				<td style="text-align: right">' . $row["advance"] . '</td>
				<td style="text-align: right">' . $row["cash_advance"] . '</td>
				<td style="text-align: right">' . $row["diesel"] . '</td>
				<td style="text-align: right">' . $row["neft_amount"] . '</td>
				<td style="text-align: right">' . $row["neft_date"] . '</td>
				<td style="text-align: right">' . $row["others"] . '</td>
				<td style="text-align: right">' . $row["extra"] . '</td>
				<td style="text-align: right">' . $row["mamul_charges"] . '</td>
				<td style="text-align: right">' . $row["balance"] . '</td>
				<td style="text-align: right">' . $row["total_paid"] . '</td>
				<td style="text-align: right">' . $row["profit"] . '</td>
				<td style="text-align: right">' . $row["payment_amount"] . '</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>';
}