Newbie here,
I have a boolean field added to the Sales Line table called "Allow Volume Disc.". I want some code that applies a volume discount to execute EVERY time the boolean field is true/checked on the Sales Order, and skip every record that this field is FALSE/unchecked.
Currently everything fires great, except when there is a record in the pack that is unchecked..it applies the volume discount to the unchecked record anyway.
Here's the code I have now:
IF SalesLine2."Allow Volume Disc." THEN REPEAT
CalcVolumeDiscount(Rec);
UNTIL SalesLine2.NEXT = 0;
What needs to be changed to check for unchecked records?
Thanks for any assistance in this matter. gad1
0
Answers
SalesLine2.setrange("documen type","Document type");
SalesLine2.setrange("documen No.","Document No.");
SalesLine2.setfilter("line no.",'<>%1',"Line No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(SalesLine2);
UNTIL SalesLine2.NEXT = 0;
If "Allow Volume Disc." then
CalcVolumeDiscount(Rec);
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Thanks for the tip...you say I should call your code from the on-validate...what if I'm calling the code from codeunit 414?
Will the code change?
Thanks again - gad1
For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
Rec is SalesHeader
SalesLine2.setrange("documen type","Document type");
SalesLine2.setrange("documen No.","No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(SalesLine2);
UNTIL SalesLine2.NEXT = 0;
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
RIS Plus, LLC
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
RIS Plus, LLC
I put the code in verbatim to the following. I also saw the "Rec is SalesHeader" from Rashed and understand why all of my records were calculated for a volume discount as a result...not just the 'checked' items.
I am getting the error 'The Record variable must belong to 36 and not to 37' when trying to save the changes to the Codeunit...where do I remedy this? I placed the following code in the OnRun area of Codeunit 414.
SalesLine2.setrange("document type","Document type");
SalesLine2.setrange("document No.","No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(SalesLine2);
UNTIL SalesLine2.NEXT = 0;
Once again, newbie... :roll: I'm only posting after I try to figure things out on my own and through reading the ADG.
Thanks - gad1
It does does the calculation. Can you paste that code in here?
So we can see what it's doing.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Basically you want to only calculate volume discount on lines that have the boolean checked.
To do this we have to modify the function.
So my question is do you want to include the lines in the calculation of volume discount but do not update the unit price on those sales lines?
Or just exlude them totally from the calculate?
So if you have two lines Item A qty 100, Item A qty 100. And you've setup volume discount of 150. Should the order get any volume discount if only 1st line is checked?
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
1. "calculate volume discount on lines that have the boolean checked."
Yes. BUT I just talked to a customer service person and I had a major spec incorrect. The function should SUM up all quantities for all checked items and apply the discount to only the SUM of all checked items.
So, if the boolean is checked for Item A qty 100 and checked for Item B qty 100 and NOT checked for Item C qty 100...if a volume discount is set to 150, then the discount will only be applied to Item A and B.
2. "do you want to include the lines in the calculation of volume discount"
I'd like to include the lines in the calculation and NOT change the unit price...but if this is too difficult then please just leave it. The issue with having the unit price change on release of the Sales Order comes later on the Sales Invoice report where we'd like to see the change between Net and Unit price and report a discount effectively at the lines level. Right now I can't do that.
3. "So if you have two lines Item A qty 100, Item A qty 100. And you've setup volume discount of 150. Should the order get any volume discount if only 1st line is checked?"
Since the functionality should sum up only the checked item qty (see 1.) I don't think this matters anymore. There are cases where this is now valid.
My apologies for writing a dictionary. Thanks - gad1
SalesLine2.setrange("document type","Document type");
SalesLine2.setrange("document No.","No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(Rec);
UNTIL SalesLine2.NEXT = 0;
In the function. CalcVolumeDiscount add the following line.
/update Unit Price on the lines if the Volume Discount produces a lower price.
IF TotalVolumeDiscAmount >= TotalInvoiceDiscAmount THEN BEGIN
//Mod Start
SalesLine.setrange("Allow Volume Disc.",true);
//Mod End
IF SalesLine.FINDSET(TRUE, FALSE) THEN REPEAT
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
This works awesome, thank you!!! I understand the code as well.
I will put 'solved' in the title.
If you can EASILY answer the following, ok, if not please disregard.
How do I get the original unit price BACK when I reopen the order and delete some of the sales lines and the volume discount is either less or should not be applied.
Right now if the unit price is 10.00, and the discounted price is 9.00, the price stays the same when I reopen and change quantities or delete lines. When I reopen the order I want the original unit price back (10.00) and then run the function again.
Thanks - gad1
SalesLine2.reset;
SalesLine2.setrange("documen type","Document type");
SalesLine2.setrange("documen No.","No.");
IF SalesLine2.find('-') THEN REPEAT
PriceCalcMgt.FindSalesLinePrice(Rec,SalesLine2,6);
SalesLine2.VALIDATE("Unit Price");
SalesLine2.modify;
UNTIL SalesLine2.NEXT = 0;
SalesLine2.reset;
Put that before
SalesLine2.setrange("document type","Document type");
SalesLine2.setrange("document No.","No.");
SalesLine2.setrange("Allow Volume Disc.",true);
IF SalesLine2.find('-') THEN REPEAT
CalcVolumeDiscount(Rec);
UNTIL SalesLine2.NEXT = 0;
Haven't tested it. So test it beforehand.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
=D>
Thanks - Chris
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n