HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/ai.naniguide.com/app/Notifications/System/InvoiceCounterReset.php
<?php

namespace App\Notifications\System;

use App\Notifications\AppNotification;

/**
 * Invoice number counter (Setting 'invoice.current') was found at or below
 * MAX(invoices.number) and was snapped up to MAX+1. Surfaces to admins so
 * the reset is visible — root cause is usually DB restore, manual SQL, a
 * plugin inserting invoices outside the counter, or a prior save failure
 * that left the counter stuck.
 */
class InvoiceCounterReset extends AppNotification
{
    public function __construct(
        public int $from,
        public int $to,
        public int $maxExisting,
    ) {}

    public function audience(): string { return self::AUDIENCE_ADMINS; }
    public function category(): string { return self::CATEGORY_ALERT; }
    public function severity(): string { return self::SEVERITY_WARNING; }

    public function groupKey(): string { return 'invoice-counter-reset'; }

    public function toArray(object $notifiable = null): array
    {
        return [
            'title' => 'Invoice number counter reset',
            'body'  => sprintf(
                'Invoice.current value is reset from %d to %d (max existing invoice number: %d).',
                $this->from,
                $this->to,
                $this->maxExisting
            ),
            'meta' => [
                'from'         => $this->from,
                'to'           => $this->to,
                'max_existing' => $this->maxExisting,
            ],
        ];
    }
}