Bocian.php 43 KB

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