Bocian.php 43 KB

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