protected virtual void ARRegisterEx_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { ARRegisterEx row = e.Row as ARRegisterEx; if (row == null) { return; } bool WODate_GT_DocDate = DateTime.Compare((DateTime)Filter.Current.WODate, (DateTime)((ARRegisterEx)e.Row).DocDate) >= 0; bool WOPeriod_GT_DocPeriod = string.Compare(Filter.Current.WOFinPeriodID, ((ARRegisterEx)e.Row).FinPeriodID) >= 0; PXUIFieldAttribute.SetEnabled <ARRegisterEx.selected>(sender, e.Row, WODate_GT_DocDate && WOPeriod_GT_DocPeriod); sender.RaiseExceptionHandling <ARRegisterEx.docDate>(e.Row, null, !WODate_GT_DocDate ? new PXSetPropertyException(Messages.WriteOff_ApplDate_Less_DocDate, PXErrorLevel.RowError, PXUIFieldAttribute.GetDisplayName <ARWriteOffFilter.wODate>(Filter.Cache)) : null); sender.RaiseExceptionHandling <ARRegisterEx.finPeriodID>(e.Row, null, !WOPeriod_GT_DocPeriod ? new PXSetPropertyException(Messages.ApplPeriod_Less_DocPeriod, PXErrorLevel.RowError, PXUIFieldAttribute.GetDisplayName <ARWriteOffFilter.wOFinPeriodID>(Filter.Cache)) : null); if (string.IsNullOrEmpty(row.ReasonCode)) { row.ReasonCode = Filter.Current.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); } }