Beispiel #1
0
        private static decimal GetAmountFromPMHistory(RMDataSource ds, PMHistory hist)
        {
            //We always use the PTD amounts; depending on BalanceType we will expand our calculation to more periods (GetPeriodsToCalculate)
            switch (ds.AmountType.Value)
            {
            case BalanceType.Amount:
            case BalanceType.TurnoverAmount:
                return(hist.FinPTDAmount.Value);

            case BalanceType.Quantity:
            case BalanceType.TurnoverQuantity:
                return(hist.FinPTDQty.Value);

            case BalanceType.BudgetAmount:
            case BalanceType.BudgetPTDAmount:
                return(hist.PTDBudgetAmount.Value);

            case BalanceType.BudgetQuantity:
            case BalanceType.BudgetPTDQuantity:
                return(hist.PTDBudgetQty.Value);

            case BalanceType.RevisedAmount:
            case BalanceType.RevisedPTDAmount:
                return(hist.PTDRevisedAmount.Value);

            case BalanceType.RevisedQuantity:
            case BalanceType.RevisedPTDQuantity:
                return(hist.PTDRevisedQty.Value);

            default:
                System.Diagnostics.Debug.Assert(false, "Unknown amount type: " + ds.AmountType.Value);
                return(0);
            }
        }
Beispiel #2
0
        public virtual void dataSourceFieldSelecting(PXFieldSelectingEventArgs e, string field)
        {
            RMReport     report     = (RMReport)e.Row;
            RMDataSource dataSource = report != null?Base.DataSourceByID.Select(report.DataSourceID) : null;

            if (dataSource == null)
            {
                object defValue;
                if (Base.DataSourceByID.Cache.RaiseFieldDefaulting(field, null, out defValue))
                {
                    Base.DataSourceByID.Cache.RaiseFieldUpdating(field, null, ref defValue);
                }
                Base.DataSourceByID.Cache.RaiseFieldSelecting(field, null, ref defValue, true);
                e.ReturnState = defValue;
            }
            else
            {
                e.ReturnState = Base.DataSourceByID.Cache.GetStateExt(dataSource, field);
            }

            //Fix AmountType Combo for PM:
            if (report != null && report.Type == RMType.PM && field.Equals(typeof(RMDataSource.amountType).Name, StringComparison.InvariantCultureIgnoreCase))
            {
                e.ReturnState = PXIntState.CreateInstance(e.ReturnValue, field, false, 0, null, null,
                                                          new int[] { BalanceType.NotSet, BalanceType.Amount, BalanceType.Quantity, BalanceType.TurnoverAmount, BalanceType.TurnoverQuantity, BalanceType.BudgetAmount, BalanceType.BudgetQuantity, BalanceType.RevisedAmount, BalanceType.RevisedQuantity, BalanceType.OriginalCommittedAmount, BalanceType.OriginalCommittedQuantity, BalanceType.CommittedAmount, BalanceType.CommittedQuantity, BalanceType.CommittedOpenAmount, BalanceType.CommittedOpenQuantity, BalanceType.CommittedReceivedQuantity, BalanceType.CommittedInvoicedAmount, BalanceType.CommittedInvoicedQuantity },
                                                          new string[]
                {
                    Messages.GetLocal(Messages.NotSet),
                    Messages.GetLocal(Messages.ActualAmount),
                    Messages.GetLocal(Messages.ActualQuantity),
                    Messages.GetLocal(Messages.AmountTurnover),
                    Messages.GetLocal(Messages.QuantityTurnover),
                    Messages.GetLocal(Messages.BudgetAmount),
                    Messages.GetLocal(Messages.BudgetQuantity),
                    Messages.GetLocal(Messages.RevisedAmount),
                    Messages.GetLocal(Messages.RevisedQuantity),
                    Messages.GetLocal(Messages.OriginalCommittedAmount),
                    Messages.GetLocal(Messages.OriginalCommittedQuantity),
                    Messages.GetLocal(Messages.CommittedAmount),
                    Messages.GetLocal(Messages.CommittedQuantity),
                    Messages.GetLocal(Messages.CommittedOpenAmount),
                    Messages.GetLocal(Messages.CommittedOpenQuantity),
                    Messages.GetLocal(Messages.CommittedReceivedQuantity),
                    Messages.GetLocal(Messages.CommittedInvoicedAmount),
                    Messages.GetLocal(Messages.CommittedInvoicedQuantity)
                },
                                                          typeof(short), 0);
                ((PXFieldState)e.ReturnState).DisplayName = Messages.GetLocal(Messages.AmountType);
            }

            Base1.dataSourceFieldSelecting(e, field);

            if (e.ReturnState is PXFieldState)
            {
                ((PXFieldState)e.ReturnState).SetFieldName("DataSource" + field);
                ((PXFieldState)e.ReturnState).Visible = Base.IsFieldVisible(field, report);
            }
        }
Beispiel #3
0
        public void FillDataSource(RMDataSource ds, ARmDataSet dst, string rmType, Action <RMDataSource, ARmDataSet, string> del)
        {
            del(ds, dst, rmType);

            if (rmType == ARmReport.PM)
            {
                FillDataSourceInternal(ds, dst, rmType);
            }
        }
