diff --git a/app/Http/Controllers/FacilityController.php b/app/Http/Controllers/FacilityController.php index 36d74dd..46b9832 100644 --- a/app/Http/Controllers/FacilityController.php +++ b/app/Http/Controllers/FacilityController.php @@ -70,152 +70,260 @@ public function add_facility(Request $request) } public function my_facility() { - if (Auth::user()->access_level == 'Admin') { - $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') - // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') - ->select( - 'tbl_master_facility.name as facility_name', - 'tbl_partner_facility.avg_clients as average_clients', - 'tbl_master_facility.code', - 'tbl_master_facility.owner', - 'tbl_county.name as county_name', - 'tbl_sub_county.name as sub_county_name', - 'tbl_consituency.name as consituency_name', - 'tbl_master_facility.facility_type', - 'tbl_master_facility.keph_level as level', - 'tbl_partner_facility.is_approved', - 'tbl_partner_facility.id', - 'tbl_partner_facility.partner_id' - //'tbl_partner.name as partner_name' - ) - ->get(); - } - if (Auth::user()->access_level == 'Donor') { - $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') - // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') - ->select( - 'tbl_master_facility.name as facility_name', - 'tbl_partner_facility.avg_clients as average_clients', - 'tbl_master_facility.code', - 'tbl_master_facility.owner', - 'tbl_county.name as county_name', - 'tbl_sub_county.name as sub_county_name', - 'tbl_consituency.name as consituency_name', - 'tbl_master_facility.facility_type', - 'tbl_master_facility.keph_level as level', - 'tbl_partner_facility.is_approved', - 'tbl_partner_facility.id' - //'tbl_partner.name as partner_name' - ) - ->get(); - } - if (Auth::user()->access_level == 'Facility') { - $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') - // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') - ->select( - 'tbl_master_facility.name as facility_name', - 'tbl_master_facility.code', - 'tbl_master_facility.owner', - 'tbl_county.name as county_name', - 'tbl_partner_facility.avg_clients as average_clients', - 'tbl_sub_county.name as sub_county_name', - 'tbl_consituency.name as consituency_name', - 'tbl_master_facility.facility_type', - 'tbl_master_facility.keph_level as level', - 'tbl_partner_facility.is_approved', - 'tbl_partner_facility.id' - // 'tbl_partner.name as partner_name' - ) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->get(); - } - if (Auth::user()->access_level == 'Partner') { - $all_partners = Partner::all()->where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id); + if (env('INSTANCE') === 'UshauriDOD') { + if (Auth::user()->access_level == 'Admin') { + $facilities = Facility::join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id', + 'tbl_partner_facility.partner_id' + //'tbl_partner.name as partner_name' + ) + ->get(); + } + if (Auth::user()->access_level == 'Donor') { + $facilities = Facility::join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + //'tbl_partner.name as partner_name' + ) + ->get(); + } + if (Auth::user()->access_level == 'Facility') { + $facilities = Facility::join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + // 'tbl_partner.name as partner_name' + ) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->get(); + } + if (Auth::user()->access_level == 'Partner') { + $all_partners = Partner::all()->where('status', '=', 'Active') + ->where('id', Auth::user()->partner_id); - $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') - // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') - ->select( - 'tbl_master_facility.name as facility_name', - 'tbl_master_facility.code', - 'tbl_master_facility.owner', - 'tbl_county.name as county_name', - 'tbl_partner_facility.avg_clients as average_clients', - 'tbl_sub_county.name as sub_county_name', - 'tbl_consituency.name as consituency_name', - 'tbl_master_facility.facility_type', - 'tbl_master_facility.keph_level as level', - 'tbl_partner_facility.is_approved', - 'tbl_partner_facility.id' - // 'tbl_partner.name as partner_name' - ) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->get(); - } - if (Auth::user()->access_level == 'Sub County') { - $all_partners = Partner::all()->where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id); + $facilities = Facility::join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + // 'tbl_partner.name as partner_name' + ) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->get(); + } + if (Auth::user()->access_level == 'Sub County') { + $all_partners = Partner::all()->where('status', '=', 'Active') + ->where('id', Auth::user()->partner_id); - $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') - // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') - ->select( - 'tbl_master_facility.name as facility_name', - 'tbl_master_facility.code', - 'tbl_master_facility.owner', - 'tbl_county.name as county_name', - 'tbl_partner_facility.avg_clients as average_clients', - 'tbl_sub_county.name as sub_county_name', - 'tbl_consituency.name as consituency_name', - 'tbl_master_facility.facility_type', - 'tbl_master_facility.keph_level as level', - 'tbl_partner_facility.is_approved', - 'tbl_partner_facility.id' - // 'tbl_partner.name as partner_name' - ) - ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id) - ->get(); - } - if (Auth::user()->access_level == 'County') { - $all_partners = Partner::all()->where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id); + $facilities = Facility::join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + // 'tbl_partner.name as partner_name' + ) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id) + ->get(); + } + if (Auth::user()->access_level == 'County') { + $all_partners = Partner::all()->where('status', '=', 'Active') + ->where('id', Auth::user()->partner_id); - $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') - // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') - ->select( - 'tbl_master_facility.name as facility_name', - 'tbl_master_facility.code', - 'tbl_master_facility.owner', - 'tbl_county.name as county_name', - 'tbl_partner_facility.avg_clients as average_clients', - 'tbl_sub_county.name as sub_county_name', - 'tbl_consituency.name as consituency_name', - 'tbl_master_facility.facility_type', - 'tbl_master_facility.keph_level as level', - 'tbl_partner_facility.is_approved', - 'tbl_partner_facility.id' - // 'tbl_partner.name as partner_name' - ) - ->where('tbl_partner_facility.county_id', Auth::user()->county_id) - ->get(); + $facilities = Facility::join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + // 'tbl_partner.name as partner_name' + ) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id) + ->get(); + } + } else { + if (Auth::user()->access_level == 'Admin') { + $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') + // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_county.name as county_name', + 'tbl_sub_county.name as sub_county_name', + 'tbl_consituency.name as consituency_name', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id', + 'tbl_partner_facility.partner_id' + //'tbl_partner.name as partner_name' + ) + ->get(); + } + if (Auth::user()->access_level == 'Donor') { + $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') + // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_county.name as county_name', + 'tbl_sub_county.name as sub_county_name', + 'tbl_consituency.name as consituency_name', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + //'tbl_partner.name as partner_name' + ) + ->get(); + } + if (Auth::user()->access_level == 'Facility') { + $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') + // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_county.name as county_name', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_sub_county.name as sub_county_name', + 'tbl_consituency.name as consituency_name', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + // 'tbl_partner.name as partner_name' + ) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->get(); + } + if (Auth::user()->access_level == 'Partner') { + $all_partners = Partner::all()->where('status', '=', 'Active') + ->where('id', Auth::user()->partner_id); + + $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') + // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_county.name as county_name', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_sub_county.name as sub_county_name', + 'tbl_consituency.name as consituency_name', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + // 'tbl_partner.name as partner_name' + ) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->get(); + } + if (Auth::user()->access_level == 'Sub County') { + $all_partners = Partner::all()->where('status', '=', 'Active') + ->where('id', Auth::user()->partner_id); + + $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') + // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_county.name as county_name', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_sub_county.name as sub_county_name', + 'tbl_consituency.name as consituency_name', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + // 'tbl_partner.name as partner_name' + ) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id) + ->get(); + } + if (Auth::user()->access_level == 'County') { + $all_partners = Partner::all()->where('status', '=', 'Active') + ->where('id', Auth::user()->partner_id); + + $facilities = Facility::join('tbl_county', 'tbl_master_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_master_facility.Sub_County_ID', '=', 'tbl_sub_county.id') + // ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_consituency', 'tbl_master_facility.consituency_id', '=', 'tbl_consituency.id') + ->select( + 'tbl_master_facility.name as facility_name', + 'tbl_master_facility.code', + 'tbl_master_facility.owner', + 'tbl_county.name as county_name', + 'tbl_partner_facility.avg_clients as average_clients', + 'tbl_sub_county.name as sub_county_name', + 'tbl_consituency.name as consituency_name', + 'tbl_master_facility.facility_type', + 'tbl_master_facility.keph_level as level', + 'tbl_partner_facility.is_approved', + 'tbl_partner_facility.id' + // 'tbl_partner.name as partner_name' + ) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id) + ->get(); + } } + $all_partners = Partner::all()->where('status', '=', 'Active'); return view('facilities.my_facilities', compact('facilities', 'all_partners')); } diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index b419934..bdc0ea2 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -35,23 +35,36 @@ public function partner_summary() { $data = []; - $result = Txcurr::selectRaw('tbl_tx_cur.tx_cur as tx_cur') - ->join('tbl_partner_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->join(DB::raw('(SELECT t1.mfl_code, MAX(t1.period) AS max_period + if (env('INSTANCE') === 'UshauriDOD') { + + $result = PartnerFacility::leftJoin('tbl_client', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->leftJoin('tbl_partner', 'tbl_partner.id', '=', 'tbl_partner_facility.partner_id') + ->leftJoin('tbl_master_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->selectRaw('COUNT(tbl_client.clinic_number) as client_ever_enrolled, 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') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->whereNull('tbl_client.hei_no') + ->groupBy('tbl_partner_facility.mfl_code'); + } else { + + $result = Txcurr::selectRaw('tbl_tx_cur.tx_cur as tx_cur') + ->join('tbl_partner_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->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) { - $join->on('tbl_tx_cur.mfl_code', '=', 'latest.mfl_code') - ->on('tbl_tx_cur.period', '=', 'latest.max_period'); - }) - ->leftJoin('tbl_client', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->leftJoin('tbl_partner', 'tbl_partner.id', '=', 'tbl_partner_facility.partner_id') - ->leftJoin('tbl_county', 'tbl_county.id', '=', 'tbl_partner_facility.county_id') - ->leftJoin('tbl_master_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->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'); + $join->on('tbl_tx_cur.mfl_code', '=', 'latest.mfl_code') + ->on('tbl_tx_cur.period', '=', 'latest.max_period'); + }) + ->leftJoin('tbl_client', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->leftJoin('tbl_partner', 'tbl_partner.id', '=', 'tbl_partner_facility.partner_id') + ->leftJoin('tbl_county', 'tbl_county.id', '=', 'tbl_partner_facility.county_id') + ->leftJoin('tbl_master_facility', 'tbl_master_facility.code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->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'); + } + $data["result"] = $result->get(); @@ -6348,21 +6361,36 @@ public function filter_dashboard_charts(Request $request) $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 + if (env('INSTANCE') === 'UshauriDOD') { + $client = Txcurr::selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') + ->join('tbl_partner_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->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) { + $join->on('tbl_tx_cur.mfl_code', '=', 'latest.mfl_code') + ->on('tbl_tx_cur.period', '=', 'latest.max_period'); + }) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->groupBy('tbl_tx_cur.mfl_code') + ->remember($this->remember_period) + ->get(); + $client = $client->sum('tx_cur'); + } else { + $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) { - $join->on('tbl_tx_cur.mfl_code', '=', 'latest_fac.mfl_code') - ->on('tbl_tx_cur.period', '=', 'latest_fac.max_period'); - }) - ->where(function ($query) use ($selectedFrom, $selectedTo) { - $query->whereRaw("SUBSTRING(tbl_tx_cur.period, 1, 6) >= ?", $selectedFrom) - ->whereRaw("SUBSTRING(tbl_tx_cur.period, 1, 6) <= ?", $selectedTo); + $join->on('tbl_tx_cur.mfl_code', '=', 'latest_fac.mfl_code') + ->on('tbl_tx_cur.period', '=', 'latest_fac.max_period'); }) - ->groupBy('tbl_tx_cur.mfl_code'); - $client = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') - ->get() - ->sum('tx_cur'); + ->where(function ($query) use ($selectedFrom, $selectedTo) { + $query->whereRaw("SUBSTRING(tbl_tx_cur.period, 1, 6) >= ?", $selectedFrom) + ->whereRaw("SUBSTRING(tbl_tx_cur.period, 1, 6) <= ?", $selectedTo); + }) + ->groupBy('tbl_tx_cur.mfl_code'); + $client = $query->selectRaw('SUM(tbl_tx_cur.tx_cur) as tx_cur') + ->get() + ->sum('tx_cur'); + } // $client = $client->where('tbl_tx_cur.period', function ($query) use ($selectedFrom, $selectedTo) { // $query->select(DB::raw('MAX(period)')) diff --git a/app/Http/Controllers/NewReportController.php b/app/Http/Controllers/NewReportController.php index b791a81..c9558d0 100644 --- a/app/Http/Controllers/NewReportController.php +++ b/app/Http/Controllers/NewReportController.php @@ -29,178 +29,175 @@ class NewReportController extends Controller { public function clients_list() { - if (Auth::user()->access_level == 'Facility') { - $gender = Gender::all(); - $marital = Marital::all(); - $treatment = Condition::all(); - $grouping = Group::all()->where('status', '=', 'Active'); - $clinics = Clinic::all(); - $time = Time::all(); - $county = County::where('status', '=', 'Active')->pluck('name', 'id'); - $language = Language::all()->where('status', '=', 'Active'); + if (env('INSTANCE') === 'UshauriDOD') { + if (Auth::user()->access_level == 'Facility') { + $gender = Gender::all(); + $marital = Marital::all(); + $treatment = Condition::all(); + $grouping = Group::all()->where('status', '=', 'Active'); + $clinics = Clinic::all(); + $time = Time::all(); + $county = County::where('status', '=', 'Active')->pluck('name', 'id'); + $language = Language::all()->where('status', '=', 'Active'); - $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') - ->join('tbl_groups', 'tbl_client.group_id', '=', 'tbl_groups.id') - ->join('tbl_language', 'tbl_client.language_id', '=', 'tbl_language.id') - ->join('tbl_condition', 'tbl_client.client_status', '=', 'tbl_condition.name') - ->join('tbl_marital_status', 'tbl_client.marital', '=', 'tbl_marital_status.id') - ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') - ->select( - 'tbl_client.id', - 'tbl_client.clinic_number', - 'tbl_client.f_name', - 'tbl_client.m_name', - 'tbl_client.l_name', - 'tbl_client.dob', - 'tbl_client.created_at', - 'tbl_client.smsenable', - DB::raw('DATE(tbl_client.enrollment_date) AS enrollment_date'), - DB::raw('DATE(tbl_client.art_date) AS art_date'), - 'tbl_client.motivational_enable', - 'tbl_client.phone_no', - 'tbl_client.clinic_id', - 'tbl_client.client_status', - 'tbl_client.status', - 'tbl_client.language_id', - 'tbl_client.group_id', - 'tbl_client.txt_time', - 'tbl_condition.id as client_treatment', - 'tbl_gender.id as gender', - 'tbl_gender.name as gender_name', - 'tbl_marital_status.id as marital', - 'tbl_master_facility.code', - 'tbl_master_facility.name as facility', - 'tbl_partner.name as partner', - 'tbl_county.name as county', - 'tbl_client.locator_county', - 'tbl_client.locator_sub_county', - 'tbl_client.locator_ward', - 'tbl_client.locator_village', - 'tbl_client.locator_location', - 'tbl_client.upi_no' - ) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->paginate(20000); - } - if (Auth::user()->access_level == 'Partner') { - $gender = Gender::all(); - $marital = Marital::all(); - $treatment = Condition::all(); - $grouping = Group::all()->where('status', '=', 'Active'); - $clinics = Clinic::all(); - $time = Time::all(); - $county = County::where('status', '=', 'Active')->pluck('name', 'id'); - $language = Language::all()->where('status', '=', 'Active'); + $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') + ->join('tbl_groups', 'tbl_client.group_id', '=', 'tbl_groups.id') + ->join('tbl_language', 'tbl_client.language_id', '=', 'tbl_language.id') + ->join('tbl_condition', 'tbl_client.client_status', '=', 'tbl_condition.name') + ->join('tbl_marital_status', 'tbl_client.marital', '=', 'tbl_marital_status.id') + ->select( + 'tbl_client.id', + 'tbl_client.clinic_number', + 'tbl_client.f_name', + 'tbl_client.m_name', + 'tbl_client.l_name', + 'tbl_client.dob', + 'tbl_client.created_at', + 'tbl_client.smsenable', + DB::raw('DATE(tbl_client.enrollment_date) AS enrollment_date'), + DB::raw('DATE(tbl_client.art_date) AS art_date'), + 'tbl_client.motivational_enable', + 'tbl_client.phone_no', + 'tbl_client.clinic_id', + 'tbl_client.client_status', + 'tbl_client.status', + 'tbl_client.language_id', + 'tbl_client.group_id', + 'tbl_client.txt_time', + 'tbl_condition.id as client_treatment', + 'tbl_gender.id as gender', + 'tbl_gender.name as gender_name', + 'tbl_marital_status.id as marital', + 'tbl_master_facility.code', + 'tbl_master_facility.name as facility', + 'tbl_partner.name as partner', + 'tbl_client.locator_county', + 'tbl_client.locator_sub_county', + 'tbl_client.locator_ward', + 'tbl_client.locator_village', + 'tbl_client.locator_location', + 'tbl_client.upi_no' + ) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->paginate(20000); + } + if (Auth::user()->access_level == 'Partner') { + $gender = Gender::all(); + $marital = Marital::all(); + $treatment = Condition::all(); + $grouping = Group::all()->where('status', '=', 'Active'); + $clinics = Clinic::all(); + $time = Time::all(); + $county = County::where('status', '=', 'Active')->pluck('name', 'id'); + $language = Language::all()->where('status', '=', 'Active'); - $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') - ->join('tbl_groups', 'tbl_client.group_id', '=', 'tbl_groups.id') - ->join('tbl_language', 'tbl_client.language_id', '=', 'tbl_language.id') - ->join('tbl_condition', 'tbl_client.client_status', '=', 'tbl_condition.name') - ->join('tbl_marital_status', 'tbl_client.marital', '=', 'tbl_marital_status.id') - ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') - ->select( - 'tbl_client.id', - 'tbl_client.clinic_number', - 'tbl_client.f_name', - 'tbl_client.m_name', - 'tbl_client.l_name', - 'tbl_client.dob', - 'tbl_client.created_at', - 'tbl_client.smsenable', - DB::raw('DATE(tbl_client.enrollment_date) AS enrollment_date'), - DB::raw('DATE(tbl_client.art_date) AS art_date'), - 'tbl_client.motivational_enable', - 'tbl_client.phone_no', - 'tbl_client.clinic_id', - 'tbl_client.client_status', - 'tbl_client.status', - 'tbl_client.language_id', - 'tbl_client.group_id', - 'tbl_client.txt_time', - 'tbl_condition.id as client_treatment', - 'tbl_gender.id as gender', - 'tbl_gender.name as gender_name', - 'tbl_marital_status.id as marital', - 'tbl_master_facility.code', - 'tbl_master_facility.name as facility', - 'tbl_partner.name as partner', - 'tbl_county.name as county', - 'tbl_client.locator_county', - 'tbl_client.locator_sub_county', - 'tbl_client.locator_ward', - 'tbl_client.locator_village', - 'tbl_client.locator_location', - 'tbl_client.upi_no' - ) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->paginate(1000); - } - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $gender = Gender::all(); - $marital = Marital::all(); - $treatment = Condition::all(); - $grouping = Group::all()->where('status', '=', 'Active'); - $clinics = Clinic::all(); - $time = Time::all(); - $county = County::where('status', '=', 'Active')->pluck('name', 'id'); - $language = Language::all()->where('status', '=', 'Active'); + $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') + ->join('tbl_groups', 'tbl_client.group_id', '=', 'tbl_groups.id') + ->join('tbl_language', 'tbl_client.language_id', '=', 'tbl_language.id') + ->join('tbl_condition', 'tbl_client.client_status', '=', 'tbl_condition.name') + ->join('tbl_marital_status', 'tbl_client.marital', '=', 'tbl_marital_status.id') + ->select( + 'tbl_client.id', + 'tbl_client.clinic_number', + 'tbl_client.f_name', + 'tbl_client.m_name', + 'tbl_client.l_name', + 'tbl_client.dob', + 'tbl_client.created_at', + 'tbl_client.smsenable', + DB::raw('DATE(tbl_client.enrollment_date) AS enrollment_date'), + DB::raw('DATE(tbl_client.art_date) AS art_date'), + 'tbl_client.motivational_enable', + 'tbl_client.phone_no', + 'tbl_client.clinic_id', + 'tbl_client.client_status', + 'tbl_client.status', + 'tbl_client.language_id', + 'tbl_client.group_id', + 'tbl_client.txt_time', + 'tbl_condition.id as client_treatment', + 'tbl_gender.id as gender', + 'tbl_gender.name as gender_name', + 'tbl_marital_status.id as marital', + 'tbl_master_facility.code', + 'tbl_master_facility.name as facility', + 'tbl_partner.name as partner', + 'tbl_client.locator_county', + 'tbl_client.locator_sub_county', + 'tbl_client.locator_ward', + 'tbl_client.locator_village', + 'tbl_client.locator_location', + 'tbl_client.upi_no' + ) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->paginate(1000); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $gender = Gender::all(); + $marital = Marital::all(); + $treatment = Condition::all(); + $grouping = Group::all()->where('status', '=', 'Active'); + $clinics = Clinic::all(); + $time = Time::all(); + $county = County::where('status', '=', 'Active')->pluck('name', 'id'); + $language = Language::all()->where('status', '=', 'Active'); - $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') - ->join('tbl_groups', 'tbl_client.group_id', '=', 'tbl_groups.id') - ->join('tbl_language', 'tbl_client.language_id', '=', 'tbl_language.id') - ->join('tbl_condition', 'tbl_client.client_status', '=', 'tbl_condition.name') - ->join('tbl_marital_status', 'tbl_client.marital', '=', 'tbl_marital_status.id') - ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') - ->select( - 'tbl_client.id', - 'tbl_client.clinic_number', - 'tbl_client.f_name', - 'tbl_client.m_name', - 'tbl_client.l_name', - 'tbl_client.dob', - 'tbl_client.created_at', - 'tbl_client.smsenable', - DB::raw('DATE(tbl_client.enrollment_date) AS enrollment_date'), - DB::raw('DATE(tbl_client.art_date) AS art_date'), - 'tbl_client.motivational_enable', - 'tbl_client.phone_no', - 'tbl_client.clinic_id', - 'tbl_client.client_status', - 'tbl_client.status', - 'tbl_client.language_id', - 'tbl_client.group_id', - 'tbl_client.txt_time', - 'tbl_condition.id as client_treatment', - 'tbl_gender.id as gender', - 'tbl_gender.name as gender_name', - 'tbl_marital_status.id as marital', - 'tbl_master_facility.code', - 'tbl_master_facility.name as facility', - 'tbl_partner.name as partner', - 'tbl_county.name as county', - 'tbl_client.locator_county', - 'tbl_client.locator_sub_county', - 'tbl_client.locator_ward', - 'tbl_client.locator_village', - 'tbl_client.locator_location', - 'tbl_client.upi_no' - ) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->paginate(1000); + $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') + ->join('tbl_groups', 'tbl_client.group_id', '=', 'tbl_groups.id') + ->join('tbl_language', 'tbl_client.language_id', '=', 'tbl_language.id') + ->join('tbl_condition', 'tbl_client.client_status', '=', 'tbl_condition.name') + ->join('tbl_marital_status', 'tbl_client.marital', '=', 'tbl_marital_status.id') + ->select( + 'tbl_client.id', + 'tbl_client.clinic_number', + 'tbl_client.f_name', + 'tbl_client.m_name', + 'tbl_client.l_name', + 'tbl_client.dob', + 'tbl_client.created_at', + 'tbl_client.smsenable', + DB::raw('DATE(tbl_client.enrollment_date) AS enrollment_date'), + DB::raw('DATE(tbl_client.art_date) AS art_date'), + 'tbl_client.motivational_enable', + 'tbl_client.phone_no', + 'tbl_client.clinic_id', + 'tbl_client.client_status', + 'tbl_client.status', + 'tbl_client.language_id', + 'tbl_client.group_id', + 'tbl_client.txt_time', + 'tbl_condition.id as client_treatment', + 'tbl_gender.id as gender', + 'tbl_gender.name as gender_name', + 'tbl_marital_status.id as marital', + 'tbl_master_facility.code', + 'tbl_master_facility.name as facility', + 'tbl_partner.name as partner', + 'tbl_client.locator_county', + 'tbl_client.locator_sub_county', + 'tbl_client.locator_ward', + 'tbl_client.locator_village', + 'tbl_client.locator_location', + 'tbl_client.upi_no' + ) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->paginate(1000); + } + } else { } return view('new_reports.clients', compact('clients', 'gender', 'marital', 'clinics', 'time', 'treatment', 'language', 'grouping', 'county')); @@ -300,74 +297,144 @@ public function appointment_list() } public function active_facility() { - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') - ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') - ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - } - if (Auth::user()->access_level == 'Partner') { - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') - ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') - ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - } - if (Auth::user()->access_level == 'Sub County') { - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') - ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') - ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) - ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - } - if (Auth::user()->access_level == 'County') { - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') - ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') - ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) - ->where('tbl_partner_facility.county_id', Auth::user()->county_id) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - } - if (Auth::user()->access_level == 'Facility') { - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') - ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') - ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') - ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') - ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); + if (env('INSTANCE') === 'UshauriDOD') { + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + if (Auth::user()->access_level == 'Partner') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + if (Auth::user()->access_level == 'Sub County') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + if (Auth::user()->access_level == 'County') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + if (Auth::user()->access_level == 'Facility') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + } else { + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + if (Auth::user()->access_level == 'Partner') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + if (Auth::user()->access_level == 'Sub County') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + if (Auth::user()->access_level == 'County') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } + if (Auth::user()->access_level == 'Facility') { + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->select('tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county', 'tbl_sub_county.name as subcounty') + ->whereDate('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)->toDateString()) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + } } return view('new_reports.active_facilities', compact('active_facilities')); diff --git a/config/UshauriDOD/database.php b/config/UshauriDOD/database.php new file mode 100644 index 0000000..7ea2ee9 --- /dev/null +++ b/config/UshauriDOD/database.php @@ -0,0 +1,29 @@ + env('DB_CONNECTION', 'mysql'), + + 'connections' => [ + + 'mysql' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', 'dod_db_host'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'dod_db_name'), + 'username' => env('DB_USERNAME', 'dod_db_user'), + 'password' => env('DB_PASSWORD', 'dod_db_password'), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'strict' => true, + 'engine' => null, + ], + + // Other database connections... + + ], + + // ... + +]; diff --git a/config/UshauriPublic/database.php b/config/UshauriPublic/database.php new file mode 100644 index 0000000..9d02098 --- /dev/null +++ b/config/UshauriPublic/database.php @@ -0,0 +1,29 @@ + env('DB_CONNECTION', 'mysql'), + + 'connections' => [ + + 'mysql' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', 'public_db_host'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'public_db_name'), + 'username' => env('DB_USERNAME', 'public_db_user'), + 'password' => env('DB_PASSWORD', 'public_db_password'), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'strict' => true, + 'engine' => null, + ], + + // Other database connections... + + ], + + // ... + +]; diff --git a/config/app.php b/config/app.php index 652374d..0b3350d 100644 --- a/config/app.php +++ b/config/app.php @@ -236,4 +236,19 @@ ], + 'config' => [ + 'app' => env('INSTANCE') . '/app.php', + 'auth' => env('INSTANCE') . '/auth.php', + 'broadcasting' => env('INSTANCE') . '/broadcasting.php', + 'cache' => env('INSTANCE') . '/cache.php', + 'database' => env('INSTANCE') . '/database.php', + 'filesystems' => env('INSTANCE') . '/filesystems.php', + 'mail' => env('INSTANCE') . '/mail.php', + 'queue' => env('INSTANCE') . '/queue.php', + 'services' => env('INSTANCE') . '/services.php', + 'session' => env('INSTANCE') . '/session.php', + 'view' => env('INSTANCE') . '/view.php', + ], + + ]; \ No newline at end of file diff --git a/public/assets/images/DOD_Logo.png b/public/assets/images/DOD_Logo.png new file mode 100644 index 0000000..b11f4be Binary files /dev/null and b/public/assets/images/DOD_Logo.png differ diff --git a/resources/views/appointments/appointments_list.blade.php b/resources/views/appointments/appointments_list.blade.php index 030f14a..914f150 100644 --- a/resources/views/appointments/appointments_list.blade.php +++ b/resources/views/appointments/appointments_list.blade.php @@ -25,8 +25,13 @@ No. + @if (env('INSTANCE') === 'UshauriDOD') + KDOD Number + Service No + @else Clinic Number Serial No + @endif First Name Middle Name Last Name diff --git a/resources/views/appointments/future_appointments.blade.php b/resources/views/appointments/future_appointments.blade.php index 25a85af..d9de534 100644 --- a/resources/views/appointments/future_appointments.blade.php +++ b/resources/views/appointments/future_appointments.blade.php @@ -25,9 +25,14 @@ No. + @if (env('INSTANCE') === 'UshauriDOD') + KDOD Number + Service No + @else Clinic Number - UPI Number Serial No + @endif + UPI Number First Name Middle Name Last Name @@ -43,8 +48,8 @@ {{ $loop->iteration }} {{$result->clinic_number}} - {{$result->upi_no}} {{$result->file_no}} + {{$result->upi_no}} {{$result->f_name}} {{$result->m_name}} {{$result->l_name}} diff --git a/resources/views/appointments/future_apps_edit.blade.php b/resources/views/appointments/future_apps_edit.blade.php index 2e00b2d..6278fe2 100644 --- a/resources/views/appointments/future_apps_edit.blade.php +++ b/resources/views/appointments/future_apps_edit.blade.php @@ -25,7 +25,11 @@ No. + @if (env('INSTANCE') === 'UshauriDOD') + KDOD Number + @else Clinic Number + @endif UPI Number Appointment Date Appointment Type diff --git a/resources/views/clients/client_profile.blade.php b/resources/views/clients/client_profile.blade.php index 0700114..b10a499 100644 --- a/resources/views/clients/client_profile.blade.php +++ b/resources/views/clients/client_profile.blade.php @@ -47,7 +47,11 @@