Lots of cleanup and stuff.

This commit is contained in:
James Cole
2015-06-06 23:09:12 +02:00
parent 1a1f127993
commit 40b3097374
61 changed files with 361 additions and 323 deletions

View File

@@ -7,8 +7,9 @@ use Carbon\Carbon;
use Crypt;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection;
use FireflyIII\Repositories\Shared\ComponentRepository;
use Illuminate\Support\Collection;
/**
* Class CategoryRepository
*
@@ -48,7 +49,7 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
/** @var Collection $set */
$set = Auth::user()->categories()->orderBy('name', 'ASC')->get();
$set->sortBy(
function(Category $category) {
function (Category $category) {
return $category->name;
}
);
@@ -66,15 +67,15 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
public function getCategoriesAndExpensesCorrected($start, $end)
{
$set = Auth::user()->transactionjournals()
->leftJoin(
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
)
->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
->before($end)
->where('categories.user_id', Auth::user()->id)
->after($start)
->transactionTypes(['Withdrawal'])
->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']);
->leftJoin(
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
)
->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
->before($end)
->where('categories.user_id', Auth::user()->id)
->after($start)
->transactionTypes(['Withdrawal'])
->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']);
$result = [];
foreach ($set as $entry) {
@@ -142,10 +143,10 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
public function getLatestActivity(Category $category)
{
$latest = $category->transactionjournals()
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->first();
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->first();
if ($latest) {
return $latest->date;
}
@@ -162,15 +163,15 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
public function getWithoutCategory(Carbon $start, Carbon $end)
{
return Auth::user()
->transactionjournals()
->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->whereNull('category_transaction_journal.id')
->before($end)
->after($start)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*']);
->transactionjournals()
->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->whereNull('category_transaction_journal.id')
->before($end)
->after($start)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*']);
}
/**

View File

@@ -106,7 +106,7 @@ class JournalRepository implements JournalRepositoryInterface
*/
public function getJournalsOfTypes(array $types, $offset, $page)
{
$set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset)
$set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset)
->orderBy('date', 'DESC')
->orderBy('order', 'ASC')
->orderBy('id', 'DESC')

View File

@@ -102,7 +102,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
public function setOrder($id, $order)
{
$piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id)
->where('piggy_banks.id', $id)->first(['piggy_banks.*']);
->where('piggy_banks.id', $id)->first(['piggy_banks.*']);
if ($piggyBank) {
$piggyBank->order = $order;
$piggyBank->save();

View File

@@ -36,14 +36,14 @@ class ReminderRepository implements ReminderRepositoryInterface
$today = new Carbon;
// active reminders:
$active = Auth::user()->reminders()
->where('notnow', 0)
->where('active', 1)
->where('startdate', '<=', $today->format('Y-m-d 00:00:00'))
->where('enddate', '>=', $today->format('Y-m-d 00:00:00'))
->get();
->where('notnow', 0)
->where('active', 1)
->where('startdate', '<=', $today->format('Y-m-d 00:00:00'))
->where('enddate', '>=', $today->format('Y-m-d 00:00:00'))
->get();
$active->each(
function(Reminder $reminder) {
function (Reminder $reminder) {
$reminder->description = $this->helper->getReminderText($reminder);
}
);
@@ -58,11 +58,11 @@ class ReminderRepository implements ReminderRepositoryInterface
public function getDismissedReminders()
{
$dismissed = Auth::user()->reminders()
->where('notnow', 1)
->get();
->where('notnow', 1)
->get();
$dismissed->each(
function(Reminder $reminder) {
function (Reminder $reminder) {
$reminder->description = $this->helper->getReminderText($reminder);
}
);
@@ -77,18 +77,18 @@ class ReminderRepository implements ReminderRepositoryInterface
{
$expired = Auth::user()->reminders()
->where('notnow', 0)
->where('active', 1)
->where(
function (Builder $q) {
$today = new Carbon;
$q->where('startdate', '>', $today->format('Y-m-d 00:00:00'));
$q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00'));
}
)->get();
->where('notnow', 0)
->where('active', 1)
->where(
function (Builder $q) {
$today = new Carbon;
$q->where('startdate', '>', $today->format('Y-m-d 00:00:00'));
$q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00'));
}
)->get();
$expired->each(
function(Reminder $reminder) {
function (Reminder $reminder) {
$reminder->description = $this->helper->getReminderText($reminder);
}
);
@@ -106,7 +106,7 @@ class ReminderRepository implements ReminderRepositoryInterface
->get();
$inactive->each(
function(Reminder $reminder) {
function (Reminder $reminder) {
$reminder->description = $this->helper->getReminderText($reminder);
}
);

View File

@@ -36,7 +36,7 @@ class ComponentRepository
$cache->addProperty($shared);
$cache->addProperty('spentInPeriod');
if($cache->has()) {
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}

View File

@@ -110,7 +110,7 @@ class TagRepository implements TagRepositoryInterface
/** @var Collection $tags */
$tags = Auth::user()->tags()->get();
$tags->sortBy(
function(Tag $tag) {
function (Tag $tag) {
return $tag->tag;
}
);
@@ -204,6 +204,7 @@ class TagRepository implements TagRepositoryInterface
return false;
}
}
return true;
}
@@ -289,6 +290,7 @@ class TagRepository implements TagRepositoryInterface
// tag is attached just like that:
if ($withdrawals < 1 && $deposits < 1) {
$journal->tags()->save($tag);
return true;
}