Beispiel #4
0
 private void FillDataSourceInternal(RMDataSource ds, ARmDataSet dst, string rmType)
 {
     if (ds != null && ds.DataSourceID != null)
     {
         RMDataSourcePM dsPM = Base.Caches[typeof(RMDataSource)].GetExtension <RMDataSourcePM>(ds);
         dst[Keys.StartAccountGroup] = dsPM.StartAccountGroup;
         dst[Keys.EndAccountGroup]   = dsPM.EndAccountGroup;
         dst[Keys.StartProject]      = dsPM.StartProject;
         dst[Keys.EndProject]        = dsPM.EndProject;
         dst[Keys.StartProjectTask]  = dsPM.StartProjectTask;
         dst[Keys.EndProjectTask]    = dsPM.EndProjectTask;
         dst[Keys.StartInventory]    = dsPM.StartInventory;
         dst[Keys.EndInventory]      = dsPM.EndInventory;
     }
 }
        public static bool AccountClassInUse(PXGraph graph, string accountClassID, out string usedIn)
        {
            usedIn = null;
            Account account = (Account)PXSelect <Account, Where <Account.accountClassID, Equal <Required <AccountClass.accountClassID> > > > .SelectSingleBound(graph, null, accountClassID);

            if (account != null)
            {
                usedIn = Messages.Account + account.AccountCD;
            }
            else
            {
                RMDataSource rmds = PXSelect <RMDataSource, Where <RMDataSourceGL.accountClassID, Equal <Required <AccountClass.accountClassID> > > > .SelectSingleBound(graph, null, accountClassID);

                if (rmds != null)
                {
                    usedIn = Messages.RMDataSource;
                }
            }

            return(usedIn != null);
        }
        protected virtual void AccountClass_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            AccountClass row = (AccountClass)e.Row;

            Account account_rec = (Account)PXSelect <Account, Where <Account.accountClassID, Equal <Required <AccountClass.accountClassID> > > > .SelectWindowed(this, 0, 1, row.AccountClassID);

            if (account_rec != null)
            {
                throw new PXException(Messages.ThisAccountClassMayNotBeDeletedBecauseItIsUsedIn, "Account: " + account_rec.AccountCD);
            }

            RMDataSource rmds_rec = PXSelect <RMDataSource, Where <RMDataSourceGL.accountClassID, Equal <Required <AccountClass.accountClassID> > > > .SelectWindowed(this, 0, 1, row.AccountClassID);

            if (rmds_rec != null)
            {
                throw new PXException(Messages.ThisAccountClassMayNotBeDeletedBecauseItIsUsedIn, "Analitycal Report Manager");
            }
        }
