Blocking Order without Advance Deposit

Hello Guys my company needed to block order processing happening if customer does not have deposit in advance and my company doe not signed ATS with the System Vendor yet and i am more of the support and functional guy yet i know intermediate NAV Development and my way around it.So i tried putting the following code on the Post action on the sales order page and it works well and i need the good guys of this forum to take a look at this code and suggest enhancement or if there are any pitfalls i haven't expected.By the way i am excited to deliver my first development challenge.


Customer.GET("Sell-to Customer No.");
Customer.CALCFIELDS(Balance);
SalesLine.SETFILTER(SalesLine."Document No.","No.");
SalesLine.CALCSUMS(SalesLine.Amount);
SalesLineIncVAT:=SalesLine.Amount * 1.15;//To calculate line amount including VAT

IF Customer."Gen. Bus. Posting Group"='CREDIT' THEN //Continue if customer is credit customer
   Post(CODEUNIT::"Sales-Post (Yes/No)")
ELSE
    IF Customer.Balance < 0 THEN BEGIN
      "Cust.Bal.Pos.":=Customer.Balance*-1;//To change the negative customer to positive
       Shortage:=SalesLineIncVAT-"Cust.Bal.Pos."; //To compare Balance and order amount
           IF ("Cust.Bal.Pos." >= SalesLineIncVAT) THEN BEGIN //IF customer balance covers the order amount
               Post(CODEUNIT::"Sales-Post (Yes/No)")
           END
           ELSE
               ERROR(Text003,Customer.Balance,SalesLineIncVAT,Shortage) //IF customer balance does not cover the order amount
    END ELSE BEGIN
           ERROR(Text004);//If no deposit at all

 

//Thanks in advance!!

Related
Recommended