From 193a2ab4716a48a7943caf136df1bc2feff6d05e Mon Sep 17 00:00:00 2001 From: ivancheahhh Date: Wed, 3 Jan 2024 12:26:32 -0700 Subject: [PATCH] made tax record functional. --- Controllers/VehicleController.cs | 10 ++- Views/Home/Index.cshtml | 6 +- Views/Vehicle/Index.cshtml | 1 + Views/Vehicle/_TaxRecordModal.cshtml | 77 ++++++++++++++++++ Views/Vehicle/_TaxRecords.cshtml | 45 +++++++++++ wwwroot/js/taxrecord.js | 113 +++++++++++++++++++++++++++ wwwroot/js/vehicle.js | 13 +++ 7 files changed, 258 insertions(+), 7 deletions(-) create mode 100644 Views/Vehicle/_TaxRecordModal.cshtml create mode 100644 Views/Vehicle/_TaxRecords.cshtml create mode 100644 wwwroot/js/taxrecord.js diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 057a036..76e4c89 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -82,10 +82,12 @@ namespace CarCareTracker.Controllers public IActionResult DeleteVehicle(int vehicleId) { //Delete all service records, gas records, notes, etc. - _gasRecordDataAccess.DeleteAllGasRecordsByVehicleId(vehicleId); - _serviceRecordDataAccess.DeleteAllServiceRecordsByVehicleId(vehicleId); - _noteDataAccess.DeleteNoteByVehicleId(vehicleId); - var result = _dataAccess.DeleteVehicle(vehicleId); + var result = _gasRecordDataAccess.DeleteAllGasRecordsByVehicleId(vehicleId) && + _serviceRecordDataAccess.DeleteAllServiceRecordsByVehicleId(vehicleId) && + _collisionRecordDataAccess.DeleteAllCollisionRecordsByVehicleId(vehicleId) && + _taxRecordDataAccess.DeleteAllTaxRecordsByVehicleId(vehicleId) && + _noteDataAccess.DeleteNoteByVehicleId(vehicleId) && + _dataAccess.DeleteVehicle(vehicleId); return Json(result); } [HttpPost] diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index bc6d524..5aa112a 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -15,8 +15,8 @@ -
@@ -26,7 +26,7 @@
-
+
diff --git a/Views/Vehicle/Index.cshtml b/Views/Vehicle/Index.cshtml index 4a9cc50..0f8642b 100644 --- a/Views/Vehicle/Index.cshtml +++ b/Views/Vehicle/Index.cshtml @@ -7,6 +7,7 @@ + }
diff --git a/Views/Vehicle/_TaxRecordModal.cshtml b/Views/Vehicle/_TaxRecordModal.cshtml new file mode 100644 index 0000000..408adbe --- /dev/null +++ b/Views/Vehicle/_TaxRecordModal.cshtml @@ -0,0 +1,77 @@ +@model TaxRecordInput + + + + \ No newline at end of file diff --git a/Views/Vehicle/_TaxRecords.cshtml b/Views/Vehicle/_TaxRecords.cshtml new file mode 100644 index 0000000..88689dd --- /dev/null +++ b/Views/Vehicle/_TaxRecords.cshtml @@ -0,0 +1,45 @@ +@model List +
+
+
+ @($"# of Tax Records: {Model.Count()}") + @($"Total: {Model.Sum(x => x.Cost).ToString("C")}") +
+
+ +
+
+
+
+
+ + + + + + + + + + + @foreach (TaxRecord taxRecord in Model) + { + + + + + + + } + +
DateDescriptionCostNotes
@taxRecord.Date.ToShortDateString()@taxRecord.Description@taxRecord.Cost.ToString("C")@taxRecord.Notes
+
+
+ + + \ No newline at end of file diff --git a/wwwroot/js/taxrecord.js b/wwwroot/js/taxrecord.js new file mode 100644 index 0000000..1e665ab --- /dev/null +++ b/wwwroot/js/taxrecord.js @@ -0,0 +1,113 @@ +function showAddTaxRecordModal() { + $.get('/Vehicle/GetAddTaxRecordPartialView', function (data) { + if (data) { + $("#taxRecordModalContent").html(data); + //initiate datepicker + $('#taxRecordDate').datepicker({ + endDate: "+0d" + }); + $('#taxRecordModal').modal('show'); + } + }); +} +function showEditTaxRecordModal(taxRecordId) { + $.get(`/Vehicle/GetTaxRecordForEditById?taxRecordId=${taxRecordId}`, function (data) { + if (data) { + $("#taxRecordModalContent").html(data); + //initiate datepicker + $('#taxRecordDate').datepicker({ + endDate: "+0d" + }); + $('#taxRecordModal').modal('show'); + } + }); +} +function hideAddTaxRecordModal() { + $('#taxRecordModal').modal('hide'); +} +function deleteTaxRecord(taxRecordId) { + $("#workAroundInput").show(); + Swal.fire({ + title: "Confirm Deletion?", + text: "Deleted Tax Records cannot be restored.", + showCancelButton: true, + confirmButtonText: "Delete", + confirmButtonColor: "#dc3545" + }).then((result) => { + if (result.isConfirmed) { + $.post(`/Vehicle/DeleteTaxRecordById?taxRecordId=${taxRecordId}`, function (data) { + if (data) { + hideAddTaxRecordModal(); + successToast("Tax Record Deleted"); + var vehicleId = GetVehicleId().vehicleId; + getVehicleTaxRecords(vehicleId); + } else { + errorToast("An error has occurred, please try again later."); + } + }); + } else { + $("#workAroundInput").hide(); + } + }); +} +function saveTaxRecordToVehicle(isEdit) { + //get values + var formValues = getAndValidateTaxRecordValues(); + //validate + if (formValues.hasError) { + errorToast("Please check the form data"); + return; + } + //save to db. + $.post('/Vehicle/SaveTaxRecordToVehicleId', { taxRecord: formValues }, function (data) { + if (data) { + successToast(isEdit ? "Tax Record Updated" : "Tax Record Added."); + hideAddTaxRecordModal(); + getVehicleTaxRecords(formValues.vehicleId); + } else { + errorToast("An error has occurred, please try again later."); + } + }) +} +function getAndValidateTaxRecordValues() { + var taxDate = $("#taxRecordDate").val(); + var taxDescription = $("#taxRecordDescription").val(); + var taxCost = $("#taxRecordCost").val(); + var taxNotes = $("#taxRecordNotes").val(); + var vehicleId = GetVehicleId().vehicleId; + var taxRecordId = getTaxRecordModelData().id; + //validation + var hasError = false; + if (taxDate.trim() == '') { //eliminates whitespace. + hasError = true; + $("#taxRecordDate").addClass("is-invalid"); + } else { + $("#taxRecordDate").removeClass("is-invalid"); + } + if (taxDescription.trim() == '') { + hasError = true; + $("#taxRecordDescription").addClass("is-invalid"); + } else { + $("#taxRecordDescription").removeClass("is-invalid"); + } + if (taxCost.trim() == '') { + hasError = true; + $("#taxRecordCost").addClass("is-invalid"); + } else { + $("#taxRecordCost").removeClass("is-invalid"); + } + return { + id: taxRecordId, + hasError: hasError, + vehicleId: vehicleId, + date: taxDate, + description: taxDescription, + cost: taxCost, + notes: taxNotes, + files: uploadedFiles + } +} +function deleteTaxRecordFile(fileLocation, event) { + event.parentElement.remove(); + uploadedFiles = uploadedFiles.filter(x => x.location != fileLocation); +} \ No newline at end of file diff --git a/wwwroot/js/vehicle.js b/wwwroot/js/vehicle.js index 0532fa2..209a7a6 100644 --- a/wwwroot/js/vehicle.js +++ b/wwwroot/js/vehicle.js @@ -28,6 +28,9 @@ $(document).ready(function () { case "accident-tab": getVehicleCollisionRecords(vehicleId); break; + case "tax-tab": + getVehicleTaxRecords(vehicleId); + break; } switch (e.relatedTarget.id) { //clear out previous tabs with grids in them to help with performance case "servicerecord-tab": @@ -39,6 +42,9 @@ $(document).ready(function () { case "accident-tab": $("#accident-tab-pane").html(""); break; + case "tax-tab": + $("#tax-tab-pane").html(""); + break; } }); getVehicleServiceRecords(vehicleId); @@ -72,6 +78,13 @@ function getVehicleCollisionRecords(vehicleId) { } }); } +function getVehicleTaxRecords(vehicleId) { + $.get(`/Vehicle/GetTaxRecordsByVehicleId?vehicleId=${vehicleId}`, function (data) { + if (data) { + $("#tax-tab-pane").html(data); + } + }); +} function editVehicle(vehicleId) { $.get(`/Vehicle/GetEditVehiclePartialViewById?vehicleId=${vehicleId}`, function (data) { if (data) {