Beispiel #7
0
    protected void Page_Init(object sender, EventArgs e)
    {
        RMReportMaint graph = (RMReportMaint)ds.DataGraph;

        PXDataSourceViewSchema schema = ds.GetSchema("Report");

        RMReport    currentReport     = graph.Report.Current;
        RMRowSet    currentRowSet     = (RMRowSet)graph.Caches[typeof(RMRowSet)].Current;
        RMColumnSet currentColumnSet  = (RMColumnSet)graph.Caches[typeof(RMColumnSet)].Current;
        RMUnitSet   currentUnitSet    = (RMUnitSet)graph.Caches[typeof(RMUnitSet)].Current;
        string      currentTypeReport = currentReport != null ? currentReport.Type : null;

        RMDataSource currentDataSource = graph.DataSourceByID.Current;

        if (currentTypeReport == null)
        {
            graph.Report.Current = currentReport = new RMReport();
        }
        if (currentRowSet == null)
        {
            graph.Caches[typeof(RMRowSet)].Current = new RMRowSet();
        }
        graph.Caches[typeof(RMColumnSet)].Current = null;
        graph.Caches[typeof(RMUnitSet)].Current   = null;

        Dictionary <string, List <PXFieldSchema> > controls = new Dictionary <string, List <PXFieldSchema> >();

        string[] arrTypes = ((PXStringState)graph.Report.Cache.GetStateExt <RMReport.type>(null)).AllowedValues;

        foreach (string type in arrTypes)
        {
            graph.Report.Current.Type = type;
            ((RMRowSet)graph.Caches[typeof(RMRowSet)].Current).Type = type;
            graph.Report.Current = currentReport;

            graph.DataSourceByID.Current = null;

            List <PXFieldSchema> lControls = new List <PXFieldSchema>();
            List <PXFieldSchema> list      = RefreshFieldsList(schema, graph);

            foreach (PXFieldSchema f in list)
            {
                if (f.DataType == TypeCode.Object)
                {
                    continue;
                }
                if (!ContainsControlDictionary(f, controls))
                {
                    lControls.Add(f);
                }
            }
            controls.Add(type, lControls);
        }

        if (currentTypeReport == null)
        {
            graph.Report.Cache.Clear();
        }
        else
        {
            graph.Report.Current.Type = currentTypeReport;
        }

        graph.DataSourceByID.Current              = currentDataSource;
        graph.Caches[typeof(RMRowSet)].Current    = currentRowSet;
        graph.Caches[typeof(RMColumnSet)].Current = currentColumnSet;
        graph.Caches[typeof(RMUnitSet)].Current   = currentUnitSet;

        _insertIndex = 0;
        foreach (Control control in this.form.TemplateContainer.Controls)
        {
            if (!string.IsNullOrEmpty(control.ID))
            {
                if (!control.ID.Equals("edStartUnitCode", StringComparison.OrdinalIgnoreCase))
                {
                    _insertIndex++;
                }
                else
                {
                    break;
                }
            }
            else
            {
                _insertIndex++;
            }
        }
        _insertIndex++;

        PXLayoutRule rule1 = new PXLayoutRule()
        {
            ID = "rule1", StartGroup = true, GroupCaption = "Default Data Source Settings"
        };

        (rule1).ApplyStyleSheetSkin(this.Page);
        this.form.TemplateContainer.Controls.AddAt(_insertIndex, rule1);
        _insertIndex++;

        for (int c = arrTypes.Length - 1; c >= 0; c--)
        {
            string type = arrTypes[c];
            List <PXFieldSchema> lDsControls = new List <PXFieldSchema>();

            for (int i = 0; i < controls[type].Count; i++)
            {
                if (controls[type][i].DataField.StartsWith("DataSource", StringComparison.OrdinalIgnoreCase) &&
                    !controls[type][i].DataField.Equals("datasourceexpand", StringComparison.OrdinalIgnoreCase) &&
                    !controls[type][i].DataField.Equals("datasourceamounttype", StringComparison.OrdinalIgnoreCase) &&
                    !controls[type][i].DataField.Equals("datasourcestartPeriodOffset", StringComparison.OrdinalIgnoreCase) &&
                    !controls[type][i].DataField.Equals("datasourceEndPeriodOffset", StringComparison.OrdinalIgnoreCase)
                    //ContainsControl("Request" + controls[type][i].DataField.Replace("DataSource", string.Empty), controls[type])
                    )
                {
                    lDsControls.Add(controls[type][i]);
                }
            }

            int cntFirstColumn = lDsControls.Count / 2;
            if ((lDsControls.Count % 2) > 0)
            {
                cntFirstColumn++;
            }

            for (int i = 0; i < cntFirstColumn; i++)
            {
                AddControl(lDsControls[i], controls[type]);
                if ((lDsControls.Count - 1) >= (i + cntFirstColumn))
                {
                    AddControl(lDsControls[i + cntFirstColumn], controls[type]);
                }
            }
        }

        PXDropDown edDataSourceAmountType = new PXDropDown()
        {
            ID = "edDataSourceAmountType", AllowNull = false, DataField = "DataSourceAmountType"
        };

        form.TemplateContainer.Controls.AddAt(_insertIndex, edDataSourceAmountType);
        (edDataSourceAmountType).ApplyStyleSheetSkin(this.Page);
        _insertIndex++;

        PXCheckBox chkApplyRestrictionGroups = new PXCheckBox()
        {
            ID = "chkApplyRestrictionGroups", DataField = "ApplyRestrictionGroups"
        };

        form.TemplateContainer.Controls.AddAt(_insertIndex, chkApplyRestrictionGroups);
        (chkApplyRestrictionGroups).ApplyStyleSheetSkin(this.Page);
    }
        public static List <ARmUnit> ExpandUnit(RMReportReader report, RMDataSource ds, ARmUnit unit, object startKey, object endKey, Func <ARmDataSet, List <T> > fetchRangePredicate, Func <T, string> unitCodePredicate, Func <T, string> unitDescriptionPredicate, Action <T, string> applyWildcardToItemAction)
        {
            string nonExpandingWildcard = null;

            PreProcessNonExpandingWildcardChar(unit.DataSet, startKey, out nonExpandingWildcard);

            //This will validate Start/End range and merge the pair into a single range-like value that FillSubsList expects.
            ARmDataSet rangeToFetch = new ARmDataSet();

            RMReportWildcard.ConcatenateRangeWithDataSet(rangeToFetch, unit.DataSet, startKey, endKey, MergingMode.Intersection);

            List <T> unitItems = fetchRangePredicate(rangeToFetch);

            if (nonExpandingWildcard != null)
            {
                //TODO: Build a better auto-description based on segment values instead of copying code to description?
                unitItems = ReduceListByNonExpandingWildcard(nonExpandingWildcard, unitItems,
                                                             (u) => unitCodePredicate(u),
                                                             (u, mv) => applyWildcardToItemAction(u, mv));
            }

            switch (ds.RowDescription.Trim().ToUpper())
            {
            case RowDescriptionType.CodeDescription:
                unitItems.Sort((x, y) => (unitCodePredicate(x) + unitDescriptionPredicate(x)).CompareTo(unitCodePredicate(y) + unitDescriptionPredicate(y)));
                break;

            case RowDescriptionType.DescriptionCode:
                unitItems.Sort((x, y) => (unitDescriptionPredicate(x) + unitCodePredicate(x)).CompareTo(unitDescriptionPredicate(y) + unitCodePredicate(y)));
                break;

            case RowDescriptionType.Description:
                unitItems.Sort((x, y) => unitDescriptionPredicate(x).CompareTo(unitDescriptionPredicate(y)));
                break;

            default:
                unitItems.Sort((x, y) => unitCodePredicate(x).CompareTo(unitCodePredicate(y)));
                break;
            }

            List <ARmUnit> units = new List <ARmUnit>();
            int            n     = 0;

            foreach (T unitItem in unitItems)
            {
                n++;
                var u = new ARmUnit();
                report.FillDataSource(ds, u.DataSet, report.Report.Current.Type);
                u.DataSet[startKey] = unitCodePredicate(unitItem);
                u.DataSet[endKey]   = null;
                u.Code = unit.Code + n.ToString("D5");

                switch (ds.RowDescription.Trim())
                {
                case RowDescriptionType.CodeDescription:
                    u.Description = string.Format("{0}{1}{2}", unitCodePredicate(unitItem).Trim(), "-", unitDescriptionPredicate(unitItem));
                    break;

                case RowDescriptionType.DescriptionCode:
                    u.Description = string.Format("{0}{1}{2}", unitDescriptionPredicate(unitItem), "-", unitCodePredicate(unitItem).Trim());
                    break;

                case RowDescriptionType.Description:
                    u.Description = unitDescriptionPredicate(unitItem);
                    break;

                default:
                    u.Description = unitCodePredicate(unitItem).Trim();
                    break;
                }

                u.Formula       = unit.Formula;
                u.PrintingGroup = unit.PrintingGroup;
                units.Add(u);
            }
            return(units);
        }
