mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Merge pull request #10397 from firefly-iii/release-1748670980
🤖 Automatically merge the PR into the develop branch.
This commit is contained in:
@@ -54,7 +54,7 @@ class UpdateController extends Controller
|
|||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
/** @var User $admin */
|
/** @var User $admin */
|
||||||
$admin = auth()->user();
|
$admin = auth()->user();
|
||||||
|
|
||||||
$this->groupRepository = app(TransactionGroupRepositoryInterface::class);
|
$this->groupRepository = app(TransactionGroupRepositoryInterface::class);
|
||||||
$this->groupRepository->setUser($admin);
|
$this->groupRepository->setUser($admin);
|
||||||
@@ -73,47 +73,48 @@ class UpdateController extends Controller
|
|||||||
public function update(UpdateRequest $request, TransactionGroup $transactionGroup): JsonResponse
|
public function update(UpdateRequest $request, TransactionGroup $transactionGroup): JsonResponse
|
||||||
{
|
{
|
||||||
app('log')->debug('Now in update routine for transaction group');
|
app('log')->debug('Now in update routine for transaction group');
|
||||||
$data = $request->getAll();
|
$data = $request->getAll();
|
||||||
$oldAmount = $this->groupRepository->getTotalAmount($transactionGroup);
|
$oldAmount = $this->groupRepository->getTotalAmount($transactionGroup);
|
||||||
$transactionGroup = $this->groupRepository->update($transactionGroup, $data);
|
$transactionGroup = $this->groupRepository->update($transactionGroup, $data);
|
||||||
$newAmount = $this->groupRepository->getTotalAmount($transactionGroup);
|
$newAmount = $this->groupRepository->getTotalAmount($transactionGroup);
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
|
||||||
Log::debug(sprintf('Old amount: %s, new amount: %s', $oldAmount, $newAmount));
|
Log::debug(sprintf('Old amount: %s, new amount: %s', $oldAmount, $newAmount));
|
||||||
|
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
$applyRules = $data['apply_rules'] ?? true;
|
$applyRules = $data['apply_rules'] ?? true;
|
||||||
$fireWebhooks = $data['fire_webhooks'] ?? true;
|
$fireWebhooks = $data['fire_webhooks'] ?? true;
|
||||||
$amountChanged = 0 !== bccomp($oldAmount, $newAmount);
|
$amountChanged = 0 !== bccomp($oldAmount, $newAmount);
|
||||||
event(new UpdatedTransactionGroup($transactionGroup, $applyRules, $fireWebhooks, $amountChanged));
|
event(new UpdatedTransactionGroup($transactionGroup, $applyRules, $fireWebhooks, $amountChanged));
|
||||||
|
|
||||||
/** @var User $admin */
|
/** @var User $admin */
|
||||||
$admin = auth()->user();
|
$admin = auth()->user();
|
||||||
|
|
||||||
// use new group collector:
|
// use new group collector:
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector
|
$collector
|
||||||
->setUser($admin)
|
->setUser($admin)
|
||||||
// filter on transaction group.
|
// filter on transaction group.
|
||||||
->setTransactionGroup($transactionGroup)
|
->setTransactionGroup($transactionGroup)
|
||||||
// all info needed for the API:
|
// all info needed for the API:
|
||||||
->withAPIInformation();
|
->withAPIInformation()
|
||||||
|
;
|
||||||
|
|
||||||
$selectedGroup = $collector->getGroups()->first();
|
$selectedGroup = $collector->getGroups()->first();
|
||||||
if (null === $selectedGroup) {
|
if (null === $selectedGroup) {
|
||||||
throw new NotFoundHttpException();
|
throw new NotFoundHttpException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// enrich
|
// enrich
|
||||||
$enrichment = new TransactionGroupEnrichment();
|
$enrichment = new TransactionGroupEnrichment();
|
||||||
$enrichment->setUser($admin);
|
$enrichment->setUser($admin);
|
||||||
$selectedGroup = $enrichment->enrichSingle($selectedGroup);
|
$selectedGroup = $enrichment->enrichSingle($selectedGroup);
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
$transformer = app(TransactionGroupTransformer::class);
|
$transformer = app(TransactionGroupTransformer::class);
|
||||||
$transformer->setParameters($this->parameters);
|
$transformer->setParameters($this->parameters);
|
||||||
$resource = new Item($selectedGroup, $transformer, 'transactions');
|
$resource = new Item($selectedGroup, $transformer, 'transactions');
|
||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
@@ -69,7 +69,7 @@ class UpdateController extends Controller
|
|||||||
$transactionGroup = $this->groupRepository->update($transactionGroup, $data);
|
$transactionGroup = $this->groupRepository->update($transactionGroup, $data);
|
||||||
$applyRules = $data['apply_rules'] ?? true;
|
$applyRules = $data['apply_rules'] ?? true;
|
||||||
$fireWebhooks = $data['fire_webhooks'] ?? true;
|
$fireWebhooks = $data['fire_webhooks'] ?? true;
|
||||||
$amountChanged = true;
|
$amountChanged = true;
|
||||||
|
|
||||||
event(new UpdatedTransactionGroup($transactionGroup, $applyRules, $fireWebhooks, $amountChanged));
|
event(new UpdatedTransactionGroup($transactionGroup, $applyRules, $fireWebhooks, $amountChanged));
|
||||||
app('preferences')->mark();
|
app('preferences')->mark();
|
||||||
|
@@ -54,8 +54,8 @@ class CorrectsIbans extends Command
|
|||||||
{
|
{
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$iban = (string) $account->iban;
|
$iban = (string) $account->iban;
|
||||||
$newIban = app('steam')->filterSpaces($iban);
|
$newIban = app('steam')->filterSpaces($iban);
|
||||||
if ('' !== $iban && $iban !== $newIban) {
|
if ('' !== $iban && $iban !== $newIban) {
|
||||||
$account->iban = $newIban;
|
$account->iban = $newIban;
|
||||||
$account->save();
|
$account->save();
|
||||||
@@ -64,8 +64,8 @@ class CorrectsIbans extends Command
|
|||||||
}
|
}
|
||||||
// same for account number:
|
// same for account number:
|
||||||
$accountNumber = $account->accountMeta->where('name', 'account_number')->first();
|
$accountNumber = $account->accountMeta->where('name', 'account_number')->first();
|
||||||
if(null !== $accountNumber) {
|
if (null !== $accountNumber) {
|
||||||
$number = (string) $accountNumber->value;
|
$number = (string) $accountNumber->value;
|
||||||
$newNumber = app('steam')->filterSpaces($number);
|
$newNumber = app('steam')->filterSpaces($number);
|
||||||
if ('' !== $number && $number !== $newNumber) {
|
if ('' !== $number && $number !== $newNumber) {
|
||||||
$accountNumber->value = $newNumber;
|
$accountNumber->value = $newNumber;
|
||||||
|
@@ -42,9 +42,9 @@ class AccountMetaFactory
|
|||||||
$entry = $account->accountMeta()->where('name', $field)->first();
|
$entry = $account->accountMeta()->where('name', $field)->first();
|
||||||
// must not be an empty string:
|
// must not be an empty string:
|
||||||
if ('' !== $value) {
|
if ('' !== $value) {
|
||||||
if('account_number' === $field) {
|
if ('account_number' === $field) {
|
||||||
$value = Steam::filterSpaces($value);
|
$value = Steam::filterSpaces($value);
|
||||||
$value = trim(str_replace([' ',"\t", "\n", "\r"], '', $value));
|
$value = trim(str_replace([' ', "\t", "\n", "\r"], '', $value));
|
||||||
}
|
}
|
||||||
// if $data has field and $entry is null, create new one:
|
// if $data has field and $entry is null, create new one:
|
||||||
if (null === $entry) {
|
if (null === $entry) {
|
||||||
|
@@ -60,19 +60,20 @@ class UpdatedGroupEventHandler
|
|||||||
*/
|
*/
|
||||||
public function unifyAccounts(UpdatedTransactionGroup $updatedGroupEvent): void
|
public function unifyAccounts(UpdatedTransactionGroup $updatedGroupEvent): void
|
||||||
{
|
{
|
||||||
$group = $updatedGroupEvent->transactionGroup;
|
$group = $updatedGroupEvent->transactionGroup;
|
||||||
if (1 === $group->transactionJournals->count()) {
|
if (1 === $group->transactionJournals->count()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// first journal:
|
// first journal:
|
||||||
/** @var null|TransactionJournal $first */
|
/** @var null|TransactionJournal $first */
|
||||||
$first = $group->transactionJournals()
|
$first = $group->transactionJournals()
|
||||||
->orderBy('transaction_journals.date', 'DESC')
|
->orderBy('transaction_journals.date', 'DESC')
|
||||||
->orderBy('transaction_journals.order', 'ASC')
|
->orderBy('transaction_journals.order', 'ASC')
|
||||||
->orderBy('transaction_journals.id', 'DESC')
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
->orderBy('transaction_journals.description', 'DESC')
|
->orderBy('transaction_journals.description', 'DESC')
|
||||||
->first();
|
->first()
|
||||||
|
;
|
||||||
|
|
||||||
if (null === $first) {
|
if (null === $first) {
|
||||||
Log::warning(sprintf('Group #%d has no transaction journals.', $group->id));
|
Log::warning(sprintf('Group #%d has no transaction journals.', $group->id));
|
||||||
@@ -80,24 +81,26 @@ class UpdatedGroupEventHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$all = $group->transactionJournals()->get()->pluck('id')->toArray();
|
$all = $group->transactionJournals()->get()->pluck('id')->toArray();
|
||||||
|
|
||||||
/** @var Account $sourceAccount */
|
/** @var Account $sourceAccount */
|
||||||
$sourceAccount = $first->transactions()->where('amount', '<', '0')->first()->account;
|
$sourceAccount = $first->transactions()->where('amount', '<', '0')->first()->account;
|
||||||
|
|
||||||
/** @var Account $destAccount */
|
/** @var Account $destAccount */
|
||||||
$destAccount = $first->transactions()->where('amount', '>', '0')->first()->account;
|
$destAccount = $first->transactions()->where('amount', '>', '0')->first()->account;
|
||||||
|
|
||||||
$type = $first->transactionType->type;
|
$type = $first->transactionType->type;
|
||||||
if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||||
// set all source transactions to source account:
|
// set all source transactions to source account:
|
||||||
Transaction::whereIn('transaction_journal_id', $all)
|
Transaction::whereIn('transaction_journal_id', $all)
|
||||||
->where('amount', '<', 0)->update(['account_id' => $sourceAccount->id]);
|
->where('amount', '<', 0)->update(['account_id' => $sourceAccount->id])
|
||||||
|
;
|
||||||
}
|
}
|
||||||
if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::DEPOSIT->value === $type) {
|
if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::DEPOSIT->value === $type) {
|
||||||
// set all destination transactions to destination account:
|
// set all destination transactions to destination account:
|
||||||
Transaction::whereIn('transaction_journal_id', $all)
|
Transaction::whereIn('transaction_journal_id', $all)
|
||||||
->where('amount', '>', 0)->update(['account_id' => $destAccount->id]);
|
->where('amount', '>', 0)->update(['account_id' => $destAccount->id])
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,24 +115,24 @@ class UpdatedGroupEventHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$journals = $updatedGroupEvent->transactionGroup->transactionJournals;
|
$journals = $updatedGroupEvent->transactionGroup->transactionJournals;
|
||||||
$array = [];
|
$array = [];
|
||||||
|
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$array[] = $journal->id;
|
$array[] = $journal->id;
|
||||||
}
|
}
|
||||||
$journalIds = implode(',', $array);
|
$journalIds = implode(',', $array);
|
||||||
Log::debug(sprintf('Add local operator for journal(s): %s', $journalIds));
|
Log::debug(sprintf('Add local operator for journal(s): %s', $journalIds));
|
||||||
|
|
||||||
// collect rules:
|
// collect rules:
|
||||||
$ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
|
$ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
|
||||||
$ruleGroupRepository->setUser($updatedGroupEvent->transactionGroup->user);
|
$ruleGroupRepository->setUser($updatedGroupEvent->transactionGroup->user);
|
||||||
|
|
||||||
$groups = $ruleGroupRepository->getRuleGroupsWithRules('update-journal');
|
$groups = $ruleGroupRepository->getRuleGroupsWithRules('update-journal');
|
||||||
|
|
||||||
// file rule engine.
|
// file rule engine.
|
||||||
$newRuleEngine = app(RuleEngineInterface::class);
|
$newRuleEngine = app(RuleEngineInterface::class);
|
||||||
$newRuleEngine->setUser($updatedGroupEvent->transactionGroup->user);
|
$newRuleEngine->setUser($updatedGroupEvent->transactionGroup->user);
|
||||||
$newRuleEngine->addOperator(['type' => 'journal_id', 'value' => $journalIds]);
|
$newRuleEngine->addOperator(['type' => 'journal_id', 'value' => $journalIds]);
|
||||||
$newRuleEngine->setRuleGroups($groups);
|
$newRuleEngine->setRuleGroups($groups);
|
||||||
@@ -138,7 +141,7 @@ class UpdatedGroupEventHandler
|
|||||||
|
|
||||||
private function recalculateCredit(UpdatedTransactionGroup $event): void
|
private function recalculateCredit(UpdatedTransactionGroup $event): void
|
||||||
{
|
{
|
||||||
$group = $event->transactionGroup;
|
$group = $event->transactionGroup;
|
||||||
|
|
||||||
/** @var CreditRecalculateService $object */
|
/** @var CreditRecalculateService $object */
|
||||||
$object = app(CreditRecalculateService::class);
|
$object = app(CreditRecalculateService::class);
|
||||||
@@ -149,13 +152,13 @@ class UpdatedGroupEventHandler
|
|||||||
private function triggerWebhooks(UpdatedTransactionGroup $updatedGroupEvent): void
|
private function triggerWebhooks(UpdatedTransactionGroup $updatedGroupEvent): void
|
||||||
{
|
{
|
||||||
Log::debug(__METHOD__);
|
Log::debug(__METHOD__);
|
||||||
$group = $updatedGroupEvent->transactionGroup;
|
$group = $updatedGroupEvent->transactionGroup;
|
||||||
if (false === $updatedGroupEvent->fireWebhooks) {
|
if (false === $updatedGroupEvent->fireWebhooks) {
|
||||||
Log::info(sprintf('Will not fire webhooks for transaction group #%d', $group->id));
|
Log::info(sprintf('Will not fire webhooks for transaction group #%d', $group->id));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$user = $group->user;
|
$user = $group->user;
|
||||||
|
|
||||||
/** @var MessageGeneratorInterface $engine */
|
/** @var MessageGeneratorInterface $engine */
|
||||||
$engine = app(MessageGeneratorInterface::class);
|
$engine = app(MessageGeneratorInterface::class);
|
||||||
|
@@ -86,7 +86,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$this->hasJoinedAttTables = false;
|
$this->hasJoinedAttTables = false;
|
||||||
$this->expandGroupSearch = false;
|
$this->expandGroupSearch = false;
|
||||||
$this->hasJoinedMetaTables = false;
|
$this->hasJoinedMetaTables = false;
|
||||||
$this->booleanFields = ['source_balance_dirty','destination_balance_dirty'];
|
$this->booleanFields = ['source_balance_dirty', 'destination_balance_dirty'];
|
||||||
$this->integerFields = [
|
$this->integerFields = [
|
||||||
'transaction_group_id',
|
'transaction_group_id',
|
||||||
'user_id',
|
'user_id',
|
||||||
|
@@ -191,15 +191,15 @@ class MassController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function updateJournal(int $journalId, MassEditJournalRequest $request): void
|
private function updateJournal(int $journalId, MassEditJournalRequest $request): void
|
||||||
{
|
{
|
||||||
$journal = $this->repository->find($journalId);
|
$journal = $this->repository->find($journalId);
|
||||||
if (!$journal instanceof TransactionJournal) {
|
if (!$journal instanceof TransactionJournal) {
|
||||||
throw new FireflyException(sprintf('Trying to edit non-existent or deleted journal #%d', $journalId));
|
throw new FireflyException(sprintf('Trying to edit non-existent or deleted journal #%d', $journalId));
|
||||||
}
|
}
|
||||||
$service = app(JournalUpdateService::class);
|
$service = app(JournalUpdateService::class);
|
||||||
// for each field, call the update service.
|
// for each field, call the update service.
|
||||||
$service->setTransactionJournal($journal);
|
$service->setTransactionJournal($journal);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'date' => $this->getDateFromRequest($request, $journal->id, 'date'),
|
'date' => $this->getDateFromRequest($request, $journal->id, 'date'),
|
||||||
'description' => $this->getStringFromRequest($request, $journal->id, 'description'),
|
'description' => $this->getStringFromRequest($request, $journal->id, 'description'),
|
||||||
'source_id' => $this->getIntFromRequest($request, $journal->id, 'source_id'),
|
'source_id' => $this->getIntFromRequest($request, $journal->id, 'source_id'),
|
||||||
|
@@ -436,15 +436,17 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
|||||||
public function getTotalAmount(TransactionGroup $group): string
|
public function getTotalAmount(TransactionGroup $group): string
|
||||||
{
|
{
|
||||||
$sum = '0';
|
$sum = '0';
|
||||||
|
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach($group->transactionJournals as $journal) {
|
foreach ($group->transactionJournals as $journal) {
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
foreach($journal->transactions as $transaction) {
|
foreach ($journal->transactions as $transaction) {
|
||||||
if(-1 === bccomp('0', (string) $transaction->amount)) {
|
if (-1 === bccomp('0', (string) $transaction->amount)) {
|
||||||
$sum = bcadd($sum, $transaction->amount);
|
$sum = bcadd($sum, $transaction->amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,19 +76,19 @@ class JournalUpdateService
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->destinationAccount = null;
|
$this->destinationAccount = null;
|
||||||
$this->destinationTransaction = null;
|
$this->destinationTransaction = null;
|
||||||
$this->sourceAccount = null;
|
$this->sourceAccount = null;
|
||||||
$this->sourceTransaction = null;
|
$this->sourceTransaction = null;
|
||||||
$this->transactionGroup = null;
|
$this->transactionGroup = null;
|
||||||
$this->transactionJournal = null;
|
$this->transactionJournal = null;
|
||||||
$this->billRepository = app(BillRepositoryInterface::class);
|
$this->billRepository = app(BillRepositoryInterface::class);
|
||||||
$this->categoryRepository = app(CategoryRepositoryInterface::class);
|
$this->categoryRepository = app(CategoryRepositoryInterface::class);
|
||||||
$this->budgetRepository = app(BudgetRepositoryInterface::class);
|
$this->budgetRepository = app(BudgetRepositoryInterface::class);
|
||||||
$this->tagFactory = app(TagFactory::class);
|
$this->tagFactory = app(TagFactory::class);
|
||||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||||
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
|
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
|
||||||
$this->metaString = [
|
$this->metaString = [
|
||||||
'sepa_cc',
|
'sepa_cc',
|
||||||
'sepa_ct_op',
|
'sepa_ct_op',
|
||||||
'sepa_ct_id',
|
'sepa_ct_id',
|
||||||
@@ -103,8 +103,8 @@ class JournalUpdateService
|
|||||||
'external_id',
|
'external_id',
|
||||||
'external_url',
|
'external_url',
|
||||||
];
|
];
|
||||||
$this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date',
|
$this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date',
|
||||||
'invoice_date',];
|
'invoice_date', ];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setData(array $data): void
|
public function setData(array $data): void
|
||||||
@@ -114,16 +114,16 @@ class JournalUpdateService
|
|||||||
|
|
||||||
public function setTransactionGroup(TransactionGroup $transactionGroup): void
|
public function setTransactionGroup(TransactionGroup $transactionGroup): void
|
||||||
{
|
{
|
||||||
$this->transactionGroup = $transactionGroup;
|
$this->transactionGroup = $transactionGroup;
|
||||||
$this->billRepository->setUser($transactionGroup->user);
|
$this->billRepository->setUser($transactionGroup->user);
|
||||||
$this->categoryRepository->setUser($transactionGroup->user);
|
$this->categoryRepository->setUser($transactionGroup->user);
|
||||||
$this->budgetRepository->setUser($transactionGroup->user);
|
$this->budgetRepository->setUser($transactionGroup->user);
|
||||||
$this->tagFactory->setUser($transactionGroup->user);
|
$this->tagFactory->setUser($transactionGroup->user);
|
||||||
$this->accountRepository->setUser($transactionGroup->user);
|
$this->accountRepository->setUser($transactionGroup->user);
|
||||||
$this->destinationAccount = null;
|
$this->destinationAccount = null;
|
||||||
$this->destinationTransaction = null;
|
$this->destinationTransaction = null;
|
||||||
$this->sourceAccount = null;
|
$this->sourceAccount = null;
|
||||||
$this->sourceTransaction = null;
|
$this->sourceTransaction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTransactionJournal(TransactionJournal $transactionJournal): void
|
public function setTransactionJournal(TransactionJournal $transactionJournal): void
|
||||||
@@ -183,14 +183,14 @@ class JournalUpdateService
|
|||||||
|
|
||||||
private function hasValidSourceAccount(): bool
|
private function hasValidSourceAccount(): bool
|
||||||
{
|
{
|
||||||
$sourceId = $this->data['source_id'] ?? null;
|
$sourceId = $this->data['source_id'] ?? null;
|
||||||
$sourceName = $this->data['source_name'] ?? null;
|
$sourceName = $this->data['source_name'] ?? null;
|
||||||
Log::debug(sprintf('Now in hasValidSourceAccount("%s","%s").', $sourceId, $sourceName));
|
Log::debug(sprintf('Now in hasValidSourceAccount("%s","%s").', $sourceId, $sourceName));
|
||||||
|
|
||||||
if (!$this->hasFields(['source_id', 'source_name'])) {
|
if (!$this->hasFields(['source_id', 'source_name'])) {
|
||||||
$origSourceAccount = $this->getOriginalSourceAccount();
|
$origSourceAccount = $this->getOriginalSourceAccount();
|
||||||
$sourceId = $origSourceAccount->id;
|
$sourceId = $origSourceAccount->id;
|
||||||
$sourceName = $origSourceAccount->name;
|
$sourceName = $origSourceAccount->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make new account validator.
|
// make new account validator.
|
||||||
@@ -199,11 +199,11 @@ class JournalUpdateService
|
|||||||
|
|
||||||
// make a new validator.
|
// make a new validator.
|
||||||
/** @var AccountValidator $validator */
|
/** @var AccountValidator $validator */
|
||||||
$validator = app(AccountValidator::class);
|
$validator = app(AccountValidator::class);
|
||||||
$validator->setTransactionType($expectedType);
|
$validator->setTransactionType($expectedType);
|
||||||
$validator->setUser($this->transactionJournal->user);
|
$validator->setUser($this->transactionJournal->user);
|
||||||
|
|
||||||
$result = $validator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
|
$result = $validator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf('hasValidSourceAccount(%d, "%s") will return %s', $sourceId, $sourceName, var_export($result, true))
|
sprintf('hasValidSourceAccount(%d, "%s") will return %s', $sourceId, $sourceName, var_export($result, true))
|
||||||
);
|
);
|
||||||
@@ -228,7 +228,7 @@ class JournalUpdateService
|
|||||||
private function getOriginalSourceAccount(): Account
|
private function getOriginalSourceAccount(): Account
|
||||||
{
|
{
|
||||||
if (!$this->sourceAccount instanceof Account) {
|
if (!$this->sourceAccount instanceof Account) {
|
||||||
$source = $this->getSourceTransaction();
|
$source = $this->getSourceTransaction();
|
||||||
$this->sourceAccount = $source->account;
|
$this->sourceAccount = $source->account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ class JournalUpdateService
|
|||||||
{
|
{
|
||||||
if (!$this->sourceTransaction instanceof Transaction) {
|
if (!$this->sourceTransaction instanceof Transaction) {
|
||||||
/** @var null|Transaction $result */
|
/** @var null|Transaction $result */
|
||||||
$result = $this->transactionJournal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
$result = $this->transactionJournal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
||||||
$this->sourceTransaction = $result;
|
$this->sourceTransaction = $result;
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('getSourceTransaction: %s', $this->sourceTransaction->amount));
|
Log::debug(sprintf('getSourceTransaction: %s', $this->sourceTransaction->amount));
|
||||||
@@ -267,27 +267,27 @@ class JournalUpdateService
|
|||||||
private function hasValidDestinationAccount(): bool
|
private function hasValidDestinationAccount(): bool
|
||||||
{
|
{
|
||||||
Log::debug('Now in hasValidDestinationAccount().');
|
Log::debug('Now in hasValidDestinationAccount().');
|
||||||
$destId = $this->data['destination_id'] ?? null;
|
$destId = $this->data['destination_id'] ?? null;
|
||||||
$destName = $this->data['destination_name'] ?? null;
|
$destName = $this->data['destination_name'] ?? null;
|
||||||
|
|
||||||
if (!$this->hasFields(['destination_id', 'destination_name'])) {
|
if (!$this->hasFields(['destination_id', 'destination_name'])) {
|
||||||
Log::debug('No destination info submitted, grab the original data.');
|
Log::debug('No destination info submitted, grab the original data.');
|
||||||
$destination = $this->getOriginalDestinationAccount();
|
$destination = $this->getOriginalDestinationAccount();
|
||||||
$destId = $destination->id;
|
$destId = $destination->id;
|
||||||
$destName = $destination->name;
|
$destName = $destination->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make new account validator.
|
// make new account validator.
|
||||||
$expectedType = $this->getExpectedType();
|
$expectedType = $this->getExpectedType();
|
||||||
Log::debug(sprintf('(b) Expected type (new or unchanged) is %s', $expectedType));
|
Log::debug(sprintf('(b) Expected type (new or unchanged) is %s', $expectedType));
|
||||||
|
|
||||||
// make a new validator.
|
// make a new validator.
|
||||||
/** @var AccountValidator $validator */
|
/** @var AccountValidator $validator */
|
||||||
$validator = app(AccountValidator::class);
|
$validator = app(AccountValidator::class);
|
||||||
$validator->setTransactionType($expectedType);
|
$validator->setTransactionType($expectedType);
|
||||||
$validator->setUser($this->transactionJournal->user);
|
$validator->setUser($this->transactionJournal->user);
|
||||||
$validator->source = $this->getValidSourceAccount();
|
$validator->source = $this->getValidSourceAccount();
|
||||||
$result = $validator->validateDestination(['id' => $destId, 'name' => $destName]);
|
$result = $validator->validateDestination(['id' => $destId, 'name' => $destName]);
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'hasValidDestinationAccount(%d, "%s") will return %s',
|
'hasValidDestinationAccount(%d, "%s") will return %s',
|
||||||
@@ -306,7 +306,7 @@ class JournalUpdateService
|
|||||||
private function getOriginalDestinationAccount(): Account
|
private function getOriginalDestinationAccount(): Account
|
||||||
{
|
{
|
||||||
if (!$this->destinationAccount instanceof Account) {
|
if (!$this->destinationAccount instanceof Account) {
|
||||||
$destination = $this->getDestinationTransaction();
|
$destination = $this->getDestinationTransaction();
|
||||||
$this->destinationAccount = $destination->account;
|
$this->destinationAccount = $destination->account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ class JournalUpdateService
|
|||||||
{
|
{
|
||||||
if (!$this->destinationTransaction instanceof Transaction) {
|
if (!$this->destinationTransaction instanceof Transaction) {
|
||||||
/** @var null|Transaction $result */
|
/** @var null|Transaction $result */
|
||||||
$result = $this->transactionJournal->transactions()->where('amount', '>', 0)->first();
|
$result = $this->transactionJournal->transactions()->where('amount', '>', 0)->first();
|
||||||
$this->destinationTransaction = $result;
|
$this->destinationTransaction = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,12 +338,12 @@ class JournalUpdateService
|
|||||||
return $this->getOriginalSourceAccount();
|
return $this->getOriginalSourceAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
$sourceInfo = [
|
$sourceInfo = [
|
||||||
'id' => (int)($this->data['source_id'] ?? null),
|
'id' => (int)($this->data['source_id'] ?? null),
|
||||||
'name' => $this->data['source_name'] ?? null,
|
'name' => $this->data['source_name'] ?? null,
|
||||||
'iban' => $this->data['source_iban'] ?? null,
|
'iban' => $this->data['source_iban'] ?? null,
|
||||||
'number' => $this->data['source_number'] ?? null,
|
'number' => $this->data['source_number'] ?? null,
|
||||||
'bic' => $this->data['source_bic'] ?? null,
|
'bic' => $this->data['source_bic'] ?? null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$expectedType = $this->getExpectedType();
|
$expectedType = $this->getExpectedType();
|
||||||
@@ -366,8 +366,8 @@ class JournalUpdateService
|
|||||||
*/
|
*/
|
||||||
private function updateAccounts(): void
|
private function updateAccounts(): void
|
||||||
{
|
{
|
||||||
$source = $this->getValidSourceAccount();
|
$source = $this->getValidSourceAccount();
|
||||||
$destination = $this->getValidDestinationAccount();
|
$destination = $this->getValidDestinationAccount();
|
||||||
|
|
||||||
// cowardly refuse to update if both accounts are the same.
|
// cowardly refuse to update if both accounts are the same.
|
||||||
if ($source->id === $destination->id) {
|
if ($source->id === $destination->id) {
|
||||||
@@ -380,7 +380,7 @@ class JournalUpdateService
|
|||||||
$origSourceTransaction->account()->associate($source);
|
$origSourceTransaction->account()->associate($source);
|
||||||
$origSourceTransaction->save();
|
$origSourceTransaction->save();
|
||||||
|
|
||||||
$destTransaction = $this->getDestinationTransaction();
|
$destTransaction = $this->getDestinationTransaction();
|
||||||
$destTransaction->account()->associate($destination);
|
$destTransaction->account()->associate($destination);
|
||||||
$destTransaction->save();
|
$destTransaction->save();
|
||||||
|
|
||||||
@@ -402,12 +402,12 @@ class JournalUpdateService
|
|||||||
return $this->getOriginalDestinationAccount();
|
return $this->getOriginalDestinationAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
$destInfo = [
|
$destInfo = [
|
||||||
'id' => (int)($this->data['destination_id'] ?? null),
|
'id' => (int)($this->data['destination_id'] ?? null),
|
||||||
'name' => $this->data['destination_name'] ?? null,
|
'name' => $this->data['destination_name'] ?? null,
|
||||||
'iban' => $this->data['destination_iban'] ?? null,
|
'iban' => $this->data['destination_iban'] ?? null,
|
||||||
'number' => $this->data['destination_number'] ?? null,
|
'number' => $this->data['destination_number'] ?? null,
|
||||||
'bic' => $this->data['destination_bic'] ?? null,
|
'bic' => $this->data['destination_bic'] ?? null,
|
||||||
];
|
];
|
||||||
|
|
||||||
// make new account validator.
|
// make new account validator.
|
||||||
@@ -431,7 +431,7 @@ class JournalUpdateService
|
|||||||
{
|
{
|
||||||
Log::debug('Now in updateType()');
|
Log::debug('Now in updateType()');
|
||||||
if ($this->hasFields(['type'])) {
|
if ($this->hasFields(['type'])) {
|
||||||
$type = 'opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type'];
|
$type = 'opening-balance' === $this->data['type'] ? 'opening balance' : $this->data['type'];
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Trying to change journal #%d from a %s to a %s.',
|
'Trying to change journal #%d from a %s to a %s.',
|
||||||
@@ -443,7 +443,7 @@ class JournalUpdateService
|
|||||||
|
|
||||||
/** @var TransactionTypeFactory $typeFactory */
|
/** @var TransactionTypeFactory $typeFactory */
|
||||||
$typeFactory = app(TransactionTypeFactory::class);
|
$typeFactory = app(TransactionTypeFactory::class);
|
||||||
$result = $typeFactory->find($this->data['type']);
|
$result = $typeFactory->find($this->data['type']);
|
||||||
if (null !== $result) {
|
if (null !== $result) {
|
||||||
Log::debug('Changed transaction type!');
|
Log::debug('Changed transaction type!');
|
||||||
$this->transactionJournal->transaction_type_id = $result->id;
|
$this->transactionJournal->transaction_type_id = $result->id;
|
||||||
@@ -464,14 +464,14 @@ class JournalUpdateService
|
|||||||
{
|
{
|
||||||
$type = $this->transactionJournal->transactionType->type;
|
$type = $this->transactionJournal->transactionType->type;
|
||||||
if ((
|
if ((
|
||||||
array_key_exists('bill_id', $this->data)
|
array_key_exists('bill_id', $this->data)
|
||||||
|| array_key_exists('bill_name', $this->data)
|
|| array_key_exists('bill_name', $this->data)
|
||||||
)
|
)
|
||||||
&& TransactionTypeEnum::WITHDRAWAL->value === $type
|
&& TransactionTypeEnum::WITHDRAWAL->value === $type
|
||||||
) {
|
) {
|
||||||
$billId = (int)($this->data['bill_id'] ?? 0);
|
$billId = (int)($this->data['bill_id'] ?? 0);
|
||||||
$billName = (string)($this->data['bill_name'] ?? '');
|
$billName = (string)($this->data['bill_name'] ?? '');
|
||||||
$bill = $this->billRepository->findBill($billId, $billName);
|
$bill = $this->billRepository->findBill($billId, $billName);
|
||||||
$this->transactionJournal->bill_id = $bill?->id;
|
$this->transactionJournal->bill_id = $bill?->id;
|
||||||
Log::debug('Updated bill ID');
|
Log::debug('Updated bill ID');
|
||||||
}
|
}
|
||||||
@@ -483,7 +483,7 @@ class JournalUpdateService
|
|||||||
private function updateField(string $fieldName): void
|
private function updateField(string $fieldName): void
|
||||||
{
|
{
|
||||||
if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) {
|
if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) {
|
||||||
$value = $this->data[$fieldName];
|
$value = $this->data[$fieldName];
|
||||||
|
|
||||||
if ('date' === $fieldName) {
|
if ('date' === $fieldName) {
|
||||||
if (!$value instanceof Carbon) {
|
if (!$value instanceof Carbon) {
|
||||||
@@ -588,10 +588,10 @@ class JournalUpdateService
|
|||||||
if ($this->hasFields([$field])) {
|
if ($this->hasFields([$field])) {
|
||||||
$value = '' === $this->data[$field] ? null : $this->data[$field];
|
$value = '' === $this->data[$field] ? null : $this->data[$field];
|
||||||
Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));
|
Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));
|
||||||
$set = [
|
$set = [
|
||||||
'journal' => $this->transactionJournal,
|
'journal' => $this->transactionJournal,
|
||||||
'name' => $field,
|
'name' => $field,
|
||||||
'data' => $value,
|
'data' => $value,
|
||||||
];
|
];
|
||||||
$factory->updateOrCreate($set);
|
$factory->updateOrCreate($set);
|
||||||
}
|
}
|
||||||
@@ -615,15 +615,15 @@ class JournalUpdateService
|
|||||||
Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));
|
Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value));
|
||||||
$set = [
|
$set = [
|
||||||
'journal' => $this->transactionJournal,
|
'journal' => $this->transactionJournal,
|
||||||
'name' => $field,
|
'name' => $field,
|
||||||
'data' => $value,
|
'data' => $value,
|
||||||
];
|
];
|
||||||
$factory->updateOrCreate($set);
|
$factory->updateOrCreate($set);
|
||||||
// also set date with timezone.
|
// also set date with timezone.
|
||||||
$set = [
|
$set = [
|
||||||
'journal' => $this->transactionJournal,
|
'journal' => $this->transactionJournal,
|
||||||
'name' => sprintf('%s_tz', $field),
|
'name' => sprintf('%s_tz', $field),
|
||||||
'data' => $value?->format('e'),
|
'data' => $value?->format('e'),
|
||||||
];
|
];
|
||||||
$factory->updateOrCreate($set);
|
$factory->updateOrCreate($set);
|
||||||
}
|
}
|
||||||
@@ -636,19 +636,19 @@ class JournalUpdateService
|
|||||||
if (!$this->hasFields(['currency_id', 'currency_code'])) {
|
if (!$this->hasFields(['currency_id', 'currency_code'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$currencyId = $this->data['currency_id'] ?? null;
|
$currencyId = $this->data['currency_id'] ?? null;
|
||||||
$currencyCode = $this->data['currency_code'] ?? null;
|
$currencyCode = $this->data['currency_code'] ?? null;
|
||||||
$currency = $this->currencyRepository->findCurrency($currencyId, $currencyCode);
|
$currency = $this->currencyRepository->findCurrency($currencyId, $currencyCode);
|
||||||
// update currency everywhere.
|
// update currency everywhere.
|
||||||
$this->transactionJournal->transaction_currency_id = $currency->id;
|
$this->transactionJournal->transaction_currency_id = $currency->id;
|
||||||
$this->transactionJournal->save();
|
$this->transactionJournal->save();
|
||||||
|
|
||||||
$source = $this->getSourceTransaction();
|
$source = $this->getSourceTransaction();
|
||||||
$source->transaction_currency_id = $currency->id;
|
$source->transaction_currency_id = $currency->id;
|
||||||
$source->save();
|
$source->save();
|
||||||
|
|
||||||
$dest = $this->getDestinationTransaction();
|
$dest = $this->getDestinationTransaction();
|
||||||
$dest->transaction_currency_id = $currency->id;
|
$dest->transaction_currency_id = $currency->id;
|
||||||
$dest->save();
|
$dest->save();
|
||||||
|
|
||||||
// refresh transactions.
|
// refresh transactions.
|
||||||
@@ -664,7 +664,7 @@ class JournalUpdateService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $this->data['amount'] ?? '';
|
$value = $this->data['amount'] ?? '';
|
||||||
Log::debug(sprintf('Amount is now "%s"', $value));
|
Log::debug(sprintf('Amount is now "%s"', $value));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -674,14 +674,14 @@ class JournalUpdateService
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$origSourceTransaction = $this->getSourceTransaction();
|
$origSourceTransaction = $this->getSourceTransaction();
|
||||||
$this->amountChanged = 0 !== bccomp($origSourceTransaction->amount, app('steam')->negative($amount));
|
$this->amountChanged = 0 !== bccomp($origSourceTransaction->amount, app('steam')->negative($amount));
|
||||||
$origSourceTransaction->amount = app('steam')->negative($amount);
|
$origSourceTransaction->amount = app('steam')->negative($amount);
|
||||||
$origSourceTransaction->balance_dirty = true;
|
$origSourceTransaction->balance_dirty = true;
|
||||||
$origSourceTransaction->save();
|
$origSourceTransaction->save();
|
||||||
$destTransaction = $this->getDestinationTransaction();
|
$destTransaction = $this->getDestinationTransaction();
|
||||||
$destTransaction->amount = app('steam')->positive($amount);
|
$destTransaction->amount = app('steam')->positive($amount);
|
||||||
$destTransaction->balance_dirty = true;
|
$destTransaction->balance_dirty = true;
|
||||||
$destTransaction->save();
|
$destTransaction->save();
|
||||||
// refresh transactions.
|
// refresh transactions.
|
||||||
$this->sourceTransaction->refresh();
|
$this->sourceTransaction->refresh();
|
||||||
@@ -696,15 +696,15 @@ class JournalUpdateService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount = $this->data['foreign_amount'] ?? null;
|
$amount = $this->data['foreign_amount'] ?? null;
|
||||||
$foreignAmount = $this->getForeignAmount($amount);
|
$foreignAmount = $this->getForeignAmount($amount);
|
||||||
$source = $this->getSourceTransaction();
|
$source = $this->getSourceTransaction();
|
||||||
$dest = $this->getDestinationTransaction();
|
$dest = $this->getDestinationTransaction();
|
||||||
$foreignCurrency = $source->foreignCurrency;
|
$foreignCurrency = $source->foreignCurrency;
|
||||||
|
|
||||||
// find currency in data array
|
// find currency in data array
|
||||||
$newForeignId = $this->data['foreign_currency_id'] ?? null;
|
$newForeignId = $this->data['foreign_currency_id'] ?? null;
|
||||||
$newForeignCode = $this->data['foreign_currency_code'] ?? null;
|
$newForeignCode = $this->data['foreign_currency_code'] ?? null;
|
||||||
$foreignCurrency = $this->currencyRepository->findCurrencyNull($newForeignId, $newForeignCode)
|
$foreignCurrency = $this->currencyRepository->findCurrencyNull($newForeignId, $newForeignCode)
|
||||||
?? $foreignCurrency;
|
?? $foreignCurrency;
|
||||||
|
|
||||||
@@ -718,26 +718,26 @@ class JournalUpdateService
|
|||||||
// add foreign currency info to source and destination if possible.
|
// add foreign currency info to source and destination if possible.
|
||||||
if (null !== $foreignCurrency && null !== $foreignAmount) {
|
if (null !== $foreignCurrency && null !== $foreignAmount) {
|
||||||
$source->foreign_currency_id = $foreignCurrency->id;
|
$source->foreign_currency_id = $foreignCurrency->id;
|
||||||
$source->foreign_amount = app('steam')->negative($foreignAmount);
|
$source->foreign_amount = app('steam')->negative($foreignAmount);
|
||||||
$source->save();
|
$source->save();
|
||||||
|
|
||||||
// if the transaction is a TRANSFER, and the foreign amount and currency are set (like they seem to be)
|
// if the transaction is a TRANSFER, and the foreign amount and currency are set (like they seem to be)
|
||||||
// the correct fields to update in the destination transaction are NOT the foreign amount and currency
|
// the correct fields to update in the destination transaction are NOT the foreign amount and currency
|
||||||
// but rather the normal amount and currency. This is new behavior.
|
// but rather the normal amount and currency. This is new behavior.
|
||||||
$isTransfer = TransactionTypeEnum::TRANSFER->value === $this->transactionJournal->transactionType->type;
|
$isTransfer = TransactionTypeEnum::TRANSFER->value === $this->transactionJournal->transactionType->type;
|
||||||
// also check if it is not between an asset account and a liability, because then the same rule applies.
|
// also check if it is not between an asset account and a liability, because then the same rule applies.
|
||||||
$isBetween = $this->isBetweenAssetAndLiability();
|
$isBetween = $this->isBetweenAssetAndLiability();
|
||||||
|
|
||||||
if ($isTransfer || $isBetween) {
|
if ($isTransfer || $isBetween) {
|
||||||
Log::debug('Switch amounts, store in amount and not foreign_amount');
|
Log::debug('Switch amounts, store in amount and not foreign_amount');
|
||||||
$dest->transaction_currency_id = $foreignCurrency->id;
|
$dest->transaction_currency_id = $foreignCurrency->id;
|
||||||
$dest->amount = app('steam')->positive($foreignAmount);
|
$dest->amount = app('steam')->positive($foreignAmount);
|
||||||
$dest->foreign_amount = app('steam')->positive($source->amount);
|
$dest->foreign_amount = app('steam')->positive($source->amount);
|
||||||
$dest->foreign_currency_id = $source->transaction_currency_id;
|
$dest->foreign_currency_id = $source->transaction_currency_id;
|
||||||
}
|
}
|
||||||
if (!$isTransfer && !$isBetween) {
|
if (!$isTransfer && !$isBetween) {
|
||||||
$dest->foreign_currency_id = $foreignCurrency->id;
|
$dest->foreign_currency_id = $foreignCurrency->id;
|
||||||
$dest->foreign_amount = app('steam')->positive($foreignAmount);
|
$dest->foreign_amount = app('steam')->positive($foreignAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dest->save();
|
$dest->save();
|
||||||
@@ -759,11 +759,11 @@ class JournalUpdateService
|
|||||||
}
|
}
|
||||||
if ('0' === $amount) {
|
if ('0' === $amount) {
|
||||||
$source->foreign_currency_id = null;
|
$source->foreign_currency_id = null;
|
||||||
$source->foreign_amount = null;
|
$source->foreign_amount = null;
|
||||||
$source->save();
|
$source->save();
|
||||||
|
|
||||||
$dest->foreign_currency_id = null;
|
$dest->foreign_currency_id = null;
|
||||||
$dest->foreign_amount = null;
|
$dest->foreign_amount = null;
|
||||||
$dest->save();
|
$dest->save();
|
||||||
Log::debug(sprintf('Foreign amount is "%s" so remove foreign amount info.', $amount));
|
Log::debug(sprintf('Foreign amount is "%s" so remove foreign amount info.', $amount));
|
||||||
}
|
}
|
||||||
@@ -777,7 +777,7 @@ class JournalUpdateService
|
|||||||
private function isBetweenAssetAndLiability(): bool
|
private function isBetweenAssetAndLiability(): bool
|
||||||
{
|
{
|
||||||
/** @var Transaction $sourceTransaction */
|
/** @var Transaction $sourceTransaction */
|
||||||
$sourceTransaction = $this->transactionJournal->transactions()->where('amount', '<', 0)->first();
|
$sourceTransaction = $this->transactionJournal->transactions()->where('amount', '<', 0)->first();
|
||||||
|
|
||||||
/** @var Transaction $destinationTransaction */
|
/** @var Transaction $destinationTransaction */
|
||||||
$destinationTransaction = $this->transactionJournal->transactions()->where('amount', '>', 0)->first();
|
$destinationTransaction = $this->transactionJournal->transactions()->where('amount', '>', 0)->first();
|
||||||
@@ -792,15 +792,15 @@ class JournalUpdateService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$source = $sourceTransaction->account;
|
$source = $sourceTransaction->account;
|
||||||
$destination = $destinationTransaction->account;
|
$destination = $destinationTransaction->account;
|
||||||
|
|
||||||
if (null === $source || null === $destination) {
|
if (null === $source || null === $destination) {
|
||||||
Log::warning('Either is false, stop.');
|
Log::warning('Either is false, stop.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$sourceTypes = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
|
$sourceTypes = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
|
||||||
|
|
||||||
// source is liability, destination is asset
|
// source is liability, destination is asset
|
||||||
if (in_array($source->accountType->type, $sourceTypes, true) && AccountTypeEnum::ASSET->value === $destination->accountType->type) {
|
if (in_array($source->accountType->type, $sourceTypes, true) && AccountTypeEnum::ASSET->value === $destination->accountType->type) {
|
||||||
@@ -822,5 +822,4 @@ class JournalUpdateService
|
|||||||
{
|
{
|
||||||
return $this->amountChanged;
|
return $this->amountChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -66,7 +66,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
|||||||
$this->locations = [];
|
$this->locations = [];
|
||||||
$this->attachmentCount = [];
|
$this->attachmentCount = [];
|
||||||
$this->dateFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date'];
|
$this->dateFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date'];
|
||||||
$this->nativeCurrency = Amount::getNativeCurrency();
|
$this->nativeCurrency = Amount::getNativeCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Override]
|
#[Override]
|
||||||
@@ -196,7 +196,7 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
|||||||
$metaData = $this->metaData;
|
$metaData = $this->metaData;
|
||||||
$locations = $this->locations;
|
$locations = $this->locations;
|
||||||
$attachmentCount = $this->attachmentCount;
|
$attachmentCount = $this->attachmentCount;
|
||||||
$nativeCurrency = $this->nativeCurrency;
|
$nativeCurrency = $this->nativeCurrency;
|
||||||
|
|
||||||
$this->collection = $this->collection->map(function (array $item) use ($nativeCurrency, $notes, $tags, $metaData, $locations, $attachmentCount) {
|
$this->collection = $this->collection->map(function (array $item) use ($nativeCurrency, $notes, $tags, $metaData, $locations, $attachmentCount) {
|
||||||
foreach ($item['transactions'] as $index => $transaction) {
|
foreach ($item['transactions'] as $index => $transaction) {
|
||||||
|
@@ -155,24 +155,24 @@ class TransactionGroupTransformer extends AbstractTransformer
|
|||||||
'native_amount' => $transaction['native_amount'] ?? null,
|
'native_amount' => $transaction['native_amount'] ?? null,
|
||||||
|
|
||||||
// native currency, always present.
|
// native currency, always present.
|
||||||
'native_currency_id' => $transaction['native_currency']['id'] ?? null,
|
'native_currency_id' => $transaction['native_currency']['id'] ?? null,
|
||||||
'native_currency_code' => $transaction['native_currency']['code'] ?? null,
|
'native_currency_code' => $transaction['native_currency']['code'] ?? null,
|
||||||
'native_currency_name' => $transaction['native_currency']['name'] ?? null,
|
'native_currency_name' => $transaction['native_currency']['name'] ?? null,
|
||||||
'native_currency_symbol' => $transaction['native_currency']['symbol'] ?? null,
|
'native_currency_symbol' => $transaction['native_currency']['symbol'] ?? null,
|
||||||
'native_currency_decimal_places' => $transaction['native_currency']['decimal_places'] ?? null,
|
'native_currency_decimal_places' => $transaction['native_currency']['decimal_places'] ?? null,
|
||||||
|
|
||||||
// source balance after
|
// source balance after
|
||||||
'source_balance_after' => $transaction['source_balance_after'] ?? null,
|
'source_balance_after' => $transaction['source_balance_after'] ?? null,
|
||||||
'source_balance_dirty' => $transaction['source_balance_dirty'],
|
'source_balance_dirty' => $transaction['source_balance_dirty'],
|
||||||
|
|
||||||
// destination balance after
|
// destination balance after
|
||||||
'destination_balance_after' => $transaction['destination_balance_after'] ?? null,
|
'destination_balance_after' => $transaction['destination_balance_after'] ?? null,
|
||||||
'destination_balance_dirty' => $transaction['destination_balance_dirty'],
|
'destination_balance_dirty' => $transaction['destination_balance_dirty'],
|
||||||
|
|
||||||
// balance before and after, if not dirty.
|
// balance before and after, if not dirty.
|
||||||
//'running_balance_dirty' => $transaction['balance_dirty'] ?? false,
|
// 'running_balance_dirty' => $transaction['balance_dirty'] ?? false,
|
||||||
//'running_balance_before' => $transaction['balance_before'] ?? null,
|
// 'running_balance_before' => $transaction['balance_before'] ?? null,
|
||||||
//'running_balance_after' => $transaction['balance_after'] ?? null,
|
// 'running_balance_after' => $transaction['balance_after'] ?? null,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
14
composer.lock
generated
14
composer.lock
generated
@@ -11670,21 +11670,21 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "rector/rector",
|
"name": "rector/rector",
|
||||||
"version": "2.0.16",
|
"version": "2.0.17",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/rectorphp/rector.git",
|
"url": "https://github.com/rectorphp/rector.git",
|
||||||
"reference": "f1366d1f8c7490541c8f7af6e5c7cef7cca1b5a2"
|
"reference": "caa4ffda1d48bde44434e6ba95d132ec32e7fd40"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/rectorphp/rector/zipball/f1366d1f8c7490541c8f7af6e5c7cef7cca1b5a2",
|
"url": "https://api.github.com/repos/rectorphp/rector/zipball/caa4ffda1d48bde44434e6ba95d132ec32e7fd40",
|
||||||
"reference": "f1366d1f8c7490541c8f7af6e5c7cef7cca1b5a2",
|
"reference": "caa4ffda1d48bde44434e6ba95d132ec32e7fd40",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.4|^8.0",
|
"php": "^7.4|^8.0",
|
||||||
"phpstan/phpstan": "^2.1.14"
|
"phpstan/phpstan": "^2.1.17"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"rector/rector-doctrine": "*",
|
"rector/rector-doctrine": "*",
|
||||||
@@ -11717,7 +11717,7 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/rectorphp/rector/issues",
|
"issues": "https://github.com/rectorphp/rector/issues",
|
||||||
"source": "https://github.com/rectorphp/rector/tree/2.0.16"
|
"source": "https://github.com/rectorphp/rector/tree/2.0.17"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -11725,7 +11725,7 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2025-05-12T16:37:16+00:00"
|
"time": "2025-05-30T10:59:08+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/cli-parser",
|
"name": "sebastian/cli-parser",
|
||||||
|
@@ -78,7 +78,7 @@ return [
|
|||||||
'running_balance_column' => env('USE_RUNNING_BALANCE', false),
|
'running_balance_column' => env('USE_RUNNING_BALANCE', false),
|
||||||
// see cer.php for exchange rates feature flag.
|
// see cer.php for exchange rates feature flag.
|
||||||
],
|
],
|
||||||
'version' => 'develop/2025-05-29',
|
'version' => 'develop/2025-05-31',
|
||||||
'api_version' => '2.1.0', // field is no longer used.
|
'api_version' => '2.1.0', // field is no longer used.
|
||||||
'db_version' => 25,
|
'db_version' => 25,
|
||||||
|
|
||||||
|
62
package-lock.json
generated
62
package-lock.json
generated
@@ -53,9 +53,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/core": {
|
"node_modules/@babel/core": {
|
||||||
"version": "7.27.3",
|
"version": "7.27.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.27.3.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.27.4.tgz",
|
||||||
"integrity": "sha512-hyrN8ivxfvJ4i0fIJuV4EOlV0WDMz5Ui4StRTgVaAvWeiRCilXgwVvxJKtFQ3TKtHgJscB2YiXKGNJuVwhQMtA==",
|
"integrity": "sha512-bXYxrXFubeYdvB0NhD/NBB3Qi6aZeV20GOWVI47t2dkecCEoneR4NPVcb7abpXDEvejgrUfFtG6vG/zxAKmg+g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -64,10 +64,10 @@
|
|||||||
"@babel/generator": "^7.27.3",
|
"@babel/generator": "^7.27.3",
|
||||||
"@babel/helper-compilation-targets": "^7.27.2",
|
"@babel/helper-compilation-targets": "^7.27.2",
|
||||||
"@babel/helper-module-transforms": "^7.27.3",
|
"@babel/helper-module-transforms": "^7.27.3",
|
||||||
"@babel/helpers": "^7.27.3",
|
"@babel/helpers": "^7.27.4",
|
||||||
"@babel/parser": "^7.27.3",
|
"@babel/parser": "^7.27.4",
|
||||||
"@babel/template": "^7.27.2",
|
"@babel/template": "^7.27.2",
|
||||||
"@babel/traverse": "^7.27.3",
|
"@babel/traverse": "^7.27.4",
|
||||||
"@babel/types": "^7.27.3",
|
"@babel/types": "^7.27.3",
|
||||||
"convert-source-map": "^2.0.0",
|
"convert-source-map": "^2.0.0",
|
||||||
"debug": "^4.1.0",
|
"debug": "^4.1.0",
|
||||||
@@ -392,9 +392,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/helpers": {
|
"node_modules/@babel/helpers": {
|
||||||
"version": "7.27.3",
|
"version": "7.27.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.27.3.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.27.4.tgz",
|
||||||
"integrity": "sha512-h/eKy9agOya1IGuLaZ9tEUgz+uIRXcbtOhRtUyyMf8JFmn1iT13vnl/IGVWSkdOCG/pC57U4S1jnAabAavTMwg==",
|
"integrity": "sha512-Y+bO6U+I7ZKaM5G5rDUZiYfUvQPUibYmAFe7EnKdnKBbVXDZxvp+MWOH5gYciY0EPk4EScsuFMQBbEfpdRKSCQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -406,9 +406,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/parser": {
|
"node_modules/@babel/parser": {
|
||||||
"version": "7.27.3",
|
"version": "7.27.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.3.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.4.tgz",
|
||||||
"integrity": "sha512-xyYxRj6+tLNDTWi0KCBcZ9V7yg3/lwL9DWh9Uwh/RIVlIfFidggcgxKX3GCXwCiswwcGRawBKbEg2LG/Y8eJhw==",
|
"integrity": "sha512-BRmLHGwpUqLFR2jzx9orBuX/ABDkj2jLKOXrHDTN2aOKL+jFDDKaRNo9nyYsIl9h/UE/7lMKdDjKQQyxKKDZ7g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1255,9 +1255,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/plugin-transform-regenerator": {
|
"node_modules/@babel/plugin-transform-regenerator": {
|
||||||
"version": "7.27.1",
|
"version": "7.27.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.27.1.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.27.4.tgz",
|
||||||
"integrity": "sha512-B19lbbL7PMrKr52BNPjCqg1IyNUIjTcxKj8uX9zHO+PmWN93s19NDr/f69mIkEp2x9nmDJ08a7lgHaTTzvW7mw==",
|
"integrity": "sha512-Glp/0n8xuj+E1588otw5rjJkTXfzW7FjH3IIUrfqiZOPQCd2vbg8e+DQE8jK9g4V5/zrxFW+D9WM9gboRPELpQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1304,9 +1304,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/plugin-transform-runtime": {
|
"node_modules/@babel/plugin-transform-runtime": {
|
||||||
"version": "7.27.3",
|
"version": "7.27.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.27.3.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.27.4.tgz",
|
||||||
"integrity": "sha512-bA9ZL5PW90YwNgGfjg6U+7Qh/k3zCEQJ06BFgAGRp/yMjw9hP9UGbGPtx3KSOkHGljEPCCxaE+PH4fUR2h1sDw==",
|
"integrity": "sha512-D68nR5zxU64EUzV8i7T3R5XP0Xhrou/amNnddsRQssx6GrTLdZl1rLxyjtVZBd+v/NVX4AbTPOB5aU8thAZV1A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1592,9 +1592,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/runtime": {
|
"node_modules/@babel/runtime": {
|
||||||
"version": "7.27.3",
|
"version": "7.27.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.27.3.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.27.4.tgz",
|
||||||
"integrity": "sha512-7EYtGezsdiDMyY80+65EzwiGmcJqpmcZCojSXaRgdrBaGtWTgDZKq69cPIVped6MkIM78cTQ2GOiEYjwOlG4xw==",
|
"integrity": "sha512-t3yaEOuGu9NlIZ+hIeGbBjFtZT7j2cb2tg0fuaJKeGotchRjjLfrBA9Kwf8quhpP1EUuxModQg04q/mBwyg8uA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.9.0"
|
"node": ">=6.9.0"
|
||||||
@@ -1616,15 +1616,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/traverse": {
|
"node_modules/@babel/traverse": {
|
||||||
"version": "7.27.3",
|
"version": "7.27.4",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.27.3.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.27.4.tgz",
|
||||||
"integrity": "sha512-lId/IfN/Ye1CIu8xG7oKBHXd2iNb2aW1ilPszzGcJug6M8RCKfVNcYhpI5+bMvFYjK7lXIM0R+a+6r8xhHp2FQ==",
|
"integrity": "sha512-oNcu2QbHqts9BtOWJosOVJapWjBDSxGCpFvikNR5TGDYDQf3JwpIoMzIKrvfoti93cLfPJEG4tH9SPVeyCGgdA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.27.1",
|
"@babel/code-frame": "^7.27.1",
|
||||||
"@babel/generator": "^7.27.3",
|
"@babel/generator": "^7.27.3",
|
||||||
"@babel/parser": "^7.27.3",
|
"@babel/parser": "^7.27.4",
|
||||||
"@babel/template": "^7.27.2",
|
"@babel/template": "^7.27.2",
|
||||||
"@babel/types": "^7.27.3",
|
"@babel/types": "^7.27.3",
|
||||||
"debug": "^4.3.1",
|
"debug": "^4.3.1",
|
||||||
@@ -3108,9 +3108,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "22.15.24",
|
"version": "22.15.29",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.24.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.29.tgz",
|
||||||
"integrity": "sha512-w9CZGm9RDjzTh/D+hFwlBJ3ziUaVw7oufKA3vOFSOZlzmW9AkZnfjPb+DLnrV6qtgL/LNmP0/2zBNCFHL3F0ng==",
|
"integrity": "sha512-LNdjOkUDlU1RZb8e1kOIUpN1qQUlzGkEtbVNo53vbrwDg5om6oduhm4SiUaPW5ASTXhAiP0jInWG8Qx9fVlOeQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -10064,9 +10064,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/sass": {
|
"node_modules/sass": {
|
||||||
"version": "1.89.0",
|
"version": "1.89.1",
|
||||||
"resolved": "https://registry.npmjs.org/sass/-/sass-1.89.0.tgz",
|
"resolved": "https://registry.npmjs.org/sass/-/sass-1.89.1.tgz",
|
||||||
"integrity": "sha512-ld+kQU8YTdGNjOLfRWBzewJpU5cwEv/h5yyqlSeJcj6Yh8U4TDA9UA5FPicqDz/xgRPWRSYIQNiFks21TbA9KQ==",
|
"integrity": "sha512-eMLLkl+qz7tx/0cJ9wI+w09GQ2zodTkcE/aVfywwdlRcI3EO19xGnbmJwg/JMIm+5MxVJ6outddLZ4Von4E++Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
Reference in New Issue
Block a user