Exemple #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 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);
            }
        }
Exemple #3
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 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);
                    }
                }
            }
        }