Beispiel #9
0
        public virtual List <ARmUnit> ExpandUnit(RMDataSource ds, ARmUnit unit, Func <RMDataSource, ARmUnit, List <ARmUnit> > del)
        {
            string rmType = Base.Report.Current.Type;

            if (rmType == ARmReport.PM)
            {
                if (unit.DataSet.Expand != ExpandType.Nothing)
                {
                    PMEnsureInitialized();
                    if (ds.Expand == ExpandType.AccountGroup)
                    {
                        return(RMReportUnitExpansion <PMAccountGroup> .ExpandUnit(Base, ds, unit, Keys.StartAccountGroup, Keys.EndAccountGroup,
                                                                                  rangeToFetch => _accountGroupsRangeCache.GetItemsInRange(rangeToFetch[Keys.StartAccountGroup] as string,
                                                                                                                                           accountGroup => accountGroup.GroupCD,
                                                                                                                                           (accountGroup, code) => accountGroup.GroupCD = code),
                                                                                  accountGroup => accountGroup.GroupCD, accountGroup => accountGroup.Description,
                                                                                  (accountGroup, wildcard) => { accountGroup.GroupCD = wildcard; accountGroup.Description = wildcard; }));
                    }
                    else if (ds.Expand == ExpandType.Project)
                    {
                        return(RMReportUnitExpansion <PMProject> .ExpandUnit(Base, ds, unit, Keys.StartProject, Keys.EndProject,
                                                                             rangeToFetch => _projectsRangeCache.GetItemsInRange(rangeToFetch[Keys.StartProject] as string,
                                                                                                                                 project => project.ContractCD,
                                                                                                                                 (project, code) => project.ContractCD = code),
                                                                             project => project.ContractCD, project => project.Description,
                                                                             (project, wildcard) => { project.ContractCD = wildcard; project.Description = wildcard; }));
                    }
                    else if (ds.Expand == ExpandType.ProjectTask)
                    {
                        return(RMReportUnitExpansion <PMTask> .ExpandUnit(Base, ds, unit, Keys.StartProjectTask, Keys.EndProjectTask,
                                                                          rangeToFetch => {
                            List <PMTask> tasks = _tasksRangeCache.GetItemsInRange(rangeToFetch[Keys.StartProjectTask] as string,
                                                                                   task => task.TaskCD,
                                                                                   (task, code) => task.TaskCD = code);

                            ARmDataSet projectRange = new ARmDataSet();
                            RMReportWildcard.ConcatenateRangeWithDataSet(projectRange, unit.DataSet, Keys.StartProject, Keys.EndProject, MergingMode.Intersection);

                            if (!String.IsNullOrEmpty(projectRange[Keys.StartProject] as string))
                            {
                                //A project range is specified in the unit; restrict tasks to tasks of this project range.
                                List <PMProject> projects = _projectsRangeCache.GetItemsInRange(projectRange[Keys.StartProject] as string,
                                                                                                project => project.ContractCD,
                                                                                                (project, code) => project.ContractCD = code);
                                tasks = tasks.Where(t => projects.Any(p => t.ProjectID == p.ContractID)).ToList <PMTask>();
                            }

                            //Same project TaskCD can be reused in multiple projects; it only makes sense to get distinct values for the purpose of filling the unit tree
                            List <PMTask> groupedTasks = tasks.GroupBy(t => t.TaskCD).Select(g => new PMTask()
                            {
                                TaskCD = g.Key, Description = g.Min(t => t.Description)
                            }).ToList <PMTask>();
                            return groupedTasks;
                        },
                                                                          task => task.TaskCD, project => project.Description,
                                                                          (task, wildcard) => { task.TaskCD = wildcard; task.Description = wildcard; }));
                    }
                    else if (ds.Expand == ExpandType.Inventory)
                    {
                        return(RMReportUnitExpansion <InventoryItem> .ExpandUnit(Base, ds, unit, Keys.StartInventory, Keys.EndInventory,
                                                                                 rangeToFetch => _itemRangeCache.GetItemsInRange(rangeToFetch[Keys.StartInventory] as string,
                                                                                                                                 item => item.InventoryCD,
                                                                                                                                 (item, code) => item.InventoryCD = code),
                                                                                 item => item.InventoryCD, item => item.Descr,
                                                                                 (item, wildcard) => { item.InventoryCD = wildcard; item.Descr = wildcard; }));
                    }
                }
            }
            else
            {
                return(del(ds, unit));
            }

            return(null);
        }
