after upgrading, The bpm for PO doesn’t work anymore.
Before, when po has been rejected, buyer should receive the email.
here is the code
Erp.Tables.POHeader POHeader;
Erp.Tables.PurAgent PurAgent;
Erp.Tables.Vendor Vendor;
string strLineDesc = string.Empty;
string strVendorName = string.Empty;
string strBuyerName = string.Empty;
foreach (var ttPOApvMsg_iterator in (from ttPOApvMsg_Row in ds.POApvMsg
where ttPOApvMsg_Row.Company == Session.CompanyID
select ttPOApvMsg_Row))
{
var ttPOApvMsgRow = ttPOApvMsg_iterator;
POHeader = (from POHeader_Row in Db.POHeader
where POHeader_Row.Company == Session.CompanyID && POHeader_Row.PONum == ttPOApvMsgRow.PONum
select POHeader_Row).FirstOrDefault();
if (POHeader != null)
{
/*Get Line Description BEGIN*/
foreach (var ttPODetailResults in (from ttPODetailRow in Db.PODetail
where ttPODetailRow.Company == Session.CompanyID
&& ttPODetailRow.PONUM == POHeader.PONum
select ttPODetailRow))
{
if (String.IsNullOrEmpty(strLineDesc))
{
strLineDesc = Convert.ToString(ttPODetailResults.POLine) + ". " + ttPODetailResults.LineDesc + ", Qty: " + String.Format("{0:0}", ttPODetailResults.OrderQty) + ", Unit Price: " + String.Format("{0:0.00}", ttPODetailResults.UnitCost) + ", Cost: " + String.Format("{0:0.00}", ttPODetailResults.OrderQty * ttPODetailResults.UnitCost);
}
else
{
strLineDesc = strLineDesc + "\n" + Convert.ToString(ttPODetailResults.POLine) + ". " + ttPODetailResults.LineDesc + ", Qty: " + String.Format("{0:0}", ttPODetailResults.OrderQty) + ", Unit Price: " + String.Format("{0:0.00}", ttPODetailResults.UnitCost) + ", Cost: " + String.Format("{0:0.00}", ttPODetailResults.OrderQty * ttPODetailResults.UnitCost);
}
}
/*Get Line Description END*/
/*Get Supplier Name BEGIN*/
Vendor = (from VendorRow in Db.Vendor
where VendorRow.Company == Session.CompanyID
&& VendorRow.VendorNum == POHeader.VendorNum
select VendorRow).FirstOrDefault();
if (Vendor != null)
{
strVendorName = Vendor.Name;
}
/*Get Supplier Name END*/
/*Get Buyer Name BEGIN*/
var PurAgentResults = (from PurAgentRow in Db.PurAgent
where PurAgentRow.Company == Session.CompanyID
&& PurAgentRow.BuyerID == POHeader.BuyerID
select PurAgentRow).FirstOrDefault();
if (PurAgentResults != null)
{
var PerConResults = (from PerConRow in Db.PerCon
where PerConRow.Company == Session.CompanyID
&& PerConRow.PerConID == PurAgentResults.PerConID
select PerConRow).FirstOrDefault();
if (PerConResults != null)
{
strBuyerName = PerConResults.Name;
}
}
/*Get Buyer Name END*/
if ((string.Compare(ttPOApvMsgRow.ApproverResponse, "APPROVED", true) == 0 || string.Compare(ttPOApvMsgRow.ApproverResponse, "REJECTED", true) == 0) && POHeader.ApprovalStatus=="A")
{
PurAgent = (from PurAgent_Row in Db.PurAgent
where PurAgent_Row.Company == Session.CompanyID && string.Compare(PurAgent_Row.BuyerID, POHeader.BuyerID, true) == 0
select PurAgent_Row).FirstOrDefault();
if (PurAgent != null)
{
if (PurAgent.EMailAddress != null)
{
var mailer = GetMailer(async: true);
var message = new Ice.Mail.SmtpMail();
message.SetFrom("epicor@ppsvcs.com");
message.SetTo(PurAgent.EMailAddress);
message.SetSubject(Session.CompanyID + " Purchase Order Approval");
message.SetBody("PO " + Convert.ToString(ttPOApvMsgRow.PONum) + " has been " + ttPOApvMsgRow.ApproverResponse +"\n"+"Comment: "+ttPOApvMsgRow.MsgText);
mailer.Send(message);
}
}
}
if (String.IsNullOrEmpty(ttPOApvMsgRow.ApproverResponse))
{
PurAgent = (from PurAgent_Row in Db.PurAgent
where PurAgent_Row.Company == Session.CompanyID && string.Compare(PurAgent_Row.BuyerID, ttPOApvMsgRow.MsgTo, true) == 0
select PurAgent_Row).FirstOrDefault();
if (PurAgent != null)
{
if (PurAgent.EMailAddress != null)
{
var mailer = GetMailer(async: true);
var message = new Ice.Mail.SmtpMail();
message.SetFrom("epicor@ppsvcs.com");
message.SetTo(PurAgent.EMailAddress);
message.SetSubject(Session.CompanyID + " Purchase Order needs Approval: " + POHeader.PONum + " Ordered By: " + strBuyerName);
message.SetBody("PO: " + Convert.ToString(POHeader.PONum) + "\nSupplier: " + strVendorName + "\n\n" + strLineDesc);
mailer.Send(message);
} /*End if PurAgent.EMailAddress != null*/
} /*End PurAgent != null*/
} /*End ApproverResponse false*/
} /*End POHeader*/
} /*End foreach ttPOApvMsg*/