<?php
session_start();
    header('Access-Control-Allow-Origin:*');
    header('Content-Type; application/json; charset=utf-8');
    header('Access-control-Allow-Method: POST');
    header('Access-control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-request-With');
    include('db.php');
        $inputdata = json_decode(file_get_contents("php://input"), true);
        
        $dat_deb = $inputdata['dat_deb'];
        $dat_fin = $inputdata['dat_fin'];
        $produit = $inputdata['produit'];
        
        $dat_deb1=DateTime::createFromFormat('d/m/Y', $dat_deb)->format('Y-m-d');
        
        $dat_fin1=DateTime::createFromFormat('d/m/Y', $dat_fin)->format('Y-m-d');
        
        $pub=$db->prepare('SELECT SUM(qty*price) AS somme FROM table_invoice_details WHERE order_date BETWEEN ? AND ? AND product_name=?');
        $pub->execute(array($dat_deb1,$dat_fin1, $produit));
        while($somm = $pub->fetch()){
            $somme=$somm['somme'];
        }
        
        echo(json_encode(['somme' => $somme]));