<?php
if(isset($_POST["action"])){
    $output = '';
	require('../config/dbcon.php');
    if($_POST["action"] == "Search"){
        $date1 = date("Y-m-d", strtotime($_POST['date1']));
        $date2 = date("Y-m-d", strtotime($_POST['date2']));
        $date1 = $date1 . ' 00:00:00';
        $date2 = $date2 . ' 23:59:59';
        $sql = "select * from sales_mst where inv_date BETWEEN '$date1' AND '$date2' order by customer_name";
		$result = mysqli_query($connect, $sql);
        if (mysqli_num_rows($result) > 0){
        $output .= '
		<div class="table-responsive" style="font-size:18px; width: 150%;">
			<table id="tblexportData" class="table table bordered" >
				<tr>				
					<th style = "text-align: left; width:5%;">inv_number</th>
    				<th style = "text-align: left; width:5%;">inv_date</th>
    				<th style = "text-align: left; width:25%;">customer_name</th>
    				<th style = "text-align: left; width:10%;">part_number</th>
    				<th style = "text-align: left; width:30%;">item_description</th>
    				<th style = "text-align: right; width:5%;">qty</th>
    				<th style = "text-align: right; width:5%;">list</th>
    				<th style = "text-align: right; width:5%;">disc_per</th>
    				<th style = "text-align: right; width:10%;">sales_value</th>
    				<th style = "text-align: right; width:10%;">inv_value</th>
				</tr>';
            while ($row = mysqli_fetch_array($result)){
			$output .= '
				<tr>
					<td style="text-align: left;">' . $row["inv_number"] . '</td>			
    				<td style="text-align: left;">' . date("d-m-Y", strtotime($row["inv_date"])). '</td>
    				<td style="text-align: left;">' . $row["customer_name"] . '</td>
    				<td style="text-align: left;">' . $row["part_number"] . '</td>
    				<td style="text-align: left;">' . $row["item_description"] . '</td>
    				<td style="text-align: right;">' . $row["qty"] . '</td>
    				<td style="text-align: right;">' . $row["list"] . '</td>
    				<td style="text-align: right;">' . $row["disc_per"] . '</td>
    				<td style="text-align: right;">' . $row["sales_value"] . '</td>
    				<td style="text-align: right;">' . $row["inv_value"] . '</td>
				</tr>';
            }
            echo $output;
        } else{
            echo 'Data Not Found';
        }
    }
}