Bocian.php 131 KB

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