mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-23 20:38:46 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -136,7 +136,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
public function findByName(string $name, array $types): ?Account
|
||||
{
|
||||
$query = $this->user->accounts();
|
||||
$query = $this->user->accounts();
|
||||
|
||||
if (0 !== count($types)) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
@@ -203,7 +203,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
public function getAttachments(Account $account): Collection
|
||||
{
|
||||
$set = $account->attachments()->get();
|
||||
$set = $account->attachments()->get();
|
||||
|
||||
/** @var \Storage $disk */
|
||||
$disk = \Storage::disk('upload');
|
||||
@@ -225,7 +225,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
public function getCashAccount(): Account
|
||||
{
|
||||
/** @var AccountType $type */
|
||||
$type = AccountType::where('type', AccountType::CASH)->first();
|
||||
$type = AccountType::where('type', AccountType::CASH)->first();
|
||||
|
||||
/** @var AccountFactory $factory */
|
||||
$factory = app(AccountFactory::class);
|
||||
@@ -291,7 +291,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getOpeningBalanceAmount(Account $account): ?string
|
||||
{
|
||||
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT])
|
||||
->first(['transaction_journals.*'])
|
||||
@@ -352,10 +352,10 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]);
|
||||
|
||||
/** @var AccountType $type */
|
||||
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
|
||||
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
|
||||
|
||||
/** @var null|Account $current */
|
||||
$current = $this->user->accounts()->where('account_type_id', $type->id)
|
||||
$current = $this->user->accounts()->where('account_type_id', $type->id)
|
||||
->where('name', $name)
|
||||
->first()
|
||||
;
|
||||
@@ -364,7 +364,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $current;
|
||||
}
|
||||
|
||||
$data = [
|
||||
$data = [
|
||||
'account_type_id' => null,
|
||||
'account_type_name' => AccountType::RECONCILIATION,
|
||||
'active' => true,
|
||||
@@ -374,7 +374,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
];
|
||||
|
||||
/** @var AccountFactory $factory */
|
||||
$factory = app(AccountFactory::class);
|
||||
$factory = app(AccountFactory::class);
|
||||
$factory->setUser($account->user);
|
||||
|
||||
return $factory->create($data);
|
||||
@@ -382,8 +382,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
|
||||
// return null if not in this list.
|
||||
if (!in_array($type, $list, true)) {
|
||||
@@ -447,7 +447,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
public function maxOrder(string $type): int
|
||||
{
|
||||
$sets = [
|
||||
$sets = [
|
||||
AccountType::ASSET => [AccountType::DEFAULT, AccountType::ASSET],
|
||||
AccountType::EXPENSE => [AccountType::EXPENSE, AccountType::BENEFICIARY],
|
||||
AccountType::REVENUE => [AccountType::REVENUE],
|
||||
@@ -463,7 +463,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
$specials = [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION];
|
||||
|
||||
$order = (int)$this->getAccountsByType($specials)->max('order');
|
||||
$order = (int)$this->getAccountsByType($specials)->max('order');
|
||||
app('log')->debug(sprintf('Return max order of "%s" set (specials!): %d', $type, $order));
|
||||
|
||||
return $order;
|
||||
|
||||
@@ -45,25 +45,25 @@ class AccountTasker implements AccountTaskerInterface
|
||||
*/
|
||||
public function getAccountReport(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$yesterday = clone $start;
|
||||
$yesterday = clone $start;
|
||||
$yesterday->subDay();
|
||||
$startSet = app('steam')->balancesByAccounts($accounts, $yesterday);
|
||||
$endSet = app('steam')->balancesByAccounts($accounts, $end);
|
||||
$startSet = app('steam')->balancesByAccounts($accounts, $yesterday);
|
||||
$endSet = app('steam')->balancesByAccounts($accounts, $end);
|
||||
app('log')->debug('Start of accountreport');
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
$return = [
|
||||
$return = [
|
||||
'accounts' => [],
|
||||
'sums' => [],
|
||||
];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$id = $account->id;
|
||||
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$id = $account->id;
|
||||
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$return['sums'][$currency->id] ??= [
|
||||
'start' => '0',
|
||||
'end' => '0',
|
||||
@@ -74,7 +74,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
'currency_name' => $currency->name,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
];
|
||||
$entry = [
|
||||
$entry = [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
'currency_id' => $currency->id,
|
||||
@@ -85,9 +85,9 @@ class AccountTasker implements AccountTaskerInterface
|
||||
];
|
||||
|
||||
// get first journal date:
|
||||
$first = $repository->oldestJournal($account);
|
||||
$entry['start_balance'] = $startSet[$account->id] ?? '0';
|
||||
$entry['end_balance'] = $endSet[$account->id] ?? '0';
|
||||
$first = $repository->oldestJournal($account);
|
||||
$entry['start_balance'] = $startSet[$account->id] ?? '0';
|
||||
$entry['end_balance'] = $endSet[$account->id] ?? '0';
|
||||
|
||||
// first journal exists, and is on start, then this is the actual opening balance:
|
||||
if (null !== $first && $first->date->isSameDay($start) && TransactionType::OPENING_BALANCE === $first->transactionType->type) {
|
||||
@@ -122,13 +122,13 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$collector->setSourceAccounts($accounts)->setRange($start, $end);
|
||||
$collector->excludeDestinationAccounts($accounts);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
$report = $this->groupExpenseByDestination($journals);
|
||||
$report = $this->groupExpenseByDestination($journals);
|
||||
|
||||
// sort the result
|
||||
// Obtain a list of columns
|
||||
$sum = [];
|
||||
$sum = [];
|
||||
foreach ($report['accounts'] as $accountId => $row) {
|
||||
$sum[$accountId] = (float)$row['sum']; // intentional float
|
||||
}
|
||||
@@ -152,11 +152,11 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$collector->setDestinationAccounts($accounts)->setRange($start, $end);
|
||||
$collector->excludeSourceAccounts($accounts);
|
||||
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])->withAccountInformation();
|
||||
$report = $this->groupIncomeBySource($collector->getExtractedJournals());
|
||||
$report = $this->groupIncomeBySource($collector->getExtractedJournals());
|
||||
|
||||
// sort the result
|
||||
// Obtain a list of columns
|
||||
$sum = [];
|
||||
$sum = [];
|
||||
foreach ($report['accounts'] as $accountId => $row) {
|
||||
$sum[$accountId] = (float)$row['sum']; // intentional float
|
||||
}
|
||||
@@ -181,9 +181,9 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = [$defaultCurrency->id => $defaultCurrency];
|
||||
$report = [
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = [$defaultCurrency->id => $defaultCurrency];
|
||||
$report = [
|
||||
'accounts' => [],
|
||||
'sums' => [],
|
||||
];
|
||||
@@ -193,8 +193,8 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$sourceId = (int)$journal['destination_account_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$key = sprintf('%s-%s', $sourceId, $currencyId);
|
||||
$currencies[$currencyId] ??= $currencyRepos->find($currencyId);
|
||||
$report['accounts'][$key] ??= [
|
||||
$currencies[$currencyId] ??= $currencyRepos->find($currencyId);
|
||||
$report['accounts'][$key] ??= [
|
||||
'id' => $sourceId,
|
||||
'name' => $journal['destination_account_name'],
|
||||
'sum' => '0',
|
||||
@@ -219,7 +219,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$report['accounts'][$key]['average'] = bcdiv($report['accounts'][$key]['sum'], (string)$report['accounts'][$key]['count']);
|
||||
}
|
||||
$currencyId = $report['accounts'][$key]['currency_id'];
|
||||
$report['sums'][$currencyId] ??= [
|
||||
$report['sums'][$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $report['accounts'][$key]['currency_id'],
|
||||
'currency_name' => $report['accounts'][$key]['currency_name'],
|
||||
@@ -241,20 +241,20 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = [$defaultCurrency->id => $defaultCurrency];
|
||||
$report = [
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = [$defaultCurrency->id => $defaultCurrency];
|
||||
$report = [
|
||||
'accounts' => [],
|
||||
'sums' => [],
|
||||
];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
$sourceId = (int)$journal['source_account_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$key = sprintf('%s-%s', $sourceId, $currencyId);
|
||||
$sourceId = (int)$journal['source_account_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$key = sprintf('%s-%s', $sourceId, $currencyId);
|
||||
if (!array_key_exists($key, $report['accounts'])) {
|
||||
$currencies[$currencyId] ??= $currencyRepos->find($currencyId);
|
||||
$currencies[$currencyId] ??= $currencyRepos->find($currencyId);
|
||||
$report['accounts'][$key] = [
|
||||
'id' => $sourceId,
|
||||
'name' => $journal['source_account_name'],
|
||||
@@ -278,7 +278,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$report['accounts'][$key]['average'] = bcdiv($report['accounts'][$key]['sum'], (string)$report['accounts'][$key]['count']);
|
||||
}
|
||||
$currencyId = $report['accounts'][$key]['currency_id'];
|
||||
$report['sums'][$currencyId] ??= [
|
||||
$report['sums'][$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $report['accounts'][$key]['currency_id'],
|
||||
'currency_name' => $report['accounts'][$key]['currency_name'],
|
||||
|
||||
@@ -184,8 +184,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
{
|
||||
$array = [];
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'currency_id' => $journal['currency_id'],
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -260,7 +260,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
if (null !== $currency) {
|
||||
$collector->setCurrency($currency);
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// same but for foreign currencies:
|
||||
if (null !== $currency) {
|
||||
@@ -286,10 +286,10 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
$result = $collector->getExtractedJournals();
|
||||
$result = $collector->getExtractedJournals();
|
||||
|
||||
// do not use array_merge because you want keys to overwrite (otherwise you get double results):
|
||||
$journals = $result + $journals;
|
||||
$journals = $result + $journals;
|
||||
}
|
||||
|
||||
return $journals;
|
||||
@@ -301,7 +301,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -312,9 +312,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->{$direction}($journal['amount'])); // @phpstan-ignore-line
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int)$journal['foreign_currency_id'];
|
||||
$foreignId = (int)$journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] ??= [
|
||||
$array[$foreignId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $foreignId,
|
||||
'currency_name' => $journal['foreign_currency_name'],
|
||||
@@ -337,7 +337,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$key = sprintf('%s-%s', $journal[$idKey], $journal['currency_id']);
|
||||
$array[$key] ??= [
|
||||
$array[$key] ??= [
|
||||
'id' => $journal[$idKey],
|
||||
'name' => $journal[$nameKey],
|
||||
'sum' => '0',
|
||||
@@ -352,7 +352,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
// also do foreign amount:
|
||||
if (0 !== (int)$journal['foreign_currency_id']) {
|
||||
$key = sprintf('%s-%s', $journal[$idKey], $journal['foreign_currency_id']);
|
||||
$array[$key] ??= [
|
||||
$array[$key] ??= [
|
||||
'id' => $journal[$idKey],
|
||||
'name' => $journal[$nameKey],
|
||||
'sum' => '0',
|
||||
@@ -377,7 +377,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
foreach ($journals as $journal) {
|
||||
$return = $this->groupByEitherJournal($return, $journal);
|
||||
}
|
||||
$final = [];
|
||||
$final = [];
|
||||
foreach ($return as $array) {
|
||||
$array['difference_float'] = (float)$array['difference'];
|
||||
$array['in_float'] = (float)$array['in'];
|
||||
@@ -390,12 +390,12 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
private function groupByEitherJournal(array $return, array $journal): array
|
||||
{
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$currencyId = $journal['currency_id'];
|
||||
$sourceKey = sprintf('%d-%d', $currencyId, $sourceId);
|
||||
$destKey = sprintf('%d-%d', $currencyId, $destinationId);
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
$sourceId = $journal['source_account_id'];
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
$currencyId = $journal['currency_id'];
|
||||
$sourceKey = sprintf('%d-%d', $currencyId, $sourceId);
|
||||
$destKey = sprintf('%d-%d', $currencyId, $destinationId);
|
||||
$amount = app('steam')->positive($journal['amount']);
|
||||
|
||||
// source first
|
||||
$return[$sourceKey] ??= [
|
||||
@@ -412,7 +412,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
];
|
||||
|
||||
// dest next:
|
||||
$return[$destKey] ??= [
|
||||
$return[$destKey] ??= [
|
||||
'id' => (string)$destinationId,
|
||||
'name' => $journal['destination_account_name'],
|
||||
'difference' => '0',
|
||||
@@ -430,15 +430,15 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$return[$sourceKey]['difference'] = bcadd($return[$sourceKey]['out'], $return[$sourceKey]['in']);
|
||||
|
||||
// destination account? money comes in:
|
||||
$return[$destKey]['in'] = bcadd($return[$destKey]['in'], $amount);
|
||||
$return[$destKey]['difference'] = bcadd($return[$destKey]['out'], $return[$destKey]['in']);
|
||||
$return[$destKey]['in'] = bcadd($return[$destKey]['in'], $amount);
|
||||
$return[$destKey]['difference'] = bcadd($return[$destKey]['out'], $return[$destKey]['in']);
|
||||
|
||||
// foreign currency
|
||||
if (null !== $journal['foreign_currency_id'] && null !== $journal['foreign_amount']) {
|
||||
$currencyId = $journal['foreign_currency_id'];
|
||||
$sourceKey = sprintf('%d-%d', $currencyId, $sourceId);
|
||||
$destKey = sprintf('%d-%d', $currencyId, $destinationId);
|
||||
$amount = app('steam')->positive($journal['foreign_amount']);
|
||||
$currencyId = $journal['foreign_currency_id'];
|
||||
$sourceKey = sprintf('%d-%d', $currencyId, $sourceId);
|
||||
$destKey = sprintf('%d-%d', $currencyId, $destinationId);
|
||||
$amount = app('steam')->positive($journal['foreign_amount']);
|
||||
|
||||
// same as above:
|
||||
// source first
|
||||
@@ -456,7 +456,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
];
|
||||
|
||||
// dest next:
|
||||
$return[$destKey] ??= [
|
||||
$return[$destKey] ??= [
|
||||
'id' => (string)$destinationId,
|
||||
'name' => $journal['destination_account_name'],
|
||||
'difference' => '0',
|
||||
@@ -473,8 +473,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$return[$sourceKey]['difference'] = bcadd($return[$sourceKey]['out'], $return[$sourceKey]['in']);
|
||||
|
||||
// destination account? money comes in:
|
||||
$return[$destKey]['in'] = bcadd($return[$destKey]['in'], $amount);
|
||||
$return[$destKey]['difference'] = bcadd($return[$destKey]['out'], $return[$destKey]['in']);
|
||||
$return[$destKey]['in'] = bcadd($return[$destKey]['in'], $amount);
|
||||
$return[$destKey]['difference'] = bcadd($return[$destKey]['out'], $return[$destKey]['in']);
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
@@ -51,7 +51,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
/** @var AttachmentHelperInterface $helper */
|
||||
$helper = app(AttachmentHelperInterface::class);
|
||||
|
||||
$path = $helper->getAttachmentLocation($attachment);
|
||||
$path = $helper->getAttachmentLocation($attachment);
|
||||
|
||||
try {
|
||||
Storage::disk('upload')->delete($path);
|
||||
@@ -118,7 +118,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
/** @var AttachmentFactory $factory */
|
||||
$factory = app(AttachmentFactory::class);
|
||||
$factory->setUser($this->user);
|
||||
$result = $factory->create($data);
|
||||
$result = $factory->create($data);
|
||||
if (null === $result) {
|
||||
throw new FireflyException('Could not store attachment.');
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
$dbNote = $attachment->notes()->first();
|
||||
$dbNote = $attachment->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($attachment);
|
||||
|
||||
@@ -41,7 +41,7 @@ class ALERepository implements ALERepositoryInterface
|
||||
|
||||
public function store(array $data): AuditLogEntry
|
||||
{
|
||||
$auditLogEntry = new AuditLogEntry();
|
||||
$auditLogEntry = new AuditLogEntry();
|
||||
|
||||
$auditLogEntry->auditable()->associate($data['auditable']);
|
||||
$auditLogEntry->changer()->associate($data['changer']);
|
||||
|
||||
@@ -155,7 +155,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');
|
||||
@@ -244,7 +244,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
|
||||
@@ -257,7 +257,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$currencyId = (int) $journal->transaction_currency_id;
|
||||
$currency = $journal->transactionCurrency;
|
||||
$result[$currencyId] ??= [
|
||||
$result[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'count' => 0,
|
||||
'avg' => '0',
|
||||
@@ -336,16 +336,16 @@ class BillRepository implements BillRepositoryInterface
|
||||
*/
|
||||
public function getRulesForBills(Collection $collection): array
|
||||
{
|
||||
$rules = $this->user->rules()
|
||||
$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 = [];
|
||||
$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 = [];
|
||||
@@ -359,11 +359,11 @@ 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')
|
||||
@@ -374,13 +374,13 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @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',
|
||||
'count' => 0,
|
||||
'avg' => '0',
|
||||
@@ -424,7 +424,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);
|
||||
@@ -432,7 +432,7 @@ 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;
|
||||
app('log')->debug('nextExpectedMatch: Start is '.$start->format('Y-m-d'));
|
||||
|
||||
while ($start < $date) {
|
||||
@@ -441,7 +441,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
app('log')->debug('Start is now '.$start->format('Y-m-d'));
|
||||
}
|
||||
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
$end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip);
|
||||
|
||||
// see if the bill was paid in this period.
|
||||
$journalCount = $bill->transactionJournals()->before($end)->after($start)->count();
|
||||
@@ -527,7 +527,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var null|Transaction $sourceTransaction */
|
||||
$sourceTransaction = $transactionJournal->transactions()->where('amount', '<', 0)->first();
|
||||
if (null !== $sourceTransaction) {
|
||||
$amount = $sourceTransaction->amount;
|
||||
$amount = $sourceTransaction->amount;
|
||||
if ((int) $sourceTransaction->foreign_currency_id === $currency->id) {
|
||||
// use foreign amount instead!
|
||||
$amount = (string) $sourceTransaction->foreign_amount;
|
||||
@@ -567,7 +567,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
if ($total > 0) {
|
||||
$currency = $bill->transactionCurrency;
|
||||
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
|
||||
$return[$currency->id] ??= [
|
||||
$return[$currency->id] ??= [
|
||||
'id' => (string) $currency->id,
|
||||
'name' => $currency->name,
|
||||
'symbol' => $currency->symbol,
|
||||
@@ -605,7 +605,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;
|
||||
|
||||
@@ -45,9 +45,9 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
|
||||
/** @var AvailableBudget $availableBudget */
|
||||
foreach ($availableBudgets as $availableBudget) {
|
||||
$start = $availableBudget->start_date->format('Y-m-d');
|
||||
$end = $availableBudget->end_date->format('Y-m-d');
|
||||
$key = sprintf('%s-%s-%s', $availableBudget->transaction_currency_id, $start, $end);
|
||||
$start = $availableBudget->start_date->format('Y-m-d');
|
||||
$end = $availableBudget->end_date->format('Y-m-d');
|
||||
$key = sprintf('%s-%s-%s', $availableBudget->transaction_currency_id, $start, $end);
|
||||
if (array_key_exists($key, $exists)) {
|
||||
app('log')->debug(sprintf('Found duplicate AB: %s %s, %s-%s. Has been deleted', $availableBudget->transaction_currency_id, $availableBudget->amount, $start, $end));
|
||||
$availableBudget->delete();
|
||||
@@ -107,7 +107,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
|
||||
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string
|
||||
{
|
||||
$amount = '0';
|
||||
$amount = '0';
|
||||
|
||||
/** @var null|AvailableBudget $availableBudget */
|
||||
$availableBudget = $this->user->availableBudgets()
|
||||
@@ -190,13 +190,13 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
*/
|
||||
public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget
|
||||
{
|
||||
$availableBudget = $this->user->availableBudgets()
|
||||
$availableBudget = $this->user->availableBudgets()
|
||||
->where('transaction_currency_id', $currency->id)
|
||||
->where('start_date', $start->format('Y-m-d'))
|
||||
->where('end_date', $end->format('Y-m-d'))->first()
|
||||
;
|
||||
if (null === $availableBudget) {
|
||||
$availableBudget = new AvailableBudget();
|
||||
$availableBudget = new AvailableBudget();
|
||||
$availableBudget->user()->associate($this->user);
|
||||
$availableBudget->transactionCurrency()->associate($currency);
|
||||
$availableBudget->start_date = $start->startOfDay();
|
||||
@@ -221,7 +221,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
if ($start instanceof Carbon) {
|
||||
$start = $data['start']->startOfDay();
|
||||
}
|
||||
$end = $data['end'];
|
||||
$end = $data['end'];
|
||||
if ($end instanceof Carbon) {
|
||||
$end = $data['end']->endOfDay();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
*/
|
||||
public function budgeted(Carbon $start, Carbon $end, TransactionCurrency $currency, ?Collection $budgets = null): string
|
||||
{
|
||||
$query = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
$query = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
|
||||
// same complex where query as below.
|
||||
->where(
|
||||
@@ -266,22 +266,22 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
{
|
||||
// if no currency has been provided, use the user's default currency:
|
||||
/** @var TransactionCurrencyFactory $factory */
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
$currency->enabled = true;
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
|
||||
// find the budget:
|
||||
$budget = $this->user->budgets()->find((int)$data['budget_id']);
|
||||
$budget = $this->user->budgets()->find((int)$data['budget_id']);
|
||||
if (null === $budget) {
|
||||
throw new FireflyException('200004: Budget does not exist.');
|
||||
}
|
||||
|
||||
// find limit with same date range and currency.
|
||||
$limit = $budget->budgetlimits()
|
||||
$limit = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $data['start_date']->format('Y-m-d'))
|
||||
->where('budget_limits.end_date', $data['end_date']->format('Y-m-d'))
|
||||
->where('budget_limits.transaction_currency_id', $currency->id)
|
||||
@@ -293,7 +293,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
app('log')->debug('No existing budget limit, create a new one');
|
||||
|
||||
// or create one and return it.
|
||||
$limit = new BudgetLimit();
|
||||
$limit = new BudgetLimit();
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->start_date = $data['start_date']->format('Y-m-d');
|
||||
$limit->end_date = $data['end_date']->format('Y-m-d');
|
||||
@@ -319,13 +319,13 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
*/
|
||||
public function update(BudgetLimit $budgetLimit, array $data): BudgetLimit
|
||||
{
|
||||
$budgetLimit->amount = array_key_exists('amount', $data) ? $data['amount'] : $budgetLimit->amount;
|
||||
$budgetLimit->budget_id = array_key_exists('budget_id', $data) ? $data['budget_id'] : $budgetLimit->budget_id;
|
||||
$budgetLimit->start_date = array_key_exists('start', $data) ? $data['start']->format('Y-m-d 00:00:00') : $budgetLimit->start_date;
|
||||
$budgetLimit->end_date = array_key_exists('end', $data) ? $data['end']->format('Y-m-d 23:59:59') : $budgetLimit->end_date;
|
||||
$budgetLimit->amount = array_key_exists('amount', $data) ? $data['amount'] : $budgetLimit->amount;
|
||||
$budgetLimit->budget_id = array_key_exists('budget_id', $data) ? $data['budget_id'] : $budgetLimit->budget_id;
|
||||
$budgetLimit->start_date = array_key_exists('start', $data) ? $data['start']->format('Y-m-d 00:00:00') : $budgetLimit->start_date;
|
||||
$budgetLimit->end_date = array_key_exists('end', $data) ? $data['end']->format('Y-m-d 23:59:59') : $budgetLimit->end_date;
|
||||
|
||||
// if no currency has been provided, use the user's default currency:
|
||||
$currency = null;
|
||||
$currency = null;
|
||||
|
||||
// update if relevant:
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
@@ -337,7 +337,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
if (null === $currency) {
|
||||
$currency = $budgetLimit->transactionCurrency ?? app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
$currency->enabled = true;
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
|
||||
$budgetLimit->transaction_currency_id = $currency->id;
|
||||
@@ -349,7 +349,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): ?BudgetLimit
|
||||
{
|
||||
// count the limits:
|
||||
$limits = $budget->budgetlimits()
|
||||
$limits = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->count('budget_limits.*')
|
||||
@@ -358,7 +358,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
|
||||
// there might be a budget limit for these dates:
|
||||
/** @var null|BudgetLimit $limit */
|
||||
$limit = $budget->budgetlimits()
|
||||
$limit = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->first(['budget_limits.*'])
|
||||
@@ -393,7 +393,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
}
|
||||
app('log')->debug('No existing budget limit, create a new one');
|
||||
// or create one and return it.
|
||||
$limit = new BudgetLimit();
|
||||
$limit = new BudgetLimit();
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->start_date = $start->startOfDay();
|
||||
$limit->end_date = $end->startOfDay();
|
||||
|
||||
@@ -82,7 +82,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
public function budgetedInPeriod(Carbon $start, Carbon $end): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in budgetedInPeriod("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
$return = [];
|
||||
$return = [];
|
||||
|
||||
/** @var BudgetLimitRepository $limitRepository */
|
||||
$limitRepository = app(BudgetLimitRepository::class);
|
||||
@@ -99,9 +99,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
/** @var BudgetLimit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
|
||||
$currency = $limit->transactionCurrency;
|
||||
$rate = $converter->getCurrencyRate($currency, $defaultCurrency, $end);
|
||||
$currencyCode = $currency->code;
|
||||
$currency = $limit->transactionCurrency;
|
||||
$rate = $converter->getCurrencyRate($currency, $defaultCurrency, $end);
|
||||
$currencyCode = $currency->code;
|
||||
$return[$currencyCode] ??= [
|
||||
'currency_id' => (string) $currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
@@ -172,19 +172,19 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
public function budgetedInPeriodForBudget(Budget $budget, Carbon $start, Carbon $end): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in budgetedInPeriod(#%d, "%s", "%s")', $budget->id, $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
$return = [];
|
||||
$return = [];
|
||||
|
||||
/** @var BudgetLimitRepository $limitRepository */
|
||||
$limitRepository = app(BudgetLimitRepository::class);
|
||||
$limitRepository->setUser($this->user);
|
||||
|
||||
app('log')->debug(sprintf('Budget #%d: "%s"', $budget->id, $budget->name));
|
||||
$limits = $limitRepository->getBudgetLimits($budget, $start, $end);
|
||||
$limits = $limitRepository->getBudgetLimits($budget, $start, $end);
|
||||
|
||||
/** @var BudgetLimit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
|
||||
$currency = $limit->transactionCurrency;
|
||||
$currency = $limit->transactionCurrency;
|
||||
$return[$currency->id] ??= [
|
||||
'id' => (string) $currency->id,
|
||||
'name' => $currency->name,
|
||||
@@ -253,7 +253,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
app('log')->debug('Now in update()');
|
||||
|
||||
$oldName = $budget->name;
|
||||
$oldName = $budget->name;
|
||||
if (array_key_exists('name', $data)) {
|
||||
$budget->name = $data['name'];
|
||||
$this->updateRuleActions($oldName, $budget->name);
|
||||
@@ -268,7 +268,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$budget->save();
|
||||
|
||||
// update or create auto-budget:
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// first things first: delete when no longer required:
|
||||
$autoBudgetType = array_key_exists('auto_budget_type', $data) ? $data['auto_budget_type'] : null;
|
||||
@@ -392,7 +392,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
public function getAttachments(Budget $budget): Collection
|
||||
{
|
||||
$set = $budget->attachments()->get();
|
||||
$set = $budget->attachments()->get();
|
||||
|
||||
/** @var \Storage $disk */
|
||||
$disk = \Storage::disk('upload');
|
||||
@@ -462,8 +462,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
// exclude specific liabilities
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($subset as $account) {
|
||||
@@ -474,7 +474,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
// start collecting:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)
|
||||
->setRange($start, $end)
|
||||
->excludeDestinationAccounts($selection)
|
||||
@@ -482,12 +482,12 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
->setBudgets($this->getActiveBudgets())
|
||||
;
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'id' => (string) $currencyId,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
@@ -498,9 +498,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] ??= [
|
||||
$array[$foreignId] ??= [
|
||||
'id' => (string) $foreignId,
|
||||
'name' => $journal['foreign_currency_name'],
|
||||
'symbol' => $journal['foreign_currency_symbol'],
|
||||
@@ -524,8 +524,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
// exclude specific liabilities
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($subset as $account) {
|
||||
@@ -536,7 +536,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
// start collecting:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)
|
||||
->setRange($start, $end)
|
||||
->excludeDestinationAccounts($selection)
|
||||
@@ -544,12 +544,12 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
->setBudget($budget)
|
||||
;
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'id' => (string) $currencyId,
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
@@ -560,9 +560,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
$foreignId = (int) $journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] ??= [
|
||||
$array[$foreignId] ??= [
|
||||
'id' => (string) $foreignId,
|
||||
'name' => $journal['foreign_currency_name'],
|
||||
'symbol' => $journal['foreign_currency_symbol'],
|
||||
@@ -584,7 +584,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function store(array $data): Budget
|
||||
{
|
||||
$order = $this->getMaxOrder();
|
||||
$order = $this->getMaxOrder();
|
||||
|
||||
try {
|
||||
$newBudget = Budget::create(
|
||||
@@ -611,7 +611,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
if (!array_key_exists('auto_budget_type', $data) || !array_key_exists('auto_budget_amount', $data) || !array_key_exists('auto_budget_period', $data)) {
|
||||
return $newBudget;
|
||||
}
|
||||
$type = $data['auto_budget_type'];
|
||||
$type = $data['auto_budget_type'];
|
||||
if ('none' === $type) {
|
||||
return $newBudget;
|
||||
}
|
||||
@@ -630,8 +630,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/** @var CurrencyRepositoryInterface $repos */
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = null;
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = null;
|
||||
if (array_key_exists('currency_id', $data)) {
|
||||
$currency = $repos->find((int) $data['currency_id']);
|
||||
}
|
||||
@@ -642,7 +642,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
|
||||
$autoBudget = new AutoBudget();
|
||||
$autoBudget = new AutoBudget();
|
||||
$autoBudget->budget()->associate($newBudget);
|
||||
$autoBudget->transaction_currency_id = $currency->id;
|
||||
$autoBudget->auto_budget_type = $type;
|
||||
@@ -651,11 +651,11 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$autoBudget->save();
|
||||
|
||||
// create initial budget limit.
|
||||
$today = today(config('app.timezone'));
|
||||
$start = app('navigation')->startOfPeriod($today, $autoBudget->period);
|
||||
$end = app('navigation')->endOfPeriod($start, $autoBudget->period);
|
||||
$today = today(config('app.timezone'));
|
||||
$start = app('navigation')->startOfPeriod($today, $autoBudget->period);
|
||||
$end = app('navigation')->endOfPeriod($start, $autoBudget->period);
|
||||
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$limitRepos->setUser($this->user);
|
||||
$limitRepos->store(
|
||||
[
|
||||
@@ -774,7 +774,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// grab default currency:
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
if (null === $autoBudget) {
|
||||
// at this point it's a blind assumption auto_budget_type is 1 or 2.
|
||||
|
||||
@@ -44,17 +44,17 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
$carbonFormat = app('navigation')->preferredCarbonFormat($start, $end);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$collector->withoutBudget();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$data = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
|
||||
$data[$currencyId] ??= [
|
||||
'id' => 0,
|
||||
@@ -67,7 +67,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
'entries' => [],
|
||||
];
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
|
||||
if (!array_key_exists($date, $data[$currencyId]['entries'])) {
|
||||
$data[$currencyId]['entries'][$date] = '0';
|
||||
@@ -84,7 +84,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
public function spentInPeriodWoBudgetMc(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->withoutBudget();
|
||||
@@ -99,7 +99,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$code = $journal['currency_code'];
|
||||
$code = $journal['currency_code'];
|
||||
if (!array_key_exists($code, $currencies)) {
|
||||
$currencies[$code] = [
|
||||
'id' => $journal['currency_id'],
|
||||
@@ -151,12 +151,12 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
}
|
||||
$collector->withoutBudget();
|
||||
$collector->withBudgetInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
|
||||
@@ -59,7 +59,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
++$count;
|
||||
app('log')->debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total));
|
||||
}
|
||||
$avg = $total;
|
||||
$avg = $total;
|
||||
if ($count > 0) {
|
||||
$avg = bcdiv($total, (string)$count);
|
||||
}
|
||||
@@ -81,21 +81,21 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
// get all transactions:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setBudgets($budgets);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// loop transactions:
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
// prep data array for currency:
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = $journal['budget_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$key = sprintf('%d-%d', $budgetId, $currencyId);
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = $journal['budget_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$key = sprintf('%d-%d', $budgetId, $currencyId);
|
||||
|
||||
$data[$key] ??= [
|
||||
$data[$key] ??= [
|
||||
'id' => $budgetId,
|
||||
'name' => sprintf('%s (%s)', $budgetName, $journal['currency_name']),
|
||||
'sum' => '0',
|
||||
@@ -133,13 +133,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setBudgets($this->getBudgets());
|
||||
}
|
||||
$collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = (string)$journal['budget_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = (string)$journal['budget_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $budgetId) {
|
||||
@@ -147,7 +147,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'budgets' => [],
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -210,8 +210,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
// TODO this filter must be somewhere in AccountRepositoryInterface because I suspect its needed more often (A113)
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($subset as $account) {
|
||||
@@ -221,7 +221,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)
|
||||
->setRange($start, $end)
|
||||
->excludeDestinationAccounts($selection)
|
||||
@@ -238,7 +238,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCurrency($currency);
|
||||
}
|
||||
$collector->setBudgets($budgets);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// same but for foreign currencies:
|
||||
if (null !== $currency) {
|
||||
@@ -252,16 +252,16 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
if (null !== $accounts) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
$result = $collector->getExtractedJournals();
|
||||
$result = $collector->getExtractedJournals();
|
||||
// app('log')->debug(sprintf('Found %d journals with currency %s.', count($result), $currency->code));
|
||||
// do not use array_merge because you want keys to overwrite (otherwise you get double results):
|
||||
$journals = $result + $journals;
|
||||
$journals = $result + $journals;
|
||||
}
|
||||
$array = [];
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -272,9 +272,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
|
||||
|
||||
// also do foreign amount:
|
||||
$foreignId = (int)$journal['foreign_currency_id'];
|
||||
$foreignId = (int)$journal['foreign_currency_id'];
|
||||
if (0 !== $foreignId) {
|
||||
$array[$foreignId] ??= [
|
||||
$array[$foreignId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $foreignId,
|
||||
'currency_name' => $journal['foreign_currency_name'],
|
||||
|
||||
@@ -144,7 +144,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
public function store(array $data): Category
|
||||
{
|
||||
/** @var CategoryFactory $factory */
|
||||
$factory = app(CategoryFactory::class);
|
||||
$factory = app(CategoryFactory::class);
|
||||
$factory->setUser($this->user);
|
||||
|
||||
$category = $factory->findOrCreate(null, $data['name']);
|
||||
@@ -177,7 +177,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
public function updateNotes(Category $category, string $notes): void
|
||||
{
|
||||
$dbNote = $category->notes()->first();
|
||||
$dbNote = $category->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($category);
|
||||
@@ -210,7 +210,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
public function getAttachments(Category $category): Collection
|
||||
{
|
||||
$set = $category->attachments()->get();
|
||||
$set = $category->attachments()->get();
|
||||
|
||||
/** @var \Storage $disk */
|
||||
$disk = \Storage::disk('upload');
|
||||
@@ -306,7 +306,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
private function getFirstTransactionDate(Category $category): ?Carbon
|
||||
{
|
||||
// check transactions:
|
||||
$query = $category->transactions()
|
||||
$query = $category->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'ASC')
|
||||
;
|
||||
@@ -321,7 +321,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
private function getLastJournalDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
$query = $category->transactionJournals()->orderBy('date', 'DESC');
|
||||
$query = $category->transactionJournals()->orderBy('date', 'DESC');
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$query->leftJoin('transactions as t', 't.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
@@ -343,7 +343,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
private function getLastTransactionDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
// check transactions:
|
||||
$query = $category->transactions()
|
||||
$query = $category->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
;
|
||||
|
||||
@@ -50,12 +50,12 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -72,9 +72,9 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
|
||||
// add journal to array:
|
||||
// only a subset of the fields.
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$array[$currencyId]['categories'][0]['transaction_journals'][$journalId]
|
||||
= [
|
||||
= [
|
||||
'amount' => app('steam')->negative($journal['amount']),
|
||||
'date' => $journal['date'],
|
||||
];
|
||||
@@ -103,12 +103,12 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -125,9 +125,9 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
];
|
||||
// add journal to array:
|
||||
// only a subset of the fields.
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$array[$currencyId]['categories'][0]['transaction_journals'][$journalId]
|
||||
= [
|
||||
= [
|
||||
'amount' => app('steam')->positive($journal['amount']),
|
||||
'date' => $journal['date'],
|
||||
];
|
||||
@@ -148,12 +148,12 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -179,12 +179,12 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -207,12 +207,12 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
|
||||
@@ -59,13 +59,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCategories($this->getCategories());
|
||||
}
|
||||
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$categoryName = (string)$journal['category_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$categoryName = (string)$journal['category_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $categoryId) {
|
||||
@@ -73,7 +73,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => (string)$currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -135,13 +135,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCategories($this->getCategories());
|
||||
}
|
||||
$collector->withCategoryInformation()->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$categoryName = (string)$journal['category_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$categoryName = (string)$journal['category_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $categoryId) {
|
||||
@@ -149,7 +149,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => (string)$currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -197,13 +197,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCategories($this->getCategories());
|
||||
}
|
||||
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$categoryName = (string)$journal['category_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$categoryName = (string)$journal['category_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $categoryId) {
|
||||
@@ -211,7 +211,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => (string)$currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -260,13 +260,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setCategories($this->getCategories());
|
||||
}
|
||||
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$categoryName = (string)$journal['category_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$categoryName = (string)$journal['category_name'];
|
||||
|
||||
// catch "no category" entries.
|
||||
if (0 === $categoryId) {
|
||||
@@ -274,7 +274,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'categories' => [],
|
||||
'currency_id' => (string)$currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -328,12 +328,12 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
$collector->setCategories($categories);
|
||||
$collector->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => (string)$currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -365,12 +365,12 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$categories = $this->getCategories();
|
||||
}
|
||||
$collector->setCategories($categories);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => (string)$currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -402,12 +402,12 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$categories = $this->getCategories();
|
||||
}
|
||||
$collector->setCategories($categories);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => (string)$currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
|
||||
@@ -57,7 +57,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
|
||||
*/
|
||||
public function getAttachments(TransactionJournal $journal): Collection
|
||||
{
|
||||
$set = $journal->attachments;
|
||||
$set = $journal->attachments;
|
||||
|
||||
/** @var \Storage $disk */
|
||||
$disk = \Storage::disk('upload');
|
||||
|
||||
@@ -118,7 +118,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
*/
|
||||
public function getMetaField(TransactionJournal $journal, string $field): ?string
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('journal-meta-updated');
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty($field);
|
||||
@@ -127,12 +127,12 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
if (null === $entry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = $entry->data;
|
||||
$value = $entry->data;
|
||||
|
||||
if (is_array($value)) {
|
||||
$return = implode(',', $value);
|
||||
@@ -167,10 +167,10 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
*/
|
||||
public function getSplitJournals(): Collection
|
||||
{
|
||||
$query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
$query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->groupBy('transaction_journals.id')
|
||||
;
|
||||
$result = $query->get(['transaction_journals.id as id', \DB::raw('count(transactions.id) as transaction_count')]); // @phpstan-ignore-line
|
||||
$result = $query->get(['transaction_journals.id as id', \DB::raw('count(transactions.id) as transaction_count')]); // @phpstan-ignore-line
|
||||
$journalIds = [];
|
||||
|
||||
/** @var \stdClass $row */
|
||||
|
||||
@@ -102,7 +102,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*/
|
||||
public function getJournalTotal(TransactionJournal $journal): string
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('amount-positive');
|
||||
if ($cache->has()) {
|
||||
|
||||
@@ -199,7 +199,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
return $existing;
|
||||
}
|
||||
|
||||
$link = new TransactionJournalLink();
|
||||
$link = new TransactionJournalLink();
|
||||
$link->linkType()->associate($linkType);
|
||||
if ('inward' === $information['direction']) {
|
||||
app('log')->debug(sprintf('Link type is inwards ("%s"), so %d is source and %d is destination.', $linkType->inward, $inward->id, $outward->id));
|
||||
@@ -285,7 +285,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
$journalLink->refresh();
|
||||
}
|
||||
|
||||
$journalLink->link_type_id = null === $data['link_type_id'] ? $journalLink->link_type_id : $data['link_type_id'];
|
||||
$journalLink->link_type_id = null === $data['link_type_id'] ? $journalLink->link_type_id : $data['link_type_id'];
|
||||
$journalLink->save();
|
||||
if (array_key_exists('notes', $data) && null !== $data['notes']) {
|
||||
$this->setNoteText($journalLink, $data['notes']);
|
||||
|
||||
@@ -55,7 +55,7 @@ trait ModifiesPiggyBanks
|
||||
|
||||
public function removeAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool
|
||||
{
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
if (null === $repetition) {
|
||||
return false;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ trait ModifiesPiggyBanks
|
||||
|
||||
public function addAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool
|
||||
{
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
if (null === $repetition) {
|
||||
return false;
|
||||
}
|
||||
@@ -96,8 +96,8 @@ trait ModifiesPiggyBanks
|
||||
$maxAmount = 1 === bccomp($leftOnAccount, $leftToSave) ? $leftToSave : $leftOnAccount;
|
||||
}
|
||||
|
||||
$compare = bccomp($amount, $maxAmount);
|
||||
$result = $compare <= 0;
|
||||
$compare = bccomp($amount, $maxAmount);
|
||||
$result = $compare <= 0;
|
||||
|
||||
app('log')->debug(sprintf('Left on account: %s on %s', $leftOnAccount, $today->format('Y-m-d')));
|
||||
app('log')->debug(sprintf('Saved so far: %s', $savedSoFar));
|
||||
@@ -139,11 +139,11 @@ trait ModifiesPiggyBanks
|
||||
|
||||
public function setCurrentAmount(PiggyBank $piggyBank, string $amount): PiggyBank
|
||||
{
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
if (null === $repetition) {
|
||||
return $piggyBank;
|
||||
}
|
||||
$max = $piggyBank->targetamount;
|
||||
$max = $piggyBank->targetamount;
|
||||
if (1 === bccomp($amount, $max) && 0 !== bccomp($piggyBank->targetamount, '0')) {
|
||||
$amount = $max;
|
||||
}
|
||||
@@ -178,12 +178,12 @@ trait ModifiesPiggyBanks
|
||||
*/
|
||||
public function store(array $data): PiggyBank
|
||||
{
|
||||
$order = $this->getMaxOrder() + 1;
|
||||
$order = $this->getMaxOrder() + 1;
|
||||
if (array_key_exists('order', $data)) {
|
||||
$order = $data['order'];
|
||||
}
|
||||
$data['order'] = 31337; // very high when creating.
|
||||
$piggyData = $data;
|
||||
$data['order'] = 31337; // very high when creating.
|
||||
$piggyData = $data;
|
||||
// unset fields just in case.
|
||||
unset($piggyData['object_group_title'], $piggyData['object_group_id'], $piggyData['notes'], $piggyData['current_amount']);
|
||||
|
||||
@@ -208,7 +208,7 @@ trait ModifiesPiggyBanks
|
||||
$this->updateNote($piggyBank, $data['notes']);
|
||||
|
||||
// repetition is auto created.
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
if (null !== $repetition && array_key_exists('current_amount', $data) && '' !== $data['current_amount']) {
|
||||
$repetition->currentamount = $data['current_amount'];
|
||||
$repetition->save();
|
||||
@@ -223,7 +223,7 @@ trait ModifiesPiggyBanks
|
||||
}
|
||||
}
|
||||
// try also with ID
|
||||
$objectGroupId = (int)($data['object_group_id'] ?? 0);
|
||||
$objectGroupId = (int)($data['object_group_id'] ?? 0);
|
||||
if (0 !== $objectGroupId) {
|
||||
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
||||
if (null !== $objectGroup) {
|
||||
@@ -254,7 +254,7 @@ trait ModifiesPiggyBanks
|
||||
|
||||
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool
|
||||
{
|
||||
$oldOrder = $piggyBank->order;
|
||||
$oldOrder = $piggyBank->order;
|
||||
// app('log')->debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->piggyBanks()->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
|
||||
@@ -281,14 +281,14 @@ trait ModifiesPiggyBanks
|
||||
|
||||
public function update(PiggyBank $piggyBank, array $data): PiggyBank
|
||||
{
|
||||
$piggyBank = $this->updateProperties($piggyBank, $data);
|
||||
$piggyBank = $this->updateProperties($piggyBank, $data);
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->updateNote($piggyBank, (string)$data['notes']);
|
||||
}
|
||||
|
||||
// update the order of the piggy bank:
|
||||
$oldOrder = $piggyBank->order;
|
||||
$newOrder = (int)($data['order'] ?? $oldOrder);
|
||||
$oldOrder = $piggyBank->order;
|
||||
$newOrder = (int)($data['order'] ?? $oldOrder);
|
||||
if ($oldOrder !== $newOrder) {
|
||||
$this->setOrder($piggyBank, $newOrder);
|
||||
}
|
||||
@@ -297,7 +297,7 @@ trait ModifiesPiggyBanks
|
||||
// remove money from the rep.
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
if (null !== $repetition && $repetition->currentamount > $piggyBank->targetamount && 0 !== bccomp($piggyBank->targetamount, '0')) {
|
||||
$difference = bcsub($piggyBank->targetamount, $repetition->currentamount);
|
||||
$difference = bcsub($piggyBank->targetamount, $repetition->currentamount);
|
||||
|
||||
// an amount will be removed, create "negative" event:
|
||||
event(new ChangedAmount($piggyBank, $difference, null, null));
|
||||
@@ -347,7 +347,7 @@ trait ModifiesPiggyBanks
|
||||
|
||||
return true;
|
||||
}
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($piggyBank);
|
||||
|
||||
@@ -92,7 +92,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
|
||||
public function getAttachments(PiggyBank $piggyBank): Collection
|
||||
{
|
||||
$set = $piggyBank->attachments()->get();
|
||||
$set = $piggyBank->attachments()->get();
|
||||
|
||||
/** @var \Storage $disk */
|
||||
$disk = \Storage::disk('upload');
|
||||
@@ -140,15 +140,15 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
{
|
||||
app('log')->debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
|
||||
|
||||
$operator = null;
|
||||
$currency = null;
|
||||
$operator = null;
|
||||
$currency = null;
|
||||
|
||||
/** @var JournalRepositoryInterface $journalRepost */
|
||||
$journalRepost = app(JournalRepositoryInterface::class);
|
||||
$journalRepost = app(JournalRepositoryInterface::class);
|
||||
$journalRepost->setUser($this->user);
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepos */
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$accountRepos->setUser($this->user);
|
||||
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
@@ -157,10 +157,10 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBankCurrency->code));
|
||||
|
||||
/** @var Transaction $source */
|
||||
$source = $journal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
||||
$source = $journal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
||||
|
||||
/** @var Transaction $destination */
|
||||
$destination = $journal->transactions()->with(['account'])->where('amount', '>', 0)->first();
|
||||
$destination = $journal->transactions()->with(['account'])->where('amount', '>', 0)->first();
|
||||
|
||||
// matches source, which means amount will be removed from piggy:
|
||||
if ($source->account_id === $piggyBank->account_id) {
|
||||
@@ -182,7 +182,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
}
|
||||
// currency of the account + the piggy bank currency are almost the same.
|
||||
// which amount from the transaction matches?
|
||||
$amount = null;
|
||||
$amount = null;
|
||||
if ((int)$source->transaction_currency_id === $currency->id) {
|
||||
app('log')->debug('Use normal amount');
|
||||
$amount = app('steam')->{$operator}($source->amount); // @phpstan-ignore-line
|
||||
@@ -198,8 +198,8 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('The currency is %s and the amount is %s', $currency->code, $amount));
|
||||
$room = bcsub($piggyBank->targetamount, $repetition->currentamount);
|
||||
$compare = bcmul($repetition->currentamount, '-1');
|
||||
$room = bcsub($piggyBank->targetamount, $repetition->currentamount);
|
||||
$compare = bcmul($repetition->currentamount, '-1');
|
||||
|
||||
if (0 === bccomp($piggyBank->targetamount, '0')) {
|
||||
// amount is zero? then the "room" is positive amount of we wish to add or remove.
|
||||
@@ -261,7 +261,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
{
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
$set = $this->getPiggyBanks();
|
||||
$set = $this->getPiggyBanks();
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($set as $piggy) {
|
||||
|
||||
@@ -288,7 +288,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($recurrence->user);
|
||||
$collector->withCategoryInformation()->withBudgetInformation()->setLimit($pageSize)->setPage($page)
|
||||
@@ -325,7 +325,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
}
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($recurrence->user);
|
||||
$collector->withCategoryInformation()->withBudgetInformation()->withAccountInformation();
|
||||
@@ -441,21 +441,21 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
);
|
||||
}
|
||||
if ('ndom' === $repetition->repetition_type) {
|
||||
$parts = explode(',', $repetition->repetition_moment);
|
||||
$parts = explode(',', $repetition->repetition_moment);
|
||||
// first part is number of week, second is weekday.
|
||||
$dayOfWeek = trans(sprintf('config.dow_%s', $parts[1]), [], $language);
|
||||
|
||||
return (string)trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $parts[0]], $language);
|
||||
}
|
||||
if ('yearly' === $repetition->repetition_type) {
|
||||
$today = today(config('app.timezone'))->endOfYear();
|
||||
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
|
||||
$today = today(config('app.timezone'))->endOfYear();
|
||||
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
|
||||
if (false === $repDate) {
|
||||
$repDate = clone $today;
|
||||
}
|
||||
$diffInYears = $today->diffInYears($repDate);
|
||||
$repDate->addYears($diffInYears); // technically not necessary.
|
||||
$string = $repDate->isoFormat((string)trans('config.month_and_day_no_year_js'));
|
||||
$string = $repDate->isoFormat((string)trans('config.month_and_day_no_year_js'));
|
||||
|
||||
return (string)trans('firefly.recurring_yearly', ['date' => $string], $language);
|
||||
}
|
||||
@@ -517,7 +517,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
$occurrences = [];
|
||||
$mutator = clone $start;
|
||||
$mutator->startOfDay();
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
$skipMod = $repetition->repetition_skip + 1;
|
||||
app('log')->debug(sprintf('Calculating occurrences for rep type "%s"', $repetition->repetition_type));
|
||||
app('log')->debug(sprintf('Mutator is now: %s', $mutator->format('Y-m-d')));
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
*/
|
||||
public function store(array $data): Rule
|
||||
{
|
||||
$ruleGroup = null;
|
||||
$ruleGroup = null;
|
||||
if (array_key_exists('rule_group_id', $data)) {
|
||||
$ruleGroup = $this->user->ruleGroups()->find($data['rule_group_id']);
|
||||
}
|
||||
@@ -235,7 +235,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
|
||||
// start by creating a new rule:
|
||||
$rule = new Rule();
|
||||
$rule = new Rule();
|
||||
$rule->user()->associate($this->user);
|
||||
$rule->userGroup()->associate($this->user->userGroup);
|
||||
|
||||
@@ -293,10 +293,10 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
|
||||
public function setOrder(Rule $rule, int $newOrder): void
|
||||
{
|
||||
$oldOrder = $rule->order;
|
||||
$groupId = $rule->rule_group_id;
|
||||
$maxOrder = $this->maxOrder($rule->ruleGroup);
|
||||
$newOrder = $newOrder > $maxOrder ? $maxOrder + 1 : $newOrder;
|
||||
$oldOrder = $rule->order;
|
||||
$groupId = $rule->rule_group_id;
|
||||
$maxOrder = $this->maxOrder($rule->ruleGroup);
|
||||
$newOrder = $newOrder > $maxOrder ? $maxOrder + 1 : $newOrder;
|
||||
app('log')->debug(sprintf('New order will be %d', $newOrder));
|
||||
|
||||
if ($newOrder > $oldOrder) {
|
||||
@@ -333,7 +333,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
|
||||
public function storeTrigger(Rule $rule, array $values): RuleTrigger
|
||||
{
|
||||
$ruleTrigger = new RuleTrigger();
|
||||
$ruleTrigger = new RuleTrigger();
|
||||
$ruleTrigger->rule()->associate($rule);
|
||||
$ruleTrigger->order = $values['order'];
|
||||
$ruleTrigger->active = $values['active'];
|
||||
@@ -347,7 +347,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
|
||||
public function storeAction(Rule $rule, array $values): RuleAction
|
||||
{
|
||||
$ruleAction = new RuleAction();
|
||||
$ruleAction = new RuleAction();
|
||||
$ruleAction->rule()->associate($rule);
|
||||
$ruleAction->order = $values['order'];
|
||||
$ruleAction->active = $values['active'];
|
||||
@@ -377,7 +377,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
}
|
||||
$rule->save();
|
||||
$rule->refresh();
|
||||
$group = $rule->ruleGroup;
|
||||
$group = $rule->ruleGroup;
|
||||
// update the order:
|
||||
$this->resetRuleOrder($group);
|
||||
if (array_key_exists('order', $data)) {
|
||||
@@ -425,7 +425,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
private function setRuleTrigger(string $moment, Rule $rule): void
|
||||
{
|
||||
/** @var null|RuleTrigger $trigger */
|
||||
$trigger = $rule->ruleTriggers()->where('trigger_type', 'user_action')->first();
|
||||
$trigger = $rule->ruleTriggers()->where('trigger_type', 'user_action')->first();
|
||||
if (null !== $trigger) {
|
||||
$trigger->trigger_value = $moment;
|
||||
$trigger->save();
|
||||
@@ -454,7 +454,7 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
$type = sprintf('-%s', $type);
|
||||
}
|
||||
|
||||
$triggerValues = [
|
||||
$triggerValues = [
|
||||
'action' => $type,
|
||||
'value' => $value,
|
||||
'stop_processing' => $stopProcessing,
|
||||
|
||||
@@ -365,7 +365,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
|
||||
public function setOrder(RuleGroup $ruleGroup, int $newOrder): void
|
||||
{
|
||||
$oldOrder = $ruleGroup->order;
|
||||
$oldOrder = $ruleGroup->order;
|
||||
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->ruleGroups()->where('rule_groups.order', '<=', $newOrder)->where('rule_groups.order', '>', $oldOrder)
|
||||
|
||||
@@ -46,9 +46,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $tags = null): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$tagIds = [];
|
||||
$tagIds = [];
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$array = [];
|
||||
$listedJournals = [];
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'tags' => [],
|
||||
'currency_id' => $currencyId,
|
||||
@@ -77,9 +77,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
// may have multiple tags:
|
||||
foreach ($journal['tags'] as $tag) {
|
||||
$tagId = (int)$tag['id'];
|
||||
$tagName = (string)$tag['name'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$tagId = (int)$tag['id'];
|
||||
$tagName = (string)$tag['name'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
if(!in_array($tagId, $tagIds, true)) {
|
||||
continue;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
if (in_array($journalId, $listedJournals, true)) {
|
||||
continue;
|
||||
}
|
||||
$listedJournals[] = $journalId;
|
||||
$listedJournals[] = $journalId;
|
||||
$array[$currencyId]['tags'][$tagId] ??= [
|
||||
'id' => $tagId,
|
||||
'name' => $tagName,
|
||||
@@ -128,9 +128,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $tags = null): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT]);
|
||||
$tagIds = [];
|
||||
$tagIds = [];
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
@@ -148,7 +148,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$listedJournals = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$array[$currencyId] ??= [
|
||||
'tags' => [],
|
||||
'currency_id' => $currencyId,
|
||||
@@ -160,9 +160,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
// may have multiple tags:
|
||||
foreach ($journal['tags'] as $tag) {
|
||||
$tagId = (int)$tag['id'];
|
||||
$tagName = (string)$tag['name'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$tagId = (int)$tag['id'];
|
||||
$tagName = (string)$tag['name'];
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
|
||||
if(!in_array($tagId, $tagIds, true)) {
|
||||
continue;
|
||||
@@ -171,9 +171,9 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
if (in_array($journalId, $listedJournals, true)) {
|
||||
continue;
|
||||
}
|
||||
$listedJournals[] = $journalId;
|
||||
$listedJournals[] = $journalId;
|
||||
|
||||
$array[$currencyId]['tags'][$tagId] ??= [
|
||||
$array[$currencyId]['tags'][$tagId] ??= [
|
||||
'id' => $tagId,
|
||||
'name' => $tagName,
|
||||
'transaction_journals' => [],
|
||||
|
||||
@@ -115,7 +115,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
|
||||
public function getAttachments(Tag $tag): Collection
|
||||
{
|
||||
$set = $tag->attachments()->get();
|
||||
$set = $tag->attachments()->get();
|
||||
|
||||
/** @var \Storage $disk */
|
||||
$disk = \Storage::disk('upload');
|
||||
@@ -123,7 +123,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk): void {
|
||||
/** @var null|Note $note */
|
||||
$note = $attachment->notes()->first();
|
||||
$note = $attachment->notes()->first();
|
||||
// only used in v1 view of tags
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes_text = null === $note ? '' : $note->text;
|
||||
@@ -134,7 +134,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
public function getTagsInYear(?int $year): array
|
||||
{
|
||||
// get all tags in the year (if present):
|
||||
$tagQuery = $this->user->tags()->with(['locations', 'attachments'])->orderBy('tags.tag');
|
||||
$tagQuery = $this->user->tags()->with(['locations', 'attachments'])->orderBy('tags.tag');
|
||||
|
||||
// add date range (or not):
|
||||
if (null === $year) {
|
||||
@@ -240,13 +240,13 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
$collector->setTag($tag)->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
$sums = [];
|
||||
$sums = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$found = false;
|
||||
$found = false;
|
||||
|
||||
/** @var array $localTag */
|
||||
foreach ($journal['tags'] as $localTag) {
|
||||
@@ -257,7 +257,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
if (false === $found) {
|
||||
continue;
|
||||
}
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$sums[$currencyId] ??= [
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -271,14 +271,14 @@ class TagRepository implements TagRepositoryInterface
|
||||
];
|
||||
|
||||
// add amount to correct type:
|
||||
$amount = app('steam')->positive((string) $journal['amount']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
$amount = app('steam')->positive((string) $journal['amount']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
$sums[$currencyId][$type] = bcadd($sums[$currencyId][$type], $amount);
|
||||
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
if (null !== $foreignCurrencyId && 0 !== $foreignCurrencyId) {
|
||||
$sums[$foreignCurrencyId] ??= [
|
||||
'currency_id' => $foreignCurrencyId,
|
||||
@@ -292,7 +292,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
TransactionType::OPENING_BALANCE => '0',
|
||||
];
|
||||
// add foreign amount to correct type:
|
||||
$amount = app('steam')->positive((string) $journal['foreign_amount']);
|
||||
$amount = app('steam')->positive((string) $journal['foreign_amount']);
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
@@ -357,7 +357,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
|
||||
// otherwise, update or create.
|
||||
if (!(null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level'])) {
|
||||
$location = $this->getLocation($tag);
|
||||
$location = $this->getLocation($tag);
|
||||
if (null === $location) {
|
||||
$location = new Location();
|
||||
$location->locatable()->associate($tag);
|
||||
|
||||
@@ -97,22 +97,22 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
{
|
||||
$repository = app(AttachmentRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$set = Attachment::whereIn('attachable_id', $journals)
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$set = Attachment::whereIn('attachable_id', $journals)
|
||||
->where('attachable_type', TransactionJournal::class)
|
||||
->where('uploaded', true)
|
||||
->whereNull('deleted_at')->get()
|
||||
;
|
||||
|
||||
$result = [];
|
||||
$result = [];
|
||||
|
||||
/** @var Attachment $attachment */
|
||||
foreach ($set as $attachment) {
|
||||
$journalId = $attachment->attachable_id;
|
||||
$result[$journalId] ??= [];
|
||||
$current = $attachment->toArray();
|
||||
$current['file_exists'] = true;
|
||||
$current['notes'] = $repository->getNoteText($attachment);
|
||||
$journalId = $attachment->attachable_id;
|
||||
$result[$journalId] ??= [];
|
||||
$current = $attachment->toArray();
|
||||
$current['file_exists'] = true;
|
||||
$current['notes'] = $repository->getNoteText($attachment);
|
||||
// already determined that this attachable is a TransactionJournal.
|
||||
$current['journal_title'] = $attachment->attachable->description; // @phpstan-ignore-line
|
||||
$result[$journalId][] = $current;
|
||||
@@ -165,7 +165,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
|
||||
/** @var TransactionJournalLink $entry */
|
||||
foreach ($set as $entry) {
|
||||
$journalId = in_array($entry->source_id, $journals, true) ? $entry->source_id : $entry->destination_id;
|
||||
$journalId = in_array($entry->source_id, $journals, true) ? $entry->source_id : $entry->destination_id;
|
||||
$return[$journalId] ??= [];
|
||||
|
||||
// phpstan: the editable field is provided by the query.
|
||||
@@ -272,14 +272,14 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
continue;
|
||||
}
|
||||
// get currency preference.
|
||||
$currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id)
|
||||
$currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id)
|
||||
->where('name', 'currency_id')
|
||||
->first()
|
||||
;
|
||||
if (null !== $currencyPreference) {
|
||||
$currency = TransactionCurrency::where('id', $currencyPreference->data)->first();
|
||||
}
|
||||
$journalId = $row->transaction_journal_id;
|
||||
$journalId = $row->transaction_journal_id;
|
||||
$return[$journalId] ??= [];
|
||||
|
||||
$return[$journalId][] = [
|
||||
@@ -420,10 +420,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
|
||||
if (0 === bccomp('0', $transaction->foreign_amount)) {
|
||||
return '';
|
||||
}
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
$return = '';
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
$return = '';
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class TransactionTypeRepository implements TransactionTypeRepositoryInterface
|
||||
return $type;
|
||||
}
|
||||
$typeString ??= TransactionType::WITHDRAWAL;
|
||||
$search = $this->findByType($typeString);
|
||||
$search = $this->findByType($typeString);
|
||||
if (null === $search) {
|
||||
$search = $this->findByType(TransactionType::WITHDRAWAL);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
*/
|
||||
public function changeEmail(User $user, string $newEmail): bool
|
||||
{
|
||||
$oldEmail = $user->email;
|
||||
$oldEmail = $user->email;
|
||||
|
||||
// save old email as pref
|
||||
app('preferences')->setForUser($user, 'previous_email_latest', $oldEmail);
|
||||
@@ -170,7 +170,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
public function getRolesInGroup(User $user, int $groupId): array
|
||||
{
|
||||
/** @var null|UserGroup $group */
|
||||
$group = UserGroup::find($groupId);
|
||||
$group = UserGroup::find($groupId);
|
||||
if (null === $group) {
|
||||
throw new FireflyException(sprintf('Could not find group #%d', $groupId));
|
||||
}
|
||||
@@ -196,7 +196,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
*/
|
||||
public function getUserData(User $user): array
|
||||
{
|
||||
$return = [];
|
||||
$return = [];
|
||||
|
||||
// two factor:
|
||||
$return['has_2fa'] = null !== $user->mfa_secret;
|
||||
@@ -244,9 +244,9 @@ class UserRepository implements UserRepositoryInterface
|
||||
|
||||
public function inviteUser(null|Authenticatable|User $user, string $email): InvitedUser
|
||||
{
|
||||
$now = today(config('app.timezone'));
|
||||
$now = today(config('app.timezone'));
|
||||
$now->addDays(2);
|
||||
$invitee = new InvitedUser();
|
||||
$invitee = new InvitedUser();
|
||||
$invitee->user()->associate($user);
|
||||
$invitee->invite_code = \Str::random(64);
|
||||
$invitee->email = $email;
|
||||
@@ -356,7 +356,7 @@ class UserRepository implements UserRepositoryInterface
|
||||
if ('' === $newEmail) {
|
||||
return true;
|
||||
}
|
||||
$oldEmail = $user->email;
|
||||
$oldEmail = $user->email;
|
||||
|
||||
// save old email as pref
|
||||
app('preferences')->setForUser($user, 'admin_previous_email_latest', $oldEmail);
|
||||
|
||||
@@ -49,7 +49,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
/** @var GroupMembership $membership */
|
||||
foreach ($memberships as $membership) {
|
||||
/** @var null|User $user */
|
||||
$user = $membership->user()->first();
|
||||
$user = $membership->user()->first();
|
||||
if (null === $user) {
|
||||
continue;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
// all users are now moved away from user group.
|
||||
// time to DESTROY all objects.
|
||||
// we have to do this one by one to trigger the necessary observers :(
|
||||
$objects = ['availableBudgets', 'bills', 'budgets', 'categories', 'currencyExchangeRates', 'objectGroups',
|
||||
$objects = ['availableBudgets', 'bills', 'budgets', 'categories', 'currencyExchangeRates', 'objectGroups',
|
||||
'recurrences', 'rules', 'ruleGroups', 'tags', 'transactionGroups', 'transactionJournals', 'piggyBanks', 'accounts', 'webhooks',
|
||||
];
|
||||
foreach ($objects as $object) {
|
||||
@@ -125,7 +125,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
$data['user'] = $this->user;
|
||||
|
||||
/** @var UserGroupFactory $factory */
|
||||
$factory = app(UserGroupFactory::class);
|
||||
$factory = app(UserGroupFactory::class);
|
||||
|
||||
return $factory->create($data);
|
||||
}
|
||||
@@ -163,11 +163,11 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
*/
|
||||
public function updateMembership(UserGroup $userGroup, array $data): UserGroup
|
||||
{
|
||||
$owner = UserRole::whereTitle(UserRoleEnum::OWNER)->first();
|
||||
$owner = UserRole::whereTitle(UserRoleEnum::OWNER)->first();
|
||||
app('log')->debug('in update membership');
|
||||
|
||||
/** @var null|User $user */
|
||||
$user = null;
|
||||
$user = null;
|
||||
if (array_key_exists('id', $data)) {
|
||||
/** @var null|User $user */
|
||||
$user = User::find($data['id']);
|
||||
@@ -252,7 +252,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
while ($exists && $loop < 10) {
|
||||
$existingGroup = $this->findByName($groupName);
|
||||
if (null === $existingGroup) {
|
||||
$exists = false;
|
||||
$exists = false;
|
||||
|
||||
/** @var null|UserGroup $existingGroup */
|
||||
$existingGroup = $this->store(['user' => $user, 'title' => $groupName]);
|
||||
|
||||
@@ -78,7 +78,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
public function findByName(string $name, array $types): ?Account
|
||||
{
|
||||
$query = $this->userGroup->accounts();
|
||||
$query = $this->userGroup->accounts();
|
||||
|
||||
if (0 !== count($types)) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
@@ -102,8 +102,8 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
|
||||
// return null if not in this list.
|
||||
if (!in_array($type, $list, true)) {
|
||||
|
||||
@@ -81,18 +81,18 @@ class BillRepository implements BillRepositoryInterface
|
||||
$currencyId = $bill->transaction_currency_id;
|
||||
|
||||
$return[$currencyId] ??= [
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'native_currency_id' => (string)$default->id,
|
||||
'native_currency_name' => $default->name,
|
||||
'native_currency_symbol' => $default->symbol,
|
||||
'native_currency_code' => $default->code,
|
||||
'native_currency_decimal_places' => $default->decimal_places,
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
];
|
||||
|
||||
/** @var TransactionJournal $transactionJournal */
|
||||
@@ -100,13 +100,13 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var null|Transaction $sourceTransaction */
|
||||
$sourceTransaction = $transactionJournal->transactions()->where('amount', '<', 0)->first();
|
||||
if (null !== $sourceTransaction) {
|
||||
$amount = $sourceTransaction->amount;
|
||||
$amount = $sourceTransaction->amount;
|
||||
if ((int)$sourceTransaction->foreign_currency_id === $currency->id) {
|
||||
// use foreign amount instead!
|
||||
$amount = (string)$sourceTransaction->foreign_amount;
|
||||
}
|
||||
// convert to native currency
|
||||
$nativeAmount = $amount;
|
||||
$nativeAmount = $amount;
|
||||
if ($currencyId !== $default->id) {
|
||||
// get rate and convert.
|
||||
$nativeAmount = $converter->convert($currency, $default, $transactionJournal->date, $amount);
|
||||
@@ -153,19 +153,19 @@ class BillRepository implements BillRepositoryInterface
|
||||
$currencyId = $bill->transaction_currency_id;
|
||||
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
|
||||
$nativeAverage = $converter->convert($currency, $default, $start, $average);
|
||||
$return[$currencyId] ??= [
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
$return[$currencyId] ??= [
|
||||
'currency_id' => (string)$currency->id,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'native_currency_id' => (string)$default->id,
|
||||
'native_currency_name' => $default->name,
|
||||
'native_currency_symbol' => $default->symbol,
|
||||
'native_currency_code' => $default->code,
|
||||
'native_currency_decimal_places' => $default->decimal_places,
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
'sum' => '0',
|
||||
'native_sum' => '0',
|
||||
];
|
||||
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], bcmul($average, (string)$total));
|
||||
$return[$currencyId]['native_sum'] = bcadd($return[$currencyId]['native_sum'], bcmul($nativeAverage, (string)$total));
|
||||
@@ -200,7 +200,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;
|
||||
|
||||
@@ -51,7 +51,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
/** @var AvailableBudget $availableBudget */
|
||||
foreach ($availableBudgets as $availableBudget) {
|
||||
$currencyId = $availableBudget->transaction_currency_id;
|
||||
$return[$currencyId] ??= [
|
||||
$return[$currencyId] ??= [
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $availableBudget->transactionCurrency->code,
|
||||
'currency_symbol' => $availableBudget->transactionCurrency->symbol,
|
||||
|
||||
@@ -56,13 +56,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$collector->setBudgets($this->getBudgets());
|
||||
}
|
||||
$collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = (string)$journal['budget_name'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$budgetName = (string)$journal['budget_name'];
|
||||
|
||||
// catch "no budget" entries.
|
||||
if (0 === $budgetId) {
|
||||
@@ -70,7 +70,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
}
|
||||
|
||||
// info about the currency:
|
||||
$array[$currencyId] ??= [
|
||||
$array[$currencyId] ??= [
|
||||
'budgets' => [],
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
@@ -88,8 +88,8 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
|
||||
// add journal to array:
|
||||
// only a subset of the fields.
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$final = [
|
||||
$journalId = (int)$journal['transaction_journal_id'];
|
||||
$final = [
|
||||
'amount' => app('steam')->negative($journal['amount']),
|
||||
'currency_id' => $journal['currency_id'],
|
||||
'foreign_amount' => null,
|
||||
|
||||
@@ -62,7 +62,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
public function currencyInUseAt(TransactionCurrency $currency): ?string
|
||||
{
|
||||
app('log')->debug(sprintf('Now in currencyInUse() for #%d ("%s")', $currency->id, $currency->code));
|
||||
$countJournals = $this->countJournals($currency);
|
||||
$countJournals = $this->countJournals($currency);
|
||||
if ($countJournals > 0) {
|
||||
app('log')->info(sprintf('Count journals is %d, return true.', $countJournals));
|
||||
|
||||
@@ -77,7 +77,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in accounts:
|
||||
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string)$currency->id))->count();
|
||||
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string)$currency->id))->count();
|
||||
if ($meta > 0) {
|
||||
app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
|
||||
|
||||
@@ -85,7 +85,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in bills:
|
||||
$bills = Bill::where('transaction_currency_id', $currency->id)->count();
|
||||
$bills = Bill::where('transaction_currency_id', $currency->id)->count();
|
||||
if ($bills > 0) {
|
||||
app('log')->info(sprintf('Used in %d bills as currency, return true. ', $bills));
|
||||
|
||||
@@ -103,7 +103,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in accounts (as integer)
|
||||
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereNull('accounts.deleted_at')
|
||||
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count()
|
||||
;
|
||||
@@ -122,7 +122,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in budget limits
|
||||
$budgetLimit = BudgetLimit::where('transaction_currency_id', $currency->id)->count();
|
||||
$budgetLimit = BudgetLimit::where('transaction_currency_id', $currency->id)->count();
|
||||
if ($budgetLimit > 0) {
|
||||
app('log')->info(sprintf('Used in %d budget limits as currency, return true. ', $budgetLimit));
|
||||
|
||||
@@ -130,7 +130,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is the default currency for the user or the system
|
||||
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
|
||||
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
|
||||
if ($count > 0) {
|
||||
app('log')->info('Is the default currency of the user, return true.');
|
||||
|
||||
@@ -138,7 +138,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is the default currency for the user or the system
|
||||
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
|
||||
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
|
||||
if ($count > 0) {
|
||||
app('log')->info('Is the default currency of the user group, return true.');
|
||||
|
||||
@@ -159,10 +159,10 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
$local = $this->get();
|
||||
|
||||
return $all->map(static function (TransactionCurrency $current) use ($local) {
|
||||
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return $entry->id === $current->id;
|
||||
});
|
||||
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return 1 === (int)$entry->pivot->group_default && $entry->id === $current->id;
|
||||
});
|
||||
$current->userGroupEnabled = $hasId;
|
||||
|
||||
Reference in New Issue
Block a user