mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-07 15:44:10 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Platform\Ai\Application\Tools;
|
|
|
|
use App\Domains\Sales\Models\Invoice;
|
|
|
|
class ListOverdueInvoicesTool extends AiTool
|
|
{
|
|
public function name(): string
|
|
{
|
|
return 'list_overdue_invoices';
|
|
}
|
|
|
|
public function description(): string
|
|
{
|
|
return 'List all invoices for the current company that are currently overdue (past their due date and unpaid or partially paid). Sorted by oldest-due-first.';
|
|
}
|
|
|
|
public function parameterSchema(): array
|
|
{
|
|
return [
|
|
'type' => 'object',
|
|
'properties' => (object) [],
|
|
'required' => [],
|
|
];
|
|
}
|
|
|
|
public function requiredAbility(): ?array
|
|
{
|
|
return ['view-invoice', Invoice::class];
|
|
}
|
|
|
|
public function execute(array $arguments, int $companyId, int $userId): mixed
|
|
{
|
|
$invoices = Invoice::query()
|
|
->where('company_id', $companyId)
|
|
->where('overdue', true)
|
|
->with('customer:id,name')
|
|
->orderBy('due_date')
|
|
->limit(100)
|
|
->get();
|
|
|
|
$totalOutstanding = (float) $invoices->sum('due_amount');
|
|
|
|
return [
|
|
'count' => $invoices->count(),
|
|
'total_outstanding' => $totalOutstanding,
|
|
'invoices' => $invoices->map(fn (Invoice $inv): array => [
|
|
'id' => $inv->id,
|
|
'invoice_number' => $inv->invoice_number,
|
|
'customer_id' => $inv->customer_id,
|
|
'customer_name' => $inv->customer?->name,
|
|
'due_date' => $this->asDate($inv->due_date),
|
|
'due_amount' => $inv->due_amount,
|
|
'total' => $inv->total,
|
|
])->all(),
|
|
];
|
|
}
|
|
}
|