Beispiel #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));
                    }
                }
            }
        }
        protected virtual void Account_CuryID_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            Account acct = cache.Locate(e.Row) as Account;

            string newCuryID = (string)e.NewValue;

            if (acct != null && string.IsNullOrEmpty(acct.CuryID) && !string.IsNullOrEmpty(newCuryID))
            {
                if (!PostedTransInOtherCuryExists(acct, newCuryID))
                {
                    return;
                }
            }

            if (acct != null && acct.CuryID != newCuryID)
            {
                if (newCuryID != null || acct.IsCashAccount == true)
                {
                    bool hasHistory = GLUtility.IsAccountHistoryExist(this, acct.AccountID);
                    if (hasHistory)
                    {
                        throw new PXSetPropertyException(Messages.CannotChangeAccountCurrencyTransactionsExist);
                    }
                }
            }

            if (acct != null && acct.IsCashAccount == true && string.IsNullOrEmpty(newCuryID))
            {
                throw new PXSetPropertyException(Messages.CannotClearCurrencyInCashAccount);
            }
        }
        protected virtual void Account_CuryID_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            Account acct = cache.Locate(e.Row) as Account;

            string newCuryID = (string)e.NewValue;

            if (acct != null && string.IsNullOrEmpty(acct.CuryID) && !string.IsNullOrEmpty(newCuryID))
            {
                if (PXSelect <CuryGLHistory, Where <CuryGLHistory.accountID, Equal <Current <Account.accountID> >, And <CuryGLHistory.curyID, NotEqual <Required <CuryGLHistory.curyID> >, And <CuryGLHistory.balanceType, NotEqual <LedgerBalanceType.report> > > > > .SelectSingleBound(this, new object[] { acct }, newCuryID).Count == 0)
                {
                    return;
                }
            }

            if (acct != null && acct.CuryID != newCuryID)
            {
                bool hasHistory = GLUtility.IsAccountHistoryExist(this, acct.AccountID);
                if (hasHistory)
                {
                    throw new PXSetPropertyException(Messages.AccountExistsCurrencyID);
                }
            }

            if (acct != null && acct.IsCashAccount == true && string.IsNullOrEmpty(newCuryID))
            {
                throw new PXSetPropertyException(Messages.CannotClearCurrencyInCashAccount);
            }
        }
