🚀 Elite Accountant Hub: Foundation & Trojan Horse deployment

This commit is contained in:
Hamza-Ayed
2026-04-22 01:05:25 +03:00
parent 2e2d76c0a8
commit 444097814d
23 changed files with 796 additions and 88 deletions

View File

@@ -1,9 +1,11 @@
/**
* ════════════════════════════════════════════════════════════
* مُصادَق (Musadaq) — Invoice Processor (Queue Consumer)
* مُصادَق (Musadaq) — Invoice Processor (Queue Consumer) / معالج الفواتير
* ════════════════════════════════════════════════════════════
* This is the main consumer for the invoice processing queue (Bull).
* It orchestrates AI extraction, tax validation, and database storage.
* المستهلك الرئيسي لطابور معالجة الفواتير (Bull Queue).
* يربط بين الذكاء الاصطناعي، التحقق الضريبي، وتوليد الـ XML.
* يقوم بالتنسيق بين استخراج البيانات بالذكاء الاصطناعي، التحقق الضريبي، وحفظ البيانات.
* ════════════════════════════════════════════════════════════
*/
@@ -50,6 +52,7 @@ export class InvoiceProcessor {
/**
* الخطوة الأولى: استخراج البيانات باستخدام AI
* Step 1: Extract data from the file using Gemini Multimodal AI
*/
@Process('extract-data')
async handleExtraction(job: Job<{ invoiceId: string; filePath: string; tenantId: string; companyId: string }>) {
@@ -97,6 +100,7 @@ export class InvoiceProcessor {
/**
* حفظ البيانات المستخرجة في قاعدة البيانات
* Save the JSON data extracted by AI into the SQL database
*/
private async saveExtractedData(invoiceId: string, data: any) {
const queryRunner = this.dataSource.createQueryRunner();
@@ -109,11 +113,14 @@ export class InvoiceProcessor {
invoice_number: data.invoice_number,
invoice_date: data.invoice_date,
invoice_type: data.invoice_type || 'cash',
ubl_type_code: data.ubl_type_code || '388',
payment_method_code: data.payment_method_code || '013',
invoice_category: data.invoice_category || 'simplified',
supplier_name: data.supplier_name,
supplier_tin: data.supplier_tin,
buyer_name: data.buyer_name,
buyer_tin: data.buyer_tin,
buyer_national_id: data.buyer_national_id,
subtotal: data.subtotal,
discount_total: data.discount_total,
tax_amount: data.tax_amount,
@@ -157,6 +164,7 @@ export class InvoiceProcessor {
/**
* الخطوة الثانية: التحقق الضريبي التلقائي
* Step 2: Perform automatic tax rules validation (ISTD Standards)
*/
private async autoValidate(invoiceId: string) {
const invoice = await this.invoiceRepository.findOne({