Bocian.php 89 KB

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