예제 #1
0
        public override void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
        {
            List <string> allowedValues = new List <string>();
            List <string> allowedLabels = new List <string>();

            allowedValues.Add(BudgetLevels.Task);
            allowedLabels.Add(PXMessages.LocalizeNoPrefix(Messages.Task));

            if (CostCodeAttribute.UseCostCode())
            {
                allowedValues.Add(BudgetLevels.CostCode);
                allowedLabels.Add(PXMessages.LocalizeNoPrefix(Messages.BudgetLevel_CostCode));
            }

            allowedValues.Add(BudgetLevels.Item);
            allowedLabels.Add(PXMessages.LocalizeNoPrefix(Messages.BudgetLevel_Item));

            if (CostCodeAttribute.UseCostCode() && PXAccess.FeatureInstalled <CS.FeaturesSet.construction>())
            {
                allowedValues.Add(BudgetLevels.Detail);
                allowedLabels.Add(PXMessages.LocalizeNoPrefix(Messages.BudgetLevel_Detail));
            }

            _AllowedValues = allowedValues.ToArray();

            _AllowedLabels = allowedLabels.ToArray();

            base.FieldSelecting(sender, e);
        }
 protected virtual void _(Events.FieldDefaulting <PMCommitment, PMCommitment.costCodeID> e)
 {
     if (!CostCodeAttribute.UseCostCode())
     {
         e.NewValue = CostCodeAttribute.GetDefaultCostCode();
     }
 }
        protected virtual void _(Events.FieldDefaulting <PMBudget, PMBudget.description> e)
        {
            if (e.Row == null)
            {
                return;
            }

            if (CostCodeAttribute.UseCostCode())
            {
                if (e.Row.CostCodeID != null && e.Row.CostCodeID != CostCodeAttribute.GetDefaultCostCode())
                {
                    PMCostCode costCode = PXSelectorAttribute.Select <PMBudget.costCodeID>(e.Cache, e.Row) as PMCostCode;
                    if (costCode != null)
                    {
                        e.NewValue = costCode.Description;
                    }
                }
            }
            else
            {
                if (e.Row.InventoryID != null && e.Row.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID)
                {
                    InventoryItem item = PXSelectorAttribute.Select <PMBudget.inventoryID>(e.Cache, e.Row) as InventoryItem;
                    if (item != null)
                    {
                        e.NewValue = item.Descr;
                    }
                }
            }
        }
 protected virtual void _(Events.FieldDefaulting <PMBudget, PMBudget.inventoryID> e)
 {
     if (CostCodeAttribute.UseCostCode())
     {
         e.NewValue = PMInventorySelectorAttribute.EmptyInventoryID;
     }
 }
 public virtual PMBudget SelectProjectBalance(IProjectFilter filter)
 {
     if (CostCodeAttribute.UseCostCode())
     {
         return(SelectProjectBalanceByCostCodes(filter));
     }
     else
     {
         return(SelectProjectBalanceByInventory(filter));
     }
 }
예제 #6
0
        protected virtual void _(Events.FieldDefaulting <ARTran, ARTran.costCodeID> e)
        {
            PMProject project;

            if (CostCodeAttribute.UseCostCode() && ProjectDefaultAttribute.IsProject(Base, e.Row.ProjectID, out project))
            {
                if (project.BudgetLevel == BudgetLevels.Task)
                {
                    e.NewValue = CostCodeAttribute.GetDefaultCostCode();
                }
            }
        }
        public bool PrepareImportRow(string viewName, IDictionary keys, IDictionary values)
        {
            if (!CostCodeAttribute.UseCostCode())
            {
                PMCostCode defaultCostCode = PXSelect <PMCostCode, Where <PMCostCode.isDefault, Equal <True> > > .Select(this);

                if (defaultCostCode != null)
                {
                    keys[nameof(PMBudget.CostCodeID)]   = defaultCostCode.CostCodeCD;
                    values[nameof(PMBudget.CostCodeID)] = defaultCostCode.CostCodeCD;
                }
            }

            return(true);
        }
        protected virtual void _(Events.FieldUpdated <PMBudget, PMCostBudget.costCodeID> e)
        {
            if (CostCodeAttribute.UseCostCode())
            {
                //Current record may be in process of importing from excel. In this case all we have is pending values for description, Uom, Rate
                string pendingDescription = null;
                string pendingUom         = null;

                object pendingDescriptionObj = Items.Cache.GetValuePending <PMBudget.description>(e.Row);
                object pendingUomObj         = Items.Cache.GetValuePending <PMBudget.uOM>(e.Row);

                if (pendingDescriptionObj != null && pendingDescriptionObj != PXCache.NotSetValue)
                {
                    pendingDescription = (string)pendingDescriptionObj;
                }

                if (pendingUomObj != null && pendingUomObj != PXCache.NotSetValue)
                {
                    pendingUom = (string)pendingUomObj;
                }

                object pendingRate = Items.Cache.GetValuePending <PMBudget.rate>(e.Row);

                if (string.IsNullOrEmpty(pendingDescription))
                {
                    e.Cache.SetDefaultExt <PMBudget.description>(e.Row);
                }

                if (string.IsNullOrEmpty(pendingUom))
                {
                    e.Cache.SetDefaultExt <PMBudget.uOM>(e.Row);
                }

                if (pendingRate == null)
                {
                    e.Cache.SetDefaultExt <PMBudget.rate>(e.Row);
                }
            }
        }
        public virtual void InitCostCodeOnModifiedEntities()
        {
            if (CostCodeAttribute.UseCostCode())
            {
                int?defaultCostCodeID = CostCodeAttribute.DefaultCostCode;
                foreach (POLine line in polines.Cache.Updated)
                {
                    if (line.CostCodeID == null)
                    {
                        polines.Cache.SetValue <POLine.costCodeID>(line, defaultCostCodeID);
                    }
                }

                foreach (SOLine line in solines.Cache.Updated)
                {
                    if (line.CostCodeID == null)
                    {
                        solines.Cache.SetValue <POLine.costCodeID>(line, defaultCostCodeID);
                    }
                }
            }
        }
