Files
CRM_Scripts_NVKH/code-current/scripts/Inlezen consultgegevens.js
T
2026-08-28 12:28:39 +02:00

117 lines
8.1 KiB
JavaScript

// last execution: Thu Feb 04 2021 11:28:51 GMT+0100 (Midden-Europese standaardtijd)
$csvfile_par_consultgegevens_als_csv='Lid Nummer,consulten 2019,\n1846,,\n1780,,\n1856,150,\n0045,,\n0878,200,\n1509,v,\n1697,,\n0325,,\n1316,v,\n1255,300,\n1871,,\n0600,362,\n1749,400,\n1938,,\n1055,,\n0949,,\n1885,v,\n1148,v,\n1258,65,\n1352,50,\n0982,100,\n1431,v,\n1924,v,\n0349,v,\n1849,,\n1761,155,\n1830,,\n1821,,\n0489,219,\n1940,,\n1682,v,\n1030,,\n1219,422,\n1675,93,\n1459,,\n0769,,\n0847,555,\n0871,v,\n0157,,\n1433,,\n1536,250,\n1158,,\n1621,,\n1820,112,\n1926,,\n0395,61,\n1436,,\n1880,,\n1896,18,\n1716,617,\n1799,,\n0220,584,\n1883,,\n1640,,\n1628,191,\n0723,,\n1242,,\n1914,168,\n0038,,\n1003,400,\n1762,,\n1256,,\n1718,304,\n1487,v,\n1259,,\n0049,212,\n1362,150,\n1706,352,\n1784,37,\n1274,v,\n1579,v,\n1547,,\n1565,,\n1001,200,\n1500,v, \n1790,33,\n1357,177,\n1727,,\n0751,520,\n1892,,\n0293,,\n1239,,\n0191,459,\n0257,v, \n1329,,\n1512,v,\n0853,,\n1842,62,\n1143,651,\n1935,40,\n1387,,\n1585,,\n0985,,\n1002,104,\n0265,760,\n0669,900,\n1872,24,\n1569,201,\n0743,,\n0577,185,\n1495,65,\n1643,90,\n1794,v,\n1750,208,\n1841,,\n1932,,\n0729,188,\n1658,,\n1571,,\n1796,,\n1713,252,\n1507,560,\n0205,900,\n0189,720,\n0956,90,\n0336,,\n1541,201,\n1933,,\n1278,262,\n0080,400,\n1690,,\n1824,25,\n1620,280,\n1584,815,\n0396,,\n0757,v,\n1736,178,\n0812,361,\n1533,,\n1063,71,\n1380,300,\n1358,380,\n1445,,\n1894,,\n1863,35,\n1681,194,\n1741,v,\n0963,,\n0778,1000,\n1205,350,\n1759,24,\n0726,,\n1293,250,\n1524,v,\n0421,,\n1203,3550,\n1878,,\n1865,,\n0111,550,\n1696,,\n1253,1000,\n1210,250,\n1288,,\n1666,v,\n1455,,\n1691,,\n0271,473,\n1787,,\n1859,728,\n0924,180,\n1811,,\n1079,90,\n1848,,\n1499,v,\n1260,445,\n0456,250,\n1826,18,\n1048,,\n1605,v,\n0961,1100,\n0451,,\n1457,,\n0685,500,\n0042,,\n1911,v,\n0957,180,\n1623,v,\n0084,,\n1828,50,\n1680,1000,\n1350,,\n1610,v,\n1684,,\n1720,190,\n0843,135,\n1869,v,\n1614,355,\n1418,190,\n1598,,\n1954,,\n1563,300,\n1919,77,\n0266,,\n1613,,\n1325,,\n1466,170,\n1747,4,\n0301,,\n0919,176,\n1729,,\n1589,v,\n1395,,\n1897,v,\n1669,,\n1171,v,\n1725,,\n1712,250,\n0286,557,\n0076,v,\n1920,,\n1693,v,\n0179,,\n1513,,\n0887,1100,\n1700,v,\n1622,v,\n0893,1219,\n0848,,\n0954,,\n1945,,\n1575,v,\n1936,,\n1917,200,\n1629,158,\n1321,310,\n0631,247,\n1895,,\n0180,,\n1860,,\n0230,,\n1853,,\n1532,253,\n1254,,\n0085,500,\n0606,500,\n1633,100,\n0398,300,\n1649,300,\n1709,160,\n1798,,\n1699,193,\n1816,35,\n1218,v,\n1868,27,\n1597,250,\n1804,,\n0799,84,\n1788,358,\n1934,40,\n0660,161,\n1810,,\n1854,,\n1428,173,\n1814,,\n1299,,\n0063,,\n0633,225,\n1939,,\n0807,450,\n0485,,\n1570,750,\n1634,280,\n1801,731,\n1889,,\n1578,,\n1554,v,\n1722,v,\n1627,230,\n1701,,\n1943,,\n0433,610,\n1652,,\n1730,285,\n1866,,\n1777,221,\n0190,496,\n1805,,\n0137,,\n1150,300,\n0525,107,\n1838,110,\n1803,96,\n1639,371,\n0140,227,\n1923,47,\n1827,,\n0866,213,\n1161,v,\n0355,39,\n1674,,\n0872,500,\n1737,180,\n1005,24,\n0155,220,\n0003,,\n1529,525,\n1040,,\n1359,250,\n0516,,\n0154,,\n1266,,\n0209,185,\n1858,,\n0185,v,\n1615,v,\n0004,125,\n1948,,\n1683,95,\n1086,v,\n0926,230,\n1899,,\n0756,60,\n1893,,\n1823,504,\n1141,,\n1808,,\n0287,,\n1464,150,\n1746,280,\n1916,,\n0967,340,\n0876,,\n1534,450,\n0861,1200,\n1949,,\n0363,204,\n0932,251,\n0953,500,\n1745,148,\n1929,,\n1653,v,\n1175,220,\n1740,54,\n1435,250,\n0226,124,\n0938,490,\n1432,400,\n1549,720,\n0047,299,\n1779,v,\n1035,431,\n1728,11,\n1797,,\n0788,v,\n1545,,\n0569,,\n0228,,\n0316,,\n1498,50,\n0461,,\n1711,108,\n0927,,\n0413,380,\n1600,,\n1887,,\n1733,v,\n1467,85,\n1641,,\n1813,,\n1425,,\n1724,900,\n1638,v,\n0869,,\n1096,710,\n0714,501,\n1781,v,\n0034,,\n1809,,\n0171,215,\n0935,360,\n0720,240,\n1510,222,\n1213,362,\n1648,833,\n1195,v,\n0203,143,\n1667,v,\n0533,v,\n1874,624,\n1556,206,\n1692,400,\n1857,,\n1465,400,\n1732,v,\n0721,,\n0899,,\n1873,,\n1891,,\n1942,15,\n1937,,\n0643,,\n0245,,\n0322,,\n1877,,\n1815,,\n0727,v,\n0292,,\n1062,,\n0112,,\n0113,502,\n0551,320,\n1562,670,\n1763,825,\n1383,,\n0984,,\n0114,,\n1468,,\n0648,1450,\n1179,,\n1703,v,\n0821,v,\n1785,,\n1886,,\n1791,290,\n0811,25,\n1572,,\n1698,108,\n1772,517,\n1471,203,\n1752,,\n0885,,\n1363,,\n1850,230,\n1178,325,\n1407,450,\n1812,,\n1773,738,\n1665,140,\n0388,217,\n1317,,\n0564,,\n0696,v,\n0875,v,\n0570,107,\n1625,,\n1941,,\n1283,,\n1084,173,\n1912,,\n1739,550,\n1612,61,\n1953,,\n1807,v,\n1422,540,\n1837,,\n0273,,\n1276,,\n1123,65,\n0580,,\n1778,110,\n1100,150,\n1843,,\n1267,,\n1930,,\n1867,,\n0022,,\n0664,,\n1659,,\n0628,,\n1663,436,\n1011,284,\n0820,482,\n0178,,\n0928,v,\n1888,,\n0342,,\n1156,,\n1308,270,\n0921,,\n';
$par_Testrun_geen_consultgegevens_maken=false;
$par_jaar=2019;
logAdd(log);
$csv = $csvfile_par_consultgegevens_als_csv;
$testrun = $par_Testrun_geen_consultgegevens_maken;
$jaar = $par_jaar;
ifThenElse($csv == '',
logAdd(log, 'error', 'Geen CSV bestand ingelezen, kies er één.');
,
logAdd(log, 'warning', 'CSV Bestand ingelezen, uitvoeren inlezen consultgegevens.');
$idx1 = string\pos($csv, ',');
$idx2 = string\pos($csv, ';');
$comma="@$@#@@";
ifThenElse($idx1,
ifThenElse($idx2,
ifThenElse($idx1 < $idx2, $comma=',', $comma=';');
,
$comma=',';
);
,
ifThen($idx2,
$comma=';';
);
);
$re_entries = string\concatenate('/["][^"]*["]|[^', $comma, ']+/');
$user_id = env\userAttribute('id');
logAdd(log, 'info', 'User id: ', $user_id);
logAdd(log, 'info', "Gevonden comma-separator: '", $comma, "' - positie ','=", $idx1, ", positie ';'=", $idx2 );
ifThenElse($testrun,
logAdd(log, 'warning', 'Testrun - er worden geen consultgegevens aangemaakt.');
,
logAdd(log, 'warning', 'Er worden consultgegevens aangemaakt');
);
// Split in lines
$rows=list();
$line='';
$csv = string\concatenate(string\trim($csv), '\n');
$idx = string\pos($csv, '\n');
$data = list();
$n_data = 2;
$heading = true;
while($idx,
$line = string\substring($csv, 0, $idx);
$csv = string\substring($csv, $idx + 1);
$entries = string\matchAll($line, $re_entries);
$k = array\length($entries);
ifThen($k < $n_data, $entries = array\push($entries, ''));
$k = array\length($entries);
ifThenElse($k < $n_data,
logAdd(log, 'error', 'Minder dan ', $n_data, ' cellen op deze rij, niet te herkennen');
logAdd(log, 'error', $line);
,
$row = list();
$j = 0;
while($j < $k,
$entry = array\at($entries, $j);
$row = array\push($row, $entry);
$j = $j + 1;
);
ifThenElse($heading,
$heading = false;
,
$rows = array\push($rows, $row);
);
);
$idx = string\pos($csv, '\n');
);
$n = array\length($rows);
logAdd(log, 'warning', $n, ' - rijen ingelezen');
$i = 0;
while($i < $n,
$row = array\at($rows, $i);
$lidnummer = toString(array\at($row, 0));
$consulten = string\trim(array\at($row, 1));
ifThen($consulten == 'v', $consulten = "");
ifThenElse($consulten != "",
$consulten_int = toInt($consulten);
$id = record\findOne('Contact', 'name', 'asc', 'lidnummer=', $lidnummer);
ifThenElse($id,
ifThenElse($testrun,
logAdd(log, 'info', 'Testrun, er worden geen consultgegevens opgevoerd');
,
$rec_id = record\create('ConsultGegevens', 'contactId', $id, 'jaar', $jaar, 'aantal', $consulten_int, 'assignedUserId', $used_id);
record\relate('Contact', $id, 'consultGegevens', $rec_id);
);
logAdd(log, 'info', 'lidnummer: ', $lidnummer, ' - ', $consulten_int, ' consulten opgegeven (', $consulten, '), voor id: ', $id);
,
logAdd(log, 'warning', 'lidnummer: ', $lidnummer, ' - geen id gevonden!');
);
,
logAdd(log, 'info', 'lidnummer: ', $lidnummer, ' - geen consulten opgegeven');
);
$i = $i + 1;
);
);