123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359 |
- 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 ) {
- event.preventDefault();
- swal({
- title: headerTitle,
- //input: 'file',
- html: '<div><input id="file-csv-upload" type="file" name="files[]" enctype="multipart/form-data" style="margin: 0 10% 0 auto;"></div>',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- preConfirm: function (file) {
- return new Promise(function (resolve, reject) {
- if (!file ) reject('Proszę wybrać plik csv');
- var fileInputData = $('#file-csv-upload').prop('files')[0];
- var formData = new FormData();
- formData.append('file', fileInputData);
- console.log('uploadowany plik: ',formData);
- var responseViewForm = parseCsvFile( formData );
- console.log('dane po przeparsowaniu', responseViewForm);
- })
- .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 (responseData) {
- }).catch(function(error) {
- console.log('request failed', error)
- });
- }
- /**
- * Funkcja przekazuje dane z pliku csv do przeparsowania
- */
- function parseCsvFile( fileData ) {
- event.preventDefault();
- fetch(URL_PARSE_CSV_FILE_AJAX, {
- method: 'POST',
- credentials: 'same-origin',
- body: fileData
- })
- .then(function(response) {
- return response.json()
- }).then(function(json) {
- console.log('parsed json', json)
- return json;
- }).catch(function(ex) {
- console.log('parsing failed', ex)
- })
- // window.fetch(URL_PARSE_CSV_FILE_AJAX, {
- // method: 'POST',
- // credentials: 'same-origin',
- // body: file
- // })
- // .then(function(response) {
- // return response.text();
- // })
- // .then(function(responseText) {
- //
- // console.log(responseText);
- // })
- // .then(function(result) {
- // result
- // if (result.type == 'success') {
- // p5UI_notifyAjaxCallback(result);
- // resolve(result.msg);
- // } else {
- // reject(result.msg);
- // }
- // })
- // .catch(function(error) {
- // console.log('request failed', error)
- // });
- }
- 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 = "https://bravecom.yellowgroup.pl/SE/index.php?_route=ViewTableAjax&namespace=default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA", 4000);
- 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.msg);
- } else {
- reject(result.msg);
- }
- })
- ;
- })
- },
- 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: 'https://bravecom.yellowgroup.pl/SE/index.php?_route=UrlAction_BiAuditRaport#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: 'https://bravecom.yellowgroup.pl/SE/index.php?_route=UrlAction_BiAuditRaport#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;
|