Some new stuff that really doesn't belong here. I'm not good at this.

This commit is contained in:
James Cole
2014-09-03 07:11:35 +02:00
parent 98612dd253
commit c3fd5c7136
11 changed files with 366 additions and 75 deletions

View File

@@ -66,7 +66,8 @@ class AccountController extends \BaseController
public function edit(Account $account)
{
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)->with('title','Edit account "'.$account->name.'"');
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)
->with('title', 'Edit account "' . $account->name . '"');
}
/**
@@ -90,7 +91,7 @@ class AccountController extends \BaseController
}
}
return View::make('accounts.index')->with('accounts', $set)->with('title','All your accounts');
return View::make('accounts.index')->with('accounts', $set)->with('title', 'All your accounts');
}
/**

View File

@@ -14,12 +14,12 @@ class BudgetController extends BaseController
protected $_repository;
/**
* @param BI $budgets
* @param BI $budgets
* @param BRI $repository
*/
public function __construct(BI $budgets, BRI $repository)
{
$this->_budgets = $budgets;
$this->_budgets = $budgets;
$this->_repository = $repository;
}
@@ -30,7 +30,7 @@ class BudgetController extends BaseController
{
$periods = \Config::get('firefly.periods_to_text');
return View::make('budgets.create')->with('periods', $periods);
return View::make('budgets.create')->with('periods', $periods)->with('title', 'Create a new budget');
}
/**
@@ -40,7 +40,8 @@ class BudgetController extends BaseController
*/
public function delete(Budget $budget)
{
return View::make('budgets.delete')->with('budget', $budget);
return View::make('budgets.delete')->with('budget', $budget)
->with('title', 'Delete budget "' . $budget->name . '"');
}
/**
@@ -50,20 +51,16 @@ class BudgetController extends BaseController
*/
public function destroy(Budget $budget)
{
// remove budget
Event::fire('budgets.destroy', [$budget]); // just before deletion.
$result = $this->_repository->destroy($budget);
if ($result === true) {
Session::flash('success', 'The budget was deleted.');
if (Input::get('from') == 'date') {
return Redirect::route('budgets.index');
} else {
return Redirect::route('budgets.index.budget');
}
} else {
Session::flash('error', 'Could not delete the budget. Check the logs to be sure.');
}
$this->_repository->destroy($budget);
Session::flash('success', 'The budget was deleted.');
return Redirect::route('budgets.index');
// redirect:
if (Input::get('from') == 'date') {
return Redirect::route('budgets.index');
}
return Redirect::route('budgets.index.budget');
}
@@ -74,7 +71,8 @@ class BudgetController extends BaseController
*/
public function edit(Budget $budget)
{
return View::make('budgets.edit')->with('budget', $budget);
return View::make('budgets.edit')->with('budget', $budget)
->with('title', 'Edit budget "' . $budget->name . '"');
}
@@ -84,62 +82,70 @@ class BudgetController extends BaseController
public function indexByBudget()
{
$budgets = $this->_repository->get();
$today = new Carbon;
return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', $today);
return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', new Carbon)
->with('title', 'Budgets grouped by budget');
}
/**
* @return $this|\Illuminate\View\View
* @throws Firefly\Exception\FireflyException
* @return $this
*/
public function indexByDate()
{
// get a list of dates by getting all repetitions:
$set = $this->_repository->get();
$set = $this->_repository->get();
$budgets = $this->_budgets->organizeByDate($set);
return View::make('budgets.indexByDate')->with('budgets', $budgets);
return View::make('budgets.indexByDate')->with('budgets', $budgets)->with('title', 'Budgets grouped by date.');
}
/**
* Three use cases for this view:
*
* - Show everything.
* - Show a specific repetition.
* - Show everything shows NO repetition.
*
* @param Budget $budget
*
* @return int
*/
public function show(Budget $budget)
{
/**
* Use the
*/
$useSessionDates = Input::get('useSession') == 'true' ? true : false;
$view = null;
$title = null;
$filters = [];
if (!is_null(Input::get('rep'))) {
$repetitionId = intval(Input::get('rep'));
$repetitions = $this->_budgets->organizeRepetition($repetitionId);
$filters[] = $repetitions[0]['limit'];
$filters[] = $repetitions[0]['limitrepetition'];
} else {
if (Input::get('noenvelope') == 'true') {
$repetitions = $this->_budgets->outsideRepetitions($budget);
$filters[] = 'no_envelope';
} else {
// grab all limit repetitions, order them, show them:
$repetitions = $this->_budgets->organizeRepetitions($budget, $useSessionDates);
}
switch (true) {
case (!is_null(Input::get('rep'))):
$repetitionId = intval(Input::get('rep'));
$data = $this->_budgets->organizeRepetition($repetitionId);
$view = 1;
$title = $budget->name.', '. $data[0]['limitrepetition']->periodShow().', '.mf($data[0]['limit']->amount,false);
break;
case (Input::get('noenvelope') == 'true'):
$data = $this->_budgets->outsideRepetitions($budget);
$view = 2;
$title = $budget->name.', transactions outside an envelope.';
break;
default:
$data = $this->_budgets->organizeRepetitions($budget, $useSessionDates);
$view = $useSessionDates ? 3 : 4;
$title = $useSessionDates ? $budget->name.' in session period' : $budget->name;
break;
}
return View::make('budgets.show')->with('budget', $budget)->with('repetitions', $repetitions)->with(
'filters', $filters
)->with('highlight', Input::get('highlight'))->with('useSessionDates', $useSessionDates);
return View::make('budgets.show')
->with('budget', $budget)
->with('repetitions', $data)
->with('view', $view)
->with('highlight', Input::get('highlight'))
->with('useSessionDates', $useSessionDates)
->with('title', $title);
}
/**

View File

@@ -52,6 +52,30 @@ class Import
}
/**
* @param Job $job
* @param array $payload
*/
public function cleanImportAccount(Job $job, array $payload)
{
$importAccountType = $this->_accounts->findAccountType('Import account');
$importAccounts = $this->_accounts->getByAccountType($importAccountType);
if (count($importAccounts) == 0) {
$job->delete();
} else if (count($importAccounts) == 1) {
/** @var \Account $importAccount */
$importAccount = $importAccounts[0];
$transactions = $importAccount->transactions()->get();
/** @var \Transaction $transaction */
foreach ($transactions as $transaction) {
$transaction->account()->associate($importAccount);
$transaction->save();
}
\Log::debug('Updated ' . count($transactions) . ' transactions from Import Account to cash.');
}
$job->delete();
}
/**
* @param Job $job
* @param array $payload
@@ -611,8 +635,13 @@ class Import
\Queue::push($jobFunction, ['data' => $entry, 'mapID' => $importMap->id]);
}
// queue a job to clean up the "import account", it should properly fall back
// to the cash account (which it doesn't always do for some reason).
\Queue::push('Firefly\Queue\Import@cleanImportAccount', ['mapID' => $importMap->id]);
}
\Log::debug('Done with job "start"');
// this is it, close the job:
$job->delete();

View File

@@ -101,6 +101,12 @@ interface AccountRepositoryInterface
*/
public function getDefault();
/**
* @param \AccountType $type
* @return mixed
*/
public function getByAccountType(\AccountType $type);
/**
* @param \User $user
* @return mixed

View File

@@ -209,6 +209,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $list;
}
public function getByAccountType(\AccountType $type)
{
return $this->_user->accounts()->with('accounttype')->orderBy('name', 'ASC')
->where('account_type_id', $type->id)->get();
}
/**
* @param $ids
*

View File

@@ -8,7 +8,11 @@ use Mockery as m;
/**
* Class AccountTest
*
* Test EVERYTHING related to accounts. Models, views controllers.
* Test EVERYTHING related to accounts. Models, views, and controllers.
*
* This class does not cover the /lib/ map, it is for a later date.
*
* As far as I am concerned, this class is complete! Yay!
*
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
@@ -68,20 +72,20 @@ class AccountTest extends TestCase
// user should equal test user:
$this->assertEquals($user->id, $account->user()->first()->id);
$this->assertEquals('testing',\App::environment());
$this->assertEquals('testing', \App::environment());
\Log::debug('Hello from test!');
\Log::debug('Number of accounts: ' . \Account::count());
\Log::debug('Number of account types: ' . \AccountType::count());
foreach(\AccountType::get() as $t) {
\Log::debug('AccountType: #'.$t->id.', ' . $t->type);
foreach (\AccountType::get() as $t) {
\Log::debug('AccountType: #' . $t->id . ', ' . $t->type);
}
// whatever the account type of this account, searching for it using the
// scope method should return one account:
$accountType = $account->accounttype()->first();
$accounts = $accountType->accounts()->count();
$accounts = $accountType->accounts()->count();
$this->assertCount($accounts, \Account::AccountTypeIn([$accountType->type])->get());
}
@@ -199,7 +203,7 @@ class AccountTest extends TestCase
{
// two account types:
$personalType = \AccountType::whereType('Default account')->first();
$benType = \AccountType::whereType('Beneficiary account')->first();
$benType = \AccountType::whereType('Beneficiary account')->first();
// create two accounts:
/** @var \Account $account */
@@ -303,6 +307,9 @@ class AccountTest extends TestCase
$this->assertSessionHas('error');
}
/**
* @covers ::store
*/
public function testStoreRecreate()
{
/** @var \Account $account */
@@ -319,6 +326,9 @@ class AccountTest extends TestCase
$this->assertSessionHas('success');
}
/**
* @covers ::update
*/
public function testUpdate()
{
/** @var \Account $account */
@@ -344,6 +354,9 @@ class AccountTest extends TestCase
}
/**
* @covers ::update
*/
public function testUpdateFails()
{
/** @var \Account $account */

View File

@@ -7,38 +7,34 @@
</h1>
<p class="lead">Budgets can help you cut back on spending.</p>
<!-- warning for selected limit -->
@if(isset($filters[0]) && is_object($filters[0]) && get_class($filters[0]) == 'Limit')
@if($view == 1)
<p class="bg-primary" style="padding:15px;">
This view is filtered to show only the envelope from
{{{$repetitions[0]['limitrepetition']->periodShow()}}},
which contains {{mf($repetitions[0]['limit']->amount,false)}}.
</p>
<p class="bg-info" style="padding:15px;">
<a href="{{route('budgets.show',$budget->id)}}" class="text-info">Reset the filter(s).</a>
</p>
@endif
<!-- warning for non-caught only -->
@if(isset($filters[0]) && $filters[0] == 'no_envelope')
@if($view == 2)
<p class="bg-primary" style="padding:15px;">
This view is filtered to show transactions not in an envelope only.
</p>
<p class="bg-info" style="padding:15px;">
<a href="{{route('budgets.show',$budget->id)}}" class="text-info">Reset the filter(s).</a>
</p>
@endif
<!-- warning for session date -->
@if($useSessionDates == true)
<!-- warning for session date -->
@if($view == 3)
<p class="bg-primary" style="padding:15px;">
This view is filtered to only show transactions between {{Session::get('start')->format('d M Y')}}
and {{Session::get('end')->format('d M Y')}}.
</p>
<p class="bg-info" style="padding:15px;">
<a href="{{route('budgets.show',$budget->id)}}" class="text-info">Reset the filter(s).</a>
</p>
@endif
@if($view != 4)
<p class="bg-info" style="padding:15px;">
<a href="{{route('budgets.show',$budget->id)}}" class="text-info">Reset the filter(s).</a>
</p>
@endif
</div>
</div>
@@ -46,17 +42,22 @@
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div id="chart"></div>
@if(isset($filters[0]) && is_object($filters[0]) && get_class($filters[0]) == 'Limit')
@if($view == 1)
<div id="instr" data-type="envelope" data-envelope="{{$repetitions[0]['limitrepetition']->id}}"></div>
@elseif(isset($filters[0]) && $filters[0] == 'no_envelope')
<div id="instr" data-type="no_envelope" data-budget="{{$budget->id}}"></div>
@elseif($useSessionDates == true)
<div id="instr" data-type="session" data-budget="{{$budget->id}}"></div>
@else
<div id="instr" data-type="default" data-budget="{{$budget->id}}"></div>
@endif
@if($view == 2)
<div id="instr" data-type="no_envelope" data-budget="{{$budget->id}}"></div>
@endif
@if($view == 3)
<div id="instr" data-type="session" data-budget="{{$budget->id}}"></div>
@endif
@if($view == 4)
<div id="instr" data-type="default" data-budget="{{$budget->id}}"></div>
@endif
</div>
</div>