protected virtual void APAdjust_CuryAdjgAmt_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e, PXFieldDefaulting del) { if (del != null) { del(sender, e); } APAdjust apRow = e.Row as APAdjust; var aPInvoiceCurData = SelectFrom <APInvoice> .View.Select(Base).RowCast <APInvoice>().ToList().FirstOrDefault(x => x.DocType == apRow.AdjdDocType && x.RefNbr == apRow.AdjdRefNbr); var aPPaymentVendorCrossRateAttr = SelectFrom <CSAnswers> . LeftJoin <BAccountR> .On <CSAnswers.refNoteID.IsEqual <BAccountR.noteID> > . LeftJoin <APAdjust> .On <BAccountR.bAccountID.IsEqual <APAdjust.vendorID> > . Where <APAdjust.vendorID.IsEqual <@P.AsInt> .And <CSAnswers.attributeID.IsEqual <VendorCrossRateAttr> > > . View.Select(Base, apRow.VendorID).TopFirst?.Value; if (aPPaymentVendorCrossRateAttr == "1") { var curyInfo = SelectFrom <CurrencyInfo> .Where <CurrencyInfo.curyInfoID.IsEqual <@P.AsInt> > .View.Select(Base, aPInvoiceCurData?.CuryInfoID).TopFirst; var curyInfoCuryRate = curyInfo?.CuryMultDiv == "M" ? curyInfo?.CuryRate : curyInfo?.RecipRate; var aPInvoiceCuryOrigDocAmt = aPInvoiceCurData?.CuryOrigDocAmt; e.NewValue = Math.Round((decimal)(aPInvoiceCuryOrigDocAmt * curyInfoCuryRate)); } }
protected static void CreatePPDApplications(APPaymentEntry paymentEntry, List <PendingPPDDebitAdjApp> list, APPayment debitAdj) { foreach (PendingPPDDebitAdjApp doc in list) { var adj = new APAdjust(); adj.AdjdDocType = doc.AdjdDocType; adj.AdjdRefNbr = doc.AdjdRefNbr; adj = paymentEntry.Adjustments_Raw.Insert(adj); adj.CuryAdjgAmt = doc.InvCuryDocBal; adj = paymentEntry.Adjustments_Raw.Update(adj); string refNbr = debitAdj.RefNbr; PXUpdate <Set <APAdjust.pPDDebitAdjRefNbr, Required <APAdjust.pPDDebitAdjRefNbr> >, APAdjust, Where <APAdjust.adjdDocType, Equal <Required <APAdjust.adjdDocType> >, And <APAdjust.adjdRefNbr, Equal <Required <APAdjust.adjdRefNbr> >, And <APAdjust.adjgDocType, Equal <Required <APAdjust.adjgDocType> >, And <APAdjust.adjgRefNbr, Equal <Required <APAdjust.adjgRefNbr> >, And <APAdjust.released, Equal <True>, And <APAdjust.voided, NotEqual <True>, And <APAdjust.pendingPPD, Equal <True> > > > > > > > > .Update(paymentEntry, refNbr, doc.AdjdDocType, doc.AdjdRefNbr, doc.AdjgDocType, doc.AdjgRefNbr); } }
public IEnumerable Adjustments() { var newAdjustments = SelectFrom <APAdjust> . LeftJoin <APInvoice> .On <APInvoice.docType.IsEqual <APAdjust.adjdDocType> .And <APInvoice.refNbr.IsEqual <APAdjust.adjdRefNbr> > > . LeftJoin <APTran> .On <APInvoice.paymentsByLinesAllowed.IsEqual <True> .And <APTran.tranType.IsEqual <APAdjust.adjdDocType> .And <APTran.refNbr.IsEqual <APAdjust.adjdRefNbr> .And <APTran.lineNbr.IsEqual <APAdjust.adjdLineNbr> > > > > . Where <APAdjust.adjgDocType.IsEqual <APPayment.docType.FromCurrent> .And <APAdjust.adjgRefNbr.IsEqual <APPayment.refNbr.FromCurrent> .And <APAdjust.released.IsNotEqual <True> > > > . View.Select(Base); var row = Base.Document.Current; if (row == null) { return(newAdjustments); } var aPPaymentVendorCrossRateAttr = SelectFrom <CSAnswers> . LeftJoin <BAccountR> .On <CSAnswers.refNoteID.IsEqual <BAccountR.noteID> > . LeftJoin <APPayment> .On <BAccountR.bAccountID.IsEqual <APPayment.vendorID> > . Where <APPayment.refNbr.IsEqual <@P.AsString> .And <APPayment.docType.IsEqual <@P.AsString> > .And <CSAnswers.attributeID.IsEqual <VendorCrossRateAttr> > > . View.Select(Base, row.RefNbr, row.DocType).TopFirst?.Value; foreach (PXResult <APAdjust, APInvoice, APTran> adjustment in newAdjustments) { APAdjust aPAdjust = adjustment; APInvoice aPInvoice = adjustment; if (row.CuryID != aPInvoice.CuryID && aPPaymentVendorCrossRateAttr == "1" && Convert.ToDecimal(aPAdjust.AdjdCuryRate) != 1.00m && aPInvoice.CuryInfoID != null) { var curyInfo = SelectFrom <CurrencyInfo> .Where <CurrencyInfo.curyInfoID.IsEqual <@P.AsInt> > .View.Select(Base, aPInvoice.CuryInfoID).TopFirst; var curyInfoCuryRate = curyInfo?.CuryMultDiv == "M" ? curyInfo?.CuryRate : curyInfo?.RecipRate; aPAdjust.AdjdCuryRate = curyInfoCuryRate == null ? aPAdjust.AdjdCuryRate : curyInfoCuryRate; } } return(newAdjustments); }
private static void SetAdjustmentStubNumber(APPaymentEntry pe, APPayment doc, APAdjust adj, string StubNbr) { adj.StubNbr = StubNbr; adj.CashAccountID = doc.CashAccountID; adj.PaymentMethodID = doc.PaymentMethodID; pe.Adjustments.Cache.Update(adj); }
public virtual IEnumerable documents() { PendingInvoiceFilter filter = Filter.Current; Dictionary <CashAcctKey, PendingPaymentSummary> result = new Dictionary <CashAcctKey, PendingPaymentSummary>(); if (filter == null && !filter.PayDate.HasValue) { return(result.Values); } PXSelectBase <APInvoice> sel = new PXSelectJoin <APInvoice, InnerJoin <CashAccount, On <CashAccount.cashAccountID, Equal <APInvoice.payAccountID> >, LeftJoin <APAdjust, On <APInvoice.docType, Equal <APAdjust.adjdDocType>, And <APInvoice.refNbr, Equal <APAdjust.adjdRefNbr>, And <APAdjust.released, Equal <BitOff> > > > > >, Where <APInvoice.paySel, Equal <BitOn>, And2 <Where <APInvoice.released, Equal <True>, Or <APInvoice.prebooked, Equal <True> > >, And <APInvoice.openDoc, Equal <BitOn> > > >, OrderBy < Asc <APInvoice.docType, Asc <APInvoice.refNbr> > > >(this); /*if(filter.CuryID != null) * { * sel.WhereAnd<Where<APInvoice.curyID, Equal<Current<PendingInvoiceFilter.curyID>>>>(); * }*/ if (filter.PayDate != null) { sel.WhereAnd <Where <APInvoice.payDate, LessEqual <Current <PendingInvoiceFilter.payDate> > > >(); } if (filter.PayAccountID != null) { sel.WhereAnd <Where <APInvoice.payAccountID, Equal <Current <PendingInvoiceFilter.payAccountID> > > >(); } if (filter.PayTypeID != null) { sel.WhereAnd <Where <APInvoice.payTypeID, Equal <Current <PendingInvoiceFilter.payTypeID> > > >(); } APInvoiceKey lastInvoice = null; foreach (PXResult <APInvoice, CashAccount, APAdjust> it in sel.Select()) { APInvoice inv = (APInvoice)it; CashAccount acct = (CashAccount)it; APAdjust adjust = (APAdjust)it; if (adjust.AdjdDocType != null) { continue; //Skip invoices, having unreleased payments } APInvoiceKey invNbr = new APInvoiceKey(inv.DocType, inv.RefNbr); if (lastInvoice != null && lastInvoice.CompareTo(invNbr) == 0) { continue; //Skip multiple entries for invoice } //inv.DocCount = it.RowCount; lastInvoice = invNbr; CashAcctKey key = new CashAcctKey(inv.PayAccountID.Value, inv.PayTypeID); PendingPaymentSummary res = null; if (!result.ContainsKey(key)) { res = new PendingPaymentSummary(); res.PayAccountID = inv.PayAccountID; res.PayTypeID = inv.PayTypeID; res.CuryID = acct.CuryID; result[key] = res; //Assign new CyrrencyInfo - to do conersion correctly. RateTypeID must be taken from the Cash Account CurrencyInfo new_info = new CurrencyInfo(); new_info.CuryID = res.CuryID; new_info.CuryRateTypeID = acct.CuryRateTypeID; new_info.CuryEffDate = filter.PayDate; new_info = this.CurrencyInfo_CuryInfoID.Insert(new_info); res.CuryInfoID = new_info.CuryInfoID; } else { res = result[key]; } APAdjust adj = new APAdjust(); adj.VendorID = inv.VendorID; adj.AdjdDocType = inv.DocType; adj.AdjdRefNbr = inv.RefNbr; adj.AdjgDocType = APDocType.Check; adj.AdjgRefNbr = " <NEW>"; try { PaymentEntry.CalcBalances <APInvoice, APAdjust>(this.CurrencyInfo_CuryInfoID, res.CuryInfoID, filter.PayDate, inv, adj); } catch (PXRateIsNotDefinedForThisDateException ex) { Documents.Cache.RaiseExceptionHandling <PendingPaymentSummary.curyID>(res, res.CuryID, new PXSetPropertyException(ex.Message, PXErrorLevel.RowError)); } Aggregate(res, new PXResult <APAdjust, APInvoice> (adj, inv), filter.PayDate); } return(result.Values); }
public static void AssignNumbers(APPaymentEntry pe, APPayment doc, ref string NextCheckNbr, bool skipStubs) { pe.RowPersisting.RemoveHandler <APAdjust>(pe.APAdjust_RowPersisting); pe.Clear(PXClearOption.PreserveTimeStamp); pe.Document.Current = (APPayment)pe.Document.Search <APPayment.refNbr>(doc.RefNbr, doc.DocType); if (String.IsNullOrEmpty(NextCheckNbr) == false) { if (String.IsNullOrEmpty(pe.Document.Current.ExtRefNbr)) { pe.Document.Current.StubCntr = 1; pe.Document.Current.BillCntr = 0; pe.Document.Current.ExtRefNbr = NextCheckNbr; if (String.IsNullOrEmpty(NextCheckNbr)) { throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing); } if (pe.Document.Current.DocType == APDocType.QuickCheck && pe.Document.Current.CuryOrigDocAmt <= 0m) { throw new PXException(Messages.ZeroCheck_CannotPrint); } if (!skipStubs) { short j = 0; foreach (PXResult <APAdjust> res in pe.Adjustments_print.Select()) { pe.Document.Current.BillCntr++; APAdjust adj = (APAdjust)res; PaymentMethod pt = pe.paymenttype.Select(); PaymentMethodAccount det = pe.cashaccountdetail.Select(); if (j > pt.APStubLines - 1) { //AssignCheckNumber only for first StubLines in check, other/all lines will be printed on remittance report if (pt.APPrintRemittance == true) { adj.StubNbr = null; pe.Adjustments.Cache.Update(adj); continue; } NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr); pe.Document.Current.StubCntr++; j = 0; } adj.StubNbr = NextCheckNbr; pe.Adjustments.Cache.Update(adj); det.APLastRefNbr = NextCheckNbr; pe.cashaccountdetail.Update(det); j++; } } NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr); pe.Document.Current.Printed = true; pe.Document.Current.Hold = false; pe.Document.Current.UpdateNextNumber = true; pe.Document.Update(pe.Document.Current); } else { if (pe.Document.Current.Printed != true || pe.Document.Current.Hold != false) { pe.Document.Current.Printed = true; pe.Document.Current.Hold = false; pe.Document.Update(pe.Document.Current); } } } else { PaymentMethod method = pe.paymenttype.Select(); PaymentMethodAccount det = pe.cashaccountdetail.Select(); //if (method != null && (method.PrintOrExport == false || det.APAutoNextNbr == true)) { if (pe.Document.Current.DocType == APDocType.QuickCheck && pe.Document.Current.CuryOrigDocAmt <= 0m) { throw new PXException(Messages.ZeroCheck_CannotPrint); } pe.Document.Current.StubCntr = 1; pe.Document.Current.BillCntr = 0; pe.Document.Current.ExtRefNbr = doc.ExtRefNbr; if (!skipStubs) { foreach (PXResult <APAdjust> res in pe.Adjustments_print.Select()) { pe.Document.Current.BillCntr++; APAdjust adj = (APAdjust)res; adj.StubNbr = doc.ExtRefNbr; pe.Adjustments.Cache.Update(adj); } } pe.Document.Current.Printed = true; pe.Document.Current.Hold = false; pe.Document.Update(pe.Document.Current); } } }