mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
615 lines
28 KiB
PHP
Executable File
615 lines
28 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\PatientFinance\Services;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Streamline\Models\CentralBillingDeposits;
|
|
use Streamline\Models\ChartOfAccount;
|
|
use Streamline\Models\CHIDeposit;
|
|
use Streamline\Models\CollectiveBillsDeposits;
|
|
use Streamline\Models\EyeGlassesDeposits;
|
|
use Streamline\Models\InvestigationDeposit;
|
|
use Streamline\Models\Patient;
|
|
use Streamline\Models\DonorDiscountDetail;
|
|
use Streamline\Models\Debtor;
|
|
use Streamline\Models\Discount;
|
|
use Streamline\Models\PatientCategoryInvoice;
|
|
use Streamline\Models\ServiceDeposit;
|
|
use Streamline\Models\ProcedureDeposit;
|
|
use Streamline\Models\SundryDeposit;
|
|
use Streamline\Models\TreatmentDeposits;
|
|
use Streamline\Models\PatientOneOffDiscount;
|
|
|
|
class DepositHelpers
|
|
{
|
|
|
|
/**
|
|
* Create new donor discount details record
|
|
*
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $receipt_number
|
|
* @param $patient_to_pay
|
|
* @param $donor_to_pay
|
|
* @param $hospital_to_pay
|
|
* @param $donor_discount_category_id
|
|
* @param $donor_id
|
|
* @param $tag_id
|
|
*/
|
|
public static function donor_discount_details($patient_id, $episode_id, $receipt_number, $patient_to_pay, $donor_to_pay, $hospital_to_pay, $donor_discount_category_id, $donor_id, $tag_id)
|
|
{
|
|
|
|
// get the patient category for current patient
|
|
$patient = Patient::find($patient_id);
|
|
|
|
// create new donor discount details object
|
|
$new_donor_discount_details = new DonorDiscountDetail;
|
|
|
|
$new_donor_discount_details->patient_id = $patient_id;
|
|
$new_donor_discount_details->episode_id = $episode_id;
|
|
$new_donor_discount_details->patient_category = $patient->category_id;
|
|
$new_donor_discount_details->receipt_number = $receipt_number;
|
|
$new_donor_discount_details->patient_to_pay = $patient_to_pay;
|
|
$new_donor_discount_details->donor_to_pay = $donor_to_pay;
|
|
$new_donor_discount_details->hospital_to_pay = $hospital_to_pay;
|
|
$new_donor_discount_details->donor_discount_category_id = $donor_discount_category_id;
|
|
$new_donor_discount_details->donor_id = $donor_id;
|
|
$new_donor_discount_details->tag_id = $tag_id;
|
|
$new_donor_discount_details->created_by = Auth::id();
|
|
|
|
$new_donor_discount_details->save();
|
|
}
|
|
|
|
/**
|
|
* Create new debtor record
|
|
*
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $balance
|
|
* @param $receipt_number
|
|
* @param $tag_id
|
|
*/
|
|
public static function debt($patient_id, $episode_id, $balance, $receipt_number, $tag_id) {
|
|
$income_account = '';
|
|
$inventory_account_id = ChartOfAccount::where('type', 10)->pluck('id')->first();
|
|
$cost_of_good_account_id = ChartOfAccount::where('type', 7)->pluck('id')->first();
|
|
|
|
if ($tag_id == 6 || $tag_id == 8 || $tag_id == 7 || $tag_id == 10) {
|
|
//Consultations / Services
|
|
$income_account = 7;
|
|
} elseif ($tag_id == 3 || $tag_id == 1) {
|
|
//Drugs / Treatments
|
|
$income_account = 4;
|
|
} elseif ($tag_id == 5) {
|
|
//Sundries
|
|
$income_account = 12;
|
|
} elseif ($tag_id == 2) {
|
|
//Investigations
|
|
$income_account = 11;
|
|
} elseif ($tag_id == 4) {
|
|
//Procedures
|
|
$income_account = 8;
|
|
}
|
|
|
|
$new_debtor = new Debtor;
|
|
|
|
$new_debtor->patient_id = $patient_id;
|
|
$new_debtor->episode_id = $episode_id;
|
|
$new_debtor->balance = $balance;
|
|
$new_debtor->receipt_number = $receipt_number;
|
|
$new_debtor->tag_id = $tag_id;
|
|
$new_debtor->income_account = $income_account;
|
|
|
|
//Drugs / Treatments
|
|
if ($tag_id == 3 || $tag_id == 1) {
|
|
$new_debtor->inventory_account = $inventory_account_id;
|
|
$new_debtor->cost_of_goods_account = $cost_of_good_account_id;
|
|
}
|
|
//Sundries
|
|
elseif ($tag_id == 5) {
|
|
$new_debtor->inventory_account = $inventory_account_id;
|
|
$new_debtor->cost_of_goods_account = $cost_of_good_account_id;
|
|
}
|
|
|
|
$new_debtor->created_by = Auth::id();
|
|
$new_debtor->save();
|
|
}
|
|
|
|
/**
|
|
* Create new discount record
|
|
*
|
|
* @param $discount_amount
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $receipt_number
|
|
* @param $reason
|
|
*/
|
|
public static function discount($discount_amount, $patient_id, $episode_id, $receipt_number, $reason) {
|
|
|
|
// get patient for the category
|
|
$patient = Patient::find($patient_id);
|
|
|
|
$new_discount = new Discount;
|
|
$new_discount->discount_amount = $discount_amount;
|
|
$new_discount->patient_id = $patient_id;
|
|
$new_discount->episode_id = $episode_id;
|
|
$new_discount->reason = $reason;
|
|
$new_discount->patient_category = $patient->category_id;
|
|
//====== check if the patient is a dependant of another patient and overide category ========//
|
|
$patient_is_a_dependant_of = patient_is_a_dependant_of($patient_id);
|
|
$does_patient_category_have_threshold = does_patient_category_have_threshold($patient->category_id);
|
|
if($does_patient_category_have_threshold || !is_null($patient_is_a_dependant_of)){
|
|
$new_discount->patient_category = get_name($patient_is_a_dependant_of, "id","category_id","patients");
|
|
}
|
|
//==============//
|
|
$new_discount->receipt_number = $receipt_number;
|
|
$new_discount->created_by = Auth::id();
|
|
$new_discount->save();
|
|
}
|
|
|
|
/**
|
|
* Create new patient category invoice record
|
|
*
|
|
* @param $patient_category_id
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $amounts_string
|
|
* @param $items_string
|
|
* @param $receipt_number
|
|
* @param $tag_id
|
|
* @param $quantity
|
|
* @param $patient_amount
|
|
* @param $transaction_date
|
|
*/
|
|
public static function patient_category_invoice($patient_category_id, $patient_id, $episode_id, $amounts_string, $items_string, $receipt_number, $tag_id, $quantity, $patient_amount, $transaction_date, $order_ids) {
|
|
|
|
$income_account = $cost_of_goods_account = $inventory_account = '';
|
|
$items_array = explode(',', $items_string);
|
|
$cost_price_array = $income_accounts_array = $cost_of_goods_account_array = $inventory_account_array = [];
|
|
|
|
for ($i = 0; $i < count($items_array); $i++) {
|
|
//Inpatient Deposits
|
|
if ($tag_id == 10) {
|
|
$income_account = 7;
|
|
}
|
|
//Consultations / Services
|
|
if ($tag_id == 6 || $tag_id == 8 || $tag_id == 7) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'services');
|
|
$income_account = is_numeric($income_account) ? $income_account : 7;
|
|
$income_accounts_array[] = $income_account;
|
|
}
|
|
//Drugs / Treatments
|
|
elseif ($tag_id == 3 || $tag_id == 1) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'drugs');
|
|
$income_account = is_numeric($income_account) ? $income_account : 4;
|
|
$income_accounts_array[] = $income_account;
|
|
$inventory_account = get_name($items_array[$i], 'id', 'inventory_account', 'drugs');
|
|
$inventory_account_array[] = $inventory_account;
|
|
$cost_of_goods_account = get_name($items_array[$i], 'id', 'cost_of_goods_account', 'drugs');
|
|
$cost_of_goods_account_array[] = $cost_of_goods_account;
|
|
$cost_price_array[$i] = get_latest_inventory_cost_price($items_array[$i], 1, Carbon::today()->toDateString());
|
|
}
|
|
//Sundries
|
|
elseif ($tag_id == 5) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'sundries');
|
|
$income_account = is_numeric($income_account) ? $income_account : 12;
|
|
$income_accounts_array[] = $income_account;
|
|
$inventory_account = get_name($items_array[$i], 'id', 'inventory_account', 'sundries');
|
|
$inventory_account_array[] = $inventory_account;
|
|
$cost_of_goods_account = get_name($items_array[$i], 'id', 'cost_of_goods_account', 'sundries');
|
|
$cost_of_goods_account_array[] = $cost_of_goods_account;
|
|
$cost_price_array[$i] = get_latest_inventory_cost_price($items_array[$i], 2, Carbon::today()->toDateString());
|
|
}
|
|
//Investigations
|
|
elseif ($tag_id == 2) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'investigations');
|
|
$income_account = is_numeric($income_account) ? $income_account : 11;
|
|
$income_accounts_array[] = $income_account;
|
|
}
|
|
//Procedures
|
|
elseif ($tag_id == 4) {
|
|
$income_account = get_name($items_array[$i], 'id', 'account_id', 'procedures');
|
|
$income_account = is_numeric($income_account) ? $income_account : 8;
|
|
$income_accounts_array[] = $income_account;
|
|
}
|
|
}
|
|
|
|
$cost_price_string = implode(',', $cost_price_array);
|
|
$income_accounts_string = is_null($income_accounts_array) ? "" : implode(',', $income_accounts_array);
|
|
$cost_of_goods_accounts_string = is_null($cost_of_goods_account_array) ? null : implode(',', $cost_of_goods_account_array);
|
|
$inventory_accounts_string = is_null($inventory_account_array) ? null : implode(',', $inventory_account_array);
|
|
|
|
// check if the transaction date is set
|
|
if ($transaction_date == "") {
|
|
$transaction_date = date('Y-m-d');
|
|
}
|
|
|
|
$new_patient_category_invoice = new PatientCategoryInvoice;
|
|
$new_patient_category_invoice->patient_id = $patient_id;
|
|
$new_patient_category_invoice->episode_id = $episode_id;
|
|
$new_patient_category_invoice->patient_category = $patient_category_id;
|
|
$new_patient_category_invoice->items_amounts = $amounts_string;
|
|
$new_patient_category_invoice->items_ids = $items_string;
|
|
$new_patient_category_invoice->items_quantity = isset($quantity) ? (is_string($quantity) ? $quantity : implode(',', $quantity)) : '';
|
|
$new_patient_category_invoice->patient_amount = $patient_amount;
|
|
$new_patient_category_invoice->receipt_number = $receipt_number;
|
|
$new_patient_category_invoice->tag_id = $tag_id;
|
|
$new_patient_category_invoice->created_by = Auth::id();
|
|
$new_patient_category_invoice->transaction_date = $transaction_date . " " . date('H:i:s');
|
|
$new_patient_category_invoice->order_ids = $order_ids;
|
|
$new_patient_category_invoice->income_account = $income_accounts_string; //$income_account;
|
|
|
|
if ($tag_id == 3 || $tag_id == 1) {
|
|
//treatments or drugs
|
|
$new_patient_category_invoice->inventory_account = $inventory_accounts_string; //$inventory_account;
|
|
$new_patient_category_invoice->cost_of_goods_account = $cost_of_goods_accounts_string; //$cost_of_goods_account;
|
|
$new_patient_category_invoice->cost_price = $cost_price_string;
|
|
} elseif ($tag_id == 5) {
|
|
//sundries
|
|
$new_patient_category_invoice->inventory_account = $inventory_accounts_string; //$inventory_account;
|
|
$new_patient_category_invoice->cost_of_goods_account = $cost_of_goods_accounts_string; //$cost_of_goods_account;
|
|
$new_patient_category_invoice->cost_price = $cost_price_string;
|
|
}
|
|
|
|
$new_patient_category_invoice->save();
|
|
}
|
|
|
|
/**
|
|
* Pay for service items and add them to the service deposits table
|
|
*
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $service_items_string
|
|
* @param $amounts_string
|
|
* @param $service_type
|
|
* @param $receipt_number
|
|
* @param $patient_amount_paid
|
|
*/
|
|
public static function service_payment($patient_id, $episode_id, $service_items_string, $amounts_string, $service_type, $receipt_number, $patient_amount_paid, $order_ids, $wallets_amount)
|
|
{
|
|
$new_service_deposit = new ServiceDeposit;
|
|
|
|
$chart_of_account_array = [];
|
|
$id_array = explode(',', $service_items_string);
|
|
for ($i = 0; $i < count($id_array); $i++) {
|
|
$account_id = get_name($id_array[$i], 'id', 'account_id', 'services');
|
|
$chart_of_account_array[$i] = $account_id;
|
|
}
|
|
$chart_of_account_string = implode(',', $chart_of_account_array);
|
|
|
|
// if payment is inpatient, use inpatient slug
|
|
if ($service_items_string == 'Inpatient_Deposit') {
|
|
$inpatient_deposits_account_id = get_name("inpatient_deposits", "slug", "id", "chart_of_accounts");
|
|
if (is_numeric($inpatient_deposits_account_id)) {
|
|
$chart_of_account_string = $inpatient_deposits_account_id;
|
|
} else {
|
|
flash('The inpatient deposit chart of account is missing. Please contact Stre@mline support immediately!')->error();
|
|
}
|
|
}
|
|
|
|
$new_service_deposit->patient_id = $patient_id;
|
|
$new_service_deposit->episode_id = $episode_id;
|
|
$new_service_deposit->items_ids = $service_items_string;
|
|
$new_service_deposit->items_amounts = $amounts_string;
|
|
$new_service_deposit->patient_amount_paid = $patient_amount_paid;
|
|
$new_service_deposit->service_type = $service_type;
|
|
$new_service_deposit->receipt_number = $receipt_number;
|
|
$new_service_deposit->current_chart_of_accounts = $chart_of_account_string;
|
|
$new_service_deposit->order_ids = $order_ids;
|
|
$new_service_deposit->created_by = Auth::id();
|
|
$new_service_deposit->save();
|
|
|
|
record_cash_credits_to_daily_collection_account(($patient_amount_paid - $wallets_amount), $receipt_number, 'Services Patient Payment');
|
|
|
|
split_service_payment($new_service_deposit->id);
|
|
}
|
|
|
|
/**
|
|
* Pay for investigation items and add them to the investigations deposits table
|
|
*
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $investigation_id
|
|
* @param $investigation_prices
|
|
* @param $discount_status
|
|
* @param $receipt_number
|
|
* @param $patient_amount_paid
|
|
*/
|
|
public static function investigation_payment($patient_id, $episode_id, $investigation_id, $investigation_prices, $discount_status, $receipt_number, $patient_amount_paid, $order_ids, $wallets_amount)
|
|
{
|
|
$new_investigation_deposit = new InvestigationDeposit;
|
|
|
|
$chart_of_account_array = [];
|
|
$id_array = explode(',', $investigation_id);
|
|
for ($i = 0; $i < count($id_array); $i++) {
|
|
$account_id = get_name($id_array[$i], 'id', 'account_id', 'investigations');
|
|
$chart_of_account_array[$i] = $account_id;
|
|
}
|
|
$chart_of_account_string = implode(',', $chart_of_account_array);
|
|
|
|
$new_investigation_deposit->patient_id = $patient_id;
|
|
$new_investigation_deposit->episode_id = $episode_id;
|
|
$new_investigation_deposit->investigation_items = $investigation_id;
|
|
$new_investigation_deposit->investigation_amounts = $investigation_prices;
|
|
$new_investigation_deposit->discount_status = $discount_status;
|
|
$new_investigation_deposit->receipt_number = $receipt_number;
|
|
$new_investigation_deposit->patient_amount_paid = $patient_amount_paid;
|
|
$new_investigation_deposit->current_chart_of_accounts = $chart_of_account_string;
|
|
$new_investigation_deposit->order_ids = $order_ids;
|
|
$new_investigation_deposit->created_by = Auth::id();
|
|
$new_investigation_deposit->save();
|
|
|
|
record_cash_credits_to_daily_collection_account(($patient_amount_paid - $wallets_amount), $receipt_number, 'Investigation Patient Payment');
|
|
|
|
split_investigation_payment($new_investigation_deposit->id);
|
|
}
|
|
|
|
/**
|
|
* Pay for treatment items and add them to the treatment deposits table
|
|
*
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $treatment_id
|
|
* @param $treatment_items
|
|
* @param $treatment_quantities
|
|
* @param $treatment_amounts
|
|
* @param $treatment_subtotals
|
|
* @param $discount_status
|
|
* @param $receipt_number
|
|
* @param $patient_amount_paid
|
|
*/
|
|
public static function treatment_payment($patient_id, $episode_id, $treatment_id, $treatment_items, $treatment_quantities, $treatment_amounts,
|
|
$treatment_subtotals, $discount_status, $receipt_number, $patient_amount_paid, $order_ids, $wallets_amount)
|
|
{
|
|
$new_treatment_deposit = new TreatmentDeposits;
|
|
|
|
$id_array = explode(',', $treatment_items);
|
|
$cost_price_array = $chart_account_array = [];
|
|
|
|
$inventory_account = $cost_of_goods_account = '';
|
|
for ($i = 0; $i < count($id_array); $i++) {
|
|
$chart_account_array[$i] = $account_id = get_name($id_array[$i], 'id', 'account_id', 'drugs');
|
|
$inventory_account = get_name($id_array[$i], 'id', 'inventory_account', 'drugs');
|
|
$cost_of_goods_account = get_name($id_array[$i], 'id', 'cost_of_goods_account', 'drugs');
|
|
$cost_price = get_name($id_array[$i], 'id', 'cost_price', 'drugs');
|
|
|
|
$cost_price_array[$i] = $cost_price;
|
|
}
|
|
$cost_price_string = implode(',', $cost_price_array);
|
|
$chart_account_string = implode(',', $chart_account_array);
|
|
|
|
$new_treatment_deposit->patient_id = $patient_id;
|
|
$new_treatment_deposit->episode_id = $episode_id;
|
|
$new_treatment_deposit->treatment_id = $treatment_id;
|
|
$new_treatment_deposit->treatment_items = $treatment_items;
|
|
$new_treatment_deposit->treatment_quantities = $treatment_quantities;
|
|
$new_treatment_deposit->treatment_amounts = $treatment_amounts;
|
|
$new_treatment_deposit->treatment_subtotals = $treatment_subtotals;
|
|
$new_treatment_deposit->discount_status = $discount_status;
|
|
$new_treatment_deposit->receipt_number = $receipt_number;
|
|
$new_treatment_deposit->patient_amount_paid = $patient_amount_paid;
|
|
$new_treatment_deposit->current_chart_of_accounts = $chart_account_string;
|
|
$new_treatment_deposit->cost_of_goods_account = $cost_of_goods_account;
|
|
$new_treatment_deposit->inventory_account = $inventory_account;
|
|
$new_treatment_deposit->cost_price = $cost_price_string;
|
|
$new_treatment_deposit->order_ids = $order_ids;
|
|
$new_treatment_deposit->created_by = Auth::id();
|
|
$new_treatment_deposit->save();
|
|
|
|
record_cash_credits_to_daily_collection_account(($patient_amount_paid - $wallets_amount), $receipt_number, 'Treatment Patient Payment');
|
|
|
|
split_treatment_payment($new_treatment_deposit->id);
|
|
}
|
|
|
|
/**
|
|
* Pay for procedure items and add them to the procedure deposits table
|
|
*
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $procedures_items_string
|
|
* @param $procedure_prices_string
|
|
* @param $discount_status
|
|
* @param $receipt_number
|
|
* @param $patient_amount_paid
|
|
*/
|
|
public static function procedures_payment($patient_id, $episode_id, $procedures_items_string, $procedure_prices_string, $discount_status,
|
|
$receipt_number, $patient_amount_paid, $order_ids, $wallets_amount)
|
|
{
|
|
$new_procedure_deposit = new ProcedureDeposit;
|
|
|
|
$chart_of_account_array = [];
|
|
$id_array = explode(',', $procedures_items_string);
|
|
for ($i = 0; $i < count($id_array); $i++) {
|
|
$account_id = get_name($id_array[$i], 'id', 'account_id', 'procedures');
|
|
$chart_of_account_array[$i] = $account_id;
|
|
}
|
|
$chart_of_account_string = implode(',', $chart_of_account_array);
|
|
|
|
$new_procedure_deposit->patient_id = $patient_id;
|
|
$new_procedure_deposit->episode_id = $episode_id;
|
|
$new_procedure_deposit->procedure_items = $procedures_items_string;
|
|
$new_procedure_deposit->procedure_amounts = $procedure_prices_string;
|
|
$new_procedure_deposit->patient_amount_paid = $patient_amount_paid;
|
|
$new_procedure_deposit->payment_status = 1; //1 to mean paid
|
|
$new_procedure_deposit->receipt_number = $receipt_number;
|
|
$new_procedure_deposit->discount_status = $discount_status;
|
|
$new_procedure_deposit->current_chart_of_accounts = $chart_of_account_string;
|
|
$new_procedure_deposit->order_ids = $order_ids;
|
|
$new_procedure_deposit->created_by = Auth::id();
|
|
$new_procedure_deposit->save();
|
|
|
|
record_cash_credits_to_daily_collection_account(($patient_amount_paid - $wallets_amount), $receipt_number, 'Procedure Patient Payment');
|
|
|
|
split_procedure_payment($new_procedure_deposit->id);
|
|
}
|
|
|
|
/**
|
|
* Pay for sundries and add them to the sundry deposits table
|
|
*
|
|
* @param $patient_id
|
|
* @param $episode_id
|
|
* @param $sundry_items_string
|
|
* @param $sundry_quantity_string
|
|
* @param $sundry_prices_string
|
|
* @param $sundry_subtotal_string
|
|
* @param $discount_status
|
|
* @param $receipt_number
|
|
* @param $patient_amount_paid
|
|
*/
|
|
public static function sundries_payment($patient_id, $episode_id, $sundry_items_string, $sundry_quantity_string, $sundry_prices_string, $sundry_subtotal_string,
|
|
$discount_status, $receipt_number, $patient_amount_paid, $order_ids, $wallets_amount)
|
|
{
|
|
$new_sundry_deposit = new SundryDeposit;
|
|
|
|
$account_id = $inventory_account = $cost_of_goods_account = '';
|
|
$id_array = explode(',', $sundry_items_string);
|
|
$cost_price_array = $chart_of_account_array = [];
|
|
|
|
for ($i = 0; $i < count($id_array); $i++) {
|
|
|
|
$account_id = get_name($id_array[$i], 'id', 'account_id', 'sundries');
|
|
$inventory_account = get_name($id_array[$i], 'id', 'inventory_account', 'sundries');
|
|
$cost_of_goods_account = get_name($id_array[$i], 'id', 'cost_of_goods_account', 'sundries');
|
|
$cost_price = get_name($id_array[$i], 'id', 'cost_price', 'sundries');
|
|
|
|
$chart_of_account_array[$i] = $account_id;
|
|
$cost_price_array[$i] = $cost_price;
|
|
}
|
|
$chart_of_account_string = implode(',', $chart_of_account_array);
|
|
$cost_price_string = implode(',', $cost_price_array);
|
|
|
|
$new_sundry_deposit->patient_id = $patient_id;
|
|
$new_sundry_deposit->episode_id = $episode_id;
|
|
$new_sundry_deposit->sundry_items = $sundry_items_string;
|
|
$new_sundry_deposit->sundry_quantity = $sundry_quantity_string;
|
|
$new_sundry_deposit->sundry_amounts = $sundry_prices_string;
|
|
$new_sundry_deposit->sundry_subtotals = $sundry_subtotal_string;
|
|
$new_sundry_deposit->patient_amount_paid = $patient_amount_paid;
|
|
$new_sundry_deposit->receipt_number = $receipt_number;
|
|
$new_sundry_deposit->discount_status = $discount_status;
|
|
$new_sundry_deposit->created_by = Auth::id();
|
|
$new_sundry_deposit->current_chart_of_accounts = $chart_of_account_string;
|
|
$new_sundry_deposit->cost_of_goods_account = $cost_of_goods_account;
|
|
$new_sundry_deposit->inventory_account = $inventory_account;
|
|
$new_sundry_deposit->cost_price = $cost_price_string;
|
|
$new_sundry_deposit->order_ids = $order_ids;
|
|
$new_sundry_deposit->save();
|
|
|
|
record_cash_credits_to_daily_collection_account(($patient_amount_paid - $wallets_amount), $receipt_number, 'Sundries Patient Payment');
|
|
|
|
split_sundry_payment($new_sundry_deposit->id);
|
|
}
|
|
|
|
public static function eye_glasses_payment($patient_id, $episode_id, $items_string, $quantity_string, $prices_string, $subtotal_string,
|
|
$discount_status, $receipt_number, $patient_amount_paid, $order_ids, $wallets_amount) {
|
|
$new_deposit = new EyeGlassesDeposits;
|
|
|
|
$inventory_account = $cost_of_goods_account = '';
|
|
$id_array = explode(',', $items_string);
|
|
$cost_price_array = $chart_of_account_array = [];
|
|
|
|
for ($i = 0; $i < count($id_array); $i++) {
|
|
$account_id = get_name($id_array[$i], 'id', 'account_id', 'eye_glasses');
|
|
$inventory_account = get_name($id_array[$i], 'id', 'inventory_account', 'eye_glasses');
|
|
$cost_of_goods_account = get_name($id_array[$i], 'id', 'cost_of_goods_account', 'eye_glasses');
|
|
$cost_price = get_name($id_array[$i], 'id', 'buying_price', 'eye_glasses');
|
|
|
|
$chart_of_account_array[$i] = $account_id;
|
|
$cost_price_array[$i] = $cost_price;
|
|
}
|
|
|
|
$chart_of_account_string = implode(',', $chart_of_account_array);
|
|
$cost_price_string = implode(',', $cost_price_array);
|
|
|
|
$new_deposit->patient_id = $patient_id;
|
|
$new_deposit->episode_id = $episode_id;
|
|
$new_deposit->items = $items_string;
|
|
$new_deposit->quantity = $quantity_string;
|
|
$new_deposit->amounts = $prices_string;
|
|
$new_deposit->subtotals = $subtotal_string;
|
|
$new_deposit->patient_amount_paid = $patient_amount_paid;
|
|
$new_deposit->receipt_number = $receipt_number;
|
|
$new_deposit->discount_status = $discount_status;
|
|
$new_deposit->current_chart_of_accounts = $chart_of_account_string;
|
|
$new_deposit->cost_of_goods_account = $cost_of_goods_account;
|
|
$new_deposit->inventory_account = $inventory_account;
|
|
$new_deposit->cost_price = $cost_price_string;
|
|
$new_deposit->order_ids = $order_ids;
|
|
$new_deposit->created_by = Auth::id();
|
|
$new_deposit->save();
|
|
|
|
record_cash_credits_to_daily_collection_account(($patient_amount_paid - $wallets_amount), $receipt_number, 'Eye Glasses Patient Payment');
|
|
|
|
split_optics_payment($new_deposit->id);
|
|
}
|
|
|
|
public static function central_billing_payments($patient_id, $episode_id, $amounts_string, $items_string, $receipt_number, $tag_id, $quantity, $patient_amount, $pat_cat_paid, $order_ids) {
|
|
$central = new CentralBillingDeposits;
|
|
|
|
$central->patient_id = $patient_id;
|
|
$central->episode_id = $episode_id;
|
|
$central->items_amounts = $amounts_string;
|
|
$central->items_ids = $items_string;
|
|
$central->items_quantity = $quantity;
|
|
$central->patient_amount_paid = $patient_amount;
|
|
$central->patient_category_amount_paid = $pat_cat_paid;
|
|
$central->receipt_number = $receipt_number;
|
|
$central->tag_id = $tag_id;
|
|
$central->order_ids = $order_ids;
|
|
$central->created_by = Auth::id();
|
|
$central->save();
|
|
}
|
|
|
|
public static function chi_deposits($patient_id, $episode_id, $items_string, $receipt_number, $tag_id, $point_of_deposit, $quantity, $chi_to_pay,
|
|
$patient_co_payment, $patient_amount_paid, $patient_balance, $order_ids, $chi_amount_total) {
|
|
$chi = new CHIDeposit();
|
|
|
|
$chi->patient_id = $patient_id;
|
|
$chi->episode_id = $episode_id;
|
|
$chi->items_ids = $items_string;
|
|
$chi->items_quantity = $quantity;
|
|
$chi->chi_to_pay = $chi_to_pay;
|
|
$chi->patient_co_payment = $patient_co_payment;
|
|
$chi->patient_amount_paid = $patient_amount_paid;
|
|
$chi->chi_amount_total = $chi_amount_total;
|
|
$chi->patient_balance = $patient_balance;
|
|
$chi->receipt_number = $receipt_number;
|
|
$chi->tag_id = $tag_id;
|
|
$chi->point_of_deposit = $point_of_deposit;
|
|
$chi->order_ids = $order_ids;
|
|
$chi->created_by = Auth::id();
|
|
$chi->save();
|
|
}
|
|
|
|
public static function collective_bills_payments($patient_id, $amounts_string, $items_string, $receipt_number, $tag_id, $quantity, $patient_amount, $order_ids)
|
|
{
|
|
$collective = new CollectiveBillsDeposits();
|
|
|
|
$collective->patient_id = $patient_id;
|
|
$collective->items_ids = $items_string;
|
|
$collective->items_amounts = $amounts_string;
|
|
$collective->items_quantity = $quantity;
|
|
$collective->patient_amount_paid = $patient_amount;
|
|
$collective->receipt_number = $receipt_number;
|
|
$collective->tag_id = $tag_id;
|
|
$collective->order_ids = $order_ids;
|
|
$collective->created_by = Auth::id();
|
|
$collective->save();
|
|
}
|
|
|
|
public static function patient_one_off_discount($patient_id, $episode_id, $amount_discounted, $tag_id, $memo, $receipt_number)
|
|
{
|
|
$discount = new PatientOneOffDiscount();
|
|
|
|
$discount->patient_id = $patient_id;
|
|
$discount->episode_id = $episode_id;
|
|
$discount->amount_discounted = $amount_discounted;
|
|
$discount->tag_id = $tag_id;
|
|
$discount->memo = $memo;
|
|
$discount->receipt_number = $receipt_number;
|
|
$discount->created_by = Auth::id();
|
|
$discount->save();
|
|
}
|
|
}
|