Skip to content

Commit 7150e4b

Browse files
committed
Fix Financeiro page
1 parent fba36cf commit 7150e4b

3 files changed

Lines changed: 617 additions & 391 deletions

File tree

actions/finance.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type NewSale = Omit<
1414
"id" | "payments" | "created_at" | "updatedAt" | "clientName" | "totalAmount"
1515
> & {
1616
totalAmount?: number;
17+
createdAt?: string;
1718
};
1819

1920
/**
@@ -23,6 +24,20 @@ export async function createSaleAction(sale: NewSale) {
2324
try {
2425
const supabase = getSupabaseAdmin();
2526

27+
// Fetch appointment start time if linked
28+
let inheritedCreatedAt = sale.createdAt || new Date().toISOString();
29+
if (sale.appointmentId) {
30+
const { data: appt } = await supabase
31+
.from("appointments")
32+
.select("start_time")
33+
.eq("id", parseInt(sale.appointmentId))
34+
.single();
35+
36+
if (appt?.start_time) {
37+
inheritedCreatedAt = appt.start_time;
38+
}
39+
}
40+
2641
// Get default commission
2742
const { data: settingData } = await supabase
2843
.from("app_settings")
@@ -48,6 +63,7 @@ export async function createSaleAction(sale: NewSale) {
4863
total_amount: computedTotal,
4964
status: sale.status || "pending",
5065
notes: sale.notes || null,
66+
created_at: inheritedCreatedAt,
5167
},
5268
])
5369
.select("*")

0 commit comments

Comments
 (0)