          SUBROUTINE (MAT OE.VARS,MAT OE.SFLAGS,UPD.LOC,LI.DATA,MSG.FLAG,MSGS,RESPS,NEW.NONSTOCK)
** Version# 132.0001[3] - 12/23/2016 - 02:49pm - TSMITH - eclipse
*** V132.0001 Change - Custom Coding . - 12/23/2016 - TSMITH - eclipse

*** SUBROUTINE - OE.LI.COMMIT
*-------------------------------------------------------------------------*
*** This attempts to add a line item to the order with as little effort as
*** possible.  This does _not_ perform all the checks necessary to add
*** a line item to an order.  See OE.LI.ADD for further information.
*-------------------------------------------------------------------------*
*** OE.VARS     - OID, GEN, etc. (see CC OE.EQUATES)               [IN]
*** OE.SFLAGS   - Order Entry screen display flags                 [IN/OUT]
*** UPD.LOC     - This is used to know where to re-enter the code  [IN/OUT]
*** LI.DATA     - This is a list of line item related data:        [IN]
***             - <1,1> = Part Number or "C"
***             - <1,2> = Quantity to Order
***             - <1,3> = Largest UM to display with
***             - <1,4> = RF Allocation Zone
***             - <1,5> = Boolean, true to insert the line
***             - <1,6> = Line Number (relative to LDID.LIST)
***             - <1,7> = Price Override
***             - <1,8> = COGS Cost Override
***             - <1,9> = Initial LDID.
***             - <1,10> = Additional data
***             - <1,12> = Product type and location
***             - <1,12,2> = Additional quantities and locations
***             - <1,16> = Diff between procure and ordered qty
***             - <1,17> = COMM Cost Override
***             - <1,18> = Substitute flag (indicates current line
***                        item is being substituted)
*** MSG.FLAG    - Boolean, if this is true then OE.ACTION.DISPLAY  (OUT)
***             - must be called to handle the user interaction.
*** MSGS        - The actions array.                               [IN/OUT]
*** RESPS       - The responses array.                             [IN/OUT]
*-------------------------------------------------------------------------*
*** Common Variables: LED, LD
***       BRCH.PROD$     - Indicates the product is branch specific
*-------------------------------------------------------------------------*
          $INCLUDE CC OE.EQUATES

          IS.RESERVE = NO
          *Check to see if this is a reserve order.
          IF USE.RESERVE$ AND MODE%='S' THEN
             LOCATE 'R' IN LED(6)<1> SETTING RSPOS THEN
                IS.RESERVE = YES
             END
          END

          GOSUB INIT

          * If re-entering because of a returned related item
          * we can skip most of the checks.
          LOCATE  'RELATED.ITEM.RETURN' IN RESPS<1> SETTING POS THEN
             GOTO CHECK.RELATED
          END

          IF NOT(NEW.LD) THEN
             GOSUB CHECK.BO.KIT.CHANGE
          END

          IF UPD.LOC # '' THEN GOTO UPD.QO
          IF NEW.LD THEN
             LDID%  = ''
             MAT LD = ''
             * Restore Previously entered Customer Part Number in LD(43)
             * so OE.GET.PN will not cause a request for the Cust Part #.
             IF CPN # '' THEN
                LD(43) = CPN
             END
             IF PN = 'C' THEN
                GOSUB CREATE.COMMENT
             END
          END ELSE
             GOSUB CHECK.CHANGE.ALLOWED
          END

          READ PRD.REC FROM PRDFILE,PN ELSE PRD.REC = ""

          GOSUB CHECK.BR
          GOSUB CHECK.PURGE
          GOSUB CHECK.QTY.CHNG
          GOSUB CHECK.LOT.RETURN
          GOSUB CHECK.LOT.MODE
          GOSUB CHECK.LOT.REMOTE
          GOSUB CHECK.LOT.INV.GEN
          GOSUB CHECK.LOT.GEN
          GOSUB CHECK.PILS
          GOSUB GET.PN
          GOSUB CHECK.DUP.OE
          GOSUB CHECK.POE.MA
          GOSUB CHECK.GC

          * Check to see if the product is going to be cut. If we need
          * to prompt the user, we will do so here.
          GOSUB CHECK.CUT

          !!! ******************************************************** !!!
          !!!                       W A R N I N G                      !!!
          !!! All code from this point on should not use               !!!
          !!! "RETURN TO FINISH" in order to get information from the  !!!
          !!! user that requires re-entering this routine. After this  !!!
          !!! line, we will create a line item and re-entering and     !!!
          !!! hitting this code again will result in a blank line item !!!
          !!! being added to the order. If you need to get something   !!!
          !!! from the user in the form of the ACTIONS array, do it    !!!
          !!! above this line                                          !!!
          !!! ******************************************************** !!!
          GOSUB CREATE.NEW.LDID

          GOSUB CHECK.LOT.QO
          GOSUB CHECK.DUP.LI
          GOSUB SET.ADDL.DATA
          GOSUB CHECK.INVALID.PRD

CHECK.RELATED:*** While re-entering for related returns start here
              *** so the correct tax is found in CHECK.RET.

          IF MODE% = 'S' THEN
             GOSUB CHECK.BO.KITS
             GOSUB CHECK.RET
          END

UPD.QO:   ***
          SV.QO = QO

          *** Locate the saved LDID.LIST to pass into OE.UPD.QO. This must
          *** done when the "PIL" warning is displayed and triggered.
          LOCATE 'SAVED.LDID' IN RESPS<1> SETTING POS ELSE RETURN
          LDID.LIST = RAISE(RESPS<2,POS>)

          !!! ******************************************************** !!!
          !!!                       W A R N I N G                      !!!
          !!! All code from this point on will only modify the new     !!!
          !!! line item that has been added to the order. Any checks   !!!
          !!! that need to happen to see whether or not the line item  !!!
          !!! should be added to the order should happen prior to the  !!!
          !!! call to OE.UPD.QO.                                       !!!
          !!! ******************************************************** !!!
          OE.UPD.QO MAT OE.VARS,MAT OE.SFLAGS,GROUP,QO,LARGEST.UM,ALLOC.ZONE,LDID.LIST,UPD.LOC,MSG.FLAG,MSGS,RESPS

          *** Because of split qtys, the QO may have changed.
          GOSUB CHECK.MOD.QO

          *** The QO may have also have changed due to sell package qtys
          GOSUB CHECK.SPKG.QO

          ** Don't proceed with Price/Cost Override updates until no
          ** messages exist (at least for Java).
          IF MSG.FLAG THEN
             GOTO FINISH
          END

          *** Check if there are any related products.
          IF MODE% = 'S' THEN
             GOSUB CHECK.PROD.RELS
          END

          SKIP.PROD.WIZ.CHECK = ADDL.NO.WIZ
          IF EXEMPT AND NOT(SKIP.PROD.WIZ.CHECK) THEN
             LOCATE 'PROD.WIZ' IN RESPS<2> SETTING POS THEN
                SKIP.PROD.WIZ.CHECK = 1
             END
          END
          IF NOT(SKIP.PROD.WIZ.CHECK) THEN
             READV SUB.ID FROM PRDFILE,PN,140 ELSE SUB.ID = ""
             IF SUB.ID # "" THEN
                UT.OPEN.FILE "OC",OCFILE,OCERR,YES
                UT.OPEN.FILE "VOC",VOCFILE,VOCERR,YES
                IF NOT(OCERR) AND NOT(VOCERR) THEN
                   READV IS.CAT FROM VOCFILE,SUB.ID,1 ELSE IS.CAT = ""

                   READV LINE.1 FROM OCFILE,SUB.ID,1 ELSE LINE.1 = ""
                   LINE.1 = FIELD(LINE.1,"(",2)
                   LINE.1 = TRIM(LINE.1,")","T")
                   CONVERT "," TO AM IN LINE.1
                   PARAM.CT = DCOUNT(LINE.1,AM)

                   IF IS.CAT = "V" AND PARAM.CT = 3 THEN
                      MSGS      = ""
                      ADD.TYPE  = "PROD.WIZ"
                      DATA      = SUB.ID
                      ACTION.ADD MSGS,ADD.TYPE,,,,,DATA
                      GOTO FINISH
                   END
                END
             END
          END
          GOSUB GET.PRICE.PER

          GOSUB PRICE.OVERRIDE
          GOSUB COGS.OVERRIDE
          GOSUB COMM.OVERRIDE

          GOSUB UPD.LINE.FGHT
          GOSUB SAVE.GC
          GOSUB ADD.COMMENT

          GOSUB GET.TYPE.LOC
          GOSUB ADD.LINE.COMMENT
          GOSUB UPD.POLE.DISP
          *if this is a purchase order and the control
          *record for automatically calculating duty charges then go a head
          *and check
          IF MODE% = 'P' AND NUM(LD(1)) AND AUTO.CALC.DUTY THEN
             GOSUB UPDATE.DUTY
          END
          GOSUB COPY.IAO.CC
          GOSUB COMMIT.CUT
FINISH:
          RETURN
*-------------------------------------------------------------------------*
CHECK.BO.KIT.CHANGE: ***  Make sure the user is not trying to change a
          *** kit that has been previously splint into multiple line items
          *** for backordering purposes
          IF IS.RESERVE THEN RETURN

          IF PN # LD(1) OR QO # LD(4) THEN
             IF LD(122) OR LD(124) THEN
                MSG.FLAG  = YES
                MSG.ID    = '%599'
                ACTION.ADD.MSG MSGS,,YES,MSG.ID,,1,,5,3
             END

             IF MSG.FLAG THEN
                RETURN TO FINISH
             END ELSE
               RETURN
             END
          END
