Bocian.php 43 KB

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