csrtechnew.ohctech.in/check_sor_grn_qty.php
2025-10-16 15:19:10 +05:30

37 lines
1.3 KiB
PHP

<?php
include("includes/config/config.php"); // DB connection
$sor_no = $_POST['sor_no'];
$item_id = $_POST['item_id'];
$qty = $_POST['qty'];
// 1. Get indent_id from SOR number
$indent_query = mysqli_query($conn, "SELECT indent_id FROM indent_master WHERE sor_no = '$sor_no'");
$indent_row = mysqli_fetch_assoc($indent_query);
$indent_id = $indent_row['indent_id'] ?? 0;
error_log("Indent ID: $indent_id");
// 2. Sum of GRN Qty for that indent and item
$grn_query = mysqli_query($conn, "SELECT SUM(grn_qty) AS total_grn_qty FROM grn_items WHERE indent_id = '$indent_id' AND item_id = '$item_id'");
$grn_row = mysqli_fetch_assoc($grn_query);
$total_grn_qty = $grn_row['total_grn_qty'] ?? 0;
error_log("Total GRN Qty: $total_grn_qty");
// 3. SOR Qty from sor_items
$sor_query = mysqli_query($conn, "SELECT sor_qty FROM sor_items WHERE sor_id = '$sor_no' AND item_id = '$item_id'");
$sor_row = mysqli_fetch_assoc($sor_query);
$sor_qty = $sor_row['sor_qty'] ?? 0;
error_log("SOR Qty: $sor_qty");
error_log("sumit raja: $total_grn_qty");
// 4. Compare
if (($total_grn_qty + $qty) <= $sor_qty) {
echo json_encode(['status' => 'ok']);
} else {
echo json_encode([
'status' => 'error',
'message' => 'SOR quantity unavailable, please select another item or increase SOR limit..'
]);
}
?>