added logic to convert numbers to booleans, fixed capitalization issues

This commit is contained in:
Alex H
2023-04-17 21:43:23 +00:00
parent d64777dca6
commit b99c3921d7

View File

@@ -37,7 +37,7 @@ export default {
odoReading: null, odoReading: null,
isTankFull: null, isTankFull: null,
hasMissedFillup: null, hasMissedFillup: null,
comments: null, // [int] comments: [], // [int]
fillingStation: null, fillingStation: null,
date: null, date: null,
fuelSubType: null, fuelSubType: null,
@@ -94,7 +94,7 @@ export default {
}, '') }, '')
} }
const calculateTotal = (row) => { const calculateTotal = (row) => {
return this.fileHeadingMap.totalAmount === -1 return this.fileHeadingMap.totalAmount === "-1"
? (row[this.fileHeadings.fuelQuantity] * row[this.fileHeadings.perUnitPrice]).toFixed(2) ? (row[this.fileHeadings.fuelQuantity] * row[this.fileHeadings.perUnitPrice]).toFixed(2)
: row[this.fileHeadingMap.totalAmount] : row[this.fileHeadingMap.totalAmount]
} }
@@ -120,8 +120,13 @@ export default {
item[k] = calculateTotal(row) item[k] = calculateTotal(row)
} else if (this.isFullTankString) { } else if (this.isFullTankString) {
item[k] = setFullTank(row) item[k] = setFullTank(row)
} else if (this.invertFullTank) { } else if (k === 'isTankFull') {
item[k] = !row[headings[k]] if (this.invertFullTank) {
item[k] = Boolean(!row[headings[k]])
} else {
item[k] = Boolean(row[headings[k]])
}
} else if (k === 'hasMissedFillup') {
} else if (k === 'date') { } else if (k === 'date') {
item[k] = new Date(row[headings[k]]).toISOString() item[k] = new Date(row[headings[k]]).toISOString()
} else { } else {
@@ -157,8 +162,9 @@ export default {
position: 'is-bottom', position: 'is-bottom',
type: 'is-danger', type: 'is-danger',
}) })
if (ex.response && ex.response.data.errors) { console.log(ex)
this.errors = ex.response.data.errors if (ex.response && ex.response.data.error) {
this.errors.push(ex.response.data.error)
} }
}) })
} catch (e) { } catch (e) {
@@ -171,14 +177,10 @@ export default {
}, },
checkFieldString() { checkFieldString() {
const tankFull = this.fileData[1][this.fileHeadingMap.isTankFull] const tankFull = this.fileData[1][this.fileHeadingMap.isTankFull]
if (typeof tankFull !== 'boolean') { if (typeof tankFull !== 'boolean' && typeof tankFull === 'string') {
if (typeof tankFull === 'string' && tankFull.length > 0) { this.isFullTankString = true
this.isFullTankString = true
} else {
this.errors.push('The value of Tank Full needs to be a boolean (true,false) or consistent string.')
}
} }
}, }
}, },
} }
</script> </script>
@@ -200,9 +202,7 @@ export default {
<li>{{ $t('importhintvehiclecreated') }}</li> <li>{{ $t('importhintvehiclecreated') }}</li>
<li v-html="$t('importhintcurrdist')"></li> <li v-html="$t('importhintcurrdist')"></li>
<li v-html="$t('importhintunits')"></li> <li v-html="$t('importhintunits')"></li>
<li <li><b>{{ $t('dontimportagain') }}</b></li>
><b>{{ $t('dontimportagain') }}</b></li
>
</ol> </ol>
</div> </div>
</div> </div>
@@ -270,7 +270,8 @@ export default {
</option> </option>
</b-select> </b-select>
</b-field> </b-field>
<b-field :label="$t('per', { '0': $t('price'), '1': $t('unit.short.' + selectedVehicle.fuelUnitDetail.key) })"> <b-field
:label="$t('per', { '0': $t('price'), '1': $t('unit.short.' + selectedVehicle.fuelUnitDetail.key) })">
<b-select v-model.number="fileHeadingMap.perUnitPrice" type="number" min="0" step=".001" expanded required> <b-select v-model.number="fileHeadingMap.perUnitPrice" type="number" min="0" step=".001" expanded required>
<option v-for="(option, index) in fileHeadings" :key="index" :value="index"> <option v-for="(option, index) in fileHeadings" :key="index" :value="index">
{{ option }} {{ option }}
@@ -334,7 +335,8 @@ export default {
</b-field> </b-field>
<br /> <br />
<b-field> <b-field>
<b-button tag="button" native-type="submit" type="is-primary" :value="$t('save')" :label="$t('import')" expanded /> <b-button tag="button" native-type="submit" type="is-primary" :value="$t('save')" :label="$t('import')"
expanded />
<p v-if="authError"> There was an error logging in to your account. </p> <p v-if="authError"> There was an error logging in to your account. </p>
</b-field> </b-field>
</span> </span>