diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index bd656de..dcc0b9d 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -1913,6 +1913,33 @@ namespace CarCareTracker.Controllers } return PartialView("_SupplyRecords", result); } + [HttpGet] + public IActionResult GetSupplyRecordsForPlanRecordTemplate(int planRecordTemplateId) + { + var viewModel = new SupplyUsageViewModel(); + var planRecordTemplate = _planRecordTemplateDataAccess.GetPlanRecordTemplateById(planRecordTemplateId); + if (planRecordTemplate != default && planRecordTemplate.VehicleId != default) + { + var supplies = _supplyRecordDataAccess.GetSupplyRecordsByVehicleId(planRecordTemplate.VehicleId); + if (_config.GetServerEnableShopSupplies()) + { + supplies.AddRange(_supplyRecordDataAccess.GetSupplyRecordsByVehicleId(0)); // add shop supplies + } + supplies.RemoveAll(x => x.Quantity <= 0); + bool _useDescending = _config.GetUserConfig(User).UseDescending; + if (_useDescending) + { + supplies = supplies.OrderByDescending(x => x.Date).ToList(); + } + else + { + supplies = supplies.OrderBy(x => x.Date).ToList(); + } + viewModel.Supplies = supplies; + viewModel.Usage = planRecordTemplate.Supplies; + } + return PartialView("_SupplyUsage", viewModel); + } [TypeFilter(typeof(CollaboratorFilter))] [HttpGet] public IActionResult GetSupplyRecordsForRecordsByVehicleId(int vehicleId) @@ -1932,7 +1959,11 @@ namespace CarCareTracker.Controllers { result = result.OrderBy(x => x.Date).ToList(); } - return PartialView("_SupplyUsage", result); + var viewModel = new SupplyUsageViewModel + { + Supplies = result + }; + return PartialView("_SupplyUsage", viewModel); } [HttpPost] public IActionResult SaveSupplyRecordToVehicleId(SupplyRecordInput supplyRecord) @@ -2024,15 +2055,11 @@ namespace CarCareTracker.Controllers { //check if template name already taken. var existingRecord = _planRecordTemplateDataAccess.GetPlanRecordTemplatesByVehicleId(planRecord.VehicleId).Where(x => x.Description == planRecord.Description).Any(); - if (existingRecord) + if (planRecord.Id == default && existingRecord) { return Json(new OperationResponse { Success = false, Message = "A template with that description already exists for this vehicle" }); } planRecord.Files = planRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList(); - if (planRecord.Supplies.Any() && planRecord.CopySuppliesAttachment) - { - planRecord.Files.AddRange(GetSuppliesAttachments(planRecord.Supplies)); - } var result = _planRecordTemplateDataAccess.SavePlanRecordTemplateToVehicle(planRecord); return Json(new OperationResponse { Success = result, Message = result ? "Template Added" : StaticHelper.GenericErrorMessage }); } @@ -2082,6 +2109,10 @@ namespace CarCareTracker.Controllers if (existingRecord.Supplies.Any()) { existingRecord.RequisitionHistory = RequisitionSupplyRecordsByUsage(existingRecord.Supplies, DateTime.Parse(existingRecord.DateCreated), existingRecord.Description); + if (existingRecord.CopySuppliesAttachment) + { + existingRecord.Files.AddRange(GetSuppliesAttachments(existingRecord.Supplies)); + } } var result = _planRecordDataAccess.SavePlanRecordToVehicle(existingRecord.ToPlanRecord()); return Json(new OperationResponse { Success = result, Message = result ? "Plan Record Added" : StaticHelper.GenericErrorMessage }); @@ -2179,6 +2210,12 @@ namespace CarCareTracker.Controllers return Json(result); } [HttpGet] + public IActionResult GetPlanRecordTemplateForEditById(int planRecordTemplateId) + { + var result = _planRecordTemplateDataAccess.GetPlanRecordTemplateById(planRecordTemplateId); + return PartialView("_PlanRecordTemplateEditModal", result); + } + [HttpGet] public IActionResult GetPlanRecordForEditById(int planRecordId) { var result = _planRecordDataAccess.GetPlanRecordById(planRecordId); diff --git a/Models/Supply/SupplyUsageViewModel.cs b/Models/Supply/SupplyUsageViewModel.cs new file mode 100644 index 0000000..4b951f2 --- /dev/null +++ b/Models/Supply/SupplyUsageViewModel.cs @@ -0,0 +1,8 @@ +namespace CarCareTracker.Models +{ + public class SupplyUsageViewModel + { + public List Supplies { get; set; } = new List(); + public List Usage { get; set; } = new List(); + } +} diff --git a/Views/Vehicle/_PlanRecordModal.cshtml b/Views/Vehicle/_PlanRecordModal.cshtml index 3f3a72b..a4e4269 100644 --- a/Views/Vehicle/_PlanRecordModal.cshtml +++ b/Views/Vehicle/_PlanRecordModal.cshtml @@ -101,10 +101,6 @@ } @@ -130,7 +126,8 @@ id: @Model.Id, dateCreated: decodeHTMLEntities('@(Model.DateCreated)'), reminderRecordId: decodeHTMLEntities('@Model.ReminderRecordId'), - createdFromReminder: @Model.CreatedFromReminder.ToString().ToLower() + createdFromReminder: @Model.CreatedFromReminder.ToString().ToLower(), + isTemplate: false } } \ No newline at end of file diff --git a/Views/Vehicle/_PlanRecordTemplateEditModal.cshtml b/Views/Vehicle/_PlanRecordTemplateEditModal.cshtml new file mode 100644 index 0000000..acd1d7e --- /dev/null +++ b/Views/Vehicle/_PlanRecordTemplateEditModal.cshtml @@ -0,0 +1,117 @@ +@using CarCareTracker.Helper +@inject IConfigHelper config +@inject ITranslationHelper translator +@model PlanRecordInput +@{ + var isNew = Model.Id == 0; + var userConfig = config.GetUserConfig(User); + var userLanguage = userConfig.UserLanguage; +} + + + +@await Html.PartialAsync("_SupplyRequisitionHistory", Model.RequisitionHistory) + \ No newline at end of file diff --git a/Views/Vehicle/_PlanRecordTemplateModal.cshtml b/Views/Vehicle/_PlanRecordTemplateModal.cshtml index 600639f..b0ca4fc 100644 --- a/Views/Vehicle/_PlanRecordTemplateModal.cshtml +++ b/Views/Vehicle/_PlanRecordTemplateModal.cshtml @@ -20,7 +20,7 @@ @translator.Translate(userLanguage,"Description") @translator.Translate(userLanguage, "Use") - @translator.Translate(userLanguage, "Delete") + @translator.Translate(userLanguage, "Edit") @@ -67,7 +67,7 @@ } - + } diff --git a/Views/Vehicle/_PlanRecords.cshtml b/Views/Vehicle/_PlanRecords.cshtml index b01cba8..2e52c2d 100644 --- a/Views/Vehicle/_PlanRecords.cshtml +++ b/Views/Vehicle/_PlanRecords.cshtml @@ -28,6 +28,8 @@ } @@ -102,7 +104,7 @@ -