<?php
require 'config_db.php';
$data = json_decode(file_get_contents('php://input'), true);
$user_type = $data['user_type'];
$mode = $data['mode'];

if ($user_type == '') {
	$returnArr = array("ResponseCode" => "401", "Result" => "false", "ResponseMsg" => "Something Went wrong try again !");
} else {
    if ($mode == 0) {
	    $cus_id = strip_tags(mysqli_real_escape_string($con, $data['customer_id']));
		$id = strip_tags(mysqli_real_escape_string($con, $data['cus_id']));
		$bid_amount = strip_tags(mysqli_real_escape_string($con, $data['bid_amount']));
		$bid_date = strip_tags(mysqli_real_escape_string($con, $data['bid_date']));
// 		$current_time = strip_tags(mysqli_real_escape_string($con, $data['current_time']));
		
        $update_bid_sql = "UPDATE `customers_chit` SET `bid_amount` = '$bid_amount',
        `bid_date` = '$bid_date' WHERE `id` = '$id' and `cus_id` = '$cus_id'";

        $result = $con->query($update_bid_sql);
        if ($result)
            $returnArr = array("ResponseCode" => "200", "Result" => "true", "ResponseMsg" => "Bid Amount Updated");
        else
            $returnArr = array("ResponseCode" => "201", "Result" => "false", "ResponseMsg" => "Failure");
	}
}

function getChitCustomerId($con)
{
	$last_cus_id = $con->query("SELECT cus_id FROM customers_chit ORDER BY id DESC LIMIT 1");
	$last_cus_id = $last_cus_id->fetch_assoc();
	$count = isset($last_cus_id['cus_id']);

	if ($count) {
		$receipt_number = $last_cus_id['cus_id'];
		$length = 7;
		$rec_text_number = explode("-", $receipt_number);
		$no = $rec_text_number[2] + 1;
		$no = substr(str_repeat(0, $length) . $no, -$length);
		$rec_no = "CUS" . "-C-" . $no;
	} else {
		$rec_no = "CUS" . "-C-" . "0000001";
	}
	return $rec_no;
}

echo json_encode($returnArr);
mysqli_close($con);
?>