Bocian.php 48 KB

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