Bocian.php 130 KB

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