mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 03:01:32 +00:00
updated streamline-setup v2
This commit is contained in:
+200
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user