<?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 payment_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 . "%') or Lower(payment_number) LIKE Lower('%" . $search . "%') 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 payment_mst order by payment_number";
}
$result = mysqli_query($connect, $query);
if (mysqli_num_rows($result) > 0) {
	$output .= '
    <div class="table-responsive" style="width: 300%; overflow:auto; height: 100%;">
    	<table id="tblexportData" style="font-size:18px;" class="table table bordered">
    		<tr>
    			<th width="80px" style=" text-align: center">Print</th>
    			<th style = "width:120px; text-align: left">payment_number</th>
    			<th style = "width:80px; text-align: left">payment_date</th>
    			<th style = "width:200px; text-align: left">supp_name</th>
    			<th style = "width:100px; text-align: left">supp_place</th>
    			<th style = "width:100px; text-align: left">srno</th>
    		    <th style = "width:100px; text-align: left">bill_number</th>
    			<th style = "width:100px; text-align: left">bill_date</th>
    			<th style = "width:100px; text-align: left">placefrom</th>
    			<th style = "width:200px; text-align: left">destination</th>
    			<th style = "width:100px; text-align: left">inv_number</th>
    			<th style = "width:100px; text-align: left">lrno</th>
    			<th style = "width:200px; text-align: left">lchno</th>
    			<th style = "width:100px; text-align: left">weight</th>
    			<th style = "width:100px; text-align: right">extra</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">payment_amount</th>
    			<th style = "width:100px; text-align: left">payment_neftref</th>
    			<th style = "width:100px; text-align: left">payment_neftdate</th>
    			<th style = "width:100px; text-align: left">payment_status</th>
    			<th style = "width:300px; text-align: left">rupeesinwords</th>
    			<th style = "width:100px; text-align: left">truck_number</th>
    		</tr>';
	while ($row = mysqli_fetch_array($result)) {
	    $orgDate = $row["payment_date"]; 
    	$newDate = date("d-m-Y", strtotime($orgDate));
    	$pay_date=$newDate;
    	
    	$orgDate1 = $row["bill_date"]; 
    	$newDate1 = date("d-m-Y", strtotime($orgDate1));
    	$bill_date1=$newDate1;
		$output .= '
			<tr>
			    <!--td><a class="float-right btn btn-primary btn-xs" style=" text-align: center;" href="invprt? payment_number=' . $row['payment_number'] . '">Print</a></td-->
				<td style="text-align: center"><a style="width:60px; height:25px; text-align: center;"  href="invprt? payment_number=' . $row['payment_number'] . '" class="float-right btn btn-primary btn-xs">Print</a></td>
				<td style="text-align: left">' . $row["payment_number"] . '</td>
				<td style="text-align: left">' . $pay_date . '</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["srno"] . '</td>
				<td style="text-align: left">' . $row["bill_number"] . '</td>
				<td style="text-align: left">' . $bill_date1 . '</td>
				<td style="text-align: left">' . $row["placefrom"] . '</td>
				<td style="text-align: left">' . $row["destination"] . '</td>
				<td style="text-align: left">' . $row["inv_number"] . '</td>
				<td style="text-align: left">' . $row["lrno"] . '</td>
				<td style="text-align: left">' . $row["lchno"] . '</td>
				<td style="text-align: left">' . $row["weight"] . '</td>
				<td style="text-align: right">' . $row["extra"] . '</td>
				<td style="text-align: right">' . $row["balance"] . '</td>
				<td style="text-align: right">' . $row["total_paid"] . '</td>
				<td style="text-align: right">' . $row["payment_amount"] . '</td>
				<td style="text-align: left">' . $row["payment_neftref"] . '</td>
				<td style="text-align: left">' . $row["payment_neftdate"] . '</td>
				<td style="text-align: left">' . $row["payment_status"] . '</td>
				<td style="text-align: left">' . $row["rupeesinwords"] . '</td>
				<td style="text-align: left">' . $row["truck_number"] . '</td>
			</tr>
		';
	}
	echo $output;
} else {
    echo '<div style="font-size:24px; font-weight:bold;  color: #000066;">Data Not Found</div>';
}