Bocian.php 92 KB

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