Bocian.php 84 KB

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