I am trying to create a BPM that will check the Customer Price Lists prior to posting an invoice. I have no problem with the placement of the BPM and I almost have the following code working, however the problem is we could have more than 1 active price list with the part number in, or the part number may not exist until the second price list.
I think I have the right order for linking \ checking the tables but the code fails if the part number isn’t in the first list. I think it works OK for finding the part if it is in the first list and not the second though I am still testing.
// Checks Price List Unit Price against Invoice Price if BASE currency
// Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.PrePrintInvoices");
// Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.PrePrintInvoices - ipGroupID: " + ipGroupID);
Erp.Tables.InvcHead InvcHead;
Erp.Tables.InvcDtl InvcDtl;
Erp.Tables.Customer Customer;
Erp.Tables.CustomerPriceLst CustomerPriceLst;
Erp.Tables.PriceLst PriceLst;
Erp.Tables.PriceLstParts PriceLstParts;
decimal unitPrice = decimal.Zero;
string infomsg = string.Empty;
string crlf = "\r\n";
foreach (var InvcHead_iterator in (from InvcHead_Row in Db.InvcHead
where InvcHead_Row.Company == Session.CompanyID
&& InvcHead_Row.GroupID == ipGroupID
select InvcHead_Row))
{
InvcHead = InvcHead_iterator;
if (InvcHead != null)
{
foreach (var InvcDtl_iterator in (from InvcDtl_Row in Db.InvcDtl
where InvcDtl_Row.Company == InvcHead.Company
&& InvcDtl_Row.InvoiceNum == InvcHead.InvoiceNum
select InvcDtl_Row))
{
InvcDtl = InvcDtl_iterator;
Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.Update - InvcDtl.InvNum - InvLine: " + InvcDtl.InvoiceNum + " - " + InvcDtl.InvoiceLine);
if (InvcDtl != null)
{
Customer = (from Customer_Row in Db.Customer
where Customer_Row.Company == InvcHead.Company
&& Customer_Row.CustNum == InvcHead.CustNum
select Customer_Row).FirstOrDefault();
Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.Update - Customer.CustNum: " + Customer.CustNum);
if (Customer != null)
{
CustomerPriceLst = (from CustomerPriceLst_Row in Db.CustomerPriceLst
where CustomerPriceLst_Row.Company == Customer.Company
&& CustomerPriceLst_Row.CustNum == Customer.CustNum
orderby CustomerPriceLst_Row.SeqNum ascending
select CustomerPriceLst_Row).FirstOrDefault();
Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.Update - CustomerPriceLst.ListCode: " + CustomerPriceLst.ListCode);
if (CustomerPriceLst != null)
{
PriceLst = (from PriceLst_Row in Db.PriceLst
where PriceLst_Row.Company == CustomerPriceLst.Company
&& PriceLst_Row.ListCode == CustomerPriceLst.ListCode
&& PriceLst_Row.EndDate == null
orderby PriceLst_Row.StartDate descending
select PriceLst_Row).FirstOrDefault();
Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.Update - PriceLst.ListCode: " + PriceLst.ListCode);
if (PriceLst != null)
{
PriceLstParts = (from PriceLstParts_Row in Db.PriceLstParts
where PriceLstParts_Row.Company == PriceLst.Company
&& PriceLstParts_Row.ListCode == PriceLst.ListCode
&& PriceLstParts_Row.PartNum == InvcDtl.PartNum
select PriceLstParts_Row).FirstOrDefault();
Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.Update - PriceLstParts.PartNum - PriceLstPrice - InvPrice: " + PriceLstParts.PartNum + " - " + PriceLstParts.BasePrice + " - " + InvcDtl.DocUnitPrice);
if (PriceLstParts != null)
// Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.Update - PriceLstPart Not Null");
{
{
if (InvcDtl.DocUnitPrice != PriceLstParts.BasePrice)
{
infomsg = infomsg + "THE UNIT PRICE ON INVOICE NUMBER " + System.Convert.ToString(InvcHead.InvoiceNum) + " FOR PART NUMBER " + System.Convert.ToString(InvcDtl.PartNum) + " (INVOICE LINE " + InvcDtl.InvoiceLine + ") DOES NOT MATCH THE CURRENT PRICE LIST PRICE!" + crlf + crlf + "Please check before Posting.";
Ice.Diagnostics.Log.WriteEntry("zBPM - ARInvoice.Update - infomsg: " + infomsg);
Epicor.Customization.Bpm.InfoMessage.Publish(infomsg);
infomsg = "";
}
}
}
}
}
}
}
}
}
} ```