All kinds of new stuff. Started with perfecting the account controller. [skip ci]

This commit is contained in:
James Cole
2014-07-26 18:53:41 +02:00
parent d088b2c558
commit b782bb8d93
75 changed files with 1075 additions and 8362 deletions

View 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.*']);
}
}

View 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);
}

View File

@@ -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',

View File

@@ -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;

View File

@@ -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