private void VerifyRow <TRow>(PXCache cache, TRow row) where TRow : class, IBqlTable, new() { var ex = PXDBQuantityAttribute.VerifyForDecimal(cache, row); if (ex != null && ex.ErrorLevel >= PXErrorLevel.Error) { cache.MarkUpdated(row); } }
public override void Parent_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { base.Parent_RowUpdated(sender, e); if (!sender.ObjectsEqual <POOrder.status, POOrder.cancelled>(e.Row, e.OldRow) || //There are two graphs when automation step with notification is getting applied. One of them (the one made by automation) will be //persisted, while another one is only displayed on the screen. Due to cache sharing and because of automatic screen refresh //we will get the same Status in e.Row and e.OldRow while in fact they are different (example - transition from NL Pending Email to NL Open step) (sender.Graph.UnattendedMode && (sender.Graph.AutomationStep != sender.Graph.AutomationStepOriginal))) { POOrder order = (POOrder)e.Row; PXCache plancache = sender.Graph.Caches[typeof(INItemPlan)]; bool Cancelled = (bool?)sender.GetValue <POOrder.cancelled>(e.Row) == true; foreach (INItemPlan plan in PXSelect <INItemPlan, Where <INItemPlan.refNoteID, Equal <Current <POOrder.noteID> > > > .Select(sender.Graph)) { if (Cancelled) { plancache.Delete(plan); } else { INItemPlan copy = PXCache <INItemPlan> .CreateCopy(plan); bool IsOnHold = IsOrderOnHold(order); string newPlanType; if (TryCalcPlanType(plan, IsOnHold, out newPlanType)) { plan.PlanType = newPlanType; } plan.Hold = IsOnHold; if (!string.Equals(copy.PlanType, plan.PlanType)) { plancache.RaiseRowUpdated(plan, copy); } plancache.MarkUpdated(plan); } } } }
public static void ReleasePayments(List <APPayment> list, string Action) { APReleaseChecks releaseChecksGraph = CreateInstance <APReleaseChecks>(); APPaymentEntry pe = CreateInstance <APPaymentEntry>(); CABatchEntry be = CreateInstance <CABatchEntry>(); bool failed = false; bool successed = false; List <APRegister> docs = new List <APRegister>(list.Count); foreach (APPayment payment in list) { if (payment.Passed == true) { releaseChecksGraph.TimeStamp = pe.TimeStamp = payment.tstamp; } switch (Action) { case ReleaseChecksFilter.action.ReleaseChecks: payment.Printed = true; break; case ReleaseChecksFilter.action.ReprintChecks: case ReleaseChecksFilter.action.VoidAndReprintChecks: payment.ExtRefNbr = null; payment.Printed = false; break; default: continue; } PXProcessing <APPayment> .SetCurrentItem(payment); if (Action == ReleaseChecksFilter.action.ReleaseChecks) { try { pe.Document.Current = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType); if (pe.Document.Current?.ExtRefNbr != payment.ExtRefNbr) { APPayment payment_copy = PXCache <APPayment> .CreateCopy(pe.Document.Current); payment_copy.ExtRefNbr = payment.ExtRefNbr; pe.Document.Update(payment_copy); } if (PaymentRefAttribute.PaymentRefMustBeUnique(pe.paymenttype.Current) && string.IsNullOrEmpty(payment.ExtRefNbr)) { throw new PXException(ErrorMessages.FieldIsEmpty, typeof(APPayment.extRefNbr).Name); } payment.IsReleaseCheckProcess = true; APPrintChecks.AssignNumbersWithNoAdditionalProcessing(pe, payment); pe.Save.Press(); object[] persisted = PXTimeStampScope.GetPersisted(pe.Document.Cache, pe.Document.Current); if (persisted == null || persisted.Length == 0) { //preserve timestamp which will be @@dbts after last record committed to db on previous Persist(). //otherwise another process updated APAdjust. docs.Add(payment); } else { if (payment.Passed == true) { pe.Document.Current.Passed = true; } docs.Add(pe.Document.Current); } successed = true; } catch (PXException e) { PXProcessing <APPayment> .SetError(e); docs.Add(null); failed = true; } } if (Action == ReleaseChecksFilter.action.ReprintChecks || Action == ReleaseChecksFilter.action.VoidAndReprintChecks) { try { payment.IsPrintingProcess = true; using (PXTransactionScope transactionScope = new PXTransactionScope()) { #region Update CABatch if ReprintChecks CABatch caBatch = PXSelectJoin <CABatch, InnerJoin <CABatchDetail, On <CABatch.batchNbr, Equal <CABatchDetail.batchNbr> > >, Where <CABatchDetail.origModule, Equal <Required <APPayment.origModule> >, And <CABatchDetail.origDocType, Equal <Required <APPayment.docType> >, And <CABatchDetail.origRefNbr, Equal <Required <APPayment.refNbr> > > > > > . Select(be, payment.OrigModule, payment.DocType, payment.RefNbr); if (caBatch != null) { be.Document.Current = caBatch; int DetailCount = be.Details.Select().Count; // load CABatchDetail detail = be.Details.Locate(new CABatchDetail() { BatchNbr = be.Document.Current.BatchNbr, OrigModule = payment.OrigModule, OrigDocType = payment.DocType, OrigRefNbr = payment.RefNbr, OrigLineNbr = CABatchDetail.origLineNbr.DefaultValue, }); if (detail != null) { // payment.Status is recalculated in CABatchEntry.Delete if (DetailCount == 1) { be.Document.Delete(be.Document.Current); // Details will delete by PXParent } else { be.Details.Delete(detail); // recalculated batch totals } } be.Save.Press(); } else { PXCache cacheAPPayment = releaseChecksGraph.APPaymentList.Cache; cacheAPPayment.SetValueExt <APPayment.printed>(payment, false); cacheAPPayment.SetValueExt <APPayment.hold>(payment, false); cacheAPPayment.SetValueExt <APPayment.extRefNbr>(payment, null); // APPayment.Status is recalculated by SetStatusCheckAttribute cacheAPPayment.MarkUpdated(payment); cacheAPPayment.PersistUpdated(payment); cacheAPPayment.Persisted(false); } #endregion // TODO: Need to rework. Use legal CRUD methods of caches! releaseChecksGraph.TimeStamp = PXDatabase.SelectTimeStamp(); // delete check numbers only if Reprint (not Void and Reprint) PaymentMethod pm = pe.paymenttype.Select(payment.PaymentMethodID); if (pm.APPrintChecks == true && Action == ReleaseChecksFilter.action.ReprintChecks) { APPayment doc = payment; new HashSet <string>(pe.Adjustments_Raw.Select(doc.DocType, doc.RefNbr) .RowCast <APAdjust>() .Select(adj => adj.StubNbr)) .ForEach(nbr => PaymentRefAttribute.DeleteCheck((int)doc.CashAccountID, doc.PaymentMethodID, nbr)); // sync PaymentMethodAccount.APLastRefNbr with actual last CashAccountCheck number PaymentMethodAccount det = releaseChecksGraph.cashaccountdetail.SelectSingle(payment.CashAccountID, payment.PaymentMethodID); PaymentRefAttribute.LastCashAccountCheckSelect.Clear(releaseChecksGraph); CashAccountCheck cacheck = PaymentRefAttribute.LastCashAccountCheckSelect.SelectSingleBound(releaseChecksGraph, new object[] { det }); det.APLastRefNbr = cacheck?.CheckNbr; releaseChecksGraph.cashaccountdetail.Cache.PersistUpdated(det); releaseChecksGraph.cashaccountdetail.Cache.Persisted(false); } // END TODO if (string.IsNullOrEmpty(payment.ExtRefNbr)) { //try to get next number releaseChecksGraph.APPaymentList.Cache.SetDefaultExt <APPayment.extRefNbr>(payment); } transactionScope.Complete(); } } catch (PXException e) { PXProcessing <APPayment> .SetError(e); } docs.Add(null); } } if (successed) { APDocumentRelease.ReleaseDoc(docs, true); } if (failed) { throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased); } }
protected virtual void SyncCommitment(PXCache sender, object row, bool skipCommitmentSelect) { if (!IsCommitmentTrackingEnabled(sender)) { return; } PXCache detailCache = sender.Graph.Caches[detailEntity]; Guid? commitmentID = (Guid?)detailCache.GetValue(row, FieldOrdinal); if (EraseCommitment(sender, row)) { DeleteCommitment(sender, commitmentID); detailCache.SetValue(row, FieldOrdinal, null); detailCache.MarkUpdated(row); } else { int?accountGroup = GetAccountGroup(sender, row); PMCommitment commitment = null; if (!skipCommitmentSelect && commitmentID != null) { commitment = PXSelect <PMCommitment, Where <PMCommitment.commitmentID, Equal <Required <PMCommitment.commitmentID> > > > .Select(sender.Graph, commitmentID); } if (commitment == null) { commitment = FromRecord(sender, row); sender.Graph.Caches[typeof(PMCommitment)].Insert(commitment); if (commitment.CommitmentID != commitmentID) { detailCache.SetValue(row, FieldOrdinal, commitment.CommitmentID); detailCache.MarkUpdated(row); } } else { PMCommitment container = FromRecord(sender, row); commitment.AccountGroupID = accountGroup; commitment.ProjectID = container.ProjectID; commitment.ProjectTaskID = container.TaskID; commitment.UOM = container.UOM; commitment.OrigQty = container.OrigQty; commitment.OrigAmount = container.OrigAmount; commitment.Qty = container.Qty; commitment.Amount = container.Amount; commitment.ReceivedQty = container.ReceivedQty; commitment.OpenQty = container.OpenQty; commitment.OpenAmount = container.OpenAmount; if (container.InvoicedIsReadonly != true) { commitment.InvoicedQty = container.InvoicedQty; commitment.InvoicedAmount = container.InvoicedAmount; } commitment.InvoicedIsReadonly = container.InvoicedIsReadonly; commitment.RefNoteID = container.RefNoteID; commitment.InventoryID = container.InventoryID; commitment.CostCodeID = container.CostCodeID; sender.Graph.Caches[typeof(PMCommitment)].Update(commitment); } } }