mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
All kinds of new stuff. Started with perfecting the account controller. [skip ci]
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Helper\Controllers\AccountInterface as AI;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
|
||||
/**
|
||||
@@ -8,59 +9,20 @@ use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
class AccountController extends \BaseController
|
||||
{
|
||||
|
||||
protected $_repository;
|
||||
protected $_accounts;
|
||||
|
||||
/**
|
||||
* @param ARI $accounts
|
||||
* @param ARI $repository
|
||||
* @param AI $accounts
|
||||
*/
|
||||
public function __construct(ARI $accounts)
|
||||
public function __construct(ARI $repository, AI $accounts)
|
||||
{
|
||||
$this->_accounts = $accounts;
|
||||
|
||||
$this->_repository = $repository;
|
||||
View::share('menu', 'accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$all = $this->_accounts->get();
|
||||
|
||||
|
||||
$list = [
|
||||
'personal' => [],
|
||||
'beneficiaries' => [],
|
||||
'initial' => [],
|
||||
'cash' => []
|
||||
];
|
||||
$total = count($all);
|
||||
|
||||
foreach ($all as $account) {
|
||||
|
||||
switch ($account->accounttype->description) {
|
||||
case 'Default account':
|
||||
$list['personal'][] = $account;
|
||||
break;
|
||||
case 'Cash account':
|
||||
$list['cash'][] = $account;
|
||||
break;
|
||||
case 'Initial balance account':
|
||||
$list['initial'][] = $account;
|
||||
break;
|
||||
case 'Beneficiary account':
|
||||
$list['beneficiaries'][] = $account;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return View::make('accounts.index')->with('accounts', $list)->with('total', $total);
|
||||
}
|
||||
//
|
||||
//
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
@@ -71,14 +33,81 @@ class AccountController extends \BaseController
|
||||
return View::make('accounts.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function delete(Account $account)
|
||||
{
|
||||
return View::make('accounts.delete')->with('account', $account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
$result = $this->_repository->destroy(Input::get('id'));
|
||||
if ($result === true) {
|
||||
Session::flash('success', 'The account was deleted.');
|
||||
|
||||
return Redirect::route('accounts.index');
|
||||
} else {
|
||||
Session::flash('danger', 'Could not delete the account. Check the logs to be sure.');
|
||||
|
||||
return Redirect::route('accounts.index');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit(Account $account)
|
||||
{
|
||||
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
|
||||
|
||||
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$accounts = $this->_repository->get();
|
||||
$display = $this->_accounts->index($accounts);
|
||||
|
||||
return View::make('accounts.index')->with('accounts', $display);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(Account $account)
|
||||
{
|
||||
return View::make('accounts.show')->with('account', $account);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
|
||||
$account = $this->_accounts->store(Input::all());
|
||||
$account = $this->_repository->store(Input::all());
|
||||
|
||||
if (!$account->id) {
|
||||
// did not save, return with error:
|
||||
Session::flash('error', 'Could not save the new account. Please check the form.');
|
||||
|
||||
return View::make('accounts.create')->withErrors($account->errors());
|
||||
} else {
|
||||
// saved! return to wherever.
|
||||
@@ -91,30 +120,6 @@ class AccountController extends \BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($accountId)
|
||||
{
|
||||
$account = $this->_accounts->find($accountId);
|
||||
|
||||
if ($account) {
|
||||
// find the initial balance transaction, if any:
|
||||
$openingBalance = $this->_accounts->findOpeningBalanceTransaction($account);
|
||||
return View::make('accounts.edit')->with('account', $account)->with('openingBalance',$openingBalance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function show($accountId)
|
||||
{
|
||||
$account = $this->_accounts->find($accountId);
|
||||
return View::make('accounts.show')->with('account',$account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
@@ -122,33 +127,11 @@ class AccountController extends \BaseController
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$account = $this->_accounts->update(Input::all());
|
||||
Session::flash('success','Account "'.$account->name.'" updated.');
|
||||
$account = $this->_repository->update(Input::all());
|
||||
Session::flash('success', 'Account "' . $account->name . '" updated.');
|
||||
|
||||
return Redirect::route('accounts.index');
|
||||
}
|
||||
|
||||
public function delete($accountId) {
|
||||
$account = $this->_accounts->find($accountId);
|
||||
if($account) {
|
||||
return View::make('accounts.delete')->with('account',$account);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $accountId
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
$result = $this->_accounts->destroy(Input::get('id'));
|
||||
if($result === true) {
|
||||
Session::flash('success','The account was deleted.');
|
||||
return Redirect::route('accounts.index');
|
||||
} else {
|
||||
Session::flash('danger','Could not delete the account. Check the logs to be sure.');
|
||||
return Redirect::route('accounts.index');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user