Monday, November 12, 2018

LS NAV - Autopost Sales with PMS assemblies

COMMENT - AutopostSales Function to run on a schedule and post sales and inventory for calculated statements.
If a store has any unposted assembly transactions, do not post any statements for that store
If a terminal's transaction count does not match the statement, do not post that statement.
 Enabled 18-Dec-2017
Updated to ignore statement if internal filter exists.
Updated to clear internal filter, recalculate and post.

AutoPostSales()
BEGIN
            //Scan through all Open Statements
            //message('started');
//      OpenStatement.SETFILTER("No.",'VS0001963'); //rem
      OpenStatement.SETFILTER("Calculated Date",'>01/01/18'); //ignore old stmts
//      OpenStatement.SETFILTER("Staff/POS Term Filter Internal",'<0'); //ignore stmts with filters
      OpenStatement.SETFILTER("No.",'>0'); //ignore invalid stmts
      OpenStatement.SETFILTER(Status,'0'); //ignore non-available statements
      OpenStatement.SETAUTOCALCFIELDS("Sales Amount");
      IF OpenStatement.FIND('-') THEN BEGIN
      //MESSAGE('found');
        REPEAT
        //Check if any lines exist
        //MESSAGE(FORMAT(OpenStatement."Sales Amount",15));
        OpenStatement.VALIDATE("Staff/POS Term Filter Internal",'');
        OpenStatement.MODIFY;
        OpenStatement.SETFILTER("Staff/POS Terminal Filter",'*');
        OpenStatement."Skip Confirmation" := TRUE;
        StmtCalc.RUN(OpenStatement);
        IF OpenStatement."Sales Amount" <> 0 THEN BEGIN
        //IF 1=1 THEN BEGIN
          //Check if currently posting
          //MESSAGE('has sales');
          BatchPostingQueue.Status := BatchPosting.GetStatementStatus(OpenStatement);
          IF (BatchPostingQueue.Status < 0) OR
             (BatchPostingQueue.Status = BatchPostingQueue.Status::Finished) THEN
            BatchPostingStatus := ''
          ELSE
            BatchPostingStatus := FORMAT(BatchPostingQueue.Status);
        //MESSAGE('Statement:' + FORMAT(OpenStatement."No.",15) + ' BatchPostingStatus:' + BatchPostingStatus);

          IF BatchPostingStatus = '' THEN BEGIN //Only post if no status
          //IF CONFIRM(Txt_ConfirmItemOnlyPosting,TRUE) THEN BEGIN
            Store.GET(OpenStatement."Store No.");
            IF NOT Store."Use Batch Posting for Statem." THEN
               BEGIN
               //MESSAGE('Posting statement:' + FORMAT(OpenStatement."No.",15));
               StatementPost.RunItemPosting(OpenStatement,FALSE);
               END
            ELSE
              BEGIN
              //Check if any missing transactions
                RetailCommentLine.SETRANGE("No.",OpenStatement."No.");
                RetailCommentLine.FINDLAST;
                SavedErrLineCounter := RetailCommentLine."Line No.";
                StmtCalc.CheckMissingTransFromPOS(OpenStatement);
                COMMIT;  // needed to commit the RetailCommentLines
                RetailCommentLine.FINDLAST;
                  IF  RetailCommentLine."Line No." <> SavedErrLineCounter THEN BEGIN
                  //Do Nothing
                  END ELSE BEGIN
                    //Check if any open assemblies for store
                      AsmHdr.RESET;
                      AsmHdr.SETRANGE("Location Code",OpenStatement."Store No.");
                      IF AsmHdr.FIND('-') THEN BEGIN
                        //Do Nothing
                        END  ELSE BEGIN
                        BatchPosting.ValidateAndPostStatement(OpenStatement,TRUE);
                      END;
                  END;

              END;
          END;
        END;
        CLEAR(StatementPost);
        CLEAR(BatchPosting);
        UNTIL OpenStatement.NEXT  <= 0;
      END;
      //MESSAGE('End Statement Post');
    END;

No comments:

Post a Comment