| 1 | import type { billingFrequencyEnum } from '@/server/db/schema' |
| 2 | |
| 3 | /** |
| 4 | * Approximate number of working hours each billing frequency represents, |
| 5 | * used to convert a non-hourly rate into an equivalent hourly rate. |
| 6 | */ |
| 7 | const HOURS_PER_FREQUENCY: Record |
| 8 | (typeof billingFrequencyEnum |
| 9 | number |
| 10 | > = { |
| 11 | hourly: 1, |
| 12 | weekly: 40, |
| 13 | biweekly: 80, |
| 14 | monthly: 160, |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Compute the billable amount in **cents** for a time entry, given its |
| 19 | * duration in minutes and the member's billing rate (also in cents). |
| 20 | * |
| 21 | * The rate is normalised to an hourly figure based on its frequency, then |
| 22 | * pro-rated by the logged duration (`/ 60` to go from minutes to hours). |
| 23 | */ |
| 24 | export function computeEntryAmount( |
| 25 | durationMinutes: number, |
| 26 | billingRate: number, |
| 27 | billingFrequency: (typeof |
| 28 | ): number { |
| 29 | const hours = |
| 30 | const ratePerHour = |
| 31 | return Math.round |
| 32 | } |