Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
129295d2e2 | ||
|
|
4b5cdf81b8 | ||
|
|
558197e870 | ||
|
|
2fd6e3c323 | ||
|
|
833845b5cf | ||
|
|
4cbdddb12e | ||
|
|
c81584095b | ||
|
|
8ccc4479be | ||
|
|
2cead626ab | ||
|
|
811a035cb0 | ||
|
|
356801324c | ||
|
|
b443fb010a | ||
|
|
026dff5399 | ||
|
|
18b6a6a470 |
@@ -17,8 +17,15 @@ POSTGRES_DB=openmonetis_db
|
|||||||
# Gere com: openssl rand -base64 32
|
# Gere com: openssl rand -base64 32
|
||||||
BETTER_AUTH_SECRET=your-secret-key-here-change-this
|
BETTER_AUTH_SECRET=your-secret-key-here-change-this
|
||||||
BETTER_AUTH_URL=http://localhost:3000
|
BETTER_AUTH_URL=http://localhost:3000
|
||||||
|
|
||||||
|
# Origins adicionais confiáveis para o Better Auth.
|
||||||
|
# Útil para Cloudflare Tunnel, reverse proxy e URLs diferentes de BETTER_AUTH_URL.
|
||||||
|
# Separe múltiplas origins por vírgula.
|
||||||
|
# Exemplo: https://*.trycloudflare.com,https://openmonetis.seudominio.com
|
||||||
|
BETTER_AUTH_TRUSTED_ORIGINS=
|
||||||
# Defina como true para bloquear novos cadastros
|
# Defina como true para bloquear novos cadastros
|
||||||
DISABLE_SIGNUP=false
|
DISABLE_SIGNUP=false
|
||||||
|
|
||||||
# Duração de sessões persistentes quando "Manter conectado" estiver marcado
|
# Duração de sessões persistentes quando "Manter conectado" estiver marcado
|
||||||
AUTH_SESSION_EXPIRES_IN_DAYS=30
|
AUTH_SESSION_EXPIRES_IN_DAYS=30
|
||||||
AUTH_SESSION_UPDATE_AGE_HOURS=24
|
AUTH_SESSION_UPDATE_AGE_HOURS=24
|
||||||
|
|||||||
56
CHANGELOG.md
@@ -5,6 +5,62 @@ Todas as mudanças notáveis deste projeto serão documentadas neste arquivo.
|
|||||||
O formato é baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/),
|
O formato é baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/),
|
||||||
e este projeto adere ao [Versionamento Semântico](https://semver.org/lang/pt-BR/).
|
e este projeto adere ao [Versionamento Semântico](https://semver.org/lang/pt-BR/).
|
||||||
|
|
||||||
|
## [2.7.7] - 2026-06-20
|
||||||
|
|
||||||
|
Esta versão faz ajustes pontuais de leitura nos resumos financeiros e no dashboard, reforçando a identidade visual de cartões e contas e deixando as listas dos widgets mais consistentes sem alterar a estrutura de navegação das páginas.
|
||||||
|
|
||||||
|
### Alterado
|
||||||
|
- Cartões e contas: os cabeçalhos dos resumos agora destacam melhor o logo, o nome da entidade e o período exibido.
|
||||||
|
- Dashboard: as listas dos widgets agora compartilham padrões de altura, espaçamento, alinhamento e truncamento para melhorar a leitura de valores, status e metadados.
|
||||||
|
|
||||||
|
## [2.7.6] - 2026-06-20
|
||||||
|
|
||||||
|
Esta versão melhora dois fluxos importantes: a importação de planilhas fica mais esperta ao reconhecer categorias já informadas no arquivo, e lançamentos avulsos podem ser reorganizados como parcelamentos ou recorrências sem precisar recriá-los manualmente.
|
||||||
|
|
||||||
|
As funcionalidades desta versão foram desenvolvidas originalmente por Yuri Argolo (`yurnasg`) e adaptadas para integração ao projeto principal.
|
||||||
|
|
||||||
|
### Adicionado
|
||||||
|
- Importação: planilhas XLS/XLSX agora aceitam a coluna `Categoria` no template e tentam mapear automaticamente o valor para uma categoria existente compatível com o tipo do lançamento.
|
||||||
|
- Lançamentos: lançamentos à vista agora podem ser convertidos em recorrentes diretamente pelo menu de ações.
|
||||||
|
- Lançamentos: lançamentos à vista de cartão de crédito agora podem ser convertidos em uma série parcelada informando o total de parcelas.
|
||||||
|
|
||||||
|
### Alterado
|
||||||
|
- Lançamentos: conversões para séries respeitam faturas pagas e limite disponível do cartão antes de criar novos movimentos.
|
||||||
|
|
||||||
|
## [2.7.5] - 2026-06-13
|
||||||
|
|
||||||
|
Esta versão faz um polimento pontual no dashboard, deixando os widgets mais explicativos, consistentes e confiáveis quando há listas maiores ou informações complementares para revisar.
|
||||||
|
|
||||||
|
### Alterado
|
||||||
|
- Dashboard: os indicadores percentuais de faturas por pessoa, despesas por categoria, receitas por categoria e tendências de categorias agora deixam explícito que a comparação é contra o mês anterior.
|
||||||
|
- Dashboard: pequenos ajustes visuais em widgets melhoram espaçamento, bordas e leitura de itens financeiros.
|
||||||
|
|
||||||
|
### Corrigido
|
||||||
|
- Dashboard: o widget `Lançamentos por categoria` agora recalcula corretamente o overflow quando a lista muda e volta a exibir o botão `Expandir` em listagens grandes.
|
||||||
|
- Relatórios: em `/reports/installment-analysis`, os cards de parcelamentos agora exibem o ícone de observação ao lado do nome do lançamento quando há anotação cadastrada.
|
||||||
|
|
||||||
|
## [2.7.4] - 2026-06-09
|
||||||
|
|
||||||
|
Esta versão corrige o fluxo de revisão de lançamentos compartilhados para que o acesso somente leitura proteja os dados originais sem impedir que a pessoa copie movimentos para a própria conta.
|
||||||
|
|
||||||
|
### Corrigido
|
||||||
|
- Pessoas: lançamentos de uma pessoa compartilhada em modo somente leitura agora podem ser selecionados e importados para a conta do usuário logado, tanto individualmente quanto em lote, mantendo edição e remoção bloqueadas no lançamento original.
|
||||||
|
|
||||||
|
## [2.7.3] - 2026-06-05
|
||||||
|
|
||||||
|
Esta versão melhora pequenos pontos de leitura e configuração para o uso diário e self-hosted. As faturas pagas ficam mais fáceis de identificar na lista de cartões, a configuração de origins confiáveis do Better Auth passa a ficar documentada para Docker e túneis, o dashboard corrige a leitura de tempo dos pré-lançamentos e as dependências seguem atualizadas sem quebrar o build da imagem.
|
||||||
|
|
||||||
|
### Adicionado
|
||||||
|
- Cartões: a lista de cartões agora exibe a etiqueta `Paga` ao lado do valor da fatura atual quando ela já foi quitada.
|
||||||
|
- Self-hosting: adicionada a variável `BETTER_AUTH_TRUSTED_ORIGINS` ao `.env.example`, ao `docker-compose.yml` e ao README para permitir origins adicionais confiáveis em cenários com Cloudflare Tunnel, reverse proxy ou URLs diferentes de `BETTER_AUTH_URL`.
|
||||||
|
|
||||||
|
### Alterado
|
||||||
|
- Dependências: atualizados Next.js, React, Better Auth, AI SDK, AWS SDK, pdf.js e ferramentas de desenvolvimento usadas no build.
|
||||||
|
|
||||||
|
### Corrigido
|
||||||
|
- Dashboard: o widget `Pré-lançamentos` agora calcula o rótulo `há X` a partir da chegada do item ao OpenMonetis, evitando deslocamentos causados por timestamps de notificação enviados com timezone incorreto.
|
||||||
|
- Anexos: o preview de PDFs foi ajustado para a API atual do `pdfjs-dist`, evitando falha de TypeScript durante o build da imagem Docker.
|
||||||
|
|
||||||
## [2.7.2] - 2026-05-31
|
## [2.7.2] - 2026-05-31
|
||||||
|
|
||||||
Esta versão atualiza as imagens de apresentação do OpenMonetis na landing page e no compartilhamento em redes sociais.
|
Esta versão atualiza as imagens de apresentação do OpenMonetis na landing page e no compartilhamento em redes sociais.
|
||||||
|
|||||||
26
README.md
@@ -6,9 +6,11 @@
|
|||||||
Projeto pessoal de gestão financeira. Self-hosted, manual e open source.
|
Projeto pessoal de gestão financeira. Self-hosted, manual e open source.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
> **⚠️ Não há versão online hospedada.** Você precisa clonar o repositório e rodar localmente ou no seu próprio servidor.
|
> **⚠️ Nota:** o OpenMonetis não está sendo encerrado, mas o desenvolvimento deve reduzir para quase zero daqui em diante. O app já cobre minhas demandas atuais de gerenciamento financeiro, então novas mudanças tendem a ser pontuais: correções, ajustes necessários e pequenas melhorias quando fizerem bastante sentido para meu uso.
|
||||||
|
|
||||||
[](CHANGELOG.md)
|
> **Não há versão online hospedada.** Você precisa clonar o repositório e rodar localmente ou no seu próprio servidor.
|
||||||
|
|
||||||
|
[](CHANGELOG.md)
|
||||||
[](https://nextjs.org/)
|
[](https://nextjs.org/)
|
||||||
[](https://www.typescriptlang.org/)
|
[](https://www.typescriptlang.org/)
|
||||||
[](https://www.postgresql.org/)
|
[](https://www.postgresql.org/)
|
||||||
@@ -63,11 +65,11 @@ A ideia é simples: ter um lugar onde consigo ver todas as minhas contas, cartõ
|
|||||||
|
|
||||||
### Funcionalidades
|
### Funcionalidades
|
||||||
|
|
||||||
💰 **Contas e transações** — Contas bancárias, cartões, dinheiro. Receitas, despesas, rendimentos e transferências. Categorização, divisão de lançamentos entre várias pessoas, filtros combináveis com intervalo de datas, extratos detalhados e importação de extratos OFX e XLS/XLSX com detecção automática de categoria.
|
💰 **Contas e transações** — Contas bancárias, cartões, dinheiro. Receitas, despesas, rendimentos e transferências. Categorização, divisão de lançamentos entre várias pessoas, filtros combináveis com intervalo de datas, extratos detalhados com identificação visual clara da conta e importação de extratos OFX e XLS/XLSX com detecção automática de categoria.
|
||||||
|
|
||||||
📊 **Dashboard e relatórios** — Widgets personalizáveis, métricas com atalhos para lançamentos, gráficos de evolução, comparativos por categoria, tendências, uso de cartões, top estabelecimentos e navegação direta entre meses pelo seletor de período. Exportação em PDF e Excel.
|
📊 **Dashboard e relatórios** — Widgets personalizáveis com listas consistentes, métricas com atalhos para lançamentos, gráficos de evolução, comparativos por categoria, tendências, uso de cartões, top estabelecimentos e navegação direta entre meses pelo seletor de período. Exportação em PDF e Excel.
|
||||||
|
|
||||||
💳 **Faturas de cartão** — Acompanhe faturas por período, controle limites e vencimentos.
|
💳 **Faturas de cartão** — Acompanhe faturas por período, controle limites e vencimentos com identificação visual mais clara do cartão.
|
||||||
|
|
||||||
🎯 **Orçamentos** — Defina limites por categoria e acompanhe o progresso.
|
🎯 **Orçamentos** — Defina limites por categoria e acompanhe o progresso.
|
||||||
|
|
||||||
@@ -451,6 +453,7 @@ POSTGRES_DB=openmonetis_db
|
|||||||
DISABLE_SIGNUP=false # true bloqueia novos cadastros
|
DISABLE_SIGNUP=false # true bloqueia novos cadastros
|
||||||
AUTH_SESSION_EXPIRES_IN_DAYS=30 # duração de sessões persistentes
|
AUTH_SESSION_EXPIRES_IN_DAYS=30 # duração de sessões persistentes
|
||||||
AUTH_SESSION_UPDATE_AGE_HOURS=24 # frequência de renovação da sessão
|
AUTH_SESSION_UPDATE_AGE_HOURS=24 # frequência de renovação da sessão
|
||||||
|
BETTER_AUTH_TRUSTED_ORIGINS= # origins adicionais confiáveis, separadas por vírgula
|
||||||
|
|
||||||
# S3 Server (opcional, necessario para anexos)
|
# S3 Server (opcional, necessario para anexos)
|
||||||
S3_ENDPOINT=
|
S3_ENDPOINT=
|
||||||
@@ -485,6 +488,19 @@ LOGO_DEV_TOKEN=
|
|||||||
LOGO_DEV_SECRET_KEY=
|
LOGO_DEV_SECRET_KEY=
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### BETTER_AUTH_TRUSTED_ORIGINS
|
||||||
|
|
||||||
|
Use `BETTER_AUTH_TRUSTED_ORIGINS` quando o OpenMonetis for acessado por uma URL diferente de `BETTER_AUTH_URL`, como Cloudflare Tunnel, reverse proxy, domínio local ou subdomínios temporários. Isso evita falhas de login como `Invalid origin` sem precisar alterar a imagem Docker.
|
||||||
|
|
||||||
|
Informe apenas origins confiáveis, separadas por vírgula:
|
||||||
|
|
||||||
|
```env
|
||||||
|
BETTER_AUTH_URL=http://localhost:3000
|
||||||
|
BETTER_AUTH_TRUSTED_ORIGINS=https://*.trycloudflare.com,https://openmonetis.seudominio.com
|
||||||
|
```
|
||||||
|
|
||||||
|
Para Google OAuth e outros callbacks externos, mantenha `BETTER_AUTH_URL` apontando para a URL pública/canônica configurada no provedor.
|
||||||
|
|
||||||
### IA local com Ollama
|
### IA local com Ollama
|
||||||
|
|
||||||
O provider Ollama permite gerar insights usando modelos locais. Instale e suba o Ollama no host onde o modelo ficará disponível:
|
O provider Ollama permite gerar insights usando modelos locais. Instale e suba o Ollama no host onde o modelo ficará disponível:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://biomejs.dev/schemas/2.4.15/schema.json",
|
"$schema": "https://biomejs.dev/schemas/2.4.16/schema.json",
|
||||||
"vcs": {
|
"vcs": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"clientKind": "git",
|
"clientKind": "git",
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ services:
|
|||||||
DATABASE_URL: ${DATABASE_URL:-postgresql://openmonetis:openmonetis_dev_password@db:5432/openmonetis_db}
|
DATABASE_URL: ${DATABASE_URL:-postgresql://openmonetis:openmonetis_dev_password@db:5432/openmonetis_db}
|
||||||
BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:-}
|
BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET:-}
|
||||||
BETTER_AUTH_URL: ${BETTER_AUTH_URL:-http://localhost:3000}
|
BETTER_AUTH_URL: ${BETTER_AUTH_URL:-http://localhost:3000}
|
||||||
|
BETTER_AUTH_TRUSTED_ORIGINS: ${BETTER_AUTH_TRUSTED_ORIGINS:-}
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|||||||
40
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "openmonetis",
|
"name": "openmonetis",
|
||||||
"version": "2.7.2",
|
"version": "2.7.7",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "pnpm@11.1.3",
|
"packageManager": "pnpm@11.1.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -31,13 +31,13 @@
|
|||||||
"mockup": "tsx scripts/mock-data.ts"
|
"mockup": "tsx scripts/mock-data.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ai-sdk/anthropic": "^3.0.79",
|
"@ai-sdk/anthropic": "^3.0.81",
|
||||||
"@ai-sdk/google": "^3.0.79",
|
"@ai-sdk/google": "^3.0.80",
|
||||||
"@ai-sdk/openai": "^3.0.65",
|
"@ai-sdk/openai": "^3.0.67",
|
||||||
"@ai-sdk/openai-compatible": "^2.0.48",
|
"@ai-sdk/openai-compatible": "^2.0.48",
|
||||||
"@aws-sdk/client-s3": "^3.1050.0",
|
"@aws-sdk/client-s3": "^3.1059.0",
|
||||||
"@aws-sdk/s3-request-presigner": "^3.1050.0",
|
"@aws-sdk/s3-request-presigner": "^3.1059.0",
|
||||||
"@better-auth/passkey": "^1.6.11",
|
"@better-auth/passkey": "^1.6.14",
|
||||||
"@dnd-kit/core": "^6.3.1",
|
"@dnd-kit/core": "^6.3.1",
|
||||||
"@dnd-kit/sortable": "^10.0.0",
|
"@dnd-kit/sortable": "^10.0.0",
|
||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
@@ -64,27 +64,27 @@
|
|||||||
"@radix-ui/react-toggle-group": "1.1.11",
|
"@radix-ui/react-toggle-group": "1.1.11",
|
||||||
"@radix-ui/react-tooltip": "1.2.8",
|
"@radix-ui/react-tooltip": "1.2.8",
|
||||||
"@remixicon/react": "4.9.0",
|
"@remixicon/react": "4.9.0",
|
||||||
"@tanstack/react-query": "^5.100.14",
|
"@tanstack/react-query": "^5.101.0",
|
||||||
"@tanstack/react-table": "8.21.3",
|
"@tanstack/react-table": "8.21.3",
|
||||||
"@tanstack/react-virtual": "^3.13.26",
|
"@tanstack/react-virtual": "^3.14.2",
|
||||||
"ai": "^6.0.191",
|
"ai": "^6.0.195",
|
||||||
"better-auth": "1.6.11",
|
"better-auth": "1.6.14",
|
||||||
"canvas-confetti": "^1.9.4",
|
"canvas-confetti": "^1.9.4",
|
||||||
"class-variance-authority": "0.7.1",
|
"class-variance-authority": "0.7.1",
|
||||||
"clsx": "2.1.1",
|
"clsx": "2.1.1",
|
||||||
"cmdk": "^1.1.1",
|
"cmdk": "^1.1.1",
|
||||||
"date-fns": "^4.3.0",
|
"date-fns": "^4.4.0",
|
||||||
"drizzle-orm": "0.45.2",
|
"drizzle-orm": "0.45.2",
|
||||||
"exceljs": "^4.4.0",
|
"exceljs": "^4.4.0",
|
||||||
"jspdf": "^4.2.1",
|
"jspdf": "^4.2.1",
|
||||||
"jspdf-autotable": "^5.0.8",
|
"jspdf-autotable": "^5.0.8",
|
||||||
"next": "16.2.6",
|
"next": "16.2.7",
|
||||||
"next-themes": "0.4.6",
|
"next-themes": "0.4.6",
|
||||||
"pdfjs-dist": "^5.7.284",
|
"pdfjs-dist": "^6.0.227",
|
||||||
"pg": "8.21.0",
|
"pg": "8.21.0",
|
||||||
"react": "19.2.6",
|
"react": "19.2.7",
|
||||||
"react-day-picker": "^10.0.1",
|
"react-day-picker": "^10.0.1",
|
||||||
"react-dom": "19.2.6",
|
"react-dom": "19.2.7",
|
||||||
"recharts": "3.8.1",
|
"recharts": "3.8.1",
|
||||||
"resend": "^6.12.4",
|
"resend": "^6.12.4",
|
||||||
"sonner": "2.0.7",
|
"sonner": "2.0.7",
|
||||||
@@ -95,19 +95,19 @@
|
|||||||
"zod": "4.4.3"
|
"zod": "4.4.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.4.15",
|
"@biomejs/biome": "2.4.16",
|
||||||
"@tailwindcss/postcss": "4.3.0",
|
"@tailwindcss/postcss": "4.3.0",
|
||||||
"@types/canvas-confetti": "^1.9.0",
|
"@types/canvas-confetti": "^1.9.0",
|
||||||
"@types/node": "25.9.1",
|
"@types/node": "25.9.1",
|
||||||
"@types/pg": "^8.20.0",
|
"@types/pg": "^8.20.0",
|
||||||
"@types/react": "19.2.15",
|
"@types/react": "19.2.16",
|
||||||
"@types/react-dom": "19.2.3",
|
"@types/react-dom": "19.2.3",
|
||||||
"babel-plugin-react-compiler": "^1.0.0",
|
"babel-plugin-react-compiler": "^1.0.0",
|
||||||
"dotenv": "^17.4.2",
|
"dotenv": "^17.4.2",
|
||||||
"drizzle-kit": "0.31.10",
|
"drizzle-kit": "0.31.10",
|
||||||
"knip": "^6.14.2",
|
"knip": "^6.15.0",
|
||||||
"tailwindcss": "4.3.0",
|
"tailwindcss": "4.3.0",
|
||||||
"tsx": "4.22.3",
|
"tsx": "4.22.4",
|
||||||
"typescript": "6.0.3"
|
"typescript": "6.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2446
pnpm-lock.yaml
generated
@@ -7,29 +7,7 @@ allowBuilds:
|
|||||||
sharp: true
|
sharp: true
|
||||||
unrs-resolver: true
|
unrs-resolver: true
|
||||||
|
|
||||||
minimumReleaseAgeExclude:
|
minimumReleaseAge: 0
|
||||||
- '@aws-sdk/client-s3@3.1050.0'
|
|
||||||
- '@aws-sdk/s3-request-presigner@3.1050.0'
|
|
||||||
- '@types/node@25.9.1'
|
|
||||||
- '@types/react@19.2.15'
|
|
||||||
- '@aws-sdk/client-s3@3.1054.0'
|
|
||||||
- '@aws-sdk/core@3.974.14'
|
|
||||||
- '@aws-sdk/credential-provider-env@3.972.40'
|
|
||||||
- '@aws-sdk/credential-provider-http@3.972.42'
|
|
||||||
- '@aws-sdk/credential-provider-ini@3.972.44'
|
|
||||||
- '@aws-sdk/credential-provider-login@3.972.44'
|
|
||||||
- '@aws-sdk/credential-provider-node@3.972.45'
|
|
||||||
- '@aws-sdk/credential-provider-process@3.972.40'
|
|
||||||
- '@aws-sdk/credential-provider-sso@3.972.44'
|
|
||||||
- '@aws-sdk/credential-provider-web-identity@3.972.44'
|
|
||||||
- '@aws-sdk/middleware-bucket-endpoint@3.972.16'
|
|
||||||
- '@aws-sdk/middleware-flexible-checksums@3.974.22'
|
|
||||||
- '@aws-sdk/middleware-sdk-s3@3.972.43'
|
|
||||||
- '@aws-sdk/nested-clients@3.997.12'
|
|
||||||
- '@aws-sdk/s3-request-presigner@3.1054.0'
|
|
||||||
- '@aws-sdk/signature-v4-multi-region@3.996.29'
|
|
||||||
- '@aws-sdk/token-providers@3.1054.0'
|
|
||||||
- '@aws-sdk/xml-builder@3.972.26'
|
|
||||||
|
|
||||||
overrides:
|
overrides:
|
||||||
defu: 6.1.7
|
defu: 6.1.7
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 598 KiB After Width: | Height: | Size: 350 KiB |
|
Before Width: | Height: | Size: 589 KiB After Width: | Height: | Size: 355 KiB |
@@ -1,3 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200" role="img" aria-label="OpenMonetis">
|
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" aria-label="OpenMonetis" role="img" viewBox="0 0 200 200"><path fill="#f73" d="M 77.66,165.64 L 37.77,141.54 L 63.30,108.72 L 27.13,97.44 L 46.81,50.77 L 77.66,63.08 L 81.91,30.26 L 126.40,29.23 L 126.06,33.85 L 122.87,67.69 L 158.51,50.77 L 178.19,90.26 L 140.96,104.62 L 162.23,127.18 L 132.98,162.56 L 103.19,131.79 Z"/></svg>
|
||||||
<path fill="#ff7733" d="M 77.66,165.64 L 37.77,141.54 L 63.30,108.72 L 27.13,97.44 L 46.81,50.77 L 77.66,63.08 L 81.91,30.26 L 126.40,29.23 L 126.06,33.85 L 122.87,67.69 L 158.51,50.77 L 178.19,90.26 L 140.96,104.62 L 162.23,127.18 L 132.98,162.56 L 103.19,131.79 Z"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 402 B After Width: | Height: | Size: 394 B |
|
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 139 KiB |
|
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 137 KiB |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 17 KiB |
@@ -1 +1 @@
|
|||||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>MiniMax</title><defs><linearGradient id="lobe-icons-minimax-gradient" x1="0%" x2="100.182%" y1="50.057%" y2="50.057%"><stop offset="0%" stop-color="#E2167E"/><stop offset="100%" stop-color="#FE603C"/></linearGradient></defs><path d="M16.278 2c1.156 0 2.093.927 2.093 2.07v12.501a.74.74 0 00.744.709.74.74 0 00.743-.709V9.099a2.06 2.06 0 012.071-2.049A2.06 2.06 0 0124 9.1v6.561a.649.649 0 01-.652.645.649.649 0 01-.653-.645V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v7.472a2.037 2.037 0 01-2.048 2.026 2.037 2.037 0 01-2.048-2.026v-12.5a.785.785 0 00-.788-.753.785.785 0 00-.789.752l-.001 15.904A2.037 2.037 0 0113.441 22a2.037 2.037 0 01-2.048-2.026V18.04c0-.356.292-.645.652-.645.36 0 .652.289.652.645v1.934c0 .263.142.506.372.638.23.131.514.131.744 0a.734.734 0 00.372-.638V4.07c0-1.143.937-2.07 2.093-2.07zm-5.674 0c1.156 0 2.093.927 2.093 2.07v11.523a.648.648 0 01-.652.645.648.648 0 01-.652-.645V4.07a.785.785 0 00-.789-.78.785.785 0 00-.789.78v14.013a2.06 2.06 0 01-2.07 2.048 2.06 2.06 0 01-2.071-2.048V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v3.8a2.06 2.06 0 01-2.071 2.049A2.06 2.06 0 010 12.9v-1.378c0-.357.292-.646.652-.646.36 0 .653.29.653.646V12.9c0 .418.343.757.766.757s.766-.339.766-.757V9.099a2.06 2.06 0 012.07-2.048 2.06 2.06 0 012.071 2.048v8.984c0 .419.343.758.767.758.423 0 .766-.339.766-.758V4.07c0-1.143.937-2.07 2.093-2.07z" fill="url(#lobe-icons-minimax-gradient)" fill-rule="nonzero"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" height="1em" style="flex:none;line-height:1" width="1em" viewBox="0 0 24 24"><title>MiniMax</title><defs><linearGradient id="lobe-icons-minimax-gradient" x1="0%" x2="100.182%" y1="50.057%" y2="50.057%"><stop offset="0%" stop-color="#E2167E"/><stop offset="100%" stop-color="#FE603C"/></linearGradient></defs><path fill="url(#lobe-icons-minimax-gradient)" fill-rule="nonzero" d="M16.278 2c1.156 0 2.093.927 2.093 2.07v12.501a.74.74 0 00.744.709.74.74 0 00.743-.709V9.099a2.06 2.06 0 012.071-2.049A2.06 2.06 0 0124 9.1v6.561a.649.649 0 01-.652.645.649.649 0 01-.653-.645V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v7.472a2.037 2.037 0 01-2.048 2.026 2.037 2.037 0 01-2.048-2.026v-12.5a.785.785 0 00-.788-.753.785.785 0 00-.789.752l-.001 15.904A2.037 2.037 0 0113.441 22a2.037 2.037 0 01-2.048-2.026V18.04c0-.356.292-.645.652-.645.36 0 .652.289.652.645v1.934c0 .263.142.506.372.638.23.131.514.131.744 0a.734.734 0 00.372-.638V4.07c0-1.143.937-2.07 2.093-2.07zm-5.674 0c1.156 0 2.093.927 2.093 2.07v11.523a.648.648 0 01-.652.645.648.648 0 01-.652-.645V4.07a.785.785 0 00-.789-.78.785.785 0 00-.789.78v14.013a2.06 2.06 0 01-2.07 2.048 2.06 2.06 0 01-2.071-2.048V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v3.8a2.06 2.06 0 01-2.071 2.049A2.06 2.06 0 010 12.9v-1.378c0-.357.292-.646.652-.646.36 0 .653.29.653.646V12.9c0 .418.343.757.766.757s.766-.339.766-.757V9.099a2.06 2.06 0 012.07-2.048 2.06 2.06 0 012.071 2.048v8.984c0 .419.343.758.767.758.423 0 .766-.339.766-.758V4.07c0-1.143.937-2.07 2.093-2.07z"/></svg>
|
||||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
@@ -136,6 +136,7 @@ export default async function Page({ params, searchParams }: PageProps) {
|
|||||||
limitAvailable: limitAmount,
|
limitAvailable: limitAmount,
|
||||||
currentInvoiceAmount: 0,
|
currentInvoiceAmount: 0,
|
||||||
currentInvoiceLabel: "",
|
currentInvoiceLabel: "",
|
||||||
|
currentInvoiceStatus: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { totalAmount, invoiceStatus, paymentDate } = invoiceData;
|
const { totalAmount, invoiceStatus, paymentDate } = invoiceData;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
@custom-variant dark (&:is(.dark *));
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
@theme {
|
@theme {
|
||||||
--spacing-custom-height-card: 29rem;
|
--spacing-custom-height-card: 30rem;
|
||||||
--spacing-8xl: 90rem;
|
--spacing-8xl: 90rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@
|
|||||||
--destructive: oklch(62% 0.2 28);
|
--destructive: oklch(62% 0.2 28);
|
||||||
--destructive-foreground: oklch(98% 0.005 30);
|
--destructive-foreground: oklch(98% 0.005 30);
|
||||||
|
|
||||||
--border: oklch(24.576% 0.0072 67.399);
|
--border: oklch(29.675% 0.01144 67.3);
|
||||||
--input: var(--border);
|
--input: var(--border);
|
||||||
--ring: var(--primary);
|
--ring: var(--primary);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { RiInformationLine } from "@remixicon/react";
|
import { RiBankLine, RiInformationLine } from "@remixicon/react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
@@ -52,28 +52,32 @@ export function AccountStatementCard({
|
|||||||
const resultado = totalIncomes - totalExpenses;
|
const resultado = totalIncomes - totalExpenses;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="gap-0 py-0">
|
<Card className="gap-0 py-0 space-y-2">
|
||||||
<CardContent className="px-4 py-4 sm:px-5 sm:py-5">
|
<CardContent className="px-4 py-4 sm:px-5 sm:py-5">
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{/* Linha 1 — identidade */}
|
{/* Linha 1 — identidade */}
|
||||||
<div className="flex items-center justify-between gap-3">
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
||||||
<div className="flex min-w-0 items-center gap-3">
|
<div className="flex min-w-0 items-start gap-3">
|
||||||
{logoPath ? (
|
{logoPath ? (
|
||||||
<div className="flex size-12 shrink-0 items-center justify-center overflow-hidden rounded-full">
|
<div className="flex size-12 shrink-0 items-center justify-center overflow-hidden rounded-full">
|
||||||
<Image
|
<Image
|
||||||
src={logoPath}
|
src={logoPath}
|
||||||
alt={`Logo ${accountName}`}
|
alt={`Logo ${accountName}`}
|
||||||
width={42}
|
width={48}
|
||||||
height={42}
|
height={48}
|
||||||
className="h-full w-full object-contain"
|
className="h-full w-full object-contain"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : (
|
||||||
<div className="min-w-0">
|
<span className="flex size-12 shrink-0 items-center justify-center rounded-full border bg-card text-primary">
|
||||||
<h2 className="truncate text-sm font-semibold text-foreground">
|
<RiBankLine className="size-5" aria-hidden />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<div className="min-w-0 space-y-1">
|
||||||
|
<h2 className="truncate text-xl font-semibold text-foreground sm:text-2xl">
|
||||||
{accountName}
|
{accountName}
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-sm leading-relaxed text-muted-foreground">
|
||||||
Extrato de {periodLabel}
|
Extrato de {periodLabel}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function PdfCanvas({ url }: PdfCanvasProps) {
|
|||||||
|
|
||||||
let pdf: Awaited<ReturnType<typeof pdfjsLib.getDocument>["promise"]>;
|
let pdf: Awaited<ReturnType<typeof pdfjsLib.getDocument>["promise"]>;
|
||||||
try {
|
try {
|
||||||
pdf = await pdfjsLib.getDocument(url).promise;
|
pdf = await pdfjsLib.getDocument({ url }).promise;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if ((err as { name?: string }).name === "PasswordException") {
|
if ((err as { name?: string }).name === "PasswordException") {
|
||||||
if (!cancelled) setLocked(true);
|
if (!cancelled) setLocked(true);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
} from "@remixicon/react";
|
} from "@remixicon/react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
|
import { Badge } from "@/shared/components/ui/badge";
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@@ -23,6 +24,10 @@ import {
|
|||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/shared/components/ui/tooltip";
|
} from "@/shared/components/ui/tooltip";
|
||||||
import { resolveCardBrandAsset } from "@/shared/lib/cards/brand-assets";
|
import { resolveCardBrandAsset } from "@/shared/lib/cards/brand-assets";
|
||||||
|
import {
|
||||||
|
INVOICE_PAYMENT_STATUS,
|
||||||
|
type InvoicePaymentStatus,
|
||||||
|
} from "@/shared/lib/invoices";
|
||||||
import { resolveLogoSrc } from "@/shared/lib/logo";
|
import { resolveLogoSrc } from "@/shared/lib/logo";
|
||||||
import { cn } from "@/shared/utils/ui";
|
import { cn } from "@/shared/utils/ui";
|
||||||
|
|
||||||
@@ -37,6 +42,7 @@ interface CardItemProps {
|
|||||||
limitAvailable?: number;
|
limitAvailable?: number;
|
||||||
currentInvoiceAmount: number;
|
currentInvoiceAmount: number;
|
||||||
currentInvoiceLabel: string;
|
currentInvoiceLabel: string;
|
||||||
|
currentInvoiceStatus: InvoicePaymentStatus | null;
|
||||||
accountName: string;
|
accountName: string;
|
||||||
logo?: string | null;
|
logo?: string | null;
|
||||||
note?: string | null;
|
note?: string | null;
|
||||||
@@ -58,6 +64,7 @@ export function CardItem({
|
|||||||
limitAvailable,
|
limitAvailable,
|
||||||
currentInvoiceAmount,
|
currentInvoiceAmount,
|
||||||
currentInvoiceLabel,
|
currentInvoiceLabel,
|
||||||
|
currentInvoiceStatus,
|
||||||
accountName: _accountName,
|
accountName: _accountName,
|
||||||
logo,
|
logo,
|
||||||
note,
|
note,
|
||||||
@@ -80,6 +87,8 @@ export function CardItem({
|
|||||||
const logoPath = resolveLogoSrc(logo);
|
const logoPath = resolveLogoSrc(logo);
|
||||||
const brandAsset = resolveCardBrandAsset(brand);
|
const brandAsset = resolveCardBrandAsset(brand);
|
||||||
const isInactive = status?.toLowerCase() === "inativo";
|
const isInactive = status?.toLowerCase() === "inativo";
|
||||||
|
const isCurrentInvoicePaid =
|
||||||
|
currentInvoiceStatus === INVOICE_PAYMENT_STATUS.PAID;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="flex flex-col p-6 w-full">
|
<Card className="flex flex-col p-6 w-full">
|
||||||
@@ -175,10 +184,17 @@ export function CardItem({
|
|||||||
<span className="text-xs text-muted-foreground">
|
<span className="text-xs text-muted-foreground">
|
||||||
{currentInvoiceLabel}
|
{currentInvoiceLabel}
|
||||||
</span>
|
</span>
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<MoneyValues
|
<MoneyValues
|
||||||
amount={currentInvoiceAmount}
|
amount={currentInvoiceAmount}
|
||||||
className="text-xl font-semibold text-info"
|
className="text-xl font-semibold text-info"
|
||||||
/>
|
/>
|
||||||
|
{isCurrentInvoicePaid ? (
|
||||||
|
<Badge variant="success" className="text-xs">
|
||||||
|
Paga
|
||||||
|
</Badge>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex gap-2 justify-between w-full">
|
<div className="flex gap-2 justify-between w-full">
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ export function CardsPage({
|
|||||||
limitAvailable={card.limitAvailable ?? card.limit ?? null}
|
limitAvailable={card.limitAvailable ?? card.limit ?? null}
|
||||||
currentInvoiceAmount={card.currentInvoiceAmount}
|
currentInvoiceAmount={card.currentInvoiceAmount}
|
||||||
currentInvoiceLabel={card.currentInvoiceLabel}
|
currentInvoiceLabel={card.currentInvoiceLabel}
|
||||||
|
currentInvoiceStatus={card.currentInvoiceStatus}
|
||||||
accountName={card.accountName}
|
accountName={card.accountName}
|
||||||
logo={card.logo}
|
logo={card.logo}
|
||||||
note={card.note}
|
note={card.note}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { InvoicePaymentStatus } from "@/shared/lib/invoices";
|
||||||
|
|
||||||
export type Card = {
|
export type Card = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -14,6 +16,7 @@ export type Card = {
|
|||||||
limitAvailable: number;
|
limitAvailable: number;
|
||||||
currentInvoiceAmount: number;
|
currentInvoiceAmount: number;
|
||||||
currentInvoiceLabel: string;
|
currentInvoiceLabel: string;
|
||||||
|
currentInvoiceStatus: InvoicePaymentStatus | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CardFormValues = {
|
export type CardFormValues = {
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ import {
|
|||||||
} from "drizzle-orm";
|
} from "drizzle-orm";
|
||||||
import { cards, financialAccounts, invoices, transactions } from "@/db/schema";
|
import { cards, financialAccounts, invoices, transactions } from "@/db/schema";
|
||||||
import { db } from "@/shared/lib/db";
|
import { db } from "@/shared/lib/db";
|
||||||
import { INVOICE_PAYMENT_STATUS } from "@/shared/lib/invoices";
|
import {
|
||||||
|
INVOICE_PAYMENT_STATUS,
|
||||||
|
INVOICE_STATUS_VALUES,
|
||||||
|
type InvoicePaymentStatus,
|
||||||
|
} from "@/shared/lib/invoices";
|
||||||
import { loadLogoOptions } from "@/shared/lib/logo/options";
|
import { loadLogoOptions } from "@/shared/lib/logo/options";
|
||||||
import {
|
import {
|
||||||
formatPeriodMonthShort,
|
formatPeriodMonthShort,
|
||||||
@@ -33,6 +37,7 @@ type CardData = {
|
|||||||
limitAvailable: number;
|
limitAvailable: number;
|
||||||
currentInvoiceAmount: number;
|
currentInvoiceAmount: number;
|
||||||
currentInvoiceLabel: string;
|
currentInvoiceLabel: string;
|
||||||
|
currentInvoiceStatus: InvoicePaymentStatus | null;
|
||||||
accountId: string;
|
accountId: string;
|
||||||
accountName: string;
|
accountName: string;
|
||||||
};
|
};
|
||||||
@@ -48,6 +53,12 @@ function formatCurrentInvoiceLabel(period: string) {
|
|||||||
return `Fatura ${formatPeriodMonthShort(period)}. ${year}`;
|
return `Fatura ${formatPeriodMonthShort(period)}. ${year}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseInvoiceStatus(value: unknown): InvoicePaymentStatus | null {
|
||||||
|
return INVOICE_STATUS_VALUES.includes(value as InvoicePaymentStatus)
|
||||||
|
? (value as InvoicePaymentStatus)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchCardsByStatus(
|
async function fetchCardsByStatus(
|
||||||
userId: string,
|
userId: string,
|
||||||
archived: boolean,
|
archived: boolean,
|
||||||
@@ -58,8 +69,14 @@ async function fetchCardsByStatus(
|
|||||||
}> {
|
}> {
|
||||||
const currentPeriod = getCurrentPeriod();
|
const currentPeriod = getCurrentPeriod();
|
||||||
const currentInvoiceLabel = formatCurrentInvoiceLabel(currentPeriod);
|
const currentInvoiceLabel = formatCurrentInvoiceLabel(currentPeriod);
|
||||||
const [cardRows, accountRows, logoOptions, usageRows, invoiceRows] =
|
const [
|
||||||
await Promise.all([
|
cardRows,
|
||||||
|
accountRows,
|
||||||
|
logoOptions,
|
||||||
|
usageRows,
|
||||||
|
invoiceRows,
|
||||||
|
invoiceStatusRows,
|
||||||
|
] = await Promise.all([
|
||||||
db.query.cards.findMany({
|
db.query.cards.findMany({
|
||||||
orderBy: (table, { desc }) => [desc(table.name)],
|
orderBy: (table, { desc }) => [desc(table.name)],
|
||||||
where: and(
|
where: and(
|
||||||
@@ -130,6 +147,15 @@ async function fetchCardsByStatus(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.groupBy(transactions.cardId),
|
.groupBy(transactions.cardId),
|
||||||
|
db
|
||||||
|
.select({
|
||||||
|
cardId: invoices.cardId,
|
||||||
|
paymentStatus: invoices.paymentStatus,
|
||||||
|
})
|
||||||
|
.from(invoices)
|
||||||
|
.where(
|
||||||
|
and(eq(invoices.userId, userId), eq(invoices.period, currentPeriod)),
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const usageMap = new Map<string, number>();
|
const usageMap = new Map<string, number>();
|
||||||
@@ -144,6 +170,13 @@ async function fetchCardsByStatus(
|
|||||||
invoiceMap.set(row.cardId, Math.abs(Number(row.total ?? 0)));
|
invoiceMap.set(row.cardId, Math.abs(Number(row.total ?? 0)));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
const invoiceStatusMap = new Map<string, InvoicePaymentStatus>();
|
||||||
|
invoiceStatusRows.forEach((row) => {
|
||||||
|
if (!row.cardId) return;
|
||||||
|
const status = parseInvoiceStatus(row.paymentStatus);
|
||||||
|
if (!status) return;
|
||||||
|
invoiceStatusMap.set(row.cardId, status);
|
||||||
|
});
|
||||||
|
|
||||||
const cardList = cardRows.map((card) => ({
|
const cardList = cardRows.map((card) => ({
|
||||||
id: card.id,
|
id: card.id,
|
||||||
@@ -166,6 +199,7 @@ async function fetchCardsByStatus(
|
|||||||
})(),
|
})(),
|
||||||
currentInvoiceAmount: invoiceMap.get(card.id) ?? 0,
|
currentInvoiceAmount: invoiceMap.get(card.id) ?? 0,
|
||||||
currentInvoiceLabel,
|
currentInvoiceLabel,
|
||||||
|
currentInvoiceStatus: invoiceStatusMap.get(card.id) ?? null,
|
||||||
accountId: card.accountId,
|
accountId: card.accountId,
|
||||||
accountName:
|
accountName:
|
||||||
(card.financialAccount as { name?: string } | null)?.name ??
|
(card.financialAccount as { name?: string } | null)?.name ??
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
isIncomeBill,
|
isIncomeBill,
|
||||||
} from "@/features/dashboard/bills/bills-helpers";
|
} from "@/features/dashboard/bills/bills-helpers";
|
||||||
import type { DashboardBill } from "@/features/dashboard/bills/bills-queries";
|
import type { DashboardBill } from "@/features/dashboard/bills/bills-queries";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import { EstablishmentLogo } from "@/shared/components/entity-avatar";
|
import { EstablishmentLogo } from "@/shared/components/entity-avatar";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
import { Button } from "@/shared/components/ui/button";
|
import { Button } from "@/shared/components/ui/button";
|
||||||
@@ -47,25 +48,22 @@ export function BillListItem({ bill, period, onPay }: BillListItemProps) {
|
|||||||
const href = buildTransactionsHref(bill.name, period);
|
const href = buildTransactionsHref(bill.name, period);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="flex items-center justify-between transition-all duration-300 py-1.5">
|
<li className={styles.row}>
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2 py-0.5">
|
<div className={styles.main}>
|
||||||
<EstablishmentLogo name={bill.name} size={37} />
|
<EstablishmentLogo name={bill.name} size={37} />
|
||||||
|
|
||||||
<div className="min-w-0">
|
<div className={styles.textStack}>
|
||||||
<Link
|
<Link href={href} className={styles.titleLink}>
|
||||||
href={href}
|
|
||||||
className="inline-flex max-w-full items-center gap-1 text-sm font-medium text-foreground underline-offset-2 hover:text-primary hover:underline"
|
|
||||||
>
|
|
||||||
<span className="truncate">{bill.name}</span>
|
<span className="truncate">{bill.name}</span>
|
||||||
</Link>
|
</Link>
|
||||||
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
<div className={styles.meta}>
|
||||||
{statusLabel ? (
|
{statusLabel ? (
|
||||||
statusTooltipLabel ? (
|
statusTooltipLabel ? (
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"cursor-help rounded-full py-0.5",
|
"cursor-help",
|
||||||
bill.isSettled && "text-success font-semibold",
|
bill.isSettled && "text-success font-semibold",
|
||||||
overdue && "text-destructive font-semibold",
|
overdue && "text-destructive font-semibold",
|
||||||
)}
|
)}
|
||||||
@@ -80,7 +78,6 @@ export function BillListItem({ bill, period, onPay }: BillListItemProps) {
|
|||||||
) : (
|
) : (
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"rounded-full py-0.5",
|
|
||||||
bill.isSettled && "text-success font-semibold",
|
bill.isSettled && "text-success font-semibold",
|
||||||
overdue && "text-destructive font-semibold",
|
overdue && "text-destructive font-semibold",
|
||||||
)}
|
)}
|
||||||
@@ -93,10 +90,10 @@ export function BillListItem({ bill, period, onPay }: BillListItemProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex shrink-0 flex-col items-end">
|
<div className={styles.trailing}>
|
||||||
<MoneyValues className="font-medium" amount={bill.amount} />
|
<MoneyValues className={styles.trailingValue} amount={bill.amount} />
|
||||||
{bill.isSettled ? (
|
{bill.isSettled ? (
|
||||||
<span className="flex h-7 items-center gap-0.5 text-xs font-medium text-success">
|
<span className={`${styles.trailingMeta} text-success`}>
|
||||||
<RiCheckboxCircleFill className="size-3.5" />{" "}
|
<RiCheckboxCircleFill className="size-3.5" />{" "}
|
||||||
{income ? "Recebido" : "Pago"}
|
{income ? "Recebido" : "Pago"}
|
||||||
</span>
|
</span>
|
||||||
@@ -105,7 +102,7 @@ export function BillListItem({ bill, period, onPay }: BillListItemProps) {
|
|||||||
type="button"
|
type="button"
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="link"
|
variant="link"
|
||||||
className="-mr-1.5 h-7 px-1.5 py-0"
|
className={styles.actionButton}
|
||||||
onClick={() => onPay(bill.id)}
|
onClick={() => onPay(bill.id)}
|
||||||
>
|
>
|
||||||
{overdue ? (
|
{overdue ? (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import type { DashboardCategoryBreakdownItem } from "@/features/dashboard/categories/category-breakdown-helpers";
|
import type { DashboardCategoryBreakdownItem } from "@/features/dashboard/categories/category-breakdown-helpers";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
||||||
import { CategoryIconBadge } from "@/shared/components/entity-avatar";
|
import { CategoryIconBadge } from "@/shared/components/entity-avatar";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
@@ -45,25 +46,23 @@ export function CategoryBreakdownListItem({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex items-center justify-between gap-2 transition-all duration-300 py-1.5">
|
<div className={styles.row}>
|
||||||
<span className="w-3 shrink-0 text-left text-xs font-medium text-muted-foreground">
|
<span className={styles.rank}>{position}</span>
|
||||||
{position}
|
<div className={styles.main}>
|
||||||
</span>
|
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2">
|
|
||||||
<CategoryIconBadge
|
<CategoryIconBadge
|
||||||
icon={category.categoryIcon}
|
icon={category.categoryIcon}
|
||||||
name={category.categoryName}
|
name={category.categoryName}
|
||||||
/>
|
/>
|
||||||
<div className="min-w-0 flex-1">
|
<div className={styles.textStack}>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Link
|
<Link
|
||||||
href={`/categories/${category.categoryId}?periodo=${periodParam}`}
|
href={`/categories/${category.categoryId}?periodo=${periodParam}`}
|
||||||
className="flex max-w-full items-center gap-1 text-sm font-medium text-foreground underline-offset-2 hover:text-primary hover:underline"
|
className={styles.titleLink}
|
||||||
>
|
>
|
||||||
<span className="truncate">{category.categoryName}</span>
|
<span className="truncate">{category.categoryName}</span>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-wrap items-center gap-x-1 text-xs text-muted-foreground">
|
<div className={styles.meta}>
|
||||||
<span>
|
<span>
|
||||||
{formatPercentage(
|
{formatPercentage(
|
||||||
category.percentageOfTotal,
|
category.percentageOfTotal,
|
||||||
@@ -97,23 +96,24 @@ export function CategoryBreakdownListItem({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex shrink-0 flex-col items-end gap-0.5">
|
<div className={styles.trailing}>
|
||||||
<MoneyValues
|
<MoneyValues
|
||||||
className="text-foreground font-medium"
|
className={styles.trailingValue}
|
||||||
amount={category.currentAmount}
|
amount={category.currentAmount}
|
||||||
/>
|
/>
|
||||||
|
{category.percentageChange !== null ? (
|
||||||
|
<span className={`${styles.trailingMeta} text-muted-foreground`}>
|
||||||
<PercentageChangeIndicator
|
<PercentageChangeIndicator
|
||||||
value={category.percentageChange}
|
value={category.percentageChange}
|
||||||
label={
|
label={formatPercentage(
|
||||||
category.percentageChange !== null
|
|
||||||
? formatPercentage(
|
|
||||||
category.percentageChange,
|
category.percentageChange,
|
||||||
config.percentageDigits,
|
config.percentageDigits,
|
||||||
)
|
)}
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
positiveTrend={config.positiveTrend}
|
positiveTrend={config.positiveTrend}
|
||||||
/>
|
/>
|
||||||
|
<span>vs. mês ant.</span>
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
export const dashboardWidgetListStyles = {
|
||||||
|
row: "flex min-h-[3.25rem] items-center justify-between gap-2 py-1.5 transition-all duration-300",
|
||||||
|
main: "flex min-w-0 flex-1 items-center gap-2",
|
||||||
|
textStack: "min-w-0 flex-1 space-y-0.5",
|
||||||
|
title: "truncate text-sm font-medium leading-5 text-foreground",
|
||||||
|
titleLink:
|
||||||
|
"inline-flex max-w-full items-center gap-1 text-sm font-medium leading-5 text-foreground underline-offset-2 hover:text-primary hover:underline",
|
||||||
|
meta: "flex min-h-4 flex-wrap items-center gap-x-2 gap-y-0.5 text-xs leading-4 text-muted-foreground",
|
||||||
|
rank: "w-3 shrink-0 text-left text-xs font-medium leading-4 text-muted-foreground",
|
||||||
|
trailing:
|
||||||
|
"flex min-w-[5.75rem] shrink-0 flex-col items-end gap-0.5 text-right",
|
||||||
|
trailingValue: "font-medium leading-5",
|
||||||
|
trailingMeta: "flex h-5 items-center gap-0.5 text-xs font-medium leading-4",
|
||||||
|
actionButton: "-mr-1 h-5 px-1 py-0 text-xs leading-4",
|
||||||
|
};
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { RiPencilLine } from "@remixicon/react";
|
import { RiPencilLine } from "@remixicon/react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import {
|
import {
|
||||||
clampGoalProgress,
|
clampGoalProgress,
|
||||||
formatGoalProgressPercentage,
|
formatGoalProgressPercentage,
|
||||||
@@ -30,7 +31,7 @@ export function GoalProgressItem({ item, onEdit }: GoalProgressItemProps) {
|
|||||||
const usedPercentageLabel = formatGoalProgressPercentage(item.usedPercentage);
|
const usedPercentageLabel = formatGoalProgressPercentage(item.usedPercentage);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="group py-2 transition-all duration-300">
|
<li className="group py-1.5 transition-all duration-300">
|
||||||
<div className="flex items-start justify-between gap-3">
|
<div className="flex items-start justify-between gap-3">
|
||||||
<div className="flex min-w-0 flex-1 items-start gap-2">
|
<div className="flex min-w-0 flex-1 items-start gap-2">
|
||||||
<CategoryIconBadge
|
<CategoryIconBadge
|
||||||
@@ -42,16 +43,14 @@ export function GoalProgressItem({ item, onEdit }: GoalProgressItemProps) {
|
|||||||
{item.categoryId ? (
|
{item.categoryId ? (
|
||||||
<Link
|
<Link
|
||||||
href={`/categories/${item.categoryId}?periodo=${formatPeriodForUrl(item.period)}`}
|
href={`/categories/${item.categoryId}?periodo=${formatPeriodForUrl(item.period)}`}
|
||||||
className="block truncate text-sm font-medium text-foreground underline-offset-2 hover:text-primary hover:underline"
|
className={`${styles.title} block underline-offset-2 hover:text-primary hover:underline`}
|
||||||
>
|
>
|
||||||
{item.categoryName}
|
{item.categoryName}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<p className="truncate text-sm font-medium text-foreground">
|
<p className={styles.title}>{item.categoryName}</p>
|
||||||
{item.categoryName}
|
|
||||||
</p>
|
|
||||||
)}
|
)}
|
||||||
<p className="mt-0.5 text-xs text-muted-foreground">
|
<p className="mt-0.5 text-xs leading-4 text-muted-foreground">
|
||||||
<MoneyValues className="font-medium" amount={item.spentAmount} />{" "}
|
<MoneyValues className="font-medium" amount={item.spentAmount} />{" "}
|
||||||
de{" "}
|
de{" "}
|
||||||
<MoneyValues className="font-medium" amount={item.budgetAmount} />
|
<MoneyValues className="font-medium" amount={item.budgetAmount} />
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
RiBankCard2Line,
|
RiBankCard2Line,
|
||||||
|
RiChat1Line,
|
||||||
RiCheckboxCircleFill,
|
RiCheckboxCircleFill,
|
||||||
RiFileList2Line,
|
RiFileList2Line,
|
||||||
RiTimeLine,
|
RiTimeLine,
|
||||||
@@ -30,6 +31,11 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "@/shared/components/ui/dialog";
|
} from "@/shared/components/ui/dialog";
|
||||||
import { Progress } from "@/shared/components/ui/progress";
|
import { Progress } from "@/shared/components/ui/progress";
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/shared/components/ui/tooltip";
|
||||||
import { resolveLogoSrc } from "@/shared/lib/logo";
|
import { resolveLogoSrc } from "@/shared/lib/logo";
|
||||||
import { cn } from "@/shared/utils";
|
import { cn } from "@/shared/utils";
|
||||||
import type { InstallmentGroup } from "./types";
|
import type { InstallmentGroup } from "./types";
|
||||||
@@ -83,6 +89,7 @@ export function InstallmentGroupCard({
|
|||||||
);
|
);
|
||||||
const cardLogoSrc = resolveLogoSrc(group.cartaoLogo);
|
const cardLogoSrc = resolveLogoSrc(group.cartaoLogo);
|
||||||
const cardName = group.cartaoName ?? "Compra parcelada";
|
const cardName = group.cartaoName ?? "Compra parcelada";
|
||||||
|
const hasNote = Boolean(group.note?.trim().length);
|
||||||
const untrackedLabel =
|
const untrackedLabel =
|
||||||
group.untrackedInstallments === 1
|
group.untrackedInstallments === 1
|
||||||
? "1 parcela anterior fora do acompanhamento"
|
? "1 parcela anterior fora do acompanhamento"
|
||||||
@@ -121,8 +128,28 @@ export function InstallmentGroupCard({
|
|||||||
<div className="flex items-center gap-3 flex-wrap">
|
<div className="flex items-center gap-3 flex-wrap">
|
||||||
<EstablishmentLogo name={group.name} size={40} />
|
<EstablishmentLogo name={group.name} size={40} />
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<CardTitle className="text-base truncate">
|
<CardTitle className="flex items-center gap-1 text-base">
|
||||||
{group.name}
|
<span className="truncate">{group.name}</span>
|
||||||
|
{hasNote ? (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<span className="inline-flex shrink-0 rounded-full p-1 hover:bg-accent transition-colors duration-300">
|
||||||
|
<RiChat1Line
|
||||||
|
className="h-4 w-4 text-muted-foreground"
|
||||||
|
aria-hidden
|
||||||
|
/>
|
||||||
|
<span className="sr-only">Ver anotação</span>
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent
|
||||||
|
side="top"
|
||||||
|
align="start"
|
||||||
|
className="max-w-xs whitespace-pre-line"
|
||||||
|
>
|
||||||
|
{group.note}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
) : null}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="flex min-w-0 items-center gap-1 text-xs">
|
<CardDescription className="flex min-w-0 items-center gap-1 text-xs">
|
||||||
{cardLogoSrc ? (
|
{cardLogoSrc ? (
|
||||||
@@ -235,8 +262,28 @@ export function InstallmentGroupCard({
|
|||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<EstablishmentLogo name={group.name} size={32} />
|
<EstablishmentLogo name={group.name} size={32} />
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
<DialogTitle className="truncate text-base">
|
<DialogTitle className="flex items-center gap-1 text-base">
|
||||||
{group.name}
|
<span className="truncate">{group.name}</span>
|
||||||
|
{hasNote ? (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<span className="inline-flex shrink-0 rounded-full p-1 hover:bg-accent transition-colors duration-300">
|
||||||
|
<RiChat1Line
|
||||||
|
className="h-4 w-4 text-muted-foreground"
|
||||||
|
aria-hidden
|
||||||
|
/>
|
||||||
|
<span className="sr-only">Ver anotação</span>
|
||||||
|
</span>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent
|
||||||
|
side="top"
|
||||||
|
align="start"
|
||||||
|
className="max-w-xs whitespace-pre-line"
|
||||||
|
>
|
||||||
|
{group.note}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
) : null}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground">
|
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground">
|
||||||
{cardLogoSrc ? (
|
{cardLogoSrc ? (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { RiCheckboxCircleFill, RiGroupLine } from "@remixicon/react";
|
import { RiCheckboxCircleFill, RiGroupLine } from "@remixicon/react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
||||||
import {
|
import {
|
||||||
buildInvoiceDetailsHref,
|
buildInvoiceDetailsHref,
|
||||||
@@ -62,18 +63,14 @@ export function InvoiceListItem({ invoice, onPay }: InvoiceListItemProps) {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
const linkNode = (
|
const linkNode = (
|
||||||
<Link
|
<Link prefetch href={detailHref} className={styles.titleLink}>
|
||||||
prefetch
|
|
||||||
href={detailHref}
|
|
||||||
className="inline-flex max-w-full items-center gap-1 text-sm font-medium text-foreground underline-offset-2 hover:text-primary hover:underline"
|
|
||||||
>
|
|
||||||
<span className="truncate">{invoice.cardName}</span>
|
<span className="truncate">{invoice.cardName}</span>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="flex items-center justify-between transition-all duration-300 py-1.5">
|
<li className={styles.row}>
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2 py-1">
|
<div className={styles.main}>
|
||||||
<InvoiceLogo
|
<InvoiceLogo
|
||||||
cardName={invoice.cardName}
|
cardName={invoice.cardName}
|
||||||
logo={invoice.logo}
|
logo={invoice.logo}
|
||||||
@@ -81,7 +78,7 @@ export function InvoiceListItem({ invoice, onPay }: InvoiceListItemProps) {
|
|||||||
containerClassName="size-9.5"
|
containerClassName="size-9.5"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="min-w-0">
|
<div className={styles.textStack}>
|
||||||
<div className="flex max-w-full items-center gap-1">
|
<div className="flex max-w-full items-center gap-1">
|
||||||
{hasBreakdown ? (
|
{hasBreakdown ? (
|
||||||
<HoverCard openDelay={150}>
|
<HoverCard openDelay={150}>
|
||||||
@@ -123,9 +120,14 @@ export function InvoiceListItem({ invoice, onPay }: InvoiceListItemProps) {
|
|||||||
className="font-medium"
|
className="font-medium"
|
||||||
amount={share.amount}
|
amount={share.amount}
|
||||||
/>
|
/>
|
||||||
|
{share.percentageChange !== null ? (
|
||||||
|
<span className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||||
<PercentageChangeIndicator
|
<PercentageChangeIndicator
|
||||||
value={share.percentageChange}
|
value={share.percentageChange}
|
||||||
/>
|
/>
|
||||||
|
<span>vs. mês ant.</span>
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
@@ -150,7 +152,7 @@ export function InvoiceListItem({ invoice, onPay }: InvoiceListItemProps) {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
<div className={styles.meta}>
|
||||||
{!isPaid ? (
|
{!isPaid ? (
|
||||||
dueTooltipLabel ? (
|
dueTooltipLabel ? (
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
@@ -199,13 +201,13 @@ export function InvoiceListItem({ invoice, onPay }: InvoiceListItemProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex shrink-0 flex-col items-end">
|
<div className={styles.trailing}>
|
||||||
<MoneyValues
|
<MoneyValues
|
||||||
className="font-medium"
|
className={styles.trailingValue}
|
||||||
amount={Math.abs(invoice.totalAmount)}
|
amount={Math.abs(invoice.totalAmount)}
|
||||||
/>
|
/>
|
||||||
{isPaid ? (
|
{isPaid ? (
|
||||||
<span className="flex h-7 items-center gap-0.5 text-xs font-medium text-success">
|
<span className={`${styles.trailingMeta} text-success`}>
|
||||||
<RiCheckboxCircleFill className="size-3.5" /> Pago
|
<RiCheckboxCircleFill className="size-3.5" /> Pago
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
@@ -213,7 +215,7 @@ export function InvoiceListItem({ invoice, onPay }: InvoiceListItemProps) {
|
|||||||
type="button"
|
type="button"
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="link"
|
variant="link"
|
||||||
className="-mr-1.5 h-7 px-1.5 py-0"
|
className={styles.actionButton}
|
||||||
onClick={() => onPay(invoice.id)}
|
onClick={() => onPay(invoice.id)}
|
||||||
>
|
>
|
||||||
{isOverdue ? (
|
{isOverdue ? (
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
RiFileList2Line,
|
RiFileList2Line,
|
||||||
RiPencilLine,
|
RiPencilLine,
|
||||||
} from "@remixicon/react";
|
} from "@remixicon/react";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import type { Note } from "@/features/notes/components/types";
|
import type { Note } from "@/features/notes/components/types";
|
||||||
import {
|
import {
|
||||||
buildNoteDisplayTitle,
|
buildNoteDisplayTitle,
|
||||||
@@ -33,18 +34,16 @@ export function NoteListItem({
|
|||||||
const isTask = note.type === "tarefa";
|
const isTask = note.type === "tarefa";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="group flex items-center justify-between gap-2 py-1.5 transition-all duration-300">
|
<li className={`group ${styles.row}`}>
|
||||||
<div className="min-w-0 flex-1">
|
<div className={styles.textStack}>
|
||||||
<p className="truncate text-sm font-medium text-foreground">
|
<p className={styles.title}>{displayTitle}</p>
|
||||||
{displayTitle}
|
<div className={styles.meta}>
|
||||||
</p>
|
|
||||||
<div className="mt-1 flex min-w-0 items-center gap-2">
|
|
||||||
{isTask ? (
|
{isTask ? (
|
||||||
<Badge variant="outline" className="h-5 px-1.5 text-xs">
|
<Badge variant="outline" className="h-5 px-1.5 text-xs">
|
||||||
{getNoteTasksSummary(note)}
|
{getNoteTasksSummary(note)}
|
||||||
</Badge>
|
</Badge>
|
||||||
) : null}
|
) : null}
|
||||||
<p className="truncate text-xs text-muted-foreground">
|
<p className="truncate">
|
||||||
<span className="inline-flex items-center gap-1">
|
<span className="inline-flex items-center gap-1">
|
||||||
<RiCalendarLine className="size-3.5 shrink-0" />
|
<RiCalendarLine className="size-3.5 shrink-0" />
|
||||||
{createdAtLabel}
|
{createdAtLabel}
|
||||||
@@ -53,7 +52,7 @@ export function NoteListItem({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex shrink-0 items-center gap-0.5">
|
<div className="flex min-w-[4.5rem] shrink-0 items-center justify-end gap-0.5">
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import {
|
import {
|
||||||
formatPaymentBreakdownPercentage,
|
formatPaymentBreakdownPercentage,
|
||||||
formatPaymentBreakdownTransactionsLabel,
|
formatPaymentBreakdownTransactionsLabel,
|
||||||
@@ -31,10 +32,8 @@ export function PaymentBreakdownListItem({
|
|||||||
position,
|
position,
|
||||||
}: PaymentBreakdownListItemProps) {
|
}: PaymentBreakdownListItemProps) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2 transition-all duration-300 py-1">
|
<div className={styles.row}>
|
||||||
<span className="w-3 shrink-0 text-left text-xs font-medium text-muted-foreground">
|
<span className={styles.rank}>{position}</span>
|
||||||
{position}
|
|
||||||
</span>
|
|
||||||
<div
|
<div
|
||||||
className="flex size-9.5 shrink-0 items-center justify-center rounded-full"
|
className="flex size-9.5 shrink-0 items-center justify-center rounded-full"
|
||||||
style={{
|
style={{
|
||||||
@@ -45,26 +44,26 @@ export function PaymentBreakdownListItem({
|
|||||||
{item.icon}
|
{item.icon}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="min-w-0 flex-1">
|
<div className={styles.textStack}>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between gap-2">
|
||||||
{item.href ? (
|
{item.href ? (
|
||||||
<Link
|
<Link href={item.href} className={styles.titleLink}>
|
||||||
href={item.href}
|
|
||||||
className="inline-flex items-center gap-1 text-sm font-medium text-foreground underline-offset-2 hover:text-primary hover:underline"
|
|
||||||
>
|
|
||||||
<span className="truncate">{item.title}</span>
|
<span className="truncate">{item.title}</span>
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-sm font-medium text-foreground">{item.title}</p>
|
<p className={styles.title}>{item.title}</p>
|
||||||
)}
|
)}
|
||||||
<MoneyValues className="shrink-0 font-medium" amount={item.amount} />
|
<MoneyValues
|
||||||
|
className={`shrink-0 ${styles.trailingValue}`}
|
||||||
|
amount={item.amount}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
<div className={styles.meta}>
|
||||||
<span>
|
<span>
|
||||||
{formatPaymentBreakdownTransactionsLabel(item.transactions)}
|
{formatPaymentBreakdownTransactionsLabel(item.transactions)}
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span className="ml-auto">
|
||||||
{formatPaymentBreakdownPercentage(item.percentage)} do total
|
{formatPaymentBreakdownPercentage(item.percentage)} do total
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { AttachmentPreview } from "@/features/attachments/components/attachment-preview";
|
import { AttachmentPreview } from "@/features/attachments/components/attachment-preview";
|
||||||
import type { AttachmentForPeriod } from "@/features/attachments/queries";
|
import type { AttachmentForPeriod } from "@/features/attachments/queries";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
@@ -77,7 +78,7 @@ export function AttachmentsWidget({ snapshot }: AttachmentsWidgetProps) {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setSelectedIndex(index)}
|
onClick={() => setSelectedIndex(index)}
|
||||||
className="flex w-full items-center gap-2 py-2 text-left"
|
className={`${styles.row} w-full text-left`}
|
||||||
>
|
>
|
||||||
<div className="shrink-0">
|
<div className="shrink-0">
|
||||||
{isPdf && <RiFilePdf2Line className="size-6 text-red-500" />}
|
{isPdf && <RiFilePdf2Line className="size-6 text-red-500" />}
|
||||||
@@ -86,10 +87,10 @@ export function AttachmentsWidget({ snapshot }: AttachmentsWidgetProps) {
|
|||||||
<RiFileLine className="size-6 text-muted-foreground" />
|
<RiFileLine className="size-6 text-muted-foreground" />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0 flex-1">
|
<div className={styles.textStack}>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<span className="block truncate text-sm font-medium text-foreground hover:underline">
|
<span className={`${styles.title} block hover:underline`}>
|
||||||
{attachment.fileName}
|
{attachment.fileName}
|
||||||
</span>
|
</span>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
@@ -97,18 +98,18 @@ export function AttachmentsWidget({ snapshot }: AttachmentsWidgetProps) {
|
|||||||
{attachment.fileName}
|
{attachment.fileName}
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<span className="block truncate text-xs text-muted-foreground">
|
<span className={`${styles.meta} block truncate`}>
|
||||||
{attachment.transactionName}
|
{attachment.transactionName}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="shrink-0 text-right">
|
<div className={styles.trailing}>
|
||||||
<span className="block text-xs text-muted-foreground">
|
<span className="block text-xs leading-4 text-muted-foreground">
|
||||||
{formatDateOnly(attachment.purchaseDate, {
|
{formatDateOnly(attachment.purchaseDate, {
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
month: "2-digit",
|
month: "2-digit",
|
||||||
}) ?? "—"}
|
}) ?? "—"}
|
||||||
</span>
|
</span>
|
||||||
<span className="block text-xs text-muted-foreground/60">
|
<span className="block text-xs leading-4 text-muted-foreground/60">
|
||||||
{formatBytes(attachment.fileSize)}
|
{formatBytes(attachment.fileSize)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
RiLineChartLine,
|
RiLineChartLine,
|
||||||
} from "@remixicon/react";
|
} from "@remixicon/react";
|
||||||
import type { DashboardCategoryBreakdownItem } from "@/features/dashboard/categories/category-breakdown-helpers";
|
import type { DashboardCategoryBreakdownItem } from "@/features/dashboard/categories/category-breakdown-helpers";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
||||||
import { CategoryIconBadge } from "@/shared/components/entity-avatar";
|
import { CategoryIconBadge } from "@/shared/components/entity-avatar";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
@@ -45,17 +46,15 @@ export function CategoryTrendsWidget({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<li key={category.categoryId}>
|
<li key={category.categoryId}>
|
||||||
<div className="-mx-2 flex items-center gap-3 rounded-md p-2">
|
<div className={styles.row}>
|
||||||
<CategoryIconBadge
|
<CategoryIconBadge
|
||||||
icon={category.categoryIcon}
|
icon={category.categoryIcon}
|
||||||
name={category.categoryName}
|
name={category.categoryName}
|
||||||
size="md"
|
size="md"
|
||||||
/>
|
/>
|
||||||
<div className="min-w-0 flex-1">
|
<div className={styles.textStack}>
|
||||||
<p className="truncate text-sm font-medium text-foreground">
|
<p className={styles.title}>{category.categoryName}</p>
|
||||||
{category.categoryName}
|
<p className={styles.meta}>
|
||||||
</p>
|
|
||||||
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
||||||
<span
|
<span
|
||||||
className="inline-flex items-center gap-1"
|
className="inline-flex items-center gap-1"
|
||||||
title="Mês anterior"
|
title="Mês anterior"
|
||||||
@@ -81,6 +80,9 @@ export function CategoryTrendsWidget({
|
|||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<span
|
||||||
|
className={`${styles.trailingMeta} min-w-[5.75rem] justify-end text-muted-foreground`}
|
||||||
|
>
|
||||||
<PercentageChangeIndicator
|
<PercentageChangeIndicator
|
||||||
value={change}
|
value={change}
|
||||||
label={formatPercentage(change, {
|
label={formatPercentage(change, {
|
||||||
@@ -89,9 +91,11 @@ export function CategoryTrendsWidget({
|
|||||||
maximumFractionDigits: 0,
|
maximumFractionDigits: 0,
|
||||||
})}
|
})}
|
||||||
positiveTrend="down"
|
positiveTrend="down"
|
||||||
className="shrink-0 text-sm font-semibold"
|
className="text-sm font-semibold"
|
||||||
iconClassName="size-3.5"
|
iconClassName="size-3.5"
|
||||||
/>
|
/>
|
||||||
|
<span>vs. mês ant.</span>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import Link from "next/link";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import type { DashboardInboxSnapshot } from "@/features/dashboard/lib/inbox-snapshot-queries";
|
import type { DashboardInboxSnapshot } from "@/features/dashboard/lib/inbox-snapshot-queries";
|
||||||
import type { DashboardWidgetQuickActionOptions } from "@/features/dashboard/widget-registry/widget-config";
|
import type { DashboardWidgetQuickActionOptions } from "@/features/dashboard/widget-registry/widget-config";
|
||||||
import {
|
import {
|
||||||
@@ -201,8 +202,8 @@ export function InboxWidget({
|
|||||||
const displayLogo = logoSrc ?? DEFAULT_INBOX_APP_LOGO;
|
const displayLogo = logoSrc ?? DEFAULT_INBOX_APP_LOGO;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={item.id} className="flex items-center justify-between py-2">
|
<div key={item.id} className={styles.row}>
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2">
|
<div className={styles.main}>
|
||||||
<Image
|
<Image
|
||||||
src={displayLogo}
|
src={displayLogo}
|
||||||
alt={item.sourceAppName ?? ""}
|
alt={item.sourceAppName ?? ""}
|
||||||
@@ -212,24 +213,22 @@ export function InboxWidget({
|
|||||||
unoptimized
|
unoptimized
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="min-w-0">
|
<div className={styles.textStack}>
|
||||||
<p className="truncate text-sm font-medium text-foreground">
|
<p className={styles.title}>{displayName}</p>
|
||||||
{displayName}
|
<div className={styles.meta}>
|
||||||
</p>
|
|
||||||
<div className="flex min-w-0 items-center gap-2 text-xs text-muted-foreground">
|
|
||||||
{item.sourceAppName && (
|
{item.sourceAppName && (
|
||||||
<span className="truncate">{item.sourceAppName}</span>
|
<span className="truncate">{item.sourceAppName}</span>
|
||||||
)}
|
)}
|
||||||
<span className="text-muted-foreground/60">
|
<span className="text-muted-foreground/60">
|
||||||
{relativeTime(item.notificationTimestamp)}
|
{relativeTime(item.createdAt)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="ml-2 flex shrink-0 items-center gap-1">
|
<div className="ml-2 flex min-w-[7.5rem] shrink-0 items-center justify-end gap-1">
|
||||||
{amount !== null && (
|
{amount !== null && (
|
||||||
<MoneyValues className="font-medium" amount={amount} />
|
<MoneyValues className={styles.trailingValue} amount={amount} />
|
||||||
)}
|
)}
|
||||||
{amount === null && (
|
{amount === null && (
|
||||||
<span className="max-w-20 text-right text-xs leading-tight text-muted-foreground">
|
<span className="max-w-20 text-right text-xs leading-tight text-muted-foreground">
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import Image from "next/image";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useTransition } from "react";
|
import { useTransition } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import type { DashboardAccount } from "@/features/dashboard/lib/accounts-queries";
|
import type { DashboardAccount } from "@/features/dashboard/lib/accounts-queries";
|
||||||
import { updateMyAccountsWidgetPreference } from "@/features/dashboard/widget-registry/widget-actions";
|
import { updateMyAccountsWidgetPreference } from "@/features/dashboard/widget-registry/widget-actions";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
@@ -139,12 +140,9 @@ export function MyAccountsWidget({
|
|||||||
const logoSrc = resolveLogoSrc(account.logo);
|
const logoSrc = resolveLogoSrc(account.logo);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li
|
<li key={account.id} className={styles.row}>
|
||||||
key={account.id}
|
<div className={styles.main}>
|
||||||
className="flex items-center justify-between py-1.5 transition-all duration-300"
|
<div className="relative flex size-9.5 shrink-0 items-center justify-center overflow-hidden rounded-full">
|
||||||
>
|
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2 py-1">
|
|
||||||
<div className="relative flex size-9.5 shrink-0 items-center justify-center overflow-hidden rounded-full bg-primary/10">
|
|
||||||
{logoSrc ? (
|
{logoSrc ? (
|
||||||
<Image
|
<Image
|
||||||
src={logoSrc}
|
src={logoSrc}
|
||||||
@@ -161,18 +159,18 @@ export function MyAccountsWidget({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="min-w-0">
|
<div className={styles.textStack}>
|
||||||
<Link
|
<Link
|
||||||
prefetch
|
prefetch
|
||||||
href={`/accounts/${
|
href={`/accounts/${
|
||||||
account.id
|
account.id
|
||||||
}/statement?periodo=${formatPeriodForUrl(period)}`}
|
}/statement?periodo=${formatPeriodForUrl(period)}`}
|
||||||
className="inline-flex max-w-full items-center gap-1 text-sm font-medium text-foreground underline-offset-2 hover:text-primary hover:underline"
|
className={styles.titleLink}
|
||||||
>
|
>
|
||||||
<span className="truncate">{account.name}</span>
|
<span className="truncate">{account.name}</span>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
<div className={styles.meta}>
|
||||||
<span className="truncate">{account.accountType}</span>
|
<span className="truncate">{account.accountType}</span>
|
||||||
{account.excludeFromBalance ? (
|
{account.excludeFromBalance ? (
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
@@ -195,10 +193,10 @@ export function MyAccountsWidget({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col items-end gap-0.5 text-right">
|
<div className={styles.trailing}>
|
||||||
<MoneyValues
|
<MoneyValues
|
||||||
className={cn(
|
className={cn(
|
||||||
"font-medium",
|
styles.trailingValue,
|
||||||
account.balance < 0 && "text-destructive",
|
account.balance < 0 && "text-destructive",
|
||||||
)}
|
)}
|
||||||
amount={account.balance}
|
amount={account.balance}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { RiGroupLine, RiVerifiedBadgeFill } from "@remixicon/react";
|
import { RiGroupLine, RiVerifiedBadgeFill } from "@remixicon/react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator";
|
||||||
import type { DashboardPagador } from "@/features/dashboard/lib/payers-queries";
|
import type { DashboardPagador } from "@/features/dashboard/lib/payers-queries";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
@@ -44,14 +45,9 @@ export function PayersWidget({ payers }: PayersWidgetProps) {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div key={payer.id} className={styles.row}>
|
||||||
key={payer.id}
|
<span className={styles.rank}>{index + 1}</span>
|
||||||
className="flex items-center justify-between gap-2 transition-all duration-300 py-1.5"
|
<div className={styles.main}>
|
||||||
>
|
|
||||||
<span className="w-3 shrink-0 text-left text-xs font-medium text-muted-foreground">
|
|
||||||
{index + 1}
|
|
||||||
</span>
|
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2 py-1">
|
|
||||||
<Avatar className="size-9.5 shrink-0">
|
<Avatar className="size-9.5 shrink-0">
|
||||||
<AvatarImage
|
<AvatarImage
|
||||||
src={getAvatarSrc(payer.avatarUrl)}
|
src={getAvatarSrc(payer.avatarUrl)}
|
||||||
@@ -60,11 +56,11 @@ export function PayersWidget({ payers }: PayersWidgetProps) {
|
|||||||
<AvatarFallback>{initials}</AvatarFallback>
|
<AvatarFallback>{initials}</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
|
|
||||||
<div className="min-w-0">
|
<div className={styles.textStack}>
|
||||||
<Link
|
<Link
|
||||||
prefetch
|
prefetch
|
||||||
href={`/payers/${payer.id}`}
|
href={`/payers/${payer.id}`}
|
||||||
className="inline-flex max-w-full items-center gap-1 text-sm text-foreground underline-offset-2 hover:text-primary hover:underline"
|
className={styles.titleLink}
|
||||||
>
|
>
|
||||||
<span className="truncate font-medium">{payer.name}</span>
|
<span className="truncate font-medium">{payer.name}</span>
|
||||||
{payer.isAdmin && (
|
{payer.isAdmin && (
|
||||||
@@ -84,18 +80,18 @@ export function PayersWidget({ payers }: PayersWidgetProps) {
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
</Link>
|
</Link>
|
||||||
<p className="truncate text-xs text-muted-foreground">
|
<p className={styles.meta}>Despesas no período</p>
|
||||||
Despesas no período
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex shrink-0 flex-col items-end">
|
<div className={styles.trailing}>
|
||||||
<MoneyValues
|
<MoneyValues
|
||||||
className="font-medium"
|
className={styles.trailingValue}
|
||||||
amount={payer.totalExpenses}
|
amount={payer.totalExpenses}
|
||||||
/>
|
/>
|
||||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
<div
|
||||||
|
className={`${styles.trailingMeta} text-muted-foreground`}
|
||||||
|
>
|
||||||
<PercentageChangeIndicator value={percentageChange} />
|
<PercentageChangeIndicator value={percentageChange} />
|
||||||
{percentageChange !== null ? (
|
{percentageChange !== null ? (
|
||||||
<span>vs. mês ant.</span>
|
<span>vs. mês ant.</span>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { RiFileList2Line, RiStore3Line } from "@remixicon/react";
|
import { RiFileList2Line, RiStore3Line } from "@remixicon/react";
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import type { PurchasesByCategoryData } from "@/features/dashboard/categories/purchases-by-category-queries";
|
import type { PurchasesByCategoryData } from "@/features/dashboard/categories/purchases-by-category-queries";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import { EstablishmentLogo } from "@/shared/components/entity-avatar";
|
import { EstablishmentLogo } from "@/shared/components/entity-avatar";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
import {
|
import {
|
||||||
@@ -162,26 +163,21 @@ export function PurchasesByCategoryWidget({
|
|||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{currentTransactions.map((transaction) => {
|
{currentTransactions.map((transaction) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div key={transaction.id} className={styles.row}>
|
||||||
key={transaction.id}
|
<div className={styles.main}>
|
||||||
className="flex items-center justify-between gap-2 transition-all duration-300 py-1.5"
|
|
||||||
>
|
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2">
|
|
||||||
<EstablishmentLogo name={transaction.name} size={37} />
|
<EstablishmentLogo name={transaction.name} size={37} />
|
||||||
|
|
||||||
<div className="min-w-0">
|
<div className={styles.textStack}>
|
||||||
<p className="truncate text-sm font-medium text-foreground">
|
<p className={styles.title}>{transaction.name}</p>
|
||||||
{transaction.name}
|
<p className={styles.meta}>
|
||||||
</p>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{formatTransactionDate(transaction.purchaseDate)}
|
{formatTransactionDate(transaction.purchaseDate)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="shrink-0 text-foreground">
|
<div className={styles.trailing}>
|
||||||
<MoneyValues
|
<MoneyValues
|
||||||
className="font-medium"
|
className={styles.trailingValue}
|
||||||
amount={transaction.amount}
|
amount={transaction.amount}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { RiRefreshLine } from "@remixicon/react";
|
import { RiRefreshLine } from "@remixicon/react";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import type { RecurringExpensesData } from "@/features/dashboard/expenses/recurring-expenses-queries";
|
import type { RecurringExpensesData } from "@/features/dashboard/expenses/recurring-expenses-queries";
|
||||||
import { EstablishmentLogo } from "@/shared/components/entity-avatar";
|
import { EstablishmentLogo } from "@/shared/components/entity-avatar";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
@@ -36,26 +37,14 @@ export function RecurringExpensesWidget({
|
|||||||
.sort((a, b) => b.amount - a.amount)
|
.sort((a, b) => b.amount - a.amount)
|
||||||
.map((expense) => {
|
.map((expense) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div key={expense.id} className={styles.row}>
|
||||||
key={expense.id}
|
<div className={styles.main}>
|
||||||
className="flex items-center gap-2 transition-all duration-300 py-1.5"
|
|
||||||
>
|
|
||||||
<EstablishmentLogo name={expense.name} size={37} />
|
<EstablishmentLogo name={expense.name} size={37} />
|
||||||
|
|
||||||
<div className="min-w-0 flex-1">
|
<div className={styles.textStack}>
|
||||||
<div className="flex items-center justify-between">
|
<p className={styles.title}>{expense.name}</p>
|
||||||
<p className="truncate text-foreground text-sm font-medium">
|
<div className={styles.meta}>
|
||||||
{expense.name}
|
<span className="inline-flex min-w-0 items-center gap-1 [&_svg]:size-3.5">
|
||||||
</p>
|
|
||||||
|
|
||||||
<MoneyValues
|
|
||||||
className="font-medium"
|
|
||||||
amount={expense.amount}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
|
||||||
<span className="inline-flex items-center gap-1 [&_svg]:size-3.5">
|
|
||||||
{getPaymentMethodIcon(expense.paymentMethod)}
|
{getPaymentMethodIcon(expense.paymentMethod)}
|
||||||
{expense.paymentMethod}
|
{expense.paymentMethod}
|
||||||
</span>
|
</span>
|
||||||
@@ -63,6 +52,14 @@ export function RecurringExpensesWidget({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.trailing}>
|
||||||
|
<MoneyValues
|
||||||
|
className={styles.trailingValue}
|
||||||
|
amount={expense.amount}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { RiStore2Line } from "@remixicon/react";
|
import { RiStore2Line } from "@remixicon/react";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import type { TopEstablishmentsData } from "@/features/dashboard/lib/top-establishments-queries";
|
import type { TopEstablishmentsData } from "@/features/dashboard/lib/top-establishments-queries";
|
||||||
import { EstablishmentLogo } from "@/shared/components/entity-avatar";
|
import { EstablishmentLogo } from "@/shared/components/entity-avatar";
|
||||||
import MoneyValues from "@/shared/components/money-values";
|
import MoneyValues from "@/shared/components/money-values";
|
||||||
@@ -30,30 +31,23 @@ export function TopEstablishmentsWidget({
|
|||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{data.establishments.map((establishment, index) => {
|
{data.establishments.map((establishment, index) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div key={establishment.id} className={styles.row}>
|
||||||
key={establishment.id}
|
<span className={styles.rank}>{index + 1}</span>
|
||||||
className="flex items-center justify-between gap-2 transition-all duration-300 py-1.5"
|
<div className={styles.main}>
|
||||||
>
|
|
||||||
<span className="w-3 shrink-0 text-left text-xs font-medium text-muted-foreground">
|
|
||||||
{index + 1}
|
|
||||||
</span>
|
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2">
|
|
||||||
<EstablishmentLogo name={establishment.name} size={37} />
|
<EstablishmentLogo name={establishment.name} size={37} />
|
||||||
|
|
||||||
<div className="min-w-0">
|
<div className={styles.textStack}>
|
||||||
<p className="truncate text-sm font-medium text-foreground">
|
<p className={styles.title}>{establishment.name}</p>
|
||||||
{establishment.name}
|
<p className={styles.meta}>
|
||||||
</p>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{formatOccurrencesLabel(establishment.occurrences)} ·
|
{formatOccurrencesLabel(establishment.occurrences)} ·
|
||||||
total acumulado
|
total acumulado
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="shrink-0 text-foreground">
|
<div className={styles.trailing}>
|
||||||
<MoneyValues
|
<MoneyValues
|
||||||
className="font-medium"
|
className={styles.trailingValue}
|
||||||
amount={establishment.amount}
|
amount={establishment.amount}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { RiArrowUpDoubleLine } from "@remixicon/react";
|
import { RiArrowUpDoubleLine } from "@remixicon/react";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
import { dashboardWidgetListStyles as styles } from "@/features/dashboard/components/dashboard-widget-list-styles";
|
||||||
import type {
|
import type {
|
||||||
TopExpense,
|
TopExpense,
|
||||||
TopExpensesData,
|
TopExpensesData,
|
||||||
@@ -49,29 +50,22 @@ export function TopExpensesWidget({ data }: TopExpensesWidgetProps) {
|
|||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{expenses.map((expense, index) => {
|
{expenses.map((expense, index) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div key={expense.id} className={styles.row}>
|
||||||
key={expense.id}
|
<span className={styles.rank}>{index + 1}</span>
|
||||||
className="flex items-center justify-between gap-2 transition-all duration-300 py-1.5"
|
<div className={styles.main}>
|
||||||
>
|
|
||||||
<span className="w-3 shrink-0 text-left text-xs font-medium text-muted-foreground">
|
|
||||||
{index + 1}
|
|
||||||
</span>
|
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-2">
|
|
||||||
<EstablishmentLogo name={expense.name} size={37} />
|
<EstablishmentLogo name={expense.name} size={37} />
|
||||||
|
|
||||||
<div className="min-w-0">
|
<div className={styles.textStack}>
|
||||||
<p className="truncate text-sm font-medium text-foreground">
|
<p className={styles.title}>{expense.name}</p>
|
||||||
{expense.name}
|
<p className={styles.meta}>
|
||||||
</p>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{formatTransactionDate(expense.purchaseDate)}
|
{formatTransactionDate(expense.purchaseDate)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="shrink-0 text-foreground">
|
<div className={styles.trailing}>
|
||||||
<MoneyValues
|
<MoneyValues
|
||||||
className="font-medium"
|
className={styles.trailingValue}
|
||||||
amount={expense.amount}
|
amount={expense.amount}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ type InstallmentDetail = {
|
|||||||
export type InstallmentGroup = {
|
export type InstallmentGroup = {
|
||||||
seriesId: string;
|
seriesId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
note: string | null;
|
||||||
paymentMethod: string;
|
paymentMethod: string;
|
||||||
cardId: string | null;
|
cardId: string | null;
|
||||||
cartaoName: string | null;
|
cartaoName: string | null;
|
||||||
@@ -80,6 +81,7 @@ export async function fetchInstallmentAnalysis(
|
|||||||
id: transactions.id,
|
id: transactions.id,
|
||||||
seriesId: transactions.seriesId,
|
seriesId: transactions.seriesId,
|
||||||
name: transactions.name,
|
name: transactions.name,
|
||||||
|
note: transactions.note,
|
||||||
amount: transactions.amount,
|
amount: transactions.amount,
|
||||||
paymentMethod: transactions.paymentMethod,
|
paymentMethod: transactions.paymentMethod,
|
||||||
currentInstallment: transactions.currentInstallment,
|
currentInstallment: transactions.currentInstallment,
|
||||||
@@ -150,6 +152,7 @@ export async function fetchInstallmentAnalysis(
|
|||||||
seriesMap.set(row.seriesId, {
|
seriesMap.set(row.seriesId, {
|
||||||
seriesId: row.seriesId,
|
seriesId: row.seriesId,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
|
note: row.note,
|
||||||
paymentMethod: row.paymentMethod,
|
paymentMethod: row.paymentMethod,
|
||||||
cardId: row.cardId,
|
cardId: row.cardId,
|
||||||
cartaoName: row.cartaoName,
|
cartaoName: row.cartaoName,
|
||||||
|
|||||||
@@ -206,32 +206,32 @@ export function InvoiceSummaryCard({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="gap-0 py-0">
|
<Card className="gap-0 py-0 space-y-2">
|
||||||
<CardContent className="px-4 py-4 sm:px-5 sm:py-5">
|
<CardContent className="px-4 py-4 sm:px-5 sm:py-5">
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{/* Linha 1 — identidade */}
|
{/* Linha 1 — identidade */}
|
||||||
<div className="flex items-center justify-between gap-3">
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
||||||
<div className="flex min-w-0 items-center gap-3">
|
<div className="flex min-w-0 items-start gap-3">
|
||||||
{logoPath ? (
|
{logoPath ? (
|
||||||
<div className="flex size-12 shrink-0 items-center justify-center overflow-hidden rounded-full">
|
<div className="flex size-12 shrink-0 items-center justify-center overflow-hidden rounded-full">
|
||||||
<Image
|
<Image
|
||||||
src={logoPath}
|
src={logoPath}
|
||||||
alt={`Logo ${cardName}`}
|
alt={`Logo ${cardName}`}
|
||||||
width={42}
|
width={48}
|
||||||
height={42}
|
height={48}
|
||||||
className="h-full w-full object-contain"
|
className="h-full w-full object-contain"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : cardBrand ? (
|
) : cardBrand ? (
|
||||||
<span className="flex size-10 shrink-0 items-center justify-center rounded-full border bg-background text-xs font-medium text-muted-foreground">
|
<span className="flex size-12 shrink-0 items-center justify-center rounded-full border bg-card text-sm font-semibold text-primary">
|
||||||
{cardBrand.slice(0, 2).toUpperCase()}
|
{cardBrand.slice(0, 2).toUpperCase()}
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="min-w-0">
|
<div className="min-w-0 space-y-1">
|
||||||
<h2 className="truncate text-sm font-semibold text-foreground">
|
<h2 className="truncate text-xl font-semibold text-foreground sm:text-2xl">
|
||||||
{cardName}
|
{cardName}
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-sm leading-relaxed text-muted-foreground">
|
||||||
Fatura de {periodLabel}
|
Fatura de {periodLabel}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export type SectionType = "Adicionado" | "Alterado" | "Corrigido" | "Removido";
|
export type SectionType = "Adicionado" | "Alterado" | "Corrigido" | "Removido";
|
||||||
|
|
||||||
export const SECTION_TYPES: readonly SectionType[] = [
|
const SECTION_TYPES: readonly SectionType[] = [
|
||||||
"Adicionado",
|
"Adicionado",
|
||||||
"Alterado",
|
"Alterado",
|
||||||
"Corrigido",
|
"Corrigido",
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ export {
|
|||||||
} from "./actions/bulk-actions";
|
} from "./actions/bulk-actions";
|
||||||
export { exportTransactionsDataAction } from "./actions/export-actions";
|
export { exportTransactionsDataAction } from "./actions/export-actions";
|
||||||
export {
|
export {
|
||||||
|
convertTransactionToInstallmentAction,
|
||||||
|
convertTransactionToRecurringAction,
|
||||||
createTransactionAction,
|
createTransactionAction,
|
||||||
deleteTransactionAction,
|
deleteTransactionAction,
|
||||||
toggleTransactionSettlementAction,
|
toggleTransactionSettlementAction,
|
||||||
|
|||||||
@@ -31,19 +31,6 @@ import { addMonthsToPeriod, MONTH_NAMES } from "@/shared/utils/period";
|
|||||||
// Authorization Validation Functions
|
// Authorization Validation Functions
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
export async function validatePayerOwnership(
|
|
||||||
userId: string,
|
|
||||||
payerId: string | null | undefined,
|
|
||||||
): Promise<boolean> {
|
|
||||||
if (!payerId) return true;
|
|
||||||
|
|
||||||
const pagador = await db.query.payers.findFirst({
|
|
||||||
where: and(eq(payers.id, payerId), eq(payers.userId, userId)),
|
|
||||||
});
|
|
||||||
|
|
||||||
return !!pagador;
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizeIds = (ids: Array<string | null | undefined>) => [
|
const normalizeIds = (ids: Array<string | null | undefined>) => [
|
||||||
...new Set(ids.filter((id): id is string => Boolean(id))),
|
...new Set(ids.filter((id): id is string => Boolean(id))),
|
||||||
];
|
];
|
||||||
@@ -526,11 +513,33 @@ export const toggleSettlementSchema = z.object({
|
|||||||
.optional(),
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const convertToInstallmentSchema = z.object({
|
||||||
|
id: uuidSchema("Lançamento"),
|
||||||
|
installmentCount: z.coerce
|
||||||
|
.number({ message: "Informe em quantas parcelas dividir." })
|
||||||
|
.int()
|
||||||
|
.min(2, "O parcelamento deve ter ao menos duas parcelas.")
|
||||||
|
.max(60, "Selecione até 60 parcelas."),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const convertToRecurringSchema = z.object({
|
||||||
|
id: uuidSchema("Lançamento"),
|
||||||
|
recurrenceCount: z.coerce
|
||||||
|
.number({ message: "Informe por quantos meses repetir." })
|
||||||
|
.int()
|
||||||
|
.min(2, "A recorrência deve ter ao menos dois meses.")
|
||||||
|
.max(60, "Selecione até 60 meses."),
|
||||||
|
});
|
||||||
|
|
||||||
type BaseInput = z.infer<typeof baseFields>;
|
type BaseInput = z.infer<typeof baseFields>;
|
||||||
export type CreateInput = z.infer<typeof createSchema>;
|
export type CreateInput = z.infer<typeof createSchema>;
|
||||||
export type UpdateInput = z.infer<typeof updateSchema>;
|
export type UpdateInput = z.infer<typeof updateSchema>;
|
||||||
export type DeleteInput = z.infer<typeof deleteSchema>;
|
export type DeleteInput = z.infer<typeof deleteSchema>;
|
||||||
export type ToggleSettlementInput = z.infer<typeof toggleSettlementSchema>;
|
export type ToggleSettlementInput = z.infer<typeof toggleSettlementSchema>;
|
||||||
|
export type ConvertToInstallmentInput = z.infer<
|
||||||
|
typeof convertToInstallmentSchema
|
||||||
|
>;
|
||||||
|
export type ConvertToRecurringInput = z.infer<typeof convertToRecurringSchema>;
|
||||||
|
|
||||||
export const revalidate = (userId: string) =>
|
export const revalidate = (userId: string) =>
|
||||||
revalidateForEntity("transactions", userId);
|
revalidateForEntity("transactions", userId);
|
||||||
@@ -592,7 +601,7 @@ type SplitShareInput = {
|
|||||||
amount: number;
|
amount: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const resolveSplitShares = (data: {
|
const resolveSplitShares = (data: {
|
||||||
payerId?: string | null;
|
payerId?: string | null;
|
||||||
secondaryPayerId?: string | null;
|
secondaryPayerId?: string | null;
|
||||||
splitShares?: SplitShareInput[];
|
splitShares?: SplitShareInput[];
|
||||||
|
|||||||
@@ -23,12 +23,17 @@ import {
|
|||||||
parseLocalDateString,
|
parseLocalDateString,
|
||||||
} from "@/shared/utils/date";
|
} from "@/shared/utils/date";
|
||||||
import { copyAttachmentsForImport } from "../lib/attachment-copy";
|
import { copyAttachmentsForImport } from "../lib/attachment-copy";
|
||||||
|
import { detectInstallmentFromName } from "../lib/installment-detection";
|
||||||
import { cleanupAttachmentsAfterTransactionDelete } from "./attachments";
|
import { cleanupAttachmentsAfterTransactionDelete } from "./attachments";
|
||||||
import {
|
import {
|
||||||
buildShares,
|
buildShares,
|
||||||
buildTransactionRecords,
|
buildTransactionRecords,
|
||||||
|
type ConvertToInstallmentInput,
|
||||||
|
type ConvertToRecurringInput,
|
||||||
type CreateInput,
|
type CreateInput,
|
||||||
centsToDecimalString,
|
centsToDecimalString,
|
||||||
|
convertToInstallmentSchema,
|
||||||
|
convertToRecurringSchema,
|
||||||
createSchema,
|
createSchema,
|
||||||
type DeleteInput,
|
type DeleteInput,
|
||||||
deleteSchema,
|
deleteSchema,
|
||||||
@@ -471,6 +476,357 @@ export async function deleteTransactionAction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function convertTransactionToInstallmentAction(
|
||||||
|
input: ConvertToInstallmentInput,
|
||||||
|
): Promise<ActionResult<{ createdCount: number }>> {
|
||||||
|
try {
|
||||||
|
const user = await getUser();
|
||||||
|
const data = convertToInstallmentSchema.parse(input);
|
||||||
|
|
||||||
|
const existing = await db.query.transactions.findFirst({
|
||||||
|
where: and(
|
||||||
|
eq(transactions.id, data.id),
|
||||||
|
eq(transactions.userId, user.id),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return { success: false, error: "Lançamento não encontrado." };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.note?.startsWith(ACCOUNT_AUTO_INVOICE_NOTE_PREFIX)) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: "Pagamentos automáticos de fatura não podem ser convertidos.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isInitialBalanceTransaction(existing)) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: "Lançamentos de saldo inicial não podem ser convertidos.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
existing.paymentMethod !== "Cartão de crédito" ||
|
||||||
|
!existing.cardId ||
|
||||||
|
existing.condition !== "À vista"
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error:
|
||||||
|
"Apenas lançamentos à vista de cartão de crédito podem ser convertidos.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.splitGroupId || existing.isDivided) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error:
|
||||||
|
"Lançamentos divididos ainda não podem ser convertidos em parcelamento.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const detected = detectInstallmentFromName(existing.name);
|
||||||
|
const transactionName =
|
||||||
|
detected?.installmentCount === data.installmentCount
|
||||||
|
? detected.name
|
||||||
|
: existing.name;
|
||||||
|
const amountSign: 1 | -1 = existing.transactionType === "Despesa" ? -1 : 1;
|
||||||
|
const totalCents = Math.round(Math.abs(Number(existing.amount)) * 100);
|
||||||
|
const seriesId = randomUUID();
|
||||||
|
const records = buildTransactionRecords({
|
||||||
|
data: {
|
||||||
|
purchaseDate: existing.purchaseDate.toISOString().slice(0, 10),
|
||||||
|
period: existing.period,
|
||||||
|
name: transactionName,
|
||||||
|
transactionType: existing.transactionType as "Receita" | "Despesa",
|
||||||
|
amount: totalCents / 100,
|
||||||
|
condition: "Parcelado",
|
||||||
|
paymentMethod: "Cartão de crédito",
|
||||||
|
payerId: existing.payerId,
|
||||||
|
isSplit: false,
|
||||||
|
accountId: null,
|
||||||
|
cardId: existing.cardId,
|
||||||
|
categoryId: existing.categoryId,
|
||||||
|
note: existing.note,
|
||||||
|
installmentCount: data.installmentCount,
|
||||||
|
startInstallment: 1,
|
||||||
|
dueDate: existing.dueDate?.toISOString().slice(0, 10),
|
||||||
|
isSettled: null,
|
||||||
|
},
|
||||||
|
userId: user.id,
|
||||||
|
period: existing.period,
|
||||||
|
purchaseDate: existing.purchaseDate,
|
||||||
|
dueDate: existing.dueDate,
|
||||||
|
boletoPaymentDate: null,
|
||||||
|
shares: [{ payerId: existing.payerId, amountCents: totalCents }],
|
||||||
|
amountSign,
|
||||||
|
shouldNullifySettled: true,
|
||||||
|
seriesId,
|
||||||
|
}).map((record) => ({
|
||||||
|
...record,
|
||||||
|
importBatchId: existing.importBatchId,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const currentRow = records[0];
|
||||||
|
const rowsToInsert = records.slice(1);
|
||||||
|
if (!currentRow) {
|
||||||
|
throw new Error("Não foi possível montar o parcelamento.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const periodsToUpdate = records
|
||||||
|
.map((row) => row.period)
|
||||||
|
.filter((period): period is string => Boolean(period));
|
||||||
|
const paidPeriods = await getPaidInvoicePeriods(
|
||||||
|
user.id,
|
||||||
|
existing.cardId,
|
||||||
|
periodsToUpdate,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (paidPeriods.length > 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: `As faturas dos meses ${formatPaidInvoicePeriods(
|
||||||
|
paidPeriods,
|
||||||
|
)} já estão pagas. Desfaça o pagamento antes de converter este lançamento.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.transactionType === "Despesa") {
|
||||||
|
const limitCheck = await validateCardLimit({
|
||||||
|
userId: user.id,
|
||||||
|
cardId: existing.cardId,
|
||||||
|
addAmount: records.reduce(
|
||||||
|
(acc, row) => acc + Math.abs(Number(row.amount)),
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
excludeTransactionIds: [existing.id],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!limitCheck.ok) {
|
||||||
|
return { success: false, error: limitCheck.error };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.transaction(async (tx: typeof db) => {
|
||||||
|
await tx
|
||||||
|
.update(transactions)
|
||||||
|
.set({
|
||||||
|
condition: currentRow.condition,
|
||||||
|
name: currentRow.name,
|
||||||
|
amount: currentRow.amount,
|
||||||
|
installmentCount: currentRow.installmentCount,
|
||||||
|
currentInstallment: currentRow.currentInstallment,
|
||||||
|
recurrenceCount: null,
|
||||||
|
period: currentRow.period,
|
||||||
|
dueDate: currentRow.dueDate,
|
||||||
|
isSettled: null,
|
||||||
|
seriesId,
|
||||||
|
})
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(transactions.id, existing.id),
|
||||||
|
eq(transactions.userId, user.id),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rowsToInsert.length > 0) {
|
||||||
|
await tx.insert(transactions).values(rowsToInsert);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
revalidate(user.id);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: `Lançamento convertido em ${data.installmentCount} parcelas.`,
|
||||||
|
data: { createdCount: rowsToInsert.length },
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return handleActionError(error) as ActionResult<{ createdCount: number }>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function convertTransactionToRecurringAction(
|
||||||
|
input: ConvertToRecurringInput,
|
||||||
|
): Promise<ActionResult<{ createdCount: number }>> {
|
||||||
|
try {
|
||||||
|
const user = await getUser();
|
||||||
|
const data = convertToRecurringSchema.parse(input);
|
||||||
|
|
||||||
|
const existing = await db.query.transactions.findFirst({
|
||||||
|
where: and(
|
||||||
|
eq(transactions.id, data.id),
|
||||||
|
eq(transactions.userId, user.id),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return { success: false, error: "Lançamento não encontrado." };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.note?.startsWith(ACCOUNT_AUTO_INVOICE_NOTE_PREFIX)) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: "Pagamentos automáticos de fatura não podem ser convertidos.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isInitialBalanceTransaction(existing)) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: "Lançamentos de saldo inicial não podem ser convertidos.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.condition !== "À vista") {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error:
|
||||||
|
"Apenas lançamentos à vista podem ser convertidos em recorrência.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.splitGroupId || existing.isDivided) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error:
|
||||||
|
"Lançamentos divididos ainda não podem ser convertidos em recorrência.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const amountSign: 1 | -1 = existing.transactionType === "Despesa" ? -1 : 1;
|
||||||
|
const totalCents = Math.round(Math.abs(Number(existing.amount)) * 100);
|
||||||
|
const seriesId = randomUUID();
|
||||||
|
const isCreditCard = existing.paymentMethod === "Cartão de crédito";
|
||||||
|
const records = buildTransactionRecords({
|
||||||
|
data: {
|
||||||
|
purchaseDate: existing.purchaseDate.toISOString().slice(0, 10),
|
||||||
|
period: existing.period,
|
||||||
|
name: existing.name,
|
||||||
|
transactionType: existing.transactionType as "Receita" | "Despesa",
|
||||||
|
amount: totalCents / 100,
|
||||||
|
condition: "Recorrente",
|
||||||
|
paymentMethod: existing.paymentMethod as
|
||||||
|
| "Pix"
|
||||||
|
| "Boleto"
|
||||||
|
| "Dinheiro"
|
||||||
|
| "Cartão de débito"
|
||||||
|
| "Cartão de crédito"
|
||||||
|
| "Pré-Pago | VR/VA"
|
||||||
|
| "Transferência bancária",
|
||||||
|
payerId: existing.payerId,
|
||||||
|
isSplit: false,
|
||||||
|
accountId: isCreditCard ? null : existing.accountId,
|
||||||
|
cardId: isCreditCard ? existing.cardId : null,
|
||||||
|
categoryId: existing.categoryId,
|
||||||
|
note: existing.note,
|
||||||
|
recurrenceCount: data.recurrenceCount,
|
||||||
|
dueDate: existing.dueDate?.toISOString().slice(0, 10),
|
||||||
|
boletoPaymentDate: existing.boletoPaymentDate
|
||||||
|
?.toISOString()
|
||||||
|
.slice(0, 10),
|
||||||
|
isSettled: existing.isSettled,
|
||||||
|
},
|
||||||
|
userId: user.id,
|
||||||
|
period: existing.period,
|
||||||
|
purchaseDate: existing.purchaseDate,
|
||||||
|
dueDate: existing.dueDate,
|
||||||
|
boletoPaymentDate: existing.boletoPaymentDate,
|
||||||
|
shares: [{ payerId: existing.payerId, amountCents: totalCents }],
|
||||||
|
amountSign,
|
||||||
|
shouldNullifySettled: isCreditCard,
|
||||||
|
seriesId,
|
||||||
|
}).map((record) => ({
|
||||||
|
...record,
|
||||||
|
importBatchId: existing.importBatchId,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const currentRow = records[0];
|
||||||
|
const rowsToInsert = records.slice(1);
|
||||||
|
if (!currentRow) {
|
||||||
|
throw new Error("Não foi possível montar a recorrência.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCreditCard && existing.cardId) {
|
||||||
|
const periodsToUpdate = records
|
||||||
|
.map((row) => row.period)
|
||||||
|
.filter((period): period is string => Boolean(period));
|
||||||
|
const paidPeriods = await getPaidInvoicePeriods(
|
||||||
|
user.id,
|
||||||
|
existing.cardId,
|
||||||
|
periodsToUpdate,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (paidPeriods.length > 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: `As faturas dos meses ${formatPaidInvoicePeriods(
|
||||||
|
paidPeriods,
|
||||||
|
)} já estão pagas. Desfaça o pagamento antes de converter este lançamento.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing.transactionType === "Despesa") {
|
||||||
|
const limitCheck = await validateCardLimit({
|
||||||
|
userId: user.id,
|
||||||
|
cardId: existing.cardId,
|
||||||
|
addAmount: records.reduce(
|
||||||
|
(acc, row) => acc + Math.abs(Number(row.amount)),
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
excludeTransactionIds: [existing.id],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!limitCheck.ok) {
|
||||||
|
return { success: false, error: limitCheck.error };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.transaction(async (tx: typeof db) => {
|
||||||
|
await tx
|
||||||
|
.update(transactions)
|
||||||
|
.set({
|
||||||
|
condition: currentRow.condition,
|
||||||
|
name: currentRow.name,
|
||||||
|
amount: currentRow.amount,
|
||||||
|
recurrenceCount: currentRow.recurrenceCount,
|
||||||
|
installmentCount: null,
|
||||||
|
currentInstallment: null,
|
||||||
|
period: currentRow.period,
|
||||||
|
purchaseDate: currentRow.purchaseDate,
|
||||||
|
dueDate: currentRow.dueDate,
|
||||||
|
isSettled: currentRow.isSettled,
|
||||||
|
boletoPaymentDate: currentRow.boletoPaymentDate,
|
||||||
|
seriesId,
|
||||||
|
})
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(transactions.id, existing.id),
|
||||||
|
eq(transactions.userId, user.id),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rowsToInsert.length > 0) {
|
||||||
|
await tx.insert(transactions).values(rowsToInsert);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
revalidate(user.id);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: `Lançamento convertido em recorrência de ${data.recurrenceCount} meses.`,
|
||||||
|
data: { createdCount: rowsToInsert.length },
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return handleActionError(error) as ActionResult<{ createdCount: number }>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function updateTransactionSplitPairAction(
|
export async function updateTransactionSplitPairAction(
|
||||||
input: UpdateInput,
|
input: UpdateInput,
|
||||||
): Promise<ActionResult> {
|
): Promise<ActionResult> {
|
||||||
|
|||||||
@@ -137,24 +137,6 @@ export function getSplitSummaryData(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSplitSummaryLabel(
|
|
||||||
formState: FormState,
|
|
||||||
payerOptions: SplitSummaryPayerOption[],
|
|
||||||
totalAmount: number,
|
|
||||||
) {
|
|
||||||
const summary = getSplitSummaryData(formState, payerOptions, totalAmount);
|
|
||||||
|
|
||||||
if (summary.type === "text") return summary.label;
|
|
||||||
|
|
||||||
const namesLabel = summary.participants
|
|
||||||
.map((participant) => participant.firstName)
|
|
||||||
.join(" ");
|
|
||||||
const remainingLabel =
|
|
||||||
summary.remainingCount > 0 ? ` +${summary.remainingCount}` : "";
|
|
||||||
|
|
||||||
return `${summary.count} pessoas: ${namesLabel}${remainingLabel} · ${summary.totalLabel}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function SplitConfigDialog({
|
export function SplitConfigDialog({
|
||||||
open,
|
open,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ const categoryGroupByTransactionType = {
|
|||||||
income: "receita",
|
income: "receita",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
const normalizeCategoryName = (value: string) => value.trim().toLowerCase();
|
||||||
|
|
||||||
interface ImportPageProps {
|
interface ImportPageProps {
|
||||||
payerOptions: SelectOption[];
|
payerOptions: SelectOption[];
|
||||||
accountOptions: SelectOption[];
|
accountOptions: SelectOption[];
|
||||||
@@ -108,9 +110,19 @@ export function ImportPage({
|
|||||||
|
|
||||||
setRows(
|
setRows(
|
||||||
stmt.transactions.map((t) => {
|
stmt.transactions.map((t) => {
|
||||||
const mappedCategoryId =
|
let mappedCategoryId =
|
||||||
categoryMappings[normalizeDescriptionKey(t.description)] ?? null;
|
categoryMappings[normalizeDescriptionKey(t.description)] ?? null;
|
||||||
|
|
||||||
|
if (t.categoryRaw) {
|
||||||
|
const categoryRaw = normalizeCategoryName(t.categoryRaw);
|
||||||
|
const matchedOption = categoryOptions.find(
|
||||||
|
(opt) => normalizeCategoryName(opt.label) === categoryRaw,
|
||||||
|
);
|
||||||
|
if (matchedOption) {
|
||||||
|
mappedCategoryId = matchedOption.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...t,
|
...t,
|
||||||
isDuplicate: t.externalId ? duplicates.has(t.externalId) : false,
|
isDuplicate: t.externalId ? duplicates.has(t.externalId) : false,
|
||||||
@@ -129,7 +141,7 @@ export function ImportPage({
|
|||||||
setIsChecking(false);
|
setIsChecking(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[isCategoryCompatible, payerId],
|
[isCategoryCompatible, payerId, categoryOptions],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Pré-seleciona cartão ou conta com base no tipo detectado no OFX
|
// Pré-seleciona cartão ou conta com base no tipo detectado no OFX
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { RiAddFill } from "@remixicon/react";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import {
|
import {
|
||||||
|
convertTransactionToInstallmentAction,
|
||||||
|
convertTransactionToRecurringAction,
|
||||||
createMassTransactionsAction,
|
createMassTransactionsAction,
|
||||||
deleteMultipleTransactionsAction,
|
deleteMultipleTransactionsAction,
|
||||||
deleteTransactionAction,
|
deleteTransactionAction,
|
||||||
@@ -18,8 +20,20 @@ import {
|
|||||||
detachAttachmentBulkAction,
|
detachAttachmentBulkAction,
|
||||||
getPresignedUploadUrlAction,
|
getPresignedUploadUrlAction,
|
||||||
} from "@/features/transactions/actions/attachments";
|
} from "@/features/transactions/actions/attachments";
|
||||||
|
import { detectInstallmentFromName } from "@/features/transactions/lib/installment-detection";
|
||||||
import { ConfirmActionDialog } from "@/shared/components/confirm-action-dialog";
|
import { ConfirmActionDialog } from "@/shared/components/confirm-action-dialog";
|
||||||
import { Button } from "@/shared/components/ui/button";
|
import { Button } from "@/shared/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/shared/components/ui/dialog";
|
||||||
|
import { Input } from "@/shared/components/ui/input";
|
||||||
|
import { Label } from "@/shared/components/ui/label";
|
||||||
|
import { formatCurrency } from "@/shared/utils/currency";
|
||||||
import type {
|
import type {
|
||||||
TransactionsExportContext,
|
TransactionsExportContext,
|
||||||
TransactionsPaginationState,
|
TransactionsPaginationState,
|
||||||
@@ -84,6 +98,9 @@ interface TransactionsPageProps {
|
|||||||
importCategoryOptions?: SelectOption[];
|
importCategoryOptions?: SelectOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pluralize = (count: number, singular: string, plural: string) =>
|
||||||
|
count === 1 ? singular : plural;
|
||||||
|
|
||||||
export function TransactionsPage({
|
export function TransactionsPage({
|
||||||
currentUserId,
|
currentUserId,
|
||||||
transactions: transactionList,
|
transactions: transactionList,
|
||||||
@@ -190,6 +207,16 @@ export function TransactionsPage({
|
|||||||
const [refundOpen, setRefundOpen] = useState(false);
|
const [refundOpen, setRefundOpen] = useState(false);
|
||||||
const [transactionToRefund, setTransactionToRefund] =
|
const [transactionToRefund, setTransactionToRefund] =
|
||||||
useState<TransactionItem | null>(null);
|
useState<TransactionItem | null>(null);
|
||||||
|
const [convertInstallmentOpen, setConvertInstallmentOpen] = useState(false);
|
||||||
|
const [transactionToConvert, setTransactionToConvert] =
|
||||||
|
useState<TransactionItem | null>(null);
|
||||||
|
const [installmentCount, setInstallmentCount] = useState("2");
|
||||||
|
const [installmentPending, setInstallmentPending] = useState(false);
|
||||||
|
const [convertRecurringOpen, setConvertRecurringOpen] = useState(false);
|
||||||
|
const [transactionToConvertRecurring, setTransactionToConvertRecurring] =
|
||||||
|
useState<TransactionItem | null>(null);
|
||||||
|
const [recurrenceCount, setRecurrenceCount] = useState("12");
|
||||||
|
const [recurrencePending, setRecurrencePending] = useState(false);
|
||||||
|
|
||||||
const handleToggleSettlement = async (item: TransactionItem) => {
|
const handleToggleSettlement = async (item: TransactionItem) => {
|
||||||
if (item.paymentMethod === "Cartão de crédito") {
|
if (item.paymentMethod === "Cartão de crédito") {
|
||||||
@@ -542,6 +569,112 @@ export function TransactionsPage({
|
|||||||
setRefundOpen(true);
|
setRefundOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleConvertToInstallment = (item: TransactionItem) => {
|
||||||
|
const detectedInstallment = detectInstallmentFromName(item.name);
|
||||||
|
setTransactionToConvert(item);
|
||||||
|
setInstallmentCount(String(detectedInstallment?.installmentCount ?? 2));
|
||||||
|
setConvertInstallmentOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmConvertToInstallment = async () => {
|
||||||
|
if (!transactionToConvert) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const count = Number(installmentCount);
|
||||||
|
if (!Number.isInteger(count) || count < 2 || count > 60) {
|
||||||
|
toast.error("Informe um parcelamento entre 2 e 60 parcelas.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setInstallmentPending(true);
|
||||||
|
const result = await convertTransactionToInstallmentAction({
|
||||||
|
id: transactionToConvert.id,
|
||||||
|
installmentCount: count,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
toast.error(result.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success(result.message);
|
||||||
|
setConvertInstallmentOpen(false);
|
||||||
|
setTransactionToConvert(null);
|
||||||
|
} finally {
|
||||||
|
setInstallmentPending(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleConvertToRecurring = (item: TransactionItem) => {
|
||||||
|
setTransactionToConvertRecurring(item);
|
||||||
|
setRecurrenceCount("12");
|
||||||
|
setConvertRecurringOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmConvertToRecurring = async () => {
|
||||||
|
if (!transactionToConvertRecurring) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const count = Number(recurrenceCount);
|
||||||
|
if (!Number.isInteger(count) || count < 2 || count > 60) {
|
||||||
|
toast.error("Informe uma recorrência entre 2 e 60 meses.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setRecurrencePending(true);
|
||||||
|
const result = await convertTransactionToRecurringAction({
|
||||||
|
id: transactionToConvertRecurring.id,
|
||||||
|
recurrenceCount: count,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
toast.error(result.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success(result.message);
|
||||||
|
setConvertRecurringOpen(false);
|
||||||
|
setTransactionToConvertRecurring(null);
|
||||||
|
} finally {
|
||||||
|
setRecurrencePending(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const parsedInstallmentCount = Number(installmentCount);
|
||||||
|
const installmentSummary =
|
||||||
|
transactionToConvert &&
|
||||||
|
Number.isInteger(parsedInstallmentCount) &&
|
||||||
|
parsedInstallmentCount >= 2 &&
|
||||||
|
parsedInstallmentCount <= 60
|
||||||
|
? {
|
||||||
|
total: formatCurrency(Math.abs(transactionToConvert.amount)),
|
||||||
|
installmentValue: formatCurrency(
|
||||||
|
Math.abs(transactionToConvert.amount) / parsedInstallmentCount,
|
||||||
|
),
|
||||||
|
count: parsedInstallmentCount,
|
||||||
|
createdCount: parsedInstallmentCount - 1,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const parsedRecurrenceCount = Number(recurrenceCount);
|
||||||
|
const recurringSummary =
|
||||||
|
transactionToConvertRecurring &&
|
||||||
|
Number.isInteger(parsedRecurrenceCount) &&
|
||||||
|
parsedRecurrenceCount >= 2 &&
|
||||||
|
parsedRecurrenceCount <= 60
|
||||||
|
? {
|
||||||
|
amount: formatCurrency(
|
||||||
|
Math.abs(transactionToConvertRecurring.amount),
|
||||||
|
),
|
||||||
|
count: parsedRecurrenceCount,
|
||||||
|
createdCount: parsedRecurrenceCount - 1,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
const handleAnticipate = (item: TransactionItem) => {
|
const handleAnticipate = (item: TransactionItem) => {
|
||||||
setSelectedForAnticipation(item);
|
setSelectedForAnticipation(item);
|
||||||
setAnticipateOpen(true);
|
setAnticipateOpen(true);
|
||||||
@@ -628,6 +761,8 @@ export function TransactionsPage({
|
|||||||
onBulkImport={handleBulkImport}
|
onBulkImport={handleBulkImport}
|
||||||
onViewDetails={handleViewDetails}
|
onViewDetails={handleViewDetails}
|
||||||
onRefund={handleRefund}
|
onRefund={handleRefund}
|
||||||
|
onConvertToInstallment={handleConvertToInstallment}
|
||||||
|
onConvertToRecurring={handleConvertToRecurring}
|
||||||
onToggleSettlement={handleToggleSettlement}
|
onToggleSettlement={handleToggleSettlement}
|
||||||
onAnticipate={handleAnticipate}
|
onAnticipate={handleAnticipate}
|
||||||
onViewAnticipationHistory={handleViewAnticipationHistory}
|
onViewAnticipationHistory={handleViewAnticipationHistory}
|
||||||
@@ -749,6 +884,138 @@ export function TransactionsPage({
|
|||||||
disabled={!transactionToDelete}
|
disabled={!transactionToDelete}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
open={convertInstallmentOpen && !!transactionToConvert}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
setConvertInstallmentOpen(open);
|
||||||
|
if (!open) {
|
||||||
|
setTransactionToConvert(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="sm:max-w-md">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Converter em parcelamento?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
O lançamento atual será mantido como a primeira parcela e os
|
||||||
|
próximos meses serão criados automaticamente.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="installmentCount">Parcelar em</Label>
|
||||||
|
<Input
|
||||||
|
id="installmentCount"
|
||||||
|
type="number"
|
||||||
|
min={2}
|
||||||
|
max={60}
|
||||||
|
value={installmentCount}
|
||||||
|
onChange={(event) => setInstallmentCount(event.target.value)}
|
||||||
|
/>
|
||||||
|
<p className="text-muted-foreground text-sm">
|
||||||
|
Use o total de parcelas da série, incluindo este lançamento.
|
||||||
|
</p>
|
||||||
|
{installmentSummary ? (
|
||||||
|
<p className="rounded-md border bg-muted/40 px-3 py-2 text-muted-foreground text-sm">
|
||||||
|
Resumo: {installmentSummary.total} será dividido em{" "}
|
||||||
|
{installmentSummary.count} parcelas de aproximadamente{" "}
|
||||||
|
{installmentSummary.installmentValue}. Este lançamento vira a
|
||||||
|
primeira parcela e {installmentSummary.createdCount}{" "}
|
||||||
|
{pluralize(
|
||||||
|
installmentSummary.createdCount,
|
||||||
|
"nova parcela será criada",
|
||||||
|
"novas parcelas serão criadas",
|
||||||
|
)}
|
||||||
|
.
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setConvertInstallmentOpen(false)}
|
||||||
|
disabled={installmentPending}
|
||||||
|
>
|
||||||
|
Cancelar
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={confirmConvertToInstallment}
|
||||||
|
disabled={installmentPending}
|
||||||
|
>
|
||||||
|
{installmentPending ? "Convertendo..." : "Converter"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
open={convertRecurringOpen && !!transactionToConvertRecurring}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
setConvertRecurringOpen(open);
|
||||||
|
if (!open) {
|
||||||
|
setTransactionToConvertRecurring(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="sm:max-w-md">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Converter em recorrente?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
O lançamento atual será mantido como a primeira recorrência e os
|
||||||
|
próximos meses serão criados automaticamente.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="recurrenceCount">Repetir por</Label>
|
||||||
|
<Input
|
||||||
|
id="recurrenceCount"
|
||||||
|
type="number"
|
||||||
|
min={2}
|
||||||
|
max={60}
|
||||||
|
value={recurrenceCount}
|
||||||
|
onChange={(event) => setRecurrenceCount(event.target.value)}
|
||||||
|
/>
|
||||||
|
<p className="text-muted-foreground text-sm">
|
||||||
|
Use o total de meses da série, incluindo este lançamento.
|
||||||
|
</p>
|
||||||
|
{recurringSummary ? (
|
||||||
|
<p className="rounded-md border bg-muted/40 px-3 py-2 text-muted-foreground text-sm">
|
||||||
|
Resumo: este lançamento vira a primeira recorrência e{" "}
|
||||||
|
{recurringSummary.createdCount}{" "}
|
||||||
|
{pluralize(
|
||||||
|
recurringSummary.createdCount,
|
||||||
|
"novo lançamento mensal será criado",
|
||||||
|
"novos lançamentos mensais serão criados",
|
||||||
|
)}{" "}
|
||||||
|
com valor de {recurringSummary.amount}.
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setConvertRecurringOpen(false)}
|
||||||
|
disabled={recurrencePending}
|
||||||
|
>
|
||||||
|
Cancelar
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={confirmConvertToRecurring}
|
||||||
|
disabled={recurrencePending}
|
||||||
|
>
|
||||||
|
{recurrencePending ? "Convertendo..." : "Converter"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
<BulkActionDialog
|
<BulkActionDialog
|
||||||
open={bulkDeleteOpen && !!pendingDeleteData}
|
open={bulkDeleteOpen && !!pendingDeleteData}
|
||||||
onOpenChange={setBulkDeleteOpen}
|
onOpenChange={setBulkDeleteOpen}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
RiRefundLine,
|
RiRefundLine,
|
||||||
RiTimeLine,
|
RiTimeLine,
|
||||||
} from "@remixicon/react";
|
} from "@remixicon/react";
|
||||||
|
import { CREDIT_CARD_PAYMENT_METHOD } from "@/features/transactions/lib/constants";
|
||||||
import { Button } from "@/shared/components/ui/button";
|
import { Button } from "@/shared/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@@ -20,6 +21,7 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/shared/components/ui/dropdown-menu";
|
} from "@/shared/components/ui/dropdown-menu";
|
||||||
import { REFUND_NOTE_PREFIX } from "@/shared/lib/accounts/constants";
|
import { REFUND_NOTE_PREFIX } from "@/shared/lib/accounts/constants";
|
||||||
|
import { getConditionIcon } from "@/shared/utils/icons";
|
||||||
import type { TransactionItem } from "../types";
|
import type { TransactionItem } from "../types";
|
||||||
|
|
||||||
type TransactionActionsMenuProps = {
|
type TransactionActionsMenuProps = {
|
||||||
@@ -33,6 +35,8 @@ type TransactionActionsMenuProps = {
|
|||||||
onRefund?: (item: TransactionItem) => void;
|
onRefund?: (item: TransactionItem) => void;
|
||||||
onAnticipate?: (item: TransactionItem) => void;
|
onAnticipate?: (item: TransactionItem) => void;
|
||||||
onViewAnticipationHistory?: (item: TransactionItem) => void;
|
onViewAnticipationHistory?: (item: TransactionItem) => void;
|
||||||
|
onConvertToInstallment?: (item: TransactionItem) => void;
|
||||||
|
onConvertToRecurring?: (item: TransactionItem) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function TransactionActionsMenu({
|
export function TransactionActionsMenu({
|
||||||
@@ -46,6 +50,8 @@ export function TransactionActionsMenu({
|
|||||||
onRefund,
|
onRefund,
|
||||||
onAnticipate,
|
onAnticipate,
|
||||||
onViewAnticipationHistory,
|
onViewAnticipationHistory,
|
||||||
|
onConvertToInstallment,
|
||||||
|
onConvertToRecurring,
|
||||||
}: TransactionActionsMenuProps) {
|
}: TransactionActionsMenuProps) {
|
||||||
const isOwnData = item.userId === currentUserId;
|
const isOwnData = item.userId === currentUserId;
|
||||||
const canRefund =
|
const canRefund =
|
||||||
@@ -55,9 +61,27 @@ export function TransactionActionsMenu({
|
|||||||
!item.splitGroupId &&
|
!item.splitGroupId &&
|
||||||
!item.readonly &&
|
!item.readonly &&
|
||||||
!item.note?.startsWith(REFUND_NOTE_PREFIX);
|
!item.note?.startsWith(REFUND_NOTE_PREFIX);
|
||||||
|
|
||||||
const showInstallmentActions =
|
const showInstallmentActions =
|
||||||
isOwnData && item.condition === "Parcelado" && item.seriesId;
|
isOwnData && item.condition === "Parcelado" && item.seriesId;
|
||||||
|
|
||||||
|
const canConvertToInstallment =
|
||||||
|
isOwnData &&
|
||||||
|
item.paymentMethod === CREDIT_CARD_PAYMENT_METHOD &&
|
||||||
|
item.condition === "À vista" &&
|
||||||
|
!item.splitGroupId &&
|
||||||
|
!item.isDivided &&
|
||||||
|
!item.readonly &&
|
||||||
|
Boolean(onConvertToInstallment);
|
||||||
|
|
||||||
|
const canConvertToRecurring =
|
||||||
|
isOwnData &&
|
||||||
|
item.condition === "À vista" &&
|
||||||
|
!item.splitGroupId &&
|
||||||
|
!item.isDivided &&
|
||||||
|
!item.readonly &&
|
||||||
|
Boolean(onConvertToRecurring);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
@@ -92,7 +116,7 @@ export function TransactionActionsMenu({
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{!item.readonly && !isOwnData ? (
|
{!isOwnData ? (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onSelect={() => onImport?.(item)}
|
onSelect={() => onImport?.(item)}
|
||||||
disabled={!onImport}
|
disabled={!onImport}
|
||||||
@@ -112,6 +136,20 @@ export function TransactionActionsMenu({
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
{canConvertToInstallment ? (
|
||||||
|
<DropdownMenuItem onSelect={() => onConvertToInstallment?.(item)}>
|
||||||
|
{getConditionIcon("Parcelado")}
|
||||||
|
Converter em Parcelamento
|
||||||
|
</DropdownMenuItem>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{canConvertToRecurring ? (
|
||||||
|
<DropdownMenuItem onSelect={() => onConvertToRecurring?.(item)}>
|
||||||
|
{getConditionIcon("Recorrente")}
|
||||||
|
Converter em Recorrente
|
||||||
|
</DropdownMenuItem>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{isOwnData ? (
|
{isOwnData ? (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ type BuildColumnsArgs = {
|
|||||||
onToggleSettlement?: (item: TransactionItem) => void;
|
onToggleSettlement?: (item: TransactionItem) => void;
|
||||||
onAnticipate?: (item: TransactionItem) => void;
|
onAnticipate?: (item: TransactionItem) => void;
|
||||||
onViewAnticipationHistory?: (item: TransactionItem) => void;
|
onViewAnticipationHistory?: (item: TransactionItem) => void;
|
||||||
|
onConvertToInstallment?: (item: TransactionItem) => void;
|
||||||
|
onConvertToRecurring?: (item: TransactionItem) => void;
|
||||||
isSettlementLoading: (id: string) => boolean;
|
isSettlementLoading: (id: string) => boolean;
|
||||||
showActions: boolean;
|
showActions: boolean;
|
||||||
columnOrder?: string[] | null;
|
columnOrder?: string[] | null;
|
||||||
@@ -109,6 +111,8 @@ function buildColumns({
|
|||||||
onToggleSettlement,
|
onToggleSettlement,
|
||||||
onAnticipate,
|
onAnticipate,
|
||||||
onViewAnticipationHistory,
|
onViewAnticipationHistory,
|
||||||
|
onConvertToInstallment,
|
||||||
|
onConvertToRecurring,
|
||||||
isSettlementLoading,
|
isSettlementLoading,
|
||||||
showActions,
|
showActions,
|
||||||
}: BuildColumnsArgs): ColumnDef<TransactionItem>[] {
|
}: BuildColumnsArgs): ColumnDef<TransactionItem>[] {
|
||||||
@@ -122,6 +126,8 @@ function buildColumns({
|
|||||||
const handleToggleSettlement = onToggleSettlement ?? noop;
|
const handleToggleSettlement = onToggleSettlement ?? noop;
|
||||||
const handleAnticipate = onAnticipate ?? noop;
|
const handleAnticipate = onAnticipate ?? noop;
|
||||||
const handleViewAnticipationHistory = onViewAnticipationHistory ?? noop;
|
const handleViewAnticipationHistory = onViewAnticipationHistory ?? noop;
|
||||||
|
const handleConvertToInstallment = onConvertToInstallment ?? noop;
|
||||||
|
const handleConvertToRecurring = onConvertToRecurring ?? noop;
|
||||||
|
|
||||||
const columns: ColumnDef<TransactionItem>[] = [
|
const columns: ColumnDef<TransactionItem>[] = [
|
||||||
{
|
{
|
||||||
@@ -139,6 +145,7 @@ function buildColumns({
|
|||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={row.getIsSelected()}
|
checked={row.getIsSelected()}
|
||||||
|
disabled={!row.getCanSelect()}
|
||||||
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
||||||
aria-label="Selecionar linha"
|
aria-label="Selecionar linha"
|
||||||
/>
|
/>
|
||||||
@@ -544,6 +551,12 @@ function buildColumns({
|
|||||||
onRefund={handleRefund}
|
onRefund={handleRefund}
|
||||||
onAnticipate={handleAnticipate}
|
onAnticipate={handleAnticipate}
|
||||||
onViewAnticipationHistory={handleViewAnticipationHistory}
|
onViewAnticipationHistory={handleViewAnticipationHistory}
|
||||||
|
onConvertToInstallment={
|
||||||
|
onConvertToInstallment ? handleConvertToInstallment : undefined
|
||||||
|
}
|
||||||
|
onConvertToRecurring={
|
||||||
|
onConvertToRecurring ? handleConvertToRecurring : undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ type TransactionsMobileListProps = {
|
|||||||
onToggleSettlement?: (item: TransactionItem) => void;
|
onToggleSettlement?: (item: TransactionItem) => void;
|
||||||
onAnticipate?: (item: TransactionItem) => void;
|
onAnticipate?: (item: TransactionItem) => void;
|
||||||
onViewAnticipationHistory?: (item: TransactionItem) => void;
|
onViewAnticipationHistory?: (item: TransactionItem) => void;
|
||||||
|
onConvertToInstallment?: (item: TransactionItem) => void;
|
||||||
|
onConvertToRecurring?: (item: TransactionItem) => void;
|
||||||
isSettlementLoading: (id: string) => boolean;
|
isSettlementLoading: (id: string) => boolean;
|
||||||
showActions?: boolean;
|
showActions?: boolean;
|
||||||
};
|
};
|
||||||
@@ -55,6 +57,8 @@ export function TransactionsMobileList({
|
|||||||
onToggleSettlement,
|
onToggleSettlement,
|
||||||
onAnticipate,
|
onAnticipate,
|
||||||
onViewAnticipationHistory,
|
onViewAnticipationHistory,
|
||||||
|
onConvertToInstallment,
|
||||||
|
onConvertToRecurring,
|
||||||
isSettlementLoading,
|
isSettlementLoading,
|
||||||
showActions = true,
|
showActions = true,
|
||||||
}: TransactionsMobileListProps) {
|
}: TransactionsMobileListProps) {
|
||||||
@@ -74,6 +78,8 @@ export function TransactionsMobileList({
|
|||||||
onToggleSettlement={onToggleSettlement}
|
onToggleSettlement={onToggleSettlement}
|
||||||
onAnticipate={onAnticipate}
|
onAnticipate={onAnticipate}
|
||||||
onViewAnticipationHistory={onViewAnticipationHistory}
|
onViewAnticipationHistory={onViewAnticipationHistory}
|
||||||
|
onConvertToInstallment={onConvertToInstallment}
|
||||||
|
onConvertToRecurring={onConvertToRecurring}
|
||||||
isSettlementLoading={isSettlementLoading}
|
isSettlementLoading={isSettlementLoading}
|
||||||
showActions={showActions}
|
showActions={showActions}
|
||||||
/>
|
/>
|
||||||
@@ -98,6 +104,8 @@ function TransactionMobileCard({
|
|||||||
onToggleSettlement,
|
onToggleSettlement,
|
||||||
onAnticipate,
|
onAnticipate,
|
||||||
onViewAnticipationHistory,
|
onViewAnticipationHistory,
|
||||||
|
onConvertToInstallment,
|
||||||
|
onConvertToRecurring,
|
||||||
isSettlementLoading,
|
isSettlementLoading,
|
||||||
showActions = true,
|
showActions = true,
|
||||||
}: TransactionMobileCardProps) {
|
}: TransactionMobileCardProps) {
|
||||||
@@ -261,6 +269,8 @@ function TransactionMobileCard({
|
|||||||
onRefund={onRefund}
|
onRefund={onRefund}
|
||||||
onAnticipate={onAnticipate}
|
onAnticipate={onAnticipate}
|
||||||
onViewAnticipationHistory={onViewAnticipationHistory}
|
onViewAnticipationHistory={onViewAnticipationHistory}
|
||||||
|
onConvertToInstallment={onConvertToInstallment}
|
||||||
|
onConvertToRecurring={onConvertToRecurring}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ type TransactionsTableProps = {
|
|||||||
onBulkImport?: (items: TransactionItem[]) => void;
|
onBulkImport?: (items: TransactionItem[]) => void;
|
||||||
onViewDetails?: (item: TransactionItem) => void;
|
onViewDetails?: (item: TransactionItem) => void;
|
||||||
onRefund?: (item: TransactionItem) => void;
|
onRefund?: (item: TransactionItem) => void;
|
||||||
|
onConvertToInstallment?: (item: TransactionItem) => void;
|
||||||
|
onConvertToRecurring?: (item: TransactionItem) => void;
|
||||||
onToggleSettlement?: (item: TransactionItem) => void;
|
onToggleSettlement?: (item: TransactionItem) => void;
|
||||||
onAnticipate?: (item: TransactionItem) => void;
|
onAnticipate?: (item: TransactionItem) => void;
|
||||||
onViewAnticipationHistory?: (item: TransactionItem) => void;
|
onViewAnticipationHistory?: (item: TransactionItem) => void;
|
||||||
@@ -100,6 +102,8 @@ export function TransactionsTable({
|
|||||||
onBulkImport,
|
onBulkImport,
|
||||||
onViewDetails,
|
onViewDetails,
|
||||||
onRefund,
|
onRefund,
|
||||||
|
onConvertToInstallment,
|
||||||
|
onConvertToRecurring,
|
||||||
onToggleSettlement,
|
onToggleSettlement,
|
||||||
onAnticipate,
|
onAnticipate,
|
||||||
onViewAnticipationHistory,
|
onViewAnticipationHistory,
|
||||||
@@ -134,6 +138,8 @@ export function TransactionsTable({
|
|||||||
onConfirmDelete,
|
onConfirmDelete,
|
||||||
onViewDetails,
|
onViewDetails,
|
||||||
onRefund,
|
onRefund,
|
||||||
|
onConvertToInstallment,
|
||||||
|
onConvertToRecurring,
|
||||||
onToggleSettlement,
|
onToggleSettlement,
|
||||||
onAnticipate,
|
onAnticipate,
|
||||||
onViewAnticipationHistory,
|
onViewAnticipationHistory,
|
||||||
@@ -151,6 +157,8 @@ export function TransactionsTable({
|
|||||||
onConfirmDelete,
|
onConfirmDelete,
|
||||||
onViewDetails,
|
onViewDetails,
|
||||||
onRefund,
|
onRefund,
|
||||||
|
onConvertToInstallment,
|
||||||
|
onConvertToRecurring,
|
||||||
onToggleSettlement,
|
onToggleSettlement,
|
||||||
onAnticipate,
|
onAnticipate,
|
||||||
onViewAnticipationHistory,
|
onViewAnticipationHistory,
|
||||||
@@ -175,7 +183,10 @@ export function TransactionsTable({
|
|||||||
: getPaginationRowModel(),
|
: getPaginationRowModel(),
|
||||||
manualPagination: isServerPaginated,
|
manualPagination: isServerPaginated,
|
||||||
pageCount: serverPagination?.totalPages,
|
pageCount: serverPagination?.totalPages,
|
||||||
enableRowSelection: (row) => !row.original.readonly,
|
enableRowSelection: (row) =>
|
||||||
|
row.original.userId === currentUserId
|
||||||
|
? !row.original.readonly
|
||||||
|
: Boolean(onBulkImport),
|
||||||
});
|
});
|
||||||
|
|
||||||
const rowModel = table.getRowModel();
|
const rowModel = table.getRowModel();
|
||||||
@@ -184,11 +195,21 @@ export function TransactionsTable({
|
|||||||
? (serverPagination?.totalItems ?? 0)
|
? (serverPagination?.totalItems ?? 0)
|
||||||
: table.getCoreRowModel().rows.length;
|
: table.getCoreRowModel().rows.length;
|
||||||
const selectedRows = table.getFilteredSelectedRowModel().rows;
|
const selectedRows = table.getFilteredSelectedRowModel().rows;
|
||||||
|
const selectedOwnRows = selectedRows.filter(
|
||||||
|
(row) => row.original.userId === currentUserId,
|
||||||
|
);
|
||||||
|
const selectedImportRows = selectedRows.filter(
|
||||||
|
(row) => row.original.userId !== currentUserId,
|
||||||
|
);
|
||||||
const selectedCount = selectedRows.length;
|
const selectedCount = selectedRows.length;
|
||||||
const selectedTotal = selectedRows.reduce(
|
const selectedTotal = selectedRows.reduce(
|
||||||
(total, row) => total + (row.original.amount ?? 0),
|
(total, row) => total + (row.original.amount ?? 0),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
const selectedImportTotal = selectedImportRows.reduce(
|
||||||
|
(total, row) => total + (row.original.amount ?? 0),
|
||||||
|
0,
|
||||||
|
);
|
||||||
const currentPage = isServerPaginated
|
const currentPage = isServerPaginated
|
||||||
? (serverPagination?.page ?? 1)
|
? (serverPagination?.page ?? 1)
|
||||||
: table.getState().pagination.pageIndex + 1;
|
: table.getState().pagination.pageIndex + 1;
|
||||||
@@ -211,8 +232,8 @@ export function TransactionsTable({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleBulkImport = () => {
|
const handleBulkImport = () => {
|
||||||
if (onBulkImport && selectedCount > 0) {
|
if (onBulkImport && selectedImportRows.length > 0) {
|
||||||
onBulkImport(selectedRows.map((row) => row.original));
|
onBulkImport(selectedImportRows.map((row) => row.original));
|
||||||
setRowSelection({});
|
setRowSelection({});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -326,7 +347,7 @@ export function TransactionsTable({
|
|||||||
|
|
||||||
{selectedCount > 0 &&
|
{selectedCount > 0 &&
|
||||||
onBulkDelete &&
|
onBulkDelete &&
|
||||||
selectedRows.every((row) => row.original.userId === currentUserId) ? (
|
selectedOwnRows.length === selectedCount ? (
|
||||||
<TransactionsBulkBar
|
<TransactionsBulkBar
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedCount}
|
||||||
selectedTotal={selectedTotal}
|
selectedTotal={selectedTotal}
|
||||||
@@ -335,12 +356,10 @@ export function TransactionsTable({
|
|||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{selectedCount > 0 &&
|
{selectedCount > 0 && onBulkImport && selectedImportRows.length > 0 ? (
|
||||||
onBulkImport &&
|
|
||||||
selectedRows.some((row) => row.original.userId !== currentUserId) ? (
|
|
||||||
<TransactionsBulkBar
|
<TransactionsBulkBar
|
||||||
selectedCount={selectedCount}
|
selectedCount={selectedImportRows.length}
|
||||||
selectedTotal={selectedTotal}
|
selectedTotal={selectedImportTotal}
|
||||||
mode="import"
|
mode="import"
|
||||||
onAction={handleBulkImport}
|
onAction={handleBulkImport}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -61,13 +61,3 @@ export function groupAndSortCategories(
|
|||||||
),
|
),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Filters secondary payer options to exclude the primary payer
|
|
||||||
*/
|
|
||||||
export function filterSecondaryPayerOptions(
|
|
||||||
allOptions: SelectOption[],
|
|
||||||
primaryPayerId?: string,
|
|
||||||
): SelectOption[] {
|
|
||||||
return allOptions.filter((option) => option.value !== primaryPayerId);
|
|
||||||
}
|
|
||||||
|
|||||||
49
src/features/transactions/lib/installment-detection.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
export type InstallmentDetection = {
|
||||||
|
name: string;
|
||||||
|
currentInstallment: number;
|
||||||
|
installmentCount: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const INSTALLMENT_SUFFIX_PATTERNS = [
|
||||||
|
/^(?<name>.+?)\s*[-–—]?\s*parcela\s+(?<current>\d{1,2})\s+de\s+(?<total>\d{1,2})\s*$/iu,
|
||||||
|
/^(?<name>.+?)\s*[-–—]?\s*parcela\s+(?<current>\d{1,2})\s*\/\s*(?<total>\d{1,2})\s*$/iu,
|
||||||
|
/^(?<name>.+?)\s*\((?<current>\d{1,2})\s*[/?]\s*(?<total>\d{1,2})\)\s*$/u,
|
||||||
|
/^(?<name>.+?)\s+(?<current>\d{1,2})\s*[/?]\s*(?<total>\d{1,2})\s*$/u,
|
||||||
|
];
|
||||||
|
|
||||||
|
const normalizeDetectedName = (value: string) =>
|
||||||
|
value
|
||||||
|
.trim()
|
||||||
|
.replace(/\s+[-–—:]\s*$/u, "")
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
export function detectInstallmentFromName(
|
||||||
|
value: string | null | undefined,
|
||||||
|
): InstallmentDetection | null {
|
||||||
|
const text = value?.trim();
|
||||||
|
if (!text) return null;
|
||||||
|
|
||||||
|
for (const pattern of INSTALLMENT_SUFFIX_PATTERNS) {
|
||||||
|
const match = pattern.exec(text);
|
||||||
|
const groups = match?.groups;
|
||||||
|
if (!groups) continue;
|
||||||
|
|
||||||
|
const currentInstallment = Number(groups.current);
|
||||||
|
const installmentCount = Number(groups.total);
|
||||||
|
const name = normalizeDetectedName(groups.name ?? "");
|
||||||
|
|
||||||
|
if (
|
||||||
|
name.length > 0 &&
|
||||||
|
Number.isInteger(currentInstallment) &&
|
||||||
|
Number.isInteger(installmentCount) &&
|
||||||
|
currentInstallment >= 1 &&
|
||||||
|
installmentCount >= 2 &&
|
||||||
|
currentInstallment <= installmentCount &&
|
||||||
|
installmentCount <= 60
|
||||||
|
) {
|
||||||
|
return { name, currentInstallment, installmentCount };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -150,10 +150,7 @@ export const getSingleParam = (
|
|||||||
return Array.isArray(value) ? (value[0] ?? null) : value;
|
return Array.isArray(value) ? (value[0] ?? null) : value;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMultiParam = (
|
const getMultiParam = (params: ResolvedSearchParams, key: string): string[] => {
|
||||||
params: ResolvedSearchParams,
|
|
||||||
key: string,
|
|
||||||
): string[] => {
|
|
||||||
const value = params?.[key];
|
const value = params?.[key];
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export function ExpandableWidgetCard({
|
|||||||
if (!element) return;
|
if (!element) return;
|
||||||
|
|
||||||
let frameId = 0;
|
let frameId = 0;
|
||||||
|
const observedElements = new Set<Element>();
|
||||||
|
|
||||||
const checkOverflow = () => {
|
const checkOverflow = () => {
|
||||||
cancelAnimationFrame(frameId);
|
cancelAnimationFrame(frameId);
|
||||||
@@ -44,13 +45,33 @@ export function ExpandableWidgetCard({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const observeContentElements = (resizeObserver: ResizeObserver) => {
|
||||||
|
for (const child of Array.from(element.children)) {
|
||||||
|
if (!observedElements.has(child)) {
|
||||||
|
resizeObserver.observe(child);
|
||||||
|
observedElements.add(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
checkOverflow();
|
checkOverflow();
|
||||||
|
|
||||||
const resizeObserver = new ResizeObserver(checkOverflow);
|
const resizeObserver = new ResizeObserver(checkOverflow);
|
||||||
resizeObserver.observe(element);
|
resizeObserver.observe(element);
|
||||||
|
observeContentElements(resizeObserver);
|
||||||
|
|
||||||
|
const mutationObserver = new MutationObserver(() => {
|
||||||
|
observeContentElements(resizeObserver);
|
||||||
|
checkOverflow();
|
||||||
|
});
|
||||||
|
mutationObserver.observe(element, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true,
|
||||||
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelAnimationFrame(frameId);
|
cancelAnimationFrame(frameId);
|
||||||
|
mutationObserver.disconnect();
|
||||||
resizeObserver.disconnect();
|
resizeObserver.disconnect();
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export type ImportedTransaction = {
|
|||||||
amount: number; // positivo = receita, negativo = despesa
|
amount: number; // positivo = receita, negativo = despesa
|
||||||
description: string; // MEMO ou NAME
|
description: string; // MEMO ou NAME
|
||||||
transactionType: "income" | "expense";
|
transactionType: "income" | "expense";
|
||||||
|
categoryRaw?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ImportStatement = {
|
export type ImportStatement = {
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ export async function parseXls(buffer: ArrayBuffer): Promise<ImportStatement> {
|
|||||||
const typeRaw =
|
const typeRaw =
|
||||||
values[4] != null ? String(values[4]).toLowerCase().trim() : "";
|
values[4] != null ? String(values[4]).toLowerCase().trim() : "";
|
||||||
const transactionType = typeRaw === "receita" ? "income" : "expense";
|
const transactionType = typeRaw === "receita" ? "income" : "expense";
|
||||||
|
const categoryRaw = values[5] != null ? String(values[5]).trim() : null;
|
||||||
|
|
||||||
if (!date || !description || amount === null || amount <= 0) return;
|
if (!date || !description || amount === null || amount <= 0) return;
|
||||||
|
|
||||||
@@ -108,6 +109,7 @@ export async function parseXls(buffer: ArrayBuffer): Promise<ImportStatement> {
|
|||||||
amount,
|
amount,
|
||||||
description,
|
description,
|
||||||
transactionType,
|
transactionType,
|
||||||
|
categoryRaw,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,16 +134,17 @@ export async function generateXlsTemplate(): Promise<ArrayBuffer> {
|
|||||||
const ws = workbook.addWorksheet("Lançamentos");
|
const ws = workbook.addWorksheet("Lançamentos");
|
||||||
|
|
||||||
ws.addRows([
|
ws.addRows([
|
||||||
["Data", "Descrição", "Valor", "Tipo"],
|
["Data", "Descrição", "Valor", "Tipo", "Categoria"],
|
||||||
["01/03/2026", "Ingressos São Januário", 160, "despesa"],
|
["01/03/2026", "Ingressos São Januário", 160, "despesa", "Lazer"],
|
||||||
["01/03/2026", "Salário", 3000.0, "receita"],
|
["01/03/2026", "Salário", 3000.0, "receita", "Salário"],
|
||||||
["01/03/2026", "Posto do Vasco da Gama", 89.9, "despesa"],
|
["01/03/2026", "Posto do Vasco da Gama", 89.9, "despesa", "Transporte"],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
ws.getColumn(1).width = 14;
|
ws.getColumn(1).width = 14;
|
||||||
ws.getColumn(2).width = 32;
|
ws.getColumn(2).width = 32;
|
||||||
ws.getColumn(3).width = 12;
|
ws.getColumn(3).width = 12;
|
||||||
ws.getColumn(4).width = 10;
|
ws.getColumn(4).width = 10;
|
||||||
|
ws.getColumn(5).width = 24;
|
||||||
|
|
||||||
// Dropdown para coluna Tipo (D2:D100)
|
// Dropdown para coluna Tipo (D2:D100)
|
||||||
for (let i = 2; i <= 100; i++) {
|
for (let i = 2; i <= 100; i++) {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export const getLogoDisplayName = (logo?: string | null): string => {
|
|||||||
* @example
|
* @example
|
||||||
* deriveNameFromLogo("my-company-logo.png") // "My Company Logo"
|
* deriveNameFromLogo("my-company-logo.png") // "My Company Logo"
|
||||||
*/
|
*/
|
||||||
export const deriveNameFromLogo = (logo?: string | null) => {
|
const deriveNameFromLogo = (logo?: string | null) => {
|
||||||
if (!logo) {
|
if (!logo) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||