protected virtual void ARWriteOffFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { PXUIFieldAttribute.SetEnabled(ARDocumentList.Cache, typeof(ARRegisterEx.reasonCode).Name, true); ARWriteOffFilter filter = (ARWriteOffFilter)e.Row; if (filter != null) { if (customer.Current != null && object.Equals(filter.CustomerID, customer.Current.BAccountID) == false) { customer.Current = null; } ARDocumentList.SetAutoPersist(true); ARDocumentList.SetProcessDelegate( delegate(List <ARRegisterEx> list) { List <ARRegister> docs = new List <ARRegister>(list.Count); foreach (ARRegister doc in list) { docs.Add(doc); } CreatePayments(docs, filter); } ); } bool isMultiCurrencyEnabled = PXAccess.FeatureInstalled <FeaturesSet.multicurrency>(); PXUIFieldAttribute.SetVisible <ARRegisterEx.curyID>(ARDocumentList.Cache, null, isMultiCurrencyEnabled); PXUIFieldAttribute.SetVisible <ARRegisterEx.curyDocBal>(ARDocumentList.Cache, null, isMultiCurrencyEnabled); }
protected virtual void ARWriteOffFilter_WOType_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { ARWriteOffFilter filter = (ARWriteOffFilter)e.Row; sender.SetDefaultExt <ARWriteOffFilter.reasonCode>(e.Row); if (customer.Current != null && customer.Current.BAccountID != filter.CustomerID) { customer.Current = null; } }
protected virtual void ARWriteOffFilter_ReasonCode_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { ARWriteOffFilter filter = (ARWriteOffFilter)e.Row; if (filter.WOType == ARWriteOffType.SmallBalanceWO) { e.NewValue = ARSetup.Current.BalanceWriteOff; } else { e.NewValue = ARSetup.Current.CreditWriteOff; } }
protected virtual void ARWriteOffFilter_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { ARWriteOffFilter row = e.Row as ARWriteOffFilter; ARWriteOffFilter oldRow = e.OldRow as ARWriteOffFilter; if (row == null || oldRow == null) { return; } if (!sender.ObjectsEqual <ARWriteOffFilter.woType, ARWriteOffFilter.branchID, ARWriteOffFilter.customerID>(row, oldRow)) { ARDocumentList.Cache.Clear(); row.SelTotal = 0; } else if (row.ReasonCode != oldRow.ReasonCode) { foreach (ARRegisterEx item in ARDocumentList.Select()) { ARDocumentList.Cache.SetValue <ARRegisterEx.reasonCode>(item, row.ReasonCode); } } }
public static void CreatePayments(List <ARRegister> list, ARWriteOffFilter filter) { if (string.IsNullOrEmpty(filter.ReasonCode)) { throw new PXException(Messages.ReasonCodeIsRequired); } bool failed = false; IARWriteOffEntry pe = null; if (filter.WOType == ARDocType.SmallBalanceWO) { pe = PXGraph.CreateInstance <ARSmallBalanceWriteOffEntry>(); } else { pe = PXGraph.CreateInstance <ARSmallCreditWriteOffEntry>(); } List <ARRegister> orig = list; list = new List <ARRegister>(orig); List <ARRegister> paylist = new List <ARRegister>(); List <int> paybind = new List <int>(); var cache = (pe as PXGraph).Caches[typeof(ARRegisterEx)]; list = list.OrderBy(doc => new Tuple <string, string, string, string, string>( (string)(cache.GetValueExt <ARRegisterEx.branchID>(doc) as PXFieldState).Value, doc.CuryID, (string)(cache.GetValueExt <ARRegisterEx.customerID>(doc) as PXFieldState).Value, doc.DocType, doc.RefNbr )).ToList(); for (int i = 0; i < list.Count; i++) { ARRegisterEx doc = (ARRegisterEx)list[i]; int idx = orig.IndexOf(doc); try { ReasonCode reasonCode = PXSelect <ReasonCode, Where <ReasonCode.reasonCodeID, Equal <Required <ReasonCode.reasonCodeID> > > > .Select((PXGraph)pe, doc.ReasonCode ?? filter.ReasonCode); if (reasonCode == null) { throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.ReasonCodeNotFound, filter.ReasonCode)); } Location customerLocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <Location.bAccountID> >, And <Location.locationID, Equal <Required <Location.locationID> > > > > .Select((PXGraph)pe, doc.CustomerID, doc.CustomerLocationID); CRLocation companyLocation = PXSelectJoin <CRLocation, InnerJoin <BAccountR, On <CRLocation.bAccountID, Equal <BAccountR.bAccountID>, And <CRLocation.locationID, Equal <BAccountR.defLocationID> > >, InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <Branch.branchID, Equal <Required <Branch.branchID> > > > .Select((PXGraph)pe, doc.BranchID); object value = null; if (reasonCode.Usage == ReasonCodeUsages.BalanceWriteOff || reasonCode.Usage == ReasonCodeUsages.CreditWriteOff) { value = ReasonCodeSubAccountMaskAttribute.MakeSub <ReasonCode.subMask>((PXGraph)pe, reasonCode.SubMask, new object[] { reasonCode.SubID, customerLocation.CSalesSubID, companyLocation.CMPSalesSubID }, new Type[] { typeof(ReasonCode.subID), typeof(Location.cSalesSubID), typeof(CRLocation.cMPSalesSubID) }); } else { throw new PXException(Messages.InvalidReasonCode); } ARReleaseProcess.EnsureNoUnreleasedVoidPaymentExists((pe as PXGraph), doc, Common.Messages.ActionWrittenOff); pe.CreateWriteOff(reasonCode, value.ToString(), filter.WODate, filter.WOFinPeriodID, doc); if (pe.ARDocument != null && !paylist.Contains(pe.ARDocument)) { paylist.Add(pe.ARDocument); paybind.Add(idx); } } catch (Exception e) { PXProcessing <ARRegister> .SetError(idx, e); failed = true; } } if (paylist.Count > 0) { try { ARDocumentRelease.ReleaseDoc(paylist, false); } catch (PXMassProcessException e) { PXProcessing <ARRegister> .SetError(paybind[e.ListIndex], e.InnerException); failed = true; } } if (failed) { throw new PXException(GL.Messages.DocumentsNotReleased); } }