Update
This commit is contained in:
@@ -10,6 +10,8 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\HospitalPortal\Helpers\ApiResponse;
|
||||
use Modules\HospitalPortal\Helpers\GrabHelper;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
|
||||
|
||||
class ApotekController extends Controller
|
||||
{
|
||||
@@ -450,7 +452,7 @@ class ApotekController extends Controller
|
||||
$apotek = DB::connection('mysql')->table('organizations')
|
||||
->leftJoin('addresses', 'addresses.id', '=', 'organizations.main_address_id')
|
||||
->where('organizations.id', '=', $prescriptions->nIDApotek)
|
||||
->select('organizations.name as nama_apotek', 'addresses.lat', 'addresses.lng')
|
||||
->select('organizations.name as nama_apotek', 'addresses.text as alamat_apotek', 'addresses.lat', 'addresses.lng')
|
||||
->first();
|
||||
|
||||
// Fetch patient (pasien) data
|
||||
@@ -496,16 +498,17 @@ class ApotekController extends Controller
|
||||
// Use GrabHelper to handle the API calls
|
||||
$grabHelper = new GrabHelper();
|
||||
$token = $grabHelper->getToken();
|
||||
$serviceType = 'INSTANT';
|
||||
$body = json_encode([
|
||||
"merchantOrderID" => $prescriptions->merchantOrderID,
|
||||
"serviceType" => "INSTANT",
|
||||
"serviceType" => $serviceType,
|
||||
"vehicleType" => "BIKE",
|
||||
"codType" => "REGULAR",
|
||||
"paymentMethod" => "CASHLESS",
|
||||
"highValue" => false,
|
||||
"packages" => $packages,
|
||||
"origin" => [
|
||||
"address" => $apotek->nama_apotek,
|
||||
"address" => $apotek->alamat_apotek,
|
||||
"coordinates" => [
|
||||
"latitude" => (float)$apotek->lat,
|
||||
"longitude" => (float)$apotek->lng
|
||||
@@ -541,17 +544,8 @@ class ApotekController extends Controller
|
||||
|
||||
// Transaction to update status
|
||||
DB::connection('oldlms')->beginTransaction();
|
||||
DB::connection('oldlms')->table('tx_prescription_orders')
|
||||
->where('tx_prescription_orders.nID', '=', $id)
|
||||
->update([
|
||||
'nDeliveryID' => $data_grab['deliveryID'],
|
||||
'sDeliveryStatus' => $data_grab['status'],
|
||||
'sStatus' => 'waiting_for_courir',
|
||||
'sUpdateBy' => auth()->user()->id,
|
||||
'dUpdateOn' => now(),
|
||||
]);
|
||||
|
||||
|
||||
//insert to api logs
|
||||
$data_logs = [
|
||||
'sType' => 'out',
|
||||
'sContext' => 'grab',
|
||||
@@ -565,6 +559,79 @@ class ApotekController extends Controller
|
||||
DB::connection('oldlms')->table('api_logs')
|
||||
->insert($data_logs);
|
||||
|
||||
|
||||
DB::connection('oldlms')->table('tx_prescription_orders')
|
||||
->where('tx_prescription_orders.nID', '=', $id)
|
||||
->update([
|
||||
'nDeliveryID' => $data_grab['deliveryID'],
|
||||
'sDeliveryStatus' => $data_grab['status'],
|
||||
'sStatus' => 'waiting_for_courir',
|
||||
'sUpdateBy' => auth()->user()->id,
|
||||
'dUpdateOn' => now(),
|
||||
]);
|
||||
//insert to delivery order
|
||||
$tm_delivery_statuses = DB::connection('oldlms')->table('tm_delivery_statuses')
|
||||
->where('tm_delivery_statuses.sStatus', '=', $data_grab['status'])
|
||||
->where('tm_delivery_statuses.nIDDelivery', '=', 3)
|
||||
->select('tm_delivery_statuses.sStatusDescription')
|
||||
->first();
|
||||
$data_delivery_orders = [
|
||||
'nIDPrescriptionOrder' => $id,
|
||||
'sUUID' => $this->generateUuid($id),
|
||||
'sType' => $serviceType,
|
||||
'nOrderID' => $data_grab['deliveryID'],
|
||||
'nVehicleTypeID' => null,
|
||||
'sCreatedDateTime' => $data_grab['schedule']['pickupTimeFrom'],
|
||||
'sFinishDateTime' => $data_grab['schedule']['pickupTimeTo'],
|
||||
'sStatus' => $data_grab['status'],
|
||||
'sStatusDescription' => $tm_delivery_statuses->sStatusDescription,
|
||||
'sMatter' => 'medicine',
|
||||
'nTotalWeightKg' => 0,
|
||||
'nPaymentAmount' => $data_grab['quote']['amount'],
|
||||
'nDeliveryFeeAmount' => $data_grab['quote']['amount'],
|
||||
'sPaymentMethod' => 'cash',
|
||||
'sCreateBy' => auth()->user()->id,
|
||||
'dCreateOn' => now(),
|
||||
];
|
||||
// Use insertGetId to insert the data and get the last inserted ID
|
||||
$lastInsertId = DB::connection('oldlms')->table('tx_delivery_orders')->insertGetId($data_delivery_orders);
|
||||
$data_points = [
|
||||
'origin' => [
|
||||
'nIDDeliveryOrder' => $lastInsertId,
|
||||
'sUUID' => $this->generateUuid($lastInsertId),
|
||||
'nDeliveryID' => $data_grab['deliveryID'],
|
||||
'nPointID' => 1,
|
||||
'nType' => 1,
|
||||
'sAddress' => $data_grab['quote']['origin']['address'],
|
||||
'nLatitude' => $data_grab['quote']['origin']['coordinates']['latitude'] ?? null,
|
||||
'nLongitude' => $data_grab['quote']['origin']['coordinates']['longitude'] ?? null,
|
||||
'sName' => $data_grab['sender']['companyName'],
|
||||
'sPhone' => $data_grab['sender']['phone'],
|
||||
'sTrackingUrl' => null,
|
||||
'sCreateBy' => auth()->user()->id,
|
||||
'dCreateOn' => now(),
|
||||
],
|
||||
'destination' => [
|
||||
'nIDDeliveryOrder' => $lastInsertId,
|
||||
'sUUID' => $this->generateUuid($lastInsertId),
|
||||
'nDeliveryID' => $data_grab['deliveryID'],
|
||||
'nPointID' => 2,
|
||||
'nType' => 2,
|
||||
'sAddress' => $data_grab['quote']['destination']['address'],
|
||||
'nLatitude' => $data_grab['quote']['destination']['coordinates']['latitude'] ?? null,
|
||||
'nLongitude' => $data_grab['quote']['destination']['coordinates']['longitude'] ?? null,
|
||||
'sName' => $data_grab['recipient']['firstName'] . " " . $data_grab['recipient']['lastName'],
|
||||
'sPhone' => $data_grab['recipient']['phone'],
|
||||
'sTrackingUrl' => null,
|
||||
'sCreateBy' => auth()->user()->id,
|
||||
'dCreateOn' => now(),
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($data_points as $value_point) {
|
||||
DB::connection('oldlms')->table('tx_delivery_order_points')->insert($value_point);
|
||||
}
|
||||
|
||||
DB::connection('oldlms')->commit();
|
||||
|
||||
// Return success response
|
||||
@@ -587,4 +654,13 @@ class ApotekController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function generateUuid($id_prescription_order)
|
||||
{
|
||||
// Define the namespace (using DNS in this example)
|
||||
$namespace = Uuid::NAMESPACE_DNS;
|
||||
|
||||
$uuidV5 = Uuid::uuid5($namespace, $id_prescription_order);
|
||||
return $uuidV5->toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user