🚀 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,8 +1,10 @@
/**
* ════════════════════════════════════════════════════════════
* مُصادَق (Musadaq) — Gemini AI Extraction Service
* مُصادَق (Musadaq) — Gemini AI Extraction Service / خدمة استخراج البيانات
* ════════════════════════════════════════════════════════════
* يقوم باستخراج البيانات من صور/ملفات الفواتير باستخدام Gemini.
* This service extracts financial data from invoice images/PDFs using Gemini AI.
* It ensures unstructured data is converted into UBL 2.1 compliant JSON.
* يقوم باستخراج البيانات المالية من صور/ملفات الفواتير باستخدام ذكاء Gemini الاصطناعي.
* يضمن تحويل البيانات غير المهيكلة إلى JSON مطابق لمعايير UBL 2.1.
* ════════════════════════════════════════════════════════════
*/
@@ -29,6 +31,7 @@ export class GeminiExtractorService {
/**
* استخراج البيانات من صورة الفاتورة (يدعم فواتير متعددة في ملف واحد)
* Extract accounting data from an invoice file (supports multiple invoices per file)
*/
async extractInvoiceData(filePath: string, storageRoot: string): Promise<any> {
try {
@@ -36,10 +39,27 @@ export class GeminiExtractorService {
const fileData = fs.readFileSync(fullPath);
const prompt = `
You are a Jordanian tax expert. Extract all details from this file (image or PDF).
The file may contain ONE or MULTIPLE distinct invoices.
Extract EACH invoice separately.
أنت الآن "مدقق ضريبي أردني خبير" (Expert Jordanian Tax Auditor).
مهمتك هي استخراج البيانات المحاسبية من هذا الملف بدقة متناهية لضمان الامتثال لنظام الفوترة الوطني (JoFotara).
قواعد الاستخراج الاستراتيجية:
1. الشخصية: تعامل مع الملف كمدقق يبحث عن أدق التفاصيل المالية والقانونية.
2. العملة: جميع المبالغ بالدينار الأردني (JOD). التزم بدقة 3 خانات عشرية (مثال: 1.250).
3. الضرائب: حدد نسب الضريبة لكل بند بناءً على القوائم المعتمدة:
- (16%): النسبة العامة (أي سلع غير مذكورة أدناه).
- (10%): حلاوة طحينة، طحينة، أجبان محضرة، أسماك محفوظة، سجق.
- (5%): عبوات الألبان والعلب المعدنية والكرتون المطبوع المخصص للتغليف.
- (4%): كرتون أطباق البيض، القرطاسية، الزي المدرسي، مدافئ الكاز والغاز، البوتاس والفوسفات.
- (2%): الملفوف، الباميا، البازلاء (طازجة أو مبردة).
- (0%): اللحوم، الأسماك، لوازم شبكات الري، آلات الزراعة، نباتات الهندباء.
- (معفى - Exempt): العدس، الشاي، الحليب، السكر، الأرز، الهواتف الخلوية، الكهرباء.
4. الأطراف: استخرج الرقم الضريبي للمورد (Supplier TIN) والرقم الضريبي أو الوطني للمشتري (Buyer TIN/National ID).
5. التصنيف:
- "simplified": إذا كان المشتري فرداً (بدون رقم ضريبي).
- "standard": إذا كان المشتري شركة أو منشأة (يوجد رقم ضريبي).
6. الفواتير المتعددة: إذا احتوى الملف على أكثر من فاتورة منفصلة، استخرج بيانات كل واحدة في عنصر مستقل في مصفوفة "invoices".
7. التجاهل: تجاهل الأختام اليدوية التي تغطي النصوص، وحاول استنتاج النص تحتها برمجياً.
The output MUST be a strict JSON object with this schema:
{
"invoices": [
@@ -47,15 +67,18 @@ export class GeminiExtractorService {
"invoice_number": "string",
"invoice_date": "YYYY-MM-DD",
"invoice_type": "cash" | "credit",
"ubl_type_code": "388" | "381",
"payment_method_code": "013" | "023",
"invoice_category": "standard" | "simplified",
"supplier_name": "string",
"supplier_tin": "string (10 digits)",
"buyer_name": "string (optional)",
"buyer_tin": "string (optional)",
"subtotal": number (before discount and tax),
"discount_total": number (total discount),
"tax_amount": number (total tax),
"grand_total": number (final amount),
"buyer_national_id": "string (10 digits, optional)",
"subtotal": number,
"discount_total": number,
"tax_amount": number,
"grand_total": number,
"currency_code": "JOD",
"lines": [
{
@@ -64,21 +87,14 @@ export class GeminiExtractorService {
"quantity": number,
"unit_price": number,
"discount": number,
"tax_rate": number (e.g. 0.16 for 16%),
"line_total": number (quantity * unit_price - discount)
"tax_rate": number (e.g. 0.16),
"line_total": number
}
]
}
]
}
JoFotara Specific Rules:
- invoice_category: "simplified" if the buyer is a regular person (no TIN), "standard" if B2B (buyer has TIN).
- Prices in Jordan (JOD) often have 3 decimal places (e.g. 2.800).
- Standard VAT Rate: 0.16 (16%)
- The formula MUST hold: Subtotal - Discount + Tax = Grand Total.
- If multiple invoices are in the PDF, ensure the "invoices" array contains all of them.
Return ONLY the JSON. No markdown formatting.
`;