Bocian.php.view.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. console.log('test1... DBG:', DBG)
  2. // localStorage.setItem('Bocian.pracownicyIds', JSON.stringify(ids))
  3. // var ids = localStorage.getItem('Bocian.pracownicyIds')
  4. // localStorage.removeItem('Bocian.pracownicyIds')
  5. // localStorage.removeItem('Bocian.kontrahenciIds')
  6. // localStorage.removeItem('Bocian.depth') // TODO: zapis na stronie głównej i BiAuditRaport
  7. if (!URL_FETCH_TEST) {
  8. throw "Brak zmiennej URL_FETCH_TEST"
  9. }
  10. $(window).on('hashchange', function() {
  11. initLocalStorage();
  12. rootChangeForm();
  13. });
  14. function loadCurrentDepthInInput(idInput) {
  15. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  16. $(idInput).val(function() {
  17. return depthValue;
  18. });
  19. }
  20. function updateLocalStorageBiAuditDepth(idInput) {
  21. $(idInput).keyup(function() {
  22. delayUpdate(function(){
  23. var newValue = $(idInput).val();
  24. var responseValue = validateValueDepth(parseInt(newValue));
  25. setItemLocalStorage('Bocian.biAuditForm.depth', responseValue);
  26. loadCurrentDepthInInput('.smad-depth');
  27. }, 1000 );
  28. });
  29. }
  30. function validateValueDepth(newValue) {
  31. var value = null;
  32. value = newValue;
  33. if (parseInt(newValue) < 0) {
  34. value = 1;
  35. }
  36. if (parseInt(newValue) > 16) {
  37. value = 16;
  38. }
  39. return value;
  40. }
  41. var delayUpdate = (function() {
  42. var timer = 0;
  43. return function(callback, ms) {
  44. clearTimeout (timer);
  45. timer = setTimeout(callback, ms);
  46. };
  47. })();
  48. function initLocalStorage() {
  49. if (getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') === null) {
  50. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
  51. }
  52. if (getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') === null) {
  53. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
  54. }
  55. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  56. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  57. if (getItemLocalStorage('Bocian.biAuditForm.depth') === null) {
  58. updateLocalStorageBiAuditDepth(2);
  59. }
  60. }
  61. function defaultBIAuditLocalStorage() {
  62. localStorage.removeItem('Bocian.biAuditForm.pracownicyIds');
  63. localStorage.removeItem('Bocian.biAuditForm.kontrahenciIds');
  64. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  65. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  66. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  67. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  68. setItemLocalStorage('Bocian.biAuditForm.depth', 2);
  69. }
  70. function generateBiAuditRaport(event) {
  71. event.preventDefault();
  72. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  73. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  74. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  75. // validate
  76. if (!depthValue || depthValue === 0) {
  77. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
  78. } else if (!pracownicyIdsArray || pracownicyIdsArray.length === 0) {
  79. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pracowników' });
  80. } else if (!kontrahenciIdsArray || kontrahenciIdsArray.length === 0) {
  81. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano kontrahentów' });
  82. } else {
  83. // send
  84. window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
  85. method: 'POST',
  86. headers: {
  87. 'Content-Type': 'application/json'
  88. },
  89. credentials: 'same-origin',
  90. body: JSON.stringify({
  91. pracownicyIds: pracownicyIdsArray,
  92. kontrahenciIds: kontrahenciIdsArray,
  93. depthValue: depthValue
  94. })
  95. })
  96. .then(function(response) {
  97. console.log('Firsst then', response);
  98. return response.text();
  99. })
  100. .then(function(responseText) {
  101. try {
  102. return JSON.parse(responseText);
  103. } catch (e) {
  104. throw responseText;
  105. }
  106. })
  107. .then(function(result) {
  108. result
  109. if (result.type == 'success') {
  110. p5UI__notifyAjaxCallback(result);
  111. defaultBIAuditLocalStorage();
  112. window.setTimeout(window.location.href = "https://bravecom.yellowgroup.pl/SE/index.php?_route=ViewTableAjax&namespace=default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA", 4000);
  113. resolve(result.msg);
  114. } else {
  115. reject(result.msg);
  116. }
  117. })
  118. .catch(function(error) {
  119. console.log('request failed', error)
  120. });
  121. }
  122. }
  123. function addPracownikToGroup(event) {
  124. event.preventDefault();
  125. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  126. if (pracownicyIdsArray === null) {
  127. showTextListIdPracownikow = 'ID pracowników: nie wybrano';
  128. } else {
  129. showTextListIdPracownikow = 'ID pracowników: ' + pracownicyIdsArray;
  130. }
  131. swal({
  132. title: 'Przenieś do grupy',
  133. input: 'select',
  134. text: showTextListIdPracownikow,
  135. inputOptions: getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups'),
  136. inputPlaceholder: 'Wybierz grupę',
  137. showCancelButton: true,
  138. confirmButtonText: 'Zapisz',
  139. showLoaderOnConfirm: true,
  140. preConfirm: function (idGroup) {
  141. return new Promise(function (resolve, reject) {
  142. console.log('value', idGroup);
  143. if ( !pracownicyIdsArray || pracownicyIdsArray === null || pracownicyIdsArray === 'undefined' ) {
  144. reject('Wybierz pracowników');
  145. } else if ( pracownicyIdsArray.length === 0 ) {
  146. reject('Wybierz pracowników');
  147. }
  148. if (!idGroup) reject('Proszę wybrać nazwę grupy');
  149. window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
  150. method: 'POST',
  151. header: {
  152. 'contentType': 'applications/json'
  153. },
  154. credentials: 'same-origin',
  155. body: JSON.stringify({
  156. 'idGroup': idGroup,
  157. 'pracownicyIds': getItemLocalStorage('Bocian.biAuditForm.pracownicyIds'),
  158. })
  159. })
  160. .then(function(response) {
  161. return response.text();
  162. })
  163. .then(function(responseText) {
  164. try {
  165. return JSON.parse(responseText);
  166. } catch (e) {
  167. throw responseText;
  168. }
  169. })
  170. .then(function(result) {
  171. result
  172. if (result.type == 'success') {
  173. p5UI__notifyAjaxCallback(result);
  174. resolve(result.msg);
  175. } else {
  176. reject(result.msg);
  177. }
  178. })
  179. .catch(function(error) {
  180. console.log('request failed', error)
  181. });
  182. })
  183. },
  184. allowOutsideClick: false
  185. }).then(function (groupPracownicyData) {
  186. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  187. });
  188. }
  189. function addKontrahenciToGroup(event) {
  190. event.preventDefault();
  191. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  192. if (kontrahenciIdsArray === null) {
  193. showTextListIdKontrahentow = 'ID pracowników: nie wybrano';
  194. } else {
  195. showTextListIdKontrahentow = 'ID pracowników: ' + pracownicyIdsArray;
  196. }
  197. swal({
  198. title: 'Przenieś do grupy',
  199. input: 'select',
  200. text: showTextListIdKontrahentow,
  201. inputOptions: getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'),
  202. inputPlaceholder: 'Wybierz grupę',
  203. showCancelButton: true,
  204. confirmButtonText: 'Zapisz',
  205. showLoaderOnConfirm: true,
  206. preConfirm: function (idGroup) {
  207. return new Promise(function (resolve, reject) {
  208. if (!idGroup) reject('Proszę wybrać nazwę grupy');
  209. if ( !kontrahenciIdsArray || kontrahenciIdsArray === null || kontrahenciIdsArray === 'undefined' ) {
  210. reject('Wybierz kontrahentów');
  211. } else if ( kontrahenciIdsArray.length === 0 ) {
  212. reject('Wybierz kontrahentów');
  213. }
  214. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  215. method: 'POST',
  216. header: {
  217. 'contentType': 'applications/json'
  218. },
  219. credentials: 'same-origin',
  220. body: JSON.stringify({
  221. 'idGroup': idGroup,
  222. 'kontrahenciIds': getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds'),
  223. })
  224. })
  225. .then(function(response) {
  226. return response.text();
  227. })
  228. .then(function(responseText) {
  229. try {
  230. return JSON.parse(responseText);
  231. } catch (e) {
  232. throw responseText;
  233. }
  234. })
  235. .then(function(result) {
  236. result
  237. if (result.type == 'success') {
  238. p5UI__notifyAjaxCallback(result);
  239. resolve(result.msg);
  240. } else {
  241. reject(result.msg);
  242. }
  243. })
  244. ;
  245. })
  246. },
  247. allowOutsideClick: false
  248. }).then(function (groupKontrahenciData) {
  249. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  250. });
  251. }
  252. function createGroupKontrahenci(event) {
  253. event.preventDefault();
  254. swal({
  255. title: 'Utwórz grupę',
  256. input: 'text',
  257. showCancelButton: true,
  258. confirmButtonText: 'Zapisz',
  259. showLoaderOnConfirm: true,
  260. preConfirm: function (NAZWA) {
  261. return new Promise(function (resolve, reject) {
  262. if (!NAZWA) reject('Proszę podać nazwę grupy');
  263. window.fetch(URL_CREATE_KONTRAHENCIS_GROUP, {
  264. method: 'POST',
  265. header: {
  266. 'contentType': 'applications/json'
  267. },
  268. credentials: 'same-origin',
  269. body: JSON.stringify({
  270. 'NAZWA': NAZWA
  271. })
  272. })
  273. .then(function(response) {
  274. return response.text();
  275. })
  276. .then(function(responseText) {
  277. try {
  278. return JSON.parse(responseText);
  279. } catch (e) {
  280. throw responseText;
  281. }
  282. })
  283. .then(function(result) {
  284. result
  285. if (result.type == 'success') {
  286. p5UI_notifyAjaxCallback(result);
  287. resolve(result.msg);
  288. } else {
  289. reject(result.msg);
  290. }
  291. })
  292. ;
  293. })
  294. },
  295. allowOutsideClick: false
  296. }).then(function (groupKontrahenciData) {
  297. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  298. groupsKontrahenci = '<button class="btn btn-default" title="'+groupKontrahenciData['NAZWA']+'" data-group-filter="'+groupKontrahenciData['ID']+'">'+groupKontrahenciData['NAZWA']+'</button>';
  299. $('#group-kontrahenci').append(groupsKontrahenci);
  300. });
  301. }
  302. function createGroupPracownicy(event) {
  303. event.preventDefault();
  304. swal({
  305. title: 'Utwórz grupę',
  306. input: 'text',
  307. showCancelButton: true,
  308. confirmButtonText: 'Zapisz',
  309. showLoaderOnConfirm: true,
  310. preConfirm: function (NAZWA) {
  311. return new Promise(function (resolve, reject) {
  312. if (!NAZWA) reject('Proszę podać nazwę grupy');
  313. window.fetch(URL_CREATE_PRACOWNICY_GROUP, {
  314. method: 'POST',
  315. header: {
  316. 'contentType': 'applications/json'
  317. },
  318. credentials: 'same-origin',
  319. body: JSON.stringify({
  320. 'NAZWA': NAZWA
  321. })
  322. })
  323. .then(function(response) {
  324. return response.text();
  325. })
  326. .then(function(responseText) {
  327. try {
  328. return JSON.parse(responseText);
  329. } catch (e) {
  330. throw responseText;
  331. }
  332. })
  333. .then(function(result) {
  334. result
  335. if (result.type == 'success') {
  336. p5UI_notifyAjaxCallback(result);
  337. resolve(result.msg);
  338. } else {
  339. reject(result.msg);
  340. }
  341. })
  342. ;
  343. })
  344. },
  345. allowOutsideClick: false
  346. }).then(function (groupPracownicyData) {
  347. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  348. groupsPracownicy = '<button class="btn btn-default" title="'+groupPracownicyData['NAZWA']+'" data-group-filter="'+groupPracownicyData['ID']+'">'+groupPracownicyData['NAZWA']+'</button>';
  349. $('#group-pracownicy').append(groupsPracownicy);
  350. });
  351. }
  352. // // Documentation: https://github.com/github/fetch
  353. // fetch(URL_FETCH_TEST, {
  354. // credentials: 'same-origin'
  355. // })
  356. // .then(function parseJSON(response) {
  357. // return response.json()
  358. // })
  359. // .then(function(data) {
  360. // //$( ".container" ).append( data.body.view );
  361. // console.log('request succeeded with JSON response', data)
  362. // }).catch(function(error) {
  363. // console.log('request failed', error)
  364. // })
  365. //
  366. // fetch(URL_FETCH_TEST_KRS, {
  367. // credentials: 'same-origin'
  368. // })
  369. // .then(function parseJSON(response) {
  370. // return response.json()
  371. // })
  372. // .then(function(data) {
  373. // console.log('request succeeded with JSON response', data)
  374. // }).catch(function(error) {
  375. // console.log('request failed', error)
  376. // })
  377. //
  378. // fetch(URL_FETCH_TEST_CEIDG, {
  379. // credentials: 'same-origin'
  380. // })
  381. // .then(function parseJSON(response) {
  382. // return response.json()
  383. // })
  384. // .then(function(data) {
  385. // console.log('request succeeded with JSON response', data)
  386. // }).catch(function(error) {
  387. // console.log('request failed', error)
  388. // })
  389. function rootChangeForm() {
  390. var valueUrl = global.location.hash;
  391. switch (valueUrl) {
  392. case '#KONTRAHENCI':
  393. $( ".container-bi_audit_form_kontrahenci_raport" ).html( VIEW_KONTRAHENCI );
  394. urlFetchKontrahenci(1);
  395. fetchGroupKontrahenci();
  396. $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  397. $( ".container-bi_audit_form_kontrahenci_raport" ).show();
  398. break;
  399. case '#PRACOWNICY':
  400. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  401. urlFetchPracownicy(1);
  402. fetchGroupPracownicy()
  403. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  404. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  405. break;
  406. default:
  407. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  408. urlFetchPracownicy(1);
  409. fetchGroupPracownicy()
  410. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  411. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  412. break;
  413. }
  414. //aktualizacja inputa głebokości powiazan
  415. loadCurrentDepthInInput('.smad-depth');
  416. updateLocalStorageBiAuditDepth('.smad-depth');
  417. }
  418. function getAddressData(objectValue) {
  419. var objectValue = objectValue || [];
  420. var listData = '';
  421. if (!objectValue) {
  422. return true;
  423. }
  424. objectValue.forEach (function(item) {
  425. if (item['kodPocztowy']) { listData += '<div>kod pocztowy: ' + item['kodPocztowy'] + '<div>'; }
  426. if (item['miejscowosc']) { listData += '<div>miejscowość: ' + item['miejscowosc'] + '<div>'; }
  427. if (item['nrBudynku']) { listData += '<div>nr budynku: ' + item['nrBudynku'] + '<div>'; }
  428. if (item['nrLokalu']) { listData += '<div>nr lokalu: ' + item['nrLokalu'] + '<div>'; }
  429. if (item['typAdresu']) { listData += '<div>typ adresu: ' + item['typAdresu'] + '<div>'; }
  430. if (item['ulica']) { listData += '<div>ulica: ' + item['ulica'] + '<div>'; }
  431. listData += '<div>------<div>';
  432. });
  433. return listData;
  434. }
  435. function urlFetchKontrahenci(page) {
  436. var page = page || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page');
  437. selectPage('KONTRAHENCI', page);
  438. if ( page === 1) {
  439. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  440. }
  441. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  442. fetch(URL_FETCH_KONTRAHENCI + '&page=' + page + '&filterIdGroup=' + filterIdGroup, {
  443. credentials: 'same-origin'
  444. })
  445. .then(function parseJSON(response) {
  446. return response.json()
  447. var filterIdGroup = filterIdGroup || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  448. })
  449. .then(function(data) {
  450. var listItemsKontrahenci = null;
  451. data.body.items.forEach (function(row) {
  452. listItemsKontrahenci += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
  453. '<td align="right">'+row["ID"]+'</td>'+
  454. '<td align="right">'+row["Nazwa_grupy_kapitalowej"]+'</td>'+
  455. '<td align="right">'+row["Pelna_nazwa_kontrahenta"]+'</td>'+
  456. '<td align="right">'+row["Numer_kontrahenta"]+'</td>'+
  457. '<td align="right">'+row["Skrocona_Nazwa_Kontrahenta"]+'</td>'+
  458. '<td align="right">'+row["Typ_kontrahenta"]+'</td>'+
  459. '<td align="right">'+row["NIP"]+'</td>'+
  460. '<td align="right">'+row["KRS"]+'</td>'+
  461. '<td align="right">'+row["REGON"]+'</td>'+
  462. '<td align="right">'+row["PESEL"]+'</td>'+
  463. '<td align="right">'+row["Forma_prawna_dzialalnosci"]+'</td>'+
  464. '<td align="right">'+row["Ulica"]+'</td>'+
  465. '<td align="right">'+row["Numer_budynku"]+'</td>'+
  466. '<td align="right">'+row["Numer_mieszkania_lokalu"]+'</td>'+
  467. '<td align="right">'+row["Miejscowosc"]+'</td>'+
  468. '<td align="right">'+row["Kod_pocztowy"]+'</td>'+
  469. '<td align="right">'+row["Kraj"]+'</td>'+
  470. '<td align="right">'+row["Telefon"]+'</td>'+
  471. '<td align="right">'+row["Fax"]+'</td>'+
  472. '<td align="right">'+row["Mail"]+'</td>'+
  473. '<td align="right">'+row["A_ADM_COMPANY"]+'</td>'+
  474. '<td align="right">'+row["A_CLASSIFIED"]+'</td>'+
  475. '<td align="right">'+row["A_STATUS"]+'</td>'+
  476. '<td align="right">'+row["A_STATUS_INFO"]+'</td>'+
  477. '<td align="right">'+row["Dodano"]+'</td>'+
  478. '<td align="right">'+row["L_APPOITMENT_USER"]+'</td>'+
  479. '<td align="right">'+row["Podmiot_dominujacy"]+'</td>'+
  480. '<td align="right">'+row["Tytul_dokumentu"]+'</td>'+
  481. '<td align="right">'+row["ownCompany"]+'</td>'+
  482. '<td align="right">'+row["uwagi"]+'</td></tr>';
  483. });
  484. if (data.body.pagination !== undefined) {
  485. Pagination.Init(document.getElementById('pagination-kontrahenci'), {
  486. url: 'https://bravecom.yellowgroup.pl/SE/index.php?_route=UrlAction_Bocian#KONTRAHENCI',
  487. id_pagination: 'pagination-kontrahenci',
  488. type: 'KONTRAHENCI',
  489. total_items: data.body.pagination.total_items, // pages size
  490. size: data.body.pagination.size, // pages size
  491. page: page, // selected page
  492. step: 1 // pages before and after current
  493. });
  494. }
  495. $( "#body-kontrahenci" ).html(listItemsKontrahenci);
  496. checkAll('KONTRAHENCI');
  497. catchEventCheckbox('KONTRAHENCI');
  498. checkedChoiseItems('KONTRAHENCI', getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') );
  499. // $( ".container-bi_audit_raport" ).append( data.body.view );
  500. console.log('request succeeded with JSON responseKontrahenci', data)
  501. }).catch(function(error) {
  502. console.log('request failed', error)
  503. })
  504. }
  505. function urlFetchPracownicy(page) {
  506. var page = page || getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page');
  507. if ( page === 1) {
  508. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  509. }
  510. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  511. selectPage('PRACOWNICY', page);
  512. fetch(URL_FETCH_PRACOWNICY + '&page=' + page + '&filterIdGroup=' + filterIdGroup, {
  513. credentials: 'same-origin'
  514. })
  515. .then(function parseJSON(response) {
  516. return response.json()
  517. })
  518. .then(function(data) {
  519. var addresPerson = '';
  520. var listItemsPracownik = null;
  521. console.log('urlFetchPracownicy', data.body.items);
  522. data.body.items.forEach (function(row) {
  523. if (row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]) {
  524. addresPerson = getAddressData(row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]);
  525. }
  526. listItemsPracownik += '<tr><td><input type="checkbox" name="prID[]" value="'+row['ID']+'" /></td>'+
  527. '<td align="right">'+row["ID"]+'</td>'+
  528. '<td align="right">'+row["imiona"]+'</td>'+
  529. '<td align="right">'+row["nazwisko"]+'</td>'+
  530. '<td align="right">'+row["nip"]+'</td>'+
  531. '<td align="right">'+row["pesel"]+'</td>'+
  532. '<td align="right">'+row["regon"]+'</td>'+
  533. '<td align="right">'+row["source"]+'</td>'+
  534. '<td align="right">'+row["A_ADM_COMPANY"]+'</td>'+
  535. '<td align="right">'+row["A_CLASSIFIED"]+'</td>'+
  536. '<td align="right">'+row["A_STATUS"]+'</td>'+
  537. '<td align="right">'+row["A_STATUS_INFO"]+'</td>'+
  538. '<td align="right">'+row["L_APPOITMENT_USER"]+'</td>'+
  539. '<td align="right">'+ addresPerson +'</td></tr>';
  540. });
  541. if (data.body.pagination.size) {
  542. Pagination.Init(document.getElementById('pagination-pracownicy'), {
  543. url: 'https://bravecom.yellowgroup.pl/SE/index.php?_route=UrlAction_Bocian#PRACOWNICY',
  544. id_pagination: 'pagination-pracownicy',
  545. type: 'PRACOWNICY',
  546. total_items: data.body.pagination.total_items, // pages size
  547. size: data.body.pagination.size, // pages size
  548. page: data.body.pagination.current, // selected page
  549. step: 1 // pages before and after current
  550. });
  551. }
  552. $( "#body-pracownicy" ).html( listItemsPracownik);
  553. checkAll('PRACOWNICY');
  554. catchEventCheckbox('PRACOWNICY');
  555. checkedChoiseItems('PRACOWNICY', getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') );
  556. // $( ".container-bi_audit_raport" ).append( data.body.view );
  557. console.log('request succeeded with JSON responsePRACOWNICY', data)
  558. }).catch(function(error) {
  559. console.log('request failed', error)
  560. })
  561. }
  562. function selectPage(type, nrPage) {
  563. var type = type.toLowerCase();
  564. $('#pagination-' + type + ' ul li a').each(function(index, value){
  565. if (this.text === nrPage) {
  566. $(this).addClass('active');
  567. } else {
  568. $(this).removeClass('active');
  569. }
  570. });
  571. }
  572. function checkAll(type) {
  573. $('#checkAll-' + type).change(function() {
  574. var valueCheckbox = null;
  575. var checkboxes = $('form').find(':checkbox');
  576. if($(this).prop('checked')) {
  577. checkboxes.prop('checked', true);
  578. //valueCheckbox = checkboxes.prop("checked");
  579. var allValsChecked = [];
  580. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  581. if (this.value !== 'on') {
  582. allValsChecked.push(parseInt(this.value));
  583. }
  584. }).get();
  585. updateListIdBiAuditReaport(type, allValsChecked);
  586. } else {
  587. checkboxes.prop('checked', false);
  588. var allValsUnChecked = [];
  589. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  590. if (this.value !== 'on') {
  591. allValsUnChecked.push(parseInt(this.value));
  592. }
  593. }).get();
  594. deleteListIdBiAuditReaport(type, allValsUnChecked);
  595. }
  596. });
  597. }
  598. /**
  599. * Select again checkbox before selected item chekbox from storage (pracownicy/kontrahenci)
  600. */
  601. function checkedChoiseItems(type, store) {
  602. var idElement = 'smad-table-' + type;
  603. // if id element exist
  604. if (document.getElementById(idElement)) {
  605. // checked again if user selected Item (pracownicy/kontrahent)
  606. for (i = 0; i < store.length; i++) {
  607. $('#body-'+type.toLowerCase() +' input[type=checkbox] ').map(function(k, v) {
  608. if ( store[i] === parseInt(this.value) ){
  609. $(this).prop('checked', true);
  610. }
  611. }).get();
  612. }
  613. }
  614. //$('#checkAll-' + type).on('bind', function() {
  615. $('#smad-table-' + type + ' input[type=checkbox]').on( 'load', function() {
  616. var itemsCHecked = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  617. getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  618. if (itemsCHecked.lenght === 0 ) {
  619. return;
  620. }
  621. var valueCheckbox = null;
  622. var checkboxes = $('form').find(':checkbox');
  623. if($(this).prop('checked')) {
  624. checkboxes.prop('checked', true);
  625. var allValsChecked = [];
  626. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  627. if (this.value !== 'on') {
  628. allValsChecked.push(parseInt(this.value));
  629. }
  630. }).get();
  631. updateListIdBiAuditReaport(type, allValsChecked);
  632. } else {
  633. checkboxes.prop('checked', false);
  634. var allValsUnChecked = [];
  635. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  636. if (this.value !== 'on') {
  637. allValsUnChecked.push(parseInt(this.value));
  638. }
  639. }).get();
  640. deleteListIdBiAuditReaport(type, allValsUnChecked);
  641. }
  642. });
  643. }
  644. function catchEventCheckbox(type) {
  645. $('#smad-table-' + type + ' input[type="checkbox"]').on('change', function() {
  646. if($(this).is(":checked")) {
  647. var allValsChecked = [];
  648. if (this.value !== 'on') {
  649. allValsChecked.push(parseInt(this.value));
  650. }
  651. updateListIdBiAuditReaport(type, allValsChecked);
  652. } else {
  653. var allValsUnChecke = [];
  654. if (this.value !== 'on') {
  655. allValsUnChecke.push(parseInt(this.value));
  656. }
  657. deleteListIdBiAuditReaport(type, allValsUnChecke);
  658. }
  659. });
  660. }
  661. function clearSelectedCheckbox() {
  662. $('#checkAll-PRACOWNICY').prop('checked', false)
  663. $('#checkAll-KONTRAHENCI').prop('checked', false)
  664. }
  665. function updateListIdBiAuditReaport(type, valueArray) {
  666. var currentStoragePracownicyIds = [];
  667. var updateListPracownicyIds = null;
  668. var currentStorageKontrahenciIds = [];
  669. var updateListKontrahenciIds = null;
  670. if ( type == 'PRACOWNICY') {
  671. currentStoragePracownicyIds = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  672. if(currentStoragePracownicyIds !== null) {
  673. updateListPracownicyIds = [...new Set([...currentStoragePracownicyIds ,...valueArray])];
  674. }
  675. else {
  676. updateListPracownicyIds = valueArray;
  677. }
  678. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', updateListPracownicyIds);
  679. }
  680. if ( type == 'KONTRAHENCI') {
  681. currentStorageKontrahenciIds = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  682. if(currentStorageKontrahenciIds !== null) {
  683. updateListKontrahenciIds = [...new Set([...currentStorageKontrahenciIds ,...valueArray])];
  684. }
  685. else {
  686. updateListKontrahenciIds = valueArray;
  687. }
  688. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', updateListKontrahenciIds);
  689. }
  690. }
  691. function deleteListIdBiAuditReaport(type, valueArray) {
  692. var currentStoragePracownicyIds = [];
  693. var updateListPracownicyIds = null;
  694. if ( type == 'PRACOWNICY') {
  695. deleteItemLocalStorage('Bocian.biAuditForm.pracownicyIds', valueArray);
  696. }
  697. if ( type == 'KONTRAHENCI') {
  698. deleteItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', valueArray);
  699. }
  700. }
  701. // filter group detect
  702. function fetchGroupPracownicy() {
  703. fetch(URL_FETCH_GROUP_PRACOWNICY, {
  704. credentials: 'same-origin'
  705. })
  706. .then(function parseJSON(response) {
  707. return response.json()
  708. })
  709. .then(function(data) {
  710. setItemLocalStorage('Bocian.biAuditForm.pracownicy.groups', data.body.itmesGroupPracownicy);
  711. if (data.body.itmesGroupPracownicy === null) {
  712. return;
  713. }
  714. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  715. var groupsPracownicy = '';
  716. var activeButton = '';
  717. data.body.itmesGroupPracownicy.forEach (function(row) {
  718. if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-pracownicy button.active').removeClass('active'); }
  719. groupsPracownicy += '<button class="btn btn-default '+activeButton+'" title="' + row['NAZWA'] + '" data-group-filter="' + row['ID'] + '">' + row['NAZWA'] + '</button>';
  720. });
  721. $("#group-pracownicy").append(groupsPracownicy);
  722. console.log('request succeeded with JSON fetchGroupPracownicy', data.body.itmesGroupPracownicy)
  723. }).catch(function(error) {
  724. console.log('request failed', error)
  725. });
  726. }
  727. function fetchGroupKontrahenci() {
  728. fetch(URL_FETCH_GROUP_KONTRAHENCI, {
  729. credentials: 'same-origin'
  730. })
  731. .then(function parseJSON(response) {
  732. return response.json()
  733. })
  734. .then(function(data) {
  735. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups', data.body.itemsGroupKontrahenci);
  736. if (data.body.itemsGroupKontrahenci === null) {
  737. return;
  738. }
  739. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  740. var groupsKontrahenci = '';
  741. var activeButton = '';
  742. data.body.itemsGroupKontrahenci.forEach (function(row) {
  743. if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-kontrahenci button.active').removeClass('active'); }
  744. groupsKontrahenci += '<button class="btn btn-default '+activeButton+'" title="'+row['NAZWA']+'" data-group-filter="'+row['ID']+'">'+row['NAZWA']+'</button>';
  745. });
  746. $("#group-kontrahenci").append(groupsKontrahenci);
  747. console.log('request succeeded with JSON fetchGroupKontrahenci', data.body.itemsGroupKontrahenci);
  748. }).catch(function(error) {
  749. console.log('request failed', error)
  750. });
  751. }
  752. function detectChoiseFilter() {
  753. $('#group-kontrahenci').on('click', 'button', function(evt) {
  754. $('#group-kontrahenci button.active').removeClass('active');
  755. $(this).addClass('active');
  756. // pobranie id grupy kliknietego buttonu
  757. var filterIdGroup = $(this).attr("data-group-filter");
  758. // ustawić id grupy do sesyjnej
  759. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', parseInt(filterIdGroup));
  760. // wywylac funckje pobrania danych
  761. urlFetchKontrahenci(1);
  762. });
  763. $('#group-pracownicy').on('click', 'button', function(evt) {
  764. $('#group-pracownicy button.active').removeClass('active');
  765. $(this).addClass('active');
  766. // pobranie id grupy kliknietego buttonu
  767. var filterIdGroup = $(this).attr("data-group-filter");
  768. // ustawić id grupy do sesyjnej
  769. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', parseInt(filterIdGroup));
  770. // wywylac funckje pobrania danych
  771. urlFetchPracownicy(1);
  772. });
  773. }
  774. // Local storage
  775. function setItemLocalStorage(key, array) {
  776. localStorage.setItem(key, JSON.stringify(array));
  777. }
  778. function getItemLocalStorage(key) {
  779. var retrievedData = localStorage.getItem(key);
  780. var response = JSON.parse(retrievedData);
  781. return response;
  782. }
  783. function deleteItemLocalStorage(key, itemsArray) {
  784. var currentStorageArray = getItemLocalStorage(key);
  785. var newStorageArray = removeItemArrayInArray(currentStorageArray, itemsArray);
  786. setItemLocalStorage(key, newStorageArray);
  787. }
  788. /**
  789. * arr - array
  790. * item - search item
  791. */
  792. function removeItemInArray(arr, item) {
  793. for(var i = arr.length; i--;) {
  794. if(arr[i] === item) {
  795. arr.splice(i, 1);
  796. }
  797. }
  798. return arr;
  799. }
  800. /**
  801. * arr - array
  802. * item - array list items
  803. */
  804. function removeItemArrayInArray(arr, itemsArray) {
  805. for(var i = arr.length; i--;) {
  806. for(var j = itemsArray.length; j--;) {
  807. if(arr[i] === itemsArray[j]) {
  808. arr.splice(i, 1);
  809. }
  810. }
  811. }
  812. return arr;
  813. }
  814. // Pagination
  815. var Pagination = {
  816. code: '', // end show html paginations
  817. clickPage: 1, // set default 1 page
  818. // --------------------
  819. // Utility
  820. // --------------------
  821. // initialize default data
  822. Extend: function(data) {
  823. data = data || {};
  824. Pagination.url = data.url;
  825. Pagination.id_pagination = data.id_pagination;
  826. Pagination.type = data.type;
  827. Pagination.total_items = data.total_items;
  828. Pagination.size = data.size || 2;
  829. Pagination.page = data.page || 1;
  830. Pagination.step = data.step || 3;
  831. },
  832. // add pages by number (from [s] to [f])
  833. Add: function(s, f) {
  834. for (var i = s; i < f; i++) {
  835. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">' + i + '</a></li>';
  836. }
  837. },
  838. // add last page with separator
  839. Last: function() {
  840. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">>></a></li>';
  841. },
  842. // add first page with separator
  843. First: function() {
  844. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><<</a></li>';
  845. },
  846. // add last page with separator
  847. Next: function() {
  848. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">></a></li>';
  849. },
  850. // add first page with separator
  851. Prev: function() {
  852. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><</a></li>';
  853. },
  854. // --------------------
  855. // Handlers
  856. // --------------------
  857. // change page
  858. Click: function() {
  859. clearSelectedCheckbox();
  860. var selectPage = $("#pagination-"+Pagination.type.toLowerCase()+' .tblAjax__footer__toolbar__pagination').find('a.active').text();
  861. Pagination.clickPage = +this.innerHTML || '';
  862. if ( selectPage === NaN || selectPage > Pagination.size) { selectPage = 1; }
  863. switch (this.innerHTML) {
  864. case '&gt;&gt;': // last
  865. Pagination.clickPage = Pagination.size;
  866. break;
  867. case '&lt;&lt;': // first
  868. Pagination.clickPage = 1;
  869. break;
  870. case '&lt;': // prev
  871. Pagination.clickPage = parseInt(selectPage) - 1;
  872. if (Pagination.clickPage < 1) {
  873. Pagination.clickPage = 1;
  874. }
  875. break;
  876. case '&gt;': // next
  877. Pagination.clickPage = parseInt(selectPage) + 1;
  878. if (Pagination.clickPage > Pagination.size) {
  879. Pagination.clickPage = Pagination.size;
  880. }
  881. break;
  882. }
  883. if ( Pagination.type === 'KONTRAHENCI' ) {
  884. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', Pagination.clickPage);
  885. Pagination.page = urlFetchKontrahenci(Pagination.clickPage);
  886. }
  887. else if ( Pagination.type === 'PRACOWNICY' ){
  888. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', Pagination.clickPage);
  889. Pagination.page = urlFetchPracownicy(Pagination.clickPage);
  890. }
  891. Pagination.Start();
  892. },
  893. // --------------------
  894. // Script structure pagination
  895. // --------------------
  896. // binding pages
  897. Bind: function() {
  898. var a = Pagination.e.getElementsByTagName('a');
  899. var currentPage = Pagination.clickPage || 1;
  900. for (var i = 0; i < a.length; i++) {
  901. if (+a[i].innerHTML === Pagination.page) a[i].className = 'btn btn-default active';
  902. a[i].addEventListener('click', Pagination.Click, false);
  903. }
  904. },
  905. // write pagination
  906. Finish: function() {
  907. Pagination.e.innerHTML = Pagination.code;
  908. Pagination.code = '</ul></nav>';
  909. Pagination.Bind();
  910. },
  911. // find pagination type
  912. Start: function() {
  913. Pagination.code = '<div class="foot-info tblAjax__footer__toolbar__info footer_pagination_menu_items"><p>Wiersze od 1 do ' + Pagination.total_items + ' z ' + Pagination.total_items + '</p></div>';
  914. Pagination.code += '<nav aria-label="Page navigation" class="footer_pagination_menu_items"><ul class="btn-group tblAjax__footer__toolbar__pagination smad-pagination">';
  915. Pagination.First();
  916. Pagination.Prev();
  917. if ( Pagination.type === 'KONTRAHENCI' ) {
  918. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page') || 1;
  919. }
  920. else if ( Pagination.type === 'PRACOWNICY' ){
  921. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page') || 1;
  922. }
  923. if ( Pagination.page > Pagination.size ) {
  924. Pagination.page = 1;
  925. }
  926. if (Pagination.size < Pagination.step * 2 + 6) {
  927. Pagination.Add(1, Pagination.size + 1);
  928. }
  929. /*else if (Pagination.page < Pagination.step * 2 + 1) {
  930. Pagination.Add(1, Pagination.step * 2 + 4);
  931. }
  932. else if (Pagination.page > Pagination.size - Pagination.step * 2) {
  933. Pagination.Add(Pagination.size - Pagination.step * 2 - 2, Pagination.size + 1);
  934. }*/
  935. else {
  936. // Pagination.Add(Pagination.page - Pagination.step, Pagination.page + Pagination.step + 1);
  937. }
  938. Pagination.Next();
  939. Pagination.Last();
  940. Pagination.Finish();
  941. },
  942. // --------------------
  943. // Initialization
  944. // --------------------
  945. // binding buttons
  946. Buttons: function(e) {
  947. var nav = e.getElementsByTagName('a');
  948. },
  949. // create skeleton
  950. Create: function(e) {
  951. var html = [
  952. '<div></div>' // pagination container
  953. ];
  954. e.innerHTML = html.join('');
  955. Pagination.e = e.getElementsByTagName('div')[0];
  956. Pagination.Buttons(e);
  957. },
  958. // init
  959. Init: function(e, data) {
  960. Pagination.Extend(data);
  961. Pagination.Create(e);
  962. Pagination.Start();
  963. }
  964. };
  965. function todo__fetchRaport(id) {
  966. p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', {
  967. primaryKey: id,
  968. resolve: 'all',
  969. resolveDepth: 3,
  970. }).then(function (features) {
  971. console.log('features', features)
  972. }).catch(function (e) {
  973. console.warn(e)
  974. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  975. })
  976. }
  977. $(document).ready(function(){
  978. rootChangeForm();
  979. detectChoiseFilter();
  980. });
  981. global.checkAll = checkAll;
  982. global.checkedChoiseItems = checkedChoiseItems;
  983. global.catchEventCheckbox = catchEventCheckbox;
  984. global.clearSelectedCheckbox = clearSelectedCheckbox;
  985. global.createGroupPracownicy = createGroupPracownicy;
  986. global.createGroupKontrahenci = createGroupKontrahenci;
  987. global.selectPage = selectPage;
  988. global.detectChoiseFilter = detectChoiseFilter;
  989. global.updateListIdBiAuditReaport = updateListIdBiAuditReaport;
  990. global.deleteListIdBiAuditReaport = deleteListIdBiAuditReaport;
  991. global.urlFetchPracownicy = urlFetchPracownicy;
  992. global.generateBiAuditRaport = generateBiAuditRaport;
  993. global.getAddressData = getAddressData;
  994. global.Pagination = Pagination;
  995. global.todo__fetchRaport = todo__fetchRaport;
  996. global.initLocalStorage = initLocalStorage;
  997. global.setItemLocalStorage = setItemLocalStorage;
  998. global.getItemLocalStorage = getItemLocalStorage;
  999. global.deleteItemLocalStorage = deleteItemLocalStorage;
  1000. global.defaultBIAuditLocalStorage = defaultBIAuditLocalStorage;
  1001. global.removeItemInArray = removeItemInArray;
  1002. global.removeItemArrayInArray = removeItemArrayInArray;
  1003. global.addPracownikToGroup = addPracownikToGroup;