🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 03:15

This commit is contained in:
Hamza-Ayed
2026-05-03 03:15:18 +03:00
parent 392f6dbd9b
commit cf68007ef1
6 changed files with 90 additions and 27 deletions

View File

@@ -20,7 +20,20 @@ final class InvoiceController
public function list(Request $request): void
{
$invoices = $this->invoiceModel->findByTenant($request->tenantId);
$tenantId = $request->tenantId;
$role = $request->user->role ?? 'viewer';
$assignedCompanyId = $request->user->assigned_company_id ?? null;
if ($role === 'super_admin') {
$invoices = $this->invoiceModel->findByTenant($tenantId);
} else {
// Filter by assigned company for admin, accountant, etc.
$db = \App\Core\Database::getInstance();
$stmt = $db->prepare("SELECT * FROM invoices WHERE tenant_id = ? AND company_id = ? AND deleted_at IS NULL ORDER BY created_at DESC");
$stmt->execute([$tenantId, $assignedCompanyId]);
$invoices = $stmt->fetchAll();
}
Response::json([
'success' => true,
'data' => $invoices
@@ -50,11 +63,10 @@ final class InvoiceController
$invoiceId = \Ramsey\Uuid\Uuid::uuid4()->toString();
$this->invoiceModel->create([
'id' => $invoiceId,
'invoice_uuid' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
'tenant_id' => $tenantId,
'company_id' => $companyId,
'uploaded_by' => $request->user->user_id,
'status' => 'PROCESSING',
'status' => 'uploaded', // Match schema ENUM
'original_file_path' => $filePath,
'original_file_hash' => $fileHash,
'idempotency_key' => bin2hex(random_bytes(16))
@@ -67,8 +79,8 @@ final class InvoiceController
// Update Invoice with extracted data
$this->invoiceModel->update($invoiceId, [
'status' => 'EXTRACTED',
'extracted_data' => json_encode($extractedData, JSON_UNESCAPED_UNICODE)
'status' => 'extracted', // Match schema ENUM
'ai_raw_response' => json_encode($extractedData, JSON_UNESCAPED_UNICODE)
]);
Response::json([
@@ -83,7 +95,7 @@ final class InvoiceController
} catch (Throwable $aiError) {
// Keep it uploaded, maybe manual retry later
$this->invoiceModel->update($invoiceId, [
'status' => 'AI_FAILED'
'status' => 'validation_failed' // Match schema fallback
]);
Response::json([