Bocian.php.addItemToRaport.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. var createReactClass = window.p5VendorJs.createReactClass;
  2. var h = window.p5VendorJs.React.createElement;
  3. var ReactDOM = window.p5VendorJs.ReactDOM;
  4. var AsyncTypeahead = window.p5VendorJs.AsyncTypeahead;
  5. var swal = window.swal;
  6. var STORE_NAME = STORE_NAME || '_bocianRaportStore';
  7. var DBG = DBG || false;
  8. var DBG1 = true;
  9. function bocianFeatureKey(ns, pk) {
  10. switch (ns) {
  11. case 'default_db/BI_audit_KRS/BI_audit_KRS': return 'KRS.' + pk;
  12. case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return 'KRS/p.' + pk;
  13. case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return 'MSIG.' + pk;
  14. case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return 'MSIG/p.' + pk;
  15. case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return 'CEIDG.' + pk;
  16. default: throw "Not implemented feature key for ns '" + ns + "'";
  17. }
  18. }
  19. function getSelectedListLocalStorageKey(from) { // from: ( OD | DO )
  20. switch (from) {
  21. case 'OD': return 'Bocian.biAuditForm.odFeatureKeys';
  22. case 'DO': return 'Bocian.biAuditForm.doFeatureKeys';
  23. default: throw "Not implemented from selected list '" + from + "' - expected 'OD' or 'DO'";
  24. }
  25. }
  26. function getSelectedListFromLocalStorage(from) {
  27. return JSON.parse( localStorage.getItem(getSelectedListLocalStorageKey(from)) || '[]' );
  28. }
  29. function saveToSelectedListInLocalStorage(from, featureKey) {
  30. DBG && console.log("DBG::saveToSelectedListInLocalStorage(from, featureKey)", {from, featureKey}, {added: getSelectedListFromLocalStorage(from).concat(featureKey)});
  31. localStorage.setItem(getSelectedListLocalStorageKey(from), JSON.stringify(
  32. getSelectedListFromLocalStorage(from).concat(featureKey)
  33. ))
  34. }
  35. function removeFromSelectedListInLocalStorage(from, featureKey) {
  36. DBG && console.log("DBG::removeFromSelectedListInLocalStorage(from, featureKey)", {from, featureKey});
  37. localStorage.setItem(getSelectedListLocalStorageKey(from), JSON.stringify(
  38. getSelectedListFromLocalStorage(from).filter(function (item) {
  39. return ( item !== featureKey );
  40. })
  41. ))
  42. }
  43. function convertXlinkToObjects(items) {
  44. var _childCache = {}; // fieldName => { pk => child }
  45. items.forEach(function (item) {
  46. var refFields = Object.keys(item).filter(function (fieldName) {
  47. return (-1 !== fieldName.indexOf(':') && item[fieldName]);
  48. });
  49. refFields.forEach(function (fieldName) {
  50. item[fieldName].forEach(function (child) {
  51. if (1 === Object.keys(child).length && 'xlink' in child) {
  52. // xlink
  53. } else if (Object.keys(child).length > 1) {
  54. if ('@primaryKey' in child) {
  55. if (!(fieldName in _childCache)) _childCache[fieldName] = {};
  56. _childCache[fieldName][ child['@primaryKey'] ] = child;
  57. }
  58. }
  59. })
  60. })
  61. return item;
  62. });
  63. DBG && console.log('DBG convertXlinkToObjects', { _childCache, items });
  64. return items.map(function (item) {
  65. var refFields = Object.keys(item).filter(function (fieldName) {
  66. return (-1 !== fieldName.indexOf(':') && item[fieldName]);
  67. });
  68. refFields.forEach(function (fieldName) {
  69. item[fieldName] = item[fieldName].map(function (child) {
  70. if (1 === Object.keys(child).length && 'xlink' in child) {
  71. var pk = child['xlink'].split('.').pop();
  72. return _childCache[fieldName][pk];
  73. } else if ('p5:links' in child && 'p5:next' in child['p5:links']) {
  74. return Object.assign({}, child['p5:links']['p5:next'], {
  75. type: 'p5:next'
  76. });
  77. // child.value = "https://.../SE/wfs-data.php/?SERVICE=WFS&VERSION=1.0.0&TYPENAME=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&REQUEST=GetFeature&backRefNS=default_db/BI_audit_KRS/BI_audit_KRS&backRefPK=1332604&backRefField=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&maxFeatures=10&startIndex=10"
  78. }
  79. return child;
  80. })
  81. })
  82. return item;
  83. })
  84. }
  85. function filterByHelper(option, node) {
  86. var text = (node && node.text) ? node.text : '';
  87. var label = option.label.toLowerCase();
  88. var words = ( (text.indexOf(' ') > 0)
  89. ? text.split(' ')
  90. : [ text ]
  91. ).map(function (word) { return word.trim().replace(/^[0]+/g, '').toLowerCase(); })
  92. .filter(function (word) { return word.length > 2; });
  93. var foundWords = words.filter(function (word) {
  94. return (label.indexOf(word) > -1);
  95. })
  96. return (foundWords.length === words.length);
  97. }
  98. // function (option, text) {
  99. // if (option.ID == 161323) return false;
  100. // console.log('TODO: filterBy...', {option, text});
  101. // return true;
  102. // },
  103. var P5UI_AddItemToReport_SelectKrsPerson = createReactClass({
  104. // h(SelectKrsPerson, { krs: this.state.selected })
  105. // this.props.krs: {
  106. // "@primaryKey": "161323",
  107. // "A_kod": "80-299",
  108. // "A_kraj": "POLSKA",
  109. // "A_miejscowosc": "GDAŃSK",
  110. // "A_nrDomu": "54C",
  111. // "A_nrLokalu": null,
  112. // "A_poczta": "GDAŃSK",
  113. // "A_ulica": "BARNIEWICKA",
  114. // "ID": "161323",
  115. // "S_kraj": "POLSKA",
  116. // "S_miejscowosc": "GDAŃSK",
  117. // "S_wojewodztwo": "POMORSKIE",
  118. // "krs": "0000223476",
  119. // "nazwa": "BIALL Sp. z o.o.",
  120. // "nip": "6040018535",
  121. // "regon": "193106935",
  122. // "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person": [
  123. // {
  124. // "@primaryKey": "747004",
  125. // "ID": "747004",
  126. // "imiona": "ADRIAN RYSZARD",
  127. // "nazwisko": "WIECZORKOWSKI",
  128. // "pesel": "75040301615"
  129. // },
  130. // {
  131. // "@primaryKey": "747003",
  132. // "ID": "747003",
  133. // "imiona": "EWA",
  134. // "nazwisko": "WIECZORKOWSKA",
  135. // "pesel": "75090401549"
  136. // },
  137. // ...
  138. // {
  139. // "@backRefNS: "default_db/BI_audit_KRS/BI_audit_KRS"
  140. // @backRefPK: "1332604"
  141. // @maxFeatures: 10
  142. // @startIndex: 10
  143. // @typeName: "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person"
  144. // type: "p5:next"
  145. // value: "https://biuro.biall-net.pl/dev-pl/se-projects/bocian/SE/wfs-data.php/?SERVICE=WFS&VERSION=1.0.0&TYPENAME=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&REQUEST=GetFeature&backRefNS=default_db/BI_audit_KRS/BI_audit_KRS&backRefPK=1332604&backRefField=default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person&maxFeatures=10&startIndex=10"
  146. // }
  147. getKrsPersonsFromProps: function () {
  148. return (this.props.krs && this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
  149. ? this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
  150. : [];
  151. },
  152. handleFetchMore: function () {
  153. this.props.fetchMoreKrsPerson(this.props.krs);
  154. },
  155. render: function () {
  156. var krsPresons = this.getKrsPersonsFromProps();
  157. // var _selectPerson = this.props.selectPerson.bind(this)
  158. var selectedBaza = 'default_db/BI_audit_KRS_person/BI_audit_KRS_person';
  159. var handleFetchMore = this.handleFetchMore.bind(this);
  160. return (krsPresons.length > 0)
  161. ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, krsPresons.map(function (person) {
  162. var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || '');
  163. if ('type' in person && "p5:next" == person['type']) {
  164. return h('li', {}, [
  165. h('a', { className: "btn btn-link", onClick: handleFetchMore }, "pobierz więcej ...")
  166. ]);
  167. }
  168. return h('li', {}, [
  169. h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: person }),
  170. h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: person }),
  171. h('span', { style: { 'margin-left': "6px" } }, label),
  172. // h('button', {
  173. // className: "btn btn-primary",
  174. // style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
  175. // onClick: function () { _selectPerson(person) }
  176. // }, "Dodaj osobę")
  177. ]);
  178. }))
  179. : null;
  180. }
  181. });
  182. var P5UI_AddItemToReport_SelectMSIGPerson = createReactClass({
  183. render: function () { // BI_audit_MSIG_person
  184. var msigPresons = (this.props.msig && this.props.msig['default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person'])
  185. ? this.props.msig['default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person']
  186. : [];
  187. var _selectPerson = this.props.selectPerson.bind(this)
  188. var selectedBaza = 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person';
  189. return (msigPresons.length > 0)
  190. ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, msigPresons.map(function (person) {
  191. var label = (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || '');
  192. return h('li', {}, [
  193. h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: person }),
  194. h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: person }),
  195. h('span', { style: { 'margin-left': "6px" } }, label),
  196. // h('button', {
  197. // className: "btn btn-primary",
  198. // style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
  199. // onClick: function () { _selectPerson(person) }
  200. // }, "Dodaj osobę")
  201. ]);
  202. }))
  203. : null;
  204. }
  205. });
  206. var P5UI_AddItemToReport_BazaMenuItem = createReactClass({
  207. // this.props: { key: option.ID, baza: selectedBaza, data: option }
  208. render: function () {
  209. return h('div', {}, this.props.data.label);
  210. }
  211. });
  212. var P5UI_AddItemToReport_Checkbox = createReactClass({
  213. _getStore: function () {
  214. DBG && console.warn('DBG:: window[STORE_NAME]', { store: window[STORE_NAME], STORE_NAME: STORE_NAME})
  215. return window[STORE_NAME] || null;
  216. },
  217. getStateFromStore: function () {
  218. var featureKey = bocianFeatureKey(this.props.selectedBaza, this.props.selectedItem['@primaryKey']);
  219. var storeState = this._getStore().getState();
  220. return {
  221. featureKey: featureKey,
  222. isSelected: (-1 !== this.getStoreList(this.props.from).indexOf(featureKey)),
  223. // totalOdPracownicy: storeState.totalOdPracownicy,
  224. // totalOdPozostale: storeState.totalOdPozostale,
  225. // totalDoKontrahenci: storeState.totalDoKontrahenci,
  226. // totalDoPozostale: storeState.totalDoPozostale,
  227. };
  228. },
  229. getStoreList: function (from) {
  230. var storeState = this._getStore().getState();
  231. switch (from) {
  232. case 'OD': return storeState.pozostaleOd;
  233. case 'DO': return storeState.pozostaleDo;
  234. default: throw "Not imeplemented store list from = '" + from + "'";
  235. }
  236. },
  237. getInitialState: function () {
  238. return this.getStateFromStore();
  239. },
  240. componentDidMount: function () {
  241. var store = this._getStore()
  242. this._unsubscribe = store ? store.subscribe(this.storeUpdated) : function () {};
  243. },
  244. componentWillUnmount: function () {
  245. this._unsubscribe();
  246. },
  247. storeUpdated: function () {
  248. DBG && console.log('DBG::P5UI__BocianHeader::storeUpdated ', this.getStateFromStore());
  249. this.setState(this.getStateFromStore())
  250. },
  251. _handleClick: function () {
  252. this.state.isSelected ? this.removeItem() : this.saveItem();
  253. // _onSelect(from, selectedBaza, selectedItem);
  254. },
  255. removeItem: function () {
  256. this._getStore().dispatch({ type: 'RM_' + this.props.from, featureKey: this.state.featureKey })
  257. // removeFromSelectedListInLocalStorage(this.props.from, this.state.featureKey);
  258. // this.setState({ isSelected: false });
  259. },
  260. saveItem: function () {
  261. this._getStore().dispatch({ type: 'ADD_' + this.props.from, featureKey: this.state.featureKey })
  262. // saveToSelectedListInLocalStorage(this.props.from, this.state.featureKey);
  263. // this.setState({ isSelected: true });
  264. },
  265. render: function () {
  266. var handleClick = this._handleClick.bind(this);
  267. // var _onSelect = this.props.onSelect;
  268. var isSelected = this.state.isSelected;
  269. return h('div', { className: "checkbox", style: { display: "inline-block", 'margin-left': "6px" } }, [
  270. h('label', { style: { border: "1px solid " + ( isSelected ? "red" : "#ccc" ), 'border-radius': "4px", padding: "2px 6px 0 6px", 'font-size': "12px" } }, [
  271. h('input', {
  272. style: { margin: "0 6px 0 0", position: "relative" },
  273. type: "checkbox",
  274. checked: isSelected,
  275. onClick: handleClick,
  276. }),
  277. h('span', { style: { 'line-height': "20px" } }, this.props.from),
  278. ])
  279. ]);
  280. }
  281. });
  282. var P5UI_AddItemToReport = createReactClass({
  283. getInitialState: function () {
  284. // var listOd = getSelectedListFromLocalStorage('OD');
  285. // var listDo = getSelectedListFromLocalStorage('DO');
  286. return {
  287. baza: null,
  288. newItemBaza: null,
  289. isSearching: false,
  290. selected: null,
  291. };
  292. },
  293. _handleSelectBaza: function (baza) {
  294. this.setState({ baza: baza, newItemBaza: null, selected: null, isSearching: false });
  295. },
  296. _handleSelectNewItem: function (baza) {
  297. this.setState({ baza: null, newItemBaza: baza, selected: null, isSearching: false });
  298. },
  299. _handleSelected: function (selected) {
  300. this.setState({ selected: (selected.length > 0) ? selected[0] : null });
  301. },
  302. _fetchMoreKrsPerson: function (krs) {
  303. var _addMoreKrsPersons = this._addMoreKrsPersons.bind(this);
  304. var pk = krs['@primaryKey']
  305. var krsPersons = (krs && krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
  306. ? krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
  307. : [];
  308. var lastPerson = krsPersons[ krsPersons.length - 1 ];
  309. if (lastPerson && 'type' in lastPerson && "p5:next" == lastPerson['type']) {
  310. var fetchNextLink = lastPerson['value'];
  311. DBG && console.log("DBG: fetchNextLink", { fetchNextLink });
  312. var cols = [ 'ID', 'imiona', 'nazwisko', 'pesel' ];
  313. p5WFS_GetFeature(lastPerson['@typeName'], {
  314. 'p5:next': fetchNextLink.replace('&maxFeatures=10', '&maxFeatures=100') + '&' + 'propertyName=' + cols.join(',')
  315. }).then(function (results) {
  316. DBG && console.log('DBG: _fetchMoreKrsPerson result', { results });
  317. _addMoreKrsPersons(pk, results.map(function (item) { return Object.assign({}, item, { '@primaryKey': item['ID'] }) }));
  318. })
  319. } else {
  320. DBG && console.log("DBG: missing fetch more link");
  321. return;
  322. }
  323. },
  324. _addMoreKrsPersons: function (pk, moreKrsPersons) {
  325. var newOptions = this.state.options.map(function (item) {
  326. if (item['@primaryKey'] === pk) {
  327. item['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'].pop() // rm last link node - p5:link/p5:next
  328. return Object.assign(item, {
  329. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person': item['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'].concat(moreKrsPersons)
  330. })
  331. }
  332. return item;
  333. });
  334. this.setState({
  335. options: newOptions
  336. })
  337. },
  338. _handleSearch: function (query) {
  339. this.setState({ isSearching: true });
  340. var _setState = this.setState.bind(this);
  341. var baza = this.state.baza;
  342. window.fetch(URL_FETCH_FROM_BAZA, {
  343. method: 'POST',
  344. header: {
  345. 'contentType': 'applications/json'
  346. },
  347. credentials: 'same-origin',
  348. body: JSON.stringify({
  349. baza: baza,
  350. query: query,
  351. })
  352. })
  353. .then(function(response) {
  354. return response.text();
  355. })
  356. .then(function(responseText) {
  357. try {
  358. return JSON.parse(responseText);
  359. } catch (e) {
  360. throw responseText;
  361. }
  362. })
  363. .then(function(result) {
  364. if (result.type == 'success') {
  365. // p5UI__notifyAjaxCallback(result);
  366. if (result.body && result.body.items && result.body.items.length > 0) {
  367. return result.body.items;
  368. } else {
  369. p5UI__notifyAjaxCallback({ type: 'warning', msg: "Brak danych pasujących do kryteriów wyszukiwania" });
  370. _setState({ isSearching: false, options: [] });
  371. }
  372. }
  373. })
  374. .then(function(items) {
  375. DBG && console.log('items fetched:', items);
  376. _setState({ isSearching: false, options: convertXlinkToObjects(items) });
  377. })
  378. .catch(function(error) {
  379. DBG && console.log('request failed', error);
  380. })
  381. },
  382. componentWillUnmount: function () {
  383. DBG && console.log("DBG: conponentDidUnmount...");
  384. },
  385. renderItemSave__OLD(selectedBaza, selectedItem) {
  386. var _onSelect = this.props.onSelect;
  387. return h('div', { style: { margin: '22px' } }, [
  388. h('button', {
  389. className: "btn btn-primary",
  390. onClick: function () {
  391. _onSelect(selectedBaza, selectedItem);
  392. // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
  393. // swal.close()
  394. }
  395. }, "XXX Dodaj " + (
  396. ( ('default_db/BI_audit_KRS_person/BI_audit_KRS_person' === selectedBaza)
  397. || ('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person' === selectedBaza)
  398. )
  399. ? "osobę"
  400. : "firmę"
  401. )) // TODO: |> KRS -> firmę, |> KRS Person -> osobę, ....
  402. ]);
  403. },
  404. renderItemSave(selectedBaza, selectedItem) {
  405. return h('div', { style: { margin: '22px', 'font-size': "16px" } }, [
  406. "Dodaj jako: ",
  407. h(P5UI_AddItemToReport_Checkbox, { from: 'OD', selectedBaza: selectedBaza, selectedItem: selectedItem }),
  408. h(P5UI_AddItemToReport_Checkbox, { from: 'DO', selectedBaza: selectedBaza, selectedItem: selectedItem }),
  409. ]);
  410. },
  411. render: function () {
  412. var bazaBtns = [];
  413. bazaBtns.push({ baza: "default_db/BI_audit_KRS/BI_audit_KRS", title: "KRS - Firmy", label: "KRS" });
  414. bazaBtns.push({ baza: "default_db/BI_audit_KRS_person/BI_audit_KRS_person", title: "KRS - Osoby", label: "KRS/p" });
  415. bazaBtns.push({ baza: "default_db/BI_audit_MSIG/BI_audit_MSIG", title: "MSIG - Firmy", label: "MSIG" });
  416. bazaBtns.push({ baza: "default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", title: "MSIG - Osoby", label: "MSIG/p" });
  417. //bazaBtns.push({ baza: "default_db/BI_audit_taxpayer/BI_audit_taxpayer", title: "VAT - Aktywni płatnicy", label: "VATp" });
  418. bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" });
  419. var newItemBtns = [];
  420. // newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY", title: "Nowa osoba", label: "Nowa osoba" });
  421. // newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "Nowy podmiot", label: "Nowy podmiot" });
  422. function generateBazaBtn(btn, opts) {
  423. return h('button', {
  424. title: btn.title,
  425. className: "btn btn-success" + (opts.selected ? " active" : ""),
  426. style: { margin: "3px" },
  427. onClick: function () {
  428. opts.onClick(btn.baza)
  429. },
  430. }, btn.label)
  431. }
  432. function generateNewItemBtn(btn, opts) {
  433. return h('button', {
  434. title: btn.title,
  435. className: "btn btn-success" + (opts.selected ? " active" : ""),
  436. style: { margin: "3px" },
  437. onClick: function () {
  438. opts.onClick(btn.baza)
  439. },
  440. }, btn.label)
  441. }
  442. var handleSelectBaza = this._handleSelectBaza.bind(this);
  443. var handleSelectNewItem = this._handleSelectNewItem.bind(this);
  444. var selectedBaza = this.state.baza;
  445. var selectedNewItemBaza = this.state.newItemBaza;
  446. var selectedItem = this.state.selected;
  447. var selectedLabel = '';
  448. if (selectedBaza) {
  449. var selBazaBtn = bazaBtns.filter(function (btn) { return btn.baza === selectedBaza; })
  450. if (selBazaBtn) {
  451. selBazaBtn[0].title
  452. }
  453. }
  454. var handleSearch = this._handleSearch.bind(this);
  455. var handleSelected = this._handleSelected.bind(this);
  456. var _onSelect = this.props.onSelect;
  457. var _fetchMoreKrsPerson = this._fetchMoreKrsPerson.bind(this);
  458. DBG && console.log('DBG: render this.state.options', this.state.options);
  459. return h('div', {}, [
  460. h('p', { style: { textAlign: "center" } }, "Wybierz bazę"),
  461. h('div', { style: { marginBottom: '22px' } },
  462. bazaBtns.map(function (btn) {
  463. return generateBazaBtn(btn, {
  464. onClick: handleSelectBaza,
  465. selected: (selectedBaza === btn.baza),
  466. });
  467. }).concat(
  468. newItemBtns.map(function (btn) {
  469. return generateNewItemBtn(btn, {
  470. onClick: handleSelectNewItem,
  471. selected: (selectedNewItemBaza === btn.baza),
  472. });
  473. })
  474. )
  475. ),
  476. ('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza) && h(AsyncTypeahead, {
  477. isLoading: this.state.isSearching,
  478. allowNew: false,
  479. multiple: false,
  480. options: this.state.options,
  481. labelKey: "label",
  482. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  483. searchText: "Wyszukiwanie...",
  484. // labelKey: function (option) {
  485. // return [
  486. // option.nazwa.replace('"', ''),
  487. // option.nip,
  488. // option.krs,
  489. // option.regon,
  490. // option.S_miejscowosc,
  491. // ].join(' ')
  492. // },
  493. minLength: 3,
  494. onSearch: handleSearch,
  495. placeholder: "Wyszukaj...",
  496. onChange: handleSelected,
  497. autoFocus: true,
  498. filterBy: filterByHelper,
  499. renderMenuItemChildren: function (option, props) {
  500. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  501. }
  502. }),
  503. ('default_db/BI_audit_KRS_person/BI_audit_KRS_person' === selectedBaza) && h(AsyncTypeahead, {
  504. isLoading: this.state.isSearching,
  505. allowNew: false,
  506. multiple: false,
  507. options: this.state.options,
  508. labelKey: "label",
  509. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  510. searchText: "Wyszukiwanie...",
  511. // labelKey: function (option) {
  512. // return [
  513. // option.nazwa.replace('"', ''),
  514. // option.nip,
  515. // option.krs,
  516. // option.regon,
  517. // option.S_miejscowosc,
  518. // ].join(' ')
  519. // },
  520. minLength: 3,
  521. onSearch: handleSearch,
  522. placeholder: "Wyszukaj...",
  523. onChange: handleSelected,
  524. autoFocus: true,
  525. filterBy: filterByHelper,
  526. renderMenuItemChildren: function (option, props) {
  527. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  528. }
  529. }),
  530. ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza) && h(AsyncTypeahead, {
  531. isLoading: this.state.isSearching,
  532. allowNew: false,
  533. multiple: false,
  534. options: this.state.options,
  535. labelKey: "label",
  536. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  537. searchText: "Wyszukiwanie...",
  538. // labelKey: function (option) {
  539. // return [
  540. // option.nazwa.replace('"', ''),
  541. // option.nip,
  542. // option.krs,
  543. // option.regon,
  544. // option.S_miejscowosc,
  545. // ].join(' ')
  546. // },
  547. minLength: 3,
  548. onSearch: handleSearch,
  549. placeholder: "Wyszukaj...",
  550. onChange: handleSelected,
  551. autoFocus: true,
  552. filterBy: filterByHelper,
  553. renderMenuItemChildren: function (option, props) {
  554. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  555. }
  556. }),
  557. ('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person' === selectedBaza) && h(AsyncTypeahead, {
  558. isLoading: this.state.isSearching,
  559. allowNew: false,
  560. multiple: false,
  561. options: this.state.options,
  562. labelKey: "label",
  563. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  564. searchText: "Wyszukiwanie...",
  565. // labelKey: function (option) {
  566. // return [
  567. // option.nazwa.replace('"', ''),
  568. // option.nip,
  569. // option.krs,
  570. // option.regon,
  571. // option.S_miejscowosc,
  572. // ].join(' ')
  573. // },
  574. minLength: 3,
  575. onSearch: handleSearch,
  576. placeholder: "Wyszukaj...",
  577. onChange: handleSelected,
  578. autoFocus: true,
  579. filterBy: filterByHelper,
  580. renderMenuItemChildren: function (option, props) {
  581. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  582. }
  583. }),
  584. ('default_db/BI_audit_CEIDG/BI_audit_CEIDG' === selectedBaza) && h(AsyncTypeahead, {
  585. isLoading: this.state.isSearching,
  586. allowNew: false,
  587. multiple: false,
  588. options: this.state.options,
  589. labelKey: "label",
  590. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  591. searchText: "Wyszukiwanie...",
  592. // labelKey: function (option) {
  593. // return [
  594. // option.nazwa.replace('"', ''),
  595. // option.nip,
  596. // option.krs,
  597. // option.regon,
  598. // option.S_miejscowosc,
  599. // ].join(' ')
  600. // },
  601. minLength: 3,
  602. onSearch: handleSearch,
  603. placeholder: "Wyszukaj...",
  604. onChange: handleSelected,
  605. autoFocus: true,
  606. filterBy: filterByHelper,
  607. renderMenuItemChildren: function (option, props) {
  608. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  609. }
  610. }),
  611. ("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY" === selectedNewItemBaza) && h('div', { className: 'form-group' }, [
  612. h('input',{
  613. className:'form-control required',
  614. id:'personName',
  615. placeholder:'Imię'
  616. }),
  617. h('input',{
  618. className:'form-control required',
  619. id:'personSurname',
  620. placeholder:'Nazwisko'
  621. }),
  622. h('input',{
  623. className:'form-control required',
  624. id:'personPesel',
  625. placeholder:'Pesel'
  626. }),
  627. h('input',{
  628. className:'form-control',
  629. id:'personNip',
  630. placeholder:'NIP'
  631. }),
  632. h('button', { className: "btn btn-primary", onClick: function () {
  633. _onSelect(selectedNewItemBaza, {
  634. personName: document.getElementById('personName').value,
  635. personSurname: document.getElementById('personSurname').value,
  636. personPesel: document.getElementById('personPesel').value,
  637. personNip: document.getElementById('personNip').value,
  638. })
  639. swal.close();
  640. }.bind(this) }, "Dodaj osobę")
  641. ]),
  642. ("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI" === selectedNewItemBaza) && h('div', { className: 'form-group' }, [
  643. h('input',{
  644. className:'form-control required',
  645. id:'companyName',
  646. placeholder:'Nazwa'
  647. }),
  648. h('input',{
  649. className:'form-control required',
  650. id:'companyPesel',
  651. placeholder:'Pesel'
  652. }),
  653. h('input',{
  654. className:'form-control required',
  655. id:'companyStreet',
  656. placeholder:'Ulica'
  657. }),
  658. h('input',{
  659. className:'form-control required',
  660. id:'companyNumber',
  661. placeholder:'Numer budynku'
  662. }),
  663. h('input',{
  664. className:'form-control required',
  665. id:'companyNumberLocal',
  666. placeholder:'Numer lokalu'
  667. }),
  668. h('input',{
  669. className:'form-control required',
  670. id:'companyPostCode',
  671. placeholder:'Kod pocztowy'
  672. }),
  673. h('input',{
  674. className:'form-control required',
  675. id:'companyCity',
  676. placeholder:'Miejscowosc'
  677. }),
  678. h('input',{
  679. className:'form-control required',
  680. id:'companyNip',
  681. placeholder:'NIP'
  682. }),
  683. h('input',{
  684. className:'form-control',
  685. id:'companyRegon',
  686. placeholder:'REGON'
  687. }),
  688. h('input',{
  689. className:'form-control',
  690. id:'companyKrs',
  691. placeholder:'KRS'
  692. }),
  693. h('button', { className: "btn btn-primary", onClick: function () {
  694. _onSelect(selectedNewItemBaza, {
  695. companyName: document.getElementById('companyName').value,
  696. companyNip: document.getElementById('companyNip').value,
  697. companyRegon: document.getElementById('companyRegon').value,
  698. companyPesel: document.getElementById('companyPesel').value,
  699. companyStreet: document.getElementById('companyStreet').value,
  700. companyNumber: document.getElementById('companyNumber').value,
  701. companyNumberLocal: document.getElementById('companyNumberLocal').value,
  702. companyPostCode: document.getElementById('companyPostCode').value,
  703. companyCity: document.getElementById('companyCity').value,
  704. companyKrs: document.getElementById('companyKrs').value,
  705. })
  706. swal.close();
  707. }.bind(this) }, "Dodaj podmiot")
  708. ]),
  709. (selectedBaza && selectedItem) && this.renderItemSave(selectedBaza, selectedItem),
  710. ('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectKrsPerson, {
  711. krs: selectedItem,
  712. selectPerson: function (person) {
  713. _onSelect("default_db/BI_audit_KRS_person/BI_audit_KRS_person", person);
  714. // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
  715. // swal.close()
  716. },
  717. fetchMoreKrsPerson: _fetchMoreKrsPerson
  718. }),
  719. ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectMSIGPerson, {
  720. msig: selectedItem,
  721. selectPerson: function (person) {
  722. _onSelect("default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", person);
  723. // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
  724. // swal.close()
  725. }
  726. }),
  727. (DBG && selectedItem) && h('pre', { style: { textAlign: 'left' } }, JSON.stringify(selectedItem, null, 2)),
  728. ])
  729. }
  730. });
  731. function getWindowWidth() {
  732. var w = window, d = document,
  733. e = d.documentElement,
  734. g = d.getElementsByTagName('body')[0];
  735. return w.innerWidth || e.clientWidth || g.clientWidth;
  736. }
  737. function addItemToRaport(event) {
  738. // default_db/BI_audit_KRS/BI_audit_KRS
  739. // default_db/BI_audit_KRS_person/BI_audit_KRS_person
  740. // default_db/BI_audit_MSIG/BI_audit_MSIG
  741. // default_db/BI_audit_MSIG_person/BI_audit_MSIG_person
  742. // default_db/BI_audit_taxpayer/BI_audit_taxpayer
  743. // default_db/BI_audit_CEIDG/BI_audit_CEIDG
  744. // default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY
  745. // default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI
  746. // default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY
  747. var valueUrl = global.location.hash;
  748. swal({
  749. title: "Dodaj osobę lub podmiot",
  750. width: (getWindowWidth() * 0.8),
  751. html: '<div id="' + FUNCTION_NAME + '__searchBaza" style="padding:0 24px 24px 24px; min-height:400px"></div>',
  752. animation: false,
  753. showConfirmButton: false,
  754. showCancelButton: false,
  755. showCloseButton: true,
  756. allowEnterKey: false,
  757. onOpen: function () {
  758. ReactDOM.render(
  759. h(P5UI_AddItemToReport, {
  760. onSelect: function (from, baza, selected) {
  761. DBG && console.log('TODO: selected ', { from, baza, selected });
  762. global.fetch(URL_SAVE_TO_DB, {
  763. method: 'POST',
  764. credentials: 'same-origin',
  765. headers: { 'Content-Type': 'application/json' },
  766. body: JSON.stringify({
  767. from: from,
  768. baza: baza,
  769. item: selected
  770. })
  771. }).then(function(response) {
  772. return response.json();
  773. }).then(function(result) {
  774. if(result.type === "success"){
  775. if(valueUrl === '#PRACOWNICY'){
  776. urlFetchPracownicy(1);
  777. }else{
  778. urlFetchKontrahenci(1);
  779. }
  780. }
  781. p5UI__notifyAjaxCallback(result);
  782. })
  783. }
  784. }),
  785. document.getElementById(FUNCTION_NAME + '__searchBaza')
  786. )
  787. }
  788. }).catch(function (err) {
  789. DBG && console.log('err', err)
  790. })
  791. }
  792. // global[FUNCTION_NAME] = addItemToRaport;
  793. module.exports[FUNCTION_NAME] = addItemToRaport;
  794. // module.exports = {
  795. // P5UI_AddItemToReport_BazaMenuItem,
  796. // P5UI_AddItemToReport,
  797. // createPracownikAjax
  798. // }