private Batch BuildReclassificationBatch(IReadOnlyCollection <ReclassificationItem> transForReclassItems, List <GLTran> transMovedFromExistingBatch, Batch batchForEditing = null) { DateTime earliestNewTranDate = DateTime.MaxValue; Batch batch; var representativeTranForReclass = transForReclassItems.First().HeadTranForReclass; JournalEntryInstance.BatchModule.Current = null; if (batchForEditing == null) { batch = JournalEntryInstance.BatchModule.Insert(new Batch() { BranchID = representativeTranForReclass.NewBranchID, FinPeriodID = representativeTranForReclass.NewFinPeriodID }); } else { batch = batchForEditing; JournalEntryInstance.BatchModule.Current = batch; } //adding or editing of transactions foreach (var reclassItem in transForReclassItems) { IEnumerable <GLTranForReclassification> headTranForReclass = IsReclassAttrChanged(reclassItem.HeadTranForReclass) ? reclassItem.HeadTranForReclass.SingleToArray().Union(reclassItem.SplittingTransForReclass) : new GLTranForReclassification[0]; IEnumerable <GLTranForReclassification> tranForReclassToProcess = headTranForReclass.Union(reclassItem.SplittingTransForReclass); foreach (var tranForReclass in tranForReclassToProcess) { GLTran reclassifyingTran = CreateOrEditReclassTranPair(tranForReclass, reclassItem, transMovedFromExistingBatch); if (reclassifyingTran.TranDate < earliestNewTranDate) { earliestNewTranDate = reclassifyingTran.TranDate.Value; } } } //remove deleted trans if (batchForEditing != null) { foreach (var tranForReclassToDel in State.GLTranForReclassToDelete) { var reverseTran = LocateReverseTran(JournalEntryInstance.GLTranModuleBatNbr.Cache, tranForReclassToDel); var reclassifyingTran = LocateReclassifyingTran(JournalEntryInstance.GLTranModuleBatNbr.Cache, tranForReclassToDel); JournalEntryInstance.GLTranModuleBatNbr.Delete(reclassifyingTran); JournalEntryInstance.GLTranModuleBatNbr.Delete(reverseTran); } } //creating and editing of batch header if (batchForEditing == null) { var batchCuryInfo = PXCache <CurrencyInfo> .CreateCopy(transForReclassItems.First().CuryInfo); batchCuryInfo.CuryInfoID = null; batchCuryInfo = JournalEntryInstance.currencyinfo.Insert(batchCuryInfo); batch.BatchType = BatchTypeCode.Reclassification; batch.BranchID = representativeTranForReclass.NewBranchID; FinPeriodIDAttribute.SetPeriodsByMaster <Batch.finPeriodID>(JournalEntryInstance.BatchModule.Cache, batch, representativeTranForReclass.TranPeriodID); batch.LedgerID = representativeTranForReclass.LedgerID; batch.Module = BatchModule.GL; batch.CuryInfoID = batchCuryInfo.CuryInfoID; } else { CurrencyInfo firstCuryInfo = null; int? minLineNbr = int.MaxValue; foreach (var item in transForReclassItems) { var reclassTran = item.ReclassifyingTrans.GetItemWithMin(m => m.LineNbr.Value); if (minLineNbr > reclassTran.LineNbr) { minLineNbr = reclassTran.LineNbr; firstCuryInfo = item.CuryInfo; } } var batchCuryInfo = PXCache <CurrencyInfo> .CreateCopy(firstCuryInfo); batchCuryInfo.CuryInfoID = JournalEntryInstance.currencyInfo.CuryInfoID; batchCuryInfo.tstamp = JournalEntryInstance.currencyInfo.tstamp; JournalEntryInstance.currencyinfo.Update(batchCuryInfo); } batch.DateEntered = earliestNewTranDate; batch.CuryID = representativeTranForReclass.CuryID; if (State.ReclassScreenMode == ReclassScreenMode.Reversing) { batch.OrigModule = State.OrigBatchModuleToReverse; batch.OrigBatchNbr = State.OrigBatchNbrToReverse; batch.AutoReverseCopy = true; } batch = JournalEntryInstance.BatchModule.Update(batch); return(batch); }
protected virtual void SetOrigLineNumber(GLTran tran, ReclassificationItem reclassItem) { tran.OrigLineNbr = reclassItem.HeadTranForReclass.LineNbr; }
private static void ValidateCATrans(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period) { PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.module>(graph.Caches[typeof(GLTran)], null, false); PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.batchNbr>(graph.Caches[typeof(GLTran)], null, false); PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.ledgerID>(graph.Caches[typeof(GLTran)], null, false); PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.finPeriodID>(graph.Caches[typeof(GLTran)], null, false); using (new PXConnectionScope()) { const int rowsPerCycle = 10000; bool noMoreTran = false; int? lastGLTranIDOnPreviousStep = null; int previousCountRows = 0; while (!noMoreTran) { noMoreTran = true; int countRows = 0; int?lastGLTranID = null; using (PXTransactionScope ts = new PXTransactionScope()) { foreach (PXResult <GLTran, Ledger, Batch> res in PXSelectJoin <GLTran, InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLTran.ledgerID> >, InnerJoin <Batch, On <Batch.module, Equal <GLTran.module>, And <Batch.batchNbr, Equal <GLTran.batchNbr>, And <Batch.scheduled, Equal <False>, And <Batch.voided, NotEqual <True> > > > > > >, Where <GLTran.accountID, Equal <Required <GLTran.accountID> >, And <GLTran.subID, Equal <Required <GLTran.subID> >, And <GLTran.branchID, Equal <Required <GLTran.branchID> >, And <Ledger.balanceType, Equal <LedgerBalanceType.actual>, //ignoring CM because DefaultValues always return null for CM And <GLTran.module, NotEqual <BatchModule.moduleCM>, And <GLTran.cATranID, IsNull, And <GLTran.finPeriodID, GreaterEqual <Required <GLTran.finPeriodID> > > > > > > > >, OrderBy <Asc <GLTran.tranID> > > .SelectWindowed(graph, 0, rowsPerCycle, cashAccount.AccountID, cashAccount.SubID, cashAccount.BranchID, period.FinPeriodID)) { GLTran gltran = (GLTran)res; lastGLTranID = gltran.TranID; noMoreTran = false; countRows++; CATran catran = GLCashTranIDAttribute.DefaultValues <GLTran.cATranID>(graph.gltrancache, gltran); if (catran != null) { long id; bool newCATRan = false; if (graph.catrancache.Locate(catran) == null) { catran = (CATran)graph.catrancache.Insert(catran); newCATRan = true; graph.catrancache.PersistInserted(catran); id = Convert.ToInt64(PXDatabase.SelectIdentity()); } else { catran = (CATran)graph.catrancache.Update(catran); graph.catrancache.PersistUpdated(catran); id = catran.TranID.Value; } gltran.CATranID = id; graph.gltrancache.Update(gltran); if (catran.OrigModule != GLTranType.GLEntry) { switch (catran.OrigModule) { case BatchModule.AR: ARPayment arPayment = PXSelect <ARPayment, Where <ARPayment.docType, Equal <Required <ARPayment.docType> >, And <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> > > > > .Select(graph, catran.OrigTranType, catran.OrigRefNbr); if (arPayment != null && (arPayment.CATranID == null || newCATRan)) { arPayment.CATranID = id; arPayment = (ARPayment)graph.Caches[typeof(ARPayment)].Update(arPayment); graph.Caches[typeof(ARPayment)].PersistUpdated(arPayment); } break; case BatchModule.AP: APPayment apPayment = PXSelect <APPayment, Where <APPayment.docType, Equal <Required <APPayment.docType> >, And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > > .Select(graph, catran.OrigTranType, catran.OrigRefNbr); if (apPayment != null && (apPayment.CATranID == null || newCATRan)) { apPayment.CATranID = id; apPayment = (APPayment)graph.Caches[typeof(APPayment)].Update(apPayment); graph.Caches[typeof(APPayment)].PersistUpdated(apPayment); } break; } } } } if (!noMoreTran && countRows == previousCountRows && lastGLTranID == lastGLTranIDOnPreviousStep) { throw new PXException(Messages.ProcessCannotBeCompleted); } previousCountRows = countRows; lastGLTranIDOnPreviousStep = lastGLTranID; graph.gltrancache.ClearQueryCache(); graph.gltrancache.Persist(PXDBOperation.Update); graph.gltrancache.Clear(); graph.catrancache.Clear(); graph.catrancache.ClearQueryCache(); graph.Caches[typeof(APPayment)].Clear(); graph.Caches[typeof(ARPayment)].Clear(); ts.Complete(graph); } } graph.gltrancache.Persisted(false); graph.catrancache.Persisted(false); } }
private static void ValidateCAAdjustments(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period) { using (new PXConnectionScope()) { PXCache adjcache = graph.Caches[typeof(CAAdj)]; using (PXTransactionScope ts = new PXTransactionScope()) { foreach (PXResult <CAAdj, CATran> res in PXSelectJoin <CAAdj, LeftJoin <CATran, On <CATran.tranID, Equal <CAAdj.tranID> >, LeftJoin <GLTranDoc, On <GLTranDoc.refNbr, Equal <CAAdj.adjRefNbr>, And <GLTranDoc.tranType, Equal <CAAdj.adjTranType>, And <GLTranDoc.tranModule, Equal <BatchModule.moduleCA> > > > > >, Where <CAAdj.cashAccountID, Equal <Required <CAAdj.cashAccountID> >, And <CATran.tranID, IsNull, And <GLTranDoc.refNbr, IsNull, And <CAAdj.finPeriodID, GreaterEqual <Required <CAAdj.finPeriodID> > > > > > > .Select(graph, cashAccount.CashAccountID, period.FinPeriodID)) { CAAdj caadj = (CAAdj)res; GLTran gltran = PXSelectJoin <GLTran, InnerJoin <CashAccount, On <CashAccount.accountID, Equal <GLTran.accountID>, And <CashAccount.subID, Equal <GLTran.subID>, And <CashAccount.branchID, Equal <GLTran.branchID> > > > >, Where <GLTran.cATranID, Equal <Required <CAAdj.tranID> >, And <CashAccount.cashAccountID, Equal <Required <CAAdj.cashAccountID> > > > > .Select(graph, caadj.TranID, caadj.CashAccountID); adjcache.SetValue <CAAdj.tranID>(caadj, null); adjcache.SetValue <CAAdj.cleared>(caadj, false); CATran catran = AdjCashTranIDAttribute.DefaultValues <CAAdj.tranID>(adjcache, caadj); catran.BatchNbr = gltran?.BatchNbr; long?id = null; if (catran != null) { catran = (CATran)graph.catrancache.Insert(catran); graph.catrancache.PersistInserted(catran); id = Convert.ToInt64(PXDatabase.SelectIdentity()); graph.SelectTimeStamp(); adjcache.SetValue <CAAdj.tranID>(caadj, id); adjcache.Update(caadj); } if (id.HasValue && gltran?.TranID != null) { gltran.CATranID = id; graph.gltrancache.Update(gltran); graph.gltrancache.Persist(PXDBOperation.Update); } } adjcache.Persist(PXDBOperation.Update); ts.Complete(graph); } adjcache.Persisted(false); graph.catrancache.Persisted(false); graph.gltrancache.Persisted(false); } }
public 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); bool hasErrors = false; using (PXTransactionScope ts = new PXTransactionScope()) { foreach (RevaluedARHistory hist in list) { if (hist.FinPtdRevalued == 0m) { continue; } PXProcessing <RevaluedARHistory> .SetCurrentItem(hist); ProcessingResult result = CheckFinPeriod(filter.FinPeriodID, 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 = 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; } PXProcessing <RevaluedARHistory> .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 <RevaluedARHistory> .SetCurrentItem(null); throw new PXException(ErrorMessages.SeveralItemsFailed); } if (created.Count > 0) { je.BatchModule.Current = created[created.Count - 1]; throw new PXRedirectRequiredException(je, "Preview"); } }
public static 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); 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 = 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; 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 = 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; tran.TranPeriodID = filter.FinPeriodID; tran.FinPeriodID = 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; } } 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 virtual void PostShippedNotInvoiced(INTran intran, ARTran n, ARInvoice ardoc, JournalEntry je) { if (intran.UpdateShippedNotInvoiced != true) { return; } if (intran.Released != true) { throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(AR.Messages.ShippedNotInvoicedINtranNotReleased, intran.RefNbr)); } var trancosts = PXSelect <INTranCost, Where <INTranCost.costDocType, Equal <Required <INTranCost.costDocType> >, And <INTranCost.costRefNbr, Equal <Required <INTranCost.costRefNbr> >, And <INTranCost.lineNbr, Equal <Required <INTranCost.lineNbr> > > > > > .Select(Base, intran.DocType, intran.RefNbr, intran.LineNbr); foreach (INTranCost trancost in trancosts) { var itemPostClassRes = (PXResult <InventoryItem, INPostClass>) PXSelectJoin <InventoryItem, LeftJoin <INPostClass, On <INPostClass.postClassID, Equal <InventoryItem.postClassID> > >, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, intran.InventoryID); ReasonCode reasoncode = INTran.FK.ReasonCode.FindParent(Base, intran); INSite site = INSite.PK.Find(Base, intran.SiteID); if (trancost != null && trancost.COGSAcctID != null && intran != null) { //Credit shipped-not-invoiced account GLTran tranFromIN = new GLTran(); tranFromIN.SummPost = Base.SummPost; tranFromIN.BranchID = intran.BranchID; tranFromIN.TranType = trancost.TranType; tranFromIN.TranClass = GLTran.tranClass.ShippedNotInvoiced; tranFromIN.AccountID = intran.COGSAcctID ?? INReleaseProcess.GetAccountDefaults <INPostClass.cOGSAcctID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes, intran); tranFromIN.SubID = intran.COGSSubID ?? INReleaseProcess.GetAccountDefaults <INPostClass.cOGSSubID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes, intran); tranFromIN.CuryDebitAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.DebitAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.CuryCreditAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.CreditAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.RefNbr = trancost.RefNbr; tranFromIN.InventoryID = trancost.InventoryID; tranFromIN.Qty = (trancost.InvtMult == (short)1) ? trancost.Qty : -trancost.Qty; tranFromIN.UOM = intran.UOM; tranFromIN.TranDesc = intran.TranDesc; tranFromIN.TranDate = n.TranDate; bool isNonProject = trancost.InvtMult == (short)0; tranFromIN.ProjectID = isNonProject ? PM.ProjectDefaultAttribute.NonProject() : intran.ProjectID; tranFromIN.TaskID = isNonProject ? null : intran.TaskID; tranFromIN.CostCodeID = tranFromIN.CostCodeID; tranFromIN.Released = true; Base.InsertInvoiceDetailsINTranCostTransaction(je, tranFromIN, new GLTranInsertionContext { ARRegisterRecord = ardoc, ARTranRecord = n, INTranRecord = intran, INTranCostRecord = trancost }); //Debit COGS account tranFromIN = new GLTran(); tranFromIN.SummPost = Base.SummPost; tranFromIN.BranchID = n.BranchID; if (reasoncode?.Usage == ReasonCodeUsages.Issue) { tranFromIN.AccountID = reasoncode.AccountID; tranFromIN.SubID = INReleaseProcess.GetReasonCodeSubID(Base, reasoncode, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); } else { tranFromIN.AccountID = INReleaseProcess.GetAccountDefaults <INPostClass.cOGSAcctID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); if (((INPostClass)itemPostClassRes) != null && ((INPostClass)itemPostClassRes).COGSSubFromSales != true) //we cannot use intran here to retrive cogs/sales sub { tranFromIN.SubID = INReleaseProcess.GetAccountDefaults <INPostClass.cOGSSubID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); } else { tranFromIN.SubID = n.SubID; } } tranFromIN.CuryDebitAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.DebitAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.CuryCreditAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.CreditAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.TranType = trancost.TranType; tranFromIN.TranClass = GLTran.tranClass.ShippedNotInvoiced; tranFromIN.RefNbr = trancost.RefNbr; tranFromIN.InventoryID = trancost.InventoryID; tranFromIN.Qty = (trancost.InvtMult == (short)1) ? -trancost.Qty : trancost.Qty; tranFromIN.UOM = intran.UOM; tranFromIN.TranDesc = intran.TranDesc; tranFromIN.TranDate = n.TranDate; tranFromIN.ProjectID = (trancost.InvtMult == (short)1) ? PM.ProjectDefaultAttribute.NonProject() : intran.ProjectID; tranFromIN.TaskID = (trancost.InvtMult == (short)1) ? null : intran.TaskID; tranFromIN.CostCodeID = intran.CostCodeID; tranFromIN.Released = true; tranFromIN.TranLineNbr = (tranFromIN.SummPost == true) ? null : intran.LineNbr; Base.InsertInvoiceDetailsINTranCostTransaction(je, tranFromIN, new GLTranInsertionContext { ARRegisterRecord = ardoc, ARTranRecord = n, INTranRecord = intran, INTranCostRecord = trancost }); } } }
private void SetDependingOnReclassTypeAttrs(GLTran tran, GLTranForReclassification tranForReclassification) { tran.ReclassType = tranForReclassification.IsSplitting ? ReclassType.Split : ReclassType.Common; SetReclassAmount(tran, tranForReclassification); }
private void SetCommonBusinessAttrs(GLTran tran, GLTranForReclassification tranForReclassification) { tran.TranDate = tranForReclassification.NewTranDate; tran.TranDesc = tranForReclassification.NewTranDesc; }
private static void Validate(CATranEntry te, CashAccount tlist) { if (tlist.Reconcile != true) { te.Clear(); using (new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { PXCache adjcache = te.Caches[typeof(CATran)]; foreach (CATran catran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> > > > .Select(te, tlist.CashAccountID)) { if (tlist.Reconcile != true && (catran.Cleared != true || catran.TranDate == null)) { catran.Cleared = true; catran.ClearDate = catran.TranDate; } te.catrancache.Update(catran); } te.catrancache.Persist(PXDBOperation.Update); ts.Complete(te); } te.catrancache.Persisted(false); } } te.Clear(); using (new PXConnectionScope()) { PXCache adjcache = te.Caches[typeof(CAAdj)]; using (PXTransactionScope ts = new PXTransactionScope()) { foreach (PXResult <CAAdj, CATran> res in PXSelectJoin <CAAdj, LeftJoin <CATran, On <CATran.tranID, Equal <CAAdj.tranID> > >, Where <CAAdj.cashAccountID, Equal <Required <CAAdj.cashAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID)) { CAAdj caadj = (CAAdj)res; adjcache.SetValue <CAAdj.tranID>(caadj, null); adjcache.SetValue <CAAdj.cleared>(caadj, false); CATran catran = AdjCashTranIDAttribute.DefaultValues <CAAdj.tranID>(adjcache, caadj); if (catran != null) { catran = (CATran)te.catrancache.Insert(catran); te.catrancache.PersistInserted(catran); long id = Convert.ToInt64(PXDatabase.SelectIdentity()); adjcache.SetValue <CAAdj.tranID>(caadj, id); adjcache.Update(caadj); } } adjcache.Persist(PXDBOperation.Update); ts.Complete(te); } adjcache.Persisted(false); te.catrancache.Persisted(false); } te.Clear(); using (new PXConnectionScope()) { PXCache transfercache = te.Caches[typeof(CATransfer)]; using (PXTransactionScope ts = new PXTransactionScope()) { foreach (PXResult <CATransfer, CATran> res in PXSelectJoin <CATransfer, LeftJoin <CATran, On <CATran.tranID, Equal <CATransfer.tranIDIn> > >, Where <CATransfer.inAccountID, Equal <Required <CATransfer.inAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID)) { CATransfer catransfer = (CATransfer)res; transfercache.SetValue <CATransfer.tranIDIn>(catransfer, null); transfercache.SetValue <CATransfer.clearedIn>(catransfer, false); if (transfercache.GetValue <CATransfer.clearedOut>(catransfer) == null) { transfercache.SetValue <CATransfer.clearedOut>(catransfer, false); } CATran catran = TransferCashTranIDAttribute.DefaultValues <CATransfer.tranIDIn>(transfercache, catransfer); if (catran != null) { catran = (CATran)te.catrancache.Insert(catran); te.catrancache.PersistInserted(catran); long id = Convert.ToInt64(PXDatabase.SelectIdentity()); transfercache.SetValue <CATransfer.tranIDIn>(catransfer, id); transfercache.Update(catransfer); } } foreach (PXResult <CATransfer, CATran> res in PXSelectJoin <CATransfer, LeftJoin <CATran, On <CATran.tranID, Equal <CATransfer.tranIDOut> > >, Where <CATransfer.outAccountID, Equal <Required <CATransfer.outAccountID> >, And <CATran.tranID, IsNull> > > .Select(te, tlist.CashAccountID)) { CATransfer catransfer = (CATransfer)res; transfercache.SetValue <CATransfer.tranIDOut>(catransfer, null); transfercache.SetValue <CATransfer.clearedOut>(catransfer, false); if (transfercache.GetValue <CATransfer.clearedIn>(catransfer) == null) { transfercache.SetValue <CATransfer.clearedIn>(catransfer, false); } CATran catran = TransferCashTranIDAttribute.DefaultValues <CATransfer.tranIDOut>(transfercache, catransfer); if (catran != null) { catran = (CATran)te.catrancache.Insert(catran); te.catrancache.PersistInserted(catran); long id = Convert.ToInt64(PXDatabase.SelectIdentity()); transfercache.SetValue <CATransfer.tranIDOut>(catransfer, id); transfercache.Update(catransfer); } } transfercache.Persist(PXDBOperation.Update); ts.Complete(te); } transfercache.Persisted(false); te.catrancache.Persisted(false); } te.Clear(); PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.module>(te.Caches[typeof(GLTran)], null, false); PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.batchNbr>(te.Caches[typeof(GLTran)], null, false); PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.ledgerID>(te.Caches[typeof(GLTran)], null, false); PXDBDefaultAttribute.SetDefaultForUpdate <GLTran.finPeriodID>(te.Caches[typeof(GLTran)], null, false); using (new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { foreach (PXResult <GLTran, Ledger, Batch> res in PXSelectJoin <GLTran, InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLTran.ledgerID> >, InnerJoin <Batch, On <Batch.module, Equal <GLTran.module>, And <Batch.batchNbr, Equal <GLTran.batchNbr>, And <Batch.scheduled, Equal <False> > > > > >, Where <GLTran.accountID, Equal <Required <GLTran.accountID> >, And <GLTran.subID, Equal <Required <GLTran.subID> >, And <Ledger.balanceType, Equal <LedgerBalanceType.actual>, And <GLTran.cATranID, IsNull> > > > > .Select(te, tlist.AccountID, tlist.SubID)) { GLTran gltran = (GLTran)res; CATran catran = GLCashTranIDAttribute.DefaultValues <GLTran.cATranID>(te.gltrancache, gltran); if (catran != null) { catran = (CATran)te.catrancache.Insert(catran); te.catrancache.PersistInserted(catran); long id = Convert.ToInt64(PXDatabase.SelectIdentity()); gltran.CATranID = id; te.gltrancache.Update(gltran); } } te.gltrancache.Persist(PXDBOperation.Update); te.dailycache.Clear(); PXDatabase.Delete <CADailySummary>( new PXDataFieldRestrict("CashAccountID", PXDbType.Int, 4, tlist.CashAccountID, PXComp.EQ) ); foreach (CATran tran in PXSelect <CATran, Where <CATran.cashAccountID, Equal <Required <CATran.cashAccountID> > > > .Select(te, tlist.CashAccountID)) { CADailyAccumulatorAttribute.RowInserted <CATran.tranDate>(te.catrancache, tran); } te.dailycache.Persist(PXDBOperation.Insert); te.dailycache.Persist(PXDBOperation.Update); ts.Complete(te); } te.gltrancache.Persisted(false); te.catrancache.Persisted(false); te.dailycache.Persisted(false); } }
public GLTranReclHist(GLTran tran) { IncludedInReclassHistory = tran.IncludedInReclassHistory; BranchID = tran.BranchID; Module = tran.Module; BatchNbr = tran.BatchNbr; LineNbr = tran.LineNbr; LedgerID = tran.LedgerID; AccountID = tran.AccountID; SubID = tran.SubID; ProjectID = tran.ProjectID; TaskID = tran.TaskID; CostCodeID = tran.CostCodeID; RefNbr = tran.RefNbr; InventoryID = tran.InventoryID; UOM = tran.UOM; Qty = tran.Qty; DebitAmt = tran.DebitAmt; CreditAmt = tran.CreditAmt; CuryInfoID = tran.CuryInfoID; CuryDebitAmt = tran.CuryDebitAmt; CuryCreditAmt = tran.CuryCreditAmt; Released = tran.Released; Posted = tran.Posted; NonBillable = tran.NonBillable; IsInterCompany = tran.IsInterCompany; SummPost = tran.SummPost; ZeroPost = tran.ZeroPost; OrigModule = tran.OrigModule; OrigBatchNbr = tran.OrigBatchNbr; OrigLineNbr = tran.OrigLineNbr; OrigAccountID = tran.OrigAccountID; OrigSubID = tran.OrigSubID; TranID = tran.TranID; TranType = tran.TranType; TranClass = tran.TranClass; TranDesc = tran.TranDesc; TranDate = tran.TranDate; TranLineNbr = tran.TranLineNbr; ReferenceID = tran.ReferenceID; FinPeriodID = tran.FinPeriodID; TranPeriodID = tran.TranPeriodID; CATranID = tran.CATranID; PMTranID = tran.PMTranID; OrigPMTranID = tran.OrigPMTranID; LedgerBalanceType = tran.LedgerBalanceType; AccountRequireUnits = tran.AccountRequireUnits; TaxID = tran.TaxID; TaxCategoryID = tran.TaxCategoryID; NoteID = tran.NoteID; ReclassificationProhibited = tran.ReclassificationProhibited; ReclassBatchModule = tran.ReclassBatchModule; ReclassBatchNbr = tran.ReclassBatchNbr; IsReclassReverse = tran.IsReclassReverse; ReclassType = tran.ReclassType; CuryReclassRemainingAmt = tran.CuryReclassRemainingAmt; ReclassRemainingAmt = tran.ReclassRemainingAmt; Reclassified = tran.Reclassified; ReclassSourceTranModule = tran.ReclassSourceTranModule; ReclassSourceTranBatchNbr = tran.ReclassSourceTranBatchNbr; ReclassSourceTranLineNbr = tran.ReclassSourceTranLineNbr; ReclassSeqNbr = tran.ReclassSeqNbr; tstamp = tran.tstamp; CreatedByID = tran.CreatedByID; CreatedByScreenID = tran.CreatedByScreenID; CreatedDateTime = tran.CreatedDateTime; LastModifiedByID = tran.LastModifiedByID; LastModifiedByScreenID = tran.LastModifiedByScreenID; LastModifiedDateTime = tran.LastModifiedDateTime; }