public static List <HetRentalAgreementRate> GetRentalRates(int id, DbAppContext context, IConfiguration configuration) { HetRentalAgreement agreement = context.HetRentalAgreement.AsNoTracking() .Include(x => x.HetRentalAgreementRate) .First(x => x.RentalAgreementId == id); List <HetRentalAgreementRate> rates = new List <HetRentalAgreementRate>(); rates.AddRange(agreement.HetRentalAgreementRate); return(rates); }
public static List <HetRentalAgreementCondition> GetConditions(int id, DbAppContext context, IConfiguration configuration) { HetRentalAgreement agreement = context.HetRentalAgreement.AsNoTracking() .Include(x => x.HetRentalAgreementCondition) .First(x => x.RentalAgreementId == id); List <HetRentalAgreementCondition> conditions = new List <HetRentalAgreementCondition>(); conditions.AddRange(agreement.HetRentalAgreementCondition); return(conditions); }
/// <summary> /// Convert to RentalAgreementSummary Model /// </summary> /// <param name="agreement"></param> public static RentalAgreementSummaryLite ToSummaryLiteModel(HetRentalAgreement agreement) { RentalAgreementSummaryLite agreementSummary = new RentalAgreementSummaryLite(); if (agreement != null) { agreementSummary.Id = agreement.RentalAgreementId; agreementSummary.DatedOn = agreement.DatedOn; } return(agreementSummary); }
public static TimeRecordLite GetTimeRecords(int id, DbAppContext context, IConfiguration configuration) { HetRentalAgreement agreement = context.HetRentalAgreement.AsNoTracking() .Include(x => x.Equipment) .ThenInclude(y => y.DistrictEquipmentType) .ThenInclude(z => z.EquipmentType) .Include(x => x.Project) .Include(x => x.HetTimeRecord) .First(x => x.RentalAgreementId == id); // get the max hours for this equipment type float? hoursYtd = 0.0F; int maxHours = 0; string equipmentCode = ""; if (agreement.Equipment?.EquipmentId != null && agreement.Equipment.DistrictEquipmentType?.EquipmentType != null) { maxHours = Convert.ToInt32(agreement.Equipment.DistrictEquipmentType.EquipmentType.IsDumpTruck ? configuration.GetSection("MaximumHours:DumpTruck").Value : configuration.GetSection("MaximumHours:Default").Value); int equipmentId = agreement.Equipment.EquipmentId; hoursYtd = EquipmentHelper.GetYtdServiceHours(equipmentId, context); equipmentCode = agreement.Equipment.EquipmentCode; } // get the project info string projectName = ""; string projectNumber = ""; if (agreement.Project != null) { projectName = agreement.Project.Name; projectNumber = agreement.Project.ProvincialProjectNumber; } TimeRecordLite timeRecord = new TimeRecordLite { TimeRecords = new List <HetTimeRecord>() }; timeRecord.TimeRecords.AddRange(agreement.HetTimeRecord); timeRecord.EquipmentCode = equipmentCode; timeRecord.ProjectName = projectName; timeRecord.ProvincialProjectNumber = projectNumber; timeRecord.HoursYtd = hoursYtd; timeRecord.MaximumHours = maxHours; return(timeRecord); }
/// <summary> /// Get rental agreement /// </summary> /// <param name="district"></param> /// <param name="context"></param> /// <returns></returns> public static string GetRentalAgreementNumber(HetDistrict district, DbAppContext context) { int currentCount = 0; string result = ""; // validate item if (district?.DistrictId != null) { DateTime currentTime = DateTime.UtcNow; int fiscalYear = currentTime.Year; // fiscal year always ends in March if (currentTime.Month > 3) { fiscalYear++; } int districtNumber = district.MinistryDistrictId; int districtId = district.DistrictId; DateTime fiscalYearStart = new DateTime(fiscalYear - 1, 1, 1); // count the number of rental agreements in the system (for this district) HetRentalAgreement agreement = context.HetRentalAgreement.AsNoTracking() .Include(x => x.Project.District) .OrderBy(x => x.RentalAgreementId) .LastOrDefault(x => x.DistrictId == districtId && x.AppCreateTimestamp >= fiscalYearStart && x.Number.Contains("-D")); if (agreement != null) { string temp = agreement.Number; temp = temp.Substring(temp.LastIndexOf('-') + 1); int.TryParse(temp, out currentCount); } currentCount++; // format of the Rental Agreement number is YYYY-#-#### (new for blank agreements) result = fiscalYear + "-D" + districtNumber + "-" + currentCount.ToString("D4"); } return(result); }
/// <summary> /// Get a Rental Agreement record /// </summary> /// <param name="id"></param> /// <param name="context"></param> /// <returns></returns> public static HetRentalAgreement GetRecord(int id, DbAppContext context) { HetRentalAgreement agreement = context.HetRentalAgreement.AsNoTracking() .Include(x => x.RentalAgreementStatusType) .Include(x => x.RatePeriodType) .Include(x => x.District) .Include(x => x.Equipment) .ThenInclude(y => y.Owner) .Include(x => x.Equipment) .ThenInclude(y => y.DistrictEquipmentType) .ThenInclude(d => d.EquipmentType) .Include(x => x.Equipment) .ThenInclude(y => y.HetEquipmentAttachment) .Include(x => x.Equipment) .ThenInclude(y => y.EquipmentStatusType) .Include(x => x.Equipment) .ThenInclude(y => y.LocalArea.ServiceArea.District.Region) .Include(x => x.Project) .ThenInclude(p => p.District.Region) .Include(x => x.Project) .ThenInclude(p => p.ProjectStatusType) .Include(x => x.HetRentalAgreementCondition) .Include(x => x.HetRentalAgreementRate) .ThenInclude(x => x.RatePeriodType) .Include(x => x.HetTimeRecord) .FirstOrDefault(a => a.RentalAgreementId == id); if (agreement != null) { agreement.Status = agreement.RentalAgreementStatusType.RentalAgreementStatusTypeCode; agreement.RatePeriod = agreement.RatePeriodType.RatePeriodTypeCode; agreement.HetRentalAgreementOvertimeRate = agreement.HetRentalAgreementRate.Where(x => x.Overtime).ToList(); agreement.HetRentalAgreementRate = agreement.HetRentalAgreementRate.Where(x => !x.Overtime).ToList(); } return(agreement); }
public static AitReport MapFromHetRentalAgreement(HetRentalAgreement agreement) { var report = new AitReport { RentalAgreementId = agreement.RentalAgreementId, RentalAgreementNumber = agreement.Number, EquipmentId = agreement.EquipmentId, EquipmentCode = agreement.Equipment?.EquipmentCode, DistrictEquipmentTypeId = agreement.Equipment?.DistrictEquipmentType?.DistrictEquipmentTypeId, DistrictEquipmentName = agreement.Equipment?.DistrictEquipmentType?.DistrictEquipmentName, ProjectId = agreement.ProjectId, ProjectNumber = agreement.Project?.ProvincialProjectNumber, ProjectName = agreement.Project?.Name, DatedOn = agreement.DatedOn, StartDate = agreement.EstimateStartWork, }; return(report); }
/// <summary> /// Printed rental agreement view agreement /// </summary> /// <param name="agreement"></param> /// <param name="agreementCity"></param> /// <returns></returns> public static RentalAgreementPdfViewModel ToPdfModel(this HetRentalAgreement agreement, string agreementCity) { RentalAgreementPdfViewModel pdfModel = new RentalAgreementPdfViewModel(); if (agreement != null) { pdfModel.DatedOn = ConvertDate(agreement.DatedOn); pdfModel.AgreementCity = agreementCity; pdfModel.Equipment = agreement.Equipment; pdfModel.EquipmentRate = agreement.EquipmentRate; pdfModel.EstimateHours = agreement.EstimateHours; pdfModel.EstimateStartWork = ConvertDate(agreement.EstimateStartWork); pdfModel.Id = agreement.RentalAgreementId; pdfModel.Note = agreement.Note; pdfModel.Number = agreement.Number; pdfModel.Project = agreement.Project; pdfModel.RateComment = agreement.RateComment; pdfModel.RatePeriod = agreement.RatePeriodType.Description; pdfModel.RentalAgreementConditions = agreement.HetRentalAgreementCondition.ToList(); pdfModel.RentalAgreementRates = agreement.HetRentalAgreementRate.Where(x => x.Active).ToList(); pdfModel.Status = agreement.RentalAgreementStatusType.Description; pdfModel.ConditionsPresent = agreement.HetRentalAgreementCondition.Count > 0; foreach (HetRentalAgreementCondition condition in pdfModel.RentalAgreementConditions) { if (!string.IsNullOrEmpty(condition.Comment)) { condition.ConditionName = condition.Comment; } } pdfModel = CalculateTotals(pdfModel); } return(pdfModel); }
public static TimeRecordLite GetTimeRecords(int id, int?districtId, DbAppContext context, IConfiguration configuration) { // get fiscal year HetDistrictStatus status = context.HetDistrictStatus.AsNoTracking() .First(x => x.DistrictId == districtId); int?fiscalYear = status.CurrentFiscalYear; // get agreement and time records HetRentalAgreement agreement = context.HetRentalAgreement.AsNoTracking() .Include(x => x.Equipment) .ThenInclude(y => y.DistrictEquipmentType) .ThenInclude(z => z.EquipmentType) .Include(x => x.Project) .Include(x => x.HetTimeRecord) .First(x => x.RentalAgreementId == id); // get the max hours for this equipment type float? hoursYtd = 0.0F; int maxHours = 0; string equipmentCode = ""; if (agreement.Equipment?.EquipmentId != null && agreement.Equipment.DistrictEquipmentType?.EquipmentType != null) { maxHours = Convert.ToInt32(agreement.Equipment.DistrictEquipmentType.EquipmentType.IsDumpTruck ? configuration.GetSection("MaximumHours:DumpTruck").Value : configuration.GetSection("MaximumHours:Default").Value); int equipmentId = agreement.Equipment.EquipmentId; hoursYtd = EquipmentHelper.GetYtdServiceHours(equipmentId, context); equipmentCode = agreement.Equipment.EquipmentCode; } // get the project info string projectName = ""; string projectNumber = ""; if (agreement.Project != null) { projectName = agreement.Project.Name; projectNumber = agreement.Project.ProvincialProjectNumber; } // fiscal year in the status table stores the "start" of the year TimeRecordLite timeRecord = new TimeRecordLite(); if (fiscalYear != null) { DateTime fiscalYearStart = new DateTime((int)fiscalYear, 4, 1); timeRecord.TimeRecords = new List <HetTimeRecord>(); timeRecord.TimeRecords.AddRange(agreement.HetTimeRecord.Where(x => x.WorkedDate >= fiscalYearStart)); } timeRecord.EquipmentCode = equipmentCode; timeRecord.ProjectName = projectName; timeRecord.ProvincialProjectNumber = projectNumber; timeRecord.HoursYtd = hoursYtd; timeRecord.MaximumHours = maxHours; return(timeRecord); }
/// <summary> /// Printed rental agreement view agreement /// </summary> /// <param name="agreement"></param> /// <param name="agreementCity"></param> /// <returns></returns> public static RentalAgreementDocViewModel GetRentalAgreementReportModel(this HetRentalAgreement agreement, string agreementCity) { RentalAgreementDocViewModel docModel = new RentalAgreementDocViewModel(); if (agreement != null) { docModel.AgreementCity = agreementCity; docModel.Equipment = agreement.Equipment; docModel.EquipmentRate = agreement.EquipmentRate; docModel.EstimateHours = agreement.EstimateHours; docModel.EstimateStartWork = ConvertDate(agreement.EstimateStartWork); docModel.Number = agreement.Number; docModel.Project = agreement.Project; docModel.RateComment = agreement.RateComment; docModel.RatePeriod = agreement.RatePeriodType.Description; docModel.AgreementCity = agreement.AgreementCity; docModel.DatedOn = (agreement.DatedOn ?? DateTime.UtcNow).ToString("MM/dd/yyyy"); docModel.DoingBusinessAs = agreement.Equipment.Owner.DoingBusinessAs; docModel.EmailAddress = agreement.Equipment.Owner.PrimaryContact.EmailAddress; // format owner address string tempAddress = agreement.Equipment.Owner.Address2; if (string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.City)) { tempAddress = $"{agreement.Equipment.Owner.City}"; } if (!string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.City) && agreement.Equipment.Owner.City.Trim() != tempAddress.Trim()) { tempAddress = $"{tempAddress}, {agreement.Equipment.Owner.City}"; } if (string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.Province)) { tempAddress = $"{agreement.Equipment.Owner.Province}"; } if (!string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.Province)) { tempAddress = $"{tempAddress}, {agreement.Equipment.Owner.Province}"; } if (string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.PostalCode)) { tempAddress = $"{agreement.Equipment.Owner.PostalCode}"; } if (!string.IsNullOrEmpty(tempAddress) && !string.IsNullOrEmpty(agreement.Equipment.Owner.PostalCode)) { tempAddress = $"{tempAddress} {agreement.Equipment.Owner.PostalCode}"; } agreement.Equipment.Owner.Address2 = tempAddress; // format the note if (!string.IsNullOrEmpty(agreement.Note)) { string temp = Regex.Replace(agreement.Note, @"\n", "<BR>"); string[] tempArray = temp.Split("<BR>"); docModel.Note = new List <NoteLine>(); foreach (string row in tempArray) { NoteLine line = new NoteLine { Line = row }; docModel.Note.Add(line); } } // ensure they are ordered the way they were added docModel.RentalAgreementConditions = agreement.HetRentalAgreementCondition .OrderBy(x => x.RentalAgreementConditionId) .ToList(); docModel.RentalAgreementRates = agreement.HetRentalAgreementRate.Where(x => x.Active).ToList(); docModel.Status = agreement.RentalAgreementStatusType.Description; docModel.ConditionsPresent = agreement.HetRentalAgreementCondition.Count > 0; foreach (HetRentalAgreementCondition condition in docModel.RentalAgreementConditions) { if (!string.IsNullOrEmpty(condition.Comment)) { condition.ConditionName = condition.Comment; } } docModel = CalculateTotals(docModel); // classification (Rental Agreement) docModel.Classification = $"23010-30/{agreement.Number}"; } return(docModel); }
/// <summary> /// Convert to Equipment Lite Model /// </summary> /// <param name="equipment"></param> /// <param name="scoringRules"></param> /// <param name="agreementStatusId"></param> /// <param name="context"></param> /// <returns></returns> public static EquipmentLite ToLiteModel(HetEquipment equipment, SeniorityScoringRules scoringRules, int agreementStatusId, DbAppContext context) { EquipmentLite equipmentLite = new EquipmentLite(); if (equipment != null) { // HETS - 709 [BVT - Adjust the search for Equipment search screen] /* * int numberOfBlocks = 0; * * // get number of blocks for this equipment type * if (equipment.DistrictEquipmentType != null) * { * numberOfBlocks = equipment.DistrictEquipmentType.EquipmentType.IsDumpTruck * ? scoringRules.GetTotalBlocks("DumpTruck") + 1 * : scoringRules.GetTotalBlocks() + 1; * } * * // get equipment seniority * float seniority = 0F; * if (equipment.Seniority != null) * { * seniority = (float)equipment.Seniority; * } * * // get equipment block number * int blockNumber = 0; * if (equipment.BlockNumber != null) * { * blockNumber = (int)equipment.BlockNumber; * } * * // get equipment block number * int numberInBlock = 0; * if (equipment.NumberInBlock != null) * { * numberInBlock = (int)equipment.NumberInBlock; * } */ // map data to light model equipmentLite.Id = equipment.EquipmentId; if (equipment.DistrictEquipmentType != null) { equipmentLite.EquipmentType = equipment.DistrictEquipmentType.DistrictEquipmentName; } if (equipment.Owner != null) { equipmentLite.OwnerName = equipment.Owner.OrganizationName; equipmentLite.OwnerId = equipment.OwnerId; } // HETS - 709 [BVT - Adjust the search for Equipment search screen] //equipmentLite.SeniorityString = FormatSeniorityString(seniority, blockNumber, numberOfBlocks); equipmentLite.SeniorityString = "0"; // HETS - 709 [BVT - Adjust the search for Equipment search screen] //equipmentLite.IsHired = CheckIsHired(equipment.HetRentalAgreement.ToList()); equipmentLite.IsHired = false; // HETS - 709 [BVT - Adjust the search for Equipment search screen] //equipmentLite.SenioritySortOrder = CalculateSenioritySortOrder(blockNumber, numberInBlock); equipmentLite.SenioritySortOrder = 0; equipmentLite.Make = equipment.Make; equipmentLite.Model = equipment.Model; equipmentLite.Size = equipment.Size; equipmentLite.Year = equipment.Year; equipmentLite.EquipmentCode = equipment.EquipmentCode; equipmentLite.EquipmentPrefix = Regex.Match(equipment.EquipmentCode, @"^[^\d-]+").Value; string temp = ""; if (!string.IsNullOrEmpty(equipmentLite.EquipmentPrefix)) { temp = equipment.EquipmentCode.Replace(equipmentLite.EquipmentPrefix, ""); } temp = temp.Replace("-", ""); equipmentLite.EquipmentNumber = !string.IsNullOrEmpty(temp) ? int.Parse(Regex.Match(temp, @"\d+").Value) : 0; equipmentLite.AttachmentCount = CalculateAttachmentCount(equipment.HetEquipmentAttachment.ToList()); equipmentLite.LastVerifiedDate = equipment.LastVerifiedDate; equipmentLite.Status = equipment.EquipmentStatusType.EquipmentStatusTypeCode; equipmentLite.LocalArea = equipment.LocalArea.Name; // get project HetRentalAgreement agreement = context.HetRentalAgreement .AsNoTracking() .Include(x => x.Project) .Include(x => x.Equipment) .FirstOrDefault(x => x.RentalAgreementStatusTypeId == agreementStatusId && x.EquipmentId == equipmentLite.Id); if (agreement?.Project != null) { equipmentLite.ProjectId = agreement.Project.ProjectId; equipmentLite.ProjectName = agreement.Project.Name; } } return(equipmentLite); }
/// <summary> /// Map data /// </summary> /// <param name="dbContext"></param> /// <param name="oldObject"></param> /// <param name="timeRecord"></param> /// <param name="systemId"></param> /// <param name="maxTimeSheetIndex"></param> private static void CopyToTimeRecorded(DbAppContext dbContext, ImportModels.EquipUsage oldObject, ref HetTimeRecord timeRecord, string systemId, ref int maxTimeSheetIndex) { try { if (oldObject.Equip_Id <= 0) { return; } if (oldObject.Project_Id <= 0) { return; } // *********************************************** // we only need records from the current fiscal // so ignore all others // *********************************************** DateTime fiscalStart; if (DateTime.UtcNow.Month == 1 || DateTime.UtcNow.Month == 2 || DateTime.UtcNow.Month == 3) { fiscalStart = new DateTime(DateTime.UtcNow.AddYears(-1).Year, 4, 1); } else { fiscalStart = new DateTime(DateTime.UtcNow.Year, 4, 1); } string tempRecordDate = oldObject.Worked_Dt; if (string.IsNullOrEmpty(tempRecordDate)) { return; // ignore if we don't have a created date } if (!string.IsNullOrEmpty(tempRecordDate)) { DateTime?recordDate = ImportUtility.CleanDate(tempRecordDate); if (recordDate == null || recordDate < fiscalStart) { return; // ignore this record - it is outside of the fiscal years } } // ************************************************ // get the imported equipment record map // ************************************************ string tempId = oldObject.Equip_Id.ToString(); HetImportMap mapEquip = dbContext.HetImportMap.AsNoTracking() .FirstOrDefault(x => x.OldKey == tempId && x.OldTable == ImportEquip.OldTable && x.NewTable == ImportEquip.NewTable); if (mapEquip == null) { return; // ignore and move to the next record } // *********************************************** // find the equipment record // *********************************************** HetEquipment equipment = dbContext.HetEquipment.AsNoTracking() .Include(x => x.LocalArea) .ThenInclude(y => y.ServiceArea) .ThenInclude(z => z.District) .FirstOrDefault(x => x.EquipmentId == mapEquip.NewKey); if (equipment == null) { return; // ignore and move to the next record } // ************************************************ // get the imported project record map // ************************************************ string tempProjectId = oldObject.Project_Id.ToString(); HetImportMap mapProject = dbContext.HetImportMap.AsNoTracking() .FirstOrDefault(x => x.OldKey == tempProjectId && x.OldTable == ImportProject.OldTable && x.NewTable == ImportProject.NewTable); // *********************************************** // find the project record // (or create a project (inactive)) // *********************************************** HetProject project; if (mapProject != null) { project = dbContext.HetProject.AsNoTracking() .FirstOrDefault(x => x.ProjectId == mapProject.NewKey); if (project == null) { throw new ArgumentException(string.Format("Cannot locate Project record (Time Sheet Equip Id: {0}", tempId)); } } else { int districtId = equipment.LocalArea.ServiceArea.District.DistrictId; int?statusId = StatusHelper.GetStatusId(HetProject.StatusComplete, "projectStatus", dbContext); if (statusId == null) { throw new DataException(string.Format("Status Id cannot be null (Time Sheet Equip Id: {0}", tempId)); } // create new project project = new HetProject { DistrictId = districtId, Information = "Created to support Time Record import from BCBid", ProjectStatusTypeId = (int)statusId, Name = "Legacy BCBid Project", AppCreateUserid = systemId, AppCreateTimestamp = DateTime.UtcNow, AppLastUpdateUserid = systemId, AppLastUpdateTimestamp = DateTime.UtcNow }; // save now so we can access it for other time records dbContext.HetProject.Add(project); dbContext.SaveChangesForImport(); // add mapping record ImportUtility.AddImportMapForProgress(dbContext, ImportProject.OldTable, tempProjectId, project.ProjectId, ImportProject.NewTable); dbContext.SaveChangesForImport(); } // *********************************************** // find or create the rental agreement // *********************************************** DateTime?enteredDate = ImportUtility.CleanDate(oldObject.Entered_Dt); // use for the agreement HetRentalAgreement agreement = dbContext.HetRentalAgreement.AsNoTracking() .FirstOrDefault(x => x.EquipmentId == equipment.EquipmentId && x.ProjectId == project.ProjectId && x.DistrictId == equipment.LocalArea.ServiceArea.District.DistrictId); if (agreement == null) { int equipmentId = equipment.EquipmentId; int projectId = project.ProjectId; int districtId = equipment.LocalArea.ServiceArea.District.DistrictId; int?statusId = StatusHelper.GetStatusId(HetRentalAgreement.StatusComplete, "rentalAgreementStatus", dbContext); if (statusId == null) { throw new DataException(string.Format("Status Id cannot be null (Time Sheet Equip Id: {0}", tempId)); } int?agrRateTypeId = StatusHelper.GetRatePeriodId(HetRatePeriodType.PeriodDaily, dbContext); if (agrRateTypeId == null) { throw new DataException("Rate Period Id cannot be null"); } int?year = (ImportUtility.CleanDate(oldObject.Worked_Dt))?.Year; // create a new agreement record agreement = new HetRentalAgreement { EquipmentId = equipmentId, ProjectId = projectId, DistrictId = districtId, RentalAgreementStatusTypeId = (int)statusId, RatePeriodTypeId = (int)agrRateTypeId, Note = "Created to support Time Record import from BCBid", Number = string.Format("BCBid{0}-{1}-{2}", projectId, equipmentId, year), DatedOn = enteredDate, AppCreateUserid = systemId, AppCreateTimestamp = DateTime.UtcNow, AppLastUpdateUserid = systemId, AppLastUpdateTimestamp = DateTime.UtcNow }; // save now so we can access it for other time records dbContext.HetRentalAgreement.Add(agreement); dbContext.SaveChangesForImport(); } // *********************************************** // create time record // *********************************************** timeRecord = new HetTimeRecord { TimeRecordId = ++maxTimeSheetIndex }; // *********************************************** // set time period type // *********************************************** int?timePeriodTypeId = StatusHelper.GetTimePeriodId(HetTimePeriodType.PeriodDay, dbContext); if (timePeriodTypeId == null) { throw new DataException("Time Period Id cannot be null"); } timeRecord.TimePeriodTypeId = (int)timePeriodTypeId; // *********************************************** // set time record attributes // *********************************************** DateTime?workedDate = ImportUtility.CleanDate(oldObject.Worked_Dt); if (workedDate != null) { timeRecord.WorkedDate = (DateTime)workedDate; } else { throw new DataException(string.Format("Worked Date cannot be null (TimeSheet Index: {0}", maxTimeSheetIndex)); } // get hours worked float?tempHoursWorked = ImportUtility.GetFloatValue(oldObject.Hours); if (tempHoursWorked != null) { timeRecord.Hours = tempHoursWorked; } else { throw new DataException(string.Format("Hours cannot be null (TimeSheet Index: {0}", maxTimeSheetIndex)); } if (enteredDate != null) { timeRecord.EnteredDate = (DateTime)enteredDate; } else { throw new DataException(string.Format("Entered Date cannot be null (TimeSheet Index: {0}", maxTimeSheetIndex)); } // *********************************************** // create time record // *********************************************** int raId = agreement.RentalAgreementId; timeRecord.RentalAgreementId = raId; timeRecord.AppCreateUserid = systemId; timeRecord.AppCreateTimestamp = DateTime.UtcNow; timeRecord.AppLastUpdateUserid = systemId; timeRecord.AppLastUpdateTimestamp = DateTime.UtcNow; dbContext.HetTimeRecord.Add(timeRecord); } catch (Exception ex) { Debug.WriteLine("***Error*** - Worked Date: " + oldObject.Worked_Dt); Debug.WriteLine("***Error*** - Master Time Record Index: " + maxTimeSheetIndex); Debug.WriteLine(ex.Message); throw; } }
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)))); }