Surcharge over Line Amount in Table 37

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

Answers

  • KTA8KTA8 Member Posts: 388
    if you put your function to calculate that in the function updateamounts in table 37, doesn't it enough?
  • FragenFragerFragenFrager Member Posts: 52
    Hi KTA8,
    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.
  • KTA8KTA8 Member Posts: 388
    Are you sending the record to the codeunit instead of looking for it. Is this for an invoice or an order?
  • FragenFragerFragenFrager Member Posts: 52
    I'm doing a findset on a local variable of the Sales Line. The former updatet amounts are not stored in the local variable so far. As mentioned, it looks to me as if the changes are simply not written to the database.
  • KTA8KTA8 Member Posts: 388
    I would have to test it but with modify should be enough to let you see the changes of the values
  • vaprogvaprog Member Posts: 1,116
    Pay attention: there is the Amount field and the "Line Amount" field. Those are not the same. They differ for instance by the invoice discount amount contributed by the line. If you need this, you must make sure you calculate your surcharge after the Amount field has been calculated. But then, since you modify the document again, the Amount will be reacalculated ...
    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.
  • FragenFragerFragenFrager Member Posts: 52
    Hello vaprog,
    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.
  • vaprogvaprog Member Posts: 1,116
    Hi,

    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.
  • FragenFragerFragenFrager Member Posts: 52
    Hello vaprog,
    thanks for advice. Indeed, placing the calculation on the release seems to be the best solution.
Sign In or Register to comment.