Dear fiolks, on Codeunit 81-Sales Post(Yes/No) I've the following code on Code trigger.
salesline.RESET;
salesline.SETRANGE("Document Type", SalesHeader."Document Type");
salesline.SETRANGE("Document No.", SalesHeader."No.");
salesline.SETRANGE("Sell-to Customer No.", SalesHeader."Sell-to Customer No.");
reserva.RESET;
IF reserva.GET(salesline."Sell-to Customer No.")THEN;
IF salesline.FIND('-')THEN BEGIN;
IF reserva.FIND('-') THEN
REPEAT
reserva.CALCFIELDS("Existencias producto");
cant:=reserva."Item quantity"-reserva."Reserved quantity";
IF (salesline."No."=reserva."Item") AND (reserva."Nº customer"<>salesline."Sell-to Customer No.")
AND (salesline.Quantity>cant) AND (reserva.Reserved=TRUE) AND (reserva."Stop reserve"=FALSE)
THEN ERROR('You can't register, there is a reserved quantity');
UNTIL reserva.NEXT=0;
I've created a new table called "reserva", when a sales order is going to register this code go to the "reserva" table and looks for if the item is reserved and for which customer. If the sales order is for that customer it lets to register but if is for another customer then don`t let to resgister unless there is enough quantity for reserve and for register.
It works perfectly, but now I want that it advise me (with a message) if there is a reserved quantity for another customer (or for the same customer) of the same item. I mean, first show the message 'You can't register, there is a reserved quantity' and after, if there is another reserved from that item, shows 'Also there is another reserve fot that item". What is missing in my code?. I guess that it must turn to go over all the table again, but I don't get it.
Thanks in advance.
Comments
Thanks.
It seems like your design is wrong. You have a GET statement on your custom table. GET works with the primary key of the table, which appears to be a Customer No. If you're reserving multiple items for the same customer, how does your code work?
Since there can only be one entry per customer in your table, the "(or for the same customer)" will never happen.
Think about using the standard functionality. It will make life easier in the long run.
My Blog - nav.education
It's correct, sorry :oops: . I mean only when there is more than one reserve of the same item. It's possible?.
Thanks for help.
Thanks.
Means, at first check for reservation and if it is not the required result, do second step and find is it reserved for another customer. This is easier.
Thanks for help.
What is a structure of reserva table.
At least I need more information to write you an example.
keys: Cód. item,Nº customer,Reserved quantity,Reservr,Stop reserve
Nº linea,Posting Date,Cód. item,Nº customer
Cód. item,Reserve
Nº customer
the fields:
Field No. Field Name Caption Data Type Length Description Field Class Option String
1 Cód. item <Cód. producto> Code 30 Normal
2 Nº customer <Nº cliente> Code 20 Normal
3 Reserved quantity <Cantidad a reservar> Decimal Normal
4 Description Descripción Text 50 Normal
5 Name Nombre Text 40 Normal
6 Posting Date Fecha registro Date Normal
10 Reservar <Reservar> Boolean Normal
29 Salesperson Code Cód. vendedor Code 10 Normal
32 Vendor No. Nº proveedor Code 20 Normal
33 Familia <Familia> Code 10 Normal
34 Product <Product> Text 30 Normal
35 Nº linea <Nº linea> Integer Normal
38 Customer Posting Group <Customer Posting Group> Code 10 Normal
39 Item quantity <Existencias producto> Decimal FlowField
40 Stop reserve <Anular reserva> Boolean Normal
41 Blocked <Bloqueado> Option FlowField ,Ship,Invoice,All,Commercial
Thanks you for help.
1. You need to use temporary tables to manage lines that you want to check (sales lines) and reserva table lines to know what is left if more than one line with the same item exists in the same document.
2. At first go through existing lines (in salesline temporary table) and reduce the quantities that are reserved.
3. Go again and find do you have any other reservation.
Hope this helps.
Thanks for help.