168 lines
6.7 KiB
JavaScript
168 lines
6.7 KiB
JavaScript
// last execution: Mon Jun 07 2021 11:33:11 GMT+0200 (Midden-Europese zomertijd)
|
|
|
|
$par_uitvoeren=true;
|
|
$par_test_run_geen_mail_versturen=false;
|
|
|
|
//$date_par_visitatie_datum='2021-12-02';
|
|
//$par_visitatienummer='';
|
|
//$par_praktijk_type=list('P1', 'P2', 'P3');
|
|
//$par_lid_id='';
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
// init
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
$visitatie_datum = $par_visitatie_datum;
|
|
$nvkh_afzender = configGet('nvkh-afzender');
|
|
|
|
$visitatie_certificaat_id = configGet('visitatie-certificaat');
|
|
|
|
$lid_id=$par_lid_id;
|
|
$lid = entity\get('Contact', $lid_id);
|
|
$emailadres = attr($lid, 'emailAddress');
|
|
|
|
$secretariaat_email = configGet('secretariaat-email-address');
|
|
|
|
$geldig_jaren = configGet('visitatie-geldigheid-in-jaren');
|
|
|
|
$praktijk_type = $par_praktijk_type;
|
|
$testrun = $par_test_run_geen_mail_versturen;
|
|
|
|
html = '';
|
|
|
|
log('warning', 'visitatie datum:', $visitatie_datum);
|
|
log('warning', 'emailadres:', $emailadres);
|
|
log('warning', 'nvkh afzender:', $nvkh_afzender);
|
|
log('warning', 'visitatie-certificaat-id:', $visitatie_certificaat_id);
|
|
log('warning', 'praktijk soort:', $praktijk_type);
|
|
|
|
html = '';
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
// Visitatie formulier invullen en opsturen
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ifThenElse($par_uitvoeren,
|
|
|
|
$dt = datetime\now();
|
|
$dt = datetime\format($dt, 'Europe/Amsterdam', 'YYYY-MM-DD');
|
|
|
|
$formulier = 'visitatie-certificaat';
|
|
$formulier_id = $visitatie_certificaat_id;
|
|
|
|
log('warning', 'visitatie certificaat input document : ', $formulier, ' - id : ', $formulier_id);
|
|
|
|
$leden = list($lid);
|
|
|
|
$i = 0;
|
|
$n = array\length($leden);
|
|
log('warning', 'gerelateerde leden: ', $n);
|
|
|
|
while($i < $n,
|
|
$lid = array\at($leden, $i);
|
|
$lid_nr = attr($lid, 'lidnummer');
|
|
$lid_id = attr($lid, 'id');
|
|
$achternaam = attr($lid, 'lastName');
|
|
$voorzetsel = string\trim(attr($lid, 'middleName'));
|
|
ifThen($voorzetsel != "",
|
|
$achternaam = string\concatenate($voorzetsel, '-', $achternaam);
|
|
);
|
|
|
|
$achternaam = string\trim($achternaam);
|
|
$achternaam = string\replace($achternaam, ' ', '-');
|
|
|
|
$form_out = string\concatenate('visitatie-certificaat-', $achternaam, '.pdf');
|
|
log('warning', 'visitatie certificaat output: ', $form_out);
|
|
|
|
log('warning', 'lid id: ', $lid_id, ' naam: ', attr($lid, 'name'), ', lidnummer:', $lid_nr);
|
|
|
|
$scr_toFnLn = configGet('script-to-firstname-lastname');
|
|
$param_name = attr($lid, 'name');
|
|
exec($scr_toFnLn);
|
|
$lid_naam = $val_fn_ln;
|
|
|
|
$lid_naam = string\concatenate('van ', $lid_naam, ' op');
|
|
|
|
$email = attr($lid, 'emailAddress');
|
|
|
|
$primary_account_id = record\findRelatedOne('Contact', $lid_id, 'accounts', 'name', 'asc', 'type=', $praktijk_type);
|
|
log('warning', 'praktijk[', $praktijk_type, ']: ', $primary_account_id);
|
|
|
|
ifThenElse(!$primary_account_id,
|
|
$msg = string\concatenate(attr($lid, 'name'), ' (', $lid_nr, ') voert geen praktijk van soort ', $praktijk_type);
|
|
log('warning', $msg);
|
|
strAdd(html, '<p style="color:red">', $msg, '</p>');
|
|
,
|
|
$pr = entity\get('Account', $primary_account_id);
|
|
|
|
log('warning', 'praktijk: ', attr($pr, 'naam'));
|
|
$praktijknaam = attr($pr, 'naam');
|
|
|
|
$street = attr($pr, 'shippingAddressStreet');
|
|
$city = attr($pr, 'shippingAddressCity');
|
|
$praktijkadres = string\concatenate($street, ' te ', $city);
|
|
|
|
log('warning', 'lid_id:', $lid_id, ', praktijk:', $praktijknaam,
|
|
', visitatiedatum:', $visitatiedatum, ', van:', $lid_naam,
|
|
', adres:', $praktijkadres, ', geldig_tot:', $geldig_tot);
|
|
|
|
$visitatiedatum = '';
|
|
ifThen($visitatie_datum,
|
|
$visitatiedatum = datetime\format($visitatie_datum, 'Europe/Amsterdam', 'DD-MM-YYYY');
|
|
);
|
|
|
|
$geldig_tot = datetime\addYears($visitatie_datum, $geldig_jaren);
|
|
$gdt = datetime\format($geldig_tot, 'Europe/Amsterdam', 'D MMM YYYY');
|
|
$geldig_tot = string\concatenate('Dit certificaat is geldig tot ', $gdt);
|
|
|
|
$attach_id = ext\pdf\fillin('Contact', $lid_id,
|
|
$formulier_id, $form_out,
|
|
'praktijk', $praktijknaam,
|
|
'visitatiedatum', $visitatiedatum,
|
|
'van', $lid_naam,
|
|
'adres', $praktijkadres,
|
|
'geldig_tot', $geldig_tot
|
|
);
|
|
log('warning', 'attachment id :', $attach_id);
|
|
|
|
$body = configGet('visitatie-certificaat-email');;
|
|
|
|
$visitatie_dt = datetime\format($visitatie_datum, 'Europe/Amsterdam', 'DD/MM/YYYY');
|
|
$body = string\replace($body, '{{visitatie-datum}}', $visitatie_dt);
|
|
$body = string\replace($body, '{{nvkh-afzender}}', $nvkh_afzender);
|
|
$body = string\replace($body, '{{lid-naam}}', attr($lid, 'name'));
|
|
$body = ext\htmlize($body, 'Contact', attr($lid, 'id'));
|
|
|
|
$subject = 'Visitatie Certificaat voor visitatie d.d. {{datum}}';
|
|
$subject = string\replace($subject, '{{datum}}', $visitatie_dt);
|
|
|
|
$userId = env\userAttribute('id');
|
|
|
|
//$emailadres="sysadm@nvkh.nl";
|
|
|
|
ifThenElse($testrun,
|
|
log('warning', 'Dit is een testrun, er wordt geen email verstuurd');
|
|
,
|
|
$emailId = record\create('Email',
|
|
'subject', $subject,
|
|
'body', $body,
|
|
'to', $emailadres,
|
|
'attachmentsIds', list($attach_id),
|
|
'assignedUser', $userId,
|
|
'isUser', true,
|
|
'parentType', 'Contact',
|
|
'parentId', $lid_id
|
|
);
|
|
ext\email\send($emailId);
|
|
);
|
|
|
|
);
|
|
|
|
$i = $i + 1;
|
|
);
|
|
|
|
,
|
|
log('warning', 'Vink uitvoeren aan om dit script uit te voeren');
|
|
);
|
|
|