<?php
if(isset($_POST["action"])) {
    $output = '';
	require('../config/dbcon.php');
    if($_POST["action"] == "Customer Wise Sales") {
        $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 customer_code,customer_name,cust_place,sum(total_qty) as total_qty,sum(total_list_value) as total_list_value,sum(total_disc_amt) as total_disc_amt,sum(total_sales_val) as total_sales_val,sum(total_sgstamt) as total_sgstamt,sum(total_cgstamt) as total_cgstamt,sum(total_igstamt) as total_igstamt,sum(total_val) as total_val,sum(roundoff) as roundoff,sum(total_inv_val) as total_inv_val FROM invtotal_mst WHERE inv_date BETWEEN '$date1' AND '$date2' group by customer_name,customer_code,cust_place 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: 100%;">
			<table id="tblexportData" class="table table bordered" >
			<tr>				
				
				<th style = "text-align: left">cust_code</th>
				<th style = "text-align: left">customer_name</th>
				<th style = "text-align: left">cust_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>
					</tr>';

            while ($row = mysqli_fetch_array($result)) {
                $output .= '
					<tr>						
						<td style="text-align: left; width:70px;">' . $row["customer_code"] . '</td>
						<td style="text-align: left; width:300px;">' . $row["customer_name"] . '</td>						
						<td style="text-align: left; width:100px;">' . $row["cust_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>
						
					</tr>
				';
            }
            echo $output;
        } else {
            echo 'Data Not Found';
        }
    }
}
