199 lines
5.1 KiB
TypeScript
199 lines
5.1 KiB
TypeScript
import { defineStore } from "pinia";
|
|
|
|
export const usePoliciesStore = defineStore(
|
|
"policies",
|
|
() => {
|
|
// Schema version for persistence
|
|
const schemaVersion = "1.0";
|
|
|
|
// Core policies - initialize with empty/zero values
|
|
const equalHourlyWage = ref(0);
|
|
const payrollOncostPct = ref(0);
|
|
const savingsTargetMonths = ref(0);
|
|
const minCashCushionAmount = ref(0);
|
|
|
|
// Pay policy for member needs coverage
|
|
const payPolicy = ref({
|
|
relationship: 'equal-pay' as 'equal-pay' | 'needs-weighted' | 'role-banded' | 'hours-weighted',
|
|
roleBands: [] as Array<{ role: string; hourlyWage: number }>
|
|
});
|
|
|
|
// Deferred pay limits
|
|
const deferredCapHoursPerQtr = ref(0);
|
|
const deferredSunsetMonths = ref(0);
|
|
|
|
// Surplus distribution order
|
|
const surplusOrder = ref([
|
|
"Deferred",
|
|
"Savings",
|
|
"Hardship",
|
|
"Training",
|
|
"Patronage",
|
|
"Retained",
|
|
]);
|
|
|
|
// Payment priority order
|
|
const paymentPriority = ref(["Payroll", "Taxes", "CriticalOps", "Vendors"]);
|
|
|
|
// Volunteer scope - allowed flows
|
|
const volunteerScope = ref({
|
|
allowedFlows: ["Care", "SharedLearning"],
|
|
});
|
|
|
|
// Validation computed
|
|
const isValid = computed(() => {
|
|
return (
|
|
equalHourlyWage.value > 0 &&
|
|
payrollOncostPct.value >= 0 &&
|
|
payrollOncostPct.value <= 100 &&
|
|
savingsTargetMonths.value >= 0 &&
|
|
minCashCushionAmount.value >= 0 &&
|
|
deferredCapHoursPerQtr.value >= 0 &&
|
|
deferredSunsetMonths.value >= 0
|
|
);
|
|
});
|
|
|
|
// Wizard-required actions
|
|
function setEqualWage(amount) {
|
|
if (amount > 0) {
|
|
equalHourlyWage.value = amount;
|
|
}
|
|
}
|
|
|
|
function setOncostPct(pct) {
|
|
if (pct >= 0 && pct <= 100) {
|
|
payrollOncostPct.value = pct;
|
|
}
|
|
}
|
|
|
|
function setSavingsTargetMonths(months) {
|
|
if (months >= 0) {
|
|
savingsTargetMonths.value = months;
|
|
}
|
|
}
|
|
|
|
function setMinCashCushion(amount) {
|
|
if (amount >= 0) {
|
|
minCashCushionAmount.value = amount;
|
|
}
|
|
}
|
|
|
|
function setDeferredCap(hours) {
|
|
if (hours >= 0) {
|
|
deferredCapHoursPerQtr.value = hours;
|
|
}
|
|
}
|
|
|
|
function setDeferredSunset(months) {
|
|
if (months >= 0) {
|
|
deferredSunsetMonths.value = months;
|
|
}
|
|
}
|
|
|
|
function setVolunteerScope(allowedFlows) {
|
|
volunteerScope.value = { allowedFlows: [...allowedFlows] };
|
|
}
|
|
|
|
function setSurplusOrder(order) {
|
|
surplusOrder.value = [...order];
|
|
}
|
|
|
|
function setPaymentPriority(priority) {
|
|
paymentPriority.value = [...priority];
|
|
}
|
|
|
|
function setPayPolicy(relationship, roleBands = []) {
|
|
payPolicy.value = {
|
|
relationship,
|
|
roleBands: [...roleBands]
|
|
};
|
|
}
|
|
|
|
// Legacy actions
|
|
function updatePolicy(key, value) {
|
|
if (key === "equalHourlyWage") setEqualWage(value);
|
|
else if (key === "payrollOncostPct") setOncostPct(value);
|
|
else if (key === "savingsTargetMonths") setSavingsTargetMonths(value);
|
|
else if (key === "minCashCushionAmount") setMinCashCushion(value);
|
|
else if (key === "deferredCapHoursPerQtr") setDeferredCap(value);
|
|
else if (key === "deferredSunsetMonths") setDeferredSunset(value);
|
|
}
|
|
|
|
function updateSurplusOrder(newOrder) {
|
|
setSurplusOrder(newOrder);
|
|
}
|
|
|
|
function updatePaymentPriority(newOrder) {
|
|
setPaymentPriority(newOrder);
|
|
}
|
|
|
|
// Reset function
|
|
function resetPolicies() {
|
|
equalHourlyWage.value = 0;
|
|
payrollOncostPct.value = 0;
|
|
savingsTargetMonths.value = 0;
|
|
minCashCushionAmount.value = 0;
|
|
payPolicy.value = { relationship: 'equal-pay', roleBands: [] };
|
|
deferredCapHoursPerQtr.value = 0;
|
|
deferredSunsetMonths.value = 0;
|
|
surplusOrder.value = [
|
|
"Deferred",
|
|
"Savings",
|
|
"Hardship",
|
|
"Training",
|
|
"Patronage",
|
|
"Retained",
|
|
];
|
|
paymentPriority.value = ["Payroll", "Taxes", "CriticalOps", "Vendors"];
|
|
volunteerScope.value = { allowedFlows: ["Care", "SharedLearning"] };
|
|
}
|
|
|
|
return {
|
|
equalHourlyWage,
|
|
payrollOncostPct,
|
|
savingsTargetMonths,
|
|
minCashCushionAmount,
|
|
payPolicy,
|
|
deferredCapHoursPerQtr,
|
|
deferredSunsetMonths,
|
|
surplusOrder,
|
|
paymentPriority,
|
|
volunteerScope,
|
|
isValid,
|
|
schemaVersion,
|
|
// Wizard actions
|
|
setEqualWage,
|
|
setOncostPct,
|
|
setSavingsTargetMonths,
|
|
setMinCashCushion,
|
|
setPayPolicy,
|
|
setDeferredCap,
|
|
setDeferredSunset,
|
|
setVolunteerScope,
|
|
setSurplusOrder,
|
|
setPaymentPriority,
|
|
resetPolicies,
|
|
// Legacy actions
|
|
updatePolicy,
|
|
updateSurplusOrder,
|
|
updatePaymentPriority,
|
|
};
|
|
},
|
|
{
|
|
persist: {
|
|
key: "urgent-tools-policies",
|
|
paths: [
|
|
"equalHourlyWage",
|
|
"payrollOncostPct",
|
|
"savingsTargetMonths",
|
|
"minCashCushionAmount",
|
|
"payPolicy",
|
|
"deferredCapHoursPerQtr",
|
|
"deferredSunsetMonths",
|
|
"surplusOrder",
|
|
"paymentPriority",
|
|
"volunteerScope",
|
|
],
|
|
},
|
|
}
|
|
);
|