refactor: remove deprecated components and streamline member coverage calculations, enhance budget management with improved payroll handling, and update UI elements for better clarity
This commit is contained in:
parent
983aeca2dc
commit
09d8794d72
42 changed files with 2166 additions and 2974 deletions
209
stores/budget.ts
209
stores/budget.ts
|
|
@ -319,15 +319,22 @@ export const useBudgetStore = defineStore(
|
|||
if (!isInitialized.value) return;
|
||||
|
||||
const coopStore = useCoopBuilderStore();
|
||||
const payrollIndex = budgetWorksheet.value.expenses.findIndex(item => item.id === "expense-payroll");
|
||||
const basePayrollIndex = budgetWorksheet.value.expenses.findIndex(item => item.id === "expense-payroll-base");
|
||||
const oncostIndex = budgetWorksheet.value.expenses.findIndex(item => item.id === "expense-payroll-oncosts");
|
||||
|
||||
if (payrollIndex === -1) return; // No existing payroll entry
|
||||
// If no split payroll entries exist, look for legacy single entry
|
||||
const legacyIndex = budgetWorksheet.value.expenses.findIndex(item => item.id === "expense-payroll");
|
||||
|
||||
if (basePayrollIndex === -1 && legacyIndex === -1) return; // No existing payroll entries
|
||||
|
||||
const totalHours = coopStore.members.reduce((sum, m) => sum + (m.hoursPerMonth || 0), 0);
|
||||
const hourlyWage = coopStore.equalHourlyWage || 0;
|
||||
const oncostPct = coopStore.payrollOncostPct || 0;
|
||||
const basePayrollBudget = totalHours * hourlyWage;
|
||||
|
||||
// Declare today once for the entire function
|
||||
const today = new Date();
|
||||
|
||||
if (basePayrollBudget > 0 && coopStore.members.length > 0) {
|
||||
// Use policy-driven allocation
|
||||
const payPolicy = {
|
||||
|
|
@ -340,44 +347,92 @@ export const useBudgetStore = defineStore(
|
|||
displayName: m.name,
|
||||
monthlyPayPlanned: m.monthlyPayPlanned || 0,
|
||||
minMonthlyNeeds: m.minMonthlyNeeds || 0,
|
||||
targetMonthlyPay: m.targetMonthlyPay || 0,
|
||||
role: m.role || '',
|
||||
hoursPerMonth: m.hoursPerMonth || 0
|
||||
}));
|
||||
|
||||
const allocatedMembers = allocatePayroll(membersForAllocation, payPolicy, basePayrollBudget);
|
||||
|
||||
// Sum with operating mode consideration
|
||||
// Sum the allocated payroll amounts
|
||||
const totalAllocatedPayroll = allocatedMembers.reduce((sum, m) => {
|
||||
const planned = m.monthlyPayPlanned || 0;
|
||||
if (coopStore.operatingMode === 'min' && m.minMonthlyNeeds) {
|
||||
return sum + Math.min(planned, m.minMonthlyNeeds);
|
||||
}
|
||||
return sum + planned;
|
||||
return sum + (m.monthlyPayPlanned || 0);
|
||||
}, 0);
|
||||
|
||||
const monthlyPayroll = totalAllocatedPayroll * (1 + oncostPct / 100);
|
||||
// Update monthly values for base payroll
|
||||
|
||||
// Update monthly values
|
||||
const today = new Date();
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
|
||||
budgetWorksheet.value.expenses[payrollIndex].monthlyValues[monthKey] = monthlyPayroll;
|
||||
if (basePayrollIndex !== -1) {
|
||||
// Update base payroll entry
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
|
||||
budgetWorksheet.value.expenses[basePayrollIndex].monthlyValues[monthKey] = totalAllocatedPayroll;
|
||||
}
|
||||
|
||||
// Update annual values for base payroll
|
||||
budgetWorksheet.value.expenses[basePayrollIndex].values = {
|
||||
year1: { best: totalAllocatedPayroll * 12, worst: totalAllocatedPayroll * 8, mostLikely: totalAllocatedPayroll * 12 },
|
||||
year2: { best: totalAllocatedPayroll * 14, worst: totalAllocatedPayroll * 10, mostLikely: totalAllocatedPayroll * 13 },
|
||||
year3: { best: totalAllocatedPayroll * 16, worst: totalAllocatedPayroll * 12, mostLikely: totalAllocatedPayroll * 15 }
|
||||
};
|
||||
}
|
||||
|
||||
// Update annual values
|
||||
budgetWorksheet.value.expenses[payrollIndex].values = {
|
||||
year1: { best: monthlyPayroll * 12, worst: monthlyPayroll * 8, mostLikely: monthlyPayroll * 12 },
|
||||
year2: { best: monthlyPayroll * 14, worst: monthlyPayroll * 10, mostLikely: monthlyPayroll * 13 },
|
||||
year3: { best: monthlyPayroll * 16, worst: monthlyPayroll * 12, mostLikely: monthlyPayroll * 15 }
|
||||
};
|
||||
if (oncostIndex !== -1) {
|
||||
// Update oncost entry
|
||||
const oncostAmount = totalAllocatedPayroll * (oncostPct / 100);
|
||||
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
|
||||
budgetWorksheet.value.expenses[oncostIndex].monthlyValues[monthKey] = oncostAmount;
|
||||
}
|
||||
|
||||
// Update name with current percentage
|
||||
budgetWorksheet.value.expenses[oncostIndex].name = `Payroll Taxes & Benefits (${oncostPct}%)`;
|
||||
|
||||
// Update annual values for oncosts
|
||||
budgetWorksheet.value.expenses[oncostIndex].values = {
|
||||
year1: { best: oncostAmount * 12, worst: oncostAmount * 8, mostLikely: oncostAmount * 12 },
|
||||
year2: { best: oncostAmount * 14, worst: oncostAmount * 10, mostLikely: oncostAmount * 13 },
|
||||
year3: { best: oncostAmount * 16, worst: oncostAmount * 12, mostLikely: oncostAmount * 15 }
|
||||
};
|
||||
}
|
||||
|
||||
// Handle legacy single payroll entry (update to combined amount for backwards compatibility)
|
||||
if (legacyIndex !== -1 && basePayrollIndex === -1) {
|
||||
const monthlyPayroll = totalAllocatedPayroll * (1 + oncostPct / 100);
|
||||
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
|
||||
budgetWorksheet.value.expenses[legacyIndex].monthlyValues[monthKey] = monthlyPayroll;
|
||||
}
|
||||
|
||||
budgetWorksheet.value.expenses[legacyIndex].values = {
|
||||
year1: { best: monthlyPayroll * 12, worst: monthlyPayroll * 8, mostLikely: monthlyPayroll * 12 },
|
||||
year2: { best: monthlyPayroll * 14, worst: monthlyPayroll * 10, mostLikely: monthlyPayroll * 13 },
|
||||
year3: { best: monthlyPayroll * 16, worst: monthlyPayroll * 12, mostLikely: monthlyPayroll * 15 }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Force reinitialize - always reload from wizard data
|
||||
async function forceInitializeFromWizardData() {
|
||||
console.log("=== FORCE BUDGET INITIALIZATION ===");
|
||||
isInitialized.value = false;
|
||||
budgetWorksheet.value.revenue = [];
|
||||
budgetWorksheet.value.expenses = [];
|
||||
await initializeFromWizardData();
|
||||
}
|
||||
|
||||
// Initialize worksheet from wizard data
|
||||
async function initializeFromWizardData() {
|
||||
if (isInitialized.value && budgetWorksheet.value.revenue.length > 0) {
|
||||
console.log("=== BUDGET INITIALIZATION DEBUG ===");
|
||||
console.log("Is already initialized:", isInitialized.value);
|
||||
console.log("Current revenue items:", budgetWorksheet.value.revenue.length);
|
||||
console.log("Current expense items:", budgetWorksheet.value.expenses.length);
|
||||
|
||||
// Check if we have actual budget data (not just initialized flag)
|
||||
if (isInitialized.value && (budgetWorksheet.value.revenue.length > 0 || budgetWorksheet.value.expenses.length > 0)) {
|
||||
console.log("Already initialized with data, skipping...");
|
||||
return;
|
||||
}
|
||||
|
|
@ -388,15 +443,19 @@ export const useBudgetStore = defineStore(
|
|||
// Use the new coopBuilder store instead of the old stores
|
||||
const coopStore = useCoopBuilderStore();
|
||||
|
||||
console.log("Streams:", coopStore.streams.length, "streams");
|
||||
console.log("Members:", coopStore.members.length, "members");
|
||||
console.log("Equal wage:", coopStore.equalHourlyWage || "No wage set");
|
||||
console.log("Overhead costs:", coopStore.overheadCosts.length, "costs");
|
||||
console.log("CoopStore Data:");
|
||||
console.log("- Streams:", coopStore.streams.length, coopStore.streams);
|
||||
console.log("- Members:", coopStore.members.length, coopStore.members);
|
||||
console.log("- Equal wage:", coopStore.equalHourlyWage || "No wage set");
|
||||
console.log("- Overhead costs:", coopStore.overheadCosts.length, coopStore.overheadCosts);
|
||||
|
||||
// Clear existing data
|
||||
budgetWorksheet.value.revenue = [];
|
||||
budgetWorksheet.value.expenses = [];
|
||||
|
||||
// Declare today once for the entire function
|
||||
const today = new Date();
|
||||
|
||||
// Add revenue streams from wizard (but don't auto-load fixtures)
|
||||
// Note: We don't auto-load fixtures anymore, but wizard data should still work
|
||||
|
||||
|
|
@ -423,7 +482,6 @@ export const useBudgetStore = defineStore(
|
|||
|
||||
// Create monthly values - split the annual target evenly across 12 months
|
||||
const monthlyValues: Record<string, number> = {};
|
||||
const today = new Date();
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(
|
||||
|
|
@ -470,8 +528,16 @@ export const useBudgetStore = defineStore(
|
|||
const hourlyWage = coopStore.equalHourlyWage || 0;
|
||||
const oncostPct = coopStore.payrollOncostPct || 0;
|
||||
|
||||
console.log("=== PAYROLL CALCULATION DEBUG ===");
|
||||
console.log("Total hours:", totalHours);
|
||||
console.log("Hourly wage:", hourlyWage);
|
||||
console.log("Oncost %:", oncostPct);
|
||||
console.log("Operating mode:", coopStore.operatingMode);
|
||||
console.log("Policy relationship:", coopStore.policy.relationship);
|
||||
|
||||
// Calculate total payroll budget using policy allocation
|
||||
const basePayrollBudget = totalHours * hourlyWage;
|
||||
console.log("Base payroll budget:", basePayrollBudget);
|
||||
|
||||
if (basePayrollBudget > 0 && coopStore.members.length > 0) {
|
||||
// Use policy-driven allocation to get actual member pay amounts
|
||||
|
|
@ -487,30 +553,28 @@ export const useBudgetStore = defineStore(
|
|||
// Ensure all required fields exist
|
||||
monthlyPayPlanned: m.monthlyPayPlanned || 0,
|
||||
minMonthlyNeeds: m.minMonthlyNeeds || 0,
|
||||
targetMonthlyPay: m.targetMonthlyPay || 0,
|
||||
role: m.role || '',
|
||||
hoursPerMonth: m.hoursPerMonth || 0
|
||||
}));
|
||||
|
||||
// Allocate payroll based on policy
|
||||
const allocatedMembers = allocatePayroll(membersForAllocation, payPolicy, basePayrollBudget);
|
||||
console.log("Allocated members:", allocatedMembers.map(m => ({ name: m.name, planned: m.monthlyPayPlanned, needs: m.minMonthlyNeeds })));
|
||||
|
||||
// Sum the allocated amounts for total payroll, respecting operating mode
|
||||
// Sum the allocated amounts for total payroll
|
||||
const totalAllocatedPayroll = allocatedMembers.reduce((sum, m) => {
|
||||
const planned = m.monthlyPayPlanned || 0;
|
||||
// In "minimum" mode, cap at min needs to show a lean runway scenario
|
||||
if (coopStore.operatingMode === 'min' && m.minMonthlyNeeds) {
|
||||
return sum + Math.min(planned, m.minMonthlyNeeds);
|
||||
}
|
||||
console.log(`Member ${m.name}: planned ${planned}`);
|
||||
return sum + planned;
|
||||
}, 0);
|
||||
|
||||
console.log("Total allocated payroll:", totalAllocatedPayroll);
|
||||
|
||||
// Apply oncosts to the policy-allocated total
|
||||
const monthlyPayroll = totalAllocatedPayroll * (1 + oncostPct / 100);
|
||||
console.log("Monthly payroll with oncosts:", monthlyPayroll);
|
||||
|
||||
// Create monthly values for payroll
|
||||
const monthlyValues: Record<string, number> = {};
|
||||
const today = new Date();
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(
|
||||
|
|
@ -519,31 +583,77 @@ export const useBudgetStore = defineStore(
|
|||
monthlyValues[monthKey] = monthlyPayroll;
|
||||
}
|
||||
|
||||
console.log("Creating split payroll budget items with monthly values:", Object.keys(monthlyValues).length, "months");
|
||||
|
||||
// Create base payroll monthly values (without oncosts)
|
||||
const baseMonthlyValues: Record<string, number> = {};
|
||||
const oncostMonthlyValues: Record<string, number> = {};
|
||||
// Reuse the today variable from above
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(
|
||||
date.getMonth() + 1
|
||||
).padStart(2, "0")}`;
|
||||
baseMonthlyValues[monthKey] = totalAllocatedPayroll;
|
||||
oncostMonthlyValues[monthKey] = totalAllocatedPayroll * (oncostPct / 100);
|
||||
}
|
||||
|
||||
// Add base payroll item
|
||||
budgetWorksheet.value.expenses.push({
|
||||
id: "expense-payroll",
|
||||
id: "expense-payroll-base",
|
||||
name: "Payroll",
|
||||
mainCategory: "Salaries & Benefits",
|
||||
subcategory: "Base wages and benefits",
|
||||
source: "wizard",
|
||||
monthlyValues,
|
||||
monthlyValues: baseMonthlyValues,
|
||||
values: {
|
||||
year1: {
|
||||
best: monthlyPayroll * 12,
|
||||
worst: monthlyPayroll * 8,
|
||||
mostLikely: monthlyPayroll * 12,
|
||||
best: totalAllocatedPayroll * 12,
|
||||
worst: totalAllocatedPayroll * 8,
|
||||
mostLikely: totalAllocatedPayroll * 12,
|
||||
},
|
||||
year2: {
|
||||
best: monthlyPayroll * 14,
|
||||
worst: monthlyPayroll * 10,
|
||||
mostLikely: monthlyPayroll * 13,
|
||||
best: totalAllocatedPayroll * 14,
|
||||
worst: totalAllocatedPayroll * 10,
|
||||
mostLikely: totalAllocatedPayroll * 13,
|
||||
},
|
||||
year3: {
|
||||
best: monthlyPayroll * 16,
|
||||
worst: monthlyPayroll * 12,
|
||||
mostLikely: monthlyPayroll * 15,
|
||||
best: totalAllocatedPayroll * 16,
|
||||
worst: totalAllocatedPayroll * 12,
|
||||
mostLikely: totalAllocatedPayroll * 15,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Add payroll oncosts item (if oncost percentage > 0)
|
||||
if (oncostPct > 0) {
|
||||
const oncostAmount = totalAllocatedPayroll * (oncostPct / 100);
|
||||
budgetWorksheet.value.expenses.push({
|
||||
id: "expense-payroll-oncosts",
|
||||
name: `Payroll Taxes & Benefits (${oncostPct}%)`,
|
||||
mainCategory: "Salaries & Benefits",
|
||||
subcategory: "Payroll taxes and benefits",
|
||||
source: "wizard",
|
||||
monthlyValues: oncostMonthlyValues,
|
||||
values: {
|
||||
year1: {
|
||||
best: oncostAmount * 12,
|
||||
worst: oncostAmount * 8,
|
||||
mostLikely: oncostAmount * 12,
|
||||
},
|
||||
year2: {
|
||||
best: oncostAmount * 14,
|
||||
worst: oncostAmount * 10,
|
||||
mostLikely: oncostAmount * 13,
|
||||
},
|
||||
year3: {
|
||||
best: oncostAmount * 16,
|
||||
worst: oncostAmount * 12,
|
||||
mostLikely: oncostAmount * 15,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add overhead costs from wizard
|
||||
|
|
@ -563,7 +673,6 @@ export const useBudgetStore = defineStore(
|
|||
|
||||
// Create monthly values for overhead costs
|
||||
const monthlyValues: Record<string, number> = {};
|
||||
const today = new Date();
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(
|
||||
|
|
@ -696,7 +805,6 @@ export const useBudgetStore = defineStore(
|
|||
if (!item.monthlyValues) {
|
||||
console.log("Migrating item to monthly values:", item.name);
|
||||
item.monthlyValues = {};
|
||||
const today = new Date();
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const date = new Date(today.getFullYear(), today.getMonth() + i, 1);
|
||||
const monthKey = `${date.getFullYear()}-${String(
|
||||
|
|
@ -856,6 +964,7 @@ export const useBudgetStore = defineStore(
|
|||
groupedExpenses,
|
||||
isInitialized,
|
||||
initializeFromWizardData,
|
||||
forceInitializeFromWizardData,
|
||||
refreshPayrollInBudget,
|
||||
updateBudgetValue,
|
||||
updateMonthlyValue,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { defineStore } from "pinia";
|
||||
|
||||
export const useCashStore = defineStore("cash", () => {
|
||||
// 13-week cash flow events
|
||||
// 13-week calendar events
|
||||
const cashEvents = ref([]);
|
||||
|
||||
// Payment queue - staged payments within policy
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
state: () => ({
|
||||
operatingMode: "min" as "min" | "target",
|
||||
|
||||
// Currency preference
|
||||
currency: "EUR" as string,
|
||||
|
||||
// Flag to track if data was intentionally cleared
|
||||
_wasCleared: false,
|
||||
|
||||
members: [] as Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
role?: string;
|
||||
hoursPerMonth?: number;
|
||||
minMonthlyNeeds: number;
|
||||
targetMonthlyPay: number;
|
||||
externalMonthlyIncome: number;
|
||||
monthlyPayPlanned: number;
|
||||
}>,
|
||||
|
||||
|
|
@ -22,6 +22,8 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
id: string;
|
||||
label: string;
|
||||
monthly: number;
|
||||
annual?: number;
|
||||
amountType?: 'monthly' | 'annual';
|
||||
category?: string;
|
||||
certainty?: string;
|
||||
}>,
|
||||
|
|
@ -35,7 +37,6 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
// Scenario and stress test state
|
||||
scenario: "current" as
|
||||
| "current"
|
||||
| "quit-jobs"
|
||||
| "start-production"
|
||||
| "custom",
|
||||
stress: {
|
||||
|
|
@ -46,8 +47,7 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
|
||||
// Policy settings
|
||||
policy: {
|
||||
relationship: "equal-pay" as "equal-pay" | "needs-weighted" | "hours-weighted" | "role-banded",
|
||||
roleBands: {} as Record<string, number>,
|
||||
relationship: "equal-pay" as "equal-pay" | "needs-weighted" | "hours-weighted",
|
||||
},
|
||||
equalHourlyWage: 50,
|
||||
payrollOncostPct: 25,
|
||||
|
|
@ -63,6 +63,8 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
id?: string;
|
||||
name: string;
|
||||
amount: number;
|
||||
annualAmount?: number;
|
||||
amountType?: 'monthly' | 'annual';
|
||||
category?: string;
|
||||
}>,
|
||||
}),
|
||||
|
|
@ -110,10 +112,19 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
// Stream actions
|
||||
upsertStream(s: any) {
|
||||
const i = this.streams.findIndex((x) => x.id === s.id);
|
||||
|
||||
// Calculate monthly value based on amount type
|
||||
let monthlyValue = s.monthly || s.targetMonthlyAmount || 0;
|
||||
if (s.amountType === 'annual' && s.annual) {
|
||||
monthlyValue = Math.round(s.annual / 12);
|
||||
}
|
||||
|
||||
const withDefaults = {
|
||||
id: s.id || Date.now().toString(),
|
||||
label: s.label || s.name || "",
|
||||
monthly: s.monthly || s.targetMonthlyAmount || 0,
|
||||
monthly: monthlyValue,
|
||||
annual: s.annual || s.targetAnnualAmount || monthlyValue * 12,
|
||||
amountType: s.amountType || 'monthly',
|
||||
category: s.category ?? "",
|
||||
certainty: s.certainty ?? "Probable",
|
||||
};
|
||||
|
|
@ -148,7 +159,7 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
|
||||
// Scenario
|
||||
setScenario(
|
||||
scenario: "current" | "quit-jobs" | "start-production" | "custom"
|
||||
scenario: "current" | "start-production" | "custom"
|
||||
) {
|
||||
this.scenario = scenario;
|
||||
},
|
||||
|
|
@ -159,14 +170,10 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
},
|
||||
|
||||
// Policy updates
|
||||
setPolicy(relationship: "equal-pay" | "needs-weighted" | "hours-weighted" | "role-banded") {
|
||||
setPolicy(relationship: "equal-pay" | "needs-weighted" | "hours-weighted") {
|
||||
this.policy.relationship = relationship;
|
||||
},
|
||||
|
||||
setRoleBands(bands: Record<string, number>) {
|
||||
this.policy.roleBands = bands;
|
||||
},
|
||||
|
||||
setEqualWage(wage: number) {
|
||||
this.equalHourlyWage = wage;
|
||||
},
|
||||
|
|
@ -175,12 +182,24 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
this.payrollOncostPct = pct;
|
||||
},
|
||||
|
||||
setCurrency(currency: string) {
|
||||
this.currency = currency;
|
||||
},
|
||||
|
||||
// Overhead costs
|
||||
addOverheadCost(cost: any) {
|
||||
// Calculate monthly value based on amount type
|
||||
let monthlyValue = cost.amount || 0;
|
||||
if (cost.amountType === 'annual' && cost.annualAmount) {
|
||||
monthlyValue = Math.round(cost.annualAmount / 12);
|
||||
}
|
||||
|
||||
const withDefaults = {
|
||||
id: cost.id || Date.now().toString(),
|
||||
name: cost.name || "",
|
||||
amount: cost.amount || 0,
|
||||
amount: monthlyValue,
|
||||
annualAmount: cost.annualAmount || monthlyValue * 12,
|
||||
amountType: cost.amountType || 'monthly',
|
||||
category: cost.category ?? "",
|
||||
};
|
||||
this.overheadCosts.push(withDefaults);
|
||||
|
|
@ -188,10 +207,19 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
|
||||
upsertOverheadCost(cost: any) {
|
||||
const i = this.overheadCosts.findIndex((c) => c.id === cost.id);
|
||||
|
||||
// Calculate monthly value based on amount type
|
||||
let monthlyValue = cost.amount || 0;
|
||||
if (cost.amountType === 'annual' && cost.annualAmount) {
|
||||
monthlyValue = Math.round(cost.annualAmount / 12);
|
||||
}
|
||||
|
||||
const withDefaults = {
|
||||
id: cost.id || Date.now().toString(),
|
||||
name: cost.name || "",
|
||||
amount: cost.amount || 0,
|
||||
amount: monthlyValue,
|
||||
annualAmount: cost.annualAmount || monthlyValue * 12,
|
||||
amountType: cost.amountType || 'monthly',
|
||||
category: cost.category ?? "",
|
||||
};
|
||||
if (i === -1) {
|
||||
|
|
@ -218,6 +246,7 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
// Reset ALL state to initial empty values
|
||||
this._wasCleared = true;
|
||||
this.operatingMode = "min";
|
||||
this.currency = "EUR";
|
||||
this.members = [];
|
||||
this.streams = [];
|
||||
this.milestones = [];
|
||||
|
|
@ -229,7 +258,6 @@ export const useCoopBuilderStore = defineStore("coop", {
|
|||
};
|
||||
this.policy = {
|
||||
relationship: "equal-pay",
|
||||
roleBands: {},
|
||||
};
|
||||
this.equalHourlyWage = 0;
|
||||
this.payrollOncostPct = 0;
|
||||
|
|
|
|||
|
|
@ -43,8 +43,6 @@ export const useMembersStore = defineStore(
|
|||
const normalized = {
|
||||
id: raw.id || Date.now().toString(),
|
||||
displayName: typeof raw.displayName === "string" ? raw.displayName : "",
|
||||
roleFocus: typeof raw.roleFocus === "string" ? raw.roleFocus : "",
|
||||
role: raw.role || raw.roleFocus || "",
|
||||
hoursPerWeek: hoursPerWeek,
|
||||
payRelationship: raw.payRelationship || "FullyPaid",
|
||||
capacity: {
|
||||
|
|
@ -57,10 +55,8 @@ export const useMembersStore = defineStore(
|
|||
privacyNeeds: raw.privacyNeeds || "aggregate_ok",
|
||||
deferredHours: Number(raw.deferredHours ?? 0),
|
||||
quarterlyDeferredCap: Number(raw.quarterlyDeferredCap ?? 240),
|
||||
// NEW fields for needs coverage
|
||||
// Simplified - only minimum needs for allocation
|
||||
minMonthlyNeeds: Number(raw.minMonthlyNeeds) || 0,
|
||||
targetMonthlyPay: Number(raw.targetMonthlyPay) || 0,
|
||||
externalMonthlyIncome: Number(raw.externalMonthlyIncome) || 0,
|
||||
monthlyPayPlanned: Number(raw.monthlyPayPlanned) || 0,
|
||||
...raw,
|
||||
};
|
||||
|
|
@ -203,13 +199,11 @@ export const useMembersStore = defineStore(
|
|||
// Coverage calculations for individual members
|
||||
function getMemberCoverage(memberId) {
|
||||
const member = members.value.find((m) => m.id === memberId);
|
||||
if (!member) return { minPct: undefined, targetPct: undefined };
|
||||
if (!member) return { coveragePct: undefined };
|
||||
|
||||
return coverage(
|
||||
member.minMonthlyNeeds || 0,
|
||||
member.targetMonthlyPay || 0,
|
||||
member.monthlyPayPlanned || 0,
|
||||
member.externalMonthlyIncome || 0
|
||||
member.monthlyPayPlanned || 0
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -222,26 +216,19 @@ export const useMembersStore = defineStore(
|
|||
notes: '',
|
||||
equalBase: 0,
|
||||
needsWeight: 0.5,
|
||||
roleBands: {},
|
||||
hoursRate: 0,
|
||||
customFormula: ''
|
||||
});
|
||||
|
||||
// Setters for new fields
|
||||
function setMonthlyNeeds(memberId, minNeeds, targetPay) {
|
||||
// Setter for minimum needs only
|
||||
function setMonthlyNeeds(memberId, minNeeds) {
|
||||
const member = members.value.find((m) => m.id === memberId);
|
||||
if (member) {
|
||||
member.minMonthlyNeeds = Number(minNeeds) || 0;
|
||||
member.targetMonthlyPay = Number(targetPay) || 0;
|
||||
}
|
||||
}
|
||||
|
||||
function setExternalIncome(memberId, income) {
|
||||
const member = members.value.find((m) => m.id === memberId);
|
||||
if (member) {
|
||||
member.externalMonthlyIncome = Number(income) || 0;
|
||||
}
|
||||
}
|
||||
// Removed setExternalIncome - no longer needed
|
||||
|
||||
function setPlannedPay(memberId, planned) {
|
||||
const member = members.value.find((m) => m.id === memberId);
|
||||
|
|
@ -269,7 +256,6 @@ export const useMembersStore = defineStore(
|
|||
resetMembers,
|
||||
// New coverage actions
|
||||
setMonthlyNeeds,
|
||||
setExternalIncome,
|
||||
setPlannedPay,
|
||||
getMemberCoverage,
|
||||
// Legacy actions
|
||||
|
|
|
|||
|
|
@ -1,95 +0,0 @@
|
|||
import { defineStore } from "pinia";
|
||||
|
||||
export const useScenariosStore = defineStore("scenarios", () => {
|
||||
// Scenario presets
|
||||
const presets = ref({
|
||||
current: {
|
||||
name: "Operate Current Plan",
|
||||
description: "Continue with existing revenue and capacity",
|
||||
settings: {},
|
||||
},
|
||||
quitDayJobs: {
|
||||
name: "Quit Day Jobs",
|
||||
description: "Members leave external work, increase co-op hours",
|
||||
settings: {
|
||||
targetHoursMultiplier: 1.5,
|
||||
externalCoverageReduction: 0.8,
|
||||
},
|
||||
},
|
||||
startProduction: {
|
||||
name: "Start Production",
|
||||
description: "Launch product development phase",
|
||||
settings: {
|
||||
productionCostsIncrease: 2000,
|
||||
effortHoursIncrease: 100,
|
||||
},
|
||||
},
|
||||
sixMonth: {
|
||||
name: "6-Month Plan",
|
||||
description: "Extended planning horizon",
|
||||
settings: {
|
||||
timeHorizonMonths: 6,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// What-if sliders state
|
||||
const sliders = ref({
|
||||
monthlyRevenue: 0,
|
||||
paidHoursPerMonth: 0,
|
||||
winRatePct: 0,
|
||||
avgPayoutDelayDays: 0,
|
||||
hourlyWageAdjust: 0,
|
||||
});
|
||||
|
||||
// Selected scenario
|
||||
const activeScenario = ref("current");
|
||||
|
||||
// Computed scenario results (will be calculated by composables)
|
||||
const scenarioResults = computed(() => ({
|
||||
runway: 0,
|
||||
monthlyCosts: 0,
|
||||
cashflowRisk: "low",
|
||||
recommendations: [],
|
||||
}));
|
||||
|
||||
// Actions
|
||||
function setActiveScenario(scenarioKey) {
|
||||
activeScenario.value = scenarioKey;
|
||||
}
|
||||
|
||||
function updateSlider(key, value) {
|
||||
if (key in sliders.value) {
|
||||
sliders.value[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
function resetSliders() {
|
||||
sliders.value = {
|
||||
monthlyRevenue: 0,
|
||||
paidHoursPerMonth: 0,
|
||||
winRatePct: 0,
|
||||
avgPayoutDelayDays: 0,
|
||||
hourlyWageAdjust: 0,
|
||||
};
|
||||
}
|
||||
|
||||
function saveCustomScenario(name, settings) {
|
||||
presets.value[name.toLowerCase().replace(/\s+/g, "")] = {
|
||||
name,
|
||||
description: "Custom scenario",
|
||||
settings,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
presets: readonly(presets),
|
||||
sliders,
|
||||
activeScenario: readonly(activeScenario),
|
||||
scenarioResults,
|
||||
setActiveScenario,
|
||||
updateSlider,
|
||||
resetSliders,
|
||||
saveCustomScenario,
|
||||
};
|
||||
});
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
import { defineStore } from "pinia";
|
||||
|
||||
export const useSessionStore = defineStore("session", () => {
|
||||
// Value Accounting session checklist state
|
||||
const checklist = ref({
|
||||
monthClosed: false,
|
||||
contributionsLogged: false,
|
||||
surplusCalculated: false,
|
||||
needsReviewed: false,
|
||||
});
|
||||
|
||||
// Draft distribution allocations
|
||||
const draftAllocations = ref({
|
||||
deferredRepay: 0,
|
||||
savings: 0,
|
||||
hardship: 0,
|
||||
training: 0,
|
||||
patronage: 0,
|
||||
retained: 0,
|
||||
});
|
||||
|
||||
// Session rationale text
|
||||
const rationale = ref("");
|
||||
|
||||
// Current session period - use current month/year
|
||||
const currentDate = new Date();
|
||||
const currentYear = currentDate.getFullYear();
|
||||
const currentMonth = String(currentDate.getMonth() + 1).padStart(2, '0');
|
||||
const currentSession = ref(`${currentYear}-${currentMonth}`);
|
||||
|
||||
// Saved distribution records
|
||||
const savedRecords = ref([]);
|
||||
|
||||
// Available amounts for distribution
|
||||
const availableAmounts = ref({
|
||||
surplus: 0,
|
||||
deferredOwed: 0,
|
||||
savingsNeeded: 0,
|
||||
});
|
||||
|
||||
// Computed total allocated
|
||||
const totalAllocated = computed(() =>
|
||||
Object.values(draftAllocations.value).reduce(
|
||||
(sum, amount) => sum + amount,
|
||||
0
|
||||
)
|
||||
);
|
||||
|
||||
// Computed checklist completion
|
||||
const checklistComplete = computed(() =>
|
||||
Object.values(checklist.value).every(Boolean)
|
||||
);
|
||||
|
||||
// Actions
|
||||
function updateChecklistItem(key, value) {
|
||||
if (key in checklist.value) {
|
||||
checklist.value[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
function updateAllocation(key, amount) {
|
||||
if (key in draftAllocations.value) {
|
||||
draftAllocations.value[key] = Number(amount) || 0;
|
||||
}
|
||||
}
|
||||
|
||||
function resetAllocations() {
|
||||
Object.keys(draftAllocations.value).forEach((key) => {
|
||||
draftAllocations.value[key] = 0;
|
||||
});
|
||||
}
|
||||
|
||||
function updateRationale(text) {
|
||||
rationale.value = text;
|
||||
}
|
||||
|
||||
function saveSession() {
|
||||
const record = {
|
||||
id: Date.now().toString(),
|
||||
period: currentSession.value,
|
||||
date: new Date().toISOString(),
|
||||
allocations: { ...draftAllocations.value },
|
||||
rationale: rationale.value,
|
||||
checklist: { ...checklist.value },
|
||||
};
|
||||
|
||||
savedRecords.value.push(record);
|
||||
|
||||
// Reset for next session
|
||||
resetAllocations();
|
||||
rationale.value = "";
|
||||
Object.keys(checklist.value).forEach((key) => {
|
||||
checklist.value[key] = false;
|
||||
});
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
function loadSession(period) {
|
||||
const record = savedRecords.value.find((r) => r.period === period);
|
||||
if (record) {
|
||||
currentSession.value = period;
|
||||
Object.assign(draftAllocations.value, record.allocations);
|
||||
rationale.value = record.rationale;
|
||||
Object.assign(checklist.value, record.checklist);
|
||||
}
|
||||
}
|
||||
|
||||
function setCurrentSession(period) {
|
||||
currentSession.value = period;
|
||||
}
|
||||
|
||||
function updateAvailableAmounts(amounts) {
|
||||
Object.assign(availableAmounts.value, amounts);
|
||||
}
|
||||
|
||||
function resetSession() {
|
||||
// Reset checklist
|
||||
Object.keys(checklist.value).forEach((key) => {
|
||||
checklist.value[key] = false;
|
||||
});
|
||||
|
||||
// Reset allocations
|
||||
Object.keys(draftAllocations.value).forEach((key) => {
|
||||
draftAllocations.value[key] = 0;
|
||||
});
|
||||
|
||||
// Reset other values
|
||||
rationale.value = "";
|
||||
savedRecords.value = [];
|
||||
|
||||
// Reset available amounts
|
||||
availableAmounts.value = {
|
||||
surplus: 0,
|
||||
deferredOwed: 0,
|
||||
savingsNeeded: 0,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
checklist,
|
||||
draftAllocations,
|
||||
rationale,
|
||||
currentSession: readonly(currentSession),
|
||||
savedRecords: readonly(savedRecords),
|
||||
availableAmounts: readonly(availableAmounts),
|
||||
totalAllocated,
|
||||
checklistComplete,
|
||||
updateChecklistItem,
|
||||
updateAllocation,
|
||||
resetAllocations,
|
||||
updateRationale,
|
||||
saveSession,
|
||||
loadSession,
|
||||
setCurrentSession,
|
||||
updateAvailableAmounts,
|
||||
resetSession,
|
||||
};
|
||||
});
|
||||
|
|
@ -48,8 +48,8 @@ export const useStreamsStore = defineStore(
|
|||
} else {
|
||||
const newStream = {
|
||||
id: stream.id || Date.now().toString(),
|
||||
name: stream.name,
|
||||
category: stream.category,
|
||||
name: stream.name,
|
||||
subcategory: stream.subcategory || "",
|
||||
targetPct: stream.targetPct || 0,
|
||||
targetMonthlyAmount: stream.targetMonthlyAmount || 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue