Exemple #1
0
        protected virtual void PMProjectStatusEx_IsProduction_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            PMProjectStatusEx row = e.Row as PMProjectStatusEx;

            if (row != null)
            {
                if (row.IsProduction == true)
                {
                    bool requestRefresh = false;

                    List <PMProjectStatusEx> productionSiblings = SelectSiblings(row);

                    foreach (PMProjectStatusEx ps in productionSiblings)
                    {
                        PMProjectStatusEx item = PXCache <PMProjectStatusEx> .CreateCopy(ps);

                        item.IsProduction = false;
                        ProjectStatus.Update(item);
                        requestRefresh = true;
                    }

                    if (requestRefresh)
                    {
                        ProjectStatus.View.RequestRefresh();
                    }
                }
            }
        }
Exemple #2
0
        protected virtual void PMProjectStatusEx_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            PMProjectStatusEx row = e.Row as PMProjectStatusEx;

            if (row == null)
            {
                return;
            }

            PXUIFieldAttribute.SetEnabled <PMProjectStatusEx.uOM>(sender, e.Row, row.ActualQty == 0);
        }
Exemple #3
0
        protected List <PMProjectStatusEx> SelectSiblings(PMProjectStatusEx record)
        {
            List <PMProjectStatusEx> list = new List <PMProjectStatusEx>();

            if (Task.Current != null)
            {
                foreach (PMProjectStatusEx item in projectStatus())
                {
                    if (item.IsProduction == true && item != record)
                    {
                        list.Add(item);
                    }
                }
            }

            return(list);
        }
Exemple #4
0
        protected virtual void PMProjectStatusEx_AccountGroupID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            PMProjectStatusEx row = e.Row as PMProjectStatusEx;

            if (row != null)
            {
                if (string.IsNullOrEmpty(row.Type))
                {
                    PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(this, row.AccountGroupID);

                    if (ag != null)
                    {
                        row.Type = ag.Type;
                    }
                }
            }
        }
Exemple #5
0
        protected virtual void PMProjectStatusEx_LineNbr_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            PMProjectStatusEx row = e.Row as PMProjectStatusEx;

            if (row != null)
            {
                if (e.NewValue == null)
                {
                    int minLineNbr = 0;

                    foreach (PMProjectStatusEx ps in sender.Inserted)
                    {
                        minLineNbr = Math.Min(minLineNbr, ps.LineNbr.Value);
                    }

                    e.NewValue = minLineNbr - 1;
                }
            }
        }
Exemple #6
0
        public virtual void RunAutoBudget()
        {
            AutoBudgetWorkerProcess wp = PXGraph.CreateInstance <AutoBudgetWorkerProcess>();
            List <AutoBudgetWorkerProcess.Balance> list = wp.Run(Task.Current);

            foreach (AutoBudgetWorkerProcess.Balance b in list)
            {
                PMProjectStatusEx ps = new PMProjectStatusEx();
                ps.AccountGroupID = b.AccountGroupID;
                ps.InventoryID    = b.InventoryID;
                ps.ProjectID      = Task.Current.ProjectID;
                ps.ProjectTaskID  = Task.Current.TaskID;
                ps.Amount         = b.Amount;
                ps.RevisedAmount  = b.Amount;
                ps.Qty            = b.Quantity;
                ps.RevisedQty     = b.Quantity;
                if (b.Quantity != 0)
                {
                    ps.Rate = b.Amount / b.Quantity;
                }

                bool found = false;
                foreach (PMProjectStatusEx item in ProjectStatus.Select())
                {
                    if (item.ProjectID == ps.ProjectID &&
                        item.ProjectTaskID == ps.ProjectTaskID &&
                        item.AccountGroupID == ps.AccountGroupID &&
                        item.InventoryID == ps.InventoryID)
                    {
                        if (Task.Current.IsActive != true)
                        {
                            item.Amount = b.Amount;
                            item.Qty    = b.Quantity;
                        }

                        item.RevisedAmount = b.Amount;
                        item.RevisedQty    = b.Quantity;
                        if (b.Quantity != 0)
                        {
                            item.Rate = b.Amount / b.Quantity;
                        }
                        ProjectStatus.Update(item);

                        found = true;
                    }
                }

                if (!found)
                {
                    PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(this, ps.AccountGroupID);

                    ps.Type = ag.Type;
                    switch (ag.Type)
                    {
                    case AccountType.Asset:
                        ps.SortOrder = 1;
                        break;

                    case AccountType.Liability:
                        ps.SortOrder = 2;
                        break;

                    case AccountType.Income:
                        ps.SortOrder = 3;
                        break;

                    case AccountType.Expense:
                        ps.SortOrder = 4;
                        break;
                    }
                    this.FieldVerifying.AddHandler <PMProjectStatusEx.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
                    ProjectStatus.Insert(ps);
                }
            }

            this.Save.Press();
        }