Beispiel #4
0
        protected virtual void Account_Type_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            Account acct = e.Row as Account;

            if (acct.Active != null && acct.Type != (string)e.NewValue && acct.AccountID != null)
            {
                bool hasHistory = GLUtility.IsAccountHistoryExist(this, acct.AccountID);
                if (hasHistory)
                {
                    throw new PXSetPropertyException(Messages.AccountExistsType);
                }

                if (acct.AccountID == GLSetup.Current?.YtdNetIncAccountID && (string)e.NewValue != AccountType.Liability)
                {
                    throw new PXSetPropertyException(Messages.AccountTypeCannotBeChangedGLYTD, acct.AccountCD);
                }

                if (acct.AccountGroupID != null)
                {
                    var group = (PM.PMAccountGroup)PXSelectorAttribute.Select <Account.accountGroupID>(cache, acct);

                    throw new PXSetPropertyException(Messages.AccountHasGroup, group.GroupCD);
                }
            }
        }
        protected virtual void GLSetup_YtdNetIncAccountID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            GLSetup row = (GLSetup)e.Row;

            if (row == null)
            {
                return;
            }

            if (e.NewValue != null)
            {
                Account YtdAccNew = PXSelect <Account, Where <Account.accountID, Equal <Required <GLSetup.ytdNetIncAccountID> > > > .Select(this, e.NewValue);

                if ((int?)e.NewValue == row.RetEarnAccountID)
                {
                    Account YtdAcc = PXSelect <Account, Where <Account.accountID, Equal <Current <GLSetup.ytdNetIncAccountID> > > > .SelectSingleBound(this, new object[] { row });

                    Account REAcc = PXSelect <Account, Where <Account.accountID, Equal <Current <GLSetup.retEarnAccountID> > > > .SelectSingleBound(this, new object[] { row });

                    e.NewValue = YtdAcc == null ? null : YtdAcc.AccountCD;
                    throw new PXSetPropertyException(CS.Messages.Entry_NE, REAcc.AccountCD);
                }

                if (YtdAccNew.GLConsolAccountCD != null)
                {
                    throw new PXSetPropertyException(Messages.AccountCannotBeSpecifiedAsTheYTDNetIncome);
                }

                if (GLUtility.IsAccountHistoryExist(this, (int?)e.NewValue))
                {
                    e.NewValue = YtdAccNew == null ? null : YtdAccNew.AccountCD;
                    throw new PXSetPropertyException(Messages.AccountExistsHistory2);
                }
            }
        }
        protected virtual void GLSetup_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            GLSetup setup      = e.Row as GLSetup;
            bool    hasHistory = GLUtility.IsAccountHistoryExist(this, setup.YtdNetIncAccountID);

            PXUIFieldAttribute.SetEnabled <GLSetup.ytdNetIncAccountID>(GLSetupRecord.Cache, setup, !hasHistory);
            PXUIFieldAttribute.SetEnabled <GLSetup.retEarnAccountID>(GLSetupRecord.Cache, setup, true);
        }
        protected virtual void Account_Type_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            Account acct = e.Row as Account;

            if (acct.Active != null && acct.Type != (string)e.NewValue)
            {
                bool hasHistory = acct.AccountID != null &&
                                  GLUtility.IsAccountHistoryExist(this, acct.AccountID);
                if (hasHistory)
                {
                    throw new PXSetPropertyException(Messages.AccountExistsType);
                }
            }
        }
        protected virtual void Ledger_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            Ledger ledger = e.Row as Ledger;

            if (ledger?.LedgerID != null)
            {
                bool hasHistory = GLUtility.IsLedgerHistoryExist(this, ledger.LedgerID);

                PXUIFieldAttribute.SetEnabled <Ledger.balanceType>(LedgerRecords.Cache, ledger, !hasHistory);

                bool canChangeCurrency = ledger.BalanceType != LedgerBalanceType.Actual && !hasHistory &&
                                         PXAccess.FeatureInstalled <FeaturesSet.multicurrency>();

                PXUIFieldAttribute.SetEnabled <Ledger.baseCuryID>(LedgerRecords.Cache, ledger, canChangeCurrency);
            }
        }
