Help with a code on Codeunit 81

DarkHorseDarkHorse Member Posts: 389
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

  • i4tosti4tost Member Posts: 208
    My question: why you created this? It is standard NAV functionality. Use Orders (or Blank Orders) for reservation.
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply. I know there is a funcionality for it, thanks for alerting, but I've done this, more easy for people and only with just we need.
    Thanks.
  • matttraxmatttrax Member Posts: 2,309
    As was said, this is standard functionality. Don't reinvent the wheel if you don't have to. But if you must...

    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?
    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

    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.
  • DarkHorseDarkHorse Member Posts: 389
    Since there can only be one entry per customer in your table, the "(or for the same customer)" will never happen.

    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.
  • DarkHorseDarkHorse Member Posts: 389
    Any solution please? [-o<
    Thanks.
  • i4tosti4tost Member Posts: 208
    From my point of view, you are trying to do two different things at the same time. Split them.
    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.
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply. According to this code, how it would be please?.
    Thanks for help.
  • i4tosti4tost Member Posts: 208
    Are reserva."Item quantity" and reserva."Reserved quantity" flowfields?
    What is a structure of reserva table.
    At least I need more information to write you an example.
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply. I tell you. reserva."Item quantity" it's a flowfield. (from table Item). I post some information about "reserva" table.

    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.
  • i4tosti4tost Member Posts: 208
    I've tried, but this takes a lot of time and will be about 100 lines (i think), so i will say only some tricks due to not program for others in the future :).
    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.
  • DarkHorseDarkHorse Member Posts: 389
    Thank you very much for help. I'll try that you say.
    Thanks for help.
Sign In or Register to comment.