17 lines
760 B
TypeScript
17 lines
760 B
TypeScript
// Profit calculation. Single source of truth for every surface.
|
|
// Open Question 1: the workbook computes profit as income - fixed (no running cost).
|
|
// The app currently includes running cost. Default matches the workbook; flip the
|
|
// flag here to include running cost everywhere in the app at once.
|
|
export type ProfitInput = {
|
|
income: number;
|
|
fixed: number;
|
|
running: number;
|
|
};
|
|
export type ProfitOptions = { includeRunningCost?: boolean };
|
|
|
|
export function computeProfit(p: ProfitInput, opts: ProfitOptions = {}): number {
|
|
const { income, fixed, running } = p;
|
|
// Q1: default false = match workbook formula `= SUM(income - fixed)`
|
|
const include = opts.includeRunningCost ?? false;
|
|
return include ? income - fixed - running : income - fixed;
|
|
}
|