mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 03:01:32 +00:00
1279 lines
60 KiB
PHP
Executable File
1279 lines
60 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Insurance\Http\Controllers;
|
|
|
|
use Barryvdh\Snappy\Facades\SnappyPdf;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Streamline\Models\ChartOfAccount;
|
|
use Streamline\Models\District;
|
|
use Streamline\Models\FamilyRelationship;
|
|
use Streamline\Models\HeadOfFamily;
|
|
use Streamline\Models\HospitalInformation;
|
|
use Streamline\Models\InsuranceGroup;
|
|
use Streamline\Models\InsuranceMember;
|
|
use Streamline\Models\InsurancePremiums;
|
|
use Streamline\Models\InsuranceSubscription;
|
|
use Streamline\Models\MaritalStatus;
|
|
use Streamline\Models\Occupation;
|
|
use Streamline\Models\PatientCategory;
|
|
use Streamline\Models\Religion;
|
|
use Streamline\Models\SingleGroupPremium;
|
|
use Streamline\Models\TrackReceipt;
|
|
use Streamline\Models\Patient;
|
|
|
|
class InsurancePremiumsController extends Controller
|
|
{
|
|
|
|
function __construct()
|
|
{
|
|
$this->middleware('permission:premium-create', ['only' => ['create', 'store']]);
|
|
$this->middleware('permission:premium-receipt-list', ['only' => ['insurance_receipts']]);
|
|
$this->middleware('permission:premium-renew', ['only' => ['renew_premium', 'renew_premium_store']]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$insurance_groups = InsuranceGroup::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
$insurance_groups = ['' => '- select -'] + $insurance_groups;
|
|
|
|
$families = HeadOfFamily::orderBy('name', 'asc')->pluck('id')->toArray();
|
|
$relations = FamilyRelationship::whereNotIn('id',[1])->orderBy('id', 'asc')->pluck('name', 'id')->toArray();
|
|
$relations = ['' => '- select -'] + $relations;
|
|
|
|
$occupations = Occupation::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$patient_categories = PatientCategory::where('available', 1)->orderby('name')->pluck('name', 'id')->toArray();
|
|
$districts = District::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$marital_statuses = MaritalStatus::pluck('name', 'id')->toArray();
|
|
$religions = Religion::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$relationships = FamilyRelationship::orderBy('name')->pluck('name', 'id')->toArray();
|
|
|
|
$occupations = ['' => '- select -'] + $occupations;
|
|
$districts = ['' => '- select -'] + $districts;
|
|
$religions = ['' => '- select -'] + $religions;
|
|
$relationships = ['' => '- select -'] + $relationships;
|
|
$hospital_information = HospitalInformation::first();
|
|
$dynamic_counties = DB::table('counties')->pluck('name','id')->prepend('- Select County - ', '');
|
|
$dynamic_sub_counties = DB::table('subcounties')->pluck('name','id')->prepend('- Select Sub County - ', '');
|
|
$dynamic_parishes = DB::table('parishes')->pluck('name','id')->prepend('- Select Parish - ', '');
|
|
$villages = DB::table('villages')->pluck('name', 'id')->prepend('- Select Village - ', '');
|
|
|
|
return view('insurance::insurance_premiums.create', compact('insurance_groups', 'families', 'relations', 'dynamic_counties', 'dynamic_parishes', 'dynamic_sub_counties', 'relationships', 'religions', 'occupations', 'districts', 'marital_statuses', 'patient_categories', 'hospital_information', 'villages'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
request()->validate([
|
|
'group_id' => 'required',
|
|
'amount' => 'required',
|
|
'start_date' => 'required',
|
|
'end_date' => 'required',
|
|
'payment_date' => 'required'
|
|
]);
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
// retrieve submitted records
|
|
$group_id = $request->group_id;
|
|
$amount = $request->amount;
|
|
|
|
//get the exact members covered details
|
|
$family_heads = $request->family_id;
|
|
$family_amount = $request->family_amount;
|
|
$insurance_subscription_id = $request->insurance_id;
|
|
$members_ids_array = $request->members_id;
|
|
$members_premiums_array = $request->members_amount;
|
|
|
|
$start_date = Carbon::createFromFormat('d-m-Y', $request->start_date)->toDateString();
|
|
$end_date = Carbon::createFromFormat('d-m-Y', $request->end_date)->toDateString();
|
|
$payment_date = Carbon::createFromFormat('d-m-Y', $request->payment_date)->toDateString();
|
|
|
|
// update the track_receipt table to include created receipt
|
|
$track_receipts = new TrackReceipt;
|
|
$track_receipts->created_by = Auth::id();
|
|
$track_receipts->reason = 'Premiums';
|
|
$track_receipts->save();
|
|
$receipt_number = sprintf("%04u", $track_receipts->id);
|
|
|
|
// check if the group already has a subscriptions record
|
|
if ($insurance_subscription_id) {
|
|
//update the record in the insurance_subscriptions table
|
|
$premium = InsurancePremiums::find($insurance_subscription_id);
|
|
//$premium->group_id = $group_id;
|
|
//$premium->start_date = $start_date;
|
|
//$premium->end_date = $end_date;
|
|
//$premium->payment_date = $payment_date;
|
|
|
|
$already_stored_family_ids = explode(",", $premium->family_heads);
|
|
$already_stored_family_amounts = explode(",", $premium->family_amount);
|
|
$already_stored_family = array_combine($already_stored_family_ids, $already_stored_family_amounts);
|
|
$already_stored_members_ids = explode(",", $premium->covered_member_ids);
|
|
$already_stored_premium = explode(",", $premium->covered_member_premiums_paid);
|
|
$already_stored_members = array_combine($already_stored_members_ids, $already_stored_premium);
|
|
$current_amount = $premium->amount;
|
|
|
|
// check if patients are already there
|
|
for ($i = 0; $i < count($members_ids_array); $i++) {
|
|
if (!isset($already_stored_members[$members_ids_array[$i]])) {
|
|
$already_stored_members[$members_ids_array[$i]] = $members_premiums_array[$i];
|
|
$current_amount += $members_premiums_array[$i];
|
|
|
|
// get current family
|
|
$family_id = get_name($members_ids_array[$i], 'id', 'family_id', 'insurance_members');
|
|
|
|
if (is_integer($family_id)) {
|
|
$already_stored_family[$family_id] = ($already_stored_family[$family_id] ?? 0) + $members_premiums_array[$i];
|
|
}
|
|
}
|
|
}
|
|
|
|
$premium->family_heads = implode(",", array_keys($already_stored_family));
|
|
$premium->family_amount = implode(",", array_values($already_stored_family));
|
|
$premium->amount = $current_amount;
|
|
$premium->covered_member_ids = implode(",", array_keys($already_stored_members));
|
|
$premium->covered_member_premiums_paid = implode(",", array_values($already_stored_members));
|
|
$premium->updated_by = $logged_in_user_id;
|
|
$premium->save();
|
|
} else {
|
|
//create new record in the insurance_subscriptions table
|
|
$premium = new InsurancePremiums;
|
|
$premium->group_id = $group_id;
|
|
$premium->amount = $amount;
|
|
$premium->family_heads = implode(",", $family_heads);
|
|
$premium->family_amount = implode(",", $family_amount);
|
|
$premium->covered_member_ids = implode(",", $members_ids_array);
|
|
$premium->covered_member_premiums_paid = implode(",", $members_premiums_array);
|
|
$premium->start_date = $start_date;
|
|
$premium->end_date = $end_date;
|
|
$premium->payment_date = $payment_date;
|
|
$premium->receipt_number = $receipt_number;
|
|
$premium->created_by = $logged_in_user_id;
|
|
$premium->save();
|
|
}
|
|
|
|
// run through and update the status for the added members
|
|
for($i = 0; $i < count($members_ids_array); $i++) {
|
|
$insurance_member = InsuranceMember::find($members_ids_array[$i]);
|
|
|
|
if ($insurance_member) {
|
|
$insurance_member->current_insurance_end_date = $end_date;
|
|
$insurance_member->current_insurance_amount_paid = $members_premiums_array[$i] ?? 0;
|
|
$insurance_member->save();
|
|
}
|
|
}
|
|
|
|
//prepare the receipt
|
|
$result = DB::table('insurance_groups')->where('id', $group_id)->first();
|
|
if ($result) {
|
|
$group_name = $result->name;
|
|
$contact_name = $result->contact_name;
|
|
} else {
|
|
$group_name = "";
|
|
$contact_name = "";
|
|
}
|
|
|
|
// prep for the receipt
|
|
$hospital_information = HospitalInformation::first();
|
|
$receipt_date = $payment_date;
|
|
|
|
return view('insurance::insurance_premiums.print_receipt_group', compact('hospital_information', 'receipt_number', 'receipt_date', 'start_date', 'end_date', 'group_name', 'contact_name', 'amount'));
|
|
}
|
|
|
|
public function print_group_receipt($subscription_id) {
|
|
$subscription = DB::table('insurance_subscriptions')
|
|
->where(['id' => $subscription_id])->first();
|
|
|
|
$hospital_information = HospitalInformation::first();
|
|
$receipt_date = $subscription->payment_date;
|
|
$start_date = $subscription->start_date;
|
|
$receipt_number = $subscription->receipt_number;
|
|
$end_date = $subscription->end_date;
|
|
$amount = $subscription->amount;
|
|
|
|
$result = DB::table('insurance_groups')->where('id', $subscription->group_id)->first();
|
|
if ($result) {
|
|
$group_name = $result->name;
|
|
$contact_name = $result->contact_name;
|
|
} else {
|
|
$group_name = "";
|
|
$contact_name = "";
|
|
}
|
|
|
|
return view('insurance::insurance_premiums.print_receipt_group', compact('hospital_information', 'receipt_number', 'receipt_date', 'start_date', 'end_date', 'group_name', 'contact_name', 'amount'));
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function group_details($id) {
|
|
//code to be returned to view
|
|
$code = '<h4>Families</h4>';
|
|
$today = date('Y-m-d');
|
|
$heads = HeadOfFamily::where(['group_id' => $id])->get();
|
|
|
|
$relations = DB::table('family_relations')->whereNull('deleted_at')->pluck('name', 'id');
|
|
|
|
$subscriptions = DB::table('insurance_subscriptions')
|
|
->where(['group_id' => $id])
|
|
->where('end_date', '>', DATE($today))
|
|
->orderBy('id', 'desc')
|
|
->first();
|
|
|
|
//check if families exist in this group
|
|
if ($heads->count() > 0) {
|
|
//check if a subscription has already been made to avoid duplication
|
|
if ($subscriptions) {
|
|
$code .= '<input type="hidden" value="' . $subscriptions->id . '" name="insurance_id"/>';
|
|
}
|
|
|
|
foreach ($heads as $head) {
|
|
$members_count = 0;
|
|
|
|
$this_family_members_id_array = is_null($head->family_members_ids) ? [] : explode(",", $head->family_members_ids);
|
|
|
|
$family_premiums_to_pay = 0;
|
|
$families_code = '<table class="table success-table table-sm families_table" id="family_' . $head->id . '" style="display: none"><thead>';
|
|
$families_code .= '<tr><th><b>Name</b></th><th><b>Premium</b></th><th><b>Relation to head</b></th><th></th></tr></thead><tbody>';
|
|
|
|
foreach ($this_family_members_id_array as $this_fam_member_id) {
|
|
$member = InsuranceMember::find($this_fam_member_id);
|
|
|
|
//check if families exist in this group
|
|
if ($member) {
|
|
$families_code .= '<tr id="member_' . $member->id . '">';
|
|
$families_code .= '<td>';
|
|
$families_code .= insurance_flag($member->patient_id).' ('.get_name($member->patient_id, "id", "number", "patients").')';
|
|
$families_code .= ($member->is_family_head == 1) ? ' <span style="color: #7b6dc7; font-weight: bolder"><strong>Family Head</strong></span>' : '';
|
|
$families_code .= '</td>';
|
|
$families_code .= '<td>' . ugandan_shillings($member->premium) . '</td>';
|
|
$families_code .= '<input type="hidden" name="members_id[]" value="' . $member->id . '"/>';
|
|
$families_code .= '<input type="hidden" name="members_amount[]" class="family_member_amount_' . $head->id . '" value="' . $member->premium . '"/>';
|
|
$families_code .= '<td>' . ($relations[$member->relationship_to_head] ?? '') . '</td>';
|
|
$families_code .= '<td><a href="#" onclick="exclude_member(\'' . $member->id . '\', \'' . $head->id . '\')" style="color: #bf5656">Exclude member</a></td>';
|
|
$families_code .= '</tr>';
|
|
$family_premiums_to_pay += $member->premium;
|
|
}
|
|
$members_count++;
|
|
}
|
|
|
|
$families_code .= '<tbody></table>';
|
|
|
|
$code .= '<div id="family_details_div_' . $head->id . '">';
|
|
$code .= '<div class="form-group">';
|
|
$code .= '<input type="hidden" name="family_id[]" value="' . $head->id . '"/>';
|
|
$code .= '<label for="family_amount[]">' . $head->name . ' (' . $members_count . ') <a href="#" onclick="get_family_details('.$head->id.')">View members</a> <a href="#" onclick="exclude_family(\'' . $head->id . '\')"><font style="color: maroon">Exclude Family</font></a> </label>';
|
|
$code .= '<input class="form-control compulsory family_amount" name="family_amount[]" type="number" value="'.$family_premiums_to_pay.'" id="family_amount_'.$head->id.'" readonly>';
|
|
$code .= '<div class="help-block with-errors"></div>';
|
|
$code .= '</div>';
|
|
$code .= $families_code;
|
|
$code .= '</div>';
|
|
}
|
|
} else {
|
|
$code .= '<span style="color: red">No Families Found in This Insurance Group</span>';
|
|
}
|
|
|
|
return $code;
|
|
}
|
|
|
|
public function insurance_receipts(Request $request) {
|
|
$today = date('Y-m-d');
|
|
|
|
if ($request->id) {
|
|
//group id is set
|
|
$id = $request->id;
|
|
|
|
$receipts = DB::table('insurance_subscriptions')
|
|
->where(['group_id' => $id])
|
|
->where('end_date', '>', DATE($today))
|
|
->get();
|
|
} else {
|
|
//group id not set hence default
|
|
$receipts = DB::table('insurance_subscriptions')->take(10)
|
|
->where('end_date', '>', DATE($today))
|
|
->get();
|
|
}
|
|
|
|
$insurance_groups = DB::table('insurance_groups')->pluck('name', 'id')->toArray();
|
|
|
|
$insurance_groups = ['' => '- select -'] + $insurance_groups;
|
|
|
|
return view('insurance::insurance_premiums.insurance_receipts', compact('insurance_groups', 'receipts'));
|
|
}
|
|
|
|
public function print_receipt(Request $request)
|
|
{
|
|
$group_id = $request->group_id;
|
|
$family_id = $request->family_id;
|
|
|
|
$group_name = InsuranceGroup::where('id', $group_id)->value('name');
|
|
$family_name = HeadOfFamily::where('id', $family_id)->value('name');
|
|
|
|
$amount = $request->family_amount;
|
|
$start_date = $request->start_date;
|
|
$end_date = $request->end_date;
|
|
|
|
$subscription_record = InsurancePremiums::find($request->subscription_id);
|
|
$record_members_array = is_null($subscription_record->covered_member_ids) ? [] : explode(",",$subscription_record->covered_member_ids);
|
|
$record_premiums_array = is_null($subscription_record->covered_member_premiums_paid) ? [] : explode(",",$subscription_record->covered_member_premiums_paid);
|
|
|
|
$this_family_members_array = InsuranceMember::where('family_id', $family_id)->pluck('id')->toArray();
|
|
$covered_family_members = 0;
|
|
for ($w=0; $w < count($record_members_array) ; $w++) {
|
|
if (in_array($record_members_array[$w], $this_family_members_array)) {
|
|
$covered_family_members++;
|
|
}
|
|
}
|
|
|
|
$hospital_information = HospitalInformation::first();
|
|
$receipt_date = $request->payment_date;
|
|
$receipt_number = $request->receipt_number;
|
|
|
|
return view('insurance::insurance_premiums.print_receipt', compact('hospital_information', 'receipt_date', 'receipt_number', 'start_date', 'end_date', 'amount', 'group_name', 'family_name', 'family_id', 'group_id', 'covered_family_members', 'subscription_record'));
|
|
}
|
|
|
|
public function single_group_receipt()
|
|
{
|
|
$insurance_groups = InsuranceGroup::pluck('name', 'id')->toArray();
|
|
|
|
$insurance_groups = ['' => '- select -'] + $insurance_groups;
|
|
|
|
return view('insurance::insurance_premiums.single_group_receipt', compact('insurance_groups'));
|
|
}
|
|
|
|
public function single_group_receipt_store(Request $request) {
|
|
// update the track_receipt table to include created receipt
|
|
$track_receipts = new TrackReceipt;
|
|
$track_receipts->created_by = Auth::id();
|
|
$track_receipts->reason = 'Single Group Receipts';
|
|
$track_receipts->save();
|
|
$receipt_number = sprintf("%04u", $track_receipts->id);
|
|
|
|
//create new record in the single group premiums table
|
|
$premium = new SingleGroupPremium;
|
|
|
|
$premium->group_id = $request->group_id;
|
|
$premium->amount = $request->amount;
|
|
$premium->paid_by_name = $request->paid_by_name;
|
|
$premium->paid_by_contact = $request->paid_by_contact;
|
|
$start_date = Carbon::createFromFormat('d-m-Y', $request->start_date)->toDateString();
|
|
$end_date = Carbon::createFromFormat('d-m-Y', $request->end_date)->toDateString();
|
|
$payment_date = Carbon::createFromFormat('d-m-Y', $request->payment_date)->toDateString();
|
|
$premium->start_date = $start_date;
|
|
$premium->end_date = $end_date;
|
|
$premium->payment_date = $payment_date;
|
|
$premium->receipt_number = $receipt_number;
|
|
$premium->created_by = Auth::user()->id;
|
|
$premium->save();
|
|
|
|
// prep for the receipt
|
|
$hospital_information = HospitalInformation::first();
|
|
$receipt_date = $request->payment_date;
|
|
|
|
$group_name = InsuranceGroup::where('id', $request->group_id)->value('name');
|
|
|
|
$amount = $request->amount;
|
|
$paid_by_name = $request->paid_by_name;
|
|
$paid_by_contact = $request->paid_by_contact;
|
|
$start_date = $request->start_date;
|
|
$end_date = $request->end_date;
|
|
$group_id = $request->group_id;
|
|
$cashier_id = $premium->created_by;
|
|
|
|
return view('insurance::insurance_premiums.print_receipt_single_group', compact('hospital_information', 'receipt_number', 'receipt_date', 'start_date', 'end_date', 'paid_by_name', 'paid_by_contact', 'amount', 'group_name', 'group_id', 'cashier_id'));
|
|
}
|
|
|
|
public function single_group_receipt_history(Request $request) {
|
|
if($request->start_date){
|
|
$start = Carbon::createFromFormat('d/m/Y', $request->start_date)->toDateString();
|
|
$end = Carbon::createFromFormat('d/m/Y', $request->end_date)->toDateString();
|
|
} else {
|
|
$start = Carbon::now()->startOfDay()->toDateTimeString();
|
|
$end = Carbon::now()->endOfDay()->toDateTimeString();
|
|
}
|
|
|
|
$insurance_groups = DB::table('insurance_groups')->pluck('name', 'id')->toArray();
|
|
$insurance_groups = ['' => '- select -'] + $insurance_groups;
|
|
|
|
$search_text = "Searching between " . streamline_date($start) . " and " . streamline_date($end);
|
|
|
|
$start = date("Y-m-d", strtotime($start));
|
|
$end = date("Y-m-d", strtotime($end));
|
|
|
|
if ($request->group_id) {
|
|
$receipts = SingleGroupPremium::where(['group_id' => $request->group_id])
|
|
->whereBetween('payment_date', [$start, $end])->get();
|
|
|
|
$search_text .= " for " . ($insurance_groups[$request->group_id] ?? 'N/A');
|
|
} else {
|
|
$receipts = SingleGroupPremium::whereBetween('payment_date', [$start, $end])->get();
|
|
}
|
|
|
|
return view('insurance::insurance_premiums.single_group_receipt_history', compact('insurance_groups', 'receipts', 'search_text'));
|
|
}
|
|
|
|
public function reprint_single_group_receipt($id)
|
|
{
|
|
$receipt = SingleGroupPremium::where(['id' => $id])->first();
|
|
|
|
$hospital_information = HospitalInformation::first();
|
|
|
|
return view('insurance::insurance_premiums.reprint_single_group_receipt', compact('hospital_information', 'receipt'));
|
|
}
|
|
|
|
public function renew_premium()
|
|
{
|
|
$today = Carbon::now();
|
|
|
|
$exluded_insurance_groups = InsurancePremiums::where('end_date', '>', DATE($today))->pluck('group_id')->toArray();
|
|
|
|
$insurance_groups = InsuranceGroup::whereNotIn('id', $exluded_insurance_groups)->pluck('name', 'id')->toArray();
|
|
|
|
$insurance_groups = ['' => '- select -'] + $insurance_groups;
|
|
|
|
$families = HeadOfFamily::orderBy('name', 'asc')->pluck('id')->toArray();
|
|
$relations = FamilyRelationship::whereNotIn('id',[1])->orderBy('id', 'asc')->pluck('name', 'id')->toArray();
|
|
$relations = ['' => '- select -'] + $relations;
|
|
|
|
$occupations = Occupation::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$patient_categories = PatientCategory::where('available', 1)->orderby('name')->pluck('name', 'id')->toArray();
|
|
$districts = District::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$marital_statuses = MaritalStatus::pluck('name', 'id')->toArray();
|
|
$religions = Religion::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$relationships = FamilyRelationship::orderBy('name')->pluck('name', 'id')->toArray();
|
|
|
|
$occupations = ['' => '- select -'] + $occupations;
|
|
$districts = ['' => '- select -'] + $districts;
|
|
$religions = ['' => '- select -'] + $religions;
|
|
$relationships = ['' => '- select -'] + $relationships;
|
|
$hospital_information = HospitalInformation::first();
|
|
$dynamic_counties = DB::table('counties')->pluck('name','id')->prepend('- Select County - ', '');
|
|
$dynamic_sub_counties = DB::table('subcounties')->pluck('name','id')->prepend('- Select Sub County - ', '');
|
|
$dynamic_parishes = DB::table('parishes')->pluck('name','id')->prepend('- Select Parish - ', '');
|
|
$villages = DB::table('villages')->pluck('name', 'id')->prepend('- Select Village - ', '');
|
|
|
|
return view('insurance::insurance_premiums.renew_premium', compact('insurance_groups', 'relations', 'dynamic_counties', 'dynamic_parishes', 'dynamic_sub_counties', 'relationships', 'religions', 'occupations', 'districts', 'marital_statuses', 'patient_categories', 'hospital_information', 'villages'));
|
|
}
|
|
|
|
public function renew_premium_store(Request $request)
|
|
{
|
|
request()->validate([
|
|
'group_id' => 'required',
|
|
'amount' => 'required',
|
|
'start_date' => 'required',
|
|
'end_date' => 'required',
|
|
'payment_date' => 'required'
|
|
]);
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
|
|
// retrieve submitted records
|
|
$group_id = $request->group_id;
|
|
$amount = $request->amount;
|
|
$start_date = Carbon::createFromFormat('d-m-Y', $request->start_date)->toDateString();
|
|
$end_date = Carbon::createFromFormat('d-m-Y', $request->end_date)->toDateString();
|
|
$payment_date = Carbon::createFromFormat('d-m-Y', $request->payment_date)->toDateString();
|
|
$family_heads_array = $request->family_id;
|
|
$family_amount_array = $request->family_amount;
|
|
|
|
//update insurance income in chart of accounts
|
|
$insurance_income = DB::table('chart_of_accounts')->where('id', 2)->value('balance');
|
|
$new_insurance_income = $insurance_income + $amount;
|
|
ChartOfAccount::where(['id' => 2])->update(['balance' => $new_insurance_income]);
|
|
|
|
//convert family_amount and family_id to strings
|
|
$family_amount_string = implode(",", $family_amount_array);
|
|
$family_heads_string = implode(",", $family_heads_array);
|
|
|
|
$members_ids_array = $members_premiums_array = [];
|
|
|
|
for ($i=0; $i < count($family_heads_array); $i++) {
|
|
$heads_of_family_record = HeadOfFamily::withTrashed()->find($family_heads_array[$i]);
|
|
$split_members_ids_array = explode(",", $heads_of_family_record->family_members_ids);
|
|
|
|
for ($j=0; $j <count($split_members_ids_array) ; $j++) {
|
|
$members_ids_array[] = $split_members_ids_array[$j];
|
|
$members_premiums_array[] = get_name($split_members_ids_array[$j], "id", "premium", "insurance_members");
|
|
}
|
|
}
|
|
|
|
// update the track_receipt table to include created receipt
|
|
$track_receipts = new TrackReceipt;
|
|
$track_receipts->created_by = Auth::id();
|
|
$track_receipts->reason = 'Renew Premiums';
|
|
$track_receipts->save();
|
|
$receipt_number = sprintf("%04u", $track_receipts->id);
|
|
|
|
//create new record in the insurance_subscriptions table
|
|
$premium = new InsurancePremiums;
|
|
|
|
$premium->group_id = $group_id;
|
|
$premium->amount = $amount;
|
|
$premium->family_heads = $family_heads_string;
|
|
$premium->family_amount = $family_amount_string;
|
|
$premium->covered_member_ids = implode(",", $members_ids_array);
|
|
$premium->covered_member_premiums_paid = implode(",", $members_premiums_array);
|
|
$premium->start_date = $start_date;
|
|
$premium->end_date = $end_date;
|
|
$premium->payment_date = $payment_date;
|
|
$premium->receipt_number = $receipt_number;
|
|
$premium->created_by = $logged_in_user_id;
|
|
$premium->save();
|
|
|
|
//prepare the receipt
|
|
$result = DB::table('insurance_groups')->where('id', $group_id)->first();
|
|
|
|
$group_name = $result->name;
|
|
$contact_name = $result->contact_name;
|
|
|
|
// prep for the receipt
|
|
$hospital_information = HospitalInformation::first();
|
|
$receipt_date = $payment_date;
|
|
|
|
return view('insurance::insurance_premiums.print_receipt_group', compact('hospital_information', 'receipt_number', 'receipt_date', 'start_date', 'end_date', 'group_name', 'contact_name', 'amount'));
|
|
}
|
|
|
|
public function insurance_premiums_receipt_snappy($serialized_data)
|
|
{
|
|
$print_array = unserialize($serialized_data);
|
|
$start_date = $end_date = $amount = $group_name = $contact_name = null;
|
|
//$print_array = [$start_date, $end_date, $amount, $group_name, $contact_name];
|
|
if (is_array($print_array)) {
|
|
$start_date = $print_array[0];
|
|
$end_date = $print_array[1];
|
|
$amount = $print_array[2];
|
|
$group_name = $print_array[3];
|
|
$contact_name = $print_array[4];
|
|
$receipt_date = $print_array[5];
|
|
$receipt_number = $print_array[6];
|
|
}
|
|
|
|
$hospital_details = HospitalInformation::first();
|
|
|
|
$data = [
|
|
'hospitalInfo' => $hospital_details,
|
|
'start_date' => $start_date,
|
|
'end_date' => $end_date,
|
|
'amount' => $amount,
|
|
'group_name' => $group_name,
|
|
'contact_name' => $contact_name,
|
|
'receipt_date' => $receipt_date,
|
|
'receipt_number' => $receipt_number
|
|
];
|
|
|
|
$pdf = SnappyPDF::loadView('insurance::insurance_premiums/snappy_print_receipt_group', $data)
|
|
->setOrientation('portrait')
|
|
->setOption('margin-bottom', 7)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>Stre@mline</i>');
|
|
|
|
|
|
return $pdf->inline('Premiums Receipt' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
public function insurance_premiums_family_receipt_snappy($serialized_data)
|
|
{
|
|
try {
|
|
$print_array = unserialize($serialized_data);
|
|
|
|
if (!is_array($print_array)) {
|
|
$print_array = [];
|
|
}
|
|
} catch (\Exception | \Error $e) {
|
|
$print_array = [];
|
|
}
|
|
|
|
$start_date = $print_array[0] ?? now();
|
|
$end_date = $print_array[1] ?? now();
|
|
$amount = $print_array[2] ?? 0;
|
|
$group_name = $print_array[3] ?? "";
|
|
$family_name = $print_array[4] ?? "";
|
|
$receipt_date = $print_array[5] ?? "";
|
|
$receipt_number = $print_array[6] ?? "";
|
|
$family_id = $print_array[7] ?? "";
|
|
$group_id = $print_array[8] ?? "";
|
|
$insurance_subscription_id = $print_array[9] ?? "";
|
|
$cashier = $print_array[10] ?? "";
|
|
|
|
$hospital_details = HospitalInformation::first();
|
|
|
|
$receiver_cashier_id = 0;
|
|
$covered_family_members = [];
|
|
$subscription_record = InsuranceSubscription::find($insurance_subscription_id);
|
|
if ($subscription_record) {
|
|
$receiver_cashier_id = $subscription_record->created_by;
|
|
|
|
$record_members_array = is_null($subscription_record->covered_member_ids) ? [] : explode(",",$subscription_record->covered_member_ids);
|
|
|
|
$this_family_members_array = InsuranceMember::where('family_id', $family_id)->pluck('id')->toArray();
|
|
|
|
for ($w=0; $w < count($record_members_array) ; $w++) {
|
|
if (in_array($record_members_array[$w], $this_family_members_array)) {
|
|
$covered_family_members[] = $record_members_array[$w];
|
|
}
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'hospitalInfo' => $hospital_details,
|
|
'start_date' => $start_date,
|
|
'end_date' => $end_date,
|
|
'amount' => $amount,
|
|
'group_name' => $group_name,
|
|
'family_name' => $family_name,
|
|
'receipt_date' => $receipt_date,
|
|
'receipt_number' => $receipt_number,
|
|
'family_id' => $family_id,
|
|
'receiver_cashier_id' => $receiver_cashier_id,
|
|
'covered_family_members' => $covered_family_members,
|
|
'cashier' => $cashier,
|
|
];
|
|
|
|
$pdf = SnappyPDF::loadView('insurance::insurance_premiums/snappy_print_receipt_family', $data)
|
|
->setOrientation('portrait')
|
|
->setOption('margin-bottom', 7)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>Stre@mline</i>');
|
|
|
|
|
|
return $pdf->inline('Premiums Receipt' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
public function print_single_group_receipt_snappy($serialized_data)
|
|
{
|
|
$hospital_details = HospitalInformation::first();
|
|
|
|
$print_array = unserialize($serialized_data);
|
|
$start_date = $end_date = $amount = $group_name = $group_name = $group_id = $paid_by_name = $paid_by_contact = $cashier_id = null;
|
|
//$print_array = [$start_date, $end_date, $amount, $receipt_date, $receipt_number, $group_name, $group_id, $paid_by_name, $paid_by_contact];
|
|
if (is_array($print_array)) {
|
|
$start_date = $print_array[0];
|
|
$end_date = $print_array[1];
|
|
$amount = $print_array[2];
|
|
$receipt_date = $print_array[3];
|
|
$receipt_number = $print_array[4];
|
|
$group_name = $print_array[5];
|
|
$group_id = $print_array[6];
|
|
$paid_by_name = $print_array[7];
|
|
$paid_by_contact = $print_array[8];
|
|
$cashier_id = $print_array[9];
|
|
}
|
|
|
|
$data = [
|
|
'hospitalInfo' => $hospital_details,
|
|
'start_date' => $start_date,
|
|
'end_date' => $end_date,
|
|
'amount' => $amount,
|
|
'group_name' => $group_name,
|
|
'group_id' => $group_id,
|
|
'paid_by_name' => $paid_by_name,
|
|
'paid_by_contact' => $paid_by_contact,
|
|
'receipt_date' => $receipt_date,
|
|
'receipt_number' => $receipt_number,
|
|
'cashier_id' => $cashier_id
|
|
];
|
|
|
|
$pdf = SnappyPDF::loadView('insurance::insurance_premiums/snappy_print_single_group_receipt', $data)
|
|
->setOrientation('portrait')
|
|
->setOption('margin-bottom', 7);
|
|
|
|
|
|
return $pdf->inline('Premiums Receipt' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
|
|
public function view_chi_family_members($family_head_id) {
|
|
$code = '';
|
|
$i = 1;
|
|
$members = InsuranceMember::where(['family_id' => $family_head_id])->get();
|
|
|
|
$code .= '<table class="table success-table table-sm">';
|
|
$family_total_premiums_to_pay = 0;
|
|
$family_members_to_exclude_array = session()->has("member_ids_to_exclude") ? session()->get("member_ids_to_exclude") : [];
|
|
|
|
//check if families exist in this group
|
|
if ($members->count() > 0) {
|
|
$code .= '<tbody class="dynamicFamilyMembers">';
|
|
$code .= '<tr><th>#</th><th><b>Name</b></th><th><b>Premium</b></th><th><b>Relation to head</b></th><th></th></tr>';
|
|
|
|
//check if a subscription has already been made to avoid duplication
|
|
foreach ($members as $member) {
|
|
if (!in_array($member->id, $family_members_to_exclude_array)) {
|
|
$code .= '<tr><td>' . $i . '</td>';
|
|
$code .= '<td>';
|
|
$code .= insurance_flag($member->patient_id).' ('.get_name($member->patient_id, "id", "number", "patients").')';
|
|
$code .= ($member->is_family_head == 1) ? ' <span style="color: #7b6dc7; font-weight: bolder"><strong>Family Head</strong></span>' : '';
|
|
$code .= '</td>';
|
|
$code .= '<td>' . ugandan_shillings($member->premium) . '</td>';
|
|
$code .= '<td>';
|
|
$code .= get_name($member->relationship_to_head, "id", "name", "family_relations");
|
|
$code .= '</td>';
|
|
$code .= '<td><a href="/insurance_premiums/remove_member_from_family/'.$family_head_id.'/'.$member->id.'" onclick="return confirm(\'Are you sure?\')" style="color: #bf5656">Exclude member</a> <a href="/insurance_premiums/edit_family_head/'.$family_head_id.'/'.$member->id.'" onclick="return confirm(\'Are you sure you want to edit the head of this family?\')">Make family head</a></td>';
|
|
$code .= '</tr>';
|
|
$i++;
|
|
$family_total_premiums_to_pay += $member->premium;
|
|
}
|
|
}
|
|
$code .= '<tr><td colspan="2"><b>Total</b></td><td colspan="4"><b>'.ugandan_shillings($family_total_premiums_to_pay).'</b></td><tr>';
|
|
$code .= '<tbody>';
|
|
}
|
|
|
|
$code .= '</table>';
|
|
|
|
return $code;
|
|
}
|
|
|
|
public function remove_member_from_family($family_head_id, $member_id)
|
|
{
|
|
$insurance_member = InsuranceMember::where(['family_id' => $family_head_id, 'id' => $member_id])->orderBy('id', 'desc')->first();
|
|
$family_head_patient_id = get_name($family_head_id, "id", "patient_id", "insurance_heads_of_family");
|
|
|
|
if ($insurance_member) {
|
|
|
|
$this_family_members_to_exclude_array = session()->has("member_ids_to_exclude") ? session()->get("member_ids_to_exclude") : [];
|
|
array_push($this_family_members_to_exclude_array, $member_id);
|
|
|
|
session()->put(["member_ids_to_exclude" => $this_family_members_to_exclude_array]);
|
|
|
|
flash(get_full_name($insurance_member->patient_id, "id", "first_name", "last_name", "patients").' has been excluded from this premium payment for the family of '.get_full_name($family_head_patient_id, "id", "first_name", "last_name", "patients").' ')->success();
|
|
|
|
return redirect('edit_insurance_premiums_payment/'.$insurance_member->group_id);
|
|
} else{
|
|
flash('Family member could not be found')->error();
|
|
}
|
|
return redirect('insurance_premiums/create');
|
|
}
|
|
|
|
public function remove_chi_family_from_group($family_head_id, $group_id)
|
|
{
|
|
# 1. remove from the group
|
|
# 2. add to to a deleted_chi_families table for audit trails
|
|
# 3. soft delete from insurance_heads_of_family
|
|
|
|
$today = date('Y-m-d');
|
|
$family_head_patient_id = get_name($family_head_id, "id", "patient_id", "insurance_heads_of_family");
|
|
|
|
/* $subscriptions = DB::table('insurance_subscriptions')->whereNull('deleted_at')->where(['group_id' => $group_id])->where('end_date', '>', DATE($today))->orderBy('id', 'desc')->first();
|
|
|
|
if ($subscriptions) {
|
|
$family_heads_array = explode(",", $subscriptions->family_heads);
|
|
$family_amount_array = explode(",", $subscriptions->family_amount);
|
|
$family_amount_on_removal = 0;
|
|
//dd($family_heads_array);
|
|
|
|
for ($i=0; $i < count($family_heads_array) ; $i++) {
|
|
if ((int)$family_heads_array[$i] == (int)$family_head_id) {
|
|
$family_amount_on_removal = $family_amount_array[$i];
|
|
unset($family_heads_array[$i]);
|
|
unset($family_amount_array[$i]);
|
|
break;
|
|
}
|
|
}
|
|
$family_heads_timmed_array = array_values($family_heads_array);
|
|
$family_amounts_timmed_array = array_values($family_amount_array);
|
|
//dd($family_heads_timmed_array);
|
|
|
|
//update the insurance_subscriptions table;
|
|
$premium = InsurancePremiums::where(['group_id' => $group_id])->orderBy('id', 'desc')->first();
|
|
$premium->family_heads = implode(",", $family_heads_timmed_array);
|
|
$premium->family_amount = implode(",", $family_amounts_timmed_array);
|
|
|
|
if ($premium->save()) {
|
|
$remove_family = new RemovedChiFamily;
|
|
$remove_family->family_head_id = $family_head_id;
|
|
$remove_family->group_id = $group_id;
|
|
$remove_family->family_amount = $family_amount_on_removal;
|
|
$remove_family->created_by = Auth::id();
|
|
$remove_family->save();
|
|
|
|
$family_head = HeadOfFamily::withTrashed()->find($family_head_id);
|
|
if ($family_head) {
|
|
$family_head->delete();
|
|
}
|
|
}
|
|
|
|
flash('Family of '.get_full_name($family_head_patient_id, "id", "first_name", "last_name", "patients").' has been removed from '.get_name($group_id, "id", "name", "insurance_groups"))->success();
|
|
|
|
return redirect('edit_insurance_premiums_payment/'.$group_id);
|
|
}
|
|
|
|
flash('Family could not be removed')->error(); */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$insurance_members = InsuranceMember::where(['family_id' => $family_head_id])->orderBy('id', 'desc')->get();
|
|
|
|
$family_head_patient_id = get_name($family_head_id, "id", "patient_id", "insurance_heads_of_family");
|
|
|
|
//create the array of family ids to exclude and add it in the session
|
|
$family_ids_to_exclude_array = session()->has("family_ids_to_exclude") ? session()->get("family_ids_to_exclude") : [];
|
|
array_push($family_ids_to_exclude_array, $family_head_id);
|
|
session()->put(["family_ids_to_exclude" => $family_ids_to_exclude_array]);
|
|
|
|
$group_id = 0;
|
|
// loop through to create session of members to exclude
|
|
if (count($insurance_members) > 0) {
|
|
foreach ($insurance_members as $insurance_member) {
|
|
$this_family_members_to_exclude_array = session()->has("member_ids_to_exclude") ? session()->get("member_ids_to_exclude") : [];
|
|
array_push($this_family_members_to_exclude_array, $insurance_member->id);
|
|
|
|
session()->put(["member_ids_to_exclude" => $this_family_members_to_exclude_array]);
|
|
|
|
$group_id = $insurance_member->group_id;
|
|
}
|
|
|
|
flash('The family of '.get_full_name($family_head_patient_id, "id", "first_name", "last_name", "patients").' has been excluded from this group payment')->success();
|
|
|
|
return redirect('edit_insurance_premiums_payment/'.$group_id);
|
|
}
|
|
|
|
flash('Family member could not be found')->error();
|
|
return back()->withInput();
|
|
|
|
return redirect('insurance_premiums/create');
|
|
}
|
|
|
|
public function add_new_family_members_dynamically(Request $request)
|
|
{
|
|
//$request->new_member_contact;
|
|
$patient = new Patient;
|
|
$patient->first_name = $request->new_member_first_name;
|
|
$patient->last_name = $request->new_member_last_name;
|
|
if (is_null($request->new_member_date_of_birth)) {
|
|
$patient->date_of_birth = Carbon::now();
|
|
} else {
|
|
$patient->date_of_birth = Carbon::createFromFormat('d/m/Y', $request->new_member_date_of_birth)->toDateString();
|
|
}
|
|
$patient->marital_status = $request->new_member_marital_status;
|
|
$patient->occupation_id = $request->new_member_occupation;
|
|
$patient->religion_id = $request->new_member_religion;
|
|
$patient->category_id = $request->new_member_patient_category;
|
|
$patient->citizenship = 1;
|
|
$patient->district_id = $request->new_member_district_id;
|
|
$patient->county_id = $request->new_member_county_id;
|
|
$patient->country_id = 6; //uganda
|
|
$patient->subcounty_id = $request->new_member_subcounty_id;
|
|
$patient->insurance_status = 1;
|
|
$patient->parish_id = $request->new_member_parish;
|
|
$patient->village_id = $request->new_member_village;
|
|
$patient->gender = $request->new_member_gender;
|
|
$patient->next_of_kin = $request->new_member_next_of_kin;
|
|
//$patient->next_of_kin_relationship = $request->next_of_kin_relationship;
|
|
//$patient->phone_of_next_of_kin = removeSpaces($request->next_of_kin_phone);
|
|
$patient->phone = removeSpaces($request->new_member_phone);
|
|
$patient->national_id = $request->new_member_national_id;
|
|
$patient->phone_owner = $request->new_member_phone_owner; // problem
|
|
//$patient->hospital_contact = $request->hospital_contact;
|
|
$patient->language = $request->new_member_language;
|
|
$patient->lc_one = $request->new_member_lc_one;
|
|
$patient->created_by = Auth::user()->id;
|
|
|
|
if ($patient->save()){
|
|
$prefix = DB::table('hospital_information')->where('id', 1)->value('patient_number_abbr');
|
|
$new_id = quadLimit($patient->id);
|
|
$patient_number = $prefix . "-" . $new_id;
|
|
|
|
DB::table('patients')->where('id', $new_id)->update(['number' => $patient_number]); // Updating the patient number
|
|
|
|
flash('Patient with patient number ' . $patient_number . ' has been successfully registered')->success();
|
|
|
|
// add patient to insurance
|
|
$insurance_member = new InsuranceMember;
|
|
|
|
if ($request->hasFile('photo')){
|
|
$photo = $request->file('photo');
|
|
$photo_name = $request->patient_id . "." . $photo->getClientOriginalExtension();
|
|
$destinationPath = public_path('/uploads/insurance_members');
|
|
$photoPath = $destinationPath . "/" . $photo_name;
|
|
$photo->move($destinationPath, $photoPath);
|
|
$insurance_member->photo = $photo_name;
|
|
} else {
|
|
$insurance_member->photo = 'placeholder.png';
|
|
}
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
$insurance_member->family_id = $request->new_member_family_head_id;
|
|
$insurance_member->group_id = $request->group_id;
|
|
$insurance_member->relationship_to_head = $request->new_member_relationship_to_head;
|
|
$insurance_member->patient_id = $patient->id;
|
|
$insurance_member->is_family_head = 0;
|
|
$insurance_member->created_by = $logged_in_user_id;
|
|
$insurance_member->updated_by = $logged_in_user_id;
|
|
|
|
try {
|
|
$insurance_member->save();
|
|
$response_string = "";
|
|
$new_patient_name = $patient->first_name. " ".$patient->last_name;
|
|
flash("New Insurance Member ".$new_patient_name." has been saved")->success();
|
|
$response_string = "<tr><td></td><td>".$new_patient_name."</td><td></td></tr>";
|
|
return json_encode([
|
|
"html" => $response_string
|
|
]);
|
|
} catch (\Exception $e) {
|
|
flash("Failed to register patient. Please try again")->error();
|
|
return back()->withInput();
|
|
}
|
|
} else {
|
|
flash("Failed to register patient. Please try again")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
|
|
public function edit_family_head($family_head_id, $member_id)
|
|
{
|
|
$insurance_member = InsuranceMember::where(['family_id' => $family_head_id, 'id' => $member_id])->orderBy('id', 'desc')->first();
|
|
$family_head_patient_id = get_name($family_head_id, "id", "patient_id", "insurance_heads_of_family");
|
|
|
|
if ($insurance_member) {
|
|
$head_of_family = HeadOfFamily::find($family_head_id);
|
|
$patient = Patient::withTrashed()->find($insurance_member->patient_id);
|
|
|
|
$head_of_family->name = $patient->first_name . " " . $patient->last_name;
|
|
$head_of_family->group_id = $insurance_member->group_id;
|
|
$head_of_family->patient_id = $patient->id;
|
|
$head_of_family->created_by = Auth::id();
|
|
$head_of_family->updated_by = Auth::id();
|
|
if ($head_of_family->save()) {
|
|
$insurance_member->family_id = $head_of_family->id;
|
|
$insurance_member->is_family_head = 1;
|
|
$insurance_member->update();
|
|
|
|
//update all members related to the previous family head
|
|
$attached_insurance_members = InsuranceMember::where(['family_id' => $family_head_id])->get();
|
|
if (count($attached_insurance_members)) {
|
|
foreach ($attached_insurance_members as $attached_member) {
|
|
$attached_member->family_id = $head_of_family->id;
|
|
$attached_member->is_family_head = ($attached_member->id == $member_id) ? 1 : 0;
|
|
$attached_member->update();
|
|
}
|
|
}
|
|
}
|
|
|
|
flash(get_full_name($insurance_member->patient_id, "id", "first_name", "last_name", "patients").' has been made the head from the family of '.get_full_name($family_head_patient_id, "id", "first_name", "last_name", "patients"))->success();
|
|
|
|
return redirect('edit_insurance_premiums_payment/'.$insurance_member->group_id);
|
|
} else{
|
|
flash('Family member could not be found')->error();
|
|
}
|
|
return redirect('insurance_premiums/create');
|
|
}
|
|
|
|
public function get_expected_chi_group_amount($group_id)
|
|
{
|
|
$group_insurance_members = InsuranceMember::where('group_id', $group_id)->get();
|
|
|
|
$family_members_to_exclude_array = session()->has("member_ids_to_exclude") ? session()->get("member_ids_to_exclude") : [];
|
|
|
|
$expected_group_premium = 0;
|
|
if (count($group_insurance_members) > 0) {
|
|
foreach ($group_insurance_members as $member) {
|
|
if (!in_array($member->id, $family_members_to_exclude_array)) {
|
|
$expected_group_premium += $member->premium;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $expected_group_premium;
|
|
}
|
|
|
|
public function cancel_insurance_premiums(Request $request) {
|
|
$today = Carbon::today()->toDateString();
|
|
$yesterday = Carbon::yesterday()->toDateString();
|
|
$end = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
|
|
$start = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
|
$display = "";
|
|
$search_option = $request->search_option;
|
|
|
|
switch ($request->dates) {
|
|
case 'yesterday':
|
|
$premiums = InsurancePremiums::whereDate('payment_date', $yesterday)->where('end_date', '>', date('Y-m-d'))->paginate(1000);
|
|
$display .= $search_option. " Premiums paid yesterday, the " . streamline_date($yesterday);
|
|
break;
|
|
case 'custom_date':
|
|
$premiums = InsurancePremiums::whereDate('payment_date', $start)->where('end_date', '>', date('Y-m-d'))->paginate(1000);
|
|
$display .= $search_option. " Premiums paid on the " . streamline_date($start);
|
|
break;
|
|
case 'custom_date_range':
|
|
$premiums = InsurancePremiums::whereBetween('payment_date', [$start, $end])->where('end_date', '>', date('Y-m-d'))->paginate(1000);
|
|
$display .= $search_option. " Premiums paid from " . streamline_date($start) . " to " . streamline_date($end);
|
|
break;
|
|
default:
|
|
case 'today':
|
|
$premiums = InsurancePremiums::whereDate('payment_date', $today)->where('end_date', '>', date('Y-m-d'))->paginate(1000);
|
|
$display .= $search_option. " Premiums paid today, the " . streamline_date($today);
|
|
break;
|
|
}
|
|
|
|
$insurance_family = HeadOfFamily::pluck('name', 'id');
|
|
|
|
$insurance_groups = InsuranceGroup::pluck('name', 'id');
|
|
|
|
$relations = FamilyRelationship::pluck('name', 'id');
|
|
|
|
$insurance_groups_select = InsuranceGroup::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
$insurance_groups_select = ['' => '- select -'] + $insurance_groups_select;
|
|
|
|
return view('insurance::insurance_premiums.cancel_insurance_premiums', compact('premiums', 'insurance_family', 'insurance_groups', 'relations', 'insurance_groups_select', 'search_option', 'display'));
|
|
}
|
|
|
|
public function cancel_premium($member_id, $subscription_id) {
|
|
// get values from insurance subscriptions
|
|
$insurance_premium = InsurancePremiums::find($subscription_id);
|
|
|
|
//check for correct
|
|
if ($insurance_premium) {
|
|
$covered_members_array = explode(",", $insurance_premium->covered_member_ids);
|
|
$covered_member_premiums_array = explode(",", $insurance_premium->covered_member_premiums_paid);
|
|
|
|
if (array_search($member_id, $covered_members_array) !== false) {
|
|
//remove this member from the covered_ids value
|
|
$key_search = array_search($member_id, $covered_members_array);
|
|
unset($covered_members_array[$key_search]);
|
|
unset($covered_member_premiums_array[$key_search]);
|
|
|
|
//update the insurance_subscriptions table
|
|
$insurance_premium->covered_member_ids = implode(",", $covered_members_array);
|
|
$insurance_premium->covered_member_premiums_paid = implode(",", $covered_member_premiums_array);
|
|
$insurance_premium->update();
|
|
|
|
// update the insurance table as well
|
|
$insurance_member = InsuranceMember::find($member_id);
|
|
|
|
if ($insurance_member) {
|
|
$insurance_member->current_insurance_end_date = NULL;
|
|
$insurance_member->current_insurance_amount_paid = NULL;
|
|
$insurance_member->save();
|
|
}
|
|
|
|
$patient_id = get_name($member_id, 'id', 'patient_id', 'insurance_members');
|
|
|
|
flash(get_full_name($patient_id, "id", "first_name", "last_name", "patients")."'s premium has been canceled")->success();
|
|
return redirect("cancel_insurance_premiums");
|
|
}
|
|
}
|
|
|
|
flash("No active premium has been found for this member")->error();
|
|
return redirect("cancel_insurance_premiums");
|
|
}
|
|
|
|
public function cancel_family_premium($family_id)
|
|
{
|
|
$this_family_members = InsuranceMember::where('family_id', $family_id)->get();
|
|
|
|
$group_id = get_name($family_id, 'id', 'group_id', 'insurance_heads_of_family');
|
|
|
|
//get values from insurance subscriptions
|
|
$insurance_premium = InsurancePremiums::where('group_id', $group_id)->where('end_date', '>', date('Y-m-d'))->orderBy('id', 'desc')->first();
|
|
|
|
if (count($this_family_members) > 0) {
|
|
foreach ($this_family_members as $fam_member_record) {
|
|
$member_id = $fam_member_record->id;
|
|
|
|
if ($insurance_premium) {
|
|
$covered_members_array = explode(",", $insurance_premium->covered_member_ids);
|
|
$covered_member_premiums_array = explode(",", $insurance_premium->covered_member_premiums_paid);
|
|
|
|
if (array_search($member_id, $covered_members_array) !== false) {
|
|
//remove this member from the covered_ids value
|
|
$key_search = array_search($member_id, $covered_members_array);
|
|
unset($covered_members_array[$key_search]);
|
|
unset($covered_member_premiums_array[$key_search]);
|
|
|
|
//update the insurance_subscriptions table
|
|
$insurance_premium->covered_member_ids = implode(",", $covered_members_array);
|
|
$insurance_premium->covered_member_premiums_paid = implode(",", $covered_member_premiums_array);
|
|
$insurance_premium->update();
|
|
}
|
|
}
|
|
}
|
|
|
|
//remove the family_id and family accounts from the csv value that was previously stored
|
|
$covered_families_array = explode(",", $insurance_premium->family_heads);
|
|
$covered_families_premiums_array = explode(",", $insurance_premium->family_amount);
|
|
if (array_search($family_id, $covered_families_array) !== false) {
|
|
|
|
$key_search = array_search($family_id, $covered_families_array);
|
|
unset($covered_families_array[$key_search]);
|
|
unset($covered_families_premiums_array[$key_search]);
|
|
|
|
$insurance_premium->family_heads = implode(",", $covered_families_array);
|
|
$insurance_premium->family_amount = implode(",", $covered_families_premiums_array);
|
|
$insurance_premium->update();
|
|
}
|
|
|
|
//check if the family_heads column is empty and delete the record altogether
|
|
if ($insurance_premium->family_heads == "") {
|
|
$insurance_premium->delete();
|
|
}
|
|
|
|
flash("The family of ".get_name($family_id, "id", "name", "insurance_heads_of_family")."'s premium has been canceled")->success();
|
|
return redirect("cancel_insurance_premiums");
|
|
}
|
|
|
|
flash("No active premium has been found for this member")->error();
|
|
return redirect("cancel_insurance_premiums");
|
|
}
|
|
|
|
public function remove_member_from_group_premium($family_id, $member_id)
|
|
{
|
|
$insurance_member = InsuranceMember::where(['family_id' => $family_id, 'id' => $member_id])->orderBy('id', 'desc')->first();
|
|
$family_head_patient_id = get_name($family_id, "id", "patient_id", "insurance_heads_of_family");
|
|
|
|
if ($insurance_member) {
|
|
|
|
$this_family_members_to_exclude_array = session()->has("member_ids_to_exclude") ? session()->get("member_ids_to_exclude") : [];
|
|
array_push($this_family_members_to_exclude_array, $member_id);
|
|
|
|
session()->put(["member_ids_to_exclude" => $this_family_members_to_exclude_array]);
|
|
|
|
flash(get_full_name($insurance_member->patient_id, "id", "first_name", "last_name", "patients").' has been excluded from this premium payment for the family of '.get_full_name($family_head_patient_id, "id", "first_name", "last_name", "patients").' ')->success();
|
|
|
|
return redirect('edit_single_group_premiums_payment/'.$insurance_member->group_id);
|
|
} else{
|
|
flash('Family member could not be found')->error();
|
|
}
|
|
return redirect('insurance_premiums/single_group_receipt');
|
|
}
|
|
|
|
public function edit_insurance_premiums_payment($group_id)
|
|
{
|
|
$insurance_groups = InsuranceGroup::pluck('name', 'id')->toArray();//dd(session()->all());
|
|
|
|
$insurance_groups = ['' => '- select -'] + $insurance_groups;
|
|
$insurance_groups = InsuranceGroup::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
$insurance_groups = ['' => '- select -'] + $insurance_groups;
|
|
|
|
$families = HeadOfFamily::orderBy('name', 'asc')->pluck('id')->toArray();
|
|
$relations = FamilyRelationship::whereNotIn('id',[1])->orderBy('id', 'asc')->pluck('name', 'id')->toArray();
|
|
$relations = ['' => '- select -'] + $relations;
|
|
|
|
$occupations = Occupation::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$patient_categories = PatientCategory::where('available', 1)->orderby('name')->pluck('name', 'id')->toArray();
|
|
$districts = District::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$marital_statuses = MaritalStatus::pluck('name', 'id')->toArray();
|
|
$religions = Religion::orderBy('name')->pluck('name', 'id')->toArray();
|
|
$relationships = FamilyRelationship::orderBy('name')->pluck('name', 'id')->toArray();
|
|
|
|
$occupations = ['' => '- select -'] + $occupations;
|
|
$districts = ['' => '- select -'] + $districts;
|
|
$religions = ['' => '- select -'] + $religions;
|
|
$relationships = ['' => '- select -'] + $relationships;
|
|
$hospital_information = HospitalInformation::first();
|
|
$dynamic_counties = DB::table('counties')->pluck('name','id')->prepend('- Select County - ', '');
|
|
$dynamic_sub_counties = DB::table('subcounties')->pluck('name','id')->prepend('- Select Sub County - ', '');
|
|
$dynamic_parishes = DB::table('parishes')->pluck('name','id')->prepend('- Select Parish - ', '');
|
|
$villages = DB::table('villages')->pluck('name', 'id')->prepend('- Select Village - ', '');
|
|
|
|
return view('insurance::insurance_premiums.edit', compact('group_id','insurance_groups', 'families', 'relations', 'dynamic_counties', 'dynamic_parishes', 'dynamic_sub_counties', 'relationships', 'religions', 'occupations', 'districts', 'marital_statuses', 'patient_categories', 'hospital_information', 'villages'));
|
|
}
|
|
|
|
public function edit_single_group_premiums_payment($group_id)
|
|
{
|
|
$insurance_groups = InsuranceGroup::pluck('name', 'id')->toArray();
|
|
|
|
$insurance_groups = ['' => '- select -'] + $insurance_groups;
|
|
|
|
return view('insurance::insurance_premiums.single_group_receipt_edit', compact('group_id','insurance_groups'));
|
|
}
|
|
|
|
public function remove_family_from_group_premium($family_id)
|
|
{
|
|
$insurance_members = InsuranceMember::where(['family_id' => $family_id])->orderBy('id', 'desc')->get();
|
|
|
|
$family_head_patient_id = get_name($family_id, "id", "patient_id", "insurance_heads_of_family");
|
|
|
|
//create the array of family ids to exclude and add it in the session
|
|
$family_ids_to_exclude_array = session()->has("family_ids_to_exclude") ? session()->get("family_ids_to_exclude") : [];
|
|
array_push($family_ids_to_exclude_array, $family_id);
|
|
session()->put(["family_ids_to_exclude" => $family_ids_to_exclude_array]);
|
|
|
|
|
|
$group_id = 0;
|
|
// loop through to create session of members to exclude
|
|
if (count($insurance_members) > 0) {
|
|
foreach ($insurance_members as $insurance_member) {
|
|
$this_family_members_to_exclude_array = session()->has("member_ids_to_exclude") ? session()->get("member_ids_to_exclude") : [];
|
|
array_push($this_family_members_to_exclude_array, $insurance_member->id);
|
|
|
|
session()->put(["member_ids_to_exclude" => $this_family_members_to_exclude_array]);
|
|
|
|
$group_id = $insurance_member->group_id;
|
|
}
|
|
|
|
flash('The family of '.get_full_name($family_head_patient_id, "id", "first_name", "last_name", "patients").' has been excluded from this group payment')->success();
|
|
|
|
return redirect('edit_single_group_premiums_payment/'.$group_id);
|
|
}
|
|
|
|
flash('Family member could not be found')->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|