コード例 #1
0
        protected virtual void Ledger_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            Ledger ledger = e.Row as Ledger;

            if (ledger != null && ledger.LedgerID.HasValue)
            {
                //Type and Currency are forbidden for changses for the used accounts
                bool hasHistory = GLUtility.IsLedgerHistoryExist(this, ledger.LedgerID);
                PXUIFieldAttribute.SetEnabled <Ledger.balanceType>(LedgerRecords.Cache, ledger, !hasHistory);
                PXUIFieldAttribute.SetEnabled <Ledger.baseCuryID>(LedgerRecords.Cache, ledger, !hasHistory && PXAccess.FeatureInstalled <FeaturesSet.multicurrency>());
            }

            if (ledger != null)
            {
                PXUIFieldAttribute.SetEnabled <Ledger.postInterCompany>(cache, e.Row, ledger.BalanceType == LedgerBalanceType.Actual && ledger.DefBranchID != null);
                PXUIFieldAttribute.SetEnabled <Ledger.defBranchID>(cache, e.Row, ledger.BalanceType == LedgerBalanceType.Actual);

                if (ledger.BalanceType == LedgerBalanceType.Actual && ledger.DefBranchID != null)
                {
                    using (new PXReadBranchRestrictedScope())
                    {
                        GLHistory hist = PXSelectReadonly <GLHistory, Where <GLHistory.ledgerID, Equal <Current <Ledger.ledgerID> >, And <GLHistory.branchID, Equal <Current <Ledger.defBranchID> > > > > .SelectWindowed(this, 0, 1);

                        PXResultset <GLHistory> hist2 = PXSelectGroupBy <GLHistory, Where <GLHistory.ledgerID, Equal <Current <Ledger.ledgerID> > >, Aggregate <GroupBy <GLHistory.branchID> > > .Select(this);

                        PXUIFieldAttribute.SetEnabled <Ledger.postInterCompany>(cache, e.Row, (hist2.Count <= 1));
                        PXUIFieldAttribute.SetEnabled <Ledger.defBranchID>(cache, e.Row, (hist == null));
                    }
                }
            }
        }
        public virtual void Branch_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            using (new PXReadBranchRestrictedScope())
            {
                GLHistory hist = PXSelectReadonly <GLHistory, Where <GLHistory.ledgerID, Equal <Current <Branch.ledgerID> >, And <GLHistory.branchID, Equal <Current <Branch.branchID> > > > > .SelectWindowed(this, 0, 1);

                PXUIFieldAttribute.SetEnabled <Branch.ledgerID>(sender, e.Row, (hist == null));
            }
        }
