Deploy Ladill Frontdesk / deploy (push) Has been cancelled
Pro includes 5,000 email and 5,000 SMS host alerts per month with hard monthly caps; Enterprise is unlimited. Custom badge templates are Enterprise-only, and plan benefit copy matches the new limits.
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Frontdesk;
|
|
|
|
use App\Models\NotificationUsage;
|
|
use App\Models\Organization;
|
|
|
|
class NotificationUsageService
|
|
{
|
|
public function currentPeriod(): string
|
|
{
|
|
return now()->format('Y-m');
|
|
}
|
|
|
|
public function forOrganization(Organization $organization, ?string $period = null): NotificationUsage
|
|
{
|
|
$period ??= $this->currentPeriod();
|
|
|
|
return NotificationUsage::firstOrCreate(
|
|
['organization_id' => $organization->id, 'period' => $period],
|
|
['email_count' => 0, 'sms_count' => 0, 'email_charged_minor' => 0, 'sms_charged_minor' => 0],
|
|
);
|
|
}
|
|
|
|
public function emailCountThisMonth(Organization $organization): int
|
|
{
|
|
return (int) $this->forOrganization($organization)->email_count;
|
|
}
|
|
|
|
public function smsCountThisMonth(Organization $organization): int
|
|
{
|
|
return (int) $this->forOrganization($organization)->sms_count;
|
|
}
|
|
|
|
public function recordEmail(Organization $organization, int $chargedMinor = 0): void
|
|
{
|
|
$usage = $this->forOrganization($organization);
|
|
$usage->increment('email_count');
|
|
if ($chargedMinor > 0) {
|
|
$usage->increment('email_charged_minor', $chargedMinor);
|
|
}
|
|
}
|
|
|
|
public function recordSms(Organization $organization, int $chargedMinor = 0): void
|
|
{
|
|
$usage = $this->forOrganization($organization);
|
|
$usage->increment('sms_count');
|
|
if ($chargedMinor > 0) {
|
|
$usage->increment('sms_charged_minor', $chargedMinor);
|
|
}
|
|
}
|
|
}
|