forked from git.gladyson/openmonetis
refactor: adicionar logos de cartões e corrigir contagem de parcelas pendentes
- Exibir logo do cartão ao lado do nome da parcela na análise - Corrigir contagem de "X pendentes" para excluir parcelas já pagas - Adicionar cartaoLogo à query e tipo InstallmentGroup
This commit is contained in:
@@ -6,9 +6,10 @@ import { Card, CardContent } from "@/components/ui/card";
|
|||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { Progress } from "@/components/ui/progress";
|
import { Progress } from "@/components/ui/progress";
|
||||||
import { cn } from "@/lib/utils/ui";
|
import { cn } from "@/lib/utils/ui";
|
||||||
import { RiArrowDownSLine, RiArrowRightSLine } from "@remixicon/react";
|
import { RiArrowDownSLine, RiArrowRightSLine, RiCreditCardLine } from "@remixicon/react";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { ptBR } from "date-fns/locale";
|
import { ptBR } from "date-fns/locale";
|
||||||
|
import Image from "next/image";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { InstallmentGroup } from "./types";
|
import type { InstallmentGroup } from "./types";
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@ export function InstallmentGroupCard({
|
|||||||
(i) => !i.isSettled
|
(i) => !i.isSettled
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const unpaidCount = unpaidInstallments.length;
|
||||||
|
|
||||||
const isFullySelected =
|
const isFullySelected =
|
||||||
selectedInstallments.size === unpaidInstallments.length &&
|
selectedInstallments.size === unpaidInstallments.length &&
|
||||||
unpaidInstallments.length > 0;
|
unpaidInstallments.length > 0;
|
||||||
@@ -63,7 +66,22 @@ export function InstallmentGroupCard({
|
|||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<div className="flex items-start justify-between gap-3">
|
<div className="flex items-start justify-between gap-3">
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{group.cartaoLogo ? (
|
||||||
|
<Image
|
||||||
|
src={group.cartaoLogo}
|
||||||
|
alt={group.cartaoName || "Cartão"}
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
className="size-6 shrink-0 rounded"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex size-6 shrink-0 items-center justify-center rounded bg-muted">
|
||||||
|
<RiCreditCardLine className="size-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<p className="text-sm font-bold">{group.name}</p>
|
<p className="text-sm font-bold">{group.name}</p>
|
||||||
|
</div>
|
||||||
<div className="mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
|
<div className="mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
|
||||||
{group.cartaoName && (
|
{group.cartaoName && (
|
||||||
<>
|
<>
|
||||||
@@ -96,10 +114,8 @@ export function InstallmentGroupCard({
|
|||||||
{group.paidInstallments} de {group.totalInstallments} pagas
|
{group.paidInstallments} de {group.totalInstallments} pagas
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
{group.pendingInstallments.length}{" "}
|
{unpaidCount}{" "}
|
||||||
{group.pendingInstallments.length === 1
|
{unpaidCount === 1 ? "pendente" : "pendentes"}
|
||||||
? "pendente"
|
|
||||||
: "pendentes"}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<Progress value={progress} className="h-1.5" />
|
<Progress value={progress} className="h-1.5" />
|
||||||
@@ -109,8 +125,7 @@ export function InstallmentGroupCard({
|
|||||||
<div className="mt-2 flex flex-wrap gap-2">
|
<div className="mt-2 flex flex-wrap gap-2">
|
||||||
{isPartiallySelected && (
|
{isPartiallySelected && (
|
||||||
<Badge variant="secondary" className="text-xs">
|
<Badge variant="secondary" className="text-xs">
|
||||||
{selectedInstallments.size} de{" "}
|
{selectedInstallments.size} de {unpaidCount} selecionadas
|
||||||
{group.pendingInstallments.length} selecionadas
|
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export type InstallmentGroup = {
|
|||||||
paymentMethod: string;
|
paymentMethod: string;
|
||||||
cartaoId: string | null;
|
cartaoId: string | null;
|
||||||
cartaoName: string | null;
|
cartaoName: string | null;
|
||||||
|
cartaoLogo: string | null;
|
||||||
cartaoDueDay: string | null;
|
cartaoDueDay: string | null;
|
||||||
totalInstallments: number;
|
totalInstallments: number;
|
||||||
paidInstallments: number;
|
paidInstallments: number;
|
||||||
@@ -74,6 +75,7 @@ export async function fetchInstallmentAnalysis(
|
|||||||
purchaseDate: lancamentos.purchaseDate,
|
purchaseDate: lancamentos.purchaseDate,
|
||||||
cartaoId: lancamentos.cartaoId,
|
cartaoId: lancamentos.cartaoId,
|
||||||
cartaoName: cartoes.name,
|
cartaoName: cartoes.name,
|
||||||
|
cartaoLogo: cartoes.logo,
|
||||||
cartaoDueDay: cartoes.dueDay,
|
cartaoDueDay: cartoes.dueDay,
|
||||||
})
|
})
|
||||||
.from(lancamentos)
|
.from(lancamentos)
|
||||||
@@ -131,6 +133,7 @@ export async function fetchInstallmentAnalysis(
|
|||||||
paymentMethod: row.paymentMethod,
|
paymentMethod: row.paymentMethod,
|
||||||
cartaoId: row.cartaoId,
|
cartaoId: row.cartaoId,
|
||||||
cartaoName: row.cartaoName,
|
cartaoName: row.cartaoName,
|
||||||
|
cartaoLogo: row.cartaoLogo,
|
||||||
cartaoDueDay: row.cartaoDueDay,
|
cartaoDueDay: row.cartaoDueDay,
|
||||||
totalInstallments: row.installmentCount ?? 0,
|
totalInstallments: row.installmentCount ?? 0,
|
||||||
paidInstallments: 0,
|
paidInstallments: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user