Bocian.php 133 KB

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