          SUBROUTINE (ORD.ID,GEN,OLDID,LDIDS,TOL.CNT,SUBR.NAME,FORM,ISPEC,QTYP,UID,DDE.SUBR,BOX.QTY)
** Version# 45.0001[13] - 09/23/2013 - 04:31pm - TSMITH - eclipse
*** V45.0001 Change - Custom Coding . - 09/23/2013 - TSMITH - eclipse

*** Subroutine - UD.DOC.PRINT.ONE
*-------------------------------------------------------------------------*
*** This subroutine will print or download one of the user-defined
*** documents.
*-------------------------------------------------------------------------*
*** Parameters
***  OID - the id of the order that the document is being printed  (IN)
***  GEN - the current generation of that order                    (IN)
***  OLDID - The line item that the user was on when this program  (IN)
***          was called.
***          However, if call originated at
***          Warehouse Picking Confirmation screen then
***          the following information is encoded:
***           OLDID<1,1> = 'PICK.CONF'   - String to identify
***                                        source of call
***           OLDID<1,2> = TOTAL.PKG.CNT - Total package count
***                                        defined on that screen
***  LDIDS - all the line items on the order (for this gen)        (IN)
***  TOL.CNT - the number of labels that need to be printed        (IN)
***          TOL.CNT<1> contains the number of labels to print.
***          TOL.CNT<2> MAY contain a 'Y' if the user changed
***                     the BEST GUESS of the numbber of labels
***                     to print.
***  SUBR.NAME - The subroutine to call that will handle the       (IN)
***              formatting
***  FORM - The form type for this document                        (IN)
***  ISPEC - Label Type (Item-Specific, Order-Specific, etc...)    (IN)
***          'IM' = Item  Specific, Multi-Call
***          'IS' = Item  Specific, Single-Call
***          'OM' = Order Specific, Multi-Call
***          'OS' = Order Specific, Single-Call
***          'NO' = No autolooping ==> ALWAYS ONLY 1 Label
***  QTYP - An integer indicating the TYPE of label                (IN/OUT)
***         printing selected by the user. The set of integer
***         Constants to be used for this variable are
***         defined in UD.DOC.PRINT.GET.SELCTS.
***  UID - Additional Data                                         (IN)
***  DDE.SUBR - the name of the subroutine that should be called   (IN)
***             after the file is downloaded to the user's PC
***             (if the form type is DOWNLOAD)
***  BOX.QTY - The number of items that can fit in a box.          (IN)
*-------------------------------------------------------------------------*
*** Common Vars:
***  LD() and LED() should be current.
*-------------------------------------------------------------------------*
          GOSUB INIT

          OID = ORD.ID<1,1>
          IF OID # '' AND ORD.ID<1,2> # '' THEN
             MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ""
             IF LED(8)<1,GEN> THEN
                LDIDS = RAISE(LED(48)<1,GEN>)
             END ELSE
                LDIDS = LED(49)
             END

             IF ISPEC[1,1] = "I" THEN
                QTYP = SELCT.VALUE.ALL.ITEMS
             END ELSE
                QTYP = SELCT.VALUE.ORDER.ONLY
             END
          END

          * The OLDID may have some encoded information from the Warehouse
          * Picking Confirmation screen.  Break out this information
          * if it exists.
          IF OLDID<1,1> = 'PICK.CONF' THEN
             * This call originated at the Warehouse Picking Confirmation
             * screen.  There is not a item that can be selected so...
             SELECTED.LDID = ''
          END ELSE
             * This call did NOT originate at the Warehouse Picking
             * Confirmation screen.  The user was on an item when this
             * label printing was selected.
             SELECTED.LDID = OLDID<1,1>     ;* Use <1,1> just to be safe
          END

          *************************************************************
          * Very special case here.  Cut Products have very special needs
          * for label printing.  We are not going to use the standard
          * label printing process.  Call the routine and get out of here
          * when finished.
          *************************************************************
          PGM = SUBR.NAME
          IF UPCASE(PGM[1,LEN('LABEL.CUT.PROD')]) = "LABEL.CUT.PROD" THEN
             CUT.LDID = OLDID
             IF QTYP # SELCT.VALUE.CURRENT.ITEM THEN
                CUT.LDID = ''
             END
             CALL @SUBR.NAME(OID,GEN,CUT.LDID,LDIDS,TOL.CNT,UID)
             GOTO FINISH
          END

          BOX.FLAG = NO
          DRPT     = ''
          QTY.OVRD = ''
          SV.UID   = UID
          LBL.CNTR = 0
          LQTY = ''
          BEGIN CASE
          CASE FORM = 'None' OR FORM = ''
          CASE FORM = 'DOWNLOAD' OR FORM = 'HOLD' OR FORM = ''
             DRPT<27> = 'HOLD'
             TITLE    = SUBR.NAME
             PRINTER.ON 250,TITLE,DOC.ID,RPT.DFLT=DRPT
          CASE FORM = 'VIEW'
             DRPT<27> = 'VIEW'
             TITLE    = SUBR.NAME
             PRINTER.ON 250,TITLE,DOC.ID,RPT.DFLT=DRPT
           CASE OTHERWISE
             PRINTER.ON FORM
          END CASE

          OE.GET.QSIGN QSIGN,OID,GEN
          LBL.QTY = 1

          *---------------------------------------------------------------*
          * If allowed, print a **START** label before we print the
          * desired labels.
          IF ISPEC#'NO' AND ISPEC#'' THEN
             LDID = 'START'; LBL.QTY=1; GOSUB PRT.ONE
          END

          *---------------------------------------------------------------*
          * Print the desired label(s).

          * Save a copy of the label type (aka spec) so we can change it
          * without affecting what was passed in.
          ISPEC.SV = ISPEC

          * If this is an Order Only from the Warehouse Picking
          * Confirmation screen, we need some special processing.
          IF (OLDID<1,1>='PICK.CONF') AND  (QTYP=SELCT.VALUE.ORDER.ONLY) THEN
             * For Order Only from the Warehouse Picking Confirmation
             * screen, we ALWAY want to print MULTIPLE labels so let's
             * change the label print type.
             ISPEC = 'OM'
          END

          LD.CT   = DCOUNT(LDIDS,VM)

          BEGIN CASE
          *---------------------------------------------------------------*
          * Print labels with No "Automatic Looping"
          CASE ISPEC='NO'
             * We will ALWAY only print 1 even though the TOTAL QUANTITY
             * of labels is available.  We also remove the reference to
             * any item on the order (i.e. LDID='')
             LDID    = ''
             LBL.QTY = TOL.CNT<1>
             GOSUB PRT.ONE
          CASE OLDID='0'
             LDID = OLDID
             LBL.QTY = TOL.CNT<1>
             GOSUB PRT.ONE
          *---------------------------------------------------------------*
          * Print labels for All Items
          *     AND
          * the user did NOT change the value of the BEST GUESS number of
          * labels to print.
          *
          * In this case, the number of labels printed for each item is
          * the QUANTITY ORDERED of that item.
          *
          * So if the order consisted of:
          *     9 ea    Product x
          *     2 ea    Product y
          *     5 ea    Product z
          *
          * The following labels would be printed
          *
          *    - If the label was a multi-call type (i.e. "xM"),
          *        9 labels for Product x ("n of 9" possible)
          *        2 labels for Product y ("n of 2" possible)
          *        5 labels for Product z ("n of 5" possible)
          *      In other words, this case prints 1 label for each product
          *      that is on the order.
          *
          *    - If the label was a single-call type (i.e. "xS"),
          *        1 labels for Product x (ONLY "1 of 1" possible)
          *        1 labels for Product y (ONLY "1 of 1" possible)
          *        1 labels for Product z (ONLY "1 of 1" possible)
          *      In other words, this case prints 1 label for each line
          *      item that is on the order.


          CASE UID<1> = 'PACK.AUTO.PRINT'
             OID = ''
             LDID = ''
             GOSUB GET.PN.IDS
             NUM.ORDS = DCOUNT(ORD.IDS,VM)
             FOR ORD.LP = 1 TO NUM.ORDS
                OID = FIELD(ORD.IDS<1,ORD.LP>,'.',1)

                PNS = PN.IDS<1,ORD.LP>
                NUM.PNS = DCOUNT(PN.IDS,SVM)
                FOR PN.LP = 1 TO NUM.PNS
                   PN = PNS<1,ORD.LP,PN.LP>
                   MAT LED   = ''
                   MAT LD    = ''
                   ORIG.LDID = '0'
                   LDID      = 1
                   GEN       = 1
                   LD(1)     = PN
                   LD(4)     = 1
                   LD(5)     = 1
                   LD.PUT 1
                   GOSUB PRT.ONE
                NEXT PN.LP
             NEXT ORD.LP
          CASE QTYP = 1 AND UID<1,2> = 'SRE.INT'
              PN = UID<1,1>
              MAT LED   = ''
              MAT LD    = ''
              ORIG.LDID = '0'
              LDID      = 1
              GEN       = 1
              LD(1)     = PN
              LD(4)     = 1
              LD(5)     = 1
              LBL.QTY   = TOL.CNT<1,1>
              LD.PUT 1
              GOSUB PRT.ONE
          CASE QTYP = 1 AND UID<1,2> = 'PACK.MAINT'
             * Product labels
             IF SELECTED.LDID > 0 THEN
                LDID = SELECTED.LDID
                LD.GET LDID
                PN = LD(1)
             END ELSE
                * Setup ledger detail defaults
                PN           = UID<1,1>
                MAT LD       = ''
                ORIG.LDID    = '0'
                LDID         = 1
                IF GEN = '' THEN GEN = 1
                LD(1)        = PN
                LD(4)        = 1
                LD(5)<1,GEN> = 1
                LD.PUT 1
             END
             LBL.QTY = TOL.CNT<1,1>
             GOSUB PRT.ONE
          CASE (QTYP = 2 OR QTYP = 3) AND UID<1,2> = 'PACK.MAINT'
             ORD.ID = UID<1,3>
             CTN.DATA = UID<1,4>
             GOSUB GET.PN.IDS
             PN.IDS = RAISE(CTN.DATA<1,1,6>)
             GOSUB GET.LBL.QTYS
             NUM.ORDS = DCOUNT(ORD.IDS,VM)
             FOR ORD.LP = 1 TO NUM.ORDS
                OID = FIELD(ORD.IDS<1,ORD.LP>,'.',1)
                PNS = PN.IDS<1,ORD.LP>
                NUM.PNS = DCOUNT(PN.IDS,SVM)
                FOR PN.LP = 1 TO NUM.PNS
                   PN = PNS<1,ORD.LP,PN.LP>
                   MAT LED   = ''
                   MAT LD    = ''
                   ORIG.LDID = '0'
                   LDID      = 1
                   GEN       = 1
                   LD(1)     = PN
                   LD(4)     = 1
                   LD(5)     = 1
                   LD.PUT 1
                   LBL.QTY   = LQTY<1,PN.LP>
                   BEGIN CASE
                   CASE LBL.QTY + LBL.CNTR > TOL.CNT<1,1>
                      LBLS.LEFT = TOL.CNT<1,1> - LBL.CNTR
                      LBL.QTY = LBLS.LEFT
                   CASE OTHERWISE
                      NULL
                   END CASE
                   GOSUB PRT.ONE
                   IF LBL.CNTR = TOL.CNT<1,1> THEN
                      EXIT
                   END
                NEXT PN.LP
             NEXT ORD.LP
          CASE QTYP = SELCT.VALUE.ALL.ITEMS AND TOL.CNT<2> = ''
             FOR LDN = 1 TO LD.CT
                LDID    = LDIDS<1,LDN>
                * For this item, print the number of labels as determine
                * by the quantity ordered of this item.
                GOSUB GET.QTY
                GOSUB PRT.ONE
             NEXT LDN
          *---------------------------------------------------------------*
          * Print labels for All Items
          *     AND
          * the user DID CHANGE the value of the BEST GUESS number of
          * labels to print.
          *
          * In this case, the number of labels printed for each item is
          * the CHANGED VALUE of the number of labels to print.
          *
          * So if the order consisted of:
          *     9 ea    Product x
          *     2 ea    Product y
          *     5 ea    Product z
          *
          * And the user changed the Total Count to 7
          *
          * The following labels would be printed
          *     7 labels for Product x (ONLY "1 of 1" possible)
          *     7 labels for Product y (ONLY "1 of 1" possible)
          *     7 labels for Product z (ONLY "1 of 1" possible)
          *
          * In other words, this case prints the same number of label for
          * each line item on the order.
          *
          * This seems ODD but it has been this way since R7.
          CASE QTYP = SELCT.VALUE.ALL.ITEMS AND TOL.CNT<2> = 'Y'
             FOR LDN = 1 TO LD.CT
                LDID    = LDIDS<1,LDN>
                LD.GET LDID
                MATREAD PRD FROM PRDFILE,LD(1) ELSE MAT PRD = ''
                * For this item, print the number of labels as specified
                * by the user.
                FOR OVR = 1 TO TOL.CNT<1>
                   GOSUB PRT.ONE
                NEXT OVR
             NEXT LDN
          *---------------------------------------------------------------*
          * Print labels for Current Item Only
          *
          * If the value of Total Count was 6, the following labels
          * would be printed for this line item
          *
          *    - If the label was a multi-call type (i.e. "xM"),
          *        6 labels ("n of 6" possible)
          *
          *    - If the label was a single-call type (i.e. "xS"),
          *        1 labels for Product x (ONLY "1 of 1" possible)
          CASE QTYP = SELCT.VALUE.CURRENT.ITEM
             LD.GET SELECTED.LDID
             LDID    = SELECTED.LDID ;* Use LDID of item selected on labels
             LBL.QTY = TOL.CNT<1>
             GOSUB PRT.ONE
          *---------------------------------------------------------------*
          * Print labels for Order Only etc.
          *
          * If the value of Total Count was 8, the following labels
          * would be printed for this order
          *
          *    - If the label was a multi-call type (i.e. "xM"),
          *        8 labels ("n of 8" possible)
          *
          *    - If the label was a single-call type (i.e. "xS"),
          *        1 labels for Product x (ONLY "1 of 1" possible)
          CASE OTHERWISE
             LDID    = ''      ;* No LDID defined on these labels
             LBL.QTY = TOL.CNT<1>
             GOSUB PRT.ONE
          END CASE

          * Restore the copy of the label type (aka spec) that we might
          * have changed.
          ISPEC = ISPEC.SV

          *---------------------------------------------------------------*
          * If allowed, print an **END** label after we print the
          * desired label(s).
          IF ISPEC#'NO' AND ISPEC#'' THEN
             LDID = 'END';   LBL.QTY=1; GOSUB PRT.ONE
          END

          BEGIN CASE
          CASE FORM = 'None' OR FORM = ''; NULL
          CASE FIELD(SUBR.NAME,'.',1) = 'BATCH'
             PRINTER.OFF
             PC.FILENAME = ''
             UT.DOWNLOAD.BATCHFILE DOC.ID,PC.FILENAME,YES,1,YES
             IF DDE.SUBR # '' THEN
                CALL @DDE.SUBR(PC.FILENAME)
             END
          CASE FORM = 'DOWNLOAD' AND NOT(JAVA.PROC$)
             PRINTER.OFF
             PC.FILENAME = ''
             UT.DOWNLOAD.HOLDFILE DOC.ID,PC.FILENAME,YES,1,YES
             IF DDE.SUBR # '' THEN
                CALL @DDE.SUBR(PC.FILENAME)
             END
          CASE OTHERWISE
             PRINTER.OFF
          END CASE

