feat: price summary

This commit is contained in:
Methapon Metanipat 2024-10-10 09:24:02 +07:00
parent 47272f46de
commit b292e00380
4 changed files with 85 additions and 32 deletions

View file

@ -2,7 +2,15 @@
import { useI18n } from 'vue-i18n';
import { storeToRefs } from 'pinia';
import { useQuasar } from 'quasar';
import { nextTick, onBeforeMount, onMounted, reactive, ref, watch } from 'vue';
import {
computed,
nextTick,
onBeforeMount,
onMounted,
reactive,
ref,
watch,
} from 'vue';
import { dialog } from 'stores/utils';
// NOTE: Import stores
@ -53,6 +61,8 @@ import {
columnsAttachment,
} from 'src/pages/03_customer-management/constant';
import { group } from 'node:console';
import { precisionRound } from 'src/utils/arithmetic';
import { useConfigStore } from 'src/stores/config';
defineProps<{
readonly?: boolean;
@ -71,6 +81,7 @@ type Node = {
type ProductGroupId = string;
type Id = string;
const configStore = useConfigStore();
const productServiceStore = useProductServiceStore();
const employeeFormStore = useEmployeeForm();
const customerStore = useCustomerStore();
@ -89,6 +100,8 @@ const {
quotationFull,
} = storeToRefs(quotationForm);
const { data: config } = storeToRefs(configStore);
const refSelectZoneEmployee = ref<InstanceType<typeof SelectZone>>();
const mrz = ref<Awaited<ReturnType<typeof parseResultMRZ>>>();
const selectedBranchIssuer = ref('');
@ -115,17 +128,33 @@ const workerList = ref<Employee[]>([]);
const selectedProductGroup = ref('');
const agentPrice = ref(false);
const summaryPrice = ref<{
totalPrice: number;
totalDiscount: number;
vat: number;
finalPrice: number;
}>({
totalPrice: 0,
totalDiscount: 0,
vat: 0,
finalPrice: 0,
});
const finalDiscount = ref(0);
const summaryPrice = computed(() =>
productServiceList.value.reduce(
(a, c) => {
console.log(finalDiscount.value);
const price = precisionRound(c.pricePerUnit * c.amount);
const vat = precisionRound(
(c.pricePerUnit * c.amount - c.discount) * (config.value?.vat || 0.07),
);
a.totalPrice = precisionRound(a.totalPrice + price);
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
a.vat = precisionRound(a.vat + vat);
a.finalPrice = precisionRound(
a.totalPrice - a.totalDiscount + a.vat - Number(finalDiscount.value),
);
return a;
},
{
totalPrice: 0,
totalDiscount: 0,
vat: 0,
finalPrice: 0,
},
),
);
const quotationNo = ref('');
const payBank = ref('');
@ -409,6 +438,7 @@ function changeMode(mode: string) {
}
onMounted(async () => {
await configStore.getConfig();
// get language
const getCurLang = localStorage.getItem('currentLanguage');
if (getCurLang === 'English') {
@ -748,6 +778,7 @@ watch(
v-model:pay-split-count="quotationFormData.paySplitCount"
v-model:pay-split="quotationFormData.paySplit"
:readonly
v-model:final-discount="finalDiscount"
v-model:summary-price="summaryPrice"
/>
</div>
@ -1082,7 +1113,7 @@ watch(
mrz = await runOcr(file, parseResultMRZ);
if (mrz !== null) {
const mapMrz = Object.entries(mrz.result).map(
const mapMrz = Object.entries(mrz.result || {}).map(
([key, value]) => ({
name: key,
value: value,