Beispiel #10
0
        public ARmReport GetReport(Func <ARmReport> del)
        {
            ARmReport ar = del();

            int?id = Base.Report.Current.StyleID;

            if (id != null)
            {
                RMStyle st = Base.StyleByID.SelectSingle(id);
                Base.fillStyle(st, ar.Style);
            }

            id = Base.Report.Current.DataSourceID;
            if (id != null)
            {
                RMDataSource ds = Base.DataSourceByID.SelectSingle(id);
                FillDataSourceInternal(ds, ar.DataSet, ar.Type);
            }

            List <ARmReport.ARmReportParameter> aRp = ar.ARmParams;
            PXFieldState state;
            RMReportPM   rPM = Base.Report.Cache.GetExtension <RMReportPM>(Base.Report.Current);

            if (ar.Type == ARmReport.PM)
            {
                string sViewName  = string.Empty;
                string sInputMask = string.Empty;

                // StartAccountGroup, EndAccountGroup
                bool RequestEndAccountGroup = rPM.RequestEndAccountGroup ?? false;
                //int colSpan = RequestEndAccountGroup ? 1 : 2;
                int colSpan = 2;
                sViewName = sInputMask = string.Empty;
                state     = Base.DataSourceByID.Cache.GetStateExt <RMDataSourcePM.startAccountGroup>(null) as PXFieldState;
                if (state != null && !String.IsNullOrEmpty(state.ViewName))
                {
                    sViewName = state.ViewName;
                    if (state is PXStringState)
                    {
                        sInputMask = ((PXStringState)state).InputMask;
                    }
                }
                Base.CreateParameter(Keys.StartAccountGroup, "StartAccountGroup", Messages.GetLocal(Messages.StartAccTitle), ar.DataSet[Keys.StartAccountGroup] as string, rPM.RequestStartAccountGroup ?? false, colSpan, sViewName, sInputMask, aRp);

                sViewName = sInputMask = string.Empty;
                state     = Base.DataSourceByID.Cache.GetStateExt <RMDataSourcePM.endAccountGroup>(null) as PXFieldState;
                if (state != null && !String.IsNullOrEmpty(state.ViewName))
                {
                    sViewName = state.ViewName;
                    if (state is PXStringState)
                    {
                        sInputMask = ((PXStringState)state).InputMask;
                    }
                }
                Base.CreateParameter(Keys.EndAccountGroup, "EndAccountGroup", Messages.GetLocal(Messages.EndAccTitle), ar.DataSet[Keys.EndAccountGroup] as string, RequestEndAccountGroup, colSpan, sViewName, sInputMask, aRp);

                // StartProject, EndProject
                bool bRequestEndProject = rPM.RequestEndProject ?? false;
                //colSpan = bRequestEndProject ? 1 : 2;
                colSpan   = 2;
                sViewName = sInputMask = string.Empty;
                state     = Base.DataSourceByID.Cache.GetStateExt <RMDataSourcePM.startProject>(null) as PXFieldState;
                if (state != null && !String.IsNullOrEmpty(state.ViewName))
                {
                    sViewName = state.ViewName;
                    if (state is PXStringState)
                    {
                        sInputMask = ((PXStringState)state).InputMask;
                    }
                }
                Base.CreateParameter(Keys.StartProject, "StartProject", Messages.GetLocal(Messages.StartProjectTitle), ar.DataSet[Keys.StartProject] as string, rPM.RequestStartProject ?? false, colSpan, sViewName, sInputMask, aRp);

                sViewName = sInputMask = string.Empty;
                state     = Base.DataSourceByID.Cache.GetStateExt <RMDataSourcePM.endProject>(null) as PXFieldState;
                if (state != null && !String.IsNullOrEmpty(state.ViewName))
                {
                    sViewName = state.ViewName;
                    if (state is PXStringState)
                    {
                        sInputMask = ((PXStringState)state).InputMask;
                    }
                }
                Base.CreateParameter(Keys.EndProject, "EndProject", Messages.GetLocal(Messages.EndProjectTitle), ar.DataSet[Keys.EndProject] as string, bRequestEndProject, colSpan, sViewName, sInputMask, aRp);

                // StartTask, EndTask
                bool RequestEndProjectTask = rPM.RequestEndProjectTask ?? false;

                //colSpan = RequestEndProjectTask ? 1 : 2;
                colSpan   = 2;
                sViewName = sInputMask = string.Empty;
                state     = Base.DataSourceByID.Cache.GetStateExt <RMDataSourcePM.startProjectTask>(null) as PXFieldState;
                if (state != null && !String.IsNullOrEmpty(state.ViewName))
                {
                    sViewName = state.ViewName;
                    if (state is PXStringState)
                    {
                        sInputMask = ((PXStringState)state).InputMask;
                    }
                }
                Base.CreateParameter(Keys.StartProjectTask, "StartTask", Messages.GetLocal(Messages.StartTaskTitle), ar.DataSet[Keys.StartProjectTask] as string, rPM.RequestStartProjectTask ?? false, colSpan, sViewName, sInputMask, aRp);

                sViewName = sInputMask = string.Empty;
                state     = Base.DataSourceByID.Cache.GetStateExt <RMDataSourcePM.endProjectTask>(null) as PXFieldState;
                if (state != null && !String.IsNullOrEmpty(state.ViewName))
                {
                    sViewName = state.ViewName;
                    if (state is PXStringState)
                    {
                        sInputMask = ((PXStringState)state).InputMask;
                    }
                }
                Base.CreateParameter(Keys.EndProjectTask, "EndTask", Messages.GetLocal(Messages.EndTaskTitle), ar.DataSet[Keys.EndProjectTask] as string, RequestEndProjectTask, colSpan, sViewName, sInputMask, aRp);

                // StartInventory, EndInventory
                bool bRequestEndInventory = rPM.RequestEndInventory ?? false;
                //colSpan = bRequestEndInventory ? 1 : 2;
                colSpan = 2;

                sViewName = sInputMask = string.Empty;
                state     = Base.DataSourceByID.Cache.GetStateExt <RMDataSourcePM.startInventory>(null) as PXFieldState;
                if (state != null && !String.IsNullOrEmpty(state.ViewName))
                {
                    sViewName = state.ViewName;
                    if (state is PXStringState)
                    {
                        sInputMask = ((PXStringState)state).InputMask;
                    }
                }
                Base.CreateParameter(Keys.StartInventory, "StartInventory", Messages.GetLocal(Messages.StartInventoryTitle), ar.DataSet[Keys.StartInventory] as string, rPM.RequestStartInventory ?? false, colSpan, sViewName, sInputMask, aRp);

                sViewName = sInputMask = string.Empty;
                state     = Base.DataSourceByID.Cache.GetStateExt <RMDataSourcePM.endInventory>(null) as PXFieldState;
                if (state != null && !String.IsNullOrEmpty(state.ViewName))
                {
                    sViewName = state.ViewName;
                    if (state is PXStringState)
                    {
                        sInputMask = ((PXStringState)state).InputMask;
                    }
                }
                Base.CreateParameter(Keys.EndInventory, "EndInventory", Messages.GetLocal(Messages.EndInventoryTitle), ar.DataSet[Keys.EndInventory] as string, bRequestEndInventory, colSpan, sViewName, sInputMask, aRp);
            }

            return(ar);
        }
