Bocian.php 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051
  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_DB' => $this->getLink('saveToPracownicyAjax'),
  200. 'DBG' => V::get('DBG', 0, $_GET),
  201. 'FUNCTION_NAME' => "createPracownikAjax",
  202. ]);
  203. UI::inlineJS(__FILE__ . '.addItemToRaport.js', [
  204. 'URL_FETCH_FROM_BAZA' => $this->getLink('fetchFromBazaAjax'),
  205. 'URL_SAVE_TO_DB' =>$this->getLink('saveToKontrahenciAjax'),
  206. 'DBG' => V::get('DBG', 0, $_GET),
  207. 'FUNCTION_NAME' => "createKontrahentAjax",
  208. ]);
  209. UI::inlineJS(__FILE__ . '.graphShowHide.js', [
  210. 'DBG' => V::get('DBG', 0, $_GET),
  211. 'FIELD_LIST_PRACOWNICY' => array_merge(
  212. array_map(function ($fieldName) {
  213. return "f_{$fieldName}";
  214. }, self::$FIELD_LIST_PRACOWNICY),
  215. [
  216. 'f_Adresy',
  217. ]
  218. ),
  219. 'FIELD_LIST_KONTRAHENCI' => array_map(function ($fieldName) {
  220. return "f_{$fieldName}";
  221. }, self::$FIELD_LIST_KONTRAHENCI),
  222. ]);
  223. echo '</div>'; // #smad-wrapper
  224. UI::dol();
  225. }
  226. public function saveToPracownicyAjaxAction() {
  227. Response::sendTryCatchJson(array($this, 'saveToPracownicyAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  228. }
  229. public function saveToPracownicyAjax($args) {
  230. DBG::log($args, 'array', "saveToPracownicyAjax args");
  231. $baza = V::get('baza', '', $args);
  232. $item = V::get('item', [], $args);
  233. if (empty($item)) throw new Exception("Brak danych do zapisania");
  234. switch ($baza) {
  235. case 'default_db/BI_audit_KRS/BI_audit_KRS': return $this->saveKRSToPracownicyAjax($item);
  236. case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return $this->saveKRSPersonToPracownicyAjax($item);
  237. case 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI': return $this->saveKonrahentToPracownicyAjax($item);
  238. case 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY': return $this->savePracownikToPracownicyAjax($item);
  239. case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return $this->saveMSIGToPracownicyAjax($item);
  240. case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return $this->saveMSIGPersonToPracownicyAjax($item);
  241. case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return $this->saveCEIDGToPracownicyAjax($item);
  242. }
  243. }
  244. // "@primaryKey": "161323",
  245. // "A_kod": "80-299",
  246. // "A_kraj": "POLSKA",
  247. // "A_miejscowosc": "GDAŃSK",
  248. // "A_nrDomu": "54C",
  249. // "A_nrLokalu": null,
  250. // "A_poczta": "GDAŃSK",
  251. // "A_ulica": "BARNIEWICKA",
  252. // "ID": "161323",
  253. // "S_kraj": "POLSKA",
  254. // "S_miejscowosc": "GDAŃSK",
  255. // "S_wojewodztwo": "POMORSKIE",
  256. // "krs": "0000223476",
  257. // "nazwa": "BIALL Sp. z o.o.",
  258. // "nip": "6040018535",
  259. // "regon": "193106935",
  260. function saveKRSToPracownicyAjax($item) {
  261. $companyName = V::get('nazwa', '', $item);
  262. $companyNip = V::get('nip', '', $item);
  263. $comapanyRegon = V::get('regon', '', $item);
  264. $comapanyKrs = V::get('krs', '', $item);
  265. // validate
  266. if (!$companyName) throw new Exception("Nie podano nazwy");
  267. if (!$companyNip) throw new Exception("Nie podano nip");
  268. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  269. 'imiona' => $companyName,
  270. 'nip' => ($companyNip) ? $companyNip : NULL,
  271. 'regon' => ($comapanyRegon) ? $comapanyRegon : NULL,
  272. 'krs' => ($comapanyKrs) ? $comapanyKrs : NULL,
  273. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  274. 'A_RECORD_CREATE_DATE' => 'NOW()',
  275. ]);
  276. return [
  277. 'msg' => "Dodano podmiot",
  278. 'type' => "success",
  279. ];
  280. }
  281. function saveMSIGToPracownicyAjax($item) {
  282. $companyName = V::get('nazwa', '', $item);
  283. $companyNip = V::get('nip', '', $item);
  284. $comapanyRegon = V::get('regon', '', $item);
  285. $comapanyKrs = V::get('krs', '', $item);
  286. // validate
  287. if (!$companyName) throw new Exception("Nie podano nazwy");
  288. if (!$companyNip) throw new Exception("Nie podano nip");
  289. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  290. 'imiona' => $companyName,
  291. 'nip' => ($companyNip) ? $companyNip : NULL,
  292. 'regon' => ($comapanyRegon) ? $comapanyRegon : NULL,
  293. 'krs' => ($comapanyKrs) ? $comapanyKrs : NULL,
  294. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  295. 'A_RECORD_CREATE_DATE' => 'NOW()',
  296. ]);
  297. return [
  298. 'msg' => "Dodano podmiot",
  299. 'type' => "success",
  300. ];
  301. }
  302. function saveKRSPersonToPracownicyAjax($item) {
  303. $personName = V::get('imiona', '', $item);
  304. $personSurname = V::get('nazwisko', '', $item);
  305. $personPesel = V::get('pesel', '', $item);
  306. // validate
  307. if (!$personName) throw new Exception("Nie podano imienia");
  308. if (!$personSurname) throw new Exception("Nie podano nazwiska");
  309. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  310. 'imiona' => $personName,
  311. 'nazwisko' => $personSurname,
  312. 'pesel' => ($personPesel) ? $personPesel : NULL,
  313. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  314. 'A_RECORD_CREATE_DATE' => 'NOW()',
  315. ]);
  316. return [
  317. 'msg' => "Dodano osobę",
  318. 'type' => "success",
  319. ];
  320. }
  321. function saveMSIGPersonToPracownicyAjax($item) {
  322. $personName = V::get('imiona', '', $item);
  323. $personSurname = V::get('nazwisko', '', $item);
  324. $personPesel = V::get('pesel', '', $item);
  325. // validate
  326. if (!$personName) throw new Exception("Nie podano imienia");
  327. if (!$personSurname) throw new Exception("Nie podano nazwiska");
  328. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  329. 'imiona' => $personName,
  330. 'nazwisko' => $personSurname,
  331. 'pesel' => ($personPesel) ? $personPesel : NULL,
  332. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  333. 'A_RECORD_CREATE_DATE' => 'NOW()',
  334. ]);
  335. return [
  336. 'msg' => "Dodano osobę",
  337. 'type' => "success",
  338. ];
  339. }
  340. function saveCEIDGPersonToPracownicyAjax($item) {
  341. $personName = V::get('imiona', '', $item);
  342. $personSurname = V::get('nazwisko', '', $item);
  343. $personNip = V::get('nip', '', $item);
  344. $personRegon = V::get('regon', '', $item);
  345. // validate
  346. if (!$personName) throw new Exception("Nie podano imienia");
  347. if (!$personSurname) throw new Exception("Nie podano nazwiska");
  348. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  349. 'imie' => $personName,
  350. 'nazwisko' => $personSurname,
  351. 'regon' => ($personRegon) ? $personRegon : NULL,
  352. 'nip' => ($personNip) ? $personNip : NULL,
  353. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  354. 'A_RECORD_CREATE_DATE' => 'NOW()',
  355. ]);
  356. return [
  357. 'msg' => "Dodano osobę",
  358. 'type' => "success",
  359. ];
  360. }
  361. function saveKonrahentToPracownicyAjax($item) {
  362. // companyName: document.getElementById('companyName').value,
  363. // companyNip: document.getElementById('companyNip').value,
  364. // comapanyRegon: document.getElementById('comapanyRegon').value,
  365. $companyName = V::get('companyName', '', $item);
  366. $companyNip = V::get('companyNip', '', $item);
  367. $comapanyRegon = V::get('comapanyRegon', '', $item);
  368. // validate
  369. if (!$companyName) throw new Exception("Nie wpisano nazwy");
  370. if (!$companyNip) throw new Exception("Nie wpisano nip");
  371. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  372. 'imiona' => $companyName,
  373. 'nip' => ($companyNip) ? $companyNip : NULL,
  374. 'regon' => ($comapanyRegon) ? $comapanyRegon : NULL,
  375. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  376. 'A_RECORD_CREATE_DATE' => 'NOW()',
  377. ]);
  378. return [
  379. 'msg' => "Dodano podmiot",
  380. 'type' => "success",
  381. ];
  382. }
  383. function savePracownikToPracownicyAjax($item) {
  384. $personName = V::get('personName', '', $item);
  385. $personSurname = V::get('personSurname', '', $item);
  386. $personNip = V::get('personNip', '', $item);
  387. $personPesel = V::get('personPesel', '', $item);
  388. // validate
  389. if (!$personName) throw new Exception("Nie wpisano imienia");
  390. if (!$personSurname) throw new Exception("Nie wpisano nazwiska");
  391. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  392. 'imiona' => $personName,
  393. 'nazwisko' => $personSurname,
  394. 'nip' => ($personNip) ? $personNip : NULL,
  395. 'pesel' => ($personPesel) ? $personPesel : NULL,
  396. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  397. 'A_RECORD_CREATE_DATE' => 'NOW()',
  398. ]);
  399. return [
  400. 'msg' => "Dodano osobę",
  401. 'type' => "success",
  402. ];
  403. }
  404. public function saveToKontahenciAjaxAction() {
  405. Response::sendTryCatchJson(array($this, 'saveToKontahenciAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  406. }
  407. public function saveToKontahenciAjax($args) {
  408. DBG::log($args, 'array', "saveToKontahenciAjaxActionAjax args");
  409. $baza = V::get('baza', '', $args);
  410. $item = V::get('item', [], $args);
  411. if (empty($item)) throw new Exception("Brak danych do zapisania");
  412. switch ($baza) {
  413. case 'default_db/BI_audit_KRS/BI_audit_KRS': return $this->saveKRSToKontrahenciAjax($item);
  414. case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return $this->saveKRSPersonToKontrahenciAjax($item);
  415. case 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI': return $this->saveKonrahentToKontrahenciAjax($item);
  416. case 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY': return $this->savePracownikToKontrahenciAjax($item);
  417. case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return $this->saveMSIGToKontrahenciAjax($item);
  418. case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return $this->saveMSIGPersonToKontrahenciAjax($item);
  419. case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return $this->saveCEIDGToKontrahenciAjax($item);
  420. }
  421. }
  422. function saveKRSToKontrahenciAjax($item) {
  423. $companyName = V::get('nazwa', '', $item);
  424. $companyNip = V::get('nip', '', $item);
  425. $comapanyRegon = V::get('regon', '', $item);
  426. $comapanyKrs = V::get('krs', '', $item);
  427. // validate
  428. if (!$companyName) throw new Exception("Nie podano nazwy");
  429. if (!$companyNip) throw new Exception("Nie podano nip");
  430. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  431. 'Pelna_nazwa_kontrahenta' => $companyName,
  432. 'NIP' => ($companyNip) ? $companyNip : NULL,
  433. 'REGON' => ($comapanyRegon) ? $comapanyRegon : NULL,
  434. 'KRS' => ($comapanyKrs) ? $comapanyKrs : NULL,
  435. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  436. 'A_RECORD_CREATE_DATE' => 'NOW()',
  437. ]);
  438. return [
  439. 'msg' => "Dodano podmiot",
  440. 'type' => "success",
  441. ];
  442. }
  443. function saveMSIGToKontrahenciAjax($item) {
  444. $companyName = V::get('nazwa', '', $item);
  445. $companyNip = V::get('nip', '', $item);
  446. $comapanyRegon = V::get('regon', '', $item);
  447. $comapanyKrs = V::get('krs', '', $item);
  448. // validate
  449. if (!$companyName) throw new Exception("Nie podano nazwy");
  450. if (!$companyNip) throw new Exception("Nie podano nip");
  451. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  452. 'Pelna_nazwa_kontrahenta' => $companyName,
  453. 'NIP' => ($companyNip) ? $companyNip : NULL,
  454. 'REGON' => ($comapanyRegon) ? $comapanyRegon : NULL,
  455. 'KRS' => ($comapanyKrs) ? $comapanyKrs : NULL,
  456. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  457. 'A_RECORD_CREATE_DATE' => 'NOW()',
  458. ]);
  459. return [
  460. 'msg' => "Dodano podmiot",
  461. 'type' => "success",
  462. ];
  463. }
  464. function saveCEIDGToKontrahenciAjax($item) {
  465. $personFirstName = V::get('imie', '', $item);
  466. $personLastName = V::get('nazwisko', '', $item);
  467. $personNip = V::get('nip', '', $item);
  468. $personRegon = V::get('regon', '', $item);
  469. // validate
  470. if (!$personFirstName) throw new Exception("Nie podano nazwy");
  471. if (!$personNip) throw new Exception("Nie podano nip");
  472. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  473. 'Pelna_nazwa_kontrahenta' => $personFirstName,
  474. 'Skrocona_Nazwa_Kontrahenta' => $personFirstName,
  475. 'NIP' => ($personNip) ? $personNip : NULL,
  476. 'REGON' => ($personRegon) ? $personRegon : NULL,
  477. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  478. 'A_RECORD_CREATE_DATE' => 'NOW()',
  479. ]);
  480. return [
  481. 'msg' => "Dodano podmiot",
  482. 'type' => "success",
  483. ];
  484. }
  485. function saveKRSPersonToKontrahenciAjax($item) {
  486. $personName = V::get('imiona', '', $item);
  487. $personSurname = V::get('nazwisko', '', $item);
  488. $personPesel = V::get('pesel', '', $item);
  489. // validate
  490. if (!$personName) throw new Exception("Nie podano imienia");
  491. if (!$personSurname) throw new Exception("Nie podano nazwiska");
  492. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  493. 'Skrocona_Nazwa_Kontrahenta' => $personName,
  494. 'Pelna_nazwa_kontrahenta' => $personSurname,
  495. 'PESEL' => ($personPesel) ? $personPesel : NULL,
  496. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  497. 'A_RECORD_CREATE_DATE' => 'NOW()',
  498. ]);
  499. return [
  500. 'msg' => "Dodano osobę",
  501. 'type' => "success",
  502. ];
  503. }
  504. function saveMSIGPersonToKontrahenciAjax($item) {
  505. $personName = V::get('imiona', '', $item);
  506. $personSurname = V::get('nazwisko', '', $item);
  507. $personPesel = V::get('pesel', '', $item);
  508. // validate
  509. if (!$personName) throw new Exception("Nie podano imienia");
  510. if (!$personSurname) throw new Exception("Nie podano nazwiska");
  511. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  512. 'Skrocona_Nazwa_Kontrahenta' => $personName,
  513. 'Pelna_nazwa_kontrahenta' => $personSurname,
  514. 'PESEL' => ($personPesel) ? $personPesel : NULL,
  515. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  516. 'A_RECORD_CREATE_DATE' => 'NOW()',
  517. ]);
  518. return [
  519. 'msg' => "Dodano osobę",
  520. 'type' => "success",
  521. ];
  522. }
  523. function saveKonrahentToKontrahenciAjax($item) {
  524. // companyName: document.getElementById('companyName').value,
  525. // companyNip: document.getElementById('companyNip').value,
  526. // comapanyRegon: document.getElementById('comapanyRegon').value,
  527. $companyName = V::get('companyName', '', $item);
  528. $companyNip = V::get('companyNip', '', $item);
  529. $comapanyRegon = V::get('comapanyRegon', '', $item);
  530. // validate
  531. if (!$companyName) throw new Exception("Nie wpisano nazwy");
  532. if (!$companyNip) throw new Exception("Nie wpisano nip");
  533. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  534. 'Pelna_nazwa_kontrahenta' => $companyName,
  535. 'NIP' => ($companyNip) ? $companyNip : NULL,
  536. 'REGON' => ($comapanyRegon) ? $comapanyRegon : NULL,
  537. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  538. 'A_RECORD_CREATE_DATE' => 'NOW()',
  539. ]);
  540. return [
  541. 'msg' => "Dodano podmiot",
  542. 'type' => "success",
  543. ];
  544. }
  545. function savePracownikToKontrahenciAjax($item) {
  546. $personName = V::get('personName', '', $item);
  547. $personSurname = V::get('personSurname', '', $item);
  548. $personNip = V::get('personNip', '', $item);
  549. $personPesel = V::get('personPesel', '', $item);
  550. // validate
  551. if (!$personName) throw new Exception("Nie wpisano imienia");
  552. if (!$personSurname) throw new Exception("Nie wpisano nazwiska");
  553. $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  554. 'Skrocona_Nazwa_Kontrahenta' => $personName,
  555. 'Pelna_nazwa_kontrahenta' => $personSurname,
  556. 'NIP' => ($personNip) ? $personNip : NULL,
  557. 'PESEL' => ($personPesel) ? $personPesel : NULL,
  558. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  559. 'A_RECORD_CREATE_DATE' => 'NOW()',
  560. ]);
  561. return [
  562. 'msg' => "Dodano osobę",
  563. 'type' => "success",
  564. ];
  565. }
  566. /**
  567. * Dodanie nowego pracownika
  568. */
  569. public function createPracownikAjaxAction() {
  570. 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
  571. }
  572. public function createPracownikAjax($args) {
  573. DBG::log($args, 'array', "args");
  574. $personName = V::get('personName', '', $args);
  575. $personSurname = V::get('personSurname', '', $args);
  576. $personNip = V::get('personNip', '', $args);
  577. $personPesel = V::get('personPesel', '', $args);
  578. $personRegon = V::get('personRegon', '', $args);
  579. // validate
  580. if (!$personName) throw new Exception("Nie wpisano imienia");
  581. if (!$personSurname) throw new Exception("Nie wpisano nazwiska");
  582. $idPracownik = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
  583. 'imiona' => $personName,
  584. 'nazwisko' => $personSurname,
  585. 'nip' => ($personNip) ? $personNip : NULL,
  586. 'pesel' => ($personPesel) ? $personPesel : NULL,
  587. 'regon' => ($personRegon) ? $personRegon : NULL,
  588. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  589. 'A_RECORD_CREATE_DATE' => 'NOW()',
  590. ]);
  591. return [
  592. 'msg' => "Dodano osobę",
  593. 'type' => "success",
  594. ];
  595. }
  596. /**
  597. * Dodanie nowego kontrahenta
  598. */
  599. public function createKontrahentAjaxAction() {
  600. 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
  601. }
  602. public function createKontrahentAjax($args) {
  603. $companyFullName = V::get('companyFullName', '', $args);
  604. $companyShortName = V::get('$companyShortName', '', $args);
  605. $companyNameGroup = V::get('companyNameGroup', '', $args);
  606. $companyKrs = V::get('companyKrs', '', $args);
  607. $companyNip = V::get('companyNip', '', $args);
  608. $companyPesel = V::get('companyPesel', '', $args);
  609. $companyFax = V::get('companyFax', '', $args);
  610. $companyTelefon = V::get('companyTelefon', '', $args);
  611. $companyMail = V::get('companyMail', '', $args);
  612. $companyStreet = V::get('companyStreet', '', $args);
  613. $companyNumberBuilding = V::get('companyNumberBuilding', '', $args);
  614. $companyNumberLocal = V::get('companyNumberLocal', '', $args);
  615. $companyPostCode = V::get('companyPostCode', '', $args);
  616. $companyPlace = V::get('companyPlace', '', $args);
  617. $companyCountry = V::get('companyCountry', '', $args);
  618. $companyTypeCompany = V::get('companyTypeCompany', '', $args);
  619. $companyTitleDocument = V::get('companyTitleDocument', '', $args);
  620. $companyDesc = V::get('companyDesc', '', $args);
  621. // validate
  622. if (!$companyFullName) throw new Exception("Nie wpisano pełnej nazwy kontrahenta");
  623. $idKontrahent = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
  624. 'Pelna_nazwa_kontrahenta' => $companyFullName,
  625. 'Skrocona_Nazwa_Kontrahenta' => ($companyShortName) ? $companyShortName : null,
  626. 'Nazwa_grupy_kapitalowej' => ($companyNameGroup) ? $companyNameGroup : null,
  627. 'KRS' => ($companyKrs) ? $companyKrs : null,
  628. 'NIP' => ($companyNip) ? $companyNip : null,
  629. 'PESEL' => ($companyPesel) ? $companyPesel : null,
  630. 'Fax' => ($companyFax) ? $companyFax : null,
  631. 'Telefon' => ($companyTelefon) ? $companyTelefon : null,
  632. 'Mail' => ($companyMail) ? $companyMail : null,
  633. 'Ulica' => ($companyStreet) ? $companyStreet : null,
  634. 'Numer_budynku' => ($companyNumberBuilding) ? $companyNumberBuilding : null,
  635. 'Numer_mieszkania_lokalu' => ($companyNumberLocal) ? $companyNumberLocal : null,
  636. 'Kod_pocztowy' => ($companyPostCode) ? $companyPostCode : null,
  637. 'Miejscowosc' => ($companyPlace) ? $companyPlace : null,
  638. 'Kraj' => ($companyCountry) ? $companyCountry : null,
  639. 'Typ_kontrahenta' => ($companyTypeCompany) ? $companyTypeCompany : null,
  640. 'Tytul_dokumentu' => ($companyTitleDocument) ? $companyTitleDocument : null,
  641. 'uwagi' => ($companyDesc) ? $companyDesc : null,
  642. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  643. 'A_RECORD_CREATE_DATE' => 'NOW()',
  644. ]);
  645. return [
  646. 'msg' => "Dodano podmiot/kontrahenta",
  647. 'type' => "success",
  648. ];
  649. }
  650. /**
  651. * Funkcja ajax do odebrania danych z przesłanego pliku CSV do parsowania
  652. */
  653. public function formDataCsvFileAjaxAction() {
  654. Response::sendTryCatchJson(array($this, 'formDataCsvFileAjax'));
  655. }
  656. /**
  657. * Funkcja parsuje dane wgrywanego plku csv i zwraca dane w inputach
  658. */
  659. public function formDataCsvFileAjax() {
  660. if (!file_exists($_FILES['file']['tmp_name'])) throw new Exception("Wybierz plik do przesłania.");
  661. $file = file($_FILES['file']['tmp_name']);
  662. //$showCheckbox = V::get('showCheckbox', '', $args);
  663. $showCheckbox = V::get('showCheckbox', 0, $_REQUEST, 'string');
  664. // parsujemy csv to tablicy
  665. $arrayDataCsv = $this->csvToArray($file, ';', '"', '\n\r');
  666. $i = 0;
  667. // tworzymy rekordy
  668. foreach ( $arrayDataCsv as $line ) {
  669. $viewFormCol .= '<tr>';
  670. foreach ( $line as $keyData => $rowData ) {
  671. // utworzenie nagłówków tabeli
  672. if( $i == 0) { $header .= '<td style="min-width:160px">' . $keyData . '</td>'; }
  673. // utworzenie inputa do edycji
  674. $viewFormCol .= '<td style="min-width:160px"><input type="text" name="item['.$i.']['.$keyData.']" value="'.$rowData .'" class="form-control input-lg" /></td>';
  675. }
  676. $viewFormCol .= '</tr>';
  677. $i++;
  678. }
  679. // pokaz checkbox jeśli ma status showCheckbox
  680. if ( $showCheckbox == 'yes' ) {
  681. $viewFormCol .= '<div style="margin: 10px 0"><input type="checkbox" name="override" value="1" /> Nadpisz wszystkie rekordy w bazie danych</div';
  682. }
  683. $viewFormHtml = '<div id="smad-window-modal" style="overflow-x: scroll;">
  684. <div class="table-responsive padding-0" >
  685. <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>
  686. </div>';
  687. //return $viewFormHtml;
  688. return [
  689. 'type' => 'success',
  690. 'msg' => 'OK',
  691. '__req_args' => $_REQUEST,
  692. '__args' => $args,
  693. 'body' => [
  694. 'view' => $viewFormHtml,
  695. ]
  696. ];
  697. }
  698. /**
  699. * Funkcja ajax do odebrania danych z przesłanego formularza z parsowanego CSV
  700. */
  701. public function saveFormCsvFileAjaxAction() {
  702. Response::sendTryCatchJson(array($this, 'saveFormCsvFileAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  703. //Response::sendTryCatchJson(array($this, 'saveFormCsvFileAjax'));
  704. }
  705. /**
  706. * Funkcja ajax do zapisania danych z przesłanego formularza z parsowanego CSV
  707. */
  708. public function saveFormCsvFileAjax($args) {
  709. //dane z formularza
  710. $formData = V::get('formData', '', $args);
  711. $enumType = V::get('enumType', '', $args);
  712. $override = false; // false - nie nadpisujemy danych
  713. $arrayInfo = array();
  714. $arrayInfo['insert'] = 0;
  715. $arrayInfo['update'] = 0;
  716. $arrayInfo['error'] = 0;
  717. // pobranie nazwy tabeli z db
  718. $table = $this->getNameTableByEnum( strtoupper($enumType) );
  719. if ( $table == null ) throw new Exception('Błąd zapisu. Tabela w db nie istnieje');
  720. // unserialize data from serialize in javascript
  721. parse_str($formData, $resultArrayFormdata);
  722. if ( count($resultArrayFormdata['item']) == 0) {
  723. throw new Exception("Wystapił problem podczas przesyłania danych - brak przesłanych danych.");
  724. }
  725. // ustawienie true jeśli wyrabno nadpisanie danych
  726. if ( isset($resultArrayFormdata['override']) ) { $override = true; } // aktualizuj rekordy/nadpisz istniejace
  727. // dodanie/aktualizacjia wpisu
  728. foreach ( $resultArrayFormdata['item'] as $line ) {
  729. $response = $this->saveDataToDb($table, $line, $override);
  730. // tworzymy listę informacji o liczbie nowych/zaktualizowanych/z błedami rekordów
  731. $arrayInfo = $this->responseCountListInfoAboutSaveData($response, $arrayInfo);
  732. }
  733. // utworzenie komunikatów
  734. if ( isset($arrayInfo['insert']) ) { $textInsert = "Liczba nowych rekordów: (" . $arrayInfo['insert'] . ");"; }
  735. if ( isset($arrayInfo['error']) ) { $textError = "Liczba nie zapisanych rekordów (" . $arrayInfo['insert'] . ");"; }
  736. return [
  737. 'msg' => "Zapisano dane. " . $textInsert . " " . $textError ,
  738. 'type' => "success",
  739. ];
  740. }
  741. /**
  742. * Count list
  743. */
  744. public function responseCountListInfoAboutSaveData($response, $arrayInfo) {
  745. if (!is_array($response)) throw new Exception('Wystapił bład podczas zapisu danych');
  746. $countData = array();
  747. switch(key($response)) {
  748. case 'insert':
  749. $countData['insert'] = $arrayInfo['insert'] + 1;
  750. break;
  751. case 'error':
  752. $countData['error'] = $arrayInfo['insert'] + 1;
  753. break;
  754. }
  755. return $countData;
  756. }
  757. /**
  758. * Function parse csv to array
  759. * @param $filename - file data from FILE
  760. * @param $delimiter - delimiter
  761. * @param $enclosure -
  762. * @param $escape -
  763. */
  764. function csvToArray($filedata , $delimiter=';', $enclosure='"', $escape = '\\') {
  765. if(!$filedata || empty($filedata)) return false;
  766. $header = null;
  767. $data = array();
  768. foreach( $filedata as $line) {
  769. $values = str_getcsv( $line, $delimiter, $enclosure, $escape );
  770. if(!$header) $header = $values;
  771. else $data[] = array_combine( $header, $values );
  772. }
  773. return $data;
  774. }
  775. /**
  776. * Save data in database
  777. */
  778. public function saveDataToDb( $table, $arrayData, $override = false ) {
  779. $response = array();
  780. try {
  781. if ($override) {
  782. DB::getPDO()->insertOrUpdate($table, array_merge($arrayData, [
  783. '@insert' => [
  784. 'A_RECORD_CREATE_DATE' => 'NOW()',
  785. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  786. ],
  787. '@update' => array_merge($arrayData, [
  788. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  789. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  790. ]),
  791. ]));
  792. } else {
  793. $responseInsert = DB::getPDO()->insert($table, array_merge($arrayData, [
  794. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  795. 'A_RECORD_CREATE_DATE' => 'NOW()',
  796. ]));
  797. }
  798. $response['insert'] = 1;
  799. } catch (Exception $e) {
  800. DBG::log($e);
  801. $response['error'] = 1;
  802. }
  803. return $response;
  804. }
  805. /**
  806. * Get name table by enum
  807. */
  808. public function getNameTableByEnum($type) {
  809. $nameTable = null;
  810. switch ($type) {
  811. case 'KONTRAHENCI':
  812. $nameTable = 'BI_audit_ENERGA_RUM_KONTRAHENCI';
  813. break;
  814. case 'PRACOWNICY':
  815. $nameTable = 'BI_audit_ENERGA_PRACOWNICY';
  816. break;
  817. }
  818. return $nameTable;
  819. }
  820. public function fetchEnergaRumKontrahenciPowiazaniaAjaxAction() {
  821. Response::sendTryCatchJson(array($this, 'fetchEnergaRumKontrahenciPowiazaniaAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  822. }
  823. public function fetchEnergaRumKontrahenciPowiazaniaAjax($args) {
  824. $id = V::get('ID', 26, $_REQUEST, 'int');
  825. $items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA')->buildQuery([
  826. 'cols' => [ // TODO:? propertyName = []
  827. 'ID',
  828. 'A_ADM_COMPANY',
  829. 'L_APPOITMENT_USER',
  830. 'A_CLASSIFIED',
  831. 'A_STATUS',
  832. 'A_STATUS_INFO',
  833. 'BI_analiza_maxDepth',
  834. 'BI_analiza_minDepth',
  835. 'BI_analiza_onlyTargets',
  836. 'BI_analiza_reloadCache',
  837. 'FILE_STATUS',
  838. 'FILE_STATUS_info',
  839. 'L_APPOITMENT_USER',
  840. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  841. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  842. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
  843. 'default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person',
  844. ],
  845. 'f_ID' => "{$id}",
  846. ])->getItems([
  847. 'limit' => 10
  848. ]);
  849. // $items = [
  850. // [ 'ID' => 1, 'L_APPOITMENT_INFO' => 'x', 'BI_analiza_depth' => 'a', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test1'],
  851. // [ 'ID' => 2, 'L_APPOITMENT_INFO' => 'y', 'BI_analiza_depth' => 'b', 'FILE_STATUS' => 0, 'FILE_STATUS_info' => 'test2'],
  852. // [ 'ID' => 3, 'L_APPOITMENT_INFO' => 'z', 'BI_analiza_depth' => 'c', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test3'],
  853. // ];
  854. return [
  855. 'type' => 'success',
  856. 'msg' => 'OK',
  857. '__req_args' => $_REQUEST,
  858. '__args' => $args,
  859. 'body' => [
  860. 'items' => $items,
  861. 'view' => $this->showPowiazaniaEnergaRumKontrahenciPowiazania($items),
  862. ]
  863. ];
  864. }
  865. public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
  866. $view = '<form class="form-horizontal" method="post">
  867. <table class="table table-bordered table-hover table-striped" height=5>
  868. <thead>
  869. <tr style="">
  870. <td width=1><input type="checkbox" name="checkAll" id="checkAll" /></td>
  871. <td width=1>ID</td>
  872. <td>Adnotacje</td>
  873. <td>Głębokość analizy</td>
  874. <td>Status raportu</td>
  875. <td>Status raportu - informacje</td>
  876. </tr>
  877. </thead>
  878. <tbody>
  879. ';
  880. foreach ($items as $key => $row) {
  881. $view .= '<tr>
  882. <td><input type="checkbox" name="prID[]" value="'.$row['ID'].'" onClick="checkAll()"/></td>
  883. <td align="right">'.$row["ID"].'</td>
  884. <td align="right">'.$row["L_APPOITMENT_INFO"].'</td>
  885. <td align="right">'.$row["BI_analiza_depth"].'</td>
  886. <td align="right">'.$row["FILE_STATUS"].'</td>
  887. <td align="right">'.$row["FILE_STATUS_info"].'</td>';
  888. }
  889. $view .= '</tbody></table></form>';
  890. return $view;
  891. }
  892. public function fetchTestKrsAjaxAction() {
  893. Response::sendTryCatchJson(array($this, 'fetchTestKrsAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  894. }
  895. public function fetchTestKrsAjax($args) {
  896. $id = V::get('ID', 1, $_REQUEST, 'int');
  897. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery([
  898. 'cols' => [ // TODO:? propertyName = []
  899. 'A_kod',
  900. 'A_kraj',
  901. 'A_miejscowosc',
  902. 'A_nrDomu',
  903. 'A_nrLokalu',
  904. 'A_poczta',
  905. 'A_ulica',
  906. 'ID',
  907. 'S_gmina',
  908. 'S_kraj',
  909. 'S_miejscowosc',
  910. 'S_powiat',
  911. 'S_wojewodztwo',
  912. 'dataDokumentu',
  913. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  914. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  915. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  916. 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  917. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  918. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  919. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  920. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  921. 'krs',
  922. 'nazwa',
  923. 'nip',
  924. 'regon',
  925. ],
  926. 'f_ID' => "{$id}",
  927. ])->getItems([
  928. 'limit' => 10
  929. ]);
  930. return [
  931. 'type' => 'success',
  932. 'msg' => 'KRS',
  933. '__req_args' => $_REQUEST,
  934. '__args' => $args,
  935. 'body' => [
  936. 'items' => $items,
  937. ]
  938. ];
  939. }
  940. public function fetchTestCeidgAjaxAction() {
  941. Response::sendTryCatchJson(array($this, 'fetchTestCeidgAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
  942. }
  943. public function fetchTestCeidgAjax($args) {
  944. $id = V::get('ID', 0, $_REQUEST, 'int');
  945. $items = ACL::getAclByNamespace('default_db/BI_audit_CEIDG/BI_audit_CEIDG')->buildQuery([
  946. 'cols' => [ // TODO:? propertyName = []
  947. 'ID',
  948. 'budynek',
  949. 'firma',
  950. 'gmina',
  951. 'identyfikatorWpisu',
  952. 'imie',
  953. 'kodPocztowy',
  954. 'kraj',
  955. 'lokal',
  956. 'miejscowosc',
  957. 'nazwisko',
  958. 'nip',
  959. 'poczta',
  960. 'powiat',
  961. 'regon',
  962. 'ulica',
  963. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ID',
  964. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/budynek',
  965. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/gmina',
  966. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/kodPocztowy',
  967. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/lokal',
  968. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/miejscowosc',
  969. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nazwa',
  970. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nip',
  971. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/poczta',
  972. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/powiat',
  973. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ulica',
  974. 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/wojewodztwo',
  975. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/ID',
  976. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/nip',
  977. 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/regon',
  978. ],
  979. // 'f_ID' => $id,
  980. ])->getItems([
  981. 'limit' => 10
  982. ]);
  983. return [
  984. 'type' => 'success',
  985. 'msg' => 'CEIDG',
  986. '__req_args' => $_REQUEST,
  987. '__args' => $args,
  988. 'body' => [
  989. 'items' => $items,
  990. ]
  991. ];
  992. }
  993. public function fetchKontrahenciIdsAjaxAction() {
  994. Response::sendTryCatchJson(array($this, 'fetchKontrahenciIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  995. }
  996. public function fetchKontrahenciIdsAjax($args) {
  997. $idGroup = V::get('filter_idGroup', 0, $args, 'int');
  998. if ($idGroup < 0) $idGroup = 0;
  999. $backRefFilter = [];
  1000. if ($idGroup > 0) {
  1001. $backRefFilter['__backRef'] = [
  1002. 'namespace' => 'default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  1003. 'primaryKey' => $idGroup,
  1004. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  1005. ];
  1006. }
  1007. $searchParams = []; // TODO: ???
  1008. $filtersParams = [];
  1009. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1010. return ('f_' === substr($key, 0, 2));
  1011. });
  1012. foreach ($fieldFilterKeys as $key) {
  1013. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1014. }
  1015. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  1016. $query = $acl->buildQuery(array_merge([
  1017. 'cols' => [
  1018. 'ID',
  1019. ],
  1020. //'f_ID' => $id,
  1021. 'limit' => 0,
  1022. // 'limitstart' => $limitstart, // offset
  1023. // 'order_by' => 'ID', // sortowanie po kolumnie
  1024. // 'order_dir' => 'DESC', // kierunek sortowania
  1025. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1026. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1027. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1028. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1029. ], $searchParams, $filtersParams, $backRefFilter));
  1030. // $total = $query->getTotal();
  1031. $items = $query->getItems();
  1032. return [
  1033. 'type' => 'success',
  1034. 'msg' => 'kontrahenci ids',
  1035. 'body' => [
  1036. 'ids' => array_map( V::makePick('ID'), $items ),
  1037. ],
  1038. '__DBG_args' => $args,
  1039. '__DBG_$idGroup' => $idGroup,
  1040. '__DBG_$filtersParams' => $filtersParams,
  1041. '__DBG_$backRefFilter' => $backRefFilter,
  1042. ];
  1043. }
  1044. /**
  1045. * KONTRAHENCI
  1046. */
  1047. public function fetchKontrahenciAjaxAction() {
  1048. Response::sendTryCatchJson(array($this, 'fetchKontrahenciAjax'), $args = $_REQUEST);
  1049. }
  1050. public function fetchKontrahenciAjax($args) {
  1051. $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1052. if ($idGroup < 0) $idGroup = 0;
  1053. $limit = 20;
  1054. $limitstart = V::get('limitstart', 0, $args, 'int');
  1055. if ($limitstart < 0) $limitstart = 0;
  1056. $page = V::get('page', 0, $args, 'int');
  1057. $limitstart = ($page - 1) * $limit;
  1058. $search = V::get('search', '', $args);
  1059. $searchParams = [];
  1060. if (!empty($search)) {
  1061. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1062. $searchParams['ogc:Filter'] = '
  1063. <ogc:Filter>
  1064. <ogc:Or>
  1065. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1066. <ogc:PropertyName>NIP</ogc:PropertyName>
  1067. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1068. </ogc:PropertyIsLike>
  1069. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1070. <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
  1071. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1072. </ogc:PropertyIsLike>
  1073. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1074. <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
  1075. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1076. </ogc:PropertyIsLike>
  1077. </ogc:Or>
  1078. </ogc:Filter>
  1079. ';
  1080. }
  1081. // ogc filter w środku ogcand potem ogcnot potem PropertyIsEqualTo
  1082. $backRefFilter = [];
  1083. if ($idGroup > 0) {
  1084. $backRefFilter['__backRef'] = [
  1085. 'namespace' => 'default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  1086. 'primaryKey' => $idGroup,
  1087. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  1088. ];
  1089. // - ID
  1090. // - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
  1091. // - NAZWA - nazwa grupy
  1092. // - 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_KONTRAHENCI' minOccurs="0" maxOccurs="unbounded"
  1093. }
  1094. $filtersParams = [];
  1095. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1096. return ('f_' === substr($key, 0, 2));
  1097. });
  1098. foreach ($fieldFilterKeys as $key) {
  1099. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1100. }
  1101. DBG::log($filtersParams, 'Kontrahenci $filtersParams');
  1102. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  1103. $query = $acl->buildQuery(array_merge([
  1104. 'cols' => [ // TODO:? propertyName = []
  1105. 'ID',
  1106. 'Nazwa_grupy_kapitalowej',
  1107. 'Pelna_nazwa_kontrahenta',
  1108. 'Numer_kontrahenta',
  1109. 'Skrocona_Nazwa_Kontrahenta',
  1110. 'Typ_kontrahenta',
  1111. 'NIP',
  1112. 'KRS',
  1113. 'REGON',
  1114. 'PESEL',
  1115. 'Forma_prawna_dzialalnosci',
  1116. 'Ulica',
  1117. 'Numer_budynku',
  1118. 'Numer_mieszkania_lokalu',
  1119. 'Miejscowosc',
  1120. 'Kod_pocztowy',
  1121. 'Kraj',
  1122. 'Telefon',
  1123. 'Fax',
  1124. 'Mail',
  1125. 'A_ADM_COMPANY',
  1126. 'A_CLASSIFIED',
  1127. 'Dodano',
  1128. 'Podmiot_dominujacy',
  1129. 'Tytul_dokumentu',
  1130. 'ownCompany',
  1131. 'uwagi',
  1132. ],
  1133. //'f_ID' => $id,
  1134. 'limit' => $limit,
  1135. 'limitstart' => $limitstart, // offset
  1136. 'order_by' => 'ID', // sortowanie po kolumnie
  1137. 'order_dir' => 'DESC', // kierunek sortowania
  1138. ], $searchParams, $filtersParams, $backRefFilter));
  1139. $total = $query->getTotal();
  1140. $items = $query->getItems();
  1141. $pagination = array();
  1142. $pagination['total_items'] = $total;
  1143. $pagination['size'] = ceil($total/$limit); // pages size
  1144. $pagination['current'] = $page;
  1145. $pagination['limit'] = $limit;
  1146. if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
  1147. return [
  1148. 'type' => 'success',
  1149. 'msg' => 'showKontrajenci',
  1150. 'body' => [
  1151. 'items' => $items,
  1152. //'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI'),
  1153. 'pagination' => $pagination
  1154. ],
  1155. '__DBG_args' => $args,
  1156. '__DBG_$idGroup' => $idGroup,
  1157. '__DBG_$filtersParams' => $filtersParams,
  1158. '__DBG_$backRefFilter' => $backRefFilter,
  1159. ];
  1160. }
  1161. public function fetchFromBazaAjaxAction() {
  1162. Response::sendTryCatchJson(array($this, 'fetchFromBazaAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1163. }
  1164. public function fetchFromBazaAjax($args) {
  1165. $baza = V::get('baza', '', $args);
  1166. $query = V::get('query', '', $args);
  1167. if (strlen($query) < 3) throw new Exception("Query must be more then 2 chars");
  1168. switch ($baza) {
  1169. case 'default_db/BI_audit_KRS/BI_audit_KRS': return $this->fetchFromKRS($query);
  1170. case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return $this->fetchFromKRSPerson($query);
  1171. case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return $this->fetchFromMSIG($query);
  1172. case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return $this->fetchFromMSIGPerson($query);
  1173. case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return $this->fetchFromCEIDG($query);
  1174. }
  1175. }
  1176. function fetchFromKRS($query){
  1177. $ogcSearch = "*{$query}*";
  1178. $searchParams = [];
  1179. $searchParams['ogc:Filter'] = '
  1180. <ogc:Filter>
  1181. <ogc:Or>
  1182. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1183. <ogc:PropertyName>nazwa</ogc:PropertyName>
  1184. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1185. </ogc:PropertyIsLike>
  1186. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1187. <ogc:PropertyName>nip</ogc:PropertyName>
  1188. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1189. </ogc:PropertyIsLike>
  1190. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1191. <ogc:PropertyName>S_miejscowosc</ogc:PropertyName>
  1192. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1193. </ogc:PropertyIsLike>
  1194. </ogc:Or>
  1195. </ogc:Filter>
  1196. ';
  1197. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery(array_merge([
  1198. 'cols' => [ // TODO:? propertyName = []
  1199. 'A_kod',
  1200. 'A_kraj',
  1201. 'A_miejscowosc',
  1202. 'A_nrDomu',
  1203. 'A_nrLokalu',
  1204. 'A_poczta',
  1205. 'A_ulica',
  1206. 'ID',
  1207. // 'S_gmina',
  1208. 'S_kraj',
  1209. 'S_miejscowosc',
  1210. // 'S_powiat',
  1211. 'S_wojewodztwo',
  1212. // 'dataDokumentu',
  1213. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1214. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1215. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1216. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1217. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  1218. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  1219. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  1220. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  1221. 'krs',
  1222. 'nazwa',
  1223. 'nip',
  1224. 'regon',
  1225. ],
  1226. // 'f_ID' => "{$id}",
  1227. ], $searchParams))->getItems([
  1228. 'limit' => 10
  1229. ]);
  1230. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1231. return [
  1232. 'type' => 'success',
  1233. 'msg' => 'KRS',
  1234. '__args' => $args,
  1235. 'body' => [
  1236. 'items' => array_map(function ($item) {
  1237. $nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1238. $nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
  1239. $item['nazwa'] = $nazwa;
  1240. $item['label'] = "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}";
  1241. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1242. return $item;
  1243. // return [
  1244. // 'ID' => $item['ID'],
  1245. // 'nazwa' => $shortNazwa,
  1246. // 'nip' => $item['nip'],
  1247. // 'krs' => $item['krs'],
  1248. // 'regon' => $item['regon'],
  1249. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1250. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1251. // ];
  1252. }, $items),
  1253. ]
  1254. ];
  1255. }
  1256. function fetchFromKRSPerson($query){
  1257. $ogcSearch = "*{$query}*";
  1258. $searchParams = [];
  1259. $searchParams['ogc:Filter'] = '
  1260. <ogc:Filter>
  1261. <ogc:Or>
  1262. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1263. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1264. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1265. </ogc:PropertyIsLike>
  1266. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1267. <ogc:PropertyName>imiona</ogc:PropertyName>
  1268. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1269. </ogc:PropertyIsLike>
  1270. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1271. <ogc:PropertyName>pesel</ogc:PropertyName>
  1272. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1273. </ogc:PropertyIsLike>
  1274. </ogc:Or>
  1275. </ogc:Filter>
  1276. ';
  1277. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS_person/BI_audit_KRS_person')->buildQuery(array_merge([
  1278. 'cols' => [ // TODO:? propertyName = []
  1279. 'nazwisko',
  1280. 'imiona',
  1281. 'pesel',
  1282. 'ID',
  1283. // 'dataDokumentu',
  1284. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1285. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1286. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1287. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1288. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  1289. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  1290. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  1291. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  1292. ],
  1293. // 'f_ID' => "{$id}",
  1294. ], $searchParams))->getItems([
  1295. 'limit' => 10
  1296. ]);
  1297. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1298. return [
  1299. 'type' => 'success',
  1300. 'msg' => 'KRS person',
  1301. '__args' => $args,
  1302. 'body' => [
  1303. 'items' => array_map(function ($item) {
  1304. //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1305. //$nazwa = $item['nazwisko'];
  1306. //$item['nazwa'] = $nazwa;
  1307. $item['label'] = "{$item['nazwisko']}, {$item['imiona']}, {$item['pesel']}";
  1308. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1309. return $item;
  1310. // return [
  1311. // 'ID' => $item['ID'],
  1312. // 'nazwa' => $shortNazwa,
  1313. // 'nip' => $item['nip'],
  1314. // 'krs' => $item['krs'],
  1315. // 'regon' => $item['regon'],
  1316. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1317. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1318. // ];
  1319. }, $items),
  1320. ]
  1321. ];
  1322. }
  1323. function fetchFromMSIG($query){
  1324. $ogcSearch = "*{$query}*";
  1325. $searchParams = [];
  1326. $searchParams['ogc:Filter'] = '
  1327. <ogc:Filter>
  1328. <ogc:Or>
  1329. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1330. <ogc:PropertyName>nazwa</ogc:PropertyName>
  1331. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1332. </ogc:PropertyIsLike>
  1333. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1334. <ogc:PropertyName>nip</ogc:PropertyName>
  1335. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1336. </ogc:PropertyIsLike>
  1337. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1338. <ogc:PropertyName>S_miejscowosc</ogc:PropertyName>
  1339. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1340. </ogc:PropertyIsLike>
  1341. </ogc:Or>
  1342. </ogc:Filter>
  1343. ';
  1344. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_MSIG')->buildQuery(array_merge([
  1345. 'cols' => [ // TODO:? propertyName = []
  1346. 'A_kod',
  1347. 'A_kraj',
  1348. 'A_miejscowosc',
  1349. 'A_nrDomu',
  1350. 'A_nrLokalu',
  1351. 'A_poczta',
  1352. 'A_ulica',
  1353. 'ID',
  1354. // 'S_gmina',
  1355. 'S_kraj',
  1356. 'S_miejscowosc',
  1357. // 'S_powiat',
  1358. 'S_wojewodztwo',
  1359. // 'dataDokumentu',
  1360. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1361. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1362. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1363. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1364. 'default_db__x3A__BI_audit_KRS_person:BI_audit_MSIG_person/ID',
  1365. 'default_db__x3A__BI_audit_KRS_person:BI_audit_MSIG_person/imiona',
  1366. 'default_db__x3A__BI_audit_KRS_person:BI_audit_MSIG_person/nazwisko',
  1367. 'default_db__x3A__BI_audit_KRS_person:BI_audit_MSIG_person/pesel',
  1368. 'krs',
  1369. 'nazwa',
  1370. 'nip',
  1371. 'regon',
  1372. ],
  1373. // 'f_ID' => "{$id}",
  1374. ], $searchParams))->getItems([
  1375. 'limit' => 10
  1376. ]);
  1377. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1378. return [
  1379. 'type' => 'success',
  1380. 'msg' => 'MSIG',
  1381. '__args' => $args,
  1382. 'body' => [
  1383. 'items' => array_map(function ($item) {
  1384. $nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1385. $nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
  1386. $item['nazwa'] = $nazwa;
  1387. $item['label'] = "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}";
  1388. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1389. return $item;
  1390. // return [
  1391. // 'ID' => $item['ID'],
  1392. // 'nazwa' => $shortNazwa,
  1393. // 'nip' => $item['nip'],
  1394. // 'krs' => $item['krs'],
  1395. // 'regon' => $item['regon'],
  1396. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1397. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1398. // ];
  1399. }, $items),
  1400. ]
  1401. ];
  1402. }
  1403. function fetchFromMSIGPerson($query){
  1404. $ogcSearch = "*{$query}*";
  1405. $searchParams = [];
  1406. $searchParams['ogc:Filter'] = '
  1407. <ogc:Filter>
  1408. <ogc:Or>
  1409. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1410. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1411. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1412. </ogc:PropertyIsLike>
  1413. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1414. <ogc:PropertyName>imiona</ogc:PropertyName>
  1415. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1416. </ogc:PropertyIsLike>
  1417. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1418. <ogc:PropertyName>pesel</ogc:PropertyName>
  1419. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1420. </ogc:PropertyIsLike>
  1421. </ogc:Or>
  1422. </ogc:Filter>
  1423. ';
  1424. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_MSIG_person')->buildQuery(array_merge([
  1425. 'cols' => [ // TODO:? propertyName = []
  1426. 'nazwisko',
  1427. 'imiona',
  1428. 'pesel',
  1429. 'ID',
  1430. // 'dataDokumentu',
  1431. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1432. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1433. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1434. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1435. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  1436. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  1437. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  1438. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  1439. ],
  1440. // 'f_ID' => "{$id}",
  1441. ], $searchParams))->getItems([
  1442. 'limit' => 10
  1443. ]);
  1444. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1445. return [
  1446. 'type' => 'success',
  1447. 'msg' => 'KRS',
  1448. '__args' => $args,
  1449. 'body' => [
  1450. 'items' => array_map(function ($item) {
  1451. //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1452. //$nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
  1453. //$item['nazwa'] = $nazwa;
  1454. $item['label'] = "{$item['nazwisko']}, {$item['imiona']}, {$item['pesel']}";
  1455. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1456. return $item;
  1457. // return [
  1458. // 'ID' => $item['ID'],
  1459. // 'nazwa' => $shortNazwa,
  1460. // 'nip' => $item['nip'],
  1461. // 'krs' => $item['krs'],
  1462. // 'regon' => $item['regon'],
  1463. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1464. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1465. // ];
  1466. }, $items),
  1467. ]
  1468. ];
  1469. }
  1470. function fetchFromCEIDG($query){
  1471. $ogcSearch = "*{$query}*";
  1472. $searchParams = [];
  1473. $searchParams['ogc:Filter'] = '
  1474. <ogc:Filter>
  1475. <ogc:Or>
  1476. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1477. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1478. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1479. </ogc:PropertyIsLike>
  1480. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1481. <ogc:PropertyName>imie</ogc:PropertyName>
  1482. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1483. </ogc:PropertyIsLike>
  1484. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1485. <ogc:PropertyName>miejscowosc</ogc:PropertyName>
  1486. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1487. </ogc:PropertyIsLike>
  1488. </ogc:Or>
  1489. </ogc:Filter>
  1490. ';
  1491. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_CEIDG')->buildQuery(array_merge([
  1492. 'cols' => [ // TODO:? propertyName = []
  1493. 'ID',
  1494. 'budynek',
  1495. 'firma',
  1496. 'gmina',
  1497. 'identyfikatorWpisu',
  1498. 'imie',
  1499. 'kodPocztowy',
  1500. 'kraj',
  1501. 'lokal',
  1502. 'miejscowosc',
  1503. 'nazwisko',
  1504. 'nip',
  1505. 'poczta',
  1506. 'powiat',
  1507. 'regon',
  1508. 'ulica',
  1509. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ID',
  1510. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/budynek',
  1511. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/gmina',
  1512. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/kodPocztowy',
  1513. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/lokal',
  1514. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/miejscowosc',
  1515. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nazwa',
  1516. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nip',
  1517. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/poczta',
  1518. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/powiat',
  1519. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ulica',
  1520. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/wojewodztwo',
  1521. // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/ID',
  1522. // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/nip',
  1523. // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/regon',
  1524. ],
  1525. // 'f_ID' => "{$id}",
  1526. ], $searchParams))->getItems([
  1527. 'limit' => 10
  1528. ]);
  1529. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1530. return [
  1531. 'type' => 'success',
  1532. 'msg' => 'CEIDG',
  1533. '__args' => $args,
  1534. 'body' => [
  1535. 'items' => array_map(function ($item) {
  1536. //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1537. //$nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
  1538. //$item['nazwa'] = $nazwa;
  1539. $item['label'] = "{$item['imie']}, {$item['nazwisko']}, {$item['krs']}, {$item['nip']}, {$item['regon']}";
  1540. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1541. return $item;
  1542. // return [
  1543. // 'ID' => $item['ID'],
  1544. // 'nazwa' => $shortNazwa,
  1545. // 'nip' => $item['nip'],
  1546. // 'krs' => $item['krs'],
  1547. // 'regon' => $item['regon'],
  1548. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1549. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1550. // ];
  1551. }, $items),
  1552. ]
  1553. ];
  1554. }
  1555. public function showTableKontrahenci($labels = []) {
  1556. // TODO: use self::$FIELD_LIST_KONTRAHENCI
  1557. $view = '<form class="form-horizontal" method="post">
  1558. <table class="table table-bordered table-hover table-striped" height=5>
  1559. <thead>
  1560. <tr>
  1561. <td width=1><input type="checkbox" name="checkAll" id="checkAll-KONTRAHENCI" /></td>
  1562. <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
  1563. <td>' . V::get('Nazwa_grupy_kapitalowej', 'Nazwa grupy kapitalowej', $labels) . '</td>
  1564. <td>' . V::get('Pelna_nazwa_kontrahenta', 'Pelna nazwa kontrahenta', $labels) . '</td>
  1565. <td>' . V::get('Numer_kontrahenta', 'Numer kontrahenta', $labels) . '</td>
  1566. <td>' . V::get('Skrocona_Nazwa_Kontrahenta', 'Skrócona nazwa kontrahenta', $labels) . '</td>
  1567. <td>' . V::get('Typ_kontrahenta', 'Typ_kontrahenta', $labels) . '</td>
  1568. <td>' . V::get('NIP', 'NIP', $labels) . '</td>
  1569. <td>' . V::get('KRS', 'KRS', $labels) . '</td>
  1570. <td>' . V::get('REGON', 'Regon', $labels) . '</td>
  1571. <td>' . V::get('PESEL', 'PESEL', $labels) . '</td>
  1572. <td>' . V::get('Forma_prawna_dzialalnosci', 'Forma prawna działalności', $labels) . '</td>
  1573. <td>' . V::get('Ulica', 'Ulica', $labels) . '</td>
  1574. <td>' . V::get('Numer_budynku', 'Numer budynku', $labels) . '</td>
  1575. <td>' . V::get('Numer_mieszkania_lokalu', 'Numer mieszkania lokalu', $labels) . '</td>
  1576. <td>' . V::get('Miejscowosc', 'Miejscowosc', $labels) . '</td>
  1577. <td>' . V::get('Kod_pocztowy', 'Kod pocztowy', $labels) . '</td>
  1578. <td>' . V::get('Kraj', 'Kraj', $labels) . '</td>
  1579. <td>' . V::get('Telefon', 'Telefon', $labels) . '</td>
  1580. <td>' . V::get('Fax', 'Fax', $labels) . '</td>
  1581. <td>' . V::get('Mail', 'Mail', $labels) . '</td>
  1582. <td>' . V::get('A_ADM_COMPANY', 'A_ADM_COMPANY', $labels) . '</td>
  1583. <td>' . V::get('A_CLASSIFIED', 'A_CLASSIFIED', $labels) . '</td>
  1584. <td>' . V::get('Dodano', 'Dodano', $labels) . '</td>
  1585. <td>' . V::get('Podmiot_dominujacy', 'Podmiot dominujacy', $labels) . '</td>
  1586. <td>' . V::get('Tytul_dokumentu', 'Tytul dokumentu', $labels) . '</td>
  1587. <td>' . V::get('ownCompany', 'ownCompany', $labels) . '</td>
  1588. <td>' . V::get('uwagi', 'uwagi', $labels) . '</td>
  1589. </tr>
  1590. <tr>
  1591. <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>
  1592. <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>
  1593. <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>
  1594. <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>
  1595. <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>
  1596. <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>
  1597. <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>
  1598. <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>
  1599. <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>
  1600. <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>
  1601. <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>
  1602. <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>
  1603. <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>
  1604. <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>
  1605. <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>
  1606. <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>
  1607. <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>
  1608. <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>
  1609. <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>
  1610. <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>
  1611. <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>
  1612. <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>
  1613. <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>
  1614. <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>
  1615. <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>
  1616. <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>
  1617. <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>
  1618. <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>
  1619. </tr>
  1620. </thead>
  1621. <tbody id="body-kontrahenci">
  1622. </tbody></table>
  1623. </form>
  1624. ';
  1625. return $view;
  1626. }
  1627. // tworzenie grupy kontrahentów
  1628. public function createKontrahenciGroupAjaxAction() {
  1629. 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
  1630. }
  1631. public function createKontrahenciGroupAjax($args) {
  1632. $nazwa = V::get('NAZWA', '', $args);
  1633. // TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje
  1634. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_KONTRAHENCI_group', [
  1635. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1636. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1637. 'NAZWA' => $nazwa,
  1638. 'ID_USER' => User::getID()
  1639. ]);
  1640. return [
  1641. 'msg' => "Utworzona grupę {$idGroup}",
  1642. 'type' => "success",
  1643. 'body' => [
  1644. 'id' => $idGroup,
  1645. 'nazwa' => $nazwa
  1646. ]
  1647. ];
  1648. }
  1649. // Dodanie do grupy filtra kontrahentów
  1650. public function addKontrahenciToGroupAjaxAction() {
  1651. 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
  1652. }
  1653. public function addKontrahenciToGroupAjax($args) {
  1654. $idGroup = V::get('idGroup', '', $args);
  1655. $type = V::get('type', 'ids', $args);
  1656. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  1657. $filter = V::get('filter', '', $args);
  1658. // validate
  1659. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  1660. switch ($type) {
  1661. case 'ids': {
  1662. if (!$kontrahenciIds || count($kontrahenciIds) == 0) throw new Exception("Proszę wybrać kontrahentów");
  1663. } break;
  1664. case 'filter': {
  1665. if (!isset($args['filter'])) throw new Exception("Proszę wybrać kontrahentów");
  1666. } break;
  1667. default: throw new Exception("Missing type");
  1668. }
  1669. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  1670. 'cols' => [ // TODO:? propertyName = []
  1671. 'ID',
  1672. 'ID_USER',
  1673. 'NAZWA',
  1674. ],
  1675. // 'f_ID_USER' => User::getID()
  1676. ])->getItem($idGroup);
  1677. if (!$group) throw new Exception("Grupa nie istnieje");
  1678. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1679. if ('filter' === $type) {
  1680. $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1681. if ($args__idGroup < 0) $args__idGroup = 0;
  1682. $search = V::get('search', '', $args['filter']);
  1683. $searchParams = [];
  1684. if (!empty($search)) {
  1685. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1686. $searchParams['ogc:Filter'] = '
  1687. <ogc:Filter>
  1688. <ogc:Or>
  1689. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1690. <ogc:PropertyName>NIP</ogc:PropertyName>
  1691. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1692. </ogc:PropertyIsLike>
  1693. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1694. <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
  1695. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1696. </ogc:PropertyIsLike>
  1697. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1698. <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
  1699. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1700. </ogc:PropertyIsLike>
  1701. </ogc:Or>
  1702. </ogc:Filter>
  1703. ';
  1704. }
  1705. $backRefFilter = [];
  1706. if ($args__idGroup > 0) {
  1707. $backRefFilter['__backRef'] = [
  1708. 'namespace' => 'default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  1709. 'primaryKey' => $args__idGroup,
  1710. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  1711. ];
  1712. }
  1713. $filtersParams = [];
  1714. $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
  1715. return ('f_' === substr($key, 0, 2));
  1716. });
  1717. foreach ($fieldFilterKeys as $key) {
  1718. $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
  1719. }
  1720. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  1721. $query = $acl->buildQuery(array_merge([
  1722. 'cols' => ['ID'],
  1723. ], $searchParams, $filtersParams, $backRefFilter, [
  1724. 'limit' => 0
  1725. ]));
  1726. $items = $query->getItems();
  1727. $kontrahenciIds = array_map(function ($row) {
  1728. return $row['ID'];
  1729. }, $items);
  1730. }
  1731. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  1732. $refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  1733. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  1734. foreach ($kontrahenciIds as $kontrahentIds) {
  1735. DB::getPDO()->insert($refGrupyToKontrahenci, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $kontrahentIds]);
  1736. }
  1737. return [
  1738. 'msg' => "Powiązano kontrahentów z grupą {$idGroup}",
  1739. 'type' => "success",
  1740. ];
  1741. }
  1742. public function removePracownicyFromGroupAjaxAction(){
  1743. 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
  1744. }
  1745. public function removePracownicyFromGroupAjax($args){
  1746. $idGroup = V::get('idGroup', 0, $args, "int");
  1747. $pracownicyIds = V::get('pracownicyIds', [], $args, 'array');
  1748. if ($idGroup === 0){
  1749. foreach ($pracownicyIds as $pracownikIds) {
  1750. //TO DO Błąd do naprawienia
  1751. //TO DO sprawdzanie czy już DELETED
  1752. $affected = DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY', 'ID', $pracownikIds, [
  1753. 'A_STATUS' => 'DELETED',
  1754. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  1755. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  1756. ]);
  1757. }
  1758. return [
  1759. 'msg' => "Usunięto osoby z systemu",
  1760. 'type' => "success",
  1761. ];
  1762. } else {
  1763. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  1764. 'cols' => [ // TODO:? propertyName = []
  1765. 'ID',
  1766. 'ID_USER',
  1767. 'NAZWA',
  1768. ],
  1769. // 'f_ID_USER' => User::getID()
  1770. ])->getItem($idGroup);
  1771. if (!$group) throw new Exception("Grupa nie istnieje");
  1772. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1773. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1774. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  1775. foreach ($pracownicyIds as $pracownikIds) {
  1776. $id = (int)$pracownikIds;
  1777. DB::getPDO()->execSql(" delete from `{$refGrupyToPracownicy}` where PRIMARY_KEY = :pk and REMOTE_PRIMARY_KEY = :remote_pk ", [
  1778. ':pk' => $idGroup,
  1779. ':remote_pk' => $id
  1780. ]);
  1781. }
  1782. return [
  1783. 'msg' => "Usunięto osoby z grupy {$idGroup}",
  1784. 'type' => "success",
  1785. ];
  1786. }
  1787. }
  1788. public function removeKontrahenciFromGroupAjaxAction() {
  1789. 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
  1790. }
  1791. public function removeKontrahenciFromGroupAjax($args) {
  1792. $idGroup = V::get('idGroup', 0, $args, "int");
  1793. $kontrahenciIds = V::get('kontrahenciIds', [], $args, 'array');
  1794. if ($idGroup === 0) {
  1795. foreach ($kontrahenciIds as $kontrahentIds) {
  1796. //TO DO sprawdzanie czy już DELETED
  1797. $affected = DB::getPDO()->update('BI_audit_ENERGA_RUM_KONTRAHENCI', 'ID', $kontrahentIds, [
  1798. 'A_STATUS' => 'DELETED',
  1799. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  1800. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  1801. ])->debugDumpParams();
  1802. }
  1803. return [
  1804. 'msg' => "Usunięto kontrahentów z systemu",
  1805. 'type' => "success",
  1806. ];
  1807. } else {
  1808. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  1809. 'cols' => [ // TODO:? propertyName = []
  1810. 'ID',
  1811. 'ID_USER',
  1812. 'NAZWA',
  1813. ],
  1814. // 'f_ID_USER' => User::getID()
  1815. ])->getItem($idGroup);
  1816. if (!$group) throw new Exception("Grupa nie istnieje");
  1817. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1818. $refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group',
  1819. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  1820. foreach ($kontrahenciIds as $kontrahentIds) {
  1821. $id = (int)$kontrahentIds;
  1822. DBG::log("nazwa grupy {$refGrupyToKontrahenci}");
  1823. DB::getPDO()->execSql(" delete from `{$refGrupyToKontrahenci}` where PRIMARY_KEY = :pk and REMOTE_PRIMARY_KEY = :remote_pk ", [
  1824. ':pk' => $idGroup,
  1825. ':remote_pk' => $id
  1826. ]);
  1827. }
  1828. return [
  1829. 'msg' => "Usunięto kontrahentów z grupy {$idGroup}",
  1830. 'type' => "success",
  1831. ];
  1832. }
  1833. }
  1834. public function fetchGroupKontrahenciAjaxAction() {
  1835. Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
  1836. }
  1837. public function fetchGroupKontrahenciAjax() {
  1838. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_group/BI_audit_ENERGA_KONTRAHENCI_group')->buildQuery([
  1839. 'cols' => [ // TODO:? propertyName = []
  1840. 'ID',
  1841. 'ID_USER',
  1842. 'NAZWA',
  1843. ],
  1844. 'f_ID_USER' => "=" . User::getID(),
  1845. 'f_A_STATUS' => "!DELETED",
  1846. ]);
  1847. $itemsKontrahenci = $query->getItems();
  1848. if (empty($itemsKontrahenci)) throw new AlertWarningException("Grupy nie istnieją");
  1849. $arrayGroupKontrahenci = array();
  1850. foreach ($itemsKontrahenci as $item) {
  1851. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  1852. $arrayGroupKontrahenci[] = [
  1853. 'NAZWA' => $item['NAZWA'],
  1854. 'ID' => $item['ID'],
  1855. ];
  1856. }
  1857. return [
  1858. 'type' => 'success',
  1859. 'msg' => 'fetchGroupKontrahenciAjax',
  1860. '__req_args' => $_REQUEST,
  1861. '__args' => $args,
  1862. 'body' => [
  1863. 'itemsGroupKontrahenci' => $arrayGroupKontrahenci
  1864. ]
  1865. ];
  1866. }
  1867. public function fetchPracownicyIdsAjaxAction() {
  1868. Response::sendTryCatchJson(array($this, 'fetchPracownicyIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1869. }
  1870. public function fetchPracownicyIdsAjax($args) {
  1871. $idGroup = V::get('filter_idGroup', 0, $args, 'int');
  1872. if ($idGroup < 0) $idGroup = 0;
  1873. $backRefFilter = [];
  1874. if ($idGroup > 0) {
  1875. $backRefFilter['__backRef'] = [
  1876. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1877. 'primaryKey' => $idGroup,
  1878. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1879. ];
  1880. }
  1881. $searchParams = []; // TODO: ???
  1882. $filtersParams = [];
  1883. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1884. return ('f_' === substr($key, 0, 2));
  1885. });
  1886. foreach ($fieldFilterKeys as $key) {
  1887. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1888. }
  1889. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1890. $query = $acl->buildQuery(array_merge([
  1891. 'cols' => [
  1892. 'ID',
  1893. ],
  1894. //'f_ID' => $id,
  1895. 'limit' => 0,
  1896. // 'limitstart' => $limitstart, // offset
  1897. // 'order_by' => 'ID', // sortowanie po kolumnie
  1898. // 'order_dir' => 'DESC', // kierunek sortowania
  1899. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1900. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1901. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1902. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1903. ], $searchParams, $filtersParams, $backRefFilter));
  1904. // $total = $query->getTotal();
  1905. $items = $query->getItems();
  1906. return [
  1907. 'type' => 'success',
  1908. 'msg' => 'pracownicy ids',
  1909. 'body' => [
  1910. 'ids' => array_map( V::makePick('ID'), $items ),
  1911. ],
  1912. '__args' => $args,
  1913. '__DBG_$idGroup' => $idGroup,
  1914. '__DBG_$filtersParams' => $filtersParams,
  1915. '__DBG_$backRefFilter' => $backRefFilter,
  1916. ];
  1917. }
  1918. /*
  1919. * PRACOWNICY
  1920. */
  1921. public function fetchPracownicyAjaxAction() {
  1922. Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'), $args = $_REQUEST);
  1923. }
  1924. public function fetchPracownicyAjax($args) {
  1925. $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1926. if ($idGroup < 0) $idGroup = 0;
  1927. $limit = 20;
  1928. $page = V::get('page', 0, $args, 'int');
  1929. $limitstart = ($page - 1) * $limit;
  1930. $search = V::get('search', '', $args);
  1931. $searchParams = [];
  1932. if (!empty($search)) {
  1933. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1934. $searchParams['ogc:Filter'] = '
  1935. <ogc:Filter>
  1936. <ogc:Or>
  1937. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1938. <ogc:PropertyName>nip</ogc:PropertyName>
  1939. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1940. </ogc:PropertyIsLike>
  1941. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1942. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1943. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1944. </ogc:PropertyIsLike>
  1945. </ogc:Or>
  1946. </ogc:Filter>
  1947. ';
  1948. }
  1949. $backRefFilter = [];
  1950. if ($idGroup > 0) {
  1951. $backRefFilter['__backRef'] = [
  1952. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1953. 'primaryKey' => $idGroup,
  1954. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  1955. ];
  1956. }
  1957. $filtersParams = [];
  1958. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1959. return ('f_' === substr($key, 0, 2));
  1960. });
  1961. foreach ($fieldFilterKeys as $key) {
  1962. if ('f_ID' === $key) $filtersParams[ $key ] = '=' . $args[ $key ];
  1963. else $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1964. }
  1965. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  1966. $query = $acl->buildQuery(array_merge([
  1967. 'cols' => array_merge(self::$FIELD_LIST_PRACOWNICY, [
  1968. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  1969. ]),
  1970. //'f_ID' => $id,
  1971. 'limit' => $limit,
  1972. 'limitstart' => $limitstart, // offset
  1973. 'order_by' => 'ID', // sortowanie po kolumnie
  1974. 'order_dir' => 'DESC', // kierunek sortowania
  1975. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1976. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1977. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1978. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1979. ], $searchParams, $filtersParams, $backRefFilter));
  1980. $total = $query->getTotal();
  1981. $items = $query->getItems();
  1982. $pagination = array();
  1983. $pagination['total_items'] = $total;
  1984. $pagination['size'] = ceil($total/$limit); // pages size
  1985. $pagination['current'] = $page;
  1986. $pagination['limit'] = $limit;
  1987. // $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1988. if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
  1989. // { // tworzenie własnego zapytanie mysql
  1990. // $rootTableName = $acl->getRootTableName();
  1991. // DB::getPDO()->fetchAll("
  1992. // select t.*
  1993. // from {$rootTableName} t
  1994. // where t.ID in (
  1995. // select x.ID
  1996. // from ... x
  1997. // where
  1998. // )
  1999. // ");
  2000. // }
  2001. return [
  2002. 'type' => 'success',
  2003. 'msg' => 'showPracownicy',
  2004. 'body' => [
  2005. 'items' => $items,
  2006. //'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
  2007. 'pagination' => $pagination
  2008. ],
  2009. '__DBG_$idGroup' => $idGroup,
  2010. '__DBG_$filtersParams' => $filtersParams,
  2011. '__DBG_$backRefFilter' => $backRefFilter,
  2012. ];
  2013. }
  2014. public function showTablePracownicy($labels = []) {
  2015. // TODO: use self::$FIELD_LIST_PRACOWNICY
  2016. $view = '<form class="form-horizontal" method="post">
  2017. <table class="table table-responsive table-bordered table-hover table-striped" height=5>
  2018. <thead>
  2019. <tr>
  2020. <td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
  2021. <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
  2022. <td>' . V::get('imiona', 'Imię/Imiona', $labels) . '</td>
  2023. <td>' . V::get('nazwisko', 'Nazwisko', $labels) . '</td>
  2024. <td>' . V::get('nip', 'NIP', $labels) . '</td>
  2025. <td>' . V::get('pesel', 'Pesel', $labels) . '</td>
  2026. <td>' . V::get('regon', 'Regon', $labels) . '</td>
  2027. <td>' . V::get('source', 'source', $labels) . '</td>
  2028. <td>' . V::get('jednostka_organizacyjna', 'jednostka_organizacyjna', $labels) . '</td>
  2029. <td>' . V::get('A_STATUS', 'A_STATUS', $labels) . '</td>
  2030. <td>' . V::get('A_STATUS_INFO', 'A_STATUS_INFO', $labels) . '</td>
  2031. <td>' . V::get('L_APPOITMENT_USER', 'L_APPOITMENT_USER', $labels) . '</td>
  2032. <td>' . V::get('Adresy', 'Adresy', $labels) . '</td>
  2033. </tr>
  2034. <tr>
  2035. <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>
  2036. <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>
  2037. <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>
  2038. <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>
  2039. <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>
  2040. <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>
  2041. <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>
  2042. <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>
  2043. <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>
  2044. <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>
  2045. <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>
  2046. <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>
  2047. <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>
  2048. </tr>
  2049. </thead>
  2050. <tbody id="body-pracownicy">
  2051. </tbody></table>
  2052. </form>';
  2053. return $view;
  2054. }
  2055. // tworzenie grupy pracowników
  2056. public function createPracownicyGroupAjaxAction() {
  2057. 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
  2058. }
  2059. public function createPracownicyGroupAjax($args) {
  2060. $nazwa = V::get('NAZWA', '', $args);
  2061. // validate
  2062. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  2063. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
  2064. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  2065. 'A_RECORD_CREATE_DATE' => 'NOW()',
  2066. 'NAZWA' => $nazwa,
  2067. 'ID_USER' => User::getID()
  2068. ]);
  2069. return [
  2070. 'msg' => "Utworzona grupę {$nazwa}",
  2071. 'type' => "success",
  2072. 'body' => [
  2073. 'id' => $idGroup,
  2074. 'nazwa' => $nazwa
  2075. ]
  2076. ];
  2077. }
  2078. // Dodanie do grupy filtra pracowników
  2079. public function addPracownicyToGroupAjaxAction() {
  2080. 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
  2081. }
  2082. public function addPracownicyToGroupAjax($args) {
  2083. $idGroup = V::get('idGroup', '', $args);
  2084. $type = V::get('type', 'ids', $args);
  2085. $pracownicyIds = V::get('pracownicyIds', '', $args);
  2086. $filter = V::get('filter', '', $args);
  2087. // validate
  2088. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  2089. switch ($type) {
  2090. case 'ids': {
  2091. if (!$pracownicyIds || count($pracownicyIds) == 0) throw new Exception("Proszę wybrać pracowników");
  2092. } break;
  2093. case 'filter': {
  2094. if (!isset($args['filter'])) throw new Exception("Proszę wybrać pracowników");
  2095. } break;
  2096. default: throw new Exception("Missing type");
  2097. }
  2098. // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
  2099. // default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
  2100. // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
  2101. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  2102. 'cols' => [ // TODO:? propertyName = []
  2103. 'ID',
  2104. 'ID_USER',
  2105. 'NAZWA',
  2106. ],
  2107. // 'f_ID_USER' => User::getID()
  2108. ])->getItem($idGroup);
  2109. if (!$group) throw new Exception("Grupa nie istnieje");
  2110. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  2111. if ('filter' === $type) {
  2112. $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  2113. if ($args__idGroup < 0) $args__idGroup = 0;
  2114. $search = V::get('search', '', $args['filter']);
  2115. $searchParams = [];
  2116. if (!empty($search)) {
  2117. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  2118. $searchParams['ogc:Filter'] = '
  2119. <ogc:Filter>
  2120. <ogc:Or>
  2121. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  2122. <ogc:PropertyName>nip</ogc:PropertyName>
  2123. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2124. </ogc:PropertyIsLike>
  2125. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  2126. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  2127. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2128. </ogc:PropertyIsLike>
  2129. </ogc:Or>
  2130. </ogc:Filter>
  2131. ';
  2132. }
  2133. $backRefFilter = [];
  2134. if ($args__idGroup > 0) {
  2135. $backRefFilter['__backRef'] = [
  2136. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2137. 'primaryKey' => $args__idGroup,
  2138. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  2139. ];
  2140. }
  2141. $filtersParams = [];
  2142. $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
  2143. return ('f_' === substr($key, 0, 2));
  2144. });
  2145. foreach ($fieldFilterKeys as $key) {
  2146. $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
  2147. }
  2148. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  2149. $query = $acl->buildQuery(array_merge([
  2150. 'cols' => ['ID'],
  2151. ], $searchParams, $filtersParams, $backRefFilter, [
  2152. 'limit' => 0
  2153. ]));
  2154. $items = $query->getItems();
  2155. $pracownicyIds = array_map(function ($row) {
  2156. return $row['ID'];
  2157. }, $items);
  2158. }
  2159. // $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
  2160. $refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2161. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  2162. foreach ($pracownicyIds as $idPracownik) {
  2163. DB::getPDO()->insert($refGrupyToPracownicy, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  2164. }
  2165. return [
  2166. 'msg' => "Powiązano pracowników z grupą {$idGroup}",
  2167. 'type' => "success",
  2168. ];
  2169. }
  2170. public function fetchGroupPracownicyAjaxAction() {
  2171. Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
  2172. }
  2173. public function fetchGroupPracownicyAjax() {
  2174. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  2175. 'cols' => [ // TODO:? propertyName = []
  2176. 'ID',
  2177. 'ID_USER',
  2178. 'NAZWA',
  2179. ],
  2180. 'f_ID_USER' => "=" . User::getID(), // szukamy dokładnie tej wartości - mysql: where ID_USER = "1"
  2181. 'f_A_STATUS' => "!DELETED", // `A_STATUS` != 'DELETED'
  2182. ]);
  2183. $items = $query->getItems();
  2184. if (empty($items)) throw new AlertWarningException("Grupy nie istnieją");
  2185. $arrayGroupPracownicy = array();
  2186. foreach ($items as $item) {
  2187. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy"); // or skip - continue;
  2188. $arrayGroupPracownicy[] = [
  2189. 'ID' => $item['ID'],
  2190. 'NAZWA' => $item['NAZWA'],
  2191. ];
  2192. }
  2193. return [
  2194. 'type' => 'success',
  2195. 'msg' => 'fetchGroupPracownicyAjax',
  2196. '__req_args' => $_REQUEST,
  2197. '__args' => $args,
  2198. 'body' => [
  2199. 'itmesGroupPracownicy' => $arrayGroupPracownicy
  2200. ]
  2201. ];
  2202. }
  2203. // link do ackji w php: $saveFormUrl = $this->getLink('saveRaportAjax');
  2204. // przekazać link do JavaScript i tam:
  2205. // window.fetch('{$saveFormUrl}', { ... }).then(...) - dokumentacja: https://github.com/github/fetch
  2206. public function generateBiAuditRaportAjaxAction() {
  2207. //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
  2208. Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  2209. //Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'));
  2210. }
  2211. public function generateBiAuditRaportAjax($args) {
  2212. // głebokość powiazan
  2213. $depthValue = V::get('depthValue', '', $args);
  2214. if (!$depthValue) {
  2215. throw new Exception("Nie podano wartości dla głębokości powiązań");
  2216. }
  2217. // tytuł raportu
  2218. $smadReaportTitle = V::get('smadReaportTitle', '', $args);
  2219. if (!$smadReaportTitle) {
  2220. throw new Exception("Nie podano tytułu raportu");
  2221. }
  2222. // Bi_analiza_onlyTarger
  2223. $analizaOnlyTargets = V::get('analizaOnlyTargets', '', $args);
  2224. if (!$analizaOnlyTargets) {
  2225. throw new Exception("Nie podano wartości czy zwracać wyniki tylko z obiektami docelowymi");
  2226. }
  2227. // Tworzenie relacji Raport do Pracownicy
  2228. $pracownicyIds = []; // array z nr ID na podstawie wysłanego formularza
  2229. $pracownicyIds = V::get('pracownicyIds', '', $args);
  2230. $kontrahenciIds = []; // array z nr ID na podstawie wysłanego formularza
  2231. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  2232. // walidacja listy kontrahentów i pracowników
  2233. if ( !$kontrahenciIds && !$pracownicyIds ) {
  2234. throw new Exception("Nie wybrano pozycji do analizy. Wybierz pracowników/kontrahentów.");
  2235. }
  2236. // Tworzenie rekrodu w bazie - Raport -
  2237. $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
  2238. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  2239. 'A_RECORD_CREATE_DATE' => 'NOW()',
  2240. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  2241. 'FILE_STATUS' => "TO_GENERATE",
  2242. 'A_STATUS' => "NORMAL",
  2243. 'BI_analiza_minDepth' => 1,
  2244. 'BI_analiza_maxDepth' => $depthValue,
  2245. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  2246. ]);
  2247. if ($idRaport > 0) {
  2248. DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_HIST', [
  2249. 'ID_USERS2' => $idRaport,
  2250. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  2251. 'A_RECORD_CREATE_DATE' => 'NOW()',
  2252. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  2253. 'FILE_STATUS' => "TO_GENERATE",
  2254. 'A_STATUS' => "NORMAL",
  2255. 'BI_analiza_minDepth' => 1,
  2256. 'BI_analiza_maxDepth' => $depthValue,
  2257. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  2258. ]);
  2259. }
  2260. // Tworzenie relacji Raport do Pracownicy
  2261. $refPowiazaniaToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  2262. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
  2263. // Tworzenie relacji Raport do Kontrahenci - analogicznie jak wyżej
  2264. $refPowiazaniaToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  2265. 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
  2266. /* PRACOWNICY */
  2267. if ( !$pracownicyIds ) {
  2268. // dodajemy wszystkich pracowników
  2269. DB::getPDO()->execSql("insert into `{$refPowiazaniaToPracownicy}` (`PRIMARY_KEY`,`REMOTE_PRIMARY_KEY`)
  2270. select '{$idRaport}' as PRIMARY_KEY
  2271. , ID as REMOTE_PRIMARY_KEY
  2272. from `BI_audit_ENERGA_PRACOWNICY`
  2273. ");
  2274. } else { // wybrano pracownika/ów
  2275. foreach ($pracownicyIds as $idPracownik) {
  2276. DB::getPDO()->insert($refPowiazaniaToPracownicy, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
  2277. }
  2278. }
  2279. /* KONTRAHENCI */
  2280. if ( !$kontrahenciIds ) {
  2281. // dodajemy wszystkich pracowników
  2282. DB::getPDO()->execSql("insert into `{$refPowiazaniaToKontrahenci}` (`PRIMARY_KEY`,`REMOTE_PRIMARY_KEY`)
  2283. select '{$idRaport}' as PRIMARY_KEY
  2284. , ID as REMOTE_PRIMARY_KEY
  2285. from `BI_audit_ENERGA_RUM_KONTRAHENCI`
  2286. ");
  2287. } else { // wybrano pracownika/ów
  2288. foreach ($kontrahenciIds as $idKontrahent) {
  2289. DB::getPDO()->insert($refPowiazaniaToKontrahenci, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idKontrahent ]);
  2290. }
  2291. }
  2292. return [
  2293. 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
  2294. 'type' => "success",
  2295. 'body' => [
  2296. 'id' => $idRaport,
  2297. ]
  2298. ];
  2299. }
  2300. /**
  2301. * Widok formularza dodawania pracowników i kontrahentów
  2302. */
  2303. public function defaultViewFormBiAudit($items, $type) {
  2304. $activeFormSteps = '';
  2305. $fieldLabels = [];
  2306. switch($type) {
  2307. case 'KONTRAHENCI':
  2308. $activeFormStepsKontrahent = 'complete';
  2309. $titleHeader = 'KONTRAHENCI/PODMIOTY';
  2310. $groupFilterList = '
  2311. <div class="menu-item">
  2312. <ul class="padding-0">
  2313. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  2314. </ul>
  2315. </div>
  2316. <div id="group-kontrahenci" class="btn-group">
  2317. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  2318. </div>';
  2319. $formSmadDepth = '<input type="text" class="form-control smad-depth-kontrahenci" placeholder="1-16" value="" />';
  2320. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
  2321. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
  2322. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
  2323. $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>';
  2324. $graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
  2325. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  2326. $formAddNewData ='
  2327. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  2328. <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
  2329. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  2330. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  2331. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  2332. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-kontrahenci" placeholder="Default reaport" value="" />';
  2333. $showButtonNextStep = '';
  2334. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  2335. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  2336. $fieldList = $acl->getRealFieldList();
  2337. $fieldLabels = array_combine(
  2338. $fieldList,
  2339. array_map(function ($fieldName) use ($acl) {
  2340. return $acl->getFieldLabel($fieldName);
  2341. }, $fieldList)
  2342. );
  2343. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  2344. break;
  2345. case 'OPERACYJNA_BAZA_ZGLOSZEN':
  2346. $activeFormStepsKontrahent = 'complete';
  2347. $titleHeader = 'KONTRAHENCI/PODMIOTY';
  2348. $groupFilterList = '
  2349. <div class="menu-item">
  2350. <ul class="padding-0">
  2351. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
  2352. </ul>
  2353. </div>
  2354. <div id="group-kontrahenci" class="btn-group">
  2355. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  2356. </div>';
  2357. $formSmadDepth = '<input type="text" class="form-control smad-depth-kontrahenci" placeholder="1-16" value="" />';
  2358. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
  2359. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci">Wszyscy</h2>';
  2360. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span></p>';
  2361. $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>';
  2362. $graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
  2363. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  2364. $formAddNewData ='
  2365. <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  2366. <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
  2367. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  2368. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  2369. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  2370. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-kontrahenci" placeholder="Default reaport" value="" />';
  2371. $showButtonNextStep = '';
  2372. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  2373. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  2374. $fieldList = $acl->getRealFieldList();
  2375. $fieldLabels = array_combine(
  2376. $fieldList,
  2377. array_map(function ($fieldName) use ($acl) {
  2378. return $acl->getFieldLabel($fieldName);
  2379. }, $fieldList)
  2380. );
  2381. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  2382. break;
  2383. case 'PRACOWNICY':
  2384. $titleHeader = 'OSOBY';
  2385. $groupFilterList = '
  2386. <div class="menu-item">
  2387. <ul class="padding-0">
  2388. <li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a></li>
  2389. </ul>
  2390. </div>
  2391. <div id="group-pracownicy" class="btn-group">
  2392. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  2393. </div>';
  2394. $formSmadDepth = '<input type="text" class="form-control smad-depth" placeholder="1-16" value="" />';
  2395. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target"><option value="y">tak</option><option value="n">nie</option></select>';
  2396. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-pracownicy">Wszyscy</h2>';
  2397. $formFilterHeadDesc = '<p>Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span></p>';
  2398. $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>';
  2399. $graphView = '<div class="smad-pracownicy-graph-view" style="display: none;"></div>';
  2400. $csvExamplePracownicy = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/pracownicy_example.zip';
  2401. $formAddNewData ='
  2402. <li><a title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import osób\', \'pracownicy\', \'yes\', \''.$csvExamplePracownicy.'\' )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
  2403. <li><a title="DODAJ PRACOWNIKÓW" onClick="createPracownikAjax(event)" class="btn btn-info" >+ DODAJ OSOBĘ</a></li>'; //todo: dodać obsługe doddawania pracownikow
  2404. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  2405. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addPracownikAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  2406. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removePracownikFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  2407. $showButtonNextStep = '<a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
  2408. $formSmadReaportTitleInput = '<input type="text" class="form-control smad-reaport-title-pracownicy" placeholder="Default reaport" value="" />';
  2409. $pagination_form = '<div id="pagination-pracownicy"></div>';
  2410. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY");
  2411. $fieldList = $acl->getRealFieldList();
  2412. $fieldLabels = array_combine(
  2413. $fieldList,
  2414. array_map(function ($fieldName) use ($acl) {
  2415. return $acl->getFieldLabel($fieldName);
  2416. }, $fieldList)
  2417. );
  2418. DBG::log($fieldLabels, 'array', "fieldLabels (PRACOWNICY)");
  2419. break;
  2420. }
  2421. $view = '
  2422. <!-- start:employees-section-->
  2423. <div id="smad-employees-section" class="smad-form-' . $type . '" >
  2424. <div class="container-fluid">
  2425. <div>
  2426. <div class="padding-lr-0">
  2427. <div id="smad-menu-section">
  2428. <div class="col-sm-12 col-md-6 padding-lr-0">
  2429. <div class="menu-items">
  2430. <div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $titleHeader . ' </div>
  2431. </div>
  2432. </div>
  2433. <div class="col-sm-12 col-md-6 padding-lr-0">
  2434. <div class="form-steps">
  2435. <!-- start:form steps wizard -->
  2436. <div class="row smad-wizard" style="border-bottom:0;">
  2437. <div class="col-xs-4 col-md-4 smad-wizard-step complete"><!-- complited line -->
  2438. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  2439. <div class="progress"><div class="progress-bar"></div></div>
  2440. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY" class="smad-wizard-dot"></a>
  2441. <div class="smad-wizard-info complete text-center">
  2442. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#PRACOWNICY">Krok 1</a></div>
  2443. <div class="step-title">OSOBY <span class="top--count-selected-item-pracownicy"></span></div>
  2444. </div>
  2445. </div>
  2446. <div class="col-xs-4 col-md-4 smad-wizard-step ' . $activeFormStepsKontrahent . ' ">
  2447. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  2448. <div class="progress"><div class="progress-bar"></div></div>
  2449. <a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI" class="smad-wizard-dot"></a>
  2450. <div class="smad-wizard-info text-center">
  2451. <div class="step-item"><a href="'.Request::getPathUri().'index.php?_route=UrlAction_Bocian#KONTRAHENCI">Krok 2</a></div>
  2452. <div class="step-title">PODMIOTY/<BR />KONTRAHENCI <span class="top--count-selected-item-kontrahenci"></span></div>
  2453. </div>
  2454. </div>
  2455. <div class="col-xs-4 col-md-4 smad-wizard-step ">
  2456. <div class="text-center smad-wizard-stepnum">&nbsp;</div>
  2457. <div class="progress"><div class="progress-bar"></div></div>
  2458. <a href="#" class="smad-wizard-dot"></a>
  2459. <div class="smad-wizard-info text-center">
  2460. <div class="step-item">Krok 3</div>
  2461. <div class="step-title">SZUKANIE POWIĄZAŃ</div>
  2462. </div>
  2463. </div>
  2464. </div>
  2465. <!-- end:form steps wizard -->
  2466. </div>
  2467. </div>
  2468. </div>
  2469. </div>
  2470. </div>
  2471. </div>
  2472. <div class="container-fluid">
  2473. <div class=" padding-lr-0">
  2474. <div class="smad-divider"></div>
  2475. </div>
  2476. </div>
  2477. <!-- start:filters -->
  2478. <div class="container-fluid">
  2479. <div class="row">
  2480. <div>
  2481. <div class="smad-employees-form-section" class="border-top-grey">
  2482. <div class="col-md-9 smad-border-col">
  2483. <div class="menu-items">
  2484. '.$groupFilterList.'
  2485. </div>
  2486. </div>
  2487. <div class="col-md-3">
  2488. <div class="form-input">
  2489. <div class="form-item col-md-7 col-lg-9 smad-heder-title">głębokość powiązań:</div>
  2490. <div class="form-item col-md-5 col-lg-3">
  2491. '.$formSmadDepth.'
  2492. </div>
  2493. </div>
  2494. <div class="form-input">
  2495. <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>
  2496. <div class="form-item col-md-5 col-lg-3">
  2497. '.$formSmadSelectTarget.'
  2498. </div>
  2499. </div>
  2500. </div>
  2501. </div>
  2502. </div>
  2503. </div>
  2504. </div>
  2505. <!-- end:filters -->
  2506. <!-- start:list employees -->
  2507. <div class="container-fluid">
  2508. <div class="padding-0 smad-employees-list-head">
  2509. <div class="col-md-6">
  2510. <header>
  2511. '.$formFilterHeadTitle.'
  2512. </header>
  2513. <div class="desc">
  2514. '.$formFilterHeadDesc.'
  2515. </div>
  2516. <div class="countSelectedItem">
  2517. '.$countSelectedItem.'
  2518. </div>
  2519. </div>
  2520. <div class="col-md-6">
  2521. <div class="menu-items">
  2522. <div class="menu-item">
  2523. <ul class="padding-0">
  2524. '.$formAddNewData.'
  2525. </ul>
  2526. </div>
  2527. </div>
  2528. </div>
  2529. </div>
  2530. </div>
  2531. <!-- Start: graph-view -->
  2532. <div class="smad-graph-section">
  2533. <div class="container-fluid">
  2534. '.$graphView.'
  2535. </div>
  2536. </div>
  2537. <!-- End: graph-view -->
  2538. <div class="container-fluid">
  2539. <div class="table-responsive padding-0" id="smad-table-' . $type . '">
  2540. ' . $this->showListDataByType($items, $type, $fieldLabels) . '
  2541. </div>
  2542. </div>
  2543. <!-- end:list employees -->
  2544. <!-- start:list paginations employees -->
  2545. <div class="container-fluid ">
  2546. <div>
  2547. '. $pagination_form .'
  2548. </div>
  2549. </div>
  2550. <!-- end:list paginations employees -->
  2551. <!-- start:bottom buttons -->
  2552. <div class="container-fluid smad-employees-bottom-navigation">
  2553. <div class="padding-0">
  2554. <div class="col-lg-6 ">
  2555. '.$buttonMoveToGroup.'
  2556. </div>
  2557. <div class="col-lg-6 text-right">
  2558. ' . $showButtonNextStep . '
  2559. </div>
  2560. </div>
  2561. </div>
  2562. <!-- end:bottom buttons -->
  2563. </div>
  2564. <!-- start:employees-section -->
  2565. <div class="container-fluid ">
  2566. <div class="row">
  2567. <div class="container text-center">
  2568. <div class="col-md-7 col-lg-5 " style="margin: 0 auto; float: none;">
  2569. '.$formSmadReaportTitleInput.'
  2570. </div>
  2571. </div>
  2572. </div>
  2573. </div>
  2574. <!-- START:bottom generate reaport-->
  2575. <div class="container-fluid smad-generate-reaport">
  2576. <div class="row">
  2577. <div class="container text-center">
  2578. <button type="button" class="btn btn-default smad-generate-reaport-button" onclick="generateBiAuditRaport(event)" id="button-generate-reaport" >GENERUJ RAPORT POWIĄZAŃ</button>
  2579. </div>
  2580. <div class="container smad-generate-reaport-info text-center">
  2581. <div class="step-title"><span class="bottom--count-selected-item-kontrahenci"></span></div>
  2582. <div class="step-title"><span class="bottom--count-selected-item-pracownicy"></span></div>
  2583. <div><strong><span class="bottom--message-warning-critical-search"></span></strong></div>
  2584. </div>
  2585. </div>
  2586. </div>
  2587. <!-- end:bottom generate reaport -->
  2588. ';
  2589. return $view;
  2590. }
  2591. public function showListDataByType($items, $type='PRACOWNICY', $labels) {
  2592. switch ($type) {
  2593. case 'PRACOWNICY':
  2594. return $this->showTablePracownicy($labels);
  2595. break;
  2596. case 'KONTRAHENCI':
  2597. return $this->showTableKontrahenci($labels);
  2598. break;
  2599. }
  2600. }
  2601. function fetchProgressAjaxAction() {
  2602. Response::sendTryCatchJson(array($this, 'fetchProgressAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  2603. }
  2604. function fetchProgressAjax($args) {
  2605. $DBG_FAKE_ANIM = false;
  2606. if (empty($args['ids'])) return [ 'msg' => "empty ids", 'type' => "success" ];
  2607. $ids = $args['ids'];
  2608. // private static function getDirectory($table, $id) {
  2609. $firstId = reset($ids);
  2610. {
  2611. Lib::loadClass('FoldersConfig');
  2612. $folderConf = FoldersConfig::getAll('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_COLUMN');
  2613. if (!isset($folderConf['mount_point'])) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$errMsg}", 404);
  2614. $rootPath = $folderConf['mount_point'];
  2615. }
  2616. $statuses = array_map(function ($id) {
  2617. return DB::getPDO()->fetchValue(" select FILE_STATUS from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  2618. }, $ids);
  2619. $statusesInfo = array_map(function ($id) {
  2620. return DB::getPDO()->fetchValue(" select FILE_STATUS_info from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  2621. }, $ids);
  2622. $progress = array_map(function ($id, $idx) use ($rootPath, $statuses, $DBG_FAKE_ANIM) {
  2623. DBG::log("Loop id({$id}) is-eq-82(".(82 == $id).") is-eq-'82'(".("82"==$id).")");
  2624. DBG::log("Loop id({$id}) is-eq-80(".(80 == $id).") is-eq-'80'(".("80"==$id).")");
  2625. $status = $statuses[$idx];
  2626. if ($DBG_FAKE_ANIM && 82 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2627. if ($DBG_FAKE_ANIM && 80 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2628. if ($DBG_FAKE_ANIM && 77 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2629. DBG::log("Loop id({$id}) status({$status})...");
  2630. if ('GENERATED' === $status) return 1;
  2631. if ('IN_PROGRESS' !== $status) return 0;
  2632. if (!file_exists("{$rootPath}/.tasks/generatePowiazania-{$id}.progress")) return 0;
  2633. DBG::log("Loop id({$id}) status({$status}) progress file exists");
  2634. try {
  2635. $cnt = file_get_contents("{$rootPath}/.tasks/generatePowiazania-{$id}.progress");
  2636. $json = @json_decode($cnt, $assoc = true);
  2637. if (null === $json && 0 !== json_last_error()) {
  2638. throw new Exception("Parse json error for restrictions: " . json_last_error());
  2639. }
  2640. // $json['summary']['step']: 'initialize', 'relations', 'reports'
  2641. // $json['summary']['step'] = 'initialize' - recache - skip
  2642. // $json['summary']['step'] = 'relations' - szuka powiązań (@see AVG(details.progress / summary.count))
  2643. // $json['summary']['step'] = 'reports' - generuje pliki (@see summary.created)
  2644. /*
  2645. if ($DBG_FAKE_ANIM && 82 == $id) { // TODO: DBG
  2646. $json = [
  2647. 'summary' => [
  2648. 'count' => 4,
  2649. 'step' => 'relations',
  2650. ],
  2651. 'details' => [
  2652. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2653. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2654. '22' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2655. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2656. ] ];
  2657. }
  2658. */
  2659. if ($DBG_FAKE_ANIM && 80 == $id) { // TODO: DBG
  2660. $json = [
  2661. 'summary' => [
  2662. 'count' => 4,
  2663. 'created' => 2,
  2664. 'step' => 'reports',
  2665. ],
  2666. 'details' => [
  2667. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2668. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2669. '22' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2670. '25' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2671. ] ];
  2672. }
  2673. if ($DBG_FAKE_ANIM && 77 == $id) { // TODO: DBG
  2674. $json = [
  2675. 'summary' => [
  2676. 'count' => 4,
  2677. 'created' => 2,
  2678. 'step' => 'relations',
  2679. ],
  2680. 'details' => [
  2681. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2682. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2683. '22' => [ 'progress' => 0.25, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2684. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2685. ] ];
  2686. }
  2687. DBG::log($json, 'array', "Loop id({$id}) status({$status}) progress json");
  2688. if (empty($json['summary'])) return 0;
  2689. if (empty($json['summary']['count'])) return 0;
  2690. if (empty($json['summary']['step'])) return 0;
  2691. if (empty($json['details'])) return 0;
  2692. $listDetailsProgress = array_map(function ($detail) {
  2693. return floatval($detail['progress']);
  2694. }, $json['details']);
  2695. $relationsProgress = $json['summary']['count'] > 0 ? round(floatval(array_sum($listDetailsProgress)) / floatval($json['summary']['count']), 3) : 0;
  2696. $reportsCount = V::get('reportsCount', 0, $json['summary'], 'float');
  2697. $reportsProgress = $reportsCount > 0 ? round(V::get('reportsCreated', 0, $json['summary'], 'float') / $reportsCount, 3) : 0;
  2698. return round(0.5 * $relationsProgress + 0.5 * $reportsProgress, 3);
  2699. } catch (Exception $e) {
  2700. DBG::log($e);
  2701. }
  2702. return 0;
  2703. }, $ids, array_keys($ids));
  2704. return [ 'msg' => "DBG ids set", 'type' => "success", 'body' => [
  2705. 'ids' => $ids,
  2706. 'progress' => $progress,
  2707. 'statuses' => $statuses,
  2708. 'statusesInfo' => $statusesInfo,
  2709. ] ];
  2710. }
  2711. }