public virtual PMBudget SelectProjectBalanceByInventory(IProjectFilter filter)
        {
            PXSelectBase <PMBudget> selectBudget = new PXSelect <PMBudget,
                                                                 Where <PMBudget.accountGroupID, Equal <Required <PMBudget.accountGroupID> >,
                                                                        And <PMBudget.projectID, Equal <Required <PMBudget.projectID> >,
                                                                             And <PMBudget.projectTaskID, Equal <Required <PMBudget.projectTaskID> >,
                                                                                  And <Where <PMBudget.inventoryID, Equal <Required <PMBudget.inventoryID> >, Or <PMBudget.inventoryID, Equal <Required <PMBudget.inventoryID> > > > > > > > >(graph);

            PMBudget withInventory    = null;
            PMBudget withoutInventory = null;

            foreach (PMBudget item in selectBudget.Select(filter.AccountGroupID, filter.ProjectID, filter.TaskID, filter.InventoryID, PMInventorySelectorAttribute.EmptyInventoryID))            //0..2 records
            {
                if (item.InventoryID == PMInventorySelectorAttribute.EmptyInventoryID)
                {
                    withoutInventory = item;
                }
                else
                {
                    withInventory = item;
                }
            }

            return(withInventory ?? withoutInventory);
        }
        protected virtual void PMBudget_UOM_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            PMBudget row = e.Row as PMBudget;

            if (row == null || string.IsNullOrEmpty(row.UOM))
            {
                return;
            }

            var select = new PXSelect <PMTran, Where <PMTran.projectID, Equal <Current <PMBudget.projectID> >,
                                                      And <PMTran.taskID, Equal <Current <PMBudget.projectTaskID> >,
                                                           And <PMTran.costCodeID, Equal <Current <PMBudget.costCodeID> >,
                                                                And <PMTran.inventoryID, Equal <Current <PMBudget.inventoryID> >,
                                                                     And2 <Where <PMTran.accountGroupID, Equal <Current <PMBudget.accountGroupID> >, Or <PMTran.offsetAccountGroupID, Equal <Current <PMBudget.accountGroupID> > > >,
                                                                           And <PMTran.released, Equal <True>,
                                                                                And <PMTran.uOM, NotEqual <Required <PMTran.uOM> > > > > > > > > >(this);

            string uom = (string)e.NewValue;

            if (!string.IsNullOrEmpty(uom))
            {
                PMTran tranInOtherUOM = select.SelectWindowed(0, 1, uom);

                if (tranInOtherUOM != null)
                {
                    var ex = new PXSetPropertyException(Messages.OtherUomUsedInTransaction);
                    ex.ErrorValue = uom;
                    throw ex;
                }
            }
        }
        public virtual PMTran ExpenseTransactionFromBudget(PMBudget budget, PMProject project, PMTask task, PMAccountGroup accountGroup, InventoryItem item, PMCostCode costcode)
        {
            PMTran tran = new PMTran();

            tran.AccountGroupID    = budget.AccountGroupID;
            tran.ProjectID         = budget.ProjectID;
            tran.TaskID            = budget.ProjectTaskID;
            tran.InventoryID       = budget.InventoryID;
            tran.AccountID         = item.InventoryID != null ? item.COGSAcctID : accountGroup.AccountID;
            tran.SubID             = item.InventoryID != null ? item.COGSSubID : accountGroup.AccountID;
            tran.TranCuryAmount    = budget.CuryRevisedAmount;
            tran.ProjectCuryAmount = budget.CuryRevisedAmount;
            tran.TranCuryID        = project.CuryID;
            tran.ProjectCuryID     = project.CuryID;
            tran.Qty            = budget.RevisedQty;
            tran.UOM            = budget.UOM;
            tran.BAccountID     = task.CustomerID;
            tran.LocationID     = task.LocationID;
            tran.Billable       = true;
            tran.UseBillableQty = true;
            tran.BillableQty    = budget.RevisedQty;
            tran.Released       = true;

            return(tran);
        }
        public virtual PMBudget SelectProjectBalanceByCostCodes(IProjectFilter filter)
        {
            PXSelectBase <PMBudget> selectBudget = new PXSelect <PMBudget,
                                                                 Where <PMBudget.accountGroupID, Equal <Required <PMBudget.accountGroupID> >,
                                                                        And <PMBudget.projectID, Equal <Required <PMBudget.projectID> >,
                                                                             And <PMBudget.projectTaskID, Equal <Required <PMBudget.projectTaskID> >,
                                                                                  And <Where <PMBudget.costCodeID, Equal <Required <PMBudget.costCodeID> >, Or <PMBudget.costCodeID, Equal <Required <PMBudget.costCodeID> > > > > > > > >(graph);

            PMBudget withCostCode    = null;
            PMBudget withoutCostCode = null;

            foreach (PMBudget item in selectBudget.Select(filter.AccountGroupID, filter.ProjectID, filter.TaskID, filter.CostCodeID, CostCodeAttribute.GetDefaultCostCode()))            //0..2 records
            {
                if (item.CostCodeID == CostCodeAttribute.GetDefaultCostCode())
                {
                    withoutCostCode = item;
                }
                else
                {
                    withCostCode = item;
                }
            }

            return(withCostCode ?? withoutCostCode);
        }
