Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma strängvärde byggs med konkatenering i stället för att matcha mönstret.
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import type { SupabaseClient } from '@supabase/supabase-js'
|
|
|
|
/**
|
|
* Resolve the payment terms for a new customer.
|
|
*
|
|
* Order: the caller-provided value, then the company's own default
|
|
* (company_settings.invoice_default_days, the same setting the invoice
|
|
* flow reads), then 30 as the last resort. Best-effort on the settings
|
|
* read: a missing row or query error falls back to 30 rather than
|
|
* failing the create.
|
|
*/
|
|
export async function resolveDefaultPaymentTerms(
|
|
supabase: SupabaseClient,
|
|
companyId: string,
|
|
provided: number | null | undefined,
|
|
): Promise<number> {
|
|
if (typeof provided === 'number' && Number.isFinite(provided) && provided > 0) {
|
|
return provided
|
|
}
|
|
|
|
const { data } = await supabase
|
|
.from('company_settings')
|
|
.select('invoice_default_days')
|
|
.eq('company_id', companyId)
|
|
.maybeSingle()
|
|
|
|
const days = (data as { invoice_default_days?: number | null } | null)?.invoice_default_days
|
|
return typeof days === 'number' && Number.isInteger(days) && days > 0 ? days : 30
|
|
}
|