public static void sendMail(JournalForm _journalForm)
{
InventDim inventDim;
InventDimParm invDimParm;
InventJournalTrans inventJournalTrans;
EcoResProductParameters ecoResProductParameters;
str itemonhand,availphysical;
AlertUserInfo alertUserInfo;
sysUserInfo sysUserInfo;
SysEmailBatch batch = new SysEmailBatch();
#Define.AdminMailID("joseph.waititu@cic.co.ke")
#define.Opentablerowdiv("<tr><td>")
#define.Closetablediv("</td><td>")
#define.Closetablerowdiv("</td></tr>")
#define.Header1("<h3>Dear ")
#define.Header2(",</h3><p>Below are the SKUs which have reached minimum level.</p><table width= 50% border='2' style='border-collapse:collapse'><tr><th>Item Id</th><th>Name</th><th>On hand</th></tr>");
#define.Header3("</table>")
#define.Subject("Items Reached Minimum On Hand")
try
{
select firstOnly InventLocationId from ecoResProductParameters;
while select ItemId,sum(Qty),InventDimId from inventJournalTrans group by ItemId,InventDimId
where inventJournalTrans.JournalId == _journalForm.journalTable().JournalId
join InventLocationId from inventDim group by InventLocationId
where inventDim.InventDimId == inventJournalTrans.InventDimId
&& inventDim.InventLocationId == ecoResProductParameters.CICInventLocationId
{
inventDim.InventLocationId = ecoResProductParameters.InventLocationId;
inventDim = InventDim::findOrCreate(inventDim);
invDimParm.initFromInventDim(InventDim::find(inventDim.inventDimId));
if(inventSum::findSum(inventJournalTrans.ItemId,inventDim,invDimParm).AvailPhysical <= inventTable::find(inventJournalTrans.ItemId).MinimumStockLevel )
{
availphysical = strFmt("%1",inventSum::findSum(inventJournalTrans.ItemId,inventDim,invDimParm).AvailPhysical);
itemonhand += strFmt(#Opentablerowdiv + inventJournalTrans.ItemId + #Closetablediv + InventTable::find(inventJournalTrans.ItemId).NameAlias + #Closetablediv + availphysical + #Closetablerowdiv);
}
}
if(itemonhand)
{
while select Id,Email from alertUserInfo
where alertUserInfo.MinimumStockLevel == NoYes::Yes
{
select Email from sysUserInfo
where sysUserInfo.Id == alertUserInfo.id;
batch.parmSenderAddr(#AdminMailID);
batch.parmEmailAddr(sysUserInfo.Email);
batch.parmMessageBody(#Header1 + alertUserInfo.Id + #Header2 + itemonhand + #Header3);
batch.parmSubject(#Subject);
batch.run();
}
}
}
catch (Exception::Error)
{
error("An error occur while sending mail");
}
}
{
InventDim inventDim;
InventDimParm invDimParm;
InventJournalTrans inventJournalTrans;
EcoResProductParameters ecoResProductParameters;
str itemonhand,availphysical;
AlertUserInfo alertUserInfo;
sysUserInfo sysUserInfo;
SysEmailBatch batch = new SysEmailBatch();
#Define.AdminMailID("joseph.waititu@cic.co.ke")
#define.Opentablerowdiv("<tr><td>")
#define.Closetablediv("</td><td>")
#define.Closetablerowdiv("</td></tr>")
#define.Header1("<h3>Dear ")
#define.Header2(",</h3><p>Below are the SKUs which have reached minimum level.</p><table width= 50% border='2' style='border-collapse:collapse'><tr><th>Item Id</th><th>Name</th><th>On hand</th></tr>");
#define.Header3("</table>")
#define.Subject("Items Reached Minimum On Hand")
try
{
select firstOnly InventLocationId from ecoResProductParameters;
while select ItemId,sum(Qty),InventDimId from inventJournalTrans group by ItemId,InventDimId
where inventJournalTrans.JournalId == _journalForm.journalTable().JournalId
join InventLocationId from inventDim group by InventLocationId
where inventDim.InventDimId == inventJournalTrans.InventDimId
&& inventDim.InventLocationId == ecoResProductParameters.CICInventLocationId
{
inventDim.InventLocationId = ecoResProductParameters.InventLocationId;
inventDim = InventDim::findOrCreate(inventDim);
invDimParm.initFromInventDim(InventDim::find(inventDim.inventDimId));
if(inventSum::findSum(inventJournalTrans.ItemId,inventDim,invDimParm).AvailPhysical <= inventTable::find(inventJournalTrans.ItemId).MinimumStockLevel )
{
availphysical = strFmt("%1",inventSum::findSum(inventJournalTrans.ItemId,inventDim,invDimParm).AvailPhysical);
itemonhand += strFmt(#Opentablerowdiv + inventJournalTrans.ItemId + #Closetablediv + InventTable::find(inventJournalTrans.ItemId).NameAlias + #Closetablediv + availphysical + #Closetablerowdiv);
}
}
if(itemonhand)
{
while select Id,Email from alertUserInfo
where alertUserInfo.MinimumStockLevel == NoYes::Yes
{
select Email from sysUserInfo
where sysUserInfo.Id == alertUserInfo.id;
batch.parmSenderAddr(#AdminMailID);
batch.parmEmailAddr(sysUserInfo.Email);
batch.parmMessageBody(#Header1 + alertUserInfo.Id + #Header2 + itemonhand + #Header3);
batch.parmSubject(#Subject);
batch.run();
}
}
}
catch (Exception::Error)
{
error("An error occur while sending mail");
}
}
No comments:
Post a Comment