made tax record functional.
This commit is contained in:
113
wwwroot/js/taxrecord.js
Normal file
113
wwwroot/js/taxrecord.js
Normal file
@@ -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);
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user