From e9f8bf540ec75414e3ccb5cd4a20eba34ac6823a Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:13:33 +0300 Subject: [PATCH 1/3] added confirmation message on drug dispatch --- app/Http/Controllers/NishauriController.php | 86 +++++++++++++------ .../views/nishauri/drug_delivery.blade.php | 7 +- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/NishauriController.php b/app/Http/Controllers/NishauriController.php index 220dd33..9a0d011 100644 --- a/app/Http/Controllers/NishauriController.php +++ b/app/Http/Controllers/NishauriController.php @@ -20,10 +20,28 @@ use Carbon\Carbon; use App\Models\NishauriDrugDelivery; use App\Models\NishauriDrugOrder; +use Illuminate\Support\Facades\Http; class NishauriController extends Controller { + private function send_message($source, $destination, $msg) + { + $key = env('SMS_SERVICE_KEY', ''); + $host = env('SMS_SERVICE_HOST', ''); + + $this->httpresponse = Http:: + withoutVerifying() + ->withHeaders(['api-token'=> "$key"]) + ->post("$host", [ + 'destination' => $destination, + 'msg' => $msg, + 'sender_id' => $destination, + 'gateway' => $source, + ]); + + return json_decode( $this->httpresponse->getBody(), true); + } public function reschedule() { $data = []; @@ -850,25 +868,25 @@ public function drug_delivery_list() { if (Auth::user()->access_level == 'Facility') { - $drug_delivery = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id') - ->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id') - ->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->where('tbl_nishauri_drug_order.status', '=', 'Pending') - ->get(); - $drug_dispatch = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id') - ->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id') - ->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->where('tbl_nishauri_drug_order.status', '=', 'Approved') - ->get(); - - $drug_fullfilled = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id') - ->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id') - ->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->where('tbl_nishauri_drug_order.status', '=', 'Fullfilled') - ->get(); + $drug_delivery = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id', 'tbl_nishauri_drug_order.client_phone_no') + ->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id') + ->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_nishauri_drug_order.status', '=', 'Pending') + ->get(); + $drug_dispatch = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id', 'tbl_nishauri_drug_order.client_phone_no') + ->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id') + ->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_nishauri_drug_order.status', '=', 'Approved') + ->get(); + + $drug_fullfilled = NishauriDrugDelivery::select('tbl_nishauri_drug_order.id as order_id', 'tbl_appointment.appntmnt_date', 'tbl_client.clinic_number', 'tbl_nishauri_drug_order.mode', 'tbl_nishauri_drug_order.delivery_method', 'tbl_nishauri_drug_order.delivery_person', 'tbl_nishauri_drug_order.delivery_person_contact', 'tbl_nishauri_drug_order.delivery_pickup_time', 'tbl_nishauri_drug_order.status', 'tbl_nishauri_drug_order.appointment_id', 'tbl_nishauri_drug_order.comment') + ->leftJoin('tbl_appointment', 'tbl_appointment.id', '=', 'tbl_nishauri_drug_order.appointment_id') + ->leftJoin('tbl_client', 'tbl_client.id', '=', 'tbl_nishauri_drug_order.program_identifier') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_nishauri_drug_order.status', '=', 'Fullfilled') + ->get(); return view('nishauri.drug_delivery', compact('drug_delivery', 'drug_dispatch', 'drug_fullfilled')); } @@ -880,10 +898,11 @@ public function delivery_approval(Request $request) $client = NishauriDrugDelivery::where('appointment_id', $request->appointment_id) ->update([ 'status' => 'Approved', - 'updated_at' => date('Y-m-d H:i:s') + 'updated_at' => now(), + 'approved_date' => now() ]); - // dd( $client); + // dd( $client); if ($client) { NishauriDrugOrder::create([ 'order_id' => $request->order_id, @@ -902,20 +921,31 @@ public function delivery_approval(Request $request) public function delivery_dispatch(Request $request) { try { + $order = $request->order_id; + $order_no = 'ORN' . sprintf('%03d', $order); + $client = NishauriDrugDelivery::where('appointment_id', $request->appointment_id) ->update([ 'status' => 'Dispatched', - 'updated_at' => date('Y-m-d H:i:s') + 'updated_at' => date('Y-m-d H:i:s'), + 'dispatched_date' => date('Y-m-d H:i:s'), + 'confirmation_code' => $order_no ]); - // dd( $client); + // dd( $client); if ($client) { NishauriDrugOrder::where('order_id', $request->order_id) - ->update([ - 'initiated_by' => Auth::user()->id, - 'dispatch_notes' => $request->dispatch_notes, - 'updated_at' => date('Y-m-d H:i:s') - ]); + ->update([ + 'initiated_by' => Auth::user()->id, + 'dispatch_notes' => $request->dispatch_notes, + 'updated_at' => date('Y-m-d H:i:s') + ]); + + // Send SMS notification + $destination = $request->client_phone_no; + $msg = "Your drugs for order No $order_no has been dispatched. Kindly use your order number provided for confirmation once you received the drugs"; + $source = '40149'; + $this->send_message($source, $destination, $msg); Alert::success('Success', 'Delivery Successfully Dispatched'); return redirect('delivery/list'); } else { diff --git a/resources/views/nishauri/drug_delivery.blade.php b/resources/views/nishauri/drug_delivery.blade.php index 74f8936..e836562 100644 --- a/resources/views/nishauri/drug_delivery.blade.php +++ b/resources/views/nishauri/drug_delivery.blade.php @@ -172,8 +172,8 @@ Delivery Method Delivery Person Delivery Person Contact - Pick Up Time Status + Comment @@ -188,8 +188,8 @@ {{$result->delivery_method}} {{$result->delivery_person}} {{$result->delivery_person_contact}} - {{$result->delivery_pickup_time}} {{$result->status}} + {{$result->comment}} @@ -272,6 +272,8 @@
+ +
@@ -379,6 +381,7 @@ function dispatchModal(result) { $('#dispatch_delivery_pickup_time').val(result.delivery_pickup_time); $('#dispatch_appointment_id').val(result.appointment_id); $('#dispatch_order_id').val(result.order_id); + $('#dispatch_client_phone_no').val(result.client_phone_no); } From 1640d4d50bc5ae79ed8537575f4cd874c73a5a97 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 11 Apr 2024 08:03:37 +0300 Subject: [PATCH 2/3] change on dispatch notification --- app/Http/Controllers/NishauriController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/NishauriController.php b/app/Http/Controllers/NishauriController.php index 9a0d011..4d46fe8 100644 --- a/app/Http/Controllers/NishauriController.php +++ b/app/Http/Controllers/NishauriController.php @@ -944,7 +944,7 @@ public function delivery_dispatch(Request $request) // Send SMS notification $destination = $request->client_phone_no; $msg = "Your drugs for order No $order_no has been dispatched. Kindly use your order number provided for confirmation once you received the drugs"; - $source = '40149'; + $source = 40149; $this->send_message($source, $destination, $msg); Alert::success('Success', 'Delivery Successfully Dispatched'); return redirect('delivery/list'); From e859724cd995fbf4706b64f72258b64393744017 Mon Sep 17 00:00:00 2001 From: Kevin Lanyo Date: Tue, 30 Apr 2024 13:36:11 +0300 Subject: [PATCH 3/3] Enhancement/Resend sms missed out during normal scheduling --- .../Controllers/ScheduleSMSController.php | 51 +++++++++++++++++-- app/Models/UnsentSMS.php | 13 +++++ routes/web.php | 3 ++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 app/Models/UnsentSMS.php diff --git a/app/Http/Controllers/ScheduleSMSController.php b/app/Http/Controllers/ScheduleSMSController.php index bca6297..5d5803e 100644 --- a/app/Http/Controllers/ScheduleSMSController.php +++ b/app/Http/Controllers/ScheduleSMSController.php @@ -10,6 +10,7 @@ use App\Models\ClientOutgoing; use App\Models\OutgoingSms; use App\Models\Wellness; +use App\Models\UnsentSMS; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Http; @@ -502,6 +503,48 @@ public function ltfuScheduler() } + public function resend() //resend all outgoing sms that were not sent during normal scheduling + { + $messages = UnsentSMS::all(); + foreach($messages as $message) + { + $clnt_outgoing_id = $message->id; + $destination = $message->destination; + $msg = $message->msg; + $source = $message->source; + + //call sms service + $result = $this->send_message($source,$destination,$clnt_outgoing_id,$msg); + + $status = $result['status']; + $messageid = ''; + $cost = 0; + + foreach($result as $row) + { + if($status == 'success') + { + foreach($result['data'] as $data) + { + foreach($data['Recipients'] as $Recipient) + { + $messageid = $Recipient['messageId']; + $cost = $Recipient['cost']; + } + } + } + + //update the sent message with the sms cost and send status + $sms = ClientOutgoing::find($clnt_outgoing_id); + $sms->status = $status; + $sms->cost = $cost; + $sms->message_id = $messageid; + $sms->save(); + + } + } + } + public function sender() { try{ @@ -530,7 +573,7 @@ public function sender() ->where('msg','like', '%'.$msg.'%') ->where('destination', $destination) ->where('status', 'Sent') - ->whereRaw('created_at between (CURDATE() - INTERVAL 1 DAY) AND (CURDATE() + INTERVAL 1 DAY) ') + ->whereRaw('DATE(created_at) between (CURDATE() - INTERVAL 1 DAY) AND (CURDATE() + INTERVAL 1 DAY) ') ->doesntExist()) //Message has not been sent, send the current message { // $queries = DB::getQueryLog(); @@ -544,7 +587,7 @@ public function sender() } //call sms service - $result = $this->send_message($source,$destination , $msg); + $result = $this->send_message($source,$destination,$clnt_outgoing_id,$msg); $status = $result['status']; $messageid = ''; @@ -585,7 +628,7 @@ public function sender() } } - private function send_message($source, $destination, $msg) + private function send_message($source, $destination,$sender_id, $msg) { $key = env('SMS_SERVICE_KEY', ''); $host = env('SMS_SERVICE_HOST', ''); @@ -596,7 +639,7 @@ private function send_message($source, $destination, $msg) ->post("$host", [ 'destination' => $destination, 'msg' => $msg, - 'sender_id' => $destination, + 'sender_id' => $sender_id, 'gateway' => $source, ]); diff --git a/app/Models/UnsentSMS.php b/app/Models/UnsentSMS.php new file mode 100644 index 0000000..2bd4284 --- /dev/null +++ b/app/Models/UnsentSMS.php @@ -0,0 +1,13 @@ + 'App\Http\Controllers\ScheduleSMSController@sender', 'as' => 'sms-sender']); +//resend sms notifications +Route::get('/sms/resend', ['uses' => 'App\Http\Controllers\ScheduleSMSController@resend', 'as' => 'sms-resend']); + //get KHIS TxCurr Route::get('/txcurr', ['uses' => 'App\Http\Controllers\TxCurrController@txcurr', 'as' => 'txcurr']);