<?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);
        
        $id = $inputdata['id'];
        
        $sel=$db->prepare('SELECT * FROM stock_repas WHERE id=?');
        $sel->execute(array($id));
        while($sels=$sel->fetch()){
            $produit=$sels['prix_repas'];
            $qte_init=$sels['qte'];
        }

        
            $pub=$db->prepare('UPDATE prix_repas SET qte_stock=qte_stock-? WHERE id=?');
            $pub->execute(array($qte_init,$produit));
            

            
            if($pub){
                 $ver=$db->prepare('UPDATE stock_repas SET valid=? WHERE id=?');
                 $ver->execute(array(0,$id));
                 
                 echo(json_encode(['response' => 1]));
            } else{
                 echo(json_encode(['response' => 0]));
            }

        