*-------------------------------------------------------------------------*
COPY.IAO.CC:*** Copying cogs to cost if it shoudl
          ***If the control record is set for copy COST to COGS for IAO
          ***item, we need to do it here. Note that we only do the copy
          ***if it is a sales order and the line item being updated is a
          ***new line item and of course, the product is IAO
          PRC.BR = LED(2)<1,GEN%,1>
          IF MODE% = 'S' AND NEW.LD AND LD(114) THEN
             READ COPY.IAO.COGS FROM CTRBFILE,"COPY.COST.TO.COGS.IAO~":PRC.BR ELSE COPY.IAO.COGS = ''
             IF COPY.IAO.COGS THEN
                LD(11)<1,GEN%> = LD(10)<1,GEN%>
                LD(10)<1,GEN%> = LD(27)<1,GEN%>
                OE.UPDATE.LDID LDID%,OID%,GEN%,LOG.MV%,QSIGN%
             END
          END
          RETURN
*-------------------------------------------------------------------------*
CHECK.CUT: *** Check to see if we have a cuttable product
          IF MODE%='S' OR MODE% = 'T' THEN
             CUTTABLE = NO
             * Check (at the product level) to see if this product is
             * cuttable or not. We will not check the cut groups here as
             * the product hasn't been added to the order yet. That will
             * be done in COMMIT.CUT.
             IS.PRODUCT.CUTTABLE ,,CUTTABLE
             IF CUTTABLE THEN
                * If we are already in the Cuttable screen in OE, we do
                * not need to check the cuttability here. That will be
                * handled in PROD.CUTTABLE.CHECK when called from the
                * method isCuttable(pn) in ProductCutEntry.java.
                * Therefore, that class might include this action so we
                * can skip the check here.
                ACT.ID = "SKIP.BR.CUTTABLE.CHECK"
                LOCATE ACT.ID IN RESPS<1> SETTING NOTHING THEN
                   ACT.ID2 = "OE.LI.COMMIT.CUT"
                   LOCATE ACT.ID2 IN RESPS<1> SETTING NOTHING ELSE
                      RESPS<1,-1> = ACT.ID2
                   END
                   RETURN
                END

                * Load in the units of measure that can not be cut.
                NO.CUT.UMS = RAISE(PRD(162))
                CUT.CT     = DCOUNT(NO.CUT.UMS,AM)

                * Loop through them. We cannot do a locate because
                * the data is formatted for an EclipseTable.
                FOR CCT = 1 TO CUT.CT
                   IF (NO.CUT.UMS<CCT,1,1> = "") THEN CONTINUE

                   * If the unit of measure is found, we cannot cut
                   * the product.
                   IF (NO.CUT.UMS<CCT,1,1> = LARGEST.UM) THEN
                      * Add a comment to the order explaining this...
                      CMT  = PRD(1)<1,1,1>[1,30]:" (PN#":LD(1):") "
                      CMT := "will not be cut because the unit of "
                      CMT := "measure on the order (":LARGEST.UM:") "
                      CMT := "is not cuttable."
                      OE.ADD.COMMENT OID%,LOG.MV%,CMT

                      * ...flag the product as not cuttable and return.
                      LD(143) = YES
                      RETURN
                   END
                NEXT CCT

                IF JAVA.PROC$ THEN
                   * Check to branch flag in Product Maint.
                   PRD.BR.GET.VAL SHIP.BR,PN,64,BR.CUT
                   BEGIN CASE
                   * "1" means the product will NOT be cut.
                   CASE (BR.CUT = "1")
                      * Put a comment on the order and return.
                      CMT  = PRD(1)<1,1,1>[1,30]:" (PN#":LD(1):") "
                      CMT := "will not be cut because ship branch "
                      CMT := SHIP.BR:" is not setup to allow cuts."
                      OE.ADD.COMMENT OID%,LOG.MV%,CMT
                      LD(143) = YES
                      RETURN
                   * "2" means the user will be prompted.
                   CASE (BR.CUT = "2")
                      * Setup a prompt in the Action Array.
                      ACT.ID = "CHECK.BR.CUTTABLE"
                      LOCATE ACT.ID IN RESPS<1> SETTING RESP.POS THEN
                         DO.CUT = RESPS<2,RESP.POS,1>
                      END ELSE
                         MSG.FLAG = YES
                         ACTION.ADD.CONFIRM MSGS,ACT.ID,NO,"%380"
                         RETURN TO FINISH
                      END

                      * If the user elected to not cut, the note that
                      * in the log of the order.
                      IF NOT(DO.CUT) THEN
                         CMT  = PRD(1)<1,1,1>[1,30]:" (PN#":LD(1):") "
                         CMT := "will not be cut because the user chose "
                         CMT := "not to cut the product."
                         OE.ADD.COMMENT OID%,LOG.MV%,CMT
                         LD(143) = YES
                         RETURN
                      END
                   END CASE

                   * Cut products do not currently support multiple uoms.
                   DFLT.PER.GET MODE%,PER.QTY
                   IF REM(QO,PER.QTY) > 0 THEN
                      MSG.FLAG = YES
                      MSG.ID   = "Cut products can not have multiple "
                      MSG.ID  := "units of measure."
                      ACTION.ADD.MSG MSGS,,YES,MSG.ID,,2,,5,3
                      RETURN TO FINISH
                   END

                   * If we've reached this code, it means we are going
                   * to cut the product. However, the line item hasn't
                   * been added to the order yet, so we can't cut do
                   * the cut process yet. We will save a placeholder in
                   * the responses array (RESPS) so later on, after the
                   * product has been added, we can perform the cut
                   * (see COMMIT.CUT).
                   ACT.ID = "OE.LI.COMMIT.CUT"
                   LOCATE ACT.ID IN RESPS<1> SETTING NOTHING ELSE
                      RESPS<1,-1> = ACT.ID
                   END
                END ELSE
                   * Check to branch flag in Product Maint.
                   PRD.BR.GET.VAL SHIP.BR,PN,64,BR.CUT

                   * "1" means the product will NOT be cut.
                   IF (BR.CUT = "1") THEN
                      * Put a comment on the order and return.
                      CMT  = PRD(1)<1,1,1>[1,30]:" (PN#":LD(1):") "
                      CMT := "will not be cut because ship branch "
                      CMT := SHIP.BR:" is not setup to allow cuts."
                      OE.ADD.COMMENT OID%,LOG.MV%,CMT
                      LD(143) = YES
                      RETURN
                   END ELSE
                      * From Eterm, we allow product add, but we don't mark
                      * it as a cut product, it's treated as a normal prod
                      * Warn user that they might want to add this in Solar
                      MSG.FLAG  = YES
                      MSG.ID    = "This is a cuttable product. Use Solar "
                      MSG.ID   := "to create the order ":AM:"and to "
                      MSG.ID   := "specify cut quantity and length."
                      ACTION.ADD.MSG MSGS,,YES,MSG.ID,,2,,5,3
                   END
                END
             END
          END

          RETURN
*-------------------------------------------------------------------------*
COMMIT.CUT: *** This code is going to check to see if the product needs
          *** to be cut and, if it does, carry out the cut on the order.

          * If OE.LI.COMMIT.CUT is found in the responses array, then
          * we flagged this product to be cut (see CHECK.CUT).
          ACT.ID = "OE.LI.COMMIT.CUT"
          LOCATE ACT.ID IN RESPS<1> SETTING CUT.POS THEN
             CUTTABLE = NO

             * The code in CHECK.CUT only checks to see if the product is
             * flagged as being cuttable. It can not check the cut
             * groups as the line item hasn't been added to the order in
             * CHECK.CUT and that is when the group information is
             * available. Thus, we need to call IS.PRODUCT.CUTTABLE
             * again to ensure the cut groups are properly checked too.
             IS.PRODUCT.CUTTABLE OID%,GEN%,CUTTABLE,,YES
             IF CUTTABLE THEN
                * From Solar, update Cut Product info
                OE.LI.UPD.CUT MAT OE.VARS,MAT OE.SFLAGS,RESPS

                * We are done with our "placeholder" in the responses
                * array, so lets clean up after ourselves to avoid the
                * possibility of inadvertantly cutting something.
                RESPS = DELETE(RESPS,1,CUT.POS)
             END
          END

          RETURN
*-------------------------------------------------------------------------*
UPDATE.DUTY: ***this routine will check to see if the product entered has
          ***duty harmonizing code defined or not. If it does, then
          ***we should update the freight and duty charges on the order
          OE.UPD.FRT.DUTY OID%,GEN%,LDID%,QSIGN%,LOG.MV%,''

          RETURN