Beispiel #11
0
        private List <PMHistory> GetPeriodsToCalculate(PMProject project, PMTask task, PMAccountGroup accountGroup, InventoryItem item, RMDataSource ds, RMDataSourceGL dsGL)
        {
            Dictionary <string, PMHistory> periodsForKey = null;

            var key = new PMHistoryKeyTuple(project.ContractID.Value, task.TaskCD, accountGroup.GroupID.Value, item.InventoryID.Value);

            if (!_pmhistoryPeriodsByKey.TryGetValue(key, out periodsForKey))
            {
                return(null);
            }

            if (ds.AmountType == BalanceType.Amount || ds.AmountType == BalanceType.Quantity ||
                ds.AmountType == BalanceType.BudgetAmount || ds.AmountType == BalanceType.BudgetQuantity ||
                ds.AmountType == BalanceType.RevisedAmount || ds.AmountType == BalanceType.RevisedQuantity)
            {
                //These amounts are calculated against start of project
                dsGL.StartPeriod           = _reportPeriods.PerWildcard;
                dsGL.StartPeriodOffset     = 0;
                dsGL.StartPeriodYearOffset = 0;
            }

            return(_reportPeriods.GetPeriodsForRegularAmount(dsGL, periodsForKey));
        }
Beispiel #12
0
        private object CalculateAndExpandValue(bool drilldown, RMDataSource ds, RMDataSourceGL dsGL, RMDataSourcePM dsPM, ARmDataSet dataSet, List <PMAccountGroup> accountGroups, List <PMProject> projects, List <PMTask> tasks, List <InventoryItem> items, List <object[]> splitret)
        {
            decimal totalAmount = 0;
            object  locker      = new object();
            Dictionary <PMHistoryKeyTuple, PXResult <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem> > drilldownData = null;

            if (drilldown)
            {
                drilldownData = new Dictionary <PMHistoryKeyTuple, PXResult <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem> >();
            }

            Parallel.For(0, accountGroups.Count, accountGroup =>
            {
                PMAccountGroup currentAccountGroup = accountGroups[accountGroup];
                if (!_historySegments.Contains(new PMHistoryKeyTuple(0, String.Empty, currentAccountGroup.GroupID.Value, 0)))
                {
                    return;
                }

                Parallel.For(0, projects.Count, project =>
                {
                    PMProject currentProject = projects[project];
                    if (!_historySegments.Contains(new PMHistoryKeyTuple(currentProject.ContractID.Value, String.Empty, currentAccountGroup.GroupID.Value, 0)))
                    {
                        return;
                    }

                    Parallel.For(0, tasks.Count, task =>
                    {
                        PMTask currentTask = tasks[task];
                        if (!_historySegments.Contains(new PMHistoryKeyTuple(currentProject.ContractID.Value, currentTask.TaskCD, currentAccountGroup.GroupID.Value, 0)))
                        {
                            return;
                        }
                        if (ds.Expand != ExpandType.ProjectTask && currentTask.ProjectID != currentProject.ContractID)
                        {
                            return;
                        }

                        Parallel.For(0, items.Count, item =>
                        {
                            InventoryItem currentItem = items[item];
                            List <PMHistory> periods  = GetPeriodsToCalculate(currentProject, currentTask, currentAccountGroup, currentItem, ds, dsGL);
                            if (periods == null)
                            {
                                return;
                            }

                            foreach (var hist in periods)
                            {
                                decimal amount = GetAmountFromPMHistory(ds, hist);
                                lock (locker)
                                {
                                    totalAmount += amount;
                                }

                                if (drilldown)
                                {
                                    var key = new PMHistoryKeyTuple(currentProject.ContractID.Value, currentTask.TaskCD, currentAccountGroup.GroupID.Value, currentItem.InventoryID.Value);
                                    PXResult <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem> drilldownRow = null;

                                    lock (drilldownData)
                                    {
                                        if (!drilldownData.TryGetValue(key, out drilldownRow))
                                        {
                                            drilldownRow = new PXResult <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem>(new PMHistory(), currentProject, currentTask, currentAccountGroup, currentItem);
                                            drilldownData.Add(key, drilldownRow);
                                        }
                                    }

                                    lock (drilldownRow)
                                    {
                                        AggregatePMHistoryForDrilldown(drilldownRow, hist);
                                    }
                                }

                                if (ds.Expand == ExpandType.AccountGroup)
                                {
                                    lock (currentAccountGroup)
                                    {
                                        splitret[accountGroup][2] = (decimal)splitret[accountGroup][2] + amount;
                                        if (splitret[accountGroup][3] == null)
                                        {
                                            var dataSetCopy = new ARmDataSet(dataSet);
                                            dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.StartAccountGroup] = dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.EndAccountGroup] = currentAccountGroup.GroupCD;
                                            splitret[accountGroup][3] = dataSetCopy;
                                        }
                                    }
                                }
                                else if (ds.Expand == ExpandType.Project)
                                {
                                    lock (currentProject)
                                    {
                                        splitret[project][2] = (decimal)splitret[project][2] + amount;
                                        if (splitret[project][3] == null)
                                        {
                                            var dataSetCopy = new ARmDataSet(dataSet);
                                            dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.StartProject] = dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.EndProject] = currentProject.ContractCD;
                                            splitret[project][3] = dataSetCopy;
                                        }
                                    }
                                }
                                else if (ds.Expand == ExpandType.ProjectTask)
                                {
                                    lock (currentItem)
                                    {
                                        splitret[task][2] = (decimal)splitret[task][2] + amount;
                                        if (splitret[task][3] == null)
                                        {
                                            var dataSetCopy = new ARmDataSet(dataSet);
                                            dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.StartProjectTask] = dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.EndProjectTask] = currentTask.TaskCD;
                                            splitret[task][3] = dataSetCopy;
                                        }
                                    }
                                }
                                else if (ds.Expand == ExpandType.Inventory)
                                {
                                    lock (currentItem)
                                    {
                                        splitret[item][2] = (decimal)splitret[item][2] + amount;
                                        if (splitret[item][3] == null)
                                        {
                                            var dataSetCopy = new ARmDataSet(dataSet);
                                            dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.StartInventory] = dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.EndInventory] = currentItem.InventoryCD;
                                            splitret[item][3] = dataSetCopy;
                                        }
                                    }
                                }
                            }
                        });
                    });
                });
            });

            if (drilldown)
            {
                var resultset = new PXResultset <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem>();
                foreach (var r in
                         from row in drilldownData.Values
                         let projectCD = ((PMProject)row[typeof(PMProject)]).With(_ => _.ContractCD)
                                         let taskCD = ((PMTask)row[typeof(Sub)]).With(_ => _.TaskCD)
                                                      let accGroupCD = ((PMAccountGroup)row[typeof(PMAccountGroup)]).With(_ => _.GroupCD)
                                                                       let inventoryCD = ((InventoryItem)row[typeof(InventoryItem)]).With(_ => _.InventoryCD)
                                                                                         orderby projectCD, taskCD, accGroupCD, inventoryCD
                         select row)
                {
                    resultset.Add(r);
                }
                return(resultset);
            }
            else if (ds.Expand != ExpandType.Nothing)
            {
                return(splitret);
            }
            else
            {
                return(totalAmount);
            }
        }
