Expanded some tests.

This commit is contained in:
James Cole
2015-06-05 07:49:07 +02:00
parent fea9bc4e7e
commit d483005219
4 changed files with 96 additions and 12 deletions

View File

@@ -8,6 +8,7 @@ use Closure;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Reminder;
use FireflyIII\Support\CacheProperties;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use View;
@@ -49,7 +50,8 @@ class Reminders
{
if ($this->auth->check() && !$request->isXmlHttpRequest()) {
$user = $this->auth->user();
if ($this->auth->check() && !$request->isXmlHttpRequest() && $user instanceof User) {
// do reminders stuff.
// abuse CacheProperties to find out if we need to do this:
@@ -63,7 +65,7 @@ class Reminders
return $next($request);
}
$piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get();
$piggyBanks = $user->piggyBanks()->where('remind_me', 1)->get();
/** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */
$helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface');
@@ -75,12 +77,11 @@ class Reminders
// delete invalid reminders
// this is a construction SQLITE cannot handle :(
if (env('DB_CONNECTION') != 'sqlite') {
Reminder::whereUserId($this->auth->user()->id)->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')
->whereNull('piggy_banks.id')->delete();
Reminder::whereUserId($user->id)->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')->whereNull('piggy_banks.id')->delete();
}
// get and list active reminders:
$reminders = $this->auth->user()->reminders()->today()->get();
$reminders = $user->reminders()->today()->get();
$reminders->each(
function (Reminder $reminder) use ($helper) {
$reminder->description = $helper->getReminderText($reminder);

View File

@@ -9,7 +9,6 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
/**
* Class TagRepository
@@ -64,14 +63,15 @@ class TagRepository implements TagRepositoryInterface
* @param Carbon $start
* @param Carbon $end
*
* @return integer
* @return string
*/
public function coveredByBalancingActs(Account $account, Carbon $start, Carbon $end)
{
// the quickest way to do this is by scanning all balancingAct tags
// because there will be less of them any way.
$tags = Auth::user()->tags()->where('tagMode', 'balancingAct')->get();
$amount = 0;
$amount = '0';
bcscale(2);
/** @var Tag $tag */
foreach ($tags as $tag) {
@@ -80,7 +80,7 @@ class TagRepository implements TagRepositoryInterface
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
if ($journal->destination_account->id == $account->id) {
$amount += $journal->amount;
$amount = bcadd($amount, $journal->amount);
}
}
}

View File

@@ -38,7 +38,7 @@ interface TagRepositoryInterface
* @param Carbon $start
* @param Carbon $end
*
* @return float
* @return string
*/
public function coveredByBalancingActs(Account $account, Carbon $start, Carbon $end);