mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
All kinds of new stuff. Started with perfecting the account controller. [skip ci]
This commit is contained in:
66
app/lib/Firefly/Helper/Controllers/Account.php
Normal file
66
app/lib/Firefly/Helper/Controllers/Account.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
class Account implements AccountInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*/
|
||||
public function index(Collection $accounts)
|
||||
{
|
||||
|
||||
$list = [
|
||||
'personal' => [],
|
||||
'beneficiaries' => [],
|
||||
'initial' => [],
|
||||
'cash' => []
|
||||
];
|
||||
foreach ($accounts 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 $list;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function openingBalanceTransaction(\Account $account)
|
||||
{
|
||||
$transactionType = \TransactionType::where('type', 'Opening balance')->first();
|
||||
return \TransactionJournal::
|
||||
with(
|
||||
['transactions' => function ($q) {
|
||||
$q->orderBy('amount', 'ASC');
|
||||
}]
|
||||
)->where('transaction_type_id', $transactionType->id)
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)->first(['transaction_journals.*']);
|
||||
|
||||
}
|
||||
}
|
31
app/lib/Firefly/Helper/Controllers/AccountInterface.php
Normal file
31
app/lib/Firefly/Helper/Controllers/AccountInterface.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* Interface AccountInterface
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
interface AccountInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Build the index:
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(Collection $accounts);
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function openingBalanceTransaction(\Account $account);
|
||||
|
||||
}
|
@@ -17,6 +17,12 @@ class HelperServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// controllers:
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Controllers\AccountInterface',
|
||||
'Firefly\Helper\Controllers\Account'
|
||||
);
|
||||
|
||||
// mail:
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Email\EmailHelperInterface',
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Class Toolkit
|
||||
@@ -13,15 +14,14 @@ class Toolkit implements ToolkitInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Based on the preference 'viewRange' and other variables I have not yet thought of,
|
||||
* this method will return a date range that defines the 'current' period of time.
|
||||
* @param Request $request
|
||||
*
|
||||
* ie. the current week or month.
|
||||
*
|
||||
* $start is always the past, $end is 'now' or at least later.
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed|null
|
||||
*/
|
||||
public function getDateRange()
|
||||
public function getDateRange(Request $request)
|
||||
{
|
||||
|
||||
|
||||
$preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$viewRange = $preferences->get('viewRange', '1M');
|
||||
|
||||
@@ -146,7 +146,7 @@ class Toolkit implements ToolkitInterface
|
||||
\Session::put('end', $end);
|
||||
\Session::put('range', $range);
|
||||
if ($doPrev || $doNext) {
|
||||
return \Redirect::route('index');
|
||||
return \Redirect::to($request->url());
|
||||
|
||||
}
|
||||
return null;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
/**
|
||||
* Interface ToolkitInterface
|
||||
*
|
||||
@@ -12,7 +13,7 @@ interface ToolkitInterface
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDateRange();
|
||||
public function getDateRange(Request $request);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
|
Reference in New Issue
Block a user