Merge remote-tracking branch 'origin/staging' into origin/production

This commit is contained in:
Server D3 Linksehat
2024-12-05 16:11:15 +07:00
14 changed files with 114 additions and 19 deletions

View File

@@ -52,9 +52,12 @@ class ApotekController extends Controller
});
})
->when($request->input('status'), function ($query, $status) {
$query->where(function ($query) use ($status) {
$query->where('tx_prescription_orders.sStatus', '=', $status);
});
// Apply the filter if 'status' has a value
if ($status !== 'all') {
$query->where(function ($query) use ($status) {
$query->where('tx_prescription_orders.sStatus', '=', $status);
});
}
})
->select(
'tx_prescriptions.nID as id',
@@ -65,6 +68,15 @@ class ApotekController extends Controller
'tx_prescription_orders.nIDApotek',
'tx_prescription_orders.sStatus as status',
'tx_prescription_orders.sStatus',
DB::raw('
CASE
WHEN TIMESTAMPDIFF(HOUR, tx_prescriptions.dTanggalResep, NOW()) > 72 THEN ""
WHEN TIMESTAMPDIFF(HOUR, tx_prescriptions.dTanggalResep, NOW()) > 1 AND tx_prescription_orders.sStatus = "waiting_pharmacy" THEN "1"
WHEN TIMESTAMPDIFF(HOUR, tx_prescriptions.dTanggalResep, NOW()) > 2 AND tx_prescription_orders.sStatus = "order_prepared" THEN "2"
WHEN TIMESTAMPDIFF(HOUR, tx_prescriptions.dTanggalResep, NOW()) > 3 AND tx_prescription_orders.sStatus = "ready" THEN "3"
ELSE ""
END AS alert
'),
DB::raw('
CASE
WHEN tx_prescription_orders.sStatus = "waiting_pharmacy" THEN "Diterima"
@@ -234,6 +246,14 @@ class ApotekController extends Controller
$item->apotek = $organizations->get($item->nIDApotek, '-'); // Default to 'Unknown' if not found
return $item;
});
$apotek_phone = DB::connection('mysql')->table('organizations')
// ->leftJoin('addresses', 'addresses.id','=', 'organizations.main_address_id')
->whereIn('organizations.id', $apotekIds)
->pluck('organizations.phone', 'organizations.id');
$results->getCollection()->transform(function ($item) use ($apotek_phone) {
$item->phone_apotek = $apotek_phone->get($item->nIDApotek, '-'); // Default to 'Unknown' if not found
return $item;
});
// Transform results to include allergies
$results->getCollection()->transform(function ($item) use ($organizations) {
// Get the allergies for each user
@@ -378,26 +398,26 @@ class ApotekController extends Controller
'dUpdateOn' => date('Y-m-d H:i:s'),
]);
// Insert the log
// Insert the log
$prescriptionOrder = DB::connection('oldlms')
->table('tx_prescription_orders')
->where('tx_prescription_orders.nID', '=', $id)
->join('tx_delivery_orders', 'tx_delivery_orders.nIDPrescriptionOrder', '=', 'tx_prescription_orders.nID')
->select('tx_prescription_orders.*', 'tx_delivery_orders.*', 'tx_delivery_orders.nID as nIDDelivery') // Add specific columns you want to select
->first();
if ($prescriptionOrder) {
$createdBy = $prescriptionOrder->sCreateBy;
$nIDPrescription = $prescriptionOrder->nIDPrescription;
$nIDDeliveryOrder = $prescriptionOrder->nIDDelivery;
// Insert data into the tx_delivery_log table
DB::connection('oldlms')->table('tx_delivery_log')->insert([
'sStatus' => $prescriptionOrder->sDeliveryStatus,
'sStatusPrescription' => $status,
'nIDDeliveryOrder' => $nIDDeliveryOrder,
'nIDPrescription' => $nIDPrescription,
'dCreatedOn' => now(),
'dCreatedOn' => now(),
]);
}
@@ -697,5 +717,5 @@ class ApotekController extends Controller
$uuidV5 = Uuid::uuid5($namespace, $id_prescription_order);
return $uuidV5->toString();
}
}