Example #5
0
 public Result(IList <PMHistory> history, PMBudget status, PMTaskTotal taskTotal, PMForecastHistory forecast)
 {
     this.History         = history;
     this.Status          = status;
     this.TaskTotal       = taskTotal;
     this.ForecastHistory = forecast;
 }
        public virtual RollupQty CalculateRollupQty <T>(T row, PMBudget status, decimal?quantity) where T : IBqlTable, IQuantify
        {
            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 == PMInventorySelectorAttribute.EmptyInventoryID)
                {
                    //<Other> item is present. Update only if UOMs are convertable.
                    decimal convertedQty;
                    if (IN.INUnitAttribute.TryConvertGlobalUnits(graph, row.UOM, status.UOM, quantity.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 != row.UOM && !string.IsNullOrEmpty(status.UOM) && !string.IsNullOrEmpty(row.UOM))
                    {
                        if (PXAccess.FeatureInstalled <FeaturesSet.multipleUnitMeasure>())
                        {
                            decimal inBase = IN.INUnitAttribute.ConvertToBase(graph.Caches[typeof(T)], row.InventoryID, row.UOM, quantity ?? 0, IN.INPrecision.QUANTITY);
                            try
                            {
                                rollupQty = IN.INUnitAttribute.ConvertFromBase(graph.Caches[typeof(T)], row.InventoryID, status.UOM, inBase, IN.INPrecision.QUANTITY);
                            }
                            catch (PX.Objects.IN.PXUnitConversionException ex)
                            {
                                IN.InventoryItem item = PXSelectorAttribute.Select(graph.Caches[typeof(T)], row, "inventoryID") as IN.InventoryItem;
                                string           msg  = PXMessages.LocalizeFormatNoPrefixNLA(Messages.UnitConversionNotDefinedForItemOnBudgetUpdate, item?.BaseUnit, status.UOM, item?.InventoryCD);

                                throw new PXException(msg, ex);
                            }
                        }
                        else
                        {
                            rollupQty = IN.INUnitAttribute.ConvertGlobalUnits(graph, row.UOM, status.UOM, quantity ?? 0, IN.INPrecision.QUANTITY);
                        }
                    }
                    else if (!string.IsNullOrEmpty(status.UOM))
                    {
                        rollupQty = quantity ?? 0;
                    }
                }
            }

            return(new RollupQty(UOM, rollupQty));
        }
    protected void BudgetGrid_RowDataBound(object sender, PX.Web.UI.PXGridRowEventArgs e)
    {
        PMBudget item = e.Row.DataItem as PMBudget;

        if (item != null && item.SortOrder == 1)
        {
            e.Row.Style.CssClass = "BoldText";
        }
    }
        protected virtual void _(Events.FieldUpdated <PMBudget, PMCostBudget.amount> e)
        {
            if (e.Row != null)
            {
                PMBudget  row     = (PMBudget)e.Row;
                PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, row.ProjectID);

                if (project?.BudgetFinalized == true)
                {
                    row.Amount = e.OldValue as decimal?;
                }
            }
        }
