Part number
-
+
+
+
+
+
+
+
+ tariff lookup on close
+
+
+
+
@@ -48,21 +86,24 @@ import Flag from "@/components/UI/Flag.vue";
import InputField from "@/components/UI/InputField.vue";
import AutosuggestSearchbar from "@/components/UI/AutoSuggestSearchBar.vue";
import ModalDialog from "@/components/UI/ModalDialog.vue";
-import {PhArrowCounterClockwise} from "@phosphor-icons/vue";
+import {PhArrowCounterClockwise, PhWarning} from "@phosphor-icons/vue";
import {useMaterialStore} from "@/store/material.js";
import {mapStores} from "pinia";
import {parseNumberFromString} from "@/common.js";
import Modal from "@/components/UI/Modal.vue";
import SelectMaterial from "@/components/layout/material/SelectMaterial.vue";
import {useCustomsStore} from "@/store/customs.js";
+import Checkbox from "@/components/UI/Checkbox.vue";
export default {
name: "MaterialEdit",
components: {
+ Checkbox,
+ PhWarning,
SelectMaterial,
Modal, PhArrowCounterClockwise, ModalDialog, AutosuggestSearchbar, InputField, Flag, IconButton
},
- emits: ["update:tariffRate", "updateMaterial", "update:partNumber", "update:hsCode", "save", "close"],
+ emits: ["update:tariffRate", "updateMaterial", "update:partNumber", "update:hsCode", "save", "close", "startLookup"],
props: {
description: {
type: [String, null],
@@ -72,6 +113,10 @@ export default {
required: true,
validator: (value) => value === null || typeof value === 'string'
},
+ countryId: {
+ required: true,
+ validator: (value) => value === null || typeof value === 'number'
+ },
tariffRate: {
required: true,
validator: (value) => value === null || typeof value === 'number'
@@ -93,11 +138,29 @@ export default {
...mapStores(useMaterialStore, useCustomsStore),
tariffRatePercent() {
return ((this.tariffRate ?? null) !== null) ? (this.tariffRate * 100).toFixed(2) : '';
+ },
+ showTariffWarning() {
+ return this.customsStore.showWarning(this.countryId);
+ },
+ tariffIsDefault() {
+ return this.tariffInfo?.default ?? false;
+ },
+ tariffInfo() {
+ return this.customsStore.findByCountryId(this.countryId);
+ },
+ measures() {
+ return this.tariffInfo.measures;
+ },
+ showCheckbox() {
+ return this.countryId === null;
+ },
+ disableTariff() {
+ return !this.doLookup;
}
},
data() {
return {
-
+ doLookup: false
}
},
created() {
@@ -115,22 +178,54 @@ export default {
}
});
},
- validateTariffRate(event) {
- const percentValue = parseNumberFromString(event.target.value, 2, true);
+ validateTariffRateEvent(event) {
+ event.target.value = this.validateTariffRate(event.target.value);
+ },
+ validateTariffRate(value) {
+ const percentValue = parseNumberFromString(value, 2, true);
const validatedPercent = (percentValue === null) ? null : Math.max(0, Math.min(999.99, percentValue));
const validatedDecimal = (validatedPercent === null) ? null : validatedPercent / 100;
if (validatedDecimal !== this.tariffRate) {
- this.$emit('update:tariffRate', validatedDecimal);
+ this.$emit('update:tariffRate', this.roundNumber(validatedDecimal, 4));
}
- event.target.value = validatedPercent === null ? null : validatedPercent.toFixed(2);
+ return validatedPercent === null ? null : validatedPercent.toFixed(2);
+
+ },
+ roundNumber(number, digits) {
+ const multiple = Math.pow(10, digits);
+ return Math.round(number * multiple) / multiple;
},
async fetchHsCode(query) {
- const hsCodeQuery = {searchTerm: query};
- await this.customsStore.setQuery(hsCodeQuery);
- return this.customsStore.hsCodes;
+ return await this.customsStore.findHsCode(query);
+ },
+ hsCodeChanged() {
+ const currentValue = this.$refs.hsCodeSearchbar.searchQuery;
+ this.$emit("update:hsCode", currentValue);
+ },
+ async hsCodeSelected(hsCode) {
+ let save = false;
+
+ if (hsCode !== this.hsCode) {
+ this.$emit("update:hsCode", hsCode)
+ save = true;
+ }
+
+ if ((this.countryId ?? null) !== null) {
+ const query = {hsCode: hsCode, countryIds: [this.countryId]};
+ await this.customsStore.findTariffRate(query);
+ this.validateTariffRate((this.customsStore.findByCountryId(this.countryId)?.value ?? 0.03) * 100);
+ save = true;
+ }
+
+ if (save)
+ this.$emit('save', 'material');
+ },
+ checkBoxChanged(checked) {
+ this.doLookup = checked
+ this.$emit('startLookup', checked);
}
}
}
@@ -139,11 +234,42 @@ export default {