Anton1.php 135 KB

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