Bocian.php 87 KB

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