Exemple #7
0
        public virtual IEnumerable projectStatus()
        {
            if (Task.Current == null)
            {
                yield break;
            }

            Dictionary <string, PMProjectStatusEx> cachedItems = new Dictionary <string, PMProjectStatusEx>();

            bool isDirty = false;

            int cxMax = 0;

            foreach (PMProjectStatusEx item in ProjectStatus.Cache.Cached)
            {
                cxMax = Math.Max(cxMax, item.LineNbr.Value);
                string key = string.Format("{0}.{1}.{2}.{3}", item.AccountGroupID, item.ProjectID, item.ProjectTaskID, item.InventoryID.GetValueOrDefault());

                if (!cachedItems.ContainsKey(key))
                {
                    cachedItems.Add(key, item);
                }

                if (ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Inserted ||
                    ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Updated ||
                    ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Notchanged ||
                    ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Held)
                {
                    if (ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Inserted ||
                        ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Updated)
                    {
                        isDirty = true;
                    }

                    yield return(item);
                }
            }

            PXSelectBase <PMProjectStatus> select = new PXSelectJoinGroupBy <PMProjectStatus,
                                                                             InnerJoin <PMTask, On <PMTask.projectID, Equal <PMProjectStatus.projectID>, And <PMTask.taskID, Equal <PMProjectStatus.projectTaskID> > >,
                                                                                        InnerJoin <PMAccountGroup, On <PMProjectStatus.accountGroupID, Equal <PMAccountGroup.groupID> > > >,
                                                                             Where <PMProjectStatus.projectID, Equal <Current <PMTask.projectID> >,
                                                                                    And <PMProjectStatus.projectTaskID, Equal <Current <PMTask.taskID> > > >,
                                                                             Aggregate <GroupBy <PMProjectStatus.accountGroupID,
                                                                                                 GroupBy <PMProjectStatus.projectID,
                                                                                                          GroupBy <PMProjectStatus.projectTaskID,
                                                                                                                   GroupBy <PMProjectStatus.inventoryID,
                                                                                                                            Sum <PMProjectStatus.amount,
                                                                                                                                 Sum <PMProjectStatus.qty,
                                                                                                                                      Sum <PMProjectStatus.revisedAmount,
                                                                                                                                           Sum <PMProjectStatus.revisedQty,
                                                                                                                                                Sum <PMProjectStatus.actualAmount,
                                                                                                                                                     Sum <PMProjectStatus.actualQty> > > > > > > > > > >, OrderBy <Asc <PMAccountGroup.sortOrder> > >(this);

            int cx = cxMax + 1;

            foreach (PXResult <PMProjectStatus, PMTask, PMAccountGroup> res in select.Select())
            {
                PMProjectStatus row  = (PMProjectStatus)res;
                PMTask          task = (PMTask)res;
                PMAccountGroup  ag   = (PMAccountGroup)res;

                string key = string.Format("{0}.{1}.{2}.{3}", row.AccountGroupID, row.ProjectID, row.ProjectTaskID, row.InventoryID.GetValueOrDefault());

                if (!cachedItems.ContainsKey(key))
                {
                    PMProjectStatusEx item = new PMProjectStatusEx();
                    item.LineNbr        = cx++;
                    item                = (PMProjectStatusEx)ProjectStatus.Cache.Insert(item);
                    item.ProjectID      = row.ProjectID;
                    item.ProjectTaskID  = row.ProjectTaskID;
                    item.AccountGroupID = row.AccountGroupID;
                    item.InventoryID    = row.InventoryID;
                    item.Description    = row.Description;
                    item.UOM            = row.UOM;
                    item.Rate           = row.Rate;
                    item.Qty            = row.Qty;
                    item.Amount         = row.Amount;
                    item.RevisedQty     = row.RevisedQty;
                    item.RevisedAmount  = row.RevisedAmount;
                    item.ActualQty      = row.ActualQty;
                    item.ActualAmount   = row.ActualAmount;
                    PMProjectStatus rowDetail = (PMProjectStatus)PXSelect <
                        PMProjectStatus
                        , Where <
                            PMProjectStatus.isProduction, Equal <True>
                            , And <PMProjectStatus.projectID, Equal <Required <PMProjectStatus.projectID> >
                                   , And <PMProjectStatus.projectTaskID, Equal <Required <PMProjectStatus.projectTaskID> >
                                          , And <PMProjectStatus.inventoryID, Equal <Required <PMProjectStatus.inventoryID> >
                                                 , And <PMProjectStatus.accountGroupID, Equal <Required <PMProjectStatus.accountGroupID> > >
                                                 >
                                          >
                                   >
                            >
                        > .Select(this, row.ProjectID, row.ProjectTaskID, row.InventoryID, row.AccountGroupID);

                    if (rowDetail != null)
                    {
                        item.IsProduction = true;
                    }
                    item.TaskStatus = task.Status;
                    item.Type       = ag.Type;
                    switch (ag.Type)
                    {
                    case AccountType.Asset:
                        item.SortOrder = 1;
                        break;

                    case AccountType.Liability:
                        item.SortOrder = 2;
                        break;

                    case AccountType.Income:
                        item.SortOrder = 3;
                        break;

                    case AccountType.Expense:
                        item.SortOrder = 4;
                        break;
                    }
                    ProjectStatus.Cache.SetStatus(item, PXEntryStatus.Held);

                    yield return(item);
                }
            }

            ProjectStatus.Cache.IsDirty = isDirty;
        }