Files
CRM_Scripts_NVKH/code-current/scripts/Visitatie - Bewaken voortgang proces.js
T
2026-08-28 12:28:39 +02:00

180 lines
7.0 KiB
JavaScript

// last execution: 2026-08-25 07:00:02
logAdd(log);
html = '';
$dagen_limiet = configGet('visitatie-dagen-voor-invullen-formulier');
logAdd(log, 'info', "Dagen limiet voor invullen formulier: ", $dagen_limiet);
// Check de huidige gevisiteerden die nog geen formulier hebben teruggestuurd
$wacht_op_formulier = Entity\GetMany('Visitatie', 10000, 'lidnummer', 'asc',
'resultaat=', 'VP'
);
$i = 0;
$n = array\length($wacht_op_formulier);
$n_wacht_op_formulier = $n;
logAdd(log, 'info', $n_wacht_op_formulier, ' - visitaties uitstaan die op formulier wachten');
$formulier_te_laat = "";
$f_count = 0;
while($i < $n,
$v = array\at($wacht_op_formulier, $i);
$datum = attr($v, 'visitatiedatum');
$datum_limiet = datetime\addDays(datetime\now(), $dagen_limiet);
ifThen($datum < $datum_limiet,
$rec_id = attr($v, 'id');
$contact_id = attr($v, 'contactId');
$lidnr = attr($v, 'lidnummer');
ifThenElse($contact_id,
logAdd(log, 'info', 'Visitatie record: ', $rec_id, ', voor lid: ', $lidnr);
$lid = entity\get('Contact', $contact_id);
$visiteur = entity\get('Contact', attr($v, 'visiteurId'));
$lid_name = attr($lid, 'name');
$lid_email = attr($lid, 'emailAddress');
$lid_phone = attr($lid, 'phoneNumber');
$v_name = attr($visiteur, 'name');
$v_email = attr($visiteur, 'emailAddress');
$days = datetime\diff($datum_limiet, $datum, 'days');
$row = string\concatenate("<li>",
'lid: <a href="mailto:', $lid_email, '" >', $lid_name, '</a>',
', tel: ', $lid_phone,
', dagen te laat: ', $days,
', visiteur: <a href="mailto:', $v_email, '" >', $v_name, '</a>, ',
', zie lid <a href="/#Contact/view/', $contact_id, '">', $lidnr, '</a> of ',
', <a href="/#Visitatie/view/',$rec_id, '">visitatie record</a>',
'</li>', "\n"
);
strAdd($formulier_te_laat, $row);
$f_count = $f_count + 1;
,
$row = string\concatenate("<li>",
"<span style=\"color: red;\">Visitatie record heeft geen gekoppeld lid, corrigeer of verwijder dit ",
"<b><a style=\"color: red;\"> href=\"/#Visitatie/view/", $rec_id, "\">visitatie record</a></b>.</span>",
"</li>"
);
strAdd($formulier_te_laat, $row);
logAdd(log, 'warning', 'Visitatie record: ', $rec_id, ', met lidnummer: ', $lidnr, ', er is geen gekoppeld lid gevonden');
);
);
$i = $i + 1;
);
// Proces stokt
$limiet_visitatie = configGet('visitatie-dagen-voor-visitatieproces');
logAdd(log, 'info', "Dagen limiet voor visitatieproces: ", $limiet_visitatie);
$proces_stokt = "";
$p_count = 0;
$wacht_op_proces = Entity\GetMany('Visitatie', 10000, 'lidnummer', 'asc',
'resultaat=', 'FRVG'
);
$i = 0;
$n = array\length($wacht_op_proces);
$n_wacht_op_proces = $n;
logAdd(log, 'info', $n_wacht_op_proces, ' - visitaties uitstaan die op visitatieproces wachten');
while($i < $n,
$v = array\at($wacht_op_proces, $i);
$datum = attr($v, 'visitatiedatum');
$datum_limiet = datetime\addDays(datetime\now(), -1 * $limiet_visitatie);
ifThen($datum < $datum_limiet,
$contact_id = attr($v, 'contactId');
$rec_id = attr($v, 'id');
$lidnr = attr($v, 'lidnummer');
ifThenElse($contact_id,
logAdd(log, 'info', 'Visitatie record: ', $rec_id, ', voor lid: ', $lidnr);
$lid = entity\get('Contact', $contact_id);
$visiteur = entity\get('Contact', attr($v, 'visiteurId'));
$lid_name = attr($lid, 'name');
$lid_email = attr($lid, 'emailAddress');
$lid_phone = attr($lid, 'phoneNumber');
$v_name = attr($visiteur, 'name');
$v_email = attr($visiteur, 'emailAddress');
$days = datetime\diff($datum_limiet, $datum, 'days');
$row = string\concatenate("<li>",
'lid: <a href="mailto:', $lid_email, '" >', $lid_name, '</a>',
', tel: ', $lid_phone,
', dagen te laat: ', $days,
', visiteur: <a href="mailto:', $v_email, '" >', $v_name, '</a>',
', zie lid <a href="/#Contact/view/', $contact_id, '">', $lidnr, '</a> of ',
', <a href="/#Visitatie/view/',$rec_id, '">visitatie record</a>',
'</li>', "\n"
);
strAdd($proces_stokt, $row);
$p_count = $p_count + 1;
,
$row = string\concatenate("<li>",
"<span style=\"color: red;\">Visitatie record heeft geen gekoppeld lid, corrigeer of verwijder dit ",
"<a href=\"/#Visitatie/view/", $rec_id, "\">visitatie record</a>.</span>",
"</li>"
);
strAdd($proces_stokt, $row);
logAdd(log, 'warning', 'Visitatie record: ', $rec_id, ', met lidnummer: ', $lidnr, ', er is geen gekoppeld lid gevonden');
);
);
$i = $i + 1;
);
// Verstuur de email
logAdd(log, 'info', 'Formulieren te laat: ', $f_count);
logAdd(log, 'info', 'Proces stokt: ', $p_count);
$t_count = $p_count + $f_count;
ifThenElse($t_count > 0,
$me = entity\this();
$email = attr($me, 'emailTemplate');
ifThenElse($f_count ==0,
$formulier_te_laat = '<ul><li>Geen.</li></ul>';
,
$formulier_te_laat = string\concatenate('<ul>', $formulier_te_laat, '</ul>');
);
$email = string\replace($email, '{{visitatieformulier-te-laat}}', $formulier_te_laat);
ifThenElse($p_count ==0,
$proces_stokt = '<ul><li>Geen.</li></ul>';
,
$proces_stokt = string\concatenate('<ul>', $proces_stokt, '</ul>');
);
$email = string\replace($email, '{{visitatie-proces-stokt}}', $proces_stokt);
$userId = env\userAttribute('id');
$emailadres = configGet('secretariaat-email-address');
$emailId = record\create('Email',
'subject', 'Rapportage Vertragingen Visitatieproces',
'body', $email,
'to', $emailadres,
'assignedUser', $userId,
'isUser', true,
'parentType', 'User',
'parentId', $userId
);
ext\email\send($emailId);
logAdd(log, 'info', 'eMail verstuurd naar ', $emailadres);
,
logAdd(log, 'info', 'Geen vertragingen in het visitatieproces');
);