public ResourceInformation(Resource resource, List <Task> tasks)
        {
            this.resource = resource;
            ID            = resource.getID().intValue();
            ResourceName  = resource.getName() ?? "Undefined";
            this.tasks    = tasks ?? new List <Task>();
            Cost          = resource.getCost().floatValue();
            GroupName     = resource.getGroup();

            Duration baselineWork = resource.getBaselineWork();
            double   duration     = 0;

            if (baselineWork != null)
            {
                if (resource.getType().toString() == "Work")
                {
                    foreach (Task t in tasks)
                    {
                        //Sometimes there is a null task
                        if (t != null && t.getBaselineDuration() != null)
                        {
                            duration += t.getDuration().getDuration() - t.getBaselineDuration().getDuration();
                        }
                    }
                }
            }
            Duration         = new WorkDuration(TimeUnitStringConverter.ConvertTime(resource.getBaselineWork().toString()), duration);
            CostPerTimeUnit  = Convert.ToSingle(Cost / Duration.TotalDuration());
            OvertimeWorkCost = Duration.Overtime * CostPerTimeUnit;
        }
Esempio n. 2
0
        public TaskInformation(Issue issue, ResourceInformation assignedTo)
        {
            TaskName = issue.Subject;
            ID       = issue.Id;
            Tracker  = issue.Tracker.Name;

            double est = 0, spent = 0;

            if (issue.EstimatedHours.HasValue)
            {
                est = issue.EstimatedHours.Value;
            }
            if (issue.SpentHours.HasValue)
            {
                spent = issue.SpentHours.Value;
            }
            Duration           = new WorkDuration(est, spent);
            CompletePercentage = int.Parse(issue.DoneRatio.Value.ToString());
            if (CompletePercentage == 100 && Duration.Spent == 0)
            {
                Duration.Spent = Duration.Estimated;
                Duration.ReCalculateOvertime();
            }
            Dates = new ProjectDates(issue.StartDate, issue.DueDate);

            Dates.SetCreatedDate(issue.CreatedOn);

            //Costs
            double costPerHour = assignedTo.CostPerTimeUnit;

            Cost       = (int)(costPerHour * Duration.TotalDuration());
            ActualCost = (int)(costPerHour * Duration.Spent);
            if (CompletePercentage == 100)
            {
                RemainingCost = 0;
            }
            else
            {
                RemainingCost = (int)(costPerHour * (Duration.Estimated - Duration.Spent));
            }
            OverCost = (int)(costPerHour * Duration.Overtime);

            //TODO: issue status
            if (CompletePercentage == 100)
            {
                Status = TaskStatus.Closed;
            }
            else
            {
                Status = TaskStatus.InWork;
            }


            ChildTasks = new List <TaskInformation>();
            SetAnomaly();
            SetDeviation();
        }
 //TODO: groups
 public ResourceInformation(Project project, User user, WorkDuration duration)
 {
     ResourceName = user.Login;
     ID           = user.Id;
     Duration     = duration;
     foreach (var cfield in user.CustomFields)
     {
         if (cfield.Name.ToLower() == "ставка" || cfield.Name.ToLower() == "salary")
         {
             try
             {
                 CostPerTimeUnit = int.Parse(cfield.Values[0].Info);
             }
             catch
             {
                 CostPerTimeUnit = 0;
             }
         }
     }
     Cost             = CostPerTimeUnit * Duration.TotalDuration();
     OvertimeWorkCost = CostPerTimeUnit * Duration.Overtime;
 }