2025-08-09 07:59:38 +02:00
|
|
|
<?php
|
|
|
|
|
2025-08-09 08:04:02 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2025-08-09 07:59:38 +02:00
|
|
|
namespace FireflyIII\Notifications\User;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
|
|
|
use FireflyIII\Notifications\ReturnsSettings;
|
|
|
|
use FireflyIII\User;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
use NotificationChannels\Pushover\PushoverMessage;
|
|
|
|
|
2025-08-09 08:34:18 +02:00
|
|
|
class SubscriptionsOverdueReminder extends Notification
|
2025-08-09 07:59:38 +02:00
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
|
2025-08-09 08:38:30 +02:00
|
|
|
public function __construct(private array $overdue) {}
|
2025-08-09 07:59:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
|
|
|
|
*/
|
|
|
|
public function toArray(User $notifiable): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
|
|
|
|
*/
|
|
|
|
public function toMail(User $notifiable): MailMessage
|
|
|
|
{
|
2025-08-09 08:34:18 +02:00
|
|
|
// format the data
|
2025-08-09 08:38:30 +02:00
|
|
|
$info = [];
|
2025-08-09 08:34:18 +02:00
|
|
|
$count = 0;
|
|
|
|
foreach ($this->overdue as $item) {
|
|
|
|
$current = [
|
|
|
|
'bill' => $item['bill'],
|
|
|
|
];
|
|
|
|
$current['pay_dates'] = array_map(
|
|
|
|
static function (string $date): string {
|
|
|
|
return new Carbon($date)->isoFormat((string)trans('config.month_and_day_moment_js'));
|
2025-08-09 08:38:30 +02:00
|
|
|
},
|
|
|
|
$item['dates']['pay_dates']
|
|
|
|
);
|
2025-08-09 08:34:18 +02:00
|
|
|
$info[] = $current;
|
2025-08-09 08:38:30 +02:00
|
|
|
++$count;
|
2025-08-09 08:34:18 +02:00
|
|
|
}
|
2025-08-09 08:38:30 +02:00
|
|
|
|
2025-08-09 07:59:38 +02:00
|
|
|
return new MailMessage()
|
2025-08-09 08:38:30 +02:00
|
|
|
->markdown('emails.subscriptions-overdue-warning', ['info' => $info, 'count' => $count])
|
|
|
|
->subject($this->getSubject())
|
|
|
|
;
|
2025-08-09 07:59:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getSubject(): string
|
|
|
|
{
|
2025-08-09 08:34:18 +02:00
|
|
|
if (count($this->overdue) > 1) {
|
|
|
|
return (string)trans('email.subscriptions_overdue_subject_multi', ['count' => count($this->overdue)]);
|
|
|
|
}
|
2025-08-09 08:38:30 +02:00
|
|
|
|
2025-08-09 08:34:18 +02:00
|
|
|
return (string)trans('email.subscriptions_overdue_subject_single');
|
2025-08-09 07:59:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toNtfy(User $notifiable): Message
|
|
|
|
{
|
|
|
|
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
|
|
|
|
$message = new Message();
|
|
|
|
$message->topic($settings['ntfy_topic']);
|
|
|
|
$message->title($this->getSubject());
|
2025-08-09 08:34:18 +02:00
|
|
|
$message->body((string)trans('email.bill_warning_please_action'));
|
2025-08-09 07:59:38 +02:00
|
|
|
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
|
|
|
|
*/
|
|
|
|
public function toPushover(User $notifiable): PushoverMessage
|
|
|
|
{
|
2025-08-09 08:34:18 +02:00
|
|
|
return PushoverMessage::create((string)trans('email.bill_warning_please_action'))
|
2025-08-09 08:38:30 +02:00
|
|
|
->title($this->getSubject())
|
|
|
|
;
|
2025-08-09 07:59:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
|
|
|
|
*/
|
|
|
|
public function toSlack(User $notifiable): SlackMessage
|
|
|
|
{
|
|
|
|
$bill = $this->bill;
|
|
|
|
$url = route('bills.show', [$bill->id]);
|
|
|
|
|
|
|
|
return new SlackMessage()
|
|
|
|
->warning()
|
|
|
|
->attachment(static function ($attachment) use ($bill, $url): void {
|
2025-08-09 08:34:18 +02:00
|
|
|
$attachment->title((string)trans('firefly.visit_bill', ['name' => $bill->name]), $url);
|
2025-08-09 07:59:38 +02:00
|
|
|
})
|
2025-08-09 08:38:30 +02:00
|
|
|
->content($this->getSubject())
|
|
|
|
;
|
2025-08-09 07:59:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
|
|
|
|
*/
|
|
|
|
public function via(User $notifiable): array
|
|
|
|
{
|
|
|
|
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
|
|
|
}
|
|
|
|
}
|