HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/grapossconnect/adminapi/invoice_all_platform.php
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');

header('Content-Type: application/json');
include '../config.php';
date_default_timezone_set('Asia/Calcutta');
$curDate = date('Y-m-d H:i:s');
$cipher = "aes-256-cbc";
$encryption_key = "gepl-enc2022";
$iv = '1234567891055521';
$options = 0;

$jsonRequest = file_get_contents('php://input');

$decryptedData = openssl_decrypt($jsonRequest, $cipher, $encryption_key, $options, $iv);
$base64DecodeData = base64_decode($decryptedData);
$finalDecryptedData = json_decode($base64DecodeData);

$from_domain = $finalDecryptedData->from_domain;
$if_vendor = $finalDecryptedData->if_vendor;
$transaction_type = $finalDecryptedData->transaction_type;
$payment_for = $finalDecryptedData->payment_for;
$payment_type = $finalDecryptedData->payment_type;
$payment_gateway_name = $finalDecryptedData->payment_gateway_name;
$order_id = $finalDecryptedData->order_id;
$product_mrp = $finalDecryptedData->product_mrp;
$gst_rate = $finalDecryptedData->gst_rate;
$gepl_amount = $finalDecryptedData->gepl_amount;
$discount_amount = $finalDecryptedData->discount_amount;
$net_amount = $finalDecryptedData->net_amount;
$customer_name = $finalDecryptedData->customer_name;
$customer_address = $finalDecryptedData->customer_address;
$customer_mobile = $finalDecryptedData->customer_mobile;
$customer_email = $finalDecryptedData->customer_email;
$customer_gst_name = $finalDecryptedData->customer_gst_name;
$customer_gstin = $finalDecryptedData->customer_gstin;
$customer_state_id = $finalDecryptedData->customer_state_id;
$customer_state_code = $finalDecryptedData->customer_state_code;
$customer_state_name = $finalDecryptedData->customer_state_name;
$transaction_id1 = $finalDecryptedData->transaction_id1;
$transaction_id2 = $finalDecryptedData->transaction_id2;
$transaction_date = $finalDecryptedData->transaction_date;
$ref_name1 = $finalDecryptedData->ref_name1;
$ref_id1 = $finalDecryptedData->ref_id1;
$ref_name2 = $finalDecryptedData->ref_name2;
$ref_id2 = $finalDecryptedData->ref_id2;
$ref_name3 = $finalDecryptedData->ref_name3;
$ref_id3 = $finalDecryptedData->ref_id3;

if ($from_domain == '' || $from_domain == '0') {
    $rstatus = 'failed';
    $rmsg = 'Domain name can not be empty for Invoice';
    $invoiceId = '0';
} else if ($if_vendor == '' || $if_vendor == '0') {
    $rstatus = 'failed';
    $rmsg = 'Vendor name can not be empty for Invoice, send GEPL in case of direct payment';
    $invoiceId = '0';
} else if ($order_id == '' || $order_id == '0') {
    $rstatus = 'failed';
    $rmsg = 'Order id can not be empty for Invoice';
    $invoiceId = '0';
} else if ($product_mrp == '' || $product_mrp == '0') {
    $rstatus = 'failed';
    $rmsg = 'Product MRP can not be empty for Invoice';
    $invoiceId = '0';
} else if ($customer_name == '' || $customer_name == '0') {
    $rstatus = 'failed';
    $rmsg = 'Customer name can not be empty for Invoice';
    $invoiceId = '0';
} else {

    $checkExist = $conn->query("select invoice_id from `grp_gepl_invoice` where `from_domain`='$from_domain' and `if_vendor`='$if_vendor' and `order_id`='$order_id' and `transaction_id1`='$transaction_id1' limit 1");
    $checkQuery = $checkExist->fetch_assoc();
    $invid = $checkQuery['invoice_id'];

    if ($from_domain == "https://shineolympiad.com") {
        $discount_amount = 0;
    }

    if ($discount_amount != 0) {
        $totalAmount = $product_mrp - $discount_amount;
    } else {
        $totalAmount = $product_mrp;
    }

    if ($customer_state_code == 'DL' || $customer_state_name == 'Delhi') {
        $amount = $totalAmount;
        $total_amount = round(($amount / 118 * 100), 2);
        $igst_amount = 0;
        $cgst_amount = round(($total_amount * 9 / 100), 2);
        $sgst_amount = round(($total_amount * 9 / 100), 2);
        $grand_amount = round((($amount / 118 * 100) + ($total_amount * 9 / 100) + ($total_amount * 9 / 100)), 2);
    } else {
        $cgst_amount = 0;
        $sgst_amount = 0;
        $amount = $totalAmount;
        $total_amount = round(($amount / 118 * 100), 2);
        $igst_amount = round(($total_amount * 18 / 100), 2);
        $grand_amount = round((($amount / 118 * 100) + ($total_amount * 18 / 100)), 2);
    }
    if ($invid == '') {
        $insertQuery = "INSERT INTO `grp_gepl_invoice` set `from_domain`='$from_domain', `if_vendor`='$if_vendor', `transaction_type`='$transaction_type', `payment_for`='$payment_for', `payment_type`='$payment_type', `payment_gateway_name`='$payment_gateway_name', `order_id`='$order_id', `product_mrp`='$product_mrp', `gst_rate`='$gst_rate', `igst_amount`='$igst_amount', `cgst_amount`='$cgst_amount', `sgst_amount`='$sgst_amount', `taxable_amount`='$total_amount', `gepl_amount`='$gepl_amount', `discount_amount`='$discount_amount', `net_amount`='$net_amount', `customer_name`='$customer_name', `customer_address`='$customer_address', `customer_mobile`='$customer_mobile', `customer_email`='$customer_email', `customer_gst_name`='$customer_gst_name', `customer_gstin`='$customer_gstin', `customer_state_id`='$customer_state_id', `customer_state_code`='$customer_state_code', `customer_state_name`='$customer_state_name', `transaction_id1`='$transaction_id1', `transaction_id2`='$transaction_id2', `transaction_date`='$transaction_date', `invoice_issue_date`='$curDate', `year_extn`='', `invoice_status`='1', `system_datetime`='$curDate', `cancelled_reason_if_any`='', `cancelled_datetime`='', `ref_name1`='$ref_name1', `ref_id1`='$ref_id1', `ref_name2`='$ref_name2', `ref_id2`='$ref_id2', `ref_name3`='$ref_name3', `ref_id3`='$ref_id3'";
        if ($conn->query($insertQuery)) {
            $insertId = $conn->insert_id;
            $rstatus = 'success';
            $rmsg = 'Invoice data captured successfully';
            $invoiceId = $insertId;
        } else {
            $rstatus = 'failed';
            $rmsg = 'Error: Something wrong, please try again';
            $invoiceId = '0';
        }
    } else {
        $rstatus = 'failed';
        $rmsg = 'Error: Transaction details already exist';
        $invoiceId = '0';
    }
}

if ($rstatus == "success") {
    $response["status"] = $rstatus;
    $response["message"] = $rmsg;
    $response["invoiceId"] = $invoiceId;
    $responseArray[] = $response;
} else {
    $response["status"] = $rstatus;
    $response["message"] = $rmsg;
    $response["invoiceId"] = $invoiceId;
    $responseArray[] = $response;
}
echo json_encode($responseArray);