Exemple #1
0
        protected virtual void PMTask_CompletedPct_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            PMTask row = e.Row as PMTask;

            if (row != null)
            {
                PXSelectBase <PMProjectStatus> select = new PXSelectGroupBy <PMProjectStatus,
                                                                             Where <PMProjectStatus.projectID, Equal <Required <PMTask.projectID> >,
                                                                                    And <PMProjectStatus.projectTaskID, Equal <Required <PMTask.taskID> >,
                                                                                         And <PMProjectStatus.isProduction, Equal <True> > > >,
                                                                             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> > > > > > > > > > > >(this);

                PMProjectStatus ps = select.Select(row.ProjectID, row.TaskID);

                if (ps != null)
                {
                    if (ps.RevisedQty > 0)
                    {
                        e.ReturnValue = Convert.ToInt32(100 * ps.ActualQty / ps.RevisedQty);
                        e.ReturnState = PXFieldState.CreateInstance(e.ReturnValue, typeof(decimal?), false, false, 0, 0, 0, 0, "CompletedPct", null, null, null, PXErrorLevel.Undefined, false, true, true, PXUIVisibility.Visible, null, null, null);
                    }
                }
            }
        }
Exemple #2
0
        protected virtual void PMProjectStatus_PeriodID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            PMProjectStatus row = (PMProjectStatus)e.Row;

            if (e.OldValue == null && row.PeriodID != null)
            {
                sender.SetDefaultExt <PMProjectStatus.rate>(row);
            }
        }
        protected virtual List <PMTran> CreateExpenseTransactions(PMTask task, out DateTime?lastDate)
        {
            lastDate = null;

            PXSelectBase <PMProjectStatus> select = new PXSelectJoin <PMProjectStatus,
                                                                      InnerJoin <PMTask, On <PMTask.projectID, Equal <PMProjectStatus.projectID>, And <PMTask.taskID, Equal <PMProjectStatus.projectTaskID> > >,
                                                                                 InnerJoin <PMAccountGroup, On <PMProjectStatus.accountGroupID, Equal <PMAccountGroup.groupID> >,
                                                                                            LeftJoin <InventoryItem, On <PMProjectStatus.inventoryID, Equal <InventoryItem.inventoryID> > > > >,
                                                                      Where <PMProjectStatus.projectID, Equal <Required <PMTask.projectID> >,
                                                                             And <PMProjectStatus.projectTaskID, Equal <Required <PMTask.taskID> >,
                                                                                  And <PMAccountGroup.type, Equal <AccountType.expense> > > > >(this);

            List <PMTran> trans = new List <PMTran>();

            foreach (PXResult <PMProjectStatus, PMTask, PMAccountGroup, InventoryItem> res in select.Select(task.ProjectID, task.TaskID))
            {
                PMProjectStatus ps   = (PMProjectStatus)res;
                InventoryItem   item = (InventoryItem)res;

                PMTran tran = new PMTran();
                tran.AccountGroupID = ps.AccountGroupID;
                tran.ProjectID      = ps.ProjectID;
                tran.TaskID         = ps.ProjectTaskID;
                tran.InventoryID    = ps.InventoryID;
                tran.AccountID      = item.InventoryID != null ? item.COGSAcctID : null;
                tran.SubID          = item.InventoryID != null ? item.COGSSubID : null;
                tran.Amount         = ps.Amount;
                tran.Qty            = ps.Qty;
                tran.UOM            = ps.UOM;
                tran.BAccountID     = task.CustomerID;
                tran.LocationID     = task.LocationID;
                tran.Billable       = true;
                tran.UseBillableQty = true;
                tran.BillableQty    = ps.RevisedQty;
                tran.Date           = FinPeriodIDAttribute.PeriodEndDate(this, ps.PeriodID);
                tran.StartDate      = tran.Date;
                tran.EndDate        = tran.Date;
                tran.FinPeriodID    = ps.PeriodID;
                tran.TranPeriodID   = ps.PeriodID;
                tran.Released       = true;

                if (lastDate != null)
                {
                    if (lastDate < tran.Date)
                    {
                        lastDate = tran.Date;
                    }
                }
                else
                {
                    lastDate = tran.Date;
                }
                trans.Add(Transactions.Insert(tran));
            }

            return(trans);
        }
