Bocian.php 100 KB

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