74 lines
3.0 KiB
JavaScript
74 lines
3.0 KiB
JavaScript
// last execution: 2026-08-28 06:34:01
|
|
$subject_init = 'Herinnering voor visitatie op {{visitatie-datum}}';
|
|
|
|
logAdd(log);
|
|
|
|
$cfg4weken = configGet('visitatie-weken-voor-herinnering');
|
|
$over4weken = datetime\now();
|
|
$over4weken = datetime\addWeeks($over4weken, $cfg4weken);
|
|
$o4w_str = datetime\format($over4weken, 'Europe/Amsterdam', 'DD/MM/YYYY');
|
|
$formulier_limiet_dagen = configGet('visitatie-dagen-voor-invullen-formulier');
|
|
|
|
logAdd(log, 'info', 'Check of herinnering moet worden gestuurd voor visitatiedata <= ', $o4w_str);
|
|
|
|
$visitaties = record\fetchManyHash('Visitatie',
|
|
'id, resultaat, lidnummer, contactId, visitatiedatum, visiteurId, herinnerd',
|
|
'lidnummer', 'asc',
|
|
'visitatiedatum<=', $over4weken,
|
|
'resultaat=', 'VP'
|
|
);
|
|
|
|
$i = 0;
|
|
$n = array\length($visitaties);
|
|
|
|
logAdd(log, 'info', 'Aantal visitaties om te controleren: ', $n);
|
|
|
|
while($i < $n,
|
|
$item = array\at($visitaties, $i);
|
|
$id = hash\get($item, 'id');
|
|
$lidnummer = hash\get($item, 'lidnummer');
|
|
$herinnerd = hash\get($item, 'herinnerd');
|
|
$vd = hash\get($item, 'visitatiedatum');
|
|
$vd_str = datetime\format($vd, 'Europe/Amsterdam', 'DD/MM/YYYY');
|
|
|
|
ifThenElse($herinnerd,
|
|
logAdd(log, 'info', 'Lidnummer: ', $lidnummer, ', is al herinnerd voor visitatiedatum: ', $vd);
|
|
,
|
|
logAdd(log, 'info', 'Lidnummer: ', $lidnummer, ', herinneren voor visitatiedatum: ', $vd);
|
|
|
|
$lid_id = hash\get($item, 'contactId');
|
|
$lid = entity\get('Contact', $lid_id);
|
|
$visiteur = entity\get('Contact', hash\get($item, 'visiteurId'));
|
|
|
|
$fd = datetime\addDays($vd, -1 * $formulier_limiet_dagen);
|
|
$fd_str = datetime\format($fd, 'Europe/Amsterdam', 'DD/MM/YYYY');
|
|
|
|
$email = configGet('visitatie-herinneringsmail');
|
|
$email = string\replace($email, '{{lid-naam}}', attr($lid, 'name'));
|
|
$email = string\replace($email, '{{visitatie-datum}}', $vd_str);
|
|
$email = string\replace($email, '{{visiteur}}', attr($visiteur, 'name'));
|
|
$email = string\replace($email, '{{formulier-datum}}', $fd_str);
|
|
|
|
$mailadr = attr($lid, 'emailAddress');
|
|
|
|
$subject = $subject_init;
|
|
$subject = string\replace($subject, '{{visitatie-datum}}', $vd_str);
|
|
|
|
$emailId = record\create('Email',
|
|
'subject', $subject,
|
|
'body', $email,
|
|
'to', $mailadr,
|
|
'assignedUser', $userId,
|
|
'isUser', true,
|
|
'parentType', 'Contact',
|
|
'parentId', $lid_id
|
|
);
|
|
ext\email\send($emailId);
|
|
|
|
global\set('visitatie_herinneren', true);
|
|
record\update('Visitatie', $id, 'herinnerd', true);
|
|
global\unset('visitatie_herinneren');
|
|
);
|
|
|
|
$i = $i + 1;
|
|
); |