88 lines
3.6 KiB
PHP
88 lines
3.6 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
$query1 = "";
|
|
$query2 = "";
|
|
$ohc_id = $_SESSION['current_ohcttype'];
|
|
if (!empty($_REQUEST['req_id'])) {
|
|
$sql_status = "select status,stock_issue_id from stock_issue where req_id='".$_REQUEST['req_id']."'";
|
|
$sql_status_result = mysqli_query($conn,$sql_status);
|
|
|
|
$status_value = mysqli_fetch_array($sql_status_result);
|
|
@extract($status_value);
|
|
if($status_value['status'] == 'R'){
|
|
$free_stock = "select * from `stock_issue_items` where req_id='".$_REQUEST['req_id']."' and stock_issue_id='".$status_value['stock_issue_id']."'";
|
|
|
|
error_log("free_stock:".$free_stock);
|
|
|
|
$result_free_stock = mysqli_query($conn,$free_stock);
|
|
|
|
while(($free_issue_stock = mysqli_fetch_assoc($result_free_stock))>0){
|
|
@extract($free_issue_stock);
|
|
|
|
resetStockAtStoreLevelForStore($free_issue_stock['stock_issue_id'],$ohc_id);
|
|
|
|
$update_issue_stock = "UPDATE stock_issue_items SET issue_qty=0 WHERE stock_issue_id='".$free_issue_stock['stock_issue_id']."'";
|
|
|
|
$result_update_issue_stock = mysqli_query($conn,$update_issue_stock);
|
|
if(!$result_update_issue_stock){
|
|
rollback();
|
|
exit(mysqli_error($conn));
|
|
}
|
|
error_log("update_issue_stock:".$update_issue_stock);
|
|
}
|
|
|
|
$query1 = "update requisition set status='C' where req_id = '" . $_REQUEST['req_id'] . "' ";
|
|
$query2 = "update stock_issue set status='C' where req_id = '" . $_REQUEST['req_id'] . "' ";
|
|
//echo $query1;
|
|
error_log("update status:" . $query1 . " " . $query2);
|
|
$result = @mysqli_query($conn,$query1);
|
|
$result1 = @mysqli_query($conn,$query2);
|
|
if (!$result and !$result1) {
|
|
exit(mysqli_error($conn));
|
|
echo json_encode("FAILURE");
|
|
} else {
|
|
echo json_encode("SUCCESS");
|
|
}
|
|
}
|
|
$check = "SELECT st.* , r.* FROM stock_issue_items st RIGHT JOIN received_master r ON st.req_id = r.req_id WHERE r.req_id='" . $_REQUEST['req_id'] . "' ";
|
|
|
|
$check_result = mysqli_query($conn,$check);
|
|
|
|
if (mysqli_num_rows($check_result) > 0) {
|
|
$query1 = "update requisition set status='C' where req_id = '" . $_REQUEST['req_id'] . "' ";
|
|
$query2 = "update stock_issue set status='C' where req_id = '" . $_REQUEST['req_id'] . "' ";
|
|
//echo $query1;
|
|
error_log("update status:" . $query1 . " " . $query2);
|
|
|
|
$result = @mysqli_query($conn,$query1);
|
|
$result1 = @mysqli_query($conn,$query2);
|
|
if (!$result and !$result1) {
|
|
exit(mysqli_error($conn));
|
|
echo json_encode("FAILURE");
|
|
} else {
|
|
echo json_encode("SUCCESS");
|
|
}
|
|
|
|
} else{
|
|
$check3 = "select * from stock_issue where req_id='".$_REQUEST['req_id']."'";
|
|
$result3 = mysqli_query($conn,$check3);
|
|
$result3_num_rows = mysqli_num_rows($result3);
|
|
if(!($result3_num_rows>0)){
|
|
$query1 = "update requisition set status='C' where req_id = '" . $_REQUEST['req_id'] . "' ";
|
|
error_log("update status:" . $query1);
|
|
$result = @mysqli_query($conn,$query1);
|
|
if (!$result) {
|
|
exit(mysqli_error($conn));
|
|
echo json_encode("FAILURE");
|
|
} else {
|
|
echo json_encode("SUCCESS");
|
|
}
|
|
}else{
|
|
echo "ERROR";
|
|
}
|
|
}
|
|
}
|
|
?>
|