<?php

require 'db.php';

$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
if(isset($postdata) && !empty($postdata))
{

$c_delivery_charges = mysqli_real_escape_string($con, trim($request->c_deli_charges));
$charges_desc = mysqli_real_escape_string($con, trim($request->charges_description));
$distance = mysqli_real_escape_string($con, trim($request->distance));
$start_date = mysqli_real_escape_string($con, trim($request->start_date));
$end_date = mysqli_real_escape_string($con, trim($request->end_date));
$iconx_amount = mysqli_real_escape_string($con, trim($request->iconx_amount));
$m_delivery_charges = mysqli_real_escape_string($con, trim($request->m_deli_charges));
$orders = mysqli_real_escape_string($con, trim($request->orders));
$other_charges = mysqli_real_escape_string($con, trim($request->other_charges));
$payment_name = mysqli_real_escape_string($con, trim($request->payment_name));
$razor_charges = mysqli_real_escape_string($con, trim($request->razor_charges));
$settle_amount = mysqli_real_escape_string($con, trim($request->settlement_amount));
$sales = mysqli_real_escape_string($con, trim($request->sales));
$shop_code = mysqli_real_escape_string($con, trim($request->shop_code));
$shop_id = mysqli_real_escape_string($con, trim($request->shop_id));
$subscription = mysqli_real_escape_string($con, trim($request->subscription));
$upi_charges = mysqli_real_escape_string($con, trim($request->upi_charges));


if($c_delivery_charges == null || $start_date == null ||  $end_date == "" || $iconx_amount == null ||  $m_delivery_charges == "" || $orders == null ||  $other_charges == "" ||
$payment_name == null ||  $razor_charges == "" || $settle_amount == null ||  $sales == "" || $shop_code == null ||  $shop_id == "" || $subscription == null ||  $upi_charges == "")
{
    $rows = array('status'=>false,'message' => 'Fields Missing');
    echo json_encode($rows);
}
else
{
    $sql = "INSERT INTO due_payment(shop_id,shop_code,start_date,end_date,payment_name,orders,sales,distance,m_deli_charges,c_deli_charges,upi_charges,razor_charges,other_charges,
    subscription,charges_desc,settlement_amount,iconx_amount,status) VALUES ('$shop_id','$shop_code','$start_date','$end_date','$payment_name','$orders','$sales','$distance','$m_delivery_charges','$c_delivery_charges',
    '$upi_charges','$razor_charges','$other_charges','$subscription','$charges_desc','$settle_amount','$iconx_amount','1')";
    $result = mysqli_query($con,$sql);
    if($result)
    {
        $rows = array('status'=>true,'message' => 'Due Details Added');
        echo json_encode($rows);
    }
    else
    {
        $rows = array('status'=>false,'message' => 'Due Details Error');
        echo json_encode($rows);
    }
}

}

?>
