     SUBROUTINE (INIT.ID, INIT.GEN, ORDERS, STK.BR, XFERS.TO.PROCESS, MSGS, PRT.INFO)
** Version# 3.0001[3] - 04/04/2013 - 10:28am - TSMITH - eclipse
*** V3.0001 Change - Custom Coding . - 04/04/2013 - TSMITH - eclipse

*** Subroutine - XDOCK.PROCESS.PRINT
*-------------------------------------------------------------------------*
*** This routine will process and print an order from the cross dock queue.
*** In other words, it will invoice a sales order and print a pick ticket
*** or it will recieve and print a transfer order.
*-------------------------------------------------------------------------*
*** INIT.ID  - Purchase Order or Shipment currently being received    [In]
*** INIT.GEN - Purchase Order generation NOTE: This is required if a  (In)
***            Puchase Order is being passed in  but is not used
***            if a Shipment is being passed in.
*** ORDERS   - An array of sales orders information. If               [In]
***            ORDERS<LINE,4> is set to YES then this routine will
***            attempt to process and print.
*** STK.BR   - Stock Branch                                           [In]
*** XFERS.TO.PROCESS - This routine is unable to process transfers    (out)
***          - without throwing prompts (bad for solar).  So a list
***          - of OID:'.':GEN to process is returned.
*** MSGS     - AM delimited list of messages that should for user.    [Out]
*** PRT.INFO - Printing information solar needs to print documents.   [Out]
***      <1> - DOC.IDS - VM list of IDs of the print job documents
***      <2> - LOC.OVRDS - VM list of Location to print at
***      <3> - FORM.IDS - VM list of form id
***      <4> - DOC.DESC - VM list of descriptions about printing document
*-------------------------------------------------------------------------*
*** COMMON:
*** LED changed
*-------------------------------------------------------------------------*
          DIM ASN(50)
          GOSUB INIT
          LN.CT = DCOUNT(ORDERS,AM)
          FOR LL = 1 TO LN.CT
             IF ORDERS<LL,4> THEN
                ORD.ID = ORDERS<LL,1>
                GOSUB PROCESS.ORDER
             END
          NEXT LL
          GOTO FINISH
*-------------------------------------------------------------------------*
INIT:     * Iniitalize variables common throught this routine.
          MSGS = ''
          PRT.INFO  = ''
          DOC.IDS   = ''
          LOC.OVRDS = ''
          FORM.IDS  = ''
          DOC.DESC  = ''
          XFERS.TO.PROCESS = ''

          JPOS = 0 ;* Array position for DOC.IDS and LOC.OVRDS
          IF INIT.ID[1,1] = 'N' THEN
             IS.SHIPMENT = YES
          END ELSE
             IS.SHIPMENT = NO
          END

          IF IS.SHIPMENT THEN
             * Open the files neccessary for the shipment logic..
             UT.OPEN.FILE 'ASN.DATA',ASNFILE,ERR.MSG
             IF ERR.MSG THEN RETURN TO FINISH
             MATREAD ASN FROM ASNFILE,INIT.ID ELSE MAT ASN = ''
          END
          RETURN
*-------------------------------------------------------------------------*
PROCESS.ORDER:
          IS.LOCK  = NO ;* True if lock on order that needs to be released
          HAS.AUTH = NO ;* True if user can override credit restrictions
          IF INDEX(ORD.ID,'XFER',1) THEN
             GOSUB AUTO.XFER ;* Automatically transfer
          END ELSE
             GOSUB PROCESS.CURRENT.BR
          END
          IF IS.LOCK THEN
             OE.UNLOCK.LED OID
          END
          RETURN