FINISH:   *** finish

          RETURN
*-------------------------------------------------------------------------*
PRT.ONE:  *** This routine makes one **SET** of calls to the label
          *** printing subroutine.  The number of calls in this set
          *** set is influenced by:
          ***   QTYP    - The type of label that we are printing has an
          ***             influence on whether the BOX.QTY is considered.
          ***
          ***   BOX.QTY - If we are printing labels for the current item,
          ***             the box quantity may affect the LBL.QTY.
          ***
          ***   ISPEC  - If this specification is multi-call
          ***             (i.e. 'xM'), the set will make LBL.QTY calls
          ***             to print labels.
          ***             Labels printed with this specification can print
          ***                  "m of n"
          ***             on the labels where n will be the LBL.QTY
          ***
          ***           - If this specification is single-call (i.e. 'xS'),
          ***             the set will only make 1 call to print a label.
          ***             Labels printed with this specification can only
          ***                  "1 of 1"
          ***             on the labels.
          *---------------------------------------------------------------*
          GOSUB GET.CUS.PN
          IF LD(1) = '' THEN LD(1) = UID<1>       ;* ADDED 10/02/01
          PTR.ID = FIELD(PRINTER.ID[3,99],'-',1)
          LABEL.PRINTER.SELECT PTR.ID,SEL.PRINTER

          * Unless we are printing the Current Item , we
          * ignore the box quantity because it doesn't make any sense in
          * this context.
          IF QTYP=SELCT.VALUE.CURRENT.ITEM THEN
             IF BOX.QTY # 0 AND BOX.QTY # '' THEN
                *Here is where we are getting the number of boxes that we will
                *need to print labels for.
                OE.GET.QSIGN QSIGN,OID,GEN
                SHIP.QTY =  (SUM(LD(5)<1,GEN>)+SUM(LD(6)<1,GEN>)) * QSIGN
                BOX.FLAG = YES
                ROUNDUP LBL.NUM,SHIP.QTY,BOX.QTY
                LBL.QTY = LBL.NUM
             END
          END

          IF SUBR.NAME[1,8] = '*CTN.OUT' THEN
             PACK.GET.CONTENT.CNT OID,LBL.COUNT,LBL.DATA,UID,PNS.PER.LBL
             SV.UID      = UID
             UID         = ''
             UID<1>      = OID
             UID<4>      = PNS.PER.LBL
             PN.LIST     = ''
             LBL.QTY     = LBL.COUNT
             ORD.ID      = LBL.DATA<1>
             PN.IDS      = LBL.DATA<2>
             PCK.QTYS    = LBL.DATA<3>
          END

          * From the Label Specification, determine whether
          *  - Multiple Copies of this label are allowed
          *  - Single   Copy   of this label are allowed
          IF ISPEC[2,1]='M' THEN
             * MULTIPLE copies of this label are allowed
             *
             * The Total Number of labels that we are printing is include
             * in the print subroutine call (i.e. LBL.QTY) along with the
             * current count number (i.e. LBN) so that the label can print
             * something like:
             *
             *     Part 1 of 27
             *
             * if the label is so formated.
             IF SEL.PRINTER = "Z" OR SUBR.NAME[1,1] = "*" THEN
                TQTY = 0
                FOR LBN = 1 TO LBL.QTY
                   IF BOX.FLAG THEN
                      IF LBN = LBL.QTY THEN
                         QTY.OVRD = MOD(SHIP.QTY,BOX.QTY)
                         IF QTY.OVRD = 0 THEN QTY.OVRD = BOX.QTY
                      END ELSE
                         QTY.OVRD = BOX.QTY
                      END
                   END

                   IF SUBR.NAME[1,8] = '*CTN.OUT' THEN
                      NUM.PNS = DCOUNT(PN.IDS,VM)
                      IF NUM.PNS > PNS.PER.LBL THEN NUM.PNS = PNS.PER.LBL
                      FOR LP = 1 TO NUM.PNS
                         PN.LIST<1,-1> = PN.IDS<1,1>:SVM:PCK.QTYS<1,1>
                         TQTY += PCK.QTYS<1,1>
                         DEL PN.IDS<1,1>
                         DEL PCK.QTYS<1,1>
                      NEXT LP
                      UID<2> = PN.LIST
                      IF LBN = LBL.QTY THEN
                         UID<3> = TQTY
                      END
                   END
                   UD.ZEBRA.PRINT ORD.ID,GEN,LDID,LBN,LBL.QTY,UID,SUBR.NAME,QTY.OVRD,PARENT.LDIDS
                   IF LDID # "START" AND LDID # "END" THEN
                      LBL.CNTR += 1
                   END
                   IF UID<1,2> # "SRE.INT" THEN
                      PN.LIST = ''
                      UID<2>  = ''
                   END
                NEXT LBN
             END ELSE
                IF SUBR.NAME # '' THEN
                   FOR LBN = 1 TO LBL.QTY
                      CALL @SUBR.NAME(OID,GEN,LDID,LBN,LBL.QTY,UID)
                   NEXT LBN
                END
             END
          END ELSE
             * ONLY a SINGLE copy of this label is allowed
             *
             * The Total Number of labels that we are printing is include
             * in the print subroutine call (i.e. LBL.QTY) but it is a 1
             * in this instance.  There is no current count so it is passed
             * in the print subroutine call as a ''.  This means that a
             * label printed from here will ALWAYS look like
             *
             *     Part 1 of 1
             *
             * if the label is so formated.
             IF SEL.PRINTER = "Z" OR SUBR.NAME[1,1] = "*" THEN
                UD.ZEBRA.PRINT ORD.ID,GEN,LDID,'',LBL.QTY,UID,SUBR.NAME,QTY.OVRD,PARENT.LDIDS
             END ELSE
                IF SUBR.NAME#'' THEN
                   CALL @SUBR.NAME(OID,GEN,LDID,'',LBL.QTY,UID)
                END
             END
          END
          UID = SV.UID

          RETURN
