Bocian.php 100 KB

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