refactor: use price in quotation instead
This commit is contained in:
parent
5c3d2f1499
commit
ae88440870
2 changed files with 31 additions and 72 deletions
|
|
@ -111,7 +111,7 @@ const formTaskList = ref<
|
|||
let taskListGroup = computed(() => {
|
||||
const cacheData = formTaskList.value.reduce<
|
||||
{
|
||||
product: RequestWork['productService']['product'];
|
||||
product: RequestWork['productService'];
|
||||
list: RequestWork[];
|
||||
}[]
|
||||
>((acc, curr) => {
|
||||
|
|
@ -129,7 +129,7 @@ let taskListGroup = computed(() => {
|
|||
exist.list.push(task.requestWork);
|
||||
} else {
|
||||
acc.push({
|
||||
product: task.requestWork.productService.product,
|
||||
product: task.requestWork.productService,
|
||||
list: [record],
|
||||
});
|
||||
}
|
||||
|
|
@ -189,42 +189,28 @@ async function initStatus() {
|
|||
|
||||
function getPrice(
|
||||
list: {
|
||||
product: RequestWork['productService']['product'];
|
||||
product: RequestWork['productService'];
|
||||
list: RequestWork[];
|
||||
}[],
|
||||
) {
|
||||
return list.reduce(
|
||||
(a, c) => {
|
||||
const agentPrice = !!quotationData.value?.agentPrice;
|
||||
const pricePerUnit = agentPrice ? c.product.agentPrice : c.product.price;
|
||||
const pricePerUnit =
|
||||
c.product.pricePerUnit - c.product.discount / c.product.amount;
|
||||
const amount = c.list.length;
|
||||
const discount = 0;
|
||||
const priceNoVat = c.product[
|
||||
agentPrice ? 'agentPriceVatIncluded' : 'vatIncluded'
|
||||
]
|
||||
? pricePerUnit / (1 + (config.value?.vat || 0.07))
|
||||
: pricePerUnit;
|
||||
const priceDiscountNoVat = priceNoVat * amount - discount;
|
||||
const priceNoVat = pricePerUnit;
|
||||
const priceDiscountNoVat = priceNoVat * amount;
|
||||
|
||||
const rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07);
|
||||
// const rawVat = rawVatTotal / amount;
|
||||
|
||||
a.totalPrice = a.totalPrice + priceDiscountNoVat;
|
||||
a.totalDiscount = a.totalDiscount + Number(discount);
|
||||
a.vat = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
|
||||
? a.vat + rawVatTotal
|
||||
: a.vat;
|
||||
a.vatExcluded = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
|
||||
? a.vatExcluded
|
||||
: a.vat + rawVatTotal;
|
||||
a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
|
||||
a.vat = c.product.vat !== 0 ? a.vat + rawVatTotal : a.vat;
|
||||
a.finalPrice = a.totalPrice + a.vat;
|
||||
return a;
|
||||
},
|
||||
{
|
||||
totalPrice: 0,
|
||||
totalDiscount: 0,
|
||||
vat: 0,
|
||||
vatExcluded: 0,
|
||||
finalPrice: 0,
|
||||
},
|
||||
);
|
||||
|
|
@ -754,12 +740,12 @@ onMounted(async () => {
|
|||
"
|
||||
/>
|
||||
|
||||
<!-- TODO: bind remark -->
|
||||
<RemarkExpansion
|
||||
v-if="view !== CreditNoteStatus.Success"
|
||||
:readonly="readonly"
|
||||
v-model:remark="formData.remark"
|
||||
:default-remark="defaultRemark"
|
||||
:items="[]"
|
||||
:readonly
|
||||
>
|
||||
<template #hint>
|
||||
{{ $t('general.hintRemark') }}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,26 @@
|
|||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { QTableSlots } from 'quasar';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
import { AddButton } from 'src/components/button';
|
||||
import TableEmployee from '../../09_task-order/TableEmployee.vue';
|
||||
|
||||
import { useConfigStore } from 'stores/config';
|
||||
import { RequestWork } from 'src/stores/request-list';
|
||||
import { productColumn } from '../constants';
|
||||
import { baseUrl, formatNumberDecimal } from 'src/stores/utils';
|
||||
import { precisionRound } from 'src/utils/arithmetic';
|
||||
import { useConfigStore } from 'stores/config';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { productColumn } from '../constants';
|
||||
|
||||
const currentExpanded = ref<boolean[]>([]);
|
||||
const configStore = useConfigStore();
|
||||
const { data: config } = storeToRefs(configStore);
|
||||
|
||||
const taskProduct = defineModel<{ productId: string; discount?: number }[]>(
|
||||
'taskProduct',
|
||||
{
|
||||
default: [],
|
||||
},
|
||||
);
|
||||
const currentExpanded = ref<boolean[]>([]);
|
||||
|
||||
const props = defineProps<{
|
||||
defineProps<{
|
||||
readonly?: boolean;
|
||||
agentPrice?: boolean;
|
||||
taskList: {
|
||||
product: RequestWork['productService']['product'];
|
||||
product: RequestWork['productService'];
|
||||
list: RequestWork[];
|
||||
}[];
|
||||
}>();
|
||||
|
|
@ -36,9 +29,7 @@ defineEmits<{
|
|||
(e: 'addProduct'): void;
|
||||
}>();
|
||||
|
||||
defineExpose({
|
||||
calcPricePerUnit,
|
||||
});
|
||||
defineExpose({ calcPricePerUnit });
|
||||
|
||||
function openList(index: number) {
|
||||
if (!currentExpanded.value[index]) {
|
||||
|
|
@ -49,35 +40,17 @@ function openList(index: number) {
|
|||
currentExpanded.value[index] = !currentExpanded.value[index];
|
||||
}
|
||||
|
||||
function calcPricePerUnit(product: RequestWork['productService']['product']) {
|
||||
const val = props.agentPrice ? product.agentPrice : product.price;
|
||||
|
||||
if (product[props.agentPrice ? 'agentPriceCalcVat' : 'calcVat']) {
|
||||
return val / (1 + (config.value?.vat || 0.07));
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
function calcPricePerUnit(product: RequestWork['productService']) {
|
||||
return product.pricePerUnit - product.discount / product.amount;
|
||||
}
|
||||
|
||||
function calcPrice(
|
||||
product: RequestWork['productService']['product'],
|
||||
amount: number,
|
||||
) {
|
||||
const pricePerUnit = props.agentPrice ? product.agentPrice : product.price;
|
||||
const discount =
|
||||
taskProduct.value.find((v) => v.productId === product.id)?.discount || 0;
|
||||
const priceNoVat = product[
|
||||
props.agentPrice ? 'agentPriceVatIncluded' : 'vatIncluded'
|
||||
]
|
||||
? pricePerUnit / (1 + (config.value?.vat || 0.07))
|
||||
: pricePerUnit;
|
||||
const priceDiscountNoVat = priceNoVat * amount - discount;
|
||||
function calcPrice(c: RequestWork['productService'], amount: number) {
|
||||
const pricePerUnit = c.pricePerUnit - c.discount / c.amount;
|
||||
const priceNoVat = pricePerUnit;
|
||||
const priceDiscountNoVat = priceNoVat * amount;
|
||||
|
||||
const rawVatTotal = product[
|
||||
props.agentPrice ? 'agentPriceCalcVat' : 'calcVat'
|
||||
]
|
||||
? priceDiscountNoVat * (config.value?.vat || 0.07)
|
||||
: 0;
|
||||
const rawVatTotal =
|
||||
c.vat === 0 ? 0 : priceDiscountNoVat * (config.value?.vat || 0.07);
|
||||
|
||||
return precisionRound(priceNoVat * amount + rawVatTotal);
|
||||
}
|
||||
|
|
@ -141,7 +114,7 @@ function calcPrice(
|
|||
<template
|
||||
v-slot:body="props: {
|
||||
row: {
|
||||
product: RequestWork['productService']['product'];
|
||||
product: RequestWork['productService'];
|
||||
list: RequestWork[];
|
||||
};
|
||||
} & Omit<Parameters<QTableSlots['body']>[0], 'row'>"
|
||||
|
|
@ -151,14 +124,14 @@ function calcPrice(
|
|||
{{ props.rowIndex + 1 }}
|
||||
</q-td>
|
||||
<q-td>
|
||||
{{ props.row.product.code }}
|
||||
{{ props.row.product.product.code }}
|
||||
</q-td>
|
||||
<q-td style="width: 100%" class="text-left">
|
||||
<q-avatar class="q-mr-sm" size="md">
|
||||
<q-img
|
||||
class="text-center"
|
||||
:ratio="1"
|
||||
:src="`${baseUrl}/product/${props.row.product.id}/image/${props.row.product.selectedImage}`"
|
||||
:src="`${baseUrl}/product/${props.row.product.id}/image/${props.row.product.product.selectedImage}`"
|
||||
>
|
||||
<template #error>
|
||||
<q-icon
|
||||
|
|
@ -169,7 +142,7 @@ function calcPrice(
|
|||
</template>
|
||||
</q-img>
|
||||
</q-avatar>
|
||||
{{ props.row.product.name }}
|
||||
{{ props.row.product.product.name }}
|
||||
</q-td>
|
||||
<q-td>
|
||||
{{ props.row.list.length }}
|
||||
|
|
@ -178,7 +151,7 @@ function calcPrice(
|
|||
{{
|
||||
formatNumberDecimal(
|
||||
calcPricePerUnit(props.row.product) +
|
||||
(props.row.product.calcVat
|
||||
(props.row.product.vat > 0
|
||||
? calcPricePerUnit(props.row.product) *
|
||||
(config?.vat || 0.07)
|
||||
: 0),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue