105 lines
2.5 KiB
PHP
105 lines
2.5 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, 'Dispensary Stock', 'SAVE', 'stock_update.php');
|
|
|
|
$itemId = $_POST['stock_item_id'];
|
|
echo $itemId;
|
|
$stock_qty = $_POST['stock_qty'];
|
|
|
|
$check_item = "select item_id from item_stock where item_id='" . $itemId . "' and ohc_type_id='" . $_SESSION['current_ohcttype'] . "' ";
|
|
|
|
$check_items = mysqli_query($conn, $check_item);
|
|
|
|
$row_check = @mysqli_num_rows($check_items);
|
|
$query = "";
|
|
|
|
if ($row_check > 0) {
|
|
$query = "update item_stock set stock_qty = '$stock_qty' where item_id='" . $itemId . "' and ohc_type_id='" . $_SESSION['current_ohcttype'] . "'";
|
|
} else {
|
|
$query = "insert into item_stock set item_id = '$itemId',stock_qty = '$stock_qty' , ohc_type_id='" . $_SESSION['current_ohcttype'] . "'";
|
|
}
|
|
|
|
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
error_log("Error saving Item stock" . mysqli_error($conn) . ". Error Query:" . $query);
|
|
exit(mysqli_error($conn));
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
<?php
|
|
|
|
// function get_total_quantity_by_medicine_id($medicine_id) {
|
|
|
|
// $query = "SELECT stock_qty, item_id FROM item_stock_dispensary WHERE medicine_id = ?";
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (isset($_POST['medicine_id'])) {
|
|
// $medicine_id = $_POST['medicine_id'];
|
|
|
|
|
|
// $total_quantity = get_total_quantity_by_medicine_id($medicine_id);
|
|
|
|
|
|
// echo json_encode(['total_quantity' => $total_quantity]);
|
|
// } else {
|
|
|
|
// echo json_encode(['error' => 'medicine_id not provided']);
|
|
// }
|
|
?>
|
|
|
|
|
|
<?php
|
|
|
|
$query = "SELECT stock_qty FROM item_stock WHERE item_id = ?";
|
|
|
|
function get_total_quantity_by_medicine_id($medicine_id, $conn)
|
|
{
|
|
global $query;
|
|
$itemId = $_POST['item_id'];
|
|
echo $itemId;
|
|
$stock_qty = $_POST['stock_qty'];
|
|
$stmt = $conn->prepare($query);
|
|
$stmt->bind_param('i', $medicine_id);
|
|
$stmt->execute();
|
|
$stmt->bind_result($stock_qty);
|
|
|
|
if ($stmt->fetch()) {
|
|
$stmt->close();
|
|
return $stock_qty;
|
|
} else {
|
|
$stmt->close();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
if (isset($_POST['medicine_id'])) {
|
|
$medicine_id = $_POST['medicine_id'];
|
|
|
|
$total_quantity = get_total_quantity_by_medicine_id($medicine_id, $conn);
|
|
|
|
echo json_encode(['total_quantity' => $total_quantity]);
|
|
} else {
|
|
echo json_encode(['error' => 'medicine_id not provided']);
|
|
}
|
|
|
|
//$conn->close();
|
|
|
|
?>
|
|
|
|
|