<?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);
        
        $num_cmd = $inputdata['num_cmd'];
        

            $rin=$db->prepare('SELECT SUM(total) AS tot FROM table_invoice_details WHERE num_cmd=?');
            $rin->execute(array($num_cmd));
            while ($rins=$rin->fetch()) {
                $bil=$rins['tot'];
            }
            $nap=$bil;
            

            $finalise=$db->prepare('UPDATE tbl_invoice SET total=?, nap=? WHERE num_cmd=?');
            $finalise->execute(array($bil, $nap, $num_cmd ));

            if ($finalise) {
                
                echo (json_encode(['response' => 1]));
            } else {
                echo (json_encode(['response' => 0]));
            }



      
        
