2018-06-25 16:01:45 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AutomationHandler.php
|
2020-01-28 08:45:38 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-06-25 16:01:45 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-06-25 16:01:45 +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-25 16:01:45 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-06-25 16:01:45 +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-25 16:01:45 +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-25 16:01:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Handlers\Events;
|
|
|
|
|
|
|
|
use FireflyIII\Events\RequestedReportOnJournals;
|
2023-02-22 18:03:31 +01:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2022-09-24 07:03:03 +02:00
|
|
|
use FireflyIII\Models\TransactionGroup;
|
|
|
|
use FireflyIII\Notifications\User\TransactionCreation;
|
2018-06-25 16:01:45 +02:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2022-09-24 07:03:03 +02:00
|
|
|
use FireflyIII\Transformers\TransactionGroupTransformer;
|
2023-04-01 07:04:42 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2023-05-29 13:56:55 +02:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
2018-06-25 16:01:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AutomationHandler
|
|
|
|
*/
|
|
|
|
class AutomationHandler
|
|
|
|
{
|
|
|
|
/**
|
2018-07-07 07:48:10 +02:00
|
|
|
* Respond to the creation of X journals.
|
|
|
|
*
|
2022-12-29 19:41:57 +01:00
|
|
|
* @param RequestedReportOnJournals $event
|
2023-02-22 18:03:31 +01:00
|
|
|
* @throws FireflyException
|
2018-06-25 16:01:45 +02:00
|
|
|
*/
|
2022-09-24 07:03:03 +02:00
|
|
|
public function reportJournals(RequestedReportOnJournals $event): void
|
2018-06-25 16:01:45 +02:00
|
|
|
{
|
2022-09-24 07:03:03 +02:00
|
|
|
Log::debug('In reportJournals.');
|
2018-12-15 07:59:02 +01:00
|
|
|
$sendReport = config('firefly.send_report_journals');
|
2018-10-13 13:19:41 +02:00
|
|
|
if (false === $sendReport) {
|
2022-09-24 07:03:03 +02:00
|
|
|
return;
|
2018-10-13 13:19:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 16:01:45 +02:00
|
|
|
/** @var UserRepositoryInterface $repository */
|
|
|
|
$repository = app(UserRepositoryInterface::class);
|
2021-06-30 06:17:38 +02:00
|
|
|
$user = $repository->find($event->userId);
|
2022-09-24 07:03:03 +02:00
|
|
|
if (null === $user || 0 === $event->groups->count()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-07 07:28:43 +02:00
|
|
|
|
2022-09-24 07:03:03 +02:00
|
|
|
// transform groups into array:
|
|
|
|
/** @var TransactionGroupTransformer $transformer */
|
|
|
|
$transformer = app(TransactionGroupTransformer::class);
|
2022-12-29 19:41:57 +01:00
|
|
|
$groups = [];
|
2022-09-24 07:03:03 +02:00
|
|
|
/** @var TransactionGroup $group */
|
|
|
|
foreach ($event->groups as $group) {
|
|
|
|
$groups[] = $transformer->transformObject($group);
|
2018-06-25 16:01:45 +02:00
|
|
|
}
|
|
|
|
|
2022-09-24 07:03:03 +02:00
|
|
|
Notification::send($user, new TransactionCreation($groups));
|
2018-06-25 16:01:45 +02:00
|
|
|
}
|
2018-07-22 20:32:02 +02:00
|
|
|
}
|