<?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 loading_mst where status_one = 'PENDING' and Lower(party_name) LIKE Lower('%" . $search . "%')or Lower(truck_number) LIKE Lower('%" . $search . "%') and status_one = 'PENDING' 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 loading_mst";
	$query = "Select * from loading_mst where status_one = 'PENDING' order by date_one limit $noofrow";
}

$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
	$output .= '
<div class="table-responsive" style="width: 950%; 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 style = "width:100px; text-align: left">Date</th>
				<th style = "width:175px; text-align: left">lhcno</th>
				<th style = "width:80px; text-align: left">Truck_Number</th>
				<th style = "width:250px; text-align: left">lrno</th>
				<th style = "width:250px; text-align: left">party_name</th>
			    <th style = "width:80px; text-align: right">Booking_Rate</th>
				<th style = "width:100px; text-align: right">lorry_Freight</th>
				<th style = "width:100px; text-align: right">Neft_Amount</th>
				<th style = "width:100px; text-align: left">Neft_Date</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: left">Bal_Paid_Date</th>
				
				<th style = "width:500px; text-align: left">party_address_one</th>
				<th style = "width:200px; text-align: left">party_address_two</th>
				<th style = "width:200px; text-align: left">party_place</th>
				<th style = "width:200px; text-align: left">party_contact_person</th>
				<th style = "width:200px; text-align: left">party_phone_number</th>
				<th style = "width:200px; text-align: left">party_mobile_number</th>
				<th style = "width:200px; text-align: left">party_gst_number</th>
				<th style = "width:200px; text-align: left">party_pan_number</th>
				<th style = "width:200px; text-align: left">party_aadhar_number</th>
				<th style = "width:200px; text-align: left">party_payment_terms</th>
				<th style = "width:200px; text-align: left">party_goods</th>
				<th style = "width:200px; text-align: left">party_remarks</th>
				<th style = "width:250px; text-align: left">Inv_Number</th>
				<th style = "width:150px; text-align: left">truck_owner_name</th>
				<th style = "width:150px; text-align: left">truck_address_one</th>
				<th style = "width:150px; text-align: left">truck_address_two</th>
				<th style = "width:150px; text-align: left">truck_place</th>
				<th style = "width:150px; text-align: left">truck_mobile_number</th>
				<th style = "width:150px; text-align: left">truck_pan_number</th>
				<th style = "width:150px; text-align: left">truck_bank_name</th>
				<th style = "width:150px; text-align: left">truck_bank_acc_number</th>
				<th style = "width:150px; text-align: left">truck_bank_branch</th>
				<th style = "width:150px; text-align: left">truck_ifsc_code</th>
				<th style = "width:150px; text-align: left">truck_aadhar_no</th>
                <th style = "width:150px; text-align: left">truck_remarks</th>
                <th style = "width:200px; text-align: left">From</th>
				<th style = "width:300px; text-align: left">Destination</th>
				<th style = "width:300px; text-align: left">Supp_Name</th>
				<th style = "width:300px; text-align: left">supp_address_one</th>
				<th style = "width:300px; text-align: left">supp_address_two</th>
				<th style = "width:300px; text-align: left">supp_place</th>
				<th style = "width:300px; text-align: left">supp_contact_person</th>
				<th style = "width:300px; text-align: left">supp_mobile_number</th>
				<th style = "width:300px; text-align: left">supp_pan_number</th>
				<th style = "width:300px; text-align: left">supp_bank_name</th>
				<th style = "width:300px; text-align: left">supp_bank_acc_number</th>
				<th style = "width:300px; text-align: left">supp_bank_branch</th>
				<th style = "width:300px; text-align: left">supp_ifsc_code</th>
				<th style = "width:300px; text-align: left">supp_supp_aadhar_no</th>
				<th style = "width:300px; text-align: left">supp_remarks</th>
				<th style = "width:100px; text-align: right">weight</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">Others</th>
				<th style = "width:100px; text-align: right">Extra</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:150px; text-align: left">Driver_Name</th>
				<th style = "width:150px; text-align: left">Driver_Mob_No</th>
				<th style = "width:100px; text-align: right">Mamul_Charges</th>
				<th style = "width:100px; text-align: right">Profit</th>
				<th style = "width:400px; text-align: left">Remarks</th>
				<th style = "width:150px; text-align: left">Status</th>
				<th style = "width:200px; text-align: left">Bill_Date</th>
				<th style = "width:500px; text-align: left">Rupees_In_Words</th>
				<th style = "width:30px; text-align: left">Loading_code</th>
			</tr>';
	while ($row = mysqli_fetch_array($result)) {
	    $orgDate = $row["date_one"]; 
    	$newDate = date("d-m-Y", strtotime($orgDate));
    	$inv_date=$newDate;
    	
    	$orgDate1 = $row["bill_date"]; 
    	$newDate1 = date("d-m-Y", strtotime($orgDate1));
    	$inv_date1=$newDate1;
		$output .= '
			<tr>
				<td style="text-align: center"><button type="button" style="width:60px; height:30px;" name="update" id="' . $row["id"] . '" class="update btn btn-success btn-xs">Edit</button></td>  
				<td style="text-align: left">' . $inv_date . '</td>
				<td style="text-align: left">' . $row["lchno"] . '</td>
				<td style="text-align: left">' . $row["truck_number"] . '</td>
				<td style="text-align: left">' . $row["lrno"] . '</td>
				<td style="text-align: left">' . $row["party_name"] . '</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["neft_amount"] . '</td>
				<td style="text-align: left">' . $row["neft_date"] . '</td>
				<td style="text-align: right">' . $row["balance"] . '</td>
				<td style="text-align: right">' . $row["total_paid"] . '</td>
				<td style="text-align: left">' . $row["bal_paid_date"] . '</td>
				
				<td style="text-align: left">' . $row["party_address_one"] . '</td>
				<td style="text-align: left">' . $row["party_address_two"] . '</td>
				<td style="text-align: left">' . $row["party_place"] . '</td>
				<td style="text-align: left">' . $row["party_contact_person"] . '</td>
				<td style="text-align: left">' . $row["party_phone_number"] . '</td>
				<td style="text-align: left">' . $row["party_mobile_number"] . '</td>
				<td style="text-align: left">' . $row["party_gst_number"] . '</td>
				<td style="text-align: left">' . $row["party_pan_number"] . '</td>
				<td style="text-align: left">' . $row["party_aadhar_number"] . '</td>
				<td style="text-align: left">' . $row["party_payment_terms"] . '</td>
				<td style="text-align: left">' . $row["party_goods"] . '</td>
				<td style="text-align: left">' . $row["party_remarks"] . '</td>
				<td style="text-align: left">' . $row["inv_number"] . '</td>
				<td style="text-align: left">' . $row["truck_owner_name"] . '</td>
				<td style="text-align: left">' . $row["truck_address_one"] . '</td>
				<td style="text-align: left">' . $row["truck_address_two"] . '</td>
				<td style="text-align: left">' . $row["truck_place"] . '</td>
				<td style="text-align: left">' . $row["truck_mobile_number"] . '</td>
				<td style="text-align: left">' . $row["truck_pan_number"] . '</td>
				<td style="text-align: left">' . $row["truck_bank_name"] . '</td>
				<td style="text-align: left">' . $row["truck_bank_acc_number"] . '</td>
				<td style="text-align: left">' . $row["truck_bank_branch"] . '</td>
				<td style="text-align: left">' . $row["truck_ifsc_code"] . '</td>
				<td style="text-align: left">' . $row["truck_aadhar_no"] . '</td>
				<td style="text-align: left">' . $row["truck_remarks"] . '</td>
				<td style="text-align: left">' . $row["placefrom"] . '</td>
				<td style="text-align: left">' . $row["destination"] . '</td>
				<td style="text-align: left">' . $row["supp_name"] . '</td>
				<td style="text-align: left">' . $row["supp_address_one"] . '</td>
				<td style="text-align: left">' . $row["supp_address_two"] . '</td>
				<td style="text-align: left">' . $row["supp_place"] . '</td>
				<td style="text-align: left">' . $row["supp_contact_person"] . '</td>
				<td style="text-align: left">' . $row["supp_mobile_number"] . '</td>
				<td style="text-align: left">' . $row["supp_pan_number"] . '</td>
				<td style="text-align: left">' . $row["supp_bank_name"] . '</td>
				<td style="text-align: left">' . $row["supp_bank_acc_number"] . '</td>
				<td style="text-align: left">' . $row["supp_bank_branch"] . '</td>
				<td style="text-align: left">' . $row["supp_ifsc_code"] . '</td>
				<td style="text-align: left">' . $row["supp_supp_aadhar_no"] . '</td>
				<td style="text-align: left">' . $row["supp_remarks"] . '</td>
				<td style="text-align: right">' . $row["weight"] . '</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["others"] . '</td>
				<td style="text-align: right">' . $row["extra"] . '</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: right">' . $row["mamul_charges"] . '</td>
				<td style="text-align: right">' . $row["profit"] . '</td>
				<td style="text-align: left">' . $row["remarks"] . '</td>
				<td style="text-align: left">' . $row["status_one"] . '</td>
				<td style="text-align: left">' . $inv_date1 . '</td>
				<td style="text-align: left">' . $row["rupeesinwords"] . '</td>
				<td style="text-align: left">' . $row["id"] . '</td>
			</tr>
		';
	}
	echo $output;
} else {
    echo '<div style="font-size:24px; font-weight:bold;  color: #000066;">Data Not Found</div>';
}
