feat(registratura): rework with company-prefixed numbering, directions, deadlines, attachments

- Company-specific numbering (B-0001/2026, US-0001/2026, SDT-0001/2026)
- Direction: Intrat/Ieșit replaces old 3-way type
- 9 document types: Contract, Ofertă, Factură, Scrisoare, etc.
- Status simplified to Deschis/Închis with cascade close for linked entries
- Address Book autocomplete for sender/recipient
- Deadline tracking with overdue day counter
- File attachment support (base64 encoding)
- Linked entries system

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Marius Tarau
2026-02-18 06:35:23 +02:00
parent 84d9db4515
commit 98eda56035
8 changed files with 550 additions and 109 deletions
@@ -1,3 +1,4 @@
import type { CompanyId } from '@/core/auth/types';
import type { RegistryEntry } from '../types';
const STORAGE_PREFIX = 'entry:';
@@ -30,9 +31,44 @@ export async function deleteEntry(storage: RegistryStorage, id: string): Promise
await storage.delete(`${STORAGE_PREFIX}${id}`);
}
export function generateRegistryNumber(date: string, index: number): string {
const COMPANY_PREFIXES: Record<CompanyId, string> = {
beletage: 'B',
'urban-switch': 'US',
'studii-de-teren': 'SDT',
group: 'G',
};
/**
* Generate company-specific registry number: B-0001/2026
* Uses the next sequential number for that company in that year.
*/
export function generateRegistryNumber(
company: CompanyId,
date: string,
existingEntries: RegistryEntry[]
): string {
const d = new Date(date);
const year = d.getFullYear();
const padded = String(index).padStart(4, '0');
return `${padded}/${year}`;
const prefix = COMPANY_PREFIXES[company];
// Count existing entries for this company in this year
const sameCompanyYear = existingEntries.filter((e) => {
const entryYear = new Date(e.date).getFullYear();
return e.company === company && entryYear === year;
});
const nextIndex = sameCompanyYear.length + 1;
const padded = String(nextIndex).padStart(4, '0');
return `${prefix}-${padded}/${year}`;
}
/** Calculate days overdue (negative = days remaining, positive = overdue) */
export function getOverdueDays(deadline: string | undefined): number | null {
if (!deadline) return null;
const now = new Date();
now.setHours(0, 0, 0, 0);
const dl = new Date(deadline);
dl.setHours(0, 0, 0, 0);
const diff = now.getTime() - dl.getTime();
return Math.floor(diff / (1000 * 60 * 60 * 24));
}