Exemple #4
0
        protected virtual void PMProjectStatus_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            PMProjectStatus row = e.Row as PMProjectStatus;

            if (row != null)
            {
                PMProjectStatus ps = PXSelect <PMProjectStatus,
                                               Where <PMProjectStatus.accountGroupID, Equal <Current <ProjectBalanceFilter.accountGroupID> >,
                                                      And <PMProjectStatus.projectID, Equal <Current <ProjectBalanceFilter.projectID> >,
                                                           And <PMProjectStatus.projectTaskID, Equal <Current <ProjectBalanceFilter.projectTaskID> >,
                                                                And <PMProjectStatus.inventoryID, Equal <Current <ProjectBalanceFilter.inventoryID> >,
                                                                     And <PMProjectStatus.periodID, NotEqual <Current <PMProjectStatus.periodID> > > > > > > > .SelectWindowed(this, 0, 1);

                PXUIFieldAttribute.SetEnabled <PMProjectStatus.uOM>(Items.Cache, null, ps == null);
                PXUIFieldAttribute.SetEnabled <PMProjectStatus.rate>(Items.Cache, null, ps == null);
            }
        }
Exemple #5
0
        protected virtual void PMProjectStatus_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            PMProjectStatus row = e.Row as PMProjectStatus;

            if (row != null)
            {
                PMProjectStatus ps = PXSelect <PMProjectStatus,
                                               Where <PMProjectStatus.accountGroupID, Equal <Current <ProjectBalanceFilter.accountGroupID> >,
                                                      And <PMProjectStatus.projectID, Equal <Current <ProjectBalanceFilter.projectID> >,
                                                           And <PMProjectStatus.projectTaskID, Equal <Current <ProjectBalanceFilter.projectTaskID> >,
                                                                And <PMProjectStatus.inventoryID, Equal <Current <ProjectBalanceFilter.inventoryID> >,
                                                                     And <PMProjectStatus.periodID, NotEqual <Current <PMProjectStatus.periodID> > > > > > > > .SelectWindowed(this, 0, 1);

                if (ps != null)
                {
                    row.UOM  = ps.UOM;
                    row.Rate = ps.Rate;
                }
            }
        }
        protected virtual void PMAccountGroup_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            PMAccountGroup row = e.Row as PMAccountGroup;

            if (row != null)
            {
                if (IsAccountsExist())
                {
                    e.Cancel = true;
                    throw new PXException(Messages.Account_FK);
                }

                PMProjectStatus ps = PXSelect <PMProjectStatus, Where <PMProjectStatus.accountGroupID, Equal <Required <PMAccountGroup.groupID> > > > .SelectWindowed(this, 0, 1, row.GroupID);

                if (ps != null)
                {
                    e.Cancel = true;
                    throw new PXException(Messages.ProjectStatus_FK);
                }
            }
        }
Exemple #7
0
        protected virtual void RunAutoBudget(PMTask task)
        {
            PXSelectBase <PMProjectStatus> select = new PXSelectJoin <PMProjectStatus,
                                                                      InnerJoin <PMTask, On <PMTask.projectID, Equal <PMProjectStatus.projectID>, And <PMTask.taskID, Equal <PMProjectStatus.projectTaskID> > >,
                                                                                 InnerJoin <PMAccountGroup, On <PMProjectStatus.accountGroupID, Equal <PMAccountGroup.groupID> >,
                                                                                            LeftJoin <InventoryItem, On <PMProjectStatus.inventoryID, Equal <InventoryItem.inventoryID> > > > >,
                                                                      Where <PMProjectStatus.projectID, Equal <Required <PMTask.projectID> >,
                                                                             And <PMProjectStatus.projectTaskID, Equal <Required <PMTask.taskID> >,
                                                                                  And <PMAccountGroup.type, Equal <AccountType.expense> > > > >(this);

            List <PMTran> trans = new List <PMTran>();

            foreach (PXResult <PMProjectStatus, PMTask, PMAccountGroup, InventoryItem> res in select.Select(task.ProjectID, task.TaskID))
            {
                PMProjectStatus ps   = (PMProjectStatus)res;
                InventoryItem   item = (InventoryItem)res;

                PMTran tran = new PMTran();
                tran.AccountGroupID = ps.AccountGroupID;
                tran.ProjectID      = ps.ProjectID;
                tran.TaskID         = ps.ProjectTaskID;
                tran.InventoryID    = ps.InventoryID;
                tran.AccountID      = item.InventoryID != null ? item.SalesAcctID : null;
                tran.Amount         = ps.RevisedAmount;
                tran.Qty            = ps.RevisedQty;
                tran.UOM            = ps.UOM;
                tran.BAccountID     = task.CustomerID;
                tran.LocationID     = task.LocationID;
                tran.Billable       = true;
                tran.BillableQty    = ps.RevisedQty;
                tran.Date           = FinPeriodIDAttribute.PeriodEndDate(this, ps.PeriodID);
                tran.StartDate      = tran.Date;
                tran.EndDate        = tran.Date;
                tran.FinPeriodID    = ps.PeriodID;
                tran.TranPeriodID   = ps.PeriodID;

                trans.Add(tran);
            }
        }
