/* AREVA T&D – Project – Kevin He - 16/FEB/2009 – Begin */
/* Send email with payslip to the corresponding employee. */
import PT_MCF_MAIL:*;
Local File &File;
Local string &FILE_NAME;
rem This text is used to debug email distribution
&FILE_NAME = "debug_email.txt";
&CHARSET = "U";
&File = GetFile(&FILE_NAME, "W", &CHARSET);
&retcode = 100;
Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();
&emailsentaddress = "T&D_HRIS_ADMINISTRATOR@";
&plain_text = "Areva China PaySlip";
& = &emailsentaddress;
& = &plain_text;
rem Search directory
&payslip_dir = GetEnv("PS_SERVDIR") | "/CHN_PaySlip";
&payslip_dir_all = &payslip_dir | "/*.";
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
SQLExec("select DESCR from PS_GP_CAL_RUN where CAL_RUN_ID = :1",
TD_GPCN_PSL_AET.CAL_RUN_ID, &CAL_RUN);
rem Email body saved in Explain Text of Message box, which has format.
& = MsgGetExplainText(25001, 1, "Message Not Found", &CAL_RUN);
& = "text/plain; charset=UTF-8";
rem Search for all files that end with *. and saved files name into array
&FNAMES = FindFiles(&payslip_dir_all, %FilePath_Absolute);
While & > 0
rem Pop up file name one by one
&filedir = &();
SQLExec("select substr(:1, instr(:1, '/', -1, 1) + 1, length(:1)) from dual",
&filedir, &filename);
SQLExec("SELECT SUBSTR(:1, 1, length(:1) - 8) FROM DUAL", &filename, &filename_pdf);
SQLExec("select substr(:1, 1, instr(:1, '_', -1, 1) - 1) from dual", &filename,
&emplid);
SQLExec("select email_addr from ps_email_addresses where EMPLID = :1 and E_ADDR_TYPE
='BUSN'", &emplid, &emailaddress);
REM & = &emailaddress;
rem & = "@";
& = "khe@";
Local PT_MCF_MAIL:MCFBodyPart &attach = create PT_MCF_MAIL:MCFBodyPart();
Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&(&filedir, %FilePath_Absolute, &filename, "Areva China
PaySlip", "", "");
rem add email body part
&(&text);
&(&attach);
& = ∓
Local integer &resp = &();
Evaluate &resp
When %ObEmail_Delivered
rem when email was distributed successfully, remove attachment from ftp server
&server_dir = GetEnv("PS_SERVDIR") | "/CHN_PaySlip/";
&MyFile = GetFile(&server_dir | &filename, "U", %FilePath_Absolute);
&MyFile1 = GetFile(&server_dir | &filename_pdf, "U", %FilePath_Absolute);
&();
&();
Break;
When %ObEmail_NotDelivered
rem Check &, & and
& ;
&(&filename | " was not delivered successfully. Please check his/her
email address " | &);
Error (1);
Break;
When %ObEmail_PartiallyDelivered
rem Check &, & and
&;
&(&filename | " was partially delivered successfully. Please check
his/her email address " | &);
Error (1);
Break;
When %ObEmail_FailedBeforeSending
rem Get the Message Set Number, message number, Or just get the formatted messages
from &, &;
&(&filename | " failed before sending. Please check error descr: " |
&);
Error (1);
Break;
When-Other
&(&filename | " failed. Not sure about the reason, Please check email
address or error descr: " | &);
Error (1);
Break;
End-Evaluate;
/*If (&retcode = %Attachment_Success) Then
&("DeleteAttachment succeeded");
End-If;
If (&retcode = %Attachment_Failed) Then
&("DeleteAttachment failed");
End-If;
If (&retcode = %Attachment_Cancelled) Then
&("DeleteAttachment cancelled");
End-If;
If (&retcode = %Attachment_FileTransferFailed) Then
&("DeleteAttachment failed: File Transfer did not succeed");
End-If;
If (&retcode = %Attachment_FileNotFound) Then
&("DeleteAttachment failed: Cannot locate file");
End-If;*/
/* following error message only in PeopleSoft Internet Architecture */
/*If (&retcode = %Attachment_NoDiskSpaceAppServ) Then
&("DeleteAttachment failed: No disk space on the app server");
End-If;*/
/* following error message only in PeopleSoft Internet Architecture */
/*If (&retcode = %Attachment_NoDiskSpaceWebServ) Then
&("DeleteAttachment failed: No disk space on the web server");
End-If;
If (&retcode = %Attachment_FileExceedsMaxSize) Then
&("DeleteAttachment failed: File exceeds the max size");
End-If;
If (&retcode = %Attachment_DestSystNotFound) Then
&("DeleteAttachment failed: Cannot locate destination system for
ftp");
End-If;
If (&retcode = %Attachment_DestSysFailedLogin) Then
&("DeleteAttachment failed: Unable to login into destination system
for ftp");
End-If;*/
End-While;
rem remove all files in the directory
rem RemoveDirectory(&payslip_dir, %FilePath_Absolute + %Remove_Subtree);
&();
/* AREVA T&D – Project – Kevin He - 16/FEB/2009 – End */