Bocian.php 138 KB

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