mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-30 18:11:45 +00:00
Compare commits
3 Commits
a8fffc25c0
...
72fb534eb4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72fb534eb4 | ||
|
|
69b46af245 | ||
|
|
4a901a1b42 |
@@ -173,15 +173,15 @@ class EditController extends Controller
|
||||
*/
|
||||
public function update(RecurrenceFormRequest $request, Recurrence $recurrence)
|
||||
{
|
||||
$data = $request->getAll();
|
||||
$this->repository->update($recurrence, $data);
|
||||
$data = $request->getAll();
|
||||
$recurrence = $this->repository->update($recurrence, $data);
|
||||
|
||||
$request->session()->flash('success', (string) trans('firefly.updated_recurrence', ['title' => $recurrence->title]));
|
||||
Log::channel('audit')->info(sprintf('Updated recurrence #%d.', $recurrence->id), $data);
|
||||
|
||||
// store new attachment(s):
|
||||
/** @var null|array $files */
|
||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||
if (null !== $files && !auth()->user()->hasRole('demo')) {
|
||||
$this->attachments->saveAttachmentsForModel($recurrence, $files);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ class EditController extends Controller
|
||||
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
app('preferences')->mark();
|
||||
$redirect = redirect($this->getPreviousUrl('recurrences.edit.url'));
|
||||
$redirect = redirect($this->getPreviousUrl('recurrences.edit.url'));
|
||||
if (1 === (int) $request->get('return_to_edit')) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
$request->session()->put('recurrences.edit.fromUpdate', true);
|
||||
|
||||
@@ -56,23 +56,24 @@ use function Safe\json_decode;
|
||||
|
||||
class RecurringEnrichment implements EnrichmentInterface
|
||||
{
|
||||
private array $accounts = [];
|
||||
private array $accounts = [];
|
||||
private Collection $collection;
|
||||
// private array $transactionTypeIds = [];
|
||||
// private array $transactionTypes = [];
|
||||
private readonly bool $convertToPrimary;
|
||||
private array $currencies = [];
|
||||
private array $currencyIds = [];
|
||||
private array $destinationAccountIds = [];
|
||||
private array $foreignCurrencyIds = [];
|
||||
private array $ids = [];
|
||||
private string $language = 'en_US';
|
||||
private array $notes = [];
|
||||
private readonly bool $convertToPrimary;
|
||||
private array $currencies = [];
|
||||
private array $currencyIds = [];
|
||||
private array $destinationAccountIds = [];
|
||||
private array $foreignCurrencyIds = [];
|
||||
private array $ids = [];
|
||||
private string $language = 'en_US';
|
||||
private array $notes = [];
|
||||
private readonly TransactionCurrency $primaryCurrency;
|
||||
private array $recurrenceIds = [];
|
||||
private array $repetitions = [];
|
||||
private array $sourceAccountIds = [];
|
||||
private array $transactions = [];
|
||||
private array $recurrenceIds = [];
|
||||
private array $recurrenceByTransaction = [];
|
||||
private array $repetitions = [];
|
||||
private array $sourceAccountIds = [];
|
||||
private array $transactions = [];
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
|
||||
@@ -84,6 +85,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
|
||||
public function enrich(Collection $collection): Collection
|
||||
{
|
||||
Log::debug(__METHOD__);
|
||||
$this->collection = $collection;
|
||||
$this->collectIds();
|
||||
$this->collectRepetitions();
|
||||
@@ -194,6 +196,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
foreach ($accounts as $account) {
|
||||
$id = (int)$account->id;
|
||||
$this->accounts[$id] = $account;
|
||||
Log::debug(sprintf('Collected account #%d', $id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,6 +282,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
foreach ($currencies as $currency) {
|
||||
$id = (int)$currency->id;
|
||||
$this->currencies[$id] = $currency;
|
||||
Log::debug(sprintf('Collected currency #%d', $id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,18 +291,11 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
/** @var Recurrence $recurrence */
|
||||
foreach ($this->collection as $recurrence) {
|
||||
$id = (int)$recurrence->id;
|
||||
// $typeId = (int)$recurrence->transaction_type_id;
|
||||
$this->ids[] = $id;
|
||||
// $this->transactionTypeIds[$id] = $typeId;
|
||||
Log::debug(sprintf('Collected recurrence id #%d', $id));
|
||||
}
|
||||
$this->ids = array_unique($this->ids);
|
||||
|
||||
// collect transaction types.
|
||||
// $transactionTypes = TransactionType::whereIn('id', array_unique($this->transactionTypeIds))->get();
|
||||
// foreach ($transactionTypes as $transactionType) {
|
||||
// $id = (int)$transactionType->id;
|
||||
// $this->transactionTypes[$id] = TransactionTypeEnum::from($transactionType->type);
|
||||
// }
|
||||
Log::debug('Final array:', $this->ids);
|
||||
}
|
||||
|
||||
private function collectNotes(): void
|
||||
@@ -306,10 +303,12 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
$notes = Note::query()->whereIn('noteable_id', $this->ids)
|
||||
->whereNotNull('notes.text')
|
||||
->where('notes.text', '!=', '')
|
||||
->where('noteable_type', Recurrence::class)->get(['notes.noteable_id', 'notes.text'])->toArray()
|
||||
->where('noteable_type', Recurrence::class)->get(['notes.id', 'notes.noteable_id', 'notes.text'])->toArray()
|
||||
;
|
||||
foreach ($notes as $note) {
|
||||
$this->notes[(int)$note['noteable_id']] = (string)$note['text'];
|
||||
$notableId = (int)$note['noteable_id'];
|
||||
$this->notes[$notableId] = (string)$note['text'];
|
||||
Log::debug(sprintf('Collected note #%d for recurrence #%d', $note['id'], $notableId));
|
||||
}
|
||||
Log::debug(sprintf('Enrich with %d note(s)', count($this->notes)));
|
||||
}
|
||||
@@ -341,22 +340,23 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
|
||||
/** @var RecurrenceRepetition $repetition */
|
||||
foreach ($set as $repetition) {
|
||||
$recurrence = $this->collection->filter(fn (Recurrence $item): bool => (int)$item->id === (int)$repetition->recurrence_id)->first();
|
||||
$fromDate = clone ($recurrence->latest_date ?? $recurrence->first_date);
|
||||
$id = (int)$repetition->recurrence_id;
|
||||
$repId = (int)$repetition->id;
|
||||
$this->repetitions[$id] ??= [];
|
||||
$recurrence = $this->collection->filter(fn (Recurrence $item): bool => (int)$item->id === (int)$repetition->recurrence_id)->first();
|
||||
$fromDate = clone ($recurrence->latest_date ?? $recurrence->first_date);
|
||||
$recurrenceId = (int)$repetition->recurrence_id;
|
||||
$repId = (int)$repetition->id;
|
||||
$this->repetitions[$recurrenceId] ??= [];
|
||||
Log::debug(sprintf('Collected repetition #%d of recurrence #%d.', $repId, $recurrenceId));
|
||||
|
||||
// get the (future) occurrences for this specific type of repetition:
|
||||
$amount = 'daily' === $repetition->repetition_type ? 9 : 5;
|
||||
$set = $repository->getXOccurrencesSince($repetition, $fromDate, now(config('app.timezone')), $amount);
|
||||
$occurrences = [];
|
||||
$amount = 'daily' === $repetition->repetition_type ? 9 : 5;
|
||||
$set = $repository->getXOccurrencesSince($repetition, $fromDate, now(config('app.timezone')), $amount);
|
||||
$occurrences = [];
|
||||
|
||||
/** @var Carbon $carbon */
|
||||
foreach ($set as $carbon) {
|
||||
$occurrences[] = $carbon->toAtomString();
|
||||
}
|
||||
$this->repetitions[$id][$repId] = [
|
||||
$this->repetitions[$recurrenceId][$repId] = [
|
||||
'id' => (string)$repId,
|
||||
'created_at' => $repetition->created_at->toAtomString(),
|
||||
'updated_at' => $repetition->updated_at->toAtomString(),
|
||||
@@ -373,8 +373,11 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
|
||||
private function collectTransactionMetaData(): void
|
||||
{
|
||||
$ids = array_keys($this->transactions);
|
||||
$meta = RecurrenceTransactionMeta::whereNull('deleted_at')->whereIn('rt_id', $ids)->get();
|
||||
$rtIds = [];
|
||||
foreach ($this->ids as $recurrenceId) {
|
||||
$rtIds = array_merge($rtIds, array_keys($this->transactions[$recurrenceId]));
|
||||
}
|
||||
$meta = RecurrenceTransactionMeta::whereNull('deleted_at')->whereIn('rt_id', $rtIds)->get();
|
||||
// other meta-data to be collected:
|
||||
$billIds = [];
|
||||
$piggyBankIds = [];
|
||||
@@ -386,10 +389,11 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
$transactionId = (int)$entry->rt_id;
|
||||
|
||||
// this should refer to another array, were rtIds can be used to find the recurrence.
|
||||
$recurrenceId = $this->recurrenceIds[$transactionId] ?? 0;
|
||||
$recurrenceId = $this->recurrenceByTransaction[$transactionId] ?? 0;
|
||||
Log::debug(sprintf('Collecting meta data entry #%d for recurrence transaction #%d, for recurrence #%d ', $id, $transactionId, $recurrenceId));
|
||||
$name = (string)($entry->name ?? '');
|
||||
if (0 === $recurrenceId) {
|
||||
Log::error(sprintf('Could not find recurrence ID for recurrence transaction ID %d', $transactionId));
|
||||
Log::error(sprintf('Could not find recurrence ID for recurrence transaction ID #%d', $transactionId));
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -487,16 +491,16 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
|
||||
/** @var RecurrenceTransaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$id = (int)$transaction->recurrence_id;
|
||||
$transactionId = (int)$transaction->id;
|
||||
$this->recurrenceIds[$transactionId] = $id;
|
||||
$this->transactions[$id] ??= [];
|
||||
$amount = $transaction->amount;
|
||||
$foreignAmount = $transaction->foreign_amount;
|
||||
$recurrenceId = (int)$transaction->recurrence_id;
|
||||
$transactionId = (int)$transaction->id;
|
||||
$this->recurrenceByTransaction[$transactionId] = $recurrenceId;
|
||||
$this->transactions[$recurrenceId] ??= [];
|
||||
$amount = $transaction->amount;
|
||||
$foreignAmount = $transaction->foreign_amount;
|
||||
Log::debug(sprintf('Collected transaction #%d of recurrence #%d', $transactionId, $recurrenceId));
|
||||
|
||||
$this->transactions[$id][$transactionId] = [
|
||||
$this->transactions[$recurrenceId][$transactionId] = [
|
||||
'id' => (string)$transactionId,
|
||||
// 'recurrence_id' => $id,
|
||||
'transaction_currency_id' => (int)$transaction->transaction_currency_id,
|
||||
'foreign_currency_id' => null === $transaction->foreign_currency_id ? null : (int)$transaction->foreign_currency_id,
|
||||
'source_id' => (int)$transaction->source_id,
|
||||
@@ -518,10 +522,10 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
'subscription_name' => null,
|
||||
|
||||
];
|
||||
// collect all kinds of meta data to be collected later.
|
||||
$this->currencyIds[$transactionId] = (int)$transaction->transaction_currency_id;
|
||||
$this->sourceAccountIds[$transactionId] = (int)$transaction->source_id;
|
||||
$this->destinationAccountIds[$transactionId] = (int)$transaction->destination_id;
|
||||
// collect all kinds of meta-data to be collected later.
|
||||
$this->currencyIds[$transactionId] = (int)$transaction->transaction_currency_id;
|
||||
$this->sourceAccountIds[$transactionId] = (int)$transaction->source_id;
|
||||
$this->destinationAccountIds[$transactionId] = (int)$transaction->destination_id;
|
||||
if (null !== $transaction->foreign_currency_id) {
|
||||
$this->foreignCurrencyIds[$transactionId] = (int)$transaction->foreign_currency_id;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ return [
|
||||
// see cer.php for exchange rates feature flag.
|
||||
],
|
||||
'version' => 'develop/2025-11-17',
|
||||
'build_time' => 1763350067,
|
||||
'build_time' => 1763402780,
|
||||
'api_version' => '2.1.0', // field is no longer used.
|
||||
'db_version' => 28, // field is no longer used.
|
||||
|
||||
|
||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -4075,9 +4075,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/baseline-browser-mapping": {
|
||||
"version": "2.8.28",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.28.tgz",
|
||||
"integrity": "sha512-gYjt7OIqdM0PcttNYP2aVrr2G0bMALkBaoehD4BuRGjAOtipg0b6wHg1yNL+s5zSnLZZrGHOw4IrND8CD+3oIQ==",
|
||||
"version": "2.8.29",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.29.tgz",
|
||||
"integrity": "sha512-sXdt2elaVnhpDNRDz+1BDx1JQoJRuNk7oVlAlbGiFkLikHCAQiccexF/9e91zVi6RCgqspl04aP+6Cnl9zRLrA==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
@@ -5365,9 +5365,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/csstype": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.2.tgz",
|
||||
"integrity": "sha512-D80T+tiqkd/8B0xNlbstWDG4x6aqVfO52+OlSUNIdkTvmNw0uQpJLeos2J/2XvpyidAFuTPmpad+tUxLndwj6g==",
|
||||
"version": "3.2.3",
|
||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
||||
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
@@ -6443,9 +6443,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||
"version": "4.0.5",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz",
|
||||
"integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
Reference in New Issue
Block a user