mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-06-09 23:06:01 +00:00
feat(contas): adiciona rendimento pelo extrato
This commit is contained in:
@@ -3,6 +3,7 @@ import { notFound } from "next/navigation";
|
||||
import { connection } from "next/server";
|
||||
import { AccountDialog } from "@/features/accounts/components/account-dialog";
|
||||
import { AccountStatementCard } from "@/features/accounts/components/account-statement-card";
|
||||
import { AddYieldDialog } from "@/features/accounts/components/add-yield-dialog";
|
||||
import { AdjustBalanceDialog } from "@/features/accounts/components/adjust-balance-dialog";
|
||||
import type { Account } from "@/features/accounts/components/types";
|
||||
import {
|
||||
@@ -31,6 +32,7 @@ import MonthNavigation from "@/shared/components/month-picker/month-navigation";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { getUserId } from "@/shared/lib/auth/server";
|
||||
import { loadLogoOptions } from "@/shared/lib/logo/options";
|
||||
import { getBusinessDateString } from "@/shared/utils/date";
|
||||
import { parsePeriodParam } from "@/shared/utils/period";
|
||||
|
||||
type PageSearchParams = Promise<ResolvedSearchParams>;
|
||||
@@ -52,6 +54,17 @@ const resolveDefaultPaymentMethod = (
|
||||
return "Pix";
|
||||
};
|
||||
|
||||
const resolveDefaultYieldDate = (period: string) => {
|
||||
const today = getBusinessDateString();
|
||||
if (today.startsWith(period)) return today;
|
||||
|
||||
const [year, month] = period.split("-").map((part) => Number(part));
|
||||
if (!year || !month) return today;
|
||||
|
||||
const lastDay = new Date(year, month, 0).getDate();
|
||||
return `${period}-${String(lastDay).padStart(2, "0")}`;
|
||||
};
|
||||
|
||||
export default async function Page({ params, searchParams }: PageProps) {
|
||||
await connection();
|
||||
const { accountId } = await params;
|
||||
@@ -109,6 +122,7 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
accountSummary;
|
||||
|
||||
const periodLabel = `${capitalize(monthName)} de ${year}`;
|
||||
const defaultYieldDate = resolveDefaultYieldDate(selectedPeriod);
|
||||
|
||||
const accountDialogData: Account = {
|
||||
id: account.id,
|
||||
@@ -152,11 +166,17 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
totalExpenses={totalExpenses}
|
||||
logo={account.logo}
|
||||
balanceAdjustment={
|
||||
<AdjustBalanceDialog
|
||||
accountId={account.id}
|
||||
period={selectedPeriod}
|
||||
currentBalance={currentBalance}
|
||||
/>
|
||||
<>
|
||||
<AddYieldDialog
|
||||
accountId={account.id}
|
||||
defaultDate={defaultYieldDate}
|
||||
/>
|
||||
<AdjustBalanceDialog
|
||||
accountId={account.id}
|
||||
period={selectedPeriod}
|
||||
currentBalance={currentBalance}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
actions={
|
||||
<AccountDialog
|
||||
|
||||
Reference in New Issue
Block a user