Bocian.php 84 KB

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