2018-06-10 16:59:03 +02:00
|
|
|
<?php
|
2024-11-25 04:18:55 +01:00
|
|
|
|
2018-06-10 16:59:03 +02:00
|
|
|
/**
|
2019-10-02 06:37:26 +02:00
|
|
|
* RecurrenceTransformer.php
|
2020-02-16 13:57:18 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-06-10 16:59:03 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-06-10 16:59:03 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-06-10 16:59:03 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-06-10 16:59:03 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-06-10 16:59:03 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-06-10 16:59:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Transformers;
|
2021-07-18 14:51:30 +02:00
|
|
|
|
2018-06-10 16:59:03 +02:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
|
|
|
use FireflyIII\Factory\CategoryFactory;
|
2023-11-05 16:55:16 +01:00
|
|
|
use FireflyIII\Models\Account;
|
2018-06-10 16:59:03 +02:00
|
|
|
use FireflyIII\Models\Recurrence;
|
|
|
|
use FireflyIII\Models\RecurrenceRepetition;
|
|
|
|
use FireflyIII\Models\RecurrenceTransaction;
|
|
|
|
use FireflyIII\Models\RecurrenceTransactionMeta;
|
2021-07-18 14:51:30 +02:00
|
|
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
2018-06-10 16:59:03 +02:00
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
2025-08-05 13:40:46 +02:00
|
|
|
use FireflyIII\Support\Facades\Steam;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2025-05-27 17:06:15 +02:00
|
|
|
use function Safe\json_decode;
|
|
|
|
|
2018-06-10 16:59:03 +02:00
|
|
|
/**
|
|
|
|
* Class RecurringTransactionTransformer
|
|
|
|
*/
|
2018-12-15 22:03:42 +01:00
|
|
|
class RecurrenceTransformer extends AbstractTransformer
|
2018-06-10 16:59:03 +02:00
|
|
|
{
|
|
|
|
|
2018-07-18 07:28:35 +02:00
|
|
|
/**
|
|
|
|
* RecurrenceTransformer constructor.
|
|
|
|
*/
|
2018-12-15 22:03:42 +01:00
|
|
|
public function __construct()
|
2018-06-10 16:59:03 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-18 07:28:35 +02:00
|
|
|
* Transform the recurring transaction.
|
2018-06-10 16:59:03 +02:00
|
|
|
*
|
|
|
|
* @throws FireflyException
|
|
|
|
*/
|
|
|
|
public function transform(Recurrence $recurrence): array
|
|
|
|
{
|
2025-08-05 13:40:46 +02:00
|
|
|
Log::debug('Now in Recurrence::transform()');
|
2018-12-20 20:50:05 +01:00
|
|
|
|
2025-08-06 10:46:23 +02:00
|
|
|
$shortType = (string)config(sprintf('firefly.transactionTypesToShort.%s', $recurrence->transactionType->type));
|
|
|
|
$reps = 0 === (int)$recurrence->repetitions ? null : (int)$recurrence->repetitions;
|
2025-08-05 13:40:46 +02:00
|
|
|
Log::debug('Get basic data.');
|
2021-03-06 16:15:39 +01:00
|
|
|
|
2018-07-18 07:28:35 +02:00
|
|
|
// basic data.
|
2020-10-23 19:11:25 +02:00
|
|
|
return [
|
2025-08-06 10:46:23 +02:00
|
|
|
'id' => (string)$recurrence->id,
|
2019-08-25 16:15:02 +02:00
|
|
|
'created_at' => $recurrence->created_at->toAtomString(),
|
|
|
|
'updated_at' => $recurrence->updated_at->toAtomString(),
|
|
|
|
'type' => $shortType,
|
|
|
|
'title' => $recurrence->title,
|
|
|
|
'description' => $recurrence->description,
|
2025-08-06 10:46:23 +02:00
|
|
|
'first_date' => $recurrence->first_date->toAtomString(),
|
|
|
|
'latest_date' => $recurrence->latest_date?->toAtomString(),
|
|
|
|
'repeat_until' => $recurrence->repeat_until?->toAtomString(),
|
2019-08-25 16:15:02 +02:00
|
|
|
'apply_rules' => $recurrence->apply_rules,
|
|
|
|
'active' => $recurrence->active,
|
2019-09-04 21:06:01 +02:00
|
|
|
'nr_of_repetitions' => $reps,
|
2025-08-06 15:35:29 +02:00
|
|
|
'notes' => $recurrence->meta['notes'],
|
|
|
|
'repetitions' => $recurrence->meta['repetitions'],
|
|
|
|
'new_transactions' => $recurrence->meta['transactions'],
|
2019-08-25 16:15:02 +02:00
|
|
|
'links' => [
|
2018-06-10 16:59:03 +02:00
|
|
|
[
|
|
|
|
'rel' => 'self',
|
2025-08-06 10:46:23 +02:00
|
|
|
'uri' => '/recurring/' . $recurrence->id,
|
2018-06-10 16:59:03 +02:00
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
2018-07-18 07:28:35 +02:00
|
|
|
}
|
2018-07-22 20:32:02 +02:00
|
|
|
}
|