Files
lubelog/Views/Vehicle/_BulkDataImporter.cshtml
2024-01-03 14:37:04 -07:00

55 lines
2.4 KiB
Plaintext

@model string
<div class="modal-header">
<h5 class="modal-title">Import Data from CSV</h5>
<button type="button" class="btn-close" onclick="hideBulkImportModal()" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<div class="form-group">
<div class="col-12">
<div class="alert alert-warning" role="alert">
In order for this utility to function properly, your CSV file MUST be formatted exactly like the provided sample.
Dates must be supplied in a string.
Numbers must be supplied as numbers without currency formatting.
</div>
<div class="alert alert-danger" role="alert">
Failure to format the data correctly can cause data corruption. Please make sure you make a copy of the local database before proceeding.
</div>
@if (Model == "gas")
{
<a class="btn btn-link" href="/defaults/gassample.csv" target="_blank">Download Sample</a>
}
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<label for="csvFileUploader">Upload CSV File</label>
<input onChange="uploadFileAsync(this)" type="file" multiple accept=".csv" class="form-control-file" id="csvFileUploader">
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="hideBulkImportModal()">Cancel</button>
<button type="button" onclick="importFromCsv()" class="btn btn-primary">Import</button>
</div>
<script>
var uploadedFile = "";
function importFromCsv() {
var vehicleId = GetVehicleId().vehicleId;
var mode = "@Model";
$.post('/Vehicle/ImportToVehicleIdFromCsv', { vehicleId: vehicleId, mode: mode, fileName: uploadedFile }, function (data) {
if (data) {
successToast("Data Imported Successfully");
hideBulkImportModal();
if (mode == "gas") {
getVehicleGasRecords();
}
} else {
errorToast("An error has occurred, please double check the data and try again.");
}
});
}
</script>