Update: 2026-05-04 14:40:41
This commit is contained in:
102
app/core/AI.php
102
app/core/AI.php
@@ -20,45 +20,69 @@ class AI
|
||||
return null;
|
||||
}
|
||||
|
||||
$prompt = "You are an expert in Jordanian E-Invoicing (UBL 2.1).
|
||||
Extract all data from this invoice image/document into a JSON format.
|
||||
|
||||
CRITICAL RULES:
|
||||
1. DO NOT TRANSLATE ANY TEXT. Keep the exact original language (if Arabic, keep Arabic).
|
||||
2. ALL numbers and quantities MUST be in Latin numerals (0-9). Do not use Arabic/Indic numerals (٠-٩).
|
||||
3. Identify the Supplier TIN (Tax Identification Number) and Buyer TIN (if present).
|
||||
4. Identify if the invoice is 'Cash' or 'Credit'.
|
||||
5. Identify if it is 'Simplified' (B2C) or 'Standard' (B2B).
|
||||
6. Extract line items precisely.
|
||||
7. Return ONLY valid JSON, no markdown formatting.
|
||||
|
||||
Required JSON Structure:
|
||||
{
|
||||
\"invoice_number\": \"\",
|
||||
\"invoice_date\": \"YYYY-MM-DD\",
|
||||
\"invoice_type\": \"cash|credit\",
|
||||
\"invoice_category\": \"simplified|standard\",
|
||||
\"supplier_tin\": \"\",
|
||||
\"supplier_name\": \"\",
|
||||
\"supplier_address\": \"\",
|
||||
\"buyer_tin\": \"\",
|
||||
\"buyer_name\": \"\",
|
||||
\"buyer_national_id\": \"\",
|
||||
\"subtotal\": 0.000,
|
||||
\"tax_amount\": 0.000,
|
||||
\"discount_total\": 0.000,
|
||||
\"grand_total\": 0.000,
|
||||
\"currency\": \"JOD\",
|
||||
\"items\": [
|
||||
{
|
||||
\"description\": \"\",
|
||||
\"quantity\": 0,
|
||||
\"unit_price\": 0.000,
|
||||
\"tax_amount\": 0.000,
|
||||
\"total\": 0.000
|
||||
}
|
||||
]
|
||||
}";
|
||||
$prompt = "أنت نظام متخصص في استخلاص بيانات الفواتير التجارية. مهمتك واحدة فقط: استخراج البيانات من الفاتورة المرفقة بدقة تامة.
|
||||
|
||||
## قواعد صارمة:
|
||||
**اللغة:**
|
||||
- إذا كانت الفاتورة بالعربية: أبقِ جميع أسماء السلع والعناوين بالعربية بدون ترجمة
|
||||
- إذا كانت بالإنجليزية: أبقِها بالإنجليزية بدون ترجمة
|
||||
- الأرقام دائماً بالأرقام اللاتينية (0-9) بغض النظر عن لغة الفاتورة
|
||||
- المبالغ بـ 3 أرقام عشرية (مثال: 15.000 وليس 15)
|
||||
|
||||
**الدقة:**
|
||||
- لا تخترع أي بيانات غير موجودة في الفاتورة — أعد null إذا لم تجد المعلومة
|
||||
- تحقق رياضياً: subtotal = مجموع (quantity × unit_price - discount) لكل سطر
|
||||
- تحقق: grand_total = subtotal - discount_total + tax_amount
|
||||
- إذا وجدت تناقضاً بين الأرقام في الفاتورة، سجِّله في حقل \"validation_warnings\"
|
||||
|
||||
**الضريبة:**
|
||||
- في الأردن: ضريبة المبيعات العامة (GST) = 16% للسلع العامة
|
||||
- سلع معفاة من الضريبة: المواد الغذائية الأساسية، الأدوية، الكتب، بعض المعدات الطبية
|
||||
- سلع بضريبة مخفضة: قد تكون 4% أو 8% — استخرج النسبة الفعلية من الفاتورة
|
||||
- لكل سطر: حدد tax_rate الفعلي (0 للمعفاة، وإلا النسبة المئوية كعدد عشري مثل 0.16)
|
||||
|
||||
## البيانات المطلوبة (JSON فقط، بدون أي نص إضافي):
|
||||
|
||||
```json
|
||||
{
|
||||
\"invoice_number\": \"string | null\",
|
||||
\"invoice_date\": \"YYYY-MM-DD | null\",
|
||||
\"invoice_type\": \"cash | credit\",
|
||||
\"payment_method_code\": \"013 | 010 | 001\",
|
||||
\"supplier\": {
|
||||
\"name\": \"string | null\",
|
||||
\"tin\": \"string | null\",
|
||||
\"address\": \"string | null\"
|
||||
},
|
||||
\"buyer\": {
|
||||
\"name\": \"string | null\",
|
||||
\"tin\": \"string | null\",
|
||||
\"national_id\": \"string | null\"
|
||||
},
|
||||
\"lines\": [
|
||||
{
|
||||
\"line_number\": 1,
|
||||
\"description\": \"string\",
|
||||
\"quantity\": 0.000,
|
||||
\"unit_price\": 0.000,
|
||||
\"discount\": 0.000,
|
||||
\"tax_rate\": 0.16,
|
||||
\"tax_exempt_reason\": \"string | null\",
|
||||
\"line_total\": 0.000
|
||||
}
|
||||
],
|
||||
\"subtotal\": 0.000,
|
||||
\"discount_total\": 0.000,
|
||||
\"tax_amount\": 0.000,
|
||||
\"grand_total\": 0.000,
|
||||
\"currency_code\": \"JOD\",
|
||||
\"math_verified\": true,
|
||||
\"validation_warnings\": [],
|
||||
\"ai_confidence\": 0.95
|
||||
}
|
||||
```
|
||||
|
||||
أعد JSON فقط بدون أي شرح أو مقدمة أو علامات Markdown.";
|
||||
|
||||
$payload = [
|
||||
"contents" => [
|
||||
|
||||
Reference in New Issue
Block a user