diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 27b1762..2e7cf13 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -1250,7 +1250,7 @@ namespace CarCareTracker.Controllers return PartialView("_PlanRecordModal", new PlanRecordInput()); } [HttpPost] - public IActionResult UpdatePlanRecordProgress(int planRecordId, PlanProgress planProgress) + public IActionResult UpdatePlanRecordProgress(int planRecordId, PlanProgress planProgress, int odometer = 0) { var existingRecord = _planRecordDataAccess.GetPlanRecordById(planRecordId); existingRecord.Progress = planProgress; @@ -1265,10 +1265,11 @@ namespace CarCareTracker.Controllers { VehicleId = existingRecord.VehicleId, Date = DateTime.Now, - Mileage = 0, + Mileage = odometer, Description = existingRecord.Description, Cost = existingRecord.Cost, - Notes = existingRecord.Notes + Notes = existingRecord.Notes, + Files = existingRecord.Files }; _serviceRecordDataAccess.SaveServiceRecordToVehicle(newRecord); } else if (existingRecord.ImportMode == ImportMode.RepairRecord) @@ -1277,10 +1278,11 @@ namespace CarCareTracker.Controllers { VehicleId = existingRecord.VehicleId, Date = DateTime.Now, - Mileage = 0, + Mileage = odometer, Description = existingRecord.Description, Cost = existingRecord.Cost, - Notes = existingRecord.Notes + Notes = existingRecord.Notes, + Files = existingRecord.Files }; _collisionRecordDataAccess.SaveCollisionRecordToVehicle(newRecord); } else if (existingRecord.ImportMode == ImportMode.UpgradeRecord) @@ -1289,10 +1291,11 @@ namespace CarCareTracker.Controllers { VehicleId = existingRecord.VehicleId, Date = DateTime.Now, - Mileage = 0, + Mileage = odometer, Description = existingRecord.Description, Cost = existingRecord.Cost, - Notes = existingRecord.Notes + Notes = existingRecord.Notes, + Files = existingRecord.Files }; _upgradeRecordDataAccess.SaveUpgradeRecordToVehicle(newRecord); } diff --git a/wwwroot/js/planrecord.js b/wwwroot/js/planrecord.js index 8e3a868..4c73446 100644 --- a/wwwroot/js/planrecord.js +++ b/wwwroot/js/planrecord.js @@ -132,15 +132,47 @@ function dropBox(event, newProgress) { } function updatePlanRecordProgress(newProgress) { if (draggedId > 0) { - $.post('/Vehicle/UpdatePlanRecordProgress', { planRecordId: draggedId, planProgress: newProgress }, function (data) { - if (data) { - successToast("Plan Progress Updated"); - var vehicleId = GetVehicleId().vehicleId; - getVehiclePlanRecords(vehicleId); - } else { - errorToast("An error has occurred, please try again later."); - } - }); + if (newProgress == 'Done') { + //if user is marking the task as done, we will want them to enter the mileage so that we can auto-convert it. + Swal.fire({ + title: 'Mark Task as Done?', + html: `
To confirm, please enter the current odometer reading on your vehicle, as we also need the current odometer to auto convert the task into the relevant record.
+ + `, + confirmButtonText: 'Confirm', + focusConfirm: false, + preConfirm: () => { + const odometer = $("#inputOdometer").val(); + if (!odometer || isNaN(odometer)) { + Swal.showValidationMessage(`Please enter an odometer reading`) + } + return { odometer } + }, + }).then(function (result) { + if (result.isConfirmed) { + $.post('/Vehicle/UpdatePlanRecordProgress', { planRecordId: draggedId, planProgress: newProgress, odometer: result.value.odometer }, function (data) { + if (data) { + successToast("Plan Progress Updated"); + var vehicleId = GetVehicleId().vehicleId; + getVehiclePlanRecords(vehicleId); + } else { + errorToast("An error has occurred, please try again later."); + } + }); + } + draggedId = 0; + }); + } else { + $.post('/Vehicle/UpdatePlanRecordProgress', { planRecordId: draggedId, planProgress: newProgress }, function (data) { + if (data) { + successToast("Plan Progress Updated"); + var vehicleId = GetVehicleId().vehicleId; + getVehiclePlanRecords(vehicleId); + } else { + errorToast("An error has occurred, please try again later."); + } + }); + draggedId = 0; + } } - draggedId = 0; } \ No newline at end of file