Bocian.php 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299
  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. $items = DB::getPDO()->fetchAll("
  1229. select r.ID as id
  1230. , r.L_APPOITMENT_INFO as adnotacje
  1231. , (select count(1) from `{$refRaportToPracownicyConfig->tableName}` as prRef where prRef.PRIMARY_KEY = r.ID and prRef.A_STATUS not in ('DELETED')) as totalPracownicy
  1232. , (select count(1) from `{$refRaportToKontrahenciConfig->tableName}` as comRef where comRef.PRIMARY_KEY = r.ID and comRef.A_STATUS not in ('DELETED')) as totalKontrahenci
  1233. from `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` as r
  1234. order by r.ID DESC
  1235. limit 10
  1236. ");
  1237. return [
  1238. 'type' => 'success',
  1239. 'msg' => 'ostatnie raporty',
  1240. 'body' => [
  1241. 'items' => $items,
  1242. ],
  1243. ];
  1244. }
  1245. function fetchPracownicyIdsByReportAjaxAction() { Response::sendTryCatchJson([ $this, 'fetchPracownicyIdsByReportAjax' ], $args = 'JSON_FROM_REQUEST_BODY'); }
  1246. function fetchPracownicyIdsByReportAjax($args) {
  1247. $id = V::get('id', 0, $args);
  1248. if ($id <= 0) throw new HttpException("Missing id", 400);
  1249. $refConf = ACL::getRefConfig(
  1250. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1251. $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY'
  1252. );
  1253. $items = DB::getPDO()->fetchAll("
  1254. select REMOTE_PRIMARY_KEY
  1255. from `{$refConf->tableName}`
  1256. where PRIMARY_KEY = :id
  1257. and A_STATUS not in ('DELETED')
  1258. ", [ ':id' => $id ]);
  1259. return [
  1260. 'type' => 'success',
  1261. 'msg' => 'kontrahenci ids',
  1262. 'body' => [
  1263. 'ids' => array_map( V::makePick('REMOTE_PRIMARY_KEY'), $items ),
  1264. ],
  1265. ];
  1266. }
  1267. function fetchKontrahenciIdsByReportAjaxAction() { Response::sendTryCatchJson([ $this, 'fetchKontrahenciIdsByReportAjax' ], $args = 'JSON_FROM_REQUEST_BODY'); }
  1268. function fetchKontrahenciIdsByReportAjax($args) {
  1269. $id = V::get('id', 0, $args);
  1270. if ($id <= 0) throw new HttpException("Missing id", 400);
  1271. $refConf = ACL::getRefConfig(
  1272. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  1273. $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI'
  1274. );
  1275. $items = DB::getPDO()->fetchAll("
  1276. select REMOTE_PRIMARY_KEY
  1277. from `{$refConf->tableName}`
  1278. where PRIMARY_KEY = :id
  1279. and A_STATUS not in ('DELETED')
  1280. ", [ ':id' => $id ]);
  1281. return [
  1282. 'type' => 'success',
  1283. 'msg' => 'kontrahenci ids',
  1284. 'body' => [
  1285. 'ids' => array_map( V::makePick('REMOTE_PRIMARY_KEY'), $items ),
  1286. ],
  1287. ];
  1288. }
  1289. public function fetchKontrahenciIdsAjaxAction() {
  1290. Response::sendTryCatchJson(array($this, 'fetchKontrahenciIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1291. }
  1292. public function fetchKontrahenciIdsAjax($args) {
  1293. $idGroup = V::get('filter_idGroup', 0, $args, 'int');
  1294. if ($idGroup < 0) $idGroup = 0;
  1295. $backRefFilter = [];
  1296. if ($idGroup > 0) {
  1297. $backRefFilter['__backRef'] = [
  1298. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1299. 'primaryKey' => $idGroup,
  1300. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  1301. ];
  1302. }
  1303. $searchParams = []; // TODO: ???
  1304. $filtersParams = [];
  1305. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1306. return ('f_' === substr($key, 0, 2));
  1307. });
  1308. foreach ($fieldFilterKeys as $key) {
  1309. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1310. }
  1311. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  1312. $query = $acl->buildQuery(array_merge([
  1313. 'cols' => [
  1314. 'ID',
  1315. ],
  1316. //'f_ID' => $id,
  1317. 'limit' => 0,
  1318. // 'limitstart' => $limitstart, // offset
  1319. // 'order_by' => 'ID', // sortowanie po kolumnie
  1320. // 'order_dir' => 'DESC', // kierunek sortowania
  1321. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  1322. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  1323. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  1324. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  1325. ], $searchParams, $filtersParams, $backRefFilter));
  1326. // $total = $query->getTotal();
  1327. $items = $query->getItems();
  1328. return [
  1329. 'type' => 'success',
  1330. 'msg' => 'kontrahenci ids',
  1331. 'body' => [
  1332. 'ids' => array_map( V::makePick('ID'), $items ),
  1333. ],
  1334. '__DBG_args' => $args,
  1335. '__DBG_$idGroup' => $idGroup,
  1336. '__DBG_$filtersParams' => $filtersParams,
  1337. '__DBG_$backRefFilter' => $backRefFilter,
  1338. ];
  1339. }
  1340. /**
  1341. * KONTRAHENCI
  1342. */
  1343. public function fetchKontrahenciAjaxAction() {
  1344. Response::sendTryCatchJson(array($this, 'fetchKontrahenciAjax'), $args = $_REQUEST);
  1345. }
  1346. public function fetchKontrahenciAjax($args) {
  1347. $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  1348. if ($idGroup < 0) $idGroup = 0;
  1349. $limit = 20;
  1350. $limitstart = V::get('limitstart', 0, $args, 'int');
  1351. if ($limitstart < 0) $limitstart = 0;
  1352. $page = V::get('page', 0, $args, 'int');
  1353. $limitstart = ($page - 1) * $limit;
  1354. $search = V::get('search', '', $args);
  1355. $searchParams = [];
  1356. if (!empty($search)) {
  1357. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  1358. $searchParams['ogc:Filter'] = '
  1359. <ogc:Filter>
  1360. <ogc:Or>
  1361. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  1362. <ogc:PropertyName>NIP</ogc:PropertyName>
  1363. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1364. </ogc:PropertyIsLike>
  1365. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1366. <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
  1367. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1368. </ogc:PropertyIsLike>
  1369. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1370. <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
  1371. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1372. </ogc:PropertyIsLike>
  1373. </ogc:Or>
  1374. </ogc:Filter>
  1375. ';
  1376. }
  1377. // ogc filter w środku ogcand potem ogcnot potem PropertyIsEqualTo
  1378. $backRefFilter = [];
  1379. if ($idGroup > 0) {
  1380. $backRefFilter['__backRef'] = [
  1381. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  1382. 'primaryKey' => $idGroup,
  1383. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  1384. ];
  1385. // - ID
  1386. // - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
  1387. // - NAZWA - nazwa grupy
  1388. // - 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_KONTRAHENCI' minOccurs="0" maxOccurs="unbounded"
  1389. }
  1390. $filtersParams = [];
  1391. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  1392. return ('f_' === substr($key, 0, 2));
  1393. });
  1394. foreach ($fieldFilterKeys as $key) {
  1395. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  1396. }
  1397. DBG::log($filtersParams, 'Kontrahenci $filtersParams');
  1398. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  1399. $query = $acl->buildQuery(array_merge([
  1400. 'cols' => [ // TODO:? propertyName = []
  1401. 'ID',
  1402. 'Nazwa_grupy_kapitalowej',
  1403. 'Pelna_nazwa_kontrahenta',
  1404. 'Numer_kontrahenta',
  1405. 'Skrocona_Nazwa_Kontrahenta',
  1406. 'Typ_kontrahenta',
  1407. 'NIP',
  1408. 'KRS',
  1409. 'REGON',
  1410. 'PESEL',
  1411. 'Forma_prawna_dzialalnosci',
  1412. 'Ulica',
  1413. 'Numer_budynku',
  1414. 'Numer_mieszkania_lokalu',
  1415. 'Miejscowosc',
  1416. 'Kod_pocztowy',
  1417. 'Kraj',
  1418. 'Telefon',
  1419. 'Fax',
  1420. 'Mail',
  1421. 'A_ADM_COMPANY',
  1422. 'A_CLASSIFIED',
  1423. 'Dodano',
  1424. 'Podmiot_dominujacy',
  1425. 'Tytul_dokumentu',
  1426. 'ownCompany',
  1427. 'uwagi',
  1428. ],
  1429. //'f_ID' => $id,
  1430. 'limit' => $limit,
  1431. 'limitstart' => $limitstart, // offset
  1432. 'order_by' => 'ID', // sortowanie po kolumnie
  1433. 'order_dir' => 'DESC', // kierunek sortowania
  1434. ], $searchParams, $filtersParams, $backRefFilter));
  1435. $total = $query->getTotal();
  1436. $items = $query->getItems();
  1437. $pagination = array();
  1438. $pagination['total_items'] = $total;
  1439. $pagination['size'] = ceil($total/$limit); // pages size
  1440. $pagination['current'] = $page;
  1441. $pagination['limit'] = $limit;
  1442. if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
  1443. return [
  1444. 'type' => 'success',
  1445. 'msg' => 'showKontrajenci',
  1446. 'body' => [
  1447. 'items' => $items,
  1448. //'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI'),
  1449. 'pagination' => $pagination
  1450. ],
  1451. '__DBG_args' => $args,
  1452. '__DBG_$idGroup' => $idGroup,
  1453. '__DBG_$filtersParams' => $filtersParams,
  1454. '__DBG_$backRefFilter' => $backRefFilter,
  1455. ];
  1456. }
  1457. public function fetchFromBazaAjaxAction() {
  1458. Response::sendTryCatchJson(array($this, 'fetchFromBazaAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  1459. }
  1460. public function fetchFromBazaAjax($args) {
  1461. $baza = V::get('baza', '', $args);
  1462. $query = V::get('query', '', $args);
  1463. $query = trim(trim($query), '0');
  1464. if (strlen($query) < 3) throw new Exception("Query must be more then 2 chars");
  1465. $wordsQuery = [];
  1466. if (false !== strpos($query, ' ')) {
  1467. $words = explode(' ', $query);
  1468. DBG::log($words, 'array', "\$words from \$query({$query}) - 1");
  1469. $words = array_map(function ($word) {
  1470. return trim(trim($word), '0');
  1471. }, $words);
  1472. DBG::log($words, 'array', "\$words from \$query({$query}) - 2");
  1473. $words = array_filter($words, function ($word) {
  1474. return (strlen($word) > 2);
  1475. });
  1476. DBG::log($words, 'array', "\$words from \$query({$query}) - 3");
  1477. if (empty($words)) throw new Exception("Query words must be more then 2 chars");
  1478. $wordsQuery = $words;
  1479. } else {
  1480. $wordsQuery[] = $query;
  1481. }
  1482. switch ($baza) {
  1483. case 'default_db/BI_audit_KRS/BI_audit_KRS': return $this->fetchFromKRS($wordsQuery);
  1484. case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return $this->fetchFromKRSPerson($wordsQuery);
  1485. case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return $this->fetchFromMSIG($wordsQuery);
  1486. case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return $this->fetchFromMSIGPerson($wordsQuery);
  1487. case 'default_db/BI_audit_taxpayer/BI_audit_taxpayer': return $this->fetchFromVATp($wordsQuery);
  1488. case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return $this->fetchFromCEIDG($wordsQuery);
  1489. default: throw new Exception("Unsupported database");
  1490. }
  1491. }
  1492. function generateOgcFilterFromWords($wordsQuery, $searchableFields) {
  1493. return '<ogc:Filter><ogc:And>' .
  1494. implode("\n", array_map(function ($word) use ($searchableFields) {
  1495. return '<ogc:Or>' . implode("\n", array_map(function ($fieldName) use ($word) {
  1496. return '<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1497. <ogc:PropertyName>' . $fieldName . '</ogc:PropertyName>
  1498. <ogc:Literal>' . "*{$word}*" . '</ogc:Literal>
  1499. </ogc:PropertyIsLike>';
  1500. }, $searchableFields)) . '</ogc:Or>';
  1501. }, $wordsQuery)) .
  1502. '</ogc:And></ogc:Filter>';
  1503. }
  1504. function fetchFromKRS($wordsQuery) {
  1505. $query = implode(" ", $wordsQuery);
  1506. if (empty($wordsQuery)) throw new Exception("Empty search");
  1507. $searchableFields = [];
  1508. $searchableFields[] = 'nazwa';
  1509. $searchableFields[] = 'nip';
  1510. $searchableFields[] = 'krs';
  1511. $searchableFields[] = 'regon';
  1512. $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
  1513. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery(array_merge([
  1514. 'cols' => [ // TODO:? propertyName = []
  1515. 'A_kod',
  1516. 'A_kraj',
  1517. 'A_miejscowosc',
  1518. 'A_nrDomu',
  1519. 'A_nrLokalu',
  1520. 'A_poczta',
  1521. 'A_ulica',
  1522. 'ID',
  1523. // 'S_gmina',
  1524. 'S_kraj',
  1525. 'S_miejscowosc',
  1526. // 'S_powiat',
  1527. 'S_wojewodztwo',
  1528. // 'dataDokumentu',
  1529. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1530. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1531. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1532. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1533. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  1534. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  1535. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  1536. 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  1537. 'krs',
  1538. 'nazwa',
  1539. 'nip',
  1540. 'regon',
  1541. ],
  1542. // 'f_ID' => "{$id}",
  1543. ], $searchParams))->getItems([
  1544. 'limit' => 10
  1545. ]);
  1546. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1547. return [
  1548. 'type' => 'success',
  1549. 'msg' => 'KRS',
  1550. '__args' => $args,
  1551. 'body' => [
  1552. 'items' => array_map(function ($item) {
  1553. $nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1554. $nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
  1555. $item['nazwa'] = $nazwa;
  1556. $item['label'] = "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}";
  1557. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1558. return $item;
  1559. // return [
  1560. // 'ID' => $item['ID'],
  1561. // 'nazwa' => $shortNazwa,
  1562. // 'nip' => $item['nip'],
  1563. // 'krs' => $item['krs'],
  1564. // 'regon' => $item['regon'],
  1565. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1566. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1567. // ];
  1568. }, $items),
  1569. ]
  1570. ];
  1571. }
  1572. function fetchFromKRSPerson($wordsQuery) {
  1573. $query = implode(" ", $wordsQuery);
  1574. if (empty($wordsQuery)) throw new Exception("Empty search");
  1575. $searchableFields = [];
  1576. $searchableFields[] = 'nazwisko';
  1577. $searchableFields[] = 'imiona';
  1578. $searchableFields[] = 'pesel';
  1579. $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
  1580. $items = ACL::getAclByNamespace('default_db/BI_audit_KRS_person/BI_audit_KRS_person')->buildQuery(array_merge([
  1581. 'cols' => [ // TODO:? propertyName = []
  1582. 'nazwisko',
  1583. 'imiona',
  1584. 'pesel',
  1585. 'ID',
  1586. // 'dataDokumentu',
  1587. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1588. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1589. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1590. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1591. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  1592. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  1593. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  1594. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  1595. ],
  1596. // 'f_ID' => "{$id}",
  1597. ], $searchParams))->getItems([
  1598. 'limit' => 10
  1599. ]);
  1600. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1601. return [
  1602. 'type' => 'success',
  1603. 'msg' => 'KRS person',
  1604. '__args' => $args,
  1605. 'body' => [
  1606. 'items' => array_map(function ($item) {
  1607. //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1608. //$nazwa = $item['nazwisko'];
  1609. //$item['nazwa'] = $nazwa;
  1610. $item['label'] = "{$item['nazwisko']}, {$item['imiona']}, {$item['pesel']}";
  1611. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1612. return $item;
  1613. // return [
  1614. // 'ID' => $item['ID'],
  1615. // 'nazwa' => $shortNazwa,
  1616. // 'nip' => $item['nip'],
  1617. // 'krs' => $item['krs'],
  1618. // 'regon' => $item['regon'],
  1619. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1620. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1621. // ];
  1622. }, $items),
  1623. ]
  1624. ];
  1625. }
  1626. function fetchFromVATp($query){
  1627. $ogcSearch = "*{$query}*";
  1628. $searchParams = [];
  1629. $searchParams['ogc:Filter'] = '
  1630. <ogc:Filter>
  1631. <ogc:Or>
  1632. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1633. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  1634. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1635. </ogc:PropertyIsLike>
  1636. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1637. <ogc:PropertyName>imiona</ogc:PropertyName>
  1638. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1639. </ogc:PropertyIsLike>
  1640. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  1641. <ogc:PropertyName>pesel</ogc:PropertyName>
  1642. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  1643. </ogc:PropertyIsLike>
  1644. </ogc:Or>
  1645. </ogc:Filter>
  1646. ';
  1647. $items = ACL::getAclByNamespace('default_db/BI_audit_taxpayer/BI_audit_taxpayer')->buildQuery(array_merge([
  1648. 'cols' => [ // TODO:? propertyName = []
  1649. 'nip',
  1650. 'ID',
  1651. // 'dataDokumentu',
  1652. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1653. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1654. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1655. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1656. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  1657. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  1658. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  1659. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  1660. ],
  1661. // 'f_ID' => "{$id}",
  1662. ], $searchParams))->getItems([
  1663. 'limit' => 10
  1664. ]);
  1665. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1666. return [
  1667. 'type' => 'success',
  1668. 'msg' => 'KRS person',
  1669. '__args' => $args,
  1670. 'body' => [
  1671. 'items' => array_map(function ($item) {
  1672. //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1673. //$nazwa = $item['nazwisko'];
  1674. //$item['nazwa'] = $nazwa;
  1675. $item['label'] = "{$item['nip']}";
  1676. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1677. return $item;
  1678. // return [
  1679. // 'ID' => $item['ID'],
  1680. // 'nazwa' => $shortNazwa,
  1681. // 'nip' => $item['nip'],
  1682. // 'krs' => $item['krs'],
  1683. // 'regon' => $item['regon'],
  1684. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1685. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1686. // ];
  1687. }, $items),
  1688. ]
  1689. ];
  1690. }
  1691. function fetchFromMSIG($wordsQuery) {
  1692. $query = implode(" ", $wordsQuery);
  1693. if (empty($wordsQuery)) throw new Exception("Empty search");
  1694. $searchableFields = [];
  1695. $searchableFields[] = 'nazwa';
  1696. $searchableFields[] = 'krs';
  1697. $searchableFields[] = 'nip';
  1698. $searchableFields[] = 'regon';
  1699. $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
  1700. $items = ACL::getAclByNamespace('default_db/BI_audit_MSIG/BI_audit_MSIG')->buildQuery(array_merge([
  1701. 'cols' => [ // TODO:? propertyName = []
  1702. 'A_kod',
  1703. 'A_kraj',
  1704. 'A_miejscowosc',
  1705. 'A_nrDomu',
  1706. 'A_nrLokalu',
  1707. 'A_poczta',
  1708. 'A_ulica',
  1709. 'ID',
  1710. // 'S_gmina',
  1711. 'S_kraj',
  1712. 'S_miejscowosc',
  1713. // 'S_powiat',
  1714. 'S_wojewodztwo',
  1715. // 'dataDokumentu',
  1716. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1717. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1718. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1719. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1720. 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person/ID',
  1721. 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person/imiona',
  1722. 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person/nazwisko',
  1723. 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person/pesel',
  1724. 'krs',
  1725. 'nazwa',
  1726. 'nip',
  1727. 'regon',
  1728. ],
  1729. // 'f_ID' => "{$id}",
  1730. ], $searchParams))->getItems([
  1731. 'limit' => 10
  1732. ]);
  1733. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1734. return [
  1735. 'type' => 'success',
  1736. 'msg' => 'MSIG',
  1737. '__args' => $args,
  1738. 'body' => [
  1739. 'items' => array_map(function ($item) {
  1740. $nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1741. $nazwa = str_replace([ '„', '”' ], '', $item['nazwa']);
  1742. $nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", " Sp. z o.o.", $nazwa);
  1743. $item['nazwa'] = $nazwa;
  1744. $item['label'] = "{$nazwa}, " . implode(", ", array_filter([
  1745. $item['A_miejscowosc'],
  1746. $item['krs'],
  1747. $item['nip'],
  1748. $item['regon']
  1749. ], [ 'V', 'filterNotEmpty' ]));
  1750. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1751. return $item;
  1752. // return [
  1753. // 'ID' => $item['ID'],
  1754. // 'nazwa' => $shortNazwa,
  1755. // 'nip' => $item['nip'],
  1756. // 'krs' => $item['krs'],
  1757. // 'regon' => $item['regon'],
  1758. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1759. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1760. // ];
  1761. }, $items),
  1762. ]
  1763. ];
  1764. }
  1765. function fetchFromMSIGPerson($wordsQuery) {
  1766. $query = implode(" ", $wordsQuery);
  1767. if (empty($wordsQuery)) throw new Exception("Empty search");
  1768. $searchableFields = [];
  1769. $searchableFields[] = 'nazwisko';
  1770. $searchableFields[] = 'imiona';
  1771. $searchableFields[] = 'pesel';
  1772. $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
  1773. $items = ACL::getAclByNamespace('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person')->buildQuery(array_merge([
  1774. 'cols' => [ // TODO:? propertyName = []
  1775. 'nazwisko',
  1776. 'imiona',
  1777. 'pesel',
  1778. 'ID',
  1779. // 'dataDokumentu',
  1780. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
  1781. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
  1782. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
  1783. // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
  1784. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
  1785. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
  1786. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
  1787. // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
  1788. ],
  1789. // 'f_ID' => "{$id}",
  1790. ], $searchParams))->getItems([
  1791. 'limit' => 10
  1792. ]);
  1793. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1794. return [
  1795. 'type' => 'success',
  1796. 'msg' => 'MSIG',
  1797. '__args' => $args,
  1798. 'body' => [
  1799. 'items' => array_map(function ($item) {
  1800. //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1801. //$nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
  1802. //$item['nazwa'] = $nazwa;
  1803. $item['label'] = "{$item['nazwisko']}, {$item['imiona']}, {$item['pesel']}";
  1804. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1805. return $item;
  1806. // return [
  1807. // 'ID' => $item['ID'],
  1808. // 'nazwa' => $shortNazwa,
  1809. // 'nip' => $item['nip'],
  1810. // 'krs' => $item['krs'],
  1811. // 'regon' => $item['regon'],
  1812. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1813. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1814. // ];
  1815. }, $items),
  1816. ]
  1817. ];
  1818. }
  1819. function fetchFromCEIDG($wordsQuery) {
  1820. $query = implode(" ", $wordsQuery);
  1821. if (empty($wordsQuery)) throw new Exception("Empty search");
  1822. $searchableFields = [];
  1823. $searchableFields[] = 'firma';
  1824. $searchableFields[] = 'nazwisko';
  1825. $searchableFields[] = 'imie';
  1826. $searchableFields[] = 'nip';
  1827. $searchableFields[] = 'regon';
  1828. $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
  1829. $items = ACL::getAclByNamespace('default_db/BI_audit_CEIDG/BI_audit_CEIDG')->buildQuery(array_merge([
  1830. 'cols' => [ // TODO:? propertyName = []
  1831. 'ID',
  1832. 'budynek',
  1833. 'firma',
  1834. 'gmina',
  1835. 'identyfikatorWpisu',
  1836. 'imie',
  1837. 'kodPocztowy',
  1838. 'kraj',
  1839. 'lokal',
  1840. 'miejscowosc',
  1841. 'nazwisko',
  1842. 'nip',
  1843. 'poczta',
  1844. 'powiat',
  1845. 'regon',
  1846. 'ulica',
  1847. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ID',
  1848. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/budynek',
  1849. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/gmina',
  1850. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/kodPocztowy',
  1851. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/lokal',
  1852. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/miejscowosc',
  1853. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nazwa',
  1854. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nip',
  1855. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/poczta',
  1856. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/powiat',
  1857. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ulica',
  1858. // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/wojewodztwo',
  1859. // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/ID',
  1860. // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/nip',
  1861. // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/regon',
  1862. ],
  1863. // 'f_ID' => "{$id}",
  1864. ], $searchParams))->getItems([
  1865. 'limit' => 10
  1866. ]);
  1867. DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
  1868. return [
  1869. 'type' => 'success',
  1870. 'msg' => 'CEIDG',
  1871. '__args' => $args,
  1872. 'body' => [
  1873. 'items' => array_map(function ($item) {
  1874. //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
  1875. //$nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
  1876. //$item['nazwa'] = $nazwa;
  1877. $item['label'] = "{$item['firma']} {$item['imie']} {$item['nazwisko']}, {$item['miejscowosc']}, {$item['nip']}, {$item['regon']}";
  1878. // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1879. return $item;
  1880. // return [
  1881. // 'ID' => $item['ID'],
  1882. // 'nazwa' => $shortNazwa,
  1883. // 'nip' => $item['nip'],
  1884. // 'krs' => $item['krs'],
  1885. // 'regon' => $item['regon'],
  1886. // 'S_miejscowosc' => $item['S_miejscowosc'],
  1887. // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
  1888. // ];
  1889. }, $items),
  1890. ]
  1891. ];
  1892. }
  1893. public function showTableKontrahenci($labels = []) {
  1894. // TODO: use self::$FIELD_LIST_KONTRAHENCI
  1895. $view = '<form class="form-horizontal" method="post">
  1896. <table class="table table-bordered table-hover table-striped" height=5>
  1897. <thead>
  1898. <tr>
  1899. <td width=1><input type="checkbox" name="checkAll" id="checkAll-KONTRAHENCI" /></td>
  1900. <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
  1901. <td>' . V::get('Nazwa_grupy_kapitalowej', 'Nazwa grupy kapitalowej', $labels) . '</td>
  1902. <td>' . V::get('Pelna_nazwa_kontrahenta', 'Pelna nazwa kontrahenta', $labels) . '</td>
  1903. <td>' . V::get('Numer_kontrahenta', 'Numer kontrahenta', $labels) . '</td>
  1904. <td>' . V::get('Skrocona_Nazwa_Kontrahenta', 'Skrócona nazwa kontrahenta', $labels) . '</td>
  1905. <td>' . V::get('Typ_kontrahenta', 'Typ_kontrahenta', $labels) . '</td>
  1906. <td>' . V::get('NIP', 'NIP', $labels) . '</td>
  1907. <td>' . V::get('KRS', 'KRS', $labels) . '</td>
  1908. <td>' . V::get('REGON', 'Regon', $labels) . '</td>
  1909. <td>' . V::get('PESEL', 'PESEL', $labels) . '</td>
  1910. <td>' . V::get('Forma_prawna_dzialalnosci', 'Forma prawna działalności', $labels) . '</td>
  1911. <td>' . V::get('Ulica', 'Ulica', $labels) . '</td>
  1912. <td>' . V::get('Numer_budynku', 'Numer budynku', $labels) . '</td>
  1913. <td>' . V::get('Numer_mieszkania_lokalu', 'Numer mieszkania lokalu', $labels) . '</td>
  1914. <td>' . V::get('Miejscowosc', 'Miejscowosc', $labels) . '</td>
  1915. <td>' . V::get('Kod_pocztowy', 'Kod pocztowy', $labels) . '</td>
  1916. <td>' . V::get('Kraj', 'Kraj', $labels) . '</td>
  1917. <td>' . V::get('Telefon', 'Telefon', $labels) . '</td>
  1918. <td>' . V::get('Fax', 'Fax', $labels) . '</td>
  1919. <td>' . V::get('Mail', 'Mail', $labels) . '</td>
  1920. <td>' . V::get('A_ADM_COMPANY', 'A_ADM_COMPANY', $labels) . '</td>
  1921. <td>' . V::get('A_CLASSIFIED', 'A_CLASSIFIED', $labels) . '</td>
  1922. <td>' . V::get('Dodano', 'Dodano', $labels) . '</td>
  1923. <td>' . V::get('Podmiot_dominujacy', 'Podmiot dominujacy', $labels) . '</td>
  1924. <td>' . V::get('Tytul_dokumentu', 'Tytul dokumentu', $labels) . '</td>
  1925. <td>' . V::get('ownCompany', 'ownCompany', $labels) . '</td>
  1926. <td>' . V::get('uwagi', 'uwagi', $labels) . '</td>
  1927. </tr>
  1928. <tr>
  1929. <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>
  1930. <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>
  1931. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Nazwa_grupy_kapitalowej" value="" placeholder="%"></td>
  1932. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Pelna_nazwa_kontrahenta" value="" placeholder="%"></td>
  1933. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Numer_kontrahenta" value="" placeholder="%"></td>
  1934. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Skrocona_Nazwa_Kontrahenta" value="" placeholder="%"></td>
  1935. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Typ_kontrahenta" value="" placeholder="%"></td>
  1936. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_NIP" value="" placeholder="%"></td>
  1937. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_KRS" value="" placeholder="%"></td>
  1938. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_REGON" value="" placeholder="%"></td>
  1939. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_PESEL" value="" placeholder="%"></td>
  1940. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersKontrahenci(event, this)" onKeypress="return onKeypressFiltersKontrahenci(event, this)" type="text" name="f_Forma_prawna_dzialalnosci" 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_Ulica" 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_Numer_budynku" 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_mieszkania_lokalu" 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_Miejscowosc" 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_Kod_pocztowy" 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_Kraj" 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_Telefon" 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_Fax" 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_Mail" 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_A_ADM_COMPANY" 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_A_CLASSIFIED" 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_Dodano" 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_Podmiot_dominujacy" 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_Tytul_dokumentu" 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_ownCompany" 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_uwagi" value="" placeholder="%"></td>
  1957. </tr>
  1958. </thead>
  1959. <tbody id="body-kontrahenci">
  1960. </tbody></table>
  1961. </form>
  1962. ';
  1963. return $view;
  1964. }
  1965. // tworzenie grupy kontrahentów
  1966. public function createKontrahenciGroupAjaxAction() {
  1967. 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
  1968. }
  1969. public function createKontrahenciGroupAjax($args) {
  1970. $nazwa = V::get('NAZWA', '', $args);
  1971. // TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje
  1972. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
  1973. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  1974. 'A_RECORD_CREATE_DATE' => 'NOW()',
  1975. 'NAZWA' => $nazwa,
  1976. 'ID_USER' => User::getID()
  1977. ]);
  1978. return [
  1979. 'msg' => "Utworzona grupę {$idGroup}",
  1980. 'type' => "success",
  1981. 'body' => [
  1982. 'id' => $idGroup,
  1983. 'nazwa' => $nazwa
  1984. ]
  1985. ];
  1986. }
  1987. // Dodanie do grupy filtra kontrahentów
  1988. public function addKontrahenciToGroupAjaxAction() {
  1989. 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
  1990. }
  1991. public function addKontrahenciToGroupAjax($args) {
  1992. $idGroup = V::get('idGroup', '', $args);
  1993. $type = V::get('type', 'ids', $args);
  1994. $kontrahenciIds = V::get('kontrahenciIds', '', $args);
  1995. $filter = V::get('filter', '', $args);
  1996. // validate
  1997. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  1998. switch ($type) {
  1999. case 'ids': {
  2000. if (!$kontrahenciIds || count($kontrahenciIds) == 0) throw new Exception("Proszę wybrać kontrahentów");
  2001. } break;
  2002. case 'filter': {
  2003. if (!isset($args['filter'])) throw new Exception("Proszę wybrać kontrahentów");
  2004. } break;
  2005. default: throw new Exception("Missing type");
  2006. }
  2007. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  2008. 'cols' => [ // TODO:? propertyName = []
  2009. 'ID',
  2010. 'ID_USER',
  2011. 'NAZWA',
  2012. ],
  2013. // 'f_ID_USER' => User::getID()
  2014. ])->getItem($idGroup);
  2015. if (!$group) throw new Exception("Grupa nie istnieje");
  2016. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  2017. if ('filter' === $type) {
  2018. $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  2019. if ($args__idGroup < 0) $args__idGroup = 0;
  2020. $search = V::get('search', '', $args['filter']);
  2021. $searchParams = [];
  2022. if (!empty($search)) {
  2023. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  2024. $searchParams['ogc:Filter'] = '
  2025. <ogc:Filter>
  2026. <ogc:Or>
  2027. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  2028. <ogc:PropertyName>NIP</ogc:PropertyName>
  2029. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2030. </ogc:PropertyIsLike>
  2031. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  2032. <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
  2033. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2034. </ogc:PropertyIsLike>
  2035. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  2036. <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
  2037. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2038. </ogc:PropertyIsLike>
  2039. </ogc:Or>
  2040. </ogc:Filter>
  2041. ';
  2042. }
  2043. $backRefFilter = [];
  2044. if ($args__idGroup > 0) {
  2045. $backRefFilter['__backRef'] = [
  2046. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2047. 'primaryKey' => $args__idGroup,
  2048. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  2049. ];
  2050. }
  2051. $filtersParams = [];
  2052. $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
  2053. return ('f_' === substr($key, 0, 2));
  2054. });
  2055. foreach ($fieldFilterKeys as $key) {
  2056. $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
  2057. }
  2058. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
  2059. $query = $acl->buildQuery(array_merge([
  2060. 'cols' => ['ID'],
  2061. ], $searchParams, $filtersParams, $backRefFilter, [
  2062. 'limit' => 0
  2063. ]));
  2064. $items = $query->getItems();
  2065. $kontrahenciIds = array_map(function ($row) {
  2066. return $row['ID'];
  2067. }, $items);
  2068. }
  2069. ACL::addListRef(
  2070. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2071. $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  2072. $refPrimaryKey = $idGroup,
  2073. $refListRemotePrimaryKey = $kontrahenciIds
  2074. );
  2075. return [
  2076. 'msg' => "Powiązano kontrahentów z grupą {$idGroup}",
  2077. 'type' => "success",
  2078. ];
  2079. }
  2080. public function removePracownicyFromGroupAjaxAction(){
  2081. 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
  2082. }
  2083. public function removePracownicyFromGroupAjax($args){
  2084. $idGroup = V::get('idGroup', 0, $args, "int");
  2085. $pracownicyIds = V::get('pracownicyIds', [], $args, 'array');
  2086. if ($idGroup === 0){
  2087. foreach ($pracownicyIds as $pracownikIds) {
  2088. //TO DO Błąd do naprawienia
  2089. //TO DO sprawdzanie czy już DELETED
  2090. $affected = DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY', 'ID', $pracownikIds, [
  2091. 'A_STATUS' => 'DELETED',
  2092. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  2093. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  2094. ]);
  2095. }
  2096. return [
  2097. 'msg' => "Usunięto osoby z systemu",
  2098. 'type' => "success",
  2099. ];
  2100. } else {
  2101. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  2102. 'cols' => [ // TODO:? propertyName = []
  2103. 'ID',
  2104. 'ID_USER',
  2105. 'NAZWA',
  2106. ],
  2107. // 'f_ID_USER' => User::getID()
  2108. ])->getItem($idGroup);
  2109. if (!$group) throw new Exception("Grupa nie istnieje");
  2110. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  2111. ACL::removeListRef(
  2112. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2113. $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  2114. $refPrimaryKey = $idGroup,
  2115. $refListRemotePrimaryKey = $pracownicyIds
  2116. );
  2117. return [
  2118. 'msg' => "Usunięto osoby z grupy {$idGroup}",
  2119. 'type' => "success",
  2120. ];
  2121. }
  2122. }
  2123. public function removeKontrahenciFromGroupAjaxAction() {
  2124. 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
  2125. }
  2126. public function removeKontrahenciFromGroupAjax($args) {
  2127. $idGroup = V::get('idGroup', 0, $args, "int");
  2128. $kontrahenciIds = V::get('kontrahenciIds', [], $args, 'array');
  2129. if ($idGroup === 0) {
  2130. foreach ($kontrahenciIds as $kontrahentIds) {
  2131. $affected = DB::getPDO()->update('BI_audit_ENERGA_RUM_KONTRAHENCI', 'ID', $kontrahentIds, [
  2132. 'A_STATUS' => 'DELETED',
  2133. 'A_RECORD_UPDATE_DATE' => 'NOW()',
  2134. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  2135. ]);
  2136. }
  2137. return [
  2138. 'msg' => "Usunięto kontrahentów z systemu",
  2139. 'type' => "success",
  2140. ];
  2141. } else {
  2142. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  2143. 'cols' => [ // TODO:? propertyName = []
  2144. 'ID',
  2145. 'ID_USER',
  2146. 'NAZWA',
  2147. ],
  2148. // 'f_ID_USER' => User::getID()
  2149. ])->getItem($idGroup);
  2150. if (!$group) throw new Exception("Grupa nie istnieje");
  2151. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  2152. ACL::removeListRef(
  2153. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2154. $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  2155. $refPrimaryKey = $idGroup,
  2156. $refListRemotePrimaryKey = $kontrahenciIds
  2157. );
  2158. return [
  2159. 'msg' => "Usunięto kontrahentów z grupy {$idGroup}",
  2160. 'type' => "success",
  2161. ];
  2162. }
  2163. }
  2164. public function fetchGroupKontrahenciAjaxAction() {
  2165. Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
  2166. }
  2167. public function fetchGroupKontrahenciAjax() {
  2168. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  2169. 'cols' => [ // TODO:? propertyName = []
  2170. 'ID',
  2171. 'ID_USER',
  2172. 'NAZWA',
  2173. ],
  2174. 'f_ID_USER' => "=" . User::getID(),
  2175. 'f_A_STATUS' => "!DELETED",
  2176. ]);
  2177. $itemsKontrahenci = $query->getItems();
  2178. if (empty($itemsKontrahenci)) throw new AlertWarningException("Grupy nie istnieją");
  2179. $arrayGroupKontrahenci = array();
  2180. foreach ($itemsKontrahenci as $item) {
  2181. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  2182. $arrayGroupKontrahenci[] = [
  2183. 'NAZWA' => $item['NAZWA'],
  2184. 'ID' => $item['ID'],
  2185. ];
  2186. }
  2187. return [
  2188. 'type' => 'success',
  2189. 'msg' => 'fetchGroupKontrahenciAjax',
  2190. '__req_args' => $_REQUEST,
  2191. '__args' => $args,
  2192. 'body' => [
  2193. 'itemsGroupKontrahenci' => $arrayGroupKontrahenci
  2194. ]
  2195. ];
  2196. }
  2197. public function fetchPracownicyIdsAjaxAction() {
  2198. Response::sendTryCatchJson(array($this, 'fetchPracownicyIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  2199. }
  2200. public function fetchPracownicyIdsAjax($args) {
  2201. $idGroup = V::get('filter_idGroup', 0, $args, 'int');
  2202. if ($idGroup < 0) $idGroup = 0;
  2203. $backRefFilter = [];
  2204. if ($idGroup > 0) {
  2205. $backRefFilter['__backRef'] = [
  2206. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2207. 'primaryKey' => $idGroup,
  2208. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  2209. ];
  2210. }
  2211. $searchParams = []; // TODO: ???
  2212. $filtersParams = [];
  2213. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  2214. return ('f_' === substr($key, 0, 2));
  2215. });
  2216. foreach ($fieldFilterKeys as $key) {
  2217. $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  2218. }
  2219. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  2220. $query = $acl->buildQuery(array_merge([
  2221. 'cols' => [
  2222. 'ID',
  2223. ],
  2224. //'f_ID' => $id,
  2225. 'limit' => 0,
  2226. // 'limitstart' => $limitstart, // offset
  2227. // 'order_by' => 'ID', // sortowanie po kolumnie
  2228. // 'order_dir' => 'DESC', // kierunek sortowania
  2229. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  2230. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  2231. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  2232. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  2233. ], $searchParams, $filtersParams, $backRefFilter));
  2234. // $total = $query->getTotal();
  2235. $items = $query->getItems();
  2236. return [
  2237. 'type' => 'success',
  2238. 'msg' => 'pracownicy ids',
  2239. 'body' => [
  2240. 'ids' => array_map( V::makePick('ID'), $items ),
  2241. ],
  2242. '__args' => $args,
  2243. '__DBG_$idGroup' => $idGroup,
  2244. '__DBG_$filtersParams' => $filtersParams,
  2245. '__DBG_$backRefFilter' => $backRefFilter,
  2246. ];
  2247. }
  2248. /*
  2249. * PRACOWNICY
  2250. */
  2251. public function fetchPracownicyAjaxAction() {
  2252. Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'), $args = $_REQUEST);
  2253. }
  2254. public function fetchPracownicyAjax($args) {
  2255. $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  2256. if ($idGroup < 0) $idGroup = 0;
  2257. $limit = 20;
  2258. $page = V::get('page', 0, $args, 'int');
  2259. $limitstart = ($page - 1) * $limit;
  2260. $search = V::get('search', '', $args);
  2261. $searchParams = [];
  2262. if (!empty($search)) {
  2263. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  2264. $searchParams['ogc:Filter'] = '
  2265. <ogc:Filter>
  2266. <ogc:Or>
  2267. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  2268. <ogc:PropertyName>nip</ogc:PropertyName>
  2269. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2270. </ogc:PropertyIsLike>
  2271. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  2272. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  2273. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2274. </ogc:PropertyIsLike>
  2275. </ogc:Or>
  2276. </ogc:Filter>
  2277. ';
  2278. }
  2279. $backRefFilter = [];
  2280. if ($idGroup > 0) {
  2281. $backRefFilter['__backRef'] = [
  2282. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2283. 'primaryKey' => $idGroup,
  2284. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  2285. ];
  2286. }
  2287. $filtersParams = [];
  2288. $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
  2289. return ('f_' === substr($key, 0, 2));
  2290. });
  2291. foreach ($fieldFilterKeys as $key) {
  2292. if ('f_ID' === $key) $filtersParams[ $key ] = '=' . $args[ $key ];
  2293. else $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
  2294. }
  2295. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  2296. $query = $acl->buildQuery(array_merge([
  2297. 'cols' => array_merge(self::$FIELD_LIST_PRACOWNICY, [
  2298. 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
  2299. ]),
  2300. //'f_ID' => $id,
  2301. 'limit' => $limit,
  2302. 'limitstart' => $limitstart, // offset
  2303. 'order_by' => 'ID', // sortowanie po kolumnie
  2304. 'order_dir' => 'DESC', // kierunek sortowania
  2305. // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
  2306. // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
  2307. // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
  2308. // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
  2309. ], $searchParams, $filtersParams, $backRefFilter));
  2310. $total = $query->getTotal();
  2311. $items = $query->getItems();
  2312. $pagination = array();
  2313. $pagination['total_items'] = $total;
  2314. $pagination['size'] = ceil($total/$limit); // pages size
  2315. $pagination['current'] = $page;
  2316. $pagination['limit'] = $limit;
  2317. // $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  2318. if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
  2319. // { // tworzenie własnego zapytanie mysql
  2320. // $rootTableName = $acl->getRootTableName();
  2321. // DB::getPDO()->fetchAll("
  2322. // select t.*
  2323. // from {$rootTableName} t
  2324. // where t.ID in (
  2325. // select x.ID
  2326. // from ... x
  2327. // where
  2328. // )
  2329. // ");
  2330. // }
  2331. return [
  2332. 'type' => 'success',
  2333. 'msg' => 'showPracownicy',
  2334. 'body' => [
  2335. 'items' => $items,
  2336. //'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
  2337. 'pagination' => $pagination
  2338. ],
  2339. '__DBG_$idGroup' => $idGroup,
  2340. '__DBG_$filtersParams' => $filtersParams,
  2341. '__DBG_$backRefFilter' => $backRefFilter,
  2342. ];
  2343. }
  2344. public function showTablePracownicy($labels = []) {
  2345. // TODO: use self::$FIELD_LIST_PRACOWNICY
  2346. $view = '<form class="form-horizontal" method="post">
  2347. <table class="table table-responsive table-bordered table-hover table-striped" height=5>
  2348. <thead>
  2349. <tr>
  2350. <td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
  2351. <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
  2352. <td>' . V::get('imiona', 'Imię/Imiona', $labels) . '</td>
  2353. <td>' . V::get('nazwisko', 'Nazwisko', $labels) . '</td>
  2354. <td>' . V::get('nip', 'NIP', $labels) . '</td>
  2355. <td>' . V::get('pesel', 'Pesel', $labels) . '</td>
  2356. <td>' . V::get('regon', 'Regon', $labels) . '</td>
  2357. <td>' . V::get('source', 'source', $labels) . '</td>
  2358. <td>' . V::get('jednostka_organizacyjna', 'jednostka_organizacyjna', $labels) . '</td>
  2359. <td>' . V::get('A_STATUS', 'A_STATUS', $labels) . '</td>
  2360. <td>' . V::get('A_STATUS_INFO', 'A_STATUS_INFO', $labels) . '</td>
  2361. <td>' . V::get('L_APPOITMENT_USER', 'L_APPOITMENT_USER', $labels) . '</td>
  2362. <td>' . V::get('Adresy', 'Adresy', $labels) . '</td>
  2363. </tr>
  2364. <tr>
  2365. <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>
  2366. <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>
  2367. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_imiona" value="" placeholder="%"></td>
  2368. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_nazwisko" value="" placeholder="%"></td>
  2369. <td style="padding:0"><input style="padding:2px 8px; width:100%" onChange="return onChangeFiltersPracownicy(event, this)" onKeypress="return onKeypressFiltersPracownicy(event, this)" type="text" name="f_nip" value="" placeholder="%"></td>
  2370. <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>
  2371. <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>
  2372. <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>
  2373. <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>
  2374. <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>
  2375. <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>
  2376. <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>
  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_Adresy" value="" placeholder="%"></td>
  2378. </tr>
  2379. </thead>
  2380. <tbody id="body-pracownicy">
  2381. </tbody></table>
  2382. </form>';
  2383. return $view;
  2384. }
  2385. // tworzenie grupy pracowników
  2386. public function createPracownicyGroupAjaxAction() {
  2387. 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
  2388. }
  2389. public function createPracownicyGroupAjax($args) {
  2390. $nazwa = V::get('NAZWA', '', $args);
  2391. // validate
  2392. if (!$nazwa) throw new Exception("Nie wybrano grupa");
  2393. $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
  2394. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  2395. 'A_RECORD_CREATE_DATE' => 'NOW()',
  2396. 'NAZWA' => $nazwa,
  2397. 'ID_USER' => User::getID()
  2398. ]);
  2399. return [
  2400. 'msg' => "Utworzona grupę {$nazwa}",
  2401. 'type' => "success",
  2402. 'body' => [
  2403. 'id' => $idGroup,
  2404. 'nazwa' => $nazwa
  2405. ]
  2406. ];
  2407. }
  2408. // Dodanie do grupy filtra pracowników
  2409. public function addPracownicyToGroupAjaxAction() {
  2410. 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
  2411. }
  2412. public function addPracownicyToGroupAjax($args) {
  2413. $idGroup = V::get('idGroup', '', $args);
  2414. $type = V::get('type', 'ids', $args);
  2415. $pracownicyIds = V::get('pracownicyIds', '', $args);
  2416. $filter = V::get('filter', '', $args);
  2417. // validate
  2418. if (!$idGroup) throw new Exception("Nie wybrano grupa");
  2419. switch ($type) {
  2420. case 'ids': {
  2421. if (!$pracownicyIds || count($pracownicyIds) == 0) throw new Exception("Proszę wybrać pracowników");
  2422. } break;
  2423. case 'filter': {
  2424. if (empty($filter)) throw new Exception("Proszę wybrać pracowników");
  2425. } break;
  2426. default: throw new Exception("Missing type");
  2427. }
  2428. // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
  2429. // default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
  2430. // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
  2431. $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  2432. 'cols' => [ // TODO:? propertyName = []
  2433. 'ID',
  2434. 'ID_USER',
  2435. 'NAZWA',
  2436. ],
  2437. // 'f_ID_USER' => User::getID()
  2438. ])->getItem($idGroup);
  2439. if (!$group) throw new Exception("Grupa nie istnieje");
  2440. if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
  2441. if ('filter' === $type) {
  2442. $args__idGroup = V::get('filterIdGroup', 0, $filter, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
  2443. if ($args__idGroup < 0) $args__idGroup = 0;
  2444. $search = V::get('search', '', $filter);
  2445. $searchParams = [];
  2446. if (!empty($search)) {
  2447. $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
  2448. $searchParams['ogc:Filter'] = '
  2449. <ogc:Filter>
  2450. <ogc:Or>
  2451. <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
  2452. <ogc:PropertyName>nip</ogc:PropertyName>
  2453. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2454. </ogc:PropertyIsLike>
  2455. <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
  2456. <ogc:PropertyName>nazwisko</ogc:PropertyName>
  2457. <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
  2458. </ogc:PropertyIsLike>
  2459. </ogc:Or>
  2460. </ogc:Filter>
  2461. ';
  2462. }
  2463. $backRefFilter = [];
  2464. if ($args__idGroup > 0) {
  2465. $backRefFilter['__backRef'] = [
  2466. 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2467. 'primaryKey' => $args__idGroup,
  2468. 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  2469. ];
  2470. }
  2471. $filtersParams = [];
  2472. $fieldFilterKeys = array_filter(array_keys($filter), function ($key) {
  2473. return ('f_' === substr($key, 0, 2));
  2474. });
  2475. foreach ($fieldFilterKeys as $key) {
  2476. $filtersParams[ $key ] = '%' . $filter[ $key ] . '%';
  2477. }
  2478. $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
  2479. $query = $acl->buildQuery(array_merge([
  2480. 'cols' => ['ID'],
  2481. ], $searchParams, $filtersParams, $backRefFilter, [
  2482. 'limit' => 0
  2483. ]));
  2484. $items = $query->getItems();
  2485. $pracownicyIds = array_map(function ($row) {
  2486. return $row['ID'];
  2487. }, $items);
  2488. }
  2489. ACL::addListRef(
  2490. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
  2491. $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  2492. $refPrimaryKey = $idGroup,
  2493. $refListRemotePrimaryKey = $pracownicyIds
  2494. );
  2495. return [
  2496. 'msg' => "Powiązano pracowników z grupą {$idGroup}",
  2497. 'type' => "success",
  2498. ];
  2499. }
  2500. public function fetchGroupPracownicyAjaxAction() {
  2501. Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
  2502. }
  2503. public function fetchGroupPracownicyAjax() {
  2504. $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
  2505. 'cols' => [ // TODO:? propertyName = []
  2506. 'ID',
  2507. 'ID_USER',
  2508. 'NAZWA',
  2509. ],
  2510. 'f_ID_USER' => "=" . User::getID(), // szukamy dokładnie tej wartości - mysql: where ID_USER = "1"
  2511. 'f_A_STATUS' => "!DELETED", // `A_STATUS` != 'DELETED'
  2512. ]);
  2513. $items = $query->getItems();
  2514. DBG::log($items,'array',"grupy");
  2515. if (empty($items)) throw new AlertWarningException("Grupy nie istnieją");
  2516. $arrayGroupPracownicy = array();
  2517. foreach ($items as $item) {
  2518. // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy"); // or skip - continue;
  2519. $arrayGroupPracownicy[] = [
  2520. 'ID' => $item['ID'],
  2521. 'NAZWA' => $item['NAZWA'],
  2522. ];
  2523. }
  2524. return [
  2525. 'type' => 'success',
  2526. 'msg' => 'fetchGroupPracownicyAjax',
  2527. '__req_args' => $_REQUEST,
  2528. '__args' => $args,
  2529. 'body' => [
  2530. 'itmesGroupPracownicy' => $arrayGroupPracownicy
  2531. ]
  2532. ];
  2533. }
  2534. function mapShortNs($shortNs) {
  2535. switch ($shortNs) {
  2536. case 'KRS': return 'default_db/BI_audit_KRS/BI_audit_KRS';
  2537. case 'KRS/p': return 'default_db/BI_audit_KRS_person/BI_audit_KRS_person';
  2538. case 'MSIG': return 'default_db/BI_audit_MSIG/BI_audit_MSIG';
  2539. case 'MSIG/p': return 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person';
  2540. case 'CEIDG': return 'default_db/BI_audit_CEIDG/BI_audit_CEIDG';
  2541. default: throw new Exception("Not implemented short Ns '{$shortNs}'");
  2542. }
  2543. }
  2544. public function generateBiAuditRaportAjaxAction() {
  2545. Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  2546. }
  2547. public function generateBiAuditRaportAjax($args) {
  2548. $depthValue = V::get('depthValue', '', $args);
  2549. if (!$depthValue) {
  2550. throw new Exception("Nie podano wartości dla głębokości powiązań");
  2551. }
  2552. $smadReaportTitle = V::get('smadReaportTitle', '', $args);
  2553. if (!$smadReaportTitle) {
  2554. throw new Exception("Nie podano tytułu raportu");
  2555. }
  2556. $analizaOnlyTargets = V::get('analizaOnlyTargets', '', $args);
  2557. if (!$analizaOnlyTargets) {
  2558. throw new Exception("Nie podano wartości czy zwracać wyniki tylko z obiektami docelowymi");
  2559. }
  2560. $pracownicyIds = V::get('pracownicyIds', [], $args, 'uint_array'); // array of int > 0
  2561. $kontrahenciIds = V::get('kontrahenciIds', [], $args, 'uint_array'); // array of int > 0
  2562. $pozostaleOd = V::get('pozostaleOd', [], $args, 'array');
  2563. $pozostaleDo = V::get('pozostaleDo', [], $args, 'array');
  2564. $allOdLength = count($pracownicyIds) + count($pozostaleOd);
  2565. $allDoLength = count($kontrahenciIds) + count($pozostaleDo);
  2566. // walidacja listy kontrahentów i pracowników
  2567. if ( !$allOdLength && !$allDoLength ) {
  2568. throw new Exception("Nie wybrano pozycji do analizy. Wybierz pracowników/kontrahentów.");
  2569. }
  2570. // TODO: analizaOnlyTargets = ( 'y' | 'n' ) - allDoLength should depend of analizaOnlyTargets?
  2571. // Tworzenie rekrodu w bazie - Raport -
  2572. $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
  2573. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  2574. 'A_RECORD_CREATE_DATE' => 'NOW()',
  2575. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  2576. 'FILE_STATUS' => "TO_GENERATE",
  2577. 'A_STATUS' => "NORMAL",
  2578. 'BI_analiza_minDepth' => 1,
  2579. 'BI_analiza_maxDepth' => $depthValue,
  2580. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  2581. ]);
  2582. if ($idRaport <= 0) throw new Exception("Nie udało się dodać nowego raportu");
  2583. DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_HIST', [
  2584. 'ID_USERS2' => $idRaport,
  2585. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  2586. 'A_RECORD_CREATE_DATE' => 'NOW()',
  2587. 'L_APPOITMENT_INFO' => $smadReaportTitle,
  2588. 'FILE_STATUS' => "TO_GENERATE",
  2589. 'A_STATUS' => "NORMAL",
  2590. 'BI_analiza_minDepth' => 1,
  2591. 'BI_analiza_maxDepth' => $depthValue,
  2592. 'BI_analiza_onlyTargets' => $analizaOnlyTargets
  2593. ]);
  2594. if (!empty($pracownicyIds)) {
  2595. ACL::addListRef(
  2596. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  2597. $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
  2598. $refPrimaryKey = $idRaport,
  2599. $refListRemotePrimaryKey = $pracownicyIds
  2600. );
  2601. }
  2602. if (!empty($kontrahenciIds)) {
  2603. ACL::addListRef(
  2604. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  2605. $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
  2606. $refPrimaryKey = $idRaport,
  2607. $refListRemotePrimaryKey = $kontrahenciIds
  2608. );
  2609. }
  2610. if (!empty($pozostaleOd)) {
  2611. foreach ($pozostaleOd as $featureKey) {
  2612. $idOd = DB::getPDO()->insert('BI_audit_POWIAZANIA_OD', [
  2613. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  2614. 'A_RECORD_CREATE_DATE' => 'NOW()',
  2615. ]);
  2616. // TODO: ? add OD_HIST
  2617. ACL::addRef(
  2618. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  2619. $fieldTypeName = 'default_db__x3A__BI_audit_POWIAZANIA_OD:BI_audit_POWIAZANIA_OD',
  2620. $refPrimaryKey = $idRaport,
  2621. $refRemotePrimaryKey = $idOd
  2622. );
  2623. list($shortNs, $featurePk) = explode('.', $featureKey);
  2624. $featureNs = $this->mapShortNs($shortNs);
  2625. ACL::addRef(
  2626. $rootObjectNamespace = 'default_db/BI_audit_POWIAZANIA_OD/BI_audit_POWIAZANIA_OD',
  2627. $fieldTypeName = Api_WfsNs::typeName($featureNs),
  2628. $refPrimaryKey = $idOd,
  2629. $refRemotePrimaryKey = $featurePk
  2630. );
  2631. }
  2632. }
  2633. if (!empty($pozostaleDo)) {
  2634. foreach ($pozostaleDo as $featureKey) {
  2635. $idDo = DB::getPDO()->insert('BI_audit_POWIAZANIA_DO', [
  2636. 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
  2637. 'A_RECORD_CREATE_DATE' => 'NOW()',
  2638. ]);
  2639. // TODO: ? add DO_HIST
  2640. ACL::addRef(
  2641. $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  2642. $fieldTypeName = 'default_db__x3A__BI_audit_POWIAZANIA_DO:BI_audit_POWIAZANIA_DO',
  2643. $refPrimaryKey = $idRaport,
  2644. $refRemotePrimaryKey = $idDo
  2645. );
  2646. list($shortNs, $featurePk) = explode('.', $featureKey);
  2647. $featureNs = $this->mapShortNs($shortNs);
  2648. ACL::addRef(
  2649. $rootObjectNamespace = 'default_db/BI_audit_POWIAZANIA_DO/BI_audit_POWIAZANIA_DO',
  2650. $fieldTypeName = Api_WfsNs::typeName($featureNs),
  2651. $refPrimaryKey = $idDo,
  2652. $refRemotePrimaryKey = $featurePk
  2653. );
  2654. }
  2655. }
  2656. return [
  2657. 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
  2658. 'type' => "success",
  2659. 'body' => [
  2660. 'id' => $idRaport,
  2661. ]
  2662. ];
  2663. }
  2664. /**
  2665. * Widok formularza dodawania pracowników i kontrahentów
  2666. */
  2667. public function defaultViewFormBiAudit($items, $type) {
  2668. $activeFormSteps = '';
  2669. $fieldLabels = [];
  2670. $currentDate = date("j.n.Y");
  2671. $btnGrafPowiazan = '';
  2672. switch ($type) {
  2673. 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;
  2674. 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;
  2675. }
  2676. $formFilterHeadDesc = '';
  2677. switch ($type) {
  2678. case 'PRACOWNICY': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span>'; break;
  2679. case 'KONTRAHENCI': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span>'; break;
  2680. case 'OPERACYJNA_BAZA_ZGLOSZEN': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span>'; break;
  2681. }
  2682. $formAddNewData = '';
  2683. switch($type) {
  2684. case 'KONTRAHENCI':
  2685. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
  2686. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci" style="margin-top:0">Wszyscy</h2>';
  2687. $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>';
  2688. $graphView = '<div class="smad-kontrahenci-graph-view" id="smad-kontrahenci-graph-view" style="display: none;"></div>';
  2689. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  2690. // $formAddNewData ='
  2691. // <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  2692. // <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
  2693. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  2694. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  2695. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  2696. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  2697. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  2698. $fieldList = $acl->getRealFieldList();
  2699. $fieldLabels = array_combine(
  2700. $fieldList,
  2701. array_map(function ($fieldName) use ($acl) {
  2702. return $acl->getFieldLabel($fieldName);
  2703. }, $fieldList)
  2704. );
  2705. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  2706. break;
  2707. case 'OPERACYJNA_BAZA_ZGLOSZEN':
  2708. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
  2709. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci" style="margin-top:0">Wszyscy</h2>';
  2710. $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>';
  2711. $graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
  2712. $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
  2713. // $formAddNewData ='
  2714. // <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
  2715. // <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
  2716. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  2717. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  2718. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  2719. $pagination_form = '<div id="pagination-kontrahenci"></div>';
  2720. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
  2721. $fieldList = $acl->getRealFieldList();
  2722. $fieldLabels = array_combine(
  2723. $fieldList,
  2724. array_map(function ($fieldName) use ($acl) {
  2725. return $acl->getFieldLabel($fieldName);
  2726. }, $fieldList)
  2727. );
  2728. DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
  2729. break;
  2730. case 'PRACOWNICY':
  2731. $formSmadSelectTarget = '<select class="form-control" id="smad-select-target"><option value="y">tak</option><option value="n">nie</option></select>';
  2732. $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-pracownicy" style="margin-top:0">Wszyscy</h2>';
  2733. $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>';
  2734. $graphView = '<div class="smad-pracownicy-graph-view" id="smad-pracownicy-graph-view" style="display: none;"></div>';
  2735. $csvExamplePracownicy = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/pracownicy_example.zip';
  2736. // $formAddNewData ='
  2737. // <li><a title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import osób\', \'pracownicy\', \'yes\', \''.$csvExamplePracownicy.'\' )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
  2738. // <li><a title="DODAJ PRACOWNIKÓW" onClick="createPracownikAjax(event)" class="btn btn-info" >+ DODAJ OSOBĘ</a></li>'; //todo: dodać obsługe doddawania pracownikow
  2739. $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
  2740. $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addPracownikAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
  2741. $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removePracownikFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
  2742. $pagination_form = '<div id="pagination-pracownicy"></div>';
  2743. $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY");
  2744. $fieldList = $acl->getRealFieldList();
  2745. $fieldLabels = array_combine(
  2746. $fieldList,
  2747. array_map(function ($fieldName) use ($acl) {
  2748. return $acl->getFieldLabel($fieldName);
  2749. }, $fieldList)
  2750. );
  2751. DBG::log($fieldLabels, 'array', "fieldLabels (PRACOWNICY)");
  2752. break;
  2753. }
  2754. $outLinkOD = $this->getLink() . "#PRACOWNICY";
  2755. $outLinkDO = $this->getLink() . "#KONTRAHENCI";
  2756. $outStepOdCompleted = 'complete';
  2757. $outStepDoCompleted = '';
  2758. switch ($type) {
  2759. case 'KONTRAHENCI': $outStepDoCompleted = 'complete'; break;
  2760. case 'OPERACYJNA_BAZA_ZGLOSZEN': $outStepDoCompleted = 'complete'; break;
  2761. }
  2762. $outHeaderTitle = '';
  2763. switch ($type) {
  2764. case 'KONTRAHENCI': $outHeaderTitle = 'Kontrahenci'; break;
  2765. case 'OPERACYJNA_BAZA_ZGLOSZEN': $outHeaderTitle = 'KONTRAHENCI/PODMIOTY'; break;
  2766. case 'PRACOWNICY': $outHeaderTitle = 'Pracownicy'; break;
  2767. }
  2768. $groupFilterList = '';
  2769. switch($type) {
  2770. case 'PRACOWNICY':
  2771. $groupFilterList .= '
  2772. <a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a>
  2773. <div id="group-pracownicy" class="btn-group" style="margin-left:12px">
  2774. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  2775. </div>
  2776. ';
  2777. break;
  2778. case 'KONTRAHENCI':
  2779. $groupFilterList .= '
  2780. <a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a>
  2781. <div id="group-kontrahenci" class="btn-group" style="margin-left:12px">
  2782. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  2783. </div>
  2784. ';
  2785. break;
  2786. case 'OPERACYJNA_BAZA_ZGLOSZEN':
  2787. $groupFilterList .= '
  2788. <a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a>
  2789. <div id="group-kontrahenci" class="btn-group" style="margin-left:12px">
  2790. <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
  2791. </div>
  2792. ';
  2793. break;
  2794. }
  2795. $groupFilterList = '
  2796. <h4 style="margin-top:0; margin-bottom:24px" class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $outHeaderTitle . ' </h4>
  2797. <div>
  2798. '.$groupFilterList.'
  2799. </div>
  2800. ';
  2801. $view = '';
  2802. $view .= '<div id="smad-employees-section" class="smad-form-' . $type . '" >';
  2803. $view .= '
  2804. <div class="container-fluid" style="margin-bottom:32px; margin-top:32px">
  2805. <div class="row">
  2806. <div class="col-md-12">
  2807. '.$groupFilterList.'
  2808. </div>
  2809. </div>
  2810. </div>
  2811. <div class="container-fluid">
  2812. <div class="padding-0 smad-employees-list-head">
  2813. <div class="col-md-8">
  2814. <header>
  2815. '.$formFilterHeadTitle.'
  2816. </header>
  2817. <div class="desc">
  2818. <p style="text-align:left">'.$formFilterHeadDesc.'</p>
  2819. </div>
  2820. <div class="countSelectedItem">
  2821. '.$countSelectedItem.'
  2822. </div>
  2823. </div>
  2824. <div class="col-md-4">
  2825. <div class="menu-items">
  2826. <div class="menu-item">
  2827. <ul class="padding-0">
  2828. '.$formAddNewData.'
  2829. </ul>
  2830. </div>
  2831. </div>
  2832. <div style="position:absolute; bottom:0; right:24px">
  2833. '.$btnGrafPowiazan.'
  2834. </div>
  2835. </div>
  2836. </div>
  2837. </div>
  2838. <div class="smad-graph-section">
  2839. <div class="container-fluid">
  2840. '.$graphView.'
  2841. </div>
  2842. </div>
  2843. <div class="container-fluid">
  2844. <div class="table-responsive padding-0" id="smad-table-' . $type . '">
  2845. ' . $this->showListDataByType($items, $type, $fieldLabels) . '
  2846. </div>
  2847. </div>
  2848. <div class="container-fluid ">
  2849. <div>
  2850. '. $pagination_form .'
  2851. </div>
  2852. </div>
  2853. <div class="container-fluid smad-employees-bottom-navigation">
  2854. <div class="padding-0">
  2855. <div class="col-md-12">
  2856. '.$buttonMoveToGroup.'
  2857. </div>
  2858. </div>
  2859. </div>
  2860. </div>
  2861. ';
  2862. return $view;
  2863. }
  2864. public function showListDataByType($items, $type='PRACOWNICY', $labels) {
  2865. switch ($type) {
  2866. case 'PRACOWNICY':
  2867. return $this->showTablePracownicy($labels);
  2868. break;
  2869. case 'KONTRAHENCI':
  2870. return $this->showTableKontrahenci($labels);
  2871. break;
  2872. }
  2873. }
  2874. function fetchProgressAjaxAction() {
  2875. Response::sendTryCatchJson(array($this, 'fetchProgressAjax'), $args = 'JSON_FROM_REQUEST_BODY');
  2876. }
  2877. function fetchProgressAjax($args) {
  2878. $DBG_FAKE_ANIM = false;
  2879. if (empty($args['ids'])) return [ 'msg' => "empty ids", 'type' => "success" ];
  2880. $ids = $args['ids'];
  2881. if ('last' === $ids) {
  2882. $ids = [
  2883. DB::getPDO()->fetchValue(" select ID from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA order by ID DESC limit 1 ")
  2884. ];
  2885. }
  2886. // private static function getDirectory($table, $id) {
  2887. $firstId = reset($ids);
  2888. {
  2889. Lib::loadClass('FoldersConfig');
  2890. $folderConf = FoldersConfig::getAll('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_COLUMN');
  2891. if (!isset($folderConf['mount_point'])) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$errMsg}", 404);
  2892. $rootPath = $folderConf['mount_point'];
  2893. }
  2894. $statuses = array_map(function ($id) {
  2895. return DB::getPDO()->fetchValue(" select FILE_STATUS from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  2896. }, $ids);
  2897. $statusesInfo = array_map(function ($id) {
  2898. return DB::getPDO()->fetchValue(" select FILE_STATUS_info from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
  2899. }, $ids);
  2900. $progress = array_map(function ($id, $idx) use ($rootPath, $statuses, $DBG_FAKE_ANIM) {
  2901. DBG::log("Loop id({$id}) is-eq-82(".(82 == $id).") is-eq-'82'(".("82"==$id).")");
  2902. DBG::log("Loop id({$id}) is-eq-80(".(80 == $id).") is-eq-'80'(".("80"==$id).")");
  2903. $status = $statuses[$idx];
  2904. if ($DBG_FAKE_ANIM && 82 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2905. if ($DBG_FAKE_ANIM && 80 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2906. if ($DBG_FAKE_ANIM && 77 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
  2907. DBG::log("Loop id({$id}) status({$status})...");
  2908. if ('GENERATED' === $status) return 1;
  2909. if ('IN_PROGRESS' !== $status) return 0;
  2910. if (!file_exists("{$rootPath}/.tasks/generatePowiazania-{$id}.progress")) return 0;
  2911. DBG::log("Loop id({$id}) status({$status}) progress file exists");
  2912. try {
  2913. $cnt = file_get_contents("{$rootPath}/.tasks/generatePowiazania-{$id}.progress");
  2914. $json = @json_decode($cnt, $assoc = true);
  2915. if (null === $json && 0 !== json_last_error()) {
  2916. throw new Exception("Parse json error for restrictions: " . json_last_error());
  2917. }
  2918. // $json['summary']['step']: 'initialize', 'relations', 'reports'
  2919. // $json['summary']['step'] = 'initialize' - recache - skip
  2920. // $json['summary']['step'] = 'relations' - szuka powiązań (@see AVG(details.progress / summary.count))
  2921. // $json['summary']['step'] = 'reports' - generuje pliki (@see summary.created)
  2922. /*
  2923. if ($DBG_FAKE_ANIM && 82 == $id) { // TODO: DBG
  2924. $json = [
  2925. 'summary' => [
  2926. 'count' => 4,
  2927. 'step' => 'relations',
  2928. ],
  2929. 'details' => [
  2930. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2931. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2932. '22' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2933. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2934. ] ];
  2935. }
  2936. */
  2937. if ($DBG_FAKE_ANIM && 80 == $id) { // TODO: DBG
  2938. $json = [
  2939. 'summary' => [
  2940. 'count' => 4,
  2941. 'created' => 2,
  2942. 'step' => 'reports',
  2943. ],
  2944. 'details' => [
  2945. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2946. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2947. '22' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2948. '25' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2949. ] ];
  2950. }
  2951. if ($DBG_FAKE_ANIM && 77 == $id) { // TODO: DBG
  2952. $json = [
  2953. 'summary' => [
  2954. 'count' => 4,
  2955. 'created' => 2,
  2956. 'step' => 'relations',
  2957. ],
  2958. 'details' => [
  2959. '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2960. '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2961. '22' => [ 'progress' => 0.25, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2962. '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
  2963. ] ];
  2964. }
  2965. DBG::log($json, 'array', "Loop id({$id}) status({$status}) progress json");
  2966. if (empty($json['summary'])) return 0;
  2967. if (empty($json['summary']['count'])) return 0;
  2968. if (empty($json['summary']['step'])) return 0;
  2969. if (empty($json['details'])) return 0;
  2970. $listDetailsProgress = array_map(function ($detail) {
  2971. return floatval($detail['progress']);
  2972. }, $json['details']);
  2973. $relationsProgress = $json['summary']['count'] > 0 ? round(floatval(array_sum($listDetailsProgress)) / floatval($json['summary']['count']), 3) : 0;
  2974. $reportsCount = V::get('reportsCount', 0, $json['summary'], 'float');
  2975. $reportsProgress = $reportsCount > 0 ? round(V::get('reportsCreated', 0, $json['summary'], 'float') / $reportsCount, 3) : 0;
  2976. return round(0.5 * $relationsProgress + 0.5 * $reportsProgress, 3);
  2977. } catch (Exception $e) {
  2978. DBG::log($e);
  2979. }
  2980. return 0;
  2981. }, $ids, array_keys($ids));
  2982. return [ 'msg' => "DBG ids set", 'type' => "success", 'body' => [
  2983. 'ids' => $ids,
  2984. 'progress' => $progress,
  2985. 'statuses' => $statuses,
  2986. 'statusesInfo' => $statusesInfo,
  2987. ] ];
  2988. }
  2989. }