mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup.
This commit is contained in:
@@ -501,8 +501,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
$set = $this->getUser()->transactionJournals()->withRelevantData()->leftJoin(
|
||||
'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'
|
||||
)->where('transactions.account_id', $account->id)->take($limit)->offset($offset)->before($end)->after($start)->orderBy('date', 'DESC')->get(
|
||||
['transaction_journals.*']
|
||||
);
|
||||
['transaction_journals.*']
|
||||
);
|
||||
$count = $this->getUser()->transactionJournals()->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->before($end)->after($start)->orderBy('date', 'DESC')->where('transactions.account_id', $account->id)->count();
|
||||
$items = [];
|
||||
|
@@ -198,10 +198,12 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
||||
public function getTransactionJournalsInRepetition(\Budget $budget, \LimitRepetition $repetition, $limit = 50)
|
||||
{
|
||||
$start = $repetition->startdate;
|
||||
$end = $repetition->enddate;
|
||||
$end = $repetition->enddate;
|
||||
|
||||
$offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
|
||||
$set = $budget->transactionJournals()->withRelevantData()->before($end)->after($start)->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']);
|
||||
$set = $budget->transactionJournals()->withRelevantData()->before($end)->after($start)->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(
|
||||
['transaction_journals.*']
|
||||
);
|
||||
$count = $budget->transactionJournals()->before($end)->after($start)->count();
|
||||
$items = [];
|
||||
foreach ($set as $entry) {
|
||||
|
@@ -46,15 +46,16 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
$category = new \Category;
|
||||
$category->name = $data['name'];
|
||||
$category = new \Category;
|
||||
$category->name = $data['name'];
|
||||
$category->class = 'Category';
|
||||
$category->user()->associate($this->getUser());
|
||||
if(!$category->validate()) {
|
||||
if (!$category->validate()) {
|
||||
var_dump($category->errors());
|
||||
exit();
|
||||
}
|
||||
$category->save();
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
|
@@ -20,6 +20,14 @@ interface RecurringInterface
|
||||
*/
|
||||
public function getJournalForRecurringInRange(\RecurringTransaction $recurring, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurring
|
||||
* @param \TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function scan(\RecurringTransaction $recurring, \TransactionJournal $journal);
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurring
|
||||
*
|
||||
@@ -27,12 +35,4 @@ interface RecurringInterface
|
||||
*/
|
||||
public function scanEverything(\RecurringTransaction $recurring);
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurring
|
||||
* @param \TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function scan(\RecurringTransaction $recurring,\TransactionJournal $journal);
|
||||
|
||||
}
|
@@ -59,6 +59,7 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface
|
||||
exit;
|
||||
}
|
||||
$piggybank->save();
|
||||
|
||||
return $piggybank;
|
||||
}
|
||||
|
||||
@@ -197,9 +198,8 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface
|
||||
public function find($id)
|
||||
{
|
||||
return \Piggybank::
|
||||
leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')
|
||||
->where('piggybanks.id','=',$id)
|
||||
->where('accounts.user_id', $this->getUser()->id)->first(['piggybanks.*']);
|
||||
leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where('piggybanks.id', '=', $id)->where('accounts.user_id', $this->getUser()->id)
|
||||
->first(['piggybanks.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -38,6 +38,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
public function destroy(Ardent $model)
|
||||
{
|
||||
$model->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -128,19 +129,19 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
/*
|
||||
* Store the budget.
|
||||
*/
|
||||
if(isset($data['budget_id']) && intval($data['budget_id']) > 0) {
|
||||
if (isset($data['budget_id']) && intval($data['budget_id']) > 0) {
|
||||
/** @var \FireflyIII\Database\Budget $budgetRepository */
|
||||
$budgetRepository = \App::make('FireflyIII\Database\Budget');
|
||||
$budget = $budgetRepository->find(intval($data['budget_id']));
|
||||
if($budget) {
|
||||
$budget = $budgetRepository->find(intval($data['budget_id']));
|
||||
if ($budget) {
|
||||
$journal->budgets()->save($budget);
|
||||
}
|
||||
}
|
||||
if(strlen($data['category']) > 0) {
|
||||
if (strlen($data['category']) > 0) {
|
||||
/** @var \FireflyIII\Database\Category $categoryRepository */
|
||||
$categoryRepository = \App::make('FireflyIII\Database\Category');
|
||||
$category = $categoryRepository->firstOrCreate($data['category']);
|
||||
if($category) {
|
||||
$category = $categoryRepository->firstOrCreate($data['category']);
|
||||
if ($category) {
|
||||
$journal->categories()->save($category);
|
||||
}
|
||||
}
|
||||
@@ -222,19 +223,19 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
/*
|
||||
* Store the budget.
|
||||
*/
|
||||
if(isset($data['budget_id']) && intval($data['budget_id']) > 0) {
|
||||
if (isset($data['budget_id']) && intval($data['budget_id']) > 0) {
|
||||
/** @var \FireflyIII\Database\Budget $budgetRepository */
|
||||
$budgetRepository = \App::make('FireflyIII\Database\Budget');
|
||||
$budget = $budgetRepository->find(intval($data['budget_id']));
|
||||
if($budget) {
|
||||
$budget = $budgetRepository->find(intval($data['budget_id']));
|
||||
if ($budget) {
|
||||
$model->budgets()->sync([$budget->id]);
|
||||
}
|
||||
}
|
||||
if(strlen($data['category']) > 0) {
|
||||
if (strlen($data['category']) > 0) {
|
||||
/** @var \FireflyIII\Database\Category $categoryRepository */
|
||||
$categoryRepository = \App::make('FireflyIII\Database\Category');
|
||||
$category = $categoryRepository->firstOrCreate($data['category']);
|
||||
if($category) {
|
||||
$category = $categoryRepository->firstOrCreate($data['category']);
|
||||
if ($category) {
|
||||
$model->categories()->sync([$category->id]);
|
||||
}
|
||||
}
|
||||
@@ -545,6 +546,22 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
return $sum;
|
||||
}
|
||||
|
||||
public function getDepositsPaginated($limit = 50)
|
||||
{
|
||||
$offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
|
||||
|
||||
$set = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->withRelevantData()->take($limit)->offset($offset)->orderBy(
|
||||
'date', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
$count = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->count();
|
||||
$items = [];
|
||||
foreach ($set as $entry) {
|
||||
$items[] = $entry;
|
||||
}
|
||||
|
||||
return \Paginator::make($items, $count, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $count
|
||||
@@ -568,12 +585,15 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getWithdrawalsPaginated($limit = 50) {
|
||||
public function getTransfersPaginated($limit = 50)
|
||||
{
|
||||
$offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
|
||||
|
||||
$set = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']);
|
||||
$count = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->count();
|
||||
$items = [];
|
||||
$set = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->withRelevantData()->take($limit)->offset($offset)->orderBy(
|
||||
'date', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
$count = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->count();
|
||||
$items = [];
|
||||
foreach ($set as $entry) {
|
||||
$items[] = $entry;
|
||||
}
|
||||
@@ -581,25 +601,15 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
|
||||
return \Paginator::make($items, $count, $limit);
|
||||
}
|
||||
|
||||
public function getDepositsPaginated($limit = 50) {
|
||||
public function getWithdrawalsPaginated($limit = 50)
|
||||
{
|
||||
$offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
|
||||
|
||||
$set = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']);
|
||||
$count = $this->getUser()->transactionJournals()->transactionTypes(['Deposit'])->count();
|
||||
$items = [];
|
||||
foreach ($set as $entry) {
|
||||
$items[] = $entry;
|
||||
}
|
||||
|
||||
return \Paginator::make($items, $count, $limit);
|
||||
}
|
||||
|
||||
public function getTransfersPaginated($limit = 50) {
|
||||
$offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0;
|
||||
|
||||
$set = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->withRelevantData()->take($limit)->offset($offset)->orderBy('date', 'DESC')->get(['transaction_journals.*']);
|
||||
$count = $this->getUser()->transactionJournals()->transactionTypes(['Transfer'])->count();
|
||||
$items = [];
|
||||
$set = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->withRelevantData()->take($limit)->offset($offset)->orderBy(
|
||||
'date', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
$count = $this->getUser()->transactionJournals()->transactionTypes(['Withdrawal'])->count();
|
||||
$items = [];
|
||||
foreach ($set as $entry) {
|
||||
$items[] = $entry;
|
||||
}
|
||||
|
Reference in New Issue
Block a user