Check shipment date on Sales Price

vnprocvnproc 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)
  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.

Comments

  • robbonickrobbonick Member Posts: 40
    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");
    



  • vnprocvnproc Member Posts: 41
    Thank robbonick
    Im write code
    CheckSalesPriceExpiry(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 procedure
      SalesLine.SETRANGE("Document No.",WhseShipLine."Source No.");
      CheckSalesPriceExpiry(SalesLine); 
    
    But it not work. Please help me
    Thanks so much
  • robbonickrobbonick Member Posts: 40
    vnproc wrote: »
    Thank robbonick
    Im write code
    CheckSalesPriceExpiry(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 procedure
      SalesLine.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.
  • vnprocvnproc Member Posts: 41
    Thanks robbonick.
    After I debug then result
    4nqswzee0ps7.png
    b9liorjnxllq.png

    Item Code := blank
    "Sales Code" := Customer (No filter "Customer Price Group")



  • robbonickrobbonick Member Posts: 40
    edited 2018-06-18
    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.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-06-18
    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-03
Sign In or Register to comment.