public virtual IActionResult RentalAgreementRatesIdPut([FromRoute] int id, [FromBody] HetRentalAgreementRate item)
        {
            bool exists = _context.HetRentalAgreementRate.Any(a => a.RentalAgreementRateId == id);

            // not found
            if (!exists || id != item.RentalAgreementRateId)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // set the rate period type id
            int ratePeriodTypeId = StatusHelper.GetRatePeriodId(item.RatePeriod, _context) ?? throw new DataException("Rate Period Id cannot be null");

            // get record
            HetRentalAgreementRate rate = _context.HetRentalAgreementRate.First(a => a.RentalAgreementRateId == id);

            rate.ConcurrencyControlNumber = item.ConcurrencyControlNumber;

            rate.Comment           = item.Comment;
            rate.ComponentName     = item.ComponentName;
            rate.IsIncludedInTotal = item.IsIncludedInTotal;
            rate.Rate             = item.Rate;
            rate.RatePeriodTypeId = ratePeriodTypeId;
            rate.Active           = true;
            rate.Overtime         = false;
            rate.Set = item.Set;

            // save the changes
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(rate)));
        }
        public virtual IActionResult RentalAgreementRatesIdPut([FromRoute] int id, [FromBody] HetRentalAgreementRate item)
        {
            bool exists = _context.HetRentalAgreementRate.Any(a => a.RentalAgreementRateId == id);

            // not found
            if (!exists || id != item.RentalAgreementRateId)
            {
                return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetRentalAgreementRate rate = _context.HetRentalAgreementRate.First(a => a.RentalAgreementRateId == id);

            rate.ConcurrencyControlNumber = item.ConcurrencyControlNumber;

            rate.Comment           = item.Comment;
            rate.ComponentName     = item.ComponentName;
            rate.IsIncludedInTotal = item.IsIncludedInTotal;
            rate.Rate     = item.Rate;
            rate.Active   = true;
            rate.Overtime = false;

            // save the changes
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(item)));
        }
Example #3
0
        private static string FormatRateString(HetRentalAgreementRate rentalRate, RentalAgreementPdfViewModel agreement)
        {
            string temp = "";

            // format the rate
            if (rentalRate.Rate != null)
            {
                temp = string.Format("$ {0:0.00} / {1}", rentalRate.Rate, FormatRatePeriod(agreement.RatePeriod));
            }

            return(temp);
        }
Example #4
0
        // HETS-1017 - Updates to Rental Agreement -> Overtime is always in Hours (/Hr)
        private static string FormatOvertimeRateString(HetRentalAgreementRate rentalRate)
        {
            string temp = "";

            // format the rate
            if (rentalRate.Rate != null)
            {
                temp = $"$ {rentalRate.Rate:0.00} / Hr";
            }

            return(temp);
        }
Example #5
0
        private static string FormatRateString(HetRentalAgreementRate rentalRate, RentalAgreementDocViewModel agreement)
        {
            string temp = "";

            // format the rate
            if (rentalRate.Rate != null && rentalRate.Set)
            {
                temp = $"$ {rentalRate.Rate:0.00} / Set";
            }
            else if (rentalRate.Rate != null)
            {
                temp = $"$ {rentalRate.Rate:0.00} / {FormatRatePeriod(agreement.RatePeriod)}";
            }

            return(temp);
        }
        public virtual IActionResult RentalAgreementRatesIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetRentalAgreementRate.Any(a => a.RentalAgreementRateId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetRentalAgreementRate rate = _context.HetRentalAgreementRate.First(a => a.RentalAgreementRateId == id);

            _context.HetRentalAgreementRate.Remove(rate);

            // save the changes
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(rate)));
        }
