protected virtual IEnumerable documentList() { foreach (APInvoiceExt doc in PXSelect <APInvoiceExt> .Select(this)) { bool hasUnreleasedDocument = false; foreach (PXResult <APRetainageInvoice, APTran> res in PXSelectJoin <APRetainageInvoice, LeftJoin <APTran, On <APRetainageInvoice.paymentsByLinesAllowed, Equal <True>, And <APTran.tranType, Equal <APRetainageInvoice.docType>, And <APTran.refNbr, Equal <APRetainageInvoice.refNbr>, And <APTran.origLineNbr, Equal <Required <APTran.origLineNbr> > > > > > >, Where <APRetainageInvoice.isRetainageDocument, Equal <True>, And <APRetainageInvoice.origDocType, Equal <Required <APInvoice.docType> >, And <APRetainageInvoice.origRefNbr, Equal <Required <APInvoice.refNbr> >, And <APRetainageInvoice.released, NotEqual <True> > > > > > .Select(this, doc.APTranLineNbr, doc.DocType, doc.RefNbr)) { APRetainageInvoice invoice = res; APTran tran = res; if (invoice.PaymentsByLinesAllowed != true || tran.LineNbr != null) { hasUnreleasedDocument = true; } } if (!hasUnreleasedDocument) { yield return(doc); } } }
protected virtual void APInvoice_RowSelecting(PXCache sender, PXRowSelectingEventArgs e) { APInvoice document = e.Row as APInvoice; if (document == null) { return; } if (document.RetainageApply == true && document.Released == true) { using (new PXConnectionScope()) { APRetainageInvoice dummyInvoice = new APRetainageInvoice(); dummyInvoice.CuryRetainageUnpaidTotal = 0m; dummyInvoice.CuryRetainagePaidTotal = 0m; foreach (APRetainageInvoice childRetainageBill in RetainageDocuments .Select(document.DocType, document.RefNbr) .RowCast <APRetainageInvoice>() .Where(res => res.Released == true)) { dummyInvoice.DocType = childRetainageBill.DocType; dummyInvoice.RefNbr = childRetainageBill.RefNbr; dummyInvoice.CuryOrigDocAmt = childRetainageBill.CuryOrigDocAmt; dummyInvoice.CuryDocBal = childRetainageBill.CuryOrigDocAmt; foreach (APAdjust application in PXSelect <APAdjust, Where <APAdjust.adjdDocType, Equal <Required <APAdjust.adjdDocType> >, And <APAdjust.adjdRefNbr, Equal <Required <APAdjust.adjdRefNbr> >, And <APAdjust.released, Equal <True>, And <APAdjust.voided, NotEqual <True>, And <APAdjust.adjgDocType, NotEqual <APDocType.debitAdj> > > > > > > .Select(Base, childRetainageBill.DocType, childRetainageBill.RefNbr)) { dummyInvoice.AdjustBalance(application); } dummyInvoice.CuryRetainageUnpaidTotal += childRetainageBill.DocBal * childRetainageBill.SignAmount; dummyInvoice.CuryRetainagePaidTotal += (dummyInvoice.CuryOrigDocAmt - dummyInvoice.CuryDocBal) * dummyInvoice.SignAmount; } document.CuryRetainageUnpaidTotal = document.CuryRetainageUnreleasedAmt + dummyInvoice.CuryRetainageUnpaidTotal; document.CuryRetainagePaidTotal = dummyInvoice.CuryRetainagePaidTotal; } } }
public virtual IEnumerable ReleaseRetainage(PXAdapter adapter) { APInvoice doc = Base.Document.Current; if (doc != null && doc.DocType == APDocType.Invoice && doc.RetainageApply == true && doc.CuryRetainageUnreleasedAmt > 0m) { APRetainageInvoice retainageDoc = RetainageDocuments .Select() .RowCast <APRetainageInvoice>() .FirstOrDefault(row => row.Released != true); if (retainageDoc != null) { throw new PXException( Messages.ReleaseRetainageNotReleasedDocument, PXMessages.LocalizeNoPrefix(APDocTypeDict[retainageDoc.DocType]), retainageDoc.RefNbr, PXMessages.LocalizeNoPrefix(APDocTypeDict[doc.DocType])); } APRegister reversingDoc; if (Base.CheckReversingRetainageDocumentAlreadyExists(Base.Document.Current, out reversingDoc)) { throw new PXException( Messages.ReleaseRetainageReversingDocumentExists, PXMessages.LocalizeNoPrefix(APDocTypeDict[doc.DocType]), PXMessages.LocalizeNoPrefix(APDocTypeDict[reversingDoc.DocType]), reversingDoc.RefNbr); } Base.Save.Press(); RetainageOptions retainageOpts = ReleaseRetainageOptions.Current; WebDialogResult wdr = ReleaseRetainageOptions.AskExt( (graph, view) => { retainageOpts.CuryRetainageTotal = doc.CuryRetainageUnreleasedAmt; retainageOpts.RetainagePct = 100m; retainageOpts.CuryRetainageAmt = doc.CuryRetainageUnreleasedAmt; retainageOpts.CuryRetainageUnreleasedAmt = retainageOpts.CuryRetainageTotal - retainageOpts.CuryRetainageAmt; }, true); if (wdr == WebDialogResult.OK) { APInvoice invoice = PXCache <APInvoice> .CreateCopy(doc); try { ReleaseRetainageProc(invoice, retainageOpts); return(new List <APInvoice> { Base.Document.Current }); } catch (PXException) { Base.Clear(PXClearOption.PreserveTimeStamp); Base.Document.Current = doc; throw; } } } return(adapter.Get()); }