Éditer le registre unique du personnel
Le bouton menait au registre de paramétrage juridique — un autre document, qui ne répond à aucune demande d'inspection. Le registre unique du personnel n'existait pas. Il se tient par établissement : celui-ci est demandé avant l'édition plutôt que déduit, car en tirer un au hasard pour une entreprise qui compte trente sites ne répondrait à rien. Une ligne par contrat et non par personne : un salarié réembauché a deux entrées et deux sorties, et les fondre effacerait l'interruption. Les partis y figurent aussi — c'est l'historique que l'inspection vient chercher. Les mentions manquantes sont annoncées avant le téléchargement, et comptées par salarié parce que la contravention l'est aussi. Découvrir un registre incomplet en l'ouvrant, c'est le découvrir devant l'inspection. L'édition est journalisée : le document rassemble l'identité, la nationalité et le parcours de tout le personnel d'un site. Une réserve, portée par le code et par le document : PlanFlow ne collecte pas le sexe, mention pourtant exigée. La colonne reste vide et alimente le décompte des dossiers incomplets, en attendant le champ. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8808fcdb95
commit
3bf2cbabff
12 files changed
+827
-6
No files matched your search
@@ -0,0 +1,141 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
|
||||
/**
|
||||
* Édition du registre unique du personnel.
|
||||
*
|
||||
* L'établissement est demandé avant le téléchargement, et non déduit : le
|
||||
* registre se tient **par établissement**, et en tirer un au hasard pour une
|
||||
* entreprise qui en compte trente ne répondrait à aucune demande d'inspection.
|
||||
*
|
||||
* L'avertissement sur les mentions manquantes arrive avant le fichier, pas
|
||||
* dedans : découvrir un registre incomplet en l'ouvrant, c'est le découvrir
|
||||
* devant l'inspection.
|
||||
*/
|
||||
|
||||
export interface RegisterLocation {
|
||||
id: string;
|
||||
name: string;
|
||||
incomplete: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
export function RegisterDialog({
|
||||
locations,
|
||||
}: {
|
||||
locations: RegisterLocation[];
|
||||
}) {
|
||||
const dialog = useRef<HTMLDialogElement>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [locationId, setLocationId] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const element = dialog.current;
|
||||
if (!element) return;
|
||||
if (open && !element.open) element.showModal();
|
||||
if (!open && element.open) element.close();
|
||||
}, [open]);
|
||||
|
||||
const chosen = locations.find((location) => location.id === locationId);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button onClick={() => setOpen(true)}>
|
||||
Registre unique du personnel
|
||||
</Button>
|
||||
|
||||
<dialog
|
||||
ref={dialog}
|
||||
aria-labelledby="titre-rup"
|
||||
onClose={() => setOpen(false)}
|
||||
className="m-auto w-[min(38rem,calc(100vw-2rem))] rounded-3 border border-line-1 bg-surface p-0 text-ink-1 backdrop:bg-[rgb(0_0_0/0.4)]"
|
||||
>
|
||||
<header className="flex items-center gap-3 px-5 pt-5">
|
||||
<h2 id="titre-rup" className="text-lg font-semibold">
|
||||
Téléchargez votre registre unique du personnel
|
||||
</h2>
|
||||
<span className="flex-1" />
|
||||
<Button variant="ghost" onClick={() => setOpen(false)}>
|
||||
Fermer
|
||||
</Button>
|
||||
</header>
|
||||
|
||||
<div className="flex flex-col gap-4 p-5">
|
||||
<p className="rounded-3 border border-line-1 bg-surface-2 p-4 text-sm leading-[var(--lh-prose)] text-ink-2">
|
||||
Tout employeur doit tenir un registre unique du personnel par
|
||||
établissement. Aucune forme n’est imposée : en cas de contrôle par
|
||||
l’inspection du travail, le format numérique peut être présenté.
|
||||
</p>
|
||||
|
||||
<label className="flex flex-col gap-1.5">
|
||||
<span className="text-sm font-medium">
|
||||
Établissement pour lequel éditer le registre
|
||||
</span>
|
||||
<select
|
||||
value={locationId}
|
||||
onChange={(event) => setLocationId(event.target.value)}
|
||||
className="h-10 rounded-2 border border-line-2 bg-surface px-3 text-sm text-ink-1 outline-none focus-visible:border-focus"
|
||||
>
|
||||
<option value="">Choisissez un établissement…</option>
|
||||
{locations.map((location) => (
|
||||
<option key={location.id} value={location.id}>
|
||||
{location.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{chosen && chosen.incomplete > 0 ? (
|
||||
<div
|
||||
role="alert"
|
||||
className="rounded-3 border border-warn bg-warn-soft p-4 text-sm text-warn-soft-ink"
|
||||
>
|
||||
<p className="font-semibold">
|
||||
Des mentions manquent pour {chosen.incomplete} salarié
|
||||
{chosen.incomplete > 1 ? 's' : ''} de cet établissement
|
||||
</p>
|
||||
<p className="mt-1 leading-[var(--lh-prose)]">
|
||||
Le registre reste éditable, et les manques y figurent en clair.
|
||||
Un registre incomplet expose à une contravention par salarié
|
||||
concerné : complétez les dossiers avant de le présenter.
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{chosen && chosen.total === 0 ? (
|
||||
<p className="text-sm text-ink-3">
|
||||
Aucun contrat n’est rattaché à cet établissement : le registre
|
||||
sera vide.
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<footer className="flex items-center justify-end gap-3 border-t border-line-1 px-5 py-4">
|
||||
<Button onClick={() => setOpen(false)}>Annuler</Button>
|
||||
{/* Un lien, pas un bouton : le navigateur télécharge sans quitter la
|
||||
page, et l'adresse reste rejouable. */}
|
||||
<a
|
||||
href={
|
||||
locationId ? `/equipe/registre?etablissement=${locationId}` : '#'
|
||||
}
|
||||
aria-disabled={!locationId}
|
||||
onClick={(event) => {
|
||||
if (!locationId) event.preventDefault();
|
||||
else setOpen(false);
|
||||
}}
|
||||
className={
|
||||
locationId
|
||||
? 'inline-flex h-8 items-center rounded-2 border border-accent bg-accent px-3.5 text-sm font-medium text-accent-ink hover:bg-accent-hover'
|
||||
: 'pointer-events-none inline-flex h-8 items-center rounded-2 border border-line-2 bg-surface-3 px-3.5 text-sm font-medium text-ink-3'
|
||||
}
|
||||
>
|
||||
Télécharger
|
||||
</a>
|
||||
</footer>
|
||||
</dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,8 @@ import { Suspense } from 'react';
|
||||
|
||||
import { AddEmployeeDialog } from '@/app/(app)/equipe/AddEmployeeDialog';
|
||||
import { DirectoryFilters } from '@/app/(app)/equipe/DirectoryFilters';
|
||||
import { RegisterDialog } from '@/app/(app)/equipe/RegisterDialog';
|
||||
import { listRegisterLocations } from '@/server/employees/rup';
|
||||
import { PageBody, PageHeader } from '@/components/shell/PageHeader';
|
||||
import { Badge, type Tone } from '@/components/ui/Badge';
|
||||
import { EmptyState } from '@/components/ui/Card';
|
||||
@@ -51,6 +53,9 @@ export default async function EquipePage({
|
||||
// formulaire s'en tient à l'identité.
|
||||
const hiringLocations = await listContractLocations().catch(() => []);
|
||||
|
||||
// Sans `members.register.export`, le bouton du registre ne paraît pas.
|
||||
const registerLocations = await listRegisterLocations().catch(() => []);
|
||||
|
||||
const filtered = directory.rows.length !== directory.total;
|
||||
|
||||
return (
|
||||
@@ -64,12 +69,9 @@ export default async function EquipePage({
|
||||
: {})}
|
||||
actions={
|
||||
<>
|
||||
<Link
|
||||
href="/reglages/registre"
|
||||
className="inline-flex h-8 items-center rounded-2 border border-line-3 bg-surface px-3.5 text-sm font-medium text-ink-1 hover:bg-surface-2"
|
||||
>
|
||||
Registre unique du personnel
|
||||
</Link>
|
||||
{registerLocations.length > 0 ? (
|
||||
<RegisterDialog locations={registerLocations} />
|
||||
) : null}
|
||||
<AddEmployeeDialog locations={hiringLocations} />
|
||||
</>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { NextResponse, type NextRequest } from 'next/server';
|
||||
|
||||
import { asciiFileName, sanitiseFileName } from '@/domain/documents/rules';
|
||||
import { recordAudit } from '@/server/audit';
|
||||
import { query } from '@/server/context';
|
||||
import { getRegisterData } from '@/server/employees/rup';
|
||||
import { renderRegisterPdf } from '@/server/employees/rup-pdf';
|
||||
|
||||
/**
|
||||
* Téléchargement du registre unique du personnel.
|
||||
*
|
||||
* Une route et non une action : le document est un fichier, pas un écran, et
|
||||
* son édition doit pouvoir être rejouée par une simple adresse — c'est aussi
|
||||
* ce qui permet de la présenter depuis un poste d'inspection.
|
||||
*
|
||||
* L'édition est journalisée. Le registre rassemble l'identité, la nationalité
|
||||
* et le parcours de tout le personnel d'un établissement : savoir qui l'a
|
||||
* extrait, et quand, fait partie de ce qu'on doit pouvoir répondre.
|
||||
*/
|
||||
export async function GET(request: NextRequest): Promise<NextResponse> {
|
||||
const locationId = request.nextUrl.searchParams.get('etablissement');
|
||||
if (!locationId) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Choisissez un établissement.' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const data = await getRegisterData(locationId);
|
||||
if (!data) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Établissement introuvable.' },
|
||||
{ status: 404 },
|
||||
);
|
||||
}
|
||||
|
||||
await query('members.register.export', async (db, actor) =>
|
||||
recordAudit(db, {
|
||||
actorMembershipId: actor.membershipId,
|
||||
action: 'members.register.export',
|
||||
entityType: 'Location',
|
||||
entityId: data.locationId,
|
||||
after: { lines: data.people.length, incomplete: data.incomplete },
|
||||
}),
|
||||
);
|
||||
|
||||
const pdf = await renderRegisterPdf(data);
|
||||
const stamp = new Date().toISOString().slice(0, 10).split('-').reverse().join('_');
|
||||
const name = sanitiseFileName(`RUP - ${data.locationName} - ${stamp}.pdf`);
|
||||
|
||||
return new NextResponse(pdf as BodyInit, {
|
||||
headers: {
|
||||
'Content-Type': 'application/pdf',
|
||||
'Content-Disposition': `attachment; filename="${asciiFileName(name)}"; filename*=UTF-8''${encodeURIComponent(name)}`,
|
||||
// Un registre se lit à l'instant où il est demandé : le mettre en cache
|
||||
// ferait présenter un effectif périmé au contrôle suivant.
|
||||
'Cache-Control': 'no-store',
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Registre unique du personnel — articles L1221-13 et D1221-23 du code du
|
||||
* travail.
|
||||
*
|
||||
* Tenu par établissement et non par entreprise : c'est l'inspection d'un
|
||||
* établissement donné qui le réclame, et un registre global ne répondrait pas
|
||||
* à la demande.
|
||||
*
|
||||
* Les mentions sont fixées par le texte. Elles sont énumérées ici plutôt que
|
||||
* dispersées dans le rendu, pour qu'une relecture juridique porte sur un seul
|
||||
* endroit.
|
||||
*/
|
||||
|
||||
export interface RupPerson {
|
||||
lastName: string;
|
||||
firstName: string;
|
||||
/** Mention exigée. Non collectée par PlanFlow à ce jour. */
|
||||
sex: string | null;
|
||||
nationality: string | null;
|
||||
birthDate: Date | null;
|
||||
/** Emploi tenu, tel que porté par le contrat. */
|
||||
jobTitle: string | null;
|
||||
qualification: string | null;
|
||||
contractLabel: string | null;
|
||||
entryDate: Date | null;
|
||||
exitDate: Date | null;
|
||||
}
|
||||
|
||||
export interface RupColumn {
|
||||
key: keyof RupPerson;
|
||||
label: string;
|
||||
/** Part de la largeur utile. La somme vaut 1. */
|
||||
width: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* L'ordre suit celui du texte réglementaire : identité, puis situation, puis
|
||||
* dates. Un registre réordonné se relit mal en regard de l'article.
|
||||
*/
|
||||
export const RUP_COLUMNS: RupColumn[] = [
|
||||
{ key: 'lastName', label: 'Nom', width: 0.13 },
|
||||
{ key: 'firstName', label: 'Prénom', width: 0.11 },
|
||||
{ key: 'sex', label: 'Sexe', width: 0.05 },
|
||||
{ key: 'nationality', label: 'Nationalité', width: 0.1 },
|
||||
{ key: 'birthDate', label: 'Date de naissance', width: 0.1 },
|
||||
{ key: 'jobTitle', label: 'Emploi', width: 0.14 },
|
||||
{ key: 'qualification', label: 'Qualification', width: 0.11 },
|
||||
{ key: 'contractLabel', label: 'Contrat', width: 0.08 },
|
||||
{ key: 'entryDate', label: 'Entrée', width: 0.09 },
|
||||
{ key: 'exitDate', label: 'Sortie', width: 0.09 },
|
||||
];
|
||||
|
||||
/**
|
||||
* Mentions obligatoires manquantes pour une personne.
|
||||
*
|
||||
* La date de sortie est exclue : son absence signifie que le salarié est
|
||||
* toujours présent, ce qui est une information et non un oubli.
|
||||
*/
|
||||
export function missingMentions(person: RupPerson): string[] {
|
||||
return RUP_COLUMNS.filter((column) => {
|
||||
if (column.key === 'exitDate') return false;
|
||||
const value = person[column.key];
|
||||
return value === null || value === '';
|
||||
}).map((column) => column.label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Une contravention par salarié concerné, et non une par registre : c'est ce
|
||||
* qui justifie de compter les personnes plutôt que les champs.
|
||||
*/
|
||||
export function peopleWithGaps(people: RupPerson[]): number {
|
||||
return people.filter((person) => missingMentions(person).length > 0).length;
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import 'server-only';
|
||||
|
||||
import { PDFDocument, StandardFonts, rgb, type PDFFont } from 'pdf-lib';
|
||||
|
||||
import { RUP_COLUMNS, type RupPerson } from '@/domain/legal/rup';
|
||||
import type { RupData } from '@/server/employees/rup';
|
||||
|
||||
/**
|
||||
* Rendu du registre unique du personnel.
|
||||
*
|
||||
* Aucune forme n'est imposée par la loi : ce qui compte est que les mentions y
|
||||
* soient, lisibles, et que le document puisse être présenté tel quel en cas de
|
||||
* contrôle. D'où un tableau paysage sobre plutôt qu'une mise en page.
|
||||
*
|
||||
* Helvetica et l'encodage WinAnsi : les accents français y sont, et une police
|
||||
* embarquée alourdirait le fichier sans rien apporter à un tableau.
|
||||
*/
|
||||
|
||||
const A4_LANDSCAPE: [number, number] = [841.89, 595.28];
|
||||
const MARGIN = 32;
|
||||
const ROW_HEIGHT = 18;
|
||||
const FONT_SIZE = 8;
|
||||
|
||||
const dateFormat = new Intl.DateTimeFormat('fr-FR', { dateStyle: 'short' });
|
||||
|
||||
function cell(person: RupPerson, key: keyof RupPerson): string {
|
||||
const value = person[key];
|
||||
if (value === null || value === '') return '—';
|
||||
if (value instanceof Date) return dateFormat.format(value);
|
||||
return String(value);
|
||||
}
|
||||
|
||||
/** Coupe au lieu de déborder : une colonne qui empiète sur la suivante rend
|
||||
* les deux illisibles. */
|
||||
function fit(text: string, font: PDFFont, size: number, width: number): string {
|
||||
if (font.widthOfTextAtSize(text, size) <= width) return text;
|
||||
let cut = text;
|
||||
while (cut.length > 1 && font.widthOfTextAtSize(`${cut}…`, size) > width) {
|
||||
cut = cut.slice(0, -1);
|
||||
}
|
||||
return `${cut}…`;
|
||||
}
|
||||
|
||||
export async function renderRegisterPdf(data: RupData): Promise<Uint8Array> {
|
||||
const pdf = await PDFDocument.create();
|
||||
pdf.setTitle(`Registre unique du personnel — ${data.locationName}`);
|
||||
pdf.setCreator('PlanFlow');
|
||||
|
||||
const regular = await pdf.embedFont(StandardFonts.Helvetica);
|
||||
const bold = await pdf.embedFont(StandardFonts.HelveticaBold);
|
||||
|
||||
const usable = A4_LANDSCAPE[0] - MARGIN * 2;
|
||||
const widths = RUP_COLUMNS.map((column) => column.width * usable);
|
||||
const ink = rgb(0.11, 0.11, 0.11);
|
||||
const faint = rgb(0.62, 0.62, 0.62);
|
||||
const rule = rgb(0.85, 0.85, 0.85);
|
||||
|
||||
const printedOn = dateFormat.format(new Date());
|
||||
let page = pdf.addPage(A4_LANDSCAPE);
|
||||
let y = A4_LANDSCAPE[1] - MARGIN;
|
||||
|
||||
const header = () => {
|
||||
page.drawText('Registre unique du personnel', {
|
||||
x: MARGIN,
|
||||
y: y - 12,
|
||||
size: 14,
|
||||
font: bold,
|
||||
color: ink,
|
||||
});
|
||||
page.drawText(
|
||||
[
|
||||
data.locationName,
|
||||
data.siret ? `SIRET ${data.siret}` : null,
|
||||
`édité le ${printedOn}`,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' · '),
|
||||
{ x: MARGIN, y: y - 28, size: 9, font: regular, color: faint },
|
||||
);
|
||||
y -= 48;
|
||||
|
||||
let x = MARGIN;
|
||||
RUP_COLUMNS.forEach((column, index) => {
|
||||
page.drawText(column.label, {
|
||||
x,
|
||||
y: y - 10,
|
||||
size: FONT_SIZE,
|
||||
font: bold,
|
||||
color: ink,
|
||||
});
|
||||
x += widths[index] as number;
|
||||
});
|
||||
y -= 16;
|
||||
page.drawLine({
|
||||
start: { x: MARGIN, y },
|
||||
end: { x: MARGIN + usable, y },
|
||||
thickness: 0.7,
|
||||
color: rule,
|
||||
});
|
||||
y -= 4;
|
||||
};
|
||||
|
||||
header();
|
||||
|
||||
for (const person of data.people) {
|
||||
// Nouvelle page avant d'écrire, pas après : une ligne à moitié sous la
|
||||
// marge est pire qu'une page de plus.
|
||||
if (y - ROW_HEIGHT < MARGIN + 24) {
|
||||
page = pdf.addPage(A4_LANDSCAPE);
|
||||
y = A4_LANDSCAPE[1] - MARGIN;
|
||||
header();
|
||||
}
|
||||
|
||||
let x = MARGIN;
|
||||
RUP_COLUMNS.forEach((column, index) => {
|
||||
const width = widths[index] as number;
|
||||
const value = cell(person, column.key);
|
||||
page.drawText(fit(value, regular, FONT_SIZE, width - 6), {
|
||||
x,
|
||||
y: y - 12,
|
||||
size: FONT_SIZE,
|
||||
font: regular,
|
||||
color: value === '—' ? faint : ink,
|
||||
});
|
||||
x += width;
|
||||
});
|
||||
|
||||
y -= ROW_HEIGHT;
|
||||
page.drawLine({
|
||||
start: { x: MARGIN, y: y + 4 },
|
||||
end: { x: MARGIN + usable, y: y + 4 },
|
||||
thickness: 0.4,
|
||||
color: rule,
|
||||
});
|
||||
}
|
||||
|
||||
if (data.people.length === 0) {
|
||||
page.drawText('Aucun salarié rattaché à cet établissement.', {
|
||||
x: MARGIN,
|
||||
y: y - 12,
|
||||
size: 9,
|
||||
font: regular,
|
||||
color: faint,
|
||||
});
|
||||
}
|
||||
|
||||
// Mention de pied : un registre incomplet reste un registre, mais celui qui
|
||||
// le présente doit savoir ce qui lui manque avant l'inspection.
|
||||
const pages = pdf.getPages();
|
||||
pages.forEach((current, index) => {
|
||||
current.drawText(
|
||||
[
|
||||
`Page ${index + 1} sur ${pages.length}`,
|
||||
`${data.people.length} ligne${data.people.length > 1 ? 's' : ''}`,
|
||||
data.incomplete > 0
|
||||
? `${data.incomplete} dossier${data.incomplete > 1 ? 's' : ''} incomplet${data.incomplete > 1 ? 's' : ''}`
|
||||
: 'Mentions complètes',
|
||||
].join(' · '),
|
||||
{ x: MARGIN, y: MARGIN - 12, size: 7, font: regular, color: faint },
|
||||
);
|
||||
});
|
||||
|
||||
return pdf.save();
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import 'server-only';
|
||||
|
||||
import { cache } from 'react';
|
||||
|
||||
import type { RupPerson } from '@/domain/legal/rup';
|
||||
import { peopleWithGaps } from '@/domain/legal/rup';
|
||||
import { query } from '@/server/context';
|
||||
import { contractLabel } from '@/server/employees/queries';
|
||||
|
||||
/**
|
||||
* Registre unique du personnel — lecture.
|
||||
*
|
||||
* Le registre porte **tous** ceux qui ont été employés dans l'établissement,
|
||||
* y compris les partis : c'est précisément l'historique que l'inspection vient
|
||||
* chercher. Filtrer sur les présents en ferait un trombinoscope.
|
||||
*/
|
||||
|
||||
export interface RupData {
|
||||
locationId: string;
|
||||
locationName: string;
|
||||
siret: string | null;
|
||||
people: RupPerson[];
|
||||
/** Nombre de salariés à qui il manque au moins une mention obligatoire. */
|
||||
incomplete: number;
|
||||
}
|
||||
|
||||
export const getRegisterData = cache(async function getRegisterData(
|
||||
locationId: string,
|
||||
): Promise<RupData | null> {
|
||||
return query('members.register.export', async (db) => {
|
||||
const location = await db.location.findUnique({
|
||||
where: { id: locationId },
|
||||
select: { id: true, name: true, siret: true },
|
||||
});
|
||||
if (!location) return null;
|
||||
|
||||
const contracts = await db.userContract.findMany({
|
||||
where: { locationId },
|
||||
orderBy: { startDate: 'asc' },
|
||||
include: {
|
||||
membership: {
|
||||
select: {
|
||||
profile: {
|
||||
select: {
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
nationality: true,
|
||||
birthDate: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const jobTitleIds = [
|
||||
...new Set(
|
||||
contracts
|
||||
.map((contract) => contract.jobTitleId)
|
||||
.filter((id): id is string => Boolean(id)),
|
||||
),
|
||||
];
|
||||
const jobTitles = await db.jobTitle.findMany({
|
||||
where: { id: { in: jobTitleIds } },
|
||||
select: { id: true, name: true },
|
||||
});
|
||||
const jobTitleNames = new Map(
|
||||
jobTitles.map((entry) => [entry.id, entry.name]),
|
||||
);
|
||||
|
||||
// Une ligne par contrat, pas par personne : un salarié réembauché a deux
|
||||
// entrées et deux sorties, et les fondre effacerait l'interruption.
|
||||
const people: RupPerson[] = contracts.map((contract) => ({
|
||||
lastName: contract.membership.profile?.lastName ?? '',
|
||||
firstName: contract.membership.profile?.firstName ?? '',
|
||||
// PlanFlow ne collecte pas le sexe : la mention est exigée, la colonne
|
||||
// reste donc vide et le décompte des dossiers incomplets le signale.
|
||||
sex: null,
|
||||
nationality: contract.membership.profile?.nationality ?? null,
|
||||
birthDate: contract.membership.profile?.birthDate ?? null,
|
||||
jobTitle: contract.jobTitleId
|
||||
? (jobTitleNames.get(contract.jobTitleId) ?? null)
|
||||
: null,
|
||||
qualification: contract.classification,
|
||||
contractLabel: contractLabel(contract.contractType),
|
||||
entryDate: contract.startDate,
|
||||
exitDate: contract.endDate,
|
||||
}));
|
||||
|
||||
return {
|
||||
locationId: location.id,
|
||||
locationName: location.name,
|
||||
siret: location.siret,
|
||||
people,
|
||||
incomplete: peopleWithGaps(people),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
/** Établissements pour lesquels un registre peut être tiré. */
|
||||
export const listRegisterLocations = cache(
|
||||
async function listRegisterLocations(): Promise<
|
||||
Array<{ id: string; name: string; incomplete: number; total: number }>
|
||||
> {
|
||||
return query('members.register.export', async (db) => {
|
||||
const locations = await db.location.findMany({
|
||||
where: { archivedAt: null },
|
||||
select: { id: true, name: true },
|
||||
orderBy: { name: 'asc' },
|
||||
});
|
||||
|
||||
// Le décompte des manques est calculé ici pour que l'écran puisse
|
||||
// avertir **avant** le téléchargement : découvrir un registre incomplet
|
||||
// en l'ouvrant, c'est le découvrir devant l'inspection.
|
||||
return Promise.all(
|
||||
locations.map(async (location) => {
|
||||
const contracts = await db.userContract.findMany({
|
||||
where: { locationId: location.id },
|
||||
select: {
|
||||
classification: true,
|
||||
jobTitleId: true,
|
||||
contractType: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
membership: {
|
||||
select: {
|
||||
profile: {
|
||||
select: {
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
nationality: true,
|
||||
birthDate: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const people: RupPerson[] = contracts.map((contract) => ({
|
||||
lastName: contract.membership.profile?.lastName ?? '',
|
||||
firstName: contract.membership.profile?.firstName ?? '',
|
||||
sex: null,
|
||||
nationality: contract.membership.profile?.nationality ?? null,
|
||||
birthDate: contract.membership.profile?.birthDate ?? null,
|
||||
jobTitle: contract.jobTitleId ? 'x' : null,
|
||||
qualification: contract.classification,
|
||||
contractLabel: contractLabel(contract.contractType),
|
||||
entryDate: contract.startDate,
|
||||
exitDate: contract.endDate,
|
||||
}));
|
||||
|
||||
return {
|
||||
id: location.id,
|
||||
name: location.name,
|
||||
incomplete: peopleWithGaps(people),
|
||||
total: people.length,
|
||||
};
|
||||
}),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user