Bocian.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  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_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  370. 'primaryKey' => $idGroup,
  371. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  372. ];
  373. // - ID
  374. // - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
  375. // - NAZWA - nazwa grupy
  376. // - 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_KONTRAHENCI' minOccurs="0" maxOccurs="unbounded"
  377. }
  378. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  379. $query = $acl->buildQuery(array_merge([
  380. 'cols' => [ // TODO:? propertyName = []
  381. 'ID',
  382. 'Nazwa_grupy_kapitalowej',
  383. 'Pelna_nazwa_kontrahenta',
  384. 'Numer_kontrahenta',
  385. 'Skrocona_Nazwa_Kontrahenta',
  386. 'Typ_kontrahenta',
  387. 'NIP',
  388. 'KRS',
  389. 'REGON',
  390. 'PESEL',
  391. 'Forma_prawna_dzialalnosci',
  392. 'Ulica',
  393. 'Numer_budynku',
  394. 'Numer_mieszkania_lokalu',
  395. 'Miejscowosc',
  396. 'Kod_pocztowy',
  397. 'Kraj',
  398. 'Telefon',
  399. 'Fax',
  400. 'Mail',
  401. 'A_ADM_COMPANY',
  402. 'A_CLASSIFIED',
  403. 'A_STATUS',
  404. 'A_STATUS_INFO',
  405. 'Dodano',
  406. 'L_APPOITMENT_USER',
  407. 'Podmiot_dominujacy',
  408. 'Tytul_dokumentu',
  409. 'ownCompany',
  410. 'uwagi',
  411. ],
  412. //'f_ID' => $id,
  413. 'limit' => $limit,
  414. 'limitstart' => $limitstart, // offset
  415. ], $searchParams, $backRefFilter));
  416. $total = $query->getTotal();
  417. $items = $query->getItems();
  418. $pagination = array();
  419. $pagination['total_items'] = $total;
  420. $pagination['size'] = ceil($total/$limit); // pages size
  421. $pagination['current'] = $page;
  422. $pagination['limit'] = $limit;
  423. return [
  424. 'type' => 'success',
  425. 'msg' => 'showKontrajenci',
  426. '__req_args' => $_REQUEST,
  427. '__args' => $args,
  428. 'body' => [
  429. 'items' => $items,
  430. //'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI'),
  431. 'pagination' => $pagination
  432. ]
  433. ];
  434. }
  435. // public function fetchKontrahenciAjaxOld($args) {
  436. // //$id = V::get('ID', 1, $_REQUEST, 'int');
  437. // $items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI')->buildQuery([
  438. // 'cols' => [ // TODO:? propertyName = []
  439. // 'ID',
  440. // 'Nazwa_grupy_kapitalowej',
  441. // 'Pelna_nazwa_kontrahenta',
  442. // 'NIP',
  443. // 'KRS',
  444. // 'REGON',
  445. // 'Miejscowosc',
  446. // 'Kod_pocztowy',
  447. // 'Telefon'
  448. // ],
  449. // //'f_ID' => $id,
  450. // ])->getItems([
  451. // 'limit' => 10
  452. // ]);
  453. //
  454. // return [
  455. // 'type' => 'success',
  456. // 'msg' => 'showKontrahenci',
  457. // '__req_args' => $_REQUEST,
  458. // '__args' => $args,
  459. // 'body' => [
  460. // 'items' => $items,
  461. // 'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI')
  462. // ]
  463. // ];
  464. // }
  465. public function showTableKontrahenci($items) {
  466. $view = '<form class="form-horizontal" method="post">
  467. <table class="table table-bordered table-hover table-striped" height=5>
  468. <thead>
  469. <tr>
  470. <td width=1><input type="checkbox" name="checkAll" id="checkAll-KONTRAHENCI" /></td>
  471. <td width=1>ID</td>
  472. <td>Nazwa grupy kapitalowej</td>
  473. <td>Pelna nazwa kontrahenta</td>
  474. <td>Numer kontrahenta</td>
  475. <td>Skrócona nazwa kontrahenta</td>
  476. <td>Typ_kontrahenta</td>
  477. <td>NIP</td>
  478. <td>KRS</td>
  479. <td>Regon</td>
  480. <td>PESEL</td>
  481. <td>Forma prawna działalności</td>
  482. <td>Ulica</td>
  483. <td>Numer budynku</td>
  484. <td>Numer mieszkania lokalu</td>
  485. <td>Miejscowosc</td>
  486. <td>Kod pocztowy</td>
  487. <td>Kraj</td>
  488. <td>Telefon</td>
  489. <td>Fax</td>
  490. <td>Mail</td>
  491. <td>A_ADM_COMPANY</td>
  492. <td>A_CLASSIFIED</td>
  493. <td>A_STATUS</td>
  494. <td>A_STATUS_INFO</td>
  495. <td>Dodano</td>
  496. <td>L_APPOITMENT_USER</td>
  497. <td>Podmiot dominujacy</td>
  498. <td>Tytul dokumentu</td>
  499. <td>ownCompany</td>
  500. <td>uwagi</td>
  501. </tr>
  502. </thead>
  503. <tbody id="body-kontrahenci">
  504. </tbody></table>
  505. </form>
  506. ';
  507. return $view;
  508. }
  509. // tworzenie grupy kontrahentów
  510. public function createKontrahenciGroupAjaxAction() {
  511. 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
  512. }
  513. public function createKontrahenciGroupAjax($args) {
  514. $nazwa = V::get('NAZWA', '', $args);
  515. // TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje
  516. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_KONTRAHENCI_GRUPY', [
  517. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  518. 'A_RECORD_CREATE_DATE' => 'NOW()',
  519. 'NAZWA' => $nazwa,
  520. ]);
  521. return [
  522. 'msg' => "Utworzona grupę {$idGroup}",
  523. 'type' => "success",
  524. 'body' => [
  525. 'id' => $idGroup,
  526. ]
  527. ];
  528. }
  529. // Dodanie do grupy filtra kontrahentów
  530. public function addKontrahenciToGroupAjaxAction() {
  531. // 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
  532. Response::sendTryCatchJson(array($this, 'addKontrahenciToGroupAjax'));
  533. }
  534. public function addKontrahenciToGroupAjax($args) {
  535. $idGroup = V::get('idGroup', 0, $_REQUEST, 'int');
  536. $kontrahenciIds = V::get('kontrahenciIds', [], $_REQUEST, 'array');
  537. // validate
  538. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  539. if (!$kontrahenciIds || count($kontrahenciIds) == 0 ) throw new Exception("Proszę wybrać kontrahentów");
  540. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  541. 'cols' => [ // TODO:? propertyName = []
  542. 'ID',
  543. 'ID_USER',
  544. 'NAZWA',
  545. ],
  546. // 'f_ID_USER' => User::getID()
  547. ])->getItem($idGroup);
  548. if (!$group) throw new Exception("Grupa nie istnieje");
  549. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  550. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  551. $refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  552. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  553. foreach ($kontrahenciIds as $kontrahentIds) {
  554. DB::getPDO()->insert($refGrupyToKontrahenci, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $kontrahentIds]);
  555. }
  556. return [
  557. 'msg' => "Powiązano kontrahentów z grupą {$idGroup}",
  558. 'type' => "success",
  559. ];
  560. }
  561. public function fetchGroupKontrahenciAjaxAction() {
  562. Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
  563. }
  564. public function fetchGroupKontrahenciAjax() {
  565. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  566. 'cols' => [ // TODO:? propertyName = []
  567. 'ID',
  568. 'ID_USER',
  569. 'NAZWA',
  570. ],
  571. 'f_ID_USER' => "=" . User::getID(),
  572. 'f_A_STATUS' => "!DELETED",
  573. ]);
  574. $itemsKontrahenci = $query->getItems();
  575. if (empty($itemsKontrahenci)) throw new AlertWarningException("Grupy nie istnieją");
  576. $arrayGroupKontrahenci = array();
  577. foreach ($itemsKontrahenci as $item) {
  578. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  579. $arrayGroupKontrahenci[] = [
  580. 'NAZWA' => $item['NAZWA'],
  581. 'ID' => $item['ID'],
  582. ];
  583. }
  584. return [
  585. 'type' => 'success',
  586. 'msg' => 'fetchGroupKontrahenciAjax',
  587. '__req_args' => $_REQUEST,
  588. '__args' => $args,
  589. 'body' => [
  590. 'itemsGroupKontrahenci' => $arrayGroupKontrahenci
  591. ]
  592. ];
  593. }
  594. /*
  595. * PRACOWNICY
  596. */
  597. public function fetchPracownicyAjaxAction() {
  598. Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'));
  599. }
  600. public function fetchPracownicyAjax($args) {
  601. $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  602. if ($idGroup < 0) $idGroup = 0;
  603. $limit = 2;
  604. $limitstart = V::get('limitstart', 0, $_REQUEST, 'int');
  605. if ($limitstart < 0) $limitstart = 0;
  606. $page = V::get('page', 0, $_REQUEST, 'int');
  607. $limitstart = ($page - 1) * $limit;
  608. $search = V::get('search', '', $_REQUEST);
  609. $searchParams = [];
  610. if (!empty($search)) {
  611. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  612. $searchParams['ogc:Filter'] = '
  613. <ogc:Filter>
  614. <ogc:Or>
  615. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  616. <ogc:PropertyName>nip</ogc:PropertyName>
  617. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  618. </ogc:PropertyIsLike>
  619. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  620. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  621. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  622. </ogc:PropertyIsLike>
  623. </ogc:Or>
  624. </ogc:Filter>
  625. ';
  626. }
  627. $backRefFilter = [];
  628. if ($idGroup > 0) {
  629. $backRefFilter['__backRef'] = [
  630. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group', // TODO: nowy rejetr na grupy / filty pracowników
  631. 'primaryKey' => $idGroup,
  632. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  633. ];
  634. // TODO: Storage dodać obiekt xsd default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group:
  635. // - ID
  636. // - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
  637. // - NAZWA - nazwa grupy
  638. // - 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY' minOccurs="0" maxOccurs="unbounded"
  639. }
  640. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  641. $query = $acl->buildQuery(array_merge([
  642. 'cols' => [ // TODO:? propertyName = []
  643. 'ID',
  644. 'imiona',
  645. 'nazwisko',
  646. 'nip',
  647. 'pesel',
  648. 'regon',
  649. 'source',
  650. 'A_ADM_COMPANY',
  651. 'A_CLASSIFIED',
  652. 'A_STATUS',
  653. 'A_STATUS_INFO',
  654. 'L_APPOITMENT_USER',
  655. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  656. ],
  657. //'f_ID' => $id,
  658. 'limit' => $limit,
  659. 'limitstart' => $limitstart, // offset
  660. // 'order_by' => 'ID', // sortowanie po kolumnie
  661. // 'order_dir' => 'DESC', // kierunek sortowania
  662. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  663. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  664. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  665. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  666. ], $searchParams, $backRefFilter));
  667. $total = $query->getTotal();
  668. $items = $query->getItems();
  669. $pagination = array();
  670. $pagination['total_items'] = $total;
  671. $pagination['size'] = ceil($total/$limit); // pages size
  672. $pagination['current'] = $page;
  673. $pagination['limit'] = $limit;
  674. // { // tworzenie własnego zapytanie mysql
  675. // $rootTableName = $acl->getRootTableName();
  676. // DB::getPDO()->fetchAll("
  677. // select t.*
  678. // from {$rootTableName} t
  679. // where t.ID in (
  680. // select x.ID
  681. // from ... x
  682. // where
  683. // )
  684. // ");
  685. // }
  686. return [
  687. 'type' => 'success',
  688. 'msg' => 'showPracownicy',
  689. '__req_args' => $_REQUEST,
  690. '__args' => $args,
  691. 'body' => [
  692. 'items' => $items,
  693. //'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
  694. 'pagination' => $pagination
  695. ]
  696. ];
  697. }
  698. public function showTablePracownicy() {
  699. $view = '<form class="form-horizontal" method="post">
  700. <table class="table table-responsive table-bordered table-hover table-striped" height=5>
  701. <thead>
  702. <tr>
  703. <td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
  704. <td width=1>ID</td>
  705. <td>Imię/Imiona</td>
  706. <td>Nazwisko</td>
  707. <td>NIP</td>
  708. <td>Pesel</td>
  709. <td>Regon</td>
  710. <td>source</td>
  711. <td>A_ADM_COMPANY</td>
  712. <td>A_CLASSIFIED</td>
  713. <td>A_STATUS</td>
  714. <td>A_STATUS_INFO</td>
  715. <td>L_APPOITMENT_USER</td>
  716. <td>Adresy</td>
  717. </tr>
  718. </thead>
  719. <tbody id="body-pracownicy">
  720. </tbody></table>
  721. </form>';
  722. return $view;
  723. }
  724. // tworzenie grupy pracowników
  725. public function createPracownicyGroupAjaxAction() {
  726. 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
  727. // Response::sendTryCatchJson(array($this, 'createPracownicyGroupAjax'));
  728. }
  729. public function createPracownicyGroupAjax($args) {
  730. $nazwa = V::get('NAZWA', '', $args);
  731. // TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje
  732. // validate
  733. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  734. if (!$kontrahenciIds || count($kontrahenciIds) == 0 ) throw new Exception("Proszę wybrać kontrahentów");
  735. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
  736. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  737. 'A_RECORD_CREATE_DATE' => 'NOW()',
  738. // 'A_STATUS' => 'WAITING', // jeśli trzeba to ustawić
  739. 'NAZWA' => $nazwa,
  740. ]);
  741. // DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group_HIST', [
  742. // 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  743. // 'A_RECORD_CREATE_DATE' => 'NOW()',
  744. // 'ID_USERS2' => $idRaport,
  745. // // 'A_STATUS' => 'WAITING', // jeśli trzeba to ustawić
  746. // 'NAZWA' => $nazwa,
  747. // ]);
  748. return [
  749. 'msg' => "Utworzona grupę {$idGroup}",
  750. 'type' => "success",
  751. 'body' => [
  752. 'id' => $idGroup,
  753. ]
  754. ];
  755. }
  756. // Dodanie do grupy filtra pracowników
  757. public function addPracownicyToGroupAjaxAction() {
  758. // 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
  759. Response::sendTryCatchJson(array($this, 'addPracownicyToGroupAjax'));
  760. }
  761. public function addPracownicyToGroupAjax($args) {
  762. $idGroup = V::get('idGroup', 0, $_REQUEST, 'int');
  763. $pracownicyIds = V::get('pracownicyIds', [], $_REQUEST, 'array');
  764. // validate
  765. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  766. if (!$pracownicyIds || count($pracownicyIds) == 0 ) throw new Exception("Proszę wybrać pracowników");
  767. // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
  768. // default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
  769. // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
  770. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  771. 'cols' => [ // TODO:? propertyName = []
  772. 'ID',
  773. 'ID_USER',
  774. 'NAZWA',
  775. ],
  776. // 'f_ID_USER' => User::getID()
  777. ])->getItem($idGroup);
  778. if (!$group) throw new Exception("Grupa nie istnieje");
  779. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  780. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  781. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  782. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  783. foreach ($pracownicyIds as $idPracownik) {
  784. DB::getPDO()->insert($refGrupyToPracownicy, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  785. }
  786. return [
  787. 'msg' => "Powiązano pracowników z grupą {$idGroup}",
  788. 'type' => "success",
  789. ];
  790. }
  791. public function fetchGroupPracownicyAjaxAction() {
  792. Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
  793. }
  794. public function fetchGroupPracownicyAjax() {
  795. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  796. 'cols' => [ // TODO:? propertyName = []
  797. 'ID',
  798. 'ID_USER',
  799. 'NAZWA',
  800. ],
  801. 'f_ID_USER' => "=" . User::getID(), // szukamy dokładnie tej wartości - mysql: where ID_USER = "1"
  802. 'f_A_STATUS' => "!DELETED", // `A_STATUS` != 'DELETED'
  803. ]);
  804. $items = $query->getItems();
  805. if (empty($items)) throw new AlertWarningException("Grupy nie istnieją");
  806. $arrayGroupPracownicy = array();
  807. foreach ($items as $item) {
  808. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy"); // or skip - continue;
  809. $arrayGroupPracownicy[] = [
  810. 'ID' => $item['ID'],
  811. 'NAZWA' => $item['NAZWA'],
  812. ];
  813. }
  814. // //TODO: USUNAĆ listę grup wpisane na sztywno
  815. // $arrayGroupPracownicy = array();
  816. // $arrayGroupPracownicy[0]["ID"] = 1;
  817. // $arrayGroupPracownicy[0]["NAZWA"] = "Grupa 1";
  818. // $arrayGroupPracownicy[1]["ID"] = 2;
  819. // $arrayGroupPracownicy[1]["NAZWA"] = "Grupa 2";
  820. // $arrayGroupPracownicy[2]["ID"] = 3;
  821. // $arrayGroupPracownicy[2]["NAZWA"] = "Grupa 3";
  822. // $arrayGroupPracownicy[3]["ID"] = 4;
  823. // $arrayGroupPracownicy[3]["NAZWA"] = "Grupa 4";
  824. // $arrayGroupPracownicy[4]["ID"] = 5;
  825. // $arrayGroupPracownicy[4]["NAZWA"] = "Grupa 5";
  826. return [
  827. 'type' => 'success',
  828. 'msg' => 'fetchGroupPracownicyAjax',
  829. '__req_args' => $_REQUEST,
  830. '__args' => $args,
  831. 'body' => [
  832. 'itmesGroupPracownicy' => $arrayGroupPracownicy
  833. ]
  834. ];
  835. }
  836. // link do ackji w php: $saveFormUrl = $this->getLink('saveRaportAjax');
  837. // przekazać link do JavaScript i tam:
  838. // window.fetch('{$saveFormUrl}', { ... }).then(...) - dokumentacja: https://github.com/github/fetch
  839. public function generateBiAuditRaportAjaxAction() {
  840. //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
  841. Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  842. //Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'));
  843. }
  844. public function generateBiAuditRaportAjax($args) {
  845. // głebokość powiazan
  846. $depthValue = V::get('depthValue', '', $args);
  847. if (!$depthValue) {
  848. throw new Exception("Nie podano wartości dla głębokości powiązań");
  849. }
  850. // Tworzenie relacji Raport do Pracownicy
  851. $pracownicyIds = []; // array z nr ID na podstawie wysłanego formularza
  852. $pracownicyIds = V::get('pracownicyIds', '', $args);
  853. // walidacja id pracowników
  854. if (!$pracownicyIds) {
  855. throw new Exception("Nie wybrano pracowników");
  856. }
  857. $kontrahenciIds = []; // array z nr ID na podstawie wysłanego formularza
  858. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  859. // walidacja id kontrahetów
  860. if (!$kontrahenciIds) {
  861. throw new Exception("Nie wybrano kontrahentów");
  862. }
  863. // Tworzenie rekrodu w bazie - Raport -
  864. $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
  865. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  866. 'A_RECORD_CREATE_DATE' => 'NOW()',
  867. 'A_STATUS' => 'WAITING', // TODO: czy trzeba to ustawić (pytanie do Mariusza)
  868. 'FILE_STATUS' => "TO_GENERATE",
  869. 'BI_analiza_minDepth' => 1,
  870. 'BI_analiza_maxDepth' => $depthValue
  871. ]);
  872. // Tworzenie relacji Raport do Pracownicy
  873. $refPowiazaniaToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  874. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  875. foreach ($pracownicyIds as $idPracownik) {
  876. DB::getPDO()->insert($refPowiazaniaToPracownicy, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  877. }
  878. // Tworzenie relacji Raport do Kontrahenci - analogicznie jak wyżej
  879. $refPowiazaniaToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  880. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  881. foreach ($kontrahenciIds as $idKontrahent) {
  882. DB::getPDO()->insert($refPowiazaniaToKontrahenci, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idKontrahent ]);
  883. }
  884. // ...
  885. return [
  886. 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
  887. 'type' => "success",
  888. 'body' => [
  889. 'id' => $idRaport,
  890. ]
  891. ];
  892. }
  893. /**
  894. * Widok formularza dodawania pracowników i kontrahentów
  895. */
  896. public function defaultViewFormBiAudit($items, $type) {
  897. $activeFormSteps = '';
  898. switch($type) {
  899. case 'KONTRAHENCI':
  900. $activeFormStepsKontrahent = 'complete';
  901. $titleHeader = 'KONTRAHENCI';
  902. $groupFilterList = '
  903. <div class="menu-item">
  904. <ul class="padding-0">
  905. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  906. </ul>
  907. </div>
  908. <div id="group-kontrahenci" class="btn-group">
  909. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  910. </div>';
  911. $formAddNewData ='
  912. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import kontrahentów\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  913. <!--<li><a href="#" title="DODAJ KONTRAHENCI" class="btn btn-info">+ DODAJ KONTRAHENCI</a></li>-->'; //todo: dodać obsługe doddawania kontrahentow
  914. $showButtonNextStep = '<button type="button" class="btn btn-primary" onClick="generateBiAuditRaport(event)" id="button-generate-reaport">SZUKAJ POWIĄZAŃ</button>';
  915. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  916. break;
  917. case 'PRACOWNICY':
  918. $titleHeader = 'PRACOWNICY';
  919. $groupFilterList = '
  920. <div class="menu-item">
  921. <ul class="padding-0">
  922. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a></li>
  923. </ul>
  924. </div>
  925. <div id="group-pracownicy" class="btn-group">
  926. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  927. </div>';
  928. $formAddNewData ='
  929. <li><a href="#" title="IMPORT PRACOWNIKÓW" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
  930. <!--<li><a href="#" title="DODAJ PRACOWNIKÓW" class="btn btn-info" >+ DODAJ PRACOWNIKÓW</a></li>-->'; //todo: dodać obsługe doddawania pracownikow
  931. $showButtonNextStep = '<a href="index.php?_route=UrlAction_Bocian#KONTRAHENCI" title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
  932. $pagination_form = '<div id="pagination-pracownicy"></div>';
  933. break;
  934. }
  935. $view = '
  936. <!-- start:employees-section-->
  937. <div id="smad-employees-section" class="smad-form-' . $type . '" >
  938. <div class="container-fluid">
  939. <div>
  940. <div class="padding-lr-0">
  941. <div id="smad-menu-section">
  942. <div class="col-sm-12 col-md-6 padding-lr-0">
  943. <div class="menu-items">
  944. <div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $titleHeader . ' </div>
  945. </div>
  946. </div>
  947. <div class="col-sm-12 col-md-6 padding-lr-0">
  948. <div class="form-steps">
  949. <!-- start:form steps wizard -->
  950. <div class="row smad-wizard" style="border-bottom:0;">
  951. <div class="col-xs-4 col-md-4 smad-wizard-step complete"><!-- complited line -->
  952. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  953. <div class="progress"><div class="progress-bar"></div></div>
  954. <a href="index.php?_route=UrlAction_Bocian#PRACOWNICY" class="smad-wizard-dot"></a>
  955. <div class="smad-wizard-info complete text-center">
  956. <div class="step-item">Krok 1</div>
  957. <div class="step-title ">PRACOWNICY</div>
  958. </div>
  959. </div>
  960. <div class="col-xs-4 col-md-4 smad-wizard-step ' . $activeFormStepsKontrahent . ' ">
  961. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  962. <div class="progress"><div class="progress-bar"></div></div>
  963. <a href="index.php?_route=UrlAction_Bocian#KONTRAHENCI" class="smad-wizard-dot"></a>
  964. <div class="smad-wizard-info text-center">
  965. <div class="step-item">Krok 2</div>
  966. <div class="step-title ">KONTRAHENCI</div>
  967. </div>
  968. </div>
  969. <div class="col-xs-4 col-md-4 smad-wizard-step ">
  970. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  971. <div class="progress"><div class="progress-bar"></div></div>
  972. <a href="#" class="smad-wizard-dot"></a>
  973. <div class="smad-wizard-info text-center">
  974. <div class="step-item">Krok 3</div>
  975. <div class="step-title ">SZUKANIE POWIĄZAŃ</div>
  976. </div>
  977. </div>
  978. </div>
  979. <!-- end:form steps wizard -->
  980. </div>
  981. </div>
  982. </div>
  983. </div>
  984. </div>
  985. </div>
  986. <div class="container-fluid">
  987. <div class=" padding-lr-0">
  988. <div class="smad-divider"></div>
  989. </div>
  990. </div>
  991. <!-- start:filters -->
  992. <div class="container-fluid">
  993. <div class="row">
  994. <div>
  995. <div class="smad-employees-form-section" class="border-top-grey">
  996. <div class="col-md-9 smad-border-col">
  997. <div class="menu-items">
  998. '.$groupFilterList.'
  999. </div>
  1000. </div>
  1001. <div class="col-md-3">
  1002. <div class="form-input">
  1003. <div class="form-item col-md-6 smad-heder-title">głębokość powiązań:</div>
  1004. <div class="form-item col-md-6">
  1005. <input type="text" class="form-control smad-depth" placeholder="1-16" value="" />
  1006. </div>
  1007. </div>
  1008. </div>
  1009. </div>
  1010. </div>
  1011. </div>
  1012. </div>
  1013. <!-- end:filters -->
  1014. <!-- start:list employees -->
  1015. <div class="container-fluid">
  1016. <div class="padding-0 smad-employees-list-head">
  1017. <div class="col-md-6">
  1018. <header>
  1019. <h2 class="title">Wszyscy</h2>
  1020. </header>
  1021. <div class="desc">
  1022. <!-- todo: można dodać opis -->
  1023. </div>
  1024. </div>
  1025. <div class="col-md-6">
  1026. <div class="menu-items">
  1027. <div class="menu-item">
  1028. <ul class="padding-0">
  1029. '.$formAddNewData.'
  1030. </ul>
  1031. </div>
  1032. </div>
  1033. </div>
  1034. </div>
  1035. </div>
  1036. <div class="container-fluid">
  1037. <div class="table-responsive padding-0" id="smad-table-' . $type . '">
  1038. ' . $this->showListDataByType($items, $type) . '
  1039. </div>
  1040. </div>
  1041. <!-- end:list employees -->
  1042. <!-- start:list paginations employees -->
  1043. <div class="container-fluid ">
  1044. <div>
  1045. '. $pagination_form .'
  1046. </div>
  1047. </div>
  1048. <!-- end:list paginations employees -->
  1049. <!-- start:bottom buttons -->
  1050. <div class="container-fluid smad-employees-bottom-navigation">
  1051. <div class="padding-0">
  1052. <div class="col-lg-6 ">
  1053. <a href="#" title="PRZENIEŚ DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">PRZENIEŚ DO GRUPY</a>
  1054. </div>
  1055. <div class="col-lg-6 text-right">
  1056. ' . $showButtonNextStep . '
  1057. </div>
  1058. </div>
  1059. </div>
  1060. <!-- end:bottom buttons -->
  1061. </div>
  1062. <!-- start:employees-section -->
  1063. ';
  1064. return $view;
  1065. }
  1066. public function showListDataByType($items, $type='PRACOWNICY') {
  1067. switch ($type) {
  1068. case 'PRACOWNICY':
  1069. return $this->showTablePracownicy();
  1070. break;
  1071. case 'KONTRAHENCI':
  1072. return $this->showTableKontrahenci($items);
  1073. break;
  1074. }
  1075. }
  1076. }