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 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 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); }