mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Start work on recurring transaction enrichment.
This commit is contained in:
@@ -28,7 +28,10 @@ use FireflyIII\Api\V1\Controllers\Controller;
|
|||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Recurrence;
|
use FireflyIII\Models\Recurrence;
|
||||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
|
use FireflyIII\Support\JsonApi\Enrichments\AccountEnrichment;
|
||||||
|
use FireflyIII\Support\JsonApi\Enrichments\RecurringEnrichment;
|
||||||
use FireflyIII\Transformers\RecurrenceTransformer;
|
use FireflyIII\Transformers\RecurrenceTransformer;
|
||||||
|
use FireflyIII\User;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
@@ -76,17 +79,24 @@ class ShowController extends Controller
|
|||||||
// get list of budgets. Count it and split it.
|
// get list of budgets. Count it and split it.
|
||||||
$collection = $this->repository->get();
|
$collection = $this->repository->get();
|
||||||
$count = $collection->count();
|
$count = $collection->count();
|
||||||
$piggyBanks = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
$recurrences = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
|
|
||||||
|
// enrich
|
||||||
|
/** @var User $admin */
|
||||||
|
$admin = auth()->user();
|
||||||
|
$enrichment = new RecurringEnrichment();
|
||||||
|
$enrichment->setUser($admin);
|
||||||
|
$recurrences = $enrichment->enrich($recurrences);
|
||||||
|
|
||||||
// make paginator:
|
// make paginator:
|
||||||
$paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));
|
$paginator = new LengthAwarePaginator($recurrences, $count, $pageSize, $this->parameters->get('page'));
|
||||||
$paginator->setPath(route('api.v1.recurrences.index').$this->buildParams());
|
$paginator->setPath(route('api.v1.recurrences.index').$this->buildParams());
|
||||||
|
|
||||||
/** @var RecurrenceTransformer $transformer */
|
/** @var RecurrenceTransformer $transformer */
|
||||||
$transformer = app(RecurrenceTransformer::class);
|
$transformer = app(RecurrenceTransformer::class);
|
||||||
$transformer->setParameters($this->parameters);
|
$transformer->setParameters($this->parameters);
|
||||||
|
|
||||||
$resource = new FractalCollection($piggyBanks, $transformer, 'recurrences');
|
$resource = new FractalCollection($recurrences, $transformer, 'recurrences');
|
||||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||||
|
|
||||||
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);
|
||||||
|
199
app/Support/JsonApi/Enrichments/RecurringEnrichment.php
Normal file
199
app/Support/JsonApi/Enrichments/RecurringEnrichment.php
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Support\JsonApi\Enrichments;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Enums\RecurrenceRepetitionWeekend;
|
||||||
|
use FireflyIII\Enums\TransactionTypeEnum;
|
||||||
|
use FireflyIII\Models\Preference;
|
||||||
|
use FireflyIII\Models\Recurrence;
|
||||||
|
use FireflyIII\Models\RecurrenceRepetition;
|
||||||
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Models\UserGroup;
|
||||||
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Facades\Preferences;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class RecurringEnrichment implements EnrichmentInterface
|
||||||
|
{
|
||||||
|
private Collection $collection;
|
||||||
|
private array $ids = [];
|
||||||
|
private array $transactionTypeIds = [];
|
||||||
|
private array $transactionTypes = [];
|
||||||
|
private array $repetitions = [];
|
||||||
|
private User $user;
|
||||||
|
private UserGroup $userGroup;
|
||||||
|
private string $language = 'en_US';
|
||||||
|
|
||||||
|
public function enrich(Collection $collection): Collection
|
||||||
|
{
|
||||||
|
$this->collection = $collection;
|
||||||
|
$this->collectIds();
|
||||||
|
$this->collectRepetitions();
|
||||||
|
$this->collectTransactions();
|
||||||
|
|
||||||
|
$this->appendCollectedData();
|
||||||
|
|
||||||
|
return $this->collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enrichSingle(Model|array $model): array|Model
|
||||||
|
{
|
||||||
|
Log::debug(__METHOD__);
|
||||||
|
$collection = new Collection([$model]);
|
||||||
|
$collection = $this->enrich($collection);
|
||||||
|
|
||||||
|
return $collection->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUser(User $user): void
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
$this->setUserGroup($user->userGroup);
|
||||||
|
$this->getLanguage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUserGroup(UserGroup $userGroup): void
|
||||||
|
{
|
||||||
|
$this->userGroup = $userGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function collectIds(): void
|
||||||
|
{
|
||||||
|
/** @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;
|
||||||
|
}
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function collectRepetitions(): void
|
||||||
|
{
|
||||||
|
$repository = app(RecurringRepositoryInterface::class);
|
||||||
|
$repository->setUserGroup($this->userGroup);
|
||||||
|
$set = RecurrenceRepetition::whereIn('recurrence_id', $this->ids)->get();
|
||||||
|
/** @var RecurrenceRepetition $repetition */
|
||||||
|
foreach ($set as $repetition) {
|
||||||
|
$recurrence = $this->collection->filter(function (Recurrence $item) use ($repetition) {
|
||||||
|
return (int)$item->id === (int)$repetition->recurrence_id;
|
||||||
|
})->first();
|
||||||
|
$fromDate = $recurrence->latest_date ?? $recurrence->first_date;
|
||||||
|
$id = (int)$repetition->recurrence_id;
|
||||||
|
$repId = (int)$repetition->id;
|
||||||
|
$this->repetitions[$id] ??= [];
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
/** @var Carbon $carbon */
|
||||||
|
foreach ($set as $carbon) {
|
||||||
|
$occurrences[] = $carbon->toAtomString();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->repetitions[$id][$repId] = [
|
||||||
|
'id' => (string)$repId,
|
||||||
|
'created_at' => $repetition->created_at->toAtomString(),
|
||||||
|
'updated_at' => $repetition->updated_at->toAtomString(),
|
||||||
|
'type' => $repetition->repetition_type,
|
||||||
|
'moment' => (string)$repetition->moment,
|
||||||
|
'skip' => (int)$repetition->skip,
|
||||||
|
'weekend' => RecurrenceRepetitionWeekend::from((int)$repetition->weekend),
|
||||||
|
'description' => $this->getRepetitionDescription($repetition),
|
||||||
|
'occurrences' => $occurrences,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function collectTransactions(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private function appendCollectedData(): void
|
||||||
|
{
|
||||||
|
$this->collection = $this->collection->map(function (Recurrence $item) {
|
||||||
|
$id = (int)$item->id;
|
||||||
|
$meta = [
|
||||||
|
'repetitions' => array_values($this->repetitions[$id] ?? []),
|
||||||
|
];
|
||||||
|
|
||||||
|
$item->meta = $meta;
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the repetition in a string that is user readable.
|
||||||
|
* TODO duplicate with repository.
|
||||||
|
*/
|
||||||
|
public function getRepetitionDescription(RecurrenceRepetition $repetition): string
|
||||||
|
{
|
||||||
|
if ('daily' === $repetition->repetition_type) {
|
||||||
|
return (string)trans('firefly.recurring_daily', [], $this->language);
|
||||||
|
}
|
||||||
|
if ('weekly' === $repetition->repetition_type) {
|
||||||
|
$dayOfWeek = trans(sprintf('config.dow_%s', $repetition->repetition_moment), [], $this->language);
|
||||||
|
if ($repetition->repetition_skip > 0) {
|
||||||
|
return (string)trans('firefly.recurring_weekly_skip', ['weekday' => $dayOfWeek, 'skip' => $repetition->repetition_skip + 1], $this->language);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek], $this->language);
|
||||||
|
}
|
||||||
|
if ('monthly' === $repetition->repetition_type) {
|
||||||
|
if ($repetition->repetition_skip > 0) {
|
||||||
|
return (string)trans('firefly.recurring_monthly_skip', ['dayOfMonth' => $repetition->repetition_moment, 'skip' => $repetition->repetition_skip + 1], $this->language);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string)trans('firefly.recurring_monthly', ['dayOfMonth' => $repetition->repetition_moment, 'skip' => $repetition->repetition_skip - 1], $this->language);
|
||||||
|
}
|
||||||
|
if ('ndom' === $repetition->repetition_type) {
|
||||||
|
$parts = explode(',', $repetition->repetition_moment);
|
||||||
|
// first part is number of week, second is weekday.
|
||||||
|
$dayOfWeek = trans(sprintf('config.dow_%s', $parts[1]), [], $this->language);
|
||||||
|
if ($repetition->repetition_skip > 0) {
|
||||||
|
return (string)trans('firefly.recurring_ndom_skip', ['skip' => $repetition->repetition_skip, 'weekday' => $dayOfWeek, 'dayOfMonth' => $parts[0]], $this->language);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string)trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $parts[0]], $this->language);
|
||||||
|
}
|
||||||
|
if ('yearly' === $repetition->repetition_type) {
|
||||||
|
$today = today(config('app.timezone'))->endOfYear();
|
||||||
|
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
|
||||||
|
if (!$repDate instanceof Carbon) {
|
||||||
|
$repDate = clone $today;
|
||||||
|
}
|
||||||
|
// $diffInYears = (int)$today->diffInYears($repDate, true);
|
||||||
|
//$repDate->addYears($diffInYears); // technically not necessary.
|
||||||
|
$string = $repDate->isoFormat((string)trans('config.month_and_day_no_year_js'));
|
||||||
|
|
||||||
|
return (string)trans('firefly.recurring_yearly', ['date' => $string], $this->language);
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getLanguage(): void
|
||||||
|
{
|
||||||
|
/** @var Preference $preference */
|
||||||
|
$preference = Preferences::getForUser($this->user, 'language', config('firefly.default_language', 'en_US'));
|
||||||
|
$language = $preference->data;
|
||||||
|
if (is_array($language)) {
|
||||||
|
$language = 'en_US';
|
||||||
|
}
|
||||||
|
$language = (string)$language;
|
||||||
|
$this->language = $language;
|
||||||
|
}
|
||||||
|
}
|
@@ -60,8 +60,8 @@ class PiggyBankTransformer extends AbstractTransformer
|
|||||||
if (null !== $piggyBank->meta['target_amount'] && 0 !== bccomp($piggyBank->meta['current_amount'], '0')) { // target amount is not 0.00
|
if (null !== $piggyBank->meta['target_amount'] && 0 !== bccomp($piggyBank->meta['current_amount'], '0')) { // target amount is not 0.00
|
||||||
$percentage = (int)bcmul(bcdiv($piggyBank->meta['current_amount'], $piggyBank->meta['target_amount']), '100');
|
$percentage = (int)bcmul(bcdiv($piggyBank->meta['current_amount'], $piggyBank->meta['target_amount']), '100');
|
||||||
}
|
}
|
||||||
$startDate = $piggyBank->start_date?->format('Y-m-d');
|
$startDate = $piggyBank->start_date?->toAtomString();
|
||||||
$targetDate = $piggyBank->target_date?->format('Y-m-d');
|
$targetDate = $piggyBank->target_date?->toAtomString();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (string)$piggyBank->id,
|
'id' => (string)$piggyBank->id,
|
||||||
|
@@ -38,7 +38,6 @@ use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use function Safe\json_decode;
|
use function Safe\json_decode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,35 +74,37 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
$this->repository->setUser($recurrence->user);
|
$this->repository->setUser($recurrence->user);
|
||||||
$this->piggyRepos->setUser($recurrence->user);
|
$this->piggyRepos->setUser($recurrence->user);
|
||||||
$this->factory->setUser($recurrence->user);
|
$this->factory->setUser($recurrence->user);
|
||||||
|
|
||||||
$this->budgetRepos->setUser($recurrence->user);
|
$this->budgetRepos->setUser($recurrence->user);
|
||||||
Log::debug('Set user.');
|
Log::debug('Set user.');
|
||||||
|
|
||||||
$shortType = (string) config(sprintf('firefly.transactionTypesToShort.%s', $recurrence->transactionType->type));
|
$shortType = (string)config(sprintf('firefly.transactionTypesToShort.%s', $recurrence->transactionType->type));
|
||||||
$notes = $this->repository->getNoteText($recurrence);
|
$notes = $this->repository->getNoteText($recurrence);
|
||||||
$reps = 0 === (int) $recurrence->repetitions ? null : (int) $recurrence->repetitions;
|
$reps = 0 === (int)$recurrence->repetitions ? null : (int)$recurrence->repetitions;
|
||||||
Log::debug('Get basic data.');
|
Log::debug('Get basic data.');
|
||||||
|
|
||||||
// basic data.
|
// basic data.
|
||||||
return [
|
return [
|
||||||
'id' => (string) $recurrence->id,
|
'id' => (string)$recurrence->id,
|
||||||
'created_at' => $recurrence->created_at->toAtomString(),
|
'created_at' => $recurrence->created_at->toAtomString(),
|
||||||
'updated_at' => $recurrence->updated_at->toAtomString(),
|
'updated_at' => $recurrence->updated_at->toAtomString(),
|
||||||
'type' => $shortType,
|
'type' => $shortType,
|
||||||
'title' => $recurrence->title,
|
'title' => $recurrence->title,
|
||||||
'description' => $recurrence->description,
|
'description' => $recurrence->description,
|
||||||
'first_date' => $recurrence->first_date->format('Y-m-d'),
|
'first_date' => $recurrence->first_date->toAtomString(),
|
||||||
'latest_date' => $recurrence->latest_date?->format('Y-m-d'),
|
'latest_date' => $recurrence->latest_date?->toAtomString(),
|
||||||
'repeat_until' => $recurrence->repeat_until?->format('Y-m-d'),
|
'repeat_until' => $recurrence->repeat_until?->toAtomString(),
|
||||||
'apply_rules' => $recurrence->apply_rules,
|
'apply_rules' => $recurrence->apply_rules,
|
||||||
'active' => $recurrence->active,
|
'active' => $recurrence->active,
|
||||||
'nr_of_repetitions' => $reps,
|
'nr_of_repetitions' => $reps,
|
||||||
'notes' => '' === $notes ? null : $notes,
|
'notes' => '' === $notes ? null : $notes,
|
||||||
|
'new_repetitions' => $recurrence->meta['repetitions'],
|
||||||
'repetitions' => $this->getRepetitions($recurrence),
|
'repetitions' => $this->getRepetitions($recurrence),
|
||||||
'transactions' => $this->getTransactions($recurrence),
|
'transactions' => $this->getTransactions($recurrence),
|
||||||
'links' => [
|
'links' => [
|
||||||
[
|
[
|
||||||
'rel' => 'self',
|
'rel' => 'self',
|
||||||
'uri' => '/recurring/'.$recurrence->id,
|
'uri' => '/recurring/' . $recurrence->id,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -121,7 +122,7 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
/** @var RecurrenceRepetition $repetition */
|
/** @var RecurrenceRepetition $repetition */
|
||||||
foreach ($recurrence->recurrenceRepetitions as $repetition) {
|
foreach ($recurrence->recurrenceRepetitions as $repetition) {
|
||||||
$repetitionArray = [
|
$repetitionArray = [
|
||||||
'id' => (string) $repetition->id,
|
'id' => (string)$repetition->id,
|
||||||
'created_at' => $repetition->created_at->toAtomString(),
|
'created_at' => $repetition->created_at->toAtomString(),
|
||||||
'updated_at' => $repetition->updated_at->toAtomString(),
|
'updated_at' => $repetition->updated_at->toAtomString(),
|
||||||
'type' => $repetition->repetition_type,
|
'type' => $repetition->repetition_type,
|
||||||
@@ -168,7 +169,7 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
$foreignCurrencyDp = null;
|
$foreignCurrencyDp = null;
|
||||||
$foreignCurrencyId = null;
|
$foreignCurrencyId = null;
|
||||||
if (null !== $transaction->foreign_currency_id) {
|
if (null !== $transaction->foreign_currency_id) {
|
||||||
$foreignCurrencyId = (int) $transaction->foreign_currency_id;
|
$foreignCurrencyId = (int)$transaction->foreign_currency_id;
|
||||||
$foreignCurrencyCode = $transaction->foreignCurrency->code;
|
$foreignCurrencyCode = $transaction->foreignCurrency->code;
|
||||||
$foreignCurrencySymbol = $transaction->foreignCurrency->symbol;
|
$foreignCurrencySymbol = $transaction->foreignCurrency->symbol;
|
||||||
$foreignCurrencyDp = $transaction->foreignCurrency->decimal_places;
|
$foreignCurrencyDp = $transaction->foreignCurrency->decimal_places;
|
||||||
@@ -201,20 +202,20 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
$foreignAmount = Steam::bcround($transaction->foreign_amount, $foreignCurrencyDp);
|
$foreignAmount = Steam::bcround($transaction->foreign_amount, $foreignCurrencyDp);
|
||||||
}
|
}
|
||||||
$transactionArray = [
|
$transactionArray = [
|
||||||
'id' => (string) $transaction->id,
|
'id' => (string)$transaction->id,
|
||||||
'currency_id' => (string) $transaction->transaction_currency_id,
|
'currency_id' => (string)$transaction->transaction_currency_id,
|
||||||
'currency_code' => $transaction->transactionCurrency->code,
|
'currency_code' => $transaction->transactionCurrency->code,
|
||||||
'currency_symbol' => $transaction->transactionCurrency->symbol,
|
'currency_symbol' => $transaction->transactionCurrency->symbol,
|
||||||
'currency_decimal_places' => $transaction->transactionCurrency->decimal_places,
|
'currency_decimal_places' => $transaction->transactionCurrency->decimal_places,
|
||||||
'foreign_currency_id' => null === $foreignCurrencyId ? null : (string) $foreignCurrencyId,
|
'foreign_currency_id' => null === $foreignCurrencyId ? null : (string)$foreignCurrencyId,
|
||||||
'foreign_currency_code' => $foreignCurrencyCode,
|
'foreign_currency_code' => $foreignCurrencyCode,
|
||||||
'foreign_currency_symbol' => $foreignCurrencySymbol,
|
'foreign_currency_symbol' => $foreignCurrencySymbol,
|
||||||
'foreign_currency_decimal_places' => $foreignCurrencyDp,
|
'foreign_currency_decimal_places' => $foreignCurrencyDp,
|
||||||
'source_id' => (string) $sourceId,
|
'source_id' => (string)$sourceId,
|
||||||
'source_name' => $sourceName,
|
'source_name' => $sourceName,
|
||||||
'source_iban' => $sourceIban,
|
'source_iban' => $sourceIban,
|
||||||
'source_type' => $sourceType,
|
'source_type' => $sourceType,
|
||||||
'destination_id' => (string) $destinationId,
|
'destination_id' => (string)$destinationId,
|
||||||
'destination_name' => $destinationName,
|
'destination_name' => $destinationName,
|
||||||
'destination_iban' => $destinationIban,
|
'destination_iban' => $destinationIban,
|
||||||
'destination_type' => $destinationType,
|
'destination_type' => $destinationType,
|
||||||
@@ -259,32 +260,32 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
throw new FireflyException(sprintf('Recurrence transformer cant handle field "%s"', $transactionMeta->name));
|
throw new FireflyException(sprintf('Recurrence transformer cant handle field "%s"', $transactionMeta->name));
|
||||||
|
|
||||||
case 'bill_id':
|
case 'bill_id':
|
||||||
$bill = $this->billRepos->find((int) $transactionMeta->value);
|
$bill = $this->billRepos->find((int)$transactionMeta->value);
|
||||||
if (null !== $bill) {
|
if (null !== $bill) {
|
||||||
$array['bill_id'] = (string) $bill->id;
|
$array['bill_id'] = (string)$bill->id;
|
||||||
$array['bill_name'] = $bill->name;
|
$array['bill_name'] = $bill->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'tags':
|
case 'tags':
|
||||||
$array['tags'] = json_decode((string) $transactionMeta->value);
|
$array['tags'] = json_decode((string)$transactionMeta->value);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'piggy_bank_id':
|
case 'piggy_bank_id':
|
||||||
$piggy = $this->piggyRepos->find((int) $transactionMeta->value);
|
$piggy = $this->piggyRepos->find((int)$transactionMeta->value);
|
||||||
if (null !== $piggy) {
|
if (null !== $piggy) {
|
||||||
$array['piggy_bank_id'] = (string) $piggy->id;
|
$array['piggy_bank_id'] = (string)$piggy->id;
|
||||||
$array['piggy_bank_name'] = $piggy->name;
|
$array['piggy_bank_name'] = $piggy->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'category_id':
|
case 'category_id':
|
||||||
$category = $this->factory->findOrCreate((int) $transactionMeta->value, null);
|
$category = $this->factory->findOrCreate((int)$transactionMeta->value, null);
|
||||||
if (null !== $category) {
|
if (null !== $category) {
|
||||||
$array['category_id'] = (string) $category->id;
|
$array['category_id'] = (string)$category->id;
|
||||||
$array['category_name'] = $category->name;
|
$array['category_name'] = $category->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,16 +294,16 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
case 'category_name':
|
case 'category_name':
|
||||||
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
|
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
|
||||||
if (null !== $category) {
|
if (null !== $category) {
|
||||||
$array['category_id'] = (string) $category->id;
|
$array['category_id'] = (string)$category->id;
|
||||||
$array['category_name'] = $category->name;
|
$array['category_name'] = $category->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'budget_id':
|
case 'budget_id':
|
||||||
$budget = $this->budgetRepos->find((int) $transactionMeta->value);
|
$budget = $this->budgetRepos->find((int)$transactionMeta->value);
|
||||||
if (null !== $budget) {
|
if (null !== $budget) {
|
||||||
$array['budget_id'] = (string) $budget->id;
|
$array['budget_id'] = (string)$budget->id;
|
||||||
$array['budget_name'] = $budget->name;
|
$array['budget_name'] = $budget->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2793,6 +2793,7 @@ return [
|
|||||||
'recurring_monthly' => 'Every month on the :dayOfMonth(st/nd/rd/th) day',
|
'recurring_monthly' => 'Every month on the :dayOfMonth(st/nd/rd/th) day',
|
||||||
'recurring_monthly_skip' => 'Every :skip(st/nd/rd/th) month on the :dayOfMonth(st/nd/rd/th) day',
|
'recurring_monthly_skip' => 'Every :skip(st/nd/rd/th) month on the :dayOfMonth(st/nd/rd/th) day',
|
||||||
'recurring_ndom' => 'Every month on the :dayOfMonth(st/nd/rd/th) :weekday',
|
'recurring_ndom' => 'Every month on the :dayOfMonth(st/nd/rd/th) :weekday',
|
||||||
|
'recurring_ndom_skip' => 'Every :skip(st/nd/rd/th) month on the :dayOfMonth(st/nd/rd/th) :weekday',
|
||||||
'recurring_yearly' => 'Every year on :date',
|
'recurring_yearly' => 'Every year on :date',
|
||||||
'overview_for_recurrence' => 'Overview for recurring transaction ":title"',
|
'overview_for_recurrence' => 'Overview for recurring transaction ":title"',
|
||||||
'warning_duplicates_repetitions' => 'In rare instances, dates appear twice in this list. This can happen when multiple repetitions collide. Firefly III will always generate one transaction per day.',
|
'warning_duplicates_repetitions' => 'In rare instances, dates appear twice in this list. This can happen when multiple repetitions collide. Firefly III will always generate one transaction per day.',
|
||||||
|
Reference in New Issue
Block a user