<?php
// Base URL
$baseUrl = "http://115.127.90.67/vmsapi/";
$endpoint = "api/SellMaster/Add";

// Complete API URL
$url = $baseUrl . $endpoint;

// Payload data
$data = [
    [
        "companyCode" => "101",
        "branchCode" => "101",
        "invoiceNo" => "1",
        "customerCode" => "1",
        "customerName" => "",
        "customerAddress" => "",
        "customerVATRegNo" => "",
        "issueDate" => "2021-07-20",
        "issueTime" => "14:45:37",
        "deliveryDate" => "2021-07-20",
        "deliveryTime" => "14:45:37",
        "place" => "",
        "car" => "",
        "remarks" => "",
        "challanType" => "1001",
        "distChannel" => "",
        "productCode" => "P1",
        "issueQty" => 0,
        "unitTP" => 0,
        "totalWithoutSD" => 0,
        "totalSD" => 0,
        "totalWithoutVAT" => 0,
        "totalVAT" => 0,
        "totalWithVAT" => 0,
        "netAmount" => 0,
        "discount" => 0,
        "ait" => 0,
        "errorMessage" => "",
        "transferTo" => "",
        "refLineId" => "",
        "cpc" => "",
        "itemNo" => "",
        "officeCode" => "",
        "totalTradeValue" => 0,
        "tradeVATRate" => 0,
        "totalTradeVAT" => 0
    ]
];

// Convert data to JSON
$jsonData = json_encode($data);

// Initialize cURL session
$ch = curl_init($url);

// cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json', // Set content type to JSON
    'Content-Length: ' . strlen($jsonData)
]);

// Execute cURL request
$response = curl_exec($ch);

// Check for cURL errors
if (curl_errno($ch)) {
    echo 'cURL error: ' . curl_error($ch);
} else {
    // Decode response
    $responseDecoded = json_decode($response, true);
    print_r($responseDecoded);
}

// Close cURL session
curl_close($ch);
?>
