Example #1
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);
        }
Example #2
0
        public virtual IEnumerable preload(PXAdapter adapter)
        {
            if (PreloadFilter.Current.FromAccount == null)
            {
                PreloadFilter.Cache.RaiseExceptionHandling <AccountsPreloadFilter.fromAccount>(PreloadFilter.Current, PreloadFilter.Current.FromAccount, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXErrorLevel.RowError));
                PreloadFilter.Cache.RaiseExceptionHandling <AccountsPreloadFilter.toAccount>(PreloadFilter.Current, PreloadFilter.Current.ToAccount, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXErrorLevel.RowError));
                return(adapter.Get());
            }
            GLBudgetTree currentItem = ((GLBudgetTree)PXSelect <GLBudgetTree,
                                                                Where <GLBudgetTree.groupID,
                                                                       Equal <Required <GLBudgetTree.groupID> > > > .Select(this, this.CurrentSelected.Group));

            PreloadFilter.Current.AccountCDWildcard = SubCDUtils.CreateSubCDWildcard(currentItem != null ? currentItem.AccountMask : string.Empty, AccountAttribute.DimensionName);

            GLBudgetTree LastItem = PXSelect <GLBudgetTree,
                                              Where <GLBudgetTree.parentGroupID,
                                                     Equal <Required <GLBudgetTree.parentGroupID> > >, OrderBy <Desc <GLBudgetTree.sortOrder> > > .SelectWindowed(this, 0, 1, this.CurrentSelected.Group);

            int  LastSortNum                  = LastItem == null ? 1 : LastItem.SortOrder.Value + 1;
            bool noLinesPreloaded             = true;
            List <GLBudgetTree> nodesToInsert = new List <GLBudgetTree>();

            foreach (PXResult <Account> account in PXSelect <Account, Where <Account.accountCD,
                                                                             GreaterEqual <Required <Account.accountCD> >,
                                                                             And <Account.active, Equal <True>,
                                                                                  And <Account.accountCD, LessEqual <Required <Account.accountCD> >,
                                                                                       And <Account.accountID, NotEqual <Current <GL.GLSetup.ytdNetIncAccountID> > > > > > > .Select(this,
                                                                                                                                                                                     PreloadFilter.Current.FromAccount != null ?
                                                                                                                                                                                     ((Account)PXSelect <Account, Where <Account.accountID, Equal <Current <AccountsPreloadFilter.fromAccount> > > > .Select(this)).AccountCD :
                                                                                                                                                                                     ((Account)PXSelect <Account> .Select(this).First()).AccountCD,
                                                                                                                                                                                     PreloadFilter.Current.ToAccount != null ?
                                                                                                                                                                                     ((Account)PXSelect <Account, Where <Account.accountID, Equal <Current <AccountsPreloadFilter.toAccount> > > > .Select(this)).AccountCD :
                                                                                                                                                                                     ((Account)PXSelect <Account> .Select(this).Last()).AccountCD))
            {
                foreach (PXResult <Sub> sub in PXSelect <Sub, Where <Sub.active, Equal <True>, And <Sub.subCD, Like <Current <AccountsPreloadFilter.subCDWildcard> > > > > .Select(this))
                {
                    Account      acct    = account;
                    Sub          subAcct = sub;
                    GLBudgetTree group   = new GLBudgetTree();
                    if (currentItem == null || acct.AccountID != currentItem.AccountID || subAcct.SubID != currentItem.SubID)
                    {
                        group.AccountID = acct.AccountID;
                        group.SubID     = subAcct.SubID;

                        group.SortOrder = LastSortNum++;

                        group.GroupMask = CurrentSelected.GroupMask;

                        nodesToInsert.Add(group);
                        noLinesPreloaded = false;
                    }
                }
            }
            if (noLinesPreloaded)
            {
                if (Details.Ask(Messages.BudgetTreePreloadArticlesTitle, Messages.BudgetTreePreloadArticlesNothingToPreload, MessageButtons.OK) == WebDialogResult.OK)
                {
                    return(adapter.Get());
                }
            }
            if (nodesToInsert.Count > 500)
            {
                if (Details.Ask(Messages.Confirmation, String.Format(PXMessages.LocalizeNoPrefix(Messages.BudgetTreePreloadArticlesTooManyMessage), nodesToInsert.Count), MessageButtons.OKCancel) == WebDialogResult.OK)
                {
                    InsertPreloadedNodes(nodesToInsert);
                }
            }
            else
            {
                InsertPreloadedNodes(nodesToInsert);
            }
            return(adapter.Get());
        }
Example #3
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);
        }