<?php
// required headers
header("Access-Control-Allow-Origin: *");
//header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

include_once '../config/database.php';
include_once '../objects/sales.php';
include_once '../objects/sales_detail.php';
include_once '../objects/payment.php';
include_once '../objects/ont.php';
 
$database = new Database();
$db = $database->getConnection();

$sales = new Sales($db);
$sales_detail = new SalesDetail($db);
$payment = new Payment($db);
$ont = new ONT($db);
$data = json_decode(file_get_contents("php://input"));
$sales->invoice_no = $data->inv;
$sales_detail->invoice_no = $data->inv;
$payment->invoice_no = $data->inv;
$ont->id_no = $data->id_no;
$ont->status = 0;
if($sales->delete()){
    if($sales_detail->deleteSales()){
        if($payment->deleteSales()){
            if($ont->updateStatus()){
                echo 'deleted';
            }else{
                echo 'error';
            }
        }else{
            echo 'error';
        }
    }else{
        echo 'error';
    }
}else{
    echo 'error';
}
?>