Bocian.php 135 KB

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