Bocian.php 138 KB

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