Bocian.php.addItemToRaport.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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 DBG = DBG || false;
  7. function convertXlinkToObjects(items) {
  8. var _childCache = {}; // fieldName => { pk => child }
  9. items.forEach(function (item) {
  10. var refFields = Object.keys(item).filter(function (fieldName) {
  11. return (-1 !== fieldName.indexOf(':') && item[fieldName]);
  12. });
  13. refFields.forEach(function (fieldName) {
  14. item[fieldName].forEach(function (child) {
  15. if (1 === Object.keys(child).length && 'xlink' in child) {
  16. // xlink
  17. } else if (Object.keys(child).length > 1) {
  18. if ('@primaryKey' in child) {
  19. if (!(fieldName in _childCache)) _childCache[fieldName] = {};
  20. _childCache[fieldName][ child['@primaryKey'] ] = child;
  21. }
  22. }
  23. })
  24. })
  25. return item;
  26. });
  27. DBG && console.log('DBG convertXlinkToObjects', { _childCache, items });
  28. return items.map(function (item) {
  29. var refFields = Object.keys(item).filter(function (fieldName) {
  30. return (-1 !== fieldName.indexOf(':') && item[fieldName]);
  31. });
  32. refFields.forEach(function (fieldName) {
  33. item[fieldName] = item[fieldName].map(function (child) {
  34. if (1 === Object.keys(child).length && 'xlink' in child) {
  35. var pk = child['xlink'].split('.').pop();
  36. return _childCache[fieldName][pk];
  37. }
  38. return child;
  39. })
  40. })
  41. return item;
  42. })
  43. }
  44. var P5UI_AddItemToReport_SelectKrsPerson = createReactClass({
  45. // h(SelectKrsPerson, { krs: this.state.selected })
  46. // this.props.krs: {
  47. // "@primaryKey": "161323",
  48. // "A_kod": "80-299",
  49. // "A_kraj": "POLSKA",
  50. // "A_miejscowosc": "GDAŃSK",
  51. // "A_nrDomu": "54C",
  52. // "A_nrLokalu": null,
  53. // "A_poczta": "GDAŃSK",
  54. // "A_ulica": "BARNIEWICKA",
  55. // "ID": "161323",
  56. // "S_kraj": "POLSKA",
  57. // "S_miejscowosc": "GDAŃSK",
  58. // "S_wojewodztwo": "POMORSKIE",
  59. // "krs": "0000223476",
  60. // "nazwa": "BIALL Sp. z o.o.",
  61. // "nip": "6040018535",
  62. // "regon": "193106935",
  63. // "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person": [
  64. // {
  65. // "@primaryKey": "747004",
  66. // "ID": "747004",
  67. // "imiona": "ADRIAN RYSZARD",
  68. // "nazwisko": "WIECZORKOWSKI",
  69. // "pesel": "75040301615"
  70. // },
  71. // {
  72. // "@primaryKey": "747003",
  73. // "ID": "747003",
  74. // "imiona": "EWA",
  75. // "nazwisko": "WIECZORKOWSKA",
  76. // "pesel": "75090401549"
  77. // },
  78. render: function () {
  79. var krsPresons = (this.props.krs && this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'])
  80. ? this.props.krs['default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person']
  81. : [];
  82. var _selectPerson = this.props.selectPerson.bind(this)
  83. return (krsPresons.length > 0)
  84. ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, krsPresons.map(function (person) {
  85. return h('li', {}, [
  86. (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || ''),
  87. h('button', {
  88. className: "btn btn-primary",
  89. style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
  90. onClick: function () { _selectPerson(person) }
  91. }, "Dodaj osobę")
  92. ]);
  93. }))
  94. : null;
  95. }
  96. });
  97. var P5UI_AddItemToReport_SelectMSIGPerson = createReactClass({
  98. render: function () {
  99. var msigPresons = (this.props.msig && this.props.msig['default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person'])
  100. ? this.props.msig['default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person']
  101. : [];
  102. var _selectPerson = this.props.selectPerson.bind(this)
  103. return (msigPresons.length > 0)
  104. ? h('ol', { style: { margin: '22px', textAlign: 'left' } }, msigPresons.map(function (person) {
  105. return h('li', {}, [
  106. (person.imiona || '') + ' ' + (person.nazwisko || '') + ', ' + (person.pesel || ''),
  107. h('button', {
  108. className: "btn btn-primary",
  109. style: { marginLeft: "8px", padding: "4px 8px", fontSize: "small" },
  110. onClick: function () { _selectPerson(person) }
  111. }, "Dodaj osobę")
  112. ]);
  113. }))
  114. : null;
  115. }
  116. });
  117. var P5UI_AddItemToReport_BazaMenuItem = createReactClass({
  118. // this.props: { key: option.ID, baza: selectedBaza, data: option }
  119. render: function () {
  120. return h('div', {}, this.props.data.label);
  121. }
  122. });
  123. var P5UI_AddItemToReport = createReactClass({
  124. getInitialState: function () {
  125. return {
  126. baza: null,
  127. newItemBaza: null,
  128. isSearching: false,
  129. selected: null,
  130. };
  131. },
  132. _handleSelectBaza: function (baza) {
  133. this.setState({ baza: baza, newItemBaza: null, selected: null, isSearching: false });
  134. },
  135. _handleSelectNewItem: function (baza) {
  136. this.setState({ baza: null, newItemBaza: baza, selected: null, isSearching: false });
  137. },
  138. _handleSelected: function (selected) {
  139. this.setState({ selected: (selected.length > 0) ? selected[0] : null });
  140. },
  141. _handleSearch: function (query) {
  142. this.setState({ isSearching: true });
  143. var _setState = this.setState.bind(this);
  144. var baza = this.state.baza;
  145. var options= [];
  146. window.fetch(URL_FETCH_FROM_BAZA, {
  147. method: 'POST',
  148. header: {
  149. 'contentType': 'applications/json'
  150. },
  151. credentials: 'same-origin',
  152. body: JSON.stringify({
  153. baza: baza,
  154. query: query,
  155. })
  156. })
  157. .then(function(response) {
  158. return response.text();
  159. })
  160. .then(function(responseText) {
  161. try {
  162. return JSON.parse(responseText);
  163. } catch (e) {
  164. throw responseText;
  165. }
  166. })
  167. .then(function(result) {
  168. if (result.type == 'success') {
  169. // p5UI__notifyAjaxCallback(result);
  170. if (result.body && result.body.items && result.body.items.length > 0) {
  171. return result.body.items;
  172. } else {
  173. p5UI__notifyAjaxCallback({ type: 'warning', msg: "Brak danych pasujących do kryteriów wyszukiwania" });
  174. _setState({ isSearching: false, options: [] });
  175. }
  176. }
  177. })
  178. .then(function(items) {
  179. DBG && console.log('items fetched:', items);
  180. _setState({ isSearching: false, options: convertXlinkToObjects(items) });
  181. })
  182. .catch(function(error) {
  183. DBG && console.log('request failed', error);
  184. })
  185. },
  186. componentWillUnmount: function () {
  187. DBG && console.log("DBG: conponentDidUnmount...");
  188. },
  189. render: function () {
  190. var bazaBtns = [];
  191. bazaBtns.push({ baza: "default_db/BI_audit_KRS/BI_audit_KRS", title: "KRS - Firmy", label: "KRS" });
  192. bazaBtns.push({ baza: "default_db/BI_audit_KRS_person/BI_audit_KRS_person", title: "KRS - Osoby", label: "KRS/p" });
  193. bazaBtns.push({ baza: "default_db/BI_audit_MSIG/BI_audit_MSIG", title: "MSIG - Firmy", label: "MSIG" });
  194. bazaBtns.push({ baza: "default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", title: "MSIG - Osoby", label: "MSIG/p" });
  195. //bazaBtns.push({ baza: "default_db/BI_audit_taxpayer/BI_audit_taxpayer", title: "VAT - Aktywni płatnicy", label: "VATp" });
  196. bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" });
  197. var newItemBtns = [];
  198. newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY", title: "Nowa osoba", label: "Nowa osoba" });
  199. newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "Nowy podmiot", label: "Nowy podmiot" });
  200. function generateBazaBtn(btn, opts) {
  201. return h('button', {
  202. title: btn.title,
  203. className: "btn btn-success" + (opts.selected ? " active" : ""),
  204. style: { margin: "3px" },
  205. onClick: function () {
  206. opts.onClick(btn.baza)
  207. },
  208. }, btn.label)
  209. }
  210. function generateNewItemBtn(btn, opts) {
  211. return h('button', {
  212. title: btn.title,
  213. className: "btn btn-success" + (opts.selected ? " active" : ""),
  214. style: { margin: "3px" },
  215. onClick: function () {
  216. opts.onClick(btn.baza)
  217. },
  218. }, btn.label)
  219. }
  220. var handleSelectBaza = this._handleSelectBaza.bind(this);
  221. var handleSelectNewItem = this._handleSelectNewItem.bind(this);
  222. var selectedBaza = this.state.baza;
  223. var selectedNewItemBaza = this.state.newItemBaza;
  224. var selectedItem = this.state.selected;
  225. var selectedLabel = '';
  226. if (selectedBaza) {
  227. var selBazaBtn = bazaBtns.filter(function (btn) { return btn.baza === selectedBaza; })
  228. if (selBazaBtn) {
  229. selBazaBtn[0].title
  230. }
  231. }
  232. var handleSearch = this._handleSearch.bind(this);
  233. var handleSelected = this._handleSelected.bind(this);
  234. var _onSelect = this.props.onSelect;
  235. DBG && console.log('DBG: render this.state.options', this.state.options);
  236. return h('div', {}, [
  237. h('p', { style: { textAlign: "center" } }, "Wybierz bazę"),
  238. h('div', { style: { marginBottom: '22px' } },
  239. bazaBtns.map(function (btn) {
  240. return generateBazaBtn(btn, {
  241. onClick: handleSelectBaza,
  242. selected: (selectedBaza === btn.baza),
  243. });
  244. }).concat(
  245. newItemBtns.map(function (btn) {
  246. return generateNewItemBtn(btn, {
  247. onClick: handleSelectNewItem,
  248. selected: (selectedNewItemBaza === btn.baza),
  249. });
  250. })
  251. )
  252. ),
  253. ('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza) && h(AsyncTypeahead, {
  254. isLoading: this.state.isSearching,
  255. allowNew: false,
  256. multiple: false,
  257. options: this.state.options,
  258. labelKey: "label",
  259. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  260. searchText: "Wyszukiwanie...",
  261. // labelKey: function (option) {
  262. // return [
  263. // option.nazwa.replace('"', ''),
  264. // option.nip,
  265. // option.krs,
  266. // option.regon,
  267. // option.S_miejscowosc,
  268. // ].join(' ')
  269. // },
  270. minLength: 3,
  271. onSearch: handleSearch,
  272. placeholder: "Wyszukaj...",
  273. onChange: handleSelected,
  274. autoFocus: true,
  275. // filterBy: function (option, text) {
  276. // console.log('TODO: filterBy...', {option, text});
  277. // return true;
  278. // },
  279. renderMenuItemChildren: function (option, props) {
  280. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  281. }
  282. }),
  283. ('default_db/BI_audit_KRS_person/BI_audit_KRS_person' === selectedBaza) && h(AsyncTypeahead, {
  284. isLoading: this.state.isSearching,
  285. allowNew: false,
  286. multiple: false,
  287. options: this.state.options,
  288. labelKey: "label",
  289. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  290. searchText: "Wyszukiwanie...",
  291. // labelKey: function (option) {
  292. // return [
  293. // option.nazwa.replace('"', ''),
  294. // option.nip,
  295. // option.krs,
  296. // option.regon,
  297. // option.S_miejscowosc,
  298. // ].join(' ')
  299. // },
  300. minLength: 3,
  301. onSearch: handleSearch,
  302. placeholder: "Wyszukaj...",
  303. onChange: handleSelected,
  304. autoFocus: true,
  305. // filterBy: function (option, text) {
  306. // console.log('TODO: filterBy...', {option, text});
  307. // return true;
  308. // },
  309. renderMenuItemChildren: function (option, props) {
  310. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  311. }
  312. }),
  313. ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza) && h(AsyncTypeahead, {
  314. isLoading: this.state.isSearching,
  315. allowNew: false,
  316. multiple: false,
  317. options: this.state.options,
  318. labelKey: "label",
  319. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  320. searchText: "Wyszukiwanie...",
  321. // labelKey: function (option) {
  322. // return [
  323. // option.nazwa.replace('"', ''),
  324. // option.nip,
  325. // option.krs,
  326. // option.regon,
  327. // option.S_miejscowosc,
  328. // ].join(' ')
  329. // },
  330. minLength: 3,
  331. onSearch: handleSearch,
  332. placeholder: "Wyszukaj...",
  333. onChange: handleSelected,
  334. autoFocus: true,
  335. // filterBy: function (option, text) {
  336. // console.log('TODO: filterBy...', {option, text});
  337. // return true;
  338. // },
  339. renderMenuItemChildren: function (option, props) {
  340. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  341. }
  342. }),
  343. ('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person' === selectedBaza) && h(AsyncTypeahead, {
  344. isLoading: this.state.isSearching,
  345. allowNew: false,
  346. multiple: false,
  347. options: this.state.options,
  348. labelKey: "label",
  349. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  350. searchText: "Wyszukiwanie...",
  351. // labelKey: function (option) {
  352. // return [
  353. // option.nazwa.replace('"', ''),
  354. // option.nip,
  355. // option.krs,
  356. // option.regon,
  357. // option.S_miejscowosc,
  358. // ].join(' ')
  359. // },
  360. minLength: 3,
  361. onSearch: handleSearch,
  362. placeholder: "Wyszukaj...",
  363. onChange: handleSelected,
  364. autoFocus: true,
  365. // filterBy: function (option, text) {
  366. // console.log('TODO: filterBy...', {option, text});
  367. // return true;
  368. // },
  369. renderMenuItemChildren: function (option, props) {
  370. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  371. }
  372. }),
  373. ('default_db/BI_audit_CEIDG/BI_audit_CEIDG' === selectedBaza) && h(AsyncTypeahead, {
  374. isLoading: this.state.isSearching,
  375. allowNew: false,
  376. multiple: false,
  377. options: this.state.options,
  378. labelKey: "label",
  379. emptyLabel: "Brak danych pasujących do kryteriów wyszukiwania",
  380. searchText: "Wyszukiwanie...",
  381. // labelKey: function (option) {
  382. // return [
  383. // option.nazwa.replace('"', ''),
  384. // option.nip,
  385. // option.krs,
  386. // option.regon,
  387. // option.S_miejscowosc,
  388. // ].join(' ')
  389. // },
  390. minLength: 3,
  391. onSearch: handleSearch,
  392. placeholder: "Wyszukaj...",
  393. onChange: handleSelected,
  394. autoFocus: true,
  395. // filterBy: function (option, text) {
  396. // console.log('TODO: filterBy...', {option, text});
  397. // return true;
  398. // },
  399. renderMenuItemChildren: function (option, props) {
  400. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  401. }
  402. }),
  403. (selectedNewItemBaza === "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY") && h('div', { className: 'form-group' }, [
  404. h('input',{
  405. className:'form-control required',
  406. id:'personName',
  407. placeholder:'Imię'
  408. }),
  409. h('input',{
  410. className:'form-control required',
  411. id:'personSurname',
  412. placeholder:'Nazwisko'
  413. }),
  414. h('input',{
  415. className:'form-control required',
  416. id:'personPesel',
  417. placeholder:'Pesel'
  418. }),
  419. h('input',{
  420. className:'form-control',
  421. id:'personNip',
  422. placeholder:'NIP'
  423. }),
  424. h('button', { className: "btn btn-primary", onClick: function () {
  425. _onSelect(selectedNewItemBaza, {
  426. personName: document.getElementById('personName').value,
  427. personSurname: document.getElementById('personSurname').value,
  428. personPesel: document.getElementById('personPesel').value,
  429. personNip: document.getElementById('personNip').value,
  430. })
  431. }.bind(this) }, "Dodaj osobę")
  432. ]),
  433. (selectedNewItemBaza === "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI") && h('div', { className: 'form-group' }, [
  434. h('input',{
  435. className:'form-control required',
  436. id:'companyName',
  437. placeholder:'Nazwa'
  438. }),
  439. h('input',{
  440. className:'form-control required',
  441. id:'companyPesel',
  442. placeholder:'Pesel'
  443. }),
  444. h('input',{
  445. className:'form-control required',
  446. id:'companyStreet',
  447. placeholder:'Ulica'
  448. }),
  449. h('input',{
  450. className:'form-control required',
  451. id:'companyNumber',
  452. placeholder:'Numer budynku'
  453. }),
  454. h('input',{
  455. className:'form-control required',
  456. id:'companyNumberLocal',
  457. placeholder:'Numer lokalu'
  458. }),
  459. h('input',{
  460. className:'form-control required',
  461. id:'companyPostCode',
  462. placeholder:'Kod pocztowy'
  463. }),
  464. h('input',{
  465. className:'form-control required',
  466. id:'companyCity',
  467. placeholder:'Miejscowosc'
  468. }),
  469. h('input',{
  470. className:'form-control required',
  471. id:'companyNip',
  472. placeholder:'NIP'
  473. }),
  474. h('input',{
  475. className:'form-control',
  476. id:'comapnyRegon',
  477. placeholder:'REGON'
  478. }),
  479. h('input',{
  480. className:'form-control',
  481. id:'companyKrs',
  482. placeholder:'KRS'
  483. }),
  484. h('button', { className: "btn btn-primary", onClick: function () {
  485. _onSelect(selectedNewItemBaza, {
  486. companyName: document.getElementById('companyName').value,
  487. companyNip: document.getElementById('companyNip').value,
  488. companyRegon: document.getElementById('companyRegon').value,
  489. companyPesel: document.getElementById('companyPesel').value,
  490. companyStreet: document.getElementById('companyStreet').value,
  491. companyNumber: document.getElementById('companyNumber').value,
  492. companyNumberLocal: document.getElementById('companyNumberLocal').value,
  493. companyPostCode: document.getElementById('companyPostCode').value,
  494. companyCity: document.getElementById('companyCity').value,
  495. companyKrs: document.getElementById('companyKrs').value,
  496. })
  497. }.bind(this) }, "Dodaj podmiot")
  498. ]),
  499. (selectedBaza && selectedItem) && h('div', { style: { margin: '22px' } }, [
  500. h('button', {
  501. className: "btn btn-primary",
  502. onClick: function () {
  503. _onSelect(selectedBaza, selectedItem);
  504. // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
  505. // swal.close()
  506. }
  507. }, "Dodaj firmę") // TODO: |> KRS -> firmę, |> KRS Person -> osobę, ....
  508. ]),
  509. ('default_db/BI_audit_KRS/BI_audit_KRS' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectKrsPerson, {
  510. krs: selectedItem,
  511. selectPerson: function (person) {
  512. _onSelect("default_db/BI_audit_KRS_person/BI_audit_KRS_person", person);
  513. // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
  514. // swal.close()
  515. }
  516. }),
  517. ('default_db/BI_audit_MSIG/BI_audit_MSIG' === selectedBaza && selectedItem) && h(P5UI_AddItemToReport_SelectMSIGPerson, {
  518. krs: selectedItem,
  519. selectPerson: function (person) {
  520. _onSelect("default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", person);
  521. // ReactDOM.unmountComponentAtNode(document.getElementById(FUNCTION_NAME + '__searchBaza'));
  522. // swal.close()
  523. }
  524. }),
  525. (DBG && selectedItem) && h('pre', { style: { textAlign: 'left' } }, JSON.stringify(selectedItem, null, 2)),
  526. ])
  527. }
  528. });
  529. function getWindowWidth() {
  530. var w = window, d = document,
  531. e = d.documentElement,
  532. g = d.getElementsByTagName('body')[0];
  533. return w.innerWidth || e.clientWidth || g.clientWidth;
  534. }
  535. function addItemToRaport(event) {
  536. // default_db/BI_audit_KRS/BI_audit_KRS
  537. // default_db/BI_audit_KRS_person/BI_audit_KRS_person
  538. // default_db/BI_audit_MSIG/BI_audit_MSIG
  539. // default_db/BI_audit_MSIG_person/BI_audit_MSIG_person
  540. // default_db/BI_audit_taxpayer/BI_audit_taxpayer
  541. // default_db/BI_audit_CEIDG/BI_audit_CEIDG
  542. // default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY
  543. // default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI
  544. // default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY
  545. swal({
  546. title: "Dodaj osobę lub podmiot",
  547. width: (getWindowWidth() * 0.8),
  548. html: '<div id="' + FUNCTION_NAME + '__searchBaza" style="padding:0 24px 24px 24px; min-height:400px"></div>',
  549. animation: false,
  550. showConfirmButton: false,
  551. showCancelButton: false,
  552. showCloseButton: true,
  553. allowEnterKey: false,
  554. onOpen: function () {
  555. ReactDOM.render(
  556. h(P5UI_AddItemToReport, {
  557. onSelect: function (baza, selected) {
  558. DBG && console.log('TODO: selected ', { baza, selected });
  559. global.fetch(URL_SAVE_TO_DB, {
  560. method: 'POST',
  561. credentials: 'same-origin',
  562. headers: { 'Content-Type': 'application/json' },
  563. body: JSON.stringify({
  564. baza: baza,
  565. item: selected
  566. })
  567. }).then(function(response) {
  568. return response.json();
  569. }).then(function(result) {
  570. p5UI__notifyAjaxCallback(result)
  571. })
  572. }
  573. }),
  574. document.getElementById(FUNCTION_NAME + '__searchBaza')
  575. )
  576. }
  577. }).catch(function (err) {
  578. DBG && console.log('err', err)
  579. })
  580. }
  581. // global[FUNCTION_NAME] = addItemToRaport;
  582. module.exports[FUNCTION_NAME] = addItemToRaport;
  583. // module.exports = {
  584. // P5UI_AddItemToReport_BazaMenuItem,
  585. // P5UI_AddItemToReport,
  586. // createPracownikAjax
  587. // }