示例#1
0
        protected virtual void AccountPtr_AccountID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            AccountAttribute.VerifyAccountIsNotControl <AccountPtr.accountID>(sender, e);

            AccountPtr row = e.Row as AccountPtr;

            if (row != null)
            {
                Account account = PXSelect <Account> .Search <Account.accountID>(this, e.NewValue);

                if (account != null && account.IsCashAccount == true)
                {
                    sender.RaiseExceptionHandling <AccountPtr.accountID>(row, e.NewValue,
                                                                         new PXSetPropertyException(GL.Messages.CashAccountIsNotForProjectPurposes, PXErrorLevel.Warning, account.AccountCD));
                }

                if (account != null && AccountGroup.Current != null && account.AccountGroupID != null && account.AccountGroupID != AccountGroup.Current.GroupID)
                {
                    PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(this, account.AccountGroupID);

                    sender.RaiseExceptionHandling <AccountPtr.accountID>(row, e.NewValue,
                                                                         new PXSetPropertyException(Warnings.AccountIsUsed, PXErrorLevel.Warning, ag.GroupCD));
                }
            }
        }
示例#2
0
        protected virtual void AddAccount(AccountPtr ptr)
        {
            Account account = GetAccountByID(ptr.AccountID);

            if (account != null && AccountGroup.Current != null)
            {
                account.AccountGroupID = AccountGroup.Current.GroupID;
                GLAccount.Update(account);
                GLAccount.Cache.PersistUpdated(account);
            }
        }
示例#3
0
        protected virtual void RemoveAccount(AccountPtr ptr)
        {
            Account account = GetAccountByID(ptr.AccountID);

            if (account != null && account.AccountGroupID != null)
            {
                account.AccountGroupID = null;
                GLAccount.Update(account);
                GLAccount.Cache.PersistUpdated(account);
            }
        }
        protected virtual void AccountPtr_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            AccountPtr row = e.Row as AccountPtr;

            if (row != null)
            {
                Account account = GetAccountByID(row.AccountID);
                if (account != null)
                {
                    row.AccountClassID = account.AccountClassID;
                    row.CuryID         = account.CuryID;
                    row.Description    = account.Description;
                    row.Type           = account.Type;
                }
            }
        }
        protected virtual void AccountPtr_AccountID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            AccountPtr row = e.Row as AccountPtr;

            if (row != null)
            {
                Account account = PXSelect <Account> .Search <Account.accountID>(this, e.NewValue);

                if (account != null && AccountGroup.Current != null && account.AccountGroupID != null && account.AccountGroupID != AccountGroup.Current.GroupID)
                {
                    PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(this, account.AccountGroupID);

                    sender.RaiseExceptionHandling <AccountPtr.accountID>(row, e.NewValue,
                                                                         new PXSetPropertyException(Warnings.AccountIsUsed, PXErrorLevel.Warning, ag.GroupCD));
                }
            }
        }
        protected virtual void AccountPtr_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            AccountPtr row = e.Row as AccountPtr;

            if (row != null)
            {
                switch (e.Operation)
                {
                case PXDBOperation.Delete:
                    RemoveAccount(row);
                    break;

                case PXDBOperation.Insert:
                    AddAccount(row);
                    break;
                }

                e.Cancel = true;
            }
        }
示例#7
0
        public IEnumerable accounts()
        {
            Dictionary <int, AccountPtr> inCache = new Dictionary <int, AccountPtr>();

            foreach (AccountPtr item in Accounts.Cache.Cached)
            {
                PXEntryStatus status = Accounts.Cache.GetStatus(item);
                inCache.Add(item.AccountID.Value, item);
                if (status == PXEntryStatus.Inserted || status == PXEntryStatus.Updated || status == PXEntryStatus.Notchanged)
                {
                    yield return(item);
                }
            }

            PXSelectBase <Account> select = new PXSelect <Account,
                                                          Where <Account.accountGroupID, Equal <Current <PMAccountGroup.groupID> > > >(this);

            bool isDirty = Accounts.Cache.IsDirty;

            foreach (Account acct in select.Select())
            {
                if (!inCache.ContainsKey(acct.AccountID.Value))
                {
                    AccountPtr ptr = new AccountPtr();
                    ptr.AccountID      = acct.AccountID;
                    ptr.AccountClassID = acct.AccountClassID;
                    ptr.CuryID         = acct.CuryID;
                    ptr.Description    = acct.Description;
                    ptr.Type           = acct.Type;
                    ptr.IsDefault      = AccountGroup.Current.AccountID == acct.AccountID;

                    ptr = Accounts.Insert(ptr);
                    Accounts.Cache.SetStatus(ptr, PXEntryStatus.Notchanged);

                    yield return(ptr);
                }
            }


            Accounts.Cache.IsDirty = isDirty;
        }
示例#8
0
        protected virtual void AccountPtr_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            AccountAttribute.VerifyAccountIsNotControl <AccountPtr.accountID>(sender, e);

            AccountPtr row = e.Row as AccountPtr;

            if (row != null)
            {
                switch (e.Operation)
                {
                case PXDBOperation.Delete:
                    RemoveAccount(row);
                    break;

                case PXDBOperation.Insert:
                case PXDBOperation.Update:
                    AddAccount(row);
                    break;
                }

                e.Cancel = true;
            }
        }
示例#9
0
        protected virtual void AccountPtr_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            AccountPtr row    = e.Row as AccountPtr;
            AccountPtr oldRow = e.OldRow as AccountPtr;

            if (row != null)
            {
                Account account = GetAccountByID(row.AccountID);
                if (account != null)
                {
                    row.AccountClassID = account.AccountClassID;
                    row.CuryID         = account.CuryID;
                    row.Description    = account.Description;
                    row.Type           = account.Type;
                }

                bool refresh = false;
                if (row.IsDefault != oldRow.IsDefault)
                {
                    if (row.IsDefault == true)
                    {
                        foreach (AccountPtr ptr in Accounts.Select())
                        {
                            if (ptr.AccountID == row.AccountID)
                            {
                                continue;
                            }

                            if (ptr.IsDefault == true)
                            {
                                Accounts.Cache.SetValue <AccountPtr.isDefault>(ptr, false);
                                Accounts.Cache.SmartSetStatus(ptr, PXEntryStatus.Updated);
                                refresh = true;
                            }
                        }
                    }
                }
                else
                {
                    bool hasDefault = false;
                    foreach (AccountPtr ptr in Accounts.Select())
                    {
                        if (ptr.AccountID == row.AccountID)
                        {
                            continue;
                        }

                        if (ptr.IsDefault == true)
                        {
                            hasDefault = true;
                        }
                    }

                    if (!hasDefault)
                    {
                        row.IsDefault = true;
                    }
                }

                if (refresh)
                {
                    Accounts.View.RequestRefresh();
                }
            }
        }