add receipts support

This commit is contained in:
2026-06-26 23:07:43 -04:00
parent 85df7c4627
commit b9a9b813d2
55 changed files with 3239 additions and 441 deletions
+38
View File
@@ -0,0 +1,38 @@
export type LineItemBillingType = "hourly" | "fixed";
export function isFixedLineItem(hours: number): boolean {
return hours === 0;
}
export function getLineItemBillingType(hours: number): LineItemBillingType {
return isFixedLineItem(hours) ? "fixed" : "hourly";
}
export function calculateLineItemAmount(hours: number, rate: number): number {
return isFixedLineItem(hours) ? rate : hours * rate;
}
export function formatLineItemDetail(
hours: number,
rate: number,
formatCurrency: (amount: number) => string,
): string {
if (isFixedLineItem(hours)) {
return "Fixed amount";
}
return `${hours}h @ ${formatCurrency(rate)}/hr`;
}
export function applyBillingTypeChange(
billingType: LineItemBillingType,
current: { hours: number; rate: number },
): { hours: number; rate: number; amount: number } {
if (billingType === "fixed") {
const amount = calculateLineItemAmount(current.hours, current.rate);
return { hours: 0, rate: amount, amount };
}
const hours = current.hours > 0 ? current.hours : 1;
const amount = calculateLineItemAmount(hours, current.rate);
return { hours, rate: current.rate, amount };
}