public virtual void ClosePeriodProc(FinPeriod p) { FiscalPeriod_ID.Current = p; PostGraph pg = PXGraph.CreateInstance <PostGraph>(); foreach (PXResult <Batch, BatchCopy> res in PXSelectJoin <Batch, LeftJoin <BatchCopy, On <BatchCopy.origModule, Equal <Batch.module>, And <BatchCopy.origBatchNbr, Equal <Batch.batchNbr>, And <BatchCopy.autoReverseCopy, Equal <True> > > > >, Where <Batch.finPeriodID, Equal <Required <Batch.finPeriodID> >, And <Batch.autoReverse, Equal <True>, And <Batch.released, Equal <True>, And <BatchCopy.origBatchNbr, IsNull> > > > > .Select(this, p.FinPeriodID)) { pg.Clear(); Batch copy = pg.ReverseBatchProc((Batch)res); pg.ReleaseBatchProc(copy); if (glsetup.Current.AutoPostOption == true) { pg.PostBatchProc(copy); } } if (Unreleased != null || Unposted != null) { throw new PXException(Messages.PeriodHasUnpostedBatches); } using (PXTransactionScope ts = new PXTransactionScope()) { p.Closed = true; p.DateLocked = true; p.APClosed = true; p.ARClosed = true; p.INClosed = true; p.CAClosed = true; p.FAClosed = true; Caches[typeof(FinPeriod)].Update(p); if (Unclosed == null) { if ((FinPeriod)NextFiscalYear.Select(p.FinYear) == null) { throw new PXException(Messages.NoPeriodsForNextYear); } CloseYearProc(p); } Caches[typeof(FinPeriod)].Persist(PXDBOperation.Update); Caches[typeof(FinPeriod)].Persisted(false); ts.Complete(); } }
public static void ReleaseBatch(PostGraph pg, Batch batch) { pg.Clear(); pg.ReleaseBatchProc(batch); if ((bool)batch.AutoReverse) { Batch copy = pg.ReverseBatchProc(batch); if (pg.AutoPost) { pg.PostBatchProc(batch); } pg.Clear(); pg.TimeStamp = copy.tstamp; pg.ReleaseBatchProc(copy); if (pg.AutoPost) { pg.PostBatchProc(copy); } } else if (pg.AutoPost) { pg.PostBatchProc(batch); } }
public static bool Post(List <ProcessInfo <Batch> > infoList, bool isMassProcess) { PostGraph pg = PXGraph.CreateInstance <PostGraph>(); PMSetup setup = PXSelect <PMSetup> .Select(pg); bool failed = false; if (setup != null && setup.AutoPost == true) { foreach (ProcessInfo <Batch> t in infoList) { foreach (Batch batch in t.Batches) { try { pg.Clear(); pg.PostBatchProc(batch); } catch (Exception e) { if (isMassProcess) { failed = true; PXProcessing <PMRegister> .SetError(t.RecordIndex, e is PXOuterException ?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message); } else { var message = PXMessages.LocalizeNoPrefix(Messages.PostToGLFailed) + Environment.NewLine + e.Message; throw new PXMassProcessException(t.RecordIndex, new PXException(message, e)); } } } } } return(!failed); }
public void Revalue(RevalueFilter filter, List <RevaluedGLHistory> list) { JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); PostGraph pg = PXGraph.CreateInstance <PostGraph>(); PXCache basecache = je.Caches[typeof(AcctHist)]; je.Views.Caches.Add(typeof(AcctHist)); string extRefNbrNumbering = je.CMSetup.Current.ExtRefNbrNumberingID; if (string.IsNullOrEmpty(extRefNbrNumbering) == false) { RevaluationRefNbrHelper helper = new RevaluationRefNbrHelper(extRefNbrNumbering); helper.Subscribe(je); } DocumentList <Batch> created = new DocumentList <Batch>(je); Currency currency = PXSelect <Currency, Where <Currency.curyID, Equal <Required <Currency.curyID> > > > .Select(je, filter.CuryID); bool hasErrors = false; using (PXTransactionScope ts = new PXTransactionScope()) { foreach (RevaluedGLHistory hist in list) { PXProcessing <RevaluedGLHistory> .SetCurrentItem(hist); if (hist.FinPtdRevalued == 0m) { PXProcessing <RevaluedGLHistory> .SetProcessed(); continue; } string FinPeriod = FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(hist.BranchID), filter.FinPeriodID) .Result .FinPeriodID; ProcessingResult result = CheckFinPeriod(FinPeriod, hist.BranchID); if (!result.IsSuccess) { hasErrors = true; continue; } if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted) { je.Save.Press(); if (created.Find(je.BatchModule.Current) == null) { created.Add(je.BatchModule.Current); } } Batch cmbatch = created.Find <Batch.branchID>(hist.BranchID) ?? new Batch(); if (cmbatch.BatchNbr == null) { je.Clear(); CurrencyInfo info = new CurrencyInfo(); info.CuryID = hist.CuryID; info.CuryEffDate = hist.CuryEffDate; info.BaseCalc = false; info = je.currencyinfo.Insert(info) ?? info; cmbatch = new Batch(); cmbatch.BranchID = hist.BranchID; cmbatch.Module = "CM"; cmbatch.Status = "U"; cmbatch.AutoReverse = false; cmbatch.Released = true; cmbatch.Hold = false; cmbatch.DateEntered = filter.CuryEffDate; FinPeriodIDAttribute.SetPeriodsByMaster <Batch.finPeriodID>(je.BatchModule.Cache, cmbatch, filter.FinPeriodID); cmbatch.CuryID = hist.CuryID; cmbatch.CuryInfoID = info.CuryInfoID; cmbatch.DebitTotal = 0m; cmbatch.CreditTotal = 0m; cmbatch.Description = filter.Description; je.BatchModule.Insert(cmbatch); CurrencyInfo b_info = je.currencyinfo.Select(); if (b_info != null) { b_info.CuryID = hist.CuryID; b_info.CuryEffDate = hist.CuryEffDate; b_info.CuryRateTypeID = hist.CuryRateTypeID; b_info.CuryRate = hist.CuryRate; b_info.RecipRate = hist.RateReciprocal; b_info.CuryMultDiv = hist.CuryMultDiv; je.currencyinfo.Update(b_info); } } else { if (!je.BatchModule.Cache.ObjectsEqual(je.BatchModule.Current, cmbatch)) { je.Clear(); } je.BatchModule.Current = je.BatchModule.Search <Batch.batchNbr>(cmbatch.BatchNbr, cmbatch.Module); } { GLTran tran = new GLTran(); tran.SummPost = false; tran.AccountID = hist.AccountID; tran.SubID = hist.SubID; tran.CuryDebitAmt = 0m; tran.CuryCreditAmt = 0m; if (hist.AccountType == AccountType.Asset || hist.AccountType == AccountType.Expense) { tran.DebitAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued; tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m; } else { tran.DebitAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m; tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued; } tran.TranType = "REV"; tran.TranClass = hist.AccountType; tran.RefNbr = string.Empty; tran.TranDesc = filter.Description; FinPeriodIDAttribute.SetPeriodsByMaster <GLTran.finPeriodID>(je.GLTranModuleBatNbr.Cache, tran, filter.FinPeriodID); tran.TranDate = filter.CuryEffDate; tran.CuryInfoID = null; tran.Released = true; tran.ReferenceID = null; tran.ProjectID = PM.ProjectDefaultAttribute.NonProject(); je.GLTranModuleBatNbr.Insert(tran); } foreach (GLTran tran in je.GLTranModuleBatNbr.SearchAll <Asc <GLTran.tranClass> >(new object[] { "G" })) { je.GLTranModuleBatNbr.Delete(tran); } { GLTran tran = new GLTran(); tran.SummPost = true; tran.ZeroPost = false; tran.CuryDebitAmt = 0m; tran.CuryCreditAmt = 0m; if (je.BatchModule.Current.DebitTotal > je.BatchModule.Current.CreditTotal) { tran.AccountID = currency.RevalGainAcctID; tran.SubID = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalGainSubID>(je, hist.BranchID, currency); tran.DebitAmt = 0m; tran.CreditAmt = (je.BatchModule.Current.DebitTotal - je.BatchModule.Current.CreditTotal); } else { tran.AccountID = currency.RevalLossAcctID; tran.SubID = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalLossSubID>(je, hist.BranchID, currency); tran.DebitAmt = (je.BatchModule.Current.CreditTotal - je.BatchModule.Current.DebitTotal); tran.CreditAmt = 0m; } tran.TranType = "REV"; tran.TranClass = GLTran.tranClass.UnrealizedAndRevaluationGOL; tran.RefNbr = string.Empty; tran.TranDesc = filter.Description; tran.Released = true; tran.ReferenceID = null; je.GLTranModuleBatNbr.Insert(tran); } { AcctHist accthist = new AcctHist(); accthist.BranchID = hist.BranchID; accthist.LedgerID = hist.LedgerID; accthist.AccountID = hist.AccountID; accthist.SubID = hist.SubID; accthist.FinPeriodID = filter.FinPeriodID; accthist.CuryID = hist.CuryID; accthist.BalanceType = "A"; accthist = (AcctHist)basecache.Insert(accthist); accthist.FinPtdRevalued += hist.FinPtdRevalued; } PXProcessing <RevaluedGLHistory> .SetProcessed(); } if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted) { je.Save.Press(); if (created.Find(je.BatchModule.Current) == null) { created.Add(je.BatchModule.Current); } } ts.Complete(); } CMSetup cmsetup = PXSelect <CMSetup> .Select(je); for (int i = 0; i < created.Count; i++) { if (cmsetup.AutoPostOption == true) { pg.Clear(); pg.PostBatchProc(created[i]); } } if (hasErrors) { //Clean current to prevent set exception to the last item PXProcessing <RevaluedGLHistory> .SetCurrentItem(null); throw new PXException(ErrorMessages.SeveralItemsFailed); } if (created.Count > 0) { je.BatchModule.Current = created[created.Count - 1]; throw new PXRedirectRequiredException(je, "Preview"); } decimal val = 0m; foreach (RevaluedGLHistory res in GLAccountList.Cache.Updated) { if ((bool)res.Selected) { decimal sign = AccountRules.IsDEALAccount(res.AccountType) ? 1.0m : -1.0m; val += sign * (decimal)res.FinPtdRevalued; } } if (val == 0) { throw new PXOperationCompletedWithWarningException(Messages.NoRevaluationEntryWasMade); } }
public static void RunRecognition(List <ScheduledTran> trans, DateTime?filterDate) { ScheduleMaint scheduleMaint = PXGraph.CreateInstance <ScheduleMaint>(); scheduleMaint.Clear(); bool failed = false; List <ScheduledTran> items = GetValidatedItems(trans, scheduleMaint); failed = items.Count() < trans.Count(); // Save virtual records: // - foreach (ScheduledTran tr in items) { PXProcessing <ScheduledTran> .SetCurrentItem(tr); if (tr.IsVirtual == true) { try { scheduleMaint.Document.Current = PXSelect <DRScheduleDetail, Where <DRScheduleDetail.scheduleID, Equal <Required <DRScheduleDetail.scheduleID> >, And <DRScheduleDetail.componentID, Equal <Required <DRScheduleDetail.componentID> > > > > .Select(scheduleMaint, tr.ScheduleID, tr.ComponentID ?? DRScheduleDetail.EmptyComponentID); DRScheduleTran tran = new DRScheduleTran(); tran.BranchID = tr.BranchID; tran.AccountID = tr.AccountID; tran.SubID = tr.SubID; tran.AdjgDocType = tr.AdjgDocType; tran.AdjgRefNbr = tr.AdjgRefNbr; tran.AdjNbr = tr.AdjNbr; tran.Amount = tr.Amount; tran.ComponentID = tr.ComponentID ?? DRScheduleDetail.EmptyComponentID; tran.FinPeriodID = tr.FinPeriodID; tran.ScheduleID = tr.ScheduleID; tran.RecDate = tr.RecDate; tran.Status = DRScheduleTranStatus.Open; tran = scheduleMaint.OpenTransactions.Insert(tran); tr.LineNbr = tran.LineNbr; scheduleMaint.RebuildProjections(); scheduleMaint.Save.Press(); byte[] ts = scheduleMaint.TimeStamp; scheduleMaint.Clear(); scheduleMaint.TimeStamp = ts; PXProcessing <ScheduledTran> .SetProcessed(); } catch (Exception ex) { failed = true; PXProcessing <ScheduledTran> .SetError(ex.Message); } } else { PXProcessing <ScheduledTran> .SetProcessed(); } } PXProcessing <ScheduledTran> .SetCurrentItem(null); List <DRBatch> list = SplitByFinPeriod(items); DRProcess process = CreateInstance <DRProcess>(); process.Clear(); process.TimeStamp = scheduleMaint.TimeStamp; List <Batch> batchlist = process.RunRecognition(list, filterDate); PostGraph pg = PXGraph.CreateInstance <PostGraph>(); //Post Batches if AutoPost bool postFailed = false; if (pg.AutoPost) { foreach (Batch batch in batchlist) { try { pg.Clear(); pg.TimeStamp = batch.tstamp; pg.PostBatchProc(batch); } catch (Exception) { postFailed = true; } } if (postFailed) { throw new PXException(Messages.AutoPostFailed); } } if (failed) { throw new PXException(GL.Messages.DocumentsNotReleased); } }
public static void Revalue(RevalueFilter filter, List <RevaluedGLHistory> list) { JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); PostGraph pg = PXGraph.CreateInstance <PostGraph>(); PXCache cache = je.Caches[typeof(CuryAcctHist)]; PXCache basecache = je.Caches[typeof(AcctHist)]; je.Views.Caches.Add(typeof(CuryAcctHist)); je.Views.Caches.Add(typeof(AcctHist)); string extRefNbrNumbering = je.CMSetup.Current.ExtRefNbrNumberingID; if (string.IsNullOrEmpty(extRefNbrNumbering) == false) { RevaluationRefNbrHelper helper = new RevaluationRefNbrHelper(extRefNbrNumbering); je.RowPersisting.AddHandler <GLTran>(helper.OnRowPersisting); } DocumentList <Batch> created = new DocumentList <Batch>(je); Currency currency = PXSelect <Currency, Where <Currency.curyID, Equal <Required <Currency.curyID> > > > .Select(je, filter.CuryID); using (PXTransactionScope ts = new PXTransactionScope()) { foreach (RevaluedGLHistory hist in list) { if (hist.FinPtdRevalued == 0m) { continue; } if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted) { je.Save.Press(); if (created.Find(je.BatchModule.Current) == null) { created.Add(je.BatchModule.Current); } } Batch cmbatch = created.Find <Batch.branchID>(hist.BranchID) ?? new Batch(); if (cmbatch.BatchNbr == null) { je.Clear(); CurrencyInfo info = new CurrencyInfo(); info.CuryID = hist.CuryID; info.CuryEffDate = filter.CuryEffDate; info = je.currencyinfo.Insert(info) ?? info; cmbatch = new Batch(); cmbatch.BranchID = hist.BranchID; cmbatch.Module = "CM"; cmbatch.Status = "U"; cmbatch.AutoReverse = false; cmbatch.Released = true; cmbatch.Hold = false; cmbatch.DateEntered = filter.CuryEffDate; cmbatch.FinPeriodID = filter.FinPeriodID; cmbatch.TranPeriodID = filter.FinPeriodID; cmbatch.CuryID = hist.CuryID; cmbatch.CuryInfoID = info.CuryInfoID; cmbatch.DebitTotal = 0m; cmbatch.CreditTotal = 0m; cmbatch.Description = filter.Description; je.BatchModule.Insert(cmbatch); CurrencyInfo b_info = je.currencyinfo.Select(); if (b_info != null) { b_info.CuryID = hist.CuryID; b_info.CuryEffDate = filter.CuryEffDate; b_info.CuryRate = 1m; b_info.CuryMultDiv = "M"; je.currencyinfo.Update(b_info); } } else { je.BatchModule.Current = je.BatchModule.Search <Batch.batchNbr>(cmbatch.BatchNbr, cmbatch.Module); } { GLTran tran = new GLTran(); tran.SummPost = false; tran.AccountID = hist.AccountID; tran.SubID = hist.SubID; tran.CuryDebitAmt = 0m; tran.CuryCreditAmt = 0m; if (hist.AccountType == AccountType.Asset || hist.AccountType == AccountType.Expense) { tran.DebitAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued; tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m; } else { tran.DebitAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m; tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued; } tran.TranType = "REV"; tran.TranClass = hist.AccountType; tran.RefNbr = string.Empty; tran.TranDesc = string.Empty; tran.TranPeriodID = filter.FinPeriodID; tran.FinPeriodID = filter.FinPeriodID; tran.TranDate = filter.CuryEffDate; tran.CuryInfoID = null; tran.Released = true; tran.ReferenceID = null; je.GLTranModuleBatNbr.Insert(tran); } foreach (GLTran tran in je.GLTranModuleBatNbr.SearchAll <Asc <GLTran.tranClass> >(new object[] { "G" })) { je.GLTranModuleBatNbr.Delete(tran); } { GLTran tran = new GLTran(); tran.SummPost = true; tran.CuryDebitAmt = 0m; tran.CuryCreditAmt = 0m; if (je.BatchModule.Current.DebitTotal > je.BatchModule.Current.CreditTotal) { tran.AccountID = currency.RevalGainAcctID; tran.SubID = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalGainSubID>(je, hist.BranchID, currency); tran.DebitAmt = 0m; tran.CreditAmt = (je.BatchModule.Current.DebitTotal - je.BatchModule.Current.CreditTotal); } else { tran.AccountID = currency.RevalLossAcctID; tran.SubID = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalLossSubID>(je, hist.BranchID, currency); tran.DebitAmt = (je.BatchModule.Current.CreditTotal - je.BatchModule.Current.DebitTotal); tran.CreditAmt = 0m; } tran.TranType = "REV"; tran.TranClass = "G"; tran.RefNbr = string.Empty; tran.TranDesc = string.Empty; tran.Released = true; tran.ReferenceID = null; je.GLTranModuleBatNbr.Insert(tran); } { AcctHist accthist = new AcctHist(); accthist.BranchID = hist.BranchID; accthist.LedgerID = hist.LedgerID; accthist.AccountID = hist.AccountID; accthist.SubID = hist.SubID; accthist.FinPeriodID = filter.FinPeriodID; accthist.CuryID = hist.CuryID; accthist.BalanceType = "A"; accthist = (AcctHist)basecache.Insert(accthist); accthist.FinPtdRevalued += hist.FinPtdRevalued; } { CuryAcctHist accthist = new CuryAcctHist(); accthist.BranchID = hist.BranchID; accthist.LedgerID = hist.LedgerID; accthist.AccountID = hist.AccountID; accthist.SubID = hist.SubID; accthist.FinPeriodID = filter.FinPeriodID; accthist.CuryID = hist.CuryID; accthist.BalanceType = "A"; accthist.BaseCuryID = je.currencyinfo.Current.BaseCuryID; accthist = (CuryAcctHist)cache.Insert(accthist); } } if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted) { je.Save.Press(); if (created.Find(je.BatchModule.Current) == null) { created.Add(je.BatchModule.Current); } } ts.Complete(); } CMSetup cmsetup = PXSelect <CMSetup> .Select(je); for (int i = 0; i < created.Count; i++) { if (cmsetup.AutoPostOption == true) { pg.Clear(); pg.PostBatchProc(created[i]); } } if (created.Count > 0) { je.BatchModule.Current = created[created.Count - 1]; throw new PXRedirectRequiredException(je, "Preview"); } }
public static void Revalue(RevalueFilter filter, List <RevaluedARHistory> list) { JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); PostGraph pg = PXGraph.CreateInstance <PostGraph>(); PXCache cache = je.Caches[typeof(CuryARHist)]; PXCache basecache = je.Caches[typeof(ARHist)]; je.Views.Caches.Add(typeof(CuryARHist)); je.Views.Caches.Add(typeof(ARHist)); string extRefNbrNumbering = je.CMSetup.Current.ExtRefNbrNumberingID; if (string.IsNullOrEmpty(extRefNbrNumbering) == false) { RevaluationRefNbrHelper helper = new RevaluationRefNbrHelper(extRefNbrNumbering); helper.Subscribe(je); } DocumentList <Batch> created = new DocumentList <Batch>(je); Currency currency = PXSelect <Currency, Where <Currency.curyID, Equal <Required <Currency.curyID> > > > .Select(je, filter.CuryID); using (PXTransactionScope ts = new PXTransactionScope()) { foreach (RevaluedARHistory hist in list) { if (hist.FinPtdRevalued == 0m) { continue; } if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted) { je.Save.Press(); if (created.Find(je.BatchModule.Current) == null) { created.Add(je.BatchModule.Current); } } Batch cmbatch = created.Find <Batch.branchID>(hist.BranchID) ?? new Batch(); if (cmbatch.BatchNbr == null) { je.Clear(); CurrencyInfo info = new CurrencyInfo(); info.CuryID = hist.CuryID; info.CuryEffDate = hist.CuryEffDate; info.BaseCalc = false; info = je.currencyinfo.Insert(info) ?? info; cmbatch = new Batch(); cmbatch.BranchID = hist.BranchID; cmbatch.Module = "CM"; cmbatch.Status = "U"; cmbatch.AutoReverse = true; cmbatch.Released = true; cmbatch.Hold = false; cmbatch.DateEntered = filter.CuryEffDate; cmbatch.FinPeriodID = filter.FinPeriodID; cmbatch.TranPeriodID = filter.FinPeriodID; cmbatch.CuryID = hist.CuryID; cmbatch.CuryInfoID = info.CuryInfoID; cmbatch.DebitTotal = 0m; cmbatch.CreditTotal = 0m; cmbatch.Description = filter.Description; je.BatchModule.Insert(cmbatch); CurrencyInfo b_info = je.currencyinfo.Select(); if (b_info != null) { b_info.CuryID = hist.CuryID; b_info.CuryEffDate = hist.CuryEffDate; b_info.CuryRateTypeID = hist.CuryRateTypeID; b_info.CuryRate = hist.CuryRate; b_info.RecipRate = hist.RateReciprocal; b_info.CuryMultDiv = hist.CuryMultDiv; je.currencyinfo.Update(b_info); } } else { if (!je.BatchModule.Cache.ObjectsEqual(je.BatchModule.Current, cmbatch)) { je.Clear(); } je.BatchModule.Current = je.BatchModule.Search <Batch.batchNbr>(cmbatch.BatchNbr, cmbatch.Module); } { GLTran tran = new GLTran(); tran.SummPost = false; tran.AccountID = currency.ARProvAcctID ?? hist.AccountID; tran.SubID = currency.ARProvSubID ?? hist.SubID; tran.CuryDebitAmt = 0m; tran.CuryCreditAmt = 0m; tran.DebitAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued; tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m; tran.TranType = "REV"; tran.TranClass = AccountType.Asset; tran.RefNbr = string.Empty; tran.TranDesc = filter.Description; tran.TranPeriodID = filter.FinPeriodID; tran.FinPeriodID = filter.FinPeriodID; tran.TranDate = filter.CuryEffDate; tran.CuryInfoID = null; tran.Released = true; tran.ReferenceID = hist.CustomerID; je.GLTranModuleBatNbr.Insert(tran); } CustomerClass custclass = PXSelectReadonly <CustomerClass, Where <CustomerClass.customerClassID, Equal <Required <CustomerClass.customerClassID> > > > .Select(je, hist.CustomerClassID); if (custclass == null) { custclass = new CustomerClass(); } if (custclass.UnrealizedGainAcctID == null) { custclass.UnrealizedGainSubID = null; } if (custclass.UnrealizedLossAcctID == null) { custclass.UnrealizedLossSubID = null; } { GLTran tran = new GLTran(); tran.SummPost = true; tran.ZeroPost = false; tran.CuryDebitAmt = 0m; tran.CuryCreditAmt = 0m; if (je.BatchModule.Current.DebitTotal > je.BatchModule.Current.CreditTotal) { tran.AccountID = custclass.UnrealizedGainAcctID ?? currency.UnrealizedGainAcctID; tran.SubID = custclass.UnrealizedGainSubID ?? GainLossSubAccountMaskAttribute.GetSubID <Currency.unrealizedGainSubID>(je, hist.BranchID, currency); tran.DebitAmt = 0m; tran.CreditAmt = (je.BatchModule.Current.DebitTotal - je.BatchModule.Current.CreditTotal); } else { tran.AccountID = custclass.UnrealizedLossAcctID ?? currency.UnrealizedLossAcctID; tran.SubID = custclass.UnrealizedLossSubID ?? GainLossSubAccountMaskAttribute.GetSubID <Currency.unrealizedLossSubID>(je, hist.BranchID, currency); tran.DebitAmt = (je.BatchModule.Current.CreditTotal - je.BatchModule.Current.DebitTotal); tran.CreditAmt = 0m; } tran.TranType = "REV"; tran.TranClass = GLTran.tranClass.UnrealizedAndRevaluationGOL; tran.RefNbr = string.Empty; tran.TranDesc = filter.Description; tran.Released = true; tran.ReferenceID = null; je.GLTranModuleBatNbr.Insert(tran); } { CuryARHist arhist = new CuryARHist(); arhist.BranchID = hist.BranchID; arhist.AccountID = hist.AccountID; arhist.SubID = hist.SubID; arhist.FinPeriodID = filter.FinPeriodID; arhist.CustomerID = hist.CustomerID; arhist.CuryID = hist.CuryID; arhist = (CuryARHist)cache.Insert(arhist); arhist.FinPtdRevalued += hist.FinPtdRevalued; } { ARHist arhist = new ARHist(); arhist.BranchID = hist.BranchID; arhist.AccountID = hist.AccountID; arhist.SubID = hist.SubID; arhist.FinPeriodID = filter.FinPeriodID; arhist.CustomerID = hist.CustomerID; arhist = (ARHist)basecache.Insert(arhist); arhist.FinPtdRevalued += hist.FinPtdRevalued; } } if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted) { je.Save.Press(); if (created.Find(je.BatchModule.Current) == null) { created.Add(je.BatchModule.Current); } } ts.Complete(); } CMSetup cmsetup = PXSelect <CMSetup> .Select(je); for (int i = 0; i < created.Count; i++) { if (cmsetup.AutoPostOption == true) { pg.Clear(); pg.PostBatchProc(created[i]); } } if (created.Count > 0) { je.BatchModule.Current = created[created.Count - 1]; throw new PXRedirectRequiredException(je, "Preview"); } }
public void ReleaseBatchProc(GLVoucherBatch aBatch, Dictionary <string, Dictionary <Guid, CAMessage> > errorList) { this.Clear(); GLVoucherBatch row = (GLVoucherBatch)this.Document.Select(aBatch.WorkBookID, aBatch.VoucherBatchNbr); this.Document.Current = row; Dictionary <Guid, CAMessage> errorLog = null; if (!errorList.ContainsKey(row.VoucherBatchNbr)) { errorList.Add(row.VoucherBatchNbr, new Dictionary <Guid, CAMessage>()); } errorLog = errorList[row.VoucherBatchNbr]; List <Batch> toPost = new List <Batch>(); try { Exception releaseException = null; try { this.ReleaseBatchDetailsProc(aBatch, toPost, errorLog); if (HasUnreleasedDetails(aBatch) == false) { GLVoucherBatch copy = (GLVoucherBatch)this.Document.Cache.CreateCopy(row); copy.Released = true; this.Document.Update(copy); this.Actions.PressSave(); } } catch (Exception ex) { releaseException = ex; } List <Batch> postFailedList = new List <Batch>(); if (toPost.Count > 0) { PostGraph pg = PXGraph.CreateInstance <PostGraph>(); foreach (Batch iBatch in toPost) { try { //if (rg.AutoPost) { pg.Clear(); pg.PostBatchProc(iBatch); } } catch (Exception) { postFailedList.Add(iBatch); } } } if (releaseException != null) { throw releaseException; } if (postFailedList.Count > 0) { throw new PXException(Messages.PostingOfSomeDocumentsFailed, postFailedList.Count, toPost.Count); } } catch (PXException ex) { errorLog.Add(Guid.Empty, FormatError(ex)); throw ex; } }