feat: calculation rules engine for decoupled cost attribution and chargeability
Introduces an admin-configurable rules engine that determines per-day cost attribution (CHARGE/ZERO/REDUCE) and chargeability reporting (COUNT/SKIP) for absence types (sick, vacation, public holiday). Includes shared types, Zod schemas, Prisma model, rule matching with specificity scoring, default rules, calculator integration, CRUD API router, seed data, chargeability report integration, and admin UI. 283/283 engine tests, 209/209 API tests, 0 TS errors. Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -8,7 +8,10 @@ import { BUDGET_WARNING_THRESHOLDS } from "@planarchy/shared";
|
||||
export function computeBudgetStatus(
|
||||
budgetCents: number,
|
||||
winProbability: number,
|
||||
allocations: Pick<Allocation, "status" | "dailyCostCents" | "startDate" | "endDate" | "hoursPerDay">[],
|
||||
allocations: (Pick<Allocation, "status" | "dailyCostCents" | "startDate" | "endDate" | "hoursPerDay"> & {
|
||||
/** When provided (from rules engine), used instead of dailyCostCents * days */
|
||||
adjustedTotalCostCents?: number;
|
||||
})[],
|
||||
projectStartDate: Date,
|
||||
projectEndDate: Date,
|
||||
): BudgetStatus {
|
||||
@@ -19,11 +22,10 @@ export function computeBudgetStatus(
|
||||
let proposedCents = 0;
|
||||
|
||||
for (const alloc of allocations) {
|
||||
const days = countWorkingDaysInRange(
|
||||
const totalCents = alloc.adjustedTotalCostCents ?? (alloc.dailyCostCents * countWorkingDaysInRange(
|
||||
new Date(alloc.startDate),
|
||||
new Date(alloc.endDate),
|
||||
);
|
||||
const totalCents = alloc.dailyCostCents * days;
|
||||
));
|
||||
|
||||
if (activeStatuses.has(alloc.status)) {
|
||||
confirmedCents += totalCents;
|
||||
|
||||
Reference in New Issue
Block a user