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
|
|
@ -1,42 +1,14 @@
|
|||
<template>
|
||||
<div class="max-w-4xl mx-auto space-y-6">
|
||||
<!-- Section Header with Export Controls -->
|
||||
<div class="flex items-center justify-between mb-8">
|
||||
<div>
|
||||
<h3 class="text-2xl font-black text-black mb-2">
|
||||
Where does your money go?
|
||||
</h3>
|
||||
<p class="text-neutral-600">
|
||||
Add costs like rent, tools, insurance, or other recurring expenses.
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<UButton variant="outline" color="gray" size="sm" @click="exportCosts">
|
||||
<UIcon name="i-heroicons-arrow-down-tray" class="mr-1" />
|
||||
Export
|
||||
</UButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Operating Mode Toggle -->
|
||||
<div class="p-4 border-3 border-black rounded-xl bg-white shadow-md">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h4 class="font-bold text-sm">Operating Mode</h4>
|
||||
<p class="text-xs text-gray-600 mt-1">
|
||||
Choose between minimum needs or target pay for payroll calculations
|
||||
</p>
|
||||
</div>
|
||||
<UToggle
|
||||
v-model="useTargetMode"
|
||||
@update:model-value="updateOperatingMode"
|
||||
:ui="{ active: 'bg-success-500' }"
|
||||
/>
|
||||
</div>
|
||||
<div class="mt-2 text-xs font-medium">
|
||||
{{ useTargetMode ? '🎯 Target Mode' : '⚡ Minimum Mode' }}:
|
||||
{{ useTargetMode ? 'Uses target pay allocations' : 'Uses minimum needs allocations' }}
|
||||
</div>
|
||||
<!-- Section Header -->
|
||||
<div class="mb-8">
|
||||
<h3 class="text-2xl font-black text-black mb-2">
|
||||
Where does your money go?
|
||||
</h3>
|
||||
<p class="text-neutral-600">
|
||||
Add costs like rent + utilities, software licenses, insurance, lawyer
|
||||
fees, accountant fees, and other recurring expenses.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Overhead Costs -->
|
||||
|
|
@ -44,24 +16,12 @@
|
|||
<div
|
||||
v-if="overheadCosts.length > 0"
|
||||
class="flex items-center justify-between">
|
||||
<h4 class="text-lg font-bold text-black">Monthly Overhead</h4>
|
||||
<UButton
|
||||
size="sm"
|
||||
@click="addOverheadCost"
|
||||
variant="solid"
|
||||
color="success"
|
||||
:ui="{
|
||||
base: 'cursor-pointer hover:scale-105 transition-transform',
|
||||
leadingIcon: 'hover:rotate-90 transition-transform',
|
||||
}">
|
||||
<UIcon name="i-heroicons-plus" class="mr-1" />
|
||||
Add Cost
|
||||
</UButton>
|
||||
<h4 class="text-lg font-bold text-black">Overhead</h4>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="overheadCosts.length === 0"
|
||||
class="text-center py-12 border-4 border-dashed border-black rounded-xl bg-white shadow-lg">
|
||||
class="text-center py-12 border-2 border-dashed border-neutral-300 rounded-xl bg-white shadow-sm">
|
||||
<h4 class="font-medium text-neutral-900 mb-2">No overhead costs yet</h4>
|
||||
<p class="text-sm text-neutral-500 mb-4">
|
||||
Get started by adding your first overhead cost.
|
||||
|
|
@ -79,48 +39,23 @@
|
|||
<div
|
||||
v-for="cost in overheadCosts"
|
||||
:key="cost.id"
|
||||
class="p-6 border-3 border-black rounded-xl bg-white shadow-md">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<UFormField label="Cost Name" required>
|
||||
class="p-6 border-2 border-black rounded-xl bg-white shadow-md">
|
||||
<!-- Header row with name and delete button -->
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<div class="flex items-center gap-4 flex-1">
|
||||
<UInput
|
||||
v-model="cost.name"
|
||||
placeholder="Office rent"
|
||||
size="xl"
|
||||
class="text-lg font-medium w-full"
|
||||
class="text-xl w-full font-bold flex-1"
|
||||
@update:model-value="saveCost(cost)"
|
||||
@blur="saveCost(cost)" />
|
||||
</UFormField>
|
||||
|
||||
<UFormField label="Monthly Amount" required>
|
||||
<UInput
|
||||
v-model="cost.amount"
|
||||
type="text"
|
||||
placeholder="800.00"
|
||||
size="xl"
|
||||
class="text-lg font-bold w-full"
|
||||
@update:model-value="validateAndSaveAmount($event, cost)"
|
||||
@blur="saveCost(cost)">
|
||||
<template #leading>
|
||||
<span class="text-neutral-500">€</span>
|
||||
</template>
|
||||
</UInput>
|
||||
</UFormField>
|
||||
|
||||
<UFormField label="Category">
|
||||
<USelect
|
||||
v-model="cost.category"
|
||||
:items="categoryOptions"
|
||||
size="xl"
|
||||
class="text-lg font-medium w-full"
|
||||
@update:model-value="saveCost(cost)" />
|
||||
</UFormField>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end mt-6 pt-6 border-t-3 border-black">
|
||||
</div>
|
||||
<UButton
|
||||
size="xs"
|
||||
variant="solid"
|
||||
color="error"
|
||||
class="ml-4"
|
||||
@click="removeCost(cost.id)"
|
||||
:ui="{
|
||||
base: 'cursor-pointer hover:opacity-90 transition-opacity',
|
||||
|
|
@ -128,6 +63,66 @@
|
|||
<UIcon name="i-heroicons-trash" class="w-4 h-4" />
|
||||
</UButton>
|
||||
</div>
|
||||
|
||||
<!-- Fields grid -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<UFormField label="Category">
|
||||
<USelect
|
||||
v-model="cost.category"
|
||||
:items="categoryOptions"
|
||||
size="md"
|
||||
class="text-sm font-medium w-full"
|
||||
@update:model-value="saveCost(cost)" />
|
||||
</UFormField>
|
||||
|
||||
<UFormField
|
||||
:label="
|
||||
cost.amountType === 'annual' ? 'Annual Amount' : 'Monthly Amount'
|
||||
"
|
||||
required>
|
||||
<div class="flex gap-2">
|
||||
<UInput
|
||||
:value="
|
||||
cost.amountType === 'annual' ? cost.annualAmount : cost.amount
|
||||
"
|
||||
type="text"
|
||||
:placeholder="cost.amountType === 'annual' ? '9600' : '800'"
|
||||
size="md"
|
||||
class="text-sm font-medium w-full"
|
||||
@update:model-value="validateAndSaveAmount($event, cost)"
|
||||
@blur="saveCost(cost)">
|
||||
<template #leading>
|
||||
<span class="text-neutral-500">{{ currencySymbol }}</span>
|
||||
</template>
|
||||
</UInput>
|
||||
<UButtonGroup size="md">
|
||||
<UButton
|
||||
:variant="cost.amountType === 'monthly' ? 'solid' : 'outline'"
|
||||
color="primary"
|
||||
@click="switchAmountType(cost, 'monthly')"
|
||||
class="text-xs">
|
||||
Monthly
|
||||
</UButton>
|
||||
<UButton
|
||||
:variant="cost.amountType === 'annual' ? 'solid' : 'outline'"
|
||||
color="primary"
|
||||
@click="switchAmountType(cost, 'annual')"
|
||||
class="text-xs">
|
||||
Annual
|
||||
</UButton>
|
||||
</UButtonGroup>
|
||||
</div>
|
||||
<p class="text-xs text-neutral-500 mt-1">
|
||||
<template v-if="cost.amountType === 'annual'">
|
||||
{{ currencySymbol
|
||||
}}{{ Math.round((cost.annualAmount || 0) / 12) }} per month
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ currencySymbol }}{{ (cost.amount || 0) * 12 }} per year
|
||||
</template>
|
||||
</p>
|
||||
</UFormField>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Cost Button (when items exist) -->
|
||||
|
|
@ -155,20 +150,27 @@ const emit = defineEmits<{
|
|||
"save-status": [status: "saving" | "saved" | "error"];
|
||||
}>();
|
||||
|
||||
// Store
|
||||
// Store and Currency
|
||||
const coop = useCoopBuilder();
|
||||
const { currencySymbol } = useCurrency();
|
||||
|
||||
// Get the store directly for overhead costs
|
||||
const store = useCoopBuilderStore();
|
||||
|
||||
// Computed for overhead costs (from store)
|
||||
const overheadCosts = computed(() => store.overheadCosts || []);
|
||||
// Computed for overhead costs (from store) with amountType defaults
|
||||
const overheadCosts = computed(() =>
|
||||
(store.overheadCosts || []).map((cost) => ({
|
||||
...cost,
|
||||
amountType: cost.amountType || "monthly",
|
||||
annualAmount: cost.annualAmount || (cost.amount || 0) * 12,
|
||||
}))
|
||||
);
|
||||
|
||||
// Operating mode toggle
|
||||
const useTargetMode = ref(coop.operatingMode.value === 'target');
|
||||
const useTargetMode = ref(coop.operatingMode.value === "target");
|
||||
|
||||
function updateOperatingMode(value: boolean) {
|
||||
coop.setOperatingMode(value ? 'target' : 'min');
|
||||
coop.setOperatingMode(value ? "target" : "min");
|
||||
emit("save-status", "saved");
|
||||
}
|
||||
|
||||
|
|
@ -211,23 +213,66 @@ const debouncedSave = useDebounceFn((cost: any) => {
|
|||
}, 300);
|
||||
|
||||
function saveCost(cost: any) {
|
||||
if (cost.name && cost.amount >= 0) {
|
||||
const hasValidAmount =
|
||||
cost.amountType === "annual" ? cost.annualAmount >= 0 : cost.amount >= 0;
|
||||
|
||||
if (cost.name && hasValidAmount) {
|
||||
debouncedSave(cost);
|
||||
}
|
||||
}
|
||||
|
||||
// Immediate save without debounce for UI responsiveness
|
||||
function saveCostImmediate(cost: any) {
|
||||
try {
|
||||
// Use store's upsert method directly
|
||||
store.upsertOverheadCost(cost);
|
||||
} catch (error) {
|
||||
console.error("Failed to save cost:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Validation function for amount
|
||||
function validateAndSaveAmount(value: string, cost: any) {
|
||||
const numValue = parseFloat(value.replace(/[^\d.]/g, ""));
|
||||
cost.amount = isNaN(numValue) ? 0 : Math.max(0, numValue);
|
||||
const validValue = isNaN(numValue) ? 0 : Math.max(0, numValue);
|
||||
|
||||
if (cost.amountType === "annual") {
|
||||
cost.annualAmount = validValue;
|
||||
cost.amount = Math.round(validValue / 12);
|
||||
} else {
|
||||
cost.amount = validValue;
|
||||
cost.annualAmount = validValue * 12;
|
||||
}
|
||||
|
||||
saveCost(cost);
|
||||
}
|
||||
|
||||
// Function to switch between annual and monthly
|
||||
function switchAmountType(cost: any, type: "annual" | "monthly") {
|
||||
cost.amountType = type;
|
||||
|
||||
// Recalculate values based on new type
|
||||
if (type === "annual") {
|
||||
if (!cost.annualAmount) {
|
||||
cost.annualAmount = (cost.amount || 0) * 12;
|
||||
}
|
||||
} else {
|
||||
if (!cost.amount) {
|
||||
cost.amount = Math.round((cost.annualAmount || 0) / 12);
|
||||
}
|
||||
}
|
||||
|
||||
// Save immediately without debounce for instant UI update
|
||||
saveCostImmediate(cost);
|
||||
}
|
||||
|
||||
function addOverheadCost() {
|
||||
const newCost = {
|
||||
id: Date.now().toString(),
|
||||
name: "",
|
||||
amount: 0,
|
||||
annualAmount: 0,
|
||||
amountType: "monthly",
|
||||
category: "Operations",
|
||||
recurring: true,
|
||||
};
|
||||
|
|
@ -240,24 +285,4 @@ function removeCost(id: string) {
|
|||
store.removeOverheadCost(id);
|
||||
emit("save-status", "saved");
|
||||
}
|
||||
|
||||
function exportCosts() {
|
||||
const exportData = {
|
||||
overheadCosts: overheadCosts.value,
|
||||
exportedAt: new Date().toISOString(),
|
||||
section: "costs",
|
||||
};
|
||||
|
||||
const blob = new Blob([JSON.stringify(exportData, null, 2)], {
|
||||
type: "application/json",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = `coop-costs-${new Date().toISOString().split("T")[0]}.json`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue