Bocian.php 59 KB

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