File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( "*" )
You can’t perform that action at this time.
0 commit comments