diff --git a/src/views/checkout/CheckFormView.vue b/src/views/checkout/CheckFormView.vue index 720c472..0b5fb68 100644 --- a/src/views/checkout/CheckFormView.vue +++ b/src/views/checkout/CheckFormView.vue @@ -8,7 +8,9 @@ import CurrencyInput from '@/components/ui/CurrencyInput.vue' import PersianDateInput from '@/components/ui/PersianDateInput.vue' import FormErrorBanner from '@/components/ui/FormErrorBanner.vue' import BaseButton from '@/components/ui/BaseButton.vue' -import { parseFormattedNumber } from '@/utils/format' +import IconCash from '@/components/icons/IconCash.vue' +import IconCheckBook from '@/components/icons/IconCheckBook.vue' +import { formatCurrency, formatNumber, parseFormattedNumber } from '@/utils/format' import { FORM_VALIDATION_SUMMARY, clearFieldError, @@ -26,7 +28,7 @@ import { useRequirePricedOrder } from '@/composables/useRequirePricedOrder' const router = useRouter() const orderStore = useOrderStore() -const { orderId } = useRequirePricedOrder() +const { orderId, order } = useRequirePricedOrder() const isFull = computed(() => orderStore.draftCheckMode === 'full') const amount = ref('') @@ -43,6 +45,40 @@ const backImage = ref('') const notes = ref('') const fieldErrors = ref({}) const formError = ref('') +const suggestedAmountApplied = ref(false) + +const invoiceAmount = computed(() => order.value?.finalAmount ?? 0) +const previousChecksTotal = computed(() => + orderStore.draftChecks.reduce((sum, check) => sum + check.amount, 0), +) +const currentCheckAmount = computed(() => parseFormattedNumber(amount.value) || 0) +const remainingBeforeCurrent = computed(() => + Math.max(0, invoiceAmount.value - previousChecksTotal.value), +) +const remainingAfterCurrent = computed(() => + Math.max(0, invoiceAmount.value - previousChecksTotal.value - currentCheckAmount.value), +) +const isCovered = computed( + () => + invoiceAmount.value > 0 && + previousChecksTotal.value + currentCheckAmount.value >= invoiceAmount.value, +) +const isOverInvoice = computed( + () => + invoiceAmount.value > 0 && + previousChecksTotal.value + currentCheckAmount.value > invoiceAmount.value, +) + +watch( + [invoiceAmount, remainingBeforeCurrent], + () => { + if (suggestedAmountApplied.value || amount.value) return + if (remainingBeforeCurrent.value <= 0) return + amount.value = String(remainingBeforeCurrent.value) + suggestedAmountApplied.value = true + }, + { immediate: true }, +) watch(amount, () => { fieldErrors.value = clearFieldError(fieldErrors.value, 'amount') @@ -80,6 +116,11 @@ async function handleImageUpload(event: Event, target: 'front' | 'back') { else backImage.value = base64 } +function fillRemainingAmount() { + if (remainingBeforeCurrent.value <= 0) return + amount.value = String(remainingBeforeCurrent.value) +} + function validateForm(): boolean { fieldErrors.value = {} formError.value = '' @@ -157,6 +198,7 @@ function resetForm() { notes.value = '' fieldErrors.value = {} formError.value = '' + suggestedAmountApplied.value = false } @@ -171,6 +213,72 @@ function resetForm() {
+
+
+ +
+

مانده فاکتور

+

+ با هر چک، مبلغ باقی‌مانده به‌روز می‌شود تا پوشش کامل فاکتور را از دست ندهید. +

+
+
+ +
+
+ مبلغ فاکتور + {{ formatCurrency(invoiceAmount) }} +
+
+ + + چک‌های ثبت‌شده + + ({{ formatNumber(orderStore.draftChecks.length) }}) + + + + {{ formatCurrency(previousChecksTotal) }} + +
+
+ باقی‌مانده + + {{ + isOverInvoice + ? `${formatCurrency(previousChecksTotal + currentCheckAmount - invoiceAmount)} بیش از فاکتور` + : isCovered + ? 'پوشش کامل شد' + : formatCurrency(remainingAfterCurrent) + }} + +
+
+
+
۱. اطلاعات چک ۲. چک بعدی @@ -184,6 +292,14 @@ function resetForm() { placeholder="مبلغ" :error="fieldErrors.amount" /> +