Bocian.php.view.js 66 KB

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