ohctech_p8/save_miscellaneous_stock_opd.php

82 lines
3.0 KiB
PHP
Raw Normal View History

2024-10-16 19:18:52 +05:30
<?php
include ('includes/config/config.php');
include ('includes/functions.php');
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING);
// include log entry header file
include ('log_entry.php');
// error_reporting(E_ERROR | E_PARSE);
$appointment_id = $_REQUEST['appointment_id'];
if (empty($appointment_id)) {
$query = "select max(appointment_id) appointment_id from employee_appointment ";
// echo $query;
error_log("max appointment_id query: " . $query);
if (!$result = @mysqli_query($conn, $query)) {
rollback();
2024-11-02 18:03:13 +05:30
die(error_log(mysqli_error($conn)));
2024-10-16 19:18:52 +05:30
}
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$appointment_id = $row['appointment_id'] + 1;
}
}
}
error_log("appointment_id" . $appointment_id);
// $consume_id = $_REQUEST['detentionId'];
$data = array();
$appointment_date = date('Y-m-d', strtotime($_POST['appointment_date']));
$query = "";
$query_initial = "";
$query_end = " ";
begin();
// it will be ambulance stock for now we can extend this feature to handle multiple ohcs like ambulance
$ohc_id = getFieldFromTable('ohc_type_id', 'ohc_type', 'ohc_category', 'AMB');
$sql_select_existing = "select * from opd_miscellaneous_treatment where appointment_id='" . $appointment_id . "' ";
$results = mysqli_query($conn, $sql_select_existing);
$num_rows_existing = mysqli_num_rows($results);
// if update case found
if ($num_rows_existing != 0) {
//add back to the stock the existing qty
resetOPDMiscellaneousItemsStock($appointment_id, $ohc_id);
//then delete the record
if (!@mysqli_query($conn, "delete from opd_miscellaneous_treatment where appointment_id='" . $appointment_id . "' ")) {
error_log("No records found for deletion:" . mysqli_error($conn));
rollback();
2024-11-02 18:03:13 +05:30
die(mysqli_error($conn));
2024-10-16 19:18:52 +05:30
}
}
for ($i = 0; $i < $_REQUEST['miscellaneous_count_items']; $i++) {
if (${"miscellaneous_medicine$i"} != null && ${"miscellaneous_medicine$i"} != "") {
$query_consumables = "insert into opd_miscellaneous_treatment SET appointment_id='" . $appointment_id . "',
medicine='" . addslashes(${"miscellaneous_medicine$i"}) . "',miscellaneous_item_batch_no='" . addslashes(${"miscellaneous_item_batch_no$i"}) . "',miscellaneous_issued_qty='" . ${"miscellaneous_issued_qty$i"} . "',modified_by='" . $_SESSION['user_id'] . "' ";
error_log("queryyyyyy to insert miscellaneous item stock " . $query_consumables);
if (!$result = @mysqli_query($conn, $query_consumables)) {
error_log("Error Saving miscellaneous stock data: " . mysqli_error($conn) . " Failed Query:" . $query_consumables);
rollback();
2024-11-02 18:03:13 +05:30
die(mysqli_error($conn));
2024-10-16 19:18:52 +05:30
}
//reduce the new stock qty from the
updateItemStockAtMiscellaneousStoreLevel($ohc_id, addslashes(${"miscellaneous_medicine$i"}), ${"miscellaneous_issued_qty$i"}, ${"miscellaneous_item_batch_no$i"});
}
}
commit();
$data['appointment_id'] = $appointment_id;
echo json_encode($data);
?>