Bocian.php 138 KB

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