mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
Updated the transaction everything so views and forms work with the new transaction controller.
This commit is contained in:
@@ -20,6 +20,7 @@ class TransactionController extends BaseController
|
||||
public function __construct(TJRI $repository)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
View::share('title', 'Transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,15 +30,20 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function create($what = 'deposit')
|
||||
{
|
||||
// get accounts with names and id's.
|
||||
/** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\Toolkit');
|
||||
|
||||
// get asset accounts with names and id's.
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts = $accountRepository->getActiveDefaultAsSelectList();
|
||||
$accounts = $accountRepository->getOfTypes(['Asset account','Default account']);
|
||||
$assetAccounts = $toolkit->makeSelectList($accounts);
|
||||
|
||||
|
||||
// get budgets as a select list.
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets = $budgetRepository->getAsSelectList();
|
||||
$budgets = $toolkit->makeSelectList($budgetRepository->get());
|
||||
$budgets[0] = '(no budget)';
|
||||
|
||||
// get the piggy banks.
|
||||
@@ -45,9 +51,9 @@ class TransactionController extends BaseController
|
||||
$piggyRepository = App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
$piggies = $piggyRepository->get();
|
||||
|
||||
return View::make('transactions.create')->with('accounts', $accounts)->with('budgets', $budgets)->with(
|
||||
return View::make('transactions.create')->with('accounts', $assetAccounts)->with('budgets', $budgets)->with(
|
||||
'what', $what
|
||||
)->with('piggies', $piggies);
|
||||
)->with('piggies', $piggies)->with('subTitle', 'Add a new ' . $what)->with('title', 'Transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,6 +152,71 @@ class TransactionController extends BaseController
|
||||
)->with('budgets', $budgets)->with('data', $data)->with('piggies', $piggies);
|
||||
}
|
||||
|
||||
public function expenses()
|
||||
{
|
||||
$transactionType = $this->_repository->getTransactionType('Withdrawal');
|
||||
$start = is_null(Input::get('startdate')) ? null : new Carbon(Input::get('startdate'));
|
||||
$end = is_null(Input::get('enddate')) ? null : new Carbon(Input::get('enddate'));
|
||||
if ($start <= $end && !is_null($start) && !is_null($end)) {
|
||||
$journals = $this->_repository->paginate($transactionType, 25, $start, $end);
|
||||
$filtered = true;
|
||||
$filters = ['start' => $start, 'end' => $end];
|
||||
} else {
|
||||
$journals = $this->_repository->paginate($transactionType, 25);
|
||||
$filtered = false;
|
||||
$filters = null;
|
||||
}
|
||||
|
||||
|
||||
return View::make('transactions.index')->with('journals', $journals)->with('filtered', $filtered)->with(
|
||||
'filters', $filters
|
||||
);
|
||||
}
|
||||
|
||||
public function revenue()
|
||||
{
|
||||
$transactionType = $this->_repository->getTransactionType('Deposit');
|
||||
$start = is_null(Input::get('startdate')) ? null : new Carbon(Input::get('startdate'));
|
||||
$end = is_null(Input::get('enddate')) ? null : new Carbon(Input::get('enddate'));
|
||||
if ($start <= $end && !is_null($start) && !is_null($end)) {
|
||||
$journals = $this->_repository->paginate($transactionType, 25, $start, $end);
|
||||
$filtered = true;
|
||||
$filters = ['start' => $start, 'end' => $end];
|
||||
} else {
|
||||
$journals = $this->_repository->paginate($transactionType, 25);
|
||||
$filtered = false;
|
||||
$filters = null;
|
||||
}
|
||||
|
||||
|
||||
return View::make('transactions.index')->with('journals', $journals)->with('filtered', $filtered)->with(
|
||||
'filters', $filters
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function transfers()
|
||||
{
|
||||
$transactionType = $this->_repository->getTransactionType('Transfer');
|
||||
$start = is_null(Input::get('startdate')) ? null : new Carbon(Input::get('startdate'));
|
||||
$end = is_null(Input::get('enddate')) ? null : new Carbon(Input::get('enddate'));
|
||||
if ($start <= $end && !is_null($start) && !is_null($end)) {
|
||||
$journals = $this->_repository->paginate($transactionType, 25, $start, $end);
|
||||
$filtered = true;
|
||||
$filters = ['start' => $start, 'end' => $end];
|
||||
} else {
|
||||
$journals = $this->_repository->paginate($transactionType, 25);
|
||||
$filtered = false;
|
||||
$filters = null;
|
||||
}
|
||||
|
||||
|
||||
return View::make('transactions.index')->with('journals', $journals)->with('filtered', $filtered)->with(
|
||||
'filters', $filters
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
@@ -186,8 +257,14 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function store($what)
|
||||
{
|
||||
|
||||
$journal = $this->_repository->store($what, Input::all());
|
||||
if ($journal->validate()) {
|
||||
if($journal->errors()->count() > 0) {
|
||||
Session::flash('error', 'Could not save transaction: ' . $journal->errors()->first().'!');
|
||||
return Redirect::route('transactions.create', [$what])->withInput()->withErrors($journal->errors());
|
||||
}
|
||||
|
||||
if ($journal->validate() && !is_null($journal->id)) {
|
||||
Session::flash('success', 'Transaction "' . $journal->description . '" saved!');
|
||||
|
||||
// if reminder present, deactivate it:
|
||||
@@ -204,14 +281,23 @@ class TransactionController extends BaseController
|
||||
if (Input::get('create') == '1') {
|
||||
return Redirect::route('transactions.create', [$what])->withInput();
|
||||
} else {
|
||||
return Redirect::route('transactions.index');
|
||||
switch($what) {
|
||||
case 'withdrawal':
|
||||
return Redirect::route('transactions.expenses');
|
||||
break;
|
||||
case 'deposit':
|
||||
return Redirect::route('transactions.revenue');
|
||||
break;
|
||||
case 'transfer':
|
||||
return Redirect::route('transactions.transfers');
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', 'Could not save transaction: ' . $journal->errors()->first());
|
||||
Session::flash('error', 'Could not save transaction: ' . $journal->errors()->first().'!');
|
||||
|
||||
return Redirect::route('transactions.create', [$what])->withInput()->withErrors(
|
||||
$journal->errors()
|
||||
);
|
||||
return Redirect::route('transactions.create', [$what])->withInput()->withErrors($journal->errors());
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user