Bocian.php 42 KB

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