コード例 #3
0
        public static bool RelatedForOrganizationGLHistoryExists(PXGraph graph, int?organizationID)
        {
            GLHistory history = PXSelectReadonly2 <GLHistory,
                                                   InnerJoin <Branch,
                                                              On <GLHistory.branchID, Equal <Branch.branchID> > >,
                                                   Where <Branch.organizationID, Equal <Required <Branch.organizationID> > > >
                                .SelectSingleBound(graph, null, organizationID);

            return(history != null);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        protected virtual IEnumerable enqResult()
        {
            AccountByYearFilter filter = this.CurrentFilter;
            bool showCurrency          = filter.ShowCuryDetail.HasValue && filter.ShowCuryDetail.Value;

            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyID>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyPtdCreditTotal>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyPtdDebitTotal>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyBegBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyEndBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.signCuryBegBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.signCuryEndBalance>(EnqResult.Cache, null, showCurrency);

            if (filter.AccountID == null || filter.LedgerID == null || filter.FinYear == null)
            {
                yield break;                 //Prevent code from accessing database;
            }

            PXSelectBase <GLHistoryByPeriod> cmd = new PXSelectJoinGroupBy <GLHistoryByPeriod,
                                                                            InnerJoin <Account,
                                                                                       On <GLHistoryByPeriod.accountID, Equal <Account.accountID>, And <Match <Account, Current <AccessInfo.userName> > > >,
                                                                                       InnerJoin <FinPeriod,
                                                                                                  On <GLHistoryByPeriod.finPeriodID, Equal <FinPeriod.finPeriodID> >,
                                                                                                  InnerJoin <Sub,
                                                                                                             On <GLHistoryByPeriod.subID, Equal <Sub.subID>, And <Match <Sub, Current <AccessInfo.userName> > > >,
                                                                                                             LeftJoin <GLHistory, On <GLHistoryByPeriod.accountID, Equal <GLHistory.accountID>,
                                                                                                                                      And <GLHistoryByPeriod.subID, Equal <GLHistory.subID>,
                                                                                                                                           And <GLHistoryByPeriod.branchID, Equal <GLHistory.branchID>,
                                                                                                                                                And <GLHistoryByPeriod.ledgerID, Equal <GLHistory.ledgerID>,
                                                                                                                                                     And <GLHistoryByPeriod.finPeriodID, Equal <GLHistory.finPeriodID> > > > > >,
                                                                                                                       LeftJoin <AH, On <GLHistoryByPeriod.ledgerID, Equal <AH.ledgerID>,
                                                                                                                                         And <GLHistoryByPeriod.branchID, Equal <AH.branchID>,
                                                                                                                                              And <GLHistoryByPeriod.accountID, Equal <AH.accountID>,
                                                                                                                                                   And <GLHistoryByPeriod.subID, Equal <AH.subID>,
                                                                                                                                                        And <GLHistoryByPeriod.lastActivityPeriod, Equal <AH.finPeriodID> > > > > > > > > > >,
                                                                            Where <GLHistoryByPeriod.ledgerID, Equal <Current <AccountByYearFilter.ledgerID> >,
                                                                                   And <FinPeriod.finYear, Equal <Current <AccountByYearFilter.finYear> >,
                                                                                        And <GLHistoryByPeriod.accountID, Equal <Current <AccountByYearFilter.accountID> >,
                                                                                             And <
                                                                                                 Where2 <
                                                                                                     Where <Account.accountID, NotEqual <Current <GLSetup.ytdNetIncAccountID> >, And <Where <Account.type, Equal <AccountType.asset>,
                                                                                                                                                                                             Or <Account.type, Equal <AccountType.liability> > > > >,
                                                                                                     Or <
                                                                                                         Where <GLHistoryByPeriod.lastActivityPeriod, GreaterEqual <Required <GLHistoryByPeriod.lastActivityPeriod> >,
                                                                                                                And <Where <Account.type, Equal <AccountType.expense>,
                                                                                                                            Or <Account.type, Equal <AccountType.income>,
                                                                                                                                Or <Account.accountID, Equal <Current <GLSetup.ytdNetIncAccountID> > > > > > > > > > > > >,
                                                                            Aggregate <
                                                                                Sum <AH.finYtdBalance,
                                                                                     Sum <AH.curyFinYtdBalance,
                                                                                          Sum <GLHistory.finPtdDebit,
                                                                                               Sum <GLHistory.finPtdCredit,
                                                                                                    Sum <GLHistory.finBegBalance,
                                                                                                         Sum <GLHistory.finYtdBalance,
                                                                                                              Sum <GLHistory.curyFinBegBalance,
                                                                                                                   Sum <GLHistory.curyFinYtdBalance,
                                                                                                                        Sum <GLHistory.curyFinPtdCredit,
                                                                                                                             Sum <GLHistory.curyFinPtdDebit,
                                                                                                                                  GroupBy <GLHistoryByPeriod.ledgerID,
                                                                                                                                           GroupBy <GLHistoryByPeriod.accountID,
                                                                                                                                                    GroupBy <GLHistoryByPeriod.finPeriodID
                                                                                                                                                             > > > > > > > > > > > > > > >(this);

            if (filter.SubID != null)
            {
                cmd.WhereAnd <Where <GLHistoryByPeriod.subID, Equal <Current <AccountByYearFilter.subID> > > >();
            }

            if (filter.BranchID != null)
            {
                cmd.WhereAnd <Where <GLHistoryByPeriod.branchID, Equal <Current <AccountByYearFilter.branchID> > > >();
            }

            if (!SubCDUtils.IsSubCDEmpty(filter.SubCD))
            {
                cmd.WhereAnd <Where <Sub.subCD, Like <Current <AccountByYearFilter.subCDWildcard> > > >();
            }

            string  yearBegPeriod = filter.BegFinPeriod;
            GLSetup glSetup       = glsetup.Current;
            bool    reverseSign   = (glSetup != null) && (glSetup.TrialBalanceSign == GLSetup.trialBalanceSign.Reversed);

            foreach (PXResult <GLHistoryByPeriod, Account, FinPeriod, Sub, GLHistory, AH> it in cmd.Select(yearBegPeriod))
            {
                GLHistoryByPeriod baseview = (GLHistoryByPeriod)it;
                Account           acct     = (Account)it;
                GLHistory         ah       = (GLHistory)it;
                AH ah1 = (AH)it;

                if (reverseSign && acct.AccountID == glSetup.YtdNetIncAccountID)
                {
                    continue;
                }

                GLHistoryEnquiryResult item = new GLHistoryEnquiryResult();
                item.AccountID          = baseview.AccountID;
                item.LedgerID           = baseview.LedgerID;
                item.LastActivityPeriod = baseview.FinPeriodID;
                item.PtdCreditTotal     = ah.FinPtdCredit;
                item.PtdDebitTotal      = ah.FinPtdDebit;
                item.CuryID             = ah1.CuryID;
                item.Type       = acct.Type;
                item.EndBalance = ah1.FinYtdBalance;
                if (!string.IsNullOrEmpty(ah1.CuryID))
                {
                    item.CuryEndBalance     = ah1.CuryFinYtdBalance;                         //
                    item.CuryPtdCreditTotal = ah.CuryFinPtdCredit;
                    item.CuryPtdDebitTotal  = ah.CuryFinPtdDebit;
                }
                else
                {
                    item.CuryEndBalance     = null;
                    item.CuryPtdCreditTotal = null;
                    item.CuryPtdDebitTotal  = null;
                }
                item.recalculate(true);                         // End balance is considered as correct digit - so we need to calculate begBalance base on ending one
                item.recalculateSignAmount(reverseSign);
                yield return(item);
            }
        }
コード例 #6
0
        protected virtual IEnumerable enqResult()
        {
            GLHistoryEnqFilter filter = CurrentFilter;
            bool showCurrency         = filter.ShowCuryDetail == true;

            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyID>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyPtdCreditTotal>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyPtdDebitTotal>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyBegBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyEndBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.signCuryBegBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.signCuryEndBalance>(EnqResult.Cache, null, showCurrency);

            if (filter.AccountID == null || filter.LedgerID == null || filter.FinPeriodID == null)
            {
                yield break;                                                                                    //Prevent code from accessing database;
            }
            PXSelectBase <GLHistoryByPeriod> cmd = new PXSelectJoinGroupBy <GLHistoryByPeriod,
                                                                            InnerJoin <Account,
                                                                                       On <GLHistoryByPeriod.accountID, Equal <Account.accountID>, And <Match <Account, Current <AccessInfo.userName> > > >,
                                                                                       InnerJoin <Sub,
                                                                                                  On <GLHistoryByPeriod.subID, Equal <Sub.subID>, And <Match <Sub, Current <AccessInfo.userName> > > >,
                                                                                                  LeftJoin <GLHistory, On <GLHistoryByPeriod.accountID, Equal <GLHistory.accountID>,
                                                                                                                           And <GLHistoryByPeriod.ledgerID, Equal <GLHistory.ledgerID>,
                                                                                                                                And <GLHistoryByPeriod.branchID, Equal <GLHistory.branchID>,
                                                                                                                                     And <GLHistoryByPeriod.subID, Equal <GLHistory.subID>,
                                                                                                                                          And <GLHistoryByPeriod.finPeriodID, Equal <GLHistory.finPeriodID> > > > > >,
                                                                                                            LeftJoin <AH, On <GLHistoryByPeriod.ledgerID, Equal <AH.ledgerID>,
                                                                                                                              And <GLHistoryByPeriod.branchID, Equal <AH.branchID>,
                                                                                                                                   And <GLHistoryByPeriod.accountID, Equal <AH.accountID>,
                                                                                                                                        And <GLHistoryByPeriod.subID, Equal <AH.subID>,
                                                                                                                                             And <GLHistoryByPeriod.lastActivityPeriod, Equal <AH.finPeriodID> > > > > > > > > >,
                                                                            Where <GLHistoryByPeriod.ledgerID, Equal <Current <GLHistoryEnqFilter.ledgerID> >,
                                                                                   And <GLHistoryByPeriod.accountID, Equal <Current <GLHistoryEnqFilter.accountID> >,
                                                                                        And <GLHistoryByPeriod.finPeriodID, Equal <Current <GLHistoryEnqFilter.finPeriodID> >,
                                                                                             And <
                                                                                                 Where2 <
                                                                                                     Where <Account.accountID, NotEqual <Current <GLSetup.ytdNetIncAccountID> >, And <Where <Account.type, Equal <AccountType.asset>,
                                                                                                                                                                                             Or <Account.type, Equal <AccountType.liability> > > > >,
                                                                                                     Or <Where <GLHistoryByPeriod.lastActivityPeriod, GreaterEqual <Required <GLHistoryByPeriod.lastActivityPeriod> >,
                                                                                                                And <Where <Account.type, Equal <AccountType.expense>,
                                                                                                                            Or <Account.type, Equal <AccountType.income>,
                                                                                                                                Or <Account.accountID, Equal <Current <GLSetup.ytdNetIncAccountID> > > > > > > > > > > > >,
                                                                            Aggregate <
                                                                                Sum <AH.finYtdBalance,
                                                                                     Sum <AH.curyFinYtdBalance,
                                                                                          Sum <GLHistory.finPtdDebit,
                                                                                               Sum <GLHistory.finPtdCredit,
                                                                                                    Sum <GLHistory.finBegBalance,
                                                                                                         Sum <GLHistory.finYtdBalance,
                                                                                                              Sum <GLHistory.curyFinBegBalance,
                                                                                                                   Sum <GLHistory.curyFinYtdBalance,
                                                                                                                        Sum <GLHistory.curyFinPtdCredit,
                                                                                                                             Sum <GLHistory.curyFinPtdDebit,
                                                                                                                                  GroupBy <GLHistoryByPeriod.ledgerID,
                                                                                                                                           GroupBy <GLHistoryByPeriod.accountID,
                                                                                                                                                    GroupBy <GLHistoryByPeriod.subID> > > > > > > > > > > > > > >(this);

            int[] branchIDs = null;

            if (filter.BranchID != null)
            {
                cmd.WhereAnd <Where <GLHistoryByPeriod.branchID, Equal <Current <GLHistoryEnqFilter.branchID> > > >();
            }
            else if (filter.OrganizationID != null)
            {
                branchIDs = PXAccess.GetChildBranchIDs(filter.OrganizationID);

                cmd.WhereAnd <Where <GLHistoryByPeriod.branchID, In <Required <GLHistoryEnqFilter.branchID> > > >();
            }

            if (!SubCDUtils.IsSubCDEmpty(filter.SubCD))
            {
                cmd.WhereAnd <Where <Sub.subCD, Like <Current <GLHistoryEnqFilter.subCDWildcard> > > >();
            }

            foreach (PXResult <GLHistoryByPeriod, Account, Sub, GLHistory, AH> it in cmd.Select(filter.BegFinPeriod, branchIDs))
            {
                GLHistoryByPeriod baseview = it;
                Account           acct     = it;
                GLHistory         ah       = it;
                AH ah1 = it;

                GLHistoryEnquiryResult item = new GLHistoryEnquiryResult
                {
                    AccountID          = baseview.AccountID,
                    AccountCD          = acct.AccountCD,
                    LedgerID           = baseview.LedgerID,
                    Type               = acct.Type,
                    Description        = acct.Description,
                    LastActivityPeriod = baseview.LastActivityPeriod,
                    PtdCreditTotal     = ah.FinPtdCredit,
                    PtdDebitTotal      = ah.FinPtdDebit,
                    CuryID             = ah1.CuryID,
                    SubCD              = ((Sub)it).SubCD,
                    EndBalance         = ah1.FinYtdBalance
                };
                if (!string.IsNullOrEmpty(ah1.CuryID))
                {
                    item.CuryEndBalance     = ah1.CuryFinYtdBalance;
                    item.CuryPtdCreditTotal = ah.CuryFinPtdCredit;
                    item.CuryPtdDebitTotal  = ah.CuryFinPtdDebit;
                }
                else
                {
                    item.CuryEndBalance     = null;
                    item.CuryPtdCreditTotal = null;
                    item.CuryPtdDebitTotal  = null;
                }
                item.recalculate(true);                 // End balance is considered as correct digit - so we need to calculate begBalance base on ending one
                item.recalculateSignAmount(glsetup.Current?.TrialBalanceSign == GLSetup.trialBalanceSign.Reversed);
                yield return(item);
            }
        }
コード例 #7
0
        protected virtual IEnumerable enqResult()
        {
            GLHistoryEnqFilter filter = (GLHistoryEnqFilter)this.Filter.Current;
            bool showCurrency         = filter.ShowCuryDetail.HasValue && filter.ShowCuryDetail.Value;

            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyID>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyPtdCreditTotal>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyPtdDebitTotal>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyBegBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.curyEndBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.signCuryBegBalance>(EnqResult.Cache, null, showCurrency);
            PXUIFieldAttribute.SetVisible <GLHistoryEnquiryResult.signCuryEndBalance>(EnqResult.Cache, null, showCurrency);
            if (filter.LedgerID == null || filter.FinPeriodID == null)
            {
                yield break;                 //Prevent code from accessing database;
            }
            #region cmd
            PXSelectBase <GLHistoryByPeriod> cmd = new PXSelectJoinGroupBy <GLHistoryByPeriod,
                                                                            InnerJoin <Account,
                                                                                       On <GLHistoryByPeriod.accountID, Equal <Account.accountID>, And <Match <Account, Current <AccessInfo.userName> > > >,
                                                                                       InnerJoin <Sub,
                                                                                                  On <GLHistoryByPeriod.subID, Equal <Sub.subID>, And <Match <Sub, Current <AccessInfo.userName> > > >,
                                                                                                  LeftJoin <GLHistory, On <GLHistoryByPeriod.accountID, Equal <GLHistory.accountID>,
                                                                                                                           And <GLHistoryByPeriod.ledgerID, Equal <GLHistory.ledgerID>,
                                                                                                                                And <GLHistoryByPeriod.branchID, Equal <GLHistory.branchID>,
                                                                                                                                     And <GLHistoryByPeriod.subID, Equal <GLHistory.subID>,
                                                                                                                                          And <GLHistoryByPeriod.finPeriodID, Equal <GLHistory.finPeriodID> > > > > >,
                                                                                                            LeftJoin <AH, On <GLHistoryByPeriod.ledgerID, Equal <AH.ledgerID>,
                                                                                                                              And <GLHistoryByPeriod.branchID, Equal <AH.branchID>,
                                                                                                                                   And <GLHistoryByPeriod.accountID, Equal <AH.accountID>,
                                                                                                                                        And <GLHistoryByPeriod.subID, Equal <AH.subID>,
                                                                                                                                             And <GLHistoryByPeriod.lastActivityPeriod, Equal <AH.finPeriodID> > > > > > > > > >,
                                                                            Where <GLHistoryByPeriod.ledgerID, Equal <Current <GLHistoryEnqFilter.ledgerID> >,
                                                                                   And <GLHistoryByPeriod.finPeriodID, Equal <Current <GLHistoryEnqFilter.finPeriodID> >,
                                                                                        And <
                                                                                            Where2 <
                                                                                                Where <Account.accountID, NotEqual <Current <GLSetup.ytdNetIncAccountID> >, And <Where <Account.type, Equal <AccountType.asset>,
                                                                                                                                                                                        Or <Account.type, Equal <AccountType.liability> > > > >,
                                                                                                Or <Where <GLHistoryByPeriod.lastActivityPeriod, GreaterEqual <Required <GLHistoryByPeriod.lastActivityPeriod> >,
                                                                                                           And <Where <Account.type, Equal <AccountType.expense>,
                                                                                                                       Or <Account.type, Equal <AccountType.income>,
                                                                                                                           Or <Account.accountID, Equal <Current <GLSetup.ytdNetIncAccountID> > > > > > > > > > > >,
                                                                            Aggregate <
                                                                                Sum <AH.finYtdBalance,
                                                                                     Sum <AH.tranYtdBalance,
                                                                                          Sum <AH.curyFinYtdBalance,
                                                                                               Sum <AH.curyTranYtdBalance,
                                                                                                    Sum <GLHistory.finPtdDebit,
                                                                                                         Sum <GLHistory.tranPtdDebit,
                                                                                                              Sum <GLHistory.finPtdCredit,
                                                                                                                   Sum <GLHistory.tranPtdCredit,
                                                                                                                        Sum <GLHistory.finBegBalance,
                                                                                                                             Sum <GLHistory.tranBegBalance,
                                                                                                                                  Sum <GLHistory.finYtdBalance,
                                                                                                                                       Sum <GLHistory.tranYtdBalance,
                                                                                                                                            Sum <GLHistory.curyFinBegBalance,
                                                                                                                                                 Sum <GLHistory.curyTranBegBalance,
                                                                                                                                                      Sum <GLHistory.curyFinYtdBalance,
                                                                                                                                                           Sum <GLHistory.curyTranYtdBalance,
                                                                                                                                                                Sum <GLHistory.curyFinPtdCredit,
                                                                                                                                                                     Sum <GLHistory.curyTranPtdCredit,
                                                                                                                                                                          Sum <GLHistory.curyFinPtdDebit,
                                                                                                                                                                               Sum <GLHistory.curyTranPtdDebit,
                                                                                                                                                                                    GroupBy <GLHistoryByPeriod.branchID,
                                                                                                                                                                                             GroupBy <GLHistoryByPeriod.ledgerID,
                                                                                                                                                                                                      GroupBy <GLHistoryByPeriod.accountID,
                                                                                                                                                                                                               GroupBy <GLHistoryByPeriod.finPeriodID
                                                                                                                                                                                                                        > > > > > > > > > > > > > > > > > > > > > > > > > >(this);

            if (filter.LedgerID != null)
            {
                Ledger ledger = (Ledger)PXSelectorAttribute.Select <GLHistoryEnqFilter.ledgerID>(Filter.Cache, filter);
                if (ledger?.BalanceType == LedgerBalanceType.Budget)
                {
                    // we shouldn't select history from the previous years for the budget ledgers
                    cmd.WhereAnd <Where <Substring <GLHistoryByPeriod.finPeriodID, int1, int4>, Equal <Substring <GLHistoryByPeriod.lastActivityPeriod, int1, int4> > > >();
                }
            }
            if (filter.AccountID != null)
            {
                cmd.WhereAnd <Where <GLHistoryByPeriod.accountID, Equal <Current <GLHistoryEnqFilter.accountID> > > >();
            }
            if (filter.AccountClassID != null)
            {
                cmd.WhereAnd <Where <Account.accountClassID, Equal <Current <GLHistoryEnqFilter.accountClassID> > > >();
            }

            if (filter.SubID != null)
            {
                cmd.WhereAnd <Where <GLHistoryByPeriod.subID, Equal <Current <GLHistoryEnqFilter.subID> > > >();
            }

            int[] branchIDs = null;

            if (filter.BranchID != null)
            {
                cmd.WhereAnd <Where <GLHistoryByPeriod.branchID, Equal <Current <GLHistoryEnqFilter.branchID> > > >();
            }
            else if (filter.OrganizationID != null)
            {
                branchIDs = PXAccess.GetChildBranchIDs(filter.OrganizationID, false);

                cmd.WhereAnd <Where <GLHistoryByPeriod.branchID, In <Required <GLHistoryEnqFilter.branchID> >,
                                     And <MatchWithBranch <GLHistoryByPeriod.branchID> > > >();
            }

            if (!SubCDUtils.IsSubCDEmpty(filter.SubCD))
            {
                cmd.WhereAnd <Where <Sub.subCD, Like <Current <GLHistoryEnqFilter.subCDWildcard> > > >();
            }
            //cmd.WhereAnd<Where<Match<Current<AccessInfo.userName>>>>();
            #endregion
            string  yearBegPeriod = filter.BegFinPeriod;
            GLSetup glSetup       = glsetup.Current;
            bool    reverseSign   = (glSetup != null) && (glSetup.TrialBalanceSign == GLSetup.trialBalanceSign.Reversed);
            foreach (PXResult <GLHistoryByPeriod, Account, Sub, GLHistory, AH> it in cmd.Select(yearBegPeriod, branchIDs))
            {
                GLHistoryByPeriod baseview = (GLHistoryByPeriod)it;
                Account           acct     = (Account)it;
                GLHistory         ah       = (GLHistory)it;
                AH ah1 = (AH)it;
                ah.FinFlag  = filter.UseMasterCalendar != true;
                ah1.FinFlag = filter.UseMasterCalendar != true;

                if (reverseSign && acct.AccountID == glSetup.YtdNetIncAccountID)
                {
                    continue;
                }

                GLHistoryEnquiryResult item = new GLHistoryEnquiryResult();
                item.BranchID           = baseview.BranchID;
                item.LedgerID           = baseview.LedgerID;
                item.AccountID          = baseview.AccountID;
                item.AccountCD          = acct.AccountCD;
                item.Type               = acct.Type;
                item.Description        = acct.Description;
                item.LastActivityPeriod = baseview.LastActivityPeriod;
                item.PtdCreditTotal     = ah.PtdCredit ?? 0m;
                item.PtdDebitTotal      = ah.PtdDebit ?? 0m;
                item.EndBalance         = ah1.YtdBalance ?? 0m;
                item.ConsolAccountCD    = acct.GLConsolAccountCD;
                item.AccountClassID     = acct.AccountClassID;
                if (!(string.IsNullOrEmpty(ah.CuryID) && string.IsNullOrEmpty(ah1.CuryID)))
                {
                    item.CuryEndBalance     = ah1.CuryYtdBalance ?? 0m;
                    item.CuryPtdCreditTotal = ah.CuryPtdCredit ?? 0m;
                    item.CuryPtdDebitTotal  = ah.CuryPtdDebit ?? 0m;
                    item.CuryID             = string.IsNullOrEmpty(ah.CuryID) ? ah1.CuryID : ah.CuryID;
                }
                else
                {
                    item.CuryEndBalance     = null;
                    item.CuryPtdCreditTotal = null;
                    item.CuryPtdDebitTotal  = null;
                    item.CuryID             = null;
                }

                item.recalculate(true);                 // End balance is considered as correct digit - so we need to calculate begBalance base on ending one
                item.recalculateSignAmount(reverseSign);
                yield return(item);
            }
        }
コード例 #8
0
        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);
        }