Bocian.php 86 KB

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