made tax record functional.
This commit is contained in:
@@ -82,10 +82,12 @@ namespace CarCareTracker.Controllers
|
|||||||
public IActionResult DeleteVehicle(int vehicleId)
|
public IActionResult DeleteVehicle(int vehicleId)
|
||||||
{
|
{
|
||||||
//Delete all service records, gas records, notes, etc.
|
//Delete all service records, gas records, notes, etc.
|
||||||
_gasRecordDataAccess.DeleteAllGasRecordsByVehicleId(vehicleId);
|
var result = _gasRecordDataAccess.DeleteAllGasRecordsByVehicleId(vehicleId) &&
|
||||||
_serviceRecordDataAccess.DeleteAllServiceRecordsByVehicleId(vehicleId);
|
_serviceRecordDataAccess.DeleteAllServiceRecordsByVehicleId(vehicleId) &&
|
||||||
_noteDataAccess.DeleteNoteByVehicleId(vehicleId);
|
_collisionRecordDataAccess.DeleteAllCollisionRecordsByVehicleId(vehicleId) &&
|
||||||
var result = _dataAccess.DeleteVehicle(vehicleId);
|
_taxRecordDataAccess.DeleteAllTaxRecordsByVehicleId(vehicleId) &&
|
||||||
|
_noteDataAccess.DeleteNoteByVehicleId(vehicleId) &&
|
||||||
|
_dataAccess.DeleteVehicle(vehicleId);
|
||||||
return Json(result);
|
return Json(result);
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation">
|
||||||
<button class="nav-link active" id="garage-tab" data-bs-toggle="tab" data-bs-target="#garage-tab-pane" type="button" role="tab" aria-selected="true"><i class="bi bi-car-front me-2"></i>Garage</button>
|
<button class="nav-link active" id="garage-tab" data-bs-toggle="tab" data-bs-target="#garage-tab-pane" type="button" role="tab" aria-selected="true"><i class="bi bi-car-front me-2"></i>Garage</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item ms-auto" role="presentation">
|
||||||
<button class="nav-link" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings-tab-pane" type="button" role="tab" aria-selected="false"><i class="bi bi-gear me-2"></i>Settings</button>
|
<button class="nav-link" id="help-tab" data-bs-toggle="tab" data-bs-target="#help-tab-pane" type="button" role="tab" aria-selected="false"><i class="bi bi-gear me-2"></i>Help</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content" id="homeTab">
|
<div class="tab-content" id="homeTab">
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane fade" id="settings-tab-pane" role="tabpanel" tabindex="0">
|
<div class="tab-pane fade" id="help-tab-pane" role="tabpanel" tabindex="0">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<script src="~/js/servicerecord.js" asp-append-version="true"></script>
|
<script src="~/js/servicerecord.js" asp-append-version="true"></script>
|
||||||
<script src="~/js/gasrecord.js" asp-append-version="true"></script>
|
<script src="~/js/gasrecord.js" asp-append-version="true"></script>
|
||||||
<script src="~/js/collisionrecord.js" asp-append-version="true"></script>
|
<script src="~/js/collisionrecord.js" asp-append-version="true"></script>
|
||||||
|
<script src="~/js/taxrecord.js" asp-append-version="true"></script>
|
||||||
}
|
}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
77
Views/Vehicle/_TaxRecordModal.cshtml
Normal file
77
Views/Vehicle/_TaxRecordModal.cshtml
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
@model TaxRecordInput
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">@(Model.Id == 0 ? "Add New Tax Record" : "Edit Tax Record")</h5>
|
||||||
|
<button type="button" class="btn-close" onclick="hideAddTaxRecordModal()" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 col-12">
|
||||||
|
<input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;">
|
||||||
|
<label for="taxRecordDate">Date</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" id="taxRecordDate" class="form-control" value="@Model.Date">
|
||||||
|
<span class="input-group-text"><i class="bi bi-calendar-event"></i></span>
|
||||||
|
</div>
|
||||||
|
<label for="taxRecordDescription">Description</label>
|
||||||
|
<input type="text" id="taxRecordDescription" class="form-control" value="@Model.Description">
|
||||||
|
<label for="taxRecordCost">Cost</label>
|
||||||
|
<input type="number" id="taxRecordCost" class="form-control" value="@Model.Cost">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 col-12">
|
||||||
|
<label for="taxRecordNotes">Notes(optional)</label>
|
||||||
|
<textarea id="taxRecordNotes" class="form-control" rows="5">@Model.Notes</textarea>
|
||||||
|
@if (Model.Files.Any())
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<label>Uploaded Documents</label>
|
||||||
|
@foreach (UploadedFiles filesUploaded in Model.Files)
|
||||||
|
{
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<a type="button" class="btn btn-link" href="@filesUploaded.Location" target="_blank">@filesUploaded.Name</a>
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-danger" onclick="deleteTaxRecordFile('@filesUploaded.Location', this)"><i class="bi bi-trash"></i></button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<label for="taxRecordFiles">Upload more documents</label>
|
||||||
|
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="taxRecordFiles">
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<label for="taxRecordFiles">Upload documents(optional)</label>
|
||||||
|
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="taxRecordFiles">
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
@if (Model.Id > 0)
|
||||||
|
{
|
||||||
|
<button type="button" class="btn btn-danger" onclick="deleteTaxRecord(@Model.Id)" style="margin-right:auto;">Delete</button>
|
||||||
|
}
|
||||||
|
<button type="button" class="btn btn-secondary" onclick="hideAddTaxRecordModal()">Cancel</button>
|
||||||
|
@if (Model.Id == 0)
|
||||||
|
{
|
||||||
|
<button type="button" class="btn btn-primary" onclick="saveTaxRecordToVehicle()">Add New Tax Record</button>
|
||||||
|
}
|
||||||
|
else if (Model.Id > 0)
|
||||||
|
{
|
||||||
|
<button type="button" class="btn btn-primary" onclick="saveTaxRecordToVehicle(true)">Edit Tax Record</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
var uploadedFiles = [];
|
||||||
|
getUploadedFilesFromModel();
|
||||||
|
function getUploadedFilesFromModel() {
|
||||||
|
@foreach (UploadedFiles filesUploaded in Model.Files)
|
||||||
|
{
|
||||||
|
@:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getTaxRecordModelData() {
|
||||||
|
return { id: @Model.Id}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
45
Views/Vehicle/_TaxRecords.cshtml
Normal file
45
Views/Vehicle/_TaxRecords.cshtml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
@model List<TaxRecord>
|
||||||
|
<div class="row">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div class="d-flex align-items-center flex-wrap">
|
||||||
|
<span class="ms-2 badge bg-success">@($"# of Tax Records: {Model.Count()}")</span>
|
||||||
|
<span class="ms-2 badge bg-primary">@($"Total: {Model.Sum(x => x.Cost).ToString("C")}")</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button onclick="showAddTaxRecordModal()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>Add Tax Record</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row vehicleDetailTabContainer">
|
||||||
|
<div class="col-12">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr class="d-flex">
|
||||||
|
<th scope="col" class="col-1">Date</th>
|
||||||
|
<th scope="col" class="col-6">Description</th>
|
||||||
|
<th scope="col" class="col-2">Cost</th>
|
||||||
|
<th scope="col" class="col-3">Notes</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (TaxRecord taxRecord in Model)
|
||||||
|
{
|
||||||
|
<tr class="d-flex" style="cursor:pointer;" onclick="showEditTaxRecordModal(@taxRecord.Id)">
|
||||||
|
<td class="col-1">@taxRecord.Date.ToShortDateString()</td>
|
||||||
|
<td class="col-6">@taxRecord.Description</td>
|
||||||
|
<td class="col-2">@taxRecord.Cost.ToString("C")</td>
|
||||||
|
<td class="col-3 text-truncate">@taxRecord.Notes</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="modal fade" id="taxRecordModal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-lg" role="document">
|
||||||
|
<div class="modal-content" id="taxRecordModalContent">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
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":
|
case "accident-tab":
|
||||||
getVehicleCollisionRecords(vehicleId);
|
getVehicleCollisionRecords(vehicleId);
|
||||||
break;
|
break;
|
||||||
|
case "tax-tab":
|
||||||
|
getVehicleTaxRecords(vehicleId);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
switch (e.relatedTarget.id) { //clear out previous tabs with grids in them to help with performance
|
switch (e.relatedTarget.id) { //clear out previous tabs with grids in them to help with performance
|
||||||
case "servicerecord-tab":
|
case "servicerecord-tab":
|
||||||
@@ -39,6 +42,9 @@ $(document).ready(function () {
|
|||||||
case "accident-tab":
|
case "accident-tab":
|
||||||
$("#accident-tab-pane").html("");
|
$("#accident-tab-pane").html("");
|
||||||
break;
|
break;
|
||||||
|
case "tax-tab":
|
||||||
|
$("#tax-tab-pane").html("");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getVehicleServiceRecords(vehicleId);
|
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) {
|
function editVehicle(vehicleId) {
|
||||||
$.get(`/Vehicle/GetEditVehiclePartialViewById?vehicleId=${vehicleId}`, function (data) {
|
$.get(`/Vehicle/GetEditVehiclePartialViewById?vehicleId=${vehicleId}`, function (data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user