private void CheckUnpostedBatchesNotExist(GLConsolSetup glConsolSetup) { var getUnpostedBatchesQuery = new PXSelectJoin <Batch, InnerJoin <GLConsolBatch, On <Batch.batchNbr, Equal <GLConsolBatch.batchNbr> > >, Where <GLConsolBatch.setupID, Equal <Required <GLConsolBatch.setupID> >, And <Batch.posted, Equal <False>, And <Batch.module, Equal <BatchModule.moduleGL> > > > >(this); var pars = new List <object>() { glConsolSetup.SetupID }; if (glConsolSetup.StartPeriod != null) { getUnpostedBatchesQuery.WhereAnd <Where <Batch.finPeriodID, GreaterEqual <Required <Batch.finPeriodID> > > >(); pars.Add(glConsolSetup.StartPeriod); } if (glConsolSetup.EndPeriod != null) { getUnpostedBatchesQuery.WhereAnd <Where <Batch.finPeriodID, LessEqual <Required <Batch.finPeriodID> > > >(); pars.Add(glConsolSetup.EndPeriod); } var unpostedBatch = (Batch)getUnpostedBatchesQuery.Select(pars.ToArray()); if (unpostedBatch != null) { ConsolSetupRecords.Cache.RaiseExceptionHandling <GLConsolSetup.selected>(glConsolSetup, glConsolSetup.Selected, new PXSetPropertyException(Messages.UnpostedBatchesExist, PXErrorLevel.RowWarning)); } }
protected virtual void GLConsolSetup_IsActive_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { GLConsolSetup setup = (GLConsolSetup)e.Row; if (setup != null && setup.IsActive == false) { setup.Selected = false; } }
private GLConsolSetup DecryptRemoteUserPassword(GLConsolSetup item) { GLConsolSetup setup = item; var cache = Caches[typeof(GLConsolSetup)]; PXDBCryptStringAttribute.SetDecrypted<GLConsolSetup.password>(cache, true); setup.Password = cache.GetValueExt<GLConsolSetup.password>(setup).ToString(); PXDBCryptStringAttribute.SetDecrypted<GLConsolSetup.password>(cache, false); return setup; }
protected virtual void GLConsolSetup_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { GLConsolSetup setup = (GLConsolSetup)e.Row; if (!sender.ObjectsEqual <GLConsolSetup.sourceLedgerCD>(e.Row, e.OldRow)) { string oldbranchid = (string)sender.GetValue <GLConsolSetup.sourceBranchCD>(e.Row); sender.SetValue <GLConsolSetup.sourceBranchCD>(e.Row, null); sender.SetValueExt <GLConsolSetup.sourceBranchCD>(e.Row, oldbranchid); } }
protected virtual void GLConsolSetup_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { GLConsolSetup setup = (GLConsolSetup)e.Row; if (setup != null) { PXUIFieldAttribute.SetEnabled <GLConsolSetup.selected>(sender, setup, setup.IsActive == true); } GLConsolLedger coledger = PXSelect <GLConsolLedger, Where <GLConsolLedger.setupID, Equal <Current <GLConsolSetup.setupID> >, And <GLConsolLedger.ledgerCD, Equal <Current <GLConsolSetup.sourceLedgerCD> > > > > .Select(this); PXUIFieldAttribute.SetEnabled <GLConsolSetup.sourceBranchCD>(sender, e.Row, coledger != null); }
protected static void ProcessConsolidationRead(GLConsolReadMaint processor, GLConsolSetup item) { processor.Clear(); processor.listConsolRead.Clear(); int cnt = processor.ConsolidationRead(item); if (cnt > 0) { throw new PXSetPropertyException(Messages.NumberRecodsProcessed, PXErrorLevel.RowInfo, cnt); } else { throw new PXSetPropertyException(Messages.NoRecordsToProcess, PXErrorLevel.RowInfo); } }
protected virtual IImportSubaccountMapper CreateImportSubaccountMapper(GLConsolSetup glConsolSetup) { if (PXAccess.FeatureInstalled <FeaturesSet.subAccount>()) { var segments = SubaccountSegmentsView.Select().RowCast <Segment>().ToArray(); return(new ImportSubaccountMapper(segments, GLSetup.Current, glConsolSetup, subCD => SubAccountMaint.FindSubIDByCD(this, subCD), new AppLogger())); } else { return(new SubOffImportSubaccountMapper(SubAccountAttribute.TryGetDefaultSubID)); } }
public void InitSegmentData(GLConsolSetup item) { foreach (SegmentValue segValue in PXSelect <SegmentValue, Where <SegmentValue.dimensionID, Equal <Required <SegmentValue.dimensionID> > > > .Select(this, "SUBACCOUNT")) { if (!segmentValueTriple.ContainsKey(segValue.SegmentID ?? 0)) { segmentValueTriple[segValue.SegmentID ?? 0] = new Dictionary <string, string>(); } segmentValueTriple[segValue.SegmentID ?? 0][segValue.Value] = segValue.MappedSegValue; } foreach (Segment segDetail in PXSelect <Segment, Where <Segment.dimensionID, Equal <Required <Segment.dimensionID> > > > .Select(this, "SUBACCOUNT")) { segmentPairs[segDetail.SegmentID ?? 0] = segDetail.Length ?? 0; segmentNames[segDetail.SegmentID ?? 0] = segDetail.Descr; segmentNumChars[segDetail.SegmentID ?? 0] = segDetail.ConsolNumChar ?? 0; if (segDetail.Validate != true && segmentValueTriple.ContainsKey(segDetail.SegmentID ?? 0)) { segmentValueTriple.Remove(segDetail.SegmentID ?? 0); } } // Init Segment start index short consolSegmentId = GLSetup.Current.ConsolSegmentId ?? 0; int startIndex = 0; for (short segmentId = 1; segmentId < consolSegmentId; segmentId++) { startIndex += segmentPairs[segmentId]; } segmentStartIndex = startIndex; PXCache cache = this.Caches[typeof(GLConsolSetup)]; PXDBCryptStringAttribute.SetDecrypted <GLConsolSetup.password>(cache, true); if (item != null) { consolSetup = item; consolSetup.Password = cache.GetValueExt <GLConsolSetup.password>(consolSetup).ToString(); PXDBCryptStringAttribute.SetDecrypted <GLConsolSetup.password>(cache, false); segmentInsertData = consolSetup.SegmentValue; pasteFlag = consolSetup.PasteFlag ?? false; } }
protected virtual void GLConsolSetup_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { GLConsolSetup setup = (GLConsolSetup)e.Row; if (!sender.ObjectsEqual <GLConsolSetup.sourceLedgerCD>(e.Row, e.OldRow)) { string oldbranchid = (string)sender.GetValue <GLConsolSetup.sourceBranchCD>(e.Row); sender.SetValue <GLConsolSetup.sourceBranchCD>(e.Row, null); GLConsolLedger coledger = PXSelect <GLConsolLedger, Where <GLConsolLedger.setupID, Equal <Current <GLConsolSetup.setupID> >, And <GLConsolLedger.ledgerCD, Equal <Current <GLConsolSetup.sourceLedgerCD> > > > > .Select(this); if (coledger != null && coledger.PostInterCompany == true) { sender.SetValueExt <GLConsolSetup.sourceBranchCD>(e.Row, oldbranchid); } } }
public void CreateBatch(JournalEntry je, string periodId, int?ledgerID, int?branchID, GLConsolSetup item) { je.Clear(); je.glsetup.Current.RequireControlTotal = false; Ledger ledger = PXSelect <Ledger, Where <Ledger.ledgerID, Equal <Required <Ledger.ledgerID> > > > .Select(this, ledgerID); FinPeriod fiscalPeriod = PXSelect <FinPeriod, Where <FinPeriod.finPeriodID, Equal <Required <FinPeriod.finPeriodID> > > > . Select(this, periodId); if (fiscalPeriod == null) { throw new FiscalPeriodInvalidException(periodId); } je.Accessinfo.BusinessDate = fiscalPeriod.EndDate.Value.AddDays(-1); CurrencyInfo info = new CurrencyInfo(); info.CuryID = ledger.BaseCuryID; info.CuryEffDate = fiscalPeriod.EndDate.Value.AddDays(-1); info.CuryRate = (decimal)1.0; info = je.currencyinfo.Insert(info); Batch batch = new Batch(); batch.TranPeriodID = periodId; batch.BranchID = branchID; batch.LedgerID = ledgerID; batch.Module = BatchModule.GL; batch.Hold = false; batch.Released = false; batch.CuryID = ledger.BaseCuryID; batch.CuryInfoID = info.CuryInfoID; batch.FinPeriodID = periodId; batch.CuryID = ledger.BaseCuryID; batch.BatchType = BatchTypeCode.Consolidation; batch.Description = PXMessages.LocalizeFormatNoPrefix(Messages.ConsolidationBatch, item.Description); batch = je.BatchModule.Insert(batch); foreach (GLConsolRead read in listConsolRead) { Action <decimal?, decimal?> insertTransaction = (debitAmt, creditAmt) => { GLTran tran = new GLTran(); tran.AccountID = read.AccountID; tran.SubID = read.SubID; tran.CuryInfoID = info.CuryInfoID; tran.CuryCreditAmt = creditAmt; tran.CuryDebitAmt = debitAmt; tran.CreditAmt = creditAmt; tran.DebitAmt = debitAmt; tran.TranType = GLTran.tranType.Consolidation; tran.TranClass = GLTran.tranClass.Consolidation; tran.TranDate = fiscalPeriod.EndDate.Value.AddDays(-1); tran.TranDesc = Messages.ConsolidationDetail; tran.TranPeriodID = periodId; tran.RefNbr = ""; tran.ProjectID = PM.ProjectDefaultAttribute.NonProject(); tran = je.GLTranModuleBatNbr.Insert(tran); if (tran != null && tran.SubID == null && read.MappedValue != null) { je.GLTranModuleBatNbr.SetValueExt <GLTran.subID>(tran, read.MappedValue); } if (tran == null || tran.AccountID == null || tran.SubID == null) { throw new PXException(Messages.AccountOrSubNotFound, read.AccountCD, read.MappedValue); } }; if (Math.Abs((decimal)read.ConsolAmtDebit) > 0) { insertTransaction(read.ConsolAmtDebit, 0m); } if (Math.Abs((decimal)read.ConsolAmtCredit) > 0) { insertTransaction(0m, read.ConsolAmtCredit); } } item.LastPostPeriod = periodId; item.LastConsDate = DateTime.Now; je.Caches[typeof(GLConsolSetup)].Update(item); if (!je.Views.Caches.Contains(typeof(GLConsolSetup))) { je.Views.Caches.Add(typeof(GLConsolSetup)); } GLConsolBatch cb = new GLConsolBatch(); cb.SetupID = item.SetupID; je.Caches[typeof(GLConsolBatch)].Insert(cb); if (!je.Views.Caches.Contains(typeof(GLConsolBatch))) { je.Views.Caches.Add(typeof(GLConsolBatch)); } try { je.Save.Press(); } catch (PXException e) { try { if (!String.IsNullOrEmpty(PXUIFieldAttribute.GetError <Batch.curyCreditTotal>(je.BatchModule.Cache, je.BatchModule.Current)) || !String.IsNullOrEmpty(PXUIFieldAttribute.GetError <Batch.curyDebitTotal>(je.BatchModule.Cache, je.BatchModule.Current))) { je.BatchModule.Current.Hold = true; je.BatchModule.Update(je.BatchModule.Current); } je.Save.Press(); if (exception == null) { exception = new PXException(Messages.ConsolidationBatchOutOfBalance, je.BatchModule.Current.BatchNbr); } else { exception = new PXException(exception.Message + Messages.ConsolidationBatchOutOfBalance, je.BatchModule.Current.BatchNbr); } } catch { throw e; } } }
protected virtual int ConsolidationRead(GLConsolSetup item) { int cnt = 0; string aFiscalPeriod = null; int? ledgerID = item.LedgerId; int? branchID = item.BranchID; var importSubaccountCDCalculator = CreateImportSubaccountMapper(item); PXSelect <GLConsolHistory, Where <GLConsolHistory.setupID, Equal <Required <GLConsolHistory.setupID> > > > .Select(this, item.SetupID); var roundFunc = GetRoundDelegateForLedger(ledgerID); JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); if (item.BypassAccountSubValidation == true) { je.FieldVerifying.AddHandler <GLTran.accountID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); je.FieldVerifying.AddHandler <GLTran.subID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); } consolSetup = DecryptRemoteUserPassword(item); using (PXSoapScope scope = new PXSoapScope(consolSetup.Url, consolSetup.Login, consolSetup.Password)) { GLConsolReadMaint reader = PXGraph.CreateInstance <GLConsolReadMaint>(); reader.ConsolRecords.Select(item.SourceLedgerCD, item.SourceBranchCD); scope.Process(reader); int min = 0; if (!String.IsNullOrEmpty(item.StartPeriod)) { int.TryParse(item.StartPeriod, out min); } int max = 0; if (!String.IsNullOrEmpty(item.EndPeriod)) { int.TryParse(item.EndPeriod, out max); } foreach (GLConsolData row in reader.ConsolRecords.Select()) { if (min > 0 || max > 0) { if (!String.IsNullOrEmpty(row.FinPeriodID)) { int p; if (int.TryParse(row.FinPeriodID, out p)) { if (min > 0 && p < min || max > 0 && p > max) { continue; } } } } if (aFiscalPeriod == null) { aFiscalPeriod = row.FinPeriodID; } else if (aFiscalPeriod != row.FinPeriodID) { if (listConsolRead.Count > 0) { cnt += AppendRemapped(aFiscalPeriod, ledgerID, branchID, item.SetupID, roundFunc); CreateBatch(je, aFiscalPeriod, ledgerID, branchID, item); } aFiscalPeriod = row.FinPeriodID; listConsolRead.Clear(); } GLConsolRead read = new GLConsolRead(); var account = AccountMaint.FindAccountByCD(this, row.AccountCD); if (account.AccountID == GLSetup.Current.YtdNetIncAccountID) { throw new PXException(Messages.ImportingYTDNetIncomeAccountDataIsProhibited); } read.AccountCD = account.AccountCD; read.AccountID = account.AccountID; var mappedValue = GetMappedValue(row); var subKeys = importSubaccountCDCalculator.GetMappedSubaccountKeys(mappedValue); read.MappedValue = subKeys.SubCD; read.SubID = subKeys.SubID; read.FinPeriodID = row.FinPeriodID; GLConsolHistory history = new GLConsolHistory(); history.SetupID = item.SetupID; history.FinPeriodID = read.FinPeriodID; history.AccountID = read.AccountID; history.SubID = read.SubID; history.LedgerID = item.LedgerId; history.BranchID = item.BranchID; history = (GLConsolHistory)Caches[typeof(GLConsolHistory)].Locate(history); if (history != null) { read.ConsolAmtCredit = roundFunc(row.ConsolAmtCredit) - roundFunc(history.PtdCredit); read.ConsolAmtDebit = roundFunc(row.ConsolAmtDebit) - roundFunc(history.PtdDebit); history.PtdCredit = 0m; history.PtdDebit = 0m; } else { read.ConsolAmtCredit = roundFunc(row.ConsolAmtCredit); read.ConsolAmtDebit = roundFunc(row.ConsolAmtDebit); } if (read.ConsolAmtCredit != 0m || read.ConsolAmtDebit != 0m) { listConsolRead.Add(read); cnt++; } } } if (listConsolRead.Count > 0) { cnt += AppendRemapped(aFiscalPeriod, ledgerID, branchID, item.SetupID, roundFunc); CreateBatch(je, aFiscalPeriod, ledgerID, branchID, item); } if (exception != null) { PXException ex = exception; exception = null; throw ex; } return(cnt); }
protected static void Synchronize(GLConsolSetupMaint graph, GLConsolSetup consolSetup) { using (PXSoapScope scope = new PXSoapScope(consolSetup.Url, consolSetup.Login, consolSetup.Password)) { GLConsolSetupMaint foreign = PXGraph.CreateInstance <GLConsolSetupMaint>(); foreign.ConsolAccounts.Select(); foreign.Ledgers.Select(); foreign.Branches.Select(); scope.Process(foreign); PXSelect <Account> select = new PXSelect <Account>(graph); List <Account> list = new List <Account>(); foreach (Account acct in select.Select()) { list.Add(acct); } List <GLConsolLedger> listConsolLedger = new List <GLConsolLedger>(); foreach (GLConsolLedger ledger in graph.ConsolLedgers.Select(consolSetup.SetupID)) { listConsolLedger.Add(ledger); } List <GLConsolBranch> listConsolBranch = new List <GLConsolBranch>(); foreach (GLConsolBranch branch in graph.ConsolBranches.Select(consolSetup.SetupID)) { listConsolBranch.Add(branch); } foreach (GLConsolAccount consol in foreign.ConsolAccounts.Select()) { Account acct = new Account(); acct.AccountCD = consol.AccountCD; acct = select.Locate(acct); if (acct == null) { foreign.ConsolAccounts.Delete(consol); } else { list.Remove(acct); if (acct.Description != consol.Description) { consol.Description = acct.Description; foreign.ConsolAccounts.Update(consol); } } } foreach (Ledger ledger in foreign.Ledgers.Select()) { GLConsolLedger l = new GLConsolLedger(); l.SetupID = consolSetup.SetupID; l.LedgerCD = ledger.LedgerCD; l = graph.ConsolLedgers.Locate(l); if (l != null) { listConsolLedger.Remove(l); if (l.Description != ledger.Descr || l.BalanceType != ledger.BalanceType) { l.Description = ledger.Descr; l.BalanceType = ledger.BalanceType; graph.ConsolLedgers.Cache.SetStatus(l, PXEntryStatus.Updated); } } else { l = new GLConsolLedger(); l.SetupID = consolSetup.SetupID; l.LedgerCD = ledger.LedgerCD; l.Description = ledger.Descr; l.BalanceType = ledger.BalanceType; graph.ConsolLedgers.Insert(l); } } foreach (GLConsolLedger ledger in listConsolLedger) { graph.ConsolLedgers.Delete(ledger); if (consolSetup.SourceLedgerCD == ledger.LedgerCD) { consolSetup.SourceLedgerCD = null; graph.ConsolSetupRecords.Update(consolSetup); } } foreach (Branch branch in foreign.Branches.Select()) { GLConsolBranch l = new GLConsolBranch(); l.SetupID = consolSetup.SetupID; l.BranchCD = branch.BranchCD; l = graph.ConsolBranches.Locate(l); if (l != null) { listConsolBranch.Remove(l); if (l.Description != branch.AcctName || l.LedgerCD != branch.LedgerCD) { l.LedgerCD = branch.LedgerCD; l.Description = branch.AcctName; graph.ConsolBranches.Cache.SetStatus(l, PXEntryStatus.Updated); } } else { l = new GLConsolBranch(); l.SetupID = consolSetup.SetupID; l.BranchCD = branch.BranchCD; l.LedgerCD = branch.LedgerCD; l.Description = branch.AcctName; graph.ConsolBranches.Insert(l); } } foreach (GLConsolBranch branch in listConsolBranch) { graph.ConsolBranches.Delete(branch); if (consolSetup.SourceBranchCD == branch.BranchCD) { consolSetup.SourceBranchCD = null; graph.ConsolSetupRecords.Update(consolSetup); } } foreach (Account acct in list) { GLConsolAccount consol = new GLConsolAccount(); consol.AccountCD = acct.AccountCD; consol.Description = acct.Description; foreign.ConsolAccounts.Insert(consol); } scope.Process(foreign, foreign.Save); } graph.Save.Press(); }
protected Dictionary <short, string> segmentNames = new Dictionary <short, string>(); // <segmentid, segmentName> protected virtual int ConsolidationRead(GLConsolSetup item) { int cnt = 0; string aFiscalPeriod = null; int? ledgerID = item.LedgerId; int? branchID = item.BranchID; string segmentValue = item.SegmentValue; InitSegmentData(item); PXSelect <GLConsolHistory, Where <GLConsolHistory.setupID, Equal <Required <GLConsolHistory.setupID> > > > .Select(this, item.SetupID); JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); if (item.BypassAccountSubValidation == true) { je.FieldVerifying.AddHandler <GLTran.accountID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); je.FieldVerifying.AddHandler <GLTran.subID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); } using (PXSoapScope scope = new PXSoapScope(consolSetup.Url, consolSetup.Login, consolSetup.Password)) { GLConsolReadMaint reader = PXGraph.CreateInstance <GLConsolReadMaint>(); reader.ConsolRecords.Select(item.SourceLedgerCD, item.SourceBranchCD); scope.Process(reader); int min = 0; if (!String.IsNullOrEmpty(item.StartPeriod)) { int.TryParse(item.StartPeriod, out min); } int max = 0; if (!String.IsNullOrEmpty(item.EndPeriod)) { int.TryParse(item.EndPeriod, out max); } foreach (GLConsolData row in reader.ConsolRecords.Select()) { if (min > 0 || max > 0) { if (!String.IsNullOrEmpty(row.FinPeriodID)) { int p; if (int.TryParse(row.FinPeriodID, out p)) { if (min > 0 && p < min || max > 0 && p > max) { continue; } } } } if (aFiscalPeriod == null) { aFiscalPeriod = row.FinPeriodID; } else if (aFiscalPeriod != row.FinPeriodID) { if (listConsolRead.Count > 0) { cnt += AppendRemapped(aFiscalPeriod, ledgerID, branchID, item.SetupID); CreateBatch(je, aFiscalPeriod, ledgerID, branchID, item); } aFiscalPeriod = row.FinPeriodID; listConsolRead.Clear(); } GLConsolRead read = new GLConsolRead(); int? accountId = ValidateAccountCD(row.AccountCD); string subCD = GetRegeneratedSubCD(row.MappedValue); int? subId = ValidateSubCD(subCD); read.AccountCD = row.AccountCD; read.AccountID = accountId; read.MappedValue = subCD; read.SubID = subId; read.FinPeriodID = row.FinPeriodID; GLConsolHistory history = new GLConsolHistory(); history.SetupID = item.SetupID; history.FinPeriodID = read.FinPeriodID; history.AccountID = read.AccountID; history.SubID = read.SubID; history.LedgerID = item.LedgerId; history.BranchID = item.BranchID; history = (GLConsolHistory)Caches[typeof(GLConsolHistory)].Locate(history); if (history != null) { read.ConsolAmtCredit = (row.ConsolAmtCredit - history.PtdCredit); read.ConsolAmtDebit = (row.ConsolAmtDebit - history.PtdDebit); history.PtdCredit = 0m; history.PtdDebit = 0m; } else { read.ConsolAmtCredit = row.ConsolAmtCredit; read.ConsolAmtDebit = row.ConsolAmtDebit; } if (read.ConsolAmtCredit != 0m || read.ConsolAmtDebit != 0m) { listConsolRead.Add(read); cnt++; } } } if (listConsolRead.Count > 0) { cnt += AppendRemapped(aFiscalPeriod, ledgerID, branchID, item.SetupID); CreateBatch(je, aFiscalPeriod, ledgerID, branchID, item); } if (exception != null) { PXException ex = exception; exception = null; throw ex; } return(cnt); }