*-------------------------------------------------------------------------*
PROCESS.CURRENT.BR: *** Process an order at the current branch.

          * Activate LED for branch being processed
          LOCK.ERR = ''
          DO.LOCK  = YES
          GOSUB GET.OID.GEN
          MATBUILD SV.LED FROM LED
          IF GEN = 0 THEN RETURN
          STAT = LED(6)<1,GEN>

          MSG = ''
          BEGIN CASE
          CASE LOCK.ERR
             MSG  = 'Order ':OID:' is Locked by Another Process '
             MSG := '(The Phantom).  This Order did not Print.'
          CASE STAT = 'I'
             MSG  = 'Order ':OID:' has Already Been Invoiced by '
             MSG := 'Another Process (The Phantom).  This Order '
             MSG := 'did not Print.'
          END CASE
          IF MSG THEN
             MSGS<-1> = MSG
             RETURN
          END

          * Make sure there are no credit holds prior to processing
          OE.GET.QSIGN QSIGN,OID,GEN
          HAS.AUTH = XDOCK.CHECK.CREDIT.AUTH(OID,GEN,QSIGN)
          IF NOT(HAS.AUTH) THEN
             MSGS<-1> = 'Authorization Required to Release Ticket ':OID
             RETURN
          END

          XDOCK.MSG = ''
          IF IS.SHIPMENT THEN
             GOSUB RECIEVE.SHIPMENT
          END ELSE
             XMSG = 'Cross Docked from ':INIT.ID:VM
             XDOCK.MSG<1> = RAISE(ORDERS<LL,12>) ;* List of xdockable pns
             XDOCK.MSG<2> = STR(XMSG,DCOUNT(XDOCK.MSG<1>,VM))
          END

          IF STAT = 'A' OR STAT = 'M' THEN
             STKBR = LED(2)<1,GEN,2>
             SOE.SHIP.ALL.AVL.GENS OID,STAT,STKBR,GEN,,,LED(70)<1,GEN>
             IF GEN = 0 THEN RETURN
          END

          IF XDOCK.MSG THEN
             GOSUB ADD.ORD.COMMENT
          END

          IF STAT = 'H' THEN LED(9)<1,GEN> = DATE()
          PROC.ERR = ''
          SOE.PROCESS.ORDER OID,GEN,LED(9)<1,GEN>,,PROC.ERR

          * If there was an error that caused the order not to be
          * processed (i.e. credit card failed auth), don't print the pick
          * ticket.
          IF PROC.ERR THEN
             MSGS<-1> = OID:': ':PROC.ERR
          END ELSE
             STATUS = ''
            IF OID[1,1] = 'T' THEN
                XDOCK.GET.PRT.LOCATION STATUS,GEN,LOC.OVRD
                TOE.PRINT.ORDER OID,GEN,STATUS,,,,LOC.OVRD
             END ELSE
                STATUS = 'T'
                XDOCK.GET.PRT.LOCATION STATUS,GEN,LOC.OVRD
                SOE.PRINT.ORDER OID,GEN,,"T"
                GOSUB JAVA
                READ PICK.CONF FROM CTRBFILE,"PICK.CONFIRM~":LED(2)<1,GEN,2> ELSE
                   PICK.CONF = NO
                   END
                IF PICK.CONF THEN
                   OE.SV.STATUS.GET LED(2)<1,GEN,2>,LED(70)<1,GEN>,STAT.STR
                   IF STAT.STR = "" THEN
                      XDOCK.GET.PRT.LOCATION STATUS,GEN,LOC.OVRD
                      SOE.PRINT.ORDER OID,GEN,,"O"
                GOSUB JAVA
                END
                END
             IF JAVA.PROC$ THEN
                JPOS += 1
                DOC.IDS<JPOS>   = FIELD(JAVA.PASSER$<JP.DOC.ID$>,'#',2)
                LOC.OVRDS<JPOS> = LOC.OVRD
                FORM.IDS<JPOS>  = FIELD(JAVA.PASSER$<JP.FORM$>,'#',2)
                DOC.DESC<JPOS>  = OID
             END
          END
          END

          RETURN
*-------------------------------------------------------------------------*
JAVA: *
                IF JAVA.PROC$ THEN
                JPOS += 1
                DOC.IDS<JPOS>   = FIELD(JAVA.PASSER$<JP.DOC.ID$>,'#',2)
                LOC.OVRDS<JPOS> = LOC.OVRD
                FORM.IDS<JPOS>  = FIELD(JAVA.PASSER$<JP.FORM$>,'#',2)
                DOC.DESC<JPOS>  = OID
                END
                RETURN