Beispiel #9
0
        protected virtual void Ledger_BalanceType_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            Ledger ledger = e.Row as Ledger;

            if (ledger != null && ledger.LedgerID != null && ledger.CreatedByID != null)
            {
                if (GLUtility.IsLedgerHistoryExist(this, (int)ledger.LedgerID))
                {
                    throw new PXSetPropertyException(Messages.CantChangeField, "BalanceType");
                }

                if ((string)e.NewValue == LedgerBalanceType.Actual && company.Current.BaseCuryID != ledger.BaseCuryID)
                {
                    throw new PXSetPropertyException(Messages.ActualLedgerInBaseCurrency, ledger.LedgerCD, company.Current.BaseCuryID);
                }
            }
        }
        protected virtual PXSetPropertyException CanBeLinkDeleted(OrganizationLedgerLink link)
        {
            Ledger ledger = GeneralLedgerMaint.FindLedgerByID(Base, link.LedgerID);

            if (ledger.BalanceType == LedgerBalanceType.Actual)
            {
                if (GLUtility.RelatedGLHistoryExists(Base, link.LedgerID, link.OrganizationID))
                {
                    Organization org = OrganizationMaint.FindOrganizationByID(Base, link.OrganizationID, true);
                    return(new PXSetPropertyException(Messages.TheRelationBetweenTheLedgerAndTheCompanyCannotBeRemovedBecauseAtLeastOneGeneralLedgerTransactionHasBeenPosted,
                                                      PXErrorLevel.RowError,
                                                      LinkCache.GetValueExt <OrganizationLedgerLink.ledgerID>(link),
                                                      org.OrganizationCD.Trim()
                                                      ));
                }
            }

            return(null);
        }
        protected virtual void Ledger_BalanceType_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            Ledger ledger = e.Row as Ledger;

            string newBalanceType = (string)e.NewValue;

            if (ledger != null && ledger.LedgerID != null && ledger.CreatedByID != null)
            {
                if (GLUtility.IsLedgerHistoryExist(this, (int)ledger.LedgerID))
                {
                    throw new PXSetPropertyException(Messages.CantChangeField, "BalanceType");
                }

                if (newBalanceType == LedgerBalanceType.Actual)
                {
                    if (company.Current.BaseCuryID != ledger.BaseCuryID)
                    {
                        throw new PXSetPropertyException(Messages.ActualLedgerInBaseCurrency,
                                                         ledger.LedgerCD,
                                                         company.Current.BaseCuryID);
                    }

                    CanBeLedgerSetAsActual(ledger, GetExtension <OrganizationLedgerLinkMaint>());

                    IEnumerable <Organization> organizations =
                        PXSelectJoin <Organization,
                                      InnerJoin <OrganizationLedgerLink,
                                                 On <Organization.organizationID, Equal <OrganizationLedgerLink.organizationID> > >,
                                      Where <OrganizationLedgerLink.ledgerID, Equal <Required <OrganizationLedgerLink.ledgerID> > > >
                        .Select(this, ledger.LedgerID)
                        .RowCast <Organization>();

                    foreach (Organization organization in organizations)
                    {
                        organization.ActualLedgerID = ledger.LedgerID;

                        OrganizationView.Cache.SmartSetStatus(organization, PXEntryStatus.Updated);
                    }
                }
            }
        }
        public virtual IEnumerable deleteOrganizationLedgerLink(PXAdapter adapter)
        {
            var link = LinkCache.Current as OrganizationLedgerLink;

            if (link?.OrganizationID == null || link.LedgerID == null)
            {
                return(adapter.Get());
            }

            Ledger ledger = GeneralLedgerMaint.FindLedgerByID(Base, link.LedgerID);

            if (ledger.BalanceType == LedgerBalanceType.Actual)
            {
                LinkCache.Delete(link);
            }
            else
            {
                if (GLUtility.RelatedGLHistoryExists(Base, link.LedgerID, link.OrganizationID))
                {
                    Organization org = OrganizationMaint.FindOrganizationByID(Base, link.OrganizationID, true);

                    WebDialogResult dialogResult = OrganizationLedgerLinkSelect.Ask(PXMessages.LocalizeFormatNoPrefix(
                                                                                        Messages.AtLeastOneGeneralLedgerTransactionHasBeenPosted,
                                                                                        LinkCache.GetValueExt <OrganizationLedgerLink.ledgerID>(link).ToString().Trim(),
                                                                                        org.OrganizationCD.Trim()),
                                                                                    MessageButtons.YesNo);

                    if (dialogResult == WebDialogResult.Yes)
                    {
                        LinkCache.Delete(link);
                    }
                }
                else
                {
                    LinkCache.Delete(link);
                }
            }

            return(adapter.Get());
        }
        protected virtual void GLSetup_RetEarnAccountID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            GLSetup row = (GLSetup)e.Row;

            if (row == null)
            {
                return;
            }

            if (e.NewValue != null && (int?)e.NewValue == row.YtdNetIncAccountID)
            {
                Account YtdAcc = PXSelect <Account, Where <Account.accountID, Equal <Current <GLSetup.ytdNetIncAccountID> > > > .SelectSingleBound(this, new object[] { row });

                Account REAcc = PXSelect <Account, Where <Account.accountID, Equal <Current <GLSetup.retEarnAccountID> > > > .SelectSingleBound(this, new object[] { row });

                e.NewValue = REAcc == null ? null : REAcc.AccountCD;
                throw new PXSetPropertyException(CS.Messages.Entry_NE, YtdAcc.AccountCD);
            }

            if (e.NewValue != null && GLUtility.IsAccountHistoryExist(this, (int?)e.NewValue))
            {
                sender.RaiseExceptionHandling <GLSetup.retEarnAccountID>(e.Row, null, new PXSetPropertyException(Messages.AccountExistsHistory2, PXErrorLevel.Warning));
            }
        }