[FE][Certs] Button for downloading all certs of the current date
This commit is contained in:
parent
81be2fd79f
commit
a39059d74d
@ -74,9 +74,33 @@ export function Registers(props: {person: Person | null, count: number}) {
|
||||
|
||||
const inputCheck = () => setShowHidden((x) => !x);
|
||||
|
||||
const todayRegisters = createMemo(() => {
|
||||
const today = new Date().toISOString()
|
||||
.split("T")[0];
|
||||
return registerSortedList()[0][0]
|
||||
?.filter((r) => r.register_creation_date === today) ?? [];
|
||||
});
|
||||
|
||||
const downloadTodayCerts = () => {
|
||||
if (props.person === null) return;
|
||||
|
||||
todayRegisters().forEach((register) => {
|
||||
generateCert(props.person!, register);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="m-4 p-4 rounded-md relative">
|
||||
<h3 class="text-xl font-medium">
|
||||
<button
|
||||
class="bg-c-primary inline-block w-8 h-8 mr-2 rounded-full
|
||||
disabled:opacity-25 disabled:cursor-not-allowed"
|
||||
disabled={todayRegisters().length === 0}
|
||||
title="Descargar todos los cert. creados hoy"
|
||||
onclick={downloadTodayCerts}
|
||||
>
|
||||
<DownloadSimpleIcon fill="var(--c-on-primary)" size={24} />
|
||||
</button>
|
||||
{props.person?.person_names}
|
||||
{props.person?.person_paternal_surname}
|
||||
{props.person?.person_maternal_surname}
|
||||
@ -141,37 +165,10 @@ function RegisterEl(props: {register: Register, person: Person, onClick: () => v
|
||||
};
|
||||
|
||||
const genCert = () => {
|
||||
const courseN = courseName();
|
||||
const person = props.person;
|
||||
const register = props.register;
|
||||
|
||||
const generator = certGenerator[courseN];
|
||||
if (generator === undefined) {
|
||||
alert(`Generator function with key \`${courseN}\` not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
const {year, month, day} = dateComponents();
|
||||
const personFullName = `${person.person_names} ${person.person_paternal_surname} ${person.person_maternal_surname}`;
|
||||
|
||||
// Manage custom label
|
||||
const certCustomLabel = register.register_custom_label === 1
|
||||
? ""
|
||||
: customLabelsMap()[register.register_custom_label]?.custom_label_value ?? "";
|
||||
|
||||
const certCode = register.register_is_preview ? "0000" : register.register_code.toString().padStart(4, "0");
|
||||
|
||||
generator(`${courseN} - ${personFullName}.docx`, {
|
||||
matpel: null,
|
||||
personFullName,
|
||||
personDni: person.person_dni.toString(),
|
||||
certCode,
|
||||
certYear: year,
|
||||
certMonth: month,
|
||||
certDay: day,
|
||||
certIId: register.register_code,
|
||||
certCustomLabel,
|
||||
});
|
||||
generateCert(person, register);
|
||||
};
|
||||
|
||||
const generateable = () => {
|
||||
@ -240,3 +237,35 @@ function RegisterEl(props: {register: Register, person: Person, onClick: () => v
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function generateCert(person: Person, register: Register) {
|
||||
const courseN = courseMap()[register.register_course_id]?.course_name ?? "Curso no encontrado";
|
||||
|
||||
const generator = certGenerator[courseN];
|
||||
if (generator === undefined) {
|
||||
alert(`Generator function with key \`${courseN}\` not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
const [, year, month, day] = /(\d{4})-(\d{2})-(\d{2})/.exec(register.register_display_date) ?? [];
|
||||
const personFullName = `${person.person_names} ${person.person_paternal_surname} ${person.person_maternal_surname}`;
|
||||
|
||||
// Manage custom label
|
||||
const certCustomLabel = register.register_custom_label === 1
|
||||
? ""
|
||||
: customLabelsMap()[register.register_custom_label]?.custom_label_value ?? "";
|
||||
|
||||
const certCode = register.register_is_preview ? "0000" : register.register_code.toString().padStart(4, "0");
|
||||
|
||||
generator(`${courseN} - ${personFullName}.docx`, {
|
||||
matpel: null,
|
||||
personFullName,
|
||||
personDni: person.person_dni.toString(),
|
||||
certCode,
|
||||
certYear: year,
|
||||
certMonth: month,
|
||||
certDay: day,
|
||||
certIId: register.register_code,
|
||||
certCustomLabel,
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user