Hello,
one of our customers has commissioned a surcharge that is to be calculated as a percentage of the sum of all line amounts in table 37.
The line amounts are changed in various places, e.g. by changing the quantity, the ex-factory price, etc.
This surcharge would therefore always have to be updated if the line amount was changed in any line.
Problem: I just can't find a place where this update is complete and where I can then hook in with the recalculation.
Of course, the easiest way would be to store a function call on the form, but the customer will not want that, too cumbersome, too high potential for errors.
Has anyone an idea how to solve this?
With kind regards
0
Answers
thanks for your answer.
Well, I allready gave it a try; The problem is, that the surcharge is calculated in a separate codeunit; When I call it from the updateamounts-function in table 37, the values are simply not written to the database. Putting a COMMIT in front of it would perhaps solve that issue but cause a lot of headache at a later point of time.
If you can, you should use the "Line Amount" field as a base for your surcharge.
I would suggest you calculate your surcharge on release of the document.
Even when you do not release a document manually, it will get released before any posting is done.
As an alternative, you can calculate it in the same place where the invoice discount is calculated. This has the advantage that it gets calculated even before you print the document and when calling document statistics.
Concerning doing your calculation in a different codeunit: That is no problem. You don't need a commit because of it. obviously you neeed to have INSERTed or MODIFYed the record, though. Since it runs in the context of the same transaction, you will read uncommitted values. You only need to pay attention to not using any obsolete records in the calling object. Obsolete, in this context, is you read a record into RecVar1, then you modify the same record using RecVar2, then you call RecVar1.MODIFY, without re-reading the record in RecVar1.
it seems, as if I messed up with some things. Indeed, I use the Line Amount.
There is the function UpdateAmounts in Table 37. I gave it a try, and put the call of the codeunit after it.
The function UpdateAmounts is called from serveral OnValidate-Triggers, I'm not sure where to put a MODIFY in this context.
If you want to use this trigger / function, you need to pass Rec into your function, make sure Rec is not the line containing the surcharge, process all lines, except the one you passed in, from the db, and add values from the parameter rec separately.
This is rather a messy situation. Therefore I recommend one of my other suggestions over this one.
thanks for advice. Indeed, placing the calculation on the release seems to be the best solution.