feat: add initial application structure with configuration, UI components, and state management
This commit is contained in:
parent
fadf94002c
commit
0af6b17792
56 changed files with 6137 additions and 129 deletions
132
stores/session.ts
Normal file
132
stores/session.ts
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
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
|
||||
const currentSession = ref("2024-01");
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return {
|
||||
checklist,
|
||||
draftAllocations,
|
||||
rationale,
|
||||
currentSession: readonly(currentSession),
|
||||
savedRecords: readonly(savedRecords),
|
||||
availableAmounts: readonly(availableAmounts),
|
||||
totalAllocated,
|
||||
checklistComplete,
|
||||
updateChecklistItem,
|
||||
updateAllocation,
|
||||
resetAllocations,
|
||||
updateRationale,
|
||||
saveSession,
|
||||
loadSession,
|
||||
setCurrentSession,
|
||||
updateAvailableAmounts,
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue