Bocian.php 135 KB

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