<?php
 namespace App\Services\Billing; use App\Models\Invoice; use App\Models\Log; use App\Models\Setting; class AccountingExclusionGuard { public function excludes(Invoice $invoice): bool { if ($invoice->accounting_excluded) { return true; } if ((float) $invoice->total_amount === 0.0 && Setting::getValue('exclude_zero_total_from_einvoice', true)) { $invoice->newQuery()->whereKey($invoice->getKey()) ->update(['accounting_excluded' => true]); $invoice->setAttribute('accounting_excluded', true) ->syncOriginalAttribute('accounting_excluded'); Log::create([ 'type' => Log::TYPE_SYSTEM, 'observer' => 'AccountingExclusionGuard', 'module' => 'Invoice', 'method' => 'accounting_excluded_auto', 'ip_address' => (string) (request()?->ip() ?? ''), 'client_id' => $invoice->client_id, 'description' => "Invoice #{$invoice->invoice_number} muhasebe-dışı işaretlendi (0.00 tutar, otomatik) — resmi e-fatura sevki atlandı", ]); return true; } return false; } } 