ohctech_p8/save_pending_mis_expiry_item.php
2024-10-16 19:18:52 +05:30

51 lines
2.4 KiB
PHP

<?php include ('includes/config/config.php');
include ('includes/functions.php');
include ('log_entry.php');
error_log("Start Printing Request Attributes");
$requestStr = "";
foreach ($_REQUEST as $key => $value) {
$requestStr .= $key . " : " . $value . "\n";
error_log($key . " : " . $value . "<br />\r\n");
}
error_log("End Printing Request Attributes");
save_log($requestStr, 'Nearing Expiry', 'SAVE', 'save_pending_expiry_item.php');
header('Content-type: application/json');
$item_stock_id = $_POST['item_stock_id'];
$cleanup_qty = $_POST['cleanup_qty'];
$cleanup_date = date('Y-m-d');
$user = $_SESSION['user_id'];
$ohc_id = getFieldFromTable('ohc_type_id', 'ohc_type', 'ohc_code', 'OHCAMB');
$query = "";
$response_array = array();
if ($item_stock_id != null && $item_stock_id != "") {
$sql = "select id as item_stock_id, item_id,item_batch_no,expiry_date from item_stock_miscellaneous where id='" . $item_stock_id . "' and issue_to_ohc_id='" . $ohc_id . "'";
$result_sql = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result_sql)) {
extract($row);
$sql2 = "select * from cleanup_item_stock where item_stock_id = '" . $item_stock_id . "' and ohc_type_id='" . $ohc_id . "'";
$result_sql2 = mysqli_query($conn, $sql2);
if (!(mysqli_num_rows($result_sql2) > 0)) {
$query = "insert into cleanup_item_stock set item_stock_id = '" . $row['item_stock_id'] . "',item_id='" . $row['item_id'] . "', batch_no='" . $row['item_batch_no'] . "',cleanup_qty='" . $cleanup_qty . "',expiry_date='" . $row['expiry_date'] . "',cleanup_date='" . $cleanup_date . "',modified_by = '" . $user . "' ,ohc_type_id='" . $ohc_id . "' ";
} else {
$query = "update cleanup_item_stock set item_stock_id = '" . $row['item_stock_id'] . "',item_id='" . $row['item_id'] . "', batch_no='" . $row['item_batch_no'] . "',cleanup_qty='" . $cleanup_qty . "',expiry_date='" . $row['expiry_date'] . "',modified_by = '" . $user . "',ohc_type_id='" . $ohc_id . "' where item_stock_id = '" . $item_stock_id . "' and ohc_type_id='" . $ohc_id . "' ";
}
}
}
error_log("clean query: " . $query . " " . $sql);
if ($result = @mysqli_query($conn, $query)) {
updateItemStockAtMiscellaneousStoreLevel($ohc_id, $_POST['item_id'], $cleanup_qty, $_POST['batch_no']);
$response_array['status'] = 'success';
} else {
$response_array['status'] = 'error';
}
echo json_encode($response_array);