2015-02-25 15:19:14 +01:00
|
|
|
<?php
|
2022-12-29 19:42:26 +01:00
|
|
|
|
2016-05-20 12:41:23 +02:00
|
|
|
/**
|
|
|
|
* BillRepository.php
|
2020-02-16 14:00:57 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-05-20 12:41:23 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-10-05 06:52:15 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-05-20 12:41:23 +02:00
|
|
|
*/
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2015-02-25 15:19:14 +01:00
|
|
|
|
|
|
|
namespace FireflyIII\Repositories\Bill;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2015-05-08 14:00:49 +02:00
|
|
|
use DB;
|
2019-10-30 20:02:21 +01:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2018-02-22 20:07:14 +01:00
|
|
|
use FireflyIII\Factory\BillFactory;
|
2020-05-07 06:44:01 +02:00
|
|
|
use FireflyIII\Models\Attachment;
|
2015-02-25 15:19:14 +01:00
|
|
|
use FireflyIII\Models\Bill;
|
2018-04-29 07:46:03 +02:00
|
|
|
use FireflyIII\Models\Note;
|
2021-04-07 07:53:05 +02:00
|
|
|
use FireflyIII\Models\Rule;
|
2016-10-21 06:26:12 +02:00
|
|
|
use FireflyIII\Models\Transaction;
|
2015-02-25 15:19:14 +01:00
|
|
|
use FireflyIII\Models\TransactionJournal;
|
2018-02-25 19:09:05 +01:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2020-07-01 06:33:21 +02:00
|
|
|
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
|
2018-02-22 20:07:14 +01:00
|
|
|
use FireflyIII\Services\Internal\Destroy\BillDestroyService;
|
|
|
|
use FireflyIII\Services\Internal\Update\BillUpdateService;
|
2016-10-20 21:40:45 +02:00
|
|
|
use FireflyIII\Support\CacheProperties;
|
2016-03-03 08:40:25 +01:00
|
|
|
use FireflyIII\User;
|
2023-02-19 08:43:28 +01:00
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
2015-12-26 09:39:35 +01:00
|
|
|
use Illuminate\Database\Query\JoinClause;
|
2018-02-06 18:11:33 +01:00
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
2015-04-05 18:20:06 +02:00
|
|
|
use Illuminate\Support\Collection;
|
2023-05-29 13:56:55 +02:00
|
|
|
use JsonException;
|
2020-05-07 06:44:01 +02:00
|
|
|
use Storage;
|
2015-02-25 15:19:14 +01:00
|
|
|
|
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Class BillRepository.
|
2019-08-17 10:47:29 +02:00
|
|
|
*
|
2015-02-25 15:19:14 +01:00
|
|
|
*/
|
|
|
|
class BillRepository implements BillRepositoryInterface
|
|
|
|
{
|
2020-07-01 06:33:21 +02:00
|
|
|
use CreatesObjectGroups;
|
2020-08-06 20:08:04 +02:00
|
|
|
|
2020-07-11 15:13:15 +02:00
|
|
|
private User $user;
|
2016-03-03 08:40:25 +01:00
|
|
|
|
2022-03-29 14:59:58 +02:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function billEndsWith(string $query, int $limit): Collection
|
|
|
|
{
|
|
|
|
$search = $this->user->bills();
|
|
|
|
if ('' !== $query) {
|
|
|
|
$search->where('name', 'LIKE', sprintf('%%%s', $query));
|
|
|
|
}
|
|
|
|
$search->orderBy('name', 'ASC')
|
|
|
|
->where('active', true);
|
|
|
|
|
|
|
|
return $search->take($limit)->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function billStartsWith(string $query, int $limit): Collection
|
|
|
|
{
|
|
|
|
$search = $this->user->bills();
|
|
|
|
if ('' !== $query) {
|
|
|
|
$search->where('name', 'LIKE', sprintf('%s%%', $query));
|
|
|
|
}
|
|
|
|
$search->orderBy('name', 'ASC')
|
|
|
|
->where('active', true);
|
|
|
|
|
|
|
|
return $search->take($limit)->get();
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:20:01 +01:00
|
|
|
/**
|
|
|
|
* Correct order of piggies in case of issues.
|
|
|
|
*/
|
|
|
|
public function correctOrder(): void
|
|
|
|
{
|
|
|
|
$set = $this->user->bills()->orderBy('order', 'ASC')->get();
|
|
|
|
$current = 1;
|
|
|
|
foreach ($set as $bill) {
|
2023-11-05 19:55:39 +01:00
|
|
|
if ($bill->order !== $current) {
|
2021-03-12 06:20:01 +01:00
|
|
|
$bill->order = $current;
|
|
|
|
$bill->save();
|
|
|
|
}
|
|
|
|
$current++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-05 18:20:06 +02:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
2015-04-05 18:20:06 +02:00
|
|
|
*
|
2016-04-06 09:27:45 +02:00
|
|
|
* @return bool
|
2017-12-22 18:32:43 +01:00
|
|
|
*
|
2018-04-02 15:10:40 +02:00
|
|
|
|
2015-04-05 18:20:06 +02:00
|
|
|
*/
|
2016-02-06 18:59:48 +01:00
|
|
|
public function destroy(Bill $bill): bool
|
2015-04-05 18:20:06 +02:00
|
|
|
{
|
2018-02-22 20:07:14 +01:00
|
|
|
/** @var BillDestroyService $service */
|
|
|
|
$service = app(BillDestroyService::class);
|
|
|
|
$service->destroy($bill);
|
2016-02-06 18:59:48 +01:00
|
|
|
|
|
|
|
return true;
|
2015-04-05 18:20:06 +02:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:20:01 +01:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function destroyAll(): void
|
|
|
|
{
|
|
|
|
$this->user->bills()->delete();
|
|
|
|
}
|
|
|
|
|
2019-03-17 17:05:16 +01:00
|
|
|
/**
|
|
|
|
* Find bill by parameters.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param int|null $billId
|
|
|
|
* @param string|null $billName
|
2019-03-17 17:05:16 +01:00
|
|
|
*
|
|
|
|
* @return Bill|null
|
|
|
|
*/
|
2019-05-04 20:58:43 +02:00
|
|
|
public function findBill(?int $billId, ?string $billName): ?Bill
|
2019-03-17 17:05:16 +01:00
|
|
|
{
|
|
|
|
if (null !== $billId) {
|
2023-11-05 08:15:17 +01:00
|
|
|
$searchResult = $this->find($billId);
|
2019-03-17 17:05:16 +01:00
|
|
|
if (null !== $searchResult) {
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Found bill based on #%d, will return it.', $billId));
|
2019-03-17 17:05:16 +01:00
|
|
|
|
|
|
|
return $searchResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (null !== $billName) {
|
2023-11-05 08:15:17 +01:00
|
|
|
$searchResult = $this->findByName($billName);
|
2019-03-17 17:05:16 +01:00
|
|
|
if (null !== $searchResult) {
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Found bill based on "%s", will return it.', $billName));
|
2019-03-17 17:05:16 +01:00
|
|
|
|
|
|
|
return $searchResult;
|
|
|
|
}
|
|
|
|
}
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug('Found nothing');
|
2019-03-17 17:05:16 +01:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-07-23 21:37:06 +02:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* Find a bill by ID.
|
2016-07-23 21:37:06 +02:00
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param int $billId
|
2016-07-23 21:37:06 +02:00
|
|
|
*
|
2021-05-24 08:50:17 +02:00
|
|
|
* @return Bill|null
|
2016-07-23 21:37:06 +02:00
|
|
|
*/
|
2023-06-21 12:34:58 +02:00
|
|
|
public function find(int $billId): ?Bill
|
2016-07-23 21:37:06 +02:00
|
|
|
{
|
2023-06-21 12:34:58 +02:00
|
|
|
return $this->user->bills()->find($billId);
|
2016-07-23 21:37:06 +02:00
|
|
|
}
|
|
|
|
|
2016-01-20 15:21:27 +01:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* Find a bill by name.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*
|
|
|
|
* @return Bill|null
|
2016-01-20 15:21:27 +01:00
|
|
|
*/
|
2023-06-21 12:34:58 +02:00
|
|
|
public function findByName(string $name): ?Bill
|
2016-01-20 15:21:27 +01:00
|
|
|
{
|
2023-06-21 12:34:58 +02:00
|
|
|
return $this->user->bills()->where('name', $name)->first(['bills.*']);
|
2016-01-20 15:21:27 +01:00
|
|
|
}
|
|
|
|
|
2018-12-09 13:09:43 +01:00
|
|
|
/**
|
|
|
|
* Get all attachments.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
2018-12-09 13:09:43 +01:00
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getAttachments(Bill $bill): Collection
|
|
|
|
{
|
2020-05-07 06:44:01 +02:00
|
|
|
$set = $bill->attachments()->get();
|
|
|
|
|
|
|
|
/** @var Storage $disk */
|
|
|
|
$disk = Storage::disk('upload');
|
|
|
|
|
2020-10-23 19:11:25 +02:00
|
|
|
return $set->each(
|
2020-05-07 06:44:01 +02:00
|
|
|
static function (Attachment $attachment) use ($disk) {
|
|
|
|
$notes = $attachment->notes()->first();
|
|
|
|
$attachment->file_exists = $disk->exists($attachment->fileName());
|
2023-11-05 09:40:45 +01:00
|
|
|
$attachment->notes_text = null !== $notes ? $notes->text : '';
|
2020-05-07 06:44:01 +02:00
|
|
|
|
|
|
|
return $attachment;
|
|
|
|
}
|
|
|
|
);
|
2018-12-09 13:09:43 +01:00
|
|
|
}
|
|
|
|
|
2015-04-05 18:20:06 +02:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2016-02-06 18:59:48 +01:00
|
|
|
public function getBills(): Collection
|
2015-04-05 18:20:06 +02:00
|
|
|
{
|
2020-06-30 20:33:08 +02:00
|
|
|
return $this->user->bills()
|
|
|
|
->orderBy('order', 'ASC')
|
|
|
|
->orderBy('active', 'DESC')
|
|
|
|
->orderBy('name', 'ASC')->get();
|
2015-04-05 18:20:06 +02:00
|
|
|
}
|
|
|
|
|
2015-12-12 10:33:19 +01:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Collection $accounts
|
2015-12-12 10:33:19 +01:00
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2016-02-06 18:59:48 +01:00
|
|
|
public function getBillsForAccounts(Collection $accounts): Collection
|
2015-12-12 10:33:19 +01:00
|
|
|
{
|
2022-12-29 19:42:26 +01:00
|
|
|
$fields = [
|
|
|
|
'bills.id',
|
|
|
|
'bills.created_at',
|
|
|
|
'bills.updated_at',
|
|
|
|
'bills.deleted_at',
|
|
|
|
'bills.user_id',
|
|
|
|
'bills.name',
|
|
|
|
'bills.amount_min',
|
|
|
|
'bills.amount_max',
|
|
|
|
'bills.date',
|
|
|
|
'bills.transaction_currency_id',
|
|
|
|
'bills.repeat_freq',
|
|
|
|
'bills.skip',
|
|
|
|
'bills.automatch',
|
|
|
|
'bills.active',
|
|
|
|
];
|
2016-10-01 09:37:18 +02:00
|
|
|
$ids = $accounts->pluck('id')->toArray();
|
2020-11-11 19:14:05 +01:00
|
|
|
|
2020-10-23 19:11:25 +02:00
|
|
|
return $this->user->bills()
|
2020-11-11 19:14:05 +01:00
|
|
|
->leftJoin(
|
|
|
|
'transaction_journals',
|
|
|
|
static function (JoinClause $join) {
|
|
|
|
$join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
|
|
|
|
}
|
|
|
|
)
|
|
|
|
->leftJoin(
|
|
|
|
'transactions',
|
|
|
|
static function (JoinClause $join) {
|
|
|
|
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
->whereIn('transactions.account_id', $ids)
|
|
|
|
->whereNull('transaction_journals.deleted_at')
|
|
|
|
->orderBy('bills.active', 'DESC')
|
|
|
|
->orderBy('bills.name', 'ASC')
|
|
|
|
->groupBy($fields)
|
|
|
|
->get($fields);
|
2015-12-12 10:33:19 +01:00
|
|
|
}
|
|
|
|
|
2018-05-07 20:35:14 +02:00
|
|
|
/**
|
|
|
|
* Get all bills with these ID's.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param array $billIds
|
2018-05-07 20:35:14 +02:00
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getByIds(array $billIds): Collection
|
|
|
|
{
|
|
|
|
return $this->user->bills()->whereIn('id', $billIds)->get();
|
|
|
|
}
|
|
|
|
|
2018-04-29 07:46:03 +02:00
|
|
|
/**
|
|
|
|
* Get text or return empty string.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
2018-04-29 07:46:03 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getNoteText(Bill $bill): string
|
|
|
|
{
|
2023-11-04 06:52:40 +01:00
|
|
|
/** @var Note|null $note */
|
2018-04-29 07:46:03 +02:00
|
|
|
$note = $bill->notes()->first();
|
2023-11-04 06:52:40 +01:00
|
|
|
return (string)$note?->text;
|
2018-04-29 07:46:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-23 21:37:06 +02:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
2016-07-23 21:37:06 +02:00
|
|
|
*
|
2020-08-06 20:08:04 +02:00
|
|
|
* @return array
|
2016-07-23 21:37:06 +02:00
|
|
|
*/
|
2020-08-06 20:08:04 +02:00
|
|
|
public function getOverallAverage(Bill $bill): array
|
2016-07-23 21:37:06 +02:00
|
|
|
{
|
2018-02-25 19:09:05 +01:00
|
|
|
/** @var JournalRepositoryInterface $repos */
|
|
|
|
$repos = app(JournalRepositoryInterface::class);
|
|
|
|
$repos->setUser($this->user);
|
2020-08-06 20:08:04 +02:00
|
|
|
|
|
|
|
// get and sort on currency
|
2020-11-11 19:14:05 +01:00
|
|
|
$result = [];
|
2016-08-26 09:30:52 +02:00
|
|
|
$journals = $bill->transactionJournals()->get();
|
2020-08-06 20:08:04 +02:00
|
|
|
|
2016-07-23 21:37:06 +02:00
|
|
|
/** @var TransactionJournal $journal */
|
|
|
|
foreach ($journals as $journal) {
|
2020-08-06 20:08:04 +02:00
|
|
|
/** @var Transaction $transaction */
|
|
|
|
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
2022-12-29 19:42:26 +01:00
|
|
|
$currencyId = (int)$journal->transaction_currency_id;
|
2020-08-06 20:08:04 +02:00
|
|
|
$currency = $journal->transactionCurrency;
|
2023-12-10 06:45:59 +01:00
|
|
|
$result[$currencyId] ??= [
|
2022-12-29 19:42:26 +01:00
|
|
|
'sum' => '0',
|
|
|
|
'count' => 0,
|
|
|
|
'avg' => '0',
|
|
|
|
'currency_id' => $currency->id,
|
|
|
|
'currency_code' => $currency->code,
|
|
|
|
'currency_symbol' => $currency->symbol,
|
|
|
|
'currency_decimal_places' => $currency->decimal_places,
|
|
|
|
];
|
2020-08-06 20:08:04 +02:00
|
|
|
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], $transaction->amount);
|
|
|
|
$result[$currencyId]['count']++;
|
2016-07-23 21:37:06 +02:00
|
|
|
}
|
|
|
|
|
2020-08-06 20:08:04 +02:00
|
|
|
// after loop, re-loop for avg.
|
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @var int $currencyId
|
2020-08-06 20:08:04 +02:00
|
|
|
* @var array $arr
|
|
|
|
*/
|
|
|
|
foreach ($result as $currencyId => $arr) {
|
2022-12-29 19:42:26 +01:00
|
|
|
$result[$currencyId]['avg'] = bcdiv($arr['sum'], (string)$arr['count']);
|
2020-08-06 20:08:04 +02:00
|
|
|
}
|
2020-11-11 19:14:05 +01:00
|
|
|
|
2020-08-06 20:08:04 +02:00
|
|
|
return $result;
|
2016-07-23 21:37:06 +02:00
|
|
|
}
|
|
|
|
|
2018-02-06 18:11:33 +01:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param User|Authenticatable|null $user
|
|
|
|
*/
|
|
|
|
public function setUser(User | Authenticatable | null $user): void
|
|
|
|
{
|
2023-10-30 19:49:40 +01:00
|
|
|
if ($user instanceof User) {
|
2023-06-21 12:34:58 +02:00
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $size
|
2018-02-06 18:11:33 +01:00
|
|
|
*
|
|
|
|
* @return LengthAwarePaginator
|
|
|
|
*/
|
|
|
|
public function getPaginator(int $size): LengthAwarePaginator
|
|
|
|
{
|
2019-08-23 06:40:48 +02:00
|
|
|
return $this->user->bills()
|
|
|
|
->orderBy('active', 'DESC')
|
|
|
|
->orderBy('name', 'ASC')->paginate($size);
|
2018-02-06 18:11:33 +01:00
|
|
|
}
|
|
|
|
|
2016-10-23 14:56:05 +02:00
|
|
|
/**
|
2017-06-28 15:45:28 +02:00
|
|
|
* The "paid dates" list is a list of dates of transaction journals that are linked to this bill.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
2016-10-23 14:56:05 +02:00
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getPaidDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection
|
|
|
|
{
|
2023-10-29 06:33:43 +01:00
|
|
|
//app('log')->debug('Now in getPaidDatesInRange()');
|
2020-11-11 19:14:05 +01:00
|
|
|
|
2019-08-21 04:59:35 +02:00
|
|
|
return $bill->transactionJournals()
|
|
|
|
->before($end)->after($start)->get(
|
2023-12-10 06:45:59 +01:00
|
|
|
[
|
2023-05-29 13:56:55 +02:00
|
|
|
'transaction_journals.id',
|
|
|
|
'transaction_journals.date',
|
|
|
|
'transaction_journals.transaction_group_id',
|
|
|
|
]
|
2023-12-10 06:45:59 +01:00
|
|
|
);
|
2016-10-23 14:56:05 +02:00
|
|
|
}
|
|
|
|
|
2018-04-14 09:59:04 +02:00
|
|
|
/**
|
|
|
|
* Return all rules for one bill
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
2018-04-14 09:59:04 +02:00
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getRulesForBill(Bill $bill): Collection
|
|
|
|
{
|
|
|
|
return $this->user->rules()
|
|
|
|
->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id')
|
|
|
|
->where('rule_actions.action_type', 'link_to_bill')
|
|
|
|
->where('rule_actions.action_value', $bill->name)
|
|
|
|
->get(['rules.*']);
|
|
|
|
}
|
|
|
|
|
2018-04-08 17:36:37 +02:00
|
|
|
/**
|
|
|
|
* Return all rules related to the bills in the collection, in an associative array:
|
|
|
|
* 5= billid
|
|
|
|
*
|
|
|
|
* 5 => [['id' => 1, 'title' => 'Some rule'],['id' => 2, 'title' => 'Some other rule']]
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Collection $collection
|
2018-04-08 17:36:37 +02:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getRulesForBills(Collection $collection): array
|
|
|
|
{
|
|
|
|
$rules = $this->user->rules()
|
|
|
|
->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id')
|
|
|
|
->where('rule_actions.action_type', 'link_to_bill')
|
2018-05-07 20:35:14 +02:00
|
|
|
->get(['rules.id', 'rules.title', 'rule_actions.action_value', 'rules.active']);
|
2018-04-08 17:36:37 +02:00
|
|
|
$array = [];
|
2021-04-07 07:53:05 +02:00
|
|
|
/** @var Rule $rule */
|
2018-04-08 17:36:37 +02:00
|
|
|
foreach ($rules as $rule) {
|
2023-12-10 06:45:59 +01:00
|
|
|
$array[$rule->action_value] ??= [];
|
2018-05-07 20:35:14 +02:00
|
|
|
$array[$rule->action_value][] = ['id' => $rule->id, 'title' => $rule->title, 'active' => $rule->active];
|
2018-04-08 17:36:37 +02:00
|
|
|
}
|
|
|
|
$return = [];
|
|
|
|
foreach ($collection as $bill) {
|
|
|
|
$return[$bill->id] = $array[$bill->name] ?? [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2016-07-23 21:37:06 +02:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
|
|
|
* @param Carbon $date
|
2016-07-23 21:37:06 +02:00
|
|
|
*
|
2020-08-06 20:08:04 +02:00
|
|
|
* @return array
|
2016-07-23 21:37:06 +02:00
|
|
|
*/
|
2020-08-06 20:08:04 +02:00
|
|
|
public function getYearAverage(Bill $bill, Carbon $date): array
|
2016-07-23 21:37:06 +02:00
|
|
|
{
|
2018-02-25 19:09:05 +01:00
|
|
|
/** @var JournalRepositoryInterface $repos */
|
|
|
|
$repos = app(JournalRepositoryInterface::class);
|
|
|
|
$repos->setUser($this->user);
|
|
|
|
|
2020-08-06 20:08:04 +02:00
|
|
|
// get and sort on currency
|
|
|
|
$result = [];
|
|
|
|
|
2016-08-26 09:30:52 +02:00
|
|
|
$journals = $bill->transactionJournals()
|
2023-06-21 12:34:58 +02:00
|
|
|
->where('date', '>=', $date->year . '-01-01 00:00:00')
|
|
|
|
->where('date', '<=', $date->year . '-12-31 23:59:59')
|
2016-07-23 21:37:06 +02:00
|
|
|
->get();
|
2020-08-06 20:08:04 +02:00
|
|
|
|
2016-07-23 21:37:06 +02:00
|
|
|
/** @var TransactionJournal $journal */
|
|
|
|
foreach ($journals as $journal) {
|
2023-11-04 06:52:40 +01:00
|
|
|
/** @var Transaction|null $transaction */
|
2020-11-11 19:14:05 +01:00
|
|
|
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
|
|
|
if (null === $transaction) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-12-29 19:42:26 +01:00
|
|
|
$currencyId = (int)$journal->transaction_currency_id;
|
2020-08-06 20:08:04 +02:00
|
|
|
$currency = $journal->transactionCurrency;
|
2023-12-10 06:45:59 +01:00
|
|
|
$result[$currencyId] ??= [
|
2022-12-29 19:42:26 +01:00
|
|
|
'sum' => '0',
|
|
|
|
'count' => 0,
|
|
|
|
'avg' => '0',
|
|
|
|
'currency_id' => $currency->id,
|
|
|
|
'currency_code' => $currency->code,
|
|
|
|
'currency_symbol' => $currency->symbol,
|
|
|
|
'currency_decimal_places' => $currency->decimal_places,
|
|
|
|
];
|
2020-08-06 20:08:04 +02:00
|
|
|
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], $transaction->amount);
|
|
|
|
$result[$currencyId]['count']++;
|
2016-07-23 21:37:06 +02:00
|
|
|
}
|
|
|
|
|
2020-08-06 20:08:04 +02:00
|
|
|
// after loop, re-loop for avg.
|
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @var int $currencyId
|
2020-08-06 20:08:04 +02:00
|
|
|
* @var array $arr
|
|
|
|
*/
|
|
|
|
foreach ($result as $currencyId => $arr) {
|
2022-12-29 19:42:26 +01:00
|
|
|
$result[$currencyId]['avg'] = bcdiv($arr['sum'], (string)$arr['count']);
|
2020-08-06 20:08:04 +02:00
|
|
|
}
|
2020-11-11 19:14:05 +01:00
|
|
|
|
2020-08-06 20:08:04 +02:00
|
|
|
return $result;
|
2016-07-23 21:37:06 +02:00
|
|
|
}
|
|
|
|
|
2018-04-14 09:59:04 +02:00
|
|
|
/**
|
|
|
|
* Link a set of journals to a bill.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
|
|
|
* @param array $transactions
|
2018-04-14 09:59:04 +02:00
|
|
|
*/
|
2019-07-21 17:15:06 +02:00
|
|
|
public function linkCollectionToBill(Bill $bill, array $transactions): void
|
2018-04-14 09:59:04 +02:00
|
|
|
{
|
2018-04-14 23:25:28 +02:00
|
|
|
/** @var Transaction $transaction */
|
|
|
|
foreach ($transactions as $transaction) {
|
2022-12-29 19:42:26 +01:00
|
|
|
$journal = $bill->user->transactionJournals()->find((int)$transaction['transaction_journal_id']);
|
2018-04-14 23:23:47 +02:00
|
|
|
$journal->bill_id = $bill->id;
|
|
|
|
$journal->save();
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Linked journal #%d to bill #%d', $journal->id, $bill->id));
|
2018-04-14 23:23:47 +02:00
|
|
|
}
|
2018-04-14 09:59:04 +02:00
|
|
|
}
|
|
|
|
|
2016-10-21 06:26:12 +02:00
|
|
|
/**
|
|
|
|
* Given the date in $date, this method will return a moment in the future where the bill is expected to be paid.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
|
|
|
* @param Carbon $date
|
2015-02-25 15:19:14 +01:00
|
|
|
*
|
2016-10-20 21:40:45 +02:00
|
|
|
* @return Carbon
|
2021-09-18 10:26:12 +02:00
|
|
|
* @throws JsonException
|
2015-02-25 15:19:14 +01:00
|
|
|
*/
|
2016-10-20 21:40:45 +02:00
|
|
|
public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon
|
2015-02-25 15:19:14 +01:00
|
|
|
{
|
2022-10-30 14:24:28 +01:00
|
|
|
$cache = new CacheProperties();
|
2016-10-20 21:40:45 +02:00
|
|
|
$cache->addProperty($bill->id);
|
|
|
|
$cache->addProperty('nextExpectedMatch');
|
2016-10-21 06:26:12 +02:00
|
|
|
$cache->addProperty($date);
|
2016-10-20 21:40:45 +02:00
|
|
|
if ($cache->has()) {
|
2021-06-30 06:17:38 +02:00
|
|
|
return $cache->get();
|
2015-02-25 15:19:14 +01:00
|
|
|
}
|
2016-10-20 21:40:45 +02:00
|
|
|
// find the most recent date for this bill NOT in the future. Cache this date:
|
|
|
|
$start = clone $bill->date;
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug('nextExpectedMatch: Start is ' . $start->format('Y-m-d'));
|
2016-10-20 21:40:45 +02:00
|
|
|
|
2016-10-21 07:29:25 +02:00
|
|
|
while ($start < $date) {
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('$start (%s) < $date (%s)', $start->format('Y-m-d'), $date->format('Y-m-d')));
|
2018-02-22 20:07:14 +01:00
|
|
|
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug('Start is now ' . $start->format('Y-m-d'));
|
2016-10-21 07:29:25 +02:00
|
|
|
}
|
2016-10-20 21:40:45 +02:00
|
|
|
|
2018-02-22 20:07:14 +01:00
|
|
|
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
2016-10-20 21:40:45 +02:00
|
|
|
|
|
|
|
// see if the bill was paid in this period.
|
|
|
|
$journalCount = $bill->transactionJournals()->before($end)->after($start)->count();
|
|
|
|
|
|
|
|
if ($journalCount > 0) {
|
|
|
|
// this period had in fact a bill. The new start is the current end, and we create a new end.
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Journal count is %d, so start becomes %s', $journalCount, $end->format('Y-m-d')));
|
2016-10-20 21:40:45 +02:00
|
|
|
$start = clone $end;
|
2018-02-22 20:07:14 +01:00
|
|
|
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
2015-02-25 15:19:14 +01:00
|
|
|
}
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug('nextExpectedMatch: Final start is ' . $start->format('Y-m-d'));
|
|
|
|
app('log')->debug('nextExpectedMatch: Matching end is ' . $end->format('Y-m-d'));
|
2016-10-21 07:29:25 +02:00
|
|
|
|
2016-10-20 21:40:45 +02:00
|
|
|
$cache->store($start);
|
2015-02-25 15:19:14 +01:00
|
|
|
|
2016-10-20 21:40:45 +02:00
|
|
|
return $start;
|
2015-02-25 15:19:14 +01:00
|
|
|
}
|
|
|
|
|
2023-06-21 12:34:58 +02:00
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return Bill
|
|
|
|
* @throws FireflyException
|
|
|
|
* @throws JsonException
|
|
|
|
*/
|
|
|
|
public function store(array $data): Bill
|
|
|
|
{
|
|
|
|
/** @var BillFactory $factory */
|
|
|
|
$factory = app(BillFactory::class);
|
|
|
|
$factory->setUser($this->user);
|
|
|
|
|
|
|
|
return $factory->create($data);
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:20:01 +01:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function removeObjectGroup(Bill $bill): Bill
|
|
|
|
{
|
|
|
|
$bill->objectGroups()->sync([]);
|
|
|
|
|
|
|
|
return $bill;
|
|
|
|
}
|
|
|
|
|
2019-03-02 14:12:09 +01:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param string $query
|
|
|
|
* @param int $limit
|
2019-03-02 14:12:09 +01:00
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2020-07-21 06:22:29 +02:00
|
|
|
public function searchBill(string $query, int $limit): Collection
|
2019-03-02 14:12:09 +01:00
|
|
|
{
|
|
|
|
$query = sprintf('%%%s%%', $query);
|
|
|
|
|
2020-07-21 06:22:29 +02:00
|
|
|
return $this->user->bills()->where('name', 'LIKE', $query)->take($limit)->get();
|
2019-03-02 14:12:09 +01:00
|
|
|
}
|
|
|
|
|
2021-03-12 06:20:01 +01:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function setObjectGroup(Bill $bill, string $objectGroupTitle): Bill
|
|
|
|
{
|
|
|
|
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
|
|
|
|
if (null !== $objectGroup) {
|
|
|
|
$bill->objectGroups()->sync([$objectGroup->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $bill;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function setOrder(Bill $bill, int $order): void
|
|
|
|
{
|
|
|
|
$bill->order = $order;
|
|
|
|
$bill->save();
|
|
|
|
}
|
|
|
|
|
2017-01-30 16:46:30 +01:00
|
|
|
/**
|
2022-12-29 19:42:26 +01:00
|
|
|
* @inheritDoc
|
2017-01-30 16:46:30 +01:00
|
|
|
*/
|
2022-12-29 19:42:26 +01:00
|
|
|
public function sumPaidInRange(Carbon $start, Carbon $end): array
|
2017-01-30 16:46:30 +01:00
|
|
|
{
|
2022-12-29 19:42:26 +01:00
|
|
|
$bills = $this->getActiveBills();
|
|
|
|
$return = [];
|
|
|
|
/** @var Bill $bill */
|
|
|
|
foreach ($bills as $bill) {
|
|
|
|
/** @var Collection $set */
|
|
|
|
$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);
|
|
|
|
$currency = $bill->transactionCurrency;
|
2023-06-01 19:49:28 +02:00
|
|
|
|
2023-12-10 06:45:59 +01:00
|
|
|
$return[$currency->id] ??= [
|
2023-06-01 19:49:28 +02:00
|
|
|
'id' => (string)$currency->id,
|
|
|
|
'name' => $currency->name,
|
|
|
|
'symbol' => $currency->symbol,
|
|
|
|
'code' => $currency->code,
|
|
|
|
'decimal_places' => $currency->decimal_places,
|
|
|
|
'sum' => '0',
|
|
|
|
];
|
|
|
|
|
|
|
|
/** @var TransactionJournal $transactionJournal */
|
|
|
|
foreach ($set as $transactionJournal) {
|
2023-06-18 06:26:38 +02:00
|
|
|
/** @var Transaction|null $sourceTransaction */
|
2023-06-01 19:49:28 +02:00
|
|
|
$sourceTransaction = $transactionJournal->transactions()->where('amount', '<', 0)->first();
|
2023-06-18 06:26:38 +02:00
|
|
|
if (null !== $sourceTransaction) {
|
2023-11-05 19:41:37 +01:00
|
|
|
$amount = $sourceTransaction->amount;
|
|
|
|
if ((int)$sourceTransaction->foreign_currency_id === $currency->id) {
|
2023-06-18 06:26:38 +02:00
|
|
|
// use foreign amount instead!
|
|
|
|
$amount = (string)$sourceTransaction->foreign_amount;
|
|
|
|
}
|
|
|
|
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
|
2023-06-01 19:49:28 +02:00
|
|
|
}
|
2022-12-29 19:42:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
2017-01-30 16:46:30 +01:00
|
|
|
}
|
|
|
|
|
2023-06-21 12:34:58 +02:00
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getActiveBills(): Collection
|
|
|
|
{
|
|
|
|
return $this->user->bills()
|
|
|
|
->where('active', true)
|
|
|
|
->orderBy('bills.name', 'ASC')
|
2023-11-28 05:05:42 +01:00
|
|
|
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]); // @phpstan-ignore-line
|
2023-06-21 12:34:58 +02:00
|
|
|
}
|
|
|
|
|
2015-02-25 15:19:14 +01:00
|
|
|
/**
|
2022-12-29 19:42:26 +01:00
|
|
|
* @inheritDoc
|
2015-02-25 15:19:14 +01:00
|
|
|
*/
|
2022-12-29 19:42:26 +01:00
|
|
|
public function sumUnpaidInRange(Carbon $start, Carbon $end): array
|
2015-02-25 15:19:14 +01:00
|
|
|
{
|
2023-10-14 07:13:35 +02:00
|
|
|
app('log')->debug(sprintf('Now in sumUnpaidInRange("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d')));
|
2022-12-29 19:42:26 +01:00
|
|
|
$bills = $this->getActiveBills();
|
|
|
|
$return = [];
|
|
|
|
/** @var Bill $bill */
|
|
|
|
foreach ($bills as $bill) {
|
2023-10-14 07:13:35 +02:00
|
|
|
app('log')->debug(sprintf('Processing bill #%d ("%s")', $bill->id, $bill->name));
|
2022-12-29 19:42:26 +01:00
|
|
|
$dates = $this->getPayDatesInRange($bill, $start, $end);
|
|
|
|
$count = $bill->transactionJournals()->after($start)->before($end)->count();
|
|
|
|
$total = $dates->count() - $count;
|
2023-10-14 07:13:35 +02:00
|
|
|
app('log')->debug(sprintf('Pay dates: %d, count: %d, left: %d', $dates->count(), $count, $total));
|
|
|
|
app('log')->debug('dates', $dates->toArray());
|
2015-02-25 15:19:14 +01:00
|
|
|
|
2022-12-29 19:42:26 +01:00
|
|
|
if ($total > 0) {
|
|
|
|
$currency = $bill->transactionCurrency;
|
|
|
|
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
|
2023-12-10 06:45:59 +01:00
|
|
|
$return[$currency->id] ??= [
|
2022-12-29 19:42:26 +01:00
|
|
|
'id' => (string)$currency->id,
|
|
|
|
'name' => $currency->name,
|
|
|
|
'symbol' => $currency->symbol,
|
|
|
|
'code' => $currency->code,
|
|
|
|
'decimal_places' => $currency->decimal_places,
|
|
|
|
'sum' => '0',
|
|
|
|
];
|
|
|
|
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], bcmul($average, (string)$total));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
2015-02-25 15:19:14 +01:00
|
|
|
}
|
|
|
|
|
2019-09-23 17:11:01 +02:00
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* Between start and end, tells you on which date(s) the bill is expected to hit.
|
|
|
|
*
|
|
|
|
* @param Bill $bill
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection
|
|
|
|
{
|
|
|
|
$set = new Collection();
|
|
|
|
$currentStart = clone $start;
|
2023-10-29 06:33:43 +01:00
|
|
|
//app('log')->debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq));
|
|
|
|
//app('log')->debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d')));
|
2023-06-21 12:34:58 +02:00
|
|
|
|
|
|
|
while ($currentStart <= $end) {
|
2023-10-29 06:33:43 +01:00
|
|
|
//app('log')->debug(sprintf('Currentstart is now %s.', $currentStart->format('Y-m-d')));
|
2023-06-21 12:34:58 +02:00
|
|
|
$nextExpectedMatch = $this->nextDateMatch($bill, $currentStart);
|
2023-10-29 06:33:43 +01:00
|
|
|
//app('log')->debug(sprintf('Next Date match after %s is %s', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
2023-06-21 12:34:58 +02:00
|
|
|
if ($nextExpectedMatch > $end) {// If nextExpectedMatch is after end, we continue
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$set->push(clone $nextExpectedMatch);
|
2023-10-29 06:33:43 +01:00
|
|
|
//app('log')->debug(sprintf('Now %d dates in set.', $set->count()));
|
2023-06-21 12:34:58 +02:00
|
|
|
$nextExpectedMatch->addDay();
|
|
|
|
|
2023-10-29 06:33:43 +01:00
|
|
|
//app('log')->debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
2023-06-21 12:34:58 +02:00
|
|
|
|
|
|
|
$currentStart = clone $nextExpectedMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $set;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a bill and a date, this method will tell you at which moment this bill expects its next
|
|
|
|
* transaction. Whether or not it is there already, is not relevant.
|
|
|
|
*
|
|
|
|
* @param Bill $bill
|
|
|
|
* @param Carbon $date
|
|
|
|
*
|
|
|
|
* @return Carbon
|
|
|
|
*/
|
|
|
|
public function nextDateMatch(Bill $bill, Carbon $date): Carbon
|
|
|
|
{
|
|
|
|
$cache = new CacheProperties();
|
|
|
|
$cache->addProperty($bill->id);
|
|
|
|
$cache->addProperty('nextDateMatch');
|
|
|
|
$cache->addProperty($date);
|
|
|
|
if ($cache->has()) {
|
|
|
|
return $cache->get();
|
|
|
|
}
|
|
|
|
// find the most recent date for this bill NOT in the future. Cache this date:
|
|
|
|
$start = clone $bill->date;
|
|
|
|
|
|
|
|
while ($start < $date) {
|
|
|
|
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
|
|
|
}
|
|
|
|
$cache->store($start);
|
|
|
|
|
|
|
|
return $start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Bill $bill
|
2019-09-23 17:11:01 +02:00
|
|
|
*/
|
|
|
|
public function unlinkAll(Bill $bill): void
|
|
|
|
{
|
|
|
|
$this->user->transactionJournals()->where('bill_id', $bill->id)->update(['bill_id' => null]);
|
|
|
|
}
|
2020-06-30 20:33:08 +02:00
|
|
|
|
|
|
|
/**
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Bill $bill
|
|
|
|
* @param array $data
|
2021-03-12 06:20:01 +01:00
|
|
|
*
|
|
|
|
* @return Bill
|
2023-02-22 18:03:31 +01:00
|
|
|
* @throws FireflyException
|
|
|
|
* @throws JsonException
|
2020-07-01 06:33:21 +02:00
|
|
|
*/
|
2021-03-12 06:20:01 +01:00
|
|
|
public function update(Bill $bill, array $data): Bill
|
2020-07-01 06:33:21 +02:00
|
|
|
{
|
2021-03-12 06:20:01 +01:00
|
|
|
/** @var BillUpdateService $service */
|
|
|
|
$service = app(BillUpdateService::class);
|
2020-07-11 15:13:15 +02:00
|
|
|
|
2021-03-12 06:20:01 +01:00
|
|
|
return $service->update($bill, $data);
|
2020-07-11 15:13:15 +02:00
|
|
|
}
|
2015-02-25 15:19:14 +01:00
|
|
|
}
|