Bocian.php 129 KB

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