protected virtual IEnumerable consolRecords( [PXDBString] string ledgerCD, [PXDBString] string branchCD ) { Ledger ledger = PXSelect <Ledger, Where <Ledger.consolAllowed, Equal <True>, And <Ledger.ledgerCD, Equal <Required <Ledger.ledgerCD> > > > > .Select(this, ledgerCD); Branch branch = PXSelect <Branch, Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > > .Select(this, branchCD); if (ledger == null) { throw new PXException(Messages.CantFindConsolidationLedger, ledgerCD); } if (!string.IsNullOrEmpty(branchCD) && branch == null) { throw new PXException(Messages.CantFindConsolidationBranch, branchCD); } var exportSubaccountMapper = CreateExportSubaccountMapper(); var noSegmentsToExport = false; if (PXAccess.FeatureInstalled <FeaturesSet.subAccount>()) { noSegmentsToExport = SubaccountSegmentsView.Select() .RowCast <Segment>() .All(segment => segment.ConsolNumChar <= 0); } PXSelectBase <GLHistory> cmd = new PXSelectJoin <GLHistory, InnerJoin <Account, On <Account.accountID, Equal <GLHistory.accountID> >, InnerJoin <Sub, On <Sub.subID, Equal <GLHistory.subID> >, InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLHistory.ledgerID> >, InnerJoin <Branch, On <Branch.branchID, Equal <GLHistory.branchID> > > > > >, Where <Ledger.ledgerCD, Equal <Required <Ledger.ledgerCD> >, And <GLHistory.accountID, NotEqual <Current <GLSetup.ytdNetIncAccountID> > > >, OrderBy <Asc <GLHistory.finPeriodID, Asc <Account.accountCD, Asc <Sub.subCD> > > > >(this); if (!string.IsNullOrEmpty(branchCD)) { cmd.WhereAnd <Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > >(); } foreach (PXResult <GLHistory, Account, Sub> result in cmd.Select(ledgerCD, branchCD)) { GLHistory history = result; Account account = result; Sub sub = result; string accountCD = account.GLConsolAccountCD; string subCD = exportSubaccountMapper.GetMappedSubaccountCD(sub); if (accountCD != null && accountCD.TrimEnd() != "" && (subCD != null && subCD.TrimEnd() != "" || noSegmentsToExport)) { GLConsolData consolData = new GLConsolData(); consolData.MappedValue = subCD; consolData.AccountCD = accountCD; consolData.FinPeriodID = history.FinPeriodID; consolData = ConsolRecords.Locate(consolData); if (consolData != null) { consolData.ConsolAmtDebit += history.FinPtdDebit; consolData.ConsolAmtCredit += history.FinPtdCredit; } else { consolData = new GLConsolData(); consolData.MappedValue = subCD; consolData.MappedValueLength = subCD.Length; consolData.AccountCD = accountCD; consolData.FinPeriodID = history.FinPeriodID; consolData.ConsolAmtDebit = history.FinPtdDebit; consolData.ConsolAmtCredit = history.FinPtdCredit; ConsolRecords.Insert(consolData); } } } return(ConsolRecords.Cache.Inserted); }
private string GetMappedValue(GLConsolData data) { return(data.MappedValue.PadRight(data.MappedValueLength.Value, ' ')); }
protected virtual IEnumerable consolRecords( [PXDBString] string ledgerCD, [PXDBString] string branchCD ) { Ledger ledger = PXSelect <Ledger, Where <Ledger.consolAllowed, Equal <boolTrue>, And <Ledger.ledgerCD, Equal <Required <Ledger.ledgerCD> > > > > .Select(this, ledgerCD); Branch branch = PXSelect <Branch, Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > > .Select(this, branchCD); if (ledger == null) { throw new PXException(Messages.CantFindConsolidationLedger, ledgerCD); } if (!string.IsNullOrEmpty(branchCD) && branch == null) { throw new PXException(Messages.CantFindConsolidationBranch, branchCD); } if (true) { InitSegmentData(null); PXSelectBase <GLHistory> cmd = new PXSelectJoin <GLHistory, InnerJoin <Account, On <Account.accountID, Equal <GLHistory.accountID> >, InnerJoin <Sub, On <Sub.subID, Equal <GLHistory.subID> >, InnerJoin <Ledger, On <Ledger.ledgerID, Equal <GLHistory.ledgerID> >, InnerJoin <Branch, On <Branch.branchID, Equal <GLHistory.branchID> > > > > >, Where <Ledger.ledgerCD, Equal <Required <Ledger.ledgerCD> >, And <GLHistory.accountID, NotEqual <Current <GLSetup.ytdNetIncAccountID> > > >, OrderBy <Asc <GLHistory.finPeriodID, Asc <Account.accountCD, Asc <Sub.subCD> > > > >(this); if (!string.IsNullOrEmpty(branchCD)) { cmd.WhereAnd <Where <Branch.branchCD, Equal <Required <Branch.branchCD> > > >(); } foreach (PXResult <GLHistory, Account, Sub> result in cmd.Select(ledgerCD, branchCD)) { GLHistory history = result; Account account = result; Sub sub = result; string accountCD = account.GLConsolAccountCD; string subCD = GetMappedValue(sub.SubCD); if (accountCD != null && accountCD.TrimEnd() != "" && subCD != null && subCD.TrimEnd() != "") { GLConsolData consolData = new GLConsolData(); consolData.MappedValue = subCD; consolData.AccountCD = accountCD; consolData.FinPeriodID = history.FinPeriodID; consolData = ConsolRecords.Locate(consolData); if (consolData != null) { consolData.ConsolAmtDebit += history.FinPtdDebit; consolData.ConsolAmtCredit += history.FinPtdCredit; } else { consolData = new GLConsolData(); consolData.MappedValue = subCD; consolData.AccountCD = accountCD; consolData.FinPeriodID = history.FinPeriodID; consolData.ConsolAmtDebit = history.FinPtdDebit; consolData.ConsolAmtCredit = history.FinPtdCredit; ConsolRecords.Insert(consolData); } } } } return(ConsolRecords.Cache.Inserted); }