Bocian.php 131 KB

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