This commit is contained in:
2026-08-28 12:27:35 +02:00
parent bfeff94be7
commit 45e62fda5f
178 changed files with 10 additions and 7257 deletions
@@ -1,215 +0,0 @@
// last execution: Tue Jul 07 2026 10:09:08 GMT+0200 (Midden-Europese zomertijd)
//ex last execution: Sat Jan 16 2021 16:45:52 GMT+0100 (Midden-Europese standaardtijd)
logAdd(log);
logAdd(log, 'info', 'Aanmaken Excel Exports');
$leden = record\fetchManyHash('Contact', 'name, lidnummer', 'lastName', 'asc', 'regiocode<=', '10');
$js_leden = '';
$n = array\length($leden);
$i = 0;
while($i < $n,
$obj = array\at($leden, $i);
$naam = hash\get($obj, 'name');
$lidnr = hash\get($obj, 'lidnummer');
$naam = string\replace($naam, "'", "\'");
ifThen($i > 0, strAdd($js_leden, ', '));
strAdd($js_leden, "['", $naam, "', '", $lidnr, "']");
$i = $i + 1;
);
logAdd(log, 'info', $n, ' leden');
$func_name = "exportFiles_";
$func_name = string\concatenate($func_name, number\randomInt());
$h = "";
strAdd($h, '<script nonce="7tgetfwru8">', "\n");
strAdd($h, 'function ',$func_name, '() { ', "\n");
strAdd($h, "console.log('exporteren presentielijsten');");
strAdd($h, 'var leden = [', $js_leden, '];', "\n");
$nascholingen = entity\getRelated(Entity\this(), 'nascholingen', 1000, 'name', 'asc');
$n = array\length($nascholingen);
$aantal_nascholingen = $n;
$i = 0;
while($i < $n,
$nascholing = array\at($nascholingen, $i);
$nascholing_id = attr($nascholing, 'id');
$code = attr($nascholing, 'code');
$naam = attr($nascholing, 'name');
$datum = attr($nascholing, 'datum');
$einde = attr($nascholing, 'eindDatum');
$fn_name = string\replace($naam, " ", "_");
$fn_name = string\replace($fn_name, ".", "_");
$fn_name = string\replace($fn_name, "(", "_");
$fn_name = string\replace($fn_name, ")", "_");
$datum_rows = record\fetchRelatedManyHash('Nascholing', $nascholing_id, 'nascholingsDatums', 'datum', 'datum', 'asc');
$datums = list();
$k = 0;
$days = array\length($datum_rows);
logAdd(log, 'info', 'datum: ', $datum, ', eind datum: ', $einde, ', dagen: ', $days);
while ($k < $days,
$datum_row = array\at($datum_rows, $k);
$dat = hash\Get($datum_row, 'datum');
$datums = array\push($datums, $dat);
$k = $k + 1;
);
$k = 0;
$dates = '';
$comma = '';
while($k < $days,
$dt = array\at($datums, $k);
strAdd($dates, $comma, "new Date('", $dt, "')");
$k = $k + 1;
$comma = ',';
);
logAdd(log, 'info', 'dates: ', $dates);
strAdd($h, "{", "\n");
// Data
strAdd($h, ' var data = leden.map(function(x) { return x; });', "\n");
strAdd($h, " data.unshift(['Naam', 'Lidnummer', ",$dates, "]);");
strAdd($h, ' data.unshift([]);', "\n");
strAdd($h, " data.unshift(['Gebruik een X om aan te kruizen of een lid aanwezig is, vul anders niets in.']);");
strAdd($h, ' data.unshift([]);', "\n");
strAdd($h, " data.unshift(['Nascholing', '", $code, "', '", $naam, "']);", "\n");
strAdd($h, " data.unshift(['Presentielijst', 'Nascholingsdatum:', new Date('", $datum, "'), 't/m', new Date('",$einde, "')]);", "\n");
strAdd($h, " var ws_name = 'Presentielijst';", "\n");
strAdd($h, " var filename = 'Presentielijst-", $datum, "-", $fn_name, ".xlsx';", "\n");
strAdd($h, " var wb = new ExcelJS.Workbook();", "\n");
strAdd($h, " var ws = wb.addWorksheet(ws_name);", "\n");
strAdd($h, " ws.getColumn(1).width = 40;", "\n");
strAdd($h, " ws.getColumn(2).width = 18;", "\n");
strAdd($h, " ws.getColumn(3).width = 12;", "\n");
strAdd($h, " ws.getColumn(4).width = 12;", "\n");
strAdd($h, " ws.getColumn(5).width = 12;", "\n");
$k = 0;
while($k < $days,
strAdd($h, " ws.getColumn(3 + ", $k, ").width = 12;", "\n");
$k = $k + 1;
);
strAdd($h, " var i;", "\n");
strAdd($h, " for(i = 0; i < data.length; i++) {", "\n");
strAdd($h, " var row = ws.getRow(i + 1);", "\n");
strAdd($h, " var j;", "\n");
strAdd($h, " var r = data[i];", "\n");
strAdd($h, " for(j = 0; j < r.length; j++) {", "\n");
strAdd($h, " row.getCell(j + 1).value = r[j];", "\n");
strAdd($h, " }", "\n");
strAdd($h, " }", "\n");
// Formatting
strAdd($h, " ws.getCell('C1').alignment = { horizontal:'left' };", "\n");
strAdd($h, " ws.getCell('A1').font = { name: 'Arial', size:14, bold:true };", "\n");
strAdd($h, " ws.getCell('A2').font = { name: 'Arial', bold:true };", "\n");
strAdd($h, " ws.getCell('D1').alignment = { horizontal:'center' };", "\n");
strAdd($h, " ws.getCell('A6').font = { name: 'Arial', bold: true };", "\n");
strAdd($h, " ws.getCell('B6').font = { name: 'Arial', bold: true };", "\n");
$k = 0;
while($k < $days,
strAdd($h, " ws.getCell(String.fromCharCode(67 + ",$k,") + '6').font = { name: 'Arial', bold: true };", "\n");
$k = $k + 1;
);
strAdd($h, " for(i = 0; i < leden.length; i++) {", "\n");
strAdd($h, " ws.getCell('B' + (i + 6)).alignment = { horizontal:'center' };", "\n");
$k = 0;
while($k < $days,
strAdd($h, " ws.getCell(String.fromCharCode(67 + ", $k, ") + (i + 6)).alignment = { horizontal:'center' };", "\n");
$k = $k + 1;
);
//strAdd($h, " ws.getCell('C' + (i + 6)).alignment = { horizontal:'center' };", "\n");
strAdd($h, " }","\n");
// Conditional formatting
$formulae = "'OR('";
$k = 0;
$comma = '';
while($k < $days,
strAdd($formulae, "+'", $comma, "$' + String.fromCharCode(67 + ", $k, ") + '7=\"X\"'");
$comma = ';';
strAdd($formulae, "+'", $comma, "$' + String.fromCharCode(67 + ", $k, ") + '7=\"x\"'");
$k = $k + 1;
);
strAdd($formulae, "+')'");
$k = 0;
while($k < $days,
$formulae = string\concatenate("'$' + String.fromCharCode(67 + ", $k, ") + '7=\"X\"'");
strAdd($h, " ws.addConditionalFormatting({", "\n");
strAdd($h, " ref: 'A7:' + String.fromCharCode(67 + ", $days - 1, ") + (leden.length + 7), ", "\n");
strAdd($h, " rules: [ { type: 'expression', formulae: [", $formulae, "], ", "\n");
strAdd($h, " style: {fill: {type: 'pattern', pattern: 'solid', bgColor: {argb: 'FF82F59F'}}}", "\n");
strAdd($h, " }]", "\n");
strAdd($h, " });", "\n");
$k = $k + 1;
);
// Output to file
strAdd($h, " var wrt = function(fn, wb) {", "\n");
strAdd($h, " wb.xlsx.writeBuffer().then(function(data) {", "\n");
strAdd($h, " const blob = new Blob([data], ", "\n");
strAdd($h, " { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });", "\n");
strAdd($h, " const url = window.URL.createObjectURL(blob);", "\n");
strAdd($h, " const anchor = document.createElement('a');", "\n");
//strAdd($h, " anchor.style.display='none';", "\n");
strAdd($h, " document.body.appendChild(anchor);", "\n");
strAdd($h, " anchor.href = url;", "\n");
strAdd($h, " anchor.download = fn;", "\n");
strAdd($h, " console.log(fn);", "\n");
strAdd($h, " anchor.click();", "\n");
//strAdd($h, " window.URL.revokeObjectURL(url);", "\n");
strAdd($h, " });", "\n");
strAdd($h, " };", "\n");
strAdd($h, "wrt(filename, wb);", "\n");
// End
strAdd($h, "console.log(filename);");
strAdd($h, "}", "\n");
$i = $i + 1;
);
strAdd($h, "}", "\n");
strAdd($h, "</script>", "\n");
logAdd(log, 'info', 'Export button');
ifThenElse($aantal_nascholingen == 0,
strAdd($h, "<h1>Presentielijsten maken</h1>");
strAdd($h, "Selecteer 1 of meer geaccrediteerde nascholingen om lijsten voor te maken.");
,
strAdd($h, "<h1>Presentielijsten maken</h1>");
$pl = "presentielijsten";
ifThen($aantal_nascholingen == 1, $pl = "presentielijst");
$button_id = "jdkerehnsmrletjkrk%34js";
strAdd($h, '<button id="', $button_id, '">');
strAdd($h, " Download ", $aantal_nascholingen, " ", $pl);
strAdd($h, "</button>");
strAdd($h, '<script nonce="7tgetfwru8">', "\n");
strAdd($h, ' { let button_el = document.getElementById(\'', $button_id, '\');', "\n");
strAdd($h, ' console.log(button_el);', "\n");
strAdd($h, ' $(button_el).on(\'click\', ', $func_name, ');', "\n");
strAdd($h, ' }', "\n");
//strAdd($h, ' $("#" + \'', $button_id, '\').on(\'click\', ', $func_name, ');', "\n");
strAdd($h, '</script>', "\n");
);
logAdd(log, 'info', 'setting html');
html = $h;
logAdd(log, 'info', 'done');