Hello all,
I have a basic requirement that an AP Bill should only be created if the PO receipt is 100%, else it should allow the user to even create it. How to achieve this?
Hello all,
I have a basic requirement that an AP Bill should only be created if the PO receipt is 100%, else it should allow the user to even create it. How to achieve this?
Best answer by Naveen Boga
Hi
Graph Extension — RowInserting / RowPersisting Override
Extend the APInvoiceEntry graph and add a validation that checks receipt completion before allowing the bill to be saved.
Hope this helps!
public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
public override void Initialize()
{
base.Initialize();
}
protected void _(Events.RowPersisting<APInvoice> e)
{
if (e.Operation == PXDBOperation.Insert ||
e.Operation == PXDBOperation.Update)
{
APInvoice bill = e.Row as APInvoice;
if (bill == null) return;
if (!IsReceiptFullyReceived(bill))
{
e.Cache.RaiseExceptionHandling<APInvoice.refNbr>(
bill,
bill.RefNbr,
new PXSetPropertyException(
"AP Bill cannot be created. The linked PO Receipt is not 100% complete.",
PXErrorLevel.Error));
e.Cancel = true;
}
}
}
private bool IsReceiptFullyReceived(APInvoice bill)
{
// Query POReceiptLine to check if all lines are fully billed
var receiptLines = PXSelectJoin<POReceiptLine,
InnerJoin<APTran,
On<APTran.receiptNbr, Equal<POReceiptLine.receiptNbr>,
And<APTran.receiptLineNbr, Equal<POReceiptLine.lineNbr>>>>,
Where<APTran.tranType, Equal<Required<APTran.tranType>>,
And<APTran.refNbr, Equal<Required<APTran.refNbr>>>>>
.Select(Base, bill.DocType, bill.RefNbr);
foreach (PXResult<POReceiptLine, APTran> row in receiptLines)
{
POReceiptLine receiptLine = row;
// Compare received qty vs billed qty
if (receiptLine.ReceiptQty > receiptLine.BilledQty)
{
return false;
}
}
return true;
}
}
No account yet? Create an account
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.