Bocian.php.addItemToRaport.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. //Baza= this.state.baza;
  34. setTimeout(function () {
  35. var options = [];
  36. options.push({
  37. ID: 601900,
  38. nazwa: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA",
  39. krs: "0000721712", nip: "5862328735", regon: "369609850",
  40. S_kraj: "POLSKA", S_miejscowosc: "GDYNIA", A_kod: "81-310", A_ulica: "ŚLĄSKA", A_nrDomu: "35/37",
  41. searchLabel: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA, ŚLĄSKA 35/37, 81-310 GDYNIA, krs: 0000721712, nip: 5862328735, regon: 369609850",
  42. label: "ADEGROUP SPÓŁKA ..., ŚLĄSKA 35/37, 81-310 GDYNIA"
  43. })
  44. options.push({
  45. ID: 601900,
  46. nazwa: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ",
  47. krs: "0000721708", nip: "9452218050", regon: "369608402",
  48. S_kraj: "POLSKA", S_miejscowosc: "KRAKÓW", A_kod: "31-315", A_ulica: "ELIASZA RADZIKOWSKIEGO", A_nrLokalu: "16", A_nrDomu: "74",
  49. searchLabel: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW 0000721708 9452218050 369608402",
  50. label: "BIZNESLIMIT.PL ..., ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW"
  51. })
  52. this.setState({ isSearching: false, options: options });
  53. }.bind(this), 1000);
  54. // makeAndHandleRequest(query)
  55. // .then(({ options }) => {
  56. // this.setState({
  57. // isLoading: false,
  58. // options,
  59. // });
  60. // });
  61. },
  62. componentWillUnmount: function () {
  63. DBG && console.log("DBG: conponentDidUnmount...");
  64. },
  65. render: function () {
  66. // '<div>' +
  67. // '<p style="text-align:center">' + 'Wybierz bazę' + '</p>' +
  68. // '<div>' + .join(' ') + '</div>' +
  69. // +
  70. // '</div>',
  71. var bazaBtns = [];
  72. bazaBtns.push({ baza: "default_db/BI_audit_KRS/BI_audit_KRS", title: "KRS - Firmy", label: "KRS" });
  73. bazaBtns.push({ baza: "default_db/BI_audit_KRS_person/BI_audit_KRS_person", title: "KRS - Osoby", label: "KRS/p" });
  74. bazaBtns.push({ baza: "default_db/BI_audit_MSIG/BI_audit_MSIG", title: "MSIG - Firmy", label: "MSIG" });
  75. bazaBtns.push({ baza: "default_db/BI_audit_MSIG_person/BI_audit_MSIG_person", title: "KRS - Osoby", label: "MSIG/p" });
  76. bazaBtns.push({ baza: "default_db/BI_audit_taxpayer/BI_audit_taxpayer", title: "VAT - Aktywni płatnicy", label: "VATp" });
  77. bazaBtns.push({ baza: "default_db/BI_audit_CEIDG/BI_audit_CEIDG", title: "CEIDG", label: "CEIDG" });
  78. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY", title: "RUM Umowy", label: "RUM/u" });
  79. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "RUM Kontrahenci", label: "RUM/k" });
  80. // bazaBtns.push({ baza: "default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY", title: "Faktury - do imoportowania", label: "Faktury" });
  81. var newItemBtns = [];
  82. newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY", title: "Nowa osoba", label: "Nowa osoba" });
  83. newItemBtns.push({ baza: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI", title: "Nowy podmiot", label: "Nowy podmiot" });
  84. function generateBazaBtn(btn, opts) {
  85. return h('button', {
  86. title: btn.title,
  87. className: "btn btn-success" + (opts.selected ? " active" : ""),
  88. style: { margin: "3px" },
  89. onClick: function () {
  90. opts.onClick(btn.baza)
  91. },
  92. }, btn.label)
  93. }
  94. function generateNewItemBtn(btn, opts) {
  95. return h('button', {
  96. title: btn.title,
  97. className: "btn btn-success" + (opts.selected ? " active" : ""),
  98. style: { margin: "3px" },
  99. onClick: function () {
  100. opts.onClick(btn.baza)
  101. },
  102. }, btn.label)
  103. }
  104. var handleSelectBaza = this._handleSelectBaza.bind(this);
  105. var handleSelectNewItem = this._handleSelectNewItem.bind(this);
  106. var selectedBaza = this.state.baza;
  107. var selectedNewItem = this.state.newItemBaza;
  108. var selectedLabel = '';
  109. if (selectedBaza) {
  110. var selBazaBtn = bazaBtns.filter(function (btn) { return btn.baza === selectedBaza; })
  111. if (selBazaBtn) {
  112. selBazaBtn[0].title
  113. }
  114. }
  115. var handleSearch = this._handleSearch.bind(this);
  116. var handleSelected = this._handleSelected.bind(this);
  117. return h('div', {}, [
  118. h('p', { style: { textAlign: "center" } }, "Wybierz bazę"),
  119. h('div', { style: { marginBottom: '22px' } },
  120. bazaBtns.map(function (btn) {
  121. return generateBazaBtn(btn, {
  122. onClick: handleSelectBaza,
  123. selected: (selectedBaza === btn.baza),
  124. });
  125. }).concat(
  126. newItemBtns.map(function (btn) {
  127. return generateNewItemBtn(btn, {
  128. onClick: handleSelectNewItem,
  129. selected: (selectedNewItem === btn.baza),
  130. });
  131. })
  132. )
  133. ),
  134. selectedBaza && h(AsyncTypeahead, {
  135. isLoading: this.state.isSearching,
  136. allowNew: false,
  137. multiple: false,
  138. options: this.state.options,
  139. labelKey: "searchLabel",
  140. minLength: 2,
  141. onSearch: handleSearch,
  142. placeholder: "Wyszukaj...",
  143. onChange: handleSelected,
  144. autoFocus: true,
  145. // filterBy: function (option, text) {
  146. // console.log('TODO: filterBy...', {option, text});
  147. // return true;
  148. // },
  149. renderMenuItemChildren: function (option, props) {
  150. return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
  151. }
  152. }),
  153. selectedNewItem && h('p', {}, "Dodaj nowy ... " + selectedNewItem),
  154. // '' === selectedNewItem && h
  155. (selectedBaza && this.state.selected) && h('div', { style: { marginTop: '22px' } }, [
  156. h('button', {
  157. className: "btn btn-success active",
  158. onClick: function () {
  159. //this.props.onSelect(this.state.baza, this.state.selected)
  160. ReactDOM.unmountComponentAtNode(document.getElementById('createPracownikAjax__searchBaza'));
  161. swal.close()
  162. }
  163. }, "Dodaj")
  164. ])
  165. ])
  166. }
  167. })
  168. function getWindowWidth() {
  169. var w = window, d = document,
  170. e = d.documentElement,
  171. g = d.getElementsByTagName('body')[0];
  172. return w.innerWidth || e.clientWidth || g.clientWidth;
  173. }
  174. function createPracownikAjax(event) {
  175. // default_db/BI_audit_KRS/BI_audit_KRS
  176. // default_db/BI_audit_KRS_person/BI_audit_KRS_person
  177. // default_db/BI_audit_MSIG/BI_audit_MSIG
  178. // default_db/BI_audit_MSIG_person/BI_audit_MSIG_person
  179. // default_db/BI_audit_taxpayer/BI_audit_taxpayer
  180. // default_db/BI_audit_CEIDG/BI_audit_CEIDG
  181. // default_db/BI_audit_ENERGA_RUM_UMOWY/BI_audit_ENERGA_RUM_UMOWY
  182. // default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI
  183. // default_db/BI_audit_ENERGA_FAKTURY/BI_audit_ENERGA_FAKTURY
  184. swal({
  185. title: "Dodaj osobę lub podmiot",
  186. width: (getWindowWidth() * 0.8),
  187. html: '<div id="createPracownikAjax__searchBaza" style="padding:0 24px 24px 24px"></div>',
  188. animation: false,
  189. showConfirmButton: false,
  190. showCancelButton: false,
  191. showCloseButton: true,
  192. onOpen: function () {
  193. ReactDOM.render(
  194. h(P5UI_AddItemToReport, {
  195. onSelect: function (baza, selected) {
  196. //insert do tabeli BI_audit_ENERGA_PRACOWNICY
  197. console.log('TODO: selected ', { baza, selected });
  198. }
  199. }),
  200. document.getElementById('createPracownikAjax__searchBaza')
  201. )
  202. }
  203. }).catch(function (err) {
  204. DBG && console.log('err', err)
  205. })
  206. }
  207. global.createPracownikAjax = createPracownikAjax;
  208. // module.exports = {
  209. // P5UI_AddItemToReport_BazaMenuItem,
  210. // P5UI_AddItemToReport,
  211. // createPracownikAjax
  212. // }