123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012 |
- var DBG = DBG || 0;
- var DBG1 = true;
- var CURRENT_DATE = CURRENT_DATE || '';
- if (!STORE_NAME) throw "Store name not defined";
- if (!global[STORE_NAME]) throw "Store not defined";
- if (!URL_TABLE_POWIAZANIA) throw "Brak URL_TABLE_POWIAZANIA";
- if (!BASE_URLS) throw "Brak BASE_URLS"
- var RECORD_MORE_FUNCTIONS_OPENED_NODE = null;
- if (!FIELD_LIST_PRACOWNICY) throw "Brak FIELD_LIST_PRACOWNICY"
- if (!FIELD_LIST_KONTRAHENCI) throw "Brak FIELD_LIST_KONTRAHENCI"
- var createReactClass = global.p5VendorJs.createReactClass;
- var h = global.p5VendorJs.React.createElement;
- var ReactDOM = global.p5VendorJs.ReactDOM;
- var swal = window.swal;
- var globalRaportStore = global[STORE_NAME];
- var P5UI__BocianHeader = createReactClass({
- getStateFromStore: function () {
- var storeState = this.props.store.getState();
- return {
- totalOdPracownicy: storeState.totalOdPracownicy,
- totalOdPozostale: storeState.totalOdPozostale,
- totalDoKontrahenci: storeState.totalDoKontrahenci,
- totalDoPozostale: storeState.totalDoPozostale,
- depth: storeState.depth,
- onlyTargets: storeState.onlyTargets,
- title: storeState.title,
- };
- },
- getInitialState: function() {
- return this.getStateFromStore();
- },
- componentDidMount: function () {
- this.unsubscribe = this.props.store.subscribe(this.storeUpdated)
- },
- componentWillUnmount: function () {
- this.unsubscribe()
- },
- storeUpdated: function () {
- DBG && console.log('DBG::P5UI__BocianHeader::storeUpdated ', this.getStateFromStore());
- this.setState(this.getStateFromStore())
- },
- addOdPozostale: function (event) {
- // window['createPracownikAjax'](event)
- window['addPozostaleOdDo'](event)
- },
- addDoPozostale: function (event) {
- // window['createKontrahentAjax'](event)
- window['addPozostaleOdDo'](event)
- },
- clearPozostaleOd: function (event) {
- this.props.store.dispatch({ type: 'CLEAR_POZOSTALE_OD' })
- },
- clearPozostaleDo: function (event) {
- this.props.store.dispatch({ type: 'CLEAR_POZOSTALE_DO' })
- },
- handleChangeDepth: function (event) {
- var store = this.props.store;
- var depth = event.target.value;
- store.dispatch({ type: 'SET_DEPTH', depth: depth })
- },
- handleChangeSetOnlyTargetsYes: function () {
- this.props.store.dispatch({ type: 'SET_ONLY_TARGETS', onlyTargets: true })
- },
- handleChangeSetOnlyTargetsNo: function () {
- this.props.store.dispatch({ type: 'SET_ONLY_TARGETS', onlyTargets: false })
- },
- handleChangeTitle: function (event) {
- this.props.store.dispatch({ type: 'SET_TITLE', title: event.target.value })
- },
- handleRaportSubmitForm: function (event) {
- event.preventDefault();
- var self_store = this.props.store;
- var idsPracownicy = getListFromLocalStorage('Bocian.biAuditForm.pracownicyIds');
- var idsKontrahenci = getListFromLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- var pozostaleOd = getListFromLocalStorage(getSelectedListLocalStorageKey('OD'));
- var pozostaleDo = getListFromLocalStorage(getSelectedListLocalStorageKey('DO'));
- var allOdLength = idsPracownicy.length + pozostaleOd.length;
- var allDoLength = idsKontrahenci.length + pozostaleDo.length;
- var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
- var smadReaportTitle = getItemLocalStorage('Bocian.biAuditForm.smadReaportTitle');
- var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
- if ( !smadReaportTitle ) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano tytułu raportu' });
- return;
- }
- if ( !depthValue ) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości dla głębokości powiązań' });
- return;
- }
- if ( !analizaOnlyTargets ) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie podano wartości czy zwracać wyniki tylko z obiektami docelowymi' });
- return;
- }
- if ( !allOdLength ) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pozycji OD do analizy (pracownicy lub pozostałe bazy)' });
- return;
- }
- if ( !allOdLength && !allDoLength ) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: 'Nie wybrano pozycji do analizy' });
- return;
- }
- // TODO: analizaOnlyTargets = ( 'y' | 'n' ) - allDoLength should depend of analizaOnlyTargets?
- // if not choise 'pracownicy' or 'kontrahenci'
- if ( !allOdLength || !allDoLength ) {
- var messageConfirm = '';
- if ( !allDoLength ) {
- messageConfirm = 'Nie wybrano podmiotów/kontrahentów! Czas przygotowania raportu może wydłużyć się ze względu na sprawdzenie powiązania ze wszystkimi podmiotami/kontrahentami w systemie. Czy jesteś pewny? ';
- }
- // show confirm window with message
- if (!confirm(messageConfirm)) return;
- }
- window.fetch(URL_GENERATE_BI_AUDIT_RAPORT_AJAX, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- credentials: 'same-origin',
- body: JSON.stringify({
- pracownicyIds: idsPracownicy,
- kontrahenciIds: idsKontrahenci,
- pozostaleOd: pozostaleOd,
- pozostaleDo: pozostaleDo,
- depthValue: depthValue,
- smadReaportTitle: smadReaportTitle,
- analizaOnlyTargets: analizaOnlyTargets
- })
- })
- .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);
- self_store.dispatch({ type: 'CLEAR_ALL' })
- updateTopCounters();
- $('#smad-table-PRACOWNICY form').find(':checkbox').prop('checked', false);
- $('#smad-table-KONTRAHENCI form').find(':checkbox').prop('checked', false);
- $('#count-selected-item-kontrahenci').text('0');
- $('#count-selected-item-pracownicy').text('0');
- $('.bottom--message-warning-critical-search').text('');
- swal({
- title: result.msg,
- html: '<a href="' + URL_TABLE_POWIAZANIA + '" title="przejdź do raportów" >Przejdź do raportów</a>',
- allowOutsideClick: false, // TODO: btn Anuluj na dole?
- showCloseButton: true,
- confirmButtonText: 'OK',
- });
- window.setTimeout(function () {
- console.warn("URL_TABLE_POWIAZANIA:", URL_TABLE_POWIAZANIA);
- }, 100);
- window.setTimeout(function () {
- window.location.href = URL_TABLE_POWIAZANIA;
- }, 6000);
- resolve(result.msg);
- } else {
- if (result.type && result.msg) p5UI__notifyAjaxCallback(result);
- reject(result.msg);
- }
- })
- .catch(function(error) {
- if(DBG) console.log('request failed', error);
- });
- },
- handleAddByLastReportClick: function (event) {
- swal({
- title: "dodaj do analizy wg raportu",
- input: 'radio',
- inputOptions: {
- 'pracownicy' : "Pracownicy",
- 'kontrahenci' : "Kontrahenci",
- // 'pracownicy_pozostale' : "Pracownicy (pozostałe)",
- // 'kontrahenci_pozostale' : "Kontrahenci (pozostałe)",
- },
- inputValidator: function (value) {
- return !value && 'Proszę wybrać typ danych';
- }
- }).then(function (data) {
- handleAddToReportByPreviousReport(data.value);
- })
- // TODO: like addToReportByPreviousReport but after select report, show counters for pracow., kontr., pozostale od and do with checkbox
- // swal({
- // title: "TODO: dodaj do analizy wg raportu",
- // })
- // TODO: https://github.com/sweetalert2/sweetalert2-react-content
- // - just pass React element to 'html' ?
- },
- renderClearPozostaleOdBtn: function () {
- return h('i', {
- title: "Wyczyść pozostałe",
- className: "glyphicon glyphicon-remove",
- style: { 'font-size': '14px', 'line-height': '21px', 'margin-left': '3px', 'vertical-align': 'middle', color: "#f00", opacity: "0.5", cursor: "pointer" },
- onClick: this.clearPozostaleOd, 'line-height': '20px'
- });
- },
- renderClearPozostaleDoBtn: function () {
- return h('i', {
- title: "Wyczyść pozostałe",
- className: "glyphicon glyphicon-remove",
- style: { 'font-size': '14px', 'line-height': '21px', 'margin-left': '3px', 'vertical-align': 'middle', color: "#f00", opacity: "0.5", cursor: "pointer" },
- onClick: this.clearPozostaleDo, 'line-height': '20px'
- });
- },
- renderSummaryList: function () {
- var totalOd = this.state.totalOdPracownicy + this.state.totalOdPozostale;
- var totalDo = this.state.totalDoKontrahenci + this.state.totalDoPozostale;
- return h('ul', {}, [
- h('li', { style: { marginTop: "6px" } }, [
- h('span', {
- style: totalOd > 0 ? { color: "#d7142d" } : {}
- }, [
- " OD ",
- h('span', { className: "badge", style: totalOd > 0 ? { 'background-color': "#d7142d" } : {} }, totalOd),
- " : ",
- ]),
- h('a', { className: "btn btn-primary btn-xs", href: "#PRACOWNICY" }, [ // .bi-btn-primary
- " pracownicy ",
- h('span', { className: "badge" }, this.state.totalOdPracownicy),
- ]),
- h('i', { className: "glyphicon glyphicon-plus", style: { 'font-size': "14px", margin: "0 12px" } }),
- h('button', { className: "btn btn-primary btn-xs", onClick: this.addOdPozostale }, [ // .bi-btn-primary
- " pozostałe ",
- h('span', { className: "badge" }, this.state.totalOdPozostale),
- ]),
- (this.state.totalOdPozostale > 0) ? this.renderClearPozostaleOdBtn() : null,
- ]),
- h('li', { style: { marginTop: "6px" } }, [
- h('span', {
- style: totalDo > 0 ? { color: "#d7142d" } : {}
- }, [
- " DO ",
- h('span', { className: "badge", style: totalDo > 0 ? { 'background-color': "#d7142d" } : {} }, totalDo),
- " : ",
- ]),
- h('a', { className: "btn btn-primary btn-xs", href: "#KONTRAHENCI" }, [ // .bi-btn-primary
- " kontrahenci ",
- h('span', { className: "badge" }, this.state.totalDoKontrahenci),
- ]),
- h('i', { className: "glyphicon glyphicon-plus", style: { 'font-size': "14px", margin: "0 12px" } }),
- h('button', { className: "btn btn-primary btn-xs", onClick: this.addOdPozostale }, [ // .bi-btn-primary
- " pozostałe ",
- h('span', { className: "badge" }, this.state.totalDoPozostale),
- ]),
- (this.state.totalDoPozostale > 0) ? this.renderClearPozostaleDoBtn() : null,
- ]),
- ]);
- },
- renderRaportParamsForm: function () {
- var depth = parseInt(this.state.depth);
- var isDepthValid = ( !isNaN(depth) && depth >= 1 && depth <= 16 );
- var onlyTargets = this.state.onlyTargets;
- return h('div', {}, [
- h('div', { className: "row" + ( isDepthValid ? "" : " has-error" ), style: { 'margin-bottom': "12px" } }, [
- h('div', { className: "form-item col-md-7 col-lg-9 smad-heder-title", style: { 'font-size': "14px", 'text-align': "right", 'padding-top': "5px", 'padding-bottom': "0" } }, [
- "głębokość powiązań: ",
- ]),
- h('div', { className: "form-item col-md-5 col-lg-3" }, [
- h('input', { type: "number", className: "form-control", placeholder: "1-16", value: this.state.depth, onChange: this.handleChangeDepth, min: 1, max: 16 }),
- ]),
- ]),
- h('div', { className: "row", style: { 'margin-bottom': "12px" } }, [
- h('div', { className: "form-item col-md-7 col-lg-9 smad-heder-title", style: { 'font-size': "14px", 'text-align': "right", 'padding-top': "5px", 'padding-bottom': "0" } }, [
- "Czy zwracać wyniki tylko ze znalezionymi obiektami docelowymi (DO)? ",
- ]),
- h('div', { className: "form-item col-md-5 col-lg-3" }, [
- h('div', { className: "btn-group" }, [
- h('div', { className: "btn btn-default" + ( onlyTargets ? " active" : "" ), style: { padding: "6px 12px" }, onClick: this.handleChangeSetOnlyTargetsYes }, "TAK"),
- h('div', { className: "btn btn-default" + ( onlyTargets ? "" : " active" ), style: { padding: "6px 12px" }, onClick: this.handleChangeSetOnlyTargetsNo }, "NIE"),
- ]),
- ]),
- ]),
- h('div', { className: "row", style: { 'margin-bottom': "12px" } }, [
- h('div', { className: "form-item col-md-3 col-lg-3", style: { 'font-size': "14px", 'text-align': "right", 'padding-top': "5px", 'padding-bottom': "0" } }, [
- "Tytuł:",
- ]),
- h('div', { className: "form-item col-md-9 col-lg-9" }, [
- h('input', { type: "text", className: "form-control", placeholder: 'Raport bez tytułu z dnia ' + CURRENT_DATE, value: this.state.title, onChange: this.handleChangeTitle }),
- ]),
- ]),
- ]);
- },
- renderRaportFormSubmitBtn: function () {
- var totalOd = this.state.totalOdPracownicy + this.state.totalOdPozostale;
- var totalDo = this.state.totalDoKontrahenci + this.state.totalDoPozostale;
- var isFormValid = (totalOd || totalDo);
- return h('div', { className: "row", style: { padding: "0", 'margin-bottom': "0", 'text-align': "right" } }, [
- h('div', { className: "form-item col-md-12 col-lg-12" }, [
- h('button', {
- type: "button",
- className: "btn btn-default" + ( isFormValid ? "" : " disabled" ),
- onClick: this.handleRaportSubmitForm,
- style: { padding: "18px 42px", 'font-size': "18px", 'font-weight': "900" }
- }, "GENERUJ RAPORT POWIĄZAŃ"),
- ]),
- ]);
- },
- renderAddMoreBtns: function () {
- return h('div', {
- style: { 'padding-top': 6, 'padding-bottom': 20 }
- }, [
- h('button', { className: "btn btn-success btn-xs", onClick: this.handleAddByLastReportClick }, "dodaj do analizy wg raportu"),
- ]);
- },
- render: function () {
- DBG && console.log('DBG::P5UI__BocianHeader::render ', { state: this.state });
- var totalOd = this.state.totalOdPracownicy + this.state.totalOdPozostale;
- var totalDo = this.state.totalDoKontrahenci + this.state.totalDoPozostale;
- var depth = this.state.depth;
- var errorMsg = (depth > 16) ? "Maksymalna głębokość powiązań to 16!" : "";
- var warningMsg = ( ( !totalOd || !totalDo ) && depth > 6 ) ? "Krytyczne wielkości danych do przeszukania. Optymalna głębokość szukania powiaząń to: 6" : "";
- return h('div', { className: "container-fluid", style: { backgroundColor: "#efefef" } }, [
- h('div', { style: { fontSize: '16px', fontWeight: "normal", color: "#777" } }, [
- h('div', { className: "row" }, [
- h('div', { className: "col-md-6" }, [
- h('h3', { style: { color: "#000" } }, [
- h('span', { style: { fontSize: "120%", color: "#d7142d" } }, "|"),
- " Tworzenie nowego raportu ",
- h('br'),
- h('small', {}, [
- "(Wybierz elementy do porównania: ",
- h('span', { style: { color: "#d7142d" } }, " OD "),
- h('i', { className: "glyphicon glyphicon-random", style: { padding: '0 3px', 'font-size': "80%", color: "#000" } }),
- h('span', { style: { color: "#d7142d" } }, " DO"),
- ")",
- ])
- ]),
- "Wybrano:",
- this.renderSummaryList(),
- this.renderAddMoreBtns(),
- ]),
- h('div', { className: "col-md-6", style: { 'padding-top': "20px", 'padding-bottom': "20px" } }, [
- this.renderRaportParamsForm(),
- this.renderRaportFormSubmitBtn(),
- ]),
- ]),
- h('div', { className: "row" }, [
- h('div', { className: "col-md-8 col-md-offset-2 col-xs-12" }, [
- errorMsg ? h('div', { className: "alert alert-danger" }, errorMsg) : null,
- warningMsg ? h('div', { className: "alert alert-warning" }, warningMsg) : null,
- ]),
- ]),
- ])
- ])
- }
- })
- function getSelectedListLocalStorageKey(from) { // from: ( OD | DO )
- switch (from) {
- case 'OD': return 'Bocian.biAuditForm.odFeatureKeys';
- case 'DO': return 'Bocian.biAuditForm.doFeatureKeys';
- default: throw "Not implemented from selected list '" + from + "' - expected 'OD' or 'DO'";
- }
- }
- function getListFromLocalStorage(key) {
- return JSON.parse( localStorage.getItem(key) || '[]' );
- }
- function getSignedIntFromLocalStorage(key, defaultValue) {
- return JSON.parse( localStorage.getItem(key) || defaultValue );
- }
- function getStringFromLocalStorage(key, defaultValue) {
- var value = localStorage.getItem(key);
- value = (value) ? JSON.parse(value) : '';
- return (value) ? value : defaultValue;
- }
- // function saveToSelectedListInLocalStorage(from, featureKey) {
- // DBG && console.log("DBG::saveToSelectedListInLocalStorage(from, featureKey)", {from, featureKey}, {added: getSelectedListFromLocalStorage(from).concat(featureKey)});
- // localStorage.setItem(getSelectedListLocalStorageKey(from), JSON.stringify(
- // getSelectedListFromLocalStorage(from).concat(featureKey)
- // ))
- // }
- // function removeFromSelectedListInLocalStorage(from, featureKey) {
- // DBG && console.log("DBG::removeFromSelectedListInLocalStorage(from, featureKey)", {from, featureKey});
- // localStorage.setItem(getSelectedListLocalStorageKey(from), JSON.stringify(
- // getSelectedListFromLocalStorage(from).filter(function (item) {
- // return ( item !== featureKey );
- // })
- // ))
- // }
- /* 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);
- }).catch(function(error) {
- if(DBG) console.log('request failed', error)
- });
- }
- /* FORM DATA FOR GENERATAE REAPORT */
- /**
- * Załadowanie wybranej pozycji w select czy zwracać wyniki tylko z obiektami docelowymi onlyTarget
- */
- function loadCurrentOnlyTargetsSelect() {
- var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
- $('#smad-select-target').val(analizaOnlyTargets).attr("selected", "selected");
- $('#smad-select-target-kontrahenci').val(analizaOnlyTargets).attr("selected", "selected");
- }
- /**
- * Załadowanie do storage informacji czy zwracać wyniki tylko z obiektami docelowymi
- */
- function updateLocalStorageBiAuditOnlyTargets(idSelect) {
- $(idSelect).change(function() {
- var newValue = $(idSelect).val();
- var responseValue = newValue;
- setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', responseValue);
- $('#smad-select-target').val(newValue).attr("selected", "selected");
- $('#smad-select-target-kontrahenci').val(newValue).attr("selected", "selected");
- // load in select selected option
- loadCurrentOnlyTargetsSelect();
- });
- }
- /**
- * Funkcja pozwala na wyświetlenie okienka importu
- */
- function showViewUploadFile( event, headerTitle, enumType, showCheckbox, csvFileExample ) {
- event.preventDefault();
- var enumType = enumType;
- if( csvFileExample !== undefined) { // przykład + instrukcja do pobrania
- csvFileExample = '<div><a href="'+csvFileExample+'" title="Pobierz przykład" download target="_balnk">Pobierz przykład</a></div>';
- }
- swal({
- title: 'Importuj plik csv',
- input: 'file',
- html: csvFileExample,
- 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 input = document.querySelector('input[type="file"]');
- var data = new FormData()
- data.append('file', input.files[0])
- data.append('showCheckbox', showCheckbox);
- var responseParseFile = parseCsvFile( data, enumType );
- resolve('file imported')
- })
- },
- }).then(function (result) {
- if(DBG) console.log('result', result);
- }).catch(function (e) {
- if(DBG) console.log('catch: ', e);
- });
- }
- /**
- * Funkcja przekazuje dane z pliku csv do przeparsowania
- */
- function parseCsvFile( fileData, enumType ) {
- event.preventDefault();
- if(DBG) console.log( 'parseCsvFile fileData', fileData);
- fetch(URL_FORM_DATA_CSV_FILE_AJAX, {
- method: 'POST',
- credentials: 'same-origin',
- body: fileData
- })
- .then(function(response) {
- return response.json()
- }).then(function(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);
- resolve('data save from form')
- })
- },
- }).then(function (result) {
- if(DBG) console.log('result', result)
- }).catch(function (e) {
- if(DBG) console.log('catch: ', e)
- });
- }).catch(function(ex) {
- if(DBG) 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,"]");
- 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) {
- if(DBG) console.log('parsed json', json);
- if (response.type == 'success') {
- p5UI__notifyAjaxCallback(response.msg);
- }
- // return json;
- }).catch(function(ex) {
- if(DBG) console.log('parsing failed', ex);
- });
- }
- /**
- * Dodaj nowego pracownika
- */
- function createPracownikAjax(event) {
- event.preventDefault();
- swal({
- title: 'Dodaj osobę',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- html:
- '<div class="form-group">'+
- '<input class="form-control required" id="personName" placeholder="Imię" >' +
- '<input class="form-control required" id="personSurname" placeholder="Nazwisko">'+
- '<input class="form-control required" id="personNip" placeholder="NIP">'+
- '<input class="form-control required" id="personPesel" placeholder="PESEL">'+
- '<input class="form-control required" id="personRegon" placeholder="REGON">'+
- '</div>',
- preConfirm: () => {
- return new Promise(function (resolve, reject) {
- // data from form
- var personName = $('#personName').val();
- var personSurname = $('#personSurname').val();
- var personNip = $('#personNip').val();
- var personPesel = $('#personPesel').val();
- var personRegon = $('#personRegon').val();
- //validate data from input
- if (!personName){
- reject('Proszę podać imię')
- return;
- }
- if (!personSurname){
- reject('Proszę podać nazwisko')
- return;
- }
- window.fetch(URL_CREATE_PRACOWNICY, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'personName': personName,
- 'personSurname': personSurname,
- 'personNip': personNip,
- 'personPesel': personPesel,
- 'personRegon': personRegon
- })
- })
- .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);
- urlFetchPracownicy(1);
- }
- })
- .catch(function(error) {
- if(DBG) console.log('request failed', error);
- })
- })
- },
- allowOutsideClick: false
- }).then(function (createPerson) {
- if(DBG) console.log('dodanie osoby: ', createPerson);
- });
- }
- /**
- * Dodaj nowego kontrahenta
- */
- function createKontrahentAjax(event) {
- event.preventDefault();
- swal({
- title: 'Dodaj podmiot/kontrahenta',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- html:
- '<div class="form-group">'+
- '<input class="form-control required" id="companyFullName" placeholder="Pelna nazwa" >' +
- '<input class="form-control required" id="companyShortName" placeholder="Skrócona nazwa\">'+
- '<input class="form-control required" id="companyNameGroup" placeholder="Nazwa grupy kapitałowej">'+
- '<input class="form-control required" id="companyKrs" placeholder="KRS">'+
- '<input class="form-control required" id="companyNip" placeholder="NIP">'+
- '<input class="form-control required" id="companyPesel" placeholder="PESEL">'+
- '<input class="form-control required" id="companyFax" placeholder="FAX">'+
- '<input class="form-control required" id="companyTelefon" placeholder="Telefon">'+
- '<input class="form-control required" id="companyMail" placeholder="Mail">'+
- '<input class="form-control required" id="companyStreet" placeholder="Ulica">'+
- '<input class="form-control required" id="companyNumberBuilding" placeholder="Numer budynku">'+
- '<input class="form-control required" id="companyNumberLocal" placeholder="Numer mieszkania /lokalu">'+
- '<input class="form-control required" id="companyPostCode" placeholder="Kod pocztowy">'+
- '<input class="form-control required" id="companyPlace" placeholder="Miejscowosc">'+
- '<input class="form-control required" id="companyCountry" placeholder="Kraj">'+
- '<input class="form-control required" id="companyTypeCompany" placeholder="Typ kontrahenta">'+
- '<input class="form-control required" id="companyTitleDocument" placeholder="Tytul dokumentu">'+
- '<input class="form-control required" id="companyDesc" placeholder="uwagi">'+
- '</div>',
- preConfirm: () => {
- return new Promise(function (resolve, reject) {
- // data from form
- var companyFullName = $('#companyFullName').val();
- var companyShortName = $('#companyShortName').val();
- var companyNameGroup = $('#companyNameGroup').val();
- var companyKrs = $('#companyKrs').val();
- var companyNip = $('#companyNip').val();
- var companyPesel = $('#companyPesel').val();
- var companyFax = $('#companyFax').val();
- var companyTelefon = $('#companyTelefon').val();
- var companyMail = $('#companyMail').val();
- var companyStreet = $('#companyStreet').val();
- var companyNumberBuilding = $('#companyNumberBuilding').val();
- var companyNumberLocal = $('#companyNumberLocal').val();
- var companyPostCode = $('#companyPostCode').val();
- var companyPlace = $('#companyPlace').val();
- var companyCountry = $('#companyCountry').val();
- var companyTypeCompany = $('#companyTypeCompany').val();
- var companyTitleDocument = $('#companyTitleDocument').val();
- var companyDesc = $('#companyDesc').val();
- //validate data from input
- if (!companyFullName){
- reject('Proszę podać pełną nazwę');
- return;
- }
- window.fetch(URL_CREATE_KONTRAHENCI, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'companyFullName': companyFullName,
- 'companyShortName': companyShortName,
- 'companyNameGroup': companyNameGroup,
- 'companyKrs': companyKrs,
- 'companyNip': companyNip,
- 'companyPesel': companyPesel,
- 'companyFax': companyFax,
- 'companyTelefon': companyTelefon,
- 'companyMail': companyMail,
- 'companyStreet': companyStreet,
- 'companyNumberBuilding': companyNumberBuilding,
- 'companyNumberLocal': companyNumberLocal,
- 'companyPostCode': companyPostCode,
- 'companyPlace': companyPlace,
- 'companyCountry': companyCountry,
- 'companyTypeCompany': companyTypeCompany,
- 'companyTitleDocument': companyTitleDocument,
- 'companyDesc': companyDesc
- })
- })
- .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);
- urlFetchKontrahenci(1);
- }
- })
- .catch(function(error) {
- if(DBG) console.log('request failed', error);
- })
- })
- },
- allowOutsideClick: false
- }).then(function (createPerson) {
- if(DBG) console.log('dodanie podmiotu: ', createPerson);
- });
- }
- /**
- * Popup z opcja przeniesienia pracowników do innej grupy
- */
- function addPracownikToGroup(event) {
- event.preventDefault();
- var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
- if (pracownicyIdsArray === null || !pracownicyIdsArray || !pracownicyIdsArray.length) {
- showTextListIdPracownikow = 'nie wybrano osób';
- } else {
- showTextListIdPracownikow = '' + pracownicyIdsArray.length + ' osób';
- }
- var arrayGroupOptions = [];
- var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
- // utworzenie tablicy Optionsów grupy
- listGroupStorage.map(function(item) {
- if (item.ID !== undefined) {
- arrayGroupOptions[item.ID] = item.NAZWA;
- }
- });
- swal({
- title: 'Dodaj do grupy',
- input: 'select',
- text: showTextListIdPracownikow,
- inputOptions: arrayGroupOptions,
- inputPlaceholder: 'Wybierz grupę',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- preConfirm: function (idGroup) {
- if (!idGroup) {
- swal.showValidationError('Proszę wybrać nazwę grupy');
- return;
- }
- if (!pracownicyIdsArray || !pracownicyIdsArray.length) {
- swal.showValidationError('Proszę wybrać pracowników');
- return;
- }
- return new Promise(function (resolve, reject) {
- 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) {
- if(DBG) console.warn('request failed', error);
- });
- })
- },
- allowOutsideClick: false
- }).then(function (value) {
- { // remove from selected
- setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
- updateCountItemCheckedByType('pracownicy');
- $('form').find(':checkbox').prop('checked', false);
- }
- }).catch(function (e) {
- DBG && console.log('DBG: e', e)
- });
- }
- function addPracownikAllToGroup(event) {
- event.preventDefault();
- var showTextListIdPracownikow = 'wszystkich pracowników pasujących do kryteriów wyszukiwania';
- var arrayGroupOptions = [];
- var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
- // utworzenie tablicy Optionsów grupy
- listGroupStorage.map(function(item) {
- if (item.ID !== undefined) {
- arrayGroupOptions[item.ID] = item.NAZWA;
- }
- });
- swal({
- title: 'Dodaj do grupy',
- input: 'select',
- text: showTextListIdPracownikow,
- inputOptions: arrayGroupOptions,
- 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');
- return;
- }
- var filterFields = {}
- var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
- var fieldNameList = FIELD_LIST_PRACOWNICY
- fieldNameList.filter(function (fieldName) {
- if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"');
- return (frm[fieldName]) ? true : false
- }).map(function (fieldName) {
- return [ fieldName, frm[fieldName].value ]
- }).filter(function (filter) {
- return ( filter[1].length > 0 )
- }).map(function (filter) {
- filterFields[ filter[0] ] = filter[1]
- })
- var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
- if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
- window.fetch(URL_ADD_PRACOWNICY_TO_GROUP, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'idGroup': idGroup,
- 'type': 'filter',
- 'filter': filterFields,
- })
- })
- .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) {
- if(DBG) console.log('request failed', error);
- });
- })
- },
- allowOutsideClick: false
- }).then(function (groupPracownicyData) {
- //TODO: pIOTRKU CZY TU POWINIENEM COŚ JESZCZE OBSŁUŻYĆ
- });
- }
- /**
- * Popup z opcja przeniesienia kontrahentów do innej grupy
- */
- function addKontrahenciToGroup(event) {
- event.preventDefault();
- var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- if (kontrahenciIdsArray === null || !kontrahenciIdsArray || !kontrahenciIdsArray.length) {
- showTextListIdKontrahentow = 'nie wybrano kontrahentów';
- } else {
- showTextListIdKontrahentow = '' + kontrahenciIdsArray.length + ' podmiotów/kontrahentów';
- }
- var arrayGroupOptions = [];
- var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
- // utworzenie tablicy Optionsów grupy
- listGroupStorage.map(function(item) {
- if (item.ID !== undefined) {
- arrayGroupOptions[item.ID] = item.NAZWA;
- }
- });
- swal({
- title: 'Dodaj do grupy',
- input: 'select',
- text: showTextListIdKontrahentow,
- inputOptions: arrayGroupOptions,
- inputPlaceholder: 'Wybierz grupę',
- showCancelButton: true,
- confirmButtonText: 'Zapisz',
- showLoaderOnConfirm: true,
- preConfirm: function (idGroup) {
- if (!idGroup) {
- swal.showValidationError('Proszę wybrać nazwę grupy');
- return;
- }
- if (!kontrahenciIdsArray || !kontrahenciIdsArray.length) {
- swal.showValidationError('Proszę wybrać kontrahentów');
- return;
- }
- return new Promise(function (resolve, reject) {
- 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) {
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- resolve(result.msg);
- } else {
- reject(result.msg);
- }
- })
- .catch(function(error) {
- if(DBG) console.warn('request failed', error);
- });
- })
- },
- allowOutsideClick: false
- }).then(function (value) {
- { // remove from selected
- setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
- updateCountItemCheckedByType('kontrahenci');
- $('form').find(':checkbox').prop('checked', false);
- }
- }).catch(function (e) {
- DBG && console.log('DBG: e', e)
- });
- }
- function addKontrahenciAllToGroup(event) {
- event.preventDefault();
- var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- var showTextListIdKontrahentow = 'wszystkich podmotów/kontrahentów pasujących do kryteriów wyszukiwania';
- var arrayGroupOptions = [];
- var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
- // utworzenie tablicy Optionsów grupy
- listGroupStorage.map(function(item) {
- if (item.ID !== undefined) {
- arrayGroupOptions[item.ID] = item.NAZWA;
- }
- });
- swal({
- title: 'Dodaj do grupy',
- input: 'select',
- text: showTextListIdKontrahentow,
- inputOptions: arrayGroupOptions,
- 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');
- return;
- }
- var filterFields = {}
- var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
- var fieldNameList = FIELD_LIST_KONTRAHENCI
- fieldNameList.filter(function (fieldName) {
- if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"')
- return (frm[fieldName]) ? true : false
- }).map(function (fieldName) {
- return [ fieldName, frm[fieldName].value ]
- }).filter(function (filter) {
- return ( filter[1].length > 0 )
- }).map(function (filter) {
- filterFields[ filter[0] ] = filter[1]
- })
- var filterIdGroup = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
- if (filterIdGroup) filterFields[ 'filterIdGroup' ] = filterIdGroup
- window.fetch(URL_ADD_KONTRAHENCI_TO_GROUP, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'idGroup': idGroup,
- 'type': 'filter',
- 'filter': filterFields,
- })
- })
- .then(function(response) {
- return response.text();
- })
- .then(function(responseText) {
- try {
- return JSON.parse(responseText);
- } catch (e) {
- throw responseText;
- }
- })
- .then(function(result) {
- $('#smad-table-PRACOWNICY form').find(':checkbox').prop('checked', false);
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- resolve(result.msg);
- } else {
- reject(result.msg);
- }
- })
- .catch(function(error) {
- if(DBG) console.log('request failed', error);
- });
- })
- },
- allowOutsideClick: false
- });
- }
- function removeKontrahenciFromGroup(event) {
- event.preventDefault;
- var kontrahenciIdsArray = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- if (kontrahenciIdsArray === null || !kontrahenciIdsArray || !kontrahenciIdsArray.length) {
- showTextListIdKontrahentow = 'nie wybrano kontrahentów';
- } else {
- showTextListIdKontrahentow = '' + kontrahenciIdsArray.length + ' podmiotów/kontrahentów';
- }
- var groupId = getItemLocalStorage("Bocian.biAuditForm.kontrahenci.filterIdGroup");
- var removeTitle = "Czy chcesz usunąć z "
- if (groupId === "0") {
- removeTitle += "systemu";
- } else {
- var arrayGroupOptions = [];
- var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups');
- // utworzenie tablicy Optionsów grupy
- listGroupStorage.map(function(item) {
- if (item.ID !== undefined) {
- arrayGroupOptions[item.ID] = item.NAZWA;
- }
- });
- removeTitle += "grupy ";
- removeTitle += arrayGroupOptions[groupId];
- }
- swal({
- title: removeTitle,
- text: showTextListIdKontrahentow,
- showConfirmButton: true,
- showCancelButton: true,
- confirmButtonText: 'Usuń',
- cancelButtonText: 'Anuluj',
- showLoaderOnConfirm: true,
- preConfirm: function () {
- return new Promise(function (resolve, reject) {
- if (!kontrahenciIdsArray || !kontrahenciIdsArray.length) {
- reject('Wybierz kontrahentów');
- return;
- }
- window.fetch(URL_REMOVE_KONTRAHENCI_FROM_GROUP, {
- method: 'POST',
- header: { 'contentType': 'applications/json' },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'idGroup': getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup'),
- '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);
- updateTopCounters();
- $('#smad-table-KONTRAHENCI form').find(':checkbox').prop('checked', false);
- resolve(result.msg);
- } else {
- reject(result.msg);
- }
- })
- })
- },
- allowOutsideClick: false
- }).then((result) => {
- if (!result) return;
- if (result.dismiss) return;
- if (!result.value) return;
- { // remove from selected
- setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
- updateCountItemCheckedByType('kontrahenci');
- $('#smad-table-KONTRAHENCI form').find(':checkbox').prop('checked', false);
- }
- urlFetchKontrahenci(1);
- });
- }
- function removePracownikFromGroup(event){
- event.preventDefault;
- var pracownicyIdsArray = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
- if (pracownicyIdsArray === null || !pracownicyIdsArray || !pracownicyIdsArray.length) {
- showTextListIdPracownikow = 'nie wybrano osób';
- } else {
- showTextListIdPracownikow = '' + pracownicyIdsArray.length + ' osób';
- }
- var groupId = getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup');
- var removeTitle = "Czy chcesz usunąć z "
- if (!groupId) {
- removeTitle += "systemu";
- } else {
- var arrayGroupOptions = [];
- var listGroupStorage = getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups');
- // utworzenie tablicy Optionsów grupy
- listGroupStorage.map(function(item) {
- if (item.ID !== undefined) {
- arrayGroupOptions[item.ID] = item.NAZWA;
- }
- });
- removeTitle += "grupy ";
- removeTitle += arrayGroupOptions[groupId];
- }
- swal({
- title: removeTitle,
- text: showTextListIdPracownikow,
- showConfirmButton: true,
- showCancelButton: true,
- confirmButtonText: 'Usuń',
- cancelButtonText: 'Anuluj',
- showLoaderOnConfirm: true,
- preConfirm: function () {
- return new Promise(function (resolve, reject) {
- if (!pracownicyIdsArray || !pracownicyIdsArray.length) {
- reject('Wybierz osoby');
- return;
- }
- window.fetch(URL_REMOVE_PRACOWNICY_FROM_GROUP, {
- method: 'POST',
- header: { 'contentType': 'applications/json' },
- credentials: 'same-origin',
- body: JSON.stringify({
- 'idGroup': getItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup'),
- '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);
- updateTopCounters();
- $('#smad-table-PRACOWNICY form').find(':checkbox').prop('checked', false);
- resolve(result.msg);
- } else {
- reject(result.msg);
- }
- })
- })
- },
- allowOutsideClick: false
- }).then((result) => {
- if (!result) return;
- if (result.dismiss) return;
- if (!result.value) return;
- { // remove from selected
- setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
- updateCountItemCheckedByType('pracownicy');
- $('#smad-table-PRACOWNICY form').find(':checkbox').prop('checked', false);
- }
- urlFetchPracownicy(1);
- });
- }
- 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');
- return;
- }
- 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.body);
- } else {
- reject("Proszę podać inną nazwę grupy");
- }
- })
- .catch(function(error) {
- if(DBG) console.log('request failed', error);
- })
- })
- },
- allowOutsideClick: false
- }).then(function (result) {
- if (!result) return;
- if (result.dismiss) return;
- if (!result.value) return;
- // NOTE: swal has input, so resolver object from preConfirm is in { value: resolvedObject }
- var addedGroup = result.value;
- if (addedGroup.id && addedGroup.nazwa) {
- $('#group-kontrahenci').append('<button class="btn btn-default" title="'+addedGroup['nazwa']+'" data-group-filter="'+addedGroup['id']+'">'+addedGroup['nazwa']+'</button>');
- { // add group to local storage
- setItemLocalStorage(
- 'Bocian.biAuditForm.kontrahenci.groups',
- [].concat(
- getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups') || [],
- [ { 'ID': addedGroup.id, 'NAZWA': addedGroup.nazwa } ]
- )
- );
- }
- }
- //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
- });
- }
- 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');
- return;
- }
- 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) {
- console.warn('DBG group added? result', result)
- if (result.type == 'success') {
- p5UI__notifyAjaxCallback(result);
- resolve(result.body);
- } else {
- reject("Proszę podać inną nazwę grupy");
- }
- })
- .catch(function(error) {
- if(DBG) console.log('request failed', error);
- })
- })
- },
- allowOutsideClick: false
- }).then(function (result) {
- if (!result) return;
- if (result.dismiss) return;
- if (!result.value) return;
- // NOTE: swal has input, so resolver object from preConfirm is in { value: resolvedObject }
- var addedGroup = result.value;
- if (addedGroup.id && addedGroup.nazwa) {
- $('#group-pracownicy').append('<button class="btn btn-default" title="'+addedGroup['nazwa']+'" data-group-filter="'+addedGroup['id']+'">'+addedGroup['nazwa']+'</button>');
- { // add group to local storage
- setItemLocalStorage(
- 'Bocian.biAuditForm.pracownicy.groups',
- [].concat(
- getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups') || [],
- [ { 'ID': addedGroup.id, 'NAZWA': addedGroup.nazwa } ]
- )
- );
- }
- }
- //TODO: aktualizacja fitrów na widoku -> SPrawdzić co dostaniemy w odpowiedzi po dodaniu filtra grupy
- });
- }
- /**
- * Function for load view Form pracownicy/kontrahenci
- */
- function rootChangeForm() {
- //todo: do przeniesienia
- urlFetchKontrahenciPowiazania();
- var valueUrl = global.location.hash;
- 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();
- $(".container-bi-audit_form_operacyjna_baza_zgloszen").hide();
- //parseGraph();
- 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();
- $(".container-bi-audit_form_operacyjna_baza_zgloszen").hide();
- break;
- case '#OPERACYJNA_BAZA_ZGLOSZEN':
- $( ".container-bi_audit_form_operacyjna_baza_zgloszen" ).html( OPERACYJNA_BAZA_ZGLOSZEN );
- // urlFetchPracownicy(1);
- // fetchGroupPracownicy();
- $( ".container-bi_audit_form_kontrahenci_raport" ).hide();
- $( ".container-bi_audit_form_pracownicy_raport" ).hide();
- $(".container-bi-audit_form_operacyjna_baza_zgloszen").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-training" ).hide();
- $( ".container-about" ).hide();
- $( ".container-bi_audit_form_pracownicy_raport" ).show();
- break;
- }
- // aktualizacja select option czy zwracać wyniki tylko z obiektami docelowymi
- updateLocalStorageBiAuditOnlyTargets('#smad-select-target');
- updateLocalStorageBiAuditOnlyTargets('#smad-select-target-kontrahenci');
- // load in select selected option BI_analiza_onlyTargets
- loadCurrentOnlyTargetsSelect();
- }
- 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;
- }
- /**
- * Get name name group
- */
- function getNameGroupById(store, filterIdGroup) {
- var NAZWA = '';
- if (!store || filterIdGroup === 0 ) {
- NAZWA = 'Wszyscy';
- } else {
- $(store).each(function() {
- if ( parseInt(filterIdGroup) === parseInt(this.ID) ) {
- NAZWA = this.NAZWA;
- }
- });
- }
- return NAZWA;
- }
- function urlFetchKontrahenci(page) {
- hideMoreRecordFunctionsPopover()
- 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');
- var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
- var fieldNameList = FIELD_LIST_KONTRAHENCI
- var filterFields = fieldNameList.map(function (fieldName) {
- return [ fieldName, frm[fieldName].value ]
- }).filter(function (filter) {
- return ( filter[1].length > 0 )
- }).map(function (filter) {
- return '' + filter[0] + '=' + filter[1]
- }).join('&')
- filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
- fetch(URL_FETCH_KONTRAHENCI + '&page=' + page + '&filterIdGroup=' + filterIdGroup + filterFields, {
- credentials: 'same-origin'
- })
- .then(function parseJSON(response) {
- return response.json()
- var filterIdGroup = filterIdGroup || getItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup');
- })
- .then(function(data) {
- var listItemsKontrahenci = null;
- data.body.items.forEach (function(row) {
- listItemsKontrahenci += '<tr><td style="white-space:nowrap">' +
- '<input style="vertical-align:top" type="checkbox" name="kontrID[]" value="'+row['ID']+'" />' +
- '<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>' +
- '</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["Dodano"] || '' ) + '</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: BASE_URLS+'index.php?_route=UrlAction_Bocian#KONTRAHENCI',
- id_pagination: 'pagination-kontrahenci',
- type: 'KONTRAHENCI',
- limit: data.body.pagination.limit,
- 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
- });
- var paginationShowNextCount = 1;
- if ( parseInt(data.body.pagination.current) !== 1) {
- paginationShowNextCount = parseInt(data.body.pagination.limit) * (parseInt(data.body.pagination.current) - 1 ) + 1;
- }
- $('#paginationShowNextCount-KONTRAHENCI').text(paginationShowNextCount);
- $('#smad-filter-desc-kontrahenci').text(data.body.pagination.total_items);
- if (data.body.pagination.total_items > 0) {
- var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>');
- btnAddAll.on('click', { type: 'kontrahenci', pagination: data.body.pagination }, addAllMatchesToReport);
- $('#smad-filter-desc-kontrahenci').append(btnAddAll);
- // var btnAddByReport = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ DO ANALIZY WG RAPORTU</button>');
- // btnAddByReport.on('click', { type: 'kontrahenci', pagination: data.body.pagination }, addToReportByPreviousReport);
- // $('#smad-filter-desc-kontrahenci').append(btnAddByReport);
- var btnAddAllToGroup = $('<button class="btn btn-info" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</button>');
- btnAddAllToGroup.on('click', addKontrahenciAllToGroup);
- $('#smad-filter-desc-kontrahenci').append(btnAddAllToGroup);
- }
- }
- var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.kontrahenci.groups'), filterIdGroup);
- $('#smad-filter-head-title-kontrahenci').text(groupSelectData);
- if(DBG) console.log('kontrahenci groupSelectData: ', groupSelectData);
- $( "#body-kontrahenci" ).html(listItemsKontrahenci);
- checkAll('KONTRAHENCI');
- catchEventCheckbox('KONTRAHENCI');
- checkedChoiseItems('KONTRAHENCI', getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds') );
- // $( ".container-bi_audit_raport" ).append( data.body.view );
- if(DBG) console.log('request succeeded with JSON responseKontrahenci', data)
- updateTopCounters();
- }).catch(function(error) {
- if(DBG) console.log('request failed', error);
- })
- }
- function urlFetchPracownicy(page) {
- hideMoreRecordFunctionsPopover()
- 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);
- var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
- var fieldNameList = FIELD_LIST_PRACOWNICY
- var filterFields = fieldNameList.filter(function (fieldName) {
- if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"')
- return (frm[fieldName]) ? true : false
- }).map(function (fieldName) {
- return [ fieldName, frm[fieldName].value ]
- }).filter(function (filter) {
- return ( filter[1].length > 0 )
- }).map(function (filter) {
- return '' + filter[0] + '=' + filter[1]
- }).join('&')
- filterFields = (filterFields.length > 0) ? '&' + filterFields : ''
- var paginationLimit = 20;
- /*p5WFS_GetFeature('default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- Object.assign({
- sortBy: 'ID+D',
- maxFeatures: paginationLimit,
- startIndex: (page - 1) * paginationLimit,
- // TODO: backRefNS, backRefPK, backRefField - TODO: from groups
- // resolve: 'all',
- // resolveDepth: 2
- 'ogc:Filter': '<wfs:Query>' + '\n' + [
- '*',
- 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*',
- [
- 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
- 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
- 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
- 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI'
- ].join('/')
- ].map(function (fieldName) {
- return '<wfs:PropertyName>' + fieldName + '</wfs:PropertyName>';
- }).join('\n') + '\n' + '</wfs:Query>'
- }, (filterIdGroup > 0)
- ? {
- backRefNS: 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- backRefPK: filterIdGroup,
- backRefField: 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- }
- : {}
- )
- ).then(function (items) {
- if(DBG)console.log('p5WFS_GetFeature: items: ', items);
- }).catch(function (err) {
- if(DBG)console.log('p5WFS_GetFeature: err: ', err);
- })*/
- fetch(URL_FETCH_PRACOWNICY + '&page=' + page + '&filterIdGroup=' + filterIdGroup + filterFields, {
- credentials: 'same-origin'
- })
- .then(function parseJSON(response) {
- return response.json()
- })
- .then(function(data) {
- var addresPerson = '';
- var listItemsPracownik = null;
- if(DBG) 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 style="white-space:nowrap">' +
- '<input style="vertical-align:top" type="checkbox" name="prID[]" value="'+row['ID']+'" />' +
- '<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>' +
- '</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["jednostka_organizacyjna"] || '' ) + '</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: BASE_URLS+'index.php?_route=UrlAction_Bocian#PRACOWNICY',
- id_pagination: 'pagination-pracownicy',
- type: 'PRACOWNICY',
- limit: data.body.pagination.limit,
- 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
- });
- var paginationShowNextCount = 1;
- if ( parseInt(data.body.pagination.current) !== 1) {
- paginationShowNextCount = parseInt(data.body.pagination.limit) * (parseInt(data.body.pagination.current) - 1 ) + 1;
- }
- $('#paginationShowNextCount-PRACOWNICY').text(paginationShowNextCount);
- $('#smad-filter-desc-pracownicy').text(data.body.pagination.total_items);
- if (data.body.pagination.total_items > 0) {
- var btnAddAll = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO ANALIZY</button>')
- btnAddAll.on('click', { type: 'pracownicy', pagination: data.body.pagination }, addAllMatchesToReport);
- $('#smad-filter-desc-pracownicy').append(btnAddAll);
- // var btnAddByReport = $('<button class="btn btn-primary" style="padding:1px 5px; margin-left:12px">DODAJ DO ANALIZY WG RAPORTU</button>');
- // btnAddByReport.on('click', { type: 'pracownicy', pagination: data.body.pagination }, addToReportByPreviousReport);
- // $('#smad-filter-desc-pracownicy').append(btnAddByReport);
- var btnAddAllToGroup = $('<button class="btn btn-info" style="padding:1px 5px; margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</button>');
- btnAddAllToGroup.on('click', addPracownikAllToGroup);
- $('#smad-filter-desc-kontrahenci').append(btnAddAllToGroup);
- }
- }
- // wyświetlenie wybranej grupy w naglówku nad tabela
- var groupSelectData = getNameGroupById(getItemLocalStorage('Bocian.biAuditForm.pracownicy.groups'), filterIdGroup);
- $('#smad-filter-head-title-pracownicy').text(groupSelectData);
- // zaladaowanie listy pracowników
- $( "#body-pracownicy" ).html( listItemsPracownik);
- checkAll('PRACOWNICY');
- catchEventCheckbox('PRACOWNICY');
- checkedChoiseItems('PRACOWNICY', getItemLocalStorage('Bocian.biAuditForm.pracownicyIds') );
- updateTopCounters();
- }).catch(function(error) {
- if(DBG) 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);
- }
- // update count selected IDs
- updateCountItemCheckedByType(type.toLowerCase());
- });
- }
- /**
- * Select again checkbox before selected item chekbox from storage (pracownicy/kontrahenci)
- */
- function checkedChoiseItems(type, store) {
- updateCountItemCheckedByType(type.toLowerCase());
- var idElement = 'smad-table-' + type;
- // if id element exist
- if (document.getElementById(idElement)) {
- // if not checked
- if (!store) {
- return false;
- }
- // 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();
- }
- }
- $('#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);
- }
- // update count selected IDs
- updateCountItemCheckedByType(type.toLowerCase());
- });
- }
- 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) {
- if ( type == 'PRACOWNICY') {
- deleteItemLocalStorage('Bocian.biAuditForm.pracownicyIds', valueArray);
- }
- if ( type == 'KONTRAHENCI') {
- deleteItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', valueArray);
- }
- }
- 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 currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
- setItemLocalStorage('Bocian.biAuditForm.pracownicy.filterIdGroup', filterIdGroup);
- setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
- var groupsPracownicy = '';
- var activeButton = '';
- data.body.itmesGroupPracownicy.forEach (function(row) {
- activeButton = '';
- if ( filterIdGroup === parseInt(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);
- updateCountItemCheckedByType('pracownicy');
- detectChoiseFilter();
- }).catch(function(error) {
- if(DBG) 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 currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', filterIdGroup);
- setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
- var groupsKontrahenci = '';
- var activeButton = '';
- data.body.itemsGroupKontrahenci.forEach (function(row) {
- activeButton = '';
- if ( filterIdGroup === parseInt(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);
- updateCountItemCheckedByType('kontrahenci');
- detectChoiseFilter();
- }).catch(function(error) {
- if(DBG) 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");
- // aktaulna wartość zagłebienia
- var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
- // czy zwracać wyniki tylko z obiektami docelowymi
- var analizaOnlyTargets = getItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets');
- // ustawienie ostaniej wartości zagłebienia przed resete
- setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
- // czy zwracać wyniki tylko z obiektami docelowymi
- setItemLocalStorage('Bocian.biAuditForm.analizaOnlyTargets', analizaOnlyTargets);
- // ustawić id grupy do sesyjnej
- setItemLocalStorage('Bocian.biAuditForm.kontrahenci.filterIdGroup', parseInt(filterIdGroup));
- // wywylac funckje pobrania danych
- urlFetchKontrahenci(1);
- });
- $('#group-pracownicy').on('click', 'button', function(e) {
- e.preventDefault();
- $('#group-pracownicy button.active').removeClass('active');
- $(this).addClass('active');
- // pobranie id grupy kliknietego buttonu
- var filterIdGroup = $(this).attr("data-group-filter");
- // aktaulna wartość zagłebienia
- var currentDepthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
- // ustawienie ostaniej wartości zagłebienia przed resete
- setItemLocalStorage('Bocian.biAuditForm.depth', currentDepthValue);
- // 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;
- }
- /**
- * Cleart list local storage by type
- * typeNameLocalStorage - name (praconwicy/kontrahenci)
- */
- function clearListLocalStorageByType(typeNameLocalStorage) {
- if (typeNameLocalStorage === 'pracownicy') {
- setItemLocalStorage('Bocian.biAuditForm.pracownicyIds', []);
- }
- if (typeNameLocalStorage === 'kontrahenci') {
- setItemLocalStorage('Bocian.biAuditForm.kontrahenciIds', []);
- }
- // update count selected item
- updateCountItemCheckedByType(typeNameLocalStorage);
- // unchecked checkbox
- $('#smad-table-'+typeNameLocalStorage.toUpperCase()+' form').find(':checkbox').prop('checked', false);
- }
- /**
- * Update count selected pracowniyc/kontrahenci
- */
- function updateCountItemCheckedByType(typeNameLocalStorage) {
- var countId = 0;
- updateTopCounters();
- if (typeNameLocalStorage === 'pracownicy') {
- var countPracownicy = getItemLocalStorage('Bocian.biAuditForm.pracownicyIds');
- if (countPracownicy === null || countPracownicy === undefined) {
- return countId;
- }
- countId = Object.keys(countPracownicy).length;
- $('#count-selected-item-pracownicy').text(countId);
- }
- if (typeNameLocalStorage === 'kontrahenci') {
- var countKontrahenci = getItemLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- if (countKontrahenci === null || countKontrahenci === undefined) {
- return countId;
- }
- countId = Object.keys(countKontrahenci).length;
- $('#count-selected-item-kontrahenci').text(countId);
- }
- return countId;
- }
- function updateTopCounters() {
- var idsPracownicy = getListFromLocalStorage('Bocian.biAuditForm.pracownicyIds');
- var idsKontrahenci = getListFromLocalStorage('Bocian.biAuditForm.kontrahenciIds');
- var pozostaleOd = getListFromLocalStorage(getSelectedListLocalStorageKey('OD'));
- var pozostaleDo = getListFromLocalStorage(getSelectedListLocalStorageKey('DO'));
- var allOdLength = idsPracownicy.length + pozostaleOd.length;
- var allDoLength = idsKontrahenci.length + pozostaleDo.length;
- var depthValue = getItemLocalStorage('Bocian.biAuditForm.depth');
- if (globalRaportStore) globalRaportStore.dispatch({
- type: 'UPDATE',
- totalOdPracownicy: idsPracownicy.length,
- totalDoKontrahenci: idsKontrahenci.length,
- })
- }
- // 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.limit = data.limit;
- 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 = '';
- if ( Pagination.type === 'KONTRAHENCI' ) {
- 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>';
- } else if ( Pagination.type === 'PRACOWNICY' ) {
- 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>';
- }
- 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) {
- if(DBG) console.log('features', features)
- }).catch(function (e) {
- if(DBG) console.warn(e)
- p5UI__notifyAjaxCallback({ type: 'error', msg: e })
- })*/
- }
- function removeFiltersPracownicy(event, btnNode) {
- event.preventDefault()
- var fieldNameList = FIELD_LIST_PRACOWNICY
- fieldNameList.forEach(function (fieldName) {
- btnNode.form[fieldName].value = ''
- })
- urlFetchPracownicy(1)
- }
- function removeFiltersKontrahenci(event, btnNode) {
- event.preventDefault()
- var fieldNameList = FIELD_LIST_KONTRAHENCI
- fieldNameList.forEach(function (fieldName) {
- btnNode.form[fieldName].value = ''
- })
- urlFetchKontrahenci(1)
- }
- function onChangeFiltersPracownicy(event, inputNode) {
- urlFetchPracownicy(1)
- }
- function onKeypressFiltersPracownicy(event, inputNode) {
- if ("Enter" === event.key) {
- event.stopPropagation()
- event.preventDefault()
- urlFetchPracownicy(1)
- return false
- }
- }
- function onChangeFiltersKontrahenci(event, inputNode) {
- urlFetchKontrahenci(1)
- }
- function onKeypressFiltersKontrahenci(event, inputNode) {
- if ("Enter" === event.key) {
- event.stopPropagation()
- event.preventDefault()
- urlFetchKontrahenci(1)
- return false
- }
- }
- function loadMoreRecordFunctions(event, node, rowPK, namespace) {
- var _node = node
- var _rowPK = rowPK
- var toShow = true
- if (RECORD_MORE_FUNCTIONS_OPENED_NODE) {
- if (RECORD_MORE_FUNCTIONS_OPENED_NODE === node) toShow = false
- if (RECORD_MORE_FUNCTIONS_OPENED_NODE !== node) {
- jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
- }
- }
- RECORD_MORE_FUNCTIONS_OPENED_NODE = node
- // jQuery(node).popover({
- // container: 'body',
- // placement: 'right',
- // trigger: 'click',
- // template: '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">' +
- // '<div class="arrow"></div>' +
- // '<div style="display:block;position:relative;">' +
- // '<div class="popover-title">' +
- // '</div>' +
- // '<button type="button" class="close" onclick="return hideMoreRecordFunctionsPopover();" style="position:absolute;right:8px;top:6px;">×</button>' +
- // '</div>' +
- // '<div class="popover-content"></div>' +
- // '</div>' +
- // '',
- // html: true,
- // })
- // jQuery(node).popover('show')
- global.fetch(BASE_URLS + 'index.php?_route=ViewTableAjax&namespace=' + namespace + '&_task=moreFunctionsCellAjax&ID=' + rowPK, {
- credentials: 'same-origin'
- }).then(function (response) {
- return response.json()
- }).then(function (json) {
- var funcListWrap = $('<div></div>')
- var funcListNode = $('<ul class="list-unstyled popoverRowFunctions"></ul>').appendTo(funcListWrap)
- if (_node === RECORD_MORE_FUNCTIONS_OPENED_NODE) {
- if (json && 'success' === json.type && json.rowFunctions && json.rowFunctions.length > 0) {
- json.rowFunctions.forEach(function(funObj) {
- var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, _rowPK, {ico: true, label: true});
- var funcItemNode = jQuery('<li></li>')
- funcItemNode.append(funcNode)
- funcListNode.append(funcItemNode)
- });
- }
- }
- // jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
- jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover({
- container: 'body',
- placement: 'right',
- trigger: 'click',
- template: '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">' +
- '<div class="arrow"></div>' +
- '<div style="display:block;position:relative;">' +
- '<div class="popover-title">' +
- '</div>' +
- '<button type="button" class="close" onclick="return hideMoreRecordFunctionsPopover();" style="position:absolute;right:8px;top:6px;">×</button>' +
- '</div>' +
- '<div class="popover-content"></div>' +
- '</div>' +
- '',
- html: true,
- content: funcListWrap.html(),
- })
- jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('show')
- }).catch(function (err) {
- if(DBG) console.log('err', err);
- })
- }
- var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
- var defaultsProps = {
- ico: true,
- label: false
- },
- props = jQuery.extend({}, defaultsProps, props);
- funcNode = $('<a href="#" style="margin:0 2px;"></a>')
- ;
- if ('href' in funObj) funcNode.attr('href', p5Utils__format(funObj.href, [rowPK]));
- if (props.ico) {
- if ('ico' in funObj) funcNode.append('<span class="' + funObj.ico + '"></span>');
- }
- if ('onclick' in funObj) funcNode.attr('onclick', p5Utils__format(funObj.onclick, [rowPK]));
- if ('title' in funObj) funcNode.attr('title', funObj.title);
- if ('target' in funObj) funcNode.attr('target', funObj.target);
- if (props.label) {
- if ('label' in funObj) {
- funcNode.append(' ' + funObj.label);
- } else if ('title' in funObj) {
- funcNode.append(' ' + funObj.title);
- }
- }
- return funcNode;
- };
- global.p5UI_TableAjax_generateFunctionNode = p5UI_TableAjax_generateFunctionNode
- function addAllMatchesToReport(event) {
- switch (event.data.type) {
- case 'kontrahenci': break; // OK
- case 'pracownicy': break; // OK
- default: throw "Wrong type";
- }
- var postData = {}
- if ('filter_idGroup' in event.data.pagination && event.data.pagination['filter_idGroup']) postData['filter_idGroup'] = event.data.pagination['filter_idGroup']
- Object.keys(event.data.pagination).filter(function (key) {
- return ('f_' === key.substr(0, 2))
- }).forEach(function (filterKey) {
- var value = event.data.pagination[filterKey]
- postData[filterKey] = value
- })
- var thisButton = $(this)
- thisButton.attr('disabled', true)
- thisButton.text( thisButton.text() + '...' )
- if ('pracownicy' === event.data.type) {
- p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie pracowników..." })
- var frm = document.getElementById('filtersFieldRemoveBtn-PRACOWNICY').form
- var fieldNameList = FIELD_LIST_PRACOWNICY
- fieldNameList.filter(function (fieldName) {
- if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"')
- return (frm[fieldName]) ? true : false
- }).map(function (fieldName) {
- return [ fieldName, frm[fieldName].value ]
- }).filter(function (filter) {
- return ( filter[1].length > 0 )
- }).forEach(function (filter) {
- postData[ filter[0] ] = filter[1];
- })
- global.fetch(URL_FETCH_PRACOWNICY_IDS_AJAX, {
- credentials: 'same-origin',
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(postData)
- })
- .then(function __parseJSON(response) {
- return response.json()
- })
- .then(function (json) {
- if ('success' === json.type && json.body && json.body.ids) {
- updateListIdBiAuditReaport('PRACOWNICY', json.body.ids.map(function (id) {
- return parseInt(id)
- }))
- // jQuery('#body-pracownicy').find('input[name="prID[]"]').attr('checked', true)
- jQuery('#body-pracownicy').find('input[name="prID[]"]').each(function (idx, inputNode) {
- inputNode.checked = true;
- })
- thisButton.attr('disabled', false)
- var txt = thisButton.text()
- thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
- updateCountItemCheckedByType('pracownicy');
- p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" pracowników" })
- }
- })
- .catch(function (e) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
- thisButton.attr('disabled', false)
- var txt = thisButton.text()
- thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
- })
- }
- if ('kontrahenci' === event.data.type) {
- p5UI__notifyAjaxCallback({ type: 'info', msg: "Pobieranie podmiotów/kontrahentów..." })
- var frm = document.getElementById('filtersFieldRemoveBtn-KONTRAHENCI').form
- var fieldNameList = FIELD_LIST_KONTRAHENCI
- fieldNameList.filter(function (fieldName) {
- if (!frm[fieldName] && DBG) console.log('Err missing field: "'+fieldName+'"')
- return (frm[fieldName]) ? true : false
- }).map(function (fieldName) {
- return [ fieldName, frm[fieldName].value ]
- }).filter(function (filter) {
- return ( filter[1].length > 0 )
- }).forEach(function (filter) {
- postData[ filter[0] ] = filter[1];
- })
- global.fetch(URL_FETCH_KONTRAHENCI_IDS_AJAX, {
- credentials: 'same-origin',
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(postData)
- })
- .then(function __parseJSON(response) {
- return response.json()
- })
- .then(function (json) {
- if ('success' === json.type && json.body && json.body.ids) {
- updateListIdBiAuditReaport('KONTRAHENCI', json.body.ids.map(function (id) {
- return parseInt(id)
- }))
- // jQuery('#body-kontrahenci').find('input[name="kontrID[]"]').attr('checked', true); // Not working
- jQuery('#body-kontrahenci').find('input[name="kontrID[]"]').each(function (idx, inputNode) {
- inputNode.checked = true;
- })
- thisButton.attr('disabled', false);
- var txt = thisButton.text()
- thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
- updateCountItemCheckedByType('kontrahenci');
- p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+json.body.ids.length+" kontrahentów" })
- }
- })
- .catch(function (e) {
- p5UI__notifyAjaxCallback({ type: 'error', msg: '' + e })
- thisButton.attr('disabled', false)
- var txt = thisButton.text()
- thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
- });
- }
- }
- function mock_error__fetchLastReports(id) {
- return new Promise(function (resolve) {
- throw "Wystąpił błąd, spróbuj ponownie później"
- })
- }
- function mock__fetchLastReports(id) {
- return new Promise(function (resolve) {
- var fakeResponse = '{"type":"success","msg":"ostatnie raporty","body":{"items":[{"id":"103","adnotacje":"raport pani x","totalPracownicy":"1","totalKontrahenci":"2"},{"id":"102","adnotacje":"test","totalPracownicy":"1","totalKontrahenci":"1"},{"id":"101","adnotacje":"Zuranski test all 7","totalPracownicy":"1","totalKontrahenci":"9307"},{"id":"100","adnotacje":"kike all 4","totalPracownicy":"5","totalKontrahenci":"9305"},{"id":"99","adnotacje":"test pracownik z KRS bez celu 3","totalPracownicy":"1","totalKontrahenci":"9305"}]}}';
- var json = JSON.parse(fakeResponse);
- var items = json.body.items;
- console.log('items', items)
- setTimeout(function () {
- console.log('resolve items', items)
- resolve(items);
- }, 500);
- });
- }
- function fetchLastReports(id) {
- return global.fetch(URL_FETCH_LAST_REPORTS_AJAX, {
- credentials: 'same-origin',
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ id: id })
- })
- .then(function __parseJSON(response) {
- return response.json()
- })
- .then(function (json) {
- if ('success' === json.type && json.body && json.body.items) {
- if (!json.body.items.length) throw "Brak danych"
- return json.body.items;
- }
- throw "Wystąpił błąd, spróbuj ponownie później.";
- })
- }
- function fetchPracownicyIdsByReport(id) {
- return global.fetch(URL_FETCH_PRACOWNICY_IDS_BY_REPORT_AJAX, {
- credentials: 'same-origin',
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ id: id })
- })
- .then(function __parseJSON(response) {
- return response.json()
- })
- .then(function (json) {
- if ('success' === json.type && json.body && json.body.ids) {
- if (!json.body.ids.length) throw "Brak danych"
- return json.body.ids;
- }
- throw "Wystąpił błąd, spróbuj ponownie później.";
- })
- }
- function fetchKontrahenciIdsByReport(id) {
- return global.fetch(URL_FETCH_KONTRAHENCI_IDS_BY_REPORT_AJAX, {
- credentials: 'same-origin',
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ id: id })
- })
- .then(function __parseJSON(response) {
- return response.json()
- })
- .then(function (json) {
- if ('success' === json.type && json.body && json.body.ids) {
- if (!json.body.ids.length) throw "Brak danych"
- return json.body.ids;
- }
- throw "Wystąpił błąd, spróbuj ponownie później.";
- })
- }
- function addToReportByPreviousReport(event) {
- var pageType = (event.data.type) ? event.data.type : '';
- handleAddToReportByPreviousReport(pageType);
- }
- function handleAddToReportByPreviousReport(pageType) {
- switch (pageType) {
- case 'pracownicy': break; // OK
- case 'kontrahenci': break; // OK
- default: throw "Wrong type";
- }
- var thisButton = $(this)
- thisButton.attr('disabled', true)
- thisButton.text( thisButton.text() + '...' )
- function this__enableButton() {
- thisButton.attr('disabled', false)
- var txt = thisButton.text()
- thisButton.text( '...' === txt.substr(-3) ? txt.substr(0, txt.length - 3) : txt )
- }
- var lastReportOptions = new Promise(function (resolve) {
- fetchLastReports() // TODO: TEST remote `mock__`
- .then(function (items) {
- var options = {};
- items.forEach(function (item) {
- var label = "Nr " + item.id + ": " + item.adnotacje + " ";
- var total = 0;
- switch (pageType) {
- case 'pracownicy': total = parseInt(item.totalPracownicy); break;
- case 'kontrahenci': total = parseInt(item.totalKontrahenci); break;
- }
- label += ( total > 0 ? "(" + total + ")" : "brak");
- options['raport-'+item.id] = label;
- });
- resolve(options);
- })
- .catch(function (e) {
- swal.showValidationError(''+e)
- swal.hideLoading();
- resolve();
- })
- });
- swal({
- title: "Dodaj " + ('pracownicy' === pageType ? "praconików" : "kontrahentów") + " do analizy",
- showCancelButton: true,
- cancelButtonText: "Anuluj",
- showConfirmButton: true,
- confirmButtonText: "Wybierz",
- focusCancel: true,
- width: 600,
- input: 'select',
- inputOptions: lastReportOptions,
- inputClass: "form-control input-lg",
- preConfirm: function (selected) {
- var id = parseInt(selected.substr('raport-'.length));
- swal.showLoading();
- if ('pracownicy' === pageType) {
- return new Promise(function (resolve) {
- fetchPracownicyIdsByReport(id)
- .then(function (ids) {
- updateListIdBiAuditReaport('PRACOWNICY', ids.map(function (id) {
- return parseInt(id)
- }))
- ids.forEach(function (id) {
- jQuery('#body-pracownicy').find('input[name="prID[]"][value="'+id+'"]').each(function (idx, inputNode) {
- inputNode.checked = true;
- })
- })
- updateCountItemCheckedByType('pracownicy');
- p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+ids.length+" pracowników" })
- resolve();
- })
- .catch(function (e) {
- swal.showValidationError(''+e)
- swal.hideLoading();
- resolve();
- });
- });
- } else if ('kontrahenci' === pageType) {
- return new Promise(function (resolve) {
- fetchKontrahenciIdsByReport(id)
- .then(function (ids) {
- updateListIdBiAuditReaport('KONTRAHENCI', ids.map(function (id) {
- return parseInt(id)
- }))
- ids.forEach(function (id) {
- jQuery('#body-kontrahenci').find('input[name="kontrID[]"][value="'+id+'"]').each(function (idx, inputNode) {
- inputNode.checked = true;
- })
- })
- updateCountItemCheckedByType('kontrahenci');
- p5UI__notifyAjaxCallback({ type: 'success', msg: "Dodano "+ids.length+" kontrahentów" })
- resolve();
- })
- .catch(function (e) {
- swal.showValidationError(''+e)
- swal.hideLoading();
- resolve();
- });
- });
- } else return true;
- },
- // inputValidator: (value) => {
- // return !value && 'Proszę wybrać raport'
- // }
- // html: '<p>Ostatnie raporty:</p>' + '<ul id="' + uniqHtmlId + '"></ul></p>',
- }).then(function (selected) {
- this__enableButton();
- }).catch(function (e) {
- this__enableButton();
- })
- }
- $(document).ready(function(){
- DBG && console.warn('DBG:: SET window[STORE_NAME]', { store: window[STORE_NAME], STORE_NAME: STORE_NAME, globalRaportStore })
- ReactDOM.render(
- h(P5UI__BocianHeader, {
- store: globalRaportStore
- }),
- document.getElementById('bi_audit_header')
- );
- rootChangeForm();
- updateTopCounters();
- var unsubscribe = globalRaportStore.subscribe(function () {
- // TODO: fetch data from globalRaportStore.getState()
- // var defaultState = global[STORE_NAME + '__defaults']();
- })
- $(window).on('hashchange', function() {
- DBG && console.warn("$(window).on('hashchange', ...")
- rootChangeForm();
- updateTopCounters();
- hideMoreRecordFunctionsPopover()
- });
- });
- global.hideMoreRecordFunctionsPopover = function() {
- if (RECORD_MORE_FUNCTIONS_OPENED_NODE) jQuery(RECORD_MORE_FUNCTIONS_OPENED_NODE).popover('destroy')
- }
- global.pracownicyLoadMoreRecordFunctions = function(event, node, rowPK) {
- return loadMoreRecordFunctions(event, node, rowPK, "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY")
- }
- global.kontrahenciLoadMoreRecordFunctions = function(event, node, rowPK) {
- return loadMoreRecordFunctions(event, node, rowPK, "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI")
- }
- global.removeFiltersPracownicy = removeFiltersPracownicy;
- global.removeFiltersKontrahenci = removeFiltersKontrahenci;
- global.onChangeFiltersPracownicy = onChangeFiltersPracownicy;
- global.onKeypressFiltersPracownicy = onKeypressFiltersPracownicy;
- global.onChangeFiltersKontrahenci = onChangeFiltersKontrahenci;
- global.onKeypressFiltersKontrahenci = onKeypressFiltersKontrahenci;
- global.checkAll = checkAll;
- global.checkedChoiseItems = checkedChoiseItems;
- global.catchEventCheckbox = catchEventCheckbox;
- global.clearSelectedCheckbox = clearSelectedCheckbox;
- global.getNameGroupById = getNameGroupById;
- global.createGroupPracownicy = createGroupPracownicy;
- global.createGroupKontrahenci = createGroupKontrahenci;
- global.selectPage = selectPage;
- global.detectChoiseFilter = detectChoiseFilter;
- global.updateListIdBiAuditReaport = updateListIdBiAuditReaport;
- global.deleteListIdBiAuditReaport = deleteListIdBiAuditReaport;
- global.urlFetchPracownicy = urlFetchPracownicy;
- global.urlFetchKontrahenci = urlFetchKontrahenci;
- global.getAddressData = getAddressData;
- global.Pagination = Pagination;
- global.todo__fetchRaport = todo__fetchRaport;
- global.setItemLocalStorage = setItemLocalStorage;
- global.getItemLocalStorage = getItemLocalStorage;
- global.deleteItemLocalStorage = deleteItemLocalStorage;
- global.removeItemInArray = removeItemInArray;
- global.removeItemArrayInArray = removeItemArrayInArray;
- global.addPracownikToGroup = addPracownikToGroup;
- global.addPracownikAllToGroup = addPracownikAllToGroup;
- global.addKontrahenciToGroup = addKontrahenciToGroup;
- global.addKontrahenciAllToGroup = addKontrahenciAllToGroup;
- global.createPracownikAjax = createPracownikAjax;
- global.createKontrahentAjax = createKontrahentAjax;
- global.removePracownikFromGroup = removePracownikFromGroup;
- global.removeKontrahenciFromGroup = removeKontrahenciFromGroup;
- global.showViewUploadFile = showViewUploadFile;
- global.parseCsvFile = parseCsvFile;
- global.clearListLocalStorageByType = clearListLocalStorageByType;
- // message
- global.messageCriticalSearchData = 'Krytyczne wielkości danych do przeszukania. Optymalna wartość głębokość szukania powiaząń to: 6';
|