protected void SafetyPersist(PXCache cache, params PXDBOperation[] operations) { if (operations.Length < 1) { return; } bool isAborted = false; try { using (PXTransactionScope tscope = new PXTransactionScope()) { foreach (PXDBOperation operation in operations) { cache.Persist(operation); } tscope.Complete(); } } catch (Exception) { isAborted = true; throw; } finally { cache.Persisted(isAborted); } }
public override void RowPersisted(PXCache sender, PXRowPersistedEventArgs e) { if (IsTopLevel && e.TranStatus != PXTranStatus.Open) { PXCache cache = sender.Graph.Caches[typeof(CurrencyInfo)]; cache.Persisted(e.TranStatus == PXTranStatus.Aborted); } base.RowPersisted(sender, e); }
public static void UpdateTaxHistorySums(PXGraph graph, RoundingManager rmanager, string taxPeriodId, int?revisionId, int?organizationID, int?branchID, Func <TaxReportLine, bool> ShowTaxReportLine = null) { if (!rmanager.IsRequireRounding) { return; } PXCache cache = graph.Caches[typeof(TaxHistory)]; using (new PXReadBranchRestrictedScope(organizationID.SingleToArray(), branchID.SingleToArrayOrNull(), requireAccessForAllSpecified: true)) { PXResultset <TaxHistory> lines = GetTaxHistoryLines(graph, rmanager.CurrentVendor.BAccountID, taxPeriodId, revisionId); if (lines.Count == 0) { return; } if (organizationID == null) { Branch branch = PXSelect <Branch, Where <Branch.branchID, Equal <Required <Branch.branchID> > > > .SelectSingleBound(graph, null, branchID); organizationID = branch?.OrganizationID; } TaxPeriod period = TaxYearMaint.GetTaxPeriodByKey(graph, organizationID, rmanager.CurrentVendor.BAccountID, taxPeriodId); Company company = PXSelect <Company> .Select(graph); PXResult <Currency, CurrencyRateByDate> curyWithRateSet = GetCurrencyAndRateByDate(graph, rmanager.CurrentVendor, company, period); Currency currency = curyWithRateSet; CurrencyRateByDate rateByDate = currency.CuryID != company.BaseCuryID ? curyWithRateSet : null; TaxBucketsCalculation taxBucketsAggregatesCalc = new TaxBucketsCalculation(TaxReportLineType.TaxAmount, graph, rmanager, currency, rateByDate, ShowTaxReportLine); TaxBucketsCalculation taxableBucketsAggregatesCalc = new TaxBucketsCalculation(TaxReportLineType.TaxableAmount, graph, rmanager, currency, rateByDate, ShowTaxReportLine); taxBucketsAggregatesCalc.CalculateTaxBuckets(lines); taxableBucketsAggregatesCalc.CalculateTaxBuckets(lines); } cache.Persist(PXDBOperation.Insert); cache.Persisted(isAborted: false); }
public static void UpdateTaxHistorySums(PXGraph graph, RoundingManager rmanager, string taxPeriodId, int?revisionId, int?branchID, Func <TaxReportLine, bool> ShowTaxReportLine = null) { if (!rmanager.IsRequireRounding) { return; } PXCache cache = graph.Caches[typeof(TaxHistory)]; using (new PXReadBranchRestrictedScope(branchID)) { PXResultset <TaxHistory> lines = GetTaxHistoryLines(graph, rmanager.CurrentVendor.BAccountID, taxPeriodId, revisionId); if (lines.Count == 0) { return; } Branch branch = BranchMaint.FindBranchByID(graph, branchID); TaxPeriod period = TaxYearMaint.GetTaxPeriodByKey(graph, branch.ParentBranchID, rmanager.CurrentVendor.BAccountID, taxPeriodId); Company company = PXSelect <Company> .Select(graph); PXResult <Currency, CurrencyRateByDate> curyWithRateSet = GetCurrencyAndRateByDate(graph, rmanager.CurrentVendor, company, period); Currency currency = curyWithRateSet; CurrencyRateByDate rateByDate = currency.CuryID != company.BaseCuryID ? curyWithRateSet : null; TaxBucketsCalculation taxBucketsAggregatesCalc = new TaxBucketsCalculation(TaxReportLineType.TaxAmount, graph, rmanager, currency, rateByDate, ShowTaxReportLine); TaxBucketsCalculation taxableBucketsAggregatesCalc = new TaxBucketsCalculation(TaxReportLineType.TaxableAmount, graph, rmanager, currency, rateByDate, ShowTaxReportLine); taxBucketsAggregatesCalc.CalculateTaxBuckets(lines); taxableBucketsAggregatesCalc.CalculateTaxBuckets(lines); } cache.Persist(PXDBOperation.Insert); cache.Persisted(isAborted: false); }
private static void Validate(CATranEntryLight te, CashAccount tlist) { using (new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { Account account = PXSelect <Account, Where <Account.isCashAccount, Equal <False>, And <Account.accountID, Equal <Required <Account.accountID> > > > > .Select(te, tlist.AccountID); if (account != null) { account.IsCashAccount = true; te.account.Update(account); te.account.Cache.Persist(PXDBOperation.Update); te.account.Cache.Persisted(false); } ts.Complete(te); } } te.Clear(); 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> >, 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> > > > .Select(te, tlist.CashAccountID)) { 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(te, 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)te.catrancache.Insert(catran); te.catrancache.PersistInserted(catran); id = Convert.ToInt64(PXDatabase.SelectIdentity()); te.SelectTimeStamp(); adjcache.SetValue <CAAdj.tranID>(caadj, id); adjcache.Update(caadj); } if (id.HasValue && gltran?.TranID != null) { gltran.CATranID = id; te.gltrancache.Update(gltran); te.gltrancache.Persist(PXDBOperation.Update); } } adjcache.Persist(PXDBOperation.Update); ts.Complete(te); } adjcache.Persisted(false); te.catrancache.Persisted(false); te.gltrancache.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()) { 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> > > > > >, OrderBy <Asc <GLTran.tranID> > > .SelectWindowed(te, 0, rowsPerCycle, tlist.AccountID, tlist.SubID, tlist.BranchID)) { GLTran gltran = (GLTran)res; lastGLTranID = gltran.TranID; noMoreTran = false; countRows++; CATran catran = GLCashTranIDAttribute.DefaultValues <GLTran.cATranID>(te.gltrancache, gltran); if (catran != null) { long id; bool newCATRan = false; if (te.catrancache.Locate(catran) == null) { catran = (CATran)te.catrancache.Insert(catran); newCATRan = true; te.catrancache.PersistInserted(catran); id = Convert.ToInt64(PXDatabase.SelectIdentity()); } else { catran = (CATran)te.catrancache.Update(catran); te.catrancache.PersistUpdated(catran); id = catran.TranID.Value; } gltran.CATranID = id; te.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(te, catran.OrigTranType, catran.OrigRefNbr); if (arPayment != null && (arPayment.CATranID == null || newCATRan)) { arPayment.CATranID = id; arPayment = (ARPayment)te.Caches[typeof(ARPayment)].Update(arPayment); te.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(te, catran.OrigTranType, catran.OrigRefNbr); if (apPayment != null && (apPayment.CATranID == null || newCATRan)) { apPayment.CATranID = id; apPayment = (APPayment)te.Caches[typeof(APPayment)].Update(apPayment); te.Caches[typeof(APPayment)].PersistUpdated(apPayment); } break; } } } } if (!noMoreTran && countRows == previousCountRows && lastGLTranID == lastGLTranIDOnPreviousStep) { throw new PXException(Messages.ProcessCannotBeCompleted); } previousCountRows = countRows; lastGLTranIDOnPreviousStep = lastGLTranID; te.gltrancache.ClearQueryCache(); te.gltrancache.Persist(PXDBOperation.Update); te.gltrancache.Clear(); te.catrancache.Clear(); te.catrancache.ClearQueryCache(); te.dailycache.Clear(); te.Caches[typeof(APPayment)].Clear(); te.Caches[typeof(ARPayment)].Clear(); ts.Complete(te); } } 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); te.gltrancache.Persisted(false); te.catrancache.Persisted(false); te.dailycache.Persisted(false); } }
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); } }
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); } }
private static void ValidateCATransfers(CATranEntryLight graph, CashAccount cashAccount, IFinPeriod period) { using (new PXConnectionScope()) { PXCache transfercache = graph.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, And <CATransfer.inDate, GreaterEqual <Required <CATransfer.inDate> > > > > > .Select(graph, cashAccount.CashAccountID, period.StartDate)) { 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)graph.catrancache.Insert(catran); graph.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, And <CATransfer.outDate, GreaterEqual <Required <CATransfer.outDate> > > > > > .Select(graph, cashAccount.CashAccountID, period.StartDate)) { 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)graph.catrancache.Insert(catran); graph.catrancache.PersistInserted(catran); long id = Convert.ToInt64(PXDatabase.SelectIdentity()); transfercache.SetValue <CATransfer.tranIDOut>(catransfer, id); transfercache.Update(catransfer); } } transfercache.Persist(PXDBOperation.Update); ts.Complete(graph); } transfercache.Persisted(false); graph.catrancache.Persisted(false); } }
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); } }