<?php include("../db.php");?>
<?php
 $connection = new mysqli($dbhost,$dbusername,$dbpassword,$dbname);
 if($_SERVER["REQUEST_METHOD"]=="POST"){
    $from_date=date("Y-m-d H:i:s", strtotime($_POST["from_date"]));
    $to_date=date("Y-m-d H:i:s", strtotime($_POST["to_date"]));
    $getfilteredData="SELECT 
            m.Invoice,
            s.ID AS orderid,
            m.Date,
            m.OrderType,
            p.Name AS Product_name, 
            s.AmountPerPC AS Price,
            s.Quantity,
            s.Amount
        FROM invoice m
        INNER JOIN orders s ON m.Invoice = s.Invoice
        INNER JOIN product p ON s.Product = p.ID
        WHERE m.Order_Status = 'Confirmed'
        AND m.Date BETWEEN '$from_date' AND '$to_date'";
        $result=$connection->query($getfilteredData);
        $data=[];
        while($row=$result->fetch_assoc()){ 
            $data[]=$row;
        }
 echo "RESULTS <br>".json_encode($data);
 exit;
    }
 ?>
            

