          SUBROUTINE (DOC.ID,ERR.MSG,PASSER)
** Version# 12.0004[2] - 05/02/2017 - 11:31am - TSMITH - eclipse
*** V12.0004 Change - Custom Coding 1-3 - 05/02/2017 - TSMITH - eclipse
*** V12.0003 Change - Custom Coding . - 12/23/2014 - TSMITH - eclipse
*** V12.0002 Change - Custom Coding . - 02/18/2014 - TSMITH - eclipse
*** V12.0001 Change - Custom Coding . - 10/29/2013 - TSMITH - eclipse

*** Subroutine - EMAIL.SEND.REPORT
*-------------------------------------------------------------------------*
*** This routine should be used to send an email report from the hold
*** file.  For now, it is used only for phantom scheduled reports
*** (PRINTER.OFF.INIT) but it could be easily plugged in to maunally
*** emailed reports (PRINT.REPORT) as well.
*-------------------------------------------------------------------------*
*** DOC.ID  - Document ID                                          [IN]
*** ERR.MSG - Any errors encountered                               (OUT)
*** PASSER  - Email passer from Solar                              (IN)
*-------------------------------------------------------------------------*
*** COMMON Variables:
***       PHANTOM.PROC and JAVA.PROC$ are read but not changed
*-------------------------------------------------------------------------*

          ERR.MSG = ''

          UT.OPEN.FILE '&HOLD&',HOLDFILE,ERR.MSG,YES
          IF ERR.MSG THEN RETURN

          READ RPT FROM RPTFILE, DOC.ID ELSE RETURN
          READ DOC FROM HOLDFILE,DOC.ID ELSE RETURN
          DOC.HDR  = RPT<8>
          DOC.FTR  = RPT<9>
          IF NOT(PASSER) THEN
             E.BODY = RPT<57>         ;* set previously saved body
             PASSER = RAISE(RPT<58>)  ;* set previously saved email info
          END ELSE
             E.BODY = PASSER<14>
          END

          * Control file to store valid email REPORT attachment types
          CTRL.ID = "ECLIPSE.FORMS.DEFAULTS"
          READV DFLT.RPT.FEXT FROM CTRLFILE,CTRL.ID,21 ELSE
             DFLT.RPT.FEXT = ''
          END

          * Indicate that this is a non-PDF report being emailed.
          IF USE.ECLIPSE.FORMS$ THEN
             IF NOT(PASSER<18>) THEN
                PASSER<18> = DFLT.RPT.FEXT<1,1>
                IF NOT(PASSER<18>) THEN
                   PASSER<18> = '.pdf'
                END
             END

             IF UPCASE(PASSER<18>) # '.PDF' THEN
                PASSER<29> = '2'
             END ELSE
                PASSER<29> = ''
             END
          END

          * combine the header, doc and footer
          E.ATTACH = DOC.HDR:VM:DOC:VM:DOC.FTR
          E.ATTACH = TRIM(E.ATTACH,VM)

          * set additional PASSER vars
          IF PASSER<5> = '' THEN
             PASSER<5> = RPT<1>      ;* Subject
          END
          IF PHANTOM.PROC OR JAVA.PROC$ THEN
             PASSER<11> = YES        ;* don't prompt user when sending
          END
          PASSER<10> = YES
          PASSER<13> = YES           ;* don't override attach flag
          PASSER<14> = LOWER(E.BODY)
          IF DOC.ID[5]  = '.html' THEN
             PASSER<18> = '.html'
          END

          * Only overwrite the attachment name if the Extract flag is not
          * set or we are emailing a non-Print Price Sheet report.
          IF NOT(PASSER<29>) OR PASSER<29> = '2' THEN
             PASSER<21> = 'DOC':DOC.ID ;* attachment name
          END
          RECIPIENT = RPT<58,1>
          IF PASSER<5>[1,21]='Cust Sales Comparison' THEN
          PASSER<21> = PASSER<5>
          END ELSE
          IF PASSER<5>[1,14]='GPS Ticket Log' THEN
          PASSER<21> = PASSER<5>
          END ELSE
          IF FIELD(RECIPIENT,"@",1)= 'awallace' THEN
          PASSER<21> = 'Business Summary Report'
          PASSER<18> = ''
          END ELSE
          IF FIELD(RECIPIENT,"@",1)='bob' OR FIELD(RECIPIENT,"@",1)='tommy' THEN
          PASSER<21> = PASSER<5>
          PASSER<18>= ''
          END ELSE
          IF RECIPIENT = 'randy.allison@nhyates.com' THEN
          PASSER<21> = 'Aquatherm Monthly Report'
          PASSER<18> = ''
          END
          END
          END
          END
          END
          IF USE.ECLIPSE.FORMS$ THEN
             IF NOT(PASSER<17>) THEN
                PASSER<17> = PASSER<21>:PASSER<18>
             END ELSE
                IF NOT(INDEX(PASSER<17>,'.',1)) THEN
                   PASSER<17> := PASSER<18>
                END
             END
          END

          * Set EXT.DOC.ID for emailing extracts.
          IF NOT(PASSER<28>) OR PASSER<28> = "NEED_ID" THEN
             PASSER<28> = DOC.ID
          END

          EM.DATA = ''
          EM.DATA<11> = 'USER':VM:USER.ID
          EMAIL.DATA.GET EM.DATA,PASSER,E.BODY,E.ATTACH,ERR.MSG
          IF ERR.MSG THEN RETURN

          * If there is no 'To' address, don't send anything.
          IF PASSER<1> = '' THEN RETURN

          * Log action taken on this document
          PROC.INFO = RPT<53>
          PROC.ID = PROC.INFO<1,1>
          IF PROC.ID THEN
             PID.REC     = ''
             PID.REC<3>  = PROC.INFO<1,3>
             PID.REC<4>  = PROC.INFO<1,4>
             PID.REC<5>  = USER.ID
             DETAIL      = DOC.ID:VM:'(Email ': PASSER<1,1>:')'
             PROC.ACTION = 'Print'
             UPDATE.PHANTOM.LOG PID.REC,PROC.ID,PROC.ACTION,'','',DETAIL
          END

          RETURN
!TSMITH~05/02/17~11:31