*-------------------------------------------------------------------------*
RECIEVE.SHIPMENT: *** Receive necessary qtys on the shipment so we can
            *** process the order

          *** Close out anything on the shipment that is needed
          *** to process this order
          * Get the products and qtys needed for this order/gen
          GET.GEN.PN.QTYS OID,GEN,PNS,QTYS
          * Loop thru each product and see if we need to close
          * out inprocess records on the shipment
          PNCT = DCOUNT(PNS<1>,VM)
          PNCTR = 1; RECV.PNS = ''
          FOR PNX = 1 TO PNCT
             PN = PNS<1,PNX>
             GET.ALL.PRD TO.BR,PN
             PRDD.BR.GET STK.BR,PN
             * get the stock qtys
             ADDL.DATA = ''
             ADDL.DATA<1,1> = PN
             ADDL.DATA<1,2> = STK.BR
             ADDL.DATA<1,3> = INIT.ID
             SHP.IP = ''
             GET.ONHAND PRDD.BR(1),PRDD.BR(8),TMP.QTYS,,,,,,SHP.IP,ADDL.DATA
             * if we need more than what we have in stock then
             * we need to take the qtys from the shipment
             CHK.QTYS = TMP.QTYS + SHP.IP
             IF TMP.QTYS < QTYS<1,PNX> THEN
             IF CHK.QTYS > 0 THEN
                IF SHP.IP <= QTYS<1,PNX> THEN
                   RECV.PNS<1,PNCTR> = PN
                   RECV.PNS<2,PNCTR> = SHP.IP
                   PNCTR += 1
                END ELSE
                   RECV.PNS<1,PNCTR> = PN
                   RECV.PNS<2,PNCTR> = QTYS<1,PNX>
                   PNCTR += 1
                END
             END ELSE
                IF STAT # 'A' AND STAT # 'H' THEN
                   RECV.PNS = ''; RECV.PNS = ''
                   EXIT
                END
             END
             END
          NEXT PNX

          PNCT = DCOUNT(RECV.PNS,VM)
          PNCTR = 1
          PNS = ''
          FOR PNX = 1 TO PNCT
             IF RECV.PNS<1,PNX> # '' THEN
                PNS<1,PNCTR> = RECV.PNS<1,PNX>
                PNS<2,PNCTR> = RECV.PNS<2,PNX>
                PNCTR += 1
             END
          NEXT PNX

          PNS = LOWER(PNS)
          IF PNS THEN
             *** Receive the necessary qtys on the shipment
             SHIPMENT.MAINT.XDOCK.RECV MAT ASN,ASN.ID,PNS
             *** Close out the necessary qtys on the shipment
             XDOCK.MSG = ''
             CONT.DATA = ASN(25)
             CONT.CT = DCOUNT(CONT.DATA,VM)
             FOR CONTX = 1 TO CONT.CT
                CONT.ID = CONT.DATA<1,CONTX>
                SHIPMENT.MAINT.CLOSE.CONT MAT ASN,ASN.ID,CONT.ID,CONTX,LK.MSG,PNS,,XDOCK.INFO
                XDOCK.INFO = RAISE(XDOCK.INFO)
                MPNCT = DCOUNT(XDOCK.INFO<1>,VM)
                FOR MPNX = 1 TO MPNCT
                   THIS.PN = XDOCK.INFO<1,MPNX>
                   LOCATE THIS.PN IN XDOCK.MSG<1> SETTING LPOS ELSE
                      XDOCK.MSG = INSERT(XDOCK.MSG,1,LPOS;THIS.PN)
                   END
                   CONCT = DCOUNT(XDOCK.INFO<2,LPOS>,SVM)
                   FOR CON = 1 TO CONCT
                      THIS.CON = XDOCK.INFO<2,LPOS,CONCT>
                      XMSG  = 'Cross Docked on Shipment ':ASN.ID
                      XMSG := ', container ':THIS.CON:SVM
                      XDOCK.MSG = INSERT(XDOCK.MSG,2,LPOS,-1;XMSG)
                   NEXT CON
                NEXT LDX
             NEXT CONTX
          END
          GOSUB GET.OID.GEN
          RETURN
