Bocian.php 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164
  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('removePracownicyFromGroupAjax'),
  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 removePracownicyFromGroupAjaxAction(){
  980. Response::sendTryCatchJson(array($this, 'removePracownicyFromGroupAjax'), $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 removePracownicyFromGroupAjax($args){
  983. $idGroup = V::get('idGroup', 0, $args, "int");
  984. $pracownicyIds = V::get('pracownicyIds', [], $args, 'array');
  985. if ($idGroup === 0){
  986. foreach ($pracownicyIds as $pracownikIds) {
  987. //TO DO Błąd do naprawienia
  988. //TO DO sprawdzanie czy już DELETED
  989. $affected = DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY', 'ID', $pracownikIds, [
  990. 'A_STATUS' => 'DELETED',
  991. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  992. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  993. ]);
  994. }
  995. return [
  996. 'msg' => "Usunięto osoby z systemu",
  997. 'type' => "success",
  998. ];
  999. } else {
  1000. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1001. 'cols' => [ // TODO:? propertyName = []
  1002. 'ID',
  1003. 'ID_USER',
  1004. 'NAZWA',
  1005. ],
  1006. // 'f_ID_USER' => User::getID()
  1007. ])->getItem($idGroup);
  1008. if (!$group) throw new Exception("Grupa nie istnieje");
  1009. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1010. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1011. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1012. foreach ($pracownicyIds as $pracownikIds) {
  1013. $id = (int)$pracownikIds;
  1014. DB::getPDO()->execSql("delete from {$refGrupyToPracownicy} where PRIMARY_KEY= {$idGroup} and REMOTE_PRIMARY_KEY = {$id}");
  1015. }
  1016. return [
  1017. 'msg' => "Usunięto osoby z grupy {$idGroup}",
  1018. 'type' => "success",
  1019. ];
  1020. }
  1021. }
  1022. public function removeKontrahenciFromGroupAjaxAction() {
  1023. 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
  1024. }
  1025. public function removeKontrahenciFromGroupAjax($args) {
  1026. $idGroup = V::get('idGroup', 0, $args, "int");
  1027. $kontrahenciIds = V::get('kontrahenciIds', [], $args, 'array');
  1028. if ($idGroup === 0){
  1029. foreach ($kontrahenciIds as $kontrahentIds) {
  1030. //TO DO sprawdzanie czy już DELETED
  1031. $affected = DB::getPDO()->update('BI_audit_ENERGA_RUM_KONTRAHENCI', 'ID', $kontrahentIds, [
  1032. 'A_STATUS' => 'DELETED',
  1033. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  1034. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  1035. ])->debugDumpParams();
  1036. }
  1037. return [
  1038. 'msg' => "Usunięto kontrahentów z systemu",
  1039. 'type' => "success",
  1040. ];
  1041. } else {
  1042. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  1043. 'cols' => [ // TODO:? propertyName = []
  1044. 'ID',
  1045. 'ID_USER',
  1046. 'NAZWA',
  1047. ],
  1048. // 'f_ID_USER' => User::getID()
  1049. ])->getItem($idGroup);
  1050. if (!$group) throw new Exception("Grupa nie istnieje");
  1051. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1052. $refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  1053. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  1054. foreach ($kontrahenciIds as $kontrahentIds) {
  1055. // DB::getPDO()->insert($refGrupyToKontrahenci, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $kontrahentIds]);
  1056. $id = (int)$kontrahentIds;
  1057. DBG::log("nazwa grupy {$refGrupyToKontrahenci}");
  1058. DB::getPDO()->execSql("delete from {$refGrupyToKontrahenci} where PRIMARY_KEY= {$idGroup} and REMOTE_PRIMARY_KEY = {$id}");
  1059. //DB::
  1060. }
  1061. return [
  1062. 'msg' => "Usunięto kontrahentów z grupy {$idGroup}",
  1063. 'type' => "success",
  1064. ];
  1065. }
  1066. }
  1067. public function fetchGroupKontrahenciAjaxAction() {
  1068. Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
  1069. }
  1070. public function fetchGroupKontrahenciAjax() {
  1071. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  1072. 'cols' => [ // TODO:? propertyName = []
  1073. 'ID',
  1074. 'ID_USER',
  1075. 'NAZWA',
  1076. ],
  1077. 'f_ID_USER' => "=" . User::getID(),
  1078. 'f_A_STATUS' => "!DELETED",
  1079. ]);
  1080. $itemsKontrahenci = $query->getItems();
  1081. if (empty($itemsKontrahenci)) throw new AlertWarningException("Grupy nie istnieją");
  1082. $arrayGroupKontrahenci = array();
  1083. foreach ($itemsKontrahenci as $item) {
  1084. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1085. $arrayGroupKontrahenci[] = [
  1086. 'NAZWA' => $item['NAZWA'],
  1087. 'ID' => $item['ID'],
  1088. ];
  1089. }
  1090. return [
  1091. 'type' => 'success',
  1092. 'msg' => 'fetchGroupKontrahenciAjax',
  1093. '__req_args' => $_REQUEST,
  1094. '__args' => $args,
  1095. 'body' => [
  1096. 'itemsGroupKontrahenci' => $arrayGroupKontrahenci
  1097. ]
  1098. ];
  1099. }
  1100. public function fetchPracownicyIdsAjaxAction() {
  1101. Response::sendTryCatchJson(array($this, 'fetchPracownicyIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1102. }
  1103. public function fetchPracownicyIdsAjax($args) {
  1104. $idGroup = V::get('filter_idGroup', 0, $args, 'int');
  1105. if ($idGroup < 0) $idGroup = 0;
  1106. $backRefFilter = [];
  1107. if ($idGroup > 0) {
  1108. $backRefFilter['__backRef'] = [
  1109. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1110. 'primaryKey' => $idGroup,
  1111. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1112. ];
  1113. }
  1114. $searchParams = []; // TODO: ???
  1115. $filtersParams = [];
  1116. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1117. return ('f_' === substr($key, 0, 2));
  1118. });
  1119. foreach ($fieldFilterKeys as $key) {
  1120. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1121. }
  1122. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1123. $query = $acl->buildQuery(array_merge([
  1124. 'cols' => [
  1125. 'ID',
  1126. ],
  1127. //'f_ID' => $id,
  1128. 'limit' => 0,
  1129. // 'limitstart' => $limitstart, // offset
  1130. // 'order_by' => 'ID', // sortowanie po kolumnie
  1131. // 'order_dir' => 'DESC', // kierunek sortowania
  1132. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1133. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1134. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1135. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1136. ], $searchParams, $filtersParams, $backRefFilter));
  1137. // $total = $query->getTotal();
  1138. $items = $query->getItems();
  1139. return [
  1140. 'type' => 'success',
  1141. 'msg' => 'pracownicy ids',
  1142. 'body' => [
  1143. 'ids' => array_map( V::makePick('ID'), $items ),
  1144. ],
  1145. '__args' => $args,
  1146. '__DBG_$idGroup' => $idGroup,
  1147. '__DBG_$filtersParams' => $filtersParams,
  1148. '__DBG_$backRefFilter' => $backRefFilter,
  1149. ];
  1150. }
  1151. /*
  1152. * PRACOWNICY
  1153. */
  1154. public function fetchPracownicyAjaxAction() {
  1155. Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'), $args = $_REQUEST);
  1156. }
  1157. public function fetchPracownicyAjax($args) {
  1158. $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1159. if ($idGroup < 0) $idGroup = 0;
  1160. $limit = 20;
  1161. $page = V::get('page', 0, $args, 'int');
  1162. $limitstart = ($page - 1) * $limit;
  1163. $search = V::get('search', '', $args);
  1164. $searchParams = [];
  1165. if (!empty($search)) {
  1166. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1167. $searchParams['ogc:Filter'] = '
  1168. <ogc:Filter>
  1169. <ogc:Or>
  1170. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1171. <ogc:PropertyName>nip</ogc:PropertyName>
  1172. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1173. </ogc:PropertyIsLike>
  1174. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1175. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1176. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1177. </ogc:PropertyIsLike>
  1178. </ogc:Or>
  1179. </ogc:Filter>
  1180. ';
  1181. }
  1182. $backRefFilter = [];
  1183. if ($idGroup > 0) {
  1184. $backRefFilter['__backRef'] = [
  1185. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1186. 'primaryKey' => $idGroup,
  1187. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1188. ];
  1189. }
  1190. $filtersParams = [];
  1191. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1192. return ('f_' === substr($key, 0, 2));
  1193. });
  1194. foreach ($fieldFilterKeys as $key) {
  1195. if ('f_ID' === $key) $filtersParams[ $key ] = '=' . $args[ $key ];
  1196. else $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1197. }
  1198. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1199. $query = $acl->buildQuery(array_merge([
  1200. 'cols' => array_merge(self::$FIELD_LIST_PRACOWNICY, [
  1201. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  1202. ]),
  1203. //'f_ID' => $id,
  1204. 'limit' => $limit,
  1205. 'limitstart' => $limitstart, // offset
  1206. 'order_by' => 'ID', // sortowanie po kolumnie
  1207. 'order_dir' => 'DESC', // kierunek sortowania
  1208. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1209. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1210. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1211. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1212. ], $searchParams, $filtersParams, $backRefFilter));
  1213. $total = $query->getTotal();
  1214. $items = $query->getItems();
  1215. $pagination = array();
  1216. $pagination['total_items'] = $total;
  1217. $pagination['size'] = ceil($total/$limit); // pages size
  1218. $pagination['current'] = $page;
  1219. $pagination['limit'] = $limit;
  1220. // $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1221. if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
  1222. // { // tworzenie własnego zapytanie mysql
  1223. // $rootTableName = $acl->getRootTableName();
  1224. // DB::getPDO()->fetchAll("
  1225. // select t.*
  1226. // from {$rootTableName} t
  1227. // where t.ID in (
  1228. // select x.ID
  1229. // from ... x
  1230. // where
  1231. // )
  1232. // ");
  1233. // }
  1234. return [
  1235. 'type' => 'success',
  1236. 'msg' => 'showPracownicy',
  1237. 'body' => [
  1238. 'items' => $items,
  1239. //'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
  1240. 'pagination' => $pagination
  1241. ],
  1242. '__DBG_$idGroup' => $idGroup,
  1243. '__DBG_$filtersParams' => $filtersParams,
  1244. '__DBG_$backRefFilter' => $backRefFilter,
  1245. ];
  1246. }
  1247. public function showTablePracownicy($labels = []) {
  1248. // TODO: use self::$FIELD_LIST_PRACOWNICY
  1249. $view = '<form class="form-horizontal" method="post">
  1250. <table class="table table-responsive table-bordered table-hover table-striped" height=5>
  1251. <thead>
  1252. <tr>
  1253. <td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
  1254. <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
  1255. <td>' . V::get('imiona', 'Imię/Imiona', $labels) . '</td>
  1256. <td>' . V::get('nazwisko', 'Nazwisko', $labels) . '</td>
  1257. <td>' . V::get('nip', 'NIP', $labels) . '</td>
  1258. <td>' . V::get('pesel', 'Pesel', $labels) . '</td>
  1259. <td>' . V::get('regon', 'Regon', $labels) . '</td>
  1260. <td>' . V::get('source', 'source', $labels) . '</td>
  1261. <td>' . V::get('jednostka_organizacyjna', 'jednostka_organizacyjna', $labels) . '</td>
  1262. <td>' . V::get('A_STATUS', 'A_STATUS', $labels) . '</td>
  1263. <td>' . V::get('A_STATUS_INFO', 'A_STATUS_INFO', $labels) . '</td>
  1264. <td>' . V::get('L_APPOITMENT_USER', 'L_APPOITMENT_USER', $labels) . '</td>
  1265. <td>' . V::get('Adresy', 'Adresy', $labels) . '</td>
  1266. </tr>
  1267. <tr>
  1268. <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>
  1269. <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>
  1270. <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>
  1271. <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>
  1272. <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>
  1273. <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>
  1274. <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>
  1275. <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>
  1276. <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>
  1277. <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>
  1278. <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>
  1279. <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>
  1280. <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>
  1281. </tr>
  1282. </thead>
  1283. <tbody id="body-pracownicy">
  1284. </tbody></table>
  1285. </form>';
  1286. return $view;
  1287. }
  1288. // tworzenie grupy pracowników
  1289. public function createPracownicyGroupAjaxAction() {
  1290. 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
  1291. }
  1292. public function createPracownicyGroupAjax($args) {
  1293. $nazwa = V::get('NAZWA', '', $args);
  1294. // validate
  1295. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  1296. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
  1297. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1298. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1299. 'NAZWA' => $nazwa,
  1300. 'ID_USER' => User::getID()
  1301. ]);
  1302. return [
  1303. 'msg' => "Utworzona grupę {$nazwa}",
  1304. 'type' => "success",
  1305. 'body' => [
  1306. 'id' => $idGroup,
  1307. 'nazwa' => $nazwa
  1308. ]
  1309. ];
  1310. }
  1311. // Dodanie do grupy filtra pracowników
  1312. public function addPracownicyToGroupAjaxAction() {
  1313. 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
  1314. }
  1315. public function addPracownicyToGroupAjax($args) {
  1316. $idGroup = V::get('idGroup', '', $args);
  1317. $type = V::get('type', 'ids', $args);
  1318. $pracownicyIds = V::get('pracownicyIds', '', $args);
  1319. $filter = V::get('filter', '', $args);
  1320. // validate
  1321. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  1322. switch ($type) {
  1323. case 'ids': {
  1324. if (!$pracownicyIds || count($pracownicyIds) == 0) throw new Exception("Proszę wybrać pracowników");
  1325. } break;
  1326. case 'filter': {
  1327. if (!isset($args['filter'])) throw new Exception("Proszę wybrać pracowników");
  1328. } break;
  1329. default: throw new Exception("Missing type");
  1330. }
  1331. // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
  1332. // default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
  1333. // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
  1334. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1335. 'cols' => [ // TODO:? propertyName = []
  1336. 'ID',
  1337. 'ID_USER',
  1338. 'NAZWA',
  1339. ],
  1340. // 'f_ID_USER' => User::getID()
  1341. ])->getItem($idGroup);
  1342. if (!$group) throw new Exception("Grupa nie istnieje");
  1343. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1344. if ('filter' === $type) {
  1345. $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1346. if ($args__idGroup < 0) $args__idGroup = 0;
  1347. $search = V::get('search', '', $args['filter']);
  1348. $searchParams = [];
  1349. if (!empty($search)) {
  1350. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1351. $searchParams['ogc:Filter'] = '
  1352. <ogc:Filter>
  1353. <ogc:Or>
  1354. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1355. <ogc:PropertyName>nip</ogc:PropertyName>
  1356. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1357. </ogc:PropertyIsLike>
  1358. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1359. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1360. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1361. </ogc:PropertyIsLike>
  1362. </ogc:Or>
  1363. </ogc:Filter>
  1364. ';
  1365. }
  1366. $backRefFilter = [];
  1367. if ($args__idGroup > 0) {
  1368. $backRefFilter['__backRef'] = [
  1369. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1370. 'primaryKey' => $args__idGroup,
  1371. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1372. ];
  1373. }
  1374. $filtersParams = [];
  1375. $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
  1376. return ('f_' === substr($key, 0, 2));
  1377. });
  1378. foreach ($fieldFilterKeys as $key) {
  1379. $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
  1380. }
  1381. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1382. $query = $acl->buildQuery(array_merge([
  1383. 'cols' => ['ID'],
  1384. ], $searchParams, $filtersParams, $backRefFilter, [
  1385. 'limit' => 0
  1386. ]));
  1387. $items = $query->getItems();
  1388. $pracownicyIds = array_map(function ($row) {
  1389. return $row['ID'];
  1390. }, $items);
  1391. }
  1392. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  1393. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1394. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1395. foreach ($pracownicyIds as $idPracownik) {
  1396. DB::getPDO()->insert($refGrupyToPracownicy, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  1397. }
  1398. return [
  1399. 'msg' => "Powiązano pracowników z grupą {$idGroup}",
  1400. 'type' => "success",
  1401. ];
  1402. }
  1403. public function fetchGroupPracownicyAjaxAction() {
  1404. Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
  1405. }
  1406. public function fetchGroupPracownicyAjax() {
  1407. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1408. 'cols' => [ // TODO:? propertyName = []
  1409. 'ID',
  1410. 'ID_USER',
  1411. 'NAZWA',
  1412. ],
  1413. 'f_ID_USER' => "=" . User::getID(), // szukamy dokładnie tej wartości - mysql: where ID_USER = "1"
  1414. 'f_A_STATUS' => "!DELETED", // `A_STATUS` != 'DELETED'
  1415. ]);
  1416. $items = $query->getItems();
  1417. if (empty($items)) throw new AlertWarningException("Grupy nie istnieją");
  1418. $arrayGroupPracownicy = array();
  1419. foreach ($items as $item) {
  1420. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy"); // or skip - continue;
  1421. $arrayGroupPracownicy[] = [
  1422. 'ID' => $item['ID'],
  1423. 'NAZWA' => $item['NAZWA'],
  1424. ];
  1425. }
  1426. return [
  1427. 'type' => 'success',
  1428. 'msg' => 'fetchGroupPracownicyAjax',
  1429. '__req_args' => $_REQUEST,
  1430. '__args' => $args,
  1431. 'body' => [
  1432. 'itmesGroupPracownicy' => $arrayGroupPracownicy
  1433. ]
  1434. ];
  1435. }
  1436. // link do ackji w php: $saveFormUrl = $this->getLink('saveRaportAjax');
  1437. // przekazać link do JavaScript i tam:
  1438. // window.fetch('{$saveFormUrl}', { ... }).then(...) - dokumentacja: https://github.com/github/fetch
  1439. public function generateBiAuditRaportAjaxAction() {
  1440. //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
  1441. Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1442. //Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'));
  1443. }
  1444. public function generateBiAuditRaportAjax($args) {
  1445. // głebokość powiazan
  1446. $depthValue = V::get('depthValue', '', $args);
  1447. if (!$depthValue) {
  1448. throw new Exception("Nie podano wartości dla głębokości powiązań");
  1449. }
  1450. // tytuł raportu
  1451. $smadReaportTitle = V::get('smadReaportTitle', '', $args);
  1452. if (!$smadReaportTitle) {
  1453. throw new Exception("Nie podano tytułu raportu");
  1454. }
  1455. // Bi_analiza_onlyTarger
  1456. $analizaOnlyTargets = V::get('analizaOnlyTargets', '', $args);
  1457. if (!$analizaOnlyTargets) {
  1458. throw new Exception("Nie podano wartości czy zwracać wyniki tylko z obiektami docelowymi");
  1459. }
  1460. // Tworzenie relacji Raport do Pracownicy
  1461. $pracownicyIds = []; // array z nr ID na podstawie wysłanego formularza
  1462. $pracownicyIds = V::get('pracownicyIds', '', $args);
  1463. $kontrahenciIds = []; // array z nr ID na podstawie wysłanego formularza
  1464. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  1465. // walidacja listy kontrahentów i pracowników
  1466. if ( !$kontrahenciIds && !$pracownicyIds ) {
  1467. throw new Exception("Nie wybrano pozycji do analizy. Wybierz pracowników/kontrahentów.");
  1468. }
  1469. // Tworzenie rekrodu w bazie - Raport -
  1470. $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
  1471. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1472. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1473. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  1474. 'FILE_STATUS' => "TO_GENERATE",
  1475. 'A_STATUS' => "NORMAL",
  1476. 'BI_analiza_minDepth' => 1,
  1477. 'BI_analiza_maxDepth' => $depthValue,
  1478. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  1479. ]);
  1480. if ($idRaport > 0) {
  1481. DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_HIST', [
  1482. 'ID_USERS2' => $idRaport,
  1483. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1484. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1485. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  1486. 'FILE_STATUS' => "TO_GENERATE",
  1487. 'A_STATUS' => "NORMAL",
  1488. 'BI_analiza_minDepth' => 1,
  1489. 'BI_analiza_maxDepth' => $depthValue,
  1490. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  1491. ]);
  1492. }
  1493. // Tworzenie relacji Raport do Pracownicy
  1494. $refPowiazaniaToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1495. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1496. // Tworzenie relacji Raport do Kontrahenci - analogicznie jak wyżej
  1497. $refPowiazaniaToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1498. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  1499. /* PRACOWNICY */
  1500. if ( !$pracownicyIds ) {
  1501. // dodajemy wszystkich pracowników
  1502. DB::getPDO()->execSql("insert into `{$refPowiazaniaToPracownicy}` (`PRIMARY_KEY`,`REMOTE_PRIMARY_KEY`)
  1503. select '{$idRaport}' as PRIMARY_KEY
  1504. , ID as REMOTE_PRIMARY_KEY
  1505. from `BI_audit_ENERGA_PRACOWNICY`
  1506. ");
  1507. } else { // wybrano pracownika/ów
  1508. foreach ($pracownicyIds as $idPracownik) {
  1509. DB::getPDO()->insert($refPowiazaniaToPracownicy, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  1510. }
  1511. }
  1512. /* KONTRAHENCI */
  1513. if ( !$kontrahenciIds ) {
  1514. // dodajemy wszystkich pracowników
  1515. DB::getPDO()->execSql("insert into `{$refPowiazaniaToKontrahenci}` (`PRIMARY_KEY`,`REMOTE_PRIMARY_KEY`)
  1516. select '{$idRaport}' as PRIMARY_KEY
  1517. , ID as REMOTE_PRIMARY_KEY
  1518. from `BI_audit_ENERGA_RUM_KONTRAHENCI`
  1519. ");
  1520. } else { // wybrano pracownika/ów
  1521. foreach ($kontrahenciIds as $idKontrahent) {
  1522. DB::getPDO()->insert($refPowiazaniaToKontrahenci, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idKontrahent ]);
  1523. }
  1524. }
  1525. return [
  1526. 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
  1527. 'type' => "success",
  1528. 'body' => [
  1529. 'id' => $idRaport,
  1530. ]
  1531. ];
  1532. }
  1533. /**
  1534. * Widok formularza dodawania pracowników i kontrahentów
  1535. */
  1536. public function defaultViewFormBiAudit($items, $type) {
  1537. $activeFormSteps = '';
  1538. $fieldLabels = [];
  1539. switch($type) {
  1540. case 'KONTRAHENCI':
  1541. $activeFormStepsKontrahent = 'complete';
  1542. $titleHeader = 'KONTRAHENCI/PODMIOTY';
  1543. $groupFilterList = '
  1544. <div class="menu-item">
  1545. <ul class="padding-0">
  1546. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  1547. </ul>
  1548. </div>
  1549. <div id="group-kontrahenci" class="btn-group">
  1550. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1551. </div>';
  1552. $formSmadDepth = '<input type="text" class="form-control smad-depth-kontrahenci" placeholder="1-16" value="" />';
  1553. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
  1554. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
  1555. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
  1556. $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>';
  1557. $graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
  1558. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  1559. $formAddNewData ='
  1560. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  1561. <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
  1562. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  1563. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  1564. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  1565. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-kontrahenci" placeholder="Default reaport" value="" />';
  1566. $showButtonNextStep = '';
  1567. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  1568. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  1569. $fieldList = $acl->getRealFieldList();
  1570. $fieldLabels = array_combine(
  1571. $fieldList,
  1572. array_map(function ($fieldName) use ($acl) {
  1573. return $acl->getFieldLabel($fieldName);
  1574. }, $fieldList)
  1575. );
  1576. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  1577. break;
  1578. case 'PRACOWNICY':
  1579. $titleHeader = 'OSOBY';
  1580. $groupFilterList = '
  1581. <div class="menu-item">
  1582. <ul class="padding-0">
  1583. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a></li>
  1584. </ul>
  1585. </div>
  1586. <div id="group-pracownicy" class="btn-group">
  1587. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1588. </div>';
  1589. $formSmadDepth = '<input type="text" class="form-control smad-depth" placeholder="1-16" value="" />';
  1590. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target"><option value="y">tak</option><option value="n">nie</option></select>';
  1591. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-pracownicy">Wszyscy</h2>';
  1592. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span></p>';
  1593. $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>';
  1594. $graphView = '<div class="smad-pracownicy-graph-view" style="display: none;"></div>';
  1595. $csvExamplePracownicy = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/pracownicy_example.zip';
  1596. $formAddNewData ='
  1597. <li><a title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import osób\', \'pracownicy\', \'yes\', \''.$csvExamplePracownicy.'\' )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
  1598. <li><a title="DODAJ PRACOWNIKÓW" onClick="createPracownikAjax(event)" class="btn btn-info" >+ DODAJ OSOBĘ</a></li>'; //todo: dodać obsługe doddawania pracownikow
  1599. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  1600. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addPracownikAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  1601. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removePracownikFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  1602. $showButtonNextStep = '<a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
  1603. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-pracownicy" placeholder="Default reaport" value="" />';
  1604. $pagination_form = '<div id="pagination-pracownicy"></div>';
  1605. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY");
  1606. $fieldList = $acl->getRealFieldList();
  1607. $fieldLabels = array_combine(
  1608. $fieldList,
  1609. array_map(function ($fieldName) use ($acl) {
  1610. return $acl->getFieldLabel($fieldName);
  1611. }, $fieldList)
  1612. );
  1613. DBG::log($fieldLabels, 'array', "fieldLabels (PRACOWNICY)");
  1614. break;
  1615. }
  1616. $view = '
  1617. <!-- start:employees-section-->
  1618. <div id="smad-employees-section" class="smad-form-' . $type . '" >
  1619. <div class="container-fluid">
  1620. <div>
  1621. <div class="padding-lr-0">
  1622. <div id="smad-menu-section">
  1623. <div class="col-sm-12 col-md-6 padding-lr-0">
  1624. <div class="menu-items">
  1625. <div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $titleHeader . ' </div>
  1626. </div>
  1627. </div>
  1628. <div class="col-sm-12 col-md-6 padding-lr-0">
  1629. <div class="form-steps">
  1630. <!-- start:form steps wizard -->
  1631. <div class="row smad-wizard" style="border-bottom:0;">
  1632. <div class="col-xs-4 col-md-4 smad-wizard-step complete"><!-- complited line -->
  1633. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1634. <div class="progress"><div class="progress-bar"></div></div>
  1635. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY" class="smad-wizard-dot"></a>
  1636. <div class="smad-wizard-info complete text-center">
  1637. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY">Krok 1</a></div>
  1638. <div class="step-title">OSOBY <span class="top--count-selected-item-pracownicy"></span></div>
  1639. </div>
  1640. </div>
  1641. <div class="col-xs-4 col-md-4 smad-wizard-step ' . $activeFormStepsKontrahent . ' ">
  1642. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1643. <div class="progress"><div class="progress-bar"></div></div>
  1644. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" class="smad-wizard-dot"></a>
  1645. <div class="smad-wizard-info text-center">
  1646. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI">Krok 2</a></div>
  1647. <div class="step-title">PODMIOTY/<BR />KONTRAHENCI <span class="top--count-selected-item-kontrahenci"></span></div>
  1648. </div>
  1649. </div>
  1650. <div class="col-xs-4 col-md-4 smad-wizard-step ">
  1651. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1652. <div class="progress"><div class="progress-bar"></div></div>
  1653. <a href="#" class="smad-wizard-dot"></a>
  1654. <div class="smad-wizard-info text-center">
  1655. <div class="step-item">Krok 3</div>
  1656. <div class="step-title">SZUKANIE POWIĄZAŃ</div>
  1657. </div>
  1658. </div>
  1659. </div>
  1660. <!-- end:form steps wizard -->
  1661. </div>
  1662. </div>
  1663. </div>
  1664. </div>
  1665. </div>
  1666. </div>
  1667. <div class="container-fluid">
  1668. <div class=" padding-lr-0">
  1669. <div class="smad-divider"></div>
  1670. </div>
  1671. </div>
  1672. <!-- start:filters -->
  1673. <div class="container-fluid">
  1674. <div class="row">
  1675. <div>
  1676. <div class="smad-employees-form-section" class="border-top-grey">
  1677. <div class="col-md-9 smad-border-col">
  1678. <div class="menu-items">
  1679. '.$groupFilterList.'
  1680. </div>
  1681. </div>
  1682. <div class="col-md-3">
  1683. <div class="form-input">
  1684. <div class="form-item col-md-7 col-lg-9 smad-heder-title">głębokość powiązań:</div>
  1685. <div class="form-item col-md-5 col-lg-3">
  1686. '.$formSmadDepth.'
  1687. </div>
  1688. </div>
  1689. <div class="form-input">
  1690. <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>
  1691. <div class="form-item col-md-5 col-lg-3">
  1692. '.$formSmadSelectTarget.'
  1693. </div>
  1694. </div>
  1695. </div>
  1696. </div>
  1697. </div>
  1698. </div>
  1699. </div>
  1700. <!-- end:filters -->
  1701. <!-- start:list employees -->
  1702. <div class="container-fluid">
  1703. <div class="padding-0 smad-employees-list-head">
  1704. <div class="col-md-6">
  1705. <header>
  1706. '.$formFilterHeadTitle.'
  1707. </header>
  1708. <div class="desc">
  1709. '.$formFilterHeadDesc.'
  1710. </div>
  1711. <div class="countSelectedItem">
  1712. '.$countSelectedItem.'
  1713. </div>
  1714. </div>
  1715. <div class="col-md-6">
  1716. <div class="menu-items">
  1717. <div class="menu-item">
  1718. <ul class="padding-0">
  1719. '.$formAddNewData.'
  1720. </ul>
  1721. </div>
  1722. </div>
  1723. </div>
  1724. </div>
  1725. </div>
  1726. <!-- Start: graph-view -->
  1727. <div class="smad-graph-section">
  1728. <div class="container-fluid">
  1729. '.$graphView.'
  1730. </div>
  1731. </div>
  1732. <!-- End: graph-view -->
  1733. <div class="container-fluid">
  1734. <div class="table-responsive padding-0" id="smad-table-' . $type . '">
  1735. ' . $this->showListDataByType($items, $type, $fieldLabels) . '
  1736. </div>
  1737. </div>
  1738. <!-- end:list employees -->
  1739. <!-- start:list paginations employees -->
  1740. <div class="container-fluid ">
  1741. <div>
  1742. '. $pagination_form .'
  1743. </div>
  1744. </div>
  1745. <!-- end:list paginations employees -->
  1746. <!-- start:bottom buttons -->
  1747. <div class="container-fluid smad-employees-bottom-navigation">
  1748. <div class="padding-0">
  1749. <div class="col-lg-6 ">
  1750. '.$buttonMoveToGroup.'
  1751. </div>
  1752. <div class="col-lg-6 text-right">
  1753. ' . $showButtonNextStep . '
  1754. </div>
  1755. </div>
  1756. </div>
  1757. <!-- end:bottom buttons -->
  1758. </div>
  1759. <!-- start:employees-section -->
  1760. <div class="container-fluid ">
  1761. <div class="row">
  1762. <div class="container text-center">
  1763. <div class="col-md-7 col-lg-5 " style="margin: 0 auto; float: none;">
  1764. '.$formSmadReaportTitleInput.'
  1765. </div>
  1766. </div>
  1767. </div>
  1768. </div>
  1769. <!-- START:bottom generate reaport-->
  1770. <div class="container-fluid smad-generate-reaport">
  1771. <div class="row">
  1772. <div class="container text-center">
  1773. <button type="button" class="btn btn-default smad-generate-reaport-button" onclick="generateBiAuditRaport(event)" id="button-generate-reaport" >GENERUJ RAPORT POWIĄZAŃ</button>
  1774. </div>
  1775. <div class="container smad-generate-reaport-info text-center">
  1776. <div class="step-title"><span class="bottom--count-selected-item-kontrahenci"></span></div>
  1777. <div class="step-title"><span class="bottom--count-selected-item-pracownicy"></span></div>
  1778. <div><strong><span class="bottom--message-warning-critical-search"></span></strong></div>
  1779. </div>
  1780. </div>
  1781. </div>
  1782. <!-- end:bottom generate reaport -->
  1783. ';
  1784. return $view;
  1785. }
  1786. public function showListDataByType($items, $type='PRACOWNICY', $labels) {
  1787. switch ($type) {
  1788. case 'PRACOWNICY':
  1789. return $this->showTablePracownicy($labels);
  1790. break;
  1791. case 'KONTRAHENCI':
  1792. return $this->showTableKontrahenci($labels);
  1793. break;
  1794. }
  1795. }
  1796. function fetchProgressAjaxAction() {
  1797. Response::sendTryCatchJson(array($this, 'fetchProgressAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1798. }
  1799. function fetchProgressAjax($args) {
  1800. $DBG_FAKE_ANIM = false;
  1801. if (empty($args['ids'])) return [ 'msg' => "empty ids", 'type' => "success" ];
  1802. $ids = $args['ids'];
  1803. // private static function getDirectory($table, $id) {
  1804. $firstId = reset($ids);
  1805. {
  1806. Lib::loadClass('FoldersConfig');
  1807. $folderConf = FoldersConfig::getAll('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_COLUMN');
  1808. if (!isset($folderConf['mount_point'])) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$errMsg}", 404);
  1809. $rootPath = $folderConf['mount_point'];
  1810. }
  1811. $statuses = array_map(function ($id) {
  1812. return DB::getPDO()->fetchValue(" select FILE_STATUS from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  1813. }, $ids);
  1814. $statusesInfo = array_map(function ($id) {
  1815. return DB::getPDO()->fetchValue(" select FILE_STATUS_info from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  1816. }, $ids);
  1817. $progress = array_map(function ($id, $idx) use ($rootPath, $statuses, $DBG_FAKE_ANIM) {
  1818. DBG::log("Loop id({$id}) is-eq-82(".(82 == $id).") is-eq-'82'(".("82"==$id).")");
  1819. DBG::log("Loop id({$id}) is-eq-80(".(80 == $id).") is-eq-'80'(".("80"==$id).")");
  1820. $status = $statuses[$idx];
  1821. if ($DBG_FAKE_ANIM && 82 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  1822. if ($DBG_FAKE_ANIM && 80 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  1823. if ($DBG_FAKE_ANIM && 77 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  1824. DBG::log("Loop id({$id}) status({$status})...");
  1825. if ('GENERATED' === $status) return 1;
  1826. if ('IN_PROGRESS' !== $status) return 0;
  1827. if (!file_exists("{$rootPath}/.tasks/generatePowiazania-{$id}.progress")) return 0;
  1828. DBG::log("Loop id({$id}) status({$status}) progress file exists");
  1829. try {
  1830. $cnt = file_get_contents("{$rootPath}/.tasks/generatePowiazania-{$id}.progress");
  1831. $json = @json_decode($cnt, $assoc = true);
  1832. if (null === $json && 0 !== json_last_error()) {
  1833. throw new Exception("Parse json error for restrictions: " . json_last_error());
  1834. }
  1835. // $json['summary']['step']: 'initialize', 'relations', 'reports'
  1836. // $json['summary']['step'] = 'initialize' - recache - skip
  1837. // $json['summary']['step'] = 'relations' - szuka powiązań (@see AVG(details.progress / summary.count))
  1838. // $json['summary']['step'] = 'reports' - generuje pliki (@see summary.created)
  1839. /*
  1840. if ($DBG_FAKE_ANIM && 82 == $id) { // TODO: DBG
  1841. $json = [
  1842. 'summary' => [
  1843. 'count' => 4,
  1844. 'step' => 'relations',
  1845. ],
  1846. 'details' => [
  1847. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1848. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1849. '22' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1850. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1851. ] ];
  1852. }
  1853. */
  1854. if ($DBG_FAKE_ANIM && 80 == $id) { // TODO: DBG
  1855. $json = [
  1856. 'summary' => [
  1857. 'count' => 4,
  1858. 'created' => 2,
  1859. 'step' => 'reports',
  1860. ],
  1861. 'details' => [
  1862. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1863. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1864. '22' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1865. '25' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1866. ] ];
  1867. }
  1868. if ($DBG_FAKE_ANIM && 77 == $id) { // TODO: DBG
  1869. $json = [
  1870. 'summary' => [
  1871. 'count' => 4,
  1872. 'created' => 2,
  1873. 'step' => 'relations',
  1874. ],
  1875. 'details' => [
  1876. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1877. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1878. '22' => [ 'progress' => 0.25, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1879. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  1880. ] ];
  1881. }
  1882. DBG::log($json, 'array', "Loop id({$id}) status({$status}) progress json");
  1883. if (empty($json['summary'])) return 0;
  1884. if (empty($json['summary']['count'])) return 0;
  1885. if (empty($json['summary']['step'])) return 0;
  1886. if (empty($json['details'])) return 0;
  1887. $listDetailsProgress = array_map(function ($detail) {
  1888. return floatval($detail['progress']);
  1889. }, $json['details']);
  1890. $relationsProgress = $json['summary']['count'] > 0 ? round(floatval(array_sum($listDetailsProgress)) / floatval($json['summary']['count']), 3) : 0;
  1891. $reportsCount = V::get('reportsCount', 0, $json['summary'], 'float');
  1892. $reportsProgress = $reportsCount > 0 ? round(V::get('reportsCreated', 0, $json['summary'], 'float') / $reportsCount, 3) : 0;
  1893. return round(0.5 * $relationsProgress + 0.5 * $reportsProgress, 3);
  1894. } catch (Exception $e) {
  1895. DBG::log($e);
  1896. }
  1897. return 0;
  1898. }, $ids, array_keys($ids));
  1899. return [ 'msg' => "DBG ids set", 'type' => "success", 'body' => [
  1900. 'ids' => $ids,
  1901. 'progress' => $progress,
  1902. 'statuses' => $statuses,
  1903. 'statusesInfo' => $statusesInfo,
  1904. ] ];
  1905. }
  1906. }