mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
resolved conflicts
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Finance\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;
|
||||
}
|
||||
+1154
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Finance\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Streamline\Models\Banking;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\Equity;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EquityController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index() {
|
||||
$equities = Equity::orderBy('name', 'asc')->paginate(1000);
|
||||
|
||||
return view('finance::equity.index', compact('equities'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create() {
|
||||
$banks = ChartOfAccount::where('type', 4)->orderBy('name', 'asc')->pluck('name', 'id')->prepend('- select -', '')->toArray();
|
||||
$chart_of_accounts = ChartOfAccount::where('type', 5)->orderBy('name', 'asc')->pluck('name', 'id')->prepend('- select -', '')->toArray();
|
||||
|
||||
return view('finance::equity.create', compact('chart_of_accounts', 'banks'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$trans_id = generateReceiptNumberFromDB('Equity Deposit to bank account');
|
||||
|
||||
$equity = new Equity;
|
||||
|
||||
$equity->name = $request->name;
|
||||
$equity->amount = $request->amount;
|
||||
$equity->account_id = $request->account_id;
|
||||
$equity->deposit_to = $request->deposit_to;
|
||||
$equity->deposit_date = $request->deposit_date;
|
||||
$equity->created_by = $logged_in_user_id;
|
||||
$equity->updated_by = $logged_in_user_id;
|
||||
|
||||
$equity->save();
|
||||
|
||||
$current_bank_balance = Banking::where('bank', $request->deposit_to)->latest()->first();
|
||||
$balance_after_addition = (int)$current_bank_balance->account_balance + (int)$request->amount;
|
||||
|
||||
capture_bank_record('DEPOSIT', Carbon::parse($request->deposit_date)->toDateString(), $request->deposit_to,
|
||||
$request->account_id, $balance_after_addition, $request->amount, 0, $request->amount, $trans_id);
|
||||
|
||||
flash($request->name . " Equity has been saved")->success();
|
||||
return redirect("/equities/");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id) {
|
||||
$equity = Equity::where(['id' => $id])->first();
|
||||
$banks = ChartOfAccount::where('type', 4)->orderBy('name', 'asc')->pluck('name', 'id')->prepend('- select -', '')->toArray();
|
||||
$chart_of_accounts = ChartOfAccount::where('type', 5)->orderBy('name', 'asc')->pluck('name', 'id')->prepend('- select -', '')->toArray();
|
||||
|
||||
if (!$equity) {
|
||||
flash()->error("There is no such equity");
|
||||
return redirect('/equities/');
|
||||
} else {
|
||||
return view('finance::equity.edit', compact('equity', 'chart_of_accounts', 'banks'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$logged_in_user_id = Auth::user()->id;
|
||||
|
||||
$equity = Equity::find($id);
|
||||
$equity->name = $request->name;
|
||||
$equity->amount = $request->amount;
|
||||
$equity->account_id = $request->account_id;
|
||||
$equity->updated_by = $logged_in_user_id;
|
||||
|
||||
try {
|
||||
$equity->save();
|
||||
flash($request->name . " Equity has been updated")->success();
|
||||
return redirect("/equities/");
|
||||
} catch (QueryException $e) {
|
||||
flash("An error occurred")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id) {
|
||||
$equity = Equity::find($id);
|
||||
|
||||
if ($equity->delete()):
|
||||
flash("Equity has been deleted.")->success();
|
||||
return redirect('/equities/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the inactive resource(s).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inactive() {
|
||||
|
||||
$equities = Equity::onlyTrashed()
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(50);
|
||||
|
||||
if (count($equities) < 1) {
|
||||
flash()->error("There is no inactive equity");
|
||||
return redirect('/equities/');
|
||||
} else {
|
||||
return view('finance::equity.inactive', compact('equities'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the specified resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activate($id) {
|
||||
$equity = Equity::withTrashed()->find($id);
|
||||
|
||||
if ($equity->restore()):
|
||||
flash("Equity has been activated.")->success();
|
||||
return redirect('/equities/inactive');
|
||||
endif;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Finance\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class FinanceController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('finance::finance.index');
|
||||
}
|
||||
|
||||
public function incoming_opd_payments(Request $request): View
|
||||
{
|
||||
$clinic_id = $request->clinic_id;
|
||||
$search_by = $request->search_by;
|
||||
|
||||
$patient_categories = DB::table('patient_categories')->pluck("name", "id");
|
||||
|
||||
$filters = [];
|
||||
if($search_by == 0){
|
||||
$start_date = Carbon::now()->startOfDay()->toDateTimeString();
|
||||
$end_date = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
} elseif ($search_by == 1) {
|
||||
$start_date = Carbon::now()->subDay()->startOfDay()->toDateTimeString();
|
||||
$end_date = Carbon::now()->subDay()->endOfDay()->toDateTimeString();
|
||||
} elseif ($search_by == 2) {
|
||||
$start_date = Carbon::parse($request->reg_date)->startOfDay()->toDateTimeString();
|
||||
$end_date = Carbon::parse($request->reg_date)->endOfDay()->toDateTimeString();
|
||||
} elseif ($search_by ==3) {
|
||||
// custom date range
|
||||
$start_date = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
||||
$end_date = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
|
||||
} else {
|
||||
$start_date = Carbon::now()->toDateTimeString();
|
||||
$end_date = Carbon::now()->toDateTimeString();
|
||||
}
|
||||
|
||||
if ($clinic_id != 0) {
|
||||
$filters[] = ['patient_episodes.clinic_id', '=', $clinic_id];
|
||||
}
|
||||
|
||||
if (is_numeric($request->patient_number)) {
|
||||
$filters[] = ['patient_episodes.patient_id', '=', $request->patient_number];
|
||||
$start_date = Carbon::now()->startOfCentury()->toDateTimeString();
|
||||
$end_date = Carbon::now()->endOfDay()->toDateTimeString();
|
||||
}
|
||||
|
||||
$patient_episodes = DB::table('patient_episodes')
|
||||
->leftJoin('patients', 'patients.id', '=', 'patient_episodes.patient_id')
|
||||
->leftJoin('treatments', 'treatments.episode_id', '=', 'patient_episodes.id')
|
||||
->leftJoin('ordered_procedures', 'ordered_procedures.episode_id', '=', 'patient_episodes.id')
|
||||
->leftJoin('ordered_investigations', 'ordered_investigations.episode_id', '=', 'patient_episodes.id')
|
||||
->leftJoin('ordered_sundries', 'ordered_sundries.episode_id', '=', 'patient_episodes.id')
|
||||
->leftJoin('ordered_services', 'ordered_services.episode_id', '=', 'patient_episodes.id')
|
||||
->where($filters)
|
||||
->groupBy('patient_episodes.id')
|
||||
->whereBetween('patient_episodes.created_at', [$start_date, $end_date])
|
||||
->select('patient_episodes.id as episode_id', 'patient_episodes.patient_id', 'patients.first_name', 'patients.last_name', 'patients.date_of_birth', 'patients.number',
|
||||
'patients.phone', 'patients.category_id',
|
||||
'treatments.id as treatment_id', 'treatments.payment_status as treatment_payment_status', 'treatments.inpatient_bill_generated as treatment_is_inpatient',
|
||||
'ordered_procedures.id as procedure_id', 'ordered_procedures.payment_status as procedures_payment_status', 'ordered_procedures.inpatient_bill_generated as procedures_is_inpatient',
|
||||
'ordered_investigations.id as investigation_id', 'ordered_investigations.payment_status as investigation_payment_status', 'ordered_investigations.inpatient_bill_generated as invs_is_inpatient',
|
||||
'ordered_sundries.id as sundries_id', 'ordered_sundries.payment_status as sundries_payment_status', 'ordered_sundries.inpatient_bill_generated as sundry_is_inpatient',
|
||||
'ordered_services.id as service_id', 'ordered_services.payment_status as service_payment_status', 'ordered_services.inpatient_bill_generated as service_is_inpatient')
|
||||
->get();
|
||||
|
||||
$clinics = DB::table("clinics")->whereNull("deleted_at")->orderBy("name")->pluck("name", "id")->toArray();
|
||||
$clinics = [0 => 'OPD'] + ['' => '- select -'] + $clinics;
|
||||
|
||||
return view('finance::finance.incoming_opd_payments', compact('patient_categories', 'clinics', 'patient_episodes'));
|
||||
}
|
||||
}
|
||||
+635
@@ -0,0 +1,635 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Finance\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Streamline\Models\Banking;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\FixedAsset;
|
||||
use Streamline\Models\HospitalBill;
|
||||
use Streamline\Models\Payment;
|
||||
use Streamline\Models\Supplier;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
use Streamline\Models\TrackInvoice;
|
||||
use Streamline\Models\TrackReceipt;
|
||||
use Streamline\Models\Equity;
|
||||
|
||||
class FixedAssetsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:fixed-assets-list', ['only' => ['index']]);
|
||||
$this->middleware('permission:create-fixed-assets', ['only' => ['create', 'store']]);
|
||||
$this->middleware('permission:edit-fixed-assets', ['only' => ['edit', 'update']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$fixed_assets = FixedAsset::orderBy('name', 'asc')->get();
|
||||
$suppliers = DB::table('suppliers')->where('available', 1)->pluck("name", "id");
|
||||
return view('finance::fixed_assets.index', compact('fixed_assets', 'suppliers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$suppliers = Supplier::where('available', 1)->pluck('name', 'id')->toArray();
|
||||
$suppliers = ['' => '- select -'] + $suppliers;
|
||||
$fixed_asset_chart_of_accounts = ChartOfAccount::where(['type' => 3])->pluck('name', 'id')->toArray();/*4-fixed asset*/
|
||||
$fixed_asset_chart_of_accounts = ['' => '- select -'] + $fixed_asset_chart_of_accounts;
|
||||
$bank_chart_of_accounts = ChartOfAccount::where(['type' => 4])->pluck('name', 'id')->toArray();/*3-bank*/
|
||||
$bank_chart_of_accounts = ['' => '- select -'] + $bank_chart_of_accounts;
|
||||
$payable_accounts = ChartOfAccount::whereIn('type', [6, 9])->pluck('name', 'id')->toArray();
|
||||
|
||||
return view('finance::fixed_assets.create', compact('suppliers', 'fixed_asset_chart_of_accounts', 'bank_chart_of_accounts', 'payable_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'acquisition_date' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
|
||||
$fixed_asset = new FixedAsset;
|
||||
$fixed_asset->name = $request->name;
|
||||
$fixed_asset->serial_number = $request->serial_number;
|
||||
$fixed_asset->cost_price = $request->cost_price;
|
||||
$fixed_asset->acquisition_date = $acquisition_date = $request->acquisition_date != null ? Carbon::createFromFormat('d-m-Y', $request->acquisition_date)->toDateString() : null;
|
||||
$fixed_asset->item_condition = $request->item_condition;
|
||||
$fixed_asset->depreciation = $request->depreciation;
|
||||
$fixed_asset->supplier_id = $request->supplier;
|
||||
$fixed_asset->fixed_asset_account_id = $request->fixed_asset_account;
|
||||
$fixed_asset->warranty_expiration_date = $request->warranty_expiration_date != null ? Carbon::createFromFormat('d-m-Y', $request->warranty_expiration_date)->toDateString() : null;
|
||||
$fixed_asset->bank_account_id = $request->bank_account_id;
|
||||
$fixed_asset->description = $request->description;
|
||||
$fixed_asset->payment_type = $request->payment_type;
|
||||
$fixed_asset->created_by = Auth::id();
|
||||
|
||||
if ($fixed_asset->save()) {
|
||||
|
||||
if ($request->payment_type == 'cash') :
|
||||
|
||||
$current_bank_balance = get_latest_banking_record_based_on_transaction_date($request->bank_account_id, getTodayCarbon()->toDateString());
|
||||
|
||||
if (!is_null($current_bank_balance)) :
|
||||
|
||||
$balance_after_deduction = (int)$current_bank_balance->account_balance - (int)$request->amount_paid;
|
||||
$track_receipt = new TrackReceipt;
|
||||
$track_receipt->created_by = Auth::id();
|
||||
$track_receipt->reason = 'Fixed Asset Purchase';
|
||||
$track_receipt->save();
|
||||
$trans_id = sprintf("%04u", $track_receipt->id);
|
||||
|
||||
$last_insert_id_from_account = capture_bank_record(
|
||||
'PAYMENT',
|
||||
$acquisition_date,
|
||||
$request->bank_account_id,
|
||||
$request->fixed_asset_account,
|
||||
$balance_after_deduction,
|
||||
0,
|
||||
$request->cost_price,
|
||||
'Fixed Asset Purchase',
|
||||
$trans_id
|
||||
);
|
||||
|
||||
$fixed_asset->banking_id = $last_insert_id_from_account;
|
||||
$fixed_asset->save();
|
||||
|
||||
//update running bank balance
|
||||
update_banking_record_balances($acquisition_date, $request->bank_account_id, $last_insert_id_from_account, $balance_after_deduction);
|
||||
|
||||
if ($request->balance > 0) :
|
||||
// track the invoice
|
||||
$track_invoice = new TrackInvoice;
|
||||
$track_invoice->reason = (!is_null($request->description) ? $request->description : "Fixed Assets Creation");
|
||||
$track_invoice->created_by = Auth::id();
|
||||
$track_invoice->save();
|
||||
$invoice_number = sprintf("%04u", $track_invoice->id);
|
||||
|
||||
$bill = new HospitalBill;
|
||||
$bill->vendor = $request->supplier;
|
||||
$bill->bill_date = $acquisition_date;
|
||||
$bill->bill_memo = $request->description;
|
||||
$bill->bill_number = $invoice_number;
|
||||
$bill->total_amount = $request->balance;
|
||||
$bill->item_ids = $fixed_asset->id;
|
||||
$bill->item_accounts = $request->fixed_asset_account;
|
||||
$bill->item_quantities = 1;
|
||||
$bill->item_subtotals = $request->balance;
|
||||
$bill->payable_account = $request->payable_account;
|
||||
$bill->account_type = 3;
|
||||
$bill->created_by = Auth::id();
|
||||
$bill->bill_type = 'ASSETS';
|
||||
|
||||
$bill->balance_history = serialize(array());
|
||||
$bill->receipt_history = serialize(array());
|
||||
$bill->staff_incharge_history = serialize(array());
|
||||
$bill->amount_paid_history = serialize(array());
|
||||
$bill->date_paid_history = serialize(array());
|
||||
|
||||
$bill->save();
|
||||
endif;
|
||||
|
||||
else :
|
||||
|
||||
flash('error occured. contact system admin')->error();
|
||||
return redirect()->back()->withInput();
|
||||
endif;
|
||||
|
||||
elseif ($request->payment_type == 'bill') :
|
||||
// track the invoice
|
||||
$track_invoice = new TrackInvoice;
|
||||
$track_invoice->reason = (!is_null($request->description) ? $request->description : "Fixed Assets Creation");
|
||||
$track_invoice->created_by = Auth::id();
|
||||
$track_invoice->save();
|
||||
$invoice_number = sprintf("%04u", $track_invoice->id);
|
||||
|
||||
$bill = new HospitalBill;
|
||||
$bill->vendor = $request->supplier;
|
||||
$bill->bill_date = $acquisition_date;
|
||||
$bill->bill_memo = $request->description;
|
||||
$bill->bill_number = $invoice_number;
|
||||
$bill->total_amount = $request->cost_price;
|
||||
$bill->item_ids = $fixed_asset->id;
|
||||
$bill->item_accounts = $request->fixed_asset_account;
|
||||
$bill->item_quantities = 1;
|
||||
$bill->item_subtotals = $request->cost_price;
|
||||
$bill->payable_account = $request->payable_account;
|
||||
$bill->account_type = 3;
|
||||
$bill->created_by = Auth::id();
|
||||
$bill->bill_type = 'ASSETS';
|
||||
|
||||
$bill->balance_history = serialize(array());
|
||||
$bill->receipt_history = serialize(array());
|
||||
$bill->staff_incharge_history = serialize(array());
|
||||
$bill->amount_paid_history = serialize(array());
|
||||
$bill->date_paid_history = serialize(array());
|
||||
|
||||
$bill->save();
|
||||
|
||||
elseif ($request->payment_type == 'asset_exists') :
|
||||
// Update the opening_fixed_assets Equity Account
|
||||
$opening_fixed_assets = ChartOfAccount::where(['slug' => 'opening_fixed_assets'])->first();
|
||||
$opening_fixed_assets_balance = $opening_fixed_assets->balance;
|
||||
$opening_fixed_assets->balance = $opening_fixed_assets_balance + $request->cost_price;
|
||||
$opening_fixed_assets->updated_by = Auth::id();
|
||||
$opening_fixed_assets->update();
|
||||
|
||||
$equity = new Equity;
|
||||
$equity->name = $fixed_asset->name;
|
||||
$equity->amount = $request->cost_price;
|
||||
$equity->account_id = $opening_fixed_assets->id;
|
||||
$equity->created_by = Auth::id();
|
||||
$equity->updated_by = Auth::id();
|
||||
$equity->save();
|
||||
endif;
|
||||
|
||||
flash($fixed_asset->name . ' has been saved')->success();
|
||||
return redirect('fixed_assets');
|
||||
}
|
||||
flash('error occured. contact system admin')->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$fixed_asset = FixedAsset::find($id);
|
||||
$suppliers = Supplier::where('available', 1)->pluck('name', 'id')->toArray();
|
||||
$suppliers = ['' => '- select -'] + $suppliers;
|
||||
$fixed_asset_chart_of_accounts = ChartOfAccount::where(['type' => 3])->pluck('name', 'id')->toArray();/*4-fixed asset*/
|
||||
$fixed_asset_chart_of_accounts = ['' => '- select -'] + $fixed_asset_chart_of_accounts;
|
||||
$bank_chart_of_accounts = ChartOfAccount::where(['type' => 4])->pluck('name', 'id')->toArray();/*3-bank*/
|
||||
$bank_chart_of_accounts = ['' => '- select -'] + $bank_chart_of_accounts;
|
||||
$payable_accounts = ChartOfAccount::whereIn('type', [6, 9])->pluck('name', 'id')->toArray();
|
||||
|
||||
return view('finance::fixed_assets.edit', compact('suppliers', 'fixed_asset_chart_of_accounts', 'bank_chart_of_accounts', 'fixed_asset', 'payable_accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'acquisition_date' => 'required',
|
||||
'warranty_expiration_date' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
flash($string)->error();
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
//1. check if payment type's been edited
|
||||
//2. if it is a bill, ensure that the bill does not have a payment else reject
|
||||
//3. if already existing, do adjustments in equities
|
||||
//4. if cash, check if all was paid then check for the bill created for unpaid balance
|
||||
$hospital_bill = null;
|
||||
if ($request->edit_payment_type == 1) {
|
||||
$hospital_bill = HospitalBill::where(['item_ids' => $id, 'bill_type' => 'ASSETS'])->first();
|
||||
|
||||
$amount_paid_history_array = unserialize($hospital_bill->amount_paid_history);
|
||||
if (count($amount_paid_history_array) > 0) {
|
||||
//bill has a paid payment so can not be edited
|
||||
flash('Bill has some payments so first undo the payments')->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
}
|
||||
//dd($request->all());
|
||||
$acquisition_date = Carbon::parse($request->acquisition_date)->toDateString();
|
||||
|
||||
$fixed_asset = FixedAsset::find($id);
|
||||
|
||||
$previous_acquisition_date = $fixed_asset->acquisition_date;
|
||||
$previous_asset_name = $fixed_asset->name;
|
||||
$previous_bank_account_id = $fixed_asset->bank_account_id;
|
||||
$previous_cost_price = $fixed_asset->cost_price;
|
||||
$previous_asset_account = $fixed_asset->fixed_asset_account_id;
|
||||
|
||||
$fixed_asset->name = $request->name;
|
||||
$fixed_asset->serial_number = $request->serial_number;
|
||||
$fixed_asset->cost_price = $request->cost_price;
|
||||
$fixed_asset->acquisition_date = $acquisition_date;
|
||||
$fixed_asset->item_condition = $request->item_condition;
|
||||
$fixed_asset->supplier_id = $request->supplier;
|
||||
$fixed_asset->depreciation = $request->depreciation;
|
||||
$fixed_asset->fixed_asset_account_id = $request->fixed_asset_account;
|
||||
$fixed_asset->warranty_expiration_date = Carbon::parse($request->warranty_expiration_date)->toDateString();
|
||||
$fixed_asset->bank_account_id = $request->bank_account_id;
|
||||
$fixed_asset->description = $request->description;
|
||||
$fixed_asset->created_by = Auth::id();
|
||||
|
||||
//if the payment has been edited then we do
|
||||
if ($request->edit_payment_type == 1) {
|
||||
//payment type has not changed so handle accordingly
|
||||
if ($fixed_asset->payment_type == $request->payment_type) {
|
||||
# if it has a bill or bank and has no payment then adjust amount, if exisiting asset adjust the equity
|
||||
if ($fixed_asset->payment_type == "bill") {
|
||||
// track the invoice
|
||||
$track_invoice = new TrackInvoice;
|
||||
$track_invoice->reason = (!is_null($request->description) ? $request->description : "Fixed Assets Creation");
|
||||
$track_invoice->created_by = Auth::id();
|
||||
$track_invoice->save();
|
||||
$invoice_number = sprintf("%04u", $track_invoice->id);
|
||||
|
||||
$bill = HospitalBill::where(['item_ids' => $id, 'bill_type' => 'ASSETS'])->first();
|
||||
$bill->vendor = $request->supplier;
|
||||
$bill->bill_date = $fixed_asset->acquisition_date;
|
||||
$bill->bill_memo = $request->description;
|
||||
$bill->bill_number = $invoice_number;
|
||||
$bill->total_amount = $request->balance;
|
||||
$bill->item_ids = $fixed_asset->id;
|
||||
$bill->item_accounts = $request->fixed_asset_account;
|
||||
$bill->item_quantities = 1;
|
||||
$bill->item_subtotals = $request->balance;
|
||||
$bill->payable_account = $request->payable_account;
|
||||
$bill->account_type = 3;
|
||||
$bill->created_by = Auth::id();
|
||||
$bill->bill_type = 'ASSETS';
|
||||
|
||||
$bill->balance_history = serialize(array());
|
||||
$bill->receipt_history = serialize(array());
|
||||
$bill->staff_incharge_history = serialize(array());
|
||||
$bill->amount_paid_history = serialize(array());
|
||||
$bill->date_paid_history = serialize(array());
|
||||
$bill->save();
|
||||
} elseif ($fixed_asset->payment_type == "cash" && ($fixed_asset->cost_price != $previous_cost_price)) {
|
||||
//but first check it the money has changed
|
||||
$banking_record = Banking::where(["bank" => $previous_bank_account_id, "debit" => $previous_cost_price, "memo" => "Fixed Asset Purchase", "trans_date" => $previous_acquisition_date])->first();
|
||||
|
||||
if ($banking_record) {
|
||||
$banking_record->trans_date = $acquisition_date;
|
||||
$banking_record->bank = $request->bank_account_id;
|
||||
$banking_record->credit = $request->amount_paid;
|
||||
$current_bank_balance_record = get_latest_banking_record_based_on_transaction_date($request->bank_account_id, getTodayCarbon()->toDateString());
|
||||
$balance_after_deduction = is_null($current_bank_balance_record) ? 0 : (int)$current_bank_balance_record->account_balance - (int)$request->amount_paid;
|
||||
$banking_record->account_balance = $balance_after_deduction;
|
||||
$banking_record->update();
|
||||
}
|
||||
|
||||
//remember to re-calculate the running balance of this bank
|
||||
update_banking_record_balances($acquisition_date, $request->bank_account_id, $banking_record, $balance_after_deduction);
|
||||
|
||||
// track the invoice
|
||||
$track_invoice = new TrackInvoice;
|
||||
$track_invoice->reason = (!is_null($request->description) ? $request->description : "Fixed Assets Creation");
|
||||
$track_invoice->created_by = Auth::id();
|
||||
$track_invoice->save();
|
||||
$invoice_number = sprintf("%04u", $track_invoice->id);
|
||||
|
||||
//If the balance is more, find existing bill and adjust figures or create a new bill
|
||||
$hospital_bill = HospitalBill::where(['item_ids' => $id,'bill_type'=>'ASSETS'])->first();
|
||||
$bill = is_null($hospital_bill) ? new HospitalBill : $hospital_bill;
|
||||
|
||||
$bill->vendor = $request->supplier;
|
||||
$bill->bill_date = $acquisition_date;
|
||||
$bill->bill_memo = $request->description;
|
||||
$bill->bill_number = $invoice_number;
|
||||
$bill->total_amount = $request->balance;
|
||||
$bill->item_ids = $fixed_asset->id;
|
||||
$bill->item_accounts = $request->fixed_asset_account;
|
||||
$bill->item_quantities = 1;
|
||||
$bill->item_subtotals = $request->balance;
|
||||
$bill->payable_account = $request->payable_account;
|
||||
$bill->account_type = 3;
|
||||
$bill->created_by = Auth::id();
|
||||
$bill->bill_type = 'ASSETS';
|
||||
|
||||
$bill->balance_history = serialize(array());
|
||||
$bill->receipt_history = serialize(array());
|
||||
$bill->staff_incharge_history = serialize(array());
|
||||
$bill->amount_paid_history = serialize(array());
|
||||
$bill->date_paid_history = serialize(array());
|
||||
|
||||
$bill->save();
|
||||
} elseif ($fixed_asset->payment_type == "asset_exists") {
|
||||
$equity = Equity::where(['account_id' => $previous_asset_account, 'name' => $previous_asset_name, 'amount' => $previous_cost_price])->first();
|
||||
|
||||
// Update the opening_fixed_assets Equity Account
|
||||
$opening_fixed_assets = ChartOfAccount::where(['slug' => 'opening_fixed_assets'])->first();
|
||||
$opening_fixed_assets_balance = $opening_fixed_assets->balance;
|
||||
$opening_fixed_assets->balance = $opening_fixed_assets_balance + $request->cost_price;
|
||||
$opening_fixed_assets->updated_by = Auth::id();
|
||||
$opening_fixed_assets->update();
|
||||
|
||||
$equity->name = $fixed_asset->name;
|
||||
$equity->amount = $request->cost_price;
|
||||
$equity->account_id = $opening_fixed_assets->id;
|
||||
$equity->updated_by = Auth::id();
|
||||
$equity->save();
|
||||
}
|
||||
}
|
||||
|
||||
//payment type has changed deal with new payment type and old payment type too
|
||||
else {
|
||||
// if the previous payment type is bill and the payment type has changed then delete the bill
|
||||
if ($fixed_asset->payment_type == "bill") {
|
||||
$hospital_bill->delete();
|
||||
}
|
||||
|
||||
// if previous payment was already existing and payment has changed then delete equity and update chart of account with deduction
|
||||
if ($fixed_asset->payment_type == "asset_exists") {
|
||||
$equity = Equity::where(['account_id' => $previous_asset_account, 'name' => $previous_asset_name, 'amount' => $previous_cost_price])->first();
|
||||
$equity->delete();
|
||||
|
||||
$opening_fixed_assets = ChartOfAccount::where(['slug' => 'opening_fixed_assets'])->first();
|
||||
$opening_fixed_assets->balance = $opening_fixed_assets->balance - $fixed_asset->cost_price;
|
||||
$opening_fixed_assets->updated_by = Auth::id();
|
||||
$opening_fixed_assets->update();
|
||||
}
|
||||
|
||||
//if previous payment was cash and payment has changed then increase the balance of the bank the asset was paid from
|
||||
if ($fixed_asset->payment_type == "cash") {
|
||||
$track_receipt = new TrackReceipt;
|
||||
$track_receipt->created_by = Auth::id();
|
||||
$track_receipt->reason = 'Fixed Asset Purchase Edit';
|
||||
$track_receipt->save();
|
||||
$trans_id = sprintf("%04u", $track_receipt->id);
|
||||
|
||||
$current_bank_balance = get_latest_banking_record_based_on_transaction_date($previous_bank_account_id, getTodayCarbon()->toDateString());
|
||||
if (!is_null($current_bank_balance)) :
|
||||
|
||||
$balance_after_addition = (int)$current_bank_balance->account_balance + (int)$fixed_asset->amount_paid;
|
||||
endif;
|
||||
|
||||
$last_insert_id_from_account = capture_bank_record(
|
||||
'DEPOSIT',
|
||||
$fixed_asset->acquisition_date,
|
||||
$previous_bank_account_id,
|
||||
$fixed_asset->fixed_asset_account_id,
|
||||
$balance_after_addition,
|
||||
$previous_cost_price,
|
||||
0,
|
||||
'Fixed Asset Purchase Edit',
|
||||
$trans_id
|
||||
);
|
||||
|
||||
update_banking_record_balances($fixed_asset->acquisition_date, $previous_bank_account_id, $last_insert_id_from_account, $balance_after_addition);
|
||||
}
|
||||
|
||||
//deal with the new selected payment type
|
||||
if ($request->payment_type == 'cash') :
|
||||
|
||||
$current_bank_balance = get_latest_banking_record_based_on_transaction_date($request->bank_account_id, getTodayCarbon()->toDateString());
|
||||
|
||||
if (!is_null($current_bank_balance)) :
|
||||
|
||||
$balance_after_deduction = (int)$current_bank_balance->account_balance - (int)$request->amount_paid;
|
||||
$track_receipt = new TrackReceipt;
|
||||
$track_receipt->created_by = Auth::id();
|
||||
$track_receipt->reason = 'Fixed Asset Purchase';
|
||||
$track_receipt->save();
|
||||
$trans_id = sprintf("%04u", $track_receipt->id);
|
||||
|
||||
$last_insert_id_from_account = capture_bank_record(
|
||||
'PAYMENT',
|
||||
$fixed_asset->acquisition_date,
|
||||
$request->bank_account_id,
|
||||
$request->fixed_asset_account,
|
||||
$balance_after_deduction,
|
||||
0,
|
||||
$request->cost_price,
|
||||
'Fixed Asset Purchase',
|
||||
$trans_id
|
||||
);
|
||||
|
||||
update_banking_record_balances($fixed_asset->acquisition_date, $request->bank_account_id, $last_insert_id_from_account, $balance_after_deduction);
|
||||
|
||||
if ($request->balance > 0) :
|
||||
// track the invoice
|
||||
$track_invoice = new TrackInvoice;
|
||||
$track_invoice->reason = (!is_null($request->description) ? $request->description : "Fixed Assets Creation");
|
||||
$track_invoice->created_by = Auth::id();
|
||||
$track_invoice->save();
|
||||
$invoice_number = sprintf("%04u", $track_invoice->id);
|
||||
|
||||
$bill = new HospitalBill;
|
||||
$bill->vendor = $request->supplier;
|
||||
$bill->bill_date = $fixed_asset->acquisition_date;
|
||||
$bill->bill_memo = $request->description;
|
||||
$bill->bill_number = $invoice_number;
|
||||
$bill->total_amount = $request->balance;
|
||||
$bill->item_ids = $fixed_asset->id;
|
||||
$bill->item_accounts = $request->fixed_asset_account;
|
||||
$bill->item_quantities = 1;
|
||||
$bill->item_subtotals = $request->balance;
|
||||
$bill->payable_account = $request->payable_account;
|
||||
$bill->account_type = 3;
|
||||
$bill->created_by = Auth::id();
|
||||
$bill->bill_type = 'ASSETS';
|
||||
|
||||
$bill->balance_history = serialize(array());
|
||||
$bill->receipt_history = serialize(array());
|
||||
$bill->staff_incharge_history = serialize(array());
|
||||
$bill->amount_paid_history = serialize(array());
|
||||
$bill->date_paid_history = serialize(array());
|
||||
|
||||
$bill->save();
|
||||
endif;
|
||||
|
||||
else :
|
||||
|
||||
flash('error occured. contact system admin')->error();
|
||||
return redirect()->back()->withInput();
|
||||
endif;
|
||||
|
||||
elseif ($request->payment_type == 'asset_exists') :
|
||||
// Update the opening_fixed_assets Equity Account
|
||||
$opening_fixed_assets = ChartOfAccount::where(['slug' => 'opening_fixed_assets'])->first();
|
||||
$opening_fixed_assets_balance = $opening_fixed_assets->balance;
|
||||
$opening_fixed_assets->balance = $opening_fixed_assets_balance + $request->cost_price;
|
||||
$opening_fixed_assets->updated_by = Auth::id();
|
||||
$opening_fixed_assets->update();
|
||||
|
||||
$equity = new Equity;
|
||||
$equity->name = $fixed_asset->name;
|
||||
$equity->amount = $request->cost_price;
|
||||
$equity->account_id = $opening_fixed_assets->id;
|
||||
$equity->created_by = Auth::id();
|
||||
$equity->updated_by = Auth::id();
|
||||
$equity->save();
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
if ($fixed_asset->update()) {
|
||||
flash($fixed_asset->name . ' has been updated')->success();
|
||||
return redirect('fixed_assets');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$fixed_asset = FixedAsset::find($id);
|
||||
|
||||
$bill = HospitalBill::where(['item_ids' => $id, 'bill_type' => 'ASSETS'])->first();
|
||||
|
||||
if ($bill) {
|
||||
if (is_null($bill->balance)) {
|
||||
# no money has been paid on this bill so delete it
|
||||
$bill->delete();
|
||||
} elseif ($bill->total_amount > 0) {
|
||||
# reverse the partial payment back to the respective bank then delete the bill
|
||||
$payments = Payment::where('bill_id', $bill->id)->get();
|
||||
|
||||
foreach ($payments as $payment) {
|
||||
$delete_result = delete_hospital_bill_payment($payment->id);
|
||||
}
|
||||
|
||||
# finally the bill with the fixed asset
|
||||
$bill->delete();
|
||||
}
|
||||
}
|
||||
|
||||
if ($fixed_asset->payment_type == 'cash') {
|
||||
if (is_null($fixed_asset->banking_id)) {
|
||||
$current_bank_balance = get_latest_banking_record_based_on_transaction_date($fixed_asset->bank_account_id, getTodayCarbon()->toDateString());
|
||||
|
||||
if (!is_null($current_bank_balance)) {
|
||||
$balance_after_deduction = (int)$current_bank_balance->account_balance + (int)$fixed_asset->cost_price;
|
||||
|
||||
$track_receipt = new TrackReceipt;
|
||||
$track_receipt->created_by = Auth::id();
|
||||
$track_receipt->reason = 'Fixed Asset Purchase Deletion';
|
||||
$track_receipt->save();
|
||||
$trans_id = sprintf("%04u", $track_receipt->id);
|
||||
|
||||
$last_insert_id = capture_bank_record('DEPOSIT', getTodayCarbon()->toDateString(), $fixed_asset->bank_account_id, $fixed_asset->fixed_asset_account_id,
|
||||
$balance_after_deduction, $fixed_asset->cost_price, 0, 'Fixed Asset Purchase Deletion', $trans_id);
|
||||
|
||||
update_banking_record_balances(date('Y-m-d'), $fixed_asset->bank_account_id, $last_insert_id, $balance_after_deduction);
|
||||
}
|
||||
} else {
|
||||
$bank_record = Banking::find($fixed_asset->banking_id);
|
||||
|
||||
if ($bank_record) {
|
||||
$bank_record->account_balance = $bank_record->account_balance + $fixed_asset->cost_price;
|
||||
$bank_record->debit = 0;
|
||||
$bank_record->update();
|
||||
|
||||
update_banking_record_balances($bank_record->trans_date, $fixed_asset->bank_account_id, $fixed_asset->banking_id, $bank_record->account_balance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($fixed_asset->delete()) {
|
||||
flash($fixed_asset->name . ' has been deleted')->success();
|
||||
return redirect('fixed_assets');
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
public function is_fixed_asset_attached_to_bill(Request $request)
|
||||
{
|
||||
$fixed_asset = FixedAsset::find($request->fixed_asset_id);
|
||||
|
||||
$bill = HospitalBill::where(['item_ids' => $fixed_asset->id, 'bill_type' => 'ASSETS'])->first();
|
||||
|
||||
if ($bill) {
|
||||
if ($bill->total_amount > 0) {
|
||||
return "has_attached_bill";
|
||||
}
|
||||
}
|
||||
|
||||
return "no_attached_bill";
|
||||
}
|
||||
}
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Finance\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Streamline\Models\MarkupTag;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Streamline\Models\Drug;
|
||||
use Streamline\Models\Sundry;
|
||||
|
||||
|
||||
class MarkupTagController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$markup_tags = MarkupTag::orderBy('name','asc')->get();
|
||||
return view('finance::markup_tags.index',compact('markup_tags'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('finance::markup_tags.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$string = "";
|
||||
foreach ($validator->errors()->getMessages() as $item) {
|
||||
$string .= "{$item[0]}<br>";
|
||||
}
|
||||
return back()->withErrors($validator)->withInput();
|
||||
} else {
|
||||
$markup = new MarkupTag;
|
||||
$markup->name = $request->name;
|
||||
$markup->percentage = $request->percentage;
|
||||
$markup->created_by = auth()->user()->id;
|
||||
if ($markup->save()) {
|
||||
flash('successfully saved markup')->success();
|
||||
return redirect('markup_tag');
|
||||
}
|
||||
flash('Error in saving new markup. Contact system admin')->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$tag = MarkupTag::find($id);
|
||||
|
||||
if (!$tag) {
|
||||
flash()->error("There is no such bed category");
|
||||
return redirect('markup_tag');
|
||||
} else {
|
||||
return view('finance::markup_tags.edit', compact('tag'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$tag = MarkupTag::find($id);
|
||||
$tag->update($request->all());
|
||||
flash('successfully updated details for '.$tag->name)->success();
|
||||
return redirect('markup_tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$tag = MarkupTag::find($id);
|
||||
if ($tag->delete()) {
|
||||
flash($tag->name. ' has been successfully deleted')->success();
|
||||
return redirect('markup_tag');
|
||||
}
|
||||
flash('error occurred. Contact system admin')->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
/*
|
||||
*Display inactive markup
|
||||
*/
|
||||
public function inactive()
|
||||
{
|
||||
$tags = MarkupTag::onlyTrashed()->orderBy('name','asc')->paginate(50);
|
||||
|
||||
if (count($tags) < 1) {
|
||||
flash()->error("There is no inactive occupation");
|
||||
return redirect('markup_tag');
|
||||
} else {
|
||||
return view('finance::markup_tags.inactive', compact('tags'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Activate an inactive
|
||||
*/
|
||||
public function activate($id)
|
||||
{
|
||||
$tag = MarkupTag::withTrashed()->find($id);
|
||||
|
||||
if ($tag->restore()):
|
||||
flash("Tag has been activated.")->success();
|
||||
return redirect('/inactive/markup_tag/');
|
||||
endif;
|
||||
}
|
||||
|
||||
/* Add markups to drugs */
|
||||
public function add_markups_to_drugs(Request $request)
|
||||
{
|
||||
$tags = MarkupTag::orderBy('name', 'asc')->get();
|
||||
$tags_select = MarkupTag::pluck('name','id')->toArray();
|
||||
$tags_select = ['' => '- Select Markup -'] + $tags_select;
|
||||
$drugs = DB::table('drugs')->where('available', 1)->whereNull('deleted_at')->orderBy('name', 'asc')->get();
|
||||
$tags_array = MarkupTag::pluck('name','id')->toArray();
|
||||
$names_array = Drug::where('available', 1)->orderby('name')->distinct()->pluck('name');
|
||||
return view('finance::markup_tags.add_markups_to_drugs', compact('tags','tags_select','drugs','tags_array','names_array'));
|
||||
}
|
||||
|
||||
/* Apply mark ups to drugs */
|
||||
public function update_mark_up_to_drug(Request $request)
|
||||
{
|
||||
$markup_tag_id = $request->markup_tag;
|
||||
$markup_tag = MarkupTag::find($markup_tag_id);
|
||||
if (!is_null($markup_tag)) {
|
||||
$markup_percentage = $markup_tag->percentage;
|
||||
|
||||
//use the markup percentage to calculate and set the selling price of the checked drugs
|
||||
$checked_drug_array = $request->checked_drug;
|
||||
for ($i=0; $i < count($checked_drug_array) ; $i++) {
|
||||
$drug = Drug::find($checked_drug_array[$i]);
|
||||
if (!is_null($drug)) {
|
||||
if ($drug->cost_price != 0) { /* add this to avoid */
|
||||
$markup = ($markup_percentage/100) * $drug->cost_price;
|
||||
$selling_price = $drug->cost_price + $markup;
|
||||
$drug->non_insured_price = $selling_price;
|
||||
$drug->markup_tag_id = $markup_tag_id;
|
||||
$price_has_been_updated = $drug->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($price_has_been_updated)) {
|
||||
flash("Drug selling prices have been updated with the new markup")->success();
|
||||
return redirect('stores');
|
||||
}
|
||||
|
||||
flash("Something went wrong. Contact your IT personel for help")->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
/* drug search */
|
||||
public function drug_markup_search(Request $request)
|
||||
{
|
||||
$drugs = DB::select("select * from drugs where deleted_at IS NULL AND name like '%".$request->drug_name."%' ORDER BY name ASC");
|
||||
$names_array = Drug::where('available', 1)->orderby('name')->distinct()->pluck('name');
|
||||
$tags = MarkupTag::orderBy('name', 'asc')->get();
|
||||
$tags_select = MarkupTag::pluck('name','id')->toArray();
|
||||
$tags_select = ['' => '- Select Markup -'] + $tags_select;
|
||||
//$drugs = DB::table('drugs')->whereNull('deleted_at')->orderBy('name', 'asc')->get();
|
||||
$tags_array = MarkupTag::pluck('name','id')->toArray();
|
||||
|
||||
return view('finance::markup_tags.add_markups_to_drugs', compact('names_array','tags','tags_select','drugs','tags_array'));
|
||||
}
|
||||
|
||||
/* view drugs of selected markup tag */
|
||||
public function view_markup_drugs($id)
|
||||
{
|
||||
$drugs = Drug::where('markup_tag_id',$id)->orderBy('name')->get();
|
||||
$tag = MarkupTag::find($id);
|
||||
return view('finance::markup_tags.view_drugs_of_a_markup', compact('drugs','tag'));
|
||||
}
|
||||
|
||||
/* Add markups to sundries */
|
||||
public function add_markups_to_sundries(Request $request)
|
||||
{
|
||||
$tags = MarkupTag::orderBy('name', 'asc')->get();
|
||||
$tags_select = MarkupTag::pluck('name','id')->toArray();
|
||||
$tags_select = ['' => '- Select Markup -'] + $tags_select;
|
||||
$sundries = DB::table('sundries')->whereNull('deleted_at')->orderBy('name', 'asc')->get();
|
||||
$tags_array = MarkupTag::pluck('name','id')->toArray();
|
||||
$names_array = Sundry::where('available', 1)->orderby('name')->distinct()->pluck('name');
|
||||
return view('finance::markup_tags.add_markups_to_sundries', compact('tags','tags_select','sundries','tags_array','names_array'));
|
||||
}
|
||||
|
||||
/* Apply mark ups to sundries */
|
||||
public function update_mark_up_to_sundry(Request $request)
|
||||
{
|
||||
$markup_tag_id = $request->markup_tag;
|
||||
$markup_tag = MarkupTag::find($markup_tag_id);
|
||||
if (!is_null($markup_tag)) {
|
||||
$markup_percentage = $markup_tag->percentage;
|
||||
|
||||
//use the markup percentage to calculate and set the selling price of the checked sundries
|
||||
$checked_sundry_array = $request->checked_sundry;
|
||||
for ($i=0; $i < count($checked_sundry_array) ; $i++) {
|
||||
$sundry = Sundry::find($checked_sundry_array[$i]);
|
||||
if (!is_null($sundry)) {
|
||||
if ($sundry->cost_price != 0) { /* add this to avoid division by zero */
|
||||
$markup = ($markup_percentage/100) * $sundry->cost_price;
|
||||
$selling_price = $sundry->cost_price + $markup;
|
||||
$sundry->non_insured_price = $selling_price;
|
||||
$sundry->markup_tag_id = $markup_tag_id;
|
||||
$price_has_been_updated = $sundry->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($price_has_been_updated)) {
|
||||
flash("Sundry selling prices have been updated with the new markup")->success();
|
||||
return redirect('sundries_stock_sheet');
|
||||
}
|
||||
|
||||
flash("Make sure the cost price is not 0 else something went wrong. Contact your IT personel for help")->error();
|
||||
return redirect()->back()->withInput();
|
||||
}
|
||||
|
||||
/* sundry search */
|
||||
public function sundry_markup_search(Request $request)
|
||||
{
|
||||
$sundries = DB::select("select * from sundries where deleted_at IS NULL AND name like '%".$request->sundry_name."%' ORDER BY name ASC");
|
||||
$names_array = Sundry::where('available', 1)->orderby('name')->distinct()->pluck('name');
|
||||
$tags = MarkupTag::orderBy('name', 'asc')->get();
|
||||
$tags_select = MarkupTag::pluck('name','id')->toArray();
|
||||
$tags_select = ['' => '- Select Markup -'] + $tags_select;
|
||||
$tags_array = MarkupTag::pluck('name','id')->toArray();
|
||||
|
||||
return view('finance::markup_tags.add_markups_to_sundries', compact('names_array','tags','tags_select','sundries','tags_array'));
|
||||
}
|
||||
}
|
||||
Executable
+1076
File diff suppressed because it is too large
Load Diff
+150
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Finance\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Streamline\Models\ChartOfAccount;
|
||||
use Streamline\Models\HospitalInformation;
|
||||
use Streamline\Models\Patient;
|
||||
use Streamline\Models\PatientEpisode;
|
||||
use Streamline\Models\PaymentItem;
|
||||
use Streamline\Models\StreamlineBillReport;
|
||||
|
||||
class StreamlineBillsController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:streamline-bills-create');
|
||||
$this->middleware('permission:streamline-bills-index');
|
||||
}
|
||||
|
||||
public function index(){
|
||||
$reports = StreamlineBillReport::all();
|
||||
$hospital_information = HospitalInformation::first();
|
||||
return view('finance::streamline_bills.index', compact('reports', 'hospital_information'));
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$episodes = [];
|
||||
$patients = [];
|
||||
$user = Auth::id();
|
||||
$date_string = '';
|
||||
$patient_string = '';
|
||||
$report = new StreamlineBillReport;
|
||||
$hospital_information = HospitalInformation::first();
|
||||
|
||||
return view('finance::streamline_bills.create', compact( 'hospital_information','user', 'episodes', 'patients', 'date_string',
|
||||
'patient_string', 'patients'));
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$user = Auth::id();
|
||||
$report = StreamlineBillReport::where('id', $id)->first();
|
||||
$hospital_information = HospitalInformation::first();
|
||||
|
||||
return view('finance::streamline_bills.detail', compact( 'hospital_information', 'report', 'user'));
|
||||
}
|
||||
|
||||
public function generate(Request $request){
|
||||
$user = Auth::id();
|
||||
$patients = [];
|
||||
$report = new StreamlineBillReport;
|
||||
$hospital_information = HospitalInformation::first();
|
||||
|
||||
if($request->dates == "yesterday") {
|
||||
$start = Carbon::yesterday()->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::yesterday()->endOfDay()->toDateTimeString();
|
||||
} else if($request->dates == "custom_date") {
|
||||
$start = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::parse($request->start_date)->endOfDay()->toDateTimeString();
|
||||
} else if($request->dates == "custom_date_range") {
|
||||
$start = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
|
||||
} else {
|
||||
$start = Carbon::today()->startOfDay()->toDateTimeString();
|
||||
$end = Carbon::today()->endOfDay()->toDateTimeString();
|
||||
}
|
||||
|
||||
$dates = array($start, $end);
|
||||
$date_string = implode('&', $dates);
|
||||
$episodes = PatientEpisode::whereBetween('created_at', [$start, $end])->groupBy('patient_id')->get();
|
||||
foreach ($episodes as $item){
|
||||
$patient = Patient::where('id', $item->patient_id)->whereNotIn('id', findTestOrDemoPatients())->whereBetween('created_at', [$start, $end])->first();
|
||||
if(isset($patient->number)){
|
||||
array_push($patients, $patient->id);
|
||||
}
|
||||
}
|
||||
|
||||
$patient_string = implode('/', $patients);
|
||||
$report_check = StreamlineBillReport::where('patients', '=', $patient_string)->first();
|
||||
if($report_check === null){
|
||||
$report->patients = $patient_string;
|
||||
$report->time_frame = $date_string;
|
||||
$report->type = 3;
|
||||
$report->created_by = Auth::id();
|
||||
$report->save();
|
||||
}
|
||||
|
||||
return view('finance::streamline_bills.create', compact( 'hospital_information','user', 'dates',
|
||||
'episodes', 'request', 'patients', 'date_string', 'patient_string'));
|
||||
}
|
||||
|
||||
public function transfer(Request $request){
|
||||
|
||||
$result = StreamlineBillReport::where('patients', $request->patient_string)->update([
|
||||
'amount_to_be_paid'=>$request->total,
|
||||
'amount_paid'=>0
|
||||
]);
|
||||
|
||||
$current_balance = ChartOfAccount::where('id', 14)->pluck('balance')->first();
|
||||
$transfer = ChartOfAccount::where('id', 14)->update(['balance' => ((int)$request->total + $current_balance)]);
|
||||
$total_amount_transfer = ((int)$request->total);
|
||||
$deposit_on_item = PaymentItem::where('name', 'streamline bill')->update(['unit_cost'=> $total_amount_transfer]);
|
||||
|
||||
if($transfer == 1 && $deposit_on_item == 1){
|
||||
flash('Streamline Bill Transfer was Successful')->success();
|
||||
}else{
|
||||
flash('Streamline Bill Transfer Failed')->error();
|
||||
}
|
||||
|
||||
return redirect('/streamline_bill');
|
||||
}
|
||||
|
||||
public function view_patients(Request $request){
|
||||
$patients_string = StreamlineBillReport::where('id', $request->id)->pluck('patients')->first();
|
||||
$patients = explode("/", $patients_string);
|
||||
$display = "";
|
||||
foreach ($patients as $patient){
|
||||
$display .= "<li>".get_full_name($patient, 'id', 'first_name', 'last_name', 'patients')."</li>";
|
||||
}
|
||||
return $display;
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
$streamline_bill = StreamlineBillReport::find($id);
|
||||
|
||||
if ($streamline_bill->delete()):
|
||||
flash("Streamline Bill has been deleted.")->success();
|
||||
return redirect('/streamline_bill/');
|
||||
endif;
|
||||
}
|
||||
|
||||
public function verify_patients($patient_id){
|
||||
$reports = StreamlineBillReport::all();
|
||||
foreach($reports as $item){
|
||||
$patient_array = explode('/', $item['patients']);
|
||||
for($i = 0; $i < count($patient_array); $i++){
|
||||
if($patient_array[$i] == $patient_id){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
return $patient_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user