Bocian.php 60 KB

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