Added front end for supplies.
This commit is contained in:
2
wwwroot/defaults/supplysample.csv
Normal file
2
wwwroot/defaults/supplysample.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
Date,PartNumber,PartSupplier,PartQuantity,Description,Cost,Notes
|
||||
1/16/2024,EVA17872045551,Evan Fischer,1,Front Bumper,$95.14,Altima Activities
|
||||
|
121
wwwroot/js/supplyrecord.js
Normal file
121
wwwroot/js/supplyrecord.js
Normal file
@@ -0,0 +1,121 @@
|
||||
function showAddSupplyRecordModal() {
|
||||
$.get('/Vehicle/GetAddSupplyRecordPartialView', function (data) {
|
||||
if (data) {
|
||||
$("#supplyRecordModalContent").html(data);
|
||||
//initiate datepicker
|
||||
initDatePicker($('#supplyRecordDate'));
|
||||
$('#supplyRecordModal').modal('show');
|
||||
}
|
||||
});
|
||||
}
|
||||
function showEditSupplyRecordModal(supplyRecordId) {
|
||||
$.get(`/Vehicle/GetSupplyRecordForEditById?supplyRecordId=${supplyRecordId}`, function (data) {
|
||||
if (data) {
|
||||
$("#supplyRecordModalContent").html(data);
|
||||
//initiate datepicker
|
||||
initDatePicker($('#supplyRecordDate'));
|
||||
$('#supplyRecordModal').modal('show');
|
||||
}
|
||||
});
|
||||
}
|
||||
function hideAddSupplyRecordModal() {
|
||||
$('#supplyRecordModal').modal('hide');
|
||||
}
|
||||
function deleteSupplyRecord(supplyRecordId) {
|
||||
$("#workAroundInput").show();
|
||||
Swal.fire({
|
||||
title: "Confirm Deletion?",
|
||||
text: "Deleted Supply Records cannot be restored.",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Delete",
|
||||
confirmButtonColor: "#dc3545"
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.post(`/Vehicle/DeleteSupplyRecordById?supplyRecordId=${supplyRecordId}`, function (data) {
|
||||
if (data) {
|
||||
hideAddSupplyRecordModal();
|
||||
successToast("Supply Record Deleted");
|
||||
var vehicleId = GetVehicleId().vehicleId;
|
||||
getVehicleSupplyRecords(vehicleId);
|
||||
} else {
|
||||
errorToast("An error has occurred, please try again later.");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$("#workAroundInput").hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
function saveSupplyRecordToVehicle(isEdit) {
|
||||
//get values
|
||||
var formValues = getAndValidateSupplyRecordValues();
|
||||
//validate
|
||||
if (formValues.hasError) {
|
||||
errorToast("Please check the form data");
|
||||
return;
|
||||
}
|
||||
//save to db.
|
||||
$.post('/Vehicle/SaveSupplyRecordToVehicleId', { supplyRecord: formValues }, function (data) {
|
||||
if (data) {
|
||||
successToast(isEdit ? "Supply Record Updated" : "Supply Record Added.");
|
||||
hideAddSupplyRecordModal();
|
||||
saveScrollPosition();
|
||||
getVehicleSupplyRecords(formValues.vehicleId);
|
||||
if (formValues.addReminderRecord) {
|
||||
setTimeout(function () { showAddReminderModal(formValues); }, 500);
|
||||
}
|
||||
} else {
|
||||
errorToast("An error has occurred, please try again later.");
|
||||
}
|
||||
})
|
||||
}
|
||||
function getAndValidateSupplyRecordValues() {
|
||||
var supplyDate = $("#supplyRecordDate").val();
|
||||
var supplyPartNumber = $("#supplyRecordPartNumber").val();
|
||||
var supplyDescription = $("#supplyRecordDescription").val();
|
||||
var supplySupplier = $("#supplyRecordSupplier").val();
|
||||
var supplyQuantity = $("#supplyRecordQuantity").val();
|
||||
var supplyCost = $("#supplyRecordCost").val();
|
||||
var supplyNotes = $("#supplyRecordNotes").val();
|
||||
var vehicleId = GetVehicleId().vehicleId;
|
||||
var supplyRecordId = getSupplyRecordModelData().id;
|
||||
//validation
|
||||
var hasError = false;
|
||||
if (supplyDate.trim() == '') { //eliminates whitespace.
|
||||
hasError = true;
|
||||
$("#supplyRecordDate").addClass("is-invalid");
|
||||
} else {
|
||||
$("#supplyRecordDate").removeClass("is-invalid");
|
||||
}
|
||||
if (supplyDescription.trim() == '') {
|
||||
hasError = true;
|
||||
$("#supplyRecordDescription").addClass("is-invalid");
|
||||
} else {
|
||||
$("#supplyRecordDescription").removeClass("is-invalid");
|
||||
}
|
||||
if (supplyQuantity.trim() == '' || !isValidMoney(supplyQuantity)) {
|
||||
hasError = true;
|
||||
$("#supplyRecordQuantity").addClass("is-invalid");
|
||||
} else {
|
||||
$("#supplyRecordQuantity").removeClass("is-invalid");
|
||||
}
|
||||
if (supplyCost.trim() == '' || !isValidMoney(supplyCost)) {
|
||||
hasError = true;
|
||||
$("#supplyRecordCost").addClass("is-invalid");
|
||||
} else {
|
||||
$("#supplyRecordCost").removeClass("is-invalid");
|
||||
}
|
||||
return {
|
||||
id: supplyRecordId,
|
||||
hasError: hasError,
|
||||
vehicleId: vehicleId,
|
||||
date: supplyDate,
|
||||
partNumber: supplyPartNumber,
|
||||
partSupplier: supplySupplier,
|
||||
description: supplyDescription,
|
||||
cost: supplyCost,
|
||||
notes: supplyNotes,
|
||||
quantity: supplyQuantity,
|
||||
files: uploadedFiles
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,9 @@ $(document).ready(function () {
|
||||
case "upgrade-tab":
|
||||
getVehicleUpgradeRecords(vehicleId);
|
||||
break;
|
||||
case "supply-tab":
|
||||
getVehicleSupplyRecords(vehicleId);
|
||||
break;
|
||||
}
|
||||
switch (e.relatedTarget.id) { //clear out previous tabs with grids in them to help with performance
|
||||
case "servicerecord-tab":
|
||||
@@ -56,6 +59,9 @@ $(document).ready(function () {
|
||||
case "notes-tab":
|
||||
$("#notes-tab-pane").html("");
|
||||
break;
|
||||
case "supply-tab":
|
||||
$("#supply-tab-pane").html("");
|
||||
break;
|
||||
}
|
||||
});
|
||||
var defaultTab = GetDefaultTab().tab;
|
||||
@@ -84,6 +90,9 @@ $(document).ready(function () {
|
||||
case "UpgradeRecord":
|
||||
getVehicleUpgradeRecords(vehicleId);
|
||||
break;
|
||||
case "SupplyRecord":
|
||||
getVehicleSupplyRecords(vehicleId);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -104,6 +113,15 @@ function getVehicleServiceRecords(vehicleId) {
|
||||
}
|
||||
});
|
||||
}
|
||||
function getVehicleSupplyRecords(vehicleId) {
|
||||
$.get(`/Vehicle/GetSupplyRecordsByVehicleId?vehicleId=${vehicleId}`, function (data) {
|
||||
if (data) {
|
||||
$("#supply-tab-pane").html(data);
|
||||
restoreScrollPosition();
|
||||
getVehicleHaveImportantReminders(vehicleId);
|
||||
}
|
||||
});
|
||||
}
|
||||
function getVehicleUpgradeRecords(vehicleId) {
|
||||
$.get(`/Vehicle/GetUpgradeRecordsByVehicleId?vehicleId=${vehicleId}`, function (data) {
|
||||
if (data) {
|
||||
|
||||
Reference in New Issue
Block a user