Bocian.php.view.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  1. if (!URL_TABLE_POWIAZANIA) throw "Brak URL_TABLE_POWIAZANIA";
  2. if (!BASE_URLS) throw "Brak BASE_URLS"
  3. var RECORD_MORE_FUNCTIONS_OPENED_NODE = null;
  4. if (!FIELD_LIST_PRACOWNICY) throw "Brak FIELD_LIST_PRACOWNICY"
  5. if (!FIELD_LIST_KONTRAHENCI) throw "Brak FIELD_LIST_KONTRAHENCI"
  6. $(window).on('hashchange', function() {
  7. initLocalStorage();
  8. rootChangeForm();
  9. updateTopCounters();
  10. hideMoreRecordFunctionsPopover()
  11. });
  12. /* DATA FOR READ REAPORT */
  13. function urlFetchKontrahenciPowiazania() {
  14. // Documentation: https://github.com/github/fetch
  15. fetch(URL_FETCH_KONTRAHENCI_POWIAZANIA, {
  16. credentials: 'same-origin'
  17. })
  18. .then(function parseJSON(response) {
  19. return response.json()
  20. })
  21. .then(function(data) {
  22. var reaportItemsKontrahenciPowiazani = null;
  23. data.body.items.forEach (function(row) {
  24. reaportItemsKontrahenciPowiazani += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
  25. '<td align="right">'+row["ID"]+'</td>';
  26. });
  27. $( "#body-reaport-kontrahenci-powiazani-tree" ).html(reaportItemsKontrahenciPowiazani);
  28. }).catch(function(error) {
  29. console.log('request failed', error)
  30. });
  31. }
  32. /* FORM DATA FOR GENERATAE REAPORT */
  33. function loadCurrentDepthInInput(idInput) {
  34. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  35. $(idInput).val(function() {
  36. return depthValue;
  37. });
  38. }
  39. function updateLocalStorageBiAuditDepth(idInput) {
  40. $(idInput).keyup(function() {
  41. delayUpdate(function(){
  42. var newValue = $(idInput).val();
  43. var responseValue = validateValueDepth(parseInt(newValue));
  44. setItemLocalStorage('Bocian.biAuditForm.depth', responseValue);
  45. loadCurrentDepthInInput('.smad-depth');
  46. loadCurrentDepthInInput('.smad-depth-kontrahenci');
  47. // check depth value
  48. if ( parseInt(newValue) > 4 ) {
  49. // check count praconwicy/kontrahenci
  50. var formItemsPraconwicyKontrahenci = countChoiseItemsPraconwicyKontrahenci();
  51. // disable button generate reaport if not choise 'praconwicy' or 'kontrahenci'
  52. if (
  53. (formItemsPraconwicyKontrahenci.totalPracownicy === 0 && formItemsPraconwicyKontrahenci.totalKontrahenci != 0 ) ||
  54. (formItemsPraconwicyKontrahenci.totalPracownicy != 0 && formItemsPraconwicyKontrahenci.totalKontrahenci === 0 )
  55. ) {
  56. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Krytyczne wielkości danych do przeszukania. Czy jesteś pewien? Optymalna wartość głębokość powiazań to: 4.' });
  57. }
  58. }
  59. }, 1000 );
  60. });
  61. }
  62. function validateValueDepth(newValue) {
  63. var value = null;
  64. value = newValue;
  65. if (parseInt(newValue) < 0) {
  66. value = 1;
  67. }
  68. if (parseInt(newValue) > 16) {
  69. value = 16;
  70. }
  71. return value;
  72. }
  73. var delayUpdate = (function() {
  74. var timer = 0;
  75. return function(callback, ms) {
  76. clearTimeout (timer);
  77. timer = setTimeout(callback, ms);
  78. };
  79. })();
  80. /**
  81. * Check count choise pracownicy/kontrahenci
  82. */
  83. function countChoiseItemsPraconwicyKontrahenci() {
  84. var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  85. var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  86. var formItems = {
  87. 'totalPracownicy': ((countPracownicy) ? Object.keys(countPracownicy).length : 0),
  88. 'totalKontrahenci': ((countKontrahenci) ? Object.keys(countKontrahenci).length : 0)
  89. };
  90. return formItems;
  91. }
  92. /**
  93. * Załadowanie wybranej pozycji w select czy zwracać wyniki tylko z obiektami docelowymi onlyTarget
  94. */
  95. function loadCurrentOnlyTargetsSelect() {
  96. var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
  97. $('#smad-select-target').val(analizaOnlyTargets).attr("selected", "selected");
  98. $('#smad-select-target-kontrahenci').val(analizaOnlyTargets).attr("selected", "selected");
  99. }
  100. /**
  101. * Załadowanie do storage informacji czy zwracać wyniki tylko z obiektami docelowymi
  102. */
  103. function updateLocalStorageBiAuditOnlyTargets(idSelect) {
  104. $(idSelect).change(function() {
  105. var newValue = $(idSelect).val();
  106. var responseValue = newValue;
  107. setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', responseValue);
  108. $('#smad-select-target').val(newValue).attr("selected", "selected");
  109. $('#smad-select-target-kontrahenci').val(newValue).attr("selected", "selected");
  110. // load in select selected option
  111. loadCurrentOnlyTargetsSelect();
  112. });
  113. }
  114. function initLocalStorage() {
  115. if (getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') === null) {
  116. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
  117. }
  118. if (getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') === null) {
  119. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
  120. }
  121. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  122. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  123. if (getItemLocalStorage('Bocian.biAuditForm.depth') === null) {
  124. updateLocalStorageBiAuditDepth(7);
  125. }
  126. if (getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets') === null) {
  127. setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', 'n');
  128. //updateLocalStorageBiAuditOnlyTargets('#smad-select-target-kontrahenci');
  129. //updateLocalStorageBiAuditOnlyTargets('#smad-select-target-kontrahenci');
  130. }
  131. }
  132. /**
  133. * Funkcja pozwala na wyświetlenie okienka importu
  134. */
  135. function showViewUploadFile( event, headerTitle, enumType, showCheckbox, csvFileExample ) {
  136. event.preventDefault();
  137. var enumType = enumType;
  138. if( csvFileExample !== undefined) { // przykład + instrukcja do pobrania
  139. csvFileExample = '<div><a href="'+csvFileExample+'" title="Pobierz przykład" download target="_balnk">Pobierz przykład</a></div>';
  140. }
  141. swal({
  142. title: 'Importuj plik csv',
  143. input: 'file',
  144. html: csvFileExample,
  145. inputAttributes: {
  146. 'accept': 'text/csv',
  147. 'aria-label': 'Upload csv file'
  148. },
  149. confirmButtonText: 'Importuj',
  150. preConfirm: function (file) {
  151. return new Promise(function (resolve, reject) {
  152. if (!file) {
  153. reject("Proszę wybrać plik csv");
  154. return
  155. }
  156. var input = document.querySelector('input[type="file"]');
  157. var data = new FormData()
  158. data.append('file', input.files[0])
  159. data.append('showCheckbox', showCheckbox);
  160. var responseParseFile = parseCsvFile( data, enumType );
  161. resolve('file imported')
  162. })
  163. },
  164. }).then(function (result) {
  165. console.log('result', result)
  166. }).catch(function (e) {
  167. console.log('catch: ', e)
  168. });
  169. }
  170. /**
  171. * Funkcja przekazuje dane z pliku csv do przeparsowania
  172. */
  173. function parseCsvFile( fileData, enumType ) {
  174. event.preventDefault();
  175. console.log( 'parseCsvFile fileData', fileData);
  176. fetch(URL_FORM_DATA_CSV_FILE_AJAX, {
  177. method: 'POST',
  178. credentials: 'same-origin',
  179. body: fileData
  180. })
  181. .then(function(response) {
  182. return response.json()
  183. }).then(function(json) {
  184. swal({
  185. title: 'Dane załadowane z pliku CSV',
  186. html: json.body.view,
  187. width: Math.round(window.innerWidth * 0.9),
  188. allowOutsideClick: false, // TODO: btn Anuluj na dole?
  189. showCloseButton: true,
  190. confirmButtonText: 'Zapisz',
  191. preConfirm: function (dataForm) {
  192. return new Promise(function (resolve, reject) {
  193. if (!dataForm) {
  194. reject("Formularz nie zawiera danych do zapisania");
  195. return
  196. }
  197. // zapisanie danych
  198. var responseSaveData = saveFormCsvFileAjaxAction(enumType);
  199. resolve('data save from form')
  200. })
  201. },
  202. }).then(function (result) {
  203. console.log('result', result)
  204. }).catch(function (e) {
  205. console.log('catch: ', e)
  206. });
  207. }).catch(function(ex) {
  208. console.log('parsing failed', ex)
  209. });
  210. }
  211. /**
  212. * Funkcja zapisuje dane z formularza do wgrania pliku csv
  213. */
  214. function saveFormCsvFileAjaxAction(enumType) {
  215. event.preventDefault();
  216. var formDataFrom = $("#formDataFromCsv").serialize();
  217. formDataFrom = formDataFrom.replace(/%5B/g,"[");
  218. formDataFrom = formDataFrom.replace(/%5D/g,"]");
  219. //var formDataFrom = $("#formDataFromCsv").serializeArray();
  220. console.log('dane z formularza formDataFrom ', formDataFrom );
  221. fetch(URL_SAVE_FORM_CSV_FILE_AJAX, {
  222. method: 'POST',
  223. credentials: 'same-origin',
  224. headers: {
  225. 'Content-Type': 'application/json'
  226. },
  227. body: JSON.stringify({
  228. formData: formDataFrom,
  229. enumType: enumType
  230. })
  231. })
  232. .then(function(response) {
  233. return response.json()
  234. }).then(function(json) {
  235. console.log('parsed json', json)
  236. if (response.type == 'success') {
  237. p5UI__notifyAjaxCallback(response.msg);
  238. }
  239. // return json;
  240. }).catch(function(ex) {
  241. console.log('parsing failed', ex)
  242. });
  243. }
  244. function defaultBIAuditLocalStorage() {
  245. localStorage.removeItem('Bocian.biAuditForm.pracownicyIds');
  246. localStorage.removeItem('Bocian.biAuditForm.kontrahenciIds');
  247. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  248. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  249. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
  250. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
  251. setItemLocalStorage('Bocian.biAuditForm.depth', 7);
  252. setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', 'n');
  253. }
  254. function generateBiAuditRaport(event) {
  255. event.preventDefault();
  256. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  257. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  258. var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  259. var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
  260. // validate
  261. if (!depthValue || depthValue === 0) {
  262. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
  263. } else if (!pracownicyIdsArray || pracownicyIdsArray.length === 0) {
  264. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pracowników' });
  265. } else if (!kontrahenciIdsArray || kontrahenciIdsArray.length === 0) {
  266. p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano kontrahentów' });
  267. } else {
  268. // send
  269. window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
  270. method: 'POST',
  271. headers: {
  272. 'Content-Type': 'application/json'
  273. },
  274. credentials: 'same-origin',
  275. body: JSON.stringify({
  276. pracownicyIds: pracownicyIdsArray,
  277. kontrahenciIds: kontrahenciIdsArray,
  278. depthValue: depthValue,
  279. analizaOnlyTargets: analizaOnlyTargets
  280. })
  281. })
  282. .then(function(response) {
  283. console.log('Firsst then', response);
  284. return response.text();
  285. })
  286. .then(function(responseText) {
  287. try {
  288. return JSON.parse(responseText);
  289. } catch (e) {
  290. throw responseText;
  291. }
  292. })
  293. .then(function(result) {
  294. if (result.type == 'success') {
  295. p5UI__notifyAjaxCallback(result);
  296. defaultBIAuditLocalStorage();
  297. updateTopCounters();
  298. window.setTimeout(URL_TABLE_POWIAZANIA, 6000);
  299. resolve(result.msg);
  300. } else {
  301. reject(result.msg);
  302. }
  303. })
  304. .catch(function(error) {
  305. console.log('request failed', error)
  306. });
  307. }
  308. }
  309. /**
  310. * Popup z opcja przeniesienia pracowników do innej grupy
  311. */
  312. function addPracownikToGroup(event) {
  313. event.preventDefault();
  314. var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  315. if (pracownicyIdsArray === null || !pracownicyIdsArray || !pracownicyIdsArray.length) {
  316. showTextListIdPracownikow = 'nie wybrano pracowników';
  317. } else {
  318. showTextListIdPracownikow = '' + pracownicyIdsArray.length + ' pracowników';
  319. }
  320. var arrayGroupOptions = [];
  321. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
  322. // utworzenie tablicy Optionsów grupy
  323. listGroupStorage.map(function(item) {
  324. if (item.ID !== undefined) {
  325. arrayGroupOptions[item.ID] = item.NAZWA;
  326. }
  327. });
  328. swal({
  329. title: 'Dodaj do grupy',
  330. input: 'select',
  331. text: showTextListIdPracownikow,
  332. inputOptions: arrayGroupOptions,
  333. inputPlaceholder: 'Wybierz grupę',
  334. showCancelButton: true,
  335. confirmButtonText: 'Zapisz',
  336. showLoaderOnConfirm: true,
  337. preConfirm: function (idGroup) {
  338. return new Promise(function (resolve, reject) {
  339. console.log('idGrupy value', idGroup);
  340. if ( !pracownicyIdsArray || pracownicyIdsArray === null || pracownicyIdsArray === 'undefined' ) {
  341. reject('Wybierz pracowników');
  342. } else if ( pracownicyIdsArray.length === 0 ) {
  343. reject('Wybierz pracowników');
  344. }
  345. if (!idGroup) reject('Proszę wybrać nazwę grupy');
  346. window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
  347. method: 'POST',
  348. header: {
  349. 'contentType': 'applications/json'
  350. },
  351. credentials: 'same-origin',
  352. body: JSON.stringify({
  353. 'idGroup': idGroup,
  354. 'pracownicyIds': getItemLocalStorage('Bocian.biAuditForm.pracownicyIds'),
  355. })
  356. })
  357. .then(function(response) {
  358. return response.text();
  359. })
  360. .then(function(responseText) {
  361. try {
  362. return JSON.parse(responseText);
  363. } catch (e) {
  364. throw responseText;
  365. }
  366. })
  367. .then(function(result) {
  368. if (result.type == 'success') {
  369. p5UI__notifyAjaxCallback(result);
  370. resolve(result.msg);
  371. } else {
  372. reject(result.msg);
  373. }
  374. })
  375. .catch(function(error) {
  376. console.log('request failed', error)
  377. });
  378. })
  379. },
  380. allowOutsideClick: false
  381. }).then(function (groupPracownicyData) {
  382. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  383. });
  384. }
  385. function addPracownikAllToGroup(event) {
  386. event.preventDefault();
  387. var showTextListIdPracownikow = 'wszystkich pracowników pasujących do kryteriów wyszukiwania';
  388. var arrayGroupOptions = [];
  389. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
  390. // utworzenie tablicy Optionsów grupy
  391. listGroupStorage.map(function(item) {
  392. if (item.ID !== undefined) {
  393. arrayGroupOptions[item.ID] = item.NAZWA;
  394. }
  395. });
  396. swal({
  397. title: 'Dodaj do grupy',
  398. input: 'select',
  399. text: showTextListIdPracownikow,
  400. inputOptions: arrayGroupOptions,
  401. inputPlaceholder: 'Wybierz grupę',
  402. showCancelButton: true,
  403. confirmButtonText: 'Zapisz',
  404. showLoaderOnConfirm: true,
  405. preConfirm: function (idGroup) {
  406. return new Promise(function (resolve, reject) {
  407. if (!idGroup) {
  408. reject('Proszę wybrać nazwę grupy');
  409. return;
  410. }
  411. var filterFields = {}
  412. var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
  413. var fieldNameList = FIELD_LIST_PRACOWNICY
  414. fieldNameList.filter(function (fieldName) {
  415. if (!frm[fieldName]) console.log('Err missing field: "'+fieldName+'"')
  416. return (frm[fieldName]) ? true : false
  417. }).map(function (fieldName) {
  418. return [ fieldName, frm[fieldName].value ]
  419. }).filter(function (filter) {
  420. return ( filter[1].length > 0 )
  421. }).map(function (filter) {
  422. filterFields[ filter[0] ] = filter[1]
  423. })
  424. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  425. if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
  426. window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
  427. method: 'POST',
  428. header: {
  429. 'contentType': 'applications/json'
  430. },
  431. credentials: 'same-origin',
  432. body: JSON.stringify({
  433. 'idGroup': idGroup,
  434. 'type': 'filter',
  435. 'filter': filterFields,
  436. })
  437. })
  438. .then(function(response) {
  439. return response.text();
  440. })
  441. .then(function(responseText) {
  442. try {
  443. return JSON.parse(responseText);
  444. } catch (e) {
  445. throw responseText;
  446. }
  447. })
  448. .then(function(result) {
  449. if (result.type == 'success') {
  450. p5UI__notifyAjaxCallback(result);
  451. resolve(result.msg);
  452. } else {
  453. reject(result.msg);
  454. }
  455. })
  456. .catch(function(error) {
  457. console.log('request failed', error)
  458. });
  459. })
  460. },
  461. allowOutsideClick: false
  462. }).then(function (groupPracownicyData) {
  463. //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  464. });
  465. }
  466. /**
  467. * Popup z opcja przeniesienia kontrahentów do innej grupy
  468. */
  469. function addKontrahenciToGroup(event) {
  470. event.preventDefault();
  471. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  472. if (kontrahenciIdsArray === null || !kontrahenciIdsArray || !kontrahenciIdsArray.length) {
  473. showTextListIdKontrahentow = 'nie wybrano kontrahentów';
  474. } else {
  475. showTextListIdKontrahentow = '' + kontrahenciIdsArray.length + ' kontrahentów';
  476. }
  477. var arrayGroupOptions = [];
  478. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
  479. // utworzenie tablicy Optionsów grupy
  480. listGroupStorage.map(function(item) {
  481. if (item.ID !== undefined) {
  482. arrayGroupOptions[item.ID] = item.NAZWA;
  483. }
  484. });
  485. swal({
  486. title: 'Dodaj do grupy',
  487. input: 'select',
  488. text: showTextListIdKontrahentow,
  489. inputOptions: arrayGroupOptions,
  490. inputPlaceholder: 'Wybierz grupę',
  491. showCancelButton: true,
  492. confirmButtonText: 'Zapisz',
  493. showLoaderOnConfirm: true,
  494. preConfirm: function (idGroup) {
  495. return new Promise(function (resolve, reject) {
  496. if (!idGroup) {
  497. reject('Proszę wybrać nazwę grupy');
  498. return;
  499. }
  500. if (!kontrahenciIdsArray || !kontrahenciIdsArray.length) {
  501. reject('Wybierz kontrahentów');
  502. return;
  503. }
  504. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  505. method: 'POST',
  506. header: {
  507. 'contentType': 'applications/json'
  508. },
  509. credentials: 'same-origin',
  510. body: JSON.stringify({
  511. 'idGroup': idGroup,
  512. 'kontrahenciIds': getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds'),
  513. })
  514. })
  515. .then(function(response) {
  516. return response.text();
  517. })
  518. .then(function(responseText) {
  519. try {
  520. return JSON.parse(responseText);
  521. } catch (e) {
  522. throw responseText;
  523. }
  524. })
  525. .then(function(result) {
  526. result
  527. if (result.type == 'success') {
  528. p5UI__notifyAjaxCallback(result);
  529. resolve(result.msg);
  530. } else {
  531. reject(result.msg);
  532. }
  533. })
  534. ;
  535. })
  536. },
  537. allowOutsideClick: false
  538. }).then(function (groupKontrahenciData) {
  539. //TODO: PIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
  540. });
  541. }
  542. function addKontrahenciAllToGroup(event) {
  543. event.preventDefault();
  544. var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  545. var showTextListIdKontrahentow = 'wszystkich kontrahentów pasujących do kryteriów wyszukiwania';
  546. var arrayGroupOptions = [];
  547. var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
  548. // utworzenie tablicy Optionsów grupy
  549. listGroupStorage.map(function(item) {
  550. if (item.ID !== undefined) {
  551. arrayGroupOptions[item.ID] = item.NAZWA;
  552. }
  553. });
  554. swal({
  555. title: 'Dodaj do grupy',
  556. input: 'select',
  557. text: showTextListIdKontrahentow,
  558. inputOptions: arrayGroupOptions,
  559. inputPlaceholder: 'Wybierz grupę',
  560. showCancelButton: true,
  561. confirmButtonText: 'Zapisz',
  562. showLoaderOnConfirm: true,
  563. preConfirm: function (idGroup) {
  564. return new Promise(function (resolve, reject) {
  565. if (!idGroup) {
  566. reject('Proszę wybrać nazwę grupy');
  567. return;
  568. }
  569. var filterFields = {}
  570. var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
  571. var fieldNameList = FIELD_LIST_KONTRAHENCI
  572. fieldNameList.filter(function (fieldName) {
  573. if (!frm[fieldName]) console.log('Err missing field: "'+fieldName+'"')
  574. return (frm[fieldName]) ? true : false
  575. }).map(function (fieldName) {
  576. return [ fieldName, frm[fieldName].value ]
  577. }).filter(function (filter) {
  578. return ( filter[1].length > 0 )
  579. }).map(function (filter) {
  580. filterFields[ filter[0] ] = filter[1]
  581. })
  582. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  583. if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
  584. window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
  585. method: 'POST',
  586. header: {
  587. 'contentType': 'applications/json'
  588. },
  589. credentials: 'same-origin',
  590. body: JSON.stringify({
  591. 'idGroup': idGroup,
  592. 'type': 'filter',
  593. 'filter': filterFields,
  594. })
  595. })
  596. .then(function(response) {
  597. return response.text();
  598. })
  599. .then(function(responseText) {
  600. try {
  601. return JSON.parse(responseText);
  602. } catch (e) {
  603. throw responseText;
  604. }
  605. })
  606. .then(function(result) {
  607. if (result.type == 'success') {
  608. p5UI__notifyAjaxCallback(result);
  609. resolve(result.msg);
  610. } else {
  611. reject(result.msg);
  612. }
  613. })
  614. .catch(function(error) {
  615. console.log('request failed', error)
  616. });
  617. })
  618. },
  619. allowOutsideClick: false
  620. });
  621. }
  622. function createGroupKontrahenci(event) {
  623. event.preventDefault();
  624. swal({
  625. title: 'Utwórz grupę',
  626. input: 'text',
  627. showCancelButton: true,
  628. confirmButtonText: 'Zapisz',
  629. showLoaderOnConfirm: true,
  630. preConfirm: function (NAZWA) {
  631. return new Promise(function (resolve, reject) {
  632. if (!NAZWA) reject('Proszę podać nazwę grupy');
  633. window.fetch(URL_CREATE_KONTRAHENCIS_GROUP, {
  634. method: 'POST',
  635. header: {
  636. 'contentType': 'applications/json'
  637. },
  638. credentials: 'same-origin',
  639. body: JSON.stringify({
  640. 'NAZWA': NAZWA
  641. })
  642. })
  643. .then(function(response) {
  644. return response.text();
  645. })
  646. .then(function(responseText) {
  647. try {
  648. return JSON.parse(responseText);
  649. } catch (e) {
  650. throw responseText;
  651. }
  652. })
  653. .then(function(result) {
  654. if (result.type == 'success') {
  655. p5UI__notifyAjaxCallback(result);
  656. resolve(result.body);
  657. } else {
  658. reject("Proszę podać inną nazwę grupy");
  659. }
  660. })
  661. .catch(function(error) {
  662. console.log('request failed', error)
  663. })
  664. })
  665. },
  666. allowOutsideClick: false
  667. }).then(function (groupKontrahenciData) {
  668. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  669. groupsKontrahenci = '<button class="btn btn-default" title="'+groupKontrahenciData['nazwa']+'" data-group-filter="'+groupKontrahenciData['id']+'">'+groupKontrahenciData['nazwa']+'</button>';
  670. $('#group-kontrahenci').append(groupsKontrahenci);
  671. });
  672. }
  673. function createGroupPracownicy(event) {
  674. event.preventDefault();
  675. swal({
  676. title: 'Utwórz grupę',
  677. input: 'text',
  678. showCancelButton: true,
  679. confirmButtonText: 'Zapisz',
  680. showLoaderOnConfirm: true,
  681. preConfirm: function (NAZWA) {
  682. return new Promise(function (resolve, reject) {
  683. if (!NAZWA) reject('Proszę podać nazwę grupy');
  684. window.fetch(URL_CREATE_PRACOWNICY_GROUP, {
  685. method: 'POST',
  686. header: {
  687. 'contentType': 'applications/json'
  688. },
  689. credentials: 'same-origin',
  690. body: JSON.stringify({
  691. 'NAZWA': NAZWA
  692. })
  693. })
  694. .then(function(response) {
  695. return response.text();
  696. })
  697. .then(function(responseText) {
  698. try {
  699. return JSON.parse(responseText);
  700. } catch (e) {
  701. throw responseText;
  702. }
  703. })
  704. .then(function(result) {
  705. if (result.type == 'success') {
  706. p5UI__notifyAjaxCallback(result);
  707. resolve(result.body);
  708. } else {
  709. reject("Proszę podać inną nazwę grupy");
  710. }
  711. })
  712. .catch(function(error) {
  713. console.log('request failed', error)
  714. })
  715. })
  716. },
  717. allowOutsideClick: false
  718. }).then(function (groupPracownicyData) {
  719. console.log('grupa prac2: ', groupPracownicyData);
  720. //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
  721. groupsPracownicy = '<button class="btn btn-default" title="'+groupPracownicyData['nazwa']+'" data-group-filter="'+groupPracownicyData['id']+'">'+groupPracownicyData['nazwa']+'</button>';
  722. $('#group-pracownicy').append(groupsPracownicy);
  723. });
  724. }
  725. function rootChangeForm() {
  726. //todo: do przeniesienia
  727. urlFetchKontrahenciPowiazania();
  728. var valueUrl = global.location.hash;
  729. switch (valueUrl) {
  730. case '#KONTRAHENCI':
  731. $( ".container-bi_audit_form_kontrahenci_raport" ).html( VIEW_KONTRAHENCI );
  732. urlFetchKontrahenci(1);
  733. fetchGroupKontrahenci();
  734. $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  735. $( ".container-bi_audit_form_kontrahenci_raport" ).show();
  736. break;
  737. case '#PRACOWNICY':
  738. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  739. urlFetchPracownicy(1);
  740. fetchGroupPracownicy();
  741. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  742. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  743. break;
  744. // case '#REAPORT':
  745. // $( ".container-bi_audit_form_raport_data" ).html( VIEW_TREE_REAPORT );
  746. // urlFetchKontrahenciPowiazania();
  747. // $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  748. // $( ".container-bi_audit_form_pracownicy_raport" ).hide();
  749. // $( ".container-bi_audit_form_raport_data" ).show();
  750. // break;
  751. default:
  752. $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
  753. urlFetchPracownicy(1);
  754. fetchGroupPracownicy();
  755. $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
  756. $( ".container-bi_audit_form_pracownicy_raport" ).show();
  757. break;
  758. }
  759. //aktualizacja inputa głebokości powiazan
  760. loadCurrentDepthInInput('.smad-depth');
  761. loadCurrentDepthInInput('.smad-depth-kontrahenci');
  762. updateLocalStorageBiAuditDepth('.smad-depth');
  763. updateLocalStorageBiAuditDepth('.smad-depth-kontrahenci');
  764. // aktualizacja select option czy zwracać wyniki tylko z obiektami docelowymi
  765. updateLocalStorageBiAuditOnlyTargets('#smad-select-target');
  766. updateLocalStorageBiAuditOnlyTargets('#smad-select-target-kontrahenci');
  767. // load in select selected option BI_analiza_onlyTargets
  768. loadCurrentOnlyTargetsSelect();
  769. }
  770. function getAddressData(objectValue) {
  771. var objectValue = objectValue || [];
  772. var listData = '';
  773. if (!objectValue) {
  774. return true;
  775. }
  776. objectValue.forEach (function(item) {
  777. if (item['kodPocztowy']) { listData += '<div>kod pocztowy: ' + item['kodPocztowy'] + '<div>'; }
  778. if (item['miejscowosc']) { listData += '<div>miejscowość: ' + item['miejscowosc'] + '<div>'; }
  779. if (item['nrBudynku']) { listData += '<div>nr budynku: ' + item['nrBudynku'] + '<div>'; }
  780. if (item['nrLokalu']) { listData += '<div>nr lokalu: ' + item['nrLokalu'] + '<div>'; }
  781. if (item['typAdresu']) { listData += '<div>typ adresu: ' + item['typAdresu'] + '<div>'; }
  782. if (item['ulica']) { listData += '<div>ulica: ' + item['ulica'] + '<div>'; }
  783. listData += '<div>------<div>';
  784. });
  785. return listData;
  786. }
  787. /**
  788. * Get name name group
  789. */
  790. function getNameGroupById(store, filterIdGroup) {
  791. var NAZWA = '';
  792. if (!store || filterIdGroup === 0 ) {
  793. NAZWA = 'Wszyscy';
  794. } else {
  795. $(store).each(function() {
  796. if ( parseInt(filterIdGroup) === parseInt(this.ID) ) {
  797. NAZWA = this.NAZWA;
  798. }
  799. });
  800. }
  801. return NAZWA;
  802. }
  803. function urlFetchKontrahenci(page) {
  804. hideMoreRecordFunctionsPopover()
  805. var page = page || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page');
  806. selectPage('KONTRAHENCI', page);
  807. if ( page === 1) {
  808. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
  809. }
  810. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  811. var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
  812. var fieldNameList = FIELD_LIST_KONTRAHENCI
  813. var filterFields = fieldNameList.map(function (fieldName) {
  814. return [ fieldName, frm[fieldName].value ]
  815. }).filter(function (filter) {
  816. return ( filter[1].length > 0 )
  817. }).map(function (filter) {
  818. return '' + filter[0] + '=' + filter[1]
  819. }).join('&')
  820. filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
  821. fetch(URL_FETCH_KONTRAHENCI + '&page=' + page + '&filterIdGroup=' + filterIdGroup + filterFields, {
  822. credentials: 'same-origin'
  823. })
  824. .then(function parseJSON(response) {
  825. return response.json()
  826. var filterIdGroup = filterIdGroup || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  827. })
  828. .then(function(data) {
  829. var listItemsKontrahenci = null;
  830. data.body.items.forEach (function(row) {
  831. listItemsKontrahenci += '<tr><td style="white-space:nowrap">' +
  832. '<input style="vertical-align:top" type="checkbox" name="kontrID[]" value="'+row['ID']+'" />' +
  833. '<i onClick="kontrahenciLoadMoreRecordFunctions(event, this, '+row['ID']+')" style="margin-left:6px; cursor:pointer; color:#333" class="glyphicon glyphicon-menu-hamburger" title="Więcej funkcji dla rekordu nr ' + row['ID'] + '"></i>' +
  834. '</td>' +
  835. '<td align="right">'+row["ID"]+'</td>'+
  836. '<td align="right">' + ( row["Nazwa_grupy_kapitalowej"] || '' ) + '</td>' +
  837. '<td align="right">' + ( row["Pelna_nazwa_kontrahenta"] || '' ) + '</td>' +
  838. '<td align="right">' + ( row["Numer_kontrahenta"] || '' ) + '</td>' +
  839. '<td align="right">' + ( row["Skrocona_Nazwa_Kontrahenta"] || '' ) + '</td>' +
  840. '<td align="right">' + ( row["Typ_kontrahenta"] || '' ) + '</td>' +
  841. '<td align="right">' + ( row["NIP"] || '' ) + '</td>' +
  842. '<td align="right">' + ( row["KRS"] || '' ) + '</td>' +
  843. '<td align="right">' + ( row["REGON"] || '' ) + '</td>' +
  844. '<td align="right">' + ( row["PESEL"] || '' ) + '</td>' +
  845. '<td align="right">' + ( row["Forma_prawna_dzialalnosci"] || '' ) + '</td>' +
  846. '<td align="right">' + ( row["Ulica"] || '' ) + '</td>' +
  847. '<td align="right">' + ( row["Numer_budynku"] || '' ) + '</td>' +
  848. '<td align="right">' + ( row["Numer_mieszkania_lokalu"] || '' ) + '</td>' +
  849. '<td align="right">' + ( row["Miejscowosc"] || '' ) + '</td>' +
  850. '<td align="right">' + ( row["Kod_pocztowy"] || '' ) + '</td>' +
  851. '<td align="right">' + ( row["Kraj"] || '' ) + '</td>' +
  852. '<td align="right">' + ( row["Telefon"] || '' ) + '</td>' +
  853. '<td align="right">' + ( row["Fax"] || '' ) + '</td>' +
  854. '<td align="right">' + ( row["Mail"] || '' ) + '</td>' +
  855. '<td align="right">' + ( row["A_ADM_COMPANY"] || '' ) + '</td>' +
  856. '<td align="right">' + ( row["A_CLASSIFIED"] || '' ) + '</td>' +
  857. '<td align="right">' + ( row["Dodano"] || '' ) + '</td>' +
  858. '<td align="right">' + ( row["Podmiot_dominujacy"] || '' ) + '</td>' +
  859. '<td align="right">' + ( row["Tytul_dokumentu"] || '' ) + '</td>' +
  860. '<td align="right">' + ( row["ownCompany"] || '' ) + '</td>' +
  861. '<td align="right">' + ( row["uwagi"] || '' ) + '</td></tr>';
  862. });
  863. if (data.body.pagination !== undefined) {
  864. Pagination.Init(document.getElementById('pagination-kontrahenci'), {
  865. url: BASE_URLS+'index.php?_route=UrlAction_Bocian#KONTRAHENCI',
  866. id_pagination: 'pagination-kontrahenci',
  867. type: 'KONTRAHENCI',
  868. limit: data.body.pagination.limit,
  869. total_items: data.body.pagination.total_items, // pages size
  870. size: data.body.pagination.size, // pages size
  871. page: page, // selected page
  872. step: 1 // pages before and after current
  873. });
  874. var paginationShowNextCount = 1;
  875. if ( parseInt(data.body.pagination.current) !== 1) {
  876. paginationShowNextCount = parseInt(data.body.pagination.limit) * (parseInt(data.body.pagination.current) - 1 ) + 1;
  877. }
  878. $('#paginationShowNextCount-KONTRAHENCI').text(paginationShowNextCount);
  879. $('#smad-filter-desc-kontrahenci').text(data.body.pagination.total_items);
  880. if (data.body.pagination.total_items > 0) {
  881. var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
  882. btnAddAll.on('click', { pagination: data.body.pagination }, function (event) {
  883. // event.data.pagination: { [ filter_idGroup: ... ] }
  884. // fetch ids from request, set to LocatStorage, update selected on gui
  885. var postData = {}
  886. if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
  887. Object.keys(event.data.pagination).filter(function (key) {
  888. return ('f_' === key.substr(0, 2))
  889. }).forEach(function (filterKey) {
  890. var value = event.data.pagination[filterKey]
  891. postData[filterKey] = value
  892. })
  893. var thisButton = $(this)
  894. thisButton.attr('disabled', true)
  895. thisButton.text( thisButton.text() + '...' )
  896. p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie kontrahentów..." })
  897. global.fetch(URL_FETCH_KONTRAHENCI_IDS_AJAX, {
  898. credentials: 'same-origin',
  899. method: 'POST',
  900. headers: {
  901. 'Content-Type': 'application/json'
  902. },
  903. body: JSON.stringify(postData)
  904. })
  905. .then(function __parseJSON(response) {
  906. return response.json()
  907. })
  908. .then(function (json) {
  909. if ('success' === json.type && json.body && json.body.ids) {
  910. updateListIdBiAuditReaport('KONTRAHENCI', json.body.ids.map(function (id) {
  911. return parseInt(id)
  912. }))
  913. jQuery('#body-kontrahenci').find('input[name="kontrID[]"]').attr('checked', true)
  914. thisButton.attr('disabled', false)
  915. var txt = thisButton.text()
  916. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  917. p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" kontrahentów" })
  918. }
  919. })
  920. .catch(function (e) {
  921. p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
  922. thisButton.attr('disabled', false)
  923. var txt = thisButton.text()
  924. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  925. })
  926. })
  927. $('#smad-filter-desc-kontrahenci').append(btnAddAll);
  928. }
  929. }
  930. var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'), filterIdGroup);
  931. $('#smad-filter-head-title-kontrahenci').text(groupSelectData);
  932. console.log('kontrahenci groupSelectData: ', groupSelectData);
  933. $( "#body-kontrahenci" ).html(listItemsKontrahenci);
  934. checkAll('KONTRAHENCI');
  935. catchEventCheckbox('KONTRAHENCI');
  936. checkedChoiseItems('KONTRAHENCI', getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') );
  937. // $( ".container-bi_audit_raport" ).append( data.body.view );
  938. console.log('request succeeded with JSON responseKontrahenci', data)
  939. updateTopCounters();
  940. }).catch(function(error) {
  941. console.log('request failed', error)
  942. })
  943. }
  944. function urlFetchPracownicy(page) {
  945. hideMoreRecordFunctionsPopover()
  946. var page = page || getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page');
  947. if ( page === 1) {
  948. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
  949. }
  950. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  951. selectPage('PRACOWNICY', page);
  952. var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
  953. var fieldNameList = FIELD_LIST_PRACOWNICY
  954. var filterFields = fieldNameList.filter(function (fieldName) {
  955. if (!frm[fieldName]) console.log('Err missing field: "'+fieldName+'"')
  956. return (frm[fieldName]) ? true : false
  957. }).map(function (fieldName) {
  958. return [ fieldName, frm[fieldName].value ]
  959. }).filter(function (filter) {
  960. return ( filter[1].length > 0 )
  961. }).map(function (filter) {
  962. return '' + filter[0] + '=' + filter[1]
  963. }).join('&')
  964. filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
  965. fetch(URL_FETCH_PRACOWNICY + '&page=' + page + '&filterIdGroup=' + filterIdGroup + filterFields, {
  966. credentials: 'same-origin'
  967. })
  968. .then(function parseJSON(response) {
  969. return response.json()
  970. })
  971. .then(function(data) {
  972. var addresPerson = '';
  973. var listItemsPracownik = null;
  974. console.log('urlFetchPracownicy', data.body.items);
  975. data.body.items.forEach (function(row) {
  976. if (row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]) {
  977. addresPerson = getAddressData(row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]);
  978. }
  979. listItemsPracownik += '<tr><td style="white-space:nowrap">' +
  980. '<input style="vertical-align:top" type="checkbox" name="prID[]" value="'+row['ID']+'" />' +
  981. '<i onClick="pracownicyLoadMoreRecordFunctions(event, this, '+row['ID']+')" style="margin-left:6px; cursor:pointer; color:#333" class="glyphicon glyphicon-menu-hamburger" title="Więcej funkcji dla rekordu nr ' + row['ID'] + '"></i>' +
  982. '</td>' +
  983. '<td align="right">'+row["ID"]+'</td>' +
  984. '<td align="right">' + ( row["imiona"] || '' ) + '</td>' +
  985. '<td align="right">' + ( row["nazwisko"] || '' ) + '</td>' +
  986. '<td align="right">' + ( row["nip"] || '' ) + '</td>' +
  987. '<td align="right">' + ( row["pesel"] || '' ) + '</td>' +
  988. '<td align="right">' + ( row["regon"] || '' ) + '</td>' +
  989. '<td align="right">' + ( row["source"] || '' ) + '</td>' +
  990. '<td align="right">' + ( row["jednostka_organizacyjna"] || '' ) + '</td>' +
  991. '<td align="right">' + ( row["A_STATUS"] || '' ) + '</td>' +
  992. '<td align="right">' + ( row["A_STATUS_INFO"] || '' ) + '</td>' +
  993. '<td align="right">' + ( row["L_APPOITMENT_USER"] || '' ) + '</td>' +
  994. '<td align="right">'+ addresPerson +'</td></tr>';
  995. });
  996. if (data.body.pagination.size) {
  997. Pagination.Init(document.getElementById('pagination-pracownicy'), {
  998. url: BASE_URLS+'index.php?_route=UrlAction_Bocian#PRACOWNICY',
  999. id_pagination: 'pagination-pracownicy',
  1000. type: 'PRACOWNICY',
  1001. limit: data.body.pagination.limit,
  1002. total_items: data.body.pagination.total_items, // pages size
  1003. size: data.body.pagination.size, // pages size
  1004. page: data.body.pagination.current, // selected page
  1005. step: 1 // pages before and after current
  1006. });
  1007. var paginationShowNextCount = 1;
  1008. if ( parseInt(data.body.pagination.current) !== 1) {
  1009. paginationShowNextCount = parseInt(data.body.pagination.limit) * (parseInt(data.body.pagination.current) - 1 ) + 1;
  1010. }
  1011. $('#paginationShowNextCount-PRACOWNICY').text(paginationShowNextCount);
  1012. $('#smad-filter-desc-pracownicy').text(data.body.pagination.total_items);
  1013. if (data.body.pagination.total_items > 0) {
  1014. var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
  1015. btnAddAll.on('click', { pagination: data.body.pagination }, function (event) {
  1016. // event.data.pagination: { [ filter_idGroup: ... ] }
  1017. // fetch ids from request, set to LocatStorage, redirect to '#KONTRAHENCI'
  1018. var postData = {}
  1019. if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
  1020. Object.keys(event.data.pagination).filter(function (key) {
  1021. return ('f_' === key.substr(0, 2))
  1022. }).forEach(function (filterKey) {
  1023. var value = event.data.pagination[filterKey]
  1024. postData[filterKey] = value
  1025. })
  1026. var thisButton = $(this)
  1027. thisButton.attr('disabled', true)
  1028. thisButton.text( thisButton.text() + '...' )
  1029. p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie pracowników..." })
  1030. global.fetch(URL_FETCH_PRACOWNICY_IDS_AJAX, {
  1031. credentials: 'same-origin',
  1032. method: 'POST',
  1033. headers: {
  1034. 'Content-Type': 'application/json'
  1035. },
  1036. body: JSON.stringify(postData)
  1037. })
  1038. .then(function __parseJSON(response) {
  1039. return response.json()
  1040. })
  1041. .then(function (json) {
  1042. if ('success' === json.type && json.body && json.body.ids) {
  1043. updateListIdBiAuditReaport('PRACOWNICY', json.body.ids.map(function (id) {
  1044. return parseInt(id)
  1045. }))
  1046. thisButton.attr('disabled', false)
  1047. var txt = thisButton.text()
  1048. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  1049. p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" pracowników" })
  1050. window.location.hash = 'KONTRAHENCI'
  1051. }
  1052. })
  1053. .catch(function (e) {
  1054. p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
  1055. thisButton.attr('disabled', false)
  1056. var txt = thisButton.text()
  1057. thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
  1058. })
  1059. })
  1060. $('#smad-filter-desc-pracownicy').append(btnAddAll);
  1061. }
  1062. }
  1063. // wyświetlenie wybranej grupy w naglówku nad tabela
  1064. var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups'), filterIdGroup);
  1065. $('#smad-filter-head-title-pracownicy').text(groupSelectData);
  1066. // zaladaowanie listy pracowników
  1067. $( "#body-pracownicy" ).html( listItemsPracownik);
  1068. checkAll('PRACOWNICY');
  1069. catchEventCheckbox('PRACOWNICY');
  1070. checkedChoiseItems('PRACOWNICY', getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') );
  1071. updateTopCounters();
  1072. }).catch(function(error) {
  1073. console.log('request failed', error)
  1074. })
  1075. }
  1076. function selectPage(type, nrPage) {
  1077. var type = type.toLowerCase();
  1078. $('#pagination-' + type + ' ul li a').each(function(index, value){
  1079. if (this.text === nrPage) {
  1080. $(this).addClass('active');
  1081. } else {
  1082. $(this).removeClass('active');
  1083. }
  1084. });
  1085. }
  1086. function checkAll(type) {
  1087. $('#checkAll-' + type).change(function() {
  1088. var valueCheckbox = null;
  1089. var checkboxes = $('form').find(':checkbox');
  1090. if($(this).prop('checked')) {
  1091. checkboxes.prop('checked', true);
  1092. //valueCheckbox = checkboxes.prop("checked");
  1093. var allValsChecked = [];
  1094. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  1095. if (this.value !== 'on') {
  1096. allValsChecked.push(parseInt(this.value));
  1097. }
  1098. }).get();
  1099. updateListIdBiAuditReaport(type, allValsChecked);
  1100. } else {
  1101. checkboxes.prop('checked', false);
  1102. var allValsUnChecked = [];
  1103. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  1104. if (this.value !== 'on') {
  1105. allValsUnChecked.push(parseInt(this.value));
  1106. }
  1107. }).get();
  1108. deleteListIdBiAuditReaport(type, allValsUnChecked);
  1109. }
  1110. // update count selected IDs
  1111. updateCountItemCheckedByType(type.toLowerCase());
  1112. });
  1113. }
  1114. /**
  1115. * Select again checkbox before selected item chekbox from storage (pracownicy/kontrahenci)
  1116. */
  1117. function checkedChoiseItems(type, store) {
  1118. updateCountItemCheckedByType(type.toLowerCase());
  1119. var idElement = 'smad-table-' + type;
  1120. // if id element exist
  1121. if (document.getElementById(idElement)) {
  1122. // if not checked
  1123. if (!store) {
  1124. return false;
  1125. }
  1126. // checked again if user selected Item (pracownicy/kontrahent)
  1127. for (i = 0; i < store.length; i++) {
  1128. $('#body-'+type.toLowerCase() +' input[type=checkbox] ').map(function(k, v) {
  1129. if ( store[i] === parseInt(this.value) ){
  1130. $(this).prop('checked', true);
  1131. }
  1132. }).get();
  1133. }
  1134. }
  1135. $('#smad-table-' + type + ' input[type=checkbox]').on( 'load', function() {
  1136. var itemsCHecked = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1137. getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1138. if (itemsCHecked.lenght === 0 ) {
  1139. return;
  1140. }
  1141. var valueCheckbox = null;
  1142. var checkboxes = $('form').find(':checkbox');
  1143. if($(this).prop('checked')) {
  1144. checkboxes.prop('checked', true);
  1145. var allValsChecked = [];
  1146. var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
  1147. if (this.value !== 'on') {
  1148. allValsChecked.push(parseInt(this.value));
  1149. }
  1150. }).get();
  1151. updateListIdBiAuditReaport(type, allValsChecked);
  1152. } else {
  1153. checkboxes.prop('checked', false);
  1154. var allValsUnChecked = [];
  1155. var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
  1156. if (this.value !== 'on') {
  1157. allValsUnChecked.push(parseInt(this.value));
  1158. }
  1159. }).get();
  1160. deleteListIdBiAuditReaport(type, allValsUnChecked);
  1161. }
  1162. });
  1163. }
  1164. function catchEventCheckbox(type) {
  1165. $('#smad-table-' + type + ' input[type="checkbox"]').on('change', function() {
  1166. if($(this).is(":checked")) {
  1167. var allValsChecked = [];
  1168. if (this.value !== 'on') {
  1169. allValsChecked.push(parseInt(this.value));
  1170. }
  1171. updateListIdBiAuditReaport(type, allValsChecked);
  1172. } else {
  1173. var allValsUnChecke = [];
  1174. if (this.value !== 'on') {
  1175. allValsUnChecke.push(parseInt(this.value));
  1176. }
  1177. deleteListIdBiAuditReaport(type, allValsUnChecke);
  1178. }
  1179. // update count selected IDs
  1180. updateCountItemCheckedByType(type.toLowerCase());
  1181. });
  1182. }
  1183. function clearSelectedCheckbox() {
  1184. $('#checkAll-PRACOWNICY').prop('checked', false)
  1185. $('#checkAll-KONTRAHENCI').prop('checked', false)
  1186. }
  1187. function updateListIdBiAuditReaport(type, valueArray) {
  1188. var currentStoragePracownicyIds = [];
  1189. var updateListPracownicyIds = null;
  1190. var currentStorageKontrahenciIds = [];
  1191. var updateListKontrahenciIds = null;
  1192. if ( type == 'PRACOWNICY') {
  1193. currentStoragePracownicyIds = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1194. if(currentStoragePracownicyIds !== null) {
  1195. updateListPracownicyIds = [...new Set([...currentStoragePracownicyIds ,...valueArray])];
  1196. }
  1197. else {
  1198. updateListPracownicyIds = valueArray;
  1199. }
  1200. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', updateListPracownicyIds);
  1201. }
  1202. if ( type == 'KONTRAHENCI') {
  1203. currentStorageKontrahenciIds = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1204. if(currentStorageKontrahenciIds !== null) {
  1205. updateListKontrahenciIds = [...new Set([...currentStorageKontrahenciIds ,...valueArray])];
  1206. }
  1207. else {
  1208. updateListKontrahenciIds = valueArray;
  1209. }
  1210. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', updateListKontrahenciIds);
  1211. }
  1212. }
  1213. function deleteListIdBiAuditReaport(type, valueArray) {
  1214. var currentStoragePracownicyIds = [];
  1215. var updateListPracownicyIds = null;
  1216. if ( type == 'PRACOWNICY') {
  1217. deleteItemLocalStorage('Bocian.biAuditForm.pracownicyIds', valueArray);
  1218. }
  1219. if ( type == 'KONTRAHENCI') {
  1220. deleteItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', valueArray);
  1221. }
  1222. }
  1223. // filter group detect
  1224. function fetchGroupPracownicy() {
  1225. fetch(URL_FETCH_GROUP_PRACOWNICY, {
  1226. credentials: 'same-origin'
  1227. })
  1228. .then(function parseJSON(response) {
  1229. return response.json()
  1230. })
  1231. .then(function(data) {
  1232. setItemLocalStorage('Bocian.biAuditForm.pracownicy.groups', data.body.itmesGroupPracownicy);
  1233. if (data.body.itmesGroupPracownicy === null) {
  1234. return;
  1235. }
  1236. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
  1237. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1238. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', filterIdGroup);
  1239. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1240. var groupsPracownicy = '';
  1241. var activeButton = '';
  1242. data.body.itmesGroupPracownicy.forEach (function(row) {
  1243. if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-pracownicy button.active').removeClass('active'); }
  1244. groupsPracownicy += '<button class="btn btn-default '+activeButton+'" title="' + row['NAZWA'] + '" data-group-filter="' + row['ID'] + '">' + row['NAZWA'] + '</button>';
  1245. });
  1246. $("#group-pracownicy").append(groupsPracownicy);
  1247. updateCountItemCheckedByType('pracownicy');
  1248. // detect filter group
  1249. detectChoiseFilter();
  1250. }).catch(function(error) {
  1251. console.log('request failed', error)
  1252. });
  1253. }
  1254. function fetchGroupKontrahenci() {
  1255. fetch(URL_FETCH_GROUP_KONTRAHENCI, {
  1256. credentials: 'same-origin'
  1257. })
  1258. .then(function parseJSON(response) {
  1259. return response.json()
  1260. })
  1261. .then(function(data) {
  1262. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups', data.body.itemsGroupKontrahenci);
  1263. if (data.body.itemsGroupKontrahenci === null) {
  1264. return;
  1265. }
  1266. var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
  1267. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1268. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', filterIdGroup);
  1269. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1270. var groupsKontrahenci = '';
  1271. var activeButton = '';
  1272. data.body.itemsGroupKontrahenci.forEach (function(row) {
  1273. if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-kontrahenci button.active').removeClass('active'); }
  1274. groupsKontrahenci += '<button class="btn btn-default '+activeButton+'" title="'+row['NAZWA']+'" data-group-filter="'+row['ID']+'">'+row['NAZWA']+'</button>';
  1275. });
  1276. $("#group-kontrahenci").append(groupsKontrahenci);
  1277. updateCountItemCheckedByType('kontrahenci');
  1278. // detect filter group
  1279. detectChoiseFilter();
  1280. console.log('request succeeded with JSON fetchGroupKontrahenci', data.body.itemsGroupKontrahenci);
  1281. }).catch(function(error) {
  1282. console.log('request failed', error)
  1283. });
  1284. }
  1285. function detectChoiseFilter() {
  1286. $('#group-kontrahenci').on('click', 'button', function(evt) {
  1287. $('#group-kontrahenci button.active').removeClass('active');
  1288. $(this).addClass('active');
  1289. // pobranie id grupy kliknietego buttonu
  1290. var filterIdGroup = $(this).attr("data-group-filter");
  1291. // aktaulna wartość zagłebienia
  1292. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1293. // czy zwracać wyniki tylko z obiektami docelowymi
  1294. var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
  1295. //reset LocalStorage
  1296. // defaultBIAuditLocalStorage();
  1297. // ustawienie ostaniej wartości zagłebienia przed resete
  1298. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1299. // czy zwracać wyniki tylko z obiektami docelowymi
  1300. setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', analizaOnlyTargets);
  1301. // ustawić id grupy do sesyjnej
  1302. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', parseInt(filterIdGroup));
  1303. // wywylac funckje pobrania danych
  1304. urlFetchKontrahenci(1);
  1305. });
  1306. $('#group-pracownicy').on('click', 'button', function(evt) {
  1307. $('#group-pracownicy button.active').removeClass('active');
  1308. $(this).addClass('active');
  1309. // pobranie id grupy kliknietego buttonu
  1310. var filterIdGroup = $(this).attr("data-group-filter");
  1311. // aktaulna wartość zagłebienia
  1312. var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
  1313. //reset LocalStorage
  1314. // defaultBIAuditLocalStorage();
  1315. // ustawienie ostaniej wartości zagłebienia przed resete
  1316. setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
  1317. // ustawić id grupy do sesyjnej
  1318. setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', parseInt(filterIdGroup));
  1319. // wywylac funckje pobrania danych
  1320. urlFetchPracownicy(1);
  1321. });
  1322. }
  1323. // Local storage
  1324. function setItemLocalStorage(key, array) {
  1325. localStorage.setItem(key, JSON.stringify(array));
  1326. }
  1327. function getItemLocalStorage(key) {
  1328. var retrievedData = localStorage.getItem(key);
  1329. var response = JSON.parse(retrievedData);
  1330. return response;
  1331. }
  1332. function deleteItemLocalStorage(key, itemsArray) {
  1333. var currentStorageArray = getItemLocalStorage(key);
  1334. var newStorageArray = removeItemArrayInArray(currentStorageArray, itemsArray);
  1335. setItemLocalStorage(key, newStorageArray);
  1336. }
  1337. /**
  1338. * arr - array
  1339. * item - search item
  1340. */
  1341. function removeItemInArray(arr, item) {
  1342. for(var i = arr.length; i--;) {
  1343. if(arr[i] === item) {
  1344. arr.splice(i, 1);
  1345. }
  1346. }
  1347. return arr;
  1348. }
  1349. /**
  1350. * arr - array
  1351. * item - array list items
  1352. */
  1353. function removeItemArrayInArray(arr, itemsArray) {
  1354. for(var i = arr.length; i--;) {
  1355. for(var j = itemsArray.length; j--;) {
  1356. if(arr[i] === itemsArray[j]) {
  1357. arr.splice(i, 1);
  1358. }
  1359. }
  1360. }
  1361. return arr;
  1362. }
  1363. /**
  1364. * Cleart list local storage by type
  1365. * typeNameLocalStorage - name (praconwicy/kontrahenci)
  1366. */
  1367. function clearListLocalStorageByType(typeNameLocalStorage) {
  1368. if (typeNameLocalStorage === 'pracownicy') {
  1369. setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
  1370. }
  1371. if (typeNameLocalStorage === 'kontrahenci') {
  1372. setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
  1373. }
  1374. // update count selected item
  1375. updateCountItemCheckedByType(typeNameLocalStorage);
  1376. // unchecked checkbox
  1377. $('#smad-table-'+typeNameLocalStorage.toUpperCase()+' form').find(':checkbox').prop('checked', false);
  1378. }
  1379. /**
  1380. * Update count selected pracowniyc/kontrahenci
  1381. */
  1382. function updateCountItemCheckedByType(typeNameLocalStorage) {
  1383. var countId = 0;
  1384. updateTopCounters();
  1385. if (typeNameLocalStorage === 'pracownicy') {
  1386. var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1387. if (countPracownicy === null || countPracownicy === undefined) {
  1388. return countId;
  1389. }
  1390. countId = Object.keys(countPracownicy).length;
  1391. $('#count-selected-item-pracownicy').text(countId);
  1392. }
  1393. if (typeNameLocalStorage === 'kontrahenci') {
  1394. var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1395. if (countKontrahenci === null || countKontrahenci === undefined) {
  1396. return countId;
  1397. }
  1398. countId = Object.keys(countKontrahenci).length;
  1399. $('#count-selected-item-kontrahenci').text(countId);
  1400. }
  1401. return countId;
  1402. }
  1403. function updateTopCounters() {
  1404. var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
  1405. var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
  1406. var totalPracownicy = (countPracownicy) ? Object.keys(countPracownicy).length : 0;
  1407. var totalKontrahenci = (countKontrahenci) ? Object.keys(countKontrahenci).length : 0;
  1408. console.warn({totalPracownicy: totalPracownicy, totalKontrahenci: totalKontrahenci})
  1409. $('.top--count-selected-item-pracownicy').text(totalPracownicy ? '('+totalPracownicy+')' : '');
  1410. $('.top--count-selected-item-kontrahenci').text(totalKontrahenci ? '('+totalKontrahenci+')' : '');
  1411. $('.bottom--count-selected-item-pracownicy').text(totalPracownicy ? "Wybrano: (" + totalPracownicy + ") pracownika/ów" : '');
  1412. $('.bottom--count-selected-item-kontrahenci').text(totalKontrahenci ? "Wybrano: (" + totalKontrahenci + ") kontrahenta/ów" : '');
  1413. // disable button generate reaport if not choise 'praconwicy' or 'kontrahenci'
  1414. if ( totalPracownicy === 0 && totalKontrahenci === 0 ) {
  1415. $('.smad-generate-reaport-button').addClass('disabled');
  1416. } else {
  1417. $('.smad-generate-reaport-button').removeClass('disabled');
  1418. }
  1419. }
  1420. // Pagination
  1421. var Pagination = {
  1422. code: '', // end show html paginations
  1423. clickPage: 1, // set default 1 page
  1424. // --------------------
  1425. // Utility
  1426. // --------------------
  1427. // initialize default data
  1428. Extend: function(data) {
  1429. data = data || {};
  1430. Pagination.url = data.url;
  1431. Pagination.id_pagination = data.id_pagination;
  1432. Pagination.type = data.type;
  1433. Pagination.limit = data.limit;
  1434. Pagination.total_items = data.total_items;
  1435. Pagination.size = data.size || 2;
  1436. Pagination.page = data.page || 1;
  1437. Pagination.step = data.step || 3;
  1438. },
  1439. // add pages by number (from [s] to [f])
  1440. Add: function(s, f) {
  1441. for (var i = s; i < f; i++) {
  1442. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">' + i + '</a></li>';
  1443. }
  1444. },
  1445. // add last page with separator
  1446. Last: function() {
  1447. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">>></a></li>';
  1448. },
  1449. // add first page with separator
  1450. First: function() {
  1451. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><<</a></li>';
  1452. },
  1453. // add last page with separator
  1454. Next: function() {
  1455. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">></a></li>';
  1456. },
  1457. // add first page with separator
  1458. Prev: function() {
  1459. Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><</a></li>';
  1460. },
  1461. // --------------------
  1462. // Handlers
  1463. // --------------------
  1464. // change page
  1465. Click: function() {
  1466. clearSelectedCheckbox();
  1467. var selectPage = $("#pagination-"+Pagination.type.toLowerCase()+' .tblAjax__footer__toolbar__pagination').find('a.active').text();
  1468. Pagination.clickPage = +this.innerHTML || '';
  1469. if ( selectPage === NaN || selectPage > Pagination.size) { selectPage = 1; }
  1470. switch (this.innerHTML) {
  1471. case '&gt;&gt;': // last
  1472. Pagination.clickPage = Pagination.size;
  1473. break;
  1474. case '&lt;&lt;': // first
  1475. Pagination.clickPage = 1;
  1476. break;
  1477. case '&lt;': // prev
  1478. Pagination.clickPage = parseInt(selectPage) - 1;
  1479. if (Pagination.clickPage < 1) {
  1480. Pagination.clickPage = 1;
  1481. }
  1482. break;
  1483. case '&gt;': // next
  1484. Pagination.clickPage = parseInt(selectPage) + 1;
  1485. if (Pagination.clickPage > Pagination.size) {
  1486. Pagination.clickPage = Pagination.size;
  1487. }
  1488. break;
  1489. }
  1490. if ( Pagination.type === 'KONTRAHENCI' ) {
  1491. setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', Pagination.clickPage);
  1492. Pagination.page = urlFetchKontrahenci(Pagination.clickPage);
  1493. }
  1494. else if ( Pagination.type === 'PRACOWNICY' ){
  1495. setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', Pagination.clickPage);
  1496. Pagination.page = urlFetchPracownicy(Pagination.clickPage);
  1497. }
  1498. Pagination.Start();
  1499. },
  1500. // --------------------
  1501. // Script structure pagination
  1502. // --------------------
  1503. // binding pages
  1504. Bind: function() {
  1505. var a = Pagination.e.getElementsByTagName('a');
  1506. var currentPage = Pagination.clickPage || 1;
  1507. for (var i = 0; i < a.length; i++) {
  1508. if (+a[i].innerHTML === Pagination.page) a[i].className = 'btn btn-default active';
  1509. a[i].addEventListener('click', Pagination.Click, false);
  1510. }
  1511. },
  1512. // write pagination
  1513. Finish: function() {
  1514. Pagination.e.innerHTML = Pagination.code;
  1515. Pagination.code = '</ul></nav>';
  1516. Pagination.Bind();
  1517. },
  1518. // find pagination type
  1519. Start: function() {
  1520. Pagination.code = '';
  1521. if ( Pagination.type === 'KONTRAHENCI' ) {
  1522. Pagination.code = '<div class="foot-info tblAjax__footer__toolbar__info footer_pagination_menu_items"><p>Wiersze od <span id="paginationShowNextCount-KONTRAHENCI"></span> do ' + Pagination.total_items + ' z ' + Pagination.total_items + '</p></div>';
  1523. } else if ( Pagination.type === 'PRACOWNICY' ) {
  1524. Pagination.code = '<div class="foot-info tblAjax__footer__toolbar__info footer_pagination_menu_items"><p>Wiersze od <span id="paginationShowNextCount-PRACOWNICY"></span> do ' + Pagination.total_items + ' z ' + Pagination.total_items + '</p></div>';
  1525. }
  1526. Pagination.code += '<nav aria-label="Page navigation" class="footer_pagination_menu_items"><ul class="btn-group tblAjax__footer__toolbar__pagination smad-pagination">';
  1527. Pagination.First();
  1528. Pagination.Prev();
  1529. if ( Pagination.type === 'KONTRAHENCI' ) {
  1530. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page') || 1;
  1531. }
  1532. else if ( Pagination.type === 'PRACOWNICY' ) {
  1533. Pagination.page = getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page') || 1;
  1534. }
  1535. if ( Pagination.page > Pagination.size ) {
  1536. Pagination.page = 1;
  1537. }
  1538. if (Pagination.size < Pagination.step * 2 + 6) {
  1539. Pagination.Add(1, Pagination.size + 1);
  1540. }
  1541. else if (Pagination.page < Pagination.step * 2 + 1) {
  1542. Pagination.Add(1, Pagination.step * 2 + 4);
  1543. }
  1544. else if (Pagination.page > Pagination.size - Pagination.step * 2) {
  1545. Pagination.Add(Pagination.size - Pagination.step * 2 - 2, Pagination.size + 1);
  1546. }
  1547. else {
  1548. Pagination.Add(Pagination.page - Pagination.step, Pagination.page + Pagination.step + 1);
  1549. }
  1550. Pagination.Next();
  1551. Pagination.Last();
  1552. Pagination.Finish();
  1553. },
  1554. // --------------------
  1555. // Initialization
  1556. // --------------------
  1557. // binding buttons
  1558. Buttons: function(e) {
  1559. var nav = e.getElementsByTagName('a');
  1560. },
  1561. // create skeleton
  1562. Create: function(e) {
  1563. var html = [
  1564. '<div></div>' // pagination container
  1565. ];
  1566. e.innerHTML = html.join('');
  1567. Pagination.e = e.getElementsByTagName('div')[0];
  1568. Pagination.Buttons(e);
  1569. },
  1570. // init
  1571. Init: function(e, data) {
  1572. Pagination.Extend(data);
  1573. Pagination.Create(e);
  1574. Pagination.Start();
  1575. }
  1576. };
  1577. function todo__fetchRaport(id) {
  1578. p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', {
  1579. primaryKey: id,
  1580. resolve: 'all',
  1581. resolveDepth: 3,
  1582. }).then(function (features) {
  1583. console.log('features', features)
  1584. }).catch(function (e) {
  1585. console.warn(e)
  1586. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  1587. })
  1588. }
  1589. function removeFiltersPracownicy(event, btnNode) {
  1590. event.preventDefault()
  1591. var fieldNameList = FIELD_LIST_PRACOWNICY
  1592. fieldNameList.forEach(function (fieldName) {
  1593. btnNode.form[fieldName].value = ''
  1594. })
  1595. urlFetchPracownicy(1)
  1596. }
  1597. function removeFiltersKontrahenci(event, btnNode) {
  1598. event.preventDefault()
  1599. var fieldNameList = FIELD_LIST_KONTRAHENCI
  1600. fieldNameList.forEach(function (fieldName) {
  1601. btnNode.form[fieldName].value = ''
  1602. })
  1603. urlFetchKontrahenci(1)
  1604. }
  1605. function onChangeFiltersPracownicy(event, inputNode) {
  1606. urlFetchPracownicy(1)
  1607. }
  1608. function onKeypressFiltersPracownicy(event, inputNode) {
  1609. if ("Enter" === event.key) {
  1610. event.stopPropagation()
  1611. event.preventDefault()
  1612. urlFetchPracownicy(1)
  1613. return false
  1614. }
  1615. }
  1616. function onChangeFiltersKontrahenci(event, inputNode) {
  1617. urlFetchKontrahenci(1)
  1618. }
  1619. function onKeypressFiltersKontrahenci(event, inputNode) {
  1620. if ("Enter" === event.key) {
  1621. event.stopPropagation()
  1622. event.preventDefault()
  1623. urlFetchKontrahenci(1)
  1624. return false
  1625. }
  1626. }
  1627. function loadMoreRecordFunctions(event, node, rowPK, namespace) {
  1628. var _node = node
  1629. var _rowPK = rowPK
  1630. var toShow = true
  1631. if (RECORD_MORE_FUNCTIONS_OPENED_NODE) {
  1632. if (RECORD_MORE_FUNCTIONS_OPENED_NODE === node) toShow = false
  1633. if (RECORD_MORE_FUNCTIONS_OPENED_NODE !== node) {
  1634. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  1635. }
  1636. }
  1637. RECORD_MORE_FUNCTIONS_OPENED_NODE = node
  1638. // jQuery(node).popover({
  1639. // container: 'body',
  1640. // placement: 'right',
  1641. // trigger: 'click',
  1642. // template: '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">' +
  1643. // '<div class="arrow"></div>' +
  1644. // '<div style="display:block;position:relative;">' +
  1645. // '<div class="popover-title">' +
  1646. // '</div>' +
  1647. // '<button type="button" class="close" onclick="return hideMoreRecordFunctionsPopover();" style="position:absolute;right:8px;top:6px;">&times;</button>' +
  1648. // '</div>' +
  1649. // '<div class="popover-content"></div>' +
  1650. // '</div>' +
  1651. // '',
  1652. // html: true,
  1653. // })
  1654. // jQuery(node).popover('show')
  1655. global.fetch(BASE_URLS + 'index.php?_route=ViewTableAjax&namespace=' + namespace + '&_task=moreFunctionsCellAjax&ID=' + rowPK, {
  1656. credentials: 'same-origin'
  1657. }).then(function (response) {
  1658. return response.json()
  1659. }).then(function (json) {
  1660. var funcListWrap = $('<div></div>')
  1661. var funcListNode = $('<ul class="list-unstyled popoverRowFunctions"></ul>').appendTo(funcListWrap)
  1662. if (_node === RECORD_MORE_FUNCTIONS_OPENED_NODE) {
  1663. if (json && 'success' === json.type && json.rowFunctions && json.rowFunctions.length > 0) {
  1664. json.rowFunctions.forEach(function(funObj) {
  1665. var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, _rowPK, {ico: true, label: true});
  1666. var funcItemNode = jQuery('<li></li>')
  1667. funcItemNode.append(funcNode)
  1668. funcListNode.append(funcItemNode)
  1669. });
  1670. }
  1671. }
  1672. // jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  1673. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover({
  1674. container: 'body',
  1675. placement: 'right',
  1676. trigger: 'click',
  1677. template: '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">' +
  1678. '<div class="arrow"></div>' +
  1679. '<div style="display:block;position:relative;">' +
  1680. '<div class="popover-title">' +
  1681. '</div>' +
  1682. '<button type="button" class="close" onclick="return hideMoreRecordFunctionsPopover();" style="position:absolute;right:8px;top:6px;">&times;</button>' +
  1683. '</div>' +
  1684. '<div class="popover-content"></div>' +
  1685. '</div>' +
  1686. '',
  1687. html: true,
  1688. content: funcListWrap.html(),
  1689. })
  1690. jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('show')
  1691. }).catch(function (err) {
  1692. // console.log('err', err)
  1693. })
  1694. }
  1695. var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
  1696. var defaultsProps = {
  1697. ico: true,
  1698. label: false
  1699. },
  1700. props = jQuery.extend({}, defaultsProps, props);
  1701. funcNode = $('<a href="#" style="margin:0 2px;"></a>')
  1702. ;
  1703. if ('href' in funObj) funcNode.attr('href', p5Utils__format(funObj.href, [rowPK]));
  1704. if (props.ico) {
  1705. if ('ico' in funObj) funcNode.append('<span class="' + funObj.ico + '"></span>');
  1706. }
  1707. if ('onclick' in funObj) funcNode.attr('onclick', p5Utils__format(funObj.onclick, [rowPK]));
  1708. if ('title' in funObj) funcNode.attr('title', funObj.title);
  1709. if ('target' in funObj) funcNode.attr('target', funObj.target);
  1710. if (props.label) {
  1711. if ('label' in funObj) {
  1712. funcNode.append(' ' + funObj.label);
  1713. } else if ('title' in funObj) {
  1714. funcNode.append(' ' + funObj.title);
  1715. }
  1716. }
  1717. return funcNode;
  1718. };
  1719. global.p5UI_TableAjax_generateFunctionNode = p5UI_TableAjax_generateFunctionNode
  1720. $(document).ready(function(){
  1721. rootChangeForm();
  1722. detectChoiseFilter();
  1723. updateTopCounters();
  1724. });
  1725. global.hideMoreRecordFunctionsPopover = function() {
  1726. if (RECORD_MORE_FUNCTIONS_OPENED_NODE) jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
  1727. }
  1728. global.pracownicyLoadMoreRecordFunctions = function(event, node, rowPK) {
  1729. return loadMoreRecordFunctions(event, node, rowPK, "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY")
  1730. }
  1731. global.kontrahenciLoadMoreRecordFunctions = function(event, node, rowPK) {
  1732. return loadMoreRecordFunctions(event, node, rowPK, "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI")
  1733. }
  1734. global.removeFiltersPracownicy = removeFiltersPracownicy;
  1735. global.removeFiltersKontrahenci = removeFiltersKontrahenci;
  1736. global.onChangeFiltersPracownicy = onChangeFiltersPracownicy;
  1737. global.onKeypressFiltersPracownicy = onKeypressFiltersPracownicy;
  1738. global.onChangeFiltersKontrahenci = onChangeFiltersKontrahenci;
  1739. global.onKeypressFiltersKontrahenci = onKeypressFiltersKontrahenci;
  1740. global.checkAll = checkAll;
  1741. global.checkedChoiseItems = checkedChoiseItems;
  1742. global.catchEventCheckbox = catchEventCheckbox;
  1743. global.clearSelectedCheckbox = clearSelectedCheckbox;
  1744. global.getNameGroupById = getNameGroupById;
  1745. global.createGroupPracownicy = createGroupPracownicy;
  1746. global.createGroupKontrahenci = createGroupKontrahenci;
  1747. global.selectPage = selectPage;
  1748. global.detectChoiseFilter = detectChoiseFilter;
  1749. global.updateListIdBiAuditReaport = updateListIdBiAuditReaport;
  1750. global.deleteListIdBiAuditReaport = deleteListIdBiAuditReaport;
  1751. global.urlFetchPracownicy = urlFetchPracownicy;
  1752. global.generateBiAuditRaport = generateBiAuditRaport;
  1753. global.getAddressData = getAddressData;
  1754. global.Pagination = Pagination;
  1755. global.todo__fetchRaport = todo__fetchRaport;
  1756. global.initLocalStorage = initLocalStorage;
  1757. global.setItemLocalStorage = setItemLocalStorage;
  1758. global.getItemLocalStorage = getItemLocalStorage;
  1759. global.deleteItemLocalStorage = deleteItemLocalStorage;
  1760. global.defaultBIAuditLocalStorage = defaultBIAuditLocalStorage;
  1761. global.removeItemInArray = removeItemInArray;
  1762. global.removeItemArrayInArray = removeItemArrayInArray;
  1763. global.addPracownikToGroup = addPracownikToGroup;
  1764. global.addPracownikAllToGroup = addPracownikAllToGroup;
  1765. global.addKontrahenciToGroup = addKontrahenciToGroup;
  1766. global.addKontrahenciAllToGroup = addKontrahenciAllToGroup;
  1767. global.showViewUploadFile = showViewUploadFile;
  1768. global.parseCsvFile = parseCsvFile;
  1769. global.clearListLocalStorageByType = clearListLocalStorageByType;