*-------------------------------------------------------------------------*
INIT:     *** Initialize the variables used in this routine.
          CPN = LD(43)                   ;* Entered Customer Part Number

          TAGS.CHECKED = 0
          PN          = LI.DATA<1, 1>    ;* Product ID of the new line
          QO          = LI.DATA<1, 2>    ;* The quantity to order
          LARGEST.UM  = LI.DATA<1, 3>    ;* The largest UM to display in
          ALLOC.ZONE  = LI.DATA<1, 4>    ;* The RF Allocation zone
          INS.LINE    = LI.DATA<1, 5>    ;* Boolean, true makes a new line
          LDID_LINE   = LI.DATA<1, 6>    ;* The LDID.LIST pos to ins LDID

          PRICE.OVRD  = LI.DATA<1, 7>    ;* The price to use as an ovrd,
                                         ;* this is very optional.
          COST.OVRD   = LI.DATA<1, 8>    ;* The cogs to use as an ovrd,
                                         ;* this is very optional.
          INIT.LDID   = LI.DATA<1, 9>
          ADDL.DATA   = RAISE(RAISE(LI.DATA<1,10>))

          SKIP.DUP    = LI.DATA<1,11>    ;* Suppress Duplicate LI check.
          TYP.LOC     = LI.DATA<1,12,1>    ;* Type and location
          RCV.TYPE    = LI.DATA<1,12,2>
          RCV.LOCA    = LI.DATA<1,12,3>

          CMNTS       = LI.DATA<1,13>
          * additional qty and ship type to fullfill buy package qty for
          * procurements.
          ADDL.NO.WIZ = LI.DATA<1,14,10>   ;* Addl flag to skip prod wiz.
          ADDLS       = LI.DATA<1,14>
          LD.TMP      = RAISE(RAISE(LI.DATA<1,15>))
          QTY.DIFF    = LI.DATA<1,16>
          COMM.OVRD   = LI.DATA<1,17>    ;* The COMM cost to use as an
                                         ;* ovrd, this is very optional.

          SUB.EXISTING = LI.DATA<1,18>   ;* Substitute flag (indicates
                                         ;* current line item is being
                                         ;* substituted)


          MSG.FLAG    = NO
          NEW.LD      = (INS.LINE OR LDID% = '')
          PRC.BR      = LED(2)<1,GEN%,1>
          SHIP.BR     = LED(2)<1,GEN%,2>
          LDID.LIST   = ''
          IF LDID_LINE+0=0 THEN LDID_LINE = 1

          LD.GETV PARENT.PN,ADDL.DATA<132>,1

          LOCATE 'EXEMPT' IN RESPS<1> SETTING POS THEN
             EXEMPT = 1
          END ELSE
             EXEMPT = ''
          END
          AUTO.CALC.DUTY = NO
          IF MODE% = 'P' THEN
             READ TST FROM CTRLFILE,'POE.AUTO.CALC.DUTY' ELSE TST = ''
             IF TST THEN
                AUTO.CALC.DUTY = YES
             END
          END

          MSGS = ''
          OID  = OID.DATA$<1>

          IF MODE% = 'S' THEN
             UT.OPEN.FILE 'GIFT.CERTIFICATE',GIFTCERTFILE,ERR.MSG
             IF ERR.MSG THEN RETURN
          END

          RETURN
*-------------------------------------------------------------------------*
CREATE.COMMENT: *** This creates and updates the comment as a new line
          *** line item in the current order.  Note:  this returns
          *** to FINISH (no further processing needed).

          OE.NEW.LDID OID%,LDID%

          LD(1)         = 'C'
          LD(2)         = ADDL.DATA<1>
          LD(3)         = ADDL.DATA<2>
          GEN.MV        = GEN%
          UPDATE.LEDGER.DET OID%,LDID%,QSIGN%,GEN.MV

          * Make sure this gen is added to the log variable.
          LOCATE GEN% IN LOG.MV%<1> SETTING MV.POS ELSE
             LOG.MV% = INSERT(LOG.MV%,1,MV.POS;GEN%)
          END

          * The ldid insert in LED(49) can be removed iff
          * UPDATE.LEDGER.DET updates LED(49) for comments correctly.
          LOCATE LDID% IN LED(49)<1> SETTING POS ELSE
             LED(49) = INSERT(LED(49),1,POS;LDID%)
          END

          RETURN TO FINISH
*-------------------------------------------------------------------------*
CHECK.CHANGE.ALLOWED:*** If this is not a new line item, then make sure
          *** that the user can perform the change.
          IF EXEMPT THEN
             LOCATE 'LOT.BILL' IN RESPS<2> SETTING POS THEN RETURN
          END
          IF IS.RESERVE THEN RETURN
          * Don't overwrite Comments or Subtotals.
          IF LD(1) = 'C' OR LD(1) = 'S' THEN
             MSG.FLAG             = YES
             MSG.ID               = '%731'
             IF LD(1)             = 'S' THEN MSG.ID = '%732'
             ACTION.ADD.MSG MSGS,,YES,MSG.ID,,,,5,3

             RETURN TO FINISH
          END

          * We are not considering Comments or Subtotals past this point.
          IF NOT(NUM(LD(1))) OR LD(1) = ''                   THEN RETURN


          * Disallow overwrite of Lot Items.
          IF NOT(NEW.NONSTOCK) THEN
             PRD.NUM = LD(1)
             READV PRD.STAT FROM PRDFILE,PRD.NUM,3 ELSE PRD.STAT = ''
             IF PRD.STAT = 9 THEN
                MSG.FLAG = YES
                MSG.ID   = '%733'
                ACTION.ADD.MSG MSGS,,YES,MSG.ID,,,,5,3

                RETURN TO FINISH
             END
          END

          * Make sure the user is not effecting a tagged item.
          OE.TAG.CHECK MAT OE.VARS,-LD(4)*QSIGN%,CHNG.OK,MSG.FLAG,MSGS,RESPS,PN
          IF MSG.FLAG OR NOT(CHNG.OK) THEN RETURN TO FINISH

          RETURN
*-------------------------------------------------------------------------*
CHECK.BR: *** Check to see if the product is available to sell at this br
          * Getting the branch specific settings from control file
          IF IS.RESERVE THEN RETURN

          IF EXEMPT THEN
             LOCATE 'CHECK.BR' IN RESPS<2> SETTING POS THEN RETURN
          END

          IF BRCH.PROD$ # '' AND NOT(BRCH.PROD$ = 'Disabled') THEN
             * Getting specific branches for Product
             PROD.BR = PRD.REC<118>

             * If no product specific branches exist then get price line
             * specific branches
             IF PROD.BR = '' THEN
                * Getting specific branches for Price Line
                READV PROD.BR FROM PLNEFILE,PRD.REC<9>,14 ELSE PROD.BR = ""
             END
             IF PROD.BR = '' THEN RETURN

             * If User Branch - in OE, treat as Ship Branch
             IF BRCH.PROD$ = 'User Branch' THEN

                * Find match from product or price line specific
                * branches
                AUTH.BR.OK = NO
                LOCATE SHIP.BR IN PROD.BR<1> SETTING NOTHING THEN
                   AUTH.BR.OK = YES
                END

                * If not okay, then cannot add product to branch
                IF NOT(AUTH.BR.OK) THEN
                   MSG.FLAG = YES
                   ACTION.ADD.MSG MSGS,,YES,'%40',,,YES,10,10

                   RETURN TO FINISH
                END
             END

             * If Price Branch
             IF BRCH.PROD$ = 'Price Branch' THEN
                * Get user authorized specific branches
                ORDPRICE.BR = LED(2)<1,GEN%,1>

                * Find match from product or price line specific branches
                ORDPRICE.BR.OK = NO
                LOCATE ORDPRICE.BR IN PROD.BR<1> SETTING NOTHING THEN
                   ORDPRICE.BR.OK = YES
                END

                * If not okay, then cannot add product to branch
                IF NOT(ORDPRICE.BR.OK) THEN
                   MSG.FLAG = YES
                   ACTION.ADD.MSG MSGS,,YES,'%40',,,YES,10,10

                   RETURN TO FINISH
                END
             END
          END
          RETURN