*-------------------------------------------------------------------------*
*** If we are printing a customer specific part number pass the id to
*** printer
GET.CUS.PN:
          IF NOT(LDID) OR LDID="START" OR LDID="END" THEN RETURN
          *The ldid may refer to a kit but we are trying to print one
          *compnent
          SAVE.PN = LD(1)

          LD.GET LDID
          IF LD(1)=SAVE.PN AND LD(43)<1,1> # '' THEN
             PN.ID = LD(1)<1,1>:VM:LD(43)<1,1>
             OE.CUS.PN.CMT.GET.ALL LED(1)<1,GEN>,LED(5)<1,GEN>,CUSS(66),PN.ID,CPNS,LOCS,CMTS
             IF DCOUNT(CMTS,AM) > 1 THEN
                *** This should not happen, we were searching on a specific
                *** customer/customer part number pair
                CMTS = CMTS<1>
             END
             CMT = RAISE(CMTS)
             IF CMT<1> THEN
                UID<4> = CMT<6>:"~":CMT<1>:"~":CMT<2>:"~":LD(1)<1,1>
             END
          END
          LD(1) = SAVE.PN
          RETURN
*-------------------------------------------------------------------------*
GET.PN.IDS: *
          UT.OPEN.FILE 'CARTON.DETAIL',CRTNDFILE,ERR.MSG
          IF ERR.MSG THEN RETURN

          READV ORD.IDS FROM CRTNDFILE, ORD.ID, 10 ELSE ORD.IDS = ''
          READV PN.IDS FROM CRTNDFILE, ORD.ID, 11 ELSE PN.IDS = ''
          ORD.ID = ''

          RETURN
