<?php
if (isset($_POST["action"])) {
	$output = '';
	require('../config/dbcon.php');
	if ($_POST["action"] == "Search") {
		$orgDate = $_POST['date1'];  
		$newDate = date("Y-m-d", strtotime($orgDate));
		$date1=$newDate;
	    
	    $orgDate1 = $_POST['date2'];  
		$newDate1 = date("Y-m-d", strtotime($orgDate1));
		$date2=$newDate1;
	    
		$date1 = $date1.' 00:00:00';
		$date2 = $date2.' 23:59:59';
		$result = mysqli_query($connect, "SELECT * FROM pinvtotal_mst WHERE inv_date BETWEEN '$date1' AND '$date2'");
		if (mysqli_num_rows($result) > 0) {
			$output .= '
			<div class="table-responsive" style="font-size:18px; width: 130%;">
			<table id="tblexportData" class="table table bordered" >
				<tr>
					<th style = "text-align: left">inv_number</th>
					<th style = "text-align: left">inv_date</th>
					<th style = "text-align: left">supplier_code</th>
					<th style = "text-align: left">supplier_name</th>
					<th style = "text-align: left">supplier_gstno</th>
					<th style = "text-align: left">supplier_place</th>
					<th style = "text-align: right">total_qty</th>
					<th style = "text-align: right">total_list_value</th>
					<th style = "text-align: right">total_disc_amt</th>
					<th style = "text-align: right">total_sales_val</th>
					<th style = "text-align: right">total_sgstamt</th>
					<th style = "text-align: right">total_cgstamt</th>
					<th style = "text-align: right">total_igstamt</th>
					<th style = "text-align: right">total_val</th>
					<th style = "text-align: right">roundoff</th>
					<th style = "text-align: right">total_inv_val</th>
					<th style = "text-align: left">tax_code</th>
				</tr>';
			while ($row = mysqli_fetch_array($result)) {
				$output .= '
					<tr>
					<td style="text-align: left; width:70px;">' . $row["inv_number"] . '</td>
					<td style="text-align: left; width:70px;">' . date("d-m-Y", strtotime($row["inv_date"])). '</td>
					<td style="text-align: left; width:70px;">' . $row["supplier_code"] . '</td>
					<td style="text-align: left; width:400px;">' . $row["supplier_name"] . '</td>
					<td style="text-align: left; width:100px;">' . $row["supplier_gstno"] . '</td>
					<td style="text-align: left; width:100px;">' . $row["supplier_place"] . '</td>
					<td style="text-align: right; width:100px;">' . $row["total_qty"] . '</td>
					<td style="text-align: right; width:80px;">' . $row["total_list_value"] . '</td>
					<td style="text-align: right; width:80px;"">' . $row["total_disc_amt"] . '</td>
					<td style="text-align: right; width:80px;"">' . $row["total_sales_val"] . '</td>
					<td style="text-align: right; width:80px;"">' . $row["total_sgstamt"] . '</td>
					<td style="text-align: right; width:80px;"">' . $row["total_cgstamt"] . '</td>
					<td style="text-align: right; width:80px;"">' . $row["total_igstamt"] . '</td>
					<td style="text-align: right; width:80px;"">' . $row["total_val"] . '</td>
					<td style="text-align: right; width:80px;"">' . $row["roundoff"] . '</td>
					<td style="text-align: right; width:80px;"">' . $row["total_inv_val"] . '</td>
					<td style="text-align: left; width:80px;"">' . $row["tax_code"] . '</td>
				</tr>
				';
			}
			echo $output;
		} else {
			echo 'Data Not Found';
		}

	}
	
}