Exemple #8
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;
        }
Exemple #9
0
        /// <summary>
        /// Updates Project Status Balance using PMProjectStatusAccum.
        /// </summary>
        public static IList <PMHistory> UpdateProjectBalance(PXGraph graph, PMTran pmt, PMAccountGroup ag, Account acc, int mult)
        {
            List <PMHistory> list = new List <PMHistory>();
            PXSelectBase <PMProjectStatus> selectProjectStatus = new PXSelect <PMProjectStatus,
                                                                               Where <PMProjectStatus.accountGroupID, Equal <Required <PMProjectStatus.accountGroupID> >,
                                                                                      And <PMProjectStatus.projectID, Equal <Required <PMProjectStatus.projectID> >,
                                                                                           And <PMProjectStatus.projectTaskID, Equal <Required <PMProjectStatus.projectTaskID> >,
                                                                                                And <PMProjectStatus.inventoryID, Equal <Required <PMProjectStatus.inventoryID> > > > > > >(graph); // select any without restricting by FinPeriod

            int             inventoryID = PMProjectStatus.EmptyInventoryID;
            PMProjectStatus status      = null;

            if (pmt.InventoryID != null)
            {
                status = selectProjectStatus.Select(ag.GroupID, pmt.ProjectID, pmt.TaskID, pmt.InventoryID);
                if (status == null)
                {
                    status = selectProjectStatus.Select(ag.GroupID, pmt.ProjectID, pmt.TaskID, PMProjectStatus.EmptyInventoryID);
                }
                else
                {
                    inventoryID = status.InventoryID ?? PMProjectStatus.EmptyInventoryID;
                }
            }
            else
            {
                status = selectProjectStatus.Select(ag.GroupID, pmt.ProjectID, pmt.TaskID, PMProjectStatus.EmptyInventoryID);
            }

            string  UOM       = null;
            decimal rollupQty = 0;

            if (status == null)
            {
                //Status does not exist for given Inventory and <Other> is not present.
            }
            else
            {
                if (status.InventoryID == PMProjectStatus.EmptyInventoryID)
                {
                    //<Other> item is present. Update only if UOMs are same.
                    decimal convertedQty;
                    if (IN.INUnitAttribute.TryConvertGlobalUnits(graph, pmt.UOM, status.UOM, pmt.Qty.GetValueOrDefault(), IN.INPrecision.QUANTITY, out convertedQty))
                    {
                        rollupQty = convertedQty;
                        UOM       = status.UOM;
                    }
                }
                else
                {
                    UOM = status.UOM;

                    //Item matches. Convert to UOM of ProjectStatus.
                    if (status.UOM != pmt.UOM)
                    {
                        decimal inBase = IN.INUnitAttribute.ConvertToBase(graph.Caches[pmt.GetType()], pmt.InventoryID, pmt.UOM, pmt.Qty ?? 0, IN.INPrecision.QUANTITY);

                        try
                        {
                            rollupQty = IN.INUnitAttribute.ConvertFromBase(graph.Caches[pmt.GetType()], pmt.InventoryID, status.UOM, inBase, IN.INPrecision.QUANTITY);
                        }
                        catch (PX.Objects.IN.PXUnitConversionException ex)
                        {
                            IN.InventoryItem item = PXSelect <IN.InventoryItem, Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(graph, pmt.InventoryID);

                            string msg = PXMessages.LocalizeFormatNoPrefixNLA(Messages.UnitConversionNotDefinedForItemOnBudgetUpdate, item.BaseUnit, status.UOM, item.InventoryCD);

                            throw new PXException(msg, ex);
                        }
                    }
                    else
                    {
                        rollupQty = pmt.Qty ?? 0;
                    }
                }
            }

            if (pmt.TaskID != null && (rollupQty != 0 || pmt.Amount != 0)) //TaskID will be null for Contract
            {
                PMProjectStatusAccum ps = new PMProjectStatusAccum();
                ps.PeriodID       = pmt.FinPeriodID;
                ps.ProjectID      = pmt.ProjectID;
                ps.ProjectTaskID  = pmt.TaskID;
                ps.AccountGroupID = ag.GroupID;
                ps.InventoryID    = inventoryID;
                ps.UOM            = UOM;
                if (status != null)
                {
                    ps.IsProduction = status.IsProduction;
                }

                ps = (PMProjectStatusAccum)graph.Caches[typeof(PMProjectStatusAccum)].Insert(ps);

                decimal amt = mult * pmt.Amount.GetValueOrDefault();

                ps.ActualQty    += rollupQty * mult;
                ps.ActualAmount += amt;

                graph.Views.Caches.Add(typeof(PMProjectStatusAccum));

                #region PMTask Totals Update

                PMTaskTotal ta = new PMTaskTotal();
                ta.ProjectID = pmt.ProjectID;
                ta.TaskID    = pmt.TaskID;

                ta = (PMTaskTotal)graph.Caches[typeof(PMTaskTotal)].Insert(ta);

                string accType = null;
                int    multFix = 1;             //flip back the sign if it was changed because of ag.Type<>acc.type
                if (pmt.TranType == BatchModule.PM && acc != null && !string.IsNullOrEmpty(acc.Type))
                {
                    //Only transactions that originated in PM were inverted and require to be fixed.
                    accType = ag.Type;

                    if (acc.Type != ag.Type)
                    {
                        multFix = -1;
                    }
                }
                else
                {
                    accType = ag.Type;
                }

                switch (accType)
                {
                case AccountType.Asset:
                    ta.Asset += amt * multFix;
                    break;

                case AccountType.Liability:
                    ta.Liability += amt * multFix;
                    break;

                case AccountType.Income:
                    ta.Income += amt * multFix;
                    break;

                case AccountType.Expense:
                    ta.Expense += amt * multFix;
                    break;
                }

                graph.Views.Caches.Add(typeof(PMTaskTotal));

                #endregion
                #region History
                PMHistory hist = new PMHistory();
                hist.ProjectID      = pmt.ProjectID;
                hist.ProjectTaskID  = pmt.TaskID;
                hist.AccountGroupID = ag.GroupID;
                hist.InventoryID    = pmt.InventoryID ?? PMProjectStatus.EmptyInventoryID;
                hist.PeriodID       = pmt.FinPeriodID;
                decimal baseQty = 0;
                list.Add(hist);
                if (pmt.InventoryID != null && pmt.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID && rollupQty != 0)
                {
                    baseQty = mult * PX.Objects.IN.INUnitAttribute.ConvertToBase(graph.Caches[typeof(PMHistory)], pmt.InventoryID, UOM, rollupQty, PX.Objects.IN.INPrecision.QUANTITY);
                }
                hist.FinPTDAmount = amt;
                hist.FinYTDAmount = amt;
                hist.FinPTDQty    = baseQty;
                hist.FinYTDQty    = baseQty;
                if (pmt.FinPeriodID == pmt.TranPeriodID)
                {
                    hist.TranPTDAmount = amt;
                    hist.TranYTDAmount = amt;
                    hist.TranPTDQty    = baseQty;
                    hist.TranYTDQty    = baseQty;
                }
                else
                {
                    PMHistory tranHist = new PMHistory();
                    tranHist.ProjectID      = pmt.ProjectID;
                    tranHist.ProjectTaskID  = pmt.TaskID;
                    tranHist.AccountGroupID = ag.GroupID;
                    tranHist.InventoryID    = pmt.InventoryID ?? PM.PMProjectStatus.EmptyInventoryID;
                    tranHist.PeriodID       = pmt.TranPeriodID;
                    list.Add(tranHist);
                    tranHist.TranPTDAmount = amt;
                    tranHist.TranYTDAmount = amt;
                    tranHist.TranPTDQty    = baseQty;
                    tranHist.TranYTDQty    = baseQty;
                }
                #endregion
            }
            return(list);
        }
        private bool IsBalanceExist()
        {
            PMProjectStatus status = PXSelect <PMProjectStatus, Where <PMProjectStatus.accountGroupID, Equal <Current <PMAccountGroup.groupID> > > > .SelectWindowed(this, 0, 1);

            return(status != null);
        }