Bocian.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  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. $type = V::get('type', 'ids', $args);
  982. $pracownicyIds = V::get('pracownicyIds', '', $args);
  983. $filter = V::get('filter', '', $args);
  984. // validate
  985. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  986. switch ($type) {
  987. case 'ids': {
  988. if (!$pracownicyIds || count($pracownicyIds) == 0) throw new Exception("Proszę wybrać pracowników");
  989. } break;
  990. case 'filter': {
  991. if (!isset($args['filter'])) throw new Exception("Proszę wybrać pracowników");
  992. } break;
  993. default: throw new Exception("Missing type");
  994. }
  995. // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
  996. // default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
  997. // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
  998. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  999. 'cols' => [ // TODO:? propertyName = []
  1000. 'ID',
  1001. 'ID_USER',
  1002. 'NAZWA',
  1003. ],
  1004. // 'f_ID_USER' => User::getID()
  1005. ])->getItem($idGroup);
  1006. if (!$group) throw new Exception("Grupa nie istnieje");
  1007. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1008. if ('filter' === $type) {
  1009. $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1010. if ($args__idGroup < 0) $args__idGroup = 0;
  1011. $search = V::get('search', '', $args['filter']);
  1012. $searchParams = [];
  1013. if (!empty($search)) {
  1014. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1015. $searchParams['ogc:Filter'] = '
  1016. <ogc:Filter>
  1017. <ogc:Or>
  1018. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1019. <ogc:PropertyName>nip</ogc:PropertyName>
  1020. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1021. </ogc:PropertyIsLike>
  1022. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1023. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1024. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1025. </ogc:PropertyIsLike>
  1026. </ogc:Or>
  1027. </ogc:Filter>
  1028. ';
  1029. }
  1030. $backRefFilter = [];
  1031. if ($args__idGroup > 0) {
  1032. $backRefFilter['__backRef'] = [
  1033. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1034. 'primaryKey' => $args__idGroup,
  1035. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1036. ];
  1037. }
  1038. $filtersParams = [];
  1039. $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
  1040. return ('f_' === substr($key, 0, 2));
  1041. });
  1042. foreach ($fieldFilterKeys as $key) {
  1043. $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
  1044. }
  1045. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1046. $query = $acl->buildQuery(array_merge([
  1047. 'cols' => array_merge(self::$FIELD_LIST_PRACOWNICY, [
  1048. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  1049. ]),
  1050. ], $searchParams, $filtersParams, $backRefFilter));
  1051. $items = $query->getItems();
  1052. $pracownicyIds = array_map(function ($row) {
  1053. return $row['ID'];
  1054. }, $items);
  1055. }
  1056. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  1057. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1058. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1059. foreach ($pracownicyIds as $idPracownik) {
  1060. DB::getPDO()->insert($refGrupyToPracownicy, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  1061. }
  1062. return [
  1063. 'msg' => "Powiązano pracowników z grupą {$idGroup}",
  1064. 'type' => "success",
  1065. ];
  1066. }
  1067. public function fetchGroupPracownicyAjaxAction() {
  1068. Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
  1069. }
  1070. public function fetchGroupPracownicyAjax() {
  1071. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1072. 'cols' => [ // TODO:? propertyName = []
  1073. 'ID',
  1074. 'ID_USER',
  1075. 'NAZWA',
  1076. ],
  1077. 'f_ID_USER' => "=" . User::getID(), // szukamy dokładnie tej wartości - mysql: where ID_USER = "1"
  1078. 'f_A_STATUS' => "!DELETED", // `A_STATUS` != 'DELETED'
  1079. ]);
  1080. $items = $query->getItems();
  1081. if (empty($items)) throw new AlertWarningException("Grupy nie istnieją");
  1082. $arrayGroupPracownicy = array();
  1083. foreach ($items as $item) {
  1084. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy"); // or skip - continue;
  1085. $arrayGroupPracownicy[] = [
  1086. 'ID' => $item['ID'],
  1087. 'NAZWA' => $item['NAZWA'],
  1088. ];
  1089. }
  1090. return [
  1091. 'type' => 'success',
  1092. 'msg' => 'fetchGroupPracownicyAjax',
  1093. '__req_args' => $_REQUEST,
  1094. '__args' => $args,
  1095. 'body' => [
  1096. 'itmesGroupPracownicy' => $arrayGroupPracownicy
  1097. ]
  1098. ];
  1099. }
  1100. // link do ackji w php: $saveFormUrl = $this->getLink('saveRaportAjax');
  1101. // przekazać link do JavaScript i tam:
  1102. // window.fetch('{$saveFormUrl}', { ... }).then(...) - dokumentacja: https://github.com/github/fetch
  1103. public function generateBiAuditRaportAjaxAction() {
  1104. //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
  1105. Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1106. //Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'));
  1107. }
  1108. public function generateBiAuditRaportAjax($args) {
  1109. // głebokość powiazan
  1110. $depthValue = V::get('depthValue', '', $args);
  1111. if (!$depthValue) {
  1112. throw new Exception("Nie podano wartości dla głębokości powiązań");
  1113. }
  1114. // Tworzenie relacji Raport do Pracownicy
  1115. $pracownicyIds = []; // array z nr ID na podstawie wysłanego formularza
  1116. $pracownicyIds = V::get('pracownicyIds', '', $args);
  1117. // walidacja id pracowników
  1118. if (!$pracownicyIds) {
  1119. throw new Exception("Nie wybrano pracowników");
  1120. }
  1121. $kontrahenciIds = []; // array z nr ID na podstawie wysłanego formularza
  1122. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  1123. // walidacja id kontrahetów
  1124. if (!$kontrahenciIds) {
  1125. throw new Exception("Nie wybrano kontrahentów");
  1126. }
  1127. // Tworzenie rekrodu w bazie - Raport -
  1128. $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
  1129. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1130. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1131. 'FILE_STATUS' => "TO_GENERATE",
  1132. 'BI_analiza_minDepth' => 1,
  1133. 'BI_analiza_maxDepth' => $depthValue
  1134. ]);
  1135. if ($idRaport > 0) {
  1136. DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_HIST', [
  1137. 'ID_USERS2' => $idRaport,
  1138. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1139. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1140. 'FILE_STATUS' => "TO_GENERATE",
  1141. 'BI_analiza_minDepth' => 1,
  1142. 'BI_analiza_maxDepth' => $depthValue
  1143. ]);
  1144. }
  1145. // Tworzenie relacji Raport do Pracownicy
  1146. $refPowiazaniaToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1147. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1148. foreach ($pracownicyIds as $idPracownik) {
  1149. DB::getPDO()->insert($refPowiazaniaToPracownicy, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  1150. }
  1151. // Tworzenie relacji Raport do Kontrahenci - analogicznie jak wyżej
  1152. $refPowiazaniaToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1153. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  1154. foreach ($kontrahenciIds as $idKontrahent) {
  1155. DB::getPDO()->insert($refPowiazaniaToKontrahenci, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idKontrahent ]);
  1156. }
  1157. // ...
  1158. return [
  1159. 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
  1160. 'type' => "success",
  1161. 'body' => [
  1162. 'id' => $idRaport,
  1163. ]
  1164. ];
  1165. }
  1166. /**
  1167. * Widok formularza dodawania pracowników i kontrahentów
  1168. */
  1169. public function defaultViewFormBiAudit($items, $type) {
  1170. $activeFormSteps = '';
  1171. $fieldLabels = [];
  1172. switch($type) {
  1173. case 'KONTRAHENCI':
  1174. $activeFormStepsKontrahent = 'complete';
  1175. $titleHeader = 'KONTRAHENCI';
  1176. $groupFilterList = '
  1177. <div class="menu-item">
  1178. <ul class="padding-0">
  1179. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  1180. </ul>
  1181. </div>
  1182. <div id="group-kontrahenci" class="btn-group">
  1183. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1184. </div>';
  1185. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
  1186. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
  1187. $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>';
  1188. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  1189. $formAddNewData ='
  1190. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  1191. <!--<li><a href="#" title="DODAJ KONTRAHENCI" class="btn btn-info">+ DODAJ KONTRAHENCI</a></li>-->'; //todo: dodać obsługe doddawania kontrahentow
  1192. $buttonMoveToGroup = '<a title="DODAJ DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ DO GRUPY</a>';
  1193. $showButtonNextStep = '<button type="button" class="btn btn-primary" onClick="generateBiAuditRaport(event)" id="button-generate-reaport">SZUKAJ POWIĄZAŃ</button>';
  1194. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  1195. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  1196. $fieldList = $acl->getRealFieldList();
  1197. $fieldLabels = array_combine(
  1198. $fieldList,
  1199. array_map(function ($fieldName) use ($acl) {
  1200. return $acl->getFieldLabel($fieldName);
  1201. }, $fieldList)
  1202. );
  1203. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  1204. break;
  1205. case 'PRACOWNICY':
  1206. $titleHeader = 'PRACOWNICY';
  1207. $groupFilterList = '
  1208. <div class="menu-item">
  1209. <ul class="padding-0">
  1210. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a></li>
  1211. </ul>
  1212. </div>
  1213. <div id="group-pracownicy" class="btn-group">
  1214. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1215. </div>';
  1216. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-pracownicy">Wszyscy</h2>';
  1217. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span></p>';
  1218. $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>';
  1219. $csvExamplePracownicy = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/pracownicy_example.zip';
  1220. $formAddNewData ='
  1221. <li><a title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import pracowników\', \'pracownicy\', \'yes\', \''.$csvExamplePracownicy.'\' )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
  1222. <!--<li><a href="#" title="DODAJ PRACOWNIKÓW" class="btn btn-info" >+ DODAJ PRACOWNIKÓW</a></li>-->'; //todo: dodać obsługe doddawania pracownikow
  1223. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  1224. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addPracownikAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  1225. $showButtonNextStep = '<a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
  1226. $pagination_form = '<div id="pagination-pracownicy"></div>';
  1227. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY");
  1228. $fieldList = $acl->getRealFieldList();
  1229. $fieldLabels = array_combine(
  1230. $fieldList,
  1231. array_map(function ($fieldName) use ($acl) {
  1232. return $acl->getFieldLabel($fieldName);
  1233. }, $fieldList)
  1234. );
  1235. DBG::log($fieldLabels, 'array', "fieldLabels (PRACOWNICY)");
  1236. break;
  1237. }
  1238. $view = '
  1239. <!-- start:employees-section-->
  1240. <div id="smad-employees-section" class="smad-form-' . $type . '" >
  1241. <div class="container-fluid">
  1242. <div>
  1243. <div class="padding-lr-0">
  1244. <div id="smad-menu-section">
  1245. <div class="col-sm-12 col-md-6 padding-lr-0">
  1246. <div class="menu-items">
  1247. <div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $titleHeader . ' </div>
  1248. </div>
  1249. </div>
  1250. <div class="col-sm-12 col-md-6 padding-lr-0">
  1251. <div class="form-steps">
  1252. <!-- start:form steps wizard -->
  1253. <div class="row smad-wizard" style="border-bottom:0;">
  1254. <div class="col-xs-4 col-md-4 smad-wizard-step complete"><!-- complited line -->
  1255. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1256. <div class="progress"><div class="progress-bar"></div></div>
  1257. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY" class="smad-wizard-dot"></a>
  1258. <div class="smad-wizard-info complete text-center">
  1259. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY">Krok 1</a></div>
  1260. <div class="step-title">PRACOWNICY <span class="top--count-selected-item-pracownicy"></span></div>
  1261. </div>
  1262. </div>
  1263. <div class="col-xs-4 col-md-4 smad-wizard-step ' . $activeFormStepsKontrahent . ' ">
  1264. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1265. <div class="progress"><div class="progress-bar"></div></div>
  1266. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" class="smad-wizard-dot"></a>
  1267. <div class="smad-wizard-info text-center">
  1268. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI">Krok 2</a></div>
  1269. <div class="step-title">KONTRAHENCI <span class="top--count-selected-item-kontrahenci"></span></div>
  1270. </div>
  1271. </div>
  1272. <div class="col-xs-4 col-md-4 smad-wizard-step ">
  1273. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1274. <div class="progress"><div class="progress-bar"></div></div>
  1275. <a href="#" class="smad-wizard-dot"></a>
  1276. <div class="smad-wizard-info text-center">
  1277. <div class="step-item">Krok 3</div>
  1278. <div class="step-title">SZUKANIE POWIĄZAŃ</div>
  1279. </div>
  1280. </div>
  1281. </div>
  1282. <!-- end:form steps wizard -->
  1283. </div>
  1284. </div>
  1285. </div>
  1286. </div>
  1287. </div>
  1288. </div>
  1289. <div class="container-fluid">
  1290. <div class=" padding-lr-0">
  1291. <div class="smad-divider"></div>
  1292. </div>
  1293. </div>
  1294. <!-- start:filters -->
  1295. <div class="container-fluid">
  1296. <div class="row">
  1297. <div>
  1298. <div class="smad-employees-form-section" class="border-top-grey">
  1299. <div class="col-md-9 smad-border-col">
  1300. <div class="menu-items">
  1301. '.$groupFilterList.'
  1302. </div>
  1303. </div>
  1304. <div class="col-md-3">
  1305. <div class="form-input">
  1306. <div class="form-item col-md-6 smad-heder-title">głębokość powiązań:</div>
  1307. <div class="form-item col-md-6">
  1308. <input type="text" class="form-control smad-depth" placeholder="1-16" value="" />
  1309. </div>
  1310. </div>
  1311. </div>
  1312. </div>
  1313. </div>
  1314. </div>
  1315. </div>
  1316. <!-- end:filters -->
  1317. <!-- start:list employees -->
  1318. <div class="container-fluid">
  1319. <div class="padding-0 smad-employees-list-head">
  1320. <div class="col-md-6">
  1321. <header>
  1322. '.$formFilterHeadTitle.'
  1323. </header>
  1324. <div class="desc">
  1325. '.$formFilterHeadDesc.'
  1326. </div>
  1327. <div class="countSelectedItem">
  1328. '.$countSelectedItem.'
  1329. </div>
  1330. </div>
  1331. <div class="col-md-6">
  1332. <div class="menu-items">
  1333. <div class="menu-item">
  1334. <ul class="padding-0">
  1335. '.$formAddNewData.'
  1336. </ul>
  1337. </div>
  1338. </div>
  1339. </div>
  1340. </div>
  1341. </div>
  1342. <div class="container-fluid">
  1343. <div class="table-responsive padding-0" id="smad-table-' . $type . '">
  1344. ' . $this->showListDataByType($items, $type, $fieldLabels) . '
  1345. </div>
  1346. </div>
  1347. <!-- end:list employees -->
  1348. <!-- start:list paginations employees -->
  1349. <div class="container-fluid ">
  1350. <div>
  1351. '. $pagination_form .'
  1352. </div>
  1353. </div>
  1354. <!-- end:list paginations employees -->
  1355. <!-- start:bottom buttons -->
  1356. <div class="container-fluid smad-employees-bottom-navigation">
  1357. <div class="padding-0">
  1358. <div class="col-lg-6 ">
  1359. '.$buttonMoveToGroup.'
  1360. </div>
  1361. <div class="col-lg-6 text-right">
  1362. ' . $showButtonNextStep . '
  1363. </div>
  1364. </div>
  1365. </div>
  1366. <!-- end:bottom buttons -->
  1367. </div>
  1368. <!-- start:employees-section -->
  1369. ';
  1370. return $view;
  1371. }
  1372. public function showListDataByType($items, $type='PRACOWNICY', $labels) {
  1373. switch ($type) {
  1374. case 'PRACOWNICY':
  1375. return $this->showTablePracownicy($labels);
  1376. break;
  1377. case 'KONTRAHENCI':
  1378. return $this->showTableKontrahenci($labels);
  1379. break;
  1380. }
  1381. }
  1382. }