Bocian.php 131 KB

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