Bocian.php.addItemToRaport.js 31 KB

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