mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 03:01:32 +00:00
resolved conflicts
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PatientDiscounts\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
Executable
+225
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PatientDiscounts\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\Donors;
|
||||
use Streamline\Models\Patient;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Streamline\Models\DiscountCategories;
|
||||
use Streamline\Models\PatientCategory;
|
||||
|
||||
class DiscountCategoryController extends Controller{
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:discount-category-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:discount-category-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:discount-category-edit', ['only' => ['edit', 'update']]);
|
||||
$this->middleware('permission:discount-category-delete', ['only' => ['destroy', 'inactive', 'activate']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(){
|
||||
$categories = PatientCategory::pluck("name", "id")->toArray();
|
||||
$donors = Donors::pluck("name", "id")->toArray();
|
||||
|
||||
$discount_categories = DiscountCategories::orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
return view('patient_discounts::discount_categories.index',compact('discount_categories','categories','donors'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create(){
|
||||
|
||||
$categories = PatientCategory::pluck("name", "id")->toArray();
|
||||
$categories = ['' => '- select -'] + $categories;
|
||||
$donors = Donors::pluck("name", "id")->toArray();
|
||||
$donors = ['' => '- select -'] + $donors;
|
||||
|
||||
return view('patient_discounts::discount_categories.create',compact('categories','donors'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request){
|
||||
request()->validate([
|
||||
'patient_category' => 'required',
|
||||
'donor' => 'required',
|
||||
'discount_name' => 'required',
|
||||
'discount_type' => 'required'
|
||||
]);
|
||||
|
||||
// get discount type
|
||||
$type = $request->discount_type;
|
||||
|
||||
$discount_category = new DiscountCategories;
|
||||
$discount_category->name = $request->discount_name;
|
||||
$discount_category->discount_type = $type;
|
||||
$discount_category->patient_category = $request->patient_category;
|
||||
$discount_category->donor_id = $request->donor;
|
||||
|
||||
// check which type of discount category has been selected and save appropriate amount
|
||||
if ($type == 1){
|
||||
// fixed figure
|
||||
$discount_category->donor_amount = $request->donor_fixed_amount;
|
||||
$discount_category->patient_amount = $request->patient_fixed_amount;
|
||||
} elseif ($type == 2) {
|
||||
// patient ceiling
|
||||
$discount_category->donor_amount = 0;
|
||||
$discount_category->patient_amount = $request->patient_ceiling;
|
||||
} elseif ($type == 3) {
|
||||
// patient top up
|
||||
$discount_category->donor_amount = $request->donor_top_up;
|
||||
$discount_category->patient_amount = 0;
|
||||
}
|
||||
|
||||
|
||||
$discount_category->created_by = auth()->user()->id;
|
||||
$discount_category->updated_by = auth()->user()->id;
|
||||
|
||||
if ($discount_category->save()) {
|
||||
return redirect('/discount_category');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id){
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
*/
|
||||
public function edit($id){
|
||||
|
||||
$discount_category = DiscountCategories::where(['id' => $id])->first();
|
||||
|
||||
$categories = PatientCategory::pluck("name", "id")->toArray();
|
||||
$categories = ['' => '- select -'] + $categories;
|
||||
|
||||
$donors = Donors::pluck("name", "id")->toArray();
|
||||
$donors = ['' => '- select -'] + $donors;
|
||||
|
||||
if (!$discount_category) {
|
||||
flash()->error("Discount category not found");
|
||||
return redirect('/discount_category/');
|
||||
} else {
|
||||
return view('patient_discounts::discount_categories.edit', compact('discount_category', 'categories', 'donors'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id){
|
||||
request()->validate([
|
||||
'patient_category' => 'required',
|
||||
'donor' => 'required',
|
||||
'discount_name' => 'required',
|
||||
'discount_type' => 'required'
|
||||
]);
|
||||
|
||||
// get discount type
|
||||
$type = $request->discount_type;
|
||||
|
||||
$discount_category = DiscountCategories::find($id);
|
||||
$discount_category->name = $request->discount_name;
|
||||
$discount_category->discount_type = $type;
|
||||
$discount_category->patient_category = $request->patient_category;
|
||||
$discount_category->donor_id = $request->donor;
|
||||
|
||||
// check which type of discount category has been selected and save appropriate amount
|
||||
if ($type == 1){
|
||||
// fixed figure
|
||||
$discount_category->donor_amount = $request->donor_fixed_amount;
|
||||
$discount_category->patient_amount = $request->patient_fixed_amount;
|
||||
} elseif ($type == 2) {
|
||||
// patient ceiling
|
||||
$discount_category->donor_amount = 0;
|
||||
$discount_category->patient_amount = $request->patient_ceiling;
|
||||
} elseif ($type == 3) {
|
||||
// patient top up
|
||||
$discount_category->donor_amount = $request->donor_top_up;
|
||||
$discount_category->patient_amount = 0;
|
||||
}
|
||||
|
||||
$discount_category->updated_by = auth()->user()->id;
|
||||
|
||||
if ($discount_category->save()) {
|
||||
return redirect('/discount_category');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id){
|
||||
$discount_category = DiscountCategories::find($id);
|
||||
|
||||
// $discount_category->active = 0;
|
||||
|
||||
if ($discount_category->delete()){
|
||||
flash("Discount category has been deleted.")->success();
|
||||
return redirect('/discount_category/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
*/
|
||||
public function inactive() {
|
||||
$discount_categories = DiscountCategories::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
$categories = PatientCategory::pluck("name", "id")->toArray();
|
||||
$donors = Donors::pluck("name", "id")->toArray();
|
||||
|
||||
if (count($donors) < 1) {
|
||||
flash()->error("There is no inactive patient discount category");
|
||||
return redirect('/discount_category/');
|
||||
} else {
|
||||
return view('patient_discounts::discount_categories.inactive', compact('categories','donors', 'discount_categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function activate($id) {
|
||||
$discount_category = DiscountCategories::withTrashed()->find($id);
|
||||
|
||||
if ($discount_category->restore()):
|
||||
flash("Discount category has been activated.")->success();
|
||||
return redirect('/discount_category/inactive');
|
||||
endif;
|
||||
}
|
||||
}
|
||||
+588
@@ -0,0 +1,588 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PatientDiscounts\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Streamline\Models\DependantsConsumption;
|
||||
use Streamline\Models\HospitalInformation;
|
||||
use Streamline\Models\OrderedInvestigation;
|
||||
use Streamline\Models\OrderedProcedure;
|
||||
use Streamline\Models\OrderedService;
|
||||
use Streamline\Models\OrderedSundry;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\PatientCategory;
|
||||
use Streamline\Models\PatientCategoryInvoice;
|
||||
use Streamline\Models\PatientDiscount;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Streamline\Models\CategoryPatientDependant;
|
||||
use Carbon\Carbon;
|
||||
use Streamline\Models\TrackInvoice;
|
||||
use Streamline\Models\Treatment;
|
||||
|
||||
class DiscountController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:discount-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:discount-create', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:discount-edit', ['only' => ['edit', 'update']]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(){
|
||||
$discounts = PatientDiscount::orderBy('patient_category', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id")->toArray();
|
||||
return view('patient_discounts::discounts.index',compact('discounts','categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create(){
|
||||
// make sure that patient discounts are not repeated
|
||||
$exiting_discount = PatientDiscount::all()->pluck('patient_category')->toArray();
|
||||
$categories = PatientCategory::whereNotIn('id',$exiting_discount)->pluck("name", "id")->toArray();
|
||||
$categories = ['' => '- select -'] + $categories;
|
||||
$expense_accounts = ChartOfAccount::where('type', 2)->pluck('name', 'id')->prepend('-select-', '')->toArray();
|
||||
|
||||
return view('patient_discounts::discounts.create',compact('categories', 'expense_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
*/
|
||||
public function store(Request $request){
|
||||
|
||||
request()->validate([
|
||||
'patient_category' => 'required',
|
||||
'pay_later' => 'required'
|
||||
]);
|
||||
|
||||
$patient_category_discount = new PatientDiscount;
|
||||
$patient_category_discount->patient_category = $request->patient_category;
|
||||
$patient_category_discount->discount = $request->discount;
|
||||
$patient_category_discount->pay_later = $request->pay_later;
|
||||
|
||||
if ($request->is_pay_later_threshold_discount == "1") {
|
||||
$patient_category_discount->threshold_type = $request->threshold_type;
|
||||
$patient_category_discount->threshold_amount = $request->threshold_amount;
|
||||
}
|
||||
|
||||
$patient_category_discount->co_payment = $request->co_payment;
|
||||
$patient_category_discount->co_payment_share = $request->co_payment_share;
|
||||
$patient_category_discount->tracking_expense_account = $request->tracking_expense_account;
|
||||
$patient_category_discount->created_by = Auth::id();
|
||||
|
||||
if ($patient_category_discount->save()) {
|
||||
flash('new patient discount saved')->success();
|
||||
return redirect('/discounts/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($id){
|
||||
|
||||
$discount = PatientDiscount::find($id);
|
||||
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id")->toArray();
|
||||
$expense_accounts = ChartOfAccount::where('type', 2)->pluck('name', 'id')->prepend('-select-', '')->toArray();
|
||||
|
||||
return view('patient_discounts::discounts.edit',compact('discount','categories', 'id', 'expense_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
*/
|
||||
public function update(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'discount' => 'required',
|
||||
'pay_later' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$patient_category_discount = PatientDiscount::find($request->id);
|
||||
|
||||
$patient_category_discount->discount = $request->discount;
|
||||
$patient_category_discount->pay_later = $request->pay_later;
|
||||
$patient_category_discount->updated_by = $request->discount;
|
||||
|
||||
if ($patient_category_discount->pay_later == 0) {
|
||||
$request->is_pay_later_threshold_discount = 0;
|
||||
$request->co_payment = 0;
|
||||
}
|
||||
|
||||
if ($request->is_pay_later_threshold_discount == 1) {
|
||||
$patient_category_discount->threshold_type = $request->threshold_type;
|
||||
$patient_category_discount->threshold_amount = $request->threshold_amount;
|
||||
} else {
|
||||
$patient_category_discount->threshold_type = NULL;
|
||||
$patient_category_discount->threshold_amount = NULL;
|
||||
}
|
||||
|
||||
if ($request->track_discounts == 1 || $request->is_pay_later_threshold_discount == 1) {
|
||||
$patient_category_discount->tracking_expense_account = $request->tracking_expense_account;
|
||||
} else {
|
||||
$patient_category_discount->tracking_expense_account = NULL;
|
||||
}
|
||||
|
||||
$patient_category_discount->co_payment = $request->co_payment;
|
||||
|
||||
if ($request->co_payment == 1) {
|
||||
$patient_category_discount->co_payment_share = $request->co_payment_share;
|
||||
} else {
|
||||
$patient_category_discount->co_payment_share = 0;
|
||||
}
|
||||
|
||||
if ($patient_category_discount->update()) {
|
||||
flash('Patient discount has been updated')->success();
|
||||
} else {
|
||||
flash("An error occurred!")->error();
|
||||
}
|
||||
return redirect('/discounts/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id) {
|
||||
if (PatientDiscount::destroy($id)) {
|
||||
flash("Patient discount has been deleted.")->success();
|
||||
return redirect('/discounts/');
|
||||
} else {
|
||||
flash("Patient discount failed to deleted.")->error();
|
||||
return redirect('/discounts/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
*/
|
||||
public function inactive() {
|
||||
$discounts = PatientDiscount::onlyTrashed()
|
||||
->orderBy('patient_category', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id")->toArray();
|
||||
|
||||
if (count($discounts) < 1) {
|
||||
flash()->error("There is no inactive discount");
|
||||
return redirect('/discounts/');
|
||||
} else {
|
||||
return view('patient_discounts::discounts.inactive', compact('discounts', 'categories'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function activate($id) {
|
||||
$discount = PatientDiscount::withTrashed()->find($id);
|
||||
|
||||
if($discount->restore()){
|
||||
flash("Patient discount has been activated.")->success();
|
||||
return redirect('/discounts/inactive');
|
||||
} else {
|
||||
flash("Patient discount failed to activate.")->error();
|
||||
return redirect('/discounts/inactive');
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_insured_drugs($patient_category_id) {
|
||||
$drugs = DB::table('drugs')->whereNull('deleted_at')->get(['id', 'name', 'patient_category_coverage']);
|
||||
|
||||
return view('patient_discounts::discounts.edit_insured_drugs', compact('drugs', 'patient_category_id'));
|
||||
}
|
||||
|
||||
public function store_edited_insured_drugs(Request $request) {
|
||||
$is_covered = $request->is_covered;
|
||||
$current_covered = is_null($request->current_covered) ? [] : $request->current_covered;
|
||||
$removed_coverage = array_diff($current_covered, $is_covered);
|
||||
|
||||
foreach ($is_covered as $value) {
|
||||
$current_coverages = get_name($value, 'id', 'patient_category_coverage', 'drugs');
|
||||
|
||||
if ($current_coverages != 'N/A') {
|
||||
if (is_null($current_coverages) || $current_coverages == "") {
|
||||
$current_coverages_array = [];
|
||||
} else {
|
||||
$current_coverages_array = explode(",", $current_coverages);
|
||||
|
||||
// check if the id is already in the array and just chill
|
||||
if (in_array($request->patient_category_id, $current_coverages_array)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$current_coverages_array[] = $request->patient_category_id;
|
||||
DB::table('drugs')->where('id', $value)->update(['patient_category_coverage' => implode(",", $current_coverages_array)]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($removed_coverage as $value) {
|
||||
$current_coverages = get_name($value, 'id', 'patient_category_coverage', 'drugs');
|
||||
|
||||
if ($current_coverages != 'N/A') {
|
||||
$current_coverages_array = explode(",", $current_coverages);
|
||||
|
||||
if (in_array($request->patient_category_id, $current_coverages_array)) {
|
||||
unset($current_coverages_array[array_search($request->patient_category_id, $current_coverages_array)]);
|
||||
}
|
||||
|
||||
DB::table('drugs')->where('id', $value)->update(['patient_category_coverage' => implode(",", $current_coverages_array)]);
|
||||
}
|
||||
}
|
||||
|
||||
flash("Drug coverages have been updated")->success();
|
||||
return redirect('/discounts/edit_insured_drugs/' . $request->patient_category_id);
|
||||
}
|
||||
|
||||
public function add_category_patient_dependants(Request $request)
|
||||
{
|
||||
$discount_id = $request->discount_id;
|
||||
$patient_discount = PatientDiscount::find($discount_id);
|
||||
$patient_category_patients = Patient::where('category_id', $patient_discount->patient_category)->orderBy('first_name', 'asc')->get();
|
||||
/*
|
||||
$patient_category_patients = DB::table("patients")->select('*')->where('category_id', $patient_discount->patient_category)->whereRaw('!FIND_IN_SET(id,'.function($query) {
|
||||
$query->select('dependant_patient_ids')->from('category_patient_dependants');
|
||||
}.')')->get();
|
||||
*/
|
||||
|
||||
return view('patient_discounts::discounts.patient_category_patients', compact('patient_discount','patient_category_patients'));
|
||||
}
|
||||
|
||||
/*
|
||||
* Display blade to enable adding dependants to a main category patient
|
||||
*/
|
||||
public function add_dependants_to_category_patient(Request $request)
|
||||
{
|
||||
$patient_id = $request->patient_id;
|
||||
$patient_category_id = $request->patient_category;
|
||||
$patient_discount_id = $request->patient_discount_id;
|
||||
$patient = Patient::find($patient_id);
|
||||
|
||||
$patients_array = [];//Patient::all(['id', 'first_name', 'last_name'])->where('category_id', 1)->pluck("full_name", "id")->toArray();
|
||||
|
||||
return view('patient_discounts::discounts.add_dependants_to_category_patient', compact('patient_id','patient_discount_id','patient_category_id','patient','patients_array'));
|
||||
}
|
||||
|
||||
/*
|
||||
* Store the added dependants
|
||||
*/
|
||||
public function store_dependants_to_category_patient(Request $request)
|
||||
{
|
||||
//check to make sure that the dependants are not attached to another dependant or even are the main patients
|
||||
$all_main_patients_array = CategoryPatientDependant::pluck('main_patient_id')->toArray();
|
||||
$patient_dependants_array = is_null($request->dependants) ? [] : $request->dependants;
|
||||
|
||||
for ($i=0; $i < count($patient_dependants_array) ; $i++) {
|
||||
if (in_array($patient_dependants_array[$i],$all_main_patients_array)) {
|
||||
flash('Patient <b>'.get_full_name($patient_dependants_array[$i], "id", "first_name", "last_name", "patients").'</b> is already a main patient and so can not be another person\'s dependant ')->error();
|
||||
return redirect('discounts');
|
||||
}
|
||||
|
||||
$all_dependants = CategoryPatientDependant::whereRaw('FIND_IN_SET(' . $patient_dependants_array[$i] . ',dependant_patient_ids)')->get();
|
||||
if (count($all_dependants)) {
|
||||
$patient_is_a_dependant_of = patient_is_a_dependant_of($patient_dependants_array[$i]);
|
||||
if (!is_null($patient_is_a_dependant_of) && ($patient_is_a_dependant_of != $request->patient_id)) {
|
||||
flash('Patient <b>'.get_full_name($patient_dependants_array[$i], "id", "first_name", "last_name", "patients").'</b> is already a dependant of someone else')->error();
|
||||
return redirect('discounts');
|
||||
}
|
||||
}
|
||||
|
||||
//make sure that they are not configured to the same category
|
||||
$main_patient_category = get_name($request->patient_id, "id", "category_id", "patients");
|
||||
$dependant_patient_category = get_name($patient_dependants_array[$i], "id", "category_id", "patients");
|
||||
if ($main_patient_category == $dependant_patient_category) {
|
||||
flash('Patient <b>'.get_full_name($patient_dependants_array[$i], "id", "first_name", "last_name", "patients").'</b> belongs to the same patient category. Both the dependant and dependee can not belong to the same category')->error();
|
||||
return redirect('discounts');
|
||||
}
|
||||
}
|
||||
|
||||
$patient = Patient::find($request->patient_id);
|
||||
$patient_category_id = $request->patient_category_id;
|
||||
$start_date = is_null($request->start_date) ? null : Carbon::createFromFormat('d/m/Y', $request->start_date)->toDateString();
|
||||
|
||||
$patient_category_depedants_record = CategoryPatientDependant::where('main_patient_id', $request->patient_id)->get();
|
||||
if (count($patient_category_depedants_record) > 0) {
|
||||
|
||||
$patient_category_depedants = $patient_category_depedants_record->first();
|
||||
$patient_category_depedants->main_patient_id = $request->patient_id;
|
||||
$patient_category_depedants->dependant_patient_ids = implode(",", $patient_dependants_array);
|
||||
$patient_category_depedants->patient_category_id = $patient_category_id;
|
||||
$patient_category_depedants->start_date = $start_date;
|
||||
$duration = 0;
|
||||
$duration = get_name($patient_category_id, "patient_category", "threshold_type", "patient_discounts");
|
||||
if ($duration == 2) {
|
||||
$duration = 12; //12 months
|
||||
}
|
||||
if ($duration == 1) {
|
||||
$duration = 1; //1 month
|
||||
}
|
||||
$patient_category_depedants->duration = $duration;
|
||||
$patient_category_depedants->update();
|
||||
} else {
|
||||
|
||||
$patient_category_depedants = new CategoryPatientDependant;
|
||||
$patient_category_depedants->main_patient_id = $request->patient_id;
|
||||
$patient_category_depedants->dependant_patient_ids = implode(",", $patient_dependants_array);
|
||||
$patient_category_depedants->patient_category_id = $patient_category_id;
|
||||
$patient_category_depedants->start_date = $start_date;
|
||||
$duration = 0;
|
||||
$duration = get_name($patient_category_id, "patient_category", "threshold_type", "patient_discounts");
|
||||
if ($duration == 2) {
|
||||
$duration = 12; //12 months
|
||||
}
|
||||
if ($duration == 1) {
|
||||
$duration = 1; //1 month
|
||||
}
|
||||
$patient_category_depedants->duration = $duration;
|
||||
$patient_category_depedants->save();
|
||||
}
|
||||
|
||||
flash('new dependants have been saved')->success();
|
||||
return redirect('discounts');
|
||||
}
|
||||
|
||||
public function view_patient_dependant_details(Request $request)
|
||||
{
|
||||
$patient_category_depedant = CategoryPatientDependant::first();
|
||||
return view('patient_discounts::discounts.view_patient_dependant_details', compact('patient_category_depedant'));
|
||||
}
|
||||
|
||||
/* View all dependants to a category patient */
|
||||
public function view_dependants_to_category_patient($id)
|
||||
{
|
||||
$patient_category_depedants_record = CategoryPatientDependant::where('main_patient_id', $id)->get();
|
||||
|
||||
$patient = Patient::find($id);
|
||||
$dependants_record = null;
|
||||
|
||||
if (count($patient_category_depedants_record) > 0) {
|
||||
$dependants_record = $patient_category_depedants_record->first();
|
||||
return view('patient_discounts::discounts.view_dependants_to_category_patient', compact('patient','dependants_record'));
|
||||
}
|
||||
return view('patient_discounts::discounts.view_dependants_to_category_patient', compact('patient','dependants_record'));
|
||||
}
|
||||
|
||||
public function search_dependant_name(Request $request)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
if ($request->has('q')) {
|
||||
$search = $request->q;
|
||||
$data = DB::table('patients')
|
||||
->where('category_id', 1)
|
||||
->where('first_name', 'LIKE', "%$search%")
|
||||
->orWhere('last_name', 'LIKE', "%$search%")
|
||||
->orWhere('number', 'LIKE', "%$search%")
|
||||
->get(["id", "first_name", "last_name", "number", "phone"]);
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function generate_dependants_payment_invoice(Request $request)
|
||||
{
|
||||
$main_patient_id = $request->main_patient_id;
|
||||
$dependants_array = [];
|
||||
$dependants = CategoryPatientDependant::where('main_patient_id', $main_patient_id)->get();
|
||||
$consumptions = DependantsConsumption::where('main_patient_id', $main_patient_id)->get();
|
||||
$patient_category_id = 0;
|
||||
foreach ($dependants as $record) {
|
||||
$dependants_array = explode(",", $record->dependant_patient_ids);
|
||||
$patient_category_id = $record->patient_category_id;
|
||||
}
|
||||
$dependants_array[] = $main_patient_id; //add the main patient in array
|
||||
|
||||
$start_of_year = Carbon::now()->startOfYear();
|
||||
$start = $start_of_year->toDateTimeString();
|
||||
$end = Carbon::now()->toDateString();
|
||||
$patient_category_name = get_name($patient_category_id, "id", "name", "patient_categories");
|
||||
$invoice_number = generateInvoiceNumberFromDB($patient_category_name);
|
||||
$invoice_start = Carbon::parse($start)->format('d-m-Y');
|
||||
$invoice_date = $invoice_start."/".$end; //according to how Benjamin organized it
|
||||
$invoice_with_payment_amount_paid = $invoice_with_payment_balance = 0;
|
||||
|
||||
$update = PatientCategoryInvoice::where('invoice_generated', 0)
|
||||
->where('patient_category', $patient_category_id)
|
||||
->whereIn('patient_id', $dependants_array)
|
||||
->update(
|
||||
[
|
||||
'invoice_generated' => 1,
|
||||
'invoice_date' => $invoice_date,
|
||||
'invoice_number' => $invoice_number,
|
||||
'is_invoice_for_individual' => $main_patient_id
|
||||
]
|
||||
);
|
||||
|
||||
$track_invoice = new TrackInvoice;
|
||||
$track_invoice->reason = $patient_category_id;
|
||||
$track_invoice->created_by = Auth::id();
|
||||
|
||||
if (!is_null($update) && $track_invoice->save()) {
|
||||
$hospital_information = HospitalInformation::first();
|
||||
$users_name = get_full_name(Auth::id(), 'id', 'first_name', 'last_name', 'users');
|
||||
|
||||
$start_date = Carbon::parse($start)->startOfDay()->toDateTimeString();
|
||||
$end_date = Carbon::parse($end)->endOfDay()->toDateTimeString();
|
||||
|
||||
//update the dependant consumption table with the generated invoices number
|
||||
$consumption = DependantsConsumption::where('main_patient_id', $main_patient_id)->whereNull('invoice_number')
|
||||
->where('unpaid_balance', '>', 0)
|
||||
->whereBetween('created_at', [$start_date, $end_date])
|
||||
->update(['invoice_number' => $invoice_number]);
|
||||
|
||||
$last_invoice = DB::table('patient_category_invoices')->select('invoice_number')->distinct()->orderBy('invoice_number', 'desc')->first();
|
||||
$last_invoice_number = $invoice_number;
|
||||
|
||||
$invoices = DB::table('patient_category_invoices')
|
||||
->whereNotIn('patient_id', findTestOrDemoPatients())
|
||||
->whereBetween('created_at', [$start_date, $end_date])
|
||||
->where('patient_category', $patient_category_id)
|
||||
->where('invoice_generated', 1)
|
||||
->where('status', 0)
|
||||
->where('invoice_number', $last_invoice_number)
|
||||
->groupBy('episode_id')->selectRaw('*, sum(patient_amount) as sum')
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
$request->merge(['invoice_number' => $invoice_number]);
|
||||
$request->merge(['patient_category' => $patient_category_id]);
|
||||
$request->merge(['start_date' => $start_date]);
|
||||
$request->merge(['end_date' => $end_date]);
|
||||
|
||||
return view('invoices::invoices.generate_invoice.patient_invoice', compact(
|
||||
'invoices',
|
||||
'request',
|
||||
'users_name',
|
||||
'hospital_information',
|
||||
'invoice_with_payment_amount_paid',
|
||||
'invoice_with_payment_balance'
|
||||
));
|
||||
} else {
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/* receive payment for a patient and his dependants */
|
||||
public function receive_dependants_payment(Request $request)
|
||||
{
|
||||
//load the page that loads invoice payment with the requests as below
|
||||
/*
|
||||
"patient_category" => "15"
|
||||
"created_by" => "17"
|
||||
"created_at" => "2021-02-01 10:35:49"
|
||||
"status" => "new"
|
||||
"total" => "3150600"
|
||||
"invoice_date" => "01-02-2021/2021-02-27"
|
||||
"invoice_number" => "0865"
|
||||
*/
|
||||
}
|
||||
|
||||
public function clean_dependants_that_are_main_patients()
|
||||
{
|
||||
//1. loop through category_patient_dependants table
|
||||
//2. explode dependants and check if any is main patient
|
||||
//3. if main patient record exists, delete main patient record, soft delete consumption and make records unpaid
|
||||
//4. soft delete episode record from patient_category_invoices and make ordered record not paid
|
||||
$patient_category_dependants = CategoryPatientDependant::all();
|
||||
if (count($patient_category_dependants) > 0) {
|
||||
foreach ($patient_category_dependants as $category_record) {
|
||||
$dependants_array = explode(",", $category_record->dependant_patient_ids);
|
||||
for ($i=0; $i < count($dependants_array) ; $i++) {
|
||||
$checking_for_main_patients = CategoryPatientDependant::where('main_patient_id',$dependants_array[$i])->get();
|
||||
if (count($checking_for_main_patients) > 0) {
|
||||
foreach ($checking_for_main_patients as $main_record) {
|
||||
$main_record->delete();
|
||||
$consumptions_records = DependantsConsumption::where('main_patient_id', $main_record->main_patient_id)->get();
|
||||
if (count($consumptions_records) > 0) {
|
||||
foreach ($consumptions_records as $consumption) {
|
||||
$consumption->delete();
|
||||
//treatments
|
||||
$treatments = Treatment::where('episode_id', $consumption->episode_id)->get();
|
||||
if (count($treatments) > 0) {
|
||||
foreach ($treatments as $treatment) {
|
||||
$treatment->update(['payment_status' => 0]);
|
||||
}
|
||||
}
|
||||
//investigations
|
||||
$investigations = OrderedInvestigation::where('episode_id', $consumption->episode_id)->get();
|
||||
if (count($investigations) > 0) {
|
||||
foreach ($investigations as $ordered_investigation) {
|
||||
$ordered_investigation->update(['payment_status' => 0]);
|
||||
}
|
||||
}
|
||||
//procedures
|
||||
$procedures = OrderedProcedure::where('episode_id', $consumption->episode_id)->get();
|
||||
if (count($procedures) > 0) {
|
||||
foreach ($procedures as $ordered_procedure) {
|
||||
$ordered_procedure->update(['payment_status' => 0]);
|
||||
}
|
||||
}
|
||||
//services
|
||||
$services = OrderedService::where('episode_id', $consumption->episode_id)->get();
|
||||
if (count($services) > 0) {
|
||||
foreach ($services as $ordered_service) {
|
||||
$ordered_service->update(['payment_status' => 0]);
|
||||
}
|
||||
}
|
||||
//sundrys
|
||||
$sundrys = OrderedSundry::where('episode_id', $consumption->episode_id)->get();
|
||||
if (count($sundrys) > 0) {
|
||||
foreach ($sundrys as $ordered_sundry) {
|
||||
$ordered_sundry->update(['payment_status' => 0]);
|
||||
}
|
||||
}
|
||||
//patient category invoice
|
||||
$patient_category_invoice = PatientCategoryInvoice::where('episode_id',$consumption->episode_id)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1018
File diff suppressed because it is too large
Load Diff
Executable
+592
@@ -0,0 +1,592 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PatientDiscounts\Http\Controllers;
|
||||
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\PatientFinance\Http\Controllers\PatientFinanceController;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\HospitalInformation;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\PatientAccountConsumption;
|
||||
use Streamline\Models\PatientAccountsDeposit;
|
||||
use Streamline\Models\PatientAccountsRefund;
|
||||
use Streamline\Models\PatientPaymentMethod;
|
||||
use Streamline\Models\TrackReceipt;
|
||||
|
||||
class PatientAccountsController extends Controller {
|
||||
|
||||
public function statement(Request $request) {
|
||||
$patient_id = session()->get('patient_id');
|
||||
|
||||
$search_by = $request->search_by;
|
||||
$reg_date = $request->reg_date;
|
||||
$start_date = $request->start_date;
|
||||
$end_date = $request->end_date;
|
||||
|
||||
$patient = DB::table('patients')
|
||||
->where('id', $patient_id)
|
||||
->first();
|
||||
|
||||
if (!is_null($search_by)){
|
||||
if($search_by == "0"){
|
||||
// last 24 hours
|
||||
$start_date_search = Carbon::now()->subDay()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
} elseif($search_by == "1"){
|
||||
// custom date
|
||||
$start_date_search = Carbon::parse($reg_date)->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::parse($reg_date)->endOfDay()->toDateTimeString();
|
||||
} elseif($search_by == "2"){
|
||||
// custom date range
|
||||
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::parse($end_date)->endOfDay()->toDateTimeString();
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
}
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
}
|
||||
|
||||
$patient_deposits = PatientAccountsDeposit::whereBetween('deposit_date', [$start_date_search, $end_date_search])
|
||||
->where('patient_id', $patient_id)
|
||||
->get();
|
||||
|
||||
$patient_refunds = PatientAccountsRefund::whereBetween('refund_date', [$start_date_search, $end_date_search])
|
||||
->where('patient_id', $patient_id)
|
||||
->get();
|
||||
|
||||
$patient_consumptions = PatientAccountConsumption::whereBetween('created_at', [$start_date_search, $end_date_search])
|
||||
->where('patient_id', $patient_id)
|
||||
->get();
|
||||
|
||||
return view('patient_discounts::patient_accounts.statement', compact('patient', 'search_by', 'reg_date', 'start_date', 'end_date',
|
||||
'patient_deposits', 'patient_refunds', 'patient_consumptions'));
|
||||
}
|
||||
|
||||
public function print_statement(Request $request) {
|
||||
$patient_id = session()->get('patient_id');
|
||||
|
||||
$search_by = $request->search_by;
|
||||
$reg_date = $request->reg_date;
|
||||
$start_date = $request->start_date;
|
||||
$end_date = $request->end_date;
|
||||
|
||||
if (!is_null($search_by)){
|
||||
if($search_by == "0"){
|
||||
// last 24 hours
|
||||
$start_date_search = Carbon::now()->subDay()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
} elseif($search_by == "1"){
|
||||
// custom date
|
||||
$start_date_search = Carbon::parse($reg_date)->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::parse($reg_date)->endOfDay()->toDateTimeString();
|
||||
} elseif($search_by == "2"){
|
||||
// custom date range
|
||||
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::parse($end_date)->endOfDay()->toDateTimeString();
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
}
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
}
|
||||
|
||||
$patient_deposits = PatientAccountsDeposit::whereBetween('deposit_date', [$start_date_search, $end_date_search])
|
||||
->where('patient_id', $patient_id)
|
||||
->get();
|
||||
|
||||
$patient_refunds = PatientAccountsRefund::whereBetween('refund_date', [$start_date_search, $end_date_search])
|
||||
->where('patient_id', $patient_id)
|
||||
->get();
|
||||
|
||||
$patient_consumptions = PatientAccountConsumption::whereBetween('created_at', [$start_date_search, $end_date_search])
|
||||
->where('patient_id', $patient_id)
|
||||
->get();
|
||||
|
||||
$hospital_information = HospitalInformation::first();
|
||||
|
||||
$data = [
|
||||
'patient_consumptions' => $patient_consumptions,
|
||||
'patient_refunds' => $patient_refunds,
|
||||
'patient_deposits' => $patient_deposits,
|
||||
'hospitalInfo' => $hospital_information,
|
||||
'patient_id' => $patient_id,
|
||||
'search_info' => "Patient Account details and transactions between " . streamline_date($start_date_search)
|
||||
. " and " . streamline_date($end_date_search) . " for " .
|
||||
get_full_name($patient_id, 'id', 'first_name', 'last_name', 'patients') .
|
||||
" (" . get_name($patient_id, 'id', 'number', 'patients') . ")"
|
||||
];
|
||||
|
||||
$pdf = SnappyPDF::loadView("patient_discounts::patient_accounts/print_statement", $data)
|
||||
->setOrientation('portrait')
|
||||
->setOption('margin-bottom', 7)
|
||||
->setOption('margin-top', 5)
|
||||
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
||||
|
||||
return $pdf->inline('Patient Account Statement' . date(" d-m-y h:ia") . '.pdf');
|
||||
}
|
||||
|
||||
public function make_deposit() {
|
||||
$patient_id = session()->get('patient_id');
|
||||
|
||||
$patient = DB::table('patients')->find($patient_id);
|
||||
|
||||
$patient_payment_methods = PatientPaymentMethod::pluck('name', 'id');
|
||||
$patient_payment_methods_options = "";
|
||||
foreach ($patient_payment_methods as $key => $value) {
|
||||
$patient_payment_methods_options .= '<option value="' . $key . '">' . $value . '</option>';
|
||||
}
|
||||
|
||||
return view('patient_discounts::patient_accounts.make_deposit', compact('patient', 'patient_payment_methods_options'));
|
||||
}
|
||||
|
||||
public function store_deposit(Request $request) {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$patient = DB::table('patients')->find($patient_id);
|
||||
|
||||
$deposit_amount = $request->deposit_amount;
|
||||
$deposit_date = $request->deposit_date;
|
||||
|
||||
$track_receipts = new TrackReceipt;
|
||||
$track_receipts->created_by = Auth::id();
|
||||
$track_receipts->reason = 'Patient Account Deposit';
|
||||
$track_receipts->save();
|
||||
$receipt_number = sprintf("%04u", $track_receipts->id);
|
||||
|
||||
$deposit = new PatientAccountsDeposit();
|
||||
|
||||
$deposit->patient_id = $patient_id;
|
||||
$deposit->deposit_amount = $deposit_amount;
|
||||
$deposit->deposit_date = Carbon::createFromFormat('d-m-Y', $deposit_date)->toDateString();
|
||||
$deposit->receipt_number = $receipt_number;
|
||||
$deposit->created_by = Auth::id();
|
||||
|
||||
if ($deposit->save()) {
|
||||
record_cash_credits_to_daily_collection_account($deposit_amount, $receipt_number, "Patient Account Deposits");
|
||||
|
||||
$patient_to_update = Patient::find($patient_id);
|
||||
$patient_to_update->patient_account_balance = $patient_to_update->patient_account_balance + (int)$request->deposit_amount;
|
||||
$patient_to_update->update();
|
||||
|
||||
$patient_account_balance_id = get_name("patient_account_balance", "slug", "id", "chart_of_accounts");
|
||||
if (is_numeric($patient_account_balance_id)) {
|
||||
// increase the balance on chart of accounts called "patient account deposit"
|
||||
$chart_of_account = ChartOfAccount::find($patient_account_balance_id);
|
||||
$chart_of_account->balance = $chart_of_account->balance + (int)$request->deposit_amount;
|
||||
$chart_of_account->update();
|
||||
} else {
|
||||
flash('A chart of accounts is missing. Please contact Stre@mline support immediately!')->error();
|
||||
}
|
||||
|
||||
$receipt_date = date('Y-m-d h:i:s');
|
||||
|
||||
$return_payment_methods = PatientFinanceController::register_payment_method($patient_id, 0, $request->original_cash_to_pay, $request->payment_method,
|
||||
$request->payment_methods_amount, array_fill(0, ($request->payment_methods_amount ? count($request->payment_methods_amount) : 0), null), array_fill(0, ($request->payment_methods_amount ? count($request->payment_methods_amount) : 0), 0), $receipt_number, 15, Auth::id(), 0);
|
||||
|
||||
flash('Patient account deposit has been updated')->success();
|
||||
|
||||
$description = "Amount Deposited";
|
||||
|
||||
if (is_cashier_receipt_type_print_html()) {
|
||||
return view('patient_discounts::patient_accounts.deposit_receipt',compact('deposit_amount', 'receipt_number', 'receipt_date', 'return_payment_methods',
|
||||
'patient', 'deposit_date', 'description'));
|
||||
} else {
|
||||
// so we first have to set a session and then go back to the payment page
|
||||
// on the payment page we can then set a JS variable that can help redirect us to our pdf print
|
||||
session()->put('print_patient_account_receipt_pdf', 1);
|
||||
|
||||
// since we want to reduce the amount of duplicate code, we shall send all items to one file for printing
|
||||
$data = [
|
||||
"deposit_amount" => $deposit_amount, "receipt_number" => $receipt_number, "deposit_date" => $deposit_date,
|
||||
"return_payment_methods" => $return_payment_methods, "receipt_date" => $receipt_date, "patient_id" => $patient_id, "description" => $description
|
||||
];
|
||||
|
||||
session()->put('print_patient_account_receipt_pdf_details', $data);
|
||||
|
||||
return redirect('/patient_finance/home/');
|
||||
}
|
||||
} else {
|
||||
return redirect('patient_accounts/make_deposit');
|
||||
}
|
||||
}
|
||||
|
||||
public function print_receipt_pdf_details() {
|
||||
$data = session()->get("print_patient_account_receipt_pdf_details");
|
||||
|
||||
// add check for when the people try to reload the page
|
||||
if (!$data) {
|
||||
return redirect('/home');
|
||||
}
|
||||
|
||||
$data['hospital_information'] = \Streamline\Models\HospitalInformation::first();
|
||||
|
||||
// lest i forget Thy love for me
|
||||
session()->forget('print_patient_account_receipt_pdf');
|
||||
session()->forget('print_patient_account_receipt_pdf_details');
|
||||
|
||||
$pdf = SnappyPDF::loadView("patient_discounts::patient_accounts.print_receipt_pdf_details", $data)
|
||||
->setOrientation('portrait')
|
||||
->setPaper('a4')
|
||||
->setOption('margin-bottom', 5)
|
||||
->setOption('margin-top', 5)
|
||||
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
||||
|
||||
return $pdf->inline('Patient Accounts Receipt' . date(" d-m-y h:ia") . '.pdf');
|
||||
}
|
||||
|
||||
public function refund_deposit() {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$patient = DB::table('patients')->find($patient_id);
|
||||
|
||||
$current_balance = get_name($patient_id, 'id', 'patient_account_balance', 'patients');
|
||||
|
||||
$banks = DB::table('chart_of_accounts')->whereNull('deleted_at')->where('type', 4)->pluck('name', 'id')->prepend('--select--', '');
|
||||
|
||||
if ($current_balance > 0) {
|
||||
return view('patient_discounts::patient_accounts.refund_deposit', compact('current_balance', 'patient', 'banks'));
|
||||
} else {
|
||||
flash("Patient account refund can not be completed because balance is less than refund limit")->error();
|
||||
return redirect('/patient_accounts/statement');
|
||||
}
|
||||
}
|
||||
|
||||
public function save_refund_deposit(Request $request) {
|
||||
$patient_id = session()->get('patient_id');
|
||||
$patient = DB::table('patients')->find($patient_id);
|
||||
|
||||
$track_receipts = new TrackReceipt;
|
||||
$track_receipts->created_by = Auth::id();
|
||||
$track_receipts->reason = 'Patient Accounts Refund';
|
||||
$track_receipts->save();
|
||||
$receipt_number = sprintf("%04u", $track_receipts->id);
|
||||
|
||||
$current_balance = $request->current_balance;
|
||||
$refund_amount = $request->refund_amount;
|
||||
$refund_date = $request->refund_date;
|
||||
$account_id = $request->account_id;
|
||||
$account_balance = $request->account_balance;
|
||||
$refund_reason = $request->refund_reason;
|
||||
|
||||
if (($current_balance < $refund_amount) || ($refund_amount < 1) || ($account_balance < $refund_amount)) {
|
||||
flash("Please enter a valid refund amount")->error();
|
||||
return redirect('/patient_accounts/refund_deposit');
|
||||
}
|
||||
|
||||
// reduce the patient's current balance by deleted amount
|
||||
$patient_to_update = Patient::find($patient_id);
|
||||
$patient_to_update->patient_account_balance = (int)$current_balance - (int)$refund_amount;
|
||||
$patient_to_update->update();
|
||||
|
||||
// decrease the balance on select account
|
||||
$chart_of_account = ChartOfAccount::find($account_id);
|
||||
$chart_of_account->balance = $chart_of_account->balance - (int)$refund_amount;
|
||||
$chart_of_account->update();
|
||||
|
||||
$account_balance_record_on_expense_date = get_latest_banking_record_based_on_transaction_date($account_id, date('Y-m-d', strtotime($refund_date)));
|
||||
$account_balance_on_expense_date_after_payment = ($account_balance_record_on_expense_date ? (int)$account_balance_record_on_expense_date->account_balance : 0) - $refund_amount;
|
||||
$last_insert_id = capture_bank_record('Patient Account Refunds', date('Y-m-d', strtotime($refund_date)), $account_id, 0,
|
||||
$account_balance_on_expense_date_after_payment, 0, $refund_amount, $refund_reason, $receipt_number);
|
||||
|
||||
update_banking_record_balances(date('Y-m-d', strtotime($refund_date)), $account_id, $last_insert_id, $account_balance_on_expense_date_after_payment);
|
||||
|
||||
$patient_account_balance_id = get_name("patient_account_balance", "slug", "id", "chart_of_accounts");
|
||||
if (is_numeric($patient_account_balance_id)) {
|
||||
// decrease the balance on chart of accounts called "patient account deposit"
|
||||
$chart_of_account = ChartOfAccount::find($patient_account_balance_id);
|
||||
$chart_of_account->balance = $chart_of_account->balance - (int)$refund_amount;
|
||||
$chart_of_account->update();
|
||||
} else {
|
||||
flash('A chart of accounts is missing. Please contact Stre@mline support immediately!')->error();
|
||||
}
|
||||
|
||||
$refund = new PatientAccountsRefund();
|
||||
$refund->patient_id = $patient_id;
|
||||
$refund->refund_amount = $refund_amount;
|
||||
$refund->refund_date = Carbon::createFromFormat('d-m-Y', $refund_date)->toDateString();
|
||||
$refund->refund_reason = $refund_reason;
|
||||
$refund->account_id = $account_id;
|
||||
$refund->receipt_number = $receipt_number;
|
||||
$refund->created_by = Auth::id();
|
||||
$refund->save();
|
||||
|
||||
$description = "Amount Refunded";
|
||||
$deposit_amount = $refund_amount;
|
||||
$receipt_date = date('Y-m-d h:i:s');
|
||||
$deposit_date = $refund_date;
|
||||
$return_payment_methods = [];
|
||||
|
||||
if (is_cashier_receipt_type_print_html()) {
|
||||
return view('patient_discounts::patient_accounts.deposit_receipt',compact('deposit_amount', 'receipt_number', 'receipt_date', 'return_payment_methods',
|
||||
'patient', 'deposit_date', 'description'));
|
||||
} else {
|
||||
// so we first have to set a session and then go back to the payment page
|
||||
// on the payment page we can then set a JS variable that can help redirect us to our pdf print
|
||||
session()->put('print_patient_account_receipt_pdf', 1);
|
||||
|
||||
// since we want to reduce the amount of duplicate code, we shall send all items to one file for printing
|
||||
$data = [
|
||||
"deposit_amount" => $deposit_amount, "receipt_number" => $receipt_number, "deposit_date" => $deposit_date,
|
||||
"return_payment_methods" => $return_payment_methods, "receipt_date" => $receipt_date, "patient_id" => $patient_id, "description" => $description
|
||||
];
|
||||
|
||||
session()->put('print_patient_account_receipt_pdf_details', $data);
|
||||
|
||||
return redirect('/patient_finance/home/');
|
||||
}
|
||||
}
|
||||
|
||||
public function deposits_report(Request $request) {
|
||||
$search_by = $request->search_by;
|
||||
$reg_date = $request->reg_date;
|
||||
$start_date = $request->start_date;
|
||||
$end_date = $request->end_date;
|
||||
$filters = [];
|
||||
|
||||
if (!is_null($search_by)){
|
||||
if($search_by == "0"){
|
||||
// last 24 hours
|
||||
$last_day = Carbon::now()->subDay();
|
||||
$filters[] = ['deposit_date', '>', $last_day];
|
||||
} elseif($search_by == "1"){
|
||||
// custom date
|
||||
$start_date_search = Carbon::parse($reg_date)->toDateString();
|
||||
$filters[] = ['deposit_date', '=', $start_date_search];
|
||||
} elseif($search_by == "2"){
|
||||
// custom date range
|
||||
if ($start_date == $end_date) {
|
||||
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateString();
|
||||
|
||||
$filters[] = ['deposit_date', '=', $start_date_search];
|
||||
} else {
|
||||
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateString();
|
||||
$end_date_search = Carbon::parse($end_date)->endOfDay()->toDateString();
|
||||
|
||||
$filters[] = ['deposit_date', '>', $start_date_search];
|
||||
$filters[] = ['deposit_date', '<', $end_date_search];
|
||||
}
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateString();
|
||||
|
||||
$filters[] = ['deposit_date', '>', $start_date_search];
|
||||
$filters[] = ['deposit_date', '<', $end_date_search];
|
||||
}
|
||||
} else {
|
||||
$filters[] = ['deposit_date', '=', Carbon::now()->toDateString()];
|
||||
}
|
||||
|
||||
if (isset($request->patient_number)) {
|
||||
$filters[] = ['patient_id', '=', get_name($request->patient_number, 'number', 'id', 'patients')];
|
||||
}
|
||||
|
||||
if (isset($request->user_id)) {
|
||||
$filters[] = ['created_by', '=', $request->user_id];
|
||||
}
|
||||
|
||||
$patient_numbers = DB::table('patients')->orderBy('number')->distinct()->pluck('number');
|
||||
|
||||
$patient_deposits = PatientAccountsDeposit::where($filters)->get();
|
||||
|
||||
return view('patient_discounts::patient_accounts.deposits_report', compact('patient_deposits', 'reg_date', 'start_date', 'end_date', 'patient_numbers'));
|
||||
}
|
||||
|
||||
public function view_details($id) {
|
||||
session()->put(['patient_id' => $id]);
|
||||
|
||||
return redirect('/patient_accounts/statement');
|
||||
}
|
||||
|
||||
public function cancel_deposit($id) {
|
||||
$deposit = PatientAccountsDeposit::find($id);
|
||||
$receipt_number = $deposit->receipt_number;
|
||||
$patient_id = $deposit->patient_id;
|
||||
$deposit_amount = $deposit->deposit_amount;
|
||||
|
||||
if ($deposit->delete()) {
|
||||
$patient_account_balance_id = get_name("patient_account_balance", "slug", "id", "chart_of_accounts");
|
||||
if (is_numeric($patient_account_balance_id)) {
|
||||
// decrease the balance on chart of accounts called "patient account deposit"
|
||||
$chart_of_account = ChartOfAccount::find($patient_account_balance_id);
|
||||
$chart_of_account->balance = (int)$chart_of_account->balance - (int)$deposit_amount;
|
||||
$chart_of_account->update();
|
||||
} else {
|
||||
flash('A chart of accounts is missing. Please contact Stre@mline support immediately!')->error();
|
||||
}
|
||||
|
||||
record_cash_debits_to_daily_collection_account($deposit_amount, $receipt_number, 'Cancel Patient Account Deposit');
|
||||
|
||||
// reduce the patient's current balance by deleted amount
|
||||
$patient_to_update = Patient::find($patient_id);
|
||||
$patient_to_update->patient_account_balance = $patient_to_update->patient_account_balance - $deposit_amount;
|
||||
$patient_to_update->update();
|
||||
|
||||
// delete the patient payment methods
|
||||
DB::table('payment_methods_transactions')
|
||||
->where('receipt_number', $receipt_number)
|
||||
->delete();
|
||||
|
||||
flash("Patient account deposit of " . $deposit_amount . " has been cancelled")->success();
|
||||
|
||||
} else {
|
||||
flash("Patient account deposit of " . $deposit_amount . " has not been cancelled")->error();
|
||||
}
|
||||
|
||||
return redirect('/patient_accounts/deposits_report');
|
||||
}
|
||||
|
||||
public function refunds_report(Request $request) {
|
||||
$search_by = $request->search_by;
|
||||
$reg_date = $request->reg_date;
|
||||
$start_date = $request->start_date;
|
||||
$end_date = $request->end_date;
|
||||
$filters = [];
|
||||
|
||||
if (!is_null($search_by)){
|
||||
if($search_by == "0"){
|
||||
// last 24 hours
|
||||
$last_day = Carbon::now()->subDay();
|
||||
array_push($filters, ['refund_date', '>', $last_day]);
|
||||
} elseif($search_by == "1"){
|
||||
// custom date
|
||||
$start_date_search = Carbon::parse($reg_date)->toDateString();
|
||||
array_push($filters, ['refund_date', '=', $start_date_search]);
|
||||
} elseif($search_by == "2"){
|
||||
// custom date range
|
||||
if ($start_date == $end_date) {
|
||||
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateString();
|
||||
|
||||
array_push($filters, ['refund_date', '=', $start_date_search]);
|
||||
} else {
|
||||
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateString();
|
||||
$end_date_search = Carbon::parse($end_date)->endOfDay()->toDateString();
|
||||
|
||||
array_push($filters, ['refund_date', '>', $start_date_search]);
|
||||
array_push($filters, ['refund_date', '<', $end_date_search]);
|
||||
}
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateString();
|
||||
|
||||
array_push($filters, ['refund_date', '>', $start_date_search]);
|
||||
array_push($filters, ['refund_date', '<', $end_date_search]);
|
||||
}
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateString();
|
||||
|
||||
array_push($filters, ['refund_date', '>', $start_date_search]);
|
||||
array_push($filters, ['refund_date', '<', $end_date_search]);
|
||||
}
|
||||
|
||||
if (isset($request->patient_number)) {
|
||||
array_push($filters, ['patient_id', '=', get_name($request->patient_number, 'number', 'id', 'patients')]);
|
||||
}
|
||||
|
||||
$patient_numbers = DB::table('patients')->orderBy('number')->distinct()->pluck('number');
|
||||
|
||||
$patient_refunds = PatientAccountsRefund::where($filters)->get();
|
||||
|
||||
return view('patient_discounts::patient_accounts.refunds_report', compact('patient_refunds', 'reg_date', 'start_date', 'end_date', 'patient_numbers'));
|
||||
}
|
||||
|
||||
public function cancel_refund($id) {
|
||||
$refund = PatientAccountsRefund::find($id);
|
||||
$refund_amount = $refund->refund_amount;
|
||||
$account_id = $refund->account_id;
|
||||
|
||||
$track_receipts = new TrackReceipt;
|
||||
$track_receipts->created_by = Auth::id();
|
||||
$track_receipts->reason = 'Patient Accounts Refund';
|
||||
$track_receipts->save();
|
||||
$receipt_number = sprintf("%04u", $track_receipts->id);
|
||||
|
||||
if ($refund->delete()) {
|
||||
// decrease the balance on select account
|
||||
$chart_of_account = ChartOfAccount::find($account_id);
|
||||
$chart_of_account->balance = $chart_of_account->balance + (int)$refund_amount;
|
||||
$chart_of_account->update();
|
||||
|
||||
$account_balance_record_on_expense_date = get_latest_banking_record_based_on_transaction_date($account_id, date('Y-m-d'));
|
||||
$account_balance_on_expense_date_after_payment = ($account_balance_record_on_expense_date ? (int)$account_balance_record_on_expense_date->account_balance : 0) + $refund_amount;
|
||||
$last_insert_id = capture_bank_record('Patient Account Refunds Cancellation', date('Y-m-d'), $account_id, 0,
|
||||
$account_balance_on_expense_date_after_payment, $refund_amount, 0, 'Patient Account Refunds Cancellation', $receipt_number);
|
||||
|
||||
update_banking_record_balances(date('Y-m-d'), $account_id, $last_insert_id, $account_balance_on_expense_date_after_payment);
|
||||
|
||||
$patient_account_balance_id = get_name("patient_account_balance", "slug", "id", "chart_of_accounts");
|
||||
if (is_numeric($patient_account_balance_id)) {
|
||||
// increase the balance on chart of accounts called "patient account deposit"
|
||||
$chart_of_account = ChartOfAccount::find($patient_account_balance_id);
|
||||
$chart_of_account->balance = (int)$chart_of_account->balance + (int)$refund_amount;
|
||||
$chart_of_account->update();
|
||||
} else {
|
||||
flash('A chart of accounts is missing. Please contact Stre@mline support immediately!')->error();
|
||||
}
|
||||
|
||||
flash("Patient account refund of " . $refund_amount . " has been cancelled")->success();
|
||||
|
||||
} else {
|
||||
flash("Patient account refund of " . $refund_amount . " has not been cancelled")->error();
|
||||
}
|
||||
|
||||
return redirect('/patient_accounts/refunds_report');
|
||||
}
|
||||
|
||||
public function consumptions_report(Request $request) {
|
||||
$search_by = $request->search_by;
|
||||
$reg_date = $request->reg_date;
|
||||
$start_date = $request->start_date;
|
||||
$end_date = $request->end_date;
|
||||
$filters = [];
|
||||
|
||||
if (!is_null($search_by)){
|
||||
if($search_by == "0"){
|
||||
// last 24 hours
|
||||
$last_day = Carbon::now()->subDay();
|
||||
array_push($filters, ['created_at', '>', $last_day]);
|
||||
} elseif($search_by == "1"){
|
||||
// custom date
|
||||
$start_date_search = Carbon::parse($reg_date)->toDateTimeString();
|
||||
array_push($filters, ['created_at', '=', $start_date_search]);
|
||||
} elseif($search_by == "2"){
|
||||
// custom date range
|
||||
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::parse($end_date)->endOfDay()->toDateTimeString();
|
||||
|
||||
array_push($filters, ['created_at', '>', $start_date_search]);
|
||||
array_push($filters, ['created_at', '<', $end_date_search]);
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
|
||||
array_push($filters, ['created_at', '>', $start_date_search]);
|
||||
array_push($filters, ['created_at', '<', $end_date_search]);
|
||||
}
|
||||
} else {
|
||||
$start_date_search = Carbon::now()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
|
||||
array_push($filters, ['created_at', '>', $start_date_search]);
|
||||
array_push($filters, ['created_at', '<', $end_date_search]);
|
||||
}
|
||||
|
||||
if (isset($request->patient_number)) {
|
||||
array_push($filters, ['patient_id', '=', get_name($request->patient_number, 'number', 'id', 'patients')]);
|
||||
}
|
||||
|
||||
$patient_numbers = DB::table('patients')->orderBy('number')->distinct()->pluck('number');
|
||||
|
||||
$patient_consumptions = PatientAccountConsumption::where($filters)->get();
|
||||
|
||||
return view('patient_discounts::patient_accounts.consumptions_report', compact('patient_consumptions', 'reg_date', 'start_date', 'end_date', 'patient_numbers'));
|
||||
}
|
||||
}
|
||||
+364
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\PatientDiscounts\Http\Controllers;
|
||||
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\PatientFinance\Http\Controllers\PatientFinanceController;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\Debtor;
|
||||
use Streamline\Models\DebtorPayment;
|
||||
use Streamline\Models\DebtPlan;
|
||||
use Streamline\Models\DebtPlanPaymentStaff;
|
||||
use Streamline\Models\HospitalInformation;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\PatientPaymentMethod;
|
||||
use Streamline\Models\Payment;
|
||||
use Streamline\Models\User;
|
||||
use Streamline\Services\PatientDiscounts\DebtorsService;
|
||||
use Streamline\Services\PatientDiscounts\DebtPlanService;
|
||||
use Streamline\Services\ReceiptService;
|
||||
use Streamline\Services\UserService;
|
||||
|
||||
class PatientDebtorsController extends Controller {
|
||||
public function __construct(
|
||||
protected ReceiptService $receiptService,
|
||||
protected DebtorsService $debtorsService,
|
||||
protected DebtPlanService $debtPlanService,
|
||||
protected UserService $userService
|
||||
) {}
|
||||
|
||||
public function receive_debtor_payment($string): View {
|
||||
$string_array = explode(",", $string);
|
||||
$debts = DB::table('debtors')->where('id', $string_array[0])->first();
|
||||
|
||||
$debt_payments = DB::table('debtor_payments')->whereNull('deleted_at')
|
||||
->where('debt_id', $string_array[0])->get();
|
||||
|
||||
$patient_payment_methods = PatientPaymentMethod::pluck('name', 'id');
|
||||
$patient_payment_methods_options = "";
|
||||
foreach ($patient_payment_methods as $key => $value) {
|
||||
$patient_payment_methods_options .= '<option value="' . $key . '">' . $value . '</option>';
|
||||
}
|
||||
|
||||
$expense_accounts = ChartOfAccount::where('type', 2)->pluck('name', 'id')->prepend('-select-', '')->toArray();
|
||||
|
||||
return view('patient_discounts::patient_debtors.receive_debtor_payment', compact('debts', 'debt_payments', 'patient_payment_methods_options', 'expense_accounts'));
|
||||
}
|
||||
|
||||
public function write_off_debts(Request $request): string {
|
||||
$new_receipt_number = $this->receiptService->createReceipt("Debt Plan Payment Update");
|
||||
|
||||
$balance = $request->amount_owed - $request->amount;
|
||||
$debtorPayment = $this->debtorsService->createDebtorPayment($request->debt_id, $new_receipt_number, $request->amount, Carbon::today()->toDateString(),
|
||||
$balance, '', $request->amount);
|
||||
|
||||
if ($debtorPayment) {
|
||||
$this->debtorsService->clearDebt($request->debt_id);
|
||||
$message = "Payment Received Successfully";
|
||||
} else {
|
||||
$message = "Payment Not Received";
|
||||
}
|
||||
|
||||
$payment = new Payment;
|
||||
$payment->item_id = "";
|
||||
$payment->vendor = "N/A";
|
||||
$payment->unit_cost = $request->amount;
|
||||
$payment->amount = $request->amount;
|
||||
$payment->quantity = 1;
|
||||
$payment->memo = $request->write_off_memo ?? "N/A";
|
||||
$payment->account_balance = 0;
|
||||
$payment->transaction_id = $new_receipt_number;
|
||||
$payment->account_id = 0;
|
||||
$payment->created_by = Auth::id();
|
||||
$payment->expense_date = now();
|
||||
$payment->expense_account = $request->expense_account;
|
||||
|
||||
$payment->save();
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function process_debtor_payment(Request $request): View|RedirectResponse
|
||||
{
|
||||
$new_receipt_number = $this->receiptService->createReceipt('Debtor Payment');
|
||||
$patient_id = $request->patient_id;
|
||||
|
||||
$debtorPayment = $this->debtorsService->createDebtorPayment($request->debt_id, $new_receipt_number, $request->amount_paid, $request->date,
|
||||
$request->balance, $request->comment, 0);
|
||||
|
||||
if ($debtorPayment) {
|
||||
$this->debtorsService->clearDebt($request->debt_id);
|
||||
record_cash_credits_to_daily_collection_account($request->amount_paid, $new_receipt_number, 'Patient Debt Payment');
|
||||
flash("Payment Received Successfully")->success();
|
||||
} else {
|
||||
flash("Payment Not Received")->error();
|
||||
return back();
|
||||
}
|
||||
|
||||
$return_payment_methods = PatientFinanceController::register_payment_method($patient_id, 0, $request->original_cash_to_pay,
|
||||
$request->payment_method, $request->payment_methods_amount, array_fill(0, count($request->payment_methods_amount ?? []), null), array_fill(0, count($request->payment_methods_amount ?? []), 0), $new_receipt_number, 13, Auth::id(), 0);
|
||||
|
||||
return $this->debtorPaymentReceipt($request, $new_receipt_number, $return_payment_methods);
|
||||
}
|
||||
|
||||
public function debtorPaymentReceipt(Request $request, $new_receipt_number, $payment_methods): View
|
||||
{
|
||||
$patient = Patient::where(['id' => $request->patient_id])->first();
|
||||
$hospital_information = HospitalInformation::first();
|
||||
$compact_values = compact('hospital_information', 'request', 'new_receipt_number', 'patient', 'payment_methods');
|
||||
|
||||
return view('patient_discounts::patient_debtors.debtor_payment', $compact_values);
|
||||
}
|
||||
|
||||
public function history_debtor_payments($debtor_id): View
|
||||
{
|
||||
$hospital_information = HospitalInformation::first();
|
||||
$payments = DebtorPayment::where('debt_id', $debtor_id)->get();
|
||||
$debtor = Debtor::where('id', $debtor_id)->first();
|
||||
$patient_id = $debtor->patient_id;
|
||||
return view('patient_discounts::patient_debtors.history_debtor_payments', compact('payments', 'hospital_information', 'patient_id', 'debtor_id'));
|
||||
}
|
||||
|
||||
public function reverse_debtor_payment($payment_id): RedirectResponse
|
||||
{
|
||||
$payment = DebtorPayment::find($payment_id);
|
||||
|
||||
$amount_being_removed = $payment->amount_paid;
|
||||
$receipt_number = $payment->receipt_number;
|
||||
|
||||
$this->debtorsService->reverseDebtPayment($payment_id);
|
||||
|
||||
// reverse any patient payment methods
|
||||
DB::table('payment_methods_transactions')
|
||||
->where('receipt_number', $receipt_number)
|
||||
->delete();
|
||||
|
||||
record_cash_debits_to_daily_collection_account($amount_being_removed, $this->receiptService->createReceipt('N/A'), "Patient Debt Payment Cancellation");
|
||||
|
||||
return redirect('patient_debtors/debtors');
|
||||
}
|
||||
|
||||
public function print_debtor_receipt_pdf_details(Request $request)
|
||||
{
|
||||
$hospital_information = HospitalInformation::find(1);
|
||||
|
||||
$data = [
|
||||
'hospital_information' => $hospital_information,
|
||||
'comment' => $request->comment,
|
||||
'amount_owed' => $request->amount_owed,
|
||||
'amount_paid' => $request->amount_paid,
|
||||
'balance' => $request->balance,
|
||||
'payment_methods' => unserialize($request->payment_methods),
|
||||
'receipt_number' => $request->receipt_number,
|
||||
'patient_id' => $request->patient_id
|
||||
];
|
||||
|
||||
$pdf = SnappyPDF::loadView("patient_discounts::patient_debtors.print_debtor_receipt_pdf_details", $data)
|
||||
->setOrientation('portrait')
|
||||
->setPaper('a4')
|
||||
->setOption('margin-bottom', 5)
|
||||
->setOption('margin-top', 5)
|
||||
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
||||
|
||||
return $pdf->inline('Patient Receipt' . date(" d-m-y h:ia") . '.pdf');
|
||||
}
|
||||
|
||||
public function reprint_debtor_receipt_pdf_details(Request $request)
|
||||
{
|
||||
$hospital_information = HospitalInformation::find(1);
|
||||
|
||||
if (isset($request->is_single_print) && is_numeric($request->is_single_print) && $request->is_single_print > 0) {
|
||||
$debt_payments = DebtorPayment::where('id', $request->is_single_print)->get();
|
||||
} else {
|
||||
$debt_payments = DebtorPayment::where('debt_id', $request->debt_id)->get();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'hospital_information' => $hospital_information,
|
||||
'debt_payments' => $debt_payments,
|
||||
'patient_id' => $request->patient_id,
|
||||
];
|
||||
|
||||
$pdf = SnappyPDF::loadView("patient_discounts::patient_debtors.reprint_debtor_receipt_pdf_details", $data)
|
||||
->setOrientation('portrait')
|
||||
->setPaper('a4')
|
||||
->setOption('margin-bottom', 5)
|
||||
->setOption('margin-top', 5)
|
||||
->setOption('footer-html', '<i>© ' . date('Y') . ' Stre@mline</i>');
|
||||
|
||||
return $pdf->inline('Patient Receipt' . date(" d-m-y h:ia") . '.pdf');
|
||||
}
|
||||
|
||||
public function debtors(Request $request) {
|
||||
$users = User::get();
|
||||
$debtors = queryDateFilter('debtors', $request);
|
||||
$display = dateLabelSetter($request);
|
||||
|
||||
return view('patient_discounts::patient_debtors.debtorsReport', compact('debtors', 'display', 'users'));
|
||||
}
|
||||
|
||||
public function debtors_patient_search($patient_id) {
|
||||
$users = User::get();
|
||||
|
||||
$debtors = DB::table('debtors')
|
||||
->where('patient_id', $patient_id)
|
||||
->whereNull('deleted_at')
|
||||
->get();
|
||||
|
||||
$display = "Showing debt records for " . get_full_name($patient_id, 'id', 'first_name', 'last_name', 'patients')
|
||||
. " (" . get_name($patient_id, 'id', 'number', 'patients') . ")";
|
||||
|
||||
return view('patient_discounts::patient_debtors.debtorsReport', compact('debtors', 'display', 'users'));
|
||||
}
|
||||
|
||||
public function receive_debt_plan_payment_staff(Request $request) {
|
||||
$debts = DB::table('debt_plan')->where('id', $request->debt_plan_id)->groupBy('staff_guarantor')->first();
|
||||
$debt_with_balances = DB::table('debt_plan_payment_staffs')->where('debt_plan_id', $request->debt_plan_id)->get();
|
||||
$expense_accounts = ChartOfAccount::where('type', 2)->pluck('name', 'id')->prepend('-select-', '')->toArray();
|
||||
$users_array = $this->userService->pluckUserFullName();
|
||||
|
||||
return view('patient_discounts::patient_debtors.debt_plan_payments_staff', compact('debts', 'debt_with_balances',
|
||||
'request', 'expense_accounts', 'users_array'));
|
||||
}
|
||||
|
||||
public function process_debt_plan_payment_staff(Request $request) {
|
||||
$new_receipt_number = $this->receiptService->createReceipt('Debt Plan');
|
||||
|
||||
$payment = $this->debtPlanService->createDebtPlanPayment(
|
||||
$request->amount_paid, $request->balance, $request->payment_id,
|
||||
$request->comment, $new_receipt_number, $request->date
|
||||
);
|
||||
|
||||
if ($payment) {
|
||||
record_cash_credits_to_daily_collection_account($request->amount_paid, $new_receipt_number, 'Debt Plan Payment');
|
||||
$this->debtPlanService->clearDebtPlan($request->payment_id, $request->amount_paid);
|
||||
flash("Payment Received Successfully")->success();
|
||||
return $this->debtPlanPaymentReceipt($request, $new_receipt_number);
|
||||
} else {
|
||||
flash("Payment Not Received")->error();
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
public function debtPlanPaymentReceipt(Request $request, $new_receipt_number)
|
||||
{
|
||||
$patient = Patient::where(['id' => $request->patient_id])->first();
|
||||
$hospital_information = HospitalInformation::first();
|
||||
$compact_values = compact('hospital_information', 'request', 'new_receipt_number', 'patient');
|
||||
|
||||
return view('patient_discounts::patient_debtors.debt_plan_payment', $compact_values);
|
||||
}
|
||||
|
||||
public function write_off_debt_plan(Request $request): string
|
||||
{
|
||||
$receipt_number = $this->receiptService->createReceipt("Patient Debt Plan Write Off");
|
||||
$today = Carbon::today()->toDateTimeString();
|
||||
|
||||
$payment = $this->debtPlanService->createDebtPlanPayment(
|
||||
$request->amount, ($request->amount_owed - $request->amount), $request->payment_id,
|
||||
$request->comment, $receipt_number, $today, $request->amount,
|
||||
);
|
||||
|
||||
if ($payment) {
|
||||
$message = "Payment Received Successfully";
|
||||
$this->debtPlanService->clearDebtPlan($request->payment_id, $request->amount);
|
||||
|
||||
$payment = new Payment;
|
||||
$payment->item_id = "";
|
||||
$payment->vendor = "N/A";
|
||||
$payment->unit_cost = $request->amount;
|
||||
$payment->amount = $request->amount;
|
||||
$payment->quantity = 1;
|
||||
$payment->memo = $request->write_off_memo ?? "N/A";
|
||||
$payment->account_balance = 0;
|
||||
$payment->transaction_id = $receipt_number;
|
||||
$payment->account_id = 0;
|
||||
$payment->created_by = Auth::id();
|
||||
$payment->expense_date = now();
|
||||
$payment->expense_account = $request->expense_account;
|
||||
$payment->save();
|
||||
} else {
|
||||
$message = "Payment Not Received";
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function debt_plan_payment($id)
|
||||
{
|
||||
$payment = DebtPlanPaymentStaff::where(['id' => $id])->first();
|
||||
$hospital_information = HospitalInformation::first();
|
||||
$compact_values = compact('hospital_information', 'payment');
|
||||
|
||||
return view('patient_discounts::patient_debtors.debt_plan_payment_detail', $compact_values);
|
||||
}
|
||||
|
||||
public function debt_plan_receipt(Request $request)
|
||||
{
|
||||
$hospital_information = HospitalInformation::first();
|
||||
$patient = Patient::where(['id' => $request->patient_id])->first();
|
||||
$debt_plan = DB::table('debt_plan')->where('id', $request->debt_plan_id)->first();
|
||||
return view('patient_discounts::patient_debtors.patient_debt_plan', compact('debt_plan', 'hospital_information', 'patient'));
|
||||
}
|
||||
|
||||
public function staff_guarantors(Request $request)
|
||||
{
|
||||
$users = DB::table('users')->get()->toArray();
|
||||
$start = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
|
||||
|
||||
if ($request->staff_member == "ALL STAFF") {
|
||||
$debts = DB::table('debt_plan')->whereBetween('created_at', [$start, $end])->get()->toArray();
|
||||
} else {
|
||||
$debts = DB::table('debt_plan')
|
||||
->where('staff_guarantor', $request->staff_member)->whereBetween('created_at', [$start, $end])->get()->toArray();
|
||||
}
|
||||
|
||||
$display = dateLabelSetter($request);
|
||||
return view('patient_discounts::patient_debtors.staffGuarantors', compact('users', 'debts', 'display', 'request'));
|
||||
}
|
||||
|
||||
public function debt_plan_patient_search($patient_id) {
|
||||
$users = DB::table('users')->get()->toArray();
|
||||
|
||||
$debts = DebtPlan::where('patient_id', $patient_id)->get();
|
||||
|
||||
$display = "Showing debt plan records of " . get_full_name($patient_id, 'id', 'first_name', 'last_name', 'patients')
|
||||
. " (" . get_name($patient_id, 'id', 'number', 'patients') . ")";
|
||||
|
||||
return view('patient_discounts::patient_debtors.staffGuarantors', compact('users', 'debts', 'display'));
|
||||
}
|
||||
|
||||
public function debt_plan_guarantor_agreement($id) {
|
||||
$debt_plan = DebtPlan::find($id);
|
||||
|
||||
if ($debt_plan) {
|
||||
// just get the first person for now but would be better to list all as well as the dates
|
||||
$user_id = explode(",", $debt_plan->staff_guarantor)[0];
|
||||
|
||||
if ($debt_plan->guarantor_type == 0) {
|
||||
$guarantor_name = get_full_name($user_id, 'id', 'first_name', 'last_name', 'non_staff_guarantors');
|
||||
} else {
|
||||
$guarantor_name = get_full_name($user_id, 'id', 'first_name', 'last_name', 'users');
|
||||
}
|
||||
|
||||
$amount_to_pay = $debt_plan->staff_guarantor_to_pay;
|
||||
$amount_owed = $debt_plan->amount_owed;
|
||||
$patient_names = get_full_name($debt_plan->patient_id, 'id', 'first_name', 'last_name', 'patients');
|
||||
$payment_date = $debt_plan->first_installment_date;
|
||||
$arrangement = $debt_plan->debt_plan_arrangement;
|
||||
|
||||
return view('patient_discounts::patient_debtors.debt_plan_guarantor_agreement', compact('amount_to_pay', 'patient_names', 'payment_date', 'arrangement', 'guarantor_name', 'amount_owed'));
|
||||
} else {
|
||||
return redirect('home');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1048
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user