Bocian.php.addItemToRaport.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. const createReactClass = window.p5VendorJs.createReactClass;
  2. const h = window.p5VendorJs.React.createElement;
  3. const ReactDOM = window.p5VendorJs.ReactDOM;
  4. const AsyncTypeahead = window.p5VendorJs.AsyncTypeahead;
  5. const swal = window.swal;
  6. const DBG = 1;
  7. var P5UI_AddItemToReport_BazaMenuItem = createReactClass({
  8. // this.props: { key: option.ID, baza: selectedBaza, data: option }
  9. render: function () {
  10. return h('div', {}, this.props.data.label);
  11. }
  12. })
  13. var P5UI_AddItemToReport = createReactClass({
  14. getInitialState: function () {
  15. return {
  16. baza: null,
  17. newItemBaza: null,
  18. isSearching: false,
  19. selected: null,
  20. };
  21. },
  22. _handleSelectBaza: function (baza) {
  23. this.setState({ baza: baza, newItemBaza: null });
  24. },
  25. _handleSelectNewItem: function (baza) {
  26. this.setState({ baza: null, newItemBaza: baza });
  27. },
  28. _handleSelected: function (selected) {
  29. this.setState({ selected: (selected.length > 0) ? selected[0] : null });
  30. },
  31. _handleSearch: function (query) {
  32. this.setState({ isSearching: true });
  33. var options= [];
  34. //Baza= this.state.baza;
  35. window.fetch(URL_FETCH_FROM_BAZA, {
  36. method: 'POST',
  37. header: {
  38. 'contentType': 'applications/json'
  39. },
  40. credentials: 'same-origin',
  41. body: JSON.stringify({
  42. 'baza': this.state.baza,
  43. })
  44. .then(function(responseText) {
  45. try {
  46. return JSON.parse(responseText);
  47. } catch (e) {
  48. throw responseText;
  49. }
  50. })
  51. .then(function(result) {
  52. if (result.type == 'success') {
  53. p5UI__notifyAjaxCallback(result);
  54. resolve(result.body);
  55. options=result.body.items;
  56. this.setState({ isSearching: false, options: options });
  57. }
  58. })
  59. .catch(function(error) {
  60. if(DBG) console.log('request failed', error);
  61. })
  62. })
  63. // setTimeout(function () {
  64. // var options = [];
  65. // options.push({
  66. // ID: 601900,
  67. // nazwa: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA",
  68. // krs: "0000721712", nip: "5862328735", regon: "369609850",
  69. // S_kraj: "POLSKA", S_miejscowosc: "GDYNIA", A_kod: "81-310", A_ulica: "ŚLĄSKA", A_nrDomu: "35/37",
  70. // searchLabel: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA, ŚLĄSKA 35/37, 81-310 GDYNIA, krs: 0000721712, nip: 5862328735, regon: 369609850",
  71. // label: "ADEGROUP SPÓŁKA ..., ŚLĄSKA 35/37, 81-310 GDYNIA"
  72. // })
  73. // options.push({
  74. // ID: 601900,
  75. // nazwa: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ",
  76. // krs: "0000721708", nip: "9452218050", regon: "369608402",
  77. // S_kraj: "POLSKA", S_miejscowosc: "KRAKÓW", A_kod: "31-315", A_ulica: "ELIASZA RADZIKOWSKIEGO", A_nrLokalu: "16", A_nrDomu: "74",
  78. // searchLabel: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW 0000721708 9452218050 369608402",
  79. // label: "BIZNESLIMIT.PL ..., ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW"
  80. // })
  81. // this.setState({ isSearching: false, options: options });
  82. // }.bind(this), 1000);
  83. makeAndHandleRequest(query)
  84. .then(({ options }) => {
  85. this.setState({
  86. isLoading: false,
  87. options,
  88. });
  89. });
  90. },
  91. componentWillUnmount: function () {
  92. DBG && console.log("DBG: conponentDidUnmount...");
  93. },
  94. render: function () {
  95. // '<div>' +
  96. // '<p style="text-align:center">' + 'Wybierz bazę' + '</p>' +
  97. // '<div>' + .join(' ') + '</div>' +
  98. // +
  99. // '</div>',
  100. var bazaBtns = [];
  101. bazaBtns.push({ baza: "default_db/BI_audit_KRS/BI_audit_KRS", title: "KRS - Firmy", label: "KRS" });
  102. bazaBtns.push({ baza: "default_db/BI_audit_KRS_person/BI_audit_KRS_person", title: "KRS - Osoby", label: "KRS/p" });
  103. bazaBtns.push({ baza: "default_db/BI_audit_MSIG/BI_audit_MSIG", title: "MSIG - Firmy", label: "MSIG" });
  104. bazaBtns.push({ baza: "default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", title: "KRS - Osoby", label: "MSIG/p" });
  105. bazaBtns.push({ baza: "default_db/BI_audit_taxpayer/BI_audit_taxpayer", title: "VAT - Aktywni płatnicy", label: "VATp" });
  106. bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" });
  107. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY", title: "RUM Umowy", label: "RUM/u" });
  108. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "RUM Kontrahenci", label: "RUM/k" });
  109. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY", title: "Faktury - do imoportowania", label: "Faktury" });
  110. var newItemBtns = [];
  111. newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY", title: "Nowa osoba", label: "Nowa osoba" });
  112. newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "Nowy podmiot", label: "Nowy podmiot" });
  113. function generateBazaBtn(btn, opts) {
  114. return h('button', {
  115. title: btn.title,
  116. className: "btn btn-success" + (opts.selected ? " active" : ""),
  117. style: { margin: "3px" },
  118. onClick: function () {
  119. opts.onClick(btn.baza)
  120. },
  121. }, btn.label)
  122. }
  123. function generateNewItemBtn(btn, opts) {
  124. return h('button', {
  125. title: btn.title,
  126. className: "btn btn-success" + (opts.selected ? " active" : ""),
  127. style: { margin: "3px" },
  128. onClick: function () {
  129. opts.onClick(btn.baza)
  130. },
  131. }, btn.label)
  132. }
  133. var handleSelectBaza = this._handleSelectBaza.bind(this);
  134. var handleSelectNewItem = this._handleSelectNewItem.bind(this);
  135. var selectedBaza = this.state.baza;
  136. var selectedNewItem = this.state.newItemBaza;
  137. var selectedLabel = '';
  138. if (selectedBaza) {
  139. var selBazaBtn = bazaBtns.filter(function (btn) { return btn.baza === selectedBaza; })
  140. if (selBazaBtn) {
  141. selBazaBtn[0].title
  142. }
  143. }
  144. var handleSearch = this._handleSearch.bind(this);
  145. var handleSelected = this._handleSelected.bind(this);
  146. return h('div', {}, [
  147. h('p', { style: { textAlign: "center" } }, "Wybierz bazę"),
  148. h('div', { style: { marginBottom: '22px' } },
  149. bazaBtns.map(function (btn) {
  150. return generateBazaBtn(btn, {
  151. onClick: handleSelectBaza,
  152. selected: (selectedBaza === btn.baza),
  153. });
  154. }).concat(
  155. newItemBtns.map(function (btn) {
  156. return generateNewItemBtn(btn, {
  157. onClick: handleSelectNewItem,
  158. selected: (selectedNewItem === btn.baza),
  159. });
  160. })
  161. )
  162. ),
  163. selectedBaza && h(AsyncTypeahead, {
  164. isLoading: this.state.isSearching,
  165. allowNew: false,
  166. multiple: false,
  167. options: this.state.options,
  168. labelKey: "searchLabel",
  169. minLength: 2,
  170. onSearch: handleSearch,
  171. placeholder: "Wyszukaj...",
  172. onChange: handleSelected,
  173. autoFocus: true,
  174. // filterBy: function (option, text) {
  175. // console.log('TODO: filterBy...', {option, text});
  176. // return true;
  177. // },
  178. renderMenuItemChildren: function (option, props) {
  179. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  180. }
  181. }),
  182. selectedNewItem && h('p', {}, "Dodaj nowy ... " + selectedNewItem),
  183. //TODO dlaczego to nie działa
  184. // selectedNewItem && h('div', {className='form-group'},[
  185. // h('input',{
  186. // className:'form-control required',
  187. // id:'personName',
  188. // placeholder:'Imię'
  189. // }),
  190. // h('input',{
  191. // className:'form-control required',
  192. // id:'personSurname',
  193. // placeholder:'Nazwisko'
  194. // },[]),
  195. // h('input',{
  196. // className:'form-control required',
  197. // id:'personNip',
  198. // placeholder:'NIP'
  199. // },[]),
  200. // h('input',{
  201. // className:'form-control required',
  202. // id:'personPesel',
  203. // placeholder:'personPesel'
  204. // },[]),
  205. // h('input',{
  206. // className:'form-control required',
  207. // id:'personRegon',
  208. // placeholder:'REGON'
  209. // },[])
  210. // ]
  211. // ),
  212. // '' === selectedNewItem && h
  213. (selectedBaza && this.state.selected) && h('div', { style: { marginTop: '22px' } }, [
  214. h('button', {
  215. className: "btn btn-success active",
  216. onClick: function () {
  217. this.props.onSelect(this.state.baza, this.state.selected);
  218. ReactDOM.unmountComponentAtNode(document.getElementById('createPracownikAjax__searchBaza'));
  219. swal.close()
  220. }
  221. }, "Dodaj")
  222. ])
  223. ])
  224. }
  225. })
  226. function getWindowWidth() {
  227. var w = window, d = document,
  228. e = d.documentElement,
  229. g = d.getElementsByTagName('body')[0];
  230. return w.innerWidth || e.clientWidth || g.clientWidth;
  231. }
  232. function createPracownikAjax(event) {
  233. // default_db/BI_audit_KRS/BI_audit_KRS
  234. // default_db/BI_audit_KRS_person/BI_audit_KRS_person
  235. // default_db/BI_audit_MSIG/BI_audit_MSIG
  236. // default_db/BI_audit_MSIG_person/BI_audit_MSIG_person
  237. // default_db/BI_audit_taxpayer/BI_audit_taxpayer
  238. // default_db/BI_audit_CEIDG/BI_audit_CEIDG
  239. // default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY
  240. // default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI
  241. // default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY
  242. swal({
  243. title: "Dodaj osobę lub podmiot",
  244. width: (getWindowWidth() * 0.8),
  245. html: '<div id="createPracownikAjax__searchBaza" style="padding:0 24px 24px 24px"></div>',
  246. animation: false,
  247. showConfirmButton: false,
  248. showCancelButton: false,
  249. showCloseButton: true,
  250. onOpen: function () {
  251. ReactDOM.render(
  252. h(P5UI_AddItemToReport, {
  253. onSelect: function (baza, selected) {
  254. //insert do tabeli BI_audit_ENERGA_PRACOWNICY
  255. console.log('TODO: selected ', { baza, selected });
  256. }
  257. }),
  258. document.getElementById('createPracownikAjax__searchBaza')
  259. )
  260. }
  261. }).catch(function (err) {
  262. DBG && console.log('err', err)
  263. })
  264. }
  265. global.createPracownikAjax = createPracownikAjax;
  266. // module.exports = {
  267. // P5UI_AddItemToReport_BazaMenuItem,
  268. // P5UI_AddItemToReport,
  269. // createPracownikAjax
  270. // }