Bocian.php 43 KB

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