Bocian.php 42 KB

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