:: This is lbox client script
:: It renames qad raw output file and sends it to lbox windows service
:: $1 = raw file name, mandatory
:: $2 = section name, optional, defaults to "report" if not set
:: $3 = email selection, optional, defaults to "noemail" if not set
@ECHO off

SET JAVA_HOME=C:\Program Files\Java\jre1.6.0_07
SET LBOX_HOME=%~dp0
SET LBOX_EMAIL=%LBOX_HOME%lbox.email
SET LBOX_002=%LBOX_HOME%lbox.002

SET rfile=%CD%\%1
SET section=%2
SET email=%3

IF "%2"=="" SET section=report
IF "%3"=="" SET email=noemail

for /f %%a in ('dir /b %rfile%') do (
  if %%~za lss 1 (
    echo No Data
    goto :EOF
  )
)

set ts=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
@REM %TIME% Puts a leading space on hours if < 10, change to 0
if "%ts:~0,1%"==" " set ts=0%ts:~1,5%
set ds=%DATE:~-4%%DATE:~4,2%%DATE:~7,2%
SET nfile=%CD%\%ds%.%ts%.%RANDOM%.txt

for /f "tokens=1,2,3,4,5 delims=^" %%a in (%LBOX_EMAIL%) do (
  if "%%a"=="%email%" (
    TYPE %LBOX_002%
    echo email:%%b^^%%c %DATE%^^ %%d^^%%e
  )
) >> %nfile%

type %rfile% >> %nfile%

CD %LBOX_HOME%
"%JAVA_HOME%\bin\java" -jar LBOX2c.jar %nfile% %section%

del %nfile% 
del %rfile% 
