Bocian.php 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  1. <?php
  2. Lib::loadClass('RouteToolBase');
  3. Lib::loadClass('UI');
  4. Lib::loadClass('Response');
  5. Lib::loadClass('Request');
  6. // index.php?_route=UrlAction_Bocian - uruchamia defaultAction
  7. class RouteTool_Bocian extends RouteToolBase {
  8. public static $helpEmailTo = 'biuro@bialnet.com.pl'; // todo:email na który zostanie wysłane zapytanie z formularza POMOCY
  9. public static $FIELD_LIST_PRACOWNICY = [
  10. 'ID',
  11. 'imiona',
  12. 'nazwisko',
  13. 'nip',
  14. 'pesel',
  15. 'regon',
  16. 'source',
  17. 'jednostka_organizacyjna',
  18. 'A_STATUS',
  19. 'A_STATUS_INFO',
  20. 'L_APPOITMENT_USER',
  21. // 'Adresy' // 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  22. ];
  23. public static $FIELD_LIST_KONTRAHENCI = [
  24. 'ID',
  25. 'Nazwa_grupy_kapitalowej',
  26. 'Pelna_nazwa_kontrahenta',
  27. 'Numer_kontrahenta',
  28. 'Skrocona_Nazwa_Kontrahenta',
  29. 'Typ_kontrahenta',
  30. 'NIP',
  31. 'KRS',
  32. 'REGON',
  33. 'PESEL',
  34. 'Forma_prawna_dzialalnosci',
  35. 'Ulica',
  36. 'Numer_budynku',
  37. 'Numer_mieszkania_lokalu',
  38. 'Miejscowosc',
  39. 'Kod_pocztowy',
  40. 'Kraj',
  41. 'Telefon',
  42. 'Fax',
  43. 'Mail',
  44. 'A_ADM_COMPANY',
  45. 'A_CLASSIFIED',
  46. 'Dodano',
  47. 'Podmiot_dominujacy',
  48. 'Tytul_dokumentu',
  49. 'ownCompany',
  50. 'uwagi',
  51. ];
  52. /**
  53. * View Page About Project
  54. */
  55. public function aboutAction() {
  56. UI::gora();
  57. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  58. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  59. Theme::top();
  60. include('page-about.view.php');
  61. UI::dol();
  62. }
  63. /**
  64. * View Page training
  65. */
  66. public function trainingAction() {
  67. UI::gora();
  68. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  69. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  70. Theme::top();
  71. include('page-training.view.php');
  72. UI::dol();
  73. }
  74. /**
  75. * View Page training
  76. */
  77. public function offerAction() {
  78. UI::gora();
  79. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  80. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  81. Theme::top();
  82. include('page-offer.view.php');
  83. UI::dol();
  84. }
  85. /**
  86. * View Page Help form
  87. */
  88. public function helpFormAction() {
  89. UI::gora();
  90. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  91. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  92. Theme::top();
  93. $messageValidate = array();
  94. if( V::get('button_send', 0, $_POST) == 1 ){
  95. // fields form
  96. $helpName = htmlentities(V::get('help_name', 0, $_POST));
  97. $helpEmail = htmlentities(V::get('help_email', 0, $_POST));
  98. $helpDescription = htmlentities(V::get('help_description', 0, $_POST));
  99. if ( empty($helpDescription) && !filter_var($helpEmail, FILTER_VALIDATE_EMAIL)) {
  100. $messageValidate['error'] = 1;
  101. }
  102. $noticeRequest = 'Email: ' . $helpEmail . "; Treść zgłoszenia: " . $helpDescription;
  103. // data for create insert in DB
  104. $idQualityNotice = DB::getPDO()->insert('QUALITY_NOTICES', [
  105. 'NOTICE_INITIAL_TYPE' => 'BAD_PROCESS',
  106. 'ID_PROCES' => '1', //todo: ustalić ID procesu - ustawiłem defaultowo 1!!!!!
  107. 'NOTICE_REQUEST' => $noticeRequest,
  108. 'NOTICE_REPLY' => '',
  109. 'NOTICE_REPLY_TYPE' => 'BAD_PROCESS',
  110. 'L_APPOITMENT_DATE' => 'NOW()',
  111. 'L_APPOITMENT_USER' => User::getLogin(),
  112. 'ADM_ACCOUNT' => User::getLogin(),
  113. 'THIS_SINGLE_WASTE_COST' => '',
  114. 'WASTE_COST_COMMENT' => '',
  115. 'THIS_SINGLE_FIX_COST' => '',
  116. 'YEAR_COST_FOREACST_OF_SUCH_PROBLEM_WITH_FIXING' => '',
  117. 'FIX_COST_COMMENT' => '',
  118. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  119. 'A_RECORD_CREATE_DATE' => 'NOW()'
  120. ]);
  121. if( $idQualityNotice > 0 ) {
  122. $messageValidate['success'] = 'send';
  123. } else {
  124. $messageValidate['error'] = 2;
  125. }
  126. /*
  127. TODO: dodać możliwość wysyłania maila używajac mail()
  128. // Data fpr create mail
  129. $to = self::$helpEmailTo; // uzupełnić mail
  130. $subject = 'Bocian - formularz pomocy';
  131. $message = "Zgłaszający: " . $helpName . " \r\n E-mail: " . $helpEmail . ". \r\n Treść wiadomości:\r\n " . $helpDescription;
  132. $headers = 'From: '. self::$helpEmailTo . "\r\n" .
  133. 'Reply-To: '. self::$helpEmailTo . "\r\n" .
  134. 'X-Mailer: PHP/' . phpversion();
  135. $sendMail = mail($to, $subject, $message, $headers);
  136. if( $sendMailResponse == true ) {
  137. $responseSendMail = true;
  138. $messageValidate['success'] = 'send';
  139. } else {
  140. $messageValidate['error'] = 2;
  141. }
  142. */
  143. }
  144. include('page-help.view.php');
  145. UI::dol();
  146. }
  147. public function defaultAction() {
  148. UI::gora();
  149. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  150. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  151. Theme::top();
  152. //echo '<div id="smad-wrapper">'; // todo: sprawdzi czy można usunać
  153. echo '<div class="container-bi_audit_form_pracownicy_raport" style="display: none;"></div>';
  154. echo '<div class="container-bi_audit_form_kontrahenci_raport" style="display: none;"></div>';
  155. // echo '<div class="container-bi_audit_form_raport_data" style="display: none;"></div>';
  156. UI::inlineJS(__FILE__ . '.view.js', [
  157. 'BASE_URLS' => Request::getPathUri(),
  158. 'URL_FETCH_KONTRAHENCI_POWIAZANIA' => $this->getLink('fetchEnergaRumKontrahenciPowiazaniaAjax'),
  159. 'URL_FETCH_TEST_KRS' => $this->getLink('fetchTestKrsAjax'),
  160. 'URL_FETCH_TEST_CEIDG' => $this->getLink('fetchTestCeidgAjax'),
  161. 'URL_FETCH_PRACOWNICY' => $this->getLink('fetchPracownicyAjax'),
  162. 'URL_FETCH_PRACOWNICY_IDS_AJAX' => $this->getLink('fetchPracownicyIdsAjax'),
  163. 'URL_FETCH_KONTRAHENCI' => $this->getLink('fetchKontrahenciAjax'),
  164. 'URL_FETCH_KONTRAHENCI_IDS_AJAX' => $this->getLink('fetchKontrahenciIdsAjax'),
  165. 'URL_CREATE_PRACOWNICY_GROUP' => $this->getLink('createPracownicyGroupAjax'),
  166. 'URL_CREATE_KONTRAHENCI_GROUP' => $this->getLink('createKontrahenciGroupAjax'),
  167. 'URL_ADD_PRACOWNICY_TO_GROUP' => $this->getLink('addPracownicyToGroupAjax'),
  168. 'URL_CREATE_PRACOWNICY' => $this->getLink('createPracownikAjax'),
  169. 'URL_CREATE_KONTRAHENCI' => $this->getLink('createKontrahentAjax'),
  170. 'URL_ADD_KONTRAHENCI_TO_GROUP' => $this->getLink('addKontrahenciToGroupAjax'),
  171. 'URL_FETCH_GROUP_PRACOWNICY' => $this->getLink('fetchGroupPracownicyAjax'),
  172. 'URL_FETCH_GROUP_KONTRAHENCI' => $this->getLink('fetchGroupKontrahenciAjax'),
  173. 'URL_GENERATE_BI_AUDIT_RAPORT_AJAX' => $this->getLink('generateBiAuditRaportAjax'),
  174. 'DBG' => V::get('DBG', 0, $_GET),
  175. 'VIEW_KONTRAHENCI' => $this->defaultViewFormBiAudit([], 'KONTRAHENCI'),
  176. 'VIEW_PRACOWNICY' => $this->defaultViewFormBiAudit([], 'PRACOWNICY'),
  177. 'URL_FORM_DATA_CSV_FILE_AJAX' => $this->getLink('formDataCsvFileAjax'),
  178. 'URL_SAVE_FORM_CSV_FILE_AJAX' => $this->getLink('saveFormCsvFileAjax'),
  179. 'URL_TABLE_POWIAZANIA' => Router::getRoute('ViewTableAjax', [ 'namespace' => "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA" ]),
  180. 'FIELD_LIST_PRACOWNICY' => array_merge(
  181. array_map(function ($fieldName) {
  182. return "f_{$fieldName}";
  183. }, self::$FIELD_LIST_PRACOWNICY),
  184. [
  185. 'f_Adresy',
  186. ]
  187. ),
  188. 'FIELD_LIST_KONTRAHENCI' => array_map(function ($fieldName) {
  189. return "f_{$fieldName}";
  190. }, self::$FIELD_LIST_KONTRAHENCI),
  191. ]);
  192. echo '</div>'; // #smad-wrapper
  193. UI::dol();
  194. }
  195. /**
  196. * Dodanie nowego pracownika
  197. */
  198. public function createPracownikAjaxAction() {
  199. Response::sendTryCatchJson(array($this, 'createPracownikAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
  200. }
  201. public function createPracownikAjax($args) {
  202. DBG::log($args, 'array', "args");
  203. $personName = V::get('personName', '', $args);
  204. $personSurname = V::get('personSurname', '', $args);
  205. $personNip = V::get('personNip', '', $args);
  206. $personPesel = V::get('personPesel', '', $args);
  207. $personRegon = V::get('personRegon', '', $args);
  208. // validate
  209. if (!$personName) throw new Exception("Nie wpisano imienia");
  210. if (!$personSurname) throw new Exception("Nie wpisano nazwiska");
  211. $idPracownik = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  212. 'imiona' => $personName,
  213. 'nazwisko' => $personSurname,
  214. 'nip' => ($personNip) ? $personNip : NULL,
  215. 'pesel' => ($personPesel) ? $personPesel : NULL,
  216. 'regon' => ($personRegon) ? $personRegon : NULL,
  217. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  218. 'A_RECORD_CREATE_DATE' => 'NOW()',
  219. ]);
  220. return [
  221. 'msg' => "Dodano osobę",
  222. 'type' => "success",
  223. ];
  224. }
  225. /**
  226. * Dodanie nowego kontrahenta
  227. */
  228. public function createKontrahentAjaxAction() {
  229. Response::sendTryCatchJson(array($this, 'createKontrahentAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
  230. }
  231. public function createKontrahentAjax($args) {
  232. $companyFullName = V::get('companyFullName', '', $args);
  233. $companyShortName = V::get('$companyShortName', '', $args);
  234. $companyNameGroup = V::get('companyNameGroup', '', $args);
  235. $companyKrs = V::get('companyKrs', '', $args);
  236. $companyNip = V::get('companyNip', '', $args);
  237. $companyPesel = V::get('companyPesel', '', $args);
  238. $companyFax = V::get('companyFax', '', $args);
  239. $companyTelefon = V::get('companyTelefon', '', $args);
  240. $companyMail = V::get('companyMail', '', $args);
  241. $companyStreet = V::get('companyStreet', '', $args);
  242. $companyNumberBuilding = V::get('companyNumberBuilding', '', $args);
  243. $companyNumberLocal = V::get('companyNumberLocal', '', $args);
  244. $companyPostCode = V::get('companyPostCode', '', $args);
  245. $companyPlace = V::get('companyPlace', '', $args);
  246. $companyCountry = V::get('companyCountry', '', $args);
  247. $companyTypeCompany = V::get('companyTypeCompany', '', $args);
  248. $companyTitleDocument = V::get('companyTitleDocument', '', $args);
  249. $companyDesc = V::get('companyDesc', '', $args);
  250. // validate
  251. if (!$companyFullName) throw new Exception("Nie wpisano pełnej nazwy kontrahenta");
  252. $idKontrahent = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  253. 'Pelna_nazwa_kontrahenta' => $companyFullName,
  254. 'Skrocona_Nazwa_Kontrahenta' => ($companyShortName) ? $companyShortName : null,
  255. 'Nazwa_grupy_kapitalowej' => ($companyNameGroup) ? $companyNameGroup : null,
  256. 'KRS' => ($companyKrs) ? $companyKrs : null,
  257. 'NIP' => ($companyNip) ? $companyNip : null,
  258. 'PESEL' => ($companyPesel) ? $companyPesel : null,
  259. 'Fax' => ($companyFax) ? $companyFax : null,
  260. 'Telefon' => ($companyTelefon) ? $companyTelefon : null,
  261. 'Mail' => ($companyMail) ? $companyMail : null,
  262. 'Ulica' => ($companyStreet) ? $companyStreet : null,
  263. 'Numer_budynku' => ($companyNumberBuilding) ? $companyNumberBuilding : null,
  264. 'Numer_mieszkania_lokalu' => ($companyNumberLocal) ? $companyNumberLocal : null,
  265. 'Kod_pocztowy' => ($companyPostCode) ? $companyPostCode : null,
  266. 'Miejscowosc' => ($companyPlace) ? $companyPlace : null,
  267. 'Kraj' => ($companyCountry) ? $companyCountry : null,
  268. 'Typ_kontrahenta' => ($companyTypeCompany) ? $companyTypeCompany : null,
  269. 'Tytul_dokumentu' => ($companyTitleDocument) ? $companyTitleDocument : null,
  270. 'uwagi' => ($companyDesc) ? $companyDesc : null,
  271. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  272. 'A_RECORD_CREATE_DATE' => 'NOW()',
  273. ]);
  274. return [
  275. 'msg' => "Dodano podmiot/kontrahenta",
  276. 'type' => "success",
  277. ];
  278. }
  279. /**
  280. * Funkcja ajax do odebrania danych z przesłanego pliku CSV do parsowania
  281. */
  282. public function formDataCsvFileAjaxAction() {
  283. Response::sendTryCatchJson(array($this, 'formDataCsvFileAjax'));
  284. }
  285. /**
  286. * Funkcja parsuje dane wgrywanego plku csv i zwraca dane w inputach
  287. */
  288. public function formDataCsvFileAjax() {
  289. if (!file_exists($_FILES['file']['tmp_name'])) throw new Exception("Wybierz plik do przesłania.");
  290. $file = file($_FILES['file']['tmp_name']);
  291. //$showCheckbox = V::get('showCheckbox', '', $args);
  292. $showCheckbox = V::get('showCheckbox', 0, $_REQUEST, 'string');
  293. // parsujemy csv to tablicy
  294. $arrayDataCsv = $this->csvToArray($file, ';', '"', '\n\r');
  295. $i = 0;
  296. // tworzymy rekordy
  297. foreach ( $arrayDataCsv as $line ) {
  298. $viewFormCol .= '<tr>';
  299. foreach ( $line as $keyData => $rowData ) {
  300. // utworzenie nagłówków tabeli
  301. if( $i == 0) { $header .= '<td style="min-width:160px">' . $keyData . '</td>'; }
  302. // utworzenie inputa do edycji
  303. $viewFormCol .= '<td style="min-width:160px"><input type="text" name="item['.$i.']['.$keyData.']" value="'.$rowData .'" class="form-control input-lg" /></td>';
  304. }
  305. $viewFormCol .= '</tr>';
  306. $i++;
  307. }
  308. // pokaz checkbox jeśli ma status showCheckbox
  309. if ( $showCheckbox == 'yes' ) {
  310. $viewFormCol .= '<div style="margin: 10px 0"><input type="checkbox" name="override" value="1" /> Nadpisz wszystkie rekordy w bazie danych</div';
  311. }
  312. $viewFormHtml = '<div id="smad-window-modal" style="overflow-x: scroll;">
  313. <div class="table-responsive padding-0" >
  314. <form method="POST" id="formDataFromCsv" class="form-horizontal"><table class="table table-bordered table-hover table-striped" height="5"><thead><tr>'. $header .'</tr></thead><tbody id="smad-csv-data">'. $viewFormCol .'</tbody></table></form></div>
  315. </div>';
  316. //return $viewFormHtml;
  317. return [
  318. 'type' => 'success',
  319. 'msg' => 'OK',
  320. '__req_args' => $_REQUEST,
  321. '__args' => $args,
  322. 'body' => [
  323. 'view' => $viewFormHtml,
  324. ]
  325. ];
  326. }
  327. /**
  328. * Funkcja ajax do odebrania danych z przesłanego formularza z parsowanego CSV
  329. */
  330. public function saveFormCsvFileAjaxAction() {
  331. Response::sendTryCatchJson(array($this, 'saveFormCsvFileAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  332. //Response::sendTryCatchJson(array($this, 'saveFormCsvFileAjax'));
  333. }
  334. /**
  335. * Funkcja ajax do zapisania danych z przesłanego formularza z parsowanego CSV
  336. */
  337. public function saveFormCsvFileAjax($args) {
  338. //dane z formularza
  339. $formData = V::get('formData', '', $args);
  340. $enumType = V::get('enumType', '', $args);
  341. $override = false; // false - nie nadpisujemy danych
  342. $arrayInfo = array();
  343. $arrayInfo['insert'] = 0;
  344. $arrayInfo['update'] = 0;
  345. $arrayInfo['error'] = 0;
  346. // pobranie nazwy tabeli z db
  347. $table = $this->getNameTableByEnum( strtoupper($enumType) );
  348. if ( $table == null ) throw new Exception('Błąd zapisu. Tabela w db nie istnieje');
  349. // unserialize data from serialize in javascript
  350. parse_str($formData, $resultArrayFormdata);
  351. if ( count($resultArrayFormdata['item']) == 0) {
  352. throw new Exception("Wystapił problem podczas przesyłania danych - brak przesłanych danych.");
  353. }
  354. // ustawienie true jeśli wyrabno nadpisanie danych
  355. if ( isset($resultArrayFormdata['override']) ) { $override = true; } // aktualizuj rekordy/nadpisz istniejace
  356. // dodanie/aktualizacjia wpisu
  357. foreach ( $resultArrayFormdata['item'] as $line ) {
  358. $response = $this->saveDataToDb($table, $line, $override);
  359. // tworzymy listę informacji o liczbie nowych/zaktualizowanych/z błedami rekordów
  360. $arrayInfo = $this->responseCountListInfoAboutSaveData($response, $arrayInfo);
  361. }
  362. // utworzenie komunikatów
  363. if ( isset($arrayInfo['insert']) ) { $textInsert = "Liczba nowych rekordów: (" . $arrayInfo['insert'] . ");"; }
  364. if ( isset($arrayInfo['error']) ) { $textError = "Liczba nie zapisanych rekordów (" . $arrayInfo['insert'] . ");"; }
  365. return [
  366. 'msg' => "Zapisano dane. " . $textInsert . " " . $textError ,
  367. 'type' => "success",
  368. ];
  369. }
  370. /**
  371. * Count list
  372. */
  373. public function responseCountListInfoAboutSaveData($response, $arrayInfo) {
  374. if (!is_array($response)) throw new Exception('Wystapił bład podczas zapisu danych');
  375. $countData = array();
  376. switch(key($response)) {
  377. case 'insert':
  378. $countData['insert'] = $arrayInfo['insert'] + 1;
  379. break;
  380. case 'error':
  381. $countData['error'] = $arrayInfo['insert'] + 1;
  382. break;
  383. }
  384. return $countData;
  385. }
  386. /**
  387. * Function parse csv to array
  388. * @param $filename - file data from FILE
  389. * @param $delimiter - delimiter
  390. * @param $enclosure -
  391. * @param $escape -
  392. */
  393. function csvToArray($filedata , $delimiter=';', $enclosure='"', $escape = '\\') {
  394. if(!$filedata || empty($filedata)) return false;
  395. $header = null;
  396. $data = array();
  397. foreach( $filedata as $line) {
  398. $values = str_getcsv( $line, $delimiter, $enclosure, $escape );
  399. if(!$header) $header = $values;
  400. else $data[] = array_combine( $header, $values );
  401. }
  402. return $data;
  403. }
  404. /**
  405. * Save data in database
  406. */
  407. public function saveDataToDb( $table, $arrayData, $override = false ) {
  408. $response = array();
  409. try {
  410. if ($override) {
  411. DB::getPDO()->insertOrUpdate($table, array_merge($arrayData, [
  412. '@insert' => [
  413. 'A_RECORD_CREATE_DATE' => 'NOW()',
  414. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  415. ],
  416. '@update' => array_merge($arrayData, [
  417. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  418. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  419. ]),
  420. ]));
  421. } else {
  422. $responseInsert = DB::getPDO()->insert($table, array_merge($arrayData, [
  423. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  424. 'A_RECORD_CREATE_DATE' => 'NOW()',
  425. ]));
  426. }
  427. $response['insert'] = 1;
  428. } catch (Exception $e) {
  429. DBG::log($e);
  430. $response['error'] = 1;
  431. }
  432. return $response;
  433. }
  434. /**
  435. * Get name table by enum
  436. */
  437. public function getNameTableByEnum($type) {
  438. $nameTable = null;
  439. switch ($type) {
  440. case 'KONTRAHENCI':
  441. $nameTable = 'BI_audit_ENERGA_RUM_KONTRAHENCI';
  442. break;
  443. case 'PRACOWNICY':
  444. $nameTable = 'BI_audit_ENERGA_PRACOWNICY';
  445. break;
  446. }
  447. return $nameTable;
  448. }
  449. public function fetchEnergaRumKontrahenciPowiazaniaAjaxAction() {
  450. Response::sendTryCatchJson(array($this, 'fetchEnergaRumKontrahenciPowiazaniaAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  451. }
  452. public function fetchEnergaRumKontrahenciPowiazaniaAjax($args) {
  453. $id = V::get('ID', 26, $_REQUEST, 'int');
  454. $items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA')->buildQuery([
  455. 'cols' => [ // TODO:? propertyName = []
  456. 'ID',
  457. 'A_ADM_COMPANY',
  458. 'L_APPOITMENT_USER',
  459. 'A_CLASSIFIED',
  460. 'A_STATUS',
  461. 'A_STATUS_INFO',
  462. 'BI_analiza_maxDepth',
  463. 'BI_analiza_minDepth',
  464. 'BI_analiza_onlyTargets',
  465. 'BI_analiza_reloadCache',
  466. 'FILE_STATUS',
  467. 'FILE_STATUS_info',
  468. 'L_APPOITMENT_USER',
  469. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  470. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  471. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  472. 'default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person',
  473. ],
  474. 'f_ID' => "{$id}",
  475. ])->getItems([
  476. 'limit' => 10
  477. ]);
  478. // $items = [
  479. // [ 'ID' => 1, 'L_APPOITMENT_INFO' => 'x', 'BI_analiza_depth' => 'a', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test1'],
  480. // [ 'ID' => 2, 'L_APPOITMENT_INFO' => 'y', 'BI_analiza_depth' => 'b', 'FILE_STATUS' => 0, 'FILE_STATUS_info' => 'test2'],
  481. // [ 'ID' => 3, 'L_APPOITMENT_INFO' => 'z', 'BI_analiza_depth' => 'c', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test3'],
  482. // ];
  483. return [
  484. 'type' => 'success',
  485. 'msg' => 'OK',
  486. '__req_args' => $_REQUEST,
  487. '__args' => $args,
  488. 'body' => [
  489. 'items' => $items,
  490. 'view' => $this->showPowiazaniaEnergaRumKontrahenciPowiazania($items),
  491. ]
  492. ];
  493. }
  494. public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
  495. $view = '<form class="form-horizontal" method="post">
  496. <table class="table table-bordered table-hover table-striped" height=5>
  497. <thead>
  498. <tr style="">
  499. <td width=1><input type="checkbox" name="checkAll" id="checkAll" /></td>
  500. <td width=1>ID</td>
  501. <td>Adnotacje</td>
  502. <td>Głębokość analizy</td>
  503. <td>Status raportu</td>
  504. <td>Status raportu - informacje</td>
  505. </tr>
  506. </thead>
  507. <tbody>
  508. ';
  509. foreach ($items as $key => $row) {
  510. $view .= '<tr>
  511. <td><input type="checkbox" name="prID[]" value="'.$row['ID'].'" onClick="checkAll()"/></td>
  512. <td align="right">'.$row["ID"].'</td>
  513. <td align="right">'.$row["L_APPOITMENT_INFO"].'</td>
  514. <td align="right">'.$row["BI_analiza_depth"].'</td>
  515. <td align="right">'.$row["FILE_STATUS"].'</td>
  516. <td align="right">'.$row["FILE_STATUS_info"].'</td>';
  517. }
  518. $view .= '</tbody></table></form>';
  519. return $view;
  520. }
  521. public function fetchTestKrsAjaxAction() {
  522. Response::sendTryCatchJson(array($this, 'fetchTestKrsAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  523. }
  524. public function fetchTestKrsAjax($args) {
  525. $id = V::get('ID', 1, $_REQUEST, 'int');
  526. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery([
  527. 'cols' => [ // TODO:? propertyName = []
  528. 'A_kod',
  529. 'A_kraj',
  530. 'A_miejscowosc',
  531. 'A_nrDomu',
  532. 'A_nrLokalu',
  533. 'A_poczta',
  534. 'A_ulica',
  535. 'ID',
  536. 'S_gmina',
  537. 'S_kraj',
  538. 'S_miejscowosc',
  539. 'S_powiat',
  540. 'S_wojewodztwo',
  541. 'dataDokumentu',
  542. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  543. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  544. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  545. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  546. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  547. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  548. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  549. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  550. 'krs',
  551. 'nazwa',
  552. 'nip',
  553. 'regon',
  554. ],
  555. 'f_ID' => "{$id}",
  556. ])->getItems([
  557. 'limit' => 10
  558. ]);
  559. return [
  560. 'type' => 'success',
  561. 'msg' => 'KRS',
  562. '__req_args' => $_REQUEST,
  563. '__args' => $args,
  564. 'body' => [
  565. 'items' => $items,
  566. ]
  567. ];
  568. }
  569. public function fetchTestCeidgAjaxAction() {
  570. Response::sendTryCatchJson(array($this, 'fetchTestCeidgAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  571. }
  572. public function fetchTestCeidgAjax($args) {
  573. $id = V::get('ID', 0, $_REQUEST, 'int');
  574. $items = ACL::getAclByNamespace('default_db/BI_audit_CEIDG/BI_audit_CEIDG')->buildQuery([
  575. 'cols' => [ // TODO:? propertyName = []
  576. 'ID',
  577. 'budynek',
  578. 'firma',
  579. 'gmina',
  580. 'identyfikatorWpisu',
  581. 'imie',
  582. 'kodPocztowy',
  583. 'kraj',
  584. 'lokal',
  585. 'miejscowosc',
  586. 'nazwisko',
  587. 'nip',
  588. 'poczta',
  589. 'powiat',
  590. 'regon',
  591. 'ulica',
  592. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ID',
  593. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/budynek',
  594. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/gmina',
  595. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/kodPocztowy',
  596. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/lokal',
  597. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/miejscowosc',
  598. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nazwa',
  599. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nip',
  600. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/poczta',
  601. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/powiat',
  602. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ulica',
  603. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/wojewodztwo',
  604. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/ID',
  605. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/nip',
  606. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/regon',
  607. ],
  608. // 'f_ID' => $id,
  609. ])->getItems([
  610. 'limit' => 10
  611. ]);
  612. return [
  613. 'type' => 'success',
  614. 'msg' => 'CEIDG',
  615. '__req_args' => $_REQUEST,
  616. '__args' => $args,
  617. 'body' => [
  618. 'items' => $items,
  619. ]
  620. ];
  621. }
  622. public function fetchKontrahenciIdsAjaxAction() {
  623. Response::sendTryCatchJson(array($this, 'fetchKontrahenciIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  624. }
  625. public function fetchKontrahenciIdsAjax($args) {
  626. $idGroup = V::get('filter_idGroup', 0, $args, 'int');
  627. if ($idGroup < 0) $idGroup = 0;
  628. $backRefFilter = [];
  629. if ($idGroup > 0) {
  630. $backRefFilter['__backRef'] = [
  631. 'namespace' => 'default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  632. 'primaryKey' => $idGroup,
  633. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  634. ];
  635. }
  636. $searchParams = []; // TODO: ???
  637. $filtersParams = [];
  638. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  639. return ('f_' === substr($key, 0, 2));
  640. });
  641. foreach ($fieldFilterKeys as $key) {
  642. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  643. }
  644. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  645. $query = $acl->buildQuery(array_merge([
  646. 'cols' => [
  647. 'ID',
  648. ],
  649. //'f_ID' => $id,
  650. 'limit' => 0,
  651. // 'limitstart' => $limitstart, // offset
  652. // 'order_by' => 'ID', // sortowanie po kolumnie
  653. // 'order_dir' => 'DESC', // kierunek sortowania
  654. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  655. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  656. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  657. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  658. ], $searchParams, $filtersParams, $backRefFilter));
  659. // $total = $query->getTotal();
  660. $items = $query->getItems();
  661. return [
  662. 'type' => 'success',
  663. 'msg' => 'kontrahenci ids',
  664. 'body' => [
  665. 'ids' => array_map( V::makePick('ID'), $items ),
  666. ],
  667. '__DBG_args' => $args,
  668. '__DBG_$idGroup' => $idGroup,
  669. '__DBG_$filtersParams' => $filtersParams,
  670. '__DBG_$backRefFilter' => $backRefFilter,
  671. ];
  672. }
  673. /**
  674. * KONTRAHENCI
  675. */
  676. public function fetchKontrahenciAjaxAction() {
  677. Response::sendTryCatchJson(array($this, 'fetchKontrahenciAjax'), $args = $_REQUEST);
  678. }
  679. public function fetchKontrahenciAjax($args) {
  680. $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  681. if ($idGroup < 0) $idGroup = 0;
  682. $limit = 20;
  683. $limitstart = V::get('limitstart', 0, $args, 'int');
  684. if ($limitstart < 0) $limitstart = 0;
  685. $page = V::get('page', 0, $args, 'int');
  686. $limitstart = ($page - 1) * $limit;
  687. $search = V::get('search', '', $args);
  688. $searchParams = [];
  689. if (!empty($search)) {
  690. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  691. $searchParams['ogc:Filter'] = '
  692. <ogc:Filter>
  693. <ogc:Or>
  694. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  695. <ogc:PropertyName>NIP</ogc:PropertyName>
  696. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  697. </ogc:PropertyIsLike>
  698. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  699. <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
  700. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  701. </ogc:PropertyIsLike>
  702. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  703. <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
  704. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  705. </ogc:PropertyIsLike>
  706. </ogc:Or>
  707. </ogc:Filter>
  708. ';
  709. }
  710. // ogc filter w środku ogcand potem ogcnot potem PropertyIsEqualTo
  711. $backRefFilter = [];
  712. if ($idGroup > 0) {
  713. $backRefFilter['__backRef'] = [
  714. 'namespace' => 'default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  715. 'primaryKey' => $idGroup,
  716. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  717. ];
  718. // - ID
  719. // - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
  720. // - NAZWA - nazwa grupy
  721. // - 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_KONTRAHENCI' minOccurs="0" maxOccurs="unbounded"
  722. }
  723. $filtersParams = [];
  724. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  725. return ('f_' === substr($key, 0, 2));
  726. });
  727. foreach ($fieldFilterKeys as $key) {
  728. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  729. }
  730. DBG::log($filtersParams, 'Kontrahenci $filtersParams');
  731. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  732. $query = $acl->buildQuery(array_merge([
  733. 'cols' => [ // TODO:? propertyName = []
  734. 'ID',
  735. 'Nazwa_grupy_kapitalowej',
  736. 'Pelna_nazwa_kontrahenta',
  737. 'Numer_kontrahenta',
  738. 'Skrocona_Nazwa_Kontrahenta',
  739. 'Typ_kontrahenta',
  740. 'NIP',
  741. 'KRS',
  742. 'REGON',
  743. 'PESEL',
  744. 'Forma_prawna_dzialalnosci',
  745. 'Ulica',
  746. 'Numer_budynku',
  747. 'Numer_mieszkania_lokalu',
  748. 'Miejscowosc',
  749. 'Kod_pocztowy',
  750. 'Kraj',
  751. 'Telefon',
  752. 'Fax',
  753. 'Mail',
  754. 'A_ADM_COMPANY',
  755. 'A_CLASSIFIED',
  756. 'Dodano',
  757. 'Podmiot_dominujacy',
  758. 'Tytul_dokumentu',
  759. 'ownCompany',
  760. 'uwagi',
  761. ],
  762. //'f_ID' => $id,
  763. 'limit' => $limit,
  764. 'limitstart' => $limitstart, // offset
  765. 'order_by' => 'ID', // sortowanie po kolumnie
  766. 'order_dir' => 'DESC', // kierunek sortowania
  767. ], $searchParams, $filtersParams, $backRefFilter));
  768. $total = $query->getTotal();
  769. $items = $query->getItems();
  770. $pagination = array();
  771. $pagination['total_items'] = $total;
  772. $pagination['size'] = ceil($total/$limit); // pages size
  773. $pagination['current'] = $page;
  774. $pagination['limit'] = $limit;
  775. if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
  776. return [
  777. 'type' => 'success',
  778. 'msg' => 'showKontrajenci',
  779. 'body' => [
  780. 'items' => $items,
  781. //'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI'),
  782. 'pagination' => $pagination
  783. ],
  784. '__DBG_args' => $args,
  785. '__DBG_$idGroup' => $idGroup,
  786. '__DBG_$filtersParams' => $filtersParams,
  787. '__DBG_$backRefFilter' => $backRefFilter,
  788. ];
  789. }
  790. public function showTableKontrahenci($labels = []) {
  791. // TODO: use self::$FIELD_LIST_KONTRAHENCI
  792. $view = '<form class="form-horizontal" method="post">
  793. <table class="table table-bordered table-hover table-striped" height=5>
  794. <thead>
  795. <tr>
  796. <td width=1><input type="checkbox" name="checkAll" id="checkAll-KONTRAHENCI" /></td>
  797. <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
  798. <td>' . V::get('Nazwa_grupy_kapitalowej', 'Nazwa grupy kapitalowej', $labels) . '</td>
  799. <td>' . V::get('Pelna_nazwa_kontrahenta', 'Pelna nazwa kontrahenta', $labels) . '</td>
  800. <td>' . V::get('Numer_kontrahenta', 'Numer kontrahenta', $labels) . '</td>
  801. <td>' . V::get('Skrocona_Nazwa_Kontrahenta', 'Skrócona nazwa kontrahenta', $labels) . '</td>
  802. <td>' . V::get('Typ_kontrahenta', 'Typ_kontrahenta', $labels) . '</td>
  803. <td>' . V::get('NIP', 'NIP', $labels) . '</td>
  804. <td>' . V::get('KRS', 'KRS', $labels) . '</td>
  805. <td>' . V::get('REGON', 'Regon', $labels) . '</td>
  806. <td>' . V::get('PESEL', 'PESEL', $labels) . '</td>
  807. <td>' . V::get('Forma_prawna_dzialalnosci', 'Forma prawna działalności', $labels) . '</td>
  808. <td>' . V::get('Ulica', 'Ulica', $labels) . '</td>
  809. <td>' . V::get('Numer_budynku', 'Numer budynku', $labels) . '</td>
  810. <td>' . V::get('Numer_mieszkania_lokalu', 'Numer mieszkania lokalu', $labels) . '</td>
  811. <td>' . V::get('Miejscowosc', 'Miejscowosc', $labels) . '</td>
  812. <td>' . V::get('Kod_pocztowy', 'Kod pocztowy', $labels) . '</td>
  813. <td>' . V::get('Kraj', 'Kraj', $labels) . '</td>
  814. <td>' . V::get('Telefon', 'Telefon', $labels) . '</td>
  815. <td>' . V::get('Fax', 'Fax', $labels) . '</td>
  816. <td>' . V::get('Mail', 'Mail', $labels) . '</td>
  817. <td>' . V::get('A_ADM_COMPANY', 'A_ADM_COMPANY', $labels) . '</td>
  818. <td>' . V::get('A_CLASSIFIED', 'A_CLASSIFIED', $labels) . '</td>
  819. <td>' . V::get('Dodano', 'Dodano', $labels) . '</td>
  820. <td>' . V::get('Podmiot_dominujacy', 'Podmiot dominujacy', $labels) . '</td>
  821. <td>' . V::get('Tytul_dokumentu', 'Tytul dokumentu', $labels) . '</td>
  822. <td>' . V::get('ownCompany', 'ownCompany', $labels) . '</td>
  823. <td>' . V::get('uwagi', 'uwagi', $labels) . '</td>
  824. </tr>
  825. <tr>
  826. <td style="padding:0" width=1><button style="padding:5px" id="filtersFieldRemoveBtn-KONTRAHENCI" onClick="return removeFiltersKontrahenci(event, this)" title="Kasuj filtry" class="btn btn-xs btn-link glyphicon glyphicon-remove"></button></td>
  827. <td style="padding:0"><input style="padding:2px 8px; width:80px" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_ID" value="" placeholder="%"></td>
  828. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Nazwa_grupy_kapitalowej" value="" placeholder="%"></td>
  829. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Pelna_nazwa_kontrahenta" value="" placeholder="%"></td>
  830. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Numer_kontrahenta" value="" placeholder="%"></td>
  831. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Skrocona_Nazwa_Kontrahenta" value="" placeholder="%"></td>
  832. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Typ_kontrahenta" value="" placeholder="%"></td>
  833. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_NIP" value="" placeholder="%"></td>
  834. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_KRS" value="" placeholder="%"></td>
  835. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_REGON" value="" placeholder="%"></td>
  836. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_PESEL" value="" placeholder="%"></td>
  837. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Forma_prawna_dzialalnosci" value="" placeholder="%"></td>
  838. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Ulica" value="" placeholder="%"></td>
  839. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Numer_budynku" value="" placeholder="%"></td>
  840. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Numer_mieszkania_lokalu" value="" placeholder="%"></td>
  841. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Miejscowosc" value="" placeholder="%"></td>
  842. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Kod_pocztowy" value="" placeholder="%"></td>
  843. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Kraj" value="" placeholder="%"></td>
  844. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Telefon" value="" placeholder="%"></td>
  845. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Fax" value="" placeholder="%"></td>
  846. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Mail" value="" placeholder="%"></td>
  847. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_A_ADM_COMPANY" value="" placeholder="%"></td>
  848. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_A_CLASSIFIED" value="" placeholder="%"></td>
  849. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Dodano" value="" placeholder="%"></td>
  850. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Podmiot_dominujacy" value="" placeholder="%"></td>
  851. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Tytul_dokumentu" value="" placeholder="%"></td>
  852. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_ownCompany" value="" placeholder="%"></td>
  853. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_uwagi" value="" placeholder="%"></td>
  854. </tr>
  855. </thead>
  856. <tbody id="body-kontrahenci">
  857. </tbody></table>
  858. </form>
  859. ';
  860. return $view;
  861. }
  862. // tworzenie grupy kontrahentów
  863. public function createKontrahenciGroupAjaxAction() {
  864. 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
  865. }
  866. public function createKontrahenciGroupAjax($args) {
  867. $nazwa = V::get('NAZWA', '', $args);
  868. // TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje
  869. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_KONTRAHENCI_group', [
  870. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  871. 'A_RECORD_CREATE_DATE' => 'NOW()',
  872. 'NAZWA' => $nazwa,
  873. 'ID_USER' => User::getID()
  874. ]);
  875. return [
  876. 'msg' => "Utworzona grupę {$idGroup}",
  877. 'type' => "success",
  878. 'body' => [
  879. 'id' => $idGroup,
  880. 'nazwa' => $nazwa
  881. ]
  882. ];
  883. }
  884. // Dodanie do grupy filtra kontrahentów
  885. public function addKontrahenciToGroupAjaxAction() {
  886. 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
  887. }
  888. public function addKontrahenciToGroupAjax($args) {
  889. $idGroup = V::get('idGroup', '', $args);
  890. $type = V::get('type', 'ids', $args);
  891. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  892. $filter = V::get('filter', '', $args);
  893. // validate
  894. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  895. switch ($type) {
  896. case 'ids': {
  897. if (!$kontrahenciIds || count($kontrahenciIds) == 0) throw new Exception("Proszę wybrać kontrahentów");
  898. } break;
  899. case 'filter': {
  900. if (!isset($args['filter'])) throw new Exception("Proszę wybrać kontrahentów");
  901. } break;
  902. default: throw new Exception("Missing type");
  903. }
  904. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  905. 'cols' => [ // TODO:? propertyName = []
  906. 'ID',
  907. 'ID_USER',
  908. 'NAZWA',
  909. ],
  910. // 'f_ID_USER' => User::getID()
  911. ])->getItem($idGroup);
  912. if (!$group) throw new Exception("Grupa nie istnieje");
  913. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  914. if ('filter' === $type) {
  915. $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  916. if ($args__idGroup < 0) $args__idGroup = 0;
  917. $search = V::get('search', '', $args['filter']);
  918. $searchParams = [];
  919. if (!empty($search)) {
  920. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  921. $searchParams['ogc:Filter'] = '
  922. <ogc:Filter>
  923. <ogc:Or>
  924. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  925. <ogc:PropertyName>NIP</ogc:PropertyName>
  926. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  927. </ogc:PropertyIsLike>
  928. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  929. <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
  930. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  931. </ogc:PropertyIsLike>
  932. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  933. <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
  934. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  935. </ogc:PropertyIsLike>
  936. </ogc:Or>
  937. </ogc:Filter>
  938. ';
  939. }
  940. $backRefFilter = [];
  941. if ($args__idGroup > 0) {
  942. $backRefFilter['__backRef'] = [
  943. 'namespace' => 'default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  944. 'primaryKey' => $args__idGroup,
  945. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  946. ];
  947. }
  948. $filtersParams = [];
  949. $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
  950. return ('f_' === substr($key, 0, 2));
  951. });
  952. foreach ($fieldFilterKeys as $key) {
  953. $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
  954. }
  955. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  956. $query = $acl->buildQuery(array_merge([
  957. 'cols' => ['ID'],
  958. ], $searchParams, $filtersParams, $backRefFilter, [
  959. 'limit' => 0
  960. ]));
  961. $items = $query->getItems();
  962. $kontrahenciIds = array_map(function ($row) {
  963. return $row['ID'];
  964. }, $items);
  965. }
  966. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  967. $refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  968. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  969. foreach ($kontrahenciIds as $kontrahentIds) {
  970. DB::getPDO()->insert($refGrupyToKontrahenci, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $kontrahentIds]);
  971. }
  972. return [
  973. 'msg' => "Powiązano kontrahentów z grupą {$idGroup}",
  974. 'type' => "success",
  975. ];
  976. }
  977. public function fetchGroupKontrahenciAjaxAction() {
  978. Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
  979. }
  980. public function fetchGroupKontrahenciAjax() {
  981. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  982. 'cols' => [ // TODO:? propertyName = []
  983. 'ID',
  984. 'ID_USER',
  985. 'NAZWA',
  986. ],
  987. 'f_ID_USER' => "=" . User::getID(),
  988. 'f_A_STATUS' => "!DELETED",
  989. ]);
  990. $itemsKontrahenci = $query->getItems();
  991. if (empty($itemsKontrahenci)) throw new AlertWarningException("Grupy nie istnieją");
  992. $arrayGroupKontrahenci = array();
  993. foreach ($itemsKontrahenci as $item) {
  994. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  995. $arrayGroupKontrahenci[] = [
  996. 'NAZWA' => $item['NAZWA'],
  997. 'ID' => $item['ID'],
  998. ];
  999. }
  1000. return [
  1001. 'type' => 'success',
  1002. 'msg' => 'fetchGroupKontrahenciAjax',
  1003. '__req_args' => $_REQUEST,
  1004. '__args' => $args,
  1005. 'body' => [
  1006. 'itemsGroupKontrahenci' => $arrayGroupKontrahenci
  1007. ]
  1008. ];
  1009. }
  1010. public function fetchPracownicyIdsAjaxAction() {
  1011. Response::sendTryCatchJson(array($this, 'fetchPracownicyIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1012. }
  1013. public function fetchPracownicyIdsAjax($args) {
  1014. $idGroup = V::get('filter_idGroup', 0, $args, 'int');
  1015. if ($idGroup < 0) $idGroup = 0;
  1016. $backRefFilter = [];
  1017. if ($idGroup > 0) {
  1018. $backRefFilter['__backRef'] = [
  1019. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1020. 'primaryKey' => $idGroup,
  1021. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1022. ];
  1023. }
  1024. $searchParams = []; // TODO: ???
  1025. $filtersParams = [];
  1026. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1027. return ('f_' === substr($key, 0, 2));
  1028. });
  1029. foreach ($fieldFilterKeys as $key) {
  1030. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1031. }
  1032. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1033. $query = $acl->buildQuery(array_merge([
  1034. 'cols' => [
  1035. 'ID',
  1036. ],
  1037. //'f_ID' => $id,
  1038. 'limit' => 0,
  1039. // 'limitstart' => $limitstart, // offset
  1040. // 'order_by' => 'ID', // sortowanie po kolumnie
  1041. // 'order_dir' => 'DESC', // kierunek sortowania
  1042. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1043. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1044. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1045. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1046. ], $searchParams, $filtersParams, $backRefFilter));
  1047. // $total = $query->getTotal();
  1048. $items = $query->getItems();
  1049. return [
  1050. 'type' => 'success',
  1051. 'msg' => 'pracownicy ids',
  1052. 'body' => [
  1053. 'ids' => array_map( V::makePick('ID'), $items ),
  1054. ],
  1055. '__args' => $args,
  1056. '__DBG_$idGroup' => $idGroup,
  1057. '__DBG_$filtersParams' => $filtersParams,
  1058. '__DBG_$backRefFilter' => $backRefFilter,
  1059. ];
  1060. }
  1061. /*
  1062. * PRACOWNICY
  1063. */
  1064. public function fetchPracownicyAjaxAction() {
  1065. Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'), $args = $_REQUEST);
  1066. }
  1067. public function fetchPracownicyAjax($args) {
  1068. $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1069. if ($idGroup < 0) $idGroup = 0;
  1070. $limit = 20;
  1071. $page = V::get('page', 0, $args, 'int');
  1072. $limitstart = ($page - 1) * $limit;
  1073. $search = V::get('search', '', $args);
  1074. $searchParams = [];
  1075. if (!empty($search)) {
  1076. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1077. $searchParams['ogc:Filter'] = '
  1078. <ogc:Filter>
  1079. <ogc:Or>
  1080. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1081. <ogc:PropertyName>nip</ogc:PropertyName>
  1082. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1083. </ogc:PropertyIsLike>
  1084. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1085. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1086. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1087. </ogc:PropertyIsLike>
  1088. </ogc:Or>
  1089. </ogc:Filter>
  1090. ';
  1091. }
  1092. $backRefFilter = [];
  1093. if ($idGroup > 0) {
  1094. $backRefFilter['__backRef'] = [
  1095. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1096. 'primaryKey' => $idGroup,
  1097. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1098. ];
  1099. }
  1100. $filtersParams = [];
  1101. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1102. return ('f_' === substr($key, 0, 2));
  1103. });
  1104. foreach ($fieldFilterKeys as $key) {
  1105. if ('f_ID' === $key) $filtersParams[ $key ] = '=' . $args[ $key ];
  1106. else $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1107. }
  1108. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1109. $query = $acl->buildQuery(array_merge([
  1110. 'cols' => array_merge(self::$FIELD_LIST_PRACOWNICY, [
  1111. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  1112. ]),
  1113. //'f_ID' => $id,
  1114. 'limit' => $limit,
  1115. 'limitstart' => $limitstart, // offset
  1116. 'order_by' => 'ID', // sortowanie po kolumnie
  1117. 'order_dir' => 'DESC', // kierunek sortowania
  1118. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1119. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1120. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1121. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1122. ], $searchParams, $filtersParams, $backRefFilter));
  1123. $total = $query->getTotal();
  1124. $items = $query->getItems();
  1125. $pagination = array();
  1126. $pagination['total_items'] = $total;
  1127. $pagination['size'] = ceil($total/$limit); // pages size
  1128. $pagination['current'] = $page;
  1129. $pagination['limit'] = $limit;
  1130. // $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1131. if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
  1132. // { // tworzenie własnego zapytanie mysql
  1133. // $rootTableName = $acl->getRootTableName();
  1134. // DB::getPDO()->fetchAll("
  1135. // select t.*
  1136. // from {$rootTableName} t
  1137. // where t.ID in (
  1138. // select x.ID
  1139. // from ... x
  1140. // where
  1141. // )
  1142. // ");
  1143. // }
  1144. return [
  1145. 'type' => 'success',
  1146. 'msg' => 'showPracownicy',
  1147. 'body' => [
  1148. 'items' => $items,
  1149. //'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
  1150. 'pagination' => $pagination
  1151. ],
  1152. '__DBG_$idGroup' => $idGroup,
  1153. '__DBG_$filtersParams' => $filtersParams,
  1154. '__DBG_$backRefFilter' => $backRefFilter,
  1155. ];
  1156. }
  1157. public function showTablePracownicy($labels = []) {
  1158. // TODO: use self::$FIELD_LIST_PRACOWNICY
  1159. $view = '<form class="form-horizontal" method="post">
  1160. <table class="table table-responsive table-bordered table-hover table-striped" height=5>
  1161. <thead>
  1162. <tr>
  1163. <td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
  1164. <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
  1165. <td>' . V::get('imiona', 'Imię/Imiona', $labels) . '</td>
  1166. <td>' . V::get('nazwisko', 'Nazwisko', $labels) . '</td>
  1167. <td>' . V::get('nip', 'NIP', $labels) . '</td>
  1168. <td>' . V::get('pesel', 'Pesel', $labels) . '</td>
  1169. <td>' . V::get('regon', 'Regon', $labels) . '</td>
  1170. <td>' . V::get('source', 'source', $labels) . '</td>
  1171. <td>' . V::get('jednostka_organizacyjna', 'jednostka_organizacyjna', $labels) . '</td>
  1172. <td>' . V::get('A_STATUS', 'A_STATUS', $labels) . '</td>
  1173. <td>' . V::get('A_STATUS_INFO', 'A_STATUS_INFO', $labels) . '</td>
  1174. <td>' . V::get('L_APPOITMENT_USER', 'L_APPOITMENT_USER', $labels) . '</td>
  1175. <td>' . V::get('Adresy', 'Adresy', $labels) . '</td>
  1176. </tr>
  1177. <tr>
  1178. <td style="padding:0" width=1><button style="padding:5px" id="filtersFieldRemoveBtn-PRACOWNICY" onClick="return removeFiltersPracownicy(event, this)" title="Kasuj filtry" class="btn btn-xs btn-link glyphicon glyphicon-remove"></button></td>
  1179. <td style="padding:0"><input style="padding:2px 8px; width:80px" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_ID" value="" placeholder="%"></td>
  1180. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_imiona" value="" placeholder="%"></td>
  1181. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_nazwisko" value="" placeholder="%"></td>
  1182. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_nip" value="" placeholder="%"></td>
  1183. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_pesel" value="" placeholder="%"></td>
  1184. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_regon" value="" placeholder="%"></td>
  1185. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_source" value="" placeholder="%"></td>
  1186. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_jednostka_organizacyjna" value="" placeholder="%"></td>
  1187. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_A_STATUS" value="" placeholder="%"></td>
  1188. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_A_STATUS_INFO" value="" placeholder="%"></td>
  1189. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_L_APPOITMENT_USER" value="" placeholder="%"></td>
  1190. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_Adresy" value="" placeholder="%"></td>
  1191. </tr>
  1192. </thead>
  1193. <tbody id="body-pracownicy">
  1194. </tbody></table>
  1195. </form>';
  1196. return $view;
  1197. }
  1198. // tworzenie grupy pracowników
  1199. public function createPracownicyGroupAjaxAction() {
  1200. 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
  1201. }
  1202. public function createPracownicyGroupAjax($args) {
  1203. $nazwa = V::get('NAZWA', '', $args);
  1204. // validate
  1205. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  1206. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
  1207. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1208. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1209. 'NAZWA' => $nazwa,
  1210. 'ID_USER' => User::getID()
  1211. ]);
  1212. return [
  1213. 'msg' => "Utworzona grupę {$nazwa}",
  1214. 'type' => "success",
  1215. 'body' => [
  1216. 'id' => $idGroup,
  1217. 'nazwa' => $nazwa
  1218. ]
  1219. ];
  1220. }
  1221. // Dodanie do grupy filtra pracowników
  1222. public function addPracownicyToGroupAjaxAction() {
  1223. 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
  1224. }
  1225. public function addPracownicyToGroupAjax($args) {
  1226. $idGroup = V::get('idGroup', '', $args);
  1227. $type = V::get('type', 'ids', $args);
  1228. $pracownicyIds = V::get('pracownicyIds', '', $args);
  1229. $filter = V::get('filter', '', $args);
  1230. // validate
  1231. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  1232. switch ($type) {
  1233. case 'ids': {
  1234. if (!$pracownicyIds || count($pracownicyIds) == 0) throw new Exception("Proszę wybrać pracowników");
  1235. } break;
  1236. case 'filter': {
  1237. if (!isset($args['filter'])) throw new Exception("Proszę wybrać pracowników");
  1238. } break;
  1239. default: throw new Exception("Missing type");
  1240. }
  1241. // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
  1242. // default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
  1243. // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
  1244. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1245. 'cols' => [ // TODO:? propertyName = []
  1246. 'ID',
  1247. 'ID_USER',
  1248. 'NAZWA',
  1249. ],
  1250. // 'f_ID_USER' => User::getID()
  1251. ])->getItem($idGroup);
  1252. if (!$group) throw new Exception("Grupa nie istnieje");
  1253. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1254. if ('filter' === $type) {
  1255. $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1256. if ($args__idGroup < 0) $args__idGroup = 0;
  1257. $search = V::get('search', '', $args['filter']);
  1258. $searchParams = [];
  1259. if (!empty($search)) {
  1260. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1261. $searchParams['ogc:Filter'] = '
  1262. <ogc:Filter>
  1263. <ogc:Or>
  1264. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1265. <ogc:PropertyName>nip</ogc:PropertyName>
  1266. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1267. </ogc:PropertyIsLike>
  1268. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1269. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1270. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1271. </ogc:PropertyIsLike>
  1272. </ogc:Or>
  1273. </ogc:Filter>
  1274. ';
  1275. }
  1276. $backRefFilter = [];
  1277. if ($args__idGroup > 0) {
  1278. $backRefFilter['__backRef'] = [
  1279. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1280. 'primaryKey' => $args__idGroup,
  1281. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1282. ];
  1283. }
  1284. $filtersParams = [];
  1285. $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
  1286. return ('f_' === substr($key, 0, 2));
  1287. });
  1288. foreach ($fieldFilterKeys as $key) {
  1289. $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
  1290. }
  1291. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1292. $query = $acl->buildQuery(array_merge([
  1293. 'cols' => ['ID'],
  1294. ], $searchParams, $filtersParams, $backRefFilter, [
  1295. 'limit' => 0
  1296. ]));
  1297. $items = $query->getItems();
  1298. $pracownicyIds = array_map(function ($row) {
  1299. return $row['ID'];
  1300. }, $items);
  1301. }
  1302. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  1303. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1304. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1305. foreach ($pracownicyIds as $idPracownik) {
  1306. DB::getPDO()->insert($refGrupyToPracownicy, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  1307. }
  1308. return [
  1309. 'msg' => "Powiązano pracowników z grupą {$idGroup}",
  1310. 'type' => "success",
  1311. ];
  1312. }
  1313. public function fetchGroupPracownicyAjaxAction() {
  1314. Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
  1315. }
  1316. public function fetchGroupPracownicyAjax() {
  1317. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1318. 'cols' => [ // TODO:? propertyName = []
  1319. 'ID',
  1320. 'ID_USER',
  1321. 'NAZWA',
  1322. ],
  1323. 'f_ID_USER' => "=" . User::getID(), // szukamy dokładnie tej wartości - mysql: where ID_USER = "1"
  1324. 'f_A_STATUS' => "!DELETED", // `A_STATUS` != 'DELETED'
  1325. ]);
  1326. $items = $query->getItems();
  1327. if (empty($items)) throw new AlertWarningException("Grupy nie istnieją");
  1328. $arrayGroupPracownicy = array();
  1329. foreach ($items as $item) {
  1330. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy"); // or skip - continue;
  1331. $arrayGroupPracownicy[] = [
  1332. 'ID' => $item['ID'],
  1333. 'NAZWA' => $item['NAZWA'],
  1334. ];
  1335. }
  1336. return [
  1337. 'type' => 'success',
  1338. 'msg' => 'fetchGroupPracownicyAjax',
  1339. '__req_args' => $_REQUEST,
  1340. '__args' => $args,
  1341. 'body' => [
  1342. 'itmesGroupPracownicy' => $arrayGroupPracownicy
  1343. ]
  1344. ];
  1345. }
  1346. // link do ackji w php: $saveFormUrl = $this->getLink('saveRaportAjax');
  1347. // przekazać link do JavaScript i tam:
  1348. // window.fetch('{$saveFormUrl}', { ... }).then(...) - dokumentacja: https://github.com/github/fetch
  1349. public function generateBiAuditRaportAjaxAction() {
  1350. //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
  1351. Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1352. //Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'));
  1353. }
  1354. public function generateBiAuditRaportAjax($args) {
  1355. // głebokość powiazan
  1356. $depthValue = V::get('depthValue', '', $args);
  1357. if (!$depthValue) {
  1358. throw new Exception("Nie podano wartości dla głębokości powiązań");
  1359. }
  1360. // tytuł raportu
  1361. $smadReaportTitle = V::get('smadReaportTitle', '', $args);
  1362. if (!$smadReaportTitle) {
  1363. throw new Exception("Nie podano tytułu raportu");
  1364. }
  1365. // Bi_analiza_onlyTarger
  1366. $analizaOnlyTargets = V::get('analizaOnlyTargets', '', $args);
  1367. if (!$analizaOnlyTargets) {
  1368. throw new Exception("Nie podano wartości czy zwracać wyniki tylko z obiektami docelowymi");
  1369. }
  1370. // Tworzenie relacji Raport do Pracownicy
  1371. $pracownicyIds = []; // array z nr ID na podstawie wysłanego formularza
  1372. $pracownicyIds = V::get('pracownicyIds', '', $args);
  1373. $kontrahenciIds = []; // array z nr ID na podstawie wysłanego formularza
  1374. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  1375. // walidacja listy kontrahentów i pracowników
  1376. if ( !$kontrahenciIds && !$pracownicyIds ) {
  1377. throw new Exception("Nie wybrano pozycji do analizy. Wybierz pracowników/kontrahentów.");
  1378. }
  1379. // Tworzenie rekrodu w bazie - Raport -
  1380. $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
  1381. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1382. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1383. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  1384. 'FILE_STATUS' => "TO_GENERATE",
  1385. 'A_STATUS' => "NORMAL",
  1386. 'BI_analiza_minDepth' => 1,
  1387. 'BI_analiza_maxDepth' => $depthValue,
  1388. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  1389. ]);
  1390. if ($idRaport > 0) {
  1391. DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_HIST', [
  1392. 'ID_USERS2' => $idRaport,
  1393. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1394. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1395. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  1396. 'FILE_STATUS' => "TO_GENERATE",
  1397. 'A_STATUS' => "NORMAL",
  1398. 'BI_analiza_minDepth' => 1,
  1399. 'BI_analiza_maxDepth' => $depthValue,
  1400. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  1401. ]);
  1402. }
  1403. // Tworzenie relacji Raport do Pracownicy
  1404. $refPowiazaniaToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1405. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1406. // Tworzenie relacji Raport do Kontrahenci - analogicznie jak wyżej
  1407. $refPowiazaniaToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1408. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  1409. /* PRACOWNICY */
  1410. if ( !$pracownicyIds ) {
  1411. // dodajemy wszystkich pracowników
  1412. DB::getPDO()->execSql("insert into `{$refPowiazaniaToPracownicy}` (`PRIMARY_KEY`,`REMOTE_PRIMARY_KEY`)
  1413. select '{$idRaport}' as PRIMARY_KEY
  1414. , ID as REMOTE_PRIMARY_KEY
  1415. from `BI_audit_ENERGA_PRACOWNICY`
  1416. ");
  1417. } else { // wybrano pracownika/ów
  1418. foreach ($pracownicyIds as $idPracownik) {
  1419. DB::getPDO()->insert($refPowiazaniaToPracownicy, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  1420. }
  1421. }
  1422. /* KONTRAHENCI */
  1423. if ( !$kontrahenciIds ) {
  1424. // dodajemy wszystkich pracowników
  1425. DB::getPDO()->execSql("insert into `{$refPowiazaniaToKontrahenci}` (`PRIMARY_KEY`,`REMOTE_PRIMARY_KEY`)
  1426. select '{$idRaport}' as PRIMARY_KEY
  1427. , ID as REMOTE_PRIMARY_KEY
  1428. from `BI_audit_ENERGA_RUM_KONTRAHENCI`
  1429. ");
  1430. } else { // wybrano pracownika/ów
  1431. foreach ($kontrahenciIds as $idKontrahent) {
  1432. DB::getPDO()->insert($refPowiazaniaToKontrahenci, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idKontrahent ]);
  1433. }
  1434. }
  1435. return [
  1436. 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
  1437. 'type' => "success",
  1438. 'body' => [
  1439. 'id' => $idRaport,
  1440. ]
  1441. ];
  1442. }
  1443. /**
  1444. * Widok formularza dodawania pracowników i kontrahentów
  1445. */
  1446. public function defaultViewFormBiAudit($items, $type) {
  1447. $activeFormSteps = '';
  1448. $fieldLabels = [];
  1449. switch($type) {
  1450. case 'KONTRAHENCI':
  1451. $activeFormStepsKontrahent = 'complete';
  1452. $titleHeader = 'KONTRAHENCI/PODMIOTY';
  1453. $groupFilterList = '
  1454. <div class="menu-item">
  1455. <ul class="padding-0">
  1456. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  1457. </ul>
  1458. </div>
  1459. <div id="group-kontrahenci" class="btn-group">
  1460. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1461. </div>';
  1462. $formSmadDepth = '<input type="text" class="form-control smad-depth-kontrahenci" placeholder="1-16" value="" />';
  1463. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
  1464. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
  1465. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
  1466. $countSelectedItem = '<div>Wybrano: <span id="count-selected-item-kontrahenci">0</span> <span><a title="wyczyść zapamietanych kontrahentów" class="link-primary" onClick="clearListLocalStorageByType(\'kontrahenci\')"><small>(wyczyść)</small></a></span></div>';
  1467. $graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
  1468. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  1469. $formAddNewData ='
  1470. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  1471. <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
  1472. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  1473. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  1474. // $buttonMoveToGroup .= ''
  1475. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-kontrahenci" placeholder="Default reaport" value="" />';
  1476. $showButtonNextStep = '';
  1477. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  1478. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  1479. $fieldList = $acl->getRealFieldList();
  1480. $fieldLabels = array_combine(
  1481. $fieldList,
  1482. array_map(function ($fieldName) use ($acl) {
  1483. return $acl->getFieldLabel($fieldName);
  1484. }, $fieldList)
  1485. );
  1486. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  1487. break;
  1488. case 'PRACOWNICY':
  1489. $titleHeader = 'OSOBY';
  1490. $groupFilterList = '
  1491. <div class="menu-item">
  1492. <ul class="padding-0">
  1493. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a></li>
  1494. </ul>
  1495. </div>
  1496. <div id="group-pracownicy" class="btn-group">
  1497. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1498. </div>';
  1499. $formSmadDepth = '<input type="text" class="form-control smad-depth" placeholder="1-16" value="" />';
  1500. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target"><option value="y">tak</option><option value="n">nie</option></select>';
  1501. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-pracownicy">Wszyscy</h2>';
  1502. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span></p>';
  1503. $countSelectedItem = '<div>Wybrano: <span id="count-selected-item-pracownicy">0</span> <span><a title="wyczyść zapamietanych pracowników" class="link-primary" onClick="clearListLocalStorageByType(\'pracownicy\')"><small>(wyczyść)</small></a></span></div>';
  1504. $graphView = '<div class="smad-pracownicy-graph-view" style="display: none;"></div>';
  1505. $csvExamplePracownicy = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/pracownicy_example.zip';
  1506. $formAddNewData ='
  1507. <li><a title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import osób\', \'pracownicy\', \'yes\', \''.$csvExamplePracownicy.'\' )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
  1508. <li><a title="DODAJ PRACOWNIKÓW" onClick="createPracownikAjax(event)" class="btn btn-info" >+ DODAJ OSOBĘ</a></li>'; //todo: dodać obsługe doddawania pracownikow
  1509. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  1510. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addPracownikAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  1511. $showButtonNextStep = '<a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
  1512. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-pracownicy" placeholder="Default reaport" value="" />';
  1513. $pagination_form = '<div id="pagination-pracownicy"></div>';
  1514. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY");
  1515. $fieldList = $acl->getRealFieldList();
  1516. $fieldLabels = array_combine(
  1517. $fieldList,
  1518. array_map(function ($fieldName) use ($acl) {
  1519. return $acl->getFieldLabel($fieldName);
  1520. }, $fieldList)
  1521. );
  1522. DBG::log($fieldLabels, 'array', "fieldLabels (PRACOWNICY)");
  1523. break;
  1524. }
  1525. $view = '
  1526. <!-- start:employees-section-->
  1527. <div id="smad-employees-section" class="smad-form-' . $type . '" >
  1528. <div class="container-fluid">
  1529. <div>
  1530. <div class="padding-lr-0">
  1531. <div id="smad-menu-section">
  1532. <div class="col-sm-12 col-md-6 padding-lr-0">
  1533. <div class="menu-items">
  1534. <div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $titleHeader . ' </div>
  1535. </div>
  1536. </div>
  1537. <div class="col-sm-12 col-md-6 padding-lr-0">
  1538. <div class="form-steps">
  1539. <!-- start:form steps wizard -->
  1540. <div class="row smad-wizard" style="border-bottom:0;">
  1541. <div class="col-xs-4 col-md-4 smad-wizard-step complete"><!-- complited line -->
  1542. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1543. <div class="progress"><div class="progress-bar"></div></div>
  1544. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY" class="smad-wizard-dot"></a>
  1545. <div class="smad-wizard-info complete text-center">
  1546. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY">Krok 1</a></div>
  1547. <div class="step-title">OSOBY <span class="top--count-selected-item-pracownicy"></span></div>
  1548. </div>
  1549. </div>
  1550. <div class="col-xs-4 col-md-4 smad-wizard-step ' . $activeFormStepsKontrahent . ' ">
  1551. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1552. <div class="progress"><div class="progress-bar"></div></div>
  1553. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" class="smad-wizard-dot"></a>
  1554. <div class="smad-wizard-info text-center">
  1555. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI">Krok 2</a></div>
  1556. <div class="step-title">PODMIOTY/<BR />KONTRAHENCI <span class="top--count-selected-item-kontrahenci"></span></div>
  1557. </div>
  1558. </div>
  1559. <div class="col-xs-4 col-md-4 smad-wizard-step ">
  1560. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1561. <div class="progress"><div class="progress-bar"></div></div>
  1562. <a href="#" class="smad-wizard-dot"></a>
  1563. <div class="smad-wizard-info text-center">
  1564. <div class="step-item">Krok 3</div>
  1565. <div class="step-title">SZUKANIE POWIĄZAŃ</div>
  1566. </div>
  1567. </div>
  1568. </div>
  1569. <!-- end:form steps wizard -->
  1570. </div>
  1571. </div>
  1572. </div>
  1573. </div>
  1574. </div>
  1575. </div>
  1576. <div class="container-fluid">
  1577. <div class=" padding-lr-0">
  1578. <div class="smad-divider"></div>
  1579. </div>
  1580. </div>
  1581. <!-- start:filters -->
  1582. <div class="container-fluid">
  1583. <div class="row">
  1584. <div>
  1585. <div class="smad-employees-form-section" class="border-top-grey">
  1586. <div class="col-md-9 smad-border-col">
  1587. <div class="menu-items">
  1588. '.$groupFilterList.'
  1589. </div>
  1590. </div>
  1591. <div class="col-md-3">
  1592. <div class="form-input">
  1593. <div class="form-item col-md-7 col-lg-9 smad-heder-title">głębokość powiązań:</div>
  1594. <div class="form-item col-md-5 col-lg-3">
  1595. '.$formSmadDepth.'
  1596. </div>
  1597. </div>
  1598. <div class="form-input">
  1599. <div class="form-item col-md-7 col-lg-9 smad-heder-title">Czy zwracać wyniki tylko ze znalezionymi obiektami docelowymi(z tabeli kontrahentów)?</div>
  1600. <div class="form-item col-md-5 col-lg-3">
  1601. '.$formSmadSelectTarget.'
  1602. </div>
  1603. </div>
  1604. </div>
  1605. </div>
  1606. </div>
  1607. </div>
  1608. </div>
  1609. <!-- end:filters -->
  1610. <!-- start:list employees -->
  1611. <div class="container-fluid">
  1612. <div class="padding-0 smad-employees-list-head">
  1613. <div class="col-md-6">
  1614. <header>
  1615. '.$formFilterHeadTitle.'
  1616. </header>
  1617. <div class="desc">
  1618. '.$formFilterHeadDesc.'
  1619. </div>
  1620. <div class="countSelectedItem">
  1621. '.$countSelectedItem.'
  1622. </div>
  1623. </div>
  1624. <div class="col-md-6">
  1625. <div class="menu-items">
  1626. <div class="menu-item">
  1627. <ul class="padding-0">
  1628. '.$formAddNewData.'
  1629. </ul>
  1630. </div>
  1631. </div>
  1632. </div>
  1633. </div>
  1634. </div>
  1635. <!-- Start: graph-view -->
  1636. <div class="smad-graph-section">
  1637. <div class="container-fluid">
  1638. '.$graphView.'
  1639. </div>
  1640. </div>
  1641. <!-- End: graph-view -->
  1642. <div class="container-fluid">
  1643. <div class="table-responsive padding-0" id="smad-table-' . $type . '">
  1644. ' . $this->showListDataByType($items, $type, $fieldLabels) . '
  1645. </div>
  1646. </div>
  1647. <!-- end:list employees -->
  1648. <!-- start:list paginations employees -->
  1649. <div class="container-fluid ">
  1650. <div>
  1651. '. $pagination_form .'
  1652. </div>
  1653. </div>
  1654. <!-- end:list paginations employees -->
  1655. <!-- start:bottom buttons -->
  1656. <div class="container-fluid smad-employees-bottom-navigation">
  1657. <div class="padding-0">
  1658. <div class="col-lg-6 ">
  1659. '.$buttonMoveToGroup.'
  1660. </div>
  1661. <div class="col-lg-6 text-right">
  1662. ' . $showButtonNextStep . '
  1663. </div>
  1664. </div>
  1665. </div>
  1666. <!-- end:bottom buttons -->
  1667. </div>
  1668. <!-- start:employees-section -->
  1669. <div class="container-fluid ">
  1670. <div class="row">
  1671. <div class="container text-center">
  1672. <div class="col-md-7 col-lg-5 " style="margin: 0 auto; float: none;">
  1673. '.$formSmadReaportTitleInput.'
  1674. </div>
  1675. </div>
  1676. </div>
  1677. </div>
  1678. <!-- START:bottom generate reaport-->
  1679. <div class="container-fluid smad-generate-reaport">
  1680. <div class="row">
  1681. <div class="container text-center">
  1682. <button type="button" class="btn btn-default smad-generate-reaport-button" onclick="generateBiAuditRaport(event)" id="button-generate-reaport" >GENERUJ RAPORT POWIĄZAŃ</button>
  1683. </div>
  1684. <div class="container smad-generate-reaport-info text-center">
  1685. <div class="step-title"><span class="bottom--count-selected-item-kontrahenci"></span></div>
  1686. <div class="step-title"><span class="bottom--count-selected-item-pracownicy"></span></div>
  1687. <div><strong><span class="bottom--message-warning-critical-search"></span></strong></div>
  1688. </div>
  1689. </div>
  1690. </div>
  1691. <!-- end:bottom generate reaport -->
  1692. ';
  1693. return $view;
  1694. }
  1695. public function showListDataByType($items, $type='PRACOWNICY', $labels) {
  1696. switch ($type) {
  1697. case 'PRACOWNICY':
  1698. return $this->showTablePracownicy($labels);
  1699. break;
  1700. case 'KONTRAHENCI':
  1701. return $this->showTableKontrahenci($labels);
  1702. break;
  1703. }
  1704. }
  1705. function fetchProgressAjaxAction() {
  1706. Response::sendTryCatchJson(array($this, 'fetchProgressAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1707. }
  1708. function fetchProgressAjax($args) {
  1709. $DBG_FAKE_ANIM = false;
  1710. if (empty($args['ids'])) return [ 'msg' => "empty ids", 'type' => "success" ];
  1711. $ids = $args['ids'];
  1712. // private static function getDirectory($table, $id) {
  1713. $firstId = reset($ids);
  1714. {
  1715. Lib::loadClass('FoldersConfig');
  1716. $folderConf = FoldersConfig::getAll('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_COLUMN');
  1717. if (!isset($folderConf['mount_point'])) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$errMsg}", 404);
  1718. $rootPath = $folderConf['mount_point'];
  1719. }
  1720. $statuses = array_map(function ($id) {
  1721. return DB::getPDO()->fetchValue(" select FILE_STATUS from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  1722. }, $ids);
  1723. $statusesInfo = array_map(function ($id) {
  1724. return DB::getPDO()->fetchValue(" select FILE_STATUS_info from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  1725. }, $ids);
  1726. $progress = array_map(function ($id, $idx) use ($rootPath, $statuses, $DBG_FAKE_ANIM) {
  1727. DBG::log("Loop id({$id}) is-eq-82(".(82 == $id).") is-eq-'82'(".("82"==$id).")");
  1728. DBG::log("Loop id({$id}) is-eq-80(".(80 == $id).") is-eq-'80'(".("80"==$id).")");
  1729. $status = $statuses[$idx];
  1730. if ($DBG_FAKE_ANIM && 82 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  1731. if ($DBG_FAKE_ANIM && 80 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  1732. if ($DBG_FAKE_ANIM && 77 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  1733. DBG::log("Loop id({$id}) status({$status})...");
  1734. if ('GENERATED' === $status) return 1;
  1735. if ('IN_PROGRESS' !== $status) return 0;
  1736. if (!file_exists("{$rootPath}/.tasks/generatePowiazania-{$id}.progress")) return 0;
  1737. DBG::log("Loop id({$id}) status({$status}) progress file exists");
  1738. try {
  1739. $cnt = file_get_contents("{$rootPath}/.tasks/generatePowiazania-{$id}.progress");
  1740. $json = @json_decode($cnt, $assoc = true);
  1741. if (null === $json && 0 !== json_last_error()) {
  1742. throw new Exception("Parse json error for restrictions: " . json_last_error());
  1743. }
  1744. // $json['summary']['step']: 'initialize', 'relations', 'reports'
  1745. // $json['summary']['step'] = 'initialize' - recache - skip
  1746. // $json['summary']['step'] = 'relations' - szuka powiązań (@see AVG(details.progress / summary.count))
  1747. // $json['summary']['step'] = 'reports' - generuje pliki (@see summary.created)
  1748. /*
  1749. if ($DBG_FAKE_ANIM && 82 == $id) { // TODO: DBG
  1750. $json = [
  1751. 'summary' => [
  1752. 'count' => 4,
  1753. 'step' => 'relations',
  1754. ],
  1755. 'details' => [
  1756. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1757. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1758. '22' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1759. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1760. ] ];
  1761. }
  1762. */
  1763. if ($DBG_FAKE_ANIM && 80 == $id) { // TODO: DBG
  1764. $json = [
  1765. 'summary' => [
  1766. 'count' => 4,
  1767. 'created' => 2,
  1768. 'step' => 'reports',
  1769. ],
  1770. 'details' => [
  1771. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1772. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1773. '22' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1774. '25' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1775. ] ];
  1776. }
  1777. if ($DBG_FAKE_ANIM && 77 == $id) { // TODO: DBG
  1778. $json = [
  1779. 'summary' => [
  1780. 'count' => 4,
  1781. 'created' => 2,
  1782. 'step' => 'relations',
  1783. ],
  1784. 'details' => [
  1785. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1786. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1787. '22' => [ 'progress' => 0.25, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1788. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1789. ] ];
  1790. }
  1791. DBG::log($json, 'array', "Loop id({$id}) status({$status}) progress json");
  1792. if (empty($json['summary'])) return 0;
  1793. if (empty($json['summary']['count'])) return 0;
  1794. if (empty($json['summary']['step'])) return 0;
  1795. if (empty($json['details'])) return 0;
  1796. $listDetailsProgress = array_map(function ($detail) {
  1797. return floatval($detail['progress']);
  1798. }, $json['details']);
  1799. $relationsProgress = $json['summary']['count'] > 0 ? round(floatval(array_sum($listDetailsProgress)) / floatval($json['summary']['count']), 3) : 0;
  1800. $reportsCount = V::get('reportsCount', 0, $json['summary'], 'float');
  1801. $reportsProgress = $reportsCount > 0 ? round(V::get('reportsCreated', 0, $json['summary'], 'float') / $reportsCount, 3) : 0;
  1802. return round(0.5 * $relationsProgress + 0.5 * $reportsProgress, 3);
  1803. } catch (Exception $e) {
  1804. DBG::log($e);
  1805. }
  1806. return 0;
  1807. }, $ids, array_keys($ids));
  1808. return [ 'msg' => "DBG ids set", 'type' => "success", 'body' => [
  1809. 'ids' => $ids,
  1810. 'progress' => $progress,
  1811. 'statuses' => $statuses,
  1812. 'statusesInfo' => $statusesInfo,
  1813. ] ];
  1814. }
  1815. }