예제 #10
0
        public virtual void AddToInvoiced(ARTran line, int?revenueAccountGroup, int mult = 1)
        {
            if (line.TaskID == null)
            {
                return;
            }

            if (revenueAccountGroup == null)
            {
                return;
            }

            if (CostCodeAttribute.UseCostCode() && line.CostCodeID == null)
            {
                return;
            }

            PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(Base, line.ProjectID);

            if (project != null && project.NonProject != true)
            {
                PMBudgetAccum invoiced = GetTargetBudget(revenueAccountGroup, line);
                invoiced = Base.Budget.Insert(invoiced);


                if (project.CuryID == project.BillingCuryID)
                {
                    invoiced.CuryInvoicedAmount += mult * (line.CuryTranAmt.GetValueOrDefault() + line.CuryRetainageAmt.GetValueOrDefault());
                    invoiced.InvoicedAmount     += mult * (line.TranAmt.GetValueOrDefault() + line.RetainageAmt.GetValueOrDefault());
                }
                else
                {
                    invoiced.CuryInvoicedAmount += mult * (line.TranAmt.GetValueOrDefault() + line.RetainageAmt.GetValueOrDefault());
                    invoiced.InvoicedAmount     += mult * (line.TranAmt.GetValueOrDefault() + line.RetainageAmt.GetValueOrDefault());
                }
            }
        }
예제 #11
0
        protected virtual void _(Events.RowSelected <PMTask> e)
        {
            if (e.Row != null)
            {
                PMProject prj = PXSelect <PMProject, Where <PMProject.contractID, Equal <Current <PMTask.projectID> > > > .SelectSingleBound(this, new object[] { e.Row });

                PXUIFieldAttribute.SetEnabled <PMTask.autoIncludeInPrj>(e.Cache, e.Row, prj != null && prj.NonProject != true);
                PXUIFieldAttribute.SetVisible <PMBudget.inventoryID>(Budget.Cache, null, !CostCodeAttribute.UseCostCode());
                PXUIFieldAttribute.SetVisibility <PMBudget.inventoryID>(Budget.Cache, null, !CostCodeAttribute.UseCostCode() ? PXUIVisibility.Visible : PXUIVisibility.Invisible);
            }
        }
        public virtual Result Calculate(PMProject project, PMTran pmt, PMAccountGroup ag, Account acc, int mult)
        {
            PMBudget existing = null;

            if (ag.Type == GL.AccountType.Income && project.BudgetLevel != BudgetLevels.CostCode)
            {
                existing = SelectProjectBalanceByInventory(pmt);
            }
            else
            {
                existing = SelectProjectBalance(pmt);
            }

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

            if (CostCodeAttribute.UseCostCode())
            {
                if (settings.CostBudgetUpdateMode == CostBudgetUpdateModes.Detailed && ag.IsExpense == true)
                {
                    if (existing == null || existing.CostCodeID == CostCodeAttribute.GetDefaultCostCode())
                    {
                        rollup = new RollupQty(pmt.UOM, pmt.Qty);
                        if (pmt.CostCodeID != null)
                        {
                            costCodeID = pmt.CostCodeID;
                        }
                    }
                }
                else if (ag.Type == GL.AccountType.Income && project.BudgetLevel != BudgetLevels.CostCode)
                {
                    costCodeID = CostCodeAttribute.GetDefaultCostCode();
                }
            }
            else
            {
                if (settings.CostBudgetUpdateMode == CostBudgetUpdateModes.Detailed && ag.IsExpense == true && pmt.InventoryID != settings.EmptyInventoryID)
                {
                    if (existing == null || existing.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, existing);
            }

            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 (existing != null)
                {
                    ps.IsProduction = existing.IsProduction;
                    ps.Description  = existing.Description;
                }
                else
                {
                    //initialize description:
                    if (CostCodeAttribute.UseCostCode())
                    {
                        PMCostCode costCode = PXSelect <PMCostCode, Where <PMCostCode.costCodeID, Equal <Required <PMCostCode.costCodeID> > > > .Select(graph, ps.CostCodeID);

                        if (costCode != null)
                        {
                            ps.Description = costCode.Description;
                        }
                    }
                    else if (inventoryID != PMInventorySelectorAttribute.EmptyInventoryID)
                    {
                        InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(graph, inventoryID);

                        if (item != null)
                        {
                            ps.Description = item.Descr;
                        }
                    }
                }

                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;

                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.
                    if (IsFlipRequired(acc.Type, ag.Type))
                    {
                        multFix = -1;
                    }
                }

                string accType = ag.Type == PMAccountType.OffBalance && ag.IsExpense == true ? AccountType.Expense : 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)
                {
                    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));
        }
 public override void FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e)
 {
     _AllowedValues = CostCodeAttribute.UseCostCode() ? new string[] { BudgetLevels.Task, BudgetLevels.CostCode, BudgetLevels.Item } : new string[] { BudgetLevels.Task, BudgetLevels.Item };
     _AllowedLabels = CostCodeAttribute.UseCostCode() ? new string[] { Messages.Task, Messages.BudgetLevel_CostCode, Messages.BudgetLevel_Item } : new string[] { Messages.Task, Messages.BudgetLevel_Item };
     base.FieldSelecting(sender, e);
 }