Ejemplo n.º 1
0
        /// <summary>
        /// Get rental request record
        /// </summary>
        /// <param name="id"></param>
        /// <param name="scoringRules"></param>
        /// <param name="context"></param>
        public static HetRentalRequest GetRecordWithRotationList(int id, SeniorityScoringRules scoringRules, DbAppContext context)
        {
            HetRentalRequest request = context.HetRentalRequest.AsNoTracking()
                                       .Include(x => x.DistrictEquipmentType)
                                       .ThenInclude(y => y.EquipmentType)
                                       .Include(x => x.FirstOnRotationList)
                                       .Include(x => x.HetRentalRequestAttachment)
                                       .Include(x => x.HetRentalRequestRotationList)
                                       .ThenInclude(y => y.Equipment)
                                       .ThenInclude(r => r.HetEquipmentAttachment)
                                       .Include(x => x.HetRentalRequestRotationList)
                                       .ThenInclude(y => y.Equipment)
                                       .ThenInclude(r => r.LocalArea)
                                       .Include(x => x.HetRentalRequestRotationList)
                                       .ThenInclude(y => y.Equipment)
                                       .ThenInclude(r => r.DistrictEquipmentType)
                                       .Include(x => x.HetRentalRequestRotationList)
                                       .ThenInclude(y => y.Equipment)
                                       .ThenInclude(e => e.Owner)
                                       .ThenInclude(c => c.PrimaryContact)
                                       .FirstOrDefault(a => a.RentalRequestId == id);

            if (request != null)
            {
                // re-sort list using: LocalArea / District Equipment Type and SenioritySortOrder (desc)
                request.HetRentalRequestRotationList = request.HetRentalRequestRotationList
                                                       .OrderBy(e => e.RotationListSortOrder)
                                                       .ToList();

                // calculate the Yes Count based on the RentalRequestList
                request.YesCount = CalculateYesCount(request);

                // calculate YTD hours for the equipment records
                if (request.HetRentalRequestRotationList != null)
                {
                    foreach (HetRentalRequestRotationList rotationList in request.HetRentalRequestRotationList)
                    {
                        if (rotationList.Equipment != null)
                        {
                            int numberOfBlocks = 0;

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

                            // get equipment seniority
                            float seniority = 0F;
                            if (rotationList.Equipment.Seniority != null)
                            {
                                seniority = (float)rotationList.Equipment.Seniority;
                            }

                            // get equipment block number
                            int blockNumber = 0;
                            if (rotationList.Equipment.BlockNumber != null)
                            {
                                blockNumber = (int)rotationList.Equipment.BlockNumber;

                                //HETS-968 - Rotation list -Wrong Block number for Open block
                                if (blockNumber == numberOfBlocks)
                                {
                                    blockNumber = 3;
                                    rotationList.Equipment.BlockNumber = blockNumber;
                                }
                            }

                            rotationList.Equipment.HoursYtd        = EquipmentHelper.GetYtdServiceHours(rotationList.Equipment.EquipmentId, context);
                            rotationList.Equipment.SeniorityString = EquipmentHelper.FormatSeniorityString(seniority, blockNumber, numberOfBlocks);
                        }
                    }
                }
            }

            return(request);
        }