Skip to content

Commit

Permalink
Merge pull request #23 from palladiumkenya/main
Browse files Browse the repository at this point in the history
Release of Ushauri Dashboards
  • Loading branch information
Murithijoshua authored Jan 29, 2024
2 parents 2d12611 + 598f215 commit 2b84568
Show file tree
Hide file tree
Showing 23 changed files with 1,601 additions and 330 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function redirectTo() {
Session::flash('statuscode', 'success');
return '/admin/dashboard';
}else {
return '/';
return '/login';
}
}
/**
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Controllers/DirectoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

class DirectoryController extends Controller
{
public function directory(Request $request, $facility)
{
$mfl = implode('', range(0, 9));

$apiUrl = env('ART_URL') . "directory/{$mfl}/{$facility}";

$response = Http::get($apiUrl);

if ($response->successful()) {

$apiData = $response->json();
return response()->json($apiData);
} else {

$errorData = $response->json();
return response()->json(['error' => 'API request failed'], $response->status());
}
}
}
23 changes: 22 additions & 1 deletion app/Http/Controllers/NewDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,28 @@ public function partner_summary()
->whereNull('tbl_client.hei_no')
->groupBy('tbl_tx_cur.mfl_code')
->remember($this->remember_period)
->selectRaw('COUNT(tbl_client.clinic_number) as client_ever_enrolled, tbl_county.name as county, tbl_partner.name as partner, tbl_master_facility.name as facility, tbl_master_facility.code as mfl_code, (SELECT COUNT(*) FROM tbl_client WHERE tbl_client.mfl_code = tbl_partner_facility.mfl_code AND tbl_client.hei_no IS NULL AND tbl_client.smsenable = "Yes" AND tbl_partner_facility.partner_id = ' . Auth::user()->partner_id . ') as client_consented');
->selectRaw('COUNT(tbl_client.clinic_number) as client_ever_enrolled, tbl_county.name as county, tbl_partner.name as partner, tbl_master_facility.name as facility, tbl_master_facility.code as mfl_code,
(SELECT
COUNT(CASE
WHEN c.smsenable = "Yes" THEN 1
WHEN a.client_id IS NOT NULL THEN
1
END) AS client_consented
FROM
tbl_client c
LEFT JOIN (
SELECT
client_id,
DATE( created_at ) AS created_at
FROM
tbl_appointment a1
WHERE
a1.id = ( SELECT MAX( a2.id ) FROM tbl_appointment a2 WHERE a2.client_id = a1.client_id )
AND a1.consented = "YES"
) a ON c.id = a.client_id
WHERE c.mfl_code = tbl_partner_facility.mfl_code AND c.hei_no IS NULL AND tbl_partner_facility.partner_id = ' . Auth::user()->partner_id . ') as client_consented');

// ->selectRaw('COUNT(tbl_client.clinic_number) as client_ever_enrolled, tbl_county.name as county, tbl_partner.name as partner, tbl_master_facility.name as facility, tbl_master_facility.code as mfl_code, (SELECT COUNT(*) FROM tbl_client WHERE tbl_client.mfl_code = tbl_partner_facility.mfl_code AND tbl_client.hei_no IS NULL AND tbl_client.smsenable = "Yes" AND tbl_partner_facility.partner_id = ' . Auth::user()->partner_id . ') as client_consented');
}


Expand Down
97 changes: 94 additions & 3 deletions app/Http/Controllers/NewReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use App\Models\Language;
use App\Models\Condition;
use App\Models\Marital;
use App\Models\UshauriProgram;
use App\Models\UshauriProgramActive;
use DB;
use Auth;
use Carbon\Carbon;
Expand Down Expand Up @@ -658,7 +660,7 @@ public function client_message(Request $request)
'tbl_client.phone_no',
'tbl_clnt_outgoing.msg',
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Failed" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "Failed" ELSE "Success" END AS callback_status'),
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "DeliveryFailure" ELSE tbl_clnt_outgoing.failure_reason END AS failure_reason'),
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "Phone No. Inactive" WHEN tbl_clnt_outgoing.failure_reason = "UserInBlackList" THEN "Service Blacklisted" WHEN tbl_clnt_outgoing.failure_reason = "AbsentSubscriber" THEN "Phone off >48 Hours" WHEN tbl_clnt_outgoing.failure_reason = "UserInactive" THEN "Failure at Telco" WHEN tbl_clnt_outgoing.failure_reason = "DeliveryFailure" THEN "Phone No. Inactive" END AS failure_reason'),
'tbl_clnt_outgoing.updated_at',
'tbl_appointment.appntmnt_date as appointment_date',
'tbl_appointment_types.name as app_type',
Expand Down Expand Up @@ -695,7 +697,7 @@ public function client_message(Request $request)
'tbl_client.phone_no',
'tbl_clnt_outgoing.msg',
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Failed" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "Failed" ELSE "Success" END AS callback_status'),
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "DeliveryFailure" ELSE tbl_clnt_outgoing.failure_reason END AS failure_reason'),
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "Phone No. Inactive" WHEN tbl_clnt_outgoing.failure_reason = "UserInBlackList" THEN "Service Blacklisted" WHEN tbl_clnt_outgoing.failure_reason = "AbsentSubscriber" THEN "Phone off >48 Hours" WHEN tbl_clnt_outgoing.failure_reason = "UserInactive" THEN "Failure at Telco" WHEN tbl_clnt_outgoing.failure_reason = "DeliveryFailure" THEN "Phone No. Inactive" END AS failure_reason'),
'tbl_clnt_outgoing.updated_at',
'tbl_appointment.appntmnt_date as appointment_date',
'tbl_appointment_types.name as app_type',
Expand Down Expand Up @@ -733,7 +735,7 @@ public function client_message(Request $request)
'tbl_client.phone_no',
'tbl_clnt_outgoing.msg',
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Failed" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "Failed" ELSE "Success" END AS callback_status'),
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "DeliveryFailure" ELSE tbl_clnt_outgoing.failure_reason END AS failure_reason'),
DB::raw('CASE WHEN tbl_clnt_outgoing.message_id IS NULL OR tbl_clnt_outgoing.message_id = "None" OR tbl_clnt_outgoing.callback_status = "Expired" THEN "Phone No. Inactive" WHEN tbl_clnt_outgoing.failure_reason = "UserInBlackList" THEN "Service Blacklisted" WHEN tbl_clnt_outgoing.failure_reason = "AbsentSubscriber" THEN "Phone off >48 Hours" WHEN tbl_clnt_outgoing.failure_reason = "UserInactive" THEN "Failure at Telco" WHEN tbl_clnt_outgoing.failure_reason = "DeliveryFailure" THEN "Phone No. Inactive" END AS failure_reason'),
'tbl_clnt_outgoing.no_of_days',
'tbl_clnt_outgoing.updated_at',
'tbl_appointment.appntmnt_date as appointment_date',
Expand All @@ -755,4 +757,93 @@ 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 = [];

$latestMonthYear = UshauriProgram::max('LastDateUsed');
$latestMonthYear = UshauriProgramActive::max('LastDateUsed');

$sixMonthsBefore = Carbon::parse($latestMonthYear)->subMonths(5);
$program = UshauriProgram::whereDate('LastDateUsed', '>=', $sixMonthsBefore)->orderBy('Months', 'ASC');
$active_site = UshauriProgramActive::whereDate('LastDateUsed', '>=', $sixMonthsBefore)->orderBy('Months', 'ASC');


$data["program"] = $program->get();
$data["active_site"] = $active_site->get();

return $data;
}
public function program_filter(Request $request)
{
$data = [];
$selected_month = $request->months;
$selected_year = $request->year;




if (!empty($selected_month)) {
$program = UshauriProgram::select('*')->orderBy('Months', 'ASC');
$program = $program->where('MonthYear', 'LIKE', "%$selected_month%");

$active_site = UshauriProgramActive::select('*')->orderBy('Months', 'ASC');
$active_site = $active_site->where('MonthYear', 'LIKE', "%$selected_month%");
}
if (!empty($selected_year)) {
$program = UshauriProgram::select('*')->orderBy('Months', 'ASC');
$program = $program->where('MonthYear', 'LIKE', "%$selected_year%");

$active_site = UshauriProgramActive::select('*')->orderBy('Months', 'ASC');
$active_site = $active_site->where('MonthYear', 'LIKE', "%$selected_year%");
}
if (!empty($selected_year) && !empty($selected_month)) {
// $program = UshauriProgram::where('MonthYear', 'LIKE', "$selected_month-$selected_year");
$selected_month_number = date('n', strtotime("$selected_month 1"));

$program = UshauriProgram::where(function ($query) use ($selected_month, $selected_year, $selected_month_number) {
$query->where('MonthYear', 'LIKE', "$selected_month-$selected_year")->orderBy('Months', 'ASC');

for ($i = 1; $i <= 5; $i++) {
$previous_month_number = $selected_month_number - $i;
$previous_month_name = date('F', mktime(0, 0, 0, $previous_month_number, 1));

if ($previous_month_number <= 0) {
$previous_month_number += 12;
$previous_year = $selected_year - 1;
} else {
$previous_year = $selected_year;
}

$query->orWhere('MonthYear', 'LIKE', "$previous_month_name-$previous_year");
}
});

$active_site = UshauriProgramActive::where(function ($query) use ($selected_month, $selected_year, $selected_month_number) {
$query->where('MonthYear', 'LIKE', "$selected_month-$selected_year")->orderBy('Months', 'ASC');

for ($i = 1; $i <= 5; $i++) {
$previous_month_number = $selected_month_number - $i;
$previous_month_name = date('F', mktime(0, 0, 0, $previous_month_number, 1));

if ($previous_month_number <= 0) {
$previous_month_number += 12;
$previous_year = $selected_year - 1;
} else {
$previous_year = $selected_year;
}

$query->orWhere('MonthYear', 'LIKE', "$previous_month_name-$previous_year");
}
});
}
$data["program"] = $program->get();
$data["active_site"] = $active_site->get();
return $data;
}
}
Loading

0 comments on commit 2b84568

Please sign in to comment.