Bocian.php 135 KB

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