mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 10:16:49 +00:00
Auto commit for release 'branch-v6.2' on 2024-12-27
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ConvertsDatesToUTC.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -74,7 +75,9 @@ class ConvertsDatesToUTC extends Command
|
||||
public function handle(): int
|
||||
{
|
||||
$this->friendlyWarning('Please do not use this command.');
|
||||
|
||||
return 0;
|
||||
|
||||
/**
|
||||
* @var string $model
|
||||
* @var array $fields
|
||||
|
@@ -66,13 +66,13 @@ class CorrectsDatabase extends Command
|
||||
'correction:ibans',
|
||||
'correction:account-order',
|
||||
'correction:meta-fields',
|
||||
'correction:opening-balance-currencies',
|
||||
'correction:long-descriptions',
|
||||
'correction:recurring-transactions',
|
||||
'correction:frontpage-accounts',
|
||||
'correction:group-accounts',
|
||||
'correction:recalculates-liabilities',
|
||||
'correction:preferences',
|
||||
'correction:opening-balance-currencies',
|
||||
'correction:long-descriptions',
|
||||
'correction:recurring-transactions',
|
||||
'correction:frontpage-accounts',
|
||||
'correction:group-accounts',
|
||||
'correction:recalculates-liabilities',
|
||||
'correction:preferences',
|
||||
// 'correction:transaction-types', // resource heavy, disabled.
|
||||
// 'correction:recalculate-native-amounts', // not necessary, disabled.
|
||||
'firefly-iii:report-integrity',
|
||||
|
@@ -52,6 +52,7 @@ class CorrectsFrontpageAccounts extends Command
|
||||
$this->fixPreference($preference);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,7 @@ class CorrectsLongDescriptions extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$journals = TransactionJournal::where(DB::raw('LENGTH(description)'),'>', self::MAX_LENGTH)->get(['id', 'description']);
|
||||
$journals = TransactionJournal::where(DB::raw('LENGTH(description)'), '>', self::MAX_LENGTH)->get(['id', 'description']);
|
||||
$count = 0;
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
@@ -56,7 +56,7 @@ class CorrectsLongDescriptions extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$groups = TransactionGroup::where(DB::raw('LENGTH(title)'),'>', self::MAX_LENGTH)->get(['id', 'title']);
|
||||
$groups = TransactionGroup::where(DB::raw('LENGTH(title)'), '>', self::MAX_LENGTH)->get(['id', 'title']);
|
||||
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* CorrectsTimezoneInformation.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
|
@@ -63,7 +63,7 @@ class RemovesOrphanedTransactions extends Command
|
||||
;
|
||||
$count = $set->count();
|
||||
if (0 === $count) {
|
||||
//$this->friendlyPositive('No orphaned journals.');
|
||||
// $this->friendlyPositive('No orphaned journals.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ class ReportsIntegrity extends Command
|
||||
return 1;
|
||||
}
|
||||
$commands = [
|
||||
//'firefly-iii:add-timezones-to-dates',
|
||||
// 'firefly-iii:add-timezones-to-dates',
|
||||
'integrity:empty-objects',
|
||||
'integrity:total-sums',
|
||||
];
|
||||
|
@@ -39,7 +39,6 @@ class ReportsSums extends Command
|
||||
protected $description = 'Report on the total sum of transactions. Must be 0.';
|
||||
protected $signature = 'integrity:total-sums';
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* UpgradesNativeAmounts.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@@ -30,14 +32,12 @@ class UpgradesNativeAmounts extends Command
|
||||
use ShowsFriendlyMessages;
|
||||
public const string CONFIG_NAME = '620_native_amounts';
|
||||
|
||||
protected $description = 'Runs the native amounts calculations.';
|
||||
protected $description = 'Runs the native amounts calculations.';
|
||||
|
||||
protected $signature = 'upgrade:620-native-amounts {--F|force : Force the execution of this command.}';
|
||||
protected $signature = 'upgrade:620-native-amounts {--F|force : Force the execution of this command.}';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -55,9 +55,6 @@ class UpgradesNativeAmounts extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
@@ -68,10 +65,6 @@ class UpgradesNativeAmounts extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -36,7 +36,6 @@ use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
||||
class UpgradesVariousCurrencyInformation extends Command
|
||||
{
|
||||
use ShowsFriendlyMessages;
|
||||
|
@@ -133,8 +133,8 @@ class BillController extends Controller
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
$currency = $bill->transactionCurrency;
|
||||
if($this->convertToNative) {
|
||||
$currency = $bill->transactionCurrency;
|
||||
if ($this->convertToNative) {
|
||||
$currency = $this->defaultCurrency;
|
||||
}
|
||||
|
||||
@@ -162,9 +162,9 @@ class BillController extends Controller
|
||||
],
|
||||
];
|
||||
$currencyId = $bill->transaction_currency_id;
|
||||
$amountMin = $bill->amount_min;
|
||||
$amountMax = $bill->amount_max;
|
||||
if($this->convertToNative && $currencyId !== $this->defaultCurrency->id) {
|
||||
$amountMin = $bill->amount_min;
|
||||
$amountMax = $bill->amount_max;
|
||||
if ($this->convertToNative && $currencyId !== $this->defaultCurrency->id) {
|
||||
$amountMin = $bill->native_amount_min;
|
||||
$amountMax = $bill->native_amount_max;
|
||||
}
|
||||
@@ -178,10 +178,10 @@ class BillController extends Controller
|
||||
$chartData[2]['entries'][$date] = '0';
|
||||
}
|
||||
$amount = bcmul($journal['amount'], '-1');
|
||||
if($this->convertToNative && $currencyId !== $journal['currency_id']) {
|
||||
$amount = bcmul($journal['native_amount'], '-1');
|
||||
if ($this->convertToNative && $currencyId !== $journal['currency_id']) {
|
||||
$amount = bcmul($journal['native_amount'], '-1');
|
||||
}
|
||||
if($this->convertToNative && $currencyId === $journal['foreign_currency_id']) {
|
||||
if ($this->convertToNative && $currencyId === $journal['foreign_currency_id']) {
|
||||
$amount = bcmul($journal['foreign_amount'], '-1');
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@ class Preference extends Model
|
||||
use ReturnsIntegerUserIdTrait;
|
||||
|
||||
protected $casts
|
||||
= [
|
||||
= [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'data' => 'array',
|
||||
@@ -56,7 +56,7 @@ class Preference extends Model
|
||||
{
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
|
||||
// some preferences do not have an administration ID.
|
||||
// some need it, to make sure the correct one is selected.
|
||||
@@ -64,8 +64,8 @@ class Preference extends Model
|
||||
$userGroupId = 0 === $userGroupId ? null : $userGroupId;
|
||||
|
||||
/** @var null|Preference $preference */
|
||||
$preference = null;
|
||||
$items = config('firefly.admin_specific_prefs');
|
||||
$preference = null;
|
||||
$items = config('firefly.admin_specific_prefs');
|
||||
if (null !== $userGroupId && in_array($value, $items, true)) {
|
||||
// find a preference with a specific user_group_id
|
||||
$preference = $user->preferences()->where('user_group_id', $userGroupId)->where('name', $value)->first();
|
||||
@@ -82,7 +82,7 @@ class Preference extends Model
|
||||
if (null !== $preference) {
|
||||
return $preference;
|
||||
}
|
||||
$default = config('firefly.default_preferences');
|
||||
$default = config('firefly.default_preferences');
|
||||
if (array_key_exists($value, $default)) {
|
||||
$preference = new self();
|
||||
$preference->name = $value;
|
||||
|
@@ -46,19 +46,19 @@ class Transaction extends Model
|
||||
|
||||
protected $casts
|
||||
= [
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
'identifier' => 'int',
|
||||
'encrypted' => 'boolean', // model does not have these fields though
|
||||
'bill_name_encrypted' => 'boolean',
|
||||
'reconciled' => 'boolean',
|
||||
'balance_dirty' => 'boolean',
|
||||
'balance_before' => 'string',
|
||||
'balance_after' => 'string',
|
||||
'date' => 'datetime',
|
||||
'amount' => 'string',
|
||||
'foreign_amount' => 'string',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
'identifier' => 'int',
|
||||
'encrypted' => 'boolean', // model does not have these fields though
|
||||
'bill_name_encrypted' => 'boolean',
|
||||
'reconciled' => 'boolean',
|
||||
'balance_dirty' => 'boolean',
|
||||
'balance_before' => 'string',
|
||||
'balance_after' => 'string',
|
||||
'date' => 'datetime',
|
||||
'amount' => 'string',
|
||||
'foreign_amount' => 'string',
|
||||
'native_amount' => 'string',
|
||||
'native_foreign_amount' => 'string',
|
||||
];
|
||||
|
@@ -61,7 +61,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
$search->whereLike('name', sprintf('%%%s', $query));
|
||||
}
|
||||
$search->orderBy('name', 'ASC')
|
||||
->where('active', true);
|
||||
->where('active', true)
|
||||
;
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
@@ -73,7 +74,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
$search->whereLike('name', sprintf('%s%%', $query));
|
||||
}
|
||||
$search->orderBy('name', 'ASC')
|
||||
->where('active', true);
|
||||
->where('active', true)
|
||||
;
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
@@ -156,7 +158,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
*/
|
||||
public function getAttachments(Bill $bill): Collection
|
||||
{
|
||||
$set = $bill->attachments()->get();
|
||||
$set = $bill->attachments()->get();
|
||||
|
||||
/** @var \Storage $disk */
|
||||
$disk = \Storage::disk('upload');
|
||||
@@ -175,9 +177,10 @@ class BillRepository implements BillRepositoryInterface
|
||||
public function getBills(): Collection
|
||||
{
|
||||
return $this->user->bills()
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('name', 'ASC')->get();
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('name', 'ASC')->get()
|
||||
;
|
||||
}
|
||||
|
||||
public function getBillsForAccounts(Collection $accounts): Collection
|
||||
@@ -201,24 +204,25 @@ class BillRepository implements BillRepositoryInterface
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
|
||||
return $this->user->bills()
|
||||
->leftJoin(
|
||||
'transaction_journals',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions',
|
||||
static function (JoinClause $join): void {
|
||||
$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);
|
||||
->leftJoin(
|
||||
'transaction_journals',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions',
|
||||
static function (JoinClause $join): void {
|
||||
$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)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,7 +247,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
public function getOverallAverage(Bill $bill): array
|
||||
{
|
||||
/** @var JournalRepositoryInterface $repos */
|
||||
$repos = app(JournalRepositoryInterface::class);
|
||||
$repos = app(JournalRepositoryInterface::class);
|
||||
$repos->setUser($this->user);
|
||||
|
||||
// get and sort on currency
|
||||
@@ -253,12 +257,12 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$currencyId = (int) $journal->transaction_currency_id;
|
||||
$currency = $journal->transactionCurrency;
|
||||
$result[$currencyId] ??= [
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$currencyId = (int) $journal->transaction_currency_id;
|
||||
$currency = $journal->transactionCurrency;
|
||||
$result[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
'native_sum' => '0',
|
||||
'count' => 0,
|
||||
'avg' => '0',
|
||||
'native_avg' => '0',
|
||||
@@ -267,7 +271,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
];
|
||||
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], $transaction->amount);
|
||||
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], $transaction->amount);
|
||||
$result[$currencyId]['native_sum'] = bcadd($result[$currencyId]['native_sum'], $transaction->native_amount ?? '0');
|
||||
if ($journal->foreign_currency_id === Amount::getDefaultCurrency()->id) {
|
||||
$result[$currencyId]['native_sum'] = bcadd($result[$currencyId]['native_sum'], $transaction->amount);
|
||||
@@ -281,14 +285,14 @@ class BillRepository implements BillRepositoryInterface
|
||||
* @var array $arr
|
||||
*/
|
||||
foreach ($result as $currencyId => $arr) {
|
||||
$result[$currencyId]['avg'] = bcdiv($arr['sum'], (string) $arr['count']);
|
||||
$result[$currencyId]['avg'] = bcdiv($arr['sum'], (string) $arr['count']);
|
||||
$result[$currencyId]['native_avg'] = bcdiv($arr['native_sum'], (string) $arr['count']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setUser(null | Authenticatable | User $user): void
|
||||
public function setUser(null|Authenticatable|User $user): void
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$this->user = $user;
|
||||
@@ -298,8 +302,9 @@ class BillRepository implements BillRepositoryInterface
|
||||
public function getPaginator(int $size): LengthAwarePaginator
|
||||
{
|
||||
return $this->user->bills()
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('name', 'ASC')->paginate($size);
|
||||
->orderBy('active', 'DESC')
|
||||
->orderBy('name', 'ASC')->paginate($size)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,13 +317,14 @@ class BillRepository implements BillRepositoryInterface
|
||||
Log::debug(sprintf('Search for linked journals between %s and %s', $start->toW3cString(), $end->toW3cString()));
|
||||
|
||||
return $bill->transactionJournals()
|
||||
->before($end)->after($start)->get(
|
||||
->before($end)->after($start)->get(
|
||||
[
|
||||
'transaction_journals.id',
|
||||
'transaction_journals.date',
|
||||
'transaction_journals.transaction_group_id',
|
||||
]
|
||||
);
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,10 +333,11 @@ class BillRepository implements BillRepositoryInterface
|
||||
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.*']);
|
||||
->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.*'])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,15 +348,16 @@ class BillRepository implements BillRepositoryInterface
|
||||
*/
|
||||
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')
|
||||
->get(['rules.id', 'rules.title', 'rule_actions.action_value', 'rules.active']);
|
||||
$array = [];
|
||||
$rules = $this->user->rules()
|
||||
->leftJoin('rule_actions', 'rule_actions.rule_id', '=', 'rules.id')
|
||||
->where('rule_actions.action_type', 'link_to_bill')
|
||||
->get(['rules.id', 'rules.title', 'rule_actions.action_value', 'rules.active'])
|
||||
;
|
||||
$array = [];
|
||||
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
$array[$rule->action_value] ??= [];
|
||||
$array[$rule->action_value] ??= [];
|
||||
$array[$rule->action_value][] = ['id' => $rule->id, 'title' => $rule->title, 'active' => $rule->active];
|
||||
}
|
||||
$return = [];
|
||||
@@ -363,27 +371,28 @@ class BillRepository implements BillRepositoryInterface
|
||||
public function getYearAverage(Bill $bill, Carbon $date): array
|
||||
{
|
||||
/** @var JournalRepositoryInterface $repos */
|
||||
$repos = app(JournalRepositoryInterface::class);
|
||||
$repos = app(JournalRepositoryInterface::class);
|
||||
$repos->setUser($this->user);
|
||||
|
||||
// get and sort on currency
|
||||
$result = [];
|
||||
$result = [];
|
||||
|
||||
$journals = $bill->transactionJournals()
|
||||
->where('date', '>=', $date->year . '-01-01 00:00:00')
|
||||
->where('date', '<=', $date->year . '-12-31 23:59:59')
|
||||
->get();
|
||||
->where('date', '>=', $date->year.'-01-01 00:00:00')
|
||||
->where('date', '<=', $date->year.'-12-31 23:59:59')
|
||||
->get()
|
||||
;
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
/** @var null|Transaction $transaction */
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
if (null === $transaction) {
|
||||
continue;
|
||||
}
|
||||
$currencyId = (int) $journal->transaction_currency_id;
|
||||
$currency = $journal->transactionCurrency;
|
||||
$result[$currencyId] ??= [
|
||||
$result[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
'count' => 0,
|
||||
@@ -433,7 +442,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
*/
|
||||
public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($bill->id);
|
||||
$cache->addProperty('nextExpectedMatch');
|
||||
$cache->addProperty($date);
|
||||
@@ -441,17 +450,17 @@ class BillRepository implements BillRepositoryInterface
|
||||
return $cache->get();
|
||||
}
|
||||
// find the most recent date for this bill NOT in the future. Cache this date:
|
||||
$start = clone $bill->date;
|
||||
$start = clone $bill->date;
|
||||
$start->startOfDay();
|
||||
app('log')->debug('nextExpectedMatch: Start is ' . $start->format('Y-m-d'));
|
||||
app('log')->debug('nextExpectedMatch: Start is '.$start->format('Y-m-d'));
|
||||
|
||||
while ($start < $date) {
|
||||
app('log')->debug(sprintf('$start (%s) < $date (%s)', $start->format('Y-m-d H:i:s'), $date->format('Y-m-d H:i:s')));
|
||||
$start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
app('log')->debug('Start is now ' . $start->format('Y-m-d H:i:s'));
|
||||
app('log')->debug('Start is now '.$start->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
$end->endOfDay();
|
||||
|
||||
// see if the bill was paid in this period.
|
||||
@@ -463,8 +472,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
$start = clone $end;
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
}
|
||||
app('log')->debug('nextExpectedMatch: Final start is ' . $start->format('Y-m-d'));
|
||||
app('log')->debug('nextExpectedMatch: Matching end is ' . $end->format('Y-m-d'));
|
||||
app('log')->debug('nextExpectedMatch: Final start is '.$start->format('Y-m-d'));
|
||||
app('log')->debug('nextExpectedMatch: Matching end is '.$end->format('Y-m-d'));
|
||||
|
||||
$cache->store($start);
|
||||
|
||||
@@ -525,8 +534,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
foreach ($bills as $bill) {
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);
|
||||
$currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency;
|
||||
$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);
|
||||
$currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency;
|
||||
$return[(int) $currency->id] ??= [
|
||||
'id' => (string) $currency->id,
|
||||
'name' => $currency->name,
|
||||
@@ -535,7 +544,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
'decimal_places' => $currency->decimal_places,
|
||||
'sum' => '0',
|
||||
];
|
||||
$setAmount = '0';
|
||||
$setAmount = '0';
|
||||
|
||||
/** @var TransactionJournal $transactionJournal */
|
||||
foreach ($set as $transactionJournal) {
|
||||
@@ -552,10 +561,10 @@ class BillRepository implements BillRepositoryInterface
|
||||
public function getActiveBills(): Collection
|
||||
{
|
||||
return $this->user->bills()
|
||||
->where('active', true)
|
||||
->orderBy('bills.name', 'ASC')
|
||||
->get(['bills.*', \DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount')]) // @phpstan-ignore-line
|
||||
;
|
||||
->where('active', true)
|
||||
->orderBy('bills.name', 'ASC')
|
||||
->get(['bills.*', \DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount')]) // @phpstan-ignore-line
|
||||
;
|
||||
}
|
||||
|
||||
public function sumUnpaidInRange(Carbon $start, Carbon $end): array
|
||||
@@ -569,9 +578,9 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var Bill $bill */
|
||||
foreach ($bills as $bill) {
|
||||
// app('log')->debug(sprintf('Processing bill #%d ("%s")', $bill->id, $bill->name));
|
||||
$dates = $this->getPayDatesInRange($bill, $start, $end);
|
||||
$count = $bill->transactionJournals()->after($start)->before($end)->count();
|
||||
$total = $dates->count() - $count;
|
||||
$dates = $this->getPayDatesInRange($bill, $start, $end);
|
||||
$count = $bill->transactionJournals()->after($start)->before($end)->count();
|
||||
$total = $dates->count() - $count;
|
||||
// app('log')->debug(sprintf('Pay dates: %d, count: %d, left: %d', $dates->count(), $count, $total));
|
||||
// app('log')->debug('dates', $dates->toArray());
|
||||
|
||||
@@ -580,10 +589,10 @@ class BillRepository implements BillRepositoryInterface
|
||||
// Log::debug(sprintf('min field is %s, max field is %s', $minField, $maxField));
|
||||
|
||||
if ($total > 0) {
|
||||
$currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency;
|
||||
$average = bcdiv(bcadd($bill->{$maxField}, $bill->{$minField}), '2');
|
||||
$currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency;
|
||||
$average = bcdiv(bcadd($bill->{$maxField}, $bill->{$minField}), '2');
|
||||
Log::debug(sprintf('Amount to pay is %s %s (%d times)', $currency->code, $average, $total));
|
||||
$return[$currency->id] ??= [
|
||||
$return[$currency->id] ??= [
|
||||
'id' => (string) $currency->id,
|
||||
'name' => $currency->name,
|
||||
'symbol' => $currency->symbol,
|
||||
@@ -621,7 +630,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
// app('log')->debug(sprintf('Currentstart (%s) has become %s.', $currentStart->format('Y-m-d'), $nextExpectedMatch->format('Y-m-d')));
|
||||
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
$currentStart = clone $nextExpectedMatch;
|
||||
}
|
||||
|
||||
return $set;
|
||||
|
Reference in New Issue
Block a user