1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387 |
- console.log('test1... DBG:', DBG)
- // localStorage.setItem('Bocian.pracownicyIds', JSON.stringify(ids))
- // var ids = localStorage.getItem('Bocian.pracownicyIds')
- // localStorage.removeItem('Bocian.pracownicyIds')
- // localStorage.removeItem('Bocian.kontrahenciIds')
- // localStorage.removeItem('Bocian.depth') // TODO: zapis na stronie głównej i BiAuditRaport
- if (!URL_FETCH_KONTRAHENCI_POWIAZANIA) {
- throw "Brak zmiennej URL_FETCH_KONTRAHENCI_POWIAZANIA"
- }
- $(window).on('hashchange', function() {
- initLocalStorage();
- rootChangeForm();
- });
- /* DATA FOR READ REAPORT */
- function urlFetchKontrahenciPowiazania() {
- // Documentation: https://github.com/github/fetch
- fetch(URL_FETCH_KONTRAHENCI_POWIAZANIA, {
- credentials: 'same-origin'
- })
- .then(function parseJSON(response) {
- return response.json()
- })
- .then(function(data) {
- var reaportItemsKontrahenciPowiazani = null;
- data.body.items.forEach (function(row) {
- reaportItemsKontrahenciPowiazani += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
- '<td align="right">'+row["ID"]+'</td>';
- });
- $( "#body-reaport-kontrahenci-powiazani-tree" ).html(reaportItemsKontrahenciPowiazani);
- console.log('request succeeded with JSON response URL_FETCH_KONTRAHENCI_POWIAZANIA', data)
- }).catch(function(error) {
- console.log('request failed', error)
- });
- }
- /* FORM DATA FOR GENERATAE REAPORT */
- function loadCurrentDepthInInput(idInput) {
- var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
- $(idInput).val(function() {
- return depthValue;
- });
- }
- function updateLocalStorageBiAuditDepth(idInput) {
- $(idInput).keyup(function() {
- delayUpdate(function(){
- var newValue = $(idInput).val();
- var responseValue = validateValueDepth(parseInt(newValue));
- setItemLocalStorage('Bocian.biAuditForm.depth', responseValue);
- loadCurrentDepthInInput('.smad-depth');
- }, 1000 );
- });
- }
- function validateValueDepth(newValue) {
- var value = null;
- value = newValue;
- if (parseInt(newValue) < 0) {
- value = 1;
- }
- if (parseInt(newValue) > 16) {
- value = 16;
- }
- return value;
- }
- var delayUpdate = (function() {
- var timer = 0;
- return function(callback, ms) {
- clearTimeout (timer);
- timer = setTimeout(callback, ms);
- };
- })();
- function initLocalStorage() {
- if (getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') === null) {
- setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
- }
- if (getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') === null) {
- setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
- }
- setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
- if (getItemLocalStorage('Bocian.biAuditForm.depth') === null) {
- updateLocalStorageBiAuditDepth(2);
- }
- }
- /**
- * Funkcja pozwala na wyświetlenie okienka importu
- */
- function showViewUploadFile( event, headerTitle, enumType ) {
- event.preventDefault();
- var enumType = enumType;
- swal({
- title: 'Importuj plik csv',
- input: 'file',
- inputAttributes: {
- 'accept': 'text/csv',
- 'aria-label': 'Upload csv file'
- },
- confirmButtonText: 'Importuj',
- preConfirm: function (file) {
- return new Promise(function (resolve, reject) {
- if (!file) {
- reject("Proszę wybrać plik csv");
- return
- }
- var formData = new FormData();
- formData.append('file', file);
- console.log('uploadowany plik: ',formData);
- var responseParseFile = parseCsvFile( formData, enumType );
- console.log('TODO: upload file', file)
- resolve('file imported')
- })
- },
- }).then(function (result) {
- console.log('result', result)
- }).catch(function (e) {
- console.log('catch: ', e)
- });
- }
- /**
- * Funkcja przekazuje dane z pliku csv do przeparsowania
- */
- function parseCsvFile( fileData, enumType ) {
- event.preventDefault();
- fetch(URL_FORM_DATA_CSV_FILE_AJAX, {
- method: 'POST',
- credentials: 'same-origin',
- body: fileData
- })
- .then(function(response) {
- return response.json()
- }).then(function(json) {
- console.log('parsed json', json)
- swal({
- title: 'Dane załadowane z pliku CSV',
- html: json.body.view,
- width: Math.round(window.innerWidth * 0.9),
- allowOutsideClick: false, // TODO: btn Anuluj na dole?
- showCloseButton: true,
- confirmButtonText: 'Zapisz',
- preConfirm: function (dataForm) {
- return new Promise(function (resolve, reject) {
- if (!dataForm) {
- reject("Formularz nie zawiera danych do zapisania");
- return
- }
- // zapisanie danych
- var responseSaveData = saveFormCsvFileAjaxAction(enumType);
- console.log('TODO: data save from form', dataForm)
- resolve('data save from form')
- })
- },
- }).then(function (result) {
- console.log('result', result)
- }).catch(function (e) {
- console.log('catch: ', e)
- });
- // return json;
- }).catch(function(ex) {
- console.log('parsing failed', ex)
- });
- }
- /**
- * Funkcja zapisuje dane z formularza do wgrania pliku csv
- */
- function saveFormCsvFileAjaxAction(enumType) {
- event.preventDefault();
- var formDataFrom = $("#formDataFromCsv").serialize();
- formDataFrom = formDataFrom.replace(/%5B/g,"[");
- formDataFrom = formDataFrom.replace(/%5D/g,"]");
- //var formDataFrom = $("#formDataFromCsv").serializeArray();
- console.log('dane z formularza formDataFrom ', formDataFrom );
- fetch(URL_SAVE_FORM_CSV_FILE_AJAX, {
- method: 'POST',
- credentials: 'same-origin',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- formData: formDataFrom,
- enumType: enumType
- })
- })
- .then(function(response) {
- return response.json()
- }).then(function(json) {
- console.log('parsed json', json)
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- }
- // return json;
- }).catch(function(ex) {
- console.log('parsing failed', ex)
- });
- }
- function defaultBIAuditLocalStorage() {
- localStorage.removeItem('Bocian.biAuditForm.pracownicyIds');
- localStorage.removeItem('Bocian.biAuditForm.kontrahenciIds');
- setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
- setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', 0);
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', 0);
- setItemLocalStorage('Bocian.biAuditForm.depth', 2);
- }
- function generateBiAuditRaport(event) {
- event.preventDefault();
- var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
- var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
- // validate
- if (!depthValue || depthValue === 0) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
- } else if (!pracownicyIdsArray || pracownicyIdsArray.length === 0) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pracowników' });
- } else if (!kontrahenciIdsArray || kontrahenciIdsArray.length === 0) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano kontrahentów' });
- } else {
- // send
- window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- pracownicyIds: pracownicyIdsArray,
- kontrahenciIds: kontrahenciIdsArray,
- depthValue: depthValue
- })
- })
- .then(function(response) {
- console.log('Firsst then', response);
- return response.text();
- })
- .then(function(responseText) {
- try {
- return JSON.parse(responseText);
- } catch (e) {
- throw responseText;
- }
- })
- .then(function(result) {
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- defaultBIAuditLocalStorage();
- window.setTimeout(window.location.href = "/SE/index.php?_route=ViewTableAjax&namespace=default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA", 4000);
- resolve(result.msg);
- } else {
- reject(result.msg);
- }
- })
- .catch(function(error) {
- console.log('request failed', error)
- });
- }
- }
- function addPracownikToGroup(event) {
- event.preventDefault();
- var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
- if (pracownicyIdsArray === null) {
- showTextListIdPracownikow = 'ID pracowników: nie wybrano';
- } else {
- showTextListIdPracownikow = 'ID pracowników: ' + pracownicyIdsArray;
- }
- swal({
- title: 'Przenieś do grupy',
- input: 'select',
- text: showTextListIdPracownikow,
- inputOptions: getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups'),
- inputPlaceholder: 'Wybierz grupę',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- preConfirm: function (idGroup) {
- return new Promise(function (resolve, reject) {
- console.log('value', idGroup);
- if ( !pracownicyIdsArray || pracownicyIdsArray === null || pracownicyIdsArray === 'undefined' ) {
- reject('Wybierz pracowników');
- } else if ( pracownicyIdsArray.length === 0 ) {
- reject('Wybierz pracowników');
- }
- if (!idGroup) reject('Proszę wybrać nazwę grupy');
- window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'idGroup': idGroup,
- 'pracownicyIds': getItemLocalStorage('Bocian.biAuditForm.pracownicyIds'),
- })
- })
- .then(function(response) {
- return response.text();
- })
- .then(function(responseText) {
- try {
- return JSON.parse(responseText);
- } catch (e) {
- throw responseText;
- }
- })
- .then(function(result) {
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- resolve(result.msg);
- } else {
- reject(result.msg);
- }
- })
- .catch(function(error) {
- console.log('request failed', error)
- });
- })
- },
- allowOutsideClick: false
- }).then(function (groupPracownicyData) {
- //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
- });
- }
- function addKontrahenciToGroup(event) {
- event.preventDefault();
- var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- if (kontrahenciIdsArray === null) {
- showTextListIdKontrahentow = 'ID pracowników: nie wybrano';
- } else {
- showTextListIdKontrahentow = 'ID pracowników: ' + pracownicyIdsArray;
- }
- swal({
- title: 'Przenieś do grupy',
- input: 'select',
- text: showTextListIdKontrahentow,
- inputOptions: getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'),
- inputPlaceholder: 'Wybierz grupę',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- preConfirm: function (idGroup) {
- return new Promise(function (resolve, reject) {
- if (!idGroup) reject('Proszę wybrać nazwę grupy');
- if ( !kontrahenciIdsArray || kontrahenciIdsArray === null || kontrahenciIdsArray === 'undefined' ) {
- reject('Wybierz kontrahentów');
- } else if ( kontrahenciIdsArray.length === 0 ) {
- reject('Wybierz kontrahentów');
- }
- window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'idGroup': idGroup,
- 'kontrahenciIds': getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds'),
- })
- })
- .then(function(response) {
- return response.text();
- })
- .then(function(responseText) {
- try {
- return JSON.parse(responseText);
- } catch (e) {
- throw responseText;
- }
- })
- .then(function(result) {
- result
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- resolve(result.msg);
- } else {
- reject(result.msg);
- }
- })
- ;
- })
- },
- allowOutsideClick: false
- }).then(function (groupKontrahenciData) {
- //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
- });
- }
- function createGroupKontrahenci(event) {
- event.preventDefault();
- swal({
- title: 'Utwórz grupę',
- input: 'text',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- preConfirm: function (NAZWA) {
- return new Promise(function (resolve, reject) {
- if (!NAZWA) reject('Proszę podać nazwę grupy');
- window.fetch(URL_CREATE_KONTRAHENCIS_GROUP, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'NAZWA': NAZWA
- })
- })
- .then(function(response) {
- return response.text();
- })
- .then(function(responseText) {
- try {
- return JSON.parse(responseText);
- } catch (e) {
- throw responseText;
- }
- })
- .then(function(result) {
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- resolve(result.body);
- } else {
- reject("Proszę podać inną nazwę grupy");
- }
- })
- .catch(function(error) {
- console.log('request failed', error)
- })
- })
- },
- allowOutsideClick: false
- }).then(function (groupKontrahenciData) {
- //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
- groupsKontrahenci = '<button class="btn btn-default" title="'+groupKontrahenciData['nazwa']+'" data-group-filter="'+groupKontrahenciData['id']+'">'+groupKontrahenciData['nazwa']+'</button>';
- $('#group-kontrahenci').append(groupsKontrahenci);
- });
- }
- function createGroupPracownicy(event) {
- event.preventDefault();
- swal({
- title: 'Utwórz grupę',
- input: 'text',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- preConfirm: function (NAZWA) {
- return new Promise(function (resolve, reject) {
- if (!NAZWA) reject('Proszę podać nazwę grupy');
- window.fetch(URL_CREATE_PRACOWNICY_GROUP, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'NAZWA': NAZWA
- })
- })
- .then(function(response) {
- return response.text();
- })
- .then(function(responseText) {
- try {
- return JSON.parse(responseText);
- } catch (e) {
- throw responseText;
- }
- })
- .then(function(result) {
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- resolve(result.msg);
- } else {
- reject(result.msg);
- }
- });
- })
- },
- allowOutsideClick: false
- }).then(function (groupPracownicyData) {
- //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
- groupsPracownicy = '<button class="btn btn-default" title="'+groupPracownicyData['NAZWA']+'" data-group-filter="'+groupPracownicyData['ID']+'">'+groupPracownicyData['NAZWA']+'</button>';
- $('#group-pracownicy').append(groupsPracownicy);
- });
- }
- // fetch(URL_FETCH_TEST_KRS, {
- // credentials: 'same-origin'
- // })
- // .then(function parseJSON(response) {
- // return response.json()
- // })
- // .then(function(data) {
- // console.log('request succeeded with JSON response', data)
- // }).catch(function(error) {
- // console.log('request failed', error)
- // })
- //
- // fetch(URL_FETCH_TEST_CEIDG, {
- // credentials: 'same-origin'
- // })
- // .then(function parseJSON(response) {
- // return response.json()
- // })
- // .then(function(data) {
- // console.log('request succeeded with JSON response', data)
- // }).catch(function(error) {
- // console.log('request failed', error)
- // })
- function rootChangeForm() {
- //todo: do przeniesienia
- urlFetchKontrahenciPowiazania();
- var valueUrl = global.location.hash;
- console.log('URL', valueUrl);
- switch (valueUrl) {
- case '#KONTRAHENCI':
- $( ".container-bi_audit_form_kontrahenci_raport" ).html( VIEW_KONTRAHENCI );
- urlFetchKontrahenci(1);
- fetchGroupKontrahenci();
- $( ".container-bi_audit_form_pracownicy_raport" ).hide();
- $( ".container-bi_audit_form_kontrahenci_raport" ).show();
- break;
- case '#PRACOWNICY':
- $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
- urlFetchPracownicy(1);
- fetchGroupPracownicy();
- $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
- $( ".container-bi_audit_form_pracownicy_raport" ).show();
- break;
- // case '#REAPORT':
- // $( ".container-bi_audit_form_raport_data" ).html( VIEW_TREE_REAPORT );
- // urlFetchKontrahenciPowiazania();
- // $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
- // $( ".container-bi_audit_form_pracownicy_raport" ).hide();
- // $( ".container-bi_audit_form_raport_data" ).show();
- // break;
- default:
- $( ".container-bi_audit_form_pracownicy_raport" ).html( VIEW_PRACOWNICY );
- urlFetchPracownicy(1);
- fetchGroupPracownicy();
- $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
- $( ".container-bi_audit_form_pracownicy_raport" ).show();
- break;
- }
- //aktualizacja inputa głebokości powiazan
- loadCurrentDepthInInput('.smad-depth');
- updateLocalStorageBiAuditDepth('.smad-depth');
- }
- function getAddressData(objectValue) {
- var objectValue = objectValue || [];
- var listData = '';
- if (!objectValue) {
- return true;
- }
- objectValue.forEach (function(item) {
- if (item['kodPocztowy']) { listData += '<div>kod pocztowy: ' + item['kodPocztowy'] + '<div>'; }
- if (item['miejscowosc']) { listData += '<div>miejscowość: ' + item['miejscowosc'] + '<div>'; }
- if (item['nrBudynku']) { listData += '<div>nr budynku: ' + item['nrBudynku'] + '<div>'; }
- if (item['nrLokalu']) { listData += '<div>nr lokalu: ' + item['nrLokalu'] + '<div>'; }
- if (item['typAdresu']) { listData += '<div>typ adresu: ' + item['typAdresu'] + '<div>'; }
- if (item['ulica']) { listData += '<div>ulica: ' + item['ulica'] + '<div>'; }
- listData += '<div>------<div>';
- });
- return listData;
- }
- function urlFetchKontrahenci(page) {
- var page = page || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page');
- selectPage('KONTRAHENCI', page);
- if ( page === 1) {
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', 1);
- }
- var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
- fetch(URL_FETCH_KONTRAHENCI + '&page=' + page + '&filterIdGroup=' + filterIdGroup, {
- credentials: 'same-origin'
- })
- .then(function parseJSON(response) {
- return response.json()
- var filterIdGroup = filterIdGroup || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
- })
- .then(function(data) {
- console.log('kkontrahenci data', data);
- var listItemsKontrahenci = null;
- data.body.items.forEach (function(row) {
- listItemsKontrahenci += '<tr><td><input type="checkbox" name="kontrID[]" value="'+row['ID']+'" /></td>'+
- '<td align="right">'+row["ID"]+'</td>'+
- '<td align="right">'+row["Nazwa_grupy_kapitalowej"]+'</td>'+
- '<td align="right">'+row["Pelna_nazwa_kontrahenta"]+'</td>'+
- '<td align="right">'+row["Numer_kontrahenta"]+'</td>'+
- '<td align="right">'+row["Skrocona_Nazwa_Kontrahenta"]+'</td>'+
- '<td align="right">'+row["Typ_kontrahenta"]+'</td>'+
- '<td align="right">'+row["NIP"]+'</td>'+
- '<td align="right">'+row["KRS"]+'</td>'+
- '<td align="right">'+row["REGON"]+'</td>'+
- '<td align="right">'+row["PESEL"]+'</td>'+
- '<td align="right">'+row["Forma_prawna_dzialalnosci"]+'</td>'+
- '<td align="right">'+row["Ulica"]+'</td>'+
- '<td align="right">'+row["Numer_budynku"]+'</td>'+
- '<td align="right">'+row["Numer_mieszkania_lokalu"]+'</td>'+
- '<td align="right">'+row["Miejscowosc"]+'</td>'+
- '<td align="right">'+row["Kod_pocztowy"]+'</td>'+
- '<td align="right">'+row["Kraj"]+'</td>'+
- '<td align="right">'+row["Telefon"]+'</td>'+
- '<td align="right">'+row["Fax"]+'</td>'+
- '<td align="right">'+row["Mail"]+'</td>'+
- '<td align="right">'+row["A_ADM_COMPANY"]+'</td>'+
- '<td align="right">'+row["A_CLASSIFIED"]+'</td>'+
- '<td align="right">'+row["A_STATUS"]+'</td>'+
- '<td align="right">'+row["A_STATUS_INFO"]+'</td>'+
- '<td align="right">'+row["Dodano"]+'</td>'+
- '<td align="right">'+row["L_APPOITMENT_USER"]+'</td>'+
- '<td align="right">'+row["Podmiot_dominujacy"]+'</td>'+
- '<td align="right">'+row["Tytul_dokumentu"]+'</td>'+
- '<td align="right">'+row["ownCompany"]+'</td>'+
- '<td align="right">'+row["uwagi"]+'</td></tr>';
- });
- if (data.body.pagination !== undefined) {
- Pagination.Init(document.getElementById('pagination-kontrahenci'), {
- url: '/SE/index.php?_route=UrlAction_Bocian#KONTRAHENCI',
- id_pagination: 'pagination-kontrahenci',
- type: 'KONTRAHENCI',
- total_items: data.body.pagination.total_items, // pages size
- size: data.body.pagination.size, // pages size
- page: page, // selected page
- step: 1 // pages before and after current
- });
- }
- $( "#body-kontrahenci" ).html(listItemsKontrahenci);
- checkAll('KONTRAHENCI');
- catchEventCheckbox('KONTRAHENCI');
- checkedChoiseItems('KONTRAHENCI', getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') );
- // $( ".container-bi_audit_raport" ).append( data.body.view );
- console.log('request succeeded with JSON responseKontrahenci', data)
- }).catch(function(error) {
- console.log('request failed', error)
- })
- }
- function urlFetchPracownicy(page) {
- var page = page || getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page');
- if ( page === 1) {
- setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', 1);
- }
- var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
- selectPage('PRACOWNICY', page);
- fetch(URL_FETCH_PRACOWNICY + '&page=' + page + '&filterIdGroup=' + filterIdGroup, {
- credentials: 'same-origin'
- })
- .then(function parseJSON(response) {
- return response.json()
- })
- .then(function(data) {
- var addresPerson = '';
- var listItemsPracownik = null;
- console.log('urlFetchPracownicy', data.body.items);
- data.body.items.forEach (function(row) {
- if (row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]) {
- addresPerson = getAddressData(row["default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy"]);
- }
- listItemsPracownik += '<tr><td><input type="checkbox" name="prID[]" value="'+row['ID']+'" /></td>'+
- '<td align="right">'+row["ID"]+'</td>'+
- '<td align="right">'+row["imiona"]+'</td>'+
- '<td align="right">'+row["nazwisko"]+'</td>'+
- '<td align="right">'+row["nip"]+'</td>'+
- '<td align="right">'+row["pesel"]+'</td>'+
- '<td align="right">'+row["regon"]+'</td>'+
- '<td align="right">'+row["source"]+'</td>'+
- '<td align="right">'+row["A_ADM_COMPANY"]+'</td>'+
- '<td align="right">'+row["A_CLASSIFIED"]+'</td>'+
- '<td align="right">'+row["A_STATUS"]+'</td>'+
- '<td align="right">'+row["A_STATUS_INFO"]+'</td>'+
- '<td align="right">'+row["L_APPOITMENT_USER"]+'</td>'+
- '<td align="right">'+ addresPerson +'</td></tr>';
- });
- if (data.body.pagination.size) {
- Pagination.Init(document.getElementById('pagination-pracownicy'), {
- url: '/SE/index.php?_route=UrlAction_Bocian#PRACOWNICY',
- id_pagination: 'pagination-pracownicy',
- type: 'PRACOWNICY',
- total_items: data.body.pagination.total_items, // pages size
- size: data.body.pagination.size, // pages size
- page: data.body.pagination.current, // selected page
- step: 1 // pages before and after current
- });
- }
- $( "#body-pracownicy" ).html( listItemsPracownik);
- checkAll('PRACOWNICY');
- catchEventCheckbox('PRACOWNICY');
- checkedChoiseItems('PRACOWNICY', getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') );
- // $( ".container-bi_audit_raport" ).append( data.body.view );
- console.log('request succeeded with JSON responsePRACOWNICY', data)
- }).catch(function(error) {
- console.log('request failed', error)
- })
- }
- function selectPage(type, nrPage) {
- var type = type.toLowerCase();
- $('#pagination-' + type + ' ul li a').each(function(index, value){
- if (this.text === nrPage) {
- $(this).addClass('active');
- } else {
- $(this).removeClass('active');
- }
- });
- }
- function checkAll(type) {
- $('#checkAll-' + type).change(function() {
- var valueCheckbox = null;
- var checkboxes = $('form').find(':checkbox');
- if($(this).prop('checked')) {
- checkboxes.prop('checked', true);
- //valueCheckbox = checkboxes.prop("checked");
- var allValsChecked = [];
- var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
- if (this.value !== 'on') {
- allValsChecked.push(parseInt(this.value));
- }
- }).get();
- updateListIdBiAuditReaport(type, allValsChecked);
- } else {
- checkboxes.prop('checked', false);
- var allValsUnChecked = [];
- var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
- if (this.value !== 'on') {
- allValsUnChecked.push(parseInt(this.value));
- }
- }).get();
- deleteListIdBiAuditReaport(type, allValsUnChecked);
- }
- });
- }
- /**
- * Select again checkbox before selected item chekbox from storage (pracownicy/kontrahenci)
- */
- function checkedChoiseItems(type, store) {
- var idElement = 'smad-table-' + type;
- // if id element exist
- if (document.getElementById(idElement)) {
- // checked again if user selected Item (pracownicy/kontrahent)
- for (i = 0; i < store.length; i++) {
- $('#body-'+type.toLowerCase() +' input[type=checkbox] ').map(function(k, v) {
- if ( store[i] === parseInt(this.value) ){
- $(this).prop('checked', true);
- }
- }).get();
- }
- }
- //$('#checkAll-' + type).on('bind', function() {
- $('#smad-table-' + type + ' input[type=checkbox]').on( 'load', function() {
- var itemsCHecked = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
- getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- if (itemsCHecked.lenght === 0 ) {
- return;
- }
- var valueCheckbox = null;
- var checkboxes = $('form').find(':checkbox');
- if($(this).prop('checked')) {
- checkboxes.prop('checked', true);
- var allValsChecked = [];
- var checkedValues = $('#smad-table-' + type + ' input:checkbox:checked').map(function() {
- if (this.value !== 'on') {
- allValsChecked.push(parseInt(this.value));
- }
- }).get();
- updateListIdBiAuditReaport(type, allValsChecked);
- } else {
- checkboxes.prop('checked', false);
- var allValsUnChecked = [];
- var checkedValues = $('#smad-table-' + type + ' input:checkbox:not(:checked)').map(function() {
- if (this.value !== 'on') {
- allValsUnChecked.push(parseInt(this.value));
- }
- }).get();
- deleteListIdBiAuditReaport(type, allValsUnChecked);
- }
- });
- }
- function catchEventCheckbox(type) {
- $('#smad-table-' + type + ' input[type="checkbox"]').on('change', function() {
- if($(this).is(":checked")) {
- var allValsChecked = [];
- if (this.value !== 'on') {
- allValsChecked.push(parseInt(this.value));
- }
- updateListIdBiAuditReaport(type, allValsChecked);
- } else {
- var allValsUnChecke = [];
- if (this.value !== 'on') {
- allValsUnChecke.push(parseInt(this.value));
- }
- deleteListIdBiAuditReaport(type, allValsUnChecke);
- }
- });
- }
- function clearSelectedCheckbox() {
- $('#checkAll-PRACOWNICY').prop('checked', false)
- $('#checkAll-KONTRAHENCI').prop('checked', false)
- }
- function updateListIdBiAuditReaport(type, valueArray) {
- var currentStoragePracownicyIds = [];
- var updateListPracownicyIds = null;
- var currentStorageKontrahenciIds = [];
- var updateListKontrahenciIds = null;
- if ( type == 'PRACOWNICY') {
- currentStoragePracownicyIds = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
- if(currentStoragePracownicyIds !== null) {
- updateListPracownicyIds = [...new Set([...currentStoragePracownicyIds ,...valueArray])];
- }
- else {
- updateListPracownicyIds = valueArray;
- }
- setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', updateListPracownicyIds);
- }
- if ( type == 'KONTRAHENCI') {
- currentStorageKontrahenciIds = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- if(currentStorageKontrahenciIds !== null) {
- updateListKontrahenciIds = [...new Set([...currentStorageKontrahenciIds ,...valueArray])];
- }
- else {
- updateListKontrahenciIds = valueArray;
- }
- setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', updateListKontrahenciIds);
- }
- }
- function deleteListIdBiAuditReaport(type, valueArray) {
- var currentStoragePracownicyIds = [];
- var updateListPracownicyIds = null;
- if ( type == 'PRACOWNICY') {
- deleteItemLocalStorage('Bocian.biAuditForm.pracownicyIds', valueArray);
- }
- if ( type == 'KONTRAHENCI') {
- deleteItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', valueArray);
- }
- }
- // filter group detect
- function fetchGroupPracownicy() {
- fetch(URL_FETCH_GROUP_PRACOWNICY, {
- credentials: 'same-origin'
- })
- .then(function parseJSON(response) {
- return response.json()
- })
- .then(function(data) {
- setItemLocalStorage('Bocian.biAuditForm.pracownicy.groups', data.body.itmesGroupPracownicy);
- if (data.body.itmesGroupPracownicy === null) {
- return;
- }
- var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
- var groupsPracownicy = '';
- var activeButton = '';
- data.body.itmesGroupPracownicy.forEach (function(row) {
- if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-pracownicy button.active').removeClass('active'); }
- groupsPracownicy += '<button class="btn btn-default '+activeButton+'" title="' + row['NAZWA'] + '" data-group-filter="' + row['ID'] + '">' + row['NAZWA'] + '</button>';
- });
- $("#group-pracownicy").append(groupsPracownicy);
- console.log('request succeeded with JSON fetchGroupPracownicy', data.body.itmesGroupPracownicy)
- }).catch(function(error) {
- console.log('request failed', error)
- });
- }
- function fetchGroupKontrahenci() {
- fetch(URL_FETCH_GROUP_KONTRAHENCI, {
- credentials: 'same-origin'
- })
- .then(function parseJSON(response) {
- return response.json()
- })
- .then(function(data) {
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups', data.body.itemsGroupKontrahenci);
- if (data.body.itemsGroupKontrahenci === null) {
- return;
- }
- var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
- var groupsKontrahenci = '';
- var activeButton = '';
- data.body.itemsGroupKontrahenci.forEach (function(row) {
- if ( filterIdGroup === row['ID'] ) { activeButton = 'active'; $('#group-kontrahenci button.active').removeClass('active'); }
- groupsKontrahenci += '<button class="btn btn-default '+activeButton+'" title="'+row['NAZWA']+'" data-group-filter="'+row['ID']+'">'+row['NAZWA']+'</button>';
- });
- $("#group-kontrahenci").append(groupsKontrahenci);
- console.log('request succeeded with JSON fetchGroupKontrahenci', data.body.itemsGroupKontrahenci);
- }).catch(function(error) {
- console.log('request failed', error)
- });
- }
- function detectChoiseFilter() {
- $('#group-kontrahenci').on('click', 'button', function(evt) {
- $('#group-kontrahenci button.active').removeClass('active');
- $(this).addClass('active');
- // pobranie id grupy kliknietego buttonu
- var filterIdGroup = $(this).attr("data-group-filter");
- // ustawić id grupy do sesyjnej
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', parseInt(filterIdGroup));
- // wywylac funckje pobrania danych
- urlFetchKontrahenci(1);
- });
- $('#group-pracownicy').on('click', 'button', function(evt) {
- $('#group-pracownicy button.active').removeClass('active');
- $(this).addClass('active');
- // pobranie id grupy kliknietego buttonu
- var filterIdGroup = $(this).attr("data-group-filter");
- // ustawić id grupy do sesyjnej
- setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', parseInt(filterIdGroup));
- // wywylac funckje pobrania danych
- urlFetchPracownicy(1);
- });
- }
- // Local storage
- function setItemLocalStorage(key, array) {
- localStorage.setItem(key, JSON.stringify(array));
- }
- function getItemLocalStorage(key) {
- var retrievedData = localStorage.getItem(key);
- var response = JSON.parse(retrievedData);
- return response;
- }
- function deleteItemLocalStorage(key, itemsArray) {
- var currentStorageArray = getItemLocalStorage(key);
- var newStorageArray = removeItemArrayInArray(currentStorageArray, itemsArray);
- setItemLocalStorage(key, newStorageArray);
- }
- /**
- * arr - array
- * item - search item
- */
- function removeItemInArray(arr, item) {
- for(var i = arr.length; i--;) {
- if(arr[i] === item) {
- arr.splice(i, 1);
- }
- }
- return arr;
- }
- /**
- * arr - array
- * item - array list items
- */
- function removeItemArrayInArray(arr, itemsArray) {
- for(var i = arr.length; i--;) {
- for(var j = itemsArray.length; j--;) {
- if(arr[i] === itemsArray[j]) {
- arr.splice(i, 1);
- }
- }
- }
- return arr;
- }
- // Pagination
- var Pagination = {
- code: '', // end show html paginations
- clickPage: 1, // set default 1 page
- // --------------------
- // Utility
- // --------------------
- // initialize default data
- Extend: function(data) {
- data = data || {};
- Pagination.url = data.url;
- Pagination.id_pagination = data.id_pagination;
- Pagination.type = data.type;
- Pagination.total_items = data.total_items;
- Pagination.size = data.size || 2;
- Pagination.page = data.page || 1;
- Pagination.step = data.step || 3;
- },
- // add pages by number (from [s] to [f])
- Add: function(s, f) {
- for (var i = s; i < f; i++) {
- Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">' + i + '</a></li>';
- }
- },
- // add last page with separator
- Last: function() {
- Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">>></a></li>';
- },
- // add first page with separator
- First: function() {
- Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><<</a></li>';
- },
- // add last page with separator
- Next: function() {
- Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default">></a></li>';
- },
- // add first page with separator
- Prev: function() {
- Pagination.code += '<li><a href="' + Pagination.url + '" class="btn btn-default"><</a></li>';
- },
- // --------------------
- // Handlers
- // --------------------
- // change page
- Click: function() {
- clearSelectedCheckbox();
- var selectPage = $("#pagination-"+Pagination.type.toLowerCase()+' .tblAjax__footer__toolbar__pagination').find('a.active').text();
- Pagination.clickPage = +this.innerHTML || '';
- if ( selectPage === NaN || selectPage > Pagination.size) { selectPage = 1; }
- switch (this.innerHTML) {
- case '>>': // last
- Pagination.clickPage = Pagination.size;
- break;
- case '<<': // first
- Pagination.clickPage = 1;
- break;
- case '<': // prev
- Pagination.clickPage = parseInt(selectPage) - 1;
- if (Pagination.clickPage < 1) {
- Pagination.clickPage = 1;
- }
- break;
- case '>': // next
- Pagination.clickPage = parseInt(selectPage) + 1;
- if (Pagination.clickPage > Pagination.size) {
- Pagination.clickPage = Pagination.size;
- }
- break;
- }
- if ( Pagination.type === 'KONTRAHENCI' ) {
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page', Pagination.clickPage);
- Pagination.page = urlFetchKontrahenci(Pagination.clickPage);
- }
- else if ( Pagination.type === 'PRACOWNICY' ){
- setItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page', Pagination.clickPage);
- Pagination.page = urlFetchPracownicy(Pagination.clickPage);
- }
- Pagination.Start();
- },
- // --------------------
- // Script structure pagination
- // --------------------
- // binding pages
- Bind: function() {
- var a = Pagination.e.getElementsByTagName('a');
- var currentPage = Pagination.clickPage || 1;
- for (var i = 0; i < a.length; i++) {
- if (+a[i].innerHTML === Pagination.page) a[i].className = 'btn btn-default active';
- a[i].addEventListener('click', Pagination.Click, false);
- }
- },
- // write pagination
- Finish: function() {
- Pagination.e.innerHTML = Pagination.code;
- Pagination.code = '</ul></nav>';
- Pagination.Bind();
- },
- // find pagination type
- Start: function() {
- Pagination.code = '<div class="foot-info tblAjax__footer__toolbar__info footer_pagination_menu_items"><p>Wiersze od 1 do ' + Pagination.total_items + ' z ' + Pagination.total_items + '</p></div>';
- Pagination.code += '<nav aria-label="Page navigation" class="footer_pagination_menu_items"><ul class="btn-group tblAjax__footer__toolbar__pagination smad-pagination">';
- Pagination.First();
- Pagination.Prev();
- if ( Pagination.type === 'KONTRAHENCI' ) {
- Pagination.page = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.pagination.page') || 1;
- }
- else if ( Pagination.type === 'PRACOWNICY' ){
- Pagination.page = getItemLocalStorage('Bocian.biAuditForm.pracownicy.pagination.page') || 1;
- }
- if ( Pagination.page > Pagination.size ) {
- Pagination.page = 1;
- }
- if (Pagination.size < Pagination.step * 2 + 6) {
- Pagination.Add(1, Pagination.size + 1);
- }
- /*else if (Pagination.page < Pagination.step * 2 + 1) {
- Pagination.Add(1, Pagination.step * 2 + 4);
- }
- else if (Pagination.page > Pagination.size - Pagination.step * 2) {
- Pagination.Add(Pagination.size - Pagination.step * 2 - 2, Pagination.size + 1);
- }*/
- else {
- // Pagination.Add(Pagination.page - Pagination.step, Pagination.page + Pagination.step + 1);
- }
- Pagination.Next();
- Pagination.Last();
- Pagination.Finish();
- },
- // --------------------
- // Initialization
- // --------------------
- // binding buttons
- Buttons: function(e) {
- var nav = e.getElementsByTagName('a');
- },
- // create skeleton
- Create: function(e) {
- var html = [
- '<div></div>' // pagination container
- ];
- e.innerHTML = html.join('');
- Pagination.e = e.getElementsByTagName('div')[0];
- Pagination.Buttons(e);
- },
- // init
- Init: function(e, data) {
- Pagination.Extend(data);
- Pagination.Create(e);
- Pagination.Start();
- }
- };
- function todo__fetchRaport(id) {
- p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', {
- primaryKey: id,
- resolve: 'all',
- resolveDepth: 3,
- }).then(function (features) {
- console.log('features', features)
- }).catch(function (e) {
- console.warn(e)
- p5UI__notifyAjaxCallback({ type: 'error', msg: e })
- })
- }
- $(document).ready(function(){
- rootChangeForm();
- detectChoiseFilter();
- });
- global.checkAll = checkAll;
- global.checkedChoiseItems = checkedChoiseItems;
- global.catchEventCheckbox = catchEventCheckbox;
- global.clearSelectedCheckbox = clearSelectedCheckbox;
- global.createGroupPracownicy = createGroupPracownicy;
- global.createGroupKontrahenci = createGroupKontrahenci;
- global.selectPage = selectPage;
- global.detectChoiseFilter = detectChoiseFilter;
- global.updateListIdBiAuditReaport = updateListIdBiAuditReaport;
- global.deleteListIdBiAuditReaport = deleteListIdBiAuditReaport;
- global.urlFetchPracownicy = urlFetchPracownicy;
- global.generateBiAuditRaport = generateBiAuditRaport;
- global.getAddressData = getAddressData;
- global.Pagination = Pagination;
- global.todo__fetchRaport = todo__fetchRaport;
- global.initLocalStorage = initLocalStorage;
- global.setItemLocalStorage = setItemLocalStorage;
- global.getItemLocalStorage = getItemLocalStorage;
- global.deleteItemLocalStorage = deleteItemLocalStorage;
- global.defaultBIAuditLocalStorage = defaultBIAuditLocalStorage;
- global.removeItemInArray = removeItemInArray;
- global.removeItemArrayInArray = removeItemArrayInArray;
- global.addPracownikToGroup = addPracownikToGroup;
- global.showViewUploadFile = showViewUploadFile;
- global.parseCsvFile = parseCsvFile;
|