Example #9
0
        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);
                }

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

                if (ps != null)
                {
                    e.Cancel = true;
                    throw new PXException(Messages.ProjectStatus_FK);
                }
            }
        }
Example #10
0
        private bool IsBalanceExist()
        {
            PMBudget status = PXSelect <PMBudget, Where <PMBudget.accountGroupID, Equal <Current <PMAccountGroup.groupID> > > > .SelectWindowed(this, 0, 1);

            return(status != null);
        }
 public Result(IList <PMHistory> history, PMBudget status, PMTaskTotal taskTotal)
 {
     this.History   = history;
     this.Status    = status;
     this.TaskTotal = taskTotal;
 }
 public virtual RollupQty CalculateRollupQty <T>(T row, PMBudget status) where T : IBqlTable, IQuantify
 {
     return(CalculateRollupQty(row, status, row.Qty));
 }
        public virtual Result Calculate(PMTran pmt, PMAccountGroup ag, Account acc, int mult)
        {
            PMBudget status = SelectProjectBalance(pmt);

            int?      inventoryID = status != null ? status.InventoryID : PMInventorySelectorAttribute.EmptyInventoryID;
            int?      costCodeID  = status != null ? status.CostCodeID : CostCodeAttribute.GetDefaultCostCode();
            RollupQty rollup      = null;

            if (settings.CostBudgetUpdateMode == CostBudgetUpdateModes.Detailed && ag.IsExpense == true && pmt.InventoryID != settings.EmptyInventoryID)
            {
                if (status == null || status.InventoryID == settings.EmptyInventoryID)
                {
                    rollup      = new RollupQty(pmt.UOM, pmt.Qty);
                    inventoryID = pmt.InventoryID;
                    if (pmt.CostCodeID != null)
                    {
                        costCodeID = pmt.CostCodeID;
                    }
                }
            }

            if (rollup == null)
            {
                rollup = CalculateRollupQty(pmt, status);
            }

            List <PMHistory> list = new List <PMHistory>();

            PMTaskTotal ta = null;
            PMBudget    ps = null;

            if (pmt.TaskID != null && (rollup.Qty != 0 || pmt.Amount != 0))             //TaskID will be null for Contract
            {
                ps                = new PMBudget();
                ps.ProjectID      = pmt.ProjectID;
                ps.ProjectTaskID  = pmt.TaskID;
                ps.AccountGroupID = ag.GroupID;
                if (ag.Type == PMAccountType.OffBalance)
                {
                    ps.Type = ag.IsExpense == true ? GL.AccountType.Expense : ag.Type;
                }
                else
                {
                    ps.Type = ag.Type;
                }
                ps.InventoryID = inventoryID;
                ps.CostCodeID  = costCodeID;
                ps.UOM         = rollup.UOM;
                if (status != null)
                {
                    ps.IsProduction = status.IsProduction;
                }

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

                if (!string.IsNullOrEmpty(ps.UOM))
                {
                    ps.ActualQty = rollup.Qty;                     // commented out otherwise invoice produces -ve Qty. * mult;
                }
                ps.ActualAmount = amt;

                #region PMTask Totals Update

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

                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;
                }

                #endregion

                #region History
                PMHistory hist = new PMHistory();
                hist.ProjectID      = pmt.ProjectID;
                hist.ProjectTaskID  = pmt.TaskID;
                hist.AccountGroupID = ag.GroupID;
                hist.InventoryID    = pmt.InventoryID ?? PMInventorySelectorAttribute.EmptyInventoryID;
                hist.CostCodeID     = pmt.CostCodeID ?? CostCodeAttribute.GetDefaultCostCode();
                hist.PeriodID       = pmt.FinPeriodID;
                decimal baseQty = 0;
                list.Add(hist);
                if (pmt.InventoryID != null && pmt.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID && pmt.Qty != 0 && !string.IsNullOrEmpty(rollup.UOM))
                {
                    if (PXAccess.FeatureInstalled <FeaturesSet.multipleUnitMeasure>())
                    {
                        baseQty = mult * IN.INUnitAttribute.ConvertToBase(graph.Caches[typeof(PMHistory)], pmt.InventoryID, pmt.UOM, pmt.Qty.Value, PX.Objects.IN.INPrecision.QUANTITY);
                    }
                    else
                    {
                        IN.InventoryItem initem = PXSelectorAttribute.Select <PMTran.inventoryID>(graph.Caches[typeof(PMTran)], pmt) as IN.InventoryItem;
                        if (initem != null)
                        {
                            baseQty = mult * IN.INUnitAttribute.ConvertGlobalUnits(graph, pmt.UOM, initem.BaseUnit, pmt.Qty ?? 0, 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.PMInventorySelectorAttribute.EmptyInventoryID;
                    tranHist.CostCodeID     = pmt.CostCodeID ?? CostCodeAttribute.GetDefaultCostCode();
                    tranHist.PeriodID       = pmt.TranPeriodID;
                    list.Add(tranHist);
                    tranHist.TranPTDAmount = amt;
                    tranHist.TranYTDAmount = amt;
                    tranHist.TranPTDQty    = baseQty;
                    tranHist.TranYTDQty    = baseQty;
                }
                #endregion
            }
            return(new Result(list, ps, ta));
        }
 private BudgetKeyTuple GetKey(PMBudget record)
 {
     return(new BudgetKeyTuple(record.ProjectID.Value, record.ProjectTaskID.Value, record.AccountGroupID.Value, record.InventoryID.Value, record.CostCodeID.Value));
 }
Example #15
0
        public virtual Result Calculate(PMProject project, PMTran pmt, PMAccountGroup ag, string accountType, int amountSign, int qtySign)
        {
            PMBudgetLite target = null;
            bool         isExisting;

            target = service.SelectProjectBalance(pmt, ag, project, out isExisting);

            var rollupQty = CalculateRollupQty(pmt, target);

            List <PMHistory>  list     = new List <PMHistory>();
            PMTaskTotal       ta       = null;
            PMBudget          ps       = null;
            PMForecastHistory forecast = null;

            if (pmt.TaskID != null && (rollupQty != 0 || pmt.Amount != 0))             //TaskID will be null for Contract
            {
                ps                = new PMBudget();
                ps.ProjectID      = target.ProjectID;
                ps.ProjectTaskID  = target.TaskID;
                ps.AccountGroupID = target.AccountGroupID;
                ps.Type           = target.Type;
                ps.InventoryID    = target.InventoryID;
                ps.CostCodeID     = target.CostCodeID;
                ps.UOM            = target.UOM;
                ps.IsProduction   = target.IsProduction;
                ps.Description    = target.Description;
                if (ps.CuryInfoID == null)
                {
                    ps.CuryInfoID = project.CuryInfoID;
                }
                decimal amt     = amountSign * pmt.Amount.GetValueOrDefault();
                decimal curyAmt = amountSign * pmt.ProjectCuryAmount.GetValueOrDefault();

                ps.ActualQty        = rollupQty * qtySign;
                ps.ActualAmount     = amt;
                ps.CuryActualAmount = curyAmt;

                #region PMTask Totals Update

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

                string accType = ag.IsExpense == true ? AccountType.Expense : ag.Type;
                switch (accType)
                {
                case AccountType.Asset:
                    ta.CuryAsset = curyAmt;
                    ta.Asset     = amt;
                    break;

                case AccountType.Liability:
                    ta.CuryLiability = curyAmt;
                    ta.Liability     = amt;
                    break;

                case AccountType.Income:
                    ta.CuryIncome = curyAmt;
                    ta.Income     = amt;
                    break;

                case AccountType.Expense:
                    ta.CuryExpense = curyAmt;
                    ta.Expense     = amt;
                    break;
                }

                #endregion

                #region History
                PMHistory hist = new PMHistory();
                hist.ProjectID      = ps.ProjectID;
                hist.ProjectTaskID  = ps.TaskID;
                hist.AccountGroupID = ps.AccountGroupID;
                hist.InventoryID    = pmt.InventoryID ?? ps.InventoryID;
                hist.CostCodeID     = pmt.CostCodeID ?? ps.CostCodeID;
                hist.PeriodID       = pmt.FinPeriodID;
                hist.BranchID       = pmt.BranchID;
                decimal baseQty = 0;
                list.Add(hist);
                if (pmt.InventoryID != null && pmt.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID && pmt.Qty != 0)
                {
                    if (PXAccess.FeatureInstalled <FeaturesSet.multipleUnitMeasure>())
                    {
                        baseQty = qtySign * IN.INUnitAttribute.ConvertToBase(graph.Caches[typeof(PMHistory)], pmt.InventoryID, pmt.UOM, pmt.Qty.Value, PX.Objects.IN.INPrecision.QUANTITY);
                    }
                    else
                    {
                        IN.InventoryItem initem = PXSelectorAttribute.Select <PMTran.inventoryID>(graph.Caches[typeof(PMTran)], pmt) as IN.InventoryItem;
                        if (initem != null && !string.IsNullOrEmpty(pmt.UOM))
                        {
                            baseQty = qtySign * IN.INUnitAttribute.ConvertGlobalUnits(graph, pmt.UOM, initem.BaseUnit, pmt.Qty ?? 0, IN.INPrecision.QUANTITY);
                        }
                    }
                }
                hist.FinPTDCuryAmount = curyAmt;
                hist.FinPTDAmount     = amt;
                hist.FinYTDCuryAmount = curyAmt;
                hist.FinYTDAmount     = amt;
                hist.FinPTDQty        = baseQty;
                hist.FinYTDQty        = baseQty;
                if (pmt.FinPeriodID == pmt.TranPeriodID)
                {
                    hist.TranPTDCuryAmount = curyAmt;
                    hist.TranPTDAmount     = amt;
                    hist.TranYTDCuryAmount = curyAmt;
                    hist.TranYTDAmount     = amt;
                    hist.TranPTDQty        = baseQty;
                    hist.TranYTDQty        = baseQty;
                }
                else
                {
                    PMHistory tranHist = new PMHistory();
                    tranHist.ProjectID      = ps.ProjectID;
                    tranHist.ProjectTaskID  = ps.TaskID;
                    tranHist.AccountGroupID = ps.AccountGroupID;
                    tranHist.InventoryID    = pmt.InventoryID ?? PM.PMInventorySelectorAttribute.EmptyInventoryID;
                    tranHist.CostCodeID     = pmt.CostCodeID ?? CostCodeAttribute.GetDefaultCostCode();
                    tranHist.PeriodID       = pmt.TranPeriodID;
                    tranHist.BranchID       = pmt.BranchID;
                    list.Add(tranHist);
                    tranHist.TranPTDCuryAmount = curyAmt;
                    tranHist.TranPTDAmount     = amt;
                    tranHist.TranYTDCuryAmount = curyAmt;
                    tranHist.TranYTDAmount     = amt;
                    tranHist.TranPTDQty        = baseQty;
                    tranHist.TranYTDQty        = baseQty;
                }
                #endregion

                forecast                  = new PMForecastHistory();
                forecast.ProjectID        = ps.ProjectID;
                forecast.ProjectTaskID    = ps.ProjectTaskID;
                forecast.AccountGroupID   = ps.AccountGroupID;
                forecast.InventoryID      = ps.InventoryID;
                forecast.CostCodeID       = ps.CostCodeID;
                forecast.PeriodID         = pmt.TranPeriodID;
                forecast.ActualQty        = ps.ActualQty;
                forecast.CuryActualAmount = ps.CuryActualAmount;
                forecast.ActualAmount     = ps.ActualAmount;
            }
            return(new Result(list, ps, ta, forecast));
        }