Implement Phase 2 features: roles, assessment groups, budget import, Kanban

- Add hierarchical roles: SuperUser Admin (is_superadmin flag), Tenant Admin,
  Tenant User with separate /admin route and admin panel
- Add Assessment Groups module for property type-based assessment rates
  (SFHs, Condos, Estate Lots with different regular/special rates)
- Enhance Chart of Accounts: initial balance on create (with journal entry),
  archive/restore accounts, edit all fields including account number & fund type
- Add Budget CSV import with downloadable template and account mapping
- Add Capital Projects Kanban board with drag-and-drop between year columns,
  table/kanban view toggle, and PDF export via browser print
- Update seed data with assessment groups, second test user, superadmin flag
- Create repeatable reseed.sh script for clean database population
- Fix AgingReportPage Mantine v7 Table prop compatibility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 14:28:46 -05:00
parent e0272f9d8a
commit 01502e07bc
29 changed files with 1792 additions and 142 deletions

View File

@@ -17,11 +17,13 @@ import {
Tabs,
Loader,
Center,
Tooltip,
SimpleGrid,
} from '@mantine/core';
import { useForm } from '@mantine/form';
import { useDisclosure } from '@mantine/hooks';
import { notifications } from '@mantine/notifications';
import { IconPlus, IconEdit, IconSearch } from '@tabler/icons-react';
import { IconPlus, IconEdit, IconSearch, IconArchive, IconArchiveOff } from '@tabler/icons-react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import api from '../../services/api';
@@ -52,36 +54,41 @@ export function AccountsPage() {
const [search, setSearch] = useState('');
const [filterType, setFilterType] = useState<string | null>(null);
const [filterFund, setFilterFund] = useState<string | null>(null);
const [showArchived, setShowArchived] = useState(false);
const queryClient = useQueryClient();
const { data: accounts = [], isLoading } = useQuery<Account[]>({
queryKey: ['accounts'],
queryKey: ['accounts', showArchived],
queryFn: async () => {
const { data } = await api.get('/accounts');
const params = showArchived ? '?includeArchived=true' : '';
const { data } = await api.get(`/accounts${params}`);
return data;
},
});
const form = useForm({
initialValues: {
account_number: 0,
accountNumber: 0,
name: '',
description: '',
account_type: 'expense',
fund_type: 'operating',
is_1099_reportable: false,
accountType: 'expense',
fundType: 'operating',
is1099Reportable: false,
initialBalance: 0,
},
validate: {
account_number: (v) => (v > 0 ? null : 'Required'),
accountNumber: (v) => (v > 0 ? null : 'Required'),
name: (v) => (v.length > 0 ? null : 'Required'),
},
});
const createMutation = useMutation({
mutationFn: (values: any) =>
editing
? api.put(`/accounts/${editing.id}`, values)
: api.post('/accounts', values),
mutationFn: (values: any) => {
if (editing) {
return api.put(`/accounts/${editing.id}`, values);
}
return api.post('/accounts', values);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['accounts'] });
notifications.show({ message: editing ? 'Account updated' : 'Account created', color: 'green' });
@@ -94,15 +101,28 @@ export function AccountsPage() {
},
});
const archiveMutation = useMutation({
mutationFn: (account: Account) =>
api.put(`/accounts/${account.id}`, { isActive: !account.is_active }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['accounts'] });
notifications.show({ message: 'Account status updated', color: 'green' });
},
onError: (err: any) => {
notifications.show({ message: err.response?.data?.message || 'Error', color: 'red' });
},
});
const handleEdit = (account: Account) => {
setEditing(account);
form.setValues({
account_number: account.account_number,
accountNumber: account.account_number,
name: account.name,
description: account.description || '',
account_type: account.account_type,
fund_type: account.fund_type,
is_1099_reportable: account.is_1099_reportable,
accountType: account.account_type,
fundType: account.fund_type,
is1099Reportable: account.is_1099_reportable,
initialBalance: 0,
});
open();
};
@@ -120,11 +140,18 @@ export function AccountsPage() {
return true;
});
const activeAccounts = filtered.filter(a => a.is_active);
const archivedAccounts = filtered.filter(a => !a.is_active);
const totalsByType = accounts.reduce((acc, a) => {
acc[a.account_type] = (acc[a.account_type] || 0) + parseFloat(a.balance || '0');
if (a.is_active) {
acc[a.account_type] = (acc[a.account_type] || 0) + parseFloat(a.balance || '0');
}
return acc;
}, {} as Record<string, number>);
const fmt = (v: number) => v.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
if (isLoading) {
return <Center h={300}><Loader /></Center>;
}
@@ -133,11 +160,28 @@ export function AccountsPage() {
<Stack>
<Group justify="space-between">
<Title order={2}>Chart of Accounts</Title>
<Button leftSection={<IconPlus size={16} />} onClick={handleNew}>
Add Account
</Button>
<Group>
<Switch
label="Show Archived"
checked={showArchived}
onChange={(e) => setShowArchived(e.currentTarget.checked)}
size="sm"
/>
<Button leftSection={<IconPlus size={16} />} onClick={handleNew}>
Add Account
</Button>
</Group>
</Group>
<SimpleGrid cols={{ base: 2, sm: 5 }}>
{Object.entries(totalsByType).map(([type, total]) => (
<Card withBorder p="xs" key={type}>
<Text size="xs" c="dimmed" tt="capitalize">{type}</Text>
<Text fw={700} size="sm" c={accountTypeColors[type]}>{fmt(total)}</Text>
</Card>
))}
</SimpleGrid>
<Group>
<TextInput
placeholder="Search accounts..."
@@ -166,50 +210,69 @@ export function AccountsPage() {
<Tabs defaultValue="all">
<Tabs.List>
<Tabs.Tab value="all">All ({accounts.length})</Tabs.Tab>
<Tabs.Tab value="all">All ({activeAccounts.length})</Tabs.Tab>
<Tabs.Tab value="operating">Operating</Tabs.Tab>
<Tabs.Tab value="reserve">Reserve</Tabs.Tab>
{showArchived && archivedAccounts.length > 0 && (
<Tabs.Tab value="archived" color="gray">Archived ({archivedAccounts.length})</Tabs.Tab>
)}
</Tabs.List>
<Tabs.Panel value="all" pt="sm">
<AccountTable accounts={filtered} onEdit={handleEdit} />
<AccountTable accounts={activeAccounts} onEdit={handleEdit} onArchive={archiveMutation.mutate} />
</Tabs.Panel>
<Tabs.Panel value="operating" pt="sm">
<AccountTable accounts={filtered.filter(a => a.fund_type === 'operating')} onEdit={handleEdit} />
<AccountTable accounts={activeAccounts.filter(a => a.fund_type === 'operating')} onEdit={handleEdit} onArchive={archiveMutation.mutate} />
</Tabs.Panel>
<Tabs.Panel value="reserve" pt="sm">
<AccountTable accounts={filtered.filter(a => a.fund_type === 'reserve')} onEdit={handleEdit} />
<AccountTable accounts={activeAccounts.filter(a => a.fund_type === 'reserve')} onEdit={handleEdit} onArchive={archiveMutation.mutate} />
</Tabs.Panel>
{showArchived && (
<Tabs.Panel value="archived" pt="sm">
<AccountTable accounts={archivedAccounts} onEdit={handleEdit} onArchive={archiveMutation.mutate} isArchivedView />
</Tabs.Panel>
)}
</Tabs>
<Modal opened={opened} onClose={close} title={editing ? 'Edit Account' : 'New Account'} size="md">
<form onSubmit={form.onSubmit((values) => createMutation.mutate(values))}>
<Stack>
<NumberInput label="Account Number" required {...form.getInputProps('account_number')} />
<NumberInput label="Account Number" required {...form.getInputProps('accountNumber')} />
<TextInput label="Account Name" required {...form.getInputProps('name')} />
<TextInput label="Description" {...form.getInputProps('description')} />
<Select
label="Account Type"
required
data={[
{ value: 'asset', label: 'Asset' },
{ value: 'liability', label: 'Liability' },
{ value: 'equity', label: 'Equity' },
{ value: 'income', label: 'Income' },
{ value: 'expense', label: 'Expense' },
]}
{...form.getInputProps('account_type')}
/>
<Select
label="Fund Type"
required
data={[
{ value: 'operating', label: 'Operating' },
{ value: 'reserve', label: 'Reserve' },
]}
{...form.getInputProps('fund_type')}
/>
<Switch label="1099 Reportable" {...form.getInputProps('is_1099_reportable', { type: 'checkbox' })} />
<Group grow>
<Select
label="Account Type"
required
data={[
{ value: 'asset', label: 'Asset' },
{ value: 'liability', label: 'Liability' },
{ value: 'equity', label: 'Equity' },
{ value: 'income', label: 'Income' },
{ value: 'expense', label: 'Expense' },
]}
{...form.getInputProps('accountType')}
/>
<Select
label="Fund Type"
required
data={[
{ value: 'operating', label: 'Operating' },
{ value: 'reserve', label: 'Reserve' },
]}
{...form.getInputProps('fundType')}
/>
</Group>
<Switch label="1099 Reportable" {...form.getInputProps('is1099Reportable', { type: 'checkbox' })} />
{!editing && (
<NumberInput
label="Initial Balance"
description="Opening balance (creates a journal entry)"
prefix="$"
decimalScale={2}
{...form.getInputProps('initialBalance')}
/>
)}
<Button type="submit" loading={createMutation.isPending}>
{editing ? 'Update' : 'Create'}
</Button>
@@ -220,7 +283,17 @@ export function AccountsPage() {
);
}
function AccountTable({ accounts, onEdit }: { accounts: Account[]; onEdit: (a: Account) => void }) {
function AccountTable({
accounts,
onEdit,
onArchive,
isArchivedView = false,
}: {
accounts: Account[];
onEdit: (a: Account) => void;
onArchive: (a: Account) => void;
isArchivedView?: boolean;
}) {
const fmt = (v: string) => {
const n = parseFloat(v || '0');
return n.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
@@ -240,10 +313,24 @@ function AccountTable({ accounts, onEdit }: { accounts: Account[]; onEdit: (a: A
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{accounts.length === 0 && (
<Table.Tr>
<Table.Td colSpan={7}>
<Text ta="center" c="dimmed" py="lg">
{isArchivedView ? 'No archived accounts' : 'No accounts found'}
</Text>
</Table.Td>
</Table.Tr>
)}
{accounts.map((a) => (
<Table.Tr key={a.id}>
<Table.Tr key={a.id} style={{ opacity: a.is_active ? 1 : 0.6 }}>
<Table.Td fw={500}>{a.account_number}</Table.Td>
<Table.Td>{a.name}</Table.Td>
<Table.Td>
<div>
<Text size="sm">{a.name}</Text>
{a.description && <Text size="xs" c="dimmed">{a.description}</Text>}
</div>
</Table.Td>
<Table.Td>
<Badge color={accountTypeColors[a.account_type]} variant="light" size="sm">
{a.account_type}
@@ -255,13 +342,26 @@ function AccountTable({ accounts, onEdit }: { accounts: Account[]; onEdit: (a: A
</Badge>
</Table.Td>
<Table.Td ta="right" ff="monospace">{fmt(a.balance)}</Table.Td>
<Table.Td>{a.is_1099_reportable ? '1099' : ''}</Table.Td>
<Table.Td>{a.is_1099_reportable ? <Badge size="xs" color="yellow">1099</Badge> : ''}</Table.Td>
<Table.Td>
{!a.is_system && (
<ActionIcon variant="subtle" onClick={() => onEdit(a)}>
<IconEdit size={16} />
</ActionIcon>
)}
<Group gap={4}>
<Tooltip label="Edit account">
<ActionIcon variant="subtle" onClick={() => onEdit(a)}>
<IconEdit size={16} />
</ActionIcon>
</Tooltip>
{!a.is_system && (
<Tooltip label={a.is_active ? 'Archive account' : 'Restore account'}>
<ActionIcon
variant="subtle"
color={a.is_active ? 'gray' : 'green'}
onClick={() => onArchive(a)}
>
{a.is_active ? <IconArchive size={16} /> : <IconArchiveOff size={16} />}
</ActionIcon>
</Tooltip>
)}
</Group>
</Table.Td>
</Table.Tr>
))}