Email
sending/saving PDF through class (batch job):
KNBEmailProcessing class:
class KNBEmailProcessing extends
runbaseBatch
{
// Packed
PAYPeriodCode PeriodCode;//edit field
HcmPersonnelNumberId hcmPersonnelNumberId;//edit field
DimensionDefault defaultDimension;//edit field
PAYEmplGroupId Emplgrp;//edit field
sysQueryrun queryrun;
str PrintSlipEmplId;
PAYPeriods PAYPeriods;//table
PAYParameters PayParm;//table
ETamount DeservedBasicSalary;//edit field
dialogField dlgPeriodCode;
dialogField dlgEmplId;
dialogField dlgDimension;
dialogField dlgEmplgrp;
boolean ProjEmpl;
//DialogRunbase dialog;// Added by
#define.CurrentVersion(1)
#define.Version1(1)
#localmacro.CurrentList
PeriodCode,
hcmPersonnelNumberId,
defaultDimension,
Emplgrp
#endmacro
}
public boolean
canGoBatch()
{
//
return false;
return
true;
}
public Object dialog()
{
dialogRunbase dialog = dialog::newFormnameRunbase(formstr(Approveperiod),this);//Approveperiod-form name
;
dialog = super();
dlgPeriodCode = dialog.addField(extendedTypeStr(PAYPeriodCode));
return
dialog;
}
public boolean
getFromDialog()
{
boolean
ret;
ret = super();
PeriodCode =
dlgPeriodCode.value();
//
custAccount is handled via the edit method on the form
return
ret;
}
boolean getInfoNProcess(QueryRun _EmplRun)
{
HcmWorker hcmWorker;
boolean
ret;
;
while
(_EmplRun.next())
{
hcmWorker
=_EmplRun.getNo(1);
this.saveReportToPDF(hcmWorker);
this.SendMail(hcmWorker);
ret=true;
}
return
ret;
}
public void
initParmDefault()
{
this.initQuery();
super();
}
void initQuery()
{
query query = new
query();
QueryBuildDataSource
QBDS1,QBDS2;
;
QBDS1 =
query.addDataSource(tablenum(HcmWorker));
//
QBDS2 = QBDS1.addDataSource(tableNum(HcmEmployment));
//QBDS1.addRange(fieldnum(HcmWorker,PAYEmplGroupId));
//QBDS2.addRange(fieldnum(HcmEmployment,defaultDimension));
QBDS1.addRange(fieldnum(HcmWorker,PersonnelNumber));
queryrun = new sysqueryrun(query);
}
public void new()
{
;
super();
}
public container
pack()
{
return
[#CurrentVersion,#CurrentList,queryRun.pack()];
}
void PrintReport(Hcmworker _hcmWorker)
{
SrsReportRun reportRun;
Query query;
SRSReportPrintDestinationSettings SRSReportPrintDestinationSettings;
SRSPrintDestinationSettings
srsPrintSettings;
;
delete_from
SRSReportPrintDestinationSettings;
reportRun = new SRSReportRun();
reportRun.reportName("KNBAllEmplsPayslipReport.Report"); //<ReportName>.<DesignName>
//
Set printersettings
srsPrintSettings =
reportRun.printDestinationSettings();
srsPrintSettings.printMediumType(SRSPrintMediumType::Email);
srsPrintSettings.emailTo("a.mohamed@dynamicnetsoft.com");//
srsPrintSettings.emailAttachmentFileFormat(SRSReportFileFormat::PDF);
srsPrintSettings.emailSubject(strfmt("Payslip – %1", systemdateget()));
srsPrintSettings.pack();
reportRun.showDialog(false);
reportRun.init();
reportRun.run();
}
public QueryRun queryRun()
{
return
queryRun;
}
public void
run()
{
//
ttsbegin;
super();
PAYPeriods =
PAYPeriods::find();
PayParm =
PayParameters::find();
QueryRun.query().dataSourceNo(1).addRange(fieldnum(HcmWorker,Status)).value(SysQuery::value(HRMEmplStatus::Employed));
if(this.getInfoNProcess(QueryRun))
{
info("Processing is done!");
}
else
{
info("No records processed");
}
// Warning("Use Salary Payslip Report to print the Pay
Slips");
// this.printPaySlip(); ///TODO check
//
ttscommit;
}
void SaveReport(Hcmworker _hcmWorker)
{
//SrsReportRun reportRun;
//SRSPrintDestinationSettings srsPrintSettings;
//SRSReportPrintDestinationSettings SRSReportPrintDestinationSettings;
//;
//delete_from
SRSReportPrintDestinationSettings;
//reportRun
= new SRSReportRun();
//reportRun.reportName("KNBAllEmplsPayslipReport.Report"); //<ReportName>.<DesignName>
////
Set printersettings
//reportRun.saveParameters();
//
//srsPrintSettings
= reportRun.printDestinationSettings();
//srsPrintSettings.overwriteFile(true);
//srsPrintSettings.printMediumType(SRSPrintMediumType::File);
//srsPrintSettings.fileFormat(SRSReportFileFormat::PDF);
//srsPrintSettings.fileName("\\\\DNWADY0016L\\Users\\dns.pradeepk\\Desktop\\KNBEmailFld\\Payslip.pdf");
////
srsPrintSettings.fileName("C:\\Test.pdf");
//srsPrintSettings.pack();
//reportRun.showDialog(false);
////reportRun.saveParameters(); //For Report
parameters
//reportRun.init();
//reportRun.run();
}
void saveReportToPDF(Hcmworker _hcmWorker)
{
SrsReportRun srsReportRun;
srsReportRun = new SrsReportRun("KNBAllEmplsPayslipReport.report");
srsReportRun.init();
srsReportRun.reportCaption("Payslip");
//srsReportRun.reportParameter("KNBPaySlipQry_PersonnelNumber").value("000526");
srsReportRun.reportParameter("KNBPaySlipQry_PersonnelNumber").value(_hcmWorker.PersonnelNumber);//KNBPaySlipQry_PersonnelNumber - is visual studio
parameter name(contract class parameter)
srsReportRun.showDialog(false);
//
Print to a file named ReportExample in HTML/PDF format.
srsReportRun.printDestinationSettings().printMediumType(SRSPrintMediumType::File);
srsReportRun.printDestinationSettings().fileFormat(SRSReportFileFormat::PDF);
srsReportRun.printDestinationSettings().overwriteFile(true);
srsReportRun.printDestinationSettings().fileName(@"\\\\DNWADY0016L\\Users\\dns.pradeepk\\Desktop\\KNBEmailFld\\Payslip"+_hcmWorker.PersonnelNumber+".pdf");//computer
path
if(srsReportRun)
{
srsReportRun.executeReport();
}
}
//
BP deviation documented
void SendMail(HcmWorker _hcmWorker)
{
SysMailer mailer;
SysEmailParameters
parameters;
InteropPermission
permission;
str
subject , body ;
email emplEmailId;
;
//emplEmailId
= HcmWorker::findByPersonnelNumber('000526').email();
emplEmailId =
HcmWorker::findByPersonnelNumber(_hcmWorker.PersonnelNumber).email();
//if
(email == '')
//{
//checkFailed("From email address is missing, please specify
on company information.");
//return;
//}
if
(emplEmailId == '')
{
checkFailed(strfmt("Employee
email address is missing.",_hcmWorker.PersonnelNumber)); //_hcmWorker.PersonnelNumber));
return;
}
permission = new
InteropPermission(InteropKind::ComInterop);
Body = strfmt("Dear
%1, <br/><br/> Kindly find the attached Pay slip
<br/><br/> Regards <br/>,%2",_hcmWorker.name(),HcmWorker::findUserName(curuserId()));//<br/><br/> - for new line
Subject = strfmt("Salary Slip for Employee %1",
_hcmWorker.name());
permission.assert();
//InteropPermission.assert()
;
mailer = new SysMailer();
parameters =
SysEmailParameters::find();
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber, parameters.SMTPUserName,
SysEmailParameters::password(), false
);
mailer.fromAddress("hr@dynamicnetsoft.com"); // temporary created by Fasith later his will integrated
with email parameter value
//FileName
= strfmt("%1_%2.pdf",vendParameters.KNBVendInvoicePath +
vendInvoiceJour.InvoiceId,
//date2str(systemdateget(),123,2,123,2,123,4));
mailer.attachments().add("\\\\DNWADY0016L\\Users\\dns.pradeepk\\Desktop\\KNBEmailFld\\Payslip"+_hcmWorker.PersonnelNumber+".pdf");//completeFilePath);
mailer.tos().appendAddress(emplEmailid);
mailer.subject(subject);
mailer.htmlBody(body);
mailer.sendMail();
}
public boolean
showQueryValues()
{
return
true;
}
public boolean
unpack(container packedClass)
{
version version =
runbase::getVersion(packedClass);
container queryCon;
switch
(version)
{
case #CurrentVersion:
[version,#CurrentList,queryCon] = packedClass;
if (sysQuery::isPackedOk(queryCon))
queryRun = new queryRun(queryCon);
else
this.initQuery();
break;
default:
return false;
}
return
true;
}
public boolean
validate (Object calledFrom = null)
{
boolean
ret;
ret = super(calledFrom);
if(PAYPeriods::findCertn(PeriodCode).Approved
|| PAYPeriods::findCertn(PeriodCode).JournalCreated)
throw error("Period
is already approved/processed !,you can not do any calculation on this
period");
return
ret;
}
static void
main(args args)
{
//Code
by Alfasith for email generation
KNBEmailProcessing KNBEmailProcessing = new KNBEmailProcessing();
if
(KNBEmailProcessing.prompt())
KNBEmailProcessing.run();
}
No comments:
Post a Comment