Bocian.php 41 KB

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