Sie sind auf Seite 1von 7

OBJECT Codeunit 10015002 Emails and SMS functions

{
OBJECT-PROPERTIES
{
Date=02/11/16;
Time=12:41:34;
Modified=Yes;
Version List=LSW17.00.01,TRI L.P.;
}
PROPERTIES
{
OnRun=BEGIN
END;
}
CODE
{
VAR
StaffManFunc@1200020000 : Codeunit 10015000;
OK@1200020001 : Boolean;
Text001@1100409000 : TextConst 'ENU=Please find attached your work schedul
e for %1';
Text002@1100409001 : TextConst 'ENU=%1 e-mails were sent';
Text003@1100409002 : TextConst 'ENU=%1 SMS messages were sent';
"-----TRI Rohit-----"@1000000000 : Integer;
WebServiceConnection@1000000001 : DotNet "'LSWebServiceClient, Version=1.0
.0.0, Culture=neutral, PublicKeyToken=194563f11b671d8c'.LSWebServiceClient.WebSe
rviceConnection";
WebServiceConnection2@1000000002 : DotNet "'LSWebServiceClient, Version=1.
0.0.0, Culture=neutral, PublicKeyToken=194563f11b671d8c'.LSWebServiceClient.WebS
erviceStatus";
PROCEDURE SendRosterEmailandSMS@1200020020(SendType@1200020010 : Integer;Wrk
Location@1200020001 : Code[20];Month@1200020003 : Integer;Year@1200020004 : Inte
ger;RosterName@1200020006 : Text[30];"RosterNo."@1200020009 : Code[20];EmpNo@120
0020011 : Code[20]);
VAR
PrintRec@1200020000 : Record 10015057;
PrintRep@1200020002 : Report 10015008;
PrintRec2@1200020007 : Record 10015057;
Mail@1200020005 : Codeunit 397;
PublishLog@1200020008 : Record 10015030;
FileName@1200020012 : Text;
Window@1100409000 : Dialog;
NoOfRecords@1100409001 : Integer;
RecordNo@1100409002 : Integer;
lText001@1100409003 : TextConst 'ENU=Processing...';
lText002@1100409004 : TextConst 'ENU=Record #1####';
lText003@1100409005 : TextConst 'ENU=#2#################################';
lText004@1100409006 : TextConst 'ENU=@3@@@@@@@@@@@@@@@@@@@@@@@@@@';
EmailBody@1100409007 : Text;
FileMgt@1100409008 : Codeunit 419;
ClientTempFileName@1100409009 : Text;
ClientFileName@1100409010 : Text;
BEGIN
IF EmpNo <> '' THEN BEGIN
PrintRec.SETRANGE("No.", EmpNo);
IF PrintRec.FINDFIRST THEN
CASE SendType OF
1: PrintRec.TESTFIELD("E-Mail");

0: PrintRec.TESTFIELD("Mobile Phone No.");


END;
END ELSE BEGIN
OK := PrintRec.SETCURRENTKEY("Work Location");
PrintRec.SETRANGE("Work Location", WrkLocation);
CASE SendType OF
1: PrintRec.SETFILTER("E-Mail", '<>%1', '');
0: PrintRec.SETFILTER("Mobile Phone No.", '<>%1', '');
END;
END;
IF GUIALLOWED THEN BEGIN
Window.OPEN(lText001 + '\' +
lText002 + '\' +
lText003 + '\' +
lText004);
NoOfRecords := PrintRec.COUNT;
RecordNo := 0;
END;
IF PrintRec.FINDSET THEN BEGIN
REPEAT
IF GUIALLOWED THEN BEGIN
RecordNo := RecordNo + 1;
Window.UPDATE(1,RecordNo);
Window.UPDATE(2,PrintRec."No." + ' ' + PrintRec.FullName);
Window.UPDATE(3,ROUND(RecordNo / NoOfRecords * 10000,1));
END;
PrintRec2.SETRANGE("No.", PrintRec."No.");
PublishLog.INIT;
CLEAR(PublishLog.Sequence);
PublishLog."Message Type" := SendType;
PublishLog.Description := PrintRec."First Name" + ' ' + PrintRec."Last
Name" + ' ' + RosterName;
PublishLog."Date Sent" := TODAY;
PublishLog."Time Sent" := TIME;
CASE SendType OF
1:
BEGIN
//#01 {
FileName := 'C:\temp\' + PrintRec."No." + ' ' + PrintRec."Last N
ame" + '.HTM';
}
FileName := TEMPORARYPATH + '\' + PrintRec."No." + ' ' + PrintRe
c."Last Name" + '.PDF'; //HTM';
//#01 +
IF FILE.EXISTS(FileName) THEN
FILE.ERASE(FileName);
CLEAR(PrintRep);
PrintRep.SetMonthYear(Month, Year);
PrintRep.SETTABLEVIEW(PrintRec2);
//PrintRep.SAVEASHTML(FileName); //#01
PrintRep.SAVEASPDF(FileName);
IF FILE.EXISTS(FileName) THEN BEGIN

ClientFileName := PrintRec."No." + ' ' + PrintRec."Last Name"


+ '.PDF';
ClientTempFileName := FileMgt.DownloadTempFile(FileName);
IF FILE.EXISTS(FileName) THEN
FILE.ERASE(FileName);
ClientFileName := FileMgt.MoveAndRenameClientFile(ClientTempFi
leName,ClientFileName,'');
CLEAR(Mail);
EmailBody := STRSUBSTNO(Text001,FORMAT(DMY2DATE(1,Month,Year),
0,'<Month Text> <Year4>'));
//IF FILE.EXISTS(ClientFileName) THEN
PublishLog."Sent OK" :=
Mail.NewMessage(
PrintRec."E-Mail", '', PrintRec."First Name" + ' ' + Pri
ntRec."Last Name" + ' ' +
RosterName, EmailBody, ClientFileName, FALSE);
FileMgt.DeleteClientFile(ClientFileName);
END;
PublishLog."Receivers address" := PrintRec."E-Mail";
END;
0:
PublishLog."Receivers address" := PrintRec."Mobile Phone No.";
END;
PublishLog."Employee No." := PrintRec."No.";
PublishLog."User Sending" := USERID;
PublishLog.Origin := "RosterNo.";
PublishLog.INSERT(TRUE);
COMMIT;
UNTIL PrintRec.NEXT = 0;
IF GUIALLOWED THEN
Window.CLOSE;
END;
END;
PROCEDURE SendVacancyEmailandSMS@1200020000(SendType@1200020000 : Integer;Pl
an@1200020001 : Code[20];WorkLocation@1200020002 : Code[20];Role@1200020003 : Co
de[20];Shift@1200020004 : Code[20];VacancyDate@1200020005 : Date);
VAR
Frm@1200020006 : Page 10015060;
Employee@1200020007 : Record 10015057;
Location@1200020011 : Record 10015021;
EmployeeRoles@1200020010 : Record 10015005;
MsgText@1200020009 : Text[100];
UnavailableTxt@1200020008 : Text[30];
Mail@1200020013 : Codeunit 397;
PublishLog@1200020012 : Record 10015030;
Txt1@1200020014 : Text[100];
Txt2@1200020015 : Text[100];
Txt3@1200020016 : Text[50];
Schedule@1200020017 : Record 10015018;
Setup@10012000 : Record 10015010;
WrkScheduleLines@10012001 : Record 10015015;
CurrSchedule@10012002 : Record 10015022;
RosterWrkTable@10012003 : Record 10015020;
FrmAction@1200020018 : Action;

NoOfEmailsSent@1100409000 : Integer;
NoOfSMSSent@1100409001 : Integer;
BEGIN
Location.GET(WorkLocation);
Setup.GET;
IF Location."Work Region" = '' THEN BEGIN
Employee.SETCURRENTKEY("Work Location");
Employee.SETRANGE("Work Location", Location.Code);
END ELSE BEGIN
Employee.SETCURRENTKEY("Work Region", "First Name");
Employee.SETRANGE("Work Region", Location."Work Region");
END;
Employee.SETRANGE(Status, Employee.Status::Active);
IF Employee.FINDSET THEN
REPEAT
EmployeeRoles.SETRANGE("Employee No.", Employee."No.");
EmployeeRoles.SETRANGE("Work Role Code", Role);
IF EmployeeRoles.FINDFIRST OR (Employee."Work Role" = Role) THEN BEGIN
Schedule.SETCURRENTKEY("Employee No.", "Schedule Date", "Work Locati
on");
Schedule.SETRANGE("Employee No.", Employee."No.");
Schedule.SETRANGE("Schedule Date", VacancyDate);
Schedule.SETRANGE("Plan No.", Plan);
IF NOT Schedule.FINDFIRST THEN
IF StaffManFunc.CheckAvailable(Employee."No.", VacancyDate, WorkLo
cation,
Shift, Role, MsgText, UnavailableTxt)
THEN
Employee.MARK(TRUE);
END;
UNTIL Employee.NEXT = 0;
Employee.MARKEDONLY(TRUE);
Frm.SetParameters(0, Plan, WorkLocation, Role, Shift, VacancyDate);
Frm.SETTABLEVIEW(Employee);
NoOfEmailsSent := 0;
NoOfSMSSent := 0;
FrmAction := Frm.RUNMODAL;
IF (FrmAction = ACTION::OK) OR (FrmAction = ACTION::Yes) THEN BEGIN
Employee.RESET;
Employee.SETFILTER("No.", Frm.ExitFilter);
IF Employee.FINDSET THEN
REPEAT
Frm.ExitTxt(Txt1, Txt2, Txt3);
PublishLog.INIT;
CLEAR(PublishLog.Sequence);
PublishLog."Message Type" := SendType;
PublishLog.Description := 'Work Request:' + Employee."First Name" +
' ' + Employee."Last Name";
PublishLog."Date Sent" := TODAY;
PublishLog."Time Sent" := TIME;

CASE SendType OF
1:
BEGIN
CLEAR(Mail);
PublishLog."Sent OK" :=
Mail.NewMessage(Employee."E-Mail", '', PublishLog.Descriptio
n,
Txt1 + ' ' + Txt2 + ' ' + Txt3, '', FALSE);
PublishLog."Receivers address" := Employee."E-Mail";
NoOfEmailsSent := NoOfEmailsSent + 1;
END;
0:
BEGIN
IF SendSMS(Employee."Mobile Phone No.", Txt1 + ' ' + Txt2 + '
' + Txt3, PublishLog.Description) THEN
PublishLog."Sent OK" := TRUE;
PublishLog."Receivers address" := Employee."Mobile Phone No.";
NoOfSMSSent := NoOfSMSSent + 1;
END;
END;
PublishLog."Employee No." := Employee."No.";
PublishLog."User Sending" := USERID;
PublishLog.Origin := Plan;
PublishLog.INSERT(TRUE);
IF Setup."Create Request Entries" THEN BEGIN
CurrSchedule.GET(Plan);
RosterWrkTable.SETRANGE("Plan No.", Plan);
RosterWrkTable.SETRANGE("Employee No.", Employee."No.");
IF RosterWrkTable.ISEMPTY THEN
StaffManFunc.InsertEmployeeRoster(Employee,CurrSchedule,0);
Schedule.INIT;
Schedule."Employee No." := Employee."No.";
Schedule."Schedule Date" := VacancyDate;
Schedule."Work Location" := WorkLocation;
Schedule."Plan No." := Plan;
Schedule."Work Role" := Role;
Schedule."Work Shift" := Shift;
IF NOT WrkScheduleLines.GET(Schedule."Work Shift", Schedule."Work
Role", 1, DATE2DWY(Schedule."Schedule Date", 1)) THEN
IF NOT WrkScheduleLines.GET(Schedule."Work Shift", '', 1, DATE2D
WY(Schedule."Schedule Date", 1)) THEN
WrkScheduleLines.INIT;
Schedule."From Time" := WrkScheduleLines."Time From";
Schedule."To Time" := WrkScheduleLines."Time To";
Schedule."After Midnight" := WrkScheduleLines."After Midnight";
Schedule.VALIDATE("No. Of Hours", WrkScheduleLines."Total Hours");
Schedule."Entry Type" := Schedule."Entry Type"::Request;
Schedule."Schedule Status" := CurrSchedule.Status;
OK := Schedule.INSERT(TRUE);
END;

COMMIT;
UNTIL Employee.NEXT = 0;
END;
IF NoOfEmailsSent > 0 THEN
MESSAGE(Text002,NoOfEmailsSent);
IF NoOfSMSSent > 0 THEN
MESSAGE(Text003,NoOfSMSSent);
END;
PROCEDURE SendSMS@1200020001(SMSnumber@1200020002 : Text[30];SmsMessage@1200
020003 : Text[250];Description@1200020006 : Text[200]) : Boolean;
VAR
URL@1200020001 : Text[250];
Setup@1200020004 : Record 10015010;
Mail@1200020005 : Codeunit 397;
HTTPRequest@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221
} 3.0:{F6D90F16-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v3.0'.XMLHTTP";
BEGIN
//HTTPRequest is an automation such as 'Microsoft XML, v6.0'.XMLHTTP
IF (SMSnumber <> '') AND (SmsMessage <> '') THEN BEGIN
Setup.GET;
CASE Setup."SMS Send Type" OF
Setup."SMS Send Type"::"HTTP Request" :
BEGIN
URL := Setup."SMS HTTP URL" + '?number=' + DELCHR(SMSnumber) + '&m
essage=';
CREATE(HTTPRequest,FALSE,TRUE);
HTTPRequest.open('POST', URL + SmsMessage, 0, Setup."SMS User", Se
tup."SMS Password");
HTTPRequest.send;
CLEAR(HTTPRequest);
EXIT(TRUE);
END;
Setup."SMS Send Type"::Email:
IF Mail.NewMessage(SMSnumber + '@' + Setup."SMS Email Server", '', D
escription, SmsMessage, '', FALSE) THEN
EXIT(TRUE);
END;
END;
EXIT(FALSE);
END;
PROCEDURE "------TRI Rohit------"@1000000004();
BEGIN
END;
PROCEDURE "SendSMS-Auto"@1000000000(SMSnumber@1000000002 : Text[30];SmsMessa
ge@1000000001 : Text[250];Description@1000000000 : Text[200]) : Boolean;
VAR
Setup@1000000003 : Record 10015010;
"----TRI Rohit-----"@1000000004 : Integer;
LRecRetailSetup@1000000005 : Record 10000700;
BEGIN
//WebServiceConnection is a DotNet such as LSWebServiceClient.WebServiceCo
nnection.'LSWebServiceClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1

94563f11b671d8c'
//used for sending SMS on scheduling.
LRecRetailSetup.GET;
IF (SMSnumber <> '') AND (SmsMessage <> '') THEN BEGIN
Setup.GET;
CASE Setup."SMS Send Type" OF
Setup."SMS Send Type"::"HTTP Request" :
BEGIN
IF NOT ISNULL(WebServiceConnection) THEN
CLEAR(WebServiceConnection);
WebServiceConnection := WebServiceConnection.WebServiceConnectio
n;
WebServiceConnection.Connect(STRSUBSTNO(Setup."SMS HTTP URL",Set
up."SMS User",Setup."SMS Password",SMSnumber,SmsMessage,LRecRetailSetup."Local S
tore No."),100000);
EXIT(TRUE);
{ Code Commented : Acknowledgement is always False from the Dotn
et variable.
ELSE
EXIT(FALSE);
}
END;
END;
END;
EXIT(FALSE);
END;
BEGIN
END.
}
}

Das könnte Ihnen auch gefallen