mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some new code.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace FireflyIII\Repositories\Account;
|
||||
|
||||
use App;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
@@ -10,7 +12,10 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Log;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Class AccountRepository
|
||||
@@ -32,6 +37,43 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param int $page
|
||||
* @param string $range
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJournals(Account $account, $page, $range = 'session')
|
||||
{
|
||||
$offset = $page * 50;
|
||||
$items = [];
|
||||
$query = Auth::user()
|
||||
->transactionJournals()
|
||||
//->withRelevantData()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->orderBy('date', 'DESC');
|
||||
|
||||
if ($range == 'session') {
|
||||
$query->before(Session::get('end', Carbon::now()->startOfMonth()));
|
||||
$query->after(Session::get('start', Carbon::now()->startOfMonth()));
|
||||
}
|
||||
$count = $query->count();
|
||||
$set = $query->take(50)->offset($offset)->get(['transaction_journals.*']);
|
||||
|
||||
foreach ($set as $entry) {
|
||||
$items[] = $entry;
|
||||
}
|
||||
|
||||
$paginator = new LengthAwarePaginator($items, $count, 50, $page);
|
||||
return $paginator;
|
||||
|
||||
//return Paginator::make($items, $count, 50);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace FireflyIII\Repositories\Account;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
|
||||
/**
|
||||
* Interface AccountRepositoryInterface
|
||||
*
|
||||
@@ -11,13 +12,6 @@ use FireflyIII\Models\TransactionJournal;
|
||||
*/
|
||||
interface AccountRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function store(array $data);
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
@@ -27,11 +21,12 @@ interface AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
* @param int $page
|
||||
* @param string $range
|
||||
*
|
||||
* @return Account
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(Account $account, array $data);
|
||||
public function getJournals(Account $account, $page, $range = 'session');
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
@@ -40,5 +35,18 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function openingBalanceTransaction(Account $account);
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function store(array $data);
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function update(Account $account, array $data);
|
||||
}
|
||||
Reference in New Issue
Block a user