لماذا يتضاعف التأثير المحاسبي عند استخدام totalActualValue من رأس المستند داخل مسار كيان لكل سطر؟

Viewed 1

في أحد السيناريوهات على مستند "فاتورة مشروع" (CPAProjectInvoice)، تم إعداد مسار كيان لحساب العمولة في كل سطر من سطور المستند، عن طريق نسخ قيمة n2 من المشروع الموجود في السطر إلى الحقل details.n3، ثم ضربها في الحقل totalActualValue الموجود في رأس المستند، وتخزين الناتج في details.n4:

details.n3=details.project.n2
details.n4=sql(select {details.n3} * {totalActualValue} / 100)

ثم استُخدمت قيمة details.n4 لإضافة تأثير محاسبي عبر EAAddAccountingEffect:

details.n4=DrEffect,CrEffect

النتيجة هي أن قيمة التأثير المحاسبي النهائي تخرج مضاعفة. ما سبب المشكلة وما الحل الصحيح؟

1 Answers

سبب المشكلة

القيمة في totalActualValue تمثل مجموع الحقل details.price.actualValue لجميع السطور (إجمالي الرأس). وعند ضربها في كل سطر على حدة لحساب العمولة، أدى ذلك إلى مضاعفة قيمة التأثير المحاسبي النهائي، لأنك تطبّق الإجمالي مرة واحدة على كل سطر بدلًا من تطبيق قيمة السطر الخاصة به.

الحل الصحيح

بدلًا من استخدام totalActualValue من الرأس، استخدم قيمة details.price.actualVal الخاصة بكل سطر لحساب العمولة بدقة:

details.n4=sql(select {details.n3} * {details.price.actualVal} / 100)

المسار المصحح الكامل

يمكن استيراد هذا التعريف مباشرة من قائمة "Direct Import":

{
    "targetType": "CPAProjectInvoice",
    "targetAction": "UpdateCalculatedFields",
    "details": [
        {
            "className": "com.namasoft.infor.domainbase.util.actions.EAFieldsValuesCalculator",
            "title1": "First",
            "parameter1": "details.n3=details.project.n2\ndetails.n4=sql(select {details.n3} *{details.price.actualVal}/100)",
            "targetAction": "UpdateCalculatedFields",
            "description": "Sets fields from one field to another.\nParameter 1: fields Map. Format as follows:\nwarehouse=book.ref1\nname1=code\nField Value can be another field id, \"quoted string\",sql(select max(n1) from InvItem where id <> {id})\ncustomer.runCommand=\"edit\"\ncustomer.runCommand=\"save\"\n"
        },
        {
            "className": "com.namasoft.modules.accounting.domain.utils.actions.EAAddAccountingEffect",
            "title1": "Effects: fieldId=DebitEffectAccSideCode,CreditEffectAccSideCode eg:\nn1=N1EffectDR,N1EffectCR\nlines.n2=DetailsN2EffectDR,DetailsN2EffectCR",
            "parameter1": "details.n4=DrEffect,CrEffect",
            "title2": "Apply When Query (Return 0 or 1), example:\nselect case when {lines.ref1.entityType} in ('Branch','Department') then 1 else 0 end\nThis example will make the effect happen only for lines ref1 being a branch or a department",
            "targetAction": "Automatic",
            "description": "Add Extra Effect to Any Document File existing ledger request."
        }
    ]
}

بهذا التعديل يتم احتساب التأثير المحاسبي بدقة لكل سطر على حدة دون مضاعفة.