Bocian.php 84 KB

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