*-------------------------------------------------------------------------*
GET.LBL.QTYS: *

          CTN.DATA = UID<1,4>
          LBL.QTYS = CTN.DATA<1,1,5>
          LQTY = RAISE(RAISE(LBL.QTYS))

          RETURN
*-------------------------------------------------------------------------*
GET.QTY:  IF LDID+0=0 THEN           LBL.QTY = 1; RETURN
          LD.GET LDID
          IF NOT(NUM(LD(1))) THEN    LBL.QTY = 0; RETURN
          MATREAD PRD FROM PRDFILE,LD(1) ELSE MAT PRD = ''
          OE.LABEL.QTY.CALC OID,GEN,LDID,QSIGN,LBL.QTY,OVRD
          RETURN
*-------------------------------------------------------------------------*
INIT:     *** Initialize values for this routine
          *---------------------------------------------------------------*

          *---------------------------------------------------------------*
          * Define the legal Print Selection options for the type of
          * printing.
          *
          * The TEXT STRINGS that the user selects OFTEN determines
          * how the labels print (i.e. sets the value of QTYP).
          *
          * Get the Print Selection TEXT STRING Constants that are
          * displayed to the user, and the INTEGER VALUES Constants that
          * represent these strings.
          UD.DOC.PRINT.GET.SELCTS SELCT.CURRENT.ITEM,SELCT.ALL.ITEMS,SELCT.ORDER.ONLY,SELCT.VALUE.CURRENT.ITEM,SELCT.VALUE.ALL.ITEMS,SELCT.VALUE.ORDER.ONLY

          RETURN
*-------------------------------------------------------------------------*
!TSMITH~09/23/13~16:31
