From cb7bee429ec5cc557a83df6271ecd7178359bad4 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 22 Nov 2023 08:14:25 +0300 Subject: [PATCH 1/9] sms receiver merged --- app/Http/Controllers/ReceiverController.php | 76 +++++++++++++++++++++ app/Models/UshauriInbox.php | 18 +++++ app/Models/UshauriOutbox.php | 18 +++++ routes/api.php | 6 +- 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/ReceiverController.php create mode 100644 app/Models/UshauriInbox.php create mode 100644 app/Models/UshauriOutbox.php diff --git a/app/Http/Controllers/ReceiverController.php b/app/Http/Controllers/ReceiverController.php new file mode 100644 index 0000000..a67baf9 --- /dev/null +++ b/app/Http/Controllers/ReceiverController.php @@ -0,0 +1,76 @@ +to == '40149') { + + // dd($request->all()); + + $inbox = new UshauriInbox; + + $inbox->destination = $request->to; + $inbox->source = $request->from; + $inbox->msg = $request->text; + $inbox->receivedtime = $request->date; + $inbox->reference = $request->id; + $inbox->LinkId = $request->linkId; + + $inbox->save(); + + $lastID1 = $inbox->id; + $task = 1; + $this->task($task, $lastID1); + } + } + + function task($task, $LastInsertId) + { + Log::info("ID: " . $LastInsertId . ", TASK: " . $task); + switch ($task) { + case 1: + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, "http://ushaurinode.localhost/receiver/$LastInsertId"); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_exec($ch); + + curl_close($ch); + echo 'Done task 1'; + break; + default: + break; + } + } + + public function ushauri_callback(Request $request) + { + + //check incoming id and update single sms with telco status + + $updateDetails = [ + 'callback_status' => $request->get('status'), + 'failure_reason' => $request->get('failureReason') + ]; + + // return $request; + + $sms = UshauriOutbox::where('message_id', $request->id)->first(); + if ($sms) { + $sms = UshauriOutbox::where('message_id', $request->id) + ->update($updateDetails); + } + } +} diff --git a/app/Models/UshauriInbox.php b/app/Models/UshauriInbox.php new file mode 100644 index 0000000..cf4cdfa --- /dev/null +++ b/app/Models/UshauriInbox.php @@ -0,0 +1,18 @@ +get('/user', function (Request $request) { - return $request->user(); + return $request->user(); }); + + +Route::post('/sms/receiver', 'App\Http\Controllers\ReceiverController@index'); +Route::post('/sms/callback/ushauri', 'App\Http\Controllers\ReceiverController@ushauri_callback'); From dde699ab1fc7d9f526358218e3904881d4a1114a Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 30 Nov 2023 09:37:07 +0300 Subject: [PATCH 2/9] added program indicators and review of nishauri dashboard --- app/Http/Controllers/NewReportController.php | 31 ++ app/Http/Controllers/NishauriController.php | 223 ++++++----- app/Models/NishauriAccess.php | 17 + app/Models/NishauriFacility.php | 18 + app/Models/NishauriUptake.php | 18 + app/Models/UshauriProgram.php | 15 + resources/views/dashboard/program.blade.php | 387 ++++++++++++++++++ resources/views/nishauri/dashboard.blade.php | 393 +++++++++++++------ routes/web.php | 6 + 9 files changed, 884 insertions(+), 224 deletions(-) create mode 100644 app/Models/NishauriAccess.php create mode 100644 app/Models/NishauriFacility.php create mode 100644 app/Models/NishauriUptake.php create mode 100644 app/Models/UshauriProgram.php create mode 100644 resources/views/dashboard/program.blade.php diff --git a/app/Http/Controllers/NewReportController.php b/app/Http/Controllers/NewReportController.php index 01ffd7a..4d7274a 100644 --- a/app/Http/Controllers/NewReportController.php +++ b/app/Http/Controllers/NewReportController.php @@ -17,6 +17,7 @@ use App\Models\Language; use App\Models\Condition; use App\Models\Marital; +use App\Models\UshauriProgram; use DB; use Auth; use Carbon\Carbon; @@ -755,4 +756,34 @@ public function client_message(Request $request) return view('new_reports.client_messages', compact('client_messages', 'selected_from', 'selected_to')); } + public function program_index() + { + return view('dashboard.program'); + } + + public function program() + { + $data = []; + + $program = UshauriProgram::select('*')->orderBy('MonthYear', 'ASC'); + $months = UshauriProgram::select('MonthYear')->orderBy('MonthYear', 'ASC')->groupBy('MonthYear'); + + $data["program"] = $program->get(); + $data["months"] = $months->get(); + + return $data; + } + public function program_filter(Request $request) + { + $data = []; + $selected_month = $request->month; + + $program = UshauriProgram::select('*')->orderBy('MonthYear', 'ASC'); + + if (!empty($selected_month)) { + $program = $program->where('MonthYear', $selected_month); + } + $data["program"] = $program->get(); + return $data; + } } diff --git a/app/Http/Controllers/NishauriController.php b/app/Http/Controllers/NishauriController.php index 5b9c7d4..4a59898 100644 --- a/app/Http/Controllers/NishauriController.php +++ b/app/Http/Controllers/NishauriController.php @@ -11,6 +11,9 @@ use App\Models\Partner; use App\Models\County; use App\Models\SubCounty; +use App\Models\NishauriUptake; +use App\Models\NishauriAccess; +use App\Models\NishauriFacility; use RealRashid\SweetAlert\Facades\Alert; use Illuminate\Support\Facades\Auth; use DB; @@ -140,14 +143,12 @@ public function dashboard() ->get(); $counties = County::where("status", "=", "Active") - ->remember($this->remember_period) ->get(['id', 'name']); $sub_counties = SubCounty::select('tbl_sub_county.id', 'tbl_sub_county.name') ->join('tbl_partner_facility', 'tbl_sub_county.id', '=', 'tbl_partner_facility.sub_county_id') ->where('tbl_partner_facility.county_id', Auth::user()->county_id) ->groupBy('tbl_sub_county.name') - ->remember($this->remember_period) ->get(); @@ -207,12 +208,15 @@ public function nishauri_uptake() ->groupBy('tbl_tx_cur.mfl_code') ->get(); $txcurr = $txcurr->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_national_uptake(?,?,?,?,?,?,?,?)", ["%", "%", "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*'); + $all_module = NishauriAccess::select('*'); $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get()->map(function ($item) { + $item['no_of_clients'] = (int)$item['no_of_clients']; + return $item; + }); + $data['all_module'] = $all_module->get(); } if (Auth::user()->access_level == 'Facility') { $facility = Auth::user()->facility_id; @@ -229,12 +233,12 @@ public function nishauri_uptake() ->groupBy('tbl_tx_cur.mfl_code') ->get(); $txcurr = $txcurr->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", "%", $facility, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", "%", $facility, "1900-01-01", $currentDate]); + $all_enrollment = NishauriFacility::select('*')->where('mfl_code', Auth::user()->facility_id); + $all_module = NishauriAccess::select('*')->where('mfl_code', Auth::user()->facility_id); $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get(); + $data['all_module'] = $all_module->get(); } if (Auth::user()->access_level == 'Partner') { $partner = Auth::user()->partner_id; @@ -251,12 +255,15 @@ public function nishauri_uptake() ->groupBy('tbl_tx_cur.mfl_code') ->get(); $txcurr = $txcurr->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_national_uptake(?,?,?,?,?,?,?,?)", [$partner, "%", "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$partner, "%", "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('partner_id', Auth::user()->partner_id); + $all_module = NishauriAccess::select('*')->where('partner_id', Auth::user()->partner_id); $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get()->map(function ($item) { + $item['no_of_clients'] = (int)$item['no_of_clients']; + return $item; + }); + $data['all_module'] = $all_module->get(); } if (Auth::user()->access_level == 'County') { $county = Auth::user()->county_id; @@ -273,12 +280,15 @@ public function nishauri_uptake() ->groupBy('tbl_tx_cur.mfl_code') ->get(); $txcurr = $txcurr->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_national_uptake(?,?,?,?,?,?,?,?)", ["%", $county, "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", $county, "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('county_id', Auth::user()->county_id); + $all_module = NishauriAccess::select('*')->where('county_id', Auth::user()->county_id); $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get()->map(function ($item) { + $item['no_of_clients'] = (int)$item['no_of_clients']; + return $item; + }); + $data['all_module'] = $all_module->get(); } if (Auth::user()->access_level == 'Sub County') { $subcounty = Auth::user()->sub_county_id; @@ -294,12 +304,16 @@ public function nishauri_uptake() ->groupBy('tbl_tx_cur.mfl_code') ->get(); $txcurr = $txcurr->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_national_uptake(?,?,?,?,?,?,?,?)", ["%", "%", $subcounty, "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", $subcounty, "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('sub_county_id', Auth::user()->subcounty_id); + $all_module = NishauriAccess::select('*')->where('sub_county_id', Auth::user()->subcounty_id); + $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get()->map(function ($item) { + $item['no_of_clients'] = (int)$item['no_of_clients']; + return $item; + }); + $data['all_module'] = $all_module->get(); } return $data; @@ -333,8 +347,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$selected_partners, "%", "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$selected_partners, "%", "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('partner_id', $selected_partners); + $all_module = NishauriAccess::select('*')->where('partner_id', $selected_partners); } if (!empty($selected_counties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -347,8 +361,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$partner, $selected_counties, "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$partner, $selected_counties, "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('partner_id', Auth::user()->partner_id)->where('county_id', $selected_counties); + $all_module = NishauriAccess::select('*')->where('partner_id', Auth::user()->partner_id)->where('county_id', $selected_counties); } if (!empty($selected_subcounties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -362,8 +376,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$partner, "%", $selected_subcounties, "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$partner, "%", $selected_subcounties, "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('partner_id', Auth::user()->partner_id)->where('sub_county_id', $selected_subcounties); + $all_module = NishauriAccess::select('*')->where('partner_id', Auth::user()->partner_id)->where('sub_county_id', $selected_subcounties); } if (!empty($selected_facilites)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -377,8 +391,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$partner, "%", "%", $selected_facilites, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$partner, "%", "%", $selected_facilites, "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('partner_id', Auth::user()->partner_id)->where('mfl_code', $selected_facilites); + $all_module = NishauriAccess::select('*')->where('partner_id', Auth::user()->partner_id)->where('mfl_code', $selected_facilites); } if (!empty($selected_from || $selected_to)) { @@ -398,14 +412,17 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$partner, "%", "%", "%", date($request->from), date($request->to), date($request->from), date($request->to)]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$partner, "%", "%", "%", date($request->from), date($request->to)]); + $all_enrollment = NishauriUptake::select('*')->where('partner_id', Auth::user()->partner_id)->where('enrolled_date', '>=', date($request->from))->where('enrolled_date', '<=', date($request->to)); + $all_module = NishauriAccess::select('*')->where('partner_id', Auth::user()->partner_id)->where('date', '>=', date($request->from))->where('date', '<=', date($request->to)); } $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get()->map(function ($item) { + $item['no_of_clients'] = (int)$item['no_of_clients']; + return $item; + }); + $data['all_module'] = $all_module->get(); return $data; } @@ -435,8 +452,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$selected_partners, $county, "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$selected_partners, $county, "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('county_id', Auth::user()->county_id)->where('partner_id', $selected_partners); + $all_module = NishauriAccess::select('*')->where('county_id', Auth::user()->county_id)->where('partner_id', $selected_partners); } if (!empty($selected_counties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -449,8 +466,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", $selected_counties, "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", $selected_counties, "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('county_id', Auth::user()->county_id)->where('county_id', $selected_counties); + $all_module = NishauriAccess::select('*')->where('county_id', Auth::user()->county_id)->where('county_id', $selected_counties); } if (!empty($selected_subcounties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -464,8 +481,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", $county, $selected_subcounties, "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", $county, $selected_subcounties, "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('county_id', Auth::user()->county_id)->where('sub_county_id', $selected_subcounties); + $all_module = NishauriAccess::select('*')->where('county_id', Auth::user()->county_id)->where('sub_county_id', $selected_subcounties); } if (!empty($selected_facilites)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -479,8 +496,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", $county, "%", $selected_facilites, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", $county, "%", $selected_facilites, "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('mfl_code', $selected_facilites); + $all_module = NishauriAccess::select('*')->where('mfl_code', $selected_facilites); } if (!empty($selected_from || $selected_to)) { @@ -500,14 +517,17 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", $county, "%", "%", date($request->from), date($request->to), date($request->from), date($request->to)]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", $county, "%", "%", date($request->from), date($request->to)]); + $all_enrollment = NishauriUptake::select('*')->where('county_id', Auth::user()->county_id)->where('enrolled_date', '>=', date($request->from))->where('enrolled_date', '<=', date($request->to)); + $all_module = NishauriAccess::select('*')->where('county_id', Auth::user()->county_id)->where('date', '>=', date($request->from))->where('date', '<=', date($request->to)); } $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get()->map(function ($item) { + $item['no_of_clients'] = (int)$item['no_of_clients']; + return $item; + }); + $data['all_module'] = $all_module->get(); return $data; } @@ -537,8 +557,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$selected_partners, "%", $subcounty, "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$selected_partners, "%", $subcounty, "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('partner_id', $selected_partners); + $all_module = NishauriAccess::select('*')->where('partner_id', $selected_partners); } if (!empty($selected_counties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -551,8 +571,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", $selected_counties, $subcounty, "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", $selected_counties, $subcounty, "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('county_id', $selected_counties); + $all_module = NishauriAccess::select('*')->where('county_id', $selected_counties); } if (!empty($selected_subcounties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -566,8 +586,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", $selected_subcounties, "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", $selected_subcounties, "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('sub_county_id', $selected_subcounties); + $all_module = NishauriAccess::select('*')->where('sub_county_id', $selected_subcounties); } if (!empty($selected_facilites)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -581,8 +601,8 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", $subcounty, $selected_facilites, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", $subcounty, $selected_facilites, "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('mfl_code', $selected_facilites); + $all_module = NishauriAccess::select('*')->where('mfl_code', $selected_facilites); } if (!empty($selected_from || $selected_to)) { @@ -602,13 +622,16 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", $subcounty, "%", date($request->from), date($request->to), date($request->from), date($request->to)]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", $subcounty, "%", date($request->from), date($request->to)]); + $all_enrollment = NishauriUptake::select('*')->where('sub_county_id', Auth::user()->subcounty_id)->where('enrolled_date', '>=', date($request->from))->where('enrolled_date', '<=', date($request->to)); + $all_module = NishauriAccess::select('*')->where('sub_county_id', Auth::user()->subcounty_id)->where('date', '>=', date($request->from))->where('date', '<=', date($request->to)); } $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; + $data['all_enrollment'] = $all_enrollment->get()->map(function ($item) { + $item['no_of_clients'] = (int)$item['no_of_clients']; + return $item; + }); $data['all_module'] = $all_module; return $data; @@ -626,7 +649,7 @@ public function filter_nishauri_uptake(Request $request) $currentDate = Carbon::now(); $query = Txcurr::query()->join('tbl_partner_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id); if (!empty($selected_partners)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period @@ -639,13 +662,13 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$selected_partners, "%", "%", $facility, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$selected_partners, "%", "%", $facility, "1900-01-01", $currentDate]); + $all_enrollment = NishauriFacility::select('*')->where('partner_id', $selected_partners); + $all_module = NishauriAccess::select('*')->where('partner_id', $selected_partners); } if (!empty($selected_counties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period - FROM tbl_tx_cur t1 - GROUP BY t1.mfl_code) latest_con'), function ($join) { + FROM tbl_tx_cur t1 + GROUP BY t1.mfl_code) latest_con'), function ($join) { $join->on('tbl_tx_cur.mfl_code', '=', 'latest_con.mfl_code') ->on('tbl_tx_cur.period', '=', 'latest_con.max_period'); })->where('tbl_partner_facility.county_id', $selected_counties) @@ -653,13 +676,13 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", $selected_counties, "%", $facility, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", $selected_counties, "%", $facility, "1900-01-01", $currentDate]); + $all_enrollment = NishauriFacility::select('*')->where('county_id', $selected_counties); + $all_module = NishauriAccess::select('*')->where('county_id', $selected_counties); } if (!empty($selected_subcounties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period - FROM tbl_tx_cur t1 - GROUP BY t1.mfl_code) latest_sub'), function ($join) { + FROM tbl_tx_cur t1 + GROUP BY t1.mfl_code) latest_sub'), function ($join) { $join->on('tbl_tx_cur.mfl_code', '=', 'latest_sub.mfl_code') ->on('tbl_tx_cur.period', '=', 'latest_sub.max_period'); }) @@ -668,13 +691,13 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", $selected_subcounties, $facility, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", $selected_subcounties, $facility, "1900-01-01", $currentDate]); + $all_enrollment = NishauriFacility::select('*')->where('sub_county_id', $selected_subcounties); + $all_module = NishauriAccess::select('*')->where('sub_county_id', $selected_subcounties); } if (!empty($selected_facilites)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period - FROM tbl_tx_cur t1 - GROUP BY t1.mfl_code) latest_fac'), function ($join) { + FROM tbl_tx_cur t1 + GROUP BY t1.mfl_code) latest_fac'), function ($join) { $join->on('tbl_tx_cur.mfl_code', '=', 'latest_fac.mfl_code') ->on('tbl_tx_cur.period', '=', 'latest_fac.max_period'); }) @@ -683,16 +706,16 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", "%", $selected_facilites, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", "%", $selected_facilites, "1900-01-01", $currentDate]); + $all_enrollment = NishauriFacility::select('*')->where('mfl_code', $selected_facilites); + $all_module = NishauriAccess::select('*')->where('mfl_code', $selected_facilites); } if (!empty($selected_from || $selected_to)) { $selectedFrom = date('Ym', strtotime($request->from)); $selectedTo = date('Ym', strtotime($request->to)); $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period - FROM tbl_tx_cur t1 - GROUP BY t1.mfl_code) latest_date'), function ($join) { + FROM tbl_tx_cur t1 + GROUP BY t1.mfl_code) latest_date'), function ($join) { $join->on('tbl_tx_cur.mfl_code', '=', 'latest_date.mfl_code') ->on('tbl_tx_cur.period', '=', 'latest_date.max_period'); }) @@ -704,14 +727,14 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", "%", $facility, date($request->from), date($request->to), date($request->from), date($request->to)]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", "%", $facility, date($request->from), date($request->to)]); + $all_enrollment = NishauriFacility::select('*')->where('mfl_code', Auth::user()->facility_id)->where('enrolled_date', '>=', date($request->from))->where('enrolled_date', '<=', date($request->to)); + $all_module = NishauriAccess::select('*')->where('mfl_code', Auth::user()->facility_id)->where('date', '>=', date($request->from))->where('date', '<=', date($request->to)); } $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get(); + $data['all_module'] = $all_module->get(); return $data; } @@ -730,8 +753,8 @@ public function filter_nishauri_uptake(Request $request) if (!empty($selected_partners)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period - FROM tbl_tx_cur t1 - GROUP BY t1.mfl_code) latest'), function ($join) { + FROM tbl_tx_cur t1 + GROUP BY t1.mfl_code) latest'), function ($join) { $join->on('tbl_tx_cur.mfl_code', '=', 'latest.mfl_code') ->on('tbl_tx_cur.period', '=', 'latest.max_period'); })->where('tbl_partner_facility.partner_id', $selected_partners) @@ -739,13 +762,13 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", [$selected_partners, "%", "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", [$selected_partners, "%", "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('partner_id', $selected_partners); + $all_module = NishauriAccess::select('*')->where('partner_id', $selected_partners); } if (!empty($selected_counties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period - FROM tbl_tx_cur t1 - GROUP BY t1.mfl_code) latest_con'), function ($join) { + FROM tbl_tx_cur t1 + GROUP BY t1.mfl_code) latest_con'), function ($join) { $join->on('tbl_tx_cur.mfl_code', '=', 'latest_con.mfl_code') ->on('tbl_tx_cur.period', '=', 'latest_con.max_period'); })->where('tbl_partner_facility.county_id', $selected_counties) @@ -753,13 +776,13 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", $selected_counties, "%", "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", $selected_counties, "%", "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('county_id', $selected_counties); + $all_module = NishauriAccess::select('*')->where('county_id', $selected_counties); } if (!empty($selected_subcounties)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period - FROM tbl_tx_cur t1 - GROUP BY t1.mfl_code) latest_sub'), function ($join) { + FROM tbl_tx_cur t1 + GROUP BY t1.mfl_code) latest_sub'), function ($join) { $join->on('tbl_tx_cur.mfl_code', '=', 'latest_sub.mfl_code') ->on('tbl_tx_cur.period', '=', 'latest_sub.max_period'); }) @@ -768,13 +791,13 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", $selected_subcounties, "%", "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", $selected_subcounties, "%", "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('sub_county_id', $selected_subcounties); + $all_module = NishauriAccess::select('*')->where('sub_county_id', $selected_subcounties); } if (!empty($selected_facilites)) { $query->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period - FROM tbl_tx_cur t1 - GROUP BY t1.mfl_code) latest_fac'), function ($join) { + FROM tbl_tx_cur t1 + GROUP BY t1.mfl_code) latest_fac'), function ($join) { $join->on('tbl_tx_cur.mfl_code', '=', 'latest_fac.mfl_code') ->on('tbl_tx_cur.period', '=', 'latest_fac.max_period'); }) @@ -783,9 +806,10 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", "%", $selected_facilites, "1900-01-01", $currentDate, "1900-01-01", $currentDate]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", "%", $selected_facilites, "1900-01-01", $currentDate]); + $all_enrollment = NishauriUptake::select('*')->where('mfl_code', $selected_facilites); + $all_module = NishauriAccess::select('*')->where('mfl_code', $selected_facilites); } + if (!empty($selected_from || $selected_to)) { $selectedFrom = date('Ym', strtotime($request->from)); @@ -804,14 +828,17 @@ public function filter_nishauri_uptake(Request $request) $txcurr = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') ->get() ->sum('tx_cur'); - $all_enrollment = DB::select("CALL sp_nishauri_uptake(?,?,?,?,?,?,?,?)", ["%", "%", "%", "%", date($request->from), date($request->to), date($request->from), date($request->to)]); - $all_module = DB::select("CALL sp_nishauri_access_uptake(?,?,?,?,?,?)", ["%", "%", "%", "%", date($request->from), date($request->to)]); + $all_enrollment = NishauriUptake::select('*')->where('enrolled_date', '>=', date($request->from))->where('enrolled_date', '<=', date($request->to)); + $all_module = NishauriAccess::select('*')->where('date', '>=', date($request->from))->where('date', '<=', date($request->to)); } $data['txcurr'] = $txcurr; - $data['all_enrollment'] = $all_enrollment; - $data['all_module'] = $all_module; + $data['all_enrollment'] = $all_enrollment->get()->map(function ($item) { + $item['no_of_clients'] = (int)$item['no_of_clients']; + return $item; + }); + $data['all_module'] = $all_module->get(); return $data; } diff --git a/app/Models/NishauriAccess.php b/app/Models/NishauriAccess.php new file mode 100644 index 0000000..98e45aa --- /dev/null +++ b/app/Models/NishauriAccess.php @@ -0,0 +1,17 @@ + + + + +@endsection + +@section('main-content') + + +
+ +
+ {{ csrf_field() }} +
+ +
+
+ + + +
+
+
+
+ + + +
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@endsection \ No newline at end of file diff --git a/resources/views/nishauri/dashboard.blade.php b/resources/views/nishauri/dashboard.blade.php index dbd164a..ab652ea 100644 --- a/resources/views/nishauri/dashboard.blade.php +++ b/resources/views/nishauri/dashboard.blade.php @@ -155,7 +155,7 @@
+ + + + +
+ +
+
+ + + +
@@ -134,6 +157,25 @@ - + + -@endsection +@endsection \ No newline at end of file diff --git a/resources/views/directory/search.blade.php b/resources/views/directory/search.blade.php new file mode 100644 index 0000000..5ae30d9 --- /dev/null +++ b/resources/views/directory/search.blade.php @@ -0,0 +1,211 @@ + + + + + + + + + Ushauri - Getting better one text at a time + + + + + + + +
+ +
+
+ Back +
+ +
+

Facility Directory

+
+
+ +
+
+ + +
+ +
+
+ + + +
+
+ + + +
+ + + +
+ + + + + + + + + + + \ No newline at end of file diff --git a/resources/views/landing/page.blade.php b/resources/views/landing/page.blade.php new file mode 100644 index 0000000..1871ab7 --- /dev/null +++ b/resources/views/landing/page.blade.php @@ -0,0 +1,62 @@ + + + + + + + + + Ushauri - Getting better one text at a time + + + + + + + +
+
+

mHealth Applications

+
+ +
+ + + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 230161f..370cea8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -26,9 +26,15 @@ | */ -Route::get('/', function () { +Route::get('/login', function () { return view('auth/login'); }); +Route::get('/', function () { + return view('landing/page'); +}); +Route::get('/directory', function () { + return view('directory/search'); +}); //SMS Scheduler routes