Example #7
0
        public virtual IActionResult RentalRequestIdRotationListIdPut([FromRoute] int id, [FromBody] HetRentalRequestRotationList item)
        {
            // not found
            if (item == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            bool exists = _context.HetRentalRequest.Any(a => a.RentalRequestId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            int?statusId = StatusHelper.GetStatusId(HetRentalRequest.StatusInProgress, "rentalRequestStatus", _context);

            if (statusId == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
            }

            // check if we have the rental request that is In Progress
            exists = _context.HetRentalRequest
                     .Any(a => a.RentalRequestId == id &&
                          a.RentalRequestStatusTypeId == statusId);

            // rental request must be "in progress"
            if (!exists)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-06", ErrorViewModel.GetDescription("HETS-06", _configuration))));
            }

            // get rental request record
            HetRentalRequest request = _context.HetRentalRequest
                                       .Include(x => x.Project)
                                       .ThenInclude(x => x.District)
                                       .Include(x => x.LocalArea)
                                       .Include(x => x.HetRentalRequestRotationList)
                                       .ThenInclude(x => x.Equipment)
                                       .First(a => a.RentalRequestId == id);

            // get rotation list record
            HetRentalRequestRotationList requestRotationList = _context.HetRentalRequestRotationList
                                                               .FirstOrDefault(a => a.RentalRequestRotationListId == item.RentalRequestRotationListId);

            // not found
            if (requestRotationList == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // update rotation list record
            int tempEquipmentId = item.Equipment.EquipmentId;

            requestRotationList.ConcurrencyControlNumber = item.ConcurrencyControlNumber;
            requestRotationList.EquipmentId           = tempEquipmentId;
            requestRotationList.IsForceHire           = item.IsForceHire;
            requestRotationList.AskedDateTime         = DateTime.UtcNow;
            requestRotationList.Note                  = item.Note;
            requestRotationList.OfferRefusalReason    = item.OfferRefusalReason;
            requestRotationList.OfferResponse         = item.OfferResponse;
            requestRotationList.OfferResponseDatetime = item.OfferResponseDatetime;
            requestRotationList.WasAsked              = item.WasAsked;
            requestRotationList.OfferResponseNote     = item.OfferResponseNote;

            // do we need to create or modify a Rental Agreement?
            if (item.IsForceHire == true ||
                item.OfferResponse.Equals("Yes", StringComparison.InvariantCultureIgnoreCase))
            {
                // get rental agreement record
                HetRentalAgreement rentalAgreement = _context.HetRentalAgreement
                                                     .FirstOrDefault(a => a.RentalAgreementId == item.RentalAgreementId);

                // create rental agreement if it doesn't exist
                if (rentalAgreement == null)
                {
                    // generate the rental agreement number
                    string agreementNumber = RentalAgreementHelper.GetRentalAgreementNumber(item.Equipment, _context);

                    // get user info - agreement city
                    User   user          = UserAccountHelper.GetUser(_context, _httpContext);
                    string agreementCity = user.AgreementCity;

                    int?rateTypeId = StatusHelper.GetRatePeriodId(HetRatePeriodType.PeriodHourly, _context);
                    if (rateTypeId == null)
                    {
                        return(new NotFoundObjectResult(new HetsResponse("HETS-24", ErrorViewModel.GetDescription("HETS-24", _configuration))));
                    }

                    rentalAgreement = new HetRentalAgreement
                    {
                        ProjectId        = request.ProjectId,
                        DistrictId       = request.Project.District.DistrictId,
                        EquipmentId      = tempEquipmentId,
                        Number           = agreementNumber,
                        RatePeriodTypeId = (int)rateTypeId,
                        AgreementCity    = agreementCity
                    };

                    // add overtime rates
                    List <HetProvincialRateType> overtime = _context.HetProvincialRateType.AsNoTracking()
                                                            .Where(x => x.Overtime)
                                                            .ToList();

                    // agreement overtime records (default overtime flag)
                    foreach (HetProvincialRateType rate in overtime)
                    {
                        // add the rate
                        HetRentalAgreementRate newAgreementRate = new HetRentalAgreementRate
                        {
                            Comment           = rate.Description,
                            ComponentName     = rate.RateType,
                            Overtime          = true,
                            Active            = rate.Active,
                            IsIncludedInTotal = rate.IsIncludedInTotal,
                            Rate = rate.Rate
                        };

                        if (rentalAgreement.HetRentalAgreementRate == null)
                        {
                            rentalAgreement.HetRentalAgreementRate = new List <HetRentalAgreementRate>();
                        }

                        rentalAgreement.HetRentalAgreementRate.Add(newAgreementRate);
                    }

                    _context.HetRentalAgreement.Add(rentalAgreement);
                }

                int?statusIdAgreement = StatusHelper.GetStatusId(HetRentalAgreement.StatusActive, "rentalAgreementStatus", _context);
                if (statusIdAgreement == null)
                {
                    return(new NotFoundObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
                }

                // update rental agreement
                rentalAgreement.RentalAgreementStatusTypeId = (int)statusIdAgreement;
                rentalAgreement.DatedOn                     = DateTime.UtcNow;
                rentalAgreement.EstimateHours               = request.ExpectedHours;
                rentalAgreement.EstimateStartWork           = request.ExpectedStartDate;
                rentalAgreement.RentalRequestId             = request.RentalRequestId;
                rentalAgreement.RentalRequestRotationListId = requestRotationList.RentalRequestRotationListId;

                // have to save the agreement
                _context.SaveChanges();

                // relate the new rental agreement to the original rotation list record
                int tempRentalAgreementId = rentalAgreement.RentalAgreementId;
                requestRotationList.RentalAgreementId = tempRentalAgreementId;
                requestRotationList.RentalAgreement   = rentalAgreement;
            }

            // can we "Complete" this rental request (if the Yes or Forced Hires = Request.EquipmentCount)
            int countOfYeses          = 0;
            int equipmentRequestCount = request.EquipmentCount;

            foreach (HetRentalRequestRotationList rotationList in request.HetRentalRequestRotationList)
            {
                if (rotationList.OfferResponse != null &&
                    rotationList.OfferResponse.Equals("Yes", StringComparison.InvariantCultureIgnoreCase))
                {
                    countOfYeses = countOfYeses + 1;
                }
                else if (rotationList.IsForceHire != null &&
                         rotationList.IsForceHire == true)
                {
                    countOfYeses = countOfYeses + 1;
                }
            }

            if (countOfYeses >= equipmentRequestCount)
            {
                int?statusIdComplete = StatusHelper.GetStatusId(HetRentalRequest.StatusComplete, "rentalRequestStatus", _context);
                if (statusIdComplete == null)
                {
                    return(new NotFoundObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
                }

                request.RentalRequestStatusTypeId = (int)statusIdComplete;
                request.Status = "Complete";
                request.FirstOnRotationList = null;
            }

            // 1. get the number of blocks for this equipment type
            // 2. set which rotation list record is currently "active"
            int numberOfBlocks = EquipmentHelper.GetNumberOfBlocks(item.Equipment, _configuration);

            RentalRequestHelper.UpdateRotationList(request, numberOfBlocks, _context);

            // save the changes
            _context.SaveChanges();

            // get the scoring rules
            SeniorityScoringRules scoringRules = new SeniorityScoringRules(_configuration);

            return(new ObjectResult(new HetsResponse(RentalRequestHelper.GetRecordWithRotationList(id, scoringRules, _context))));
        }