Beispiel #13
0
        public virtual object GetHistoryValue(ARmDataSet dataSet, bool drilldown, Func <ARmDataSet, bool, object> del)
        {
            string rmType = Base.Report.Current.Type;

            if (rmType == ARmReport.PM)
            {
                RMDataSource   ds   = Base.DataSourceByID.Current;
                RMDataSourcePM dsPM = Base.Caches[typeof(RMDataSource)].GetExtension <RMDataSourcePM>(ds);

                ds.AmountType          = (short?)dataSet[RMReportReaderGL.Keys.AmountType];
                dsPM.StartAccountGroup = dataSet[Keys.StartAccountGroup] as string ?? "";
                dsPM.EndAccountGroup   = dataSet[Keys.EndAccountGroup] as string ?? "";
                dsPM.StartProject      = dataSet[Keys.StartProject] as string ?? "";
                dsPM.EndProject        = dataSet[Keys.EndProject] as string ?? "";
                dsPM.StartProjectTask  = dataSet[Keys.StartProjectTask] as string ?? "";
                dsPM.EndProjectTask    = dataSet[Keys.EndProjectTask] as string ?? "";
                dsPM.StartInventory    = dataSet[Keys.StartInventory] as string ?? "";
                dsPM.EndInventory      = dataSet[Keys.EndInventory] as string ?? "";

                RMDataSourceGL dsGL = Base.Caches[typeof(RMDataSource)].GetExtension <RMDataSourceGL>(ds);
                dsGL.StartBranch           = dataSet[RMReportReaderGL.Keys.StartBranch] as string ?? "";
                dsGL.EndBranch             = dataSet[RMReportReaderGL.Keys.EndBranch] as string ?? "";
                dsGL.EndPeriod             = ((dataSet[RMReportReaderGL.Keys.EndPeriod] as string ?? "").Length > 2 ? ((dataSet[RMReportReaderGL.Keys.EndPeriod] as string ?? "").Substring(2) + "    ").Substring(0, 4) : "    ") + ((dataSet[RMReportReaderGL.Keys.EndPeriod] as string ?? "").Length > 2 ? (dataSet[RMReportReaderGL.Keys.EndPeriod] as string ?? "").Substring(0, 2) : dataSet[RMReportReaderGL.Keys.EndPeriod] as string ?? "");
                dsGL.EndPeriodOffset       = (short?)(int?)dataSet[RMReportReaderGL.Keys.EndOffset];
                dsGL.EndPeriodYearOffset   = (short?)(int?)dataSet[RMReportReaderGL.Keys.EndYearOffset];
                dsGL.StartPeriod           = ((dataSet[RMReportReaderGL.Keys.StartPeriod] as string ?? "").Length > 2 ? ((dataSet[RMReportReaderGL.Keys.StartPeriod] as string ?? "").Substring(2) + "    ").Substring(0, 4) : "    ") + ((dataSet[RMReportReaderGL.Keys.StartPeriod] as string ?? "").Length > 2 ? (dataSet[RMReportReaderGL.Keys.StartPeriod] as string ?? "").Substring(0, 2) : dataSet[RMReportReaderGL.Keys.StartPeriod] as string ?? "");
                dsGL.StartPeriodOffset     = (short?)(int?)dataSet[RMReportReaderGL.Keys.StartOffset];
                dsGL.StartPeriodYearOffset = (short?)(int?)dataSet[RMReportReaderGL.Keys.StartYearOffset];

                List <object[]> splitret = null;

                if (ds.Expand != ExpandType.Nothing)
                {
                    splitret = new List <object[]>();
                }

                if (ds.AmountType == null || ds.AmountType == 0)
                {
                    return(0m);
                }

                PMEnsureInitialized();
                EnsureHistoryLoaded(dsPM);
                NormalizeDataSource(dsPM);

                List <PMAccountGroup> accountGroups = _accountGroupsRangeCache.GetItemsInRange(dataSet[Keys.StartAccountGroup] as string,
                                                                                               group => group.GroupCD,
                                                                                               (group, code) => group.GroupCD = code);
                List <PMProject> projects = _projectsRangeCache.GetItemsInRange(dataSet[Keys.StartProject] as string,
                                                                                project => project.ContractCD,
                                                                                (project, code) => project.ContractCD = code);
                List <PMTask> tasks = _tasksRangeCache.GetItemsInRange(dataSet[Keys.StartProjectTask] as string,
                                                                       task => task.TaskCD,
                                                                       (task, code) => task.TaskCD = code);
                List <InventoryItem> items = _itemRangeCache.GetItemsInRange(dataSet[Keys.StartInventory] as string,
                                                                             item => item.InventoryCD,
                                                                             (item, code) => item.InventoryCD = code);

                if (ds.Expand == ExpandType.AccountGroup)
                {
                    accountGroups.ForEach(a => splitret.Add(new object[] { a.GroupCD, a.Description, 0m, null, string.Empty }));
                }
                else if (ds.Expand == ExpandType.Project)
                {
                    projects.ForEach(p => splitret.Add(new object[] { p.ContractCD, p.Description, 0m, null, string.Empty }));
                }
                else if (ds.Expand == ExpandType.ProjectTask)
                {
                    //To avoid useless expansion, first restrict list of tasks to those tasks which point to current projects
                    tasks = tasks.Where(t => projects.Any(p => t.ProjectID == p.ContractID)).ToList <PMTask>();
                    tasks = tasks.GroupBy(t => t.TaskCD).Select(g => new PMTask()
                    {
                        TaskCD = g.Key, TaskID = g.Min(t => t.TaskID), Description = g.Min(t => t.Description)
                    }).ToList <PMTask>();
                    tasks.ForEach(pt => splitret.Add(new object[] { pt.TaskCD, pt.Description, 0m, null, string.Empty }));
                }
                else if (ds.Expand == ExpandType.Inventory)
                {
                    items.ForEach(i => splitret.Add(new object[] { i.InventoryCD, i.Descr, 0m, null, string.Empty }));
                }

                return(CalculateAndExpandValue(drilldown, ds, dsGL, dsPM, dataSet, accountGroups, projects, tasks, items, splitret));
            }
            else
            {
                return(del(dataSet, drilldown));
            }
        }