<?php

require_once __DIR__ . '/db_config.php';
require_once __DIR__ . '/notify.php';

$r = array();

if (isset($_POST["id"]) ) {
 
$report_id=$_POST["id"];
$cname=$_POST["cname"];
$amount=$_POST["amount"];

$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

$query= "SELECT approved_amount FROM defect_report WHERE report_id='$report_id' AND companyname='$cname'";

$result = mysqli_query($con,$query);
if(!empty($result) && mysqli_num_rows($result) > 0){
    
    $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
    $approved = $row["approved_amount"];
    
    $allowed = $approved + ($approved * 0.10);
    
    if($amount>$allowed){
         $r["s"] = 0;
         $r["m"] = "Maximum allowed amount $allowed";
    }else{
        $r["s"] = 1;
    }
}

mysqli_close($con);

}

echo json_encode($r,JSON_UNESCAPED_SLASHES);


?>