Bocian.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. <?php
  2. Lib::loadClass('RouteToolBase');
  3. Lib::loadClass('UI');
  4. Lib::loadClass('Response');
  5. // index.php?_route=UrlAction_BiAuditRaport - uruchamia defaultAction
  6. class Bocian extends RouteToolBase {
  7. public function defaultAction() {
  8. UI::gora();
  9. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  10. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  11. Theme::top();
  12. //echo '<div id="smad-wrapper">'; // todo: sprawdzi czy można usunać
  13. echo '<div class="container-bi_audit_form_pracownicy_raport" style="display: none;"></div>';
  14. echo '<div class="container-bi_audit_form_kontrahenci_raport" style="display: none;"></div>';
  15. // echo '<div class="container-bi_audit_form_raport_data" style="display: none;"></div>';
  16. UI::inlineJS(__FILE__ . '.view.js', [
  17. 'URL_FETCH_KONTRAHENCI_POWIAZANIA' => $this->getLink('fetchEnergaRumKontrahenciPowiazaniaAjax'),
  18. 'URL_FETCH_TEST_KRS' => $this->getLink('fetchTestKrsAjax'),
  19. 'URL_FETCH_TEST_CEIDG' => $this->getLink('fetchTestCeidgAjax'),
  20. 'URL_FETCH_PRACOWNICY' => $this->getLink('fetchPracownicyAjax'),
  21. 'URL_FETCH_KONTRAHENCI' => $this->getLink('fetchKontrahenciAjax'),
  22. 'URL_CREATE_PRACOWNICY_GROUP' => $this->getLink('createPracownicyGroupAjax'),
  23. 'URL_CREATE_KONTRAHENCIS_GROUP' => $this->getLink('createKontrahenciGroupAjax'),
  24. 'URL_ADD_PRACOWNICY_TO_GROUP' => $this->getLink('addPracownicyToGroupAjax'),
  25. 'URL_ADD_KONTRAHENCI_TO_GROUP' => $this->getLink('addKontrahenciToGroupAjax'),
  26. 'URL_FETCH_GROUP_PRACOWNICY' => $this->getLink('fetchGroupPracownicyAjax'),
  27. 'URL_FETCH_GROUP_KONTRAHENCI' => $this->getLink('fetchGroupKontrahenciAjax'),
  28. 'URL_GENERATE_BI_AUDIT_RAPORT_AJAX' => $this->getLink('generateBiAuditRaportAjax'),
  29. 'DBG' => V::get('DBG', 0, $_GET),
  30. 'VIEW_KONTRAHENCI' => $this->defaultViewFormBiAudit([], 'KONTRAHENCI'),
  31. 'VIEW_PRACOWNICY' => $this->defaultViewFormBiAudit([], 'PRACOWNICY'),
  32. 'URL_PARSE_CSV_FILE_AJAX' => $this->getLink('parseCsvFileAjax'),
  33. 'URL_SAVE_FORM_CSV_FILE_AJAX' => $this->getLink('saveFormCsvFileAjax'),
  34. ]);
  35. echo '</div>'; // #smad-wrapper
  36. UI::dol();
  37. }
  38. /**
  39. * Funkcja ajax do odebrania danych z przesłanego pliku CSV do parsowania
  40. */
  41. public function parseCsvFileAjaxAction() {
  42. Response::sendTryCatchJson(array($this, 'parseCsvFileAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  43. }
  44. /**
  45. * Funkcja parsuje dane wgrywanego plku csv
  46. */
  47. public function parseCsvFileAjax() {
  48. if (!file_exists($_FILES['file']['tmp_name'])) throw new Exception("Wybierz plik do przesłania.");
  49. $file = file($_FILES['file']['tmp_name']);
  50. // nagłowki csv
  51. $headCsv = array();
  52. // wiersze CSV(poza pierwszym)
  53. $arrayRows = array();
  54. $i = 0;
  55. $viewFormHtml = '<div id="smad-window-modal" style="overflow-x: scroll;"><form method="POST" id="formDataFromCsv" >';
  56. foreach ($file as $line) {
  57. if ( $i == 0 ) {
  58. $headCsv = explode(';', $line);
  59. } else {
  60. $arrayRows = explode(';', $line);
  61. $viewFormHtml .= '<div style="margin: 10px 0"><span>'.$i.'. </span>';
  62. foreach ($arrayRows as $keyData => $rowData) {
  63. // sprawdzenie czy ustawiony naglówek - jeśli nie to wyświetl komunikat
  64. // if ($headCsv[$keyData]) throw new Exception("Brak nagłówka w kolumnie " . ($keyData + 1) . "w pliku CSV.");
  65. // usuwamy puste znaki i znaki od nowej linii
  66. $rowData = trim(str_replace(array("\n", "\r", "\r\n", "\n\r"), ' ', $rowData));
  67. $nameValue = trim(str_replace(array("\n", "\r", "\r\n", "\n\r"), ' ', $headCsv[$keyData]));
  68. // utworzenie inputa do edycji
  69. $viewFormHtml .= "<input type='text' name='item[$i][$nameValue]' value='".str_replace('"', '', $rowData )."' />";
  70. }
  71. $viewFormHtml .= '</div><div style="margin: 20px 0;"></div>';
  72. }
  73. $i++;
  74. }
  75. $viewFormHtml .= '</form></div>';
  76. //return $viewFormHtml;
  77. return [
  78. 'type' => 'success',
  79. 'msg' => 'OK',
  80. '__req_args' => $_REQUEST,
  81. '__args' => $args,
  82. 'body' => [
  83. 'view' => $viewFormHtml,
  84. ]
  85. ];
  86. // if (!isset($_FILES['fileData'])) throw new Exception("Błąd formularza ");
  87. }
  88. /**
  89. * Funkcja ajax do odebrania danych z przesłanego formularza z parsowanego CSV
  90. */
  91. public function saveFormCsvFileAjaxAction() {
  92. Response::sendTryCatchJson(array($this, 'saveFormCsvFileAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  93. Response::sendTryCatchJson(array($this, 'saveFormCsvFileAjax'));
  94. }
  95. /**
  96. * Funkcja ajax do zapisania danych z przesłanego formularza z parsowanego CSV
  97. */
  98. public function saveFormCsvFileAjax($args) {
  99. $formData = V::get('formData', '', $args);
  100. parse_str($formData, $resultArrayFormdata);
  101. //$formData = V::get('formData', '', $_REQUEST, '');
  102. print_r($resultArrayFormdata);
  103. //print_r($formData);
  104. //todo: dane do zapisania z formularza
  105. }
  106. public function fetchEnergaRumKontrahenciPowiazaniaAjaxAction() {
  107. Response::sendTryCatchJson(array($this, 'fetchEnergaRumKontrahenciPowiazaniaAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  108. }
  109. public function fetchEnergaRumKontrahenciPowiazaniaAjax($args) {
  110. $id = V::get('ID', 26, $_REQUEST, 'int');
  111. $items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA')->buildQuery([
  112. 'cols' => [ // TODO:? propertyName = []
  113. 'ID',
  114. 'A_ADM_COMPANY',
  115. 'L_APPOITMENT_USER',
  116. 'A_CLASSIFIED',
  117. 'A_STATUS',
  118. 'A_STATUS_INFO',
  119. 'BI_analiza_maxDepth',
  120. 'BI_analiza_minDepth',
  121. 'BI_analiza_onlyTargets',
  122. 'BI_analiza_reloadCache',
  123. 'FILE_STATUS',
  124. 'FILE_STATUS_info',
  125. 'L_APPOITMENT_USER',
  126. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  127. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  128. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  129. 'default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person',
  130. ],
  131. 'f_ID' => "{$id}",
  132. ])->getItems([
  133. 'limit' => 10
  134. ]);
  135. // $items = [
  136. // [ 'ID' => 1, 'L_APPOITMENT_INFO' => 'x', 'BI_analiza_depth' => 'a', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test1'],
  137. // [ 'ID' => 2, 'L_APPOITMENT_INFO' => 'y', 'BI_analiza_depth' => 'b', 'FILE_STATUS' => 0, 'FILE_STATUS_info' => 'test2'],
  138. // [ 'ID' => 3, 'L_APPOITMENT_INFO' => 'z', 'BI_analiza_depth' => 'c', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test3'],
  139. // ];
  140. return [
  141. 'type' => 'success',
  142. 'msg' => 'OK',
  143. '__req_args' => $_REQUEST,
  144. '__args' => $args,
  145. 'body' => [
  146. 'items' => $items,
  147. 'view' => $this->showPowiazaniaEnergaRumKontrahenciPowiazania($items),
  148. ]
  149. ];
  150. }
  151. public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
  152. $view = '<form class="form-horizontal" method="post">
  153. <table class="table table-bordered table-hover table-striped" height=5>
  154. <thead>
  155. <tr style="">
  156. <td width=1><input type="checkbox" name="checkAll" id="checkAll" /></td>
  157. <td width=1>ID</td>
  158. <td>Adnotacje</td>
  159. <td>Głębokość analizy</td>
  160. <td>Status raportu</td>
  161. <td>Status raportu - informacje</td>
  162. </tr>
  163. </thead>
  164. <tbody>
  165. ';
  166. foreach ($items as $key => $row) {
  167. $view .= '<tr>
  168. <td><input type="checkbox" name="prID[]" value="'.$row['ID'].'" onClick="checkAll()"/></td>
  169. <td align="right">'.$row["ID"].'</td>
  170. <td align="right">'.$row["L_APPOITMENT_INFO"].'</td>
  171. <td align="right">'.$row["BI_analiza_depth"].'</td>
  172. <td align="right">'.$row["FILE_STATUS"].'</td>
  173. <td align="right">'.$row["FILE_STATUS_info"].'</td>';
  174. }
  175. $view .= '</tbody></table></form>';
  176. return $view;
  177. }
  178. public function fetchTestKrsAjaxAction() {
  179. Response::sendTryCatchJson(array($this, 'fetchTestKrsAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  180. }
  181. public function fetchTestKrsAjax($args) {
  182. $id = V::get('ID', 1, $_REQUEST, 'int');
  183. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery([
  184. 'cols' => [ // TODO:? propertyName = []
  185. 'A_kod',
  186. 'A_kraj',
  187. 'A_miejscowosc',
  188. 'A_nrDomu',
  189. 'A_nrLokalu',
  190. 'A_poczta',
  191. 'A_ulica',
  192. 'ID',
  193. 'S_gmina',
  194. 'S_kraj',
  195. 'S_miejscowosc',
  196. 'S_powiat',
  197. 'S_wojewodztwo',
  198. 'dataDokumentu',
  199. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  200. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  201. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  202. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  203. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  204. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  205. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  206. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  207. 'krs',
  208. 'nazwa',
  209. 'nip',
  210. 'regon',
  211. ],
  212. 'f_ID' => "{$id}",
  213. ])->getItems([
  214. 'limit' => 10
  215. ]);
  216. return [
  217. 'type' => 'success',
  218. 'msg' => 'KRS',
  219. '__req_args' => $_REQUEST,
  220. '__args' => $args,
  221. 'body' => [
  222. 'items' => $items,
  223. ]
  224. ];
  225. }
  226. public function fetchTestCeidgAjaxAction() {
  227. Response::sendTryCatchJson(array($this, 'fetchTestCeidgAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  228. }
  229. public function fetchTestCeidgAjax($args) {
  230. $id = V::get('ID', 0, $_REQUEST, 'int');
  231. $items = ACL::getAclByNamespace('default_db/BI_audit_CEIDG/BI_audit_CEIDG')->buildQuery([
  232. 'cols' => [ // TODO:? propertyName = []
  233. 'ID',
  234. 'budynek',
  235. 'firma',
  236. 'gmina',
  237. 'identyfikatorWpisu',
  238. 'imie',
  239. 'kodPocztowy',
  240. 'kraj',
  241. 'lokal',
  242. 'miejscowosc',
  243. 'nazwisko',
  244. 'nip',
  245. 'poczta',
  246. 'powiat',
  247. 'regon',
  248. 'ulica',
  249. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ID',
  250. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/budynek',
  251. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/gmina',
  252. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/kodPocztowy',
  253. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/lokal',
  254. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/miejscowosc',
  255. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nazwa',
  256. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nip',
  257. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/poczta',
  258. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/powiat',
  259. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ulica',
  260. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/wojewodztwo',
  261. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/ID',
  262. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/nip',
  263. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/regon',
  264. ],
  265. // 'f_ID' => $id,
  266. ])->getItems([
  267. 'limit' => 10
  268. ]);
  269. return [
  270. 'type' => 'success',
  271. 'msg' => 'CEIDG',
  272. '__req_args' => $_REQUEST,
  273. '__args' => $args,
  274. 'body' => [
  275. 'items' => $items,
  276. ]
  277. ];
  278. }
  279. /**
  280. * KONTRAHENCI
  281. */
  282. public function fetchKontrahenciAjaxAction() {
  283. Response::sendTryCatchJson(array($this, 'fetchKontrahenciAjax'));
  284. }
  285. public function fetchKontrahenciAjax($args) {
  286. $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  287. if ($idGroup < 0) $idGroup = 0;
  288. $limit = 5;
  289. $limitstart = V::get('limitstart', 0, $_REQUEST, 'int');
  290. if ($limitstart < 0) $limitstart = 0;
  291. $page = V::get('page', 0, $_REQUEST, 'int');
  292. $limitstart = ($page - 1) * $limit;
  293. $search = V::get('search', '', $_REQUEST);
  294. $searchParams = [];
  295. if (!empty($search)) {
  296. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  297. $searchParams['ogc:Filter'] = '
  298. <ogc:Filter>
  299. <ogc:Or>
  300. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  301. <ogc:PropertyName>NIP</ogc:PropertyName>
  302. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  303. </ogc:PropertyIsLike>
  304. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  305. <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
  306. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  307. </ogc:PropertyIsLike>
  308. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  309. <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
  310. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  311. </ogc:PropertyIsLike>
  312. </ogc:Or>
  313. </ogc:Filter>
  314. ';
  315. }
  316. $backRefFilter = [];
  317. if ($idGroup > 0) {
  318. $backRefFilter['__backRef'] = [
  319. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_KONTRAHENCIS_GRUPY', // TODO: nowy rejetr na grupy / filty KONTRAHENCI
  320. 'primaryKey' => $idGroup,
  321. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_KONTRAHENCIS',
  322. ];
  323. // TODO: Storage dodać obiekt xsd default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY:
  324. // - ID
  325. // - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
  326. // - NAZWA - nazwa grupy
  327. // - 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_KONTRAHENCI' minOccurs="0" maxOccurs="unbounded"
  328. }
  329. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  330. $query = $acl->buildQuery(array_merge([
  331. 'cols' => [ // TODO:? propertyName = []
  332. 'ID',
  333. 'Nazwa_grupy_kapitalowej',
  334. 'Pelna_nazwa_kontrahenta',
  335. 'Numer_kontrahenta',
  336. 'Skrocona_Nazwa_Kontrahenta',
  337. 'Typ_kontrahenta',
  338. 'NIP',
  339. 'KRS',
  340. 'REGON',
  341. 'PESEL',
  342. 'Forma_prawna_dzialalnosci',
  343. 'Ulica',
  344. 'Numer_budynku',
  345. 'Numer_mieszkania_lokalu',
  346. 'Miejscowosc',
  347. 'Kod_pocztowy',
  348. 'Kraj',
  349. 'Telefon',
  350. 'Fax',
  351. 'Mail',
  352. 'A_ADM_COMPANY',
  353. 'A_CLASSIFIED',
  354. 'A_STATUS',
  355. 'A_STATUS_INFO',
  356. 'Dodano',
  357. 'L_APPOITMENT_USER',
  358. 'Podmiot_dominujacy',
  359. 'Tytul_dokumentu',
  360. 'ownCompany',
  361. 'uwagi',
  362. ],
  363. //'f_ID' => $id,
  364. 'limit' => $limit,
  365. 'limitstart' => $limitstart, // offset
  366. ], $searchParams, $backRefFilter));
  367. $total = $query->getTotal();
  368. $items = $query->getItems();
  369. $pagination = array();
  370. $pagination['total_items'] = $total;
  371. $pagination['size'] = ceil($total/$limit); // pages size
  372. $pagination['current'] = $page;
  373. $pagination['limit'] = $limit;
  374. return [
  375. 'type' => 'success',
  376. 'msg' => 'showKontrajenci',
  377. '__req_args' => $_REQUEST,
  378. '__args' => $args,
  379. 'body' => [
  380. 'items' => $items,
  381. //'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI'),
  382. 'pagination' => $pagination
  383. ]
  384. ];
  385. }
  386. //
  387. // public function fetchKontrahenciAjaxOld($args) {
  388. // //$id = V::get('ID', 1, $_REQUEST, 'int');
  389. // $items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI')->buildQuery([
  390. // 'cols' => [ // TODO:? propertyName = []
  391. // 'ID',
  392. // 'Nazwa_grupy_kapitalowej',
  393. // 'Pelna_nazwa_kontrahenta',
  394. // 'NIP',
  395. // 'KRS',
  396. // 'REGON',
  397. // 'Miejscowosc',
  398. // 'Kod_pocztowy',
  399. // 'Telefon'
  400. // ],
  401. // //'f_ID' => $id,
  402. // ])->getItems([
  403. // 'limit' => 10
  404. // ]);
  405. //
  406. // return [
  407. // 'type' => 'success',
  408. // 'msg' => 'showKontrahenci',
  409. // '__req_args' => $_REQUEST,
  410. // '__args' => $args,
  411. // 'body' => [
  412. // 'items' => $items,
  413. // 'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI')
  414. // ]
  415. // ];
  416. // }
  417. public function showTableKontrahenci($items) {
  418. $view = '<form class="form-horizontal" method="post">
  419. <table class="table table-bordered table-hover table-striped" height=5>
  420. <thead>
  421. <tr>
  422. <td width=1><input type="checkbox" name="checkAll" id="checkAll-KONTRAHENCI" /></td>
  423. <td width=1>ID</td>
  424. <td>Nazwa grupy kapitalowej</td>
  425. <td>Pelna nazwa kontrahenta</td>
  426. <td>Numer kontrahenta</td>
  427. <td>Skrócona nazwa kontrahenta</td>
  428. <td>Typ_kontrahenta</td>
  429. <td>NIP</td>
  430. <td>KRS</td>
  431. <td>Regon</td>
  432. <td>PESEL</td>
  433. <td>Forma prawna działalności</td>
  434. <td>Ulica</td>
  435. <td>Numer budynku</td>
  436. <td>Numer mieszkania lokalu</td>
  437. <td>Miejscowosc</td>
  438. <td>Kod pocztowy</td>
  439. <td>Kraj</td>
  440. <td>Telefon</td>
  441. <td>Fax</td>
  442. <td>Mail</td>
  443. <td>A_ADM_COMPANY</td>
  444. <td>A_CLASSIFIED</td>
  445. <td>A_STATUS</td>
  446. <td>A_STATUS_INFO</td>
  447. <td>Dodano</td>
  448. <td>L_APPOITMENT_USER</td>
  449. <td>Podmiot dominujacy</td>
  450. <td>Tytul dokumentu</td>
  451. <td>ownCompany</td>
  452. <td>uwagi</td>
  453. </tr>
  454. </thead>
  455. <tbody id="body-kontrahenci">
  456. </tbody></table>
  457. </form>
  458. ';
  459. return $view;
  460. }
  461. // tworzenie grupy kontrahentów
  462. public function createKontrahenciGroupAjaxAction() {
  463. Response::sendTryCatchJson(array($this, 'createKontrahenciGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
  464. }
  465. public function createKontrahenciGroupAjax($args) {
  466. $nazwa = V::get('NAZWA', '', $args);
  467. // TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje
  468. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_KONTRAHENCI_GRUPY', [
  469. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  470. 'A_RECORD_CREATE_DATE' => 'NOW()',
  471. 'NAZWA' => $nazwa,
  472. ]);
  473. return [
  474. 'msg' => "Utworzona grupę {$idGroup}",
  475. 'type' => "success",
  476. 'body' => [
  477. 'id' => $idGroup,
  478. ]
  479. ];
  480. }
  481. // Dodanie do grupy filtra kontrahentów
  482. public function addKontrahenciToGroupAjaxAction() {
  483. // Response::sendTryCatchJson(array($this, 'addKontrahenciToGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
  484. Response::sendTryCatchJson(array($this, 'addKontrahenciToGroupAjax'));
  485. }
  486. public function addKontrahenciToGroupAjax($args) {
  487. $idGroup = V::get('idGroup', 0, $_REQUEST, 'int');
  488. $kontrahenciIds = V::get('kontrahenciIds', [], $_REQUEST, 'array');
  489. // validate
  490. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  491. if (!$kontrahenciIds || count($kontrahenciIds) == 0 ) throw new Exception("Proszę wybrać kontrahentów");
  492. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY')->buildQuery([
  493. 'cols' => [ // TODO:? propertyName = []
  494. 'ID',
  495. 'ID_USER',
  496. 'NAZWA',
  497. ],
  498. // 'f_ID_USER' => User::getID()
  499. ])->getItem($idGroup);
  500. if (!$group) throw new Exception("Grupa nie istnieje");
  501. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  502. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  503. $refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY',
  504. 'default_db__x3A__BI_audit_ENERGA_KONTRAHENCI:BI_audit_ENERGA_KONTRAHENCI');
  505. foreach ($kontrahenciIds as $kontrahentIds) {
  506. DB::getPDO()->insert($refGrupyToKontrahenci, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $kontrahentIds]);
  507. }
  508. return [
  509. 'msg' => "Powiązano kontrahentów z grupą {$idGroup}",
  510. 'type' => "success",
  511. ];
  512. }
  513. public function fetchGroupKontrahenciAjaxAction() {
  514. Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
  515. }
  516. public function fetchGroupKontrahenciAjax() {
  517. // TODO: odkomentować jak zostanie dodana tabela default_db/BI_audit_ENERGA_KONTRAHENCI_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY
  518. /*$group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY')->buildQuery([
  519. 'cols' => [ // TODO:? propertyName = []
  520. 'ID',
  521. 'ID_USER',
  522. 'NAZWA',
  523. ],
  524. 'f_ID_USER' => User::getID()
  525. ])->getItem($idGroup);
  526. if (!$group) throw new Exception("Grupa nie istnieje");
  527. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  528. $itemsKontrahenci = $query->getItems();
  529. $arrayGroupKontrahenci = array();
  530. foreach ($itemsKontrahenci as $key => $value) {
  531. $arrayGroupKontrahenci[$value['ID']] = $value['NAZWA'];
  532. }
  533. */
  534. //TODO: USUNAĆ listę grup wpisane na sztywno
  535. $arrayGroupKontrahenci = array();
  536. $arrayGroupKontrahenci[0]["ID"] = 1;
  537. $arrayGroupKontrahenci[0]["NAZWA"] = "Grupa 1";
  538. $arrayGroupKontrahenci[1]["ID"] = 2;
  539. $arrayGroupKontrahenci[1]["NAZWA"] = "Grupa 2";
  540. $arrayGroupKontrahenci[2]["ID"] = 3;
  541. $arrayGroupKontrahenci[2]["NAZWA"] = "Grupa 3";
  542. $arrayGroupKontrahenci[3]["ID"] = 4;
  543. $arrayGroupKontrahenci[3]["NAZWA"] = "Grupa 4";
  544. $arrayGroupKontrahenci[4]["ID"] = 5;
  545. $arrayGroupKontrahenci[4]["NAZWA"] = "Grupa 5";
  546. $arrayGroupKontrahenci[5]["ID"] = 6;
  547. $arrayGroupKontrahenci[5]["NAZWA"] = "Grupa 6";
  548. $arrayGroupKontrahenci[6]["ID"] = 7;
  549. $arrayGroupKontrahenci[6]["NAZWA"] = "Grupa 7";
  550. $arrayGroupKontrahenci[7]["ID"] = 8;
  551. $arrayGroupKontrahenci[7]["NAZWA"] = "Grupa 8";
  552. $arrayGroupKontrahenci[8]["ID"] = 9;
  553. $arrayGroupKontrahenci[8]["NAZWA"] = "Grupa 9";
  554. $arrayGroupKontrahenci[9]["ID"] = 10;
  555. $arrayGroupKontrahenci[9]["NAZWA"] = "Grupa 10";
  556. $arrayGroupKontrahenci[9]["ID"] = 11;
  557. $arrayGroupKontrahenci[9]["NAZWA"] = "Grupa 11";
  558. return [
  559. 'type' => 'success',
  560. 'msg' => 'fetchKontrahenciToGroup',
  561. '__req_args' => $_REQUEST,
  562. '__args' => $args,
  563. 'body' => [
  564. 'itemsGroupKontrahenci' => $arrayGroupKontrahenci
  565. ]
  566. ];
  567. }
  568. /*
  569. * PRACOWNICY
  570. */
  571. public function fetchPracownicyAjaxAction() {
  572. // sleep(2);
  573. Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'));
  574. }
  575. public function fetchPracownicyAjax($args) {
  576. $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  577. if ($idGroup < 0) $idGroup = 0;
  578. $limit = 2;
  579. $limitstart = V::get('limitstart', 0, $_REQUEST, 'int');
  580. if ($limitstart < 0) $limitstart = 0;
  581. $page = V::get('page', 0, $_REQUEST, 'int');
  582. $limitstart = ($page - 1) * $limit;
  583. $search = V::get('search', '', $_REQUEST);
  584. $searchParams = [];
  585. if (!empty($search)) {
  586. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  587. $searchParams['ogc:Filter'] = '
  588. <ogc:Filter>
  589. <ogc:Or>
  590. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  591. <ogc:PropertyName>nip</ogc:PropertyName>
  592. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  593. </ogc:PropertyIsLike>
  594. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  595. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  596. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  597. </ogc:PropertyIsLike>
  598. </ogc:Or>
  599. </ogc:Filter>
  600. ';
  601. }
  602. $backRefFilter = [];
  603. if ($idGroup > 0) {
  604. $backRefFilter['__backRef'] = [
  605. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY', // TODO: nowy rejetr na grupy / filty pracowników
  606. 'primaryKey' => $idGroup,
  607. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  608. ];
  609. // TODO: Storage dodać obiekt xsd default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY:
  610. // - ID
  611. // - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
  612. // - NAZWA - nazwa grupy
  613. // - 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY' minOccurs="0" maxOccurs="unbounded"
  614. }
  615. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  616. $query = $acl->buildQuery(array_merge([
  617. 'cols' => [ // TODO:? propertyName = []
  618. 'ID',
  619. 'imiona',
  620. 'nazwisko',
  621. 'nip',
  622. 'pesel',
  623. 'regon',
  624. 'source',
  625. 'A_ADM_COMPANY',
  626. 'A_CLASSIFIED',
  627. 'A_STATUS',
  628. 'A_STATUS_INFO',
  629. 'L_APPOITMENT_USER',
  630. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  631. ],
  632. //'f_ID' => $id,
  633. 'limit' => $limit,
  634. 'limitstart' => $limitstart, // offset
  635. // 'order_by' => 'ID', // sortowanie po kolumnie
  636. // 'order_dir' => 'DESC', // kierunek sortowania
  637. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  638. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  639. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  640. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  641. ], $searchParams, $backRefFilter));
  642. $total = $query->getTotal();
  643. $items = $query->getItems();
  644. $pagination = array();
  645. $pagination['total_items'] = $total;
  646. $pagination['size'] = ceil($total/$limit); // pages size
  647. $pagination['current'] = $page;
  648. $pagination['limit'] = $limit;
  649. // { // tworzenie własnego zapytanie mysql
  650. // $rootTableName = $acl->getRootTableName();
  651. // DB::getPDO()->fetchAll("
  652. // select t.*
  653. // from {$rootTableName} t
  654. // where t.ID in (
  655. // select x.ID
  656. // from ... x
  657. // where
  658. // )
  659. // ");
  660. // }
  661. return [
  662. 'type' => 'success',
  663. 'msg' => 'showPracownicy',
  664. '__req_args' => $_REQUEST,
  665. '__args' => $args,
  666. 'body' => [
  667. 'items' => $items,
  668. //'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
  669. 'pagination' => $pagination
  670. ]
  671. ];
  672. }
  673. public function showTablePracownicy() {
  674. $view = '<form class="form-horizontal" method="post">
  675. <table class="table table-responsive table-bordered table-hover table-striped" height=5>
  676. <thead>
  677. <tr>
  678. <td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
  679. <td width=1>ID</td>
  680. <td>Imię/Imiona</td>
  681. <td>Nazwisko</td>
  682. <td>NIP</td>
  683. <td>Pesel</td>
  684. <td>Regon</td>
  685. <td>source</td>
  686. <td>A_ADM_COMPANY</td>
  687. <td>A_CLASSIFIED</td>
  688. <td>A_STATUS</td>
  689. <td>A_STATUS_INFO</td>
  690. <td>L_APPOITMENT_USER</td>
  691. <td>Adresy</td>
  692. </tr>
  693. </thead>
  694. <tbody id="body-pracownicy">
  695. </tbody></table>
  696. </form>';
  697. return $view;
  698. }
  699. // tworzenie grupy pracowników
  700. public function createPracownicyGroupAjaxAction() {
  701. Response::sendTryCatchJson(array($this, 'createPracownicyGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
  702. // Response::sendTryCatchJson(array($this, 'createPracownicyGroupAjax'));
  703. }
  704. public function createPracownicyGroupAjax($args) {
  705. $nazwa = V::get('NAZWA', '', $args);
  706. // TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje
  707. // validate
  708. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  709. if (!$kontrahenciIds || count($kontrahenciIds) == 0 ) throw new Exception("Proszę wybrać kontrahentów");
  710. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_GRUPY', [
  711. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  712. 'A_RECORD_CREATE_DATE' => 'NOW()',
  713. // 'A_STATUS' => 'WAITING', // jeśli trzeba to ustawić
  714. 'NAZWA' => $nazwa,
  715. ]);
  716. // DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_GRUPY_HIST', [
  717. // 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  718. // 'A_RECORD_CREATE_DATE' => 'NOW()',
  719. // 'ID_USERS2' => $idRaport,
  720. // // 'A_STATUS' => 'WAITING', // jeśli trzeba to ustawić
  721. // 'NAZWA' => $nazwa,
  722. // ]);
  723. return [
  724. 'msg' => "Utworzona grupę {$idGroup}",
  725. 'type' => "success",
  726. 'body' => [
  727. 'id' => $idGroup,
  728. ]
  729. ];
  730. }
  731. // Dodanie do grupy filtra pracowników
  732. public function addPracownicyToGroupAjaxAction() {
  733. // Response::sendTryCatchJson(array($this, 'addPracownicyToGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
  734. Response::sendTryCatchJson(array($this, 'addPracownicyToGroupAjax'));
  735. }
  736. public function addPracownicyToGroupAjax($args) {
  737. $idGroup = V::get('idGroup', 0, $_REQUEST, 'int');
  738. $pracownicyIds = V::get('pracownicyIds', [], $_REQUEST, 'array');
  739. // validate
  740. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  741. if (!$pracownicyIds || count($pracownicyIds) == 0 ) throw new Exception("Proszę wybrać pracowników");
  742. // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
  743. // default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY
  744. // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
  745. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY')->buildQuery([
  746. 'cols' => [ // TODO:? propertyName = []
  747. 'ID',
  748. 'ID_USER',
  749. 'NAZWA',
  750. ],
  751. // 'f_ID_USER' => User::getID()
  752. ])->getItem($idGroup);
  753. if (!$group) throw new Exception("Grupa nie istnieje");
  754. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  755. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  756. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY',
  757. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  758. foreach ($pracownicyIds as $idPracownik) {
  759. DB::getPDO()->insert($refGrupyToPracownicy, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  760. }
  761. return [
  762. 'msg' => "Powiązano pracowników z grupą {$idGroup}",
  763. 'type' => "success",
  764. ];
  765. }
  766. public function fetchGroupPracownicyAjaxAction() {
  767. Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
  768. }
  769. public function fetchGroupPracownicyAjax() {
  770. // TODO: odkomentować jak zostanie dodana tabela default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY
  771. /*$group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY')->buildQuery([
  772. 'cols' => [ // TODO:? propertyName = []
  773. 'ID',
  774. 'ID_USER',
  775. 'NAZWA',
  776. ],
  777. 'f_ID_USER' => User::getID()
  778. ])->getItem($idGroup);
  779. if (!$group) throw new Exception("Grupa nie istnieje");
  780. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  781. $items = $query->getItems();
  782. $arrayGroupPracownicy = array();
  783. foreach ($items as $key => $value) {
  784. $arrayGroupPracownicy[$value['ID']] = $value['NAZWA'];
  785. }
  786. */
  787. //TODO: USUNAĆ listę grup wpisane na sztywno
  788. $arrayGroupPracownicy = array();
  789. $arrayGroupPracownicy[0]["ID"] = 1;
  790. $arrayGroupPracownicy[0]["NAZWA"] = "Grupa 1";
  791. $arrayGroupPracownicy[1]["ID"] = 2;
  792. $arrayGroupPracownicy[1]["NAZWA"] = "Grupa 2";
  793. $arrayGroupPracownicy[2]["ID"] = 3;
  794. $arrayGroupPracownicy[2]["NAZWA"] = "Grupa 3";
  795. $arrayGroupPracownicy[3]["ID"] = 4;
  796. $arrayGroupPracownicy[3]["NAZWA"] = "Grupa 4";
  797. $arrayGroupPracownicy[4]["ID"] = 5;
  798. $arrayGroupPracownicy[4]["NAZWA"] = "Grupa 5";
  799. return [
  800. 'type' => 'success',
  801. 'msg' => 'fetchGroupPracownicyAjax',
  802. '__req_args' => $_REQUEST,
  803. '__args' => $args,
  804. 'body' => [
  805. 'itmesGroupPracownicy' => $arrayGroupPracownicy
  806. ]
  807. ];
  808. }
  809. // link do ackji w php: $saveFormUrl = $this->getLink('saveRaportAjax');
  810. // przekazać link do JavaScript i tam:
  811. // window.fetch('{$saveFormUrl}', { ... }).then(...) - dokumentacja: https://github.com/github/fetch
  812. public function generateBiAuditRaportAjaxAction() {
  813. //Response::sendTryCatchJson(array($this, 'saveRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
  814. Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  815. //Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'));
  816. }
  817. public function generateBiAuditRaportAjax($args) {
  818. // głebokość powiazan
  819. $depthValue = V::get('depthValue', '', $args);
  820. if (!$depthValue) {
  821. throw new Exception("Nie podano wartości dla głębokości powiązań");
  822. }
  823. // Tworzenie relacji Raport do Pracownicy
  824. $pracownicyIds = []; // array z nr ID na podstawie wysłanego formularza
  825. $pracownicyIds = V::get('pracownicyIds', '', $args);
  826. // walidacja id pracowników
  827. if (!$pracownicyIds) {
  828. throw new Exception("Nie wybrano pracowników");
  829. }
  830. $kontrahenciIds = []; // array z nr ID na podstawie wysłanego formularza
  831. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  832. // walidacja id kontrahetów
  833. if (!$kontrahenciIds) {
  834. throw new Exception("Nie wybrano kontrahentów");
  835. }
  836. // Tworzenie rekrodu w bazie - Raport -
  837. $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
  838. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  839. 'A_RECORD_CREATE_DATE' => 'NOW()',
  840. 'A_STATUS' => 'WAITING', // TODO: czy trzeba to ustawić (pytanie do Mariusza)
  841. 'FILE_STATUS' => "TO_GENERATE",
  842. 'BI_analiza_minDepth' => 1,
  843. 'BI_analiza_maxDepth' => $depthValue
  844. ]);
  845. // Tworzenie relacji Raport do Pracownicy
  846. $refPowiazaniaToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  847. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  848. foreach ($pracownicyIds as $idPracownik) {
  849. DB::getPDO()->insert($refPowiazaniaToPracownicy, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  850. }
  851. // Tworzenie relacji Raport do Kontrahenci - analogicznie jak wyżej
  852. $refPowiazaniaToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  853. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  854. foreach ($kontrahenciIds as $idKontrahent) {
  855. DB::getPDO()->insert($refPowiazaniaToKontrahenci, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idKontrahent ]);
  856. }
  857. // ...
  858. return [
  859. 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
  860. 'type' => "success",
  861. 'body' => [
  862. 'id' => $idRaport,
  863. ]
  864. ];
  865. }
  866. /**
  867. * Widok formularza dodawania pracowników i kontrahentów
  868. */
  869. public function defaultViewFormBiAudit($items, $type) {
  870. $activeFormSteps = '';
  871. switch($type) {
  872. case 'KONTRAHENCI':
  873. $activeFormStepsKontrahent = 'complete';
  874. $titleHeader = 'KONTRAHENCI';
  875. $groupFilterList = '
  876. <div class="menu-item">
  877. <ul class="padding-0">
  878. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  879. </ul>
  880. </div>
  881. <div id="group-kontrahenci" class="btn-group">
  882. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  883. </div>';
  884. $formAddNewData ='
  885. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import kontrahentów\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  886. <!--<li><a href="#" title="DODAJ KONTRAHENCI" class="btn btn-info">+ DODAJ KONTRAHENCI</a></li>-->'; //todo: dodać obsługe doddawania kontrahentow
  887. $showButtonNextStep = '<button type="button" class="btn btn-primary" onClick="generateBiAuditRaport(event)" id="button-generate-reaport">SZUKAJ POWIĄZAŃ</button>';
  888. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  889. break;
  890. case 'PRACOWNICY':
  891. $titleHeader = 'PRACOWNICY';
  892. $groupFilterList = '
  893. <div class="menu-item">
  894. <ul class="padding-0">
  895. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a></li>
  896. </ul>
  897. </div>
  898. <div id="group-pracownicy" class="btn-group">
  899. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  900. </div>';
  901. $formAddNewData ='
  902. <li><a href="#" title="IMPORT PRACOWNIKÓW" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
  903. <!--<li><a href="#" title="DODAJ PRACOWNIKÓW" class="btn btn-info" >+ DODAJ PRACOWNIKÓW</a></li>-->'; //todo: dodać obsługe doddawania pracownikow
  904. $showButtonNextStep = '<a href="index.php?_route=UrlAction_Bocian#KONTRAHENCI" title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
  905. $pagination_form = '<div id="pagination-pracownicy"></div>';
  906. break;
  907. }
  908. $view = '
  909. <!-- start:employees-section-->
  910. <div id="smad-employees-section" class="smad-form-' . $type . '" >
  911. <div class="container-fluid">
  912. <div>
  913. <div class="padding-lr-0">
  914. <div id="smad-menu-section">
  915. <div class="col-sm-12 col-md-6 padding-lr-0">
  916. <div class="menu-items">
  917. <div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $titleHeader . ' </div>
  918. </div>
  919. </div>
  920. <div class="col-sm-12 col-md-6 padding-lr-0">
  921. <div class="form-steps">
  922. <!-- start:form steps wizard -->
  923. <div class="row smad-wizard" style="border-bottom:0;">
  924. <div class="col-xs-4 col-md-4 smad-wizard-step complete"><!-- complited line -->
  925. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  926. <div class="progress"><div class="progress-bar"></div></div>
  927. <a href="index.php?_route=UrlAction_Bocian#PRACOWNICY" class="smad-wizard-dot"></a>
  928. <div class="smad-wizard-info complete text-center">
  929. <div class="step-item">Krok 1</div>
  930. <div class="step-title ">PRACOWNICY</div>
  931. </div>
  932. </div>
  933. <div class="col-xs-4 col-md-4 smad-wizard-step ' . $activeFormStepsKontrahent . ' ">
  934. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  935. <div class="progress"><div class="progress-bar"></div></div>
  936. <a href="index.php?_route=UrlAction_Bocian#KONTRAHENCI" class="smad-wizard-dot"></a>
  937. <div class="smad-wizard-info text-center">
  938. <div class="step-item">Krok 2</div>
  939. <div class="step-title ">KONTRAHENCI</div>
  940. </div>
  941. </div>
  942. <div class="col-xs-4 col-md-4 smad-wizard-step ">
  943. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  944. <div class="progress"><div class="progress-bar"></div></div>
  945. <a href="#" class="smad-wizard-dot"></a>
  946. <div class="smad-wizard-info text-center">
  947. <div class="step-item">Krok 3</div>
  948. <div class="step-title ">SZUKANIE POWIĄZAŃ</div>
  949. </div>
  950. </div>
  951. </div>
  952. <!-- end:form steps wizard -->
  953. </div>
  954. </div>
  955. </div>
  956. </div>
  957. </div>
  958. </div>
  959. <div class="container-fluid">
  960. <div class=" padding-lr-0">
  961. <div class="smad-divider"></div>
  962. </div>
  963. </div>
  964. <!-- start:filters -->
  965. <div class="container-fluid">
  966. <div class="row">
  967. <div>
  968. <div class="smad-employees-form-section" class="border-top-grey">
  969. <div class="col-md-9 smad-border-col">
  970. <div class="menu-items">
  971. '.$groupFilterList.'
  972. </div>
  973. </div>
  974. <div class="col-md-3">
  975. <div class="form-input">
  976. <div class="form-item col-md-6 smad-heder-title">głębokość powiązań:</div>
  977. <div class="form-item col-md-6">
  978. <input type="text" class="form-control smad-depth" placeholder="1-16" value="" />
  979. </div>
  980. </div>
  981. </div>
  982. </div>
  983. </div>
  984. </div>
  985. </div>
  986. <!-- end:filters -->
  987. <!-- start:list employees -->
  988. <div class="container-fluid">
  989. <div class="padding-0 smad-employees-list-head">
  990. <div class="col-md-6">
  991. <header>
  992. <h2 class="title">Wszyscy</h2>
  993. </header>
  994. <div class="desc">
  995. Lorem Ipsum jest tekstem stosowanym jako przykładowy wypełniacz w przemyśle poligraficznym.
  996. </div>
  997. </div>
  998. <div class="col-md-6">
  999. <div class="menu-items">
  1000. <div class="menu-item">
  1001. <ul class="padding-0">
  1002. '.$formAddNewData.'
  1003. </ul>
  1004. </div>
  1005. </div>
  1006. </div>
  1007. </div>
  1008. </div>
  1009. <div class="container-fluid">
  1010. <div class="table-responsive padding-0" id="smad-table-' . $type . '">
  1011. ' . $this->showListDataByType($items, $type) . '
  1012. </div>
  1013. </div>
  1014. <!-- end:list employees -->
  1015. <!-- start:list paginations employees -->
  1016. <div class="container-fluid ">
  1017. <div>
  1018. '. $pagination_form .'
  1019. </div>
  1020. </div>
  1021. <!-- end:list paginations employees -->
  1022. <!-- start:bottom buttons -->
  1023. <div class="container-fluid smad-employees-bottom-navigation">
  1024. <div class="padding-0">
  1025. <div class="col-lg-6 ">
  1026. <a href="#" title="PRZENIEŚ DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">PRZENIEŚ DO GRUPY</a>
  1027. </div>
  1028. <div class="col-lg-6 text-right">
  1029. ' . $showButtonNextStep . '
  1030. </div>
  1031. </div>
  1032. </div>
  1033. <!-- end:bottom buttons -->
  1034. </div>
  1035. <!-- start:employees-section -->
  1036. ';
  1037. return $view;
  1038. }
  1039. public function showListDataByType($items, $type='PRACOWNICY') {
  1040. switch ($type) {
  1041. case 'PRACOWNICY':
  1042. return $this->showTablePracownicy();
  1043. break;
  1044. case 'KONTRAHENCI':
  1045. return $this->showTableKontrahenci($items);
  1046. break;
  1047. }
  1048. }
  1049. }