updated streamline-setup v2

This commit is contained in:
2025-01-15 08:53:49 -08:00
committed by alec.turner
parent a2ce9248f0
commit 4b569f81b0
20228 changed files with 2932048 additions and 63204 deletions
@@ -0,0 +1,239 @@
<?php
namespace Modules\Insurance\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\QueryException;
use Carbon\Carbon;
use Streamline\Models\CommunityHealthInsurancePlan;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Streamline\Models\HospitalInformation;
use Streamline\Models\InsuranceBenefit;
use Streamline\Models\InsuranceBenefitItem;
class CommunityHealthInsurancePlanController extends Controller
{
public function __construct() {
/* $this->middleware('auth');
$this->middleware('permission:chi_plan-list', ['only' => ['index']]);
$this->middleware('permission:chi_plan-create', ['only' => ['create', 'store']]);
$this->middleware('permission:chi_plan-edit', ['only' => ['edit', 'update']]);
$this->middleware('permission:chi_plan-delete', ['only' => ['destroy', 'inactive', 'activate']]); */
}
/**
* Display a listing of the resource.
*
*/
public function index() {
$chi_plans = CommunityHealthInsurancePlan::orderBy('name', 'asc')->paginate(50);
return view('insurance::chi_plan.index', compact('chi_plans'));
}
/**
* Show the form for creating a new resource.
*
*/
public function create()
{
return view('insurance::chi_plan.create');
}
/**
* Store a newly created resource in storage.
*
*/
public function store(Request $request) {
request()->validate([
'name' => 'required',
'plan_start_date' => 'required',
'plan_end_date' => 'required'
]);
$start_date = Carbon::createFromFormat('d-m-Y', $request->plan_start_date)->toDateString();
$end_date = Carbon::createFromFormat('d-m-Y', $request->plan_end_date)->toDateString();
$chi_plan = new CommunityHealthInsurancePlan;
$chi_plan->name = $request->name;
$chi_plan->plan_fee = $request->plan_fee;
$chi_plan->plan_start_date = $start_date;
$chi_plan->plan_end_date = $end_date;
$chi_plan->member_annual_limit = $request->member_annual_limit;
$chi_plan->family_annual_limit = $request->family_annual_limit;
$chi_plan->is_authorized_required = $request->is_authorization_required;
$chi_plan->membership_card_color = $request->membership_card_color;
$chi_plan->created_by = auth()->user()->id;
try {
$chi_plan->save();
flash($request->name . " CHI plan has been created")->success();
return redirect("/community_health_insurance_plan/");
} catch (QueryException $e) {
flash($request->name . " CHI plan already exists!")->error();
return back()->withInput();
}
}
/**
* Display the specified resource.
*
* @param int $id
*/
public function show($id) {
$chi_plan = CommunityHealthInsurancePlan::withTrashed()->find($id);
$drugs = DB::table('drugs')->where('available', 1)->pluck('name', 'id');
$procedures = DB::table('procedures')->where('available', 1)->pluck('name', 'id');
$services = DB::table('services')->where('available', 1)->pluck('name', 'id');
$investigations = DB::table('investigations')->pluck('name', 'id');
$sundries = DB::table('sundries')->where('available', 1)->pluck('name', 'id');
if ($chi_plan) {
return view('insurance::chi_plan.show', compact('chi_plan', 'drugs', 'procedures', 'services', 'investigations', 'sundries'));
}
return redirect()->back();
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
*/
public function edit($id) {
$chi_plan = CommunityHealthInsurancePlan::findOrFail($id);
if (!$chi_plan) {
flash()->error("CHI plan not found");
return redirect('/community_health_insurance_plan/');
} else {
return view('insurance::chi_plan.edit', compact('chi_plan'));
}
}
/**
* Update the specified resource in storage.
*
*/
public function update(Request $request, $id) {
request()->validate([
'name' => 'required',
'plan_start_date' => 'required',
'plan_end_date' => 'required'
]);
$start_date = Carbon::createFromFormat('d-m-Y', $request->plan_start_date)->toDateString();
$end_date = Carbon::createFromFormat('d-m-Y', $request->plan_end_date)->toDateString();
$chi_plan = CommunityHealthInsurancePlan::findOrFail($id);
$chi_plan->name = $request->name;
$chi_plan->plan_fee = $request->plan_fee;
$chi_plan->plan_start_date = $start_date;
$chi_plan->plan_end_date = $end_date;
$chi_plan->member_annual_limit = $request->member_annual_limit;
$chi_plan->family_annual_limit = $request->family_annual_limit;
$chi_plan->is_authorized_required = $request->is_authorization_required;
$chi_plan->membership_card_color = $request->membership_card_color;
$chi_plan->created_by = auth()->user()->id;
try {
$chi_plan->update();
flash($request->name . " CHI plan has been updated")->success();
return redirect("/community_health_insurance_plan/");
} catch (QueryException $e) {
flash($request->name . " CHI plan already exists!")->error();
return back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
*/
public function destroy($id) {
$chi_plan = CommunityHealthInsurancePlan::find($id);
if ($chi_plan->delete()){
// remove benefits as well as the items
InsuranceBenefit::where('plan_id', $id)->delete();
InsuranceBenefitItem::where('plan_id', $id)->delete();
flash("CHI Plan has been deleted.")->success();
return redirect('/community_health_insurance_plan/');
} else {
flash("An error occurred. Please try again later")->error();
return back()->withInput();
}
}
/**
* Display a listing of the inactive resource(s).
*
* @return \Illuminate\Http\Response
*/
public function inactive() {
$chi_plans = CommunityHealthInsurancePlan::onlyTrashed()
->orderBy('name', 'asc')
->paginate(50);
if (count($chi_plans) < 1) {
flash()->error("There is no inactive Plans");
return redirect('/community_health_insurance_plan/');
} else {
return view('insurance::chi_plan.inactive', compact('chi_plans'));
}
}
/**
* Activate the specified resource in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function activate($id) {
$chi_plan = CommunityHealthInsurancePlan::withTrashed()->find($id);
if ($chi_plan->restore()){
flash("Plan has been activated.")->success();
return redirect('/community_health_insurance_plan/');
}
}
public function print($id)
{
$chi_plan = CommunityHealthInsurancePlan::withTrashed()->find($id);
$hospital_information = HospitalInformation::find(1);
$drugs = DB::table('drugs')->where('available', 1)->pluck('name', 'id');
$procedures = DB::table('procedures')->where('available', 1)->pluck('name', 'id');
$services = DB::table('services')->where('available', 1)->pluck('name', 'id');
$investigations = DB::table('investigations')->pluck('name', 'id');
$sundries = DB::table('sundries')->where('available', 1)->pluck('name', 'id');
$data = [
'chi_plan' => $chi_plan,
'hospitalInfo' => $hospital_information,
'drugs' => $drugs,
'procedures' => $procedures,
'services' => $services,
'investigations' => $investigations,
'sundries' => $sundries
];
$print_footer = (!is_null($hospital_information->print_footer)) ? '&nbsp&nbsp&nbsp&nbsp&nbsp<i>' . $hospital_information->print_footer . '</i>' : '';
$pdf = SnappyPDF::loadView("insurance::chi_plan/print_plan_details", $data)
->setOrientation('portrait')
->setPaper('a4')
->setOption('margin-bottom', 5)
->setOption('margin-top', 5)
->setOption('footer-html', '<i>&copy; ' . date('Y') . ' Stre@mline</i>' . $print_footer);
return $pdf->inline('C.H.I Details' . date(" d-m-y h:ia") . '.pdf');
}
}