feat: use util calc price
This commit is contained in:
parent
e538998472
commit
5b13ff98b9
1 changed files with 16 additions and 21 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { precisionRound } from 'src/utils/arithmetic';
|
||||||
|
|
||||||
import { QTableProps } from 'quasar';
|
import { QTableProps } from 'quasar';
|
||||||
import TableComponents from 'src/components/TableComponents.vue';
|
import TableComponents from 'src/components/TableComponents.vue';
|
||||||
import { QuotationPayload } from 'src/stores/quotations/types';
|
import { QuotationPayload } from 'src/stores/quotations/types';
|
||||||
import { computed } from 'vue';
|
|
||||||
|
|
||||||
const calTax = defineModel('calTax', { default: false });
|
|
||||||
|
|
||||||
defineEmits<{
|
defineEmits<{
|
||||||
(e: 'delete', index: number): void;
|
(e: 'delete', index: number): void;
|
||||||
|
|
@ -14,26 +14,25 @@ const rows = defineModel<
|
||||||
Required<QuotationPayload['productServiceList'][number]>[]
|
Required<QuotationPayload['productServiceList'][number]>[]
|
||||||
>('rows', { required: true });
|
>('rows', { required: true });
|
||||||
|
|
||||||
function calcPrice(data: (typeof rows.value)[number]) {
|
function calcPrice(c: (typeof rows.value)[number]) {
|
||||||
const price = data.pricePerUnit * data.amount;
|
const price = precisionRound(c.pricePerUnit * c.amount);
|
||||||
const discount = Math.round(price * data.discount) / 100;
|
const discount = precisionRound(price * (c.discount || 0));
|
||||||
const vat = Math.round((price - discount) * data.vat) / 100;
|
const vat = precisionRound((price - discount) * c.vat);
|
||||||
|
|
||||||
return (price * 100 - discount * 100 + vat * 100) / 100;
|
return precisionRound(price - discount + vat);
|
||||||
}
|
}
|
||||||
|
|
||||||
const summary = computed(() =>
|
const summary = computed(() =>
|
||||||
rows.value.reduce(
|
rows.value.reduce(
|
||||||
(a, c) => {
|
(a, c) => {
|
||||||
const price = c.pricePerUnit * c.amount;
|
const price = precisionRound(c.pricePerUnit * c.amount);
|
||||||
const discount = Math.round(price * c.discount) / 100;
|
const discount = precisionRound(price - (c.discount || 0));
|
||||||
const vat = Math.round((price - discount) * c.vat) / 100;
|
const vat = precisionRound((price - discount) * c.vat);
|
||||||
|
|
||||||
a.totalPrice = (a.totalPrice * 100 + price * 100) / 100;
|
a.totalPrice = precisionRound(a.totalPrice + price);
|
||||||
a.totalDiscount = (a.totalDiscount * 100 + discount * 100) / 100;
|
a.totalDiscount = precisionRound(a.totalDiscount + discount);
|
||||||
a.vat = (a.vat * 100 + vat * 100) / 100;
|
a.vat = precisionRound(a.vat + vat);
|
||||||
a.finalPrice =
|
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
|
||||||
(a.finalPrice * 100 + price * 100 - discount * 100 + vat * 100) / 100;
|
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
|
|
@ -172,11 +171,7 @@ const columns = [
|
||||||
type="number"
|
type="number"
|
||||||
style="width: 70px"
|
style="width: 70px"
|
||||||
v-model="props.row.discount"
|
v-model="props.row.discount"
|
||||||
>
|
/>
|
||||||
<template v-slot:append>
|
|
||||||
<span class="text-caption no-padding">%</span>
|
|
||||||
</template>
|
|
||||||
</q-input>
|
|
||||||
</q-td>
|
</q-td>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue