Check shipment date on Sales Price

vnproc
Member Posts: 41
Hi Everybody
I want check shipment date on table Sales Line compare Starting Date and Ending Date on table Sales Price.
I write code but it not work. (code i write in codeunit warehouse shipment)
I want check shipment date on table Sales Line compare Starting Date and Ending Date on table Sales Price.
I write code but it not work. (code i write in codeunit warehouse shipment)
SalesLine.SETFILTER("Document Type",'%1',SalesLine."Document Type"::Order); SalesLine.SETRANGE(SalesLine."No.",WhseShipLine."Item No."); SalesLine.SETRANGE("Document No.",WhseShipLine."Source No."); IF SalesLine.FINDSET THEN SalesPrice.RESET; SalesPrice.SETRANGE(SalesPrice."Item No.",SalesLine."No."); SalesPrice.SETRANGE(SalesPrice."Sales Code",SalesLine."Customer Price Group"); SalesPrice.SETFILTER(SalesPrice."Sales Type",'%1',SalesPrice."Sales Type"::"Customer Price Group"); IF SalesPrice.FINDFIRST THEN BEGIN SalesPriceload.COPYFILTERS(SalesPrice); SalesPriceload.FINDFIRST; REPEAT IF (SalesPriceload.NEXT = 0) THEN BEGIN CLEAR(SalesPriceload); IF (SalesPrice."Ending Date" <> 0D) THEN BEGIN IF (SalesLine."Shipment Date" >SalesPrice."Starting Date") AND (SalesLine."Shipment Date" > SalesPrice."Ending Date") THEN ERROR('Sales price of Item no %1 on Order : %2 expired.',SalesPrice."Item No.",SalesLine."Document No."); END; END; UNTIL SalesPrice.NEXT=0; END;Please help me. Thanks so much.
0
Comments
-
In my opinion it would be be better to move this to its own function, passing the Sales Line as a parameter.
CheckSalesPriceExpiry(SalesLine)
Then you can do something like this:SalesPrice.SETRANGE("Item No.",SalesLine."No."); SalesPrice.SETRANGE("Sales Code",SalesLine."Customer Price Group"); SalesPrice.SETRANGE("Sales Type", SalesPrice."Sales Type"::"Customer Price Group"); SalesPrice.SETFILTER("Starting Date", '%1..' , "SalesLine"."Shipment Date"); SalesPrice.SETFILTER("Ending Date", '..%1' , "SalesLine"."Shipment Date"); IF SalesPrice.ISEMPTY THEN ERROR('Could not find valid Sales Price for Item No %1, for Shipment Date %2, "SalesPrice"."Item No.", "SalesLine"."Shipment Date");
1 -
Thank robbonick
Im write codeCheckSalesPriceExpiry(SalesLine : Record "Sales Line") SalesPrice.SETRANGE("Item No.",SalesLine."No."); SalesPrice.SETRANGE("Sales Code",SalesLine."Customer Price Group"); SalesPrice.SETRANGE("Sales Type", SalesPrice."Sales Type"::"Customer Price Group"); SalesPrice.SETFILTER("Starting Date", '%1..' , "SalesLine"."Shipment Date"); SalesPrice.SETFILTER("Ending Date", '..%1' , "SalesLine"."Shipment Date"); IF SalesPrice.ISEMPTY THEN ERROR('Could not find valid Sales Price for Item No %1,for Shipment Date %2', "SalesPrice"."Item No.", "SalesLine"."Shipment Date");
And call procedureSalesLine.SETRANGE("Document No.",WhseShipLine."Source No."); CheckSalesPriceExpiry(SalesLine);
But it not work. Please help me
Thanks so much0 -
Thank robbonick
Im write codeCheckSalesPriceExpiry(SalesLine : Record "Sales Line") SalesPrice.SETRANGE("Item No.",SalesLine."No."); SalesPrice.SETRANGE("Sales Code",SalesLine."Customer Price Group"); SalesPrice.SETRANGE("Sales Type", SalesPrice."Sales Type"::"Customer Price Group"); SalesPrice.SETFILTER("Starting Date", '%1..' , "SalesLine"."Shipment Date"); SalesPrice.SETFILTER("Ending Date", '..%1' , "SalesLine"."Shipment Date"); IF SalesPrice.ISEMPTY THEN ERROR('Could not find valid Sales Price for Item No %1,for Shipment Date %2', "SalesPrice"."Item No.", "SalesLine"."Shipment Date");
And call procedureSalesLine.SETRANGE("Document No.",WhseShipLine."Source No."); CheckSalesPriceExpiry(SalesLine);
But it not work. Please help me
Thanks so much
Where does the code fail? Are you expecting it to error?
Run the debugger and check the values of each variable, for instance check if the Sales Line is correctly passed to the function. There might be something not quite right with the filtering.1 -
Thanks robbonick.
After I debug then result
Item Code := blank
"Sales Code" := Customer (No filter "Customer Price Group")
0 -
You need to ensure you are passing the right Sales Line to the function, one where the field "No." is not blank.
Also, change the Error text, if you can't find a valid Sales Price, then the variable "Sales Price" will be empty, so the field Sales Price."Starting Date" & SalesPrice."Ending Date" will be blank. So they are not useful for your error message.1 -
I would rethink the orignal requirement.
The price is (usually) binding at the time when customer places an order, not at the point in time when goods are leaving the warehouse.
Think abount following scenario - a customer ordered Item A on Day 1 and the sales price on his ordrr confirmation is X.
You don't have the item available in the system, YOUR order to the vendor is delayed, and item is received in your warehouse and ready to ship after the price expiry date. What would you do? Don't ship but contact customer telling him that they need to pay extra because YOUR delivery has been delayed?
I'd think it is illegal to force customer to pay different price than they knew when they placed the order. Therefore checking sales prices at the time of shipping does not make sense.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions