2022-03-28 12:23:46 +02:00
|
|
|
<?php
|
|
|
|
|
2022-03-29 14:55:51 +02:00
|
|
|
/*
|
|
|
|
* BillEventHandler.php
|
|
|
|
* Copyright (c) 2022 james@firefly-iii.org
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-03-28 12:23:46 +02:00
|
|
|
namespace FireflyIII\Handlers\Events;
|
|
|
|
|
|
|
|
use FireflyIII\Events\WarnUserAboutBill;
|
2022-09-23 06:05:22 +02:00
|
|
|
use FireflyIII\Notifications\User\BillReminder;
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
2025-05-27 16:57:36 +02:00
|
|
|
use Exception;
|
2022-03-28 12:23:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BillEventHandler
|
|
|
|
*/
|
|
|
|
class BillEventHandler
|
|
|
|
{
|
|
|
|
public function warnAboutBill(WarnUserAboutBill $event): void
|
|
|
|
{
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
2022-03-28 12:23:46 +02:00
|
|
|
|
2024-01-01 14:43:56 +01:00
|
|
|
$bill = $event->bill;
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-01-03 06:48:53 +01:00
|
|
|
/** @var bool $preference */
|
2023-10-29 06:22:57 +01:00
|
|
|
$preference = app('preferences')->getForUser($bill->user, 'notification_bill_reminder', true)->data;
|
2022-03-28 12:23:46 +02:00
|
|
|
|
2022-09-23 06:05:22 +02:00
|
|
|
if (true === $preference) {
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug('Bill reminder is true!');
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-11 16:12:13 +02:00
|
|
|
try {
|
|
|
|
Notification::send($bill->user, new BillReminder($bill, $event->field, $event->diff));
|
2025-05-27 16:57:36 +02:00
|
|
|
} catch (Exception $e) {
|
2023-06-11 16:12:13 +02:00
|
|
|
$message = $e->getMessage();
|
|
|
|
if (str_contains($message, 'Bcc')) {
|
2023-10-29 06:31:13 +01:00
|
|
|
app('log')->warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-11 16:12:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (str_contains($message, 'RFC 2822')) {
|
2023-10-29 06:31:13 +01:00
|
|
|
app('log')->warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-11 16:12:13 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-10-29 06:32:00 +01:00
|
|
|
app('log')->error($e->getMessage());
|
|
|
|
app('log')->error($e->getTraceAsString());
|
2023-06-11 16:12:13 +02:00
|
|
|
}
|
2022-09-23 06:05:22 +02:00
|
|
|
}
|
|
|
|
if (false === $preference) {
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug('User has disabled bill reminders.');
|
2022-09-23 06:05:22 +02:00
|
|
|
}
|
2022-03-28 12:23:46 +02:00
|
|
|
}
|
2022-03-29 14:55:51 +02:00
|
|
|
}
|