Bocian.php 135 KB

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