Bocian.php 130 KB

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