Bocian.php.addItemToRaport.js 25 KB

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