97 lines
4.2 KiB
PHP
97 lines
4.2 KiB
PHP
<?php
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
$item_id = $_POST ['item_id'];
|
|
$item_desc = getItemWithFormName ( $item_id );
|
|
$unit_id = getTableFieldValue ( 'tbl_items', 'unit_id', 'item_id', $item_id );
|
|
$unit_name = getTableFieldValue ( 'unit_master', 'unit_name', 'unit_id', $unit_id );
|
|
|
|
|
|
$sql_details = "select item_stock_id,item_id,item_batch_no,expiry_date,stock_qty from item_stock where item_id='".$_POST ['item_id']."' and stock_qty>0";
|
|
$result_details = mysqli_query($conn, $sql_details );
|
|
$detailed_info='';
|
|
|
|
|
|
if(mysqli_num_rows($result_details) > 0) {
|
|
while ( $row_details = mysqli_fetch_assoc ( $result_details ) ) {
|
|
extract ( $row_details );
|
|
|
|
if($row_details['expiry_date']!="0000-00-00" && $row_details['expiry_date']!="" && $row_details['expiry_date']!=null){
|
|
$date= date('Y-m-d', strtotime($row_details['expiry_date'])) ;
|
|
$date_today= date("Y-m-d");
|
|
|
|
|
|
// error_log($date_today." pp ".$date);
|
|
if($date>=$date_today){
|
|
$item_stock = $stock_qty;
|
|
$sql_item_stock1 = "select sum(issue_qty),item_batch_no from stock_issue_items where stock_issue_id in (select stock_issue_id from stock_issue where STATUS='N' or STATUS='R' ) and item_id=$item_id and item_batch_no='" . $item_batch_no . "' group by item_batch_no,item_id ";
|
|
$result_item_stock1 = mysqli_query($conn, $sql_item_stock1 );
|
|
$row_item_stock1 = mysqli_fetch_array ( $result_item_stock1 );
|
|
if ($row_item_stock1 [0] != "" && $row_item_stock1 [0] != null) {
|
|
$hold_qty = $row_item_stock1 [0];
|
|
} else {
|
|
$hold_qty = 0.0;
|
|
}
|
|
$item_stock+=$hold_qty;
|
|
$total_hold+=$hold_qty;//total stock to be inclusive of hold qty but would not be available for issue
|
|
$total_stock+=$item_stock;
|
|
$available_qty = floatval ( $item_stock ) - floatval ( $hold_qty );
|
|
|
|
if($total_stock>0){//display only if there is some stock or else do not list the item batch
|
|
$edit_link1 = "";
|
|
if ($hasWriteAccess || $hasExecuteAccess) {
|
|
$edit_link1="<a href=\"#\" class=\"blue\" onclick=\"open_item('".$item_id."','".$item_batch_no."','E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
|
|
}
|
|
$dateStrVal = strtotime($row_details['expiry_date']);
|
|
if (empty($dateStrVal)) {
|
|
$expired_date = 'NA';
|
|
} else {
|
|
$expired_date = date_format ( date_create ( $row_details ['expiry_date'] ), "M-Y " );
|
|
}
|
|
}
|
|
}
|
|
}else{
|
|
$item_stock = $stock_qty;
|
|
$sql_item_stock1 = "select sum(issue_qty),item_batch_no from stock_issue_items where stock_issue_id in (select stock_issue_id from stock_issue where STATUS='N' or STATUS='R' ) and item_id=$item_id and item_batch_no='" . $item_batch_no . "' group by item_batch_no,item_id ";
|
|
$result_item_stock1 = mysqli_query($conn, $sql_item_stock1 );
|
|
$row_item_stock1 = mysqli_fetch_array ( $result_item_stock1 );
|
|
if ($row_item_stock1 [0] != "" && $row_item_stock1 [0] != null) {
|
|
$hold_qty = $row_item_stock1 [0];
|
|
} else {
|
|
$hold_qty = 0.0;
|
|
}
|
|
$item_stock+=$hold_qty;
|
|
$total_hold+=$hold_qty;//total stock to be inclusive of hold qty but would not be available for issue
|
|
$total_stock+=$item_stock;
|
|
$available_qty = floatval ( $item_stock ) - floatval ( $hold_qty );
|
|
|
|
if($total_stock>0){//display only if there is some stock or else do not list the item batch
|
|
$edit_link1 = "";
|
|
if ($hasWriteAccess || $hasExecuteAccess) {
|
|
$edit_link1="<a href=\"#\" class=\"blue\" onclick=\"open_item('".$item_id."','".$item_batch_no."','E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
|
|
}
|
|
$dateStrVal = strtotime($row_details['expiry_date']);
|
|
if (empty($dateStrVal)) {
|
|
$expired_date = 'NA';
|
|
} else {
|
|
$expired_date = date_format ( date_create ( $row_details ['expiry_date'] ), "M-Y " );
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$total_available+=floatval ( $total_stock ) - floatval ( $total_hold );
|
|
$data['qty'] = $total_available;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
$data['status'] = 200;
|
|
$data['message'] = "Data not found!";
|
|
}
|
|
|
|
echo json_encode($data);
|
|
?>
|