public virtual void InsertSOAdjustments(SOOrder order, ARPaymentEntry docgraph, ARPayment payment, InsertSOAdjustmentsDelegate baseMethod) { baseMethod(order, docgraph, payment); SOOrderRUTROT orderRR = RUTROTHelper.GetExtensionNullable <SOOrder, SOOrderRUTROT>(order); if (orderRR.IsRUTROTDeductible == true) { RUTROT rutrot = PXSelect <RUTROT, Where <RUTROT.docType, Equal <Required <SOOrder.orderType> >, And <RUTROT.refNbr, Equal <Required <SOOrder.orderNbr> > > > > .Select(Base, order.OrderType, order.OrderNbr); foreach (SOAdjust adj in docgraph.SOAdjustments.Select()) { SOAdjust other = PXSelectGroupBy <SOAdjust, Where <SOAdjust.voided, Equal <False>, And <SOAdjust.adjdOrderType, Equal <Required <SOAdjust.adjdOrderType> >, And <SOAdjust.adjdOrderNbr, Equal <Required <SOAdjust.adjdOrderNbr> >, And <Where <SOAdjust.adjgDocType, NotEqual <Required <SOAdjust.adjgDocType> >, Or <SOAdjust.adjgRefNbr, NotEqual <Required <SOAdjust.adjgRefNbr> > > > > > > >, Aggregate <GroupBy <SOAdjust.adjdOrderType, GroupBy <SOAdjust.adjdOrderNbr, Sum <SOAdjust.curyAdjdAmt, Sum <SOAdjust.adjAmt> > > > > > .Select(Base, adj.AdjdOrderType, adj.AdjdOrderNbr, adj.AdjgDocType, adj.AdjgRefNbr); if (other == null || other.AdjdOrderNbr == null) { docgraph.SOAdjustments.Cache.SetValueExt <SOAdjust.curyAdjgAmt>(adj, adj.CuryAdjgAmt - rutrot.CuryTotalAmt); docgraph.SOAdjustments.Update(adj); } } } }
public static void ProcessPayment(ARPaymentCCProcessing aProcessingGraph, ARPaymentInfo aDoc) { aProcessingGraph.Clear(); aProcessingGraph.Document.Current = aProcessingGraph.Document.Search <ARPayment.docType, ARPayment.refNbr>(aDoc.DocType, aDoc.RefNbr); ARPaymentEntry.CheckValidPeriodForCCTran(aProcessingGraph, aProcessingGraph.Document.Current); CCPaymentEntry.CaptureCCPayment <ARPayment>(aDoc, aProcessingGraph.ccProcTran, true, ARPaymentEntry.UpdateARPaymentAndSetWarning); }
private static void ApplyPayment(ARPaymentEntry graph, ARAutoApplyParameters filter, ARPayment payment, List <ARInvoice> arInvoiceList, List <ARRegister> toRelease) { if (arInvoiceList.Any() == false) { return; } int invoiceIndex = 0; var paymentsViewIntoInvoiceList = new List <ARInvoice>(arInvoiceList); graph.Clear(); graph.Document.Current = payment; bool adjustmentAdded = false; while (graph.Document.Current.CuryUnappliedBal > 0 && invoiceIndex < paymentsViewIntoInvoiceList.Count) { if (graph.Document.Current.CuryApplAmt == null) { object curyapplamt = graph.Document.Cache.GetValueExt <ARPayment.curyApplAmt>(graph.Document.Current); if (curyapplamt is PXFieldState) { curyapplamt = ((PXFieldState)curyapplamt).Value; } graph.Document.Current.CuryApplAmt = (decimal?)curyapplamt; } graph.Document.Current.AdjDate = filter.ApplicationDate; graph.Document.Current.AdjFinPeriodID = filter.FinPeriodID; graph.Document.Cache.Update(graph.Document.Current); ARInvoice invoice = paymentsViewIntoInvoiceList[invoiceIndex]; ARAdjust adj = new ARAdjust(); adj.AdjdDocType = invoice.DocType; adj.AdjdRefNbr = invoice.RefNbr; graph.AutoPaymentApp = true; adj = graph.Adjustments.Insert(adj); if (adj == null) { invoiceIndex++; continue; } adjustmentAdded = true; if (adj.CuryDocBal <= 0m) { arInvoiceList.Remove(invoice); } invoiceIndex++; } if (adjustmentAdded) { graph.Save.Press(); if (filter.ReleaseBatchWhenFinished == true) { toRelease.Add(graph.Document.Current); } } }
private static void VoidProcess(ARDunningLetter doc) { ARDunningLetterMaint graph = PXGraph.CreateInstance <ARDunningLetterMaint>(); graph.Document.Current = doc; graph.Details.AllowUpdate = true; foreach (ARDunningLetterDetail detail in graph.Details.Select()) { ARDunningLetterProcess.ARInvoiceWithDL invoice = PXSelect <ARDunningLetterProcess.ARInvoiceWithDL, Where <ARDunningLetterProcess.ARInvoiceWithDL.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARDunningLetterProcess.ARInvoiceWithDL.docType, Equal <Required <ARInvoice.docType> > > > > .Select(graph, detail.RefNbr, detail.DocType); if (invoice != null && invoice.DunningLetterLevel > detail.DunningLetterLevel) { throw new PXException(Messages.DunningLetterHigherLevelExists); } } ARInvoice feeInvoice = PXSelect <ARInvoice, Where <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > .Select(graph, doc.FeeRefNbr, doc.FeeDocType); if (feeInvoice != null && feeInvoice.Voided == false) { ARInvoiceEntry invoiceGraph = PXGraph.CreateInstance <ARInvoiceEntry>(); invoiceGraph.Document.Current = feeInvoice; if (feeInvoice.Released == false) { invoiceGraph.Delete.Press(); } else if (feeInvoice.Released == true && feeInvoice.OpenDoc == true) { if (feeInvoice.CuryOrigDocAmt != feeInvoice.CuryDocBal) { throw new PXException(Messages.DunningLetterHavePaidFee); } invoiceGraph.reverseInvoice.Press(); // replace by reverse & attach in 2017R2 invoiceGraph.Document.Current.Hold = false; invoiceGraph.Document.Update(invoiceGraph.Document.Current); invoiceGraph.release.Press(); ARPaymentEntry paymentGraph = PXGraph.CreateInstance <ARPaymentEntry>(); paymentGraph.Document.Current = PXSelect <ARPayment, Where <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> >, And <ARPayment.docType, Equal <Required <ARPayment.docType> > > > > .Select(paymentGraph, invoiceGraph.Document.Current.RefNbr, invoiceGraph.Document.Current.DocType); ARAdjust adj = new ARAdjust(); paymentGraph.Adjustments.Insert(adj); adj.AdjdRefNbr = feeInvoice.RefNbr; adj.AdjdDocType = feeInvoice.DocType; paymentGraph.Adjustments.Update(adj); paymentGraph.release.Press(); } else { throw new PXException(Messages.DunningLetterHavePaidFee); } } foreach (ARDunningLetterDetail detail in graph.Details.Select()) { detail.Voided = true; graph.Details.Update(detail); } doc.Voided = true; graph.Document.Update(doc); graph.Save.Press(); }
public virtual IEnumerable ViewARDocument(PXAdapter adapter) { CABatchDetail doc = this.BatchPayments.Current; if (doc != null) { ARRegister arDoc = PXSelect <ARRegister, Where <ARRegister.docType, Equal <Required <ARRegister.docType> >, And <ARRegister.refNbr, Equal <Required <ARRegister.refNbr> > > > > .Select(this, doc.OrigDocType, doc.OrigRefNbr); if (arDoc != null) { ARPaymentEntry apGraph = PXGraph.CreateInstance <ARPaymentEntry>(); apGraph.Document.Current = apGraph.Document.Search <ARRegister.refNbr>(arDoc.RefNbr, arDoc.DocType); if (apGraph.Document.Current != null) { throw new PXRedirectRequiredException(apGraph, true, "") { Mode = PXBaseRedirectException.WindowMode.NewWindow } } ; } } return(adapter.Get()); }
public virtual IEnumerable editDetail(PXAdapter adapter) { ARPayment doc = this.ARDocumentList.Current; if (doc != null) { ARPaymentEntry pe = PXGraph.CreateInstance <ARPaymentEntry>(); pe.Document.Current = pe.Document.Search <ARPayment.refNbr>(doc.RefNbr, doc.DocType); throw new PXRedirectRequiredException(pe, true, "Payment") { Mode = PXRedirectRequiredException.WindowMode.NewWindow }; } return(adapter.Get()); }
private void HandleSetDescriptionRefName(ARPaymentEntry graph) { graph.FieldUpdated.AddHandler <ARPayment.customerID>((cache, e) => { var pmt = (ARPayment)e.Row; var cust = (BAccountR)PXSelectorAttribute.Select <ARPayment.customerID>(cache, pmt); pmt.DocDesc = String.Format(Messages.PaymentFrom, cust.AcctName); }); //PaymentRefNumberAttribute behave so nicely that we only get it at the time of persisting graph.RowPersisting.AddHandler <ARPayment>((cache, e) => { ((ARPayment)e.Row).ExtRefNbr = String.Empty; //Don't even think putting null here }); }
private static void _createPayments(List <ARInvoice> list, PayBillsFilter filter, CurrencyInfo info) { bool failed = false; ARPaymentEntry pe = PXGraph.CreateInstance <ARPaymentEntry>(); list.Sort((in1, in2) => { if (in1.CustomerID != in2.CustomerID) { return(((IComparable)in1.CustomerID).CompareTo(in2.CustomerID)); } return(((IComparable)in1.PMInstanceID).CompareTo(in2.PMInstanceID)); } ); for (int i = 0; i < list.Count; i++) { ARInvoice doc = list[i]; ARPayment pmt = null; bool docFailed = false; try { pe.CreatePayment(doc, info, filter.PayDate, filter.PayFinPeriodID, false); pmt = pe.Document.Current; if (pmt != null) { pmt.Hold = false; FinPeriodIDAttribute.SetPeriodsByMaster <ARPayment.finPeriodID>(pe.Document.Cache, pmt, filter.PayFinPeriodID); } pe.Save.Press(); } catch (Exception e) { PXFilteredProcessing <ARInvoice, PayBillsFilter> .SetError(i, e.Message); docFailed = failed = true; } if (!docFailed) { PXFilteredProcessing <ARInvoice, PayBillsFilter> .SetInfo(i, PXMessages.LocalizeFormatNoPrefixNLA(Messages.ARPaymentIsCreatedProcessingINProgress, pmt.RefNbr)); } } if (failed) { throw new PXException(Messages.CreationOfARPaymentFailedForSomeInvoices); } }
public static PXGraph FindSourceDocumentGraph(CCProcTran tran) { PXGraph target = null; if (tran != null) { if (tran.DocType == ARDocType.CashSale || tran.DocType == ARDocType.Payment) { if (tran.DocType == ARDocType.Payment) { ARPaymentEntry graph = PXGraph.CreateInstance <ARPaymentEntry>(); graph.Document.Current = graph.Document.Search <ARPayment.refNbr>(tran.RefNbr, tran.DocType); if (graph.Document.Current != null) { target = graph; } } if (tran.DocType == ARDocType.Payment) { ARCashSaleEntry graph = PXGraph.CreateInstance <ARCashSaleEntry>(); graph.Document.Current = graph.Document.Search <PX.Objects.AR.Standalone.ARCashSale.refNbr>(tran.RefNbr, tran.DocType); if (graph.Document.Current != null) { target = graph; } } } if (tran.DocType == ARDocType.Invoice) { SO.SOInvoiceEntry graph = PXGraph.CreateInstance <SO.SOInvoiceEntry>(); graph.Document.Current = graph.Document.Search <ARInvoice.refNbr>(tran.RefNbr, tran.DocType); if (graph.Document.Current != null) { target = graph; } } if (target == null && !String.IsNullOrEmpty(tran.OrigRefNbr)) { SO.SOOrderEntry graph = PXGraph.CreateInstance <SO.SOOrderEntry>(); graph.Document.Current = graph.Document.Search <SO.SOOrder.orderNbr>(tran.OrigRefNbr, tran.OrigDocType); if (graph.Document.Current != null) { target = graph; } } } return(target); }
protected virtual void RedirectToDoc(string aDocType, string aRefNbr) { Dictionary <string, string> alltypes = new ARDocType.ListAttribute().ValueLabelDic; if (new ARInvoiceType.ListAttribute().ValueLabelDic.ContainsKey(aDocType)) { ARInvoice doc = ARDocumentEnq.FindDoc <ARInvoice>(this, aDocType, aRefNbr); if (doc != null) { ARInvoiceEntry graph = PXGraph.CreateInstance <ARInvoiceEntry>(); graph.Document.Current = doc; throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } throw new PXException(Messages.DocumentNotFound, alltypes[aDocType], aRefNbr); } if (new ARPaymentType.ListAttribute().ValueLabelDic.ContainsKey(aDocType)) { ARPayment doc = ARDocumentEnq.FindDoc <ARPayment>(this, aDocType, aRefNbr); if (doc != null) { ARPaymentEntry graph = PXGraph.CreateInstance <ARPaymentEntry>(); graph.Document.Current = doc; throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } throw new PXException(Messages.DocumentNotFound, alltypes[aDocType], aRefNbr); } if (new ARCashSaleType.ListAttribute().ValueLabelDic.ContainsKey(aDocType)) { ARCashSale doc = ARDocumentEnq.FindDoc <ARCashSale>(this, aDocType, aRefNbr); if (doc != null) { ARCashSaleEntry graph = PXGraph.CreateInstance <ARCashSaleEntry>(); graph.Document.Current = doc; throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } throw new PXException(Messages.DocumentNotFound, alltypes[aDocType], aRefNbr); } throw new PXException(Messages.UnknownDocumentType); }
/// <summary> /// Manually create AR payment and related to specified sales order. /// </summary> public static void CreatePaymentProcess(SOOrder order) { ARPaymentEntry pymtEntry = PXGraph.CreateInstance <ARPaymentEntry>(); string paymentType = ARPaymentType.Payment; ARPayment payment = new ARPayment() { DocType = paymentType }; payment = PXCache <ARPayment> .CreateCopy(pymtEntry.Document.Insert(payment)); payment.CustomerID = order.CustomerID; payment.CustomerLocationID = order.CustomerLocationID; payment.PaymentMethodID = order.PaymentMethodID; payment.PMInstanceID = order.PMInstanceID; payment.CuryOrigDocAmt = 0m; payment.ExtRefNbr = order.CustomerRefNbr ?? order.OrderNbr; payment.DocDesc = order.OrderDesc; payment = pymtEntry.Document.Update(payment); SOAdjust adj = new SOAdjust() { AdjdOrderType = order.OrderType.Trim(), AdjdOrderNbr = order.OrderNbr.Trim() }; pymtEntry.SOAdjustments.Insert(adj); if (payment.CuryOrigDocAmt == 0m) { payment.CuryOrigDocAmt = payment.CurySOApplAmt; payment = pymtEntry.Document.Update(payment); } pymtEntry.Actions.PressSave(); //if (orderParams.paymentGraph.Actions.Contains("Release")) //{ // orderParams.paymentGraph.Actions["Release"].Press(); //} }
public static void ProcessPayment(ARPaymentCCProcessing aProcessingGraph, ARPaymentInfo aDoc) { aProcessingGraph.Clear(); aProcessingGraph.Document.Current = aProcessingGraph.Document.Search <ARPayment.docType, ARPayment.refNbr>(aDoc.DocType, aDoc.RefNbr); ARPaymentEntry graph = CreateInstance <ARPaymentEntry>(); graph.Document.Current = aDoc; var ext = graph.GetExtension <ARPaymentEntry.PaymentTransaction>(); ext.CheckHeldForReviewTranStatus(aDoc); ARPaymentEntry.CheckValidPeriodForCCTran(aProcessingGraph, aProcessingGraph.Document.Current); CCPaymentEntry paymentEntry = new CCPaymentEntry(aProcessingGraph); paymentEntry.AddAfterProcessCallback(ARPaymentEntry.PaymentTransaction.ChangeDocProcessingStatus); paymentEntry.AddAfterProcessCallback(ARPaymentEntry.PaymentTransaction.UpdateARPaymentAndSetWarning); paymentEntry.AddAfterProcessCallback(PaymentTransactionGraph <ARPaymentCCProcessing, ARPayment> .ReleaseARDocument); paymentEntry.AddAfterProcessCallback(PaymentTransactionGraph <ARPaymentCCProcessing, ARPayment> .CheckForHeldForReviewStatusAfterProc); paymentEntry.CaptureCCpayment(aDoc, new GenericExternalTransactionAdapter <ExternalTransaction>(aProcessingGraph.ExtTran)); }
public static PXGraph FindSourceDocumentGraph(string docType, string refNbr, string origDocType, string origRefNbr) { PXGraph target = null; if (docType == ARDocType.Payment || docType == ARDocType.VoidPayment) { ARPaymentEntry graph = PXGraph.CreateInstance <ARPaymentEntry>(); graph.Document.Current = graph.Document.Search <ARPayment.refNbr>(refNbr, docType); if (graph.Document.Current != null) { target = graph; } } if (docType == ARDocType.CashSale) { ARCashSaleEntry graph = PXGraph.CreateInstance <ARCashSaleEntry>(); graph.Document.Current = graph.Document.Search <Standalone.ARCashSale.refNbr>(refNbr, docType); if (graph.Document.Current != null) { target = graph; } } if (docType == ARDocType.Invoice) { SO.SOInvoiceEntry graph = PXGraph.CreateInstance <SO.SOInvoiceEntry>(); graph.Document.Current = graph.Document.Search <ARInvoice.refNbr>(refNbr, docType); if (graph.Document.Current != null) { target = graph; } } if (target == null && !string.IsNullOrEmpty(origRefNbr)) { SO.SOOrderEntry graph = PXGraph.CreateInstance <SO.SOOrderEntry>(); graph.Document.Current = graph.Document.Search <SO.SOOrder.orderNbr>(origRefNbr, origDocType); if (graph.Document.Current != null) { target = graph; } } return(target); }
public static void ReleaseARDocument(IBqlTable aTable, CCTranType procTran, bool success) { AR.ARRegister doc = aTable as AR.ARRegister; if (doc != null && success) { ExternalTransaction tran = null; PXGraph graph = null; if (doc.DocType == ARDocType.CashSale || doc.DocType == ARDocType.CashReturn) { ARCashSaleEntry cashSaleGraph = PXGraph.CreateInstance <ARCashSaleEntry>(); cashSaleGraph.Document.Current = PXSelect <ARCashSale, Where <ARCashSale.docType, Equal <Required <ARCashSale.docType> >, And <ARCashSale.refNbr, Equal <Required <ARCashSale.refNbr> > > > > .SelectWindowed(cashSaleGraph, 0, 1, doc.DocType, doc.RefNbr); tran = cashSaleGraph.ExternalTran.SelectSingle(doc.DocType, doc.RefNbr); graph = cashSaleGraph; } else { ARPaymentEntry paymentGraph = PXGraph.CreateInstance <ARPaymentEntry>(); paymentGraph.Document.Current = PXSelect <AR.ARPayment, Where <AR.ARPayment.docType, Equal <Required <AR.ARPayment.docType> >, And <AR.ARPayment.refNbr, Equal <Required <AR.ARPayment.refNbr> > > > > .SelectWindowed(paymentGraph, 0, 1, doc.DocType, doc.RefNbr); tran = paymentGraph.ExternalTran.SelectSingle(doc.DocType, doc.RefNbr); graph = paymentGraph; } if (tran != null) { ExternalTransactionState state = ExternalTranHelper.GetTransactionState(graph, tran); if (!state.IsDeclined && !state.IsOpenForReview) { ReleaseARDocument(aTable); } } } }
protected void Payments_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity) { EntityValueField docType = targetEntity.Fields.SingleOrDefault(f => f.Name == "DocType") as EntityValueField; EntityValueField appliedToOrderEntity = targetEntity.Fields.SingleOrDefault(f => f.Name == "AppliedToOrder") as EntityValueField; if (appliedToOrderEntity != null && appliedToOrderEntity.Value != null) { decimal appliedToOrder = decimal.Parse(appliedToOrderEntity.Value); SOOrderEntry orderEntry = (SOOrderEntry)graph; orderEntry.Save.Press(); orderEntry.CheckTermsInstallmentType(); if (docType != null) { var state = graph.Caches[typeof(ARRegister)].GetStateExt(new ARRegister(), "DocType") as PXStringState; if (state != null && state.ValueLabelDic != null) { bool keyFound = false; foreach (var rec in state.ValueLabelDic) { if (rec.Value == docType.Value || rec.Key == docType.Value) { keyFound = true; docType.Value = rec.Key; break; } } if (!keyFound) { docType = null; } } } PXGraph target; orderEntry.CreatePaymentProc(orderEntry.Document.Current, out target, docType != null ? docType.Value : ARPaymentType.Payment); ARPaymentEntry paymentEntry = (ARPaymentEntry)target; var adjustment = paymentEntry.SOAdjustments.Current; adjustment.CuryAdjgAmt = appliedToOrder; paymentEntry.SOAdjustments.Update(adjustment); ARPayment document = (ARPayment)paymentEntry.Document.Cache.CreateCopy(paymentEntry.Document.Current); EntityValueField paymentMethodEntity = targetEntity.Fields.SingleOrDefault(f => f.Name == "PaymentMethod") as EntityValueField; if (paymentMethodEntity != null && paymentMethodEntity.Value != null) { paymentEntry.Document.Cache.SetValueExt <ARPayment.paymentMethodID>(document, paymentMethodEntity.Value); } EntityValueField cashAccountEntity = targetEntity.Fields.SingleOrDefault(f => f.Name == "CashAccount") as EntityValueField; if (cashAccountEntity != null && cashAccountEntity.Value != null) { paymentEntry.Document.Cache.SetValueExt <ARPayment.cashAccountID>(document, cashAccountEntity.Value); } EntityValueField paymentAmountEntity = targetEntity.Fields.SingleOrDefault(f => f.Name == "PaymentAmount") as EntityValueField; if (paymentAmountEntity != null && paymentAmountEntity.Value != null) { decimal paymentAmount = decimal.Parse(paymentAmountEntity.Value); paymentEntry.Document.Cache.SetValueExt <ARPayment.curyOrigDocAmt>(document, paymentAmount); } else { paymentEntry.Document.Cache.SetValueExt <ARPayment.curyOrigDocAmt>(document, appliedToOrder); } paymentEntry.Document.Update(document); paymentEntry.Save.Press(); orderEntry.Cancel.Press(); try { orderEntry.Adjustments.Current = orderEntry.Adjustments.Select().Where(x => (((SOAdjust)x).AdjgDocType == paymentEntry.Document.Current.DocType && ((SOAdjust)x).AdjgRefNbr == paymentEntry.Document.Current.RefNbr)).First(); } catch { throw new PXException($"Payment {paymentEntry.Document.Current.DocType} {paymentEntry.Document.Current.RefNbr} was not found in the list of payments applied to order."); } } }
public static void ProcessDoc(ARPaymentEntry graph, ARStatementCycle cycle, ARAutoApplyParameters filter) { List <ARRegister> toRelease = new List <ARRegister>(); // Build Invoices List foreach (Customer customer in PXSelect <Customer, Where <Customer.statementCycleId, Equal <Required <Customer.statementCycleId> >, And <Match <Required <AccessInfo.userName> > > > > .Select(graph, cycle.StatementCycleId, graph.Accessinfo.UserName)) { List <ARInvoice> arInvoiceList = new List <ARInvoice>(); foreach (ARInvoice invoice in PXSelect <ARInvoice, Where <ARInvoice.customerID, Equal <Required <ARInvoice.customerID> >, And <ARInvoice.released, Equal <boolTrue>, And <ARInvoice.openDoc, Equal <boolTrue>, And <Where <ARInvoice.docType, Equal <Required <ARInvoice.docType> >, Or <ARInvoice.docType, Equal <Required <ARInvoice.docType> >, Or <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > > > > >, OrderBy <Asc <ARInvoice.dueDate> > > .Select(graph, customer.BAccountID, ARDocType.Invoice, ARDocType.FinCharge, filter.ApplyCreditMemos == true ? ARDocType.DebitMemo : ARDocType.Invoice)) { arInvoiceList.Add(invoice); } arInvoiceList.Sort(new Comparison <ARInvoice>(delegate(ARInvoice a, ARInvoice b) { if ((bool)graph.arsetup.Current.FinChargeFirst) { int aSortOrder = (a.DocType == ARDocType.FinCharge ? 0 : 1); int bSortOrder = (b.DocType == ARDocType.FinCharge ? 0 : 1); int ret = ((IComparable)aSortOrder).CompareTo(bSortOrder); if (ret != 0) { return(ret); } } { object aDueDate = a.DueDate; object bDueDate = b.DueDate; int ret = ((IComparable)aDueDate).CompareTo(bDueDate); return(ret); } } )); if (arInvoiceList.Count > 0) { int invoiceIndex = 0; // this foreach gets all payments [and CreditMemos if applyCreditMemos = true] sorted by docDate foreach (ARPayment payment in PXSelect <ARPayment, Where <ARPayment.customerID, Equal <Required <ARPayment.customerID> >, And <ARPayment.released, Equal <boolTrue>, And <ARPayment.openDoc, Equal <boolTrue>, And <Where <ARPayment.docType, Equal <Required <ARPayment.docType> >, Or <ARPayment.docType, Equal <Required <ARPayment.docType> > > > > > > >, OrderBy <Asc <ARPayment.docDate> > > .Select(graph, customer.BAccountID, ARDocType.Payment, filter.ApplyCreditMemos == true ? ARDocType.CreditMemo : ARDocType.Payment)) { graph.Clear(); graph.Document.Current = payment; if (graph.Adjustments.Select().Count == 0) { bool adjustmentAdded = false; while (graph.Document.Current.CuryUnappliedBal > 0) { if (graph.Document.Current.CuryApplAmt == null) { object curyapplamt = graph.Document.Cache.GetValueExt <ARPayment.curyApplAmt>(graph.Document.Current); if (curyapplamt is PXFieldState) { curyapplamt = ((PXFieldState)curyapplamt).Value; } graph.Document.Current.CuryApplAmt = (decimal?)curyapplamt; } graph.Document.Current.AdjDate = filter.ApplicationDate; graph.Document.Current.AdjFinPeriodID = filter.FinPeriodID; graph.Document.Cache.Update(graph.Document.Current); ARInvoice invoice = arInvoiceList[invoiceIndex]; ARAdjust adj = new ARAdjust(); adj.AdjdDocType = invoice.DocType; adj.AdjdRefNbr = invoice.RefNbr; graph.AutoPaymentApp = true; adj = graph.Adjustments.Insert(adj); if (adj == null) { throw new PXException(PXMessages.LocalizeFormat(Messages.ErrorAutoApply, invoice.DocType, invoice.RefNbr, payment.DocType, payment.RefNbr)); } adjustmentAdded = true; if (adj.CuryDocBal <= 0m) { invoiceIndex++; } if (invoiceIndex >= arInvoiceList.Count) { break; } } if (adjustmentAdded) { graph.Save.Press(); if (filter.ReleaseBatchWhenFinished == true) { toRelease.Add(graph.Document.Current); } } } if (invoiceIndex >= arInvoiceList.Count) { break; } } } } if (toRelease.Count > 0) { ARDocumentRelease.ReleaseDoc(toRelease, false); } }
public void PrepareAndImportAmazonRecords(SOScheduleProcess graph, List <SOPrepareAndImport> listOfPrepareAndImport) { objSyncOrderResponse = new InvokeServicesCallResponse(); amwOrders = new List <Order>(); amwLineItems = new List <OrderItem>(); SOAmazonSetup objSOAmazonSetup = null; SOPartialMaint logGraph = PXGraph.CreateInstance <SOPartialMaint>(); SOOrderEntry orderEntry = PXGraph.CreateInstance <SOOrderEntry>(); ARPaymentEntry paymentGraph = PXGraph.CreateInstance <ARPaymentEntry>(); bool isErrorOccured = false; DateTime? businessDateTime = PX.Common.PXTimeZoneInfo.Now; List <string> liCarriers = PXSelect <Carrier> .Select(graph).RowCast <Carrier>().Select(c => c.CarrierID).ToList(); try { SOSetupAmazonExt objSOOSetupext = orderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>(); if (SOHelper.IsSOPreferencesDetailsExist(orderEntry, objSOOSetupext)) { foreach (SOPrepareAndImport currentRecord in listOfPrepareAndImport) { objSOAmazonSetup = null; if (SOHelper.MarketplaceConfigurations(graph, currentRecord.IntegrationID, out objSOAmazonSetup)) { objSyncOrderResponse = objSyncOrderResponse != null ? null : objSyncOrderResponse; if (amwOrders != null && amwOrders.Count > 0) { amwOrders.Clear(); } if (amwLineItems != null && amwLineItems.Count > 0) { amwLineItems.Clear(); } orderEntry.Clear(); logGraph.Clear(); paymentGraph.Clear(); objServiceCallParams = new ServiceCallParameters(); objServiceCallParams.objSOAmazonSetup = objSOAmazonSetup; objServiceCallParams.amwOrderID = string.Empty; objServiceCallParams.methodCall = SOConstants.invokeListOrders; objServiceCallParams.fromDate = currentRecord.LastSyncDate; objServiceCallParams.toDate = currentRecord.ToDate; // Prepare action is invoked objSyncOrderResponse = new SOOrdersServiceCall(clientOrder).InvokeServicesCalls(graph, objServiceCallParams); if (amwLineItems != null && amwLineItems.Count > 0) { amwLineItems.Clear(); } if (objSyncOrderResponse != null && objSyncOrderResponse.objListOrderResponse != null && objSyncOrderResponse.objListOrderResponse.ListOrdersResult != null && objSyncOrderResponse.objListOrderResponse.ListOrdersResult.Orders != null && objSyncOrderResponse.objListOrderResponse.ListOrdersResult.Orders.Count > 0) { amwOrders = objSyncOrderResponse.objListOrderResponse.ListOrdersResult.Orders.ToList(); // Saving the prepare action response objScheduleParams = new PrepareAndImportOrdersParams(); objScheduleParams.objSOPrepareAndImport = currentRecord; objScheduleParams.objSOAmazonSetup = objSOAmazonSetup; objScheduleParams.objSOOrderEntry = orderEntry; objScheduleParams.objSOPartialMaint = logGraph; objScheduleParams.businessDateTime = businessDateTime; objScheduleParams.paymentGraph = paymentGraph; objScheduleParams.listOfCarriers = liCarriers; objScheduleParams.amwOrders = amwOrders; SOHelper.PrepareRecord(graph, objScheduleParams, ref isErrorOccured); if (objSyncOrderResponse.objListOrderResponse.ListOrdersResult.NextToken != null) { objScheduleParams.objNextToken = objSyncOrderResponse.objListOrderResponse.ListOrdersResult.NextToken; objScheduleParams.paymentGraph = paymentGraph; GetAmazonOrdersbyNextToken(graph, objScheduleParams, ref isErrorOccured); } } else { SOLogService.LogImportCount(null, currentRecord.IntegrationID, logGraph, currentRecord.ProcessID, SOConstants.scheduleimportorders, true); } } else { throw new PXException(SOMessages.apidetailsMissing); } } } else { throw new PXException(SOMessages.configMissing); } } catch (Exception ex) { SOLogService.LogImportStatus(objScheduleParams, false, ex.Message); throw new PXException(ex.Message); } }
public static void Redirect(PXCache sender, CATran catran) { if (catran == null) { return; } if (catran.OrigTranType == CAAPARTranType.GLEntry) { JournalEntry graph = PXGraph.CreateInstance <JournalEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.BatchModule.Current = PXSelect <Batch, Where <Batch.module, Equal <Required <Batch.module> >, And <Batch.batchNbr, Equal <Required <Batch.batchNbr> > > > > .Select(graph, catran.OrigModule, catran.OrigRefNbr); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else if (catran.OrigModule == GL.BatchModule.AP && (catran.OrigTranType == AP.APDocType.QuickCheck || catran.OrigTranType == AP.APDocType.VoidQuickCheck)) { APQuickCheckEntry graph = PXGraph.CreateInstance <APQuickCheckEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.Document.Current = PXSelect <APQuickCheck, Where <APQuickCheck.refNbr, Equal <Required <APQuickCheck.refNbr> >, And <APQuickCheck.docType, Equal <Required <APQuickCheck.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else if (catran.OrigModule == GL.BatchModule.AP && catran.OrigTranType == CATranType.CABatch) { CABatchEntry graph = PXGraph.CreateInstance <CABatchEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.Document.Current = PXSelect <CABatch, Where <CABatch.batchNbr, Equal <Required <CATran.origRefNbr> > > > .Select(graph, catran.OrigRefNbr); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else if (catran.OrigModule == GL.BatchModule.AP) { APPaymentEntry graph = PXGraph.CreateInstance <APPaymentEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.Document.Current = (APPayment)PXSelect <APPayment, Where <APPayment.refNbr, Equal <Required <APPayment.refNbr> >, And <APPayment.docType, Equal <Required <APPayment.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else if (catran.OrigModule == GL.BatchModule.AR && (catran.OrigTranType == ARDocType.CashSale || catran.OrigTranType == ARDocType.CashReturn)) { ARCashSale document = (ARCashSale)PXSelect <ARCashSale, Where <ARCashSale.refNbr, Equal <Required <ARCashSale.refNbr> >, And <ARCashSale.docType, Equal <Required <ARCashSale.docType> > > > > .Select(sender.Graph, catran.OrigRefNbr, catran.OrigTranType); if (document.OrigModule == BatchModule.SO && document.Released == false) { SO.SOInvoiceEntry graph = PXGraph.CreateInstance <SO.SOInvoiceEntry>(); graph.Clear(); sender.IsDirty = false; graph.Document.Current = (ARInvoice)PXSelect <ARInvoice, Where <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> >, And <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > .Select(sender.Graph, catran.OrigRefNbr, catran.OrigTranType); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else { ARCashSaleEntry graph = PXGraph.CreateInstance <ARCashSaleEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.Document.Current = document; throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } } else if (catran.OrigModule == GL.BatchModule.AR) { ARPaymentEntry graph = PXGraph.CreateInstance <ARPaymentEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.Document.Current = (ARPayment)PXSelect <ARPayment, Where <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> >, And <ARPayment.docType, Equal <Required <ARPayment.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else if (catran.OrigModule == GL.BatchModule.CA && catran.OrigTranType == CATranType.CAAdjustment) { CATranEntry graph = PXGraph.CreateInstance <CATranEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.CAAdjRecords.Current = PXSelect <CAAdj, Where <CAAdj.tranID, Equal <Required <CAAdj.tranID> > > > .Select(graph, catran.TranID); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else if (catran.OrigModule == GL.BatchModule.CA && catran.OrigTranType == CATranType.CATransferExp) { CATranEntry graph = PXGraph.CreateInstance <CATranEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.CAAdjRecords.Current = PXSelect <CAAdj, Where <CAAdj.adjTranType, Equal <CAAPARTranType.cATransferExp>, And <CAAdj.transferNbr, Equal <Required <CATran.origRefNbr> > > > > .Select(graph, catran.OrigRefNbr); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else if (catran.OrigModule == GL.BatchModule.CA) { if (catran.OrigTranType == CATranType.CADeposit || catran.OrigTranType == CATranType.CAVoidDeposit) { CADepositEntry graph = PXGraph.CreateInstance <CADepositEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.Document.Current = PXSelect <CADeposit, Where <CADeposit.tranType, Equal <Required <CADeposit.tranType> >, And <CADeposit.refNbr, Equal <Required <CADeposit.refNbr> > > > > .Select(graph, catran.OrigTranType, catran.OrigRefNbr); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } else { CashTransferEntry graph = PXGraph.CreateInstance <CashTransferEntry>(); graph.Clear(); if (sender != null) { sender.IsDirty = false; } graph.Transfer.Current = PXSelect <CATransfer, Where <CATransfer.tranIDOut, Equal <Required <CATransfer.tranIDOut> >, Or <CATransfer.tranIDIn, Equal <Required <CATransfer.tranIDIn> > > > > .Select(graph, catran.TranID, catran.TranID); throw new PXRedirectRequiredException(graph, true, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow }; } } }
public static void ProcessDoc(ARPaymentEntry graph, ARStatementCycle cycle, ARAutoApplyParameters filter) { List <ARRegister> toRelease = new List <ARRegister>(); foreach (Customer customer in GetCustomersForAutoApplication(graph, cycle, filter)) { List <ARInvoice> arInvoiceList = new List <ARInvoice>(); var invoiceQuery = new PXSelectJoin <ARInvoice, InnerJoin <Customer, On <ARInvoice.customerID, Equal <Customer.bAccountID> > >, Where <ARInvoice.released, Equal <True>, And <ARInvoice.openDoc, Equal <True>, And <ARInvoice.pendingPPD, NotEqual <True>, And <Where <ARInvoice.docType, Equal <ARDocType.invoice>, Or <ARInvoice.docType, Equal <ARDocType.finCharge>, Or <ARInvoice.docType, Equal <ARDocType.debitMemo> > > > > > > >, OrderBy <Asc <ARInvoice.dueDate> > >(graph); if (filter.LoadChildDocuments == LoadChildDocumentsOptions.None || customer.ParentBAccountID != null) { invoiceQuery.WhereAnd <Where <Customer.bAccountID, Equal <Required <ARInvoice.customerID> > > >(); } else { invoiceQuery.WhereAnd <Where <Customer.consolidatingBAccountID, Equal <Required <ARInvoice.customerID> > > >(); } foreach (ARInvoice invoice in invoiceQuery.Select( customer.BAccountID)) { arInvoiceList.Add(invoice); } arInvoiceList.Sort(new Comparison <ARInvoice>(delegate(ARInvoice a, ARInvoice b) { if ((bool)graph.arsetup.Current.FinChargeFirst) { int aSortOrder = (a.DocType == ARDocType.FinCharge ? 0 : 1); int bSortOrder = (b.DocType == ARDocType.FinCharge ? 0 : 1); int ret = ((IComparable)aSortOrder).CompareTo(bSortOrder); if (ret != 0) { return(ret); } } { object aDueDate = a.DueDate; object bDueDate = b.DueDate; int ret = ((IComparable)aDueDate).CompareTo(bDueDate); return(ret); } } )); if (arInvoiceList.Count > 0) { foreach (ARPayment payment in PXSelect <ARPayment, Where <ARPayment.released, Equal <True>, And <ARPayment.openDoc, Equal <True>, And <ARPayment.customerID, Equal <Required <ARPayment.customerID> >, And <Where <ARPayment.docType, Equal <ARDocType.payment>, Or <ARPayment.docType, Equal <ARDocType.prepayment>, Or <ARPayment.docType, Equal <Required <ARPayment.docType> > > > > > > > >, OrderBy <Asc <ARPayment.docDate> > > .Select(graph, customer.BAccountID, filter.ApplyCreditMemos == true ? ARDocType.CreditMemo : ARDocType.Payment)) { ApplyPayment(graph, filter, payment, arInvoiceList, toRelease); } } var remainingParentInvoices = arInvoiceList.Where(inv => inv.CustomerID == customer.BAccountID).ToList(); if (remainingParentInvoices.Count > 0 && filter.ApplyCreditMemos == true && filter.LoadChildDocuments == LoadChildDocumentsOptions.IncludeCRM) { foreach (ARPayment payment in PXSelectJoin <ARPayment, InnerJoin <Customer, On <ARPayment.customerID, Equal <Customer.bAccountID> > >, Where <ARPayment.released, Equal <True>, And <ARPayment.openDoc, Equal <True>, And <Customer.consolidatingBAccountID, Equal <Required <Customer.consolidatingBAccountID> >, And <ARPayment.docType, Equal <ARDocType.creditMemo> > > > >, OrderBy <Asc <ARPayment.docDate> > > .Select(graph, customer.BAccountID)) { ApplyPayment(graph, filter, payment, remainingParentInvoices, toRelease); } } } if (toRelease.Count > 0) { ARDocumentRelease.ReleaseDoc(toRelease, false); } }
private static void ApplyPayment(ARPaymentEntry graph, ARAutoApplyParameters filter, ARPayment payment, List <ARInvoice> arInvoiceList, List <ARRegister> toRelease, out string warningRefNbr) { warningRefNbr = String.Empty; if (arInvoiceList.Any() == false) { return; } if (payment.DocDate > filter.ApplicationDate) { warningRefNbr = payment.RefNbr; PXProcessing <ARStatementCycle> .SetWarning(Messages.FuturePaymentWarning); return; } int invoiceIndex = 0; var paymentsViewIntoInvoiceList = new List <ARInvoice>(arInvoiceList); graph.Clear(); graph.Document.Current = payment; bool adjustmentAdded = false; while (graph.Document.Current.CuryUnappliedBal > 0 && invoiceIndex < paymentsViewIntoInvoiceList.Count) { if (graph.Document.Current.CuryApplAmt == null) { object curyapplamt = graph.Document.Cache.GetValueExt <ARPayment.curyApplAmt>(graph.Document.Current); if (curyapplamt is PXFieldState) { curyapplamt = ((PXFieldState)curyapplamt).Value; } graph.Document.Current.CuryApplAmt = (decimal?)curyapplamt; } graph.Document.Current.AdjDate = filter.ApplicationDate; FinPeriodIDAttribute.SetPeriodsByMaster <ARPayment.adjFinPeriodID>(graph.Document.Cache, graph.Document.Current, filter.FinPeriodID); graph.Document.Cache.Adjust <PX.Objects.AR.AROpenPeriodAttribute>().For <ARPayment.adjFinPeriodID>(atr => atr.RedefaultOnDateChanged = false); graph.Document.Cache.Update(graph.Document.Current); ARInvoice invoice = paymentsViewIntoInvoiceList[invoiceIndex]; var trans = invoice.PaymentsByLinesAllowed == true ? PXSelect <ARTran, Where <ARTran.tranType, Equal <Required <ARTran.tranType> >, And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > .Select(graph, invoice.DocType, invoice.RefNbr) : new PXResultset <ARTran>() { null }; foreach (ARTran tran in trans) { ARAdjust adj = new ARAdjust(); adj.AdjdDocType = invoice.DocType; adj.AdjdRefNbr = invoice.RefNbr; adj.AdjdLineNbr = tran?.LineNbr ?? 0; graph.AutoPaymentApp = true; adj = graph.Adjustments.Insert(adj); if (adj != null) { adjustmentAdded = true; if (adj.CuryDocBal <= 0m) { arInvoiceList.Remove(invoice); } } } invoiceIndex++; } if (adjustmentAdded) { graph.Save.Press(); if (filter.ReleaseBatchWhenFinished == true) { toRelease.Add(graph.Document.Current); } } }
public virtual void ImportAmazonRecords(SOImportProcess graph, List <SOProcessOrder> list, SOImportFilter currentFilter) { if (list.Count < 0) { return; } List <Order> amwOrder = null; List <OrderItem> amwLineItems = null; string amwOrderID = string.Empty; List <SOAmazonSetup> liSOAmazonSetup = new List <SOAmazonSetup>(); List <SOFieldMapping> liUsrMapping = new List <SOFieldMapping>(); SOAmazonSetup objamwSetup = null; SOOrderProcessLog objProcessLog = null; SOPartialMaint logGraph = PXGraph.CreateInstance <SOPartialMaint>(); if (currentFilter.ProcessAllTypes == true) { foreach (SOAmazonSetup objSetup in PXSelect <SOAmazonSetup, Where <SOAmazonSetup.status, Equal <True> > > .Select(graph)) { liSOAmazonSetup.Add(objSetup); } } else if (SOHelper.MarketplaceConfigurations(graph, currentFilter.IntegrationID, out objamwSetup)) { liSOAmazonSetup.Add(objamwSetup); } if (liSOAmazonSetup.Count > 0) { ARPaymentEntry docgraph = PXGraph.CreateInstance <ARPaymentEntry>(); SOOrderEntry orderEntry = PXGraph.CreateInstance <SOOrderEntry>(); orderEntry.RowUpdated.AddHandler <SOOrder>((sender, e) => { if (!sender.ObjectsEqual <SOOrder.orderDate>(e.Row, e.OldRow)) { SOOrder order = (SOOrder)e.Row; order.OrderDate = order.OrderDate.HasValue ? order.OrderDate.Value.Date : order.OrderDate; } }); InvokeServicesCallResponse objSyncOrderResponse = null; PrepareAndImportOrdersParams objScheduleParams = null; objProcessLog = new SOOrderProcessLog(); objProcessLog.ProcessDate = PX.Common.PXTimeZoneInfo.Now; objProcessLog.TotalRecordstoImport = list.Count; objProcessLog.Operation = SOConstants.btnImport; objProcessLog.ImportedRecordsCount = 0; objProcessLog.FailedRecordsCount = 0; bool isErrorOccured = false; List <string> liCarriers = PXSelect <Carrier> .Select(graph).RowCast <Carrier>().Select(c => c.CarrierID).ToList(); foreach (SOProcessOrder currentRecord in list) { try { orderEntry.Clear(); logGraph.Clear(); docgraph.Clear(); objProcessLog.IntegrationID = currentFilter.IntegrationID != null ? currentFilter.IntegrationID : currentRecord.IntegrationID; logGraph.OrderProcessLog.Insert(objProcessLog); logGraph.Actions.PressSave(); foreach (SOAmazonSetup objSOAmazonSetup in liSOAmazonSetup.Where(x => x.IntegrationID == currentRecord.IntegrationID)) { if (orderEntry.sosetup.Current != null) { if (!SOHelper.CheckOrderExist(graph, currentRecord.AmazonOrderID, currentRecord.IntegrationID)) { amwOrderID = currentRecord.AmazonOrderID; if (amwLineItems != null && amwLineItems.Count > 0) { amwLineItems.Clear(); } amwOrder = new List <Order>(); amwOrder.Add(SOHelper.SchemaDeserialization(graph, amwOrderID)); objServiceCallParams = new ServiceCallParameters(); objServiceCallParams.objSOAmazonSetup = objSOAmazonSetup; objServiceCallParams.amwOrderID = currentRecord.AmazonOrderID; objServiceCallParams.methodCall = SOConstants.invokeListOrderItems; objSyncOrderResponse = new InvokeServicesCallResponse(); objSyncOrderResponse = new SOOrdersServiceCall(clientOrder).InvokeServicesCalls(graph, objServiceCallParams); amwLineItems = objSyncOrderResponse != null && objSyncOrderResponse.objListOrderItemsResponse != null && objSyncOrderResponse.objListOrderItemsResponse.ListOrderItemsResult != null && objSyncOrderResponse.objListOrderItemsResponse.ListOrderItemsResult.OrderItems.Count > 0 ? objSyncOrderResponse.objListOrderItemsResponse.ListOrderItemsResult.OrderItems : amwLineItems; objScheduleParams = new PrepareAndImportOrdersParams(); objScheduleParams.objSOPartialMaint = logGraph; objScheduleParams.objSOAmazonSetup = objSOAmazonSetup; objScheduleParams.objSOOrderEntry = orderEntry; objScheduleParams.paymentGraph = docgraph; objScheduleParams.objSOProcessOrderRecord = currentRecord; objScheduleParams.ObjCurrentOrder = amwOrder[0]; objScheduleParams.objamwLineItems = amwLineItems; objScheduleParams.objliUsrMapping = liUsrMapping; objScheduleParams.listOfCarriers = liCarriers; objScheduleParams.CurrentOrderIndex = list.IndexOf(currentRecord); CreateSO.CreateSalesOrderandPayments(objScheduleParams); } else { isErrorOccured = true; SOLogService.LogImportStatus(objScheduleParams, true, SOMessages.recordAlreadyImported); PXProcessing <SOProcessOrder> .SetInfo(list.IndexOf(currentRecord), SOMessages.recordAlreadyImported); } } else { throw new PXException(SOMessages.configMissing); } } } catch (Exception ex) { isErrorOccured = true; SOLogService.LogImportStatus(objScheduleParams, false, ex.Message); PXProcessing <SOProcessOrder> .SetError(list.IndexOf(currentRecord), ex.Message); } } if (isErrorOccured) { throw new PXException(SOMessages.showErrorMsgOrders); } } }
public static void ProcessDoc(ARPaymentEntry graph, ARStatementCycle cycle, ARAutoApplyParameters filter) { List<ARRegister> toRelease = new List<ARRegister>(); HashSet<string> trace = new HashSet<string>(); string warningRefNbr = String.Empty; int?[] branches = PXAccess.GetBranchIDs().Select(i => (int?)i).ToArray<int?>(); foreach (Customer customer in GetCustomersForAutoApplication(graph, cycle, filter)) { List<ARInvoice> arInvoiceList = new List<ARInvoice>(); var invoiceQuery = new PXSelectJoin<ARInvoice, InnerJoin<Customer, On<ARInvoice.customerID, Equal<Customer.bAccountID>>>, Where<ARInvoice.released, Equal<True>, And<ARInvoice.openDoc, Equal<True>, And<ARInvoice.pendingPPD, NotEqual<True>, And<Where<ARInvoice.docType, Equal<ARDocType.invoice>, Or<ARInvoice.docType, Equal<ARDocType.finCharge>, Or<ARInvoice.docType, Equal<ARDocType.debitMemo>>>>>>>>, OrderBy<Asc<ARInvoice.dueDate>>>(graph); if(filter.LoadChildDocuments == LoadChildDocumentsOptions.None || customer.ParentBAccountID != null) { invoiceQuery.WhereAnd<Where<Customer.bAccountID, Equal<Required<ARInvoice.customerID>>>>(); } else { invoiceQuery.WhereAnd<Where<Customer.consolidatingBAccountID, Equal<Required<ARInvoice.customerID>>>>(); } PXResultset<ARInvoice> invoices; using (new PXReadBranchRestrictedScope(null, branches, true, false)) { invoices = invoiceQuery.Select(customer.BAccountID); } foreach (ARInvoice invoice in invoices) { arInvoiceList.Add(invoice); } arInvoiceList.Sort(new Comparison<ARInvoice>(delegate(ARInvoice a, ARInvoice b) { if ((bool)graph.arsetup.Current.FinChargeFirst) { int aSortOrder = (a.DocType == ARDocType.FinCharge ? 0 : 1); int bSortOrder = (b.DocType == ARDocType.FinCharge ? 0 : 1); int ret = ((IComparable)aSortOrder).CompareTo(bSortOrder); if (ret != 0) { return ret; } } { object aDueDate = a.DueDate; object bDueDate = b.DueDate; int ret = ((IComparable)aDueDate).CompareTo(bDueDate); return ret; } } )); if (arInvoiceList.Count > 0) { PXSelectBase<ARPayment> getPaymentsQuery = new PXSelectJoin<ARPayment, InnerJoin<Branch, On<ARPayment.branchID, Equal<Branch.branchID>>, InnerJoin<OrganizationFinPeriod, On<Branch.organizationID, Equal<OrganizationFinPeriod.organizationID>, And<OrganizationFinPeriod.finPeriodID, Equal<Required<OrganizationFinPeriod.finPeriodID>>>>>>, Where< OrganizationFinPeriod.status, NotEqual<FinPeriod.status.locked>, And<OrganizationFinPeriod.status, NotEqual<FinPeriod.status.inactive>, And<ARPayment.released, Equal<True>, And<ARPayment.openDoc, Equal<True>, And<ARPayment.customerID, Equal<Required<ARPayment.customerID>>, And2<Not<HasUnreleasedVoidPayment<ARPayment.docType, ARPayment.refNbr>>, And<Where< ARPayment.docType, Equal<ARDocType.payment>, Or<ARPayment.docType, Equal<ARDocType.prepayment>, Or<ARPayment.docType, Equal<Required<ARPayment.docType>>>>>>>>>>>>, OrderBy< Asc<ARPayment.docDate>>>(graph); if (!graph.FinPeriodUtils.CanPostToClosedPeriod()) { getPaymentsQuery.WhereAnd<Where<OrganizationFinPeriod.status, NotEqual<FinPeriod.status.closed>>>(); } foreach (ARPayment payment in getPaymentsQuery.Select(filter.FinPeriodID, customer.BAccountID, filter.ApplyCreditMemos == true ? ARDocType.CreditMemo : ARDocType.Payment)) { ApplyPayment(graph, filter, payment, arInvoiceList, toRelease, out warningRefNbr); trace.Add(warningRefNbr); } } var remainingParentInvoices = arInvoiceList.Where(inv => inv.CustomerID == customer.BAccountID).ToList(); if (remainingParentInvoices.Count > 0 && filter.ApplyCreditMemos == true && filter.LoadChildDocuments == LoadChildDocumentsOptions.IncludeCRM) { PXSelectBase<ARPayment> getCreditMemosQuery = new PXSelectJoin<ARPayment, InnerJoin<Customer, On<ARPayment.customerID, Equal<Customer.bAccountID>>, InnerJoin<Branch, On<ARPayment.branchID, Equal<Branch.branchID>>, InnerJoin<OrganizationFinPeriod, On<Branch.organizationID, Equal<OrganizationFinPeriod.organizationID>, And<OrganizationFinPeriod.finPeriodID, Equal<Required<OrganizationFinPeriod.finPeriodID>>>>>>>, Where< OrganizationFinPeriod.status, NotEqual<FinPeriod.status.locked>, And<OrganizationFinPeriod.status, NotEqual<FinPeriod.status.inactive>, And<ARPayment.released, Equal<True>, And<ARPayment.openDoc, Equal<True>, And<Customer.consolidatingBAccountID, Equal<Required<Customer.consolidatingBAccountID>>, And<ARPayment.docType, Equal<ARDocType.creditMemo>, And<Not<HasUnreleasedVoidPayment<ARPayment.docType, ARPayment.refNbr>>>>>>>>>, OrderBy< Asc<ARPayment.docDate>>>(graph); if (!graph.FinPeriodUtils.CanPostToClosedPeriod()) { getCreditMemosQuery.WhereAnd<Where<OrganizationFinPeriod.status, NotEqual<FinPeriod.status.closed>>>(); } foreach (ARPayment payment in getCreditMemosQuery.Select(filter.FinPeriodID, customer.BAccountID)) { ApplyPayment(graph, filter, payment, remainingParentInvoices, toRelease, out warningRefNbr); trace.Add(warningRefNbr); } } } if (trace != null && trace.Count != 0) { PXTrace.WriteWarning(String.Format(Messages.FuturePayments, trace.Where(x => !x.IsNullOrEmpty()).JoinToString("; "))); trace.Clear(); } if (toRelease.Count > 0) { ARDocumentRelease.ReleaseDoc(toRelease, false); } }
public static void ValidateCCPayment(PXGraph graph, List <IExternalTransaction> list, bool isMassProcess) { bool failed = false; ARCashSaleEntry arCashSaleGraph = null; ARPaymentEntry arPaymentGraph = null; SOInvoiceEntry soInvoiceGraph = null; for (int i = 0; i < list.Count; i++) { if (list[i] == null) { continue; } if ((i % 100) == 0) { if (arCashSaleGraph != null) { arCashSaleGraph.Clear(); } if (arPaymentGraph != null) { arPaymentGraph.Clear(); } if (soInvoiceGraph != null) { soInvoiceGraph.Clear(); } } IExternalTransaction tran = list[i]; var resultSet = PXSelectJoin <Standalone.ARRegister, LeftJoin <ARPayment, On <ARPayment.refNbr, Equal <Standalone.ARRegister.refNbr>, And <ARPayment.docType, Equal <Standalone.ARRegister.docType> > >, LeftJoin <ARInvoice, On <ARInvoice.refNbr, Equal <Standalone.ARRegister.refNbr>, And <ARInvoice.docType, Equal <Standalone.ARRegister.docType> > >, LeftJoin <SOInvoice, On <SOInvoice.refNbr, Equal <Standalone.ARRegister.refNbr>, And <SOInvoice.docType, Equal <Standalone.ARRegister.docType> > >, LeftJoin <Standalone.ARCashSale, On <Standalone.ARCashSale.refNbr, Equal <Standalone.ARRegister.refNbr>, And <Standalone.ARCashSale.docType, Equal <Standalone.ARRegister.docType> > > > > > >, Where <Standalone.ARRegister.refNbr, Equal <Required <Standalone.ARRegister.refNbr> >, And <Standalone.ARRegister.docType, Equal <Required <Standalone.ARRegister.docType> > > > > .SelectSingleBound(graph, null, tran.RefNbr, tran.DocType); foreach (PXResult <Standalone.ARRegister, ARPayment, ARInvoice, SOInvoice, Standalone.ARCashSale> arDoc in resultSet) { if (arDoc == null) { continue; } try { if ((ARInvoice)arDoc is ARInvoice arInvoice && arInvoice != null && arInvoice.RefNbr != null) { if ((SOInvoice)arDoc is SOInvoice soInvoice && soInvoice != null && soInvoice.RefNbr != null) { soInvoiceGraph = soInvoiceGraph != null ? soInvoiceGraph : PXGraph.CreateInstance <SOInvoiceEntry>(); SOInvoiceEntry.PaymentTransaction ext = soInvoiceGraph.GetExtension <SOInvoiceEntry.PaymentTransaction>(); soInvoiceGraph.Document.Current = arInvoice; soInvoiceGraph.SODocument.Current = soInvoice; if (ext.CanValidate(arInvoice)) { ext.validateCCPayment.Press(); } } else if ((Standalone.ARCashSale)arDoc is Standalone.ARCashSale arCashSale && arCashSale != null && arCashSale.RefNbr != null) { arCashSaleGraph = arCashSaleGraph != null ? arCashSaleGraph : PXGraph.CreateInstance <ARCashSaleEntry>(); ARCashSaleEntry.PaymentTransaction ext = arCashSaleGraph.GetExtension <ARCashSaleEntry.PaymentTransaction>(); arCashSaleGraph.Document.Current = arCashSale; if (ext.CanValidate(arCashSaleGraph.Document.Current)) { ext.validateCCPayment.Press(); } } }
public static void CreatePayments(List <ARInvoice> list, PayBillsFilter filter, CurrencyInfo info) { Dictionary <ARPayment, List <int> > pmtRows = new Dictionary <ARPayment, List <int> >(); bool failed = false; ARPaymentEntry pe = PXGraph.CreateInstance <ARPaymentEntry>(); List <ARPayment> paylist = new List <ARPayment>(); list.Sort((in1, in2) => { if (in1.CustomerID != in2.CustomerID) { return(((IComparable)in1.CustomerID).CompareTo(in2.CustomerID)); } return(((IComparable)in1.PMInstanceID).CompareTo(in2.PMInstanceID)); } ); for (int i = 0; i < list.Count; i++) { ARInvoice doc = list[i]; ARPayment pmt = null; bool docFailed = false; try { pe.CreatePayment(doc, info, filter.PayDate, filter.PayFinPeriodID, false); pmt = pe.Document.Current; if (pmt != null) { if (!paylist.Contains(pmt)) { if (String.IsNullOrEmpty(pmt.ExtRefNbr)) { pe.Document.Current.ExtRefNbr = string.Format(Messages.ARAutoPaymentRefNbrFormat, filter.PayDate.Value); } paylist.Add(pmt); } if (!pmtRows.ContainsKey(pmt)) { pmtRows[pmt] = new List <int>(); } pmtRows[pmt].Add(i); pmt.Hold = false; pmt.FinPeriodID = filter.PayFinPeriodID; } pe.Save.Press(); } catch (Exception e) { PXFilteredProcessing <PayBillsFilter, ARInvoice> .SetError(i, e.Message); docFailed = failed = true; } if (!docFailed) { PXFilteredProcessing <PayBillsFilter, ARInvoice> .SetInfo(i, string.Format(Messages.ARPaymentIsCreatedProcessingINProgress, pmt.RefNbr)); } } if (failed) { throw new PXException(Messages.CreationOfARPaymentFailedForSomeInvoices); } }