*-------------------------------------------------------------------------*
AUTO.XFER: *** Automatically
          TO.PNS = RAISE(ORDERS<LL,7>)
          IF NOT(TO.PNS) THEN RETURN
          TO.BR  = RAISE(ORDERS<LL,6>)
          XDOCK.XFER.QUEUE.INIT TO.PNS,STK.BR,TO.BR,RETURN.INFO
          XFER.DATA = ''
          XFER.DATA<1> = RETURN.INFO<1> ;* Product IDs to transfer
          XFER.DATA<2> = RETURN.INFO<2> ;* To Branches
          XFER.DATA<3> = RETURN.INFO<3> ;* Suggested qty to transfer
          BR.CT = DCOUNT(XFER.DATA<2>,VM)
          FOR QQ = 1 TO BR.CT
             XFER.DATA<4,QQ> = YES      ;* Flag to create xfer
          NEXT QQ
          XDOCK.XFER.ITEMS XFER.DATA,STK.BR,'',XFERS.CREATED,AUTO.PROCESS,ERR.MSGS
          IF ERR.MSGS THEN MSGS<-1> = ERR.MSGS
          XFER.CT = DCOUNT(XFERS.CREATED<1>,VM)
          FOR XX = 1 TO XFER.CT
             MSGS<-1> = 'Transfer ':FIELD(XFERS.CREATED<1,XX>,'.',1):' Created'
             IF AUTO.PROCESS THEN XFERS.TO.PROCESS<-1> = XFERS.CREATED<1,XX>
          NEXT XX
          RETURN
*-------------------------------------------------------------------------*
ADD.ORD.COMMENT: *** Add the xdock comment to the sales order

          XDOCK.MSG = TRIM(XDOCK.MSG,SVM,'T')
          LDIDS = LED(48)<1,GEN>
          LDCT = DCOUNT(LDIDS<1,1>,SVM)
          FOR LNX = 1 TO LDCT
             LDID = LDIDS<1,1,LNX>
             LD.GET LDID
             MAT OLD.LD = MAT LD
             LOCATE LD(1) IN XDOCK.MSG<1> SETTING PPOS THEN
                LD(129)<1,GEN> = XDOCK.MSG<2,PPOS>
                GEN.MV = GEN
                UPDATE.LEDGER.DET OID,LDID,QSIGN,GEN.MV
             END
          NEXT LNX
          UPDATE.LEDGER OID
          MAT OLED = MAT LED
          RETURN

*-------------------------------------------------------------------------*
GET.OID.GEN: *** Get Order Id and Gen
          LOCK.ERR = ''
          OID      = FIELD(ORD.ID,'.',1)
          IDX      = FIELD(ORD.ID,'.',2)
          IF DO.LOCK THEN
             OE.LOCK.LED OID,LOCK.ERR,YES
             DO.LOCK = NO
             IS.LOCK = YES
          END ELSE
             MATREAD LED FROM LEDFILE,OID ELSE MAT LED = ''
          END
          MAT OLED = MAT LED
          IDX.LEN = LEN(IDX)

          IF LEN(IDX) = 3 THEN
             LOCATE IDX+0 IN LED(8)<1> SETTING GEN  ELSE GEN = 0
          END ELSE
             LOCATE IDX+0 IN LED(12)<1> SETTING GEN ELSE GEN = 0
          END
          RETURN
*-------------------------------------------------------------------------*
FINISH:   *** Exit point of the routine
          PRT.INFO<1> = LOWER(DOC.IDS)
          PRT.INFO<2> = LOWER(LOC.OVRDS)
          PRT.INFO<3> = LOWER(FORM.IDS)
          PRT.INFO<4> = LOWER(DOC.DESC)
          RETURN
!TSMITH~04/04/13~10:28
