Bocian.php 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445
  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= {$idGroup} and REMOTE_PRIMARY_KEY = {$id}");
  1224. }
  1225. return [
  1226. 'msg' => "Usunięto osoby z grupy {$idGroup}",
  1227. 'type' => "success",
  1228. ];
  1229. }
  1230. }
  1231. public function removeKontrahenciFromGroupAjaxAction() {
  1232. 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
  1233. }
  1234. public function removeKontrahenciFromGroupAjax($args) {
  1235. $idGroup = V::get('idGroup', 0, $args, "int");
  1236. $kontrahenciIds = V::get('kontrahenciIds', [], $args, 'array');
  1237. if ($idGroup === 0){
  1238. foreach ($kontrahenciIds as $kontrahentIds) {
  1239. //TO DO sprawdzanie czy już DELETED
  1240. $affected = DB::getPDO()->update('BI_audit_ENERGA_RUM_KONTRAHENCI', 'ID', $kontrahentIds, [
  1241. 'A_STATUS' => 'DELETED',
  1242. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  1243. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  1244. ])->debugDumpParams();
  1245. }
  1246. return [
  1247. 'msg' => "Usunięto kontrahentów z systemu",
  1248. 'type' => "success",
  1249. ];
  1250. } else {
  1251. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  1252. 'cols' => [ // TODO:? propertyName = []
  1253. 'ID',
  1254. 'ID_USER',
  1255. 'NAZWA',
  1256. ],
  1257. // 'f_ID_USER' => User::getID()
  1258. ])->getItem($idGroup);
  1259. if (!$group) throw new Exception("Grupa nie istnieje");
  1260. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1261. $refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  1262. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  1263. foreach ($kontrahenciIds as $kontrahentIds) {
  1264. // DB::getPDO()->insert($refGrupyToKontrahenci, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $kontrahentIds]);
  1265. $id = (int)$kontrahentIds;
  1266. DBG::log("nazwa grupy {$refGrupyToKontrahenci}");
  1267. DB::getPDO()->execSql("delete from {$refGrupyToKontrahenci} where PRIMARY_KEY= {$idGroup} and REMOTE_PRIMARY_KEY = {$id}");
  1268. //DB::
  1269. }
  1270. return [
  1271. 'msg' => "Usunięto kontrahentów z grupy {$idGroup}",
  1272. 'type' => "success",
  1273. ];
  1274. }
  1275. }
  1276. public function fetchGroupKontrahenciAjaxAction() {
  1277. Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
  1278. }
  1279. public function fetchGroupKontrahenciAjax() {
  1280. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  1281. 'cols' => [ // TODO:? propertyName = []
  1282. 'ID',
  1283. 'ID_USER',
  1284. 'NAZWA',
  1285. ],
  1286. 'f_ID_USER' => "=" . User::getID(),
  1287. 'f_A_STATUS' => "!DELETED",
  1288. ]);
  1289. $itemsKontrahenci = $query->getItems();
  1290. if (empty($itemsKontrahenci)) throw new AlertWarningException("Grupy nie istnieją");
  1291. $arrayGroupKontrahenci = array();
  1292. foreach ($itemsKontrahenci as $item) {
  1293. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1294. $arrayGroupKontrahenci[] = [
  1295. 'NAZWA' => $item['NAZWA'],
  1296. 'ID' => $item['ID'],
  1297. ];
  1298. }
  1299. return [
  1300. 'type' => 'success',
  1301. 'msg' => 'fetchGroupKontrahenciAjax',
  1302. '__req_args' => $_REQUEST,
  1303. '__args' => $args,
  1304. 'body' => [
  1305. 'itemsGroupKontrahenci' => $arrayGroupKontrahenci
  1306. ]
  1307. ];
  1308. }
  1309. public function fetchPracownicyIdsAjaxAction() {
  1310. Response::sendTryCatchJson(array($this, 'fetchPracownicyIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1311. }
  1312. public function fetchPracownicyIdsAjax($args) {
  1313. $idGroup = V::get('filter_idGroup', 0, $args, 'int');
  1314. if ($idGroup < 0) $idGroup = 0;
  1315. $backRefFilter = [];
  1316. if ($idGroup > 0) {
  1317. $backRefFilter['__backRef'] = [
  1318. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1319. 'primaryKey' => $idGroup,
  1320. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1321. ];
  1322. }
  1323. $searchParams = []; // TODO: ???
  1324. $filtersParams = [];
  1325. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1326. return ('f_' === substr($key, 0, 2));
  1327. });
  1328. foreach ($fieldFilterKeys as $key) {
  1329. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1330. }
  1331. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1332. $query = $acl->buildQuery(array_merge([
  1333. 'cols' => [
  1334. 'ID',
  1335. ],
  1336. //'f_ID' => $id,
  1337. 'limit' => 0,
  1338. // 'limitstart' => $limitstart, // offset
  1339. // 'order_by' => 'ID', // sortowanie po kolumnie
  1340. // 'order_dir' => 'DESC', // kierunek sortowania
  1341. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1342. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1343. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1344. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1345. ], $searchParams, $filtersParams, $backRefFilter));
  1346. // $total = $query->getTotal();
  1347. $items = $query->getItems();
  1348. return [
  1349. 'type' => 'success',
  1350. 'msg' => 'pracownicy ids',
  1351. 'body' => [
  1352. 'ids' => array_map( V::makePick('ID'), $items ),
  1353. ],
  1354. '__args' => $args,
  1355. '__DBG_$idGroup' => $idGroup,
  1356. '__DBG_$filtersParams' => $filtersParams,
  1357. '__DBG_$backRefFilter' => $backRefFilter,
  1358. ];
  1359. }
  1360. /*
  1361. * PRACOWNICY
  1362. */
  1363. public function fetchPracownicyAjaxAction() {
  1364. Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'), $args = $_REQUEST);
  1365. }
  1366. public function fetchPracownicyAjax($args) {
  1367. $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1368. if ($idGroup < 0) $idGroup = 0;
  1369. $limit = 20;
  1370. $page = V::get('page', 0, $args, 'int');
  1371. $limitstart = ($page - 1) * $limit;
  1372. $search = V::get('search', '', $args);
  1373. $searchParams = [];
  1374. if (!empty($search)) {
  1375. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1376. $searchParams['ogc:Filter'] = '
  1377. <ogc:Filter>
  1378. <ogc:Or>
  1379. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1380. <ogc:PropertyName>nip</ogc:PropertyName>
  1381. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1382. </ogc:PropertyIsLike>
  1383. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1384. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1385. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1386. </ogc:PropertyIsLike>
  1387. </ogc:Or>
  1388. </ogc:Filter>
  1389. ';
  1390. }
  1391. $backRefFilter = [];
  1392. if ($idGroup > 0) {
  1393. $backRefFilter['__backRef'] = [
  1394. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1395. 'primaryKey' => $idGroup,
  1396. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1397. ];
  1398. }
  1399. $filtersParams = [];
  1400. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1401. return ('f_' === substr($key, 0, 2));
  1402. });
  1403. foreach ($fieldFilterKeys as $key) {
  1404. if ('f_ID' === $key) $filtersParams[ $key ] = '=' . $args[ $key ];
  1405. else $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1406. }
  1407. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1408. $query = $acl->buildQuery(array_merge([
  1409. 'cols' => array_merge(self::$FIELD_LIST_PRACOWNICY, [
  1410. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  1411. ]),
  1412. //'f_ID' => $id,
  1413. 'limit' => $limit,
  1414. 'limitstart' => $limitstart, // offset
  1415. 'order_by' => 'ID', // sortowanie po kolumnie
  1416. 'order_dir' => 'DESC', // kierunek sortowania
  1417. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1418. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1419. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1420. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1421. ], $searchParams, $filtersParams, $backRefFilter));
  1422. $total = $query->getTotal();
  1423. $items = $query->getItems();
  1424. $pagination = array();
  1425. $pagination['total_items'] = $total;
  1426. $pagination['size'] = ceil($total/$limit); // pages size
  1427. $pagination['current'] = $page;
  1428. $pagination['limit'] = $limit;
  1429. // $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1430. if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
  1431. // { // tworzenie własnego zapytanie mysql
  1432. // $rootTableName = $acl->getRootTableName();
  1433. // DB::getPDO()->fetchAll("
  1434. // select t.*
  1435. // from {$rootTableName} t
  1436. // where t.ID in (
  1437. // select x.ID
  1438. // from ... x
  1439. // where
  1440. // )
  1441. // ");
  1442. // }
  1443. return [
  1444. 'type' => 'success',
  1445. 'msg' => 'showPracownicy',
  1446. 'body' => [
  1447. 'items' => $items,
  1448. //'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
  1449. 'pagination' => $pagination
  1450. ],
  1451. '__DBG_$idGroup' => $idGroup,
  1452. '__DBG_$filtersParams' => $filtersParams,
  1453. '__DBG_$backRefFilter' => $backRefFilter,
  1454. ];
  1455. }
  1456. public function showTablePracownicy($labels = []) {
  1457. // TODO: use self::$FIELD_LIST_PRACOWNICY
  1458. $view = '<form class="form-horizontal" method="post">
  1459. <table class="table table-responsive table-bordered table-hover table-striped" height=5>
  1460. <thead>
  1461. <tr>
  1462. <td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
  1463. <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
  1464. <td>' . V::get('imiona', 'Imię/Imiona', $labels) . '</td>
  1465. <td>' . V::get('nazwisko', 'Nazwisko', $labels) . '</td>
  1466. <td>' . V::get('nip', 'NIP', $labels) . '</td>
  1467. <td>' . V::get('pesel', 'Pesel', $labels) . '</td>
  1468. <td>' . V::get('regon', 'Regon', $labels) . '</td>
  1469. <td>' . V::get('source', 'source', $labels) . '</td>
  1470. <td>' . V::get('jednostka_organizacyjna', 'jednostka_organizacyjna', $labels) . '</td>
  1471. <td>' . V::get('A_STATUS', 'A_STATUS', $labels) . '</td>
  1472. <td>' . V::get('A_STATUS_INFO', 'A_STATUS_INFO', $labels) . '</td>
  1473. <td>' . V::get('L_APPOITMENT_USER', 'L_APPOITMENT_USER', $labels) . '</td>
  1474. <td>' . V::get('Adresy', 'Adresy', $labels) . '</td>
  1475. </tr>
  1476. <tr>
  1477. <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>
  1478. <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>
  1479. <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>
  1480. <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>
  1481. <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>
  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_pesel" 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_regon" 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_source" 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_jednostka_organizacyjna" 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_A_STATUS" 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_A_STATUS_INFO" 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_L_APPOITMENT_USER" 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_Adresy" value="" placeholder="%"></td>
  1490. </tr>
  1491. </thead>
  1492. <tbody id="body-pracownicy">
  1493. </tbody></table>
  1494. </form>';
  1495. return $view;
  1496. }
  1497. // tworzenie grupy pracowników
  1498. public function createPracownicyGroupAjaxAction() {
  1499. 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
  1500. }
  1501. public function createPracownicyGroupAjax($args) {
  1502. $nazwa = V::get('NAZWA', '', $args);
  1503. // validate
  1504. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  1505. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
  1506. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1507. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1508. 'NAZWA' => $nazwa,
  1509. 'ID_USER' => User::getID()
  1510. ]);
  1511. return [
  1512. 'msg' => "Utworzona grupę {$nazwa}",
  1513. 'type' => "success",
  1514. 'body' => [
  1515. 'id' => $idGroup,
  1516. 'nazwa' => $nazwa
  1517. ]
  1518. ];
  1519. }
  1520. // Dodanie do grupy filtra pracowników
  1521. public function addPracownicyToGroupAjaxAction() {
  1522. 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
  1523. }
  1524. public function addPracownicyToGroupAjax($args) {
  1525. $idGroup = V::get('idGroup', '', $args);
  1526. $type = V::get('type', 'ids', $args);
  1527. $pracownicyIds = V::get('pracownicyIds', '', $args);
  1528. $filter = V::get('filter', '', $args);
  1529. // validate
  1530. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  1531. switch ($type) {
  1532. case 'ids': {
  1533. if (!$pracownicyIds || count($pracownicyIds) == 0) throw new Exception("Proszę wybrać pracowników");
  1534. } break;
  1535. case 'filter': {
  1536. if (!isset($args['filter'])) throw new Exception("Proszę wybrać pracowników");
  1537. } break;
  1538. default: throw new Exception("Missing type");
  1539. }
  1540. // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
  1541. // default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
  1542. // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
  1543. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1544. 'cols' => [ // TODO:? propertyName = []
  1545. 'ID',
  1546. 'ID_USER',
  1547. 'NAZWA',
  1548. ],
  1549. // 'f_ID_USER' => User::getID()
  1550. ])->getItem($idGroup);
  1551. if (!$group) throw new Exception("Grupa nie istnieje");
  1552. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1553. if ('filter' === $type) {
  1554. $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1555. if ($args__idGroup < 0) $args__idGroup = 0;
  1556. $search = V::get('search', '', $args['filter']);
  1557. $searchParams = [];
  1558. if (!empty($search)) {
  1559. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1560. $searchParams['ogc:Filter'] = '
  1561. <ogc:Filter>
  1562. <ogc:Or>
  1563. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1564. <ogc:PropertyName>nip</ogc:PropertyName>
  1565. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1566. </ogc:PropertyIsLike>
  1567. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1568. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1569. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1570. </ogc:PropertyIsLike>
  1571. </ogc:Or>
  1572. </ogc:Filter>
  1573. ';
  1574. }
  1575. $backRefFilter = [];
  1576. if ($args__idGroup > 0) {
  1577. $backRefFilter['__backRef'] = [
  1578. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1579. 'primaryKey' => $args__idGroup,
  1580. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1581. ];
  1582. }
  1583. $filtersParams = [];
  1584. $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
  1585. return ('f_' === substr($key, 0, 2));
  1586. });
  1587. foreach ($fieldFilterKeys as $key) {
  1588. $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
  1589. }
  1590. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1591. $query = $acl->buildQuery(array_merge([
  1592. 'cols' => ['ID'],
  1593. ], $searchParams, $filtersParams, $backRefFilter, [
  1594. 'limit' => 0
  1595. ]));
  1596. $items = $query->getItems();
  1597. $pracownicyIds = array_map(function ($row) {
  1598. return $row['ID'];
  1599. }, $items);
  1600. }
  1601. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  1602. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1603. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1604. foreach ($pracownicyIds as $idPracownik) {
  1605. DB::getPDO()->insert($refGrupyToPracownicy, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  1606. }
  1607. return [
  1608. 'msg' => "Powiązano pracowników z grupą {$idGroup}",
  1609. 'type' => "success",
  1610. ];
  1611. }
  1612. public function fetchGroupPracownicyAjaxAction() {
  1613. Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
  1614. }
  1615. public function fetchGroupPracownicyAjax() {
  1616. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1617. 'cols' => [ // TODO:? propertyName = []
  1618. 'ID',
  1619. 'ID_USER',
  1620. 'NAZWA',
  1621. ],
  1622. 'f_ID_USER' => "=" . User::getID(), // szukamy dokładnie tej wartości - mysql: where ID_USER = "1"
  1623. 'f_A_STATUS' => "!DELETED", // `A_STATUS` != 'DELETED'
  1624. ]);
  1625. $items = $query->getItems();
  1626. if (empty($items)) throw new AlertWarningException("Grupy nie istnieją");
  1627. $arrayGroupPracownicy = array();
  1628. foreach ($items as $item) {
  1629. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy"); // or skip - continue;
  1630. $arrayGroupPracownicy[] = [
  1631. 'ID' => $item['ID'],
  1632. 'NAZWA' => $item['NAZWA'],
  1633. ];
  1634. }
  1635. return [
  1636. 'type' => 'success',
  1637. 'msg' => 'fetchGroupPracownicyAjax',
  1638. '__req_args' => $_REQUEST,
  1639. '__args' => $args,
  1640. 'body' => [
  1641. 'itmesGroupPracownicy' => $arrayGroupPracownicy
  1642. ]
  1643. ];
  1644. }
  1645. // link do ackji w php: $saveFormUrl = $this->getLink('saveRaportAjax');
  1646. // przekazać link do JavaScript i tam:
  1647. // window.fetch('{$saveFormUrl}', { ... }).then(...) - dokumentacja: https://github.com/github/fetch
  1648. public function generateBiAuditRaportAjaxAction() {
  1649. //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
  1650. Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1651. //Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'));
  1652. }
  1653. public function generateBiAuditRaportAjax($args) {
  1654. // głebokość powiazan
  1655. $depthValue = V::get('depthValue', '', $args);
  1656. if (!$depthValue) {
  1657. throw new Exception("Nie podano wartości dla głębokości powiązań");
  1658. }
  1659. // tytuł raportu
  1660. $smadReaportTitle = V::get('smadReaportTitle', '', $args);
  1661. if (!$smadReaportTitle) {
  1662. throw new Exception("Nie podano tytułu raportu");
  1663. }
  1664. // Bi_analiza_onlyTarger
  1665. $analizaOnlyTargets = V::get('analizaOnlyTargets', '', $args);
  1666. if (!$analizaOnlyTargets) {
  1667. throw new Exception("Nie podano wartości czy zwracać wyniki tylko z obiektami docelowymi");
  1668. }
  1669. // Tworzenie relacji Raport do Pracownicy
  1670. $pracownicyIds = []; // array z nr ID na podstawie wysłanego formularza
  1671. $pracownicyIds = V::get('pracownicyIds', '', $args);
  1672. $kontrahenciIds = []; // array z nr ID na podstawie wysłanego formularza
  1673. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  1674. // walidacja listy kontrahentów i pracowników
  1675. if ( !$kontrahenciIds && !$pracownicyIds ) {
  1676. throw new Exception("Nie wybrano pozycji do analizy. Wybierz pracowników/kontrahentów.");
  1677. }
  1678. // Tworzenie rekrodu w bazie - Raport -
  1679. $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
  1680. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1681. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1682. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  1683. 'FILE_STATUS' => "TO_GENERATE",
  1684. 'A_STATUS' => "NORMAL",
  1685. 'BI_analiza_minDepth' => 1,
  1686. 'BI_analiza_maxDepth' => $depthValue,
  1687. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  1688. ]);
  1689. if ($idRaport > 0) {
  1690. DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_HIST', [
  1691. 'ID_USERS2' => $idRaport,
  1692. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1693. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1694. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  1695. 'FILE_STATUS' => "TO_GENERATE",
  1696. 'A_STATUS' => "NORMAL",
  1697. 'BI_analiza_minDepth' => 1,
  1698. 'BI_analiza_maxDepth' => $depthValue,
  1699. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  1700. ]);
  1701. }
  1702. // Tworzenie relacji Raport do Pracownicy
  1703. $refPowiazaniaToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1704. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1705. // Tworzenie relacji Raport do Kontrahenci - analogicznie jak wyżej
  1706. $refPowiazaniaToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1707. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  1708. /* PRACOWNICY */
  1709. if ( !$pracownicyIds ) {
  1710. // dodajemy wszystkich pracowników
  1711. DB::getPDO()->execSql("insert into `{$refPowiazaniaToPracownicy}` (`PRIMARY_KEY`,`REMOTE_PRIMARY_KEY`)
  1712. select '{$idRaport}' as PRIMARY_KEY
  1713. , ID as REMOTE_PRIMARY_KEY
  1714. from `BI_audit_ENERGA_PRACOWNICY`
  1715. ");
  1716. } else { // wybrano pracownika/ów
  1717. foreach ($pracownicyIds as $idPracownik) {
  1718. DB::getPDO()->insert($refPowiazaniaToPracownicy, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  1719. }
  1720. }
  1721. /* KONTRAHENCI */
  1722. if ( !$kontrahenciIds ) {
  1723. // dodajemy wszystkich pracowników
  1724. DB::getPDO()->execSql("insert into `{$refPowiazaniaToKontrahenci}` (`PRIMARY_KEY`,`REMOTE_PRIMARY_KEY`)
  1725. select '{$idRaport}' as PRIMARY_KEY
  1726. , ID as REMOTE_PRIMARY_KEY
  1727. from `BI_audit_ENERGA_RUM_KONTRAHENCI`
  1728. ");
  1729. } else { // wybrano pracownika/ów
  1730. foreach ($kontrahenciIds as $idKontrahent) {
  1731. DB::getPDO()->insert($refPowiazaniaToKontrahenci, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idKontrahent ]);
  1732. }
  1733. }
  1734. return [
  1735. 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
  1736. 'type' => "success",
  1737. 'body' => [
  1738. 'id' => $idRaport,
  1739. ]
  1740. ];
  1741. }
  1742. /**
  1743. * Widok formularza dodawania pracowników i kontrahentów
  1744. */
  1745. public function defaultViewFormBiAudit($items, $type) {
  1746. $activeFormSteps = '';
  1747. $fieldLabels = [];
  1748. switch($type) {
  1749. case 'KONTRAHENCI':
  1750. $activeFormStepsKontrahent = 'complete';
  1751. $titleHeader = 'KONTRAHENCI/PODMIOTY';
  1752. $groupFilterList = '
  1753. <div class="menu-item">
  1754. <ul class="padding-0">
  1755. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  1756. </ul>
  1757. </div>
  1758. <div id="group-kontrahenci" class="btn-group">
  1759. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1760. </div>';
  1761. $formSmadDepth = '<input type="text" class="form-control smad-depth-kontrahenci" placeholder="1-16" value="" />';
  1762. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
  1763. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
  1764. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
  1765. $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>';
  1766. $graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
  1767. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  1768. $formAddNewData ='
  1769. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  1770. <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
  1771. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  1772. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  1773. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  1774. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-kontrahenci" placeholder="Default reaport" value="" />';
  1775. $showButtonNextStep = '';
  1776. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  1777. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  1778. $fieldList = $acl->getRealFieldList();
  1779. $fieldLabels = array_combine(
  1780. $fieldList,
  1781. array_map(function ($fieldName) use ($acl) {
  1782. return $acl->getFieldLabel($fieldName);
  1783. }, $fieldList)
  1784. );
  1785. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  1786. break;
  1787. case 'OPERACYJNA_BAZA_ZGLOSZEN':
  1788. $activeFormStepsKontrahent = 'complete';
  1789. $titleHeader = 'KONTRAHENCI/PODMIOTY';
  1790. $groupFilterList = '
  1791. <div class="menu-item">
  1792. <ul class="padding-0">
  1793. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  1794. </ul>
  1795. </div>
  1796. <div id="group-kontrahenci" class="btn-group">
  1797. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1798. </div>';
  1799. $formSmadDepth = '<input type="text" class="form-control smad-depth-kontrahenci" placeholder="1-16" value="" />';
  1800. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
  1801. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
  1802. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
  1803. $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>';
  1804. $graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
  1805. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  1806. $formAddNewData ='
  1807. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  1808. <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
  1809. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  1810. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  1811. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  1812. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-kontrahenci" placeholder="Default reaport" value="" />';
  1813. $showButtonNextStep = '';
  1814. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  1815. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  1816. $fieldList = $acl->getRealFieldList();
  1817. $fieldLabels = array_combine(
  1818. $fieldList,
  1819. array_map(function ($fieldName) use ($acl) {
  1820. return $acl->getFieldLabel($fieldName);
  1821. }, $fieldList)
  1822. );
  1823. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  1824. break;
  1825. case 'PRACOWNICY':
  1826. $titleHeader = 'OSOBY';
  1827. $groupFilterList = '
  1828. <div class="menu-item">
  1829. <ul class="padding-0">
  1830. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a></li>
  1831. </ul>
  1832. </div>
  1833. <div id="group-pracownicy" class="btn-group">
  1834. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  1835. </div>';
  1836. $formSmadDepth = '<input type="text" class="form-control smad-depth" placeholder="1-16" value="" />';
  1837. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target"><option value="y">tak</option><option value="n">nie</option></select>';
  1838. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-pracownicy">Wszyscy</h2>';
  1839. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span></p>';
  1840. $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>';
  1841. $graphView = '<div class="smad-pracownicy-graph-view" style="display: none;"></div>';
  1842. $csvExamplePracownicy = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/pracownicy_example.zip';
  1843. $formAddNewData ='
  1844. <li><a title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import osób\', \'pracownicy\', \'yes\', \''.$csvExamplePracownicy.'\' )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
  1845. <li><a title="DODAJ PRACOWNIKÓW" onClick="createPracownikAjax(event)" class="btn btn-info" >+ DODAJ OSOBĘ</a></li>'; //todo: dodać obsługe doddawania pracownikow
  1846. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  1847. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addPracownikAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  1848. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removePracownikFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  1849. $showButtonNextStep = '<a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
  1850. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-pracownicy" placeholder="Default reaport" value="" />';
  1851. $pagination_form = '<div id="pagination-pracownicy"></div>';
  1852. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY");
  1853. $fieldList = $acl->getRealFieldList();
  1854. $fieldLabels = array_combine(
  1855. $fieldList,
  1856. array_map(function ($fieldName) use ($acl) {
  1857. return $acl->getFieldLabel($fieldName);
  1858. }, $fieldList)
  1859. );
  1860. DBG::log($fieldLabels, 'array', "fieldLabels (PRACOWNICY)");
  1861. break;
  1862. }
  1863. $view = '
  1864. <!-- start:employees-section-->
  1865. <div id="smad-employees-section" class="smad-form-' . $type . '" >
  1866. <div class="container-fluid">
  1867. <div>
  1868. <div class="padding-lr-0">
  1869. <div id="smad-menu-section">
  1870. <div class="col-sm-12 col-md-6 padding-lr-0">
  1871. <div class="menu-items">
  1872. <div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $titleHeader . ' </div>
  1873. </div>
  1874. </div>
  1875. <div class="col-sm-12 col-md-6 padding-lr-0">
  1876. <div class="form-steps">
  1877. <!-- start:form steps wizard -->
  1878. <div class="row smad-wizard" style="border-bottom:0;">
  1879. <div class="col-xs-4 col-md-4 smad-wizard-step complete"><!-- complited line -->
  1880. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1881. <div class="progress"><div class="progress-bar"></div></div>
  1882. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY" class="smad-wizard-dot"></a>
  1883. <div class="smad-wizard-info complete text-center">
  1884. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY">Krok 1</a></div>
  1885. <div class="step-title">OSOBY <span class="top--count-selected-item-pracownicy"></span></div>
  1886. </div>
  1887. </div>
  1888. <div class="col-xs-4 col-md-4 smad-wizard-step ' . $activeFormStepsKontrahent . ' ">
  1889. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1890. <div class="progress"><div class="progress-bar"></div></div>
  1891. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" class="smad-wizard-dot"></a>
  1892. <div class="smad-wizard-info text-center">
  1893. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI">Krok 2</a></div>
  1894. <div class="step-title">PODMIOTY/<BR />KONTRAHENCI <span class="top--count-selected-item-kontrahenci"></span></div>
  1895. </div>
  1896. </div>
  1897. <div class="col-xs-4 col-md-4 smad-wizard-step ">
  1898. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  1899. <div class="progress"><div class="progress-bar"></div></div>
  1900. <a href="#" class="smad-wizard-dot"></a>
  1901. <div class="smad-wizard-info text-center">
  1902. <div class="step-item">Krok 3</div>
  1903. <div class="step-title">SZUKANIE POWIĄZAŃ</div>
  1904. </div>
  1905. </div>
  1906. </div>
  1907. <!-- end:form steps wizard -->
  1908. </div>
  1909. </div>
  1910. </div>
  1911. </div>
  1912. </div>
  1913. </div>
  1914. <div class="container-fluid">
  1915. <div class=" padding-lr-0">
  1916. <div class="smad-divider"></div>
  1917. </div>
  1918. </div>
  1919. <!-- start:filters -->
  1920. <div class="container-fluid">
  1921. <div class="row">
  1922. <div>
  1923. <div class="smad-employees-form-section" class="border-top-grey">
  1924. <div class="col-md-9 smad-border-col">
  1925. <div class="menu-items">
  1926. '.$groupFilterList.'
  1927. </div>
  1928. </div>
  1929. <div class="col-md-3">
  1930. <div class="form-input">
  1931. <div class="form-item col-md-7 col-lg-9 smad-heder-title">głębokość powiązań:</div>
  1932. <div class="form-item col-md-5 col-lg-3">
  1933. '.$formSmadDepth.'
  1934. </div>
  1935. </div>
  1936. <div class="form-input">
  1937. <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>
  1938. <div class="form-item col-md-5 col-lg-3">
  1939. '.$formSmadSelectTarget.'
  1940. </div>
  1941. </div>
  1942. </div>
  1943. </div>
  1944. </div>
  1945. </div>
  1946. </div>
  1947. <!-- end:filters -->
  1948. <!-- start:list employees -->
  1949. <div class="container-fluid">
  1950. <div class="padding-0 smad-employees-list-head">
  1951. <div class="col-md-6">
  1952. <header>
  1953. '.$formFilterHeadTitle.'
  1954. </header>
  1955. <div class="desc">
  1956. '.$formFilterHeadDesc.'
  1957. </div>
  1958. <div class="countSelectedItem">
  1959. '.$countSelectedItem.'
  1960. </div>
  1961. </div>
  1962. <div class="col-md-6">
  1963. <div class="menu-items">
  1964. <div class="menu-item">
  1965. <ul class="padding-0">
  1966. '.$formAddNewData.'
  1967. </ul>
  1968. </div>
  1969. </div>
  1970. </div>
  1971. </div>
  1972. </div>
  1973. <!-- Start: graph-view -->
  1974. <div class="smad-graph-section">
  1975. <div class="container-fluid">
  1976. '.$graphView.'
  1977. </div>
  1978. </div>
  1979. <!-- End: graph-view -->
  1980. <div class="container-fluid">
  1981. <div class="table-responsive padding-0" id="smad-table-' . $type . '">
  1982. ' . $this->showListDataByType($items, $type, $fieldLabels) . '
  1983. </div>
  1984. </div>
  1985. <!-- end:list employees -->
  1986. <!-- start:list paginations employees -->
  1987. <div class="container-fluid ">
  1988. <div>
  1989. '. $pagination_form .'
  1990. </div>
  1991. </div>
  1992. <!-- end:list paginations employees -->
  1993. <!-- start:bottom buttons -->
  1994. <div class="container-fluid smad-employees-bottom-navigation">
  1995. <div class="padding-0">
  1996. <div class="col-lg-6 ">
  1997. '.$buttonMoveToGroup.'
  1998. </div>
  1999. <div class="col-lg-6 text-right">
  2000. ' . $showButtonNextStep . '
  2001. </div>
  2002. </div>
  2003. </div>
  2004. <!-- end:bottom buttons -->
  2005. </div>
  2006. <!-- start:employees-section -->
  2007. <div class="container-fluid ">
  2008. <div class="row">
  2009. <div class="container text-center">
  2010. <div class="col-md-7 col-lg-5 " style="margin: 0 auto; float: none;">
  2011. '.$formSmadReaportTitleInput.'
  2012. </div>
  2013. </div>
  2014. </div>
  2015. </div>
  2016. <!-- START:bottom generate reaport-->
  2017. <div class="container-fluid smad-generate-reaport">
  2018. <div class="row">
  2019. <div class="container text-center">
  2020. <button type="button" class="btn btn-default smad-generate-reaport-button" onclick="generateBiAuditRaport(event)" id="button-generate-reaport" >GENERUJ RAPORT POWIĄZAŃ</button>
  2021. </div>
  2022. <div class="container smad-generate-reaport-info text-center">
  2023. <div class="step-title"><span class="bottom--count-selected-item-kontrahenci"></span></div>
  2024. <div class="step-title"><span class="bottom--count-selected-item-pracownicy"></span></div>
  2025. <div><strong><span class="bottom--message-warning-critical-search"></span></strong></div>
  2026. </div>
  2027. </div>
  2028. </div>
  2029. <!-- end:bottom generate reaport -->
  2030. ';
  2031. return $view;
  2032. }
  2033. public function showListDataByType($items, $type='PRACOWNICY', $labels) {
  2034. switch ($type) {
  2035. case 'PRACOWNICY':
  2036. return $this->showTablePracownicy($labels);
  2037. break;
  2038. case 'KONTRAHENCI':
  2039. return $this->showTableKontrahenci($labels);
  2040. break;
  2041. }
  2042. }
  2043. function fetchProgressAjaxAction() {
  2044. Response::sendTryCatchJson(array($this, 'fetchProgressAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  2045. }
  2046. function fetchProgressAjax($args) {
  2047. $DBG_FAKE_ANIM = false;
  2048. if (empty($args['ids'])) return [ 'msg' => "empty ids", 'type' => "success" ];
  2049. $ids = $args['ids'];
  2050. // private static function getDirectory($table, $id) {
  2051. $firstId = reset($ids);
  2052. {
  2053. Lib::loadClass('FoldersConfig');
  2054. $folderConf = FoldersConfig::getAll('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_COLUMN');
  2055. if (!isset($folderConf['mount_point'])) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$errMsg}", 404);
  2056. $rootPath = $folderConf['mount_point'];
  2057. }
  2058. $statuses = array_map(function ($id) {
  2059. return DB::getPDO()->fetchValue(" select FILE_STATUS from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  2060. }, $ids);
  2061. $statusesInfo = array_map(function ($id) {
  2062. return DB::getPDO()->fetchValue(" select FILE_STATUS_info from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  2063. }, $ids);
  2064. $progress = array_map(function ($id, $idx) use ($rootPath, $statuses, $DBG_FAKE_ANIM) {
  2065. DBG::log("Loop id({$id}) is-eq-82(".(82 == $id).") is-eq-'82'(".("82"==$id).")");
  2066. DBG::log("Loop id({$id}) is-eq-80(".(80 == $id).") is-eq-'80'(".("80"==$id).")");
  2067. $status = $statuses[$idx];
  2068. if ($DBG_FAKE_ANIM && 82 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2069. if ($DBG_FAKE_ANIM && 80 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2070. if ($DBG_FAKE_ANIM && 77 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2071. DBG::log("Loop id({$id}) status({$status})...");
  2072. if ('GENERATED' === $status) return 1;
  2073. if ('IN_PROGRESS' !== $status) return 0;
  2074. if (!file_exists("{$rootPath}/.tasks/generatePowiazania-{$id}.progress")) return 0;
  2075. DBG::log("Loop id({$id}) status({$status}) progress file exists");
  2076. try {
  2077. $cnt = file_get_contents("{$rootPath}/.tasks/generatePowiazania-{$id}.progress");
  2078. $json = @json_decode($cnt, $assoc = true);
  2079. if (null === $json && 0 !== json_last_error()) {
  2080. throw new Exception("Parse json error for restrictions: " . json_last_error());
  2081. }
  2082. // $json['summary']['step']: 'initialize', 'relations', 'reports'
  2083. // $json['summary']['step'] = 'initialize' - recache - skip
  2084. // $json['summary']['step'] = 'relations' - szuka powiązań (@see AVG(details.progress / summary.count))
  2085. // $json['summary']['step'] = 'reports' - generuje pliki (@see summary.created)
  2086. /*
  2087. if ($DBG_FAKE_ANIM && 82 == $id) { // TODO: DBG
  2088. $json = [
  2089. 'summary' => [
  2090. 'count' => 4,
  2091. 'step' => 'relations',
  2092. ],
  2093. 'details' => [
  2094. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2095. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2096. '22' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2097. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2098. ] ];
  2099. }
  2100. */
  2101. if ($DBG_FAKE_ANIM && 80 == $id) { // TODO: DBG
  2102. $json = [
  2103. 'summary' => [
  2104. 'count' => 4,
  2105. 'created' => 2,
  2106. 'step' => 'reports',
  2107. ],
  2108. 'details' => [
  2109. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2110. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2111. '22' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2112. '25' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2113. ] ];
  2114. }
  2115. if ($DBG_FAKE_ANIM && 77 == $id) { // TODO: DBG
  2116. $json = [
  2117. 'summary' => [
  2118. 'count' => 4,
  2119. 'created' => 2,
  2120. 'step' => 'relations',
  2121. ],
  2122. 'details' => [
  2123. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2124. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2125. '22' => [ 'progress' => 0.25, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2126. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2127. ] ];
  2128. }
  2129. DBG::log($json, 'array', "Loop id({$id}) status({$status}) progress json");
  2130. if (empty($json['summary'])) return 0;
  2131. if (empty($json['summary']['count'])) return 0;
  2132. if (empty($json['summary']['step'])) return 0;
  2133. if (empty($json['details'])) return 0;
  2134. $listDetailsProgress = array_map(function ($detail) {
  2135. return floatval($detail['progress']);
  2136. }, $json['details']);
  2137. $relationsProgress = $json['summary']['count'] > 0 ? round(floatval(array_sum($listDetailsProgress)) / floatval($json['summary']['count']), 3) : 0;
  2138. $reportsCount = V::get('reportsCount', 0, $json['summary'], 'float');
  2139. $reportsProgress = $reportsCount > 0 ? round(V::get('reportsCreated', 0, $json['summary'], 'float') / $reportsCount, 3) : 0;
  2140. return round(0.5 * $relationsProgress + 0.5 * $reportsProgress, 3);
  2141. } catch (Exception $e) {
  2142. DBG::log($e);
  2143. }
  2144. return 0;
  2145. }, $ids, array_keys($ids));
  2146. return [ 'msg' => "DBG ids set", 'type' => "success", 'body' => [
  2147. 'ids' => $ids,
  2148. 'progress' => $progress,
  2149. 'statuses' => $statuses,
  2150. 'statusesInfo' => $statusesInfo,
  2151. ] ];
  2152. }
  2153. }