Files
2026-08-28 12:28:39 +02:00

464 lines
18 KiB
JavaScript

// last execution: Tue Oct 01 2024 15:18:51 GMT+0200 (Midden-Europese zomertijd)
$par_hooked_formula_test=true;
$par_test_pdf_and_mail=true;
$par_espocrm_version=list('8', '-', '6', '7');
$par_tabel_rijen_per_pagina=20;
$espocrm_ver = array\at($par_espocrm_version, 0);
$aantal_rijen_op_een_pagina = $par_tabel_rijen_per_pagina;
// Constanten
$h_col = "#b3ccff";
$hh_col = "#b3ffb3";
$t_col = "#ffff99";
$test_email = 'hans@dijkewijk.nl';
// Test script
log('warning', '00 Testscript Upgrade');
logAdd(log);
logAdd(log, $hh_col, '00 Testscript Upgrade');
ifThenElse($espocrm_ver == '-',
logAdd(log, 'info', 'Log cleared, run script with other version than "-"');
html = '';
logAdd(log, 'info', 'HTML Report cleared');
,
// Hooked formula tests
ifThen($par_hooked_formula_test,
logAdd(log, $hh_col, 'Testing Hooked Formulas');
// Record\FetchManyHash
logAdd(log, $h_col, 'Record\FetchManyHash');
$rows = record\FetchManyHash('Contact', 'id, lidnummer, name, regiocode, datumRegistratie', 'name', 'asc');
$n = array\length($rows);
logAdd(log, 'info', 'FetchManyHash: ', $n);
$rows = record\FetchManyHash('Contact', 'id, lidnummer, name', 'name', 'asc', 'lidnummer=', 1935);
$n = array\length($rows);
logAdd(log, 'info', 'FetchManyHash: ', $n);
$contact = array\at($rows, 0);
$contact_id = hash\get($contact, 'id');
logAdd(log, 'info', 'id = ', hash\get($contact, 'id'));
logAdd(log, 'info', 'contact name: ', hash\get($contact, 'name'), ' nummer: ', hash\get($contact, 'lidnummer'), ', id = ', $contact_id);
// Record\FindMany
logAdd(log, 'warning', 'Record\FindMany, While, Entity\Get, Attr');
$rows = record\FindMany('Contact', 'name', 'asc', 'lidnummer>=', 1930, 'lidnummer<=', 1940);
$n = array\length($rows);
logAdd(log, 'info', 'FetchManyHash: ', $n);
$i = 0;
while($i < $n,
$c = Entity\Get('Contact', array\at($rows, $i));
logAdd(log, 'info', '--contact: ', attr($c, 'name'), ', nummer: ', attr($c, 'lidnummer'));
$i = $i + 1;
);
// EntityGroup
logAdd(log, $h_col, 'EntityGroup');
// Entity Functions
logAdd(log, $t_col, 'Entity\GetMany, SetAttr');
$entities = Entity\GetMany('Contact', 10, 'lidnummer', 'asc', 'lidnummer=', 1935);
$c = array\at($entities, 0);
$id = attr($c, 'id');
logAdd(log, 'info', 'contact c: id = ', $id);
logAdd(log, $t_col, 'Entity\Get');
$c_orig = Entity\Get('Contact', $id);
logAdd(log, 'info', '$c_orig: ', attr($c_orig, 'lidnummer'));
logAdd(log, 'info', '--fetched entity:', attr($c, 'lidnummer'), ' opmerking: ', attr($c, 'description'));
$s = string\concatenate('opmerking nieuw: ', datetime\now());
setAttr($c, 'description', $s);
logAdd(log, $t_col, 'Entity\Save');
logAdd(log, 'info', '--updated entity:', attr($c, 'lidnummer'), ' opmerking: ', attr($c, 'description'));
entity\save($c);
logAdd(log, 'info', 'entity saved');
logAdd(log, $t_col, 'Entity\GetRelated');
$rel = Entity\GetRelated($c, 'dossierdocumenten', 1000, 'name', 'asc');
$i = 0;
while($i < array\length($rel),
$account = array\at($rel, $i);
logAdd(log, 'info', $i, ': ', attr($account, 'name'));
$i = $i + 1;
);
logAdd(log, $t_col, 'Entity\This');
$e = entity\this();
logAdd(log, 'info', '--Entity\This->name = ', attr($e, 'name'));
// Config
logAdd(log, $h_col, 'Config');
logAdd(log, 'Config functions - clearing cache');
ConfigClearCache();
logAdd(log, 'config_exists hoi: ', ConfigExists('hoi'));
logAdd(log, 'config_exists visitatie-geldigheid-in-jaren: ', ConfigExists('visitatie-geldigheid-in-jaren'));
ConfigInc('visitatie-geldigheid-in-jaren');
logAdd(log, 'config_get visitatie-geldigheid-in-jaren: ', ConfigGet('visitatie-geldigheid-in-jaren'));
ConfigSet('visitatie-geldigheid-in-jaren', 5);
logAdd(log, 'config_get visitatie-geldigheid-in-jaren: ', ConfigGet('visitatie-geldigheid-in-jaren'));
// StrAdd
logAdd(log, $h_col, 'StrAdd functions');
$str = "Hoi";
logAdd(log, $str);
strAdd($str, ' Hans');
logAdd(log, 'warning', $str);
// exec
logAdd(log, $h_col, 'Exec functions');
$script = '$i = $i +1;logAdd(log, "increasing value to ", $i)';
$i = 0;
Exec($script);
Exec($script);
// Conversion
logAdd(log, $h_col, 'Conversion');
$a = '20';
logAdd(log, '(int) $a = ', toInt($a));
logAdd(log, '(double) $a = ', toDouble($a));
$b = toDouble($a);
$b = $b + 0.1;
logAdd(log, '(string) $b = ', toString($b));
// To Json file
logAdd(log, $h_col, 'ToJsonFile');
logAdd(log, 'toJsonFile: ', toJsonFile('000_upgrade_test.json', $c));
// Diff
logAdd(log, 'warning', 'Diff');
logAdd(log, 'diff: ', Diff($c_orig, $c));
// ArrayGroup
logAdd(log, $h_col, 'ArrayGroup');
logAdd(log, $t_col, 'Array\Set');
$a = list(10, 20, 30);
logAdd(log, 'info', '$a[1] = ', array\at($a, 1));
$a1 = array\at($a, 1) * 2.3;
logAdd(log, 'info', '$a1 = ', $a1);
$a = array\set($a, 1, $a1);
logAdd(log, 'info', '$a[1] = ', array\at($a, 1));
// ExtGroup
logAdd(log, $h_col, 'ExtGroup');
logAdd(log, $t_col, 'Ext\Htmlize');
$body = '<html><head></head><body>Beste {{name}},<br><br>Dit is een test voor {{today}}.</body></html>';
logAdd(log, 'info', $body);
$body = ext\htmlize($body, 'Contact', attr($c, 'id'));
logAdd(log, 'info', $body);
logAdd(log, $t_col, 'Ext\Begin, Ext\Commit');
Ext\Begin();
Entity\Save($c);
Entity\Save($c);
Ext\Commit();
logAdd(log, $t_col, 'Ext\CopyFile');
$icons = Entity\GetMany('StandaardIcon', 1, 'name', 'asc');
$icon_doc = array\at($icons, 0);
$file_id = attr($icon_doc, 'iconId');
logAdd(log, 'info', 'Standaard Icon = ', attr($icon_doc, 'name '), ', File Id = ', $file_id);
$file_id_copy = Ext\CopyFile($file_id, Entity\This());
logAdd(log, 'info', 'Copied Attachement = ', $file_id_copy);
logAdd(log, 'info', 'Deleting created attachement');
//Record\Delete('Attachment', $file_id_copy); // Vanaf EspoCRM 7.4
ifThen($par_test_pdf_and_mail,
// ExtGroup\PdfGroup
logAdd(log, $h_col, 'Ext\PdfGroup');
logAdd(log, $t_col, 'Ext\Pdf\PdfFillIn');
log('warning', 'Ext\Pdf\PdfFillIn');
$visitatie_formulier_id = configGet('visitatie-formulier');
$formulier_id = $visitatie_formulier_id;
$lid = $c;
log('warning', 'Lid: ', attr($lid, 'lidnummer'));
$praktijken = Entity\GetRelated($c, 'accounts', 1, 'name', 'asc');
log('warning', 'praktijken: ', array\length($praktijken));
$pr = array\at($praktijken, 0);
$lid_id = attr($c, 'contact_id');
$lid_nr = attr($c, 'lidnummer');
$lid_name = attr($c, 'name');
logAdd(log, 'warning', '$lid_name = ', $lid_name);
log('warning', '$lid_name = ', $lid_name);
$form_out = string\concatenate('visitatie-vragenlijst-', $lid_nr, '.pdf');
$visitatiedatum = '27-08-2024';
$two_weeks_before_visitatiedatum = '01-08-2024';
$visitatietijdstip = '12:03';
$visitatienummer = '12345';
$visiteurname = 'Liesbeth Kruyswijk';
$nvkh_afzender = 'sysadm@nvkh.nl';
$visitatie_wacht_dagen = 10;
logAdd(log, 'info', 'visitatie vragenformulier avar document : ', $form_out);
$attach_id = ext\pdf\fillin('Contact', $lid_id, $formulier_id, $form_out,
'naam_homeopaat', attr($lid, 'name'),
'naam_gevisiteerde', attr($lid, 'name'),
'AVAR_Visitatienummer', $visitatie_nummer,
'ondertekening_naam_gevisiteerde', attr($lid, 'name'),
'email_homeopaat', $email,
'naam_praktijk', attr($pr, 'naam'),
'agb_praktijk', attr($pr, 'agbcode'),
'rbcz_nummer', attr($lid, 'rbcznummer'),
'nvkh_nummer', attr($lid, 'lidnummer'),
'adres_praktijk_straat', attr($pr, 'shippingAddressStreet'),
'adres_praktijk_postcode', attr($pr, 'shippingAddressPostalCode'),
'adres_praktijk_plaats', attr($pr, 'shippingAddressCity'),
'agb_persoonlijk', attr($lid, 'agbcode'),
'datum_mbk_of_big', $mbkdatum,
'datum_vog', $vogdatum,
'email_retouradres', $retouradres,
'tel_prive', attr($lid, 'phoneNumber'),
'tel_praktijk', attr($pr, 'phoneNumber'),
'websites', attr($pr, 'website'),
'datum_diploma_vakopleiding', $diplomadatum,
'bijscholingsdagen_laatste_jaren', $bijscholing,
'datum_nascholing_big', 'Nvt',
'datum_visitatie', $visitatiedatum,
'tijdstip_visitatie', $visitatietijdstip,
'AVAR_Visitatienummer', $visitatienummer
);
logAdd(log, 'info', 'attachment id :', $attach_id);
$body = configGet('visitatie-informatie-email');
$scr_fnln = configGet('script-to-firstname-lastname');
$param_name = $lid_name;
logAdd(log, 'info', 'lid: ', $param_name);
exec($scr_fnln);
$lid_name = $val_fn_ln;
logAdd(log, 'info', 'lid_name: ', $lid_name);
$param_name = $visiteur_name;
exec($scr_fnln);
$visiteur_name = $val_fn_ln;
$emailadres = $test_email;
$secretariaat_email = 'secretariaat@nvkh.nl';
$visitatie_dt = datetime\format(datetime\now(), 'Europe/Amsterdam', 'DD/MM/YYYY');
logAdd(log, 'repl1');log('warning', 'repl1');
$body = string\replace($body, '{{visitatie-datum}}', $visitatie_dt);
logAdd(log, 'repl2');log('warning', 'repl2');
$body = string\replace($body, '{{visitatie-tijdstip}}', $visitatietijdstip);
logAdd(log, 'repl3');log('warning', 'repl3');
$body = string\replace($body, '{{visitatie-nummer}}', $visitatienummer);
logAdd(log, 'repl4');log('warning', 'repl4');
$body = string\replace($body, '{{nvkh-afzender}}', $nvkh_afzender);
logAdd(log, 'repl5');log('warning', 'repl5');
$body = string\replace($body, '{{visiteur}}', $visiteur_name);
logAdd(log, 'repl6');log('warning', 'repl6');
$body = string\replace($body, '{{wacht-dagen}}', string\concatenate('', $visitatie_wacht_dagen));
logAdd(log, 'repl7');log('warning', 'repl7');
$body = string\replace($body, '{{retourdatum}}', $two_weeks_before_visitatiedatum);
logAdd(log, 'repl8');log('warning', 'repl8');
$body = string\replace($body, '{{secretariaat-adres}}', $secretariaat_email);
logAdd(log, 'repl9');log('warning', 'repl9');
$body = string\replace($body, '{{lid-naam}}', $lid_name);
logAdd(log, 'replA');log('warning', 'replA');
$body = ext\htmlize($body, 'Contact', attr($lid, 'id'));
$userId = env\userAttribute('id');
$subject = 'Upgrade Test PdfFillIn {{datum}}';
$subject = string\replace($subject, '{{datum}}', $visitatiedatum);
$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);
);
// GlobalGroup
$key = 'upgrade-test-script-global-key';
logAdd(log, 'info', 'ConfigGet for key "', $key, '"');
$cg = ConfigGet($key);
ifThenElse($cg != 0,
Global\Set($key, $cg),
Global\UnSet($key)
);
logAdd(log, $h_col, 'GlobalGroup');
logAdd(log, $t_col, 'Global\IsSet');
$is = Global\IsSet($key);
ifThenElse($is, $is = 'yes', $is = 'no');
logAdd(log, 'info', $key, ' iset = ', $is);
ifThenElse($is == 'yes',
logAdd(log, $t_col, 'Global\Get');
$v = Global\Get($key);
$v = $v + 1;
logAdd(log, $t_col, 'Global\Set');
Global\Set($key, $v);
,
logAdd(log, 'info', 'initializing ', $key, ' to 1');
$v = 1;
logAdd(log, $t_col, 'Global\Set');
Global\Set($key, $v);
);
logAdd(log, 'info', 'Key value: ', $key, ' = ', Global\Get($key));
ifThen($v > 3,
logAdd(log, 'info', 'clearing ', $key);
logAdd(log, $t_col, 'Global\UnSet');
Global\UnSet($key);
);
ifThenElse(Global\IsSet($key),
logAdd(log, 'info', $key, ' is still set');
ConfigSet($key, $v);
logAdd(log, 'warning', 'Run this test another time!');
,
logAdd(log, 'info', $key, ' is not set anymore');
ConfigSet($key, 0);
logAdd(log, 'info', 'This test is now completed.');
);
// HashGroup
logAdd(log, $h_col, 'HashGroup');
logAdd(log, $t_col, 'Hash\New');
$hash_1 = Hash\New();
logAdd(log, $t_col, 'Hash\Set');
$hash_1 = Hash\Set($hash_1, 'key', 122213);
logAdd(log, $t_col, 'Hash\Get');
$v = Hash\Get($hash_1, 'key');
logAdd(log, 'info', 'Value for "key" = ', $v);
$hash_1 = Hash\Set($hash_1, 'key2', 'HIHI');
log('warning', 'getting keys');
$keys = Hash\Keys($hash_1);
logAdd(log, $t_col, 'Hash\Keys');
$i = 0;
$n = array\length($keys);
logAdd(log, 'info', 'Number of keys: ', $n);
log('warning', 'Number of Keys: ', $n);
while($i < array\length($keys),
$key_i = array\at($keys, $i);
logAdd(log, 'info', 'key ', $i, ' = \"', $key_i, '\", value = ', hash\get($hash_1, $key_i));
$i = $i + 1;
);
logAdd(log, $t_col, 'Hash\IsSet');
logAdd(log, 'info', 'hash\isset key2: ', Hash\IsSet($hash_1, 'key2'));
ifThen($espocrm_ver != '6',
logAdd(log, $t_col, 'Hash\Copy');
$hash_2 = Hash\Copy($hash_1);
);
logAdd(log, $t_col, 'Hash\UnSet');
$hash_1 = Hash\UnSet($hash_1, 'key2');
logAdd(log, 'info', 'hash\isset($hash_1, "key2"): ', Hash\IsSet($hash_1, 'key2'));
ifThen($espocrm_ver != '6',
logAdd(log, 'info', 'hash\isset($hash_2, "key2"): ', Hash\IsSet($hash_2, 'key2'));
);
// RecordGroup
logAdd(log, $h_col, 'RecordGroup');
logAdd(log, 'info', 'Using Contact Id ', $contact_id);
logAdd(log, $t_col, 'Record\CountRel');
$count = Record\CountRel('Contact', $contact_id, 'accounts');
logAdd(log, 'info', 'Record\CountRel = ', $count);
logAdd(log, $t_col, 'Record\FetchManyHash - ALREADY TESTED');
logAdd(log, $t_col, 'Record\FindMany - ALREADY TESTED');
logAdd(log, $t_col, 'Record\Create - ALREADY TESTED');
logAdd(log, $t_col, 'Record\FetchMany');
$rows = Record\FetchMany('Contact', 'id, lidnummer', 'lidnummer', 'desc', 'lidnummer>', 1934, 'lidnummer<', 1939);
logAdd(log, 'info', 'Fetched ', array\length($rows), ' rows');
$i = 0;
while($i < array\length($rows),
$row = array\at($rows, $i);
logAdd(log, 'info', $i, ' - id = ', array\at($row, 0), ', lidnummer = ', array\at($row, 1));
$i = $i + 1;
);
logAdd(log, $t_col, 'Record\FetchRelatedMany');
$rows = Record\FetchRelatedMany('Contact', $contact_id, 'nascholingstotalen', 'id, jaar', 'jaar', 'desc', 'jaar>=', 2022);
logAdd(log, 'info', 'Fetched ', array\length($rows), ' rows');
$i = 0;
while($i < array\length($rows),
$row = array\at($rows, $i);
logAdd(log, 'info', $i, ' - id = ', array\at($row, 0), ', jaar = ', array\at($row, 1));
$i = $i + 1;
);
logAdd(log, $t_col, 'Record\FetchRelatedManyHash');
$rows = Record\FetchRelatedManyHash('Contact', $contact_id, 'nascholingstotalen', 'id, jaar', 'jaar', 'desc', 'jaar>=', 2022);
logAdd(log, 'info', 'Fetched ', array\length($rows), ' rows');
$i = 0;
while($i < array\length($rows),
$row = array\at($rows, $i);
logAdd(log, 'info', $i, ' - id = ', hash\get($row, 'id'), ', jaar = ', hash\get($row, 'jaar'));
$i = $i + 1;
);
logAdd(log, $t_col, 'Record\Recalculate');
Record\Recalculate('Contact', 'id=', $contact_id);
logAdd(log, 'warning', 'Check the EspoCRM Logs for this one');
logAdd(log, $h_col, 'StringGroup');
logAdd(log, $t_col, 'String\Tobase64');
$b64 = String\Tobase64($contact_id);
logAdd(log, 'info', 'id = ', $contact_id, ', - b64: ', $b64);
logAdd(log, $h_col, 'TableGroup');
html = '';
$p_page_len = $aantal_rijen_op_een_pagina;
$h = '';
strAdd($h, '<div class="nvkhresult">');
$table = table\new('Naam', 75,
'Lidnummer', 5, 'right',
'registratiejaar', 20, 'center'
);
table\rowsPerPage($table, $p_page_len);
table\filename($table, 'upgrade_test_tabel');
$rows = record\FetchManyHash('Contact', 'id, lidnummer, name, datumRegistratie, lastName', 'lastName', 'desc', 'lidnummer>', 1934, 'lidnummer<', 1980);
$n = array\length($rows);
$i = 0;
while($i < $n,
$row = array\at($rows, $i);
$contact_id = hash\get($row, 'id');
$name = hash\get($row, 'name');
$reg_dat = hash\get($row, 'datumRegistratie');
$reg_jaar = datetime\year($reg_dat);
$lidnummer = hash\get($row, 'lidnummer');
logAdd(log, 'info', $i, ' - id = ', $contact_id, ', name = ', $name, ', reg_jaar = ', $reg_jaar, ', lidnummer = ', $lidnummer);
table\add($table,
table\link(string\concatenate('/#Contact/view/', $contact_id), $name),
string\concatenate(' ', $lidnummer),
toString($reg_jaar)
);
$i = $i + 1;
);
$table_html = table\toHtml($table);
strAdd($h, $table_html);
strAdd($h, '</div>');
html = string\concatenate('<h1>Upgrade Testscript Report</h1>', $h);
logAdd(log, $t_col, 'Table\New, Table\Add, Table\RowsPerPage, Table\Filename, Table\toHtml, Table\Link');
logAdd(log, 'info', 'Testresult: see Report');
logAdd(log, 'warning', 'Table\Style is not tested');
);
);