*-------------------------------------------------------------------------*
CHECK.PURGE:*** Do not add a purge item onto an order
          IF EXEMPT THEN
             LOCATE 'CHECK.PURGE' IN RESPS<2> SETTING POS THEN RETURN
          END
          IF IS.RESERVE THEN RETURN
          IF PRD.REC<3> = 7 THEN
             MSG.FLAG = YES
             ACTION.ADD.MSG MSGS,,YES,'%33',,,,2,3
             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.QTY.CHNG: *** Check to verify that the user has authorization to add
          *** the product to the order
          IF IS.RESERVE THEN RETURN
          * This check is only necessary if this is a not a new order
          IF NOT(NEW.ORDER%) THEN

             * Need to check the proper key based on whether the order
             * is invoiced or not
             IF (LED(8)<1,GEN%>) THEN
                KEY.ID = MODE%:"OE.CLOSED.QTY.EDIT"
                INV.ON = YES
             END ELSE
                KEY.ID = MODE%:"OE.OPEN.QTY.EDIT"
                INV.ON = NO
             END

             * Check the authorization key to allow the user to edit the
             * quantity (add a new line item on an existing order)
             CHECK.KEY KEY.ID,QTY.OK,QTY.LVL

             * Read the product status from the product file
             READV PSTAT FROM PRDFILE,PN,3 ELSE PSTAT = ""

             * If this is a Nonstock item...
             IF (PSTAT = "2") THEN

                * ...and if the QTY.LVL of the auth key is less than 2...
                IF (QTY.LVL < 2) THEN

                   * ...then do not allow the user to add the nonstock
                   * item to the order.
                   ACTION.ADD.MSG MSGS,,YES,"%312"
                   RETURN TO FINISH
                END

                * Check if Control set
                IF CLOSED.SHIP.ONLY$ AND MODE% = 'S' AND INV.ON THEN
                   * Dont allow SOE.CLOSED.QTY.EDIT if users home branch
                   * is not the ship branch
                   SOE.CLOSED.QTY.SHIP.ONLY OID%,GEN%,SHIP.ONLY.OK
                   IF NOT(SHIP.ONLY.OK) THEN
                      * ...then do not allow the user to add the
                      * Nonstock item to the order.
                      ACTION.ADD.MSG MSGS,,YES,"%312"
                      RETURN TO FINISH
                   END
                END

             END ELSE

                * ...otherwise, check to see if the user either does not
                * have the auth key, or (if the product status is
                * something other than stock) and the QTY.LVL of the auth
                * key is less than 2...
                IF (NOT(QTY.OK) OR ((PSTAT # "1") AND (QTY.LVL < 2))) THEN

                   * ...then do not allow the user to add the item to
                   * the order.
                   ACTION.ADD.MSG MSGS,,YES,"%314"
                   RETURN TO FINISH
                END

                * Check if Control set
                IF CLOSED.SHIP.ONLY$ AND MODE% = 'S' AND INV.ON THEN
                   * Dont allow SOE.CLOSED.QTY.EDIT if users home branch
                   * is not the ship branch
                   SOE.CLOSED.QTY.SHIP.ONLY OID%,GEN%,SHIP.ONLY.OK
                   IF NOT(SHIP.ONLY.OK) THEN
                      * ...then do not allow the user to add the
                      * item to the order.
                      ACTION.ADD.MSG MSGS,,YES,"%314"
                      RETURN TO FINISH
                   END
                END

             END
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.LOT.RETURN:*** Do not allow the user to enter a return lot item

          IF EXEMPT THEN
             LOCATE 'LOT.BILL' IN RESPS<2> SETTING POS THEN RETURN
          END
          IF IS.RESERVE THEN RETURN
          IF PRD.REC<3> = 9 AND QO < 0 THEN
             MSG.FLAG = YES
             ACTION.ADD.MSG MSGS,,YES,'%41',,,YES

             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.LOT.MODE:*** Do not allow the user to enter a lot item on a PO/Xfer
          IF EXEMPT THEN
             LOCATE 'LOT.BILL' IN RESPS<2> SETTING POS THEN RETURN
          END
          IF IS.RESERVE THEN RETURN
          * Don't even allow Solar to add a lot item.

          IF PRD.REC<3> = 9 AND (MODE%='P' OR MODE%='T') THEN
             MSG.FLAG = YES
             ACTION.ADD.MSG MSGS,,YES,'%42',,,YES
             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.LOT.REMOTE:*** Do not allow a remote user to enter a lot item
          IF EXEMPT THEN
             LOCATE 'LOT.BILL' IN RESPS<2> SETTING POS THEN RETURN
          END
          IF IS.RESERVE THEN RETURN
          IF PRD.REC<3> = 9 AND REMOTE.CUST THEN
             MSG.FLAG = YES
             ACTION.ADD.MSG MSGS,,YES,'%43',,,YES

             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.LOT.INV.GEN: *** Do not allow a lot item to be placed on an invoiced
          *** gen.
          * We're only concerned with Invoiced Gens.
          IF LED(6)<1,GEN%> # 'I'                            THEN RETURN

          * Do not allow a lot item to be added to an invoiced gen.
          IF PRD.REC<3> = 9 THEN
             MSG.FLAG = YES
             ACTION.ADD.MSG MSGS,,YES,'%623',,,YES
             RETURN TO FINISH
          END

          * We cant let anything be added to an invoiced Lot Item gen.
          IF LED(98)<1,GEN%> THEN
             MSG.FLAG = YES
             ACTION.ADD.MSG MSGS,,YES,'%769',,,YES
             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.LOT.GEN:*** Make sure that the lot item is being entered on the
          *** right gen and message the user letting them know where
          *** to access the lot item.

          IF PRD.REC<3> = 9 THEN
             OE.CHECK.LOT.BILLING OID%,GEN%,YES,MSG.FLAG,MSGS,RESPS
             IF MSG.FLAG THEN RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.CREDIT:*** For sales orders, if the customer has exceeded the credit
          *** limit, user must authorize before being able to proceed
          *** with anything.
          IF EXEMPT THEN
             LOCATE 'CHECK.CREDIT' IN RESPS<2> SETTING POS THEN RETURN
          END

          IF MODE% # 'S' OR IS.RESERVE THEN
             OE.OK = YES
             RETURN
          END

          BT.CN = LED(1)<1,GEN%>
          ST.CN = LED(5)<1,GEN%>
          SOE.CHECK.NO.OE.MSG BT.CN,ST.CN,OE.OK,,MSG.FLAG,MSGS,RESPS,OID%,GEN%,,YES
          IF MSG.FLAG THEN RETURN TO FINISH
          RETURN
*-------------------------------------------------------------------------*
CHECK.PILS:*** Verify that the user is authorized to change the qty on the
           *** original line item based on how the change effects the
           *** projected inventory levels.
          IF EXEMPT THEN
             LOCATE 'PIL.AUTH' IN RESPS<2> SETTING POS THEN RETURN
          END

          IF NEW.LD THEN RETURN
          IF IS.RESERVE THEN RETURN

          IF PN # LD(1) THEN DEL.CHK = YES ELSE DEL.CHK = NO

          OE.PIL.CHECK.BODY MAT OE.VARS,QO,DEL.CHK,PIL.OK,MSG.FLAG,MSGS,RESPS
          IF NOT(PIL.OK) OR MSG.FLAG THEN RETURN TO FINISH

          RETURN
*-------------------------------------------------------------------------*
GET.PN:   *** This attempts to load the product data & set up the LD array
          *** for the next product.

          IF INIT.LDID THEN
             LDID% = INIT.LDID
             LD.GET LDID%
             MAT OLD.LD = MAT LD
          END
          OE.GET.PN OID%,GEN%,PRC.BR,PN,LDID%,QSIGN%,GROUP,MSG.FLAG,MSGS,RESPS
          IF EXEMPT THEN
             LOCATE 'NO.MSGS' IN RESPS<2> SETTING MPOS THEN
                MSGS = ''
                MSG.FLAG = ''
             END
          END
          IF MSG.FLAG THEN RETURN TO FINISH

          RETURN
*-------------------------------------------------------------------------*
CHECK.LOT.QO:*** Lot Billing items should never have a quantity ordered
          *** that is anything other than 1.

          IF PRD(3) = 9 AND QO # 1 THEN
             QO = 1
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.MOD.QO:*** Check to see if we need to modify the QO because of
          *** split Qtys.
          IF EXEMPT THEN
             LOCATE 'CHECK.SPLIT.QTY' IN RESPS<2> SETTING POS THEN RETURN
          END
          MOD.QO    = 'OE.UPD.QO~MOD.QO'
          LOCATE MOD.QO IN RESPS<1> SETTING RPOS ELSE RETURN

          IF SV.QO # QO THEN
             LI.DATA<1,2> = QO
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.SPKG.QO:*** Check to see if we need to modify the QO because of
          *** Minimum sell package qtys

          SPKG.QO    = 'OE.UPD.QO~SPKG.QO'
          LOCATE SPKG.QO IN RESPS<1> SETTING RPOS ELSE RETURN

          IF SV.QO # QO THEN
             LI.DATA<1,2> = QO
          END

          RETURN
*-------------------------------------------------------------------------*
GET.PRICE.PER:*** This gets the price per and makes sure that it is in the
          *** right currency.

          PRICE.PER.GET PER,,,,LED(22)<1,GEN%>
          IF LED(92)<1,GEN%,2> THEN
             PER = PER / OCONV(LED(92)<1,GEN%,2>,'MR4')
          END

          RETURN
*-------------------------------------------------------------------------*
CREATE.NEW.LDID:*** Create the new ledger detail record to add to the
          *** order, or just add the new ldid to the ldid list.
          BEGIN CASE
          CASE INIT.LDID
             OE.GET.LDID.LIST LDID.LIST,OID%,GEN%
             LOCATE INIT.LDID IN LDID.LIST<1> SETTING POS ELSE
                LDID.LIST = INSERT(LDID.LIST,1,LDID_LINE;INIT.LDID)
             END
          CASE NEW.LD OR NEW.NONSTOCK
             OE.GET.LDID.LIST LDID.LIST,OID%,GEN%
             CHK.LIST  = DCOUNT(LDID.LIST,VM)+1
             IF LDID_LINE > CHK.LIST THEN LDID_LINE = CHK.LIST
             LDID.LIST = INSERT(LDID.LIST,1,LDID_LINE;'')

             OE.NEW.LDID OID%,LDID%,LDID.LIST,LDID_LINE
             LDID.LIST<1,LDID_LINE> = LDID%
          CASE OTHERWISE
             * LDID.LIST only needs to be filled in if it needs to
             * be updated by OE.UPDATE.LDID.
             LDID.LIST = ''
          END CASE

          * The LDID.LIST must be saved for circumstances when the
          * 'PIL' warning message is triggered. This is to prevent the
          * LDID.LIST from being wiped out which will need to be intact
          * for this when OE.UPD.QO IS called. The LDID.LIST will be
          * save in the responses array.  This crete routine is not
          * entered again when the 'PIL' check is displayed, so the
          * list is saved to preserve the order of LDID.LIST.
          RESP.POS = DCOUNT(RESPS<1>,VM) + 1
          RESPS<1,RESP.POS>  = 'SAVED.LDID'
          RESPS<2,RESP.POS>  =  LOWER(LDID.LIST)

          RETURN
*-------------------------------------------------------------------------*
CHECK.DUP.LI:*** If there is a duplicate line item on this order, this
          *** routine will display a message letting the user know.
          *** Note: This does _not_ stop the current line item from
          *** being added.
          IF EXEMPT THEN
             LOCATE 'OE.CHK.DUP.LINE.ITEMS' IN RESPS<2> SETTING POS THEN
                RETURN
             END
          END
          IF SKIP.DUP    THEN RETURN
          IF MODE% # 'S' THEN RETURN
          IF PRD(127)    THEN RETURN
          IF IS.RESERVE  THEN RETURN

          * Don't check for lot items.
          IF PRD(3) = 9  THEN RETURN

          READV CHK.DUP FROM CTRLFILE,'OE.DUP.ITEM.CHECK',1 ELSE CHK.DUP=''
          IF NOT(CHK.DUP) THEN RETURN

          OE.CHK.DUP.LINE.ITEMS OID%,GEN%,PN,LDID%,MSGS,RESPS

          RETURN
*-------------------------------------------------------------------------*
CHECK.POE.MA: *** Check to see if there are multiple PO matrices that
          *** we need to display to user so they can select the one they
          *** wish to use.

          * If some actions are being excluded, check to see if this
          * is one of the excluded actions.  If so, don't add to MSGS.
          ACT.ID = 'POE.MATRIX'
          IF EXEMPT THEN
             LOCATE ACT.ID IN RESPS<2> SETTING POS THEN
                RETURN
             END
          END

          *** If this is a purchase order and the control record is set to
          *** display the matrix cells, we need to check for multiple
          *** vendor matrices.
          ORIG.MSGS = MSGS
          IF MODE% = 'P' AND OPEN.VEN.MATRIX$ THEN
             LOCATE ACT.ID IN RESPS<1> SETTING NOTHING ELSE
                ACTION.ADD MSGS,ACT.ID,,,,,QO
                MSG.FLAG = YES
                RETURN TO FINISH
             END
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.GC: *** Check Gift Card prompt.

          IF NOT(PRD(154)<1,1>) THEN RETURN ;* Gift Card Check
          IF IS.RESERVE THEN RETURN
          LOCATE "GC.PRMPT1" IN RESPS<1> SETTING POS THEN
             * Get the first Gift Card Number
             GIFT.NUM1 = RESPS<2,POS>

             * Send back a message if its blank
             IF GIFT.NUM1 = '' THEN
                TEXT = 'Gift Card Number Required'
                ACTION.ADD.MSG MSGS,'GC.ERR1',YES,TEXT,,1,,1,1,,
                MSG.FLAG = YES
                RETURN TO FINISH
             END

             * If verify flag check for a confirmation Gift Card Number
             IF PRD(154)<1,3> THEN

                * Get the second Gift Card number
                LOCATE 'GC.PRMPT2' IN RESPS<1> SETTING POS THEN
                   GIFT.NUM2 = RESPS<2,POS>
                END

                * Send back a message if its blank
                IF GIFT.NUM2 = '' THEN
                   TEXT = 'Gift Card Confirmation Number Required'
                   ACTION.ADD.MSG MSGS,'GC.ERR2',YES,TEXT,,1,,1,1,,
                   MSG.FLAG = YES
                   RETURN TO FINISH
                END

                * Send back a message if the numbers don't match
                IF GIFT.NUM1 # GIFT.NUM2 THEN
                   TEXT = 'Gift Card Numbers Do Not Match'
                   ACTION.ADD.MSG MSGS,'GC.ERR3',YES,TEXT,,1,,1,1,,
                   MSG.FLAG = YES
                   RETURN TO FINISH
                END
             END

             * Send back a message if Gift Card has already been issued.
             READ GIFT.REC FROM GIFTCERTFILE,GIFT.NUM1 THEN
                TEXT = 'Gift Card Already Issued'
                ACTION.ADD.MSG MSGS,'GC.ERR4',YES,TEXT,,1,,1,1,,
                MSG.FLAG = YES
                RETURN TO FINISH
             END

          END ELSE

             * Only allow gift cards in order entry.
             IF MODE% # 'S' THEN
                ACTION.ADD.MSG MSGS,'GC.SOE.ONLY.ERR',YES,'%808',,1,,1,1
                MSG.FLAG = YES
                RETURN TO FINISH
             END

             * Do not allow gift cards on a direct order.
             IF LED(6)<1,GEN%> = 'D' THEN
                ACTION.ADD.MSG MSGS,'GC.SOE.ONLY.ERR',YES,'%809',,1,,1,1
                MSG.FLAG = YES
                RETURN TO FINISH
             END

             * Check for a Quantity of 1
             IF QO # 1 OR QO # '1' THEN
                ACTION.ADD.MSG MSGS,'GC.QO.ERR',YES,'%807',,1,,1,1
                MSG.FLAG = YES
                RETURN TO FINISH
             END

             LGTH = 15
             TEXT = 'Gift Card Number :'
             ACTION.ADD.PROMPT MSGS,'GC.PRMPT1',,TEXT,,,'MCU',LGTH,,

             * If the verification flag is set to 'YES', create
             * a second prompt for verification purposes.
             IF PRD(154)<1,3> THEN
                TEXT = 'Confirm Gift Card Number :'
                ACTION.ADD.PROMPT MSGS,'GC.PRMPT2',,TEXT,,,'MCU',LGTH,,
             END

             MSG.FLAG = YES
             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
SAVE.GC:  *** Save Gift Card information.

          IF MODE% # 'S'        THEN RETURN ;* Only update Sales Orders
          IF NOT(PRD(154)<1,1>) THEN RETURN ;* Gift Card Check

          * Update the comment of the order with the Gift Card number.
          LOCATE '1' IN LD(2) SETTING CPOS ELSE
             CPOS = DCOUNT(LD(2)<1>,VM)+1
             LD(2)<1,CPOS> = 1
          END

          LD3.POS = DCOUNT(LD(3)<1,CPOS>,SVM)+1
          LD(3)<1,CPOS,LD3.POS> = 'Gift Card# : ':GIFT.NUM1

          LD(136) = GIFT.NUM1
          OE.GET.QSIGN QSIGN,OID

          * Update the Change log of the order with the orginal
          * Gift Card Number.
          OE.ADD.COMMENT OID,,'Gift Card# : ':GIFT.NUM1

          * Update the Gift Card file with the Gift Card information.
          GIFT.REC    = ''
          GIFT.REC<1> = OID.DATA$<4>                 ;* Ship-to
          GIFT.VALUE  = ICONV(OCONV(LD(8)<1,GEN%>,'MR9'),"MR2")
          GIFT.REC<2> = GIFT.VALUE
          GIFT.REC<3> = GIFT.VALUE
          GIFT.REC<4> = LED(9)<1,GEN%>               ;* Gift date

          EXP.DAYS = PRD.REC<154,2>
          IF EXP.DAYS = '' THEN
             GIFT.REC<5> = ''
          END ELSE
             GIFT.REC<5> = GIFT.REC<4> + EXP.DAYS    ;* Expire date
          END

          GIFT.REC<6>  = PRC.BR                      ;* Purchase branch
          GIFT.REC<7>  = OID                         ;* Purchase order
          GIFT.REC<10> = LED(2)<1,GEN%,3>:'~':PRD(2) ;* GL account
          WRITE GIFT.REC ON GIFTCERTFILE,GIFT.NUM1

          LOCATE 'GC.PRMPT1' IN RESPS<1> SETTING POS THEN
             RESPS = DELETE(RESPS,1,POS)
             RESPS = DELETE(RESPS,2,POS)
          END

          * Verify Gift Card Flag
          IF PRD.REC<154,3> THEN
             LOCATE 'GC.PRMPT2' IN RESPS<1> SETTING POS THEN
                RESPS = DELETE(RESPS,1,POS)
                RESPS = DELETE(RESPS,2,POS)
             END
          END

          RETURN
*-------------------------------------------------------------------------*
SET.ADDL.DATA:*** If there was additional line item information, setup LD

          IF ADDL.DATA # '' THEN
             TCT = DCOUNT(ADDL.DATA,AM)
             FOR J = 2 TO TCT
                IF ADDL.DATA<J> THEN LD(J) = ADDL.DATA<J>
             NEXT J
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.DUP.OE:*** Check for an existing order with this line item on it.
          *** Don't check for duplicate lot billing items.
          IF EXEMPT THEN
             LOCATE 'DUP.ORDER' IN RESPS<2> SETTING POS THEN RETURN
          END
          IF IS.RESERVE THEN RETURN
          IF (MODE%='S') AND (QO > 0) AND PRD(3) # "9" THEN
             SOE.CHK.DUP.ORDER OID%,GEN%,DUP.OK,,,MSG.FLAG,MSGS,RESPS
             IF MSG.FLAG THEN RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.INVALID.PRD:*** Check to make sure that all of the required product
          *** info exists on the selected line item.

          IF EXEMPT THEN
             LOCATE 'CHECK.PRD' IN RESPS<2> SETTING POS THEN RETURN
          END
          PRD.ERR = NO
          READ GL.TYPES FROM CTRLFILE,'GL.PRODUCT.TYPE' ELSE GL.TYPES=''
          GL.ERR = NO

          * If the site has valid GL Types, then make sure each product
          * entered has a valid GL Type. If the site does not use GL Type
          * Types, don't check for this when checking for Invalid Data.
          IF GL.TYPES<1> THEN
             IF PRD.REC<2> = '' THEN
                GL.ERR = YES
             END ELSE
                GL.ERR = NO
             END
          END ELSE
             GL.ERR = NO
          END

          * GL.ERR = PRD.REC<2>: GL Types
          * PRD.REC<7>: Unit of Measure
          * PRD.REC<9>: Price Line
          IF GL.ERR OR PRD.REC<7> = '' OR PRD.REC<9> = '' THEN
                PROD.DESC = PRD.REC<1>
                CONVERT VM TO ' ' IN PROD.DESC

                MSG.FLAG  = YES
                MSG.ID    = '%51'
                MSG.ID<2> = PN[1,7]
                MSG.ID<3> = PROD.DESC[1,30]
                ACTION.ADD.MSG MSGS,,YES,MSG.ID,,YES,YES,2,3
                RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
GET.TYPE.LOC: *** Used to override

          COMMT = YES
          IF EXEMPT THEN
             LOCATE 'NO.COMMT' IN RESPS<2> SETTING POS THEN COMMT = NO
          END
          IF COMMT THEN
             GOSUB TLOC.COMMT
          END ELSE
             GOSUB TLOC.NO.COMMT
          END

          OE.UPDATE.LDID LDID%,OID%,GEN%,LOG.MV%,QSIGN%

          RETURN
*-------------------------------------------------------------------------*
TLOC.COMMT:*** Used to override type/location, stock and non stock qtys
          *** when the exempt flag 'NO.COMMT' is Not listed.

          IF TYP.LOC # '' AND TYP.LOC[1,1] # 'D' THEN
             STK.ORD.TOT  = SUM(LD(5)<1,GEN%>) * QSIGN%
             NSTK.ORD.TOT = SUM(LD(6)<1,GEN%>) * QSIGN%
             IF TYP.LOC[1,1] = 'S' THEN
                IF QTY.DIFF THEN
                   IF STK.ORD.TOT > QTY.DIFF THEN
                      STK.ORD.TOT = STK.ORD.TOT - QTY.DIFF
                   END
                END ELSE
                   QTY.DIFF = 0
                END

                NEW.QTY       = STK.ORD.TOT + NSTK.ORD.TOT
                LD(5)<1,GEN%> = NEW.QTY * QSIGN%
                LD(6)<1,GEN%> = ''

                IF QTY.DIFF THEN
                   LD(5)<1,GEN%,2> = QTY.DIFF * QSIGN%
                END
             END ELSE
                IF QTY.DIFF THEN
                   IF NSTK.ORD.TOT > QTY.DIFF THEN
                      NSTK.ORD.TOT = NSTK.ORD.TOT - QTY.DIFF
                   END
                END ELSE
                   QTY.DIFF = 0
                END

                NEW.QTY       = STK.ORD.TOT + NSTK.ORD.TOT
                LD(6)<1,GEN%> = NEW.QTY * QSIGN%
                LD(5)<1,GEN%> = ''

                IF QTY.DIFF THEN
                   LD(5)<1,GEN%,2> = QTY.DIFF * QSIGN%
                END
             END

             LD(7)<1,GEN%> = TYP.LOC
             IF QTY.DIFF THEN
                LD(7)<1,GEN%,2> = 'S~'
             END
          END

          * If Mode is 'Transfer'
          IF MODE% = 'T' THEN
             IF RCV.TYPE = '' THEN RCV.TYPE = 'S'
             STK.XFER.TOT  = SUM(LD(5)<1,2>)
             NSTK.XFER.TOT = SUM(LD(6)<1,2>)
             IF RCV.TYPE = 'S' THEN
                IF QTY.DIFF AND STK.XFER.TOT > QTY.DIFF THEN
                   STK.XFER.TOT -= QTY.DIFF
                END

                LD(5)<1,2> = -STK.XFER.TOT * QSIGN%
                IF QTY.DIFF THEN
                   LD(5)<1,2,2> = -QTY.DIFF * QSIGN%
                   QTY.DIFF.CT = DCOUNT(LD(5)<1,1>,SVM)
                   LD(5)<1,1,QTY.DIFF.CT> += QTY.DIFF * QSIGN%
                END
             END ELSE
                IF QTY.DIFF AND NSTK.XFER.TOT > QTY.DIFF THEN
                   NSTK.XFER.TOT -= QTY.DIFF
                END

                LD(6)<1,2> = -NSTK.XFER.TOT * QSIGN%
                IF QTY.DIFF THEN
                   LD(5)<1,2,2> = -QTY.DIFF * QSIGN%
                   QTY.DIFF.CT = DCOUNT(LD(5)<1,1>,SVM)
                   LD(5)<1,1,QTY.DIFF.CT> += QTY.DIFF * QSIGN%
                END
             END

             LD(7)<1,2> = RCV.TYPE:'~':RCV.LOCA
             IF QTY.DIFF THEN
                LD(7)<1,2,2> = 'S~'
             END
          END

          IF QTY.DIFF THEN
             LD(4) += QTY.DIFF * QSIGN%
          END

          RETURN
*-------------------------------------------------------------------------*
TLOC.NO.COMMT:*** Used to override type/location, total qty ordered,
          *** stock and non stock qtys when the exempt flag 'NO.COMMT'
          *** is listed.
          LD(4) = QO * QSIGN%
          IF TYP.LOC = '' THEN TYP.LOC = 'S'
          IF TYP.LOC[1,1] # 'D' THEN
             IF TYP.LOC[1,1] = 'S' THEN
                LD(5)<1,GEN%> = QO * QSIGN%
                IF QTY.DIFF THEN
                   QTY.DIFF.CT = DCOUNT(LD(5)<1,GEN%>,SVM)
                   LD(5)<1,GEN%,QTY.DIFF.CT> += QTY.DIFF * QSIGN%
                END
             END ELSE
                LD(6)<1,GEN%> = QO * QSIGN%
                IF QTY.DIFF THEN
                   QTY.DIFF.CT = DCOUNT(LD(5)<1,GEN%>,SVM)
                   LD(5)<1,GEN%,QTY.DIFF.CT> += QTY.DIFF * QSIGN%
                END
             END
             LD(7)<1,GEN%> = TYP.LOC
             IF QTY.DIFF THEN
                LD(7)<1,GEN%,QTY.DIFF.CT> = 'S~'
             END
          END

          IF RCV.TYPE = '' THEN RCV.TYPE = 'S'
          IF RCV.TYPE = 'S' THEN
             LD(5)<1,2> = -QO * QSIGN%
             IF QTY.DIFF THEN
                LD(5)<1,2,2> = -QTY.DIFF * QSIGN%
             END
          END ELSE
             LD(6)<1,2> = -QO * QSIGN%
             IF QTY.DIFF THEN
                LD(5)<1,2,2> = -QTY.DIFF * QSIGN%
             END
          END
          LD(7)<1,2> = RCV.TYPE:'~':RCV.LOCA
          IF QTY.DIFF THEN
             LD(7)<1,2,2> = 'S~'
             LD(4) += QTY.DIFF * QSIGN%
          END

          RETURN
*-------------------------------------------------------------------------*
PRICE.OVERRIDE:*** If a price override is specified for the current line
          *** item, this will applie it.
          IF PRICE.OVRD = '' THEN RETURN
          IF PRICE.OVRD  = '!' THEN RETURN

          * Make it have the proper decimal places.
          PRICE.OVRD     = ICONV(OCONV(PRICE.OVRD,'MR3'),'MR9')

          * If we are dealing with a lot item, the Price Override sets
          * the Lot Item Price.
          IF PRD(3)      = 9 THEN
             LD(67)<1,1> = PRICE.OVRD
             LD(15)      = ''
          END ELSE
             PRICE.OVRD  = ICONV(PRICE.OVRD/PER,'MR0')
             OE.REPRICE.GENS OID%,GEN%,LDID%,PRICE.OVRD,,QSIGN%,YES,'@@',,,AM:YES
             * Only calc freight factor on a purchase order where the
             * qty ordered is greater than zero - we don't want to
             * cap freight on a return item
             IF MODE%    = 'P' AND LD(4) > 0 THEN
                * They must have freight factor specified.
                FF.METH = (LED(93)<1,GEN%,1>[1,1] = 'F')
                IF FF.METH THEN
                   OE.CALC.FF LD(1),LD(8)<1,GEN%>,LED(2)<1,GEN%,1>,FGHT
                   LD(34)<1,GEN%> = FGHT
                END
             END
          END

          OE.UPDATE.LDID LDID%,OID%,GEN%,LOG.MV%,QSIGN%

          RETURN
*-------------------------------------------------------------------------*
COGS.OVERRIDE:*** If a cost override is specified for the current line
          *** this will apply it.
          IF COST.OVRD   = '' THEN RETURN
          IF COST.OVRD   = '!' THEN RETURN

          COST.OVRD      = ICONV(OCONV(COST.OVRD,'MR3'),'MR9')

          IF PRD(3)      = 9 THEN
             LD(67)<1,2> = COST.OVRD
             LD(29)      = ''
          END ELSE
             COST.OVRD=ICONV(COST.OVRD/PER,'MR0')
             IF MODE%    = 'T' THEN POVRD = 'T' ELSE POVRD = YES
             OE.UPD.COGS GEN%,POVRD,COST.OVRD,,OID%
          END

          OE.UPDATE.LDID LDID%,OID%,GEN%,LOG.MV%,QSIGN%

          RETURN
*-------------------------------------------------------------------------*
COMM.OVERRIDE:*** If a cost override is specified for the current line
          *** this will apply it.
          IF COMM.OVRD   = '' THEN RETURN
          IF COMM.OVRD   = '!' THEN RETURN

          COMM.OVRD      = ICONV(OCONV(COMM.OVRD,'MR3'),'MR9')

          IF PRD(3)      = 9 THEN RETURN

          COMM.OVRD      = ICONV(COMM.OVRD/PER,'MR0')
          IF MODE%       = 'T' THEN POVRD = 'T' ELSE POVRD = YES
          OE.UPD.COMM.COST GEN%,POVRD,COMM.OVRD,,OID%

          OE.UPDATE.LDID LDID%,OID%,GEN%,LOG.MV%,QSIGN%

          RETURN
*-------------------------------------------------------------------------*
UPD.LINE.FGHT: ***  redistribute the line freight when a line item is
          ***  added.
          IF EXEMPT THEN
             LOCATE 'UPD.FGHT' IN RESPS<2> SETTING POS THEN RETURN
          END
          IF NOT(NEW.LD) THEN RETURN
          IF NOT(MODE% = 'P') THEN RETURN
          OE.CALC.FGHT OID%,GEN%,FGHT
          POE.UPD.LINE.FGHT OID%,GEN%,FGHT
          LD.GET LDID%
          MAT OLD.LD = MAT LD

          RETURN
*-------------------------------------------------------------------------*
ADD.COMMENT:*** Add the comment for change log as and audit trail.
          ACT.ID  = 'CHG.LOG.COMMENT'
          IF EXEMPT THEN
             LOCATE ACT.ID IN RESPS<2> SETTING POS THEN RETURN
          END
          IF OLD.LD(1)#'' AND OLD.LD(1)#LD(1) THEN
             IF NEW.ORDER% THEN
                * figure out whether to log the changes based off the
                * control record.
                READ LOG.PRD.CHG FROM CTRLFILE,'OE.LOG.PRD.CHNGS' ELSE
                   LOG.PRD.CHG = ''
                END
             END ELSE
                LOG.PRD.CHG = YES
             END

             IF LOG.PRD.CHG THEN
                READV ODESC FROM PRDFILE,OLD.LD(1),1 ELSE ODESC = OLD.LD(1)
                MSG.ID    = '%67' ;* Changed Product on Line...
                MSG.ID<2> = LDID%
                MSG.ID<3> = ODESC<1,1>[1,30]
                MSG.ID<4> = PRD(1)<1,1>[1,30]
                OE.ADD.COMMENT OID%,LOG.MV%,MSG.ID
             END
          END

          RETURN
*-------------------------------------------------------------------------*
ADD.LINE.COMMENT: *** Appropriately add comments to LD. If there is
          *** a SSVM 2, then that value holds the comment type, if not,
          *** assume the comment type is 'General Comment'.
          IF CMNTS THEN
             CSVM.CT = DCOUNT(CMNTS,SVM)
             FOR SS = 1 TO CSVM.CT
                ONE.CMT = RAISE(RAISE(CMNTS<1,1,SS>))
                IF ONE.CMT<1,2> THEN ONE.TYP=ONE.CMT<1,2> ELSE ONE.TYP=1
                ONE.CMT = ONE.CMT<1,1>
                LOCATE ONE.TYP IN LD(2)<1> SETTING CPOS ELSE
                   CPOS = DCOUNT(LD(2)<1>,VM)+1
                   LD(2)<1,CPOS> = ONE.TYP
                END
                LD3.POS = DCOUNT(LD(3)<1,CPOS>,SVM)+1
                LD(3)<1,CPOS,LD3.POS> = ONE.CMT
             NEXT SS


             OE.UPDATE.LDID LDID%,OID%,GEN%,LOG.MV%,QSIGN%

          END

          RETURN
*-------------------------------------------------------------------------*
UPD.POLE.DISP: *** Updates pole display with new line item information

          IF JAVA.PROC$ THEN RETURN

          ACT.TYPE = 'POLE.DISP'

          DATA    = PRD(1)<1,1>
          DATA<2> = OCONV(LD(8)<1,GEN%>,'MR9') "R2$"

          ACTION.ADD MSGS,ACT.TYPE,,,,,LOWER(DATA)

          RETURN
*-------------------------------------------------------------------------*
CHECK.PROD.RELS: *** Add related products to the order.

          *** If the current line is being substituted in Solar, bypass
          *** product relationship logic -- Solar is taking care of adding
          *** any related items.
          IF SUB.EXISTING THEN RETURN
          IF IS.RESERVE   THEN RETURN

          *** Get subs data. Although substitutes are available in PRD,
          *** this subroutine only returns subs valid for the current
          *** branch.
          OE.GET.SUBS OID%,GEN%,SUBS.PNS

          *** Get product relationship data. Although product
          *** relationships are in PRD, this subroutine only
          *** returns items valid for the current branch.
          OE.GET.PROD.RELS OID%,GEN%,PROD.REL.PNS,PROD.REL.QTYS,PROD.REL.TYPES,PROD.REL.REQD

          *** Check availability of the parent product, determines how we
          *** choose the mode.
          STK.BR = LED(2)<1,GEN%,2>

          AVAIL.AMT = CALC.AVAIL(LED(4)<1,GEN%>,STK.BR,LD(1)<1,GEN%>)

          * Checking avail quantity with the product's purchase qty
          IF AVAIL.AMT >= QO THEN
             MODE.TO.USE = 2
          END ELSE
             MODE.TO.USE = 3
          END

          *** Get display mode settings for the different relationship
          *** types from the control record
          READ DISP.MODES FROM CTRLFILE,"PROD.REL.DISP.MODE" ELSE DISP.MODES = ""

          *** If the product has substitutes, check the subs display mode.
          *** The subs display mode is always value 2.
          IF SUBS.PNS # "" THEN
             IF DISP.MODES<MODE.TO.USE,2> = 'Review' THEN RETURN
          END

          *** Go through the related product types and display settings.
          *** If any related product's type is set to Review, related
          *** item are not automatically added to the order so return.
          PROD.REL.CNT = DCOUNT(PROD.REL.TYPES,VM)
          FOR I = 1 TO PROD.REL.CNT

             LOCATE PROD.REL.TYPES<1,I> IN DISP.MODES<1> SETTING LOC THEN
                *** If the product relationship type is in the control
                *** record without a display type, use the default.
                IF DISP.MODES<MODE.TO.USE,LOC> = "" THEN LOC = 1
             END ELSE LOC = 1

             IF DISP.MODES<MODE.TO.USE,LOC> = 'Review' THEN RETURN

             * If the amount is negative after purchase
             * and mode is 'None', then it will get checked after the
             * Product Availability screen.

             IF (DISP.MODES<MODE.TO.USE,LOC> = 'None' AND AVAIL.AMT < QO) THEN RETURN
          NEXT REL.PRD

          PROD.REL.RETURN.PNS = ''
          PROD.REL.RETURN.QTYS = ''

          *** None of the relationship types have a display mode of
          *** Review, so go through each related item and see if it needs
          *** to be added to the order.
          PROD.REL.CNT = DCOUNT(PROD.REL.PNS,VM)
          FOR REL.PRD = 1 TO PROD.REL.CNT

             REL.PRD.PN   = PROD.REL.PNS<1,REL.PRD>
             REL.PRD.QTY  = PROD.REL.QTYS<1,REL.PRD> * QO
             REL.PRD.REQD = PROD.REL.REQD<1,REL.PRD>
             REL.PRD.TYPE = PROD.REL.TYPES<1,REL.PRD>

             IF REL.PRD.PN = PARENT.PN THEN CONTINUE

             LOCATE REL.PRD.TYPE IN DISP.MODES<1> SETTING LOC THEN
                *** If the product relationship type is in the control record
                *** without a display type, use the default.
                IF DISP.MODES<MODE.TO.USE,LOC> = "" THEN LOC = 1
             END ELSE LOC = 1

             DISP.MODE = DISP.MODES<MODE.TO.USE,LOC>

             *** 'Reminder' and 'None' should only add required,
             *** 'Auto Fill' should add all.
             IF NOT(REL.PRD.REQD) AND (DISP.MODE = 'None' OR DISP.MODE='Reminder') THEN CONTINUE

             ADD.TYPE = 'ADD.LI'
             OE.GET.LDID.LIST LLIST,OID%,GEN%
             LLIST = LDID.LIST
             LOCATE LDID% IN LLIST<1> SETTING NEW.POS ELSE NEW.POS=''
             IF NEW.POS THEN NEW.POS += 1
             IF REL.PRD.QTY+0 >= 0 THEN
                ADD.DATA = '' ;* Data needed for OE.ADD.LINES.
                ADD.DATA<1, 1> = REL.PRD.PN            ;* PN
                ADD.DATA<1, 2> = REL.PRD.QTY           ;* QO
                ADD.DATA<1, 3> = ''                    ;* LARGEST.UM
                ADD.DATA<1, 4> = ''                    ;* ALLOC.ZONE
                ADD.DATA<1, 5> = YES                   ;* INS.LINE
                ADD.DATA<1, 6> = NEW.POS               ;* LINE.NUM
                ADD.DATA<1, 7> = ''                    ;* PRC.OVRD
                ADD.DATA<1, 8> = ''                    ;* CST.OVRD
                ADD.DATA<1, 9,132> = LDID%             ;* ADDL.DATA
                ADD.DATA<1,10> = ''                    ;* INIT.LDID
                ADD.DATA<1,11> = YES                   ;* SKIP.DUP
                ACTION.ADD MSGS,ADD.TYPE,,,,,ADD.DATA
                MSG.FLAG = YES
             END ELSE
                PROD.REL.RETURN.PNS<REL.PRD>  = REL.PRD.PN
                PROD.REL.RETURN.QTYS<REL.PRD> = REL.PRD.QTY
             END
          NEXT REL.PRD


                    UT.OPEN.FILE "LEDGER.GPS",LEDGPSFILE,ERR.MSG
READV CHK.OUT.DATE FROM LEDGPSFILE,OID,25 ELSE CHK.OUT.DATE = ""

          IF PROD.REL.RETURN.PNS AND CHK.OUT.DATE='' THEN
             ACT.ID = 'RELATED.ITEM.RETURN'
             LOCATE ACT.ID IN RESPS<1> SETTING RPOS THEN
                TPNS  = RAISE(RAISE(RAISE(RESPS<2,RPOS,1>)))
                TQTYS = RAISE(RAISE(RAISE(RESPS<2,RPOS,2>)))
                IF TPNS # '' THEN
                   CT = DCOUNT(TPNS,AM)
                   FOR I = 1 TO CT
                      LOCATE  TPNS<I> IN PROD.REL.RETURN.PNS SETTING TPOS THEN
                         *if there's a saved ldid list, use it to compute
                         *the position
                         LOCATE 'SAVED.LDID' IN RESPS<1> SETTING POS THEN
                            LDID.LIST = RAISE(RESPS<2,POS>)
                         END ELSE
                            OE.GET.LDID.LIST LLIST,OID%,GEN%
                         END
                         LLIST = LDID.LIST
                         LOCATE LDID% IN LLIST<1> SETTING NEW.POS ELSE NEW.POS=''
                         IF NEW.POS THEN
                            NEW.POS += 1
                         END
                         ADD.DATA = '' ;* Data needed for OE.ADD.LINES.
                         ADD.DATA<1, 1> = TPNS<I>         ;* PN
                         ADD.DATA<1, 2> = TQTYS<I>        ;* QO
                         ADD.DATA<1, 3> = ''              ;* LARGEST.UM
                         ADD.DATA<1, 4> = ''              ;* ALLOC.ZONE
                         ADD.DATA<1, 5> = YES             ;* INS.LINE
                         ADD.DATA<1, 6> = NEW.POS         ;* LINE.NUM
                         ADD.DATA<1, 7> = ''              ;* PRC.OVRD
                         ADD.DATA<1, 8> = ''              ;* CST.OVRD
                         ADD.DATA<1, 9,132> = LDID%       ;* ADDL.DATA
                         ADD.DATA<1,10> = ''              ;* INIT.LDID
                         ADD.DATA<1,11> = YES             ;* SKIP.DUP
                         ACTION.ADD MSGS,'ADD.LI',,,,,ADD.DATA
                         MSG.FLAG       = YES
                      END
                   NEXT I
                END
             END ELSE
                DATA      = LD(1)
                DATA<1,2> = ABS(QO)
                ACTION.ADD MSGS,ACT.ID,,,,,DATA
                MSG.FLAG = YES
                RETURN TO FINISH
             END
          END

          * If there are related products add them to the order.
          IF MSG.FLAG THEN
             OE.UPD.QO MAT OE.VARS,MAT OE.SFLAGS,GROUP,QO,LARGEST.UM,ALLOC.ZONE,LDID.LIST,UPD.LOC,MSG.FLAG,MSGS,RESPS
             RETURN TO FINISH
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.BO.KITS:  *** Check availability for kit components

          IF PRD(106) THEN RETURN
          IF QO + 0 < 0 THEN RETURN; * No splitting kits on returns

          * If this is a kit, check the availability of each component
          BO.AVAIL = ''
          BO.QTYS  = ''
          BO.COMPS = ''
          SPLIT.KIT = NO
          KEY.COMPS = ''
          IF PRD(53) THEN
             FOR CMP = 1 TO DCOUNT(PRD(53),VM)
                IF PRD(145)<1,CMP> # "" AND PRD(145)<1,CMP> # 0 THEN
                   SPLIT.KIT = YES
                END ELSE
                   KEY.COMPS<-1> = PRD(53)<1,CMP>
                END
             NEXT CMP
          END
          IF SPLIT.KIT THEN
             AS.OF.DATE = LED(9)<1,GEN%>
             OE.CHECK.BO.KIT.COMPS LD(1),LD(4),BO.COMPS,BO.QTYS,BO.AVAIL,SHIP.BR,QO,AS.OF.DATE
          END ELSE
             RETURN
          END
          IF BO.AVAIL = '' THEN RETURN
          * Get alternate description and comments for backorder kit
          * line items
          KIT.DESC = PRD(1)
          ALT.DESC = 'PARTIAL: ':TRIM(KIT.DESC<1,1>)
          READ BO.CMT FROM CTRLFILE,'BO.PARTIAL.KIT.COMMENT' ELSE
             BO.CMT = ''
          END
          IF BO.CMT # '' THEN BO.CMT = TRIM(BO.CMT)
          * Loop through each bo date and add a line item for each
          * partial kit
          BO.CT = DCOUNT(BO.AVAIL,VM)
          SV.NEW.POS = ''
          FOR BO = 1 TO BO.CT
             AVAIL = BO.AVAIL<1,BO>
             COMPS = BO.COMPS<1,BO>
             QTYS  = BO.QTYS<1,BO>

             KEY.CT = DCOUNT(KEY.COMPS,AM)
             FOR KEY = 1 TO KEY.CT
                LOCATE KEY.COMPS<1,KEY> IN COMPS<1,1> SETTING JUNK THEN
                   GOTO NXT.BO
                END
             NEXT KEY

             ADD.TYPE = 'ADD.LI'

             OE.GET.LDID.LIST LLIST,OID%,GEN%
             LOCATE LDID% IN LLIST<1> SETTING NEW.POS ELSE NULL
             IF NEW.POS THEN NEW.POS += 1

             ADD.DATA = ''
             ADD.DATA<1,1> = LD(1)                  ;* PN
             ADD.DATA<1,2> = QO                     ;* ORD QTY
             ADD.DATA<1, 3> = ''                    ;* LARGEST.UM
             ADD.DATA<1, 4> = ''                    ;* ALLOC.ZONE
             ADD.DATA<1, 5> = YES                   ;* INS.LINE
             ADD.DATA<1, 6> = NEW.POS               ;* LINE.NUM
             ADD.DATA<1, 7> = ''                    ;* PRC.OVRD
             ADD.DATA<1, 8> = ''                    ;* CST.OVRD
             * additional data
             ADD.DATA<1,9,31> = LOWER(COMPS)        ;* COMPONENTS
             ADD.DATA<1,9,30> = LOWER(QTYS)         ;* COMPONENT QTYS
             ADD.DATA<1,9,124> = LDID%              ;* LDID FOR KEY COMPS
             ADD.DATA<1,10> = ''                    ;* INIT.LDID
             ADD.DATA<1,11> = YES                   ;* SKIP.DUP
             IF BO.CMT # '' THEN
                ADD.DATA<1,9,3> = BO.CMT:SSVM:ALT.DESC ;* COMMENTS
                ADD.DATA<1,9,2> = '1':SSVM:'2'         ;* COMMENTS
             END ELSE
                ADD.DATA<1,9,3> = ALT.DESC          ;* COMMENTS
                ADD.DATA<1,9,2> = '2'               ;* COMMENTS
             END
             ACTION.ADD MSGS,ADD.TYPE,,,,,ADD.DATA
             MSG.FLAG       = YES
             RESP.CT = DCOUNT(RESPS<1>,VM)
             RESPS<1,RESP.CT+1> = "ADDING.PARTIAL.KIT"
             * subtract backorderd components from this ld
             COMP.CNT = DCOUNT(COMPS,SVM)
             FOR CMP = 1 TO COMP.CNT
                LOCATE COMPS<1,1,CMP> IN LD(31)<1> SETTING CPOS THEN
                   IF QTYS<1,1,CMP> >= 0 THEN
                      LD(30)<1,CPOS> -= QTYS<1,1,CMP>
                   END ELSE
                      LD(30)<1,CPOS> += QTYS<1,1,CMP>
                   END
                   IF LD(30)<1,CPOS> <= 0 THEN
                      LD(30) = DELETE(LD(30),1,CPOS)
                      LD(31) = DELETE(LD(31),1,CPOS)
                   END
                END
             NEXT CMP
NXT.BO:   NEXT BO
          RETURN
*-------------------------------------------------------------------------*
CHECK.RET:*** If we are attempting to enter a return item check to
          *** make sure there are not already positive Qty items on the
          *** order.  (This only matters if the jurisdiction code or
          *** control file item are set to use original sales order ship
          *** date to get the tax rate for the return
          TAXCD = LED(79)<1,GEN%,1>
          MATREAD TAX FROM TAXFILE,TAXCD ELSE MAT TAX=''
          IF TAX(16) = '' THEN
             READ ORIG.SALE FROM CTRLFILE,'RETURN.TAX.RATE' ELSE
                ORIG.SALE = ''
             END
          END ELSE
             ORIG.SALE = TAX(16)
          END
          IF ORIG.SALE THEN
             OE.GET.LDID.LIST LLIST,OID%,GEN%
             IF LLIST # "" THEN
                MATBUILD SAVE.LD FROM LD
                FOR LN = 1 TO DCOUNT(LLIST,VM)
                   LD.GET LLIST<1,LN>
                   ADD.MSG = NO
                   IF QO < 0 AND LD(4)+0 < 0 THEN ADD.MSG = YES
                   IF QO > 0 AND LD(4)+0 > 0 THEN ADD.MSG = YES
                   IF ADD.MSG THEN
                      MSG.FLAG  = YES
                      MSG.ID    = '%441'
                      ACTION.ADD.MSG MSGS,,YES,MSG.ID,,1,1,5,3
                      RETURN TO FINISH
                   END
                NEXT LN
                MATPARSE LD FROM SAVE.LD
             END
          END

          RETURN
*-------------------------------------------------------------------------*
!TSMITH~12/23/16~14:49
