chore: snapshot sidebar layout antes de experimentar topbar
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
cartoes,
|
||||
categorias,
|
||||
contas,
|
||||
faturas,
|
||||
lancamentos,
|
||||
pagadores,
|
||||
} from "@/db/schema";
|
||||
@@ -32,6 +33,7 @@ import {
|
||||
import { noteSchema, uuidSchema } from "@/lib/schemas/common";
|
||||
import { formatDecimalForDbRequired } from "@/lib/utils/currency";
|
||||
import { getTodayDate, parseLocalDateString } from "@/lib/utils/date";
|
||||
import { getNextPeriod } from "@/lib/utils/period";
|
||||
|
||||
// ============================================================================
|
||||
// Authorization Validation Functions
|
||||
@@ -1639,6 +1641,59 @@ export async function deleteMultipleLancamentosAction(
|
||||
}
|
||||
}
|
||||
|
||||
// Check fatura payment status and card closing day for the given period
|
||||
export async function checkFaturaStatusAction(
|
||||
cartaoId: string,
|
||||
period: string,
|
||||
): Promise<{
|
||||
shouldSuggestNext: boolean;
|
||||
isPaid: boolean;
|
||||
isAfterClosing: boolean;
|
||||
closingDay: string | null;
|
||||
cardName: string;
|
||||
nextPeriod: string;
|
||||
} | null> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
|
||||
const cartao = await db.query.cartoes.findFirst({
|
||||
where: and(eq(cartoes.id, cartaoId), eq(cartoes.userId, user.id)),
|
||||
columns: { id: true, name: true, closingDay: true },
|
||||
});
|
||||
|
||||
if (!cartao) return null;
|
||||
|
||||
const fatura = await db.query.faturas.findFirst({
|
||||
where: and(
|
||||
eq(faturas.cartaoId, cartaoId),
|
||||
eq(faturas.userId, user.id),
|
||||
eq(faturas.period, period),
|
||||
),
|
||||
columns: { paymentStatus: true },
|
||||
});
|
||||
|
||||
const isPaid = fatura?.paymentStatus === "pago";
|
||||
const today = new Date();
|
||||
const currentPeriod = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}`;
|
||||
const closingDayNum = Number.parseInt(cartao.closingDay ?? "", 10);
|
||||
const isAfterClosing =
|
||||
period === currentPeriod &&
|
||||
!Number.isNaN(closingDayNum) &&
|
||||
today.getDate() > closingDayNum;
|
||||
|
||||
return {
|
||||
shouldSuggestNext: isPaid || isAfterClosing,
|
||||
isPaid,
|
||||
isAfterClosing,
|
||||
closingDay: cartao.closingDay,
|
||||
cardName: cartao.name,
|
||||
nextPeriod: getNextPeriod(period),
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Get unique establishment names from the last 3 months
|
||||
export async function getRecentEstablishmentsAction(): Promise<string[]> {
|
||||
try {
|
||||
|
||||
@@ -72,7 +72,7 @@ export default async function DashboardLayout({
|
||||
<SiteHeader notificationsSnapshot={notificationsSnapshot} />
|
||||
<div className="flex flex-1 flex-col pt-12 md:pt-0">
|
||||
<div className="@container/main flex flex-1 flex-col gap-2">
|
||||
<div className="flex flex-col gap-4 py-4 md:gap-6">
|
||||
<div className="flex flex-col gap-4 py-4 md:gap-6 w-full max-w-8xl mx-auto">
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user