How to do the following calculation

DarkHorse
Member Posts: 389
Hello, I must realise a comparison of amounts and I do not know very clearly like doing it; I suppose that more than nothing it's a formula concept.
I 've created a table with the fields "Client", "Product" and "Amount to reserve" and what I want is that when realising a sale order, before registering, if the client of the order is not the same from the table that I've created, let's register but don't if the product is reserved for another client.
I've got it more or less. But now I want that if there are Inventory it allows to register the order although is not for the indicated client.
I put an example:
Amount to reserve: 200
Inventory: 100
Requested amount in sale line: 50
In this case it would not have to let register because the amount of the order and Inventory they give 150 and I have reserved 200 for another client at the moment.
On the following example would have to leave:
Reserved amount: 200
Inventory: 500
Requested amount in sale line: 250
Because they would continue being 250 and I only need to reserve 200. I'll like to know the formulate or expression (translated to c/AL) have I to use to do this comparison.
Thank you very much.
I 've created a table with the fields "Client", "Product" and "Amount to reserve" and what I want is that when realising a sale order, before registering, if the client of the order is not the same from the table that I've created, let's register but don't if the product is reserved for another client.
I've got it more or less. But now I want that if there are Inventory it allows to register the order although is not for the indicated client.
I put an example:
Amount to reserve: 200
Inventory: 100
Requested amount in sale line: 50
In this case it would not have to let register because the amount of the order and Inventory they give 150 and I have reserved 200 for another client at the moment.
On the following example would have to leave:
Reserved amount: 200
Inventory: 500
Requested amount in sale line: 250
Because they would continue being 250 and I only need to reserve 200. I'll like to know the formulate or expression (translated to c/AL) have I to use to do this comparison.
Thank you very much.
0
Comments
-
First of all, why are you not using the Reservation feature from Navision?
Anyhow, I would create a function in the "Sales Line" table, let's say CheckReservation.
In this function, supposing your new created table is referenced as MyTable, and is having one of the keys: Client,Product, I would write the following code:Item.GET("No."); Item.CALCFIELDS(Inventory); ReservedQty := 0; MyTable.RESET; MyTable.SETCURRENTKEY(Client,Product); MyTable.SETRANGE(Product,"No."); IF MyTable.FIND('-') THEN REPEAT ReservedQty := ReservedQty + MyTable."Amount to Reserve"; UNTIL MyTable.NEXT = 0; IF ReservedQty > Item.Inventory THEN ERROR('Your reservation for this item is greater than the available Inventory.') ELSE IF "Quantity (Base)" + ReservedQty > Item. Inventory THEN ERROR('You cannot register more than %1', Item.Inventory - ReservedQty);
0 -
DarkHorse wrote:Hello, I must realise a comparison of amounts and I do not know very clearly like doing it; I suppose that more than nothing it's a formula concept.
I 've created a table with the fields "Client", "Product" and "Amount to reserve" and what I want is that when realising a sale order, before registering, if the client of the order is not the same from the table that I've created, let's register but don't if the product is reserved for another client.
I've got it more or less. But now I want that if there are Inventory it allows to register the order although is not for the indicated client.
I put an example:
Amount to reserve: 200
Inventory: 100
Requested amount in sale line: 50
In this case it would not have to let register because the amount of the order and Inventory they give 150 and I have reserved 200 for another client at the moment.
On the following example would have to leave:
Reserved amount: 200
Inventory: 500
Requested amount in sale line: 250
Because they would continue being 250 and I only need to reserve 200. I'll like to know the formulate or expression (translated to c/AL) have I to use to do this comparison.
Thank you very much.
For me it seems like standard calculation of Item availability which will display you the Inventory warning.
All is done on the Warning Form (Form 342) - See function "Calculate".AvailToPromise.QtyAvailabletoPromise( Rec,GrossReq,SchedRcpt,GETRANGEMAX("Date Filter"), CompanyInfo."Check-Avail. Time Bucket",CompanyInfo."Check-Avail. Period Calc."); EarliestAvailDate := AvailToPromise.EarliestAvailabilityDate( Rec,-NewItemNetChange,GETRANGEMAX("Date Filter"),-OldItemNetChange,OldItemShipmentDate,AvailableQty, CompanyInfo."Check-Avail. Time Bucket",CompanyInfo."Check-Avail. Period Calc."); IF NOT UseOrderPromise THEN SchedRcpt := 0; CALCFIELDS(Inventory,"Reserved Qty. on Inventory"); InventoryQty := ConvertQty(Inventory - "Reserved Qty. on Inventory"); GrossReq := ConvertQty(GrossReq); SchedRcpt := ConvertQty(SchedRcpt); ItemNetChange := 0; IF "No." = ItemNo THEN BEGIN ItemNetChange := NewItemNetChange; GrossReq := GrossReq + OldItemNetChange; END; InitialQtyAvailable := InventoryQty + SchedRcpt - GrossReq;
0 -
Thanks both for reply. I know that there is the Reservation feature from Navision, precisely we're doing this table because the reservation feature form Navision it's a little confused and we need somethig easier and simple; thanks of all ways.
I've tried your code but it seems don't work well, but I it's fault from mine; I've forgotten to comment that when the customer it's the same from my reserve table it let's to register. Also, in my reserve table, I have the option field Reserve, marking it would have to allow all the explained one, but not if it is not marked. How could to include this two conditions in the code?.
Many thanks for help.0 -
To include these two conditions, I think you should include in your code the following two lines that have comments above them.
Item.GET("No."); Item.CALCFIELDS(Inventory); ReservedQty := 0; MyTable.RESET; MyTable.SETCURRENTKEY(Client, Product); MyTable.SETRANGE(Product, "No."); //To calculate all the reservations except these made for the specific customer MyTable.SETFILTER(Client, '<>%1', "Sell-to Customer No."); //To choose only the Items that have Reserve marked MyTable.SETRANGE(Reserve, TRUE); IF MyTable.FIND('-') THEN REPEAT ReservedQty := ReservedQty + MyTable."Amount to Reserve"; UNTIL MyTable.NEXT = 0; IF ReservedQty > Item.Inventory THEN ERROR('Your reservation for this item is greater than the available Inventory.') ELSE IF "Quantity (Base)" + ReservedQty > Item. Inventory THEN ERROR('You cannot register more than %1', Item.Inventory - ReservedQty);
0 -
Thanks for reply. When I attempt to register the sales order it shows me the message: "Item Nº PV15246 don't exist", I think is comparig the Nº of item with the sales order Nº, not the sales line item Nº with Mytable item Nº.. Can't you help me please?.
Thanks.0 -
You should ensure that the function is in the Table 37 - Sales Line, and not in the Table 36. The function should be trigerred from the field "Qty. to Ship", or "Qty. to Ship (Base)" by inserting a line of code like
CheckReservation;
and it should work.
Sorry, I forgotten something very important #-o:IF Type = Type::Item THEN BEGIN //To add this line Item.GET("No."); Item.CALCFIELDS(Inventory); ReservedQty := 0; MyTable.RESET; MyTable.SETCURRENTKEY(Client, Product); MyTable.SETRANGE(Product, "No."); //To calculate all the reservations except these made for the specific customer MyTable.SETFILTER(Client, '<>%1', "Sell-to Customer No."); //To choose only the Items that have Reserve marked MyTable.SETRANGE(Reserve, TRUE); IF MyTable.FIND('-') THEN REPEAT ReservedQty := ReservedQty + MyTable."Amount to Reserve"; UNTIL MyTable.NEXT = 0; IF ReservedQty > Item.Inventory THEN ERROR('Your reservation for this item is greater than the available Inventory.') ELSE IF "Quantity (Base)" + ReservedQty > Item. Inventory THEN ERROR('You cannot register more than %1', Item.Inventory - ReservedQty); END; //To add this line
0 -
Ok; thanks for your help and time, I'll try it.
Thank you very much.0 -
You're welcome.
In case it will work, please modify the title of the topic by adding [SOLVED].
0 -
Thank your very much, it works!!, only one thing. There cases when there are more than a line on the sales line; in case where the reserved product is on the second (or henceforth) line, when shows the line "ERROR('You cannot register more than %1', Item.Inventory - ReservedQty);" because find the reserved product on register, it shows the "Item.Inventory - ReservedQty" from the first line, I mean that don't shows the real quantity, it seems like don't look for the rest of the lines of sales line. Pardon if I don't explain myself well. You know what I mean?, I have tried to put a FIND('-') but it doesn't work to me.
Thanks in advance.0 -
Please check below if I did understand what you ment.
So, let's consider the following scenario. We have the Item No. 123, Inventory = 15 pcs, Reserved Qty. = 2 pcs. We have this Item with the Quantity (Base) = 10 pcs. on the second line of the Sales Order. The CheckReservation function will find that 10 < 15 - 2, therefore you can go further. On the sixth line of our Sales Order, we have again the Item 123, with a Quantity (Base) of 6. The CheckReservation function will again check the availability of these 6 pieces, and will find that everything is ok, because 6 < 15 -2. So, in total, we will be allowed to register (BTW, register = post?) 10 pcs. + 6 pcs. = 16 pcs., which is more than we have in the Inventory, and even more than we have available not reserved.
Is this correct?0 -
Thanks for reply, it doesn't correct but near; sorry if I have not explained myself well. If there is a Reserve quantity and the function is fulfilled, gives the error message and it's correct, it does not concern the lines that there is, the problems is the message. For example, there are two lines:
Product Quantity Inventory Reserved
001 20 50 10
002 30 20 10
Imgine that the reserved product it's the product 002 and my code line from error message says:
"ERROR('You cannot register more than %1', Item.Inventory - ReservedQty);"
On register it's stop because find a reserved line, but the message says:
ERROR: "You cannot register more than 40"
And it would have of being "You cannot register more than 10", because is the product 002. The problem is the message, no the function.
Sorry if I don't explain well.
Thanks.0
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