static void Na_SendingMailPurchRequisition(Args _args)
{
AlertUserInfo alertUserInfo;
sysUserInfo sysUserInfo,sysUserInfolog;
PurchReqTableExt purchReqTableExt;
PurchReqTable purchReqTable;
PurchReqLine purchReqLine;
EcoResCategory ecoResCategory;
str PRid,Journalno,netamt,sumAmount,Unitprice,unit;
str ItemId,Productname,procurementcategory,purchqty,postDate;
str linedetails;
TransDate PostedDate;
Amount netamount,amount;
SysEmailBatch batch = new SysEmailBatch();
#Define.AdminMailID("joseph.waititu@cic.co.ke")
#define.Opentablerowdiv("<tr><td>")
#define.Closetablediv("</td><td>")
#define.Open("<td>")
#define.Close("</td")
#define.Closetablerowdiv("</td></tr>")
#define.Header1("<p> Dear ")
#define.Header2(",</p><p>Kindly find the Payment Receipt Confirmation for the below Internal Purchase Requisition:</p>");
#define.header3("<table width= 40% border='2'><tr><td><h5>User Id</h5></td><td>")
#define.Header4("<tr><td><h5>User Name</h5></td><td>")
#define.Header5("<tr><td><h5>PR Id</h5></td><td>")
#define.Header6("<tr><td><h5>Journal no</h5></td><td>")
#define.Header7("<tr><td><h5>Posted Date</h5></td><td>")
#define.Header8("<tr><td><h5>Amount</h5></td><td>")
#define.Header9("</table>")
#define.Header10("<p>Product Details: </p><table width= 100% border='2'><tr><th>Product Code</th><th>Product Name</th><th>Procurement category</th><th>Qty</th><th>Unit</th><th>Unit Price</th><th>Net amount</th></tr>")
#define.Subject("Payment Receipt Confirmation ")
try
{
ttsbegin;
while select forupdate purchReqTableExt
where purchReqTableExt.BeforeSent == NoYes::Yes
&& purchReqTableExt.PaymentSent == NoYes::No
&& purchReqTableExt.JournalNum != ""
join sysUserInfolog
where sysUserInfolog.Id == purchReqTableExt.createdBy
join purchReqTable
where purchReqTable.RecId == purchReqTableExt.PurchReqTable
{
while select purchReqLine
where purchReqLine.PurchReqTable == purchReqTable.RecId
{
PRid = purchReqTable.PurchReqId;
Journalno = purchReqTableExt.JournalNum;
PostedDate = purchReqTable.TransDate;
netamount = purchReqLine.LineAmount;
amount += netamount;
ItemId = purchReqLine.ItemId;
Productname = InventTable::find(purchReqLine.ItemId).NameAlias;
Unitprice = strFmt("%1",purchReqLine.PurchPrice);
purchqty = strFmt("%1",purchReqLine.PurchQty);
netamt = strFmt("%1",purchReqLine.LineAmount);
sumAmount = strFmt("%1",amount);
postDate = strFmt("%1",purchReqTable.TransDate);
unit = unitOfMeasure::find(purchReqLine.purchunitofmeasure).Symbol;
select firstOnly name from ecoResCategory
where ecoResCategory.recid == purchReqLine.ProcurementCategory;
procurementcategory = ecoResCategory.Name;
linedetails += strFmt(#Opentablerowdiv + purchReqLine.ItemId + #Closetablediv + Productname +#Closetablediv + procurementcategory + #Closetablediv + purchqty + #Closetablediv+ unit+ #Closetablediv+ Unitprice +#Closetablediv+netamt + #Closetablerowdiv);
}
while select Email from sysUserInfo
join alertUserInfo
where alertUserInfo.PRPayment == NoYes::Yes
&& alertUserInfo.id == sysUserInfo.Id
{
batch.parmSenderAddr(#AdminMailID);
batch.parmEmailAddr("aslam.p@dhanushinfotech.net");//sysUserInfo.Email);
batch.parmMessageBody(#Header1 + alertUserInfo.Id + #Header2 + #Header3 + alertUserInfo.Id +#Closetablerowdiv + #Header4 + UserInfoHelp::userName(alertUserInfo.Id) +#Closetablerowdiv+ #Header5 + PRid +#Closetablerowdiv + #Header6 + Journalno +#Closetablerowdiv+ #Header7 + postDate +#Closetablerowdiv + #Header8 + sumAmount +#Closetablerowdiv+ #Header9 + #Header10 + linedetails+ #Header9);
batch.parmSubject(#Subject + PRid);
batch.run();
}
if (sysUserInfolog.Email)
{
batch.parmSenderAddr(#AdminMailID);
batch.parmEmailAddr("raghava.r@dhanushinfotech.net");//sysUserInfolog.Email);
batch.parmMessageBody(#Header1 + sysUserInfolog.Id + #Header2 + #Header3 + sysUserInfolog.Id +#Closetablerowdiv + #Header4 + UserInfoHelp::userName(sysUserInfolog.Id) +#Closetablerowdiv+ #Header5 + PRid +#Closetablerowdiv + #Header6 + Journalno +#Closetablerowdiv+ #Header7 + postDate +#Closetablerowdiv + #Header8 + sumAmount +#Closetablerowdiv+ #Header9 + #Header10 + linedetails+ #Header9);
batch.parmSubject(#Subject + PRid);
batch.run();
}
purchReqTableExt.PaymentSent = NoYes::Yes;
purchReqTableExt.update();
}
amount = 0.0;
ttsCommit;
}
catch (Exception::Error)
{
error("An Error occur while trying to send mail");
ttsAbort;
}
}
{
AlertUserInfo alertUserInfo;
sysUserInfo sysUserInfo,sysUserInfolog;
PurchReqTableExt purchReqTableExt;
PurchReqTable purchReqTable;
PurchReqLine purchReqLine;
EcoResCategory ecoResCategory;
str PRid,Journalno,netamt,sumAmount,Unitprice,unit;
str ItemId,Productname,procurementcategory,purchqty,postDate;
str linedetails;
TransDate PostedDate;
Amount netamount,amount;
SysEmailBatch batch = new SysEmailBatch();
#Define.AdminMailID("joseph.waititu@cic.co.ke")
#define.Opentablerowdiv("<tr><td>")
#define.Closetablediv("</td><td>")
#define.Open("<td>")
#define.Close("</td")
#define.Closetablerowdiv("</td></tr>")
#define.Header1("<p> Dear ")
#define.Header2(",</p><p>Kindly find the Payment Receipt Confirmation for the below Internal Purchase Requisition:</p>");
#define.header3("<table width= 40% border='2'><tr><td><h5>User Id</h5></td><td>")
#define.Header4("<tr><td><h5>User Name</h5></td><td>")
#define.Header5("<tr><td><h5>PR Id</h5></td><td>")
#define.Header6("<tr><td><h5>Journal no</h5></td><td>")
#define.Header7("<tr><td><h5>Posted Date</h5></td><td>")
#define.Header8("<tr><td><h5>Amount</h5></td><td>")
#define.Header9("</table>")
#define.Header10("<p>Product Details: </p><table width= 100% border='2'><tr><th>Product Code</th><th>Product Name</th><th>Procurement category</th><th>Qty</th><th>Unit</th><th>Unit Price</th><th>Net amount</th></tr>")
#define.Subject("Payment Receipt Confirmation ")
try
{
ttsbegin;
while select forupdate purchReqTableExt
where purchReqTableExt.BeforeSent == NoYes::Yes
&& purchReqTableExt.PaymentSent == NoYes::No
&& purchReqTableExt.JournalNum != ""
join sysUserInfolog
where sysUserInfolog.Id == purchReqTableExt.createdBy
join purchReqTable
where purchReqTable.RecId == purchReqTableExt.PurchReqTable
{
while select purchReqLine
where purchReqLine.PurchReqTable == purchReqTable.RecId
{
PRid = purchReqTable.PurchReqId;
Journalno = purchReqTableExt.JournalNum;
PostedDate = purchReqTable.TransDate;
netamount = purchReqLine.LineAmount;
amount += netamount;
ItemId = purchReqLine.ItemId;
Productname = InventTable::find(purchReqLine.ItemId).NameAlias;
Unitprice = strFmt("%1",purchReqLine.PurchPrice);
purchqty = strFmt("%1",purchReqLine.PurchQty);
netamt = strFmt("%1",purchReqLine.LineAmount);
sumAmount = strFmt("%1",amount);
postDate = strFmt("%1",purchReqTable.TransDate);
unit = unitOfMeasure::find(purchReqLine.purchunitofmeasure).Symbol;
select firstOnly name from ecoResCategory
where ecoResCategory.recid == purchReqLine.ProcurementCategory;
procurementcategory = ecoResCategory.Name;
linedetails += strFmt(#Opentablerowdiv + purchReqLine.ItemId + #Closetablediv + Productname +#Closetablediv + procurementcategory + #Closetablediv + purchqty + #Closetablediv+ unit+ #Closetablediv+ Unitprice +#Closetablediv+netamt + #Closetablerowdiv);
}
while select Email from sysUserInfo
join alertUserInfo
where alertUserInfo.PRPayment == NoYes::Yes
&& alertUserInfo.id == sysUserInfo.Id
{
batch.parmSenderAddr(#AdminMailID);
batch.parmEmailAddr("aslam.p@dhanushinfotech.net");//sysUserInfo.Email);
batch.parmMessageBody(#Header1 + alertUserInfo.Id + #Header2 + #Header3 + alertUserInfo.Id +#Closetablerowdiv + #Header4 + UserInfoHelp::userName(alertUserInfo.Id) +#Closetablerowdiv+ #Header5 + PRid +#Closetablerowdiv + #Header6 + Journalno +#Closetablerowdiv+ #Header7 + postDate +#Closetablerowdiv + #Header8 + sumAmount +#Closetablerowdiv+ #Header9 + #Header10 + linedetails+ #Header9);
batch.parmSubject(#Subject + PRid);
batch.run();
}
if (sysUserInfolog.Email)
{
batch.parmSenderAddr(#AdminMailID);
batch.parmEmailAddr("raghava.r@dhanushinfotech.net");//sysUserInfolog.Email);
batch.parmMessageBody(#Header1 + sysUserInfolog.Id + #Header2 + #Header3 + sysUserInfolog.Id +#Closetablerowdiv + #Header4 + UserInfoHelp::userName(sysUserInfolog.Id) +#Closetablerowdiv+ #Header5 + PRid +#Closetablerowdiv + #Header6 + Journalno +#Closetablerowdiv+ #Header7 + postDate +#Closetablerowdiv + #Header8 + sumAmount +#Closetablerowdiv+ #Header9 + #Header10 + linedetails+ #Header9);
batch.parmSubject(#Subject + PRid);
batch.run();
}
purchReqTableExt.PaymentSent = NoYes::Yes;
purchReqTableExt.update();
}
amount = 0.0;
ttsCommit;
}
catch (Exception::Error)
{
error("An Error occur while trying to send mail");
ttsAbort;
}
}
No comments:
Post a Comment