109 lines
3.1 KiB
TypeScript
109 lines
3.1 KiB
TypeScript
import { useMembersStore } from '~/stores/members'
|
|
import { usePoliciesStore } from '~/stores/policies'
|
|
import { useStreamsStore } from '~/stores/streams'
|
|
import { useBudgetStore } from '~/stores/budget'
|
|
import { useCashStore } from '~/stores/cash'
|
|
|
|
export type AppSnapshot = {
|
|
members: any[]
|
|
policies: Record<string, any>
|
|
streams: any[]
|
|
budget: Record<string, any>
|
|
cash: Record<string, any>
|
|
}
|
|
|
|
export function useFixtureIO() {
|
|
const exportAll = (): AppSnapshot => {
|
|
const members = useMembersStore()
|
|
const policies = usePoliciesStore()
|
|
const streams = useStreamsStore()
|
|
const budget = useBudgetStore()
|
|
const cash = useCashStore()
|
|
|
|
return {
|
|
members: members.members,
|
|
policies: {
|
|
equalHourlyWage: policies.equalHourlyWage,
|
|
payrollOncostPct: policies.payrollOncostPct,
|
|
savingsTargetMonths: policies.savingsTargetMonths,
|
|
minCashCushionAmount: policies.minCashCushionAmount,
|
|
operatingMode: policies.operatingMode,
|
|
payPolicy: policies.payPolicy,
|
|
deferredCapHoursPerQtr: policies.deferredCapHoursPerQtr,
|
|
deferredSunsetMonths: policies.deferredSunsetMonths,
|
|
surplusOrder: policies.surplusOrder,
|
|
paymentPriority: policies.paymentPriority,
|
|
volunteerScope: policies.volunteerScope
|
|
},
|
|
streams: streams.streams,
|
|
budget: {
|
|
budgetLines: budget.budgetLines,
|
|
overheadCosts: budget.overheadCosts,
|
|
productionCosts: budget.productionCosts,
|
|
currentPeriod: budget.currentPeriod
|
|
},
|
|
cash: {
|
|
cashEvents: cash.cashEvents,
|
|
paymentQueue: cash.paymentQueue,
|
|
currentCash: cash.currentCash,
|
|
currentSavings: cash.currentSavings
|
|
},
|
|
}
|
|
}
|
|
|
|
const importAll = (snapshot: AppSnapshot) => {
|
|
const members = useMembersStore()
|
|
const policies = usePoliciesStore()
|
|
const streams = useStreamsStore()
|
|
const budget = useBudgetStore()
|
|
const cash = useCashStore()
|
|
|
|
try {
|
|
// Import members
|
|
if (snapshot.members && Array.isArray(snapshot.members)) {
|
|
members.$patch({ members: snapshot.members })
|
|
}
|
|
|
|
// Import policies
|
|
if (snapshot.policies) {
|
|
policies.$patch(snapshot.policies)
|
|
}
|
|
|
|
// Import streams
|
|
if (snapshot.streams && Array.isArray(snapshot.streams)) {
|
|
streams.$patch({ streams: snapshot.streams })
|
|
}
|
|
|
|
// Import budget
|
|
if (snapshot.budget) {
|
|
budget.$patch(snapshot.budget)
|
|
}
|
|
|
|
|
|
// Import cash
|
|
if (snapshot.cash) {
|
|
cash.updateCurrentBalances(
|
|
snapshot.cash.currentCash || 0,
|
|
snapshot.cash.currentSavings || 0
|
|
)
|
|
// Handle cash events and payment queue if present
|
|
if (snapshot.cash.cashEvents) {
|
|
cash.$patch({ cashEvents: snapshot.cash.cashEvents })
|
|
}
|
|
if (snapshot.cash.paymentQueue) {
|
|
cash.$patch({ paymentQueue: snapshot.cash.paymentQueue })
|
|
}
|
|
}
|
|
|
|
|
|
console.log('Successfully imported data snapshot')
|
|
} catch (error) {
|
|
console.error('Failed to import snapshot:', error)
|
|
throw error
|
|
}
|
|
}
|
|
|
|
return { exportAll, importAll }
|
|
}
|
|
|
|
|