123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754 |
- var createReactClass = window.p5VendorJs.createReactClass;
- var h = window.p5VendorJs.React.createElement;
- var ReactDOM = window.p5VendorJs.ReactDOM;
- var AsyncTypeahead = window.p5VendorJs.AsyncTypeahead;
- var swal = window.swal;
- var STORE_NAME = STORE_NAME || '_bocianRaportStore';
- var DBG = DBG || false;
- var DBG1 = true;
- function bocianFeatureKey(ns, pk) {
- switch (ns) {
- case 'default_db/BI_audit_KRS/BI_audit_KRS': return 'KRS.' + pk;
- case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return 'KRS/p.' + pk;
- case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return 'MSIG.' + pk;
- case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return 'MSIG/p.' + pk;
- case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return 'CEIDG.' + pk;
- default: throw "Not implemented feature key for ns '" + ns + "'";
- }
- }
- 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 getSelectedListFromLocalStorage(from) {
- return JSON.parse( localStorage.getItem(getSelectedListLocalStorageKey(from)) || '[]' );
- }
- 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 );
- })
- ))
- }
- function convertXlinkToObjects(items) {
- var _childCache = {}; // fieldName => { pk => child }
- items.forEach(function (item) {
- var refFields = Object.keys(item).filter(function (fieldName) {
- return (-1 !== fieldName.indexOf(':') && item[fieldName]);
- });
- refFields.forEach(function (fieldName) {
- item[fieldName].forEach(function (child) {
- if (1 === Object.keys(child).length && 'xlink' in child) {
- // xlink
- } else if (Object.keys(child).length > 1) {
- if ('@primaryKey' in child) {
- if (!(fieldName in _childCache)) _childCache[fieldName] = {};
- _childCache[fieldName][ child['@primaryKey'] ] = child;
- }
- }
- })
- })
- return item;
- });
- DBG && console.log('DBG convertXlinkToObjects', { _childCache, items });
- return items.map(function (item) {
- var refFields = Object.keys(item).filter(function (fieldName) {
- return (-1 !== fieldName.indexOf(':') && item[fieldName]);
- });
- refFields.forEach(function (fieldName) {
- item[fieldName] = item[fieldName].map(function (child) {
- if (1 === Object.keys(child).length && 'xlink' in child) {
- var pk = child['xlink'].split('.').pop();
- return _childCache[fieldName][pk];
- }
- return child;
- })
- })
- return item;
- })
- }
- function filterByHelper(option, text) {
- var label = option.label.toLowerCase();
- var words = ( (text.indexOf(' ') > 0)
- ? text.split(' ')
- : [ text ]
- ).map(function (word) { return word.trim().replace(/^[0]+/g, '').toLowerCase(); })
- .filter(function (word) { return word.length > 2; });
- var foundWords = words.filter(function (word) {
- return (label.indexOf(word) > -1);
- })
- return (foundWords.length === words.length);
- }
- // function (option, text) {
- // if (option.ID == 161323) return false;
- // console.log('TODO: filterBy...', {option, text});
- // return true;
- // },
- var P5UI_AddItemToReport_SelectKrsPerson = createReactClass({
- // h(SelectKrsPerson, { krs: this.state.selected })
- // this.props.krs: {
- // "@primaryKey": "161323",
- // "A_kod": "80-299",
- // "A_kraj": "POLSKA",
- // "A_miejscowosc": "GDAŃSK",
- // "A_nrDomu": "54C",
- // "A_nrLokalu": null,
- // "A_poczta": "GDAŃSK",
- // "A_ulica": "BARNIEWICKA",
- // "ID": "161323",
- // "S_kraj": "POLSKA",
- // "S_miejscowosc": "GDAŃSK",
- // "S_wojewodztwo": "POMORSKIE",
- // "krs": "0000223476",
- // "nazwa": "BIALL Sp. z o.o.",
- // "nip": "6040018535",
- // "regon": "193106935",
- // "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person": [
- // {
- // "@primaryKey": "747004",
- // "ID": "747004",
- // "imiona": "ADRIAN RYSZARD",
- // "nazwisko": "WIECZORKOWSKI",
- // "pesel": "75040301615"
- // },
- // {
- // "@primaryKey": "747003",
- // "ID": "747003",
- // "imiona": "EWA",
- // "nazwisko": "WIECZORKOWSKA",
- // "pesel": "75090401549"
- // },
- render: function () {
- var krsPresons = (this.props.krs && this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
- ? this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
- : [];
- // var _selectPerson = this.props.selectPerson.bind(this)
- var selectedBaza = 'default_db/BI_audit_KRS_person/BI_audit_KRS_person';
- return (krsPresons.length > 0)
- ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, krsPresons.map(function (person) {
- var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || '');
- return h('li', {}, [
- h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: person }),
- h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: person }),
- h('span', { style: { 'margin-left': "6px" } }, label),
- // h('button', {
- // className: "btn btn-primary",
- // style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
- // onClick: function () { _selectPerson(person) }
- // }, "Dodaj osobę")
- ]);
- }))
- : null;
- }
- });
- var P5UI_AddItemToReport_SelectMSIGPerson = createReactClass({
- render: function () { // BI_audit_MSIG_person
- var msigPresons = (this.props.msig && this.props.msig['default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person'])
- ? this.props.msig['default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person']
- : [];
- var _selectPerson = this.props.selectPerson.bind(this)
- var selectedBaza = 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person';
- return (msigPresons.length > 0)
- ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, msigPresons.map(function (person) {
- var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || '');
- return h('li', {}, [
- h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: person }),
- h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: person }),
- h('span', { style: { 'margin-left': "6px" } }, label),
- // h('button', {
- // className: "btn btn-primary",
- // style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
- // onClick: function () { _selectPerson(person) }
- // }, "Dodaj osobę")
- ]);
- }))
- : null;
- }
- });
- var P5UI_AddItemToReport_BazaMenuItem = createReactClass({
- // this.props: { key: option.ID, baza: selectedBaza, data: option }
- render: function () {
- return h('div', {}, this.props.data.label);
- }
- });
- var P5UI_AddItemToReport_Checkbox = createReactClass({
- _getStore: function () {
- DBG && console.warn('DBG:: window[STORE_NAME]', { store: window[STORE_NAME], STORE_NAME: STORE_NAME})
- return window[STORE_NAME] || null;
- },
- getStateFromStore: function () {
- var featureKey = bocianFeatureKey(this.props.selectedBaza, this.props.selectedItem['@primaryKey']);
- var storeState = this._getStore().getState();
- return {
- featureKey: featureKey,
- isSelected: (-1 !== this.getStoreList(this.props.from).indexOf(featureKey)),
- // totalOdPracownicy: storeState.totalOdPracownicy,
- // totalOdPozostale: storeState.totalOdPozostale,
- // totalDoKontrahenci: storeState.totalDoKontrahenci,
- // totalDoPozostale: storeState.totalDoPozostale,
- };
- },
- getStoreList: function (from) {
- var storeState = this._getStore().getState();
- switch (from) {
- case 'OD': return storeState.pozostaleOd;
- case 'DO': return storeState.pozostaleDo;
- default: throw "Not imeplemented store list from = '" + from + "'";
- }
- },
- getInitialState: function () {
- return this.getStateFromStore();
- },
- componentDidMount: function () {
- var store = this._getStore()
- this._unsubscribe = store ? store.subscribe(this.storeUpdated) : function () {};
- },
- componentWillUnmount: function () {
- this._unsubscribe();
- },
- storeUpdated: function () {
- DBG && console.log('DBG::P5UI__BocianHeader::storeUpdated ', this.getStateFromStore());
- this.setState(this.getStateFromStore())
- },
- _handleClick: function () {
- this.state.isSelected ? this.removeItem() : this.saveItem();
- // _onSelect(from, selectedBaza, selectedItem);
- },
- removeItem: function () {
- this._getStore().dispatch({ type: 'RM_' + this.props.from, featureKey: this.state.featureKey })
- // removeFromSelectedListInLocalStorage(this.props.from, this.state.featureKey);
- // this.setState({ isSelected: false });
- },
- saveItem: function () {
- this._getStore().dispatch({ type: 'ADD_' + this.props.from, featureKey: this.state.featureKey })
- // saveToSelectedListInLocalStorage(this.props.from, this.state.featureKey);
- // this.setState({ isSelected: true });
- },
- render: function () {
- var handleClick = this._handleClick.bind(this);
- // var _onSelect = this.props.onSelect;
- var isSelected = this.state.isSelected;
- return h('div', { className: "checkbox", style: { display: "inline-block", 'margin-left': "6px" } }, [
- h('label', { style: { border: "1px solid " + ( isSelected ? "red" : "#ccc" ), 'border-radius': "4px", padding: "2px 6px 0 6px", 'font-size': "12px" } }, [
- h('input', {
- style: { margin: "0 6px 0 0", position: "relative" },
- type: "checkbox",
- checked: isSelected,
- onClick: handleClick,
- }),
- h('span', { style: { 'line-height': "20px" } }, this.props.from),
- ])
- ]);
- }
- });
- var P5UI_AddItemToReport = createReactClass({
- getInitialState: function () {
- // var listOd = getSelectedListFromLocalStorage('OD');
- // var listDo = getSelectedListFromLocalStorage('DO');
- return {
- baza: null,
- newItemBaza: null,
- isSearching: false,
- selected: null,
- };
- },
- _handleSelectBaza: function (baza) {
- this.setState({ baza: baza, newItemBaza: null, selected: null, isSearching: false });
- },
- _handleSelectNewItem: function (baza) {
- this.setState({ baza: null, newItemBaza: baza, selected: null, isSearching: false });
- },
- _handleSelected: function (selected) {
- this.setState({ selected: (selected.length > 0) ? selected[0] : null });
- },
- _handleSearch: function (query) {
- this.setState({ isSearching: true });
- var _setState = this.setState.bind(this);
- var baza = this.state.baza;
- var options= [];
- window.fetch(URL_FETCH_FROM_BAZA, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- baza: baza,
- query: query,
- })
- })
- .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);
- if (result.body && result.body.items && result.body.items.length > 0) {
- return result.body.items;
- } else {
- p5UI__notifyAjaxCallback({ type: 'warning', msg: "Brak danych pasujących do kryteriów wyszukiwania" });
- _setState({ isSearching: false, options: [] });
- }
- }
- })
- .then(function(items) {
- DBG && console.log('items fetched:', items);
- _setState({ isSearching: false, options: convertXlinkToObjects(items) });
- })
- .catch(function(error) {
- DBG && console.log('request failed', error);
- })
- },
- componentWillUnmount: function () {
- DBG && console.log("DBG: conponentDidUnmount...");
- },
- renderItemSave__OLD(selectedBaza, selectedItem) {
- var _onSelect = this.props.onSelect;
- return h('div', { style: { margin: '22px' } }, [
- h('button', {
- className: "btn btn-primary",
- onClick: function () {
- _onSelect(selectedBaza, selectedItem);
- // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
- // swal.close()
- }
- }, "XXX Dodaj " + (
- ( ('default_db/BI_audit_KRS_person/BI_audit_KRS_person' === selectedBaza)
- || ('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person' === selectedBaza)
- )
- ? "osobę"
- : "firmę"
- )) // TODO: |> KRS -> firmę, |> KRS Person -> osobę, ....
- ]);
- },
- renderItemSave(selectedBaza, selectedItem) {
- return h('div', { style: { margin: '22px', 'font-size': "16px" } }, [
- "Dodaj jako: ",
- h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: selectedItem }),
- h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: selectedItem }),
- ]);
- },
- render: function () {
- var bazaBtns = [];
- bazaBtns.push({ baza: "default_db/BI_audit_KRS/BI_audit_KRS", title: "KRS - Firmy", label: "KRS" });
- bazaBtns.push({ baza: "default_db/BI_audit_KRS_person/BI_audit_KRS_person", title: "KRS - Osoby", label: "KRS/p" });
- bazaBtns.push({ baza: "default_db/BI_audit_MSIG/BI_audit_MSIG", title: "MSIG - Firmy", label: "MSIG" });
- bazaBtns.push({ baza: "default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", title: "MSIG - Osoby", label: "MSIG/p" });
- //bazaBtns.push({ baza: "default_db/BI_audit_taxpayer/BI_audit_taxpayer", title: "VAT - Aktywni płatnicy", label: "VATp" });
- bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" });
- var newItemBtns = [];
- // newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY", title: "Nowa osoba", label: "Nowa osoba" });
- // newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "Nowy podmiot", label: "Nowy podmiot" });
- function generateBazaBtn(btn, opts) {
- return h('button', {
- title: btn.title,
- className: "btn btn-success" + (opts.selected ? " active" : ""),
- style: { margin: "3px" },
- onClick: function () {
- opts.onClick(btn.baza)
- },
- }, btn.label)
- }
- function generateNewItemBtn(btn, opts) {
- return h('button', {
- title: btn.title,
- className: "btn btn-success" + (opts.selected ? " active" : ""),
- style: { margin: "3px" },
- onClick: function () {
- opts.onClick(btn.baza)
- },
- }, btn.label)
- }
- var handleSelectBaza = this._handleSelectBaza.bind(this);
- var handleSelectNewItem = this._handleSelectNewItem.bind(this);
- var selectedBaza = this.state.baza;
- var selectedNewItemBaza = this.state.newItemBaza;
- var selectedItem = this.state.selected;
- var selectedLabel = '';
- if (selectedBaza) {
- var selBazaBtn = bazaBtns.filter(function (btn) { return btn.baza === selectedBaza; })
- if (selBazaBtn) {
- selBazaBtn[0].title
- }
- }
- var handleSearch = this._handleSearch.bind(this);
- var handleSelected = this._handleSelected.bind(this);
- var _onSelect = this.props.onSelect;
- DBG && console.log('DBG: render this.state.options', this.state.options);
- return h('div', {}, [
- h('p', { style: { textAlign: "center" } }, "Wybierz bazę"),
- h('div', { style: { marginBottom: '22px' } },
- bazaBtns.map(function (btn) {
- return generateBazaBtn(btn, {
- onClick: handleSelectBaza,
- selected: (selectedBaza === btn.baza),
- });
- }).concat(
- newItemBtns.map(function (btn) {
- return generateNewItemBtn(btn, {
- onClick: handleSelectNewItem,
- selected: (selectedNewItemBaza === btn.baza),
- });
- })
- )
- ),
- ('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza) && h(AsyncTypeahead, {
- isLoading: this.state.isSearching,
- allowNew: false,
- multiple: false,
- options: this.state.options,
- labelKey: "label",
- emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
- searchText: "Wyszukiwanie...",
- // labelKey: function (option) {
- // return [
- // option.nazwa.replace('"', ''),
- // option.nip,
- // option.krs,
- // option.regon,
- // option.S_miejscowosc,
- // ].join(' ')
- // },
- minLength: 3,
- onSearch: handleSearch,
- placeholder: "Wyszukaj...",
- onChange: handleSelected,
- autoFocus: true,
- filterBy: filterByHelper,
- renderMenuItemChildren: function (option, props) {
- return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
- }
- }),
- ('default_db/BI_audit_KRS_person/BI_audit_KRS_person' === selectedBaza) && h(AsyncTypeahead, {
- isLoading: this.state.isSearching,
- allowNew: false,
- multiple: false,
- options: this.state.options,
- labelKey: "label",
- emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
- searchText: "Wyszukiwanie...",
- // labelKey: function (option) {
- // return [
- // option.nazwa.replace('"', ''),
- // option.nip,
- // option.krs,
- // option.regon,
- // option.S_miejscowosc,
- // ].join(' ')
- // },
- minLength: 3,
- onSearch: handleSearch,
- placeholder: "Wyszukaj...",
- onChange: handleSelected,
- autoFocus: true,
- filterBy: filterByHelper,
- renderMenuItemChildren: function (option, props) {
- return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
- }
- }),
- ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza) && h(AsyncTypeahead, {
- isLoading: this.state.isSearching,
- allowNew: false,
- multiple: false,
- options: this.state.options,
- labelKey: "label",
- emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
- searchText: "Wyszukiwanie...",
- // labelKey: function (option) {
- // return [
- // option.nazwa.replace('"', ''),
- // option.nip,
- // option.krs,
- // option.regon,
- // option.S_miejscowosc,
- // ].join(' ')
- // },
- minLength: 3,
- onSearch: handleSearch,
- placeholder: "Wyszukaj...",
- onChange: handleSelected,
- autoFocus: true,
- filterBy: filterByHelper,
- renderMenuItemChildren: function (option, props) {
- return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
- }
- }),
- ('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person' === selectedBaza) && h(AsyncTypeahead, {
- isLoading: this.state.isSearching,
- allowNew: false,
- multiple: false,
- options: this.state.options,
- labelKey: "label",
- emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
- searchText: "Wyszukiwanie...",
- // labelKey: function (option) {
- // return [
- // option.nazwa.replace('"', ''),
- // option.nip,
- // option.krs,
- // option.regon,
- // option.S_miejscowosc,
- // ].join(' ')
- // },
- minLength: 3,
- onSearch: handleSearch,
- placeholder: "Wyszukaj...",
- onChange: handleSelected,
- autoFocus: true,
- filterBy: filterByHelper,
- renderMenuItemChildren: function (option, props) {
- return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
- }
- }),
- ('default_db/BI_audit_CEIDG/BI_audit_CEIDG' === selectedBaza) && h(AsyncTypeahead, {
- isLoading: this.state.isSearching,
- allowNew: false,
- multiple: false,
- options: this.state.options,
- labelKey: "label",
- emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
- searchText: "Wyszukiwanie...",
- // labelKey: function (option) {
- // return [
- // option.nazwa.replace('"', ''),
- // option.nip,
- // option.krs,
- // option.regon,
- // option.S_miejscowosc,
- // ].join(' ')
- // },
- minLength: 3,
- onSearch: handleSearch,
- placeholder: "Wyszukaj...",
- onChange: handleSelected,
- autoFocus: true,
- filterBy: filterByHelper,
- renderMenuItemChildren: function (option, props) {
- return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
- }
- }),
- ("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY" === selectedNewItemBaza) && h('div', { className: 'form-group' }, [
- h('input',{
- className:'form-control required',
- id:'personName',
- placeholder:'Imię'
- }),
- h('input',{
- className:'form-control required',
- id:'personSurname',
- placeholder:'Nazwisko'
- }),
- h('input',{
- className:'form-control required',
- id:'personPesel',
- placeholder:'Pesel'
- }),
- h('input',{
- className:'form-control',
- id:'personNip',
- placeholder:'NIP'
- }),
- h('button', { className: "btn btn-primary", onClick: function () {
- _onSelect(selectedNewItemBaza, {
- personName: document.getElementById('personName').value,
- personSurname: document.getElementById('personSurname').value,
- personPesel: document.getElementById('personPesel').value,
- personNip: document.getElementById('personNip').value,
- })
- swal.close();
- }.bind(this) }, "Dodaj osobę")
- ]),
- ("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI" === selectedNewItemBaza) && h('div', { className: 'form-group' }, [
- h('input',{
- className:'form-control required',
- id:'companyName',
- placeholder:'Nazwa'
- }),
- h('input',{
- className:'form-control required',
- id:'companyPesel',
- placeholder:'Pesel'
- }),
- h('input',{
- className:'form-control required',
- id:'companyStreet',
- placeholder:'Ulica'
- }),
- h('input',{
- className:'form-control required',
- id:'companyNumber',
- placeholder:'Numer budynku'
- }),
- h('input',{
- className:'form-control required',
- id:'companyNumberLocal',
- placeholder:'Numer lokalu'
- }),
- h('input',{
- className:'form-control required',
- id:'companyPostCode',
- placeholder:'Kod pocztowy'
- }),
- h('input',{
- className:'form-control required',
- id:'companyCity',
- placeholder:'Miejscowosc'
- }),
- h('input',{
- className:'form-control required',
- id:'companyNip',
- placeholder:'NIP'
- }),
- h('input',{
- className:'form-control',
- id:'companyRegon',
- placeholder:'REGON'
- }),
- h('input',{
- className:'form-control',
- id:'companyKrs',
- placeholder:'KRS'
- }),
- h('button', { className: "btn btn-primary", onClick: function () {
- _onSelect(selectedNewItemBaza, {
- companyName: document.getElementById('companyName').value,
- companyNip: document.getElementById('companyNip').value,
- companyRegon: document.getElementById('companyRegon').value,
- companyPesel: document.getElementById('companyPesel').value,
- companyStreet: document.getElementById('companyStreet').value,
- companyNumber: document.getElementById('companyNumber').value,
- companyNumberLocal: document.getElementById('companyNumberLocal').value,
- companyPostCode: document.getElementById('companyPostCode').value,
- companyCity: document.getElementById('companyCity').value,
- companyKrs: document.getElementById('companyKrs').value,
- })
- swal.close();
- }.bind(this) }, "Dodaj podmiot")
- ]),
- (selectedBaza && selectedItem) && this.renderItemSave(selectedBaza, selectedItem),
- ('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectKrsPerson, {
- krs: selectedItem,
- selectPerson: function (person) {
- _onSelect("default_db/BI_audit_KRS_person/BI_audit_KRS_person", person);
- // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
- // swal.close()
- }
- }),
- ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectMSIGPerson, {
- msig: selectedItem,
- selectPerson: function (person) {
- _onSelect("default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", person);
- // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
- // swal.close()
- }
- }),
- (DBG && selectedItem) && h('pre', { style: { textAlign: 'left' } }, JSON.stringify(selectedItem, null, 2)),
- ])
- }
- });
- function getWindowWidth() {
- var w = window, d = document,
- e = d.documentElement,
- g = d.getElementsByTagName('body')[0];
- return w.innerWidth || e.clientWidth || g.clientWidth;
- }
- function addItemToRaport(event) {
- // default_db/BI_audit_KRS/BI_audit_KRS
- // default_db/BI_audit_KRS_person/BI_audit_KRS_person
- // default_db/BI_audit_MSIG/BI_audit_MSIG
- // default_db/BI_audit_MSIG_person/BI_audit_MSIG_person
- // default_db/BI_audit_taxpayer/BI_audit_taxpayer
- // default_db/BI_audit_CEIDG/BI_audit_CEIDG
- // default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY
- // default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI
- // default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY
- var valueUrl = global.location.hash;
- swal({
- title: "Dodaj osobę lub podmiot",
- width: (getWindowWidth() * 0.8),
- html: '<div id="' + FUNCTION_NAME + '__searchBaza" style="padding:0 24px 24px 24px; min-height:400px"></div>',
- animation: false,
- showConfirmButton: false,
- showCancelButton: false,
- showCloseButton: true,
- allowEnterKey: false,
- onOpen: function () {
- ReactDOM.render(
- h(P5UI_AddItemToReport, {
- onSelect: function (from, baza, selected) {
- DBG && console.log('TODO: selected ', { from, baza, selected });
- global.fetch(URL_SAVE_TO_DB, {
- method: 'POST',
- credentials: 'same-origin',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({
- from: from,
- baza: baza,
- item: selected
- })
- }).then(function(response) {
- return response.json();
- }).then(function(result) {
- if(result.type === "success"){
- if(valueUrl === '#PRACOWNICY'){
- urlFetchPracownicy(1);
- }else{
- urlFetchKontrahenci(1);
- }
- }
- p5UI__notifyAjaxCallback(result);
- })
- }
- }),
- document.getElementById(FUNCTION_NAME + '__searchBaza')
- )
- }
- }).catch(function (err) {
- DBG && console.log('err', err)
- })
- }
- // global[FUNCTION_NAME] = addItemToRaport;
- module.exports[FUNCTION_NAME] = addItemToRaport;
- // module.exports = {
- // P5UI_AddItemToReport_BazaMenuItem,
- // P5UI_AddItemToReport,
- // createPracownikAjax
- // }
|