🚀 Elite Accountant Hub: Foundation & Trojan Horse deployment
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { Invoice } from '../invoices/entities/invoice.entity';
|
||||
import { TaxValidationService, ValidationResult } from './tax-validation.service';
|
||||
|
||||
@Injectable()
|
||||
export class JofotaraComplianceService {
|
||||
private readonly logger = new Logger(JofotaraComplianceService.name);
|
||||
|
||||
constructor(private taxValidation: TaxValidationService) {}
|
||||
|
||||
/**
|
||||
* الفحص الشامل للامتثال لمتطلبات جو فوترة
|
||||
* Comprehensive JOFOTARA compliance check
|
||||
*/
|
||||
async checkCompliance(invoice: Invoice, credentials?: any): Promise<ValidationResult> {
|
||||
const errors: string[] = [];
|
||||
|
||||
// 1. Schema Validation (التحقق من اكتمال الحقول الإلزامية)
|
||||
this.validateSchema(invoice, errors);
|
||||
|
||||
// 2. Tax Rules Validation (التحقق من القواعد الحسابية)
|
||||
const taxResult = this.taxValidation.validateInvoice(invoice);
|
||||
if (!taxResult.isValid) {
|
||||
errors.push(...taxResult.errors);
|
||||
}
|
||||
|
||||
// 3. Credential Check (التحقق من وجود الربط مع الضريبة)
|
||||
if (credentials && (!credentials.clientId || !credentials.secretKey)) {
|
||||
errors.push('بيانات الربط مع نظام جو فوترة (Credentials) غير مكتملة لهذه الشركة');
|
||||
}
|
||||
|
||||
return {
|
||||
isValid: errors.length === 0,
|
||||
errors,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* التحقق من الحقول الإلزامية في صيغة الفاتورة
|
||||
* Rule 008: Mandatory JOFOTARA Fields
|
||||
*/
|
||||
private validateSchema(invoice: Invoice, errors: string[]) {
|
||||
if (!invoice.invoice_number) errors.push('رقم الفاتورة (Invoice Number) مطلوب');
|
||||
if (!invoice.invoice_date) errors.push('تاريخ الفاتورة (Invoice Date) مطلوب');
|
||||
if (!invoice.supplier_tin) errors.push('الرقم الضريبي للمورد (Supplier TIN) مطلوب');
|
||||
if (invoice.supplier_tin && invoice.supplier_tin.length !== 10) {
|
||||
errors.push('الرقم الضريبي للمورد يجب أن يتكون من 10 خانات');
|
||||
}
|
||||
|
||||
// Check if lines exist
|
||||
if (!invoice.lines || invoice.lines.length === 0) {
|
||||
errors.push('يجب أن تحتوي الفاتورة على بند واحد على الأقل');
|
||||
}
|
||||
|
||||
// Additional JoFotara specific checks
|
||||
if (!['388', '381'].includes(invoice.ubl_type_code)) {
|
||||
errors.push('نوع الفاتورة (UBL Type Code) غير مدعوم');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user