Solved

Sales Invoice Amount is not calculated Correctly in acumatica

  • 20 July 2023
  • 4 replies
  • 77 views

Userlevel 3
Badge

 I had to add new field into SO303000 screen Detail Grid.

Field name - Claim Percentage

 

When the above filed is updated or entered amount need to be calculated like below formula.

 

Amount = Amount*(Claim Percentage/100)

When add the claim percentage without discount amount, It's calculations are okey.

 

In my case,After I have add the  quantity,unit price and discount amount , the Amount shows below like that.

 

Then,I added the claim percentage.

 

When I add the claim percentage, Discount Amount,Discount percentage and Amount all the fields are changed.Why this is happened and how I resolve this?

 

Below I have attached my claim p field updated event.


 

protected void ARTran_UsrClaimPercentage_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
    {
      
      var row = (ARTran)e.Row;
      ARTranExt detail = PXCache<ARTran>.GetExtension<ARTranExt>(row);

      if(detail.UsrClaimP == null || detail.UsrClaimP == 0){
        decimal? val1 =detail.UsrClaimPercentage/100;
        decimal? val = row.CuryTranAmt*val1;
        row.CuryTranAmt = val;
        detail.UsrCuryTAmt = val;
      }else{
        decimal? actualAmount = (row.CuryTranAmt*100)/detail.UsrClaimP ;
        row.CuryTranAmt = (actualAmount*detail.UsrClaimPercentage)/100;
        detail.UsrCuryTAmt=(actualAmount*detail.UsrClaimPercentage)/100;
      
      }
      
      detail.UsrClaimP = detail.UsrClaimPercentage;
     // cache.SetValueExt<ARTran.curyTranAmt>(row, val);
      
    }



 

icon

Best answer by davidnavasardyan09 12 August 2023, 16:50

View original

4 replies

Badge +11

I’d just like to point out that in this block

else{
decimal? actualAmount = (row.CuryTranAmt*100)/detail.UsrClaimP ;
row.CuryTranAmt = (actualAmount*detail.UsrClaimPercentage)/100;
detail.UsrCuryTAmt=(actualAmount*detail.UsrClaimPercentage)/100;

}

the first line can be combined with the second and third to be this, because it’s all multiplication and division, which doesn’t matter in which order you do it

row.CuryTranAmt * 100 / detail.UsrClaimP * detail.UsrClaimPercentage / 100

which is the same as this, because multiplying by 100 and then dividing by 100 is pointless

row.CuryTranAmt / detail.UsrClaimP * detail.UsrClaimPercentage

 

 

In your example, UsrClaimP and UsrClaimPercentage is the same value, which results in

row.CuryTranAmt

 

So, to me, your math seems a bit off, but maybe I’m just not understanding what situation you’d be using this for.

I do understand that this does not actually touch your original question.

Userlevel 3
Badge

Hi @darylbowman ,

When calling the else part, UsrClaimP and UsrClaimPercentage are not the same values.

UsrClaimP the old precentage value and UsrClaimPercentage is the new precentatge value,This calculation is not wrong,

Userlevel 7
Badge

Hi @jeewanishalika20 were you able to find a solution? Thank you!

Userlevel 5
Badge +1

Hello @jeewanishalika20 

The CuryTranAmt field in the ARTran DAC has multiple downstream effects because it's intrinsically linked to many calculations, especially when it comes to discounts.

When you modify CuryTranAmt, Acumatica recalculates other related fields, such as the discount amount, the discount percentage, etc., based on its in-built business logic. This is why changing the value of CuryTranAmt causes other fields to change unexpectedly.

Here's how you can approach this:

  1. Explicitly Recalculate: After updating the CuryTranAmt, you may need to manually update the fields like discount amount, etc., based on your custom logic to ensure consistency.

  2. Use Custom Fields: Instead of directly updating CuryTranAmt, consider storing the calculated value in a custom field. This way, you can show the updated value to the user without affecting other fields. This would be more of a "for display" field.

  3. Review Calculations: Ensure that the way you calculate the CuryTranAmt is consistent with how Acumatica calculates other related fields. If the built-in calculations conflict with your custom logic, it can cause unexpected values.

Looking at your FieldUpdated event, I notice you're manipulating the CuryTranAmt directly. Instead, you should consider recalculating other fields as needed after your changes or, as mentioned, use a separate field for display.

Lastly, always ensure your custom logic doesn't contradict the standard Acumatica business logic. If it does, you might need to override or extend other events to ensure consistent behavior across your customizations.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved