mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-29 02:11:12 -06:00
New bill repository provider.
This commit is contained in:
parent
13bac92a24
commit
98bd9bdaa0
41
app/Providers/BillServiceProvider.php
Normal file
41
app/Providers/BillServiceProvider.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class BillServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap the application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->bind(
|
||||||
|
'FireflyIII\Repositories\Bill\BillRepositoryInterface',
|
||||||
|
function (Application $app, array $arguments) {
|
||||||
|
if (!isset($arguments[0]) && Auth::check()) {
|
||||||
|
return app('FireflyIII\Repositories\Bill\BillRepository', [Auth::user()]);
|
||||||
|
} else {
|
||||||
|
if (!isset($arguments[0]) && !Auth::check()) {
|
||||||
|
throw new FireflyException('There is no user present.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return app('FireflyIII\Repositories\Bill\BillRepository', $arguments);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -88,7 +88,6 @@ class FireflyServiceProvider extends ServiceProvider
|
|||||||
$this->app->bind('FireflyIII\Repositories\Category\CategoryRepositoryInterface', 'FireflyIII\Repositories\Category\CategoryRepository');
|
$this->app->bind('FireflyIII\Repositories\Category\CategoryRepositoryInterface', 'FireflyIII\Repositories\Category\CategoryRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface', 'FireflyIII\Repositories\Category\SingleCategoryRepository');
|
$this->app->bind('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface', 'FireflyIII\Repositories\Category\SingleCategoryRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Journal\JournalRepositoryInterface', 'FireflyIII\Repositories\Journal\JournalRepository');
|
$this->app->bind('FireflyIII\Repositories\Journal\JournalRepositoryInterface', 'FireflyIII\Repositories\Journal\JournalRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Bill\BillRepositoryInterface', 'FireflyIII\Repositories\Bill\BillRepository');
|
|
||||||
$this->app->bind('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface', 'FireflyIII\Repositories\PiggyBank\PiggyBankRepository');
|
$this->app->bind('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface', 'FireflyIII\Repositories\PiggyBank\PiggyBankRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepository');
|
$this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepository');
|
||||||
|
@ -3,7 +3,6 @@ declare(strict_types = 1);
|
|||||||
|
|
||||||
namespace FireflyIII\Repositories\Bill;
|
namespace FireflyIII\Repositories\Bill;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
@ -11,6 +10,7 @@ use FireflyIII\Models\Bill;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Query\Builder;
|
use Illuminate\Database\Query\Builder;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@ -25,6 +25,20 @@ use Navigation;
|
|||||||
class BillRepository implements BillRepositoryInterface
|
class BillRepository implements BillRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var User */
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BillRepository constructor.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function __construct(User $user)
|
||||||
|
{
|
||||||
|
Log::debug('Constructed bill repository for user #' . $user->id . ' (' . $user->email . ')');
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Bill $bill
|
* @param Bill $bill
|
||||||
*
|
*
|
||||||
@ -43,7 +57,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
public function getActiveBills(): Collection
|
public function getActiveBills(): Collection
|
||||||
{
|
{
|
||||||
/** @var Collection $set */
|
/** @var Collection $set */
|
||||||
$set = Auth::user()->bills()
|
$set = $this->user->bills()
|
||||||
->where('active', 1)
|
->where('active', 1)
|
||||||
->get(
|
->get(
|
||||||
[
|
[
|
||||||
@ -69,7 +83,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
{
|
{
|
||||||
$ids = $bills->pluck('id')->toArray();
|
$ids = $bills->pluck('id')->toArray();
|
||||||
|
|
||||||
$set = Auth::user()->transactionjournals()
|
$set = $this->user->transactionjournals()
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
'transactions', function (JoinClause $join) {
|
'transactions', function (JoinClause $join) {
|
||||||
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0);
|
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0);
|
||||||
@ -96,7 +110,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
public function getBills(): Collection
|
public function getBills(): Collection
|
||||||
{
|
{
|
||||||
/** @var Collection $set */
|
/** @var Collection $set */
|
||||||
$set = Auth::user()->bills()->orderBy('name', 'ASC')->get();
|
$set = $this->user->bills()->orderBy('name', 'ASC')->get();
|
||||||
|
|
||||||
$set = $set->sortBy(
|
$set = $set->sortBy(
|
||||||
function (Bill $bill) {
|
function (Bill $bill) {
|
||||||
@ -118,7 +132,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
public function getBillsForAccounts(Collection $accounts): Collection
|
public function getBillsForAccounts(Collection $accounts): Collection
|
||||||
{
|
{
|
||||||
$ids = $accounts->pluck('id')->toArray();
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
$set = Auth::user()->bills()
|
$set = $this->user->bills()
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
'transaction_journals', function (JoinClause $join) {
|
'transaction_journals', function (JoinClause $join) {
|
||||||
$join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
|
$join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
|
||||||
@ -248,7 +262,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||||
->where('transactions.account_id', $creditCard->id)
|
->where('transactions.account_id', $creditCard->id)
|
||||||
->where('transactions.amount', '>', 0)// this makes the filter unnecessary.
|
->where('transactions.amount', '>', 0)// this makes the filter unnecessary.
|
||||||
->where('transaction_journals.user_id', Auth::user()->id)
|
->where('transaction_journals.user_id', $this->user->id)
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||||
->where('transaction_types.type', TransactionType::TRANSFER);
|
->where('transaction_types.type', TransactionType::TRANSFER);
|
||||||
@ -320,7 +334,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
|
|
||||||
$journals = new Collection;
|
$journals = new Collection;
|
||||||
if (count($ids) > 0) {
|
if (count($ids) > 0) {
|
||||||
$journals = Auth::user()->transactionjournals()->transactionTypes([TransactionType::WITHDRAWAL])->whereIn('transaction_journals.id', $ids)->get(
|
$journals = $this->user->transactionjournals()->transactionTypes([TransactionType::WITHDRAWAL])->whereIn('transaction_journals.id', $ids)->get(
|
||||||
['transaction_journals.*']
|
['transaction_journals.*']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user