// ============================================================ // Clients Module // ============================================================ let clientsState = { page: 1, search: '', status: '', clients: [], pagination: null }; async function renderClients(params = {}) { const content = document.getElementById('page-content'); if (params.id) return renderClientDetail(params.id); const _cc = { v: Auth.can('clients', 'view'), c: Auth.can('clients', 'create'), e: Auth.can('clients', 'edit'), d: Auth.can('clients', 'delete') }; content.innerHTML = `
Manage client relationships and contact information
Try adjusting your search or add a new client.
| Company | Industry | Contacts | Projects | Status | Actions |
|---|---|---|---|---|---|
|
${c.company_name}
${c.trading_name ? `${c.trading_name} ` : ''}
|
${c.industry || '—'} | ${c.contact_count || 0} | ${c.project_count || 0} | ${Fmt.statusBadge(c.status)} |
${Auth.can('clients', 'edit') ? `
|
${e.message}
${c.industry || '—'}
${c.vat_no || '—'}
${c.website ? `${c.website}` : '—'}
${Fmt.date(c.created_at)}
${c.notes}
${n.body}
| Project | Status | Priority | Target Date |
|---|---|---|---|
| ${p.name} | ${Fmt.statusBadge(p.status)} | ${Fmt.priorityBadge(p.priority)} | ${Fmt.date(p.target_date)} |
${res.message}
`; return; } const assets = res.data.assets; if (!assets.length) { wrap.innerHTML = `${a.serial_number}
${a.location_desc}
${Fmt.date(a.warranty_expiry)}
${a.notes}
` : ''}${res.message}
`; return; } const accounts = res.data.accounts; if (!accounts.length) { wrap.innerHTML = `${res.message}
`; return; } const pwds = res.data.passwords; if (!pwds.length) { wrap.innerHTML = `| Label | Category | Username | Password | URL | |
|---|---|---|---|---|---|
| ${CAT_ICONS[p.category] || '🔑'} ${p.label} | ${p.category} | ${p.username || '—'} |
••••••••
|
${p.url ? `🔗 Open` : '—'} |
${res.message}
`; return; } const docs = res.data.documents; const today = new Date().toISOString().split('T')[0]; if (!docs.length) { wrap.innerHTML = `| Document | Type | Expiry | Uploaded By | Date | |
|---|---|---|---|---|---|
|
${iconFor(d.mime_type)}
${d.description || d.original_name || d.filename}
${d.notes ? `${d.notes} ` : ''}
|
${d.doc_type || 'other'} | ${expiryBadge} | ${d.uploaded_by_name || '—'} | ${Fmt.date(d.created_at)} | ${d.file_path ? `View` : ''} ${Auth.can('clients', 'delete') ? `` : ''} |