We have created some customized reports and these will open up based on Sales Order type in details tab. Same way we want to send report based on order type when we use Email Invoice/Memo action from Actions menu.
We tried to override the code but still we are seeing default report is sent in email. How can I fix this? My code is below:
[PXOverride]
public PXAction<ARInvoice> sendARInvoiceMemo;
[PXUIField(DisplayName = "Send AR Invoice/Memo", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXLookupButton]
public IEnumerable SendARInvoiceMemo(PXAdapter adapter, String reportID)
{
PXReportRequiredException ex = null;
foreach (ARInvoice doc in adapter.Get<ARInvoice>())
{
var parameters = new Dictionary<string, string>();
ARTran TranData = PXSelectReadonly<ARTran, Where<ARTran.tranType, Equal<Required<ARTran.tranType>>,
And<ARTran.refNbr, Equal<Required<ARTran.refNbr>>>>>.Select(Base, doc.DocType, doc.RefNbr);
if (TranData != null)
{
if (TranData.SOOrderType == "WS" || TranData.SOOrderType == "WO" || TranData.SOOrderType == "TS" || TranData.SOOrderType == "IM")
{
if (reportID == null) reportID = "KR501011";
Dictionary<string, string> mailParams = new Dictionary<string, string>();
if (reportID == "KR501011")
{
mailParams["DocType"] = doc.DocType;
mailParams["RefNbr"] = doc.RefNbr;
if (!ReportNotificationGenerator.Send(reportID, mailParams).Any())
{
throw new PXException(ErrorMessages.MailSendFailed);
}
}
Base.Clear();
Base.Document.Current = Base.Document.Search<ARInvoice.refNbr>(doc.RefNbr, doc.DocType);
}
if (TranData.SOOrderType == "RS" || TranData.SOOrderType == "RO" || TranData.SOOrderType == "PS" || TranData.SOOrderType == "QT")
{
if (reportID == null) reportID = "KR501012";
Dictionary<string, string> mailParams = new Dictionary<string, string>();
if (reportID == "KR501012")
{
mailParams["DocType"] = doc.DocType;
mailParams["RefNbr"] = doc.RefNbr;
if (!ReportNotificationGenerator.Send(reportID, mailParams).Any())
{
throw new PXException(ErrorMessages.MailSendFailed);
}
}
Base.Clear();
Base.Document.Current = Base.Document.Search<ARInvoice.refNbr>(doc.RefNbr, doc.DocType);
}
}
}
if (ex != null) throw ex;
return adapter.Get();
}