82 lines
3.0 KiB
PHP
82 lines
3.0 KiB
PHP
<?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();
|
|
die(error_log(mysqli_error($conn)));
|
|
}
|
|
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();
|
|
die(mysqli_error($conn));
|
|
}
|
|
}
|
|
|
|
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();
|
|
die(mysqli_error($conn));
|
|
}
|
|
|
|
//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);
|
|
?>
|