FIX:Descuentos del 50
This commit is contained in:
parent
5ee73c309f
commit
83bec44121
@ -19,8 +19,11 @@ const paymentMethods = [
|
|||||||
const hasSelection = computed(() => props.selectedFines.length > 0);
|
const hasSelection = computed(() => props.selectedFines.length > 0);
|
||||||
const canPay = computed(() => hasSelection.value && selectedPaymentMethod.value !== null);
|
const canPay = computed(() => hasSelection.value && selectedPaymentMethod.value !== null);
|
||||||
|
|
||||||
|
const effectiveAmount = (f) =>
|
||||||
|
parseFloat(f._total_to_pay ?? f.discount ?? f.total_amount ?? 0);
|
||||||
|
|
||||||
const totalSelected = computed(() =>
|
const totalSelected = computed(() =>
|
||||||
props.selectedFines.reduce((sum, f) => sum + parseFloat(f.discount ?? f.total_amount ?? 0), 0)
|
props.selectedFines.reduce((sum, f) => sum + effectiveAmount(f), 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
const originalTotal = computed(() =>
|
const originalTotal = computed(() =>
|
||||||
@ -28,9 +31,21 @@ const originalTotal = computed(() =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
const hasAnyDiscount = computed(() =>
|
const hasAnyDiscount = computed(() =>
|
||||||
props.selectedFines.some((f) => f.discount != null)
|
props.selectedFines.some((f) => f.discount != null || f._has_early_discount)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hasEarlyDiscount = computed(() =>
|
||||||
|
props.selectedFines.some((f) => f._has_early_discount)
|
||||||
|
);
|
||||||
|
|
||||||
|
const earlyDiscountExpiresAt = computed(() => {
|
||||||
|
const fine = props.selectedFines.find((f) => f._early_discount_expires_at);
|
||||||
|
if (!fine) return null;
|
||||||
|
return new Date(fine._early_discount_expires_at).toLocaleDateString("es-MX", {
|
||||||
|
day: "numeric", month: "long", year: "numeric",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const totalSavings = computed(() => originalTotal.value - totalSelected.value);
|
const totalSavings = computed(() => originalTotal.value - totalSelected.value);
|
||||||
|
|
||||||
const getConcepts = (fine) => {
|
const getConcepts = (fine) => {
|
||||||
@ -87,13 +102,13 @@ const handlePay = () => {
|
|||||||
<span class="text-sm font-medium text-white">Folio: {{ fine.id }}</span>
|
<span class="text-sm font-medium text-white">Folio: {{ fine.id }}</span>
|
||||||
<div class="flex flex-col items-end shrink-0 ml-2">
|
<div class="flex flex-col items-end shrink-0 ml-2">
|
||||||
<span
|
<span
|
||||||
v-if="fine.discount != null"
|
v-if="fine.discount != null || fine._has_early_discount"
|
||||||
class="text-xs text-white/40 line-through leading-none mb-0.5"
|
class="text-xs text-white/40 line-through leading-none mb-0.5"
|
||||||
>
|
>
|
||||||
${{ parseFloat(fine.total_amount || 0).toFixed(2) }}
|
${{ parseFloat(fine.total_amount || 0).toFixed(2) }}
|
||||||
</span>
|
</span>
|
||||||
<span class="text-sm font-semibold text-white leading-none">
|
<span class="text-sm font-semibold text-white leading-none">
|
||||||
${{ parseFloat(fine.discount ?? fine.total_amount ?? 0).toFixed(2) }}
|
${{ effectiveAmount(fine).toFixed(2) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -147,12 +162,24 @@ const handlePay = () => {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
|
<!-- Aviso de descuento por pago oportuno -->
|
||||||
|
<div
|
||||||
|
v-if="hasEarlyDiscount && earlyDiscountExpiresAt"
|
||||||
|
class="flex items-start gap-2 bg-success/20 border border-success/40 rounded-lg px-3 py-2 mb-3"
|
||||||
|
>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-success shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||||
|
</svg>
|
||||||
|
<p class="text-xs text-success leading-snug">
|
||||||
|
Descuento por pago oportuno (50%) vigente hasta el <strong>{{ earlyDiscountExpiresAt }}</strong>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<div class="flex justify-between text-sm text-white/60 mb-1">
|
<div class="flex justify-between text-sm text-white/60 mb-1">
|
||||||
<span>Subtotal original</span>
|
<span>Subtotal original</span>
|
||||||
<span>${{ originalTotal.toFixed(2) }}</span>
|
<span>${{ originalTotal.toFixed(2) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between text-sm text-success mb-2">
|
<div class="flex justify-between text-sm text-success mb-2">
|
||||||
<span>Descuento</span>
|
<span>{{ hasEarlyDiscount ? 'Descuento por pago oportuno' : 'Descuento' }}</span>
|
||||||
<span>-${{ totalSavings.toFixed(2) }}</span>
|
<span>-${{ totalSavings.toFixed(2) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between font-bold text-white text-base mb-4">
|
<div class="flex justify-between font-bold text-white text-base mb-4">
|
||||||
|
|||||||
@ -24,7 +24,13 @@ const hasSelection = computed(() => selectedFines.value.length > 0);
|
|||||||
|
|
||||||
// ─── Procesado de respuestas ──────────────────────────────────────────────────
|
// ─── Procesado de respuestas ──────────────────────────────────────────────────
|
||||||
const processSingleResult = (data) => {
|
const processSingleResult = (data) => {
|
||||||
const fine = data.model;
|
const fine = {
|
||||||
|
...data.model,
|
||||||
|
_total_to_pay: data.total_to_pay,
|
||||||
|
_has_early_discount: data.has_early_discount,
|
||||||
|
_early_discount_expires_at: data.early_discount_expires_at,
|
||||||
|
_early_discount_amount: data.discount,
|
||||||
|
};
|
||||||
searchResults.value = [fine];
|
searchResults.value = [fine];
|
||||||
if (fine.status === "paid") {
|
if (fine.status === "paid") {
|
||||||
searchMessage.value = "Se encontró 1 multa (ya pagada).";
|
searchMessage.value = "Se encontró 1 multa (ya pagada).";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user