jws-frontend/src/pages/05_quotation/peview/ViewForm.vue

512 lines
14 KiB
Vue
Raw Normal View History

2024-10-16 18:03:50 +07:00
<script lang="ts" setup>
2024-10-18 10:42:47 +07:00
import { storeToRefs } from 'pinia';
2024-10-17 12:55:22 +07:00
import { onMounted, nextTick, ref, watch } from 'vue';
2024-10-18 10:42:47 +07:00
import { precisionRound } from 'src/utils/arithmetic';
2024-10-17 18:00:16 +07:00
import ThaiBahtText from 'thai-baht-text';
2024-10-17 15:20:54 +07:00
2024-10-16 18:03:50 +07:00
// NOTE: Import stores
2024-10-17 15:20:54 +07:00
import useOptionStore from 'stores/options';
2024-10-17 18:00:16 +07:00
import { formatNumberDecimal } from 'stores/utils';
2024-10-18 10:42:47 +07:00
import { useQuotationForm } from 'pages/05_quotation/form';
import { useConfigStore } from 'stores/config';
2024-10-18 11:00:49 +07:00
import { commaInput } from 'stores/utils';
2024-10-17 15:20:54 +07:00
2024-10-16 18:03:50 +07:00
// NOTE Import Types
2024-10-17 15:20:35 +07:00
import { BankBook } from 'stores/branch/types';
2024-10-18 10:42:47 +07:00
import { QuotationPayload } from 'src/stores/quotations/types';
2024-10-17 15:20:54 +07:00
2024-10-16 18:03:50 +07:00
// NOTE: Import Components
import ViewHeader from './ViewHeader.vue';
2024-10-17 15:20:54 +07:00
import BankComponents from './BankComponents.vue';
2024-10-17 12:55:22 +07:00
2024-10-18 10:42:47 +07:00
const quotationForm = useQuotationForm();
2024-10-17 15:20:54 +07:00
const optionStore = useOptionStore();
2024-10-18 10:42:47 +07:00
const configStore = useConfigStore();
const { data: config } = storeToRefs(configStore);
2024-10-17 12:55:22 +07:00
2024-10-17 18:00:16 +07:00
type Product = {
id: string;
code: string;
detail: string;
amount: number;
priceUnit: number;
discount: number;
vat: number;
value: number;
};
type SummaryPrice = {
totalPrice: number;
totalDiscount: number;
vat: number;
vatExcluded: number;
finalPrice: number;
};
2024-10-18 11:00:49 +07:00
const note = ref<string>('');
2024-10-18 11:08:19 +07:00
const productList = ref<Product[]>([]);
2024-10-17 18:00:16 +07:00
2024-10-17 12:55:22 +07:00
const elements = ref<HTMLElement[]>([]);
2024-10-17 18:00:16 +07:00
const chunks = ref<Product[][]>([[]]);
2024-10-18 10:42:47 +07:00
const data = ref<QuotationPayload>();
const summaryPrice = ref<SummaryPrice>({
totalPrice: 0,
totalDiscount: 0,
vat: 0,
vatExcluded: 0,
finalPrice: 0,
});
2024-10-17 12:55:22 +07:00
2024-10-17 15:20:54 +07:00
const bankList = ref<BankBook[]>([
{
id: 'cm14grwo30003z8chvzouoc87',
currentlyUse: true,
branchId: 'cm14grwo30002z8ch55keto89',
bankUrl:
'http://192.168.1.61:20102/api/v1/branch/cm14grwo30002z8ch55keto89/bank-qr/cm14grwo30003z8chvzouoc87?ts=1729148488206',
bankName: 'ktb',
bankBranch: 'โรงพยาบาลศิริราชปิยมหาราชการุณย์',
accountType: '',
accountNumber: '1-520-361442-23',
accountName: 'บริษัท สยามเทคโนโลยี จำกัด',
},
]);
2024-10-17 12:55:22 +07:00
async function assignData() {
2024-10-17 18:00:16 +07:00
for (let i = 0; i < productList.value.length; i++) {
2024-10-17 12:55:22 +07:00
let el = elements.value.at(-1);
if (!el) return;
if (getHeight(el) < 500) {
2024-10-17 18:00:16 +07:00
chunks.value.at(-1)?.push(productList.value[i]);
2024-10-17 12:55:22 +07:00
} else {
chunks.value.push([]);
i--;
}
await nextTick();
}
}
function getHeight(el: HTMLElement) {
const shadow = document.createElement('div');
shadow.style.opacity = '0';
shadow.style.position = 'absolute';
shadow.style.top = '-999999px';
shadow.style.left = '-999999px';
shadow.style.pointerEvents = 'none';
document.body.appendChild(shadow);
shadow.appendChild(el.cloneNode(true));
const height = shadow.offsetHeight;
document.body.removeChild(shadow);
return height;
}
2024-10-17 15:20:54 +07:00
onMounted(async () => {
2024-10-18 10:42:47 +07:00
let str =
localStorage.getItem('quotation-preview') ||
sessionStorage.getItem('quotation-preview');
if (!str) return;
const obj: QuotationPayload = JSON.parse(str);
if (obj) sessionStorage.setItem('quotation-preview', JSON.stringify(obj));
delete localStorage['quotation-preview'];
data.value = JSON.parse(sessionStorage.getItem('quotation-preview') || '{}');
2024-10-18 11:00:49 +07:00
if (data) {
productList.value =
data.value?.productServiceList.map((v) => ({
id: v.product.id,
code: v.product.code,
detail: v.product.detail,
amount: v.amount || 0,
priceUnit: v.pricePerUnit || 0,
discount: v.discount || 0,
vat: v.vat || 0,
value: precisionRound(
(v.pricePerUnit || 0) * v.amount -
(v.discount || 0) +
(v.product.calcVat
? ((v.pricePerUnit || 0) * v.amount - (v.discount || 0)) *
(config.value?.vat || 0.07)
: 0),
),
})) || [];
2024-10-18 10:45:54 +07:00
}
2024-10-18 10:42:47 +07:00
summaryPrice.value = obj.productServiceList.reduce(
(a, c) => {
const price = precisionRound((c.pricePerUnit || 0) * c.amount);
const vat = precisionRound(
((c.pricePerUnit || 0) * c.amount - (c.discount || 0)) *
(config.value?.vat || 0.07),
);
a.totalPrice = precisionRound(a.totalPrice + price);
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat;
a.vatExcluded = c.product.calcVat
? a.vatExcluded
: precisionRound(a.vat + vat);
a.finalPrice = precisionRound(
a.totalPrice - a.totalDiscount + a.vat - Number(obj.discount || 0),
);
return a;
},
{
totalPrice: 0,
totalDiscount: 0,
vat: 0,
vatExcluded: 0,
finalPrice: 0,
},
);
2024-10-17 15:20:54 +07:00
await optionStore.fetchOption();
2024-10-18 10:42:47 +07:00
2024-10-17 12:55:22 +07:00
assignData();
});
watch(elements, () => {
console.log(elements.value);
});
2024-10-16 18:03:50 +07:00
</script>
<template>
<div class="row justify-between container">
2024-10-17 12:55:22 +07:00
<section class="content" v-for="chunk in chunks">
2024-10-17 09:38:33 +07:00
<ViewHeader />
2024-10-16 18:03:50 +07:00
<span
2024-10-17 09:38:33 +07:00
class="q-mb-sm q-mt-md"
2024-10-16 18:03:50 +07:00
style="
font-weight: 800;
font-size: 16px;
color: var(--orange-5);
display: block;
border-bottom: 2px solid var(--orange-5);
"
>
2024-10-17 15:51:56 +07:00
{{ $t('peview.productList') }}
2024-10-16 18:03:50 +07:00
</span>
2024-10-17 12:55:22 +07:00
<table ref="elements" class="q-mb-sm" cellpadding="0" style="width: 100%">
2024-10-16 18:03:50 +07:00
<tbody>
<tr>
2024-10-17 15:51:56 +07:00
<th>{{ $t('peview.rank') }}</th>
<th>{{ $t('peview.productCode') }}</th>
<th>{{ $t('general.detail') }}</th>
<th>{{ $t('general.amount') }}</th>
2024-10-17 18:00:16 +07:00
<th>{{ $t('peview.pricePerUnit') }}</th>
2024-10-17 15:51:56 +07:00
<th>{{ $t('peview.discount') }}</th>
<th>{{ $t('peview.vat') }}</th>
<th>{{ $t('peview.value') }}</th>
2024-10-16 18:03:50 +07:00
</tr>
2024-10-17 18:00:16 +07:00
<tr class="color-tr" v-for="(v, i) in chunk">
2024-10-16 18:03:50 +07:00
<td class="text-center">{{ i + 1 }}</td>
2024-10-17 18:00:16 +07:00
<td>{{ v.code }}</td>
<td>{{ v.detail }}</td>
2024-10-18 11:08:19 +07:00
<td style="text-align: right">{{ v.amount }}</td>
<td style="text-align: right">
{{ formatNumberDecimal(v.priceUnit, 2) }}
</td>
<td style="text-align: right">
{{ formatNumberDecimal(v.discount, 2) }}
</td>
<td style="text-align: right">
{{ formatNumberDecimal(v.vat, 2) }}
</td>
<td style="text-align: right">
{{ formatNumberDecimal(v.value, 2) }}
</td>
2024-10-16 18:03:50 +07:00
</tr>
</tbody>
</table>
<table
style="width: 30%; margin-left: auto"
class="q-mb-md"
cellpadding="0"
>
<tbody>
<tr>
2024-10-17 18:00:16 +07:00
<td>{{ $t('general.total') }}</td>
<td class="text-right">
{{ formatNumberDecimal(summaryPrice.totalPrice, 2) }}
฿
</td>
2024-10-16 18:03:50 +07:00
</tr>
<tr class="bg-color-orange">
2024-10-17 18:00:16 +07:00
<td>{{ $t('general.discount') }}</td>
<td class="text-right">
{{ formatNumberDecimal(summaryPrice.totalDiscount, 2) || 0 }} ฿
</td>
2024-10-16 18:03:50 +07:00
</tr>
<tr>
2024-10-17 18:00:16 +07:00
<td>{{ $t('general.totalAfterDiscount') }}</td>
<td class="text-right">
{{
formatNumberDecimal(
summaryPrice.totalPrice - summaryPrice.totalDiscount,
2,
)
}}
฿
</td>
2024-10-16 18:03:50 +07:00
</tr>
<tr class="bg-color-orange">
2024-10-17 18:00:16 +07:00
<td>{{ $t('general.totalVatExcluded') }}</td>
<td class="text-right">
{{ formatNumberDecimal(summaryPrice.vatExcluded, 2) || 0 }}
฿
</td>
2024-10-16 18:03:50 +07:00
</tr>
<tr>
2024-10-17 18:00:16 +07:00
<td>{{ $t('general.totalVatIncluded') }}</td>
<td class="text-right">
{{
formatNumberDecimal(
summaryPrice.totalPrice -
summaryPrice.totalDiscount +
summaryPrice.vat,
2,
)
}}
฿
</td>
2024-10-16 18:03:50 +07:00
</tr>
<tr class="bg-color-orange">
2024-10-17 18:00:16 +07:00
<td>{{ $t('general.vat', { msg: '7%' }) }}</td>
<td class="text-right">
{{ formatNumberDecimal(summaryPrice.vat, 2) }} ฿
</td>
2024-10-16 18:03:50 +07:00
</tr>
</tbody>
</table>
<div class="row justify-between q-mb-md" style="width: 100%">
<div
class="column set-width bg-color-orange full-height"
style="padding: 12px"
>
2024-10-17 18:00:16 +07:00
({{ ThaiBahtText(summaryPrice.finalPrice) }})
2024-10-16 18:03:50 +07:00
</div>
<div
class="column text-right border-5"
style="width: 40%; background: var(--orange-5); padding: 8px"
>
<span
class="border-5"
style="
width: 70%;
margin-left: auto;
background: white;
padding: 4px;
"
>
2024-10-17 18:00:16 +07:00
{{
formatNumberDecimal(Math.max(summaryPrice.finalPrice, 0), 2) || 0
}}
฿
2024-10-16 18:03:50 +07:00
</span>
</div>
</div>
</section>
<section class="content">
<ViewHeader class="q-mb-lg" />
<span
2024-10-17 09:38:33 +07:00
class="q-mb-sm q-mt-md"
2024-10-16 18:03:50 +07:00
style="
font-weight: 800;
font-size: 16px;
color: var(--orange-5);
display: block;
border-bottom: 2px solid var(--orange-5);
"
>
หมายเหตุ
</span>
2024-10-17 18:04:27 +07:00
<div
class="border-5 surface-0 detail-note q-mb-md"
style="width: 100%; padding: 8px 16px; white-space: pre-wrap"
>
{{ note }}
2024-10-16 18:03:50 +07:00
</div>
<span
class="q-mb-sm"
style="
font-weight: 800;
font-size: 16px;
color: var(--orange-5);
display: block;
border-bottom: 2px solid var(--orange-5);
"
>
เงื่อนไข
</span>
<div
class="detail-note surface-0 border-5 q-mb-md"
style="width: 100%; padding: 8px 16px"
>
<span>
***เงื่อนไขบริการเฉพาะยื่นเอกสาร MOU นำเข้าสัญชาติเมียนมา (RE-TRUN)
เท่านั้น
</span>
<span>
- ราคาดังกล่าว เฉพาะคนต่างด้าวสัญชาติเมียนมา ที่มี Passport (เดิม)
อายุเล่ม มากกว่า 2 ปี 6 เดือน เท่านั้น กรณี เล่ม Passport (เดิม)
มีอายุเล่ม น้อยกว่า 2 ปี จะมีค่าใช้จ่ายเพิ่มเติมในการทำเล่ม Passport
(ใหม่)
</span>
<span>
- คนต่างด้าวจะต้องเดินทางกลับประเทศต้นทางก่อน Visa จะหมดอายุ
มิฉะนั้นจะถูกปรับฐานอยู่ในราชอาณาจักรเกินกำหนด (Overstay)
</span>
<span>- คนต่างด้าวจะต้องมีอายุระหว่าง 18-55 ปี เท่านั้น</span>
<span>
- คนต่างต้าวจะต้องมีบัตรประชาชนพม่า (ฉบับจริง) และสำเนาทะเบียนบ้าน
เท่านั้น
</span>
<span>- ใบเสนอราคานี้มีอายุ 30 วัน นับตั้งแต่วันที่เสนอราคา</span>
<span>- เงื่อนไขการชำระเงิน แบ่งจ่าย 3 งวด</span>
<span>- งวดที่ 1 ชำระเงิน ณ วันยื่นเอกสาร จำนวน 2000 บาท</span>
</div>
</section>
<section class="content">
<ViewHeader class="q-mb-lg" />
<span
class="q-mb-sm"
style="
font-weight: 800;
font-size: 16px;
color: var(--orange-5);
display: block;
border-bottom: 2px solid var(--orange-5);
"
>
ช่องทางซำระเงิน
</span>
2024-10-17 15:20:35 +07:00
<BankComponents
v-for="bank in bankList"
:bank-book="bank"
:key="bank.id"
/>
2024-10-16 18:03:50 +07:00
</section>
</div>
</template>
<style scoped>
table {
border-collapse: collapse;
}
th {
background: var(--orange-5);
color: white;
padding: 4px;
}
td {
padding: 4px 8px;
}
.border-5 {
border-radius: 5px;
}
.set-width {
width: 50%;
}
.bg-color-orange {
background-color: hsla(var(--orange-5-hsl) / 0.1);
}
.color-tr:nth-child(odd) {
background-color: hsla(var(--orange-5-hsl) / 0.1);
}
.container {
padding: 1rem;
display: flex;
gap: 1rem;
margin-inline: auto;
2024-10-17 09:34:30 +07:00
background: var(--gray-3);
width: calc(8.3in + 1rem);
2024-10-16 18:03:50 +07:00
}
.container :deep(*) {
font-size: 95%;
}
2024-10-17 12:55:22 +07:00
2024-10-16 18:03:50 +07:00
.content {
width: 100%;
2024-10-17 09:34:30 +07:00
padding: 0.5in;
2024-10-16 18:03:50 +07:00
align-items: center;
background: white;
page-break-after: always;
break-after: page;
2024-10-17 12:55:22 +07:00
/* height: 11.7in; */
/* max-height: 11.7in; */
2024-10-16 18:03:50 +07:00
}
2024-10-16 18:03:50 +07:00
.position-bottom {
margin-top: auto;
}
2024-10-16 18:03:50 +07:00
.detail-note {
display: flex;
flex-direction: column;
gap: 8px;
& > * {
display: flex;
flex-direction: column;
}
}
hr {
border-style: solid;
border-color: var(--orange-5);
}
@media print {
.container {
padding: 0;
gap: 0;
width: 100%;
2024-10-17 09:38:33 +07:00
background: white;
2024-10-16 18:03:50 +07:00
}
2024-10-17 09:34:30 +07:00
.content {
padding: 0;
height: unset;
2024-10-17 09:34:30 +07:00
}
2024-10-16 18:03:50 +07:00
}
</style>