Bocian.php 41 KB

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