Example #1
0
        /// <summary>
        /// Get an Owner record
        /// </summary>
        /// <param name="id"></param>
        /// <param name="context"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static HetOwner GetRecord(int id, DbAppContext context, IConfiguration configuration)
        {
            // get equipment status types
            int?statusIdArchived = StatusHelper.GetStatusId(HetEquipment.StatusArchived, "equipmentStatus", context);

            if (statusIdArchived == null)
            {
                throw new ArgumentException("Status Code not found");
            }

            // get owner record
            HetOwner owner = context.HetOwner.AsNoTracking()
                             .Include(x => x.OwnerStatusType)
                             .Include(x => x.LocalArea.ServiceArea.District.Region)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.LocalArea.ServiceArea.District.Region)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.DistrictEquipmentType)
                             .ThenInclude(z => z.EquipmentType)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.Owner)
                             .ThenInclude(c => c.PrimaryContact)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.EquipmentStatusType)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.HetEquipmentAttachment)
                             .Include(x => x.HetContact)
                             .Include(x => x.PrimaryContact)
                             .FirstOrDefault(a => a.OwnerId == id);

            if (owner != null)
            {
                // remove any archived equipment
                owner.HetEquipment = owner.HetEquipment.Where(e => e.EquipmentStatusTypeId != statusIdArchived).ToList();

                // populate the "Status" description
                owner.Status = owner.OwnerStatusType.OwnerStatusTypeCode;

                foreach (HetEquipment equipment in owner.HetEquipment)
                {
                    equipment.IsHired         = EquipmentHelper.IsHired(id, context);
                    equipment.NumberOfBlocks  = EquipmentHelper.GetNumberOfBlocks(equipment, configuration);
                    equipment.HoursYtd        = EquipmentHelper.GetYtdServiceHours(id, context);
                    equipment.Status          = equipment.EquipmentStatusType.EquipmentStatusTypeCode;
                    equipment.EquipmentNumber = int.Parse(Regex.Match(equipment.EquipmentCode, @"\d+").Value);
                }

                // HETS-1115 - Do not allow changing seniority affecting entities if an active request exists
                owner.ActiveRentalRequest = RentalRequestStatus(id, context);
            }

            return(owner);
        }
Example #2
0
        /// <summary>
        /// Get an Owner record
        /// </summary>
        /// <param name="id"></param>
        /// <param name="context"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static HetOwner GetRecord(int id, DbAppContext context, IConfiguration configuration)
        {
            HetOwner owner = context.HetOwner.AsNoTracking()
                             .Include(x => x.OwnerStatusType)
                             .Include(x => x.LocalArea.ServiceArea.District.Region)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.LocalArea.ServiceArea.District.Region)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.DistrictEquipmentType)
                             .ThenInclude(z => z.EquipmentType)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.Owner)
                             .ThenInclude(c => c.PrimaryContact)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.EquipmentStatusType)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(y => y.HetEquipmentAttachment)
                             .Include(x => x.HetContact)
                             .Include(x => x.PrimaryContact)
                             .FirstOrDefault(a => a.OwnerId == id);

            if (owner != null)
            {
                // remove any archived equipment
                owner.HetEquipment = owner.HetEquipment.Where(e => e.EquipmentStatusType.EquipmentStatusTypeCode != HetEquipment.StatusArchived).ToList();

                // populate the "Status" description
                owner.Status = owner.OwnerStatusType.OwnerStatusTypeCode;

                foreach (HetEquipment equipment in owner.HetEquipment)
                {
                    equipment.IsHired         = EquipmentHelper.IsHired(id, context);
                    equipment.NumberOfBlocks  = EquipmentHelper.GetNumberOfBlocks(equipment, configuration);
                    equipment.HoursYtd        = EquipmentHelper.GetYtdServiceHours(id, context);
                    equipment.Status          = equipment.EquipmentStatusType.EquipmentStatusTypeCode;
                    equipment.EquipmentNumber = int.Parse(Regex.Match(equipment.EquipmentCode, @"\d+").Value);
                }
            }

            return(owner);
        }
        /// <summary>
        /// Seniority List view model
        /// </summary>
        /// <param name="model"></param>
        /// <param name="scoringRules"></param>
        /// <param name="rotationList"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static SeniorityViewModel ToSeniorityViewModel(HetEquipment model, SeniorityScoringRules scoringRules,
                                                              HetRentalRequestRotationList rotationList, DbAppContext context)
        {
            SeniorityViewModel seniorityViewModel = new SeniorityViewModel();

            if (model == null)
            {
                return(seniorityViewModel);
            }

            int numberOfBlocks = 0;

            // get number of blocks for this equipment type
            if (model.DistrictEquipmentType != null)
            {
                numberOfBlocks = model.DistrictEquipmentType.EquipmentType.IsDumpTruck
                    ? scoringRules.GetTotalBlocks("DumpTruck") + 1
                    : scoringRules.GetTotalBlocks() + 1;
            }

            // get equipment block number
            int blockNumber = 0;

            if (model.BlockNumber != null)
            {
                blockNumber = (int)model.BlockNumber;
            }

            // get equipment block number
            int numberInBlock = 0;

            if (model.NumberInBlock != null)
            {
                numberInBlock = (int)model.NumberInBlock;
            }

            // *************************************************************
            // check if this record/owner was called last
            // *************************************************************
            bool callLast = rotationList != null && rotationList.EquipmentId == model.EquipmentId;

            seniorityViewModel.LastCalled = callLast ? "Y" : " ";

            // *************************************************************
            // map data to view model
            // *************************************************************
            seniorityViewModel.Id = model.EquipmentId;

            if (model.DistrictEquipmentType != null)
            {
                seniorityViewModel.EquipmentType = model.DistrictEquipmentType.DistrictEquipmentName;
            }

            if (model.Owner != null)
            {
                seniorityViewModel.OwnerName = model.Owner.OrganizationName;
                seniorityViewModel.OwnerId   = model.OwnerId;
            }

            // replacing Open with 3 (HETS-968 Rotation list -Wrong Block number for Open block)
            seniorityViewModel.Block = blockNumber == numberOfBlocks ? "3" : blockNumber.ToString();

            // format the seniority value
            seniorityViewModel.Seniority = $"{model.Seniority:0.###}";

            // format year / make / model / size
            seniorityViewModel.YearMakeModelSize = $"{model.Year}/{model.Make}/{model.Model}/{model.Size}";

            seniorityViewModel.EquipmentCode = model.EquipmentCode;

            seniorityViewModel.YearsRegistered = model.YearsOfService.ToString();

            // Determine if this equipment is currently hired
            seniorityViewModel.IsHired = EquipmentHelper.IsHired(model.EquipmentId, context) ? "Y" : "N";

            // calculate and format the ytd hours
            float tempHours = EquipmentHelper.GetYtdServiceHours(model.EquipmentId, context);

            seniorityViewModel.YtdHours = string.Format("{0:0.###}", tempHours);

            // format the hours
            seniorityViewModel.HoursYearMinus1 = string.Format("{0:0.###}", model.ServiceHoursLastYear);
            seniorityViewModel.HoursYearMinus2 = string.Format("{0:0.###}", model.ServiceHoursTwoYearsAgo);
            seniorityViewModel.HoursYearMinus3 = string.Format("{0:0.###}", model.ServiceHoursThreeYearsAgo);

            // add the correct sorting order (numeric)
            seniorityViewModel.SenioritySortOrder = EquipmentHelper.CalculateSenioritySortOrder(blockNumber, numberInBlock);

            return(seniorityViewModel);
        }