123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315 |
- <?php
- Lib::loadClass('RouteToolBase');
- Lib::loadClass('UI');
- Lib::loadClass('Response');
- Lib::loadClass('Request');
- // index.php?_route=UrlAction_Bocian - uruchamia defaultAction
- class RouteTool_Bocian extends RouteToolBase {
- public static $helpEmailTo = 'biuro@bialnet.com.pl'; // todo:email na który zostanie wysłane zapytanie z formularza POMOCY
- public static $FIELD_LIST_PRACOWNICY = [
- 'ID',
- 'imiona',
- 'nazwisko',
- 'nip',
- 'pesel',
- 'regon',
- 'source',
- 'jednostka_organizacyjna',
- 'A_STATUS',
- 'A_STATUS_INFO',
- 'L_APPOITMENT_USER',
- // 'Adresy' // 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
- ];
- public static $FIELD_LIST_KONTRAHENCI = [
- 'ID',
- 'Nazwa_grupy_kapitalowej',
- 'Pelna_nazwa_kontrahenta',
- 'Numer_kontrahenta',
- 'Skrocona_Nazwa_Kontrahenta',
- 'Typ_kontrahenta',
- 'NIP',
- 'KRS',
- 'REGON',
- 'PESEL',
- 'Forma_prawna_dzialalnosci',
- 'Ulica',
- 'Numer_budynku',
- 'Numer_mieszkania_lokalu',
- 'Miejscowosc',
- 'Kod_pocztowy',
- 'Kraj',
- 'Telefon',
- 'Fax',
- 'Mail',
- 'A_ADM_COMPANY',
- 'A_CLASSIFIED',
- 'Dodano',
- 'Podmiot_dominujacy',
- 'Tytul_dokumentu',
- 'ownCompany',
- 'uwagi',
- ];
- function aboutAction() { $this->sendPageView('page-about.view.php'); }
- function trainingAction() { $this->sendPageView('page-training.view.php'); }
- function offerAction() { $this->sendPageView('page-offer.view.php'); }
- function helpFormAction() { $this->sendPageView('page-help.view.php', [ $this, '_helpFormBeforeViewTrigger' ]); }
- function _helpFormBeforeViewTrigger($args) {
- $messageValidate = array();
- if ( V::get('button_send', 0, $args) == 1 ) {
- // fields form
- $helpName = htmlentities(V::get('help_name', 0, $args));
- $helpEmail = htmlentities(V::get('help_email', 0, $args));
- $helpDescription = htmlentities(V::get('help_description', 0, $args));
- if ( empty($helpDescription) && !filter_var($helpEmail, FILTER_VALIDATE_EMAIL)) {
- $messageValidate['error'] = 1;
- }
- $noticeRequest = 'Email: ' . $helpEmail . "; Treść zgłoszenia: " . $helpDescription;
- // data for create insert in DB
- $idQualityNotice = DB::getPDO()->insert('QUALITY_NOTICES', [
- 'NOTICE_INITIAL_TYPE' => 'BAD_PROCESS',
- 'ID_PROCES' => '1', //todo: ustalić ID procesu - ustawiłem defaultowo 1!!!!!
- 'NOTICE_REQUEST' => $noticeRequest,
- 'NOTICE_REPLY' => '',
- 'NOTICE_REPLY_TYPE' => 'BAD_PROCESS',
- 'L_APPOITMENT_DATE' => 'NOW()',
- 'L_APPOITMENT_USER' => User::getLogin(),
- 'ADM_ACCOUNT' => User::getLogin(),
- 'THIS_SINGLE_WASTE_COST' => '',
- 'WASTE_COST_COMMENT' => '',
- 'THIS_SINGLE_FIX_COST' => '',
- 'YEAR_COST_FOREACST_OF_SUCH_PROBLEM_WITH_FIXING' => '',
- 'FIX_COST_COMMENT' => '',
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()'
- ]);
- if( $idQualityNotice > 0 ) {
- $messageValidate['success'] = 'send';
- } else {
- $messageValidate['error'] = 2;
- }
- /*
- TODO: dodać możliwość wysyłania maila używajac mail()
- // Data fpr create mail
- $to = self::$helpEmailTo; // uzupełnić mail
- $subject = 'Bocian - formularz pomocy';
- $message = "Zgłaszający: " . $helpName . " \r\n E-mail: " . $helpEmail . ". \r\n Treść wiadomości:\r\n " . $helpDescription;
- $headers = 'From: '. self::$helpEmailTo . "\r\n" .
- 'Reply-To: '. self::$helpEmailTo . "\r\n" .
- 'X-Mailer: PHP/' . phpversion();
- $sendMail = mail($to, $subject, $message, $headers);
- if( $sendMailResponse == true ) {
- $responseSendMail = true;
- $messageValidate['success'] = 'send';
- } else {
- $messageValidate['error'] = 2;
- }
- */
- }
- return [
- 'messageValidate' => $messageValidate,
- ];
- }
- function sendPageView($templateFile, $beforeViewTrigger = null) {
- UI::gora();
- echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
- echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
- Theme::top();
- $tmplPath = __FILE__ . '.' . $templateFile;
- if (!file_exists($tmplPath)) throw new Exception("Template file not exists '{$templateFile}'");
- if ($beforeViewTrigger && is_callable($beforeViewTrigger)) {
- $data = $beforeViewTrigger($_POST);
- if (is_array($data) && !empty($data)) {
- extract($data);
- }
- }
- include($tmplPath);
- UI::dol();
- }
- function graphTestAction() { include __FILE__ . '.graphTest.php'; }
- function viewIncludeStoreJs($storeName = 'bocianRaportStore') {
- UI::inlineJS(__FILE__ . '.store.js', [
- 'DBG' => V::get('DBG', 0, $_GET),
- 'STORE_NAME' => $storeName,
- 'CURRENT_DATE' => date("j.n.Y"),
- ]);
- }
- function defaultAction() {
- UI::gora();
- echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
- echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
- Theme::top();
- //echo '<div id="smad-wrapper">'; // todo: sprawdzi czy można usunać
- echo '<div id="bi_audit_header"></div>' . "\n";
- echo '<div class="container-bi_audit_form_pracownicy_raport" style="display: none;"></div>' . "\n";
- echo '<div class="container-bi_audit_form_kontrahenci_raport" style="display: none;"></div>' . "\n";
- echo '<div class="container-bi-audit_form_operacyjna_baza_zgloszen" style="display:none;"></div>' . "\n";
- // echo '<div class="container-bi_audit_form_raport_data" style="display: none;"></div>';
- echo UI::h('script', ['src'=>"static/vendor.js?v=71baa97d", 'type'=>"text/javascript"]);
- $this->viewIncludeStoreJs($storeName = "bocianRaportStore");
- UI::inlineJS(__FILE__ . '.view.js', [
- 'BASE_URLS' => Request::getPathUri(),
- 'URL_FETCH_KONTRAHENCI_POWIAZANIA' => $this->getLink('fetchEnergaRumKontrahenciPowiazaniaAjax'),
- 'URL_FETCH_TEST_KRS' => $this->getLink('fetchTestKrsAjax'),
- 'URL_FETCH_TEST_CEIDG' => $this->getLink('fetchTestCeidgAjax'),
- 'URL_FETCH_PRACOWNICY' => $this->getLink('fetchPracownicyAjax'),
- 'URL_FETCH_KONTRAHENCI' => $this->getLink('fetchKontrahenciAjax'),
- 'URL_FETCH_PRACOWNICY_IDS_AJAX' => $this->getLink('fetchPracownicyIdsAjax'),
- 'URL_FETCH_KONTRAHENCI_IDS_AJAX' => $this->getLink('fetchKontrahenciIdsAjax'),
- 'URL_FETCH_LAST_REPORTS_AJAX' => $this->getLink('fetchLastReportsAjax'),
- 'URL_FETCH_PRACOWNICY_IDS_BY_REPORT_AJAX' => $this->getLink('fetchPracownicyIdsByReportAjax'),
- 'URL_FETCH_KONTRAHENCI_IDS_BY_REPORT_AJAX' => $this->getLink('fetchKontrahenciIdsByReportAjax'),
- 'URL_CREATE_PRACOWNICY_GROUP' => $this->getLink('createPracownicyGroupAjax'),
- 'URL_CREATE_KONTRAHENCI_GROUP' => $this->getLink('createKontrahenciGroupAjax'),
- 'URL_ADD_PRACOWNICY_TO_GROUP' => $this->getLink('addPracownicyToGroupAjax'),
- 'URL_REMOVE_PRACOWNICY_FROM_GROUP' => $this->getLink('removePracownicyFromGroupAjax'),
- 'URL_CREATE_PRACOWNICY' => $this->getLink('createPracownikAjax'),
- 'URL_CREATE_KONTRAHENCI' => $this->getLink('createKontrahentAjax'),
- 'URL_ADD_KONTRAHENCI_TO_GROUP' => $this->getLink('addKontrahenciToGroupAjax'),
- 'URL_REMOVE_KONTRAHENCI_FROM_GROUP' => $this->getLink('removeKontrahenciFromGroupAjax'),
- 'URL_FETCH_GROUP_PRACOWNICY' => $this->getLink('fetchGroupPracownicyAjax'),
- 'URL_FETCH_GROUP_KONTRAHENCI' => $this->getLink('fetchGroupKontrahenciAjax'),
- 'URL_GENERATE_BI_AUDIT_RAPORT_AJAX' => $this->getLink('generateBiAuditRaportAjax'),
- 'DBG' => V::get('DBG', 0, $_GET),
- 'VIEW_KONTRAHENCI' => $this->defaultViewFormBiAudit([], 'KONTRAHENCI'),
- 'VIEW_PRACOWNICY' => $this->defaultViewFormBiAudit([], 'PRACOWNICY'),
- 'VIEW_OPERACYJNA_BAZA_ZGLOSZEN' => $this->defaultViewFormBiAudit([], 'OPERACYJNA_BAZA_ZGLOSZEN'),
- 'URL_FORM_DATA_CSV_FILE_AJAX' => $this->getLink('formDataCsvFileAjax'),
- 'URL_SAVE_FORM_CSV_FILE_AJAX' => $this->getLink('saveFormCsvFileAjax'),
- 'URL_TABLE_POWIAZANIA' => Router::getRoute('ViewTableAjax')->getLink('', [ 'namespace' => "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA" ]),
- 'FIELD_LIST_PRACOWNICY' => array_merge(
- array_map(function ($fieldName) {
- return "f_{$fieldName}";
- }, self::$FIELD_LIST_PRACOWNICY),
- [
- 'f_Adresy',
- ]
- ),
- 'FIELD_LIST_KONTRAHENCI' => array_map(function ($fieldName) {
- return "f_{$fieldName}";
- }, self::$FIELD_LIST_KONTRAHENCI),
- 'CURRENT_DATE' => date("j.n.Y"),
- 'STORE_NAME' => $storeName = "bocianRaportStore",
- ]);
- UI::inlineJS(__FILE__ . '.addItemToRaport.js', [
- 'URL_FETCH_FROM_BAZA' => $this->getLink('fetchFromBazaAjax'),
- // 'URL_SAVE_TO_DB' => $this->getLink('saveToPozostaleOdDoAjax'),
- 'DBG' => V::get('DBG', 0, $_GET),
- 'FUNCTION_NAME' => "addPozostaleOdDo",
- 'STORE_NAME' => $storeName = "bocianRaportStore",
- ]);
- // UI::inlineJS(__FILE__ . '.addItemToRaport.js', [
- // 'URL_FETCH_FROM_BAZA' => $this->getLink('fetchFromBazaAjax'),
- // 'URL_SAVE_TO_DB' => $this->getLink('saveToPozostaleOdDoAjax'),
- // 'DBG' => V::get('DBG', 0, $_GET),
- // 'FUNCTION_NAME' => "createPracownikAjax",
- // ]);
- // UI::inlineJS(__FILE__ . '.addItemToRaport.js', [
- // 'URL_FETCH_FROM_BAZA' => $this->getLink('fetchFromBazaAjax'),
- // 'URL_SAVE_TO_DB' => $this->getLink('saveToPozostaleOdDoAjax'),
- // 'DBG' => V::get('DBG', 0, $_GET),
- // 'FUNCTION_NAME' => "createKontrahentAjax",
- // ]);
- UI::inlineJS(__FILE__ . '.graphShowHide.js', [
- 'DBG' => V::get('DBG', 0, $_GET),
- 'FIELD_LIST_PRACOWNICY' => array_merge(
- array_map(function ($fieldName) {
- return "f_{$fieldName}";
- }, self::$FIELD_LIST_PRACOWNICY),
- [
- 'f_Adresy',
- ]
- ),
- 'FIELD_LIST_KONTRAHENCI' => array_map(function ($fieldName) {
- return "f_{$fieldName}";
- }, self::$FIELD_LIST_KONTRAHENCI),
- ]);
- echo '</div>'; // #smad-wrapper
- UI::dol();
- }
- public function saveToPozostaleOdDoAjaxAction() {
- Response::sendTryCatchJson(array($this, 'saveToPozostaleOdDoAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function saveToPozostaleOdDoAjax($args) {
- DBG::log($args, 'array', "saveToPozostaleOdDoAjax args");
- $baza = V::get('baza', '', $args); // namespace
- $item = V::get('item', [], $args); // [ '@primaryKey' => int, ... ]
- $from = V::get('from', [], $args); // OD | DO
- if (empty($item)) throw new Exception("Brak danych do zapisania");
- switch ($baza) {
- case 'default_db/BI_audit_KRS/BI_audit_KRS':
- case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person':
- case 'default_db/BI_audit_MSIG/BI_audit_MSIG':
- case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person':
- case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG':
- default: throw new Exception("Not implemented ");
- }
- die("TODO: 500! baza({$baza}) pk({$item['@primaryKey']})");
- }
- public function saveToPracownicyAjaxAction() {
- Response::sendTryCatchJson(array($this, 'saveToPracownicyAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function saveToPracownicyAjax($args) {
- DBG::log($args, 'array', "saveToPracownicyAjax args");
- $baza = V::get('baza', '', $args);
- $item = V::get('item', [], $args);
- if (empty($item)) throw new Exception("Brak danych do zapisania");
- switch ($baza) {
- case 'default_db/BI_audit_KRS/BI_audit_KRS': return $this->saveKRSToPracownicyAjax($item);
- case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return $this->saveKRSPersonToPracownicyAjax($item);
- case 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI': return $this->saveKontrahentToPracownicyAjax($item);
- case 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY': return $this->savePracownikToPracownicyAjax($item);
- case 'default_db/BI_audit_taxpayer/BI_audit_taxpayer': return $this->saveVATpToPracownicyAjax($item);
- case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return $this->saveMSIGToPracownicyAjax($item);
- case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return $this->saveMSIGPersonToPracownicyAjax($item);
- case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return $this->saveCEIDGToPracownicyAjax($item);
- }
- }
- function saveKRSToPracownicyAjax($item) {
- $companyName = V::get('nazwa', '', $item);
- $companyNip = V::get('nip', '', $item);
- $comapanyRegon = V::get('regon', '', $item);
- $comapanyKrs = V::get('krs', '', $item);
- $companyStreet = V::get('A_ulica', '', $item);
- $companyHomeNumber = V::get('A_nrDomu', '', $item);
- $companyNumber = V::get('A_nrLokalu', '', $item);
- $companyPostCode = V::get('A_kod', '', $item);
- $companyCity = V::get('A_miejscowosc', '', $item);
- // validate
- //if (!$companyName) throw new Exception("Nie podano nazwy");
- //if (!$companyNip) throw new Exception("Nie podano nip");
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'imiona' => $companyName,
- 'nip' => ($companyNip) ? $companyNip : NULL,
- 'regon' => ($comapanyRegon) ? $comapanyRegon : NULL,
- 'krs' => ($comapanyKrs) ? $comapanyKrs : NULL,
- 'ulica' => $companyStreet,
- 'nr' => $companyHomeNumber,
- 'nrLokalu' => $companyNumber,
- 'kodPocztowy' => $companyPostCode,
- 'miejscowosc' => $companyCity,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano podmiot",
- 'type' => "success",
- ];
- }
- function saveMSIGToPracownicyAjax($item) {
- $companyName = V::get('nazwa', '', $item);
- $companyNip = V::get('nip', '', $item);
- $comapanyRegon = V::get('regon', '', $item);
- $comapanyKrs = V::get('krs', '', $item);
- $companyStreet = V::get('A_ulica', '', $item);
- $companyHomeNumber = V::get('A_nrDomu', '', $item);
- $companyNumber = V::get('A_nrLokalu', '', $item);
- $companyPostCode = V::get('A_kod', '', $item);
- $companyCity = V::get('A_miejscowosc', '', $item);
- // validate
- //if (!$companyName) throw new Exception("Nie podano nazwy");
- //if (!$companyNip) throw new Exception("Nie podano nip");
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'imiona' => $companyName,
- 'nip' => ($companyNip) ? $companyNip : NULL,
- 'regon' => ($comapanyRegon) ? $comapanyRegon : NULL,
- 'krs' => ($comapanyKrs) ? $comapanyKrs : NULL,
- 'ulica' => $companyStreet,
- 'nr' => $companyHomeNumber,
- 'nrLokalu' => $companyNumber,
- 'kodPocztowy' => $companyPostCode,
- 'miejscowosc' => $companyCity,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano podmiot",
- 'type' => "success",
- ];
- }
- function saveKRSPersonToPracownicyAjax($item) {
- $personName = V::get('imiona', '', $item);
- $personSurname = V::get('nazwisko', '', $item);
- $personPesel = V::get('pesel', '', $item);
- // validate
- //if (!$personName) throw new Exception("Nie podano imienia");
- //if (!$personSurname) throw new Exception("Nie podano nazwiska");
- try{
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'imiona' => $personName,
- 'nazwisko' => $personSurname,
- 'pesel' => ($personPesel) ? $personPesel : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- } catch( PDOException $e){
- if($e->errorInfo[1]== 1062){
- throw new Exception("Ta osoba jest już w bazie danych");
- }
- else{
- throw new Exception("Błąd bazy danych");
- }
- }
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- function saveMSIGPersonToPracownicyAjax($item) {
- $personName = V::get('imiona', '', $item);
- $personSurname = V::get('nazwisko', '', $item);
- $personPesel = V::get('pesel', '', $item);
- // validate
- //if (!$personName) throw new Exception("Nie podano imienia");
- //if (!$personSurname) throw new Exception("Nie podano nazwiska");
- try{
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'imiona' => $personName,
- 'nazwisko' => $personSurname,
- 'pesel' => ($personPesel) ? $personPesel : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- } catch( PDOException $e){
- if($e->errorInfo[1]== 1062){
- throw new Exception("Ta osoba jest już w bazie danych");
- }
- else{
- throw new Exception("Błąd bazy danych");
- }
- }
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- function saveCEIDGToPracownicyAjax($item) {
- $personName = V::get('imiona', '', $item);
- $personSurname = V::get('nazwisko', '', $item);
- $personEnterprise = V::get('firma','',$item);
- $personNip = V::get('nip', '', $item);
- $personRegon = V::get('regon', '', $item);
- $personLocal = V::get('lokal', '', $item);
- $personPostalCode = V::get('kodPocztwy', '', $item);
- $personCity = V::get('miejscowosc', '', $item);
- $personBuilding = V::get('budynek', '', $item);
- $personStreet = V::get('ulica', '', $item);
- $personName.=' ';
- $personName.=$personEnterprise;
- $personEnterprise.=' ';
- $personEnterprise.=$personSurname;
- // validate
- //if (!$personName) throw new Exception("Nie podano imienia");
- //if (!$personSurname) throw new Exception("Nie podano nazwiska");
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'imie' => $personName,
- 'nazwisko' => $personEnterprise,
- 'ulica' => $personStreet,
- 'nr' => $personBuilding,
- 'nrLokalu' => $personLocal,
- 'kodPocztowy' => $personPostalCode,
- 'miejscowosc' => $personCity,
- 'regon' => ($personRegon) ? $personRegon : NULL,
- 'nip' => ($personNip) ? $personNip : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- function saveVATpToPracownicyAjax($item) {
- $personName = V::get('imiona', '', $item);
- $personSurname = V::get('nazwisko', '', $item);
- $personNip = V::get('nip', '', $item);
- $personRegon = V::get('regon', '', $item);
- // validate
- //if (!$personName) throw new Exception("Nie podano imienia");
- //if (!$personSurname) throw new Exception("Nie podano nazwiska");
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'imie' => $personName,
- 'nazwisko' => $personSurname,
- 'regon' => ($personRegon) ? $personRegon : NULL,
- 'nip' => ($personNip) ? $personNip : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- function saveKontrahentToPracownicyAjax($item) {
- // companyName: document.getElementById('companyName').value,
- // companyNip: document.getElementById('companyNip').value,
- // comapanyRegon: document.getElementById('comapanyRegon').value,
- DBG::log($item, 'array', "argumenty do wpisania");
- $companyName = V::get('companyName', '', $item);
- $companyNip = V::get('companyNip', '', $item);
- $companyRegon = V::get('companyRegon', '', $item);
- $companyPesel = V::get('companyPesel', '', $item);
- $companyStreet = V::get('companyStreet', '', $item);
- $companyNumber = V::get('companyNumber', '', $item);
- $companyNumberLocal = V::get('companyNumberLocal', '', $item);
- $companyPostCode = V::get('companyPostCode', '', $item);
- $companyCity = V::get('companyCity', '', $item);
- $companyKrs = V::get('companyKrs', '', $item);
- // validate
- if (!$companyName) throw new Exception("Nie wpisano nazwy");
- if (!$companyNip) throw new Exception("Nie wpisano nip");
- try{
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'nazwisko' => $companyName,
- 'nip' => ($companyNip) ? $companyNip : NULL,
- 'regon' => ($companyRegon) ? $companyRegon : NULL,
- 'pesel' => $companyPesel,
- 'ulica' => $companyStreet,
- 'nr' => $companyNumber,
- 'nrLokalu' => $companyNumberLocal,
- 'kodPocztowy' => $companyPostCode,
- 'miejscowosc' => $companyCity,
- 'krs' => $companyKrs,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- } catch( PDOException $e){
- if($e->errorInfo[1]== 1062){
- throw new Exception("Ta osoba jest już w bazie danych");
- }
- else{
- throw new Exception("Błąd bazy danych");
- }
- }
- return [
- 'msg' => "Dodano podmiot",
- 'type' => "success",
- ];
- }
- function savePracownikToPracownicyAjax($item) {
- $personName = V::get('personName', '', $item);
- $personSurname = V::get('personSurname', '', $item);
- $personNip = V::get('personNip', '', $item);
- $personPesel = V::get('personPesel', '', $item);
- // validate
- if (!$personName) throw new Exception("Nie wpisano imienia");
- if (!$personSurname) throw new Exception("Nie wpisano nazwiska");
- try{
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'imiona' => $personName,
- 'nazwisko' => $personSurname,
- 'nip' => ($personNip) ? $personNip : NULL,
- 'pesel' => ($personPesel) ? $personPesel : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- } catch( PDOException $e){
- if($e->errorInfo[1]== 1062){
- throw new Exception("Ta osoba jest już w bazie danych");
- }
- else{
- throw new Exception("Błąd bazy danych");
- }
- }
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- public function saveToKontrahenciAjaxAction() {
- Response::sendTryCatchJson(array($this, 'saveToKontrahenciAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function saveToKontrahenciAjax($args) {
- DBG::log($args, 'array', "saveToKontrahenciAjaxActionAjax args");
- // $baza + $item['@primaryKey']
- $baza = V::get('baza', '', $args);
- $item = V::get('item', [], $args);
- if (empty($item)) throw new Exception("Brak danych do zapisania");
- switch ($baza) {
- case 'default_db/BI_audit_KRS/BI_audit_KRS': return $this->saveKRSToKontrahenciAjax($item);
- case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return $this->saveKRSPersonToKontrahenciAjax($item);
- case 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI': return $this->saveKontrahentToKontrahenciAjax($item);
- case 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY': return $this->savePracownikToKontrahenciAjax($item);
- case 'default_db/BI_audit_taxpayer/BI_audit_taxpayer': return $this->saveVATpToKontrahenciAjax($item);
- case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return $this->saveMSIGToKontrahenciAjax($item);
- case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return $this->saveMSIGPersonToKontrahenciAjax($item);
- case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return $this->saveCEIDGToKontrahenciAjax($item);
- }
- }
- function saveKRSToKontrahenciAjax($item) {
- $companyName = V::get('nazwa', '', $item);
- $companyNip = V::get('nip', '', $item);
- $companyRegon = V::get('regon', '', $item);
- $companyKrs = V::get('krs', '', $item);
- $companyStreet = V::get('A_ulica', '', $item);
- $companyNumberBuilding = V::get('A_nrDomu', '', $item);
- $companyNumberLocal = V::get('A_nrLokalu', '', $item);
- $companyPostCode = V::get('A_kod', '', $item);
- $companyCountry = V::get('A_kraj', '', $item);
- $companyCity = V::get('A_miejscowosc', '', $item);
- // validate
- //if (!$companyName) throw new Exception("Nie podano nazwy");
- //if (!$companyNip) throw new Exception("Nie podano nip");
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- 'Pelna_nazwa_kontrahenta' => $companyName,
- 'NIP' => ($companyNip) ? $companyNip : NULL,
- 'REGON' => ($companyRegon) ? $companyRegon : NULL,
- 'KRS' => ($companyKrs) ? $companyKrs : NULL,
- 'Ulica' => $companyStreet,
- 'Numer_mieszkania_lokalu' => $companyNumberLocal,
- 'Numer_budynku' => $companyNumberBuilding,
- 'Kod_pocztowy' => $companyPostCode,
- 'Miejscowosc' => $companyCity,
- 'Kraj' => $companyCountry,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano podmiot",
- 'type' => "success",
- ];
- }
- function saveMSIGToKontrahenciAjax($item) {
- $companyName = V::get('nazwa', '', $item);
- $companyNip = V::get('nip', '', $item);
- $comapanyRegon = V::get('regon', '', $item);
- $comapanyKrs = V::get('krs', '', $item);
- $companyStreet = V::get('A_ulica', '', $item);
- $companyNumberBuilding = V::get('A_nrDomu', '', $item);
- $companyNumberLocal = V::get('A_nrLokalu', '', $item);
- $companyPostCode = V::get('A_kod', '', $item);
- $companyCountry = V::get('A_kraj', '', $item);
- $companyCity = V::get('A_miejscowosc', '', $item);
- // validate
- //if (!$companyName) throw new Exception("Nie podano nazwy");
- //if (!$companyNip) throw new Exception("Nie podano nip");
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- 'Pelna_nazwa_kontrahenta' => $companyName,
- 'NIP' => ($companyNip) ? $companyNip : NULL,
- 'REGON' => ($comapanyRegon) ? $comapanyRegon : NULL,
- 'KRS' => ($comapanyKrs) ? $comapanyKrs : NULL,
- 'Ulica' => $companyStreet,
- 'Numer_mieszkania_lokalu' => $companyNumberLocal,
- 'Numer_budynku' => $companyNumberBuilding,
- 'Kod_pocztowy' => $companyPostCode,
- 'Miejscowosc' => $companyCity,
- 'Kraj' => $companyCountry,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano podmiot",
- 'type' => "success",
- ];
- }
- function saveCEIDGToKontrahenciAjax($item) {
- $personFirstName = V::get('imie', '', $item);
- $personLastName = V::get('nazwisko', '', $item);
- $personNip = V::get('nip', '', $item);
- $personEnterprise = V::get('firma', '', $item);
- $personStreet = V::get('ulica', '', $item);
- $personNumber = V::get('budynek', '', $item);
- $personNumberLocal = V::get('lokal', '', $item);
- $personPostalCode = V::get('kodPocztowy', '', $item);
- $personCity = V::get('miejscowosc', '', $item);
- $personCountry = V::get('kraj', '', $item);
- $personFirstName .= ' ';
- $personFirstName .= $personEnterprise;
- $personEnterprise .= ' ';
- $personEnterprise .= $personLastName;
- // validate
- //if (!$personFirstName) throw new Exception("Nie podano nazwy");
- //if (!$personNip) throw new Exception("Nie podano nip");
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- 'Pelna_nazwa_kontrahenta' => $personEnterprise,
- //'Skrocona_Nazwa_Kontrahenta' => $personFirstName,
- 'NIP' => ($personNip) ? $personNip : NULL,
- 'REGON' => ($personRegon) ? $personRegon : NULL,
- 'Ulica' => $personStreet,
- 'Numer_mieszkania_lokalu' => $personNumber,
- 'Numer_budynku' => $personNumber,
- 'Kod_pocztowy' => $personPostalCode,
- 'Miejscowosc' => $personCity,
- 'Kraj' => $personCountry,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano podmiot",
- 'type' => "success",
- ];
- }
- function saveKRSPersonToKontrahenciAjax($item) {
- $personName = V::get('imiona', '', $item);
- $personSurname = V::get('nazwisko', '', $item);
- $personPesel = V::get('pesel', '', $item);
- // validate
- //if (!$personName) throw new Exception("Nie podano imienia");
- //if (!$personSurname) throw new Exception("Nie podano nazwiska");
- try{
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- //'Skrocona_Nazwa_Kontrahenta' => $personName,
- 'Pelna_nazwa_kontrahenta' => $personSurname,
- 'PESEL' => ($personPesel) ? $personPesel : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- } catch( PDOException $e){
- if($e->errorInfo[1]== 1062){
- throw new Exception("Ta osoba jest już w bazie danych");
- }
- else{
- throw new Exception("Błąd bazy danych");
- }
- }
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- function saveMSIGPersonToKontrahenciAjax($item) {
- $personName = V::get('imiona', '', $item);
- $personSurname = V::get('nazwisko', '', $item);
- $personPesel = V::get('pesel', '', $item);
- // validate
- //if (!$personName) throw new Exception("Nie podano imienia");
- //if (!$personSurname) throw new Exception("Nie podano nazwiska");
- try{
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- //'Skrocona_Nazwa_Kontrahenta' => $personName,
- 'Pelna_nazwa_kontrahenta' => $personSurname,
- 'PESEL' => ($personPesel) ? $personPesel : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- } catch( PDOException $e){
- if($e->errorInfo[1]== 1062){
- throw new Exception("Ta osoba jest już w bazie danych");
- }
- else{
- throw new Exception("Błąd bazy danych");
- }
- }
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- function saveVATpToKontrahenciAjax($item) {
- $personName = V::get('imiona', '', $item);
- $personSurname = V::get('nazwisko', '', $item);
- $personPesel = V::get('pesel', '', $item);
- // validate
- //if (!$personName) throw new Exception("Nie podano imienia");
- //if (!$personSurname) throw new Exception("Nie podano nazwiska");
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- //'Skrocona_Nazwa_Kontrahenta' => $personName,
- 'Pelna_nazwa_kontrahenta' => $personSurname,
- 'PESEL' => ($personPesel) ? $personPesel : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- function saveKontrahentToKontrahenciAjax($item) {
- // companyName: document.getElementById('companyName').value,
- // companyNip: document.getElementById('companyNip').value,
- // comapanyRegon: document.getElementById('comapanyRegon').value,
- $companyName = V::get('companyName', '', $item);
- $companyNip = V::get('companyNip', '', $item);
- $companyRegon = V::get('companyRegon', '', $item);
- $companyPesel = V::get('companyPesel', '', $item);
- $companyStreet = V::get('companyStreet', '', $item);
- $companyNumber = V::get('companyNumber', '', $item);
- $companyNumberLocal = V::get('companyNumberLocal', '', $item);
- $companyPostCode = V::get('companyPostCode', '', $item);
- $companyCity = V::get('companyCity', '', $item);
- $companyKrs = V::get('companyKrs', '', $item);
- // validate
- if (!$companyName) throw new Exception("Nie wpisano nazwy");
- if (!$companyNip) throw new Exception("Nie wpisano nip");
- try{
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- 'Pelna_nazwa_kontrahenta' => $companyName,
- 'NIP' => ($companyNip) ? $companyNip : NULL,
- 'REGON' => ($comapanyRegon) ? $comapanyRegon : NULL,
- 'PESEL' => ($companyPesel) ? $companyPesel : NULL,
- 'Ulica' => ($companyStreet) ? $companyStreet : NULL,
- 'Numer_budynku' => ($companyNumber) ? $companyNumber : NULL,
- 'Numer_mieszkania_lokalu' => ($companyNumberLocal) ? $companyNumberLocal : NULL,
- 'Kod_pocztowy' => ($companyPostCode) ? $companyPostCode : NULL,
- 'Miejscowosc' => ($companyCity) ? $companyCity : NULL,
- 'KRS' => ($companyKrs) ? $companyKrs : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- } catch( PDOException $e){
- if($e->errorInfo[1]== 1062){
- throw new Exception("Ta osoba jest już w bazie danych");
- }
- else{
- throw new Exception("Błąd bazy danych");
- }
- }
- return [
- 'msg' => "Dodano podmiot",
- 'type' => "success",
- ];
- }
- function savePracownikToKontrahenciAjax($item) {
- $personName = V::get('personName', '', $item);
- $personSurname = V::get('personSurname', '', $item);
- $personNip = V::get('personNip', '', $item);
- $personPesel = V::get('personPesel', '', $item);
- // validate
- if (!$personName) throw new Exception("Nie wpisano imienia");
- if (!$personSurname) throw new Exception("Nie wpisano nazwiska");
- try{
- $idOd = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- //'Skrocona_Nazwa_Kontrahenta' => $personName,
- 'Pelna_nazwa_kontrahenta' => $personSurname,
- 'NIP' => ($personNip) ? $personNip : NULL,
- 'PESEL' => ($personPesel) ? $personPesel : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- } catch( PDOException $e){
- if($e->errorInfo[1]== 1062){
- throw new Exception("Ta osoba jest już w bazie danych");
- }
- else{
- throw new Exception("Błąd bazy danych");
- }
- }
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- /**
- * Dodanie nowego pracownika
- */
- public function createPracownikAjaxAction() {
- 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
- }
- public function createPracownikAjax($args) {
- DBG::log($args, 'array', "args");
- $personName = V::get('personName', '', $args);
- $personSurname = V::get('personSurname', '', $args);
- $personNip = V::get('personNip', '', $args);
- $personPesel = V::get('personPesel', '', $args);
- $personRegon = V::get('personRegon', '', $args);
- // validate
- if (!$personName) throw new Exception("Nie wpisano imienia");
- if (!$personSurname) throw new Exception("Nie wpisano nazwiska");
- $idPracownik = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', [
- 'imiona' => $personName,
- 'nazwisko' => $personSurname,
- 'nip' => ($personNip) ? $personNip : NULL,
- 'pesel' => ($personPesel) ? $personPesel : NULL,
- 'regon' => ($personRegon) ? $personRegon : NULL,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano osobę",
- 'type' => "success",
- ];
- }
- /**
- * Dodanie nowego kontrahenta
- */
- public function createKontrahentAjaxAction() {
- 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
- }
- public function createKontrahentAjax($args) {
- $companyFullName = V::get('companyFullName', '', $args);
- $companyShortName = V::get('$companyShortName', '', $args);
- $companyNameGroup = V::get('companyNameGroup', '', $args);
- $companyKrs = V::get('companyKrs', '', $args);
- $companyNip = V::get('companyNip', '', $args);
- $companyPesel = V::get('companyPesel', '', $args);
- $companyFax = V::get('companyFax', '', $args);
- $companyTelefon = V::get('companyTelefon', '', $args);
- $companyMail = V::get('companyMail', '', $args);
- $companyStreet = V::get('companyStreet', '', $args);
- $companyNumberBuilding = V::get('companyNumberBuilding', '', $args);
- $companyNumberLocal = V::get('companyNumberLocal', '', $args);
- $companyPostCode = V::get('companyPostCode', '', $args);
- $companyPlace = V::get('companyPlace', '', $args);
- $companyCountry = V::get('companyCountry', '', $args);
- $companyTypeCompany = V::get('companyTypeCompany', '', $args);
- $companyTitleDocument = V::get('companyTitleDocument', '', $args);
- $companyDesc = V::get('companyDesc', '', $args);
- // validate
- if (!$companyFullName) throw new Exception("Nie wpisano pełnej nazwy kontrahenta");
- $idKontrahent = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI', [
- 'Pelna_nazwa_kontrahenta' => $companyFullName,
- 'Skrocona_Nazwa_Kontrahenta' => ($companyShortName) ? $companyShortName : null,
- 'Nazwa_grupy_kapitalowej' => ($companyNameGroup) ? $companyNameGroup : null,
- 'KRS' => ($companyKrs) ? $companyKrs : null,
- 'NIP' => ($companyNip) ? $companyNip : null,
- 'PESEL' => ($companyPesel) ? $companyPesel : null,
- 'Fax' => ($companyFax) ? $companyFax : null,
- 'Telefon' => ($companyTelefon) ? $companyTelefon : null,
- 'Mail' => ($companyMail) ? $companyMail : null,
- 'Ulica' => ($companyStreet) ? $companyStreet : null,
- 'Numer_budynku' => ($companyNumberBuilding) ? $companyNumberBuilding : null,
- 'Numer_mieszkania_lokalu' => ($companyNumberLocal) ? $companyNumberLocal : null,
- 'Kod_pocztowy' => ($companyPostCode) ? $companyPostCode : null,
- 'Miejscowosc' => ($companyPlace) ? $companyPlace : null,
- 'Kraj' => ($companyCountry) ? $companyCountry : null,
- 'Typ_kontrahenta' => ($companyTypeCompany) ? $companyTypeCompany : null,
- 'Tytul_dokumentu' => ($companyTitleDocument) ? $companyTitleDocument : null,
- 'uwagi' => ($companyDesc) ? $companyDesc : null,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- return [
- 'msg' => "Dodano podmiot/kontrahenta",
- 'type' => "success",
- ];
- }
- /**
- * Funkcja ajax do odebrania danych z przesłanego pliku CSV do parsowania
- */
- public function formDataCsvFileAjaxAction() {
- Response::sendTryCatchJson(array($this, 'formDataCsvFileAjax'));
- }
- /**
- * Funkcja parsuje dane wgrywanego plku csv i zwraca dane w inputach
- */
- public function formDataCsvFileAjax() {
- if (!file_exists($_FILES['file']['tmp_name'])) throw new Exception("Wybierz plik do przesłania.");
- $file = file($_FILES['file']['tmp_name']);
- //$showCheckbox = V::get('showCheckbox', '', $args);
- $showCheckbox = V::get('showCheckbox', 0, $_REQUEST, 'string');
- // parsujemy csv to tablicy
- $arrayDataCsv = $this->csvToArray($file, ';', '"', '\n\r');
- $i = 0;
- // tworzymy rekordy
- foreach ( $arrayDataCsv as $line ) {
- $viewFormCol .= '<tr>';
- foreach ( $line as $keyData => $rowData ) {
- // utworzenie nagłówków tabeli
- if( $i == 0) { $header .= '<td style="min-width:160px">' . $keyData . '</td>'; }
- // utworzenie inputa do edycji
- $viewFormCol .= '<td style="min-width:160px"><input type="text" name="item['.$i.']['.$keyData.']" value="'.$rowData .'" class="form-control input-lg" /></td>';
- }
- $viewFormCol .= '</tr>';
- $i++;
- }
- // pokaz checkbox jeśli ma status showCheckbox
- if ( $showCheckbox == 'yes' ) {
- $viewFormCol .= '<div style="margin: 10px 0"><input type="checkbox" name="override" value="1" /> Nadpisz wszystkie rekordy w bazie danych</div';
- }
- $viewFormHtml = '<div id="smad-window-modal" style="overflow-x: scroll;">
- <div class="table-responsive padding-0" >
- <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>
- </div>';
- //return $viewFormHtml;
- return [
- 'type' => 'success',
- 'msg' => 'OK',
- '__req_args' => $_REQUEST,
- '__args' => $args,
- 'body' => [
- 'view' => $viewFormHtml,
- ]
- ];
- }
- /**
- * Funkcja ajax do odebrania danych z przesłanego formularza z parsowanego CSV
- */
- public function saveFormCsvFileAjaxAction() {
- Response::sendTryCatchJson(array($this, 'saveFormCsvFileAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- //Response::sendTryCatchJson(array($this, 'saveFormCsvFileAjax'));
- }
- /**
- * Funkcja ajax do zapisania danych z przesłanego formularza z parsowanego CSV
- */
- public function saveFormCsvFileAjax($args) {
- //dane z formularza
- $formData = V::get('formData', '', $args);
- $enumType = V::get('enumType', '', $args);
- $override = false; // false - nie nadpisujemy danych
- $arrayInfo = array();
- $arrayInfo['insert'] = 0;
- $arrayInfo['update'] = 0;
- $arrayInfo['error'] = 0;
- // pobranie nazwy tabeli z db
- $table = $this->getNameTableByEnum( strtoupper($enumType) );
- if ( $table == null ) throw new Exception('Błąd zapisu. Tabela w db nie istnieje');
- // unserialize data from serialize in javascript
- parse_str($formData, $resultArrayFormdata);
- if ( count($resultArrayFormdata['item']) == 0) {
- throw new Exception("Wystapił problem podczas przesyłania danych - brak przesłanych danych.");
- }
- // ustawienie true jeśli wyrabno nadpisanie danych
- if ( isset($resultArrayFormdata['override']) ) { $override = true; } // aktualizuj rekordy/nadpisz istniejace
- // dodanie/aktualizacjia wpisu
- foreach ( $resultArrayFormdata['item'] as $line ) {
- $response = $this->saveDataToDb($table, $line, $override);
- // tworzymy listę informacji o liczbie nowych/zaktualizowanych/z błedami rekordów
- $arrayInfo = $this->responseCountListInfoAboutSaveData($response, $arrayInfo);
- }
- // utworzenie komunikatów
- if ( isset($arrayInfo['insert']) ) { $textInsert = "Liczba nowych rekordów: (" . $arrayInfo['insert'] . ");"; }
- if ( isset($arrayInfo['error']) ) { $textError = "Liczba nie zapisanych rekordów (" . $arrayInfo['insert'] . ");"; }
- return [
- 'msg' => "Zapisano dane. " . $textInsert . " " . $textError ,
- 'type' => "success",
- ];
- }
- /**
- * Count list
- */
- public function responseCountListInfoAboutSaveData($response, $arrayInfo) {
- if (!is_array($response)) throw new Exception('Wystapił bład podczas zapisu danych');
- $countData = array();
- switch(key($response)) {
- case 'insert':
- $countData['insert'] = $arrayInfo['insert'] + 1;
- break;
- case 'error':
- $countData['error'] = $arrayInfo['insert'] + 1;
- break;
- }
- return $countData;
- }
- /**
- * Function parse csv to array
- * @param $filename - file data from FILE
- * @param $delimiter - delimiter
- * @param $enclosure -
- * @param $escape -
- */
- function csvToArray($filedata , $delimiter=';', $enclosure='"', $escape = '\\') {
- if(!$filedata || empty($filedata)) return false;
- $header = null;
- $data = array();
- foreach( $filedata as $line) {
- $values = str_getcsv( $line, $delimiter, $enclosure, $escape );
- if(!$header) $header = $values;
- else $data[] = array_combine( $header, $values );
- }
- return $data;
- }
- /**
- * Save data in database
- */
- public function saveDataToDb( $table, $arrayData, $override = false ) {
- $response = array();
- try {
- if ($override) {
- DB::getPDO()->insertOrUpdate($table, array_merge($arrayData, [
- '@insert' => [
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- ],
- '@update' => array_merge($arrayData, [
- 'A_RECORD_UPDATE_DATE' => 'NOW()',
- 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
- ]),
- ]));
- } else {
- $responseInsert = DB::getPDO()->insert($table, array_merge($arrayData, [
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]));
- }
- $response['insert'] = 1;
- } catch (Exception $e) {
- DBG::log($e);
- $response['error'] = 1;
- }
- return $response;
- }
- /**
- * Get name table by enum
- */
- public function getNameTableByEnum($type) {
- $nameTable = null;
- switch ($type) {
- case 'KONTRAHENCI':
- $nameTable = 'BI_audit_ENERGA_RUM_KONTRAHENCI';
- break;
- case 'PRACOWNICY':
- $nameTable = 'BI_audit_ENERGA_PRACOWNICY';
- break;
- }
- return $nameTable;
- }
- public function fetchEnergaRumKontrahenciPowiazaniaAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchEnergaRumKontrahenciPowiazaniaAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function fetchEnergaRumKontrahenciPowiazaniaAjax($args) {
- $id = V::get('ID', 26, $_REQUEST, 'int');
- $items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'A_ADM_COMPANY',
- 'L_APPOITMENT_USER',
- 'A_CLASSIFIED',
- 'A_STATUS',
- 'A_STATUS_INFO',
- 'BI_analiza_maxDepth',
- 'BI_analiza_minDepth',
- 'BI_analiza_onlyTargets',
- 'BI_analiza_reloadCache',
- 'FILE_STATUS',
- 'FILE_STATUS_info',
- 'L_APPOITMENT_USER',
- 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
- 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
- 'default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person',
- ],
- 'f_ID' => "{$id}",
- ])->getItems([
- 'limit' => 10
- ]);
- // $items = [
- // [ 'ID' => 1, 'L_APPOITMENT_INFO' => 'x', 'BI_analiza_depth' => 'a', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test1'],
- // [ 'ID' => 2, 'L_APPOITMENT_INFO' => 'y', 'BI_analiza_depth' => 'b', 'FILE_STATUS' => 0, 'FILE_STATUS_info' => 'test2'],
- // [ 'ID' => 3, 'L_APPOITMENT_INFO' => 'z', 'BI_analiza_depth' => 'c', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test3'],
- // ];
- return [
- 'type' => 'success',
- 'msg' => 'OK',
- '__req_args' => $_REQUEST,
- '__args' => $args,
- 'body' => [
- 'items' => $items,
- 'view' => $this->showPowiazaniaEnergaRumKontrahenciPowiazania($items),
- ]
- ];
- }
- public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
- $view = '<form class="form-horizontal" method="post">
- <table class="table table-bordered table-hover table-striped" height=5>
- <thead>
- <tr style="">
- <td width=1><input type="checkbox" name="checkAll" id="checkAll" /></td>
- <td width=1>ID</td>
- <td>Adnotacje</td>
- <td>Głębokość analizy</td>
- <td>Status raportu</td>
- <td>Status raportu - informacje</td>
- </tr>
- </thead>
- <tbody>
- ';
- foreach ($items as $key => $row) {
- $view .= '<tr>
- <td><input type="checkbox" name="prID[]" value="'.$row['ID'].'" onClick="checkAll()"/></td>
- <td align="right">'.$row["ID"].'</td>
- <td align="right">'.$row["L_APPOITMENT_INFO"].'</td>
- <td align="right">'.$row["BI_analiza_depth"].'</td>
- <td align="right">'.$row["FILE_STATUS"].'</td>
- <td align="right">'.$row["FILE_STATUS_info"].'</td>';
- }
- $view .= '</tbody></table></form>';
- return $view;
- }
- public function fetchTestKrsAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchTestKrsAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function fetchTestKrsAjax($args) {
- $id = V::get('ID', 1, $_REQUEST, 'int');
- $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'A_kod',
- 'A_kraj',
- 'A_miejscowosc',
- 'A_nrDomu',
- 'A_nrLokalu',
- 'A_poczta',
- 'A_ulica',
- 'ID',
- 'S_gmina',
- 'S_kraj',
- 'S_miejscowosc',
- 'S_powiat',
- 'S_wojewodztwo',
- 'dataDokumentu',
- 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
- 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
- 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
- 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
- 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
- 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
- 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
- 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
- 'krs',
- 'nazwa',
- 'nip',
- 'regon',
- ],
- 'f_ID' => "{$id}",
- ])->getItems([
- 'limit' => 10
- ]);
- return [
- 'type' => 'success',
- 'msg' => 'KRS',
- '__req_args' => $_REQUEST,
- '__args' => $args,
- 'body' => [
- 'items' => $items,
- ]
- ];
- }
- public function fetchTestCeidgAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchTestCeidgAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function fetchTestCeidgAjax($args) {
- $id = V::get('ID', 0, $_REQUEST, 'int');
- $items = ACL::getAclByNamespace('default_db/BI_audit_CEIDG/BI_audit_CEIDG')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'budynek',
- 'firma',
- 'gmina',
- 'identyfikatorWpisu',
- 'imie',
- 'kodPocztowy',
- 'kraj',
- 'lokal',
- 'miejscowosc',
- 'nazwisko',
- 'nip',
- 'poczta',
- 'powiat',
- 'regon',
- 'ulica',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ID',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/budynek',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/gmina',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/kodPocztowy',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/lokal',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/miejscowosc',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nazwa',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nip',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/poczta',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/powiat',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ulica',
- 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/wojewodztwo',
- 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/ID',
- 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/nip',
- 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/regon',
- ],
- // 'f_ID' => $id,
- ])->getItems([
- 'limit' => 10
- ]);
- return [
- 'type' => 'success',
- 'msg' => 'CEIDG',
- '__req_args' => $_REQUEST,
- '__args' => $args,
- 'body' => [
- 'items' => $items,
- ]
- ];
- }
- function fetchLastReportsAjaxAction() { Response::sendTryCatchJson([ $this, 'fetchLastReportsAjax' ], $args = 'JSON_FROM_REQUEST_BODY'); }
- function fetchLastReportsAjax() {
- $refRaportToPracownicyConfig = ACL::getRefConfig(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY'
- );
- $refRaportToKontrahenciConfig = ACL::getRefConfig(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI'
- );
- $refRaportToPzostaleOdConfig = ACL::getRefConfig(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_POWIAZANIA_OD:BI_audit_POWIAZANIA_OD'
- );
- $refRaportToPzostaleDoConfig = ACL::getRefConfig(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_POWIAZANIA_DO:BI_audit_POWIAZANIA_DO'
- );
- $items = DB::getPDO()->fetchAll("
- select r.ID as id
- , r.L_APPOITMENT_INFO as adnotacje
- , (select count(1) from `{$refRaportToPracownicyConfig->tableName}` as prRef where prRef.PRIMARY_KEY = r.ID and prRef.A_STATUS not in ('DELETED')) as totalPracownicy
- , (select count(1) from `{$refRaportToKontrahenciConfig->tableName}` as comRef where comRef.PRIMARY_KEY = r.ID and comRef.A_STATUS not in ('DELETED')) as totalKontrahenci
- , (select count(1) from `{$refRaportToPzostaleOdConfig->tableName}` as odRef where odRef.PRIMARY_KEY = r.ID and odRef.A_STATUS not in ('DELETED')) as totalPozostaleOd
- , (select count(1) from `{$refRaportToPzostaleDoConfig->tableName}` as doRef where doRef.PRIMARY_KEY = r.ID and doRef.A_STATUS not in ('DELETED')) as totalPozostaleDo
- from `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` as r
- order by r.ID DESC
- limit 10
- ");
- return [
- 'type' => 'success',
- 'msg' => 'ostatnie raporty',
- 'body' => [
- 'items' => $items,
- ],
- ];
- }
- function fetchPracownicyIdsByReportAjaxAction() { Response::sendTryCatchJson([ $this, 'fetchPracownicyIdsByReportAjax' ], $args = 'JSON_FROM_REQUEST_BODY'); }
- function fetchPracownicyIdsByReportAjax($args) {
- $id = V::get('id', 0, $args);
- if ($id <= 0) throw new HttpException("Missing id", 400);
- $refConf = ACL::getRefConfig(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY'
- );
- $items = DB::getPDO()->fetchAll("
- select REMOTE_PRIMARY_KEY
- from `{$refConf->tableName}`
- where PRIMARY_KEY = :id
- and A_STATUS not in ('DELETED')
- ", [ ':id' => $id ]);
- return [
- 'type' => 'success',
- 'msg' => 'kontrahenci ids',
- 'body' => [
- 'ids' => array_map( V::makePick('REMOTE_PRIMARY_KEY'), $items ),
- ],
- ];
- }
- function fetchKontrahenciIdsByReportAjaxAction() { Response::sendTryCatchJson([ $this, 'fetchKontrahenciIdsByReportAjax' ], $args = 'JSON_FROM_REQUEST_BODY'); }
- function fetchKontrahenciIdsByReportAjax($args) {
- $id = V::get('id', 0, $args);
- if ($id <= 0) throw new HttpException("Missing id", 400);
- $refConf = ACL::getRefConfig(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI'
- );
- $items = DB::getPDO()->fetchAll("
- select REMOTE_PRIMARY_KEY
- from `{$refConf->tableName}`
- where PRIMARY_KEY = :id
- and A_STATUS not in ('DELETED')
- ", [ ':id' => $id ]);
- return [
- 'type' => 'success',
- 'msg' => 'kontrahenci ids',
- 'body' => [
- 'ids' => array_map( V::makePick('REMOTE_PRIMARY_KEY'), $items ),
- ],
- ];
- }
- public function fetchKontrahenciIdsAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchKontrahenciIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function fetchKontrahenciIdsAjax($args) {
- $idGroup = V::get('filter_idGroup', 0, $args, 'int');
- if ($idGroup < 0) $idGroup = 0;
- $backRefFilter = [];
- if ($idGroup > 0) {
- $backRefFilter['__backRef'] = [
- 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- 'primaryKey' => $idGroup,
- 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
- ];
- }
- $searchParams = []; // TODO: ???
- $filtersParams = [];
- $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
- return ('f_' === substr($key, 0, 2));
- });
- foreach ($fieldFilterKeys as $key) {
- $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
- }
- $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
- $query = $acl->buildQuery(array_merge([
- 'cols' => [
- 'ID',
- ],
- //'f_ID' => $id,
- 'limit' => 0,
- // 'limitstart' => $limitstart, // offset
- // 'order_by' => 'ID', // sortowanie po kolumnie
- // 'order_dir' => 'DESC', // kierunek sortowania
- // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
- // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
- // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
- // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
- ], $searchParams, $filtersParams, $backRefFilter));
- // $total = $query->getTotal();
- $items = $query->getItems();
- return [
- 'type' => 'success',
- 'msg' => 'kontrahenci ids',
- 'body' => [
- 'ids' => array_map( V::makePick('ID'), $items ),
- ],
- '__DBG_args' => $args,
- '__DBG_$idGroup' => $idGroup,
- '__DBG_$filtersParams' => $filtersParams,
- '__DBG_$backRefFilter' => $backRefFilter,
- ];
- }
- /**
- * KONTRAHENCI
- */
- public function fetchKontrahenciAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchKontrahenciAjax'), $args = $_REQUEST);
- }
- public function fetchKontrahenciAjax($args) {
- $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
- if ($idGroup < 0) $idGroup = 0;
- $limit = 20;
- $limitstart = V::get('limitstart', 0, $args, 'int');
- if ($limitstart < 0) $limitstart = 0;
- $page = V::get('page', 0, $args, 'int');
- $limitstart = ($page - 1) * $limit;
- $search = V::get('search', '', $args);
- $searchParams = [];
- if (!empty($search)) {
- $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
- $searchParams['ogc:Filter'] = '
- <ogc:Filter>
- <ogc:Or>
- <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>NIP</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- </ogc:Or>
- </ogc:Filter>
- ';
- }
- // ogc filter w środku ogcand potem ogcnot potem PropertyIsEqualTo
- $backRefFilter = [];
- if ($idGroup > 0) {
- $backRefFilter['__backRef'] = [
- 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- 'primaryKey' => $idGroup,
- 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
- ];
- // - ID
- // - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
- // - NAZWA - nazwa grupy
- // - 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_KONTRAHENCI' minOccurs="0" maxOccurs="unbounded"
- }
- $filtersParams = [];
- $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
- return ('f_' === substr($key, 0, 2));
- });
- foreach ($fieldFilterKeys as $key) {
- $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
- }
- DBG::log($filtersParams, 'Kontrahenci $filtersParams');
- $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
- $query = $acl->buildQuery(array_merge([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'Nazwa_grupy_kapitalowej',
- 'Pelna_nazwa_kontrahenta',
- 'Numer_kontrahenta',
- 'Skrocona_Nazwa_Kontrahenta',
- 'Typ_kontrahenta',
- 'NIP',
- 'KRS',
- 'REGON',
- 'PESEL',
- 'Forma_prawna_dzialalnosci',
- 'Ulica',
- 'Numer_budynku',
- 'Numer_mieszkania_lokalu',
- 'Miejscowosc',
- 'Kod_pocztowy',
- 'Kraj',
- 'Telefon',
- 'Fax',
- 'Mail',
- 'A_ADM_COMPANY',
- 'A_CLASSIFIED',
- 'Dodano',
- 'Podmiot_dominujacy',
- 'Tytul_dokumentu',
- 'ownCompany',
- 'uwagi',
- ],
- //'f_ID' => $id,
- 'limit' => $limit,
- 'limitstart' => $limitstart, // offset
- 'order_by' => 'ID', // sortowanie po kolumnie
- 'order_dir' => 'DESC', // kierunek sortowania
- ], $searchParams, $filtersParams, $backRefFilter));
- $total = $query->getTotal();
- $items = $query->getItems();
- $pagination = array();
- $pagination['total_items'] = $total;
- $pagination['size'] = ceil($total/$limit); // pages size
- $pagination['current'] = $page;
- $pagination['limit'] = $limit;
- if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
- return [
- 'type' => 'success',
- 'msg' => 'showKontrajenci',
- 'body' => [
- 'items' => $items,
- //'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI'),
- 'pagination' => $pagination
- ],
- '__DBG_args' => $args,
- '__DBG_$idGroup' => $idGroup,
- '__DBG_$filtersParams' => $filtersParams,
- '__DBG_$backRefFilter' => $backRefFilter,
- ];
- }
- public function fetchFromBazaAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchFromBazaAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function fetchFromBazaAjax($args) {
- $baza = V::get('baza', '', $args);
- $query = V::get('query', '', $args);
- $query = trim(trim($query), '0');
- if (strlen($query) < 3) throw new Exception("Query must be more then 2 chars");
- $wordsQuery = [];
- if (false !== strpos($query, ' ')) {
- $words = explode(' ', $query);
- DBG::log($words, 'array', "\$words from \$query({$query}) - 1");
- $words = array_map(function ($word) {
- return trim(trim($word), '0');
- }, $words);
- DBG::log($words, 'array', "\$words from \$query({$query}) - 2");
- $words = array_filter($words, function ($word) {
- return (strlen($word) > 2);
- });
- DBG::log($words, 'array', "\$words from \$query({$query}) - 3");
- if (empty($words)) throw new Exception("Query words must be more then 2 chars");
- $wordsQuery = $words;
- } else {
- $wordsQuery[] = $query;
- }
- switch ($baza) {
- case 'default_db/BI_audit_KRS/BI_audit_KRS': return $this->fetchFromKRS($wordsQuery);
- case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return $this->fetchFromKRSPerson($wordsQuery);
- case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return $this->fetchFromMSIG($wordsQuery);
- case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return $this->fetchFromMSIGPerson($wordsQuery);
- case 'default_db/BI_audit_taxpayer/BI_audit_taxpayer': return $this->fetchFromVATp($wordsQuery);
- case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return $this->fetchFromCEIDG($wordsQuery);
- default: throw new Exception("Unsupported database");
- }
- }
- function generateOgcFilterFromWords($wordsQuery, $searchableFields) {
- return '<ogc:Filter><ogc:And>' .
- implode("\n", array_map(function ($word) use ($searchableFields) {
- return '<ogc:Or>' . implode("\n", array_map(function ($fieldName) use ($word) {
- return '<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>' . $fieldName . '</ogc:PropertyName>
- <ogc:Literal>' . "*{$word}*" . '</ogc:Literal>
- </ogc:PropertyIsLike>';
- }, $searchableFields)) . '</ogc:Or>';
- }, $wordsQuery)) .
- '</ogc:And></ogc:Filter>';
- }
- function fetchFromKRS($wordsQuery) {
- $query = implode(" ", $wordsQuery);
- if (empty($wordsQuery)) throw new Exception("Empty search");
- $searchableFields = [];
- $searchableFields[] = 'nazwa';
- $searchableFields[] = 'nip';
- $searchableFields[] = 'krs';
- $searchableFields[] = 'regon';
- $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
- $items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery(array_merge([
- 'cols' => [ // TODO:? propertyName = []
- 'A_kod',
- 'A_kraj',
- 'A_miejscowosc',
- 'A_nrDomu',
- 'A_nrLokalu',
- 'A_poczta',
- 'A_ulica',
- 'ID',
- // 'S_gmina',
- 'S_kraj',
- 'S_miejscowosc',
- // 'S_powiat',
- 'S_wojewodztwo',
- // 'dataDokumentu',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
- 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
- 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
- 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
- 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
- 'krs',
- 'nazwa',
- 'nip',
- 'regon',
- ],
- // 'f_ID' => "{$id}",
- ], $searchParams))->getItems([
- 'limit' => 10
- ]);
- DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
- return [
- 'type' => 'success',
- 'msg' => 'KRS',
- '__args' => $args,
- 'body' => [
- 'items' => array_map(function ($item) {
- $nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
- $nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
- $item['nazwa'] = $nazwa;
- $item['label'] = "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}";
- // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- return $item;
- // return [
- // 'ID' => $item['ID'],
- // 'nazwa' => $shortNazwa,
- // 'nip' => $item['nip'],
- // 'krs' => $item['krs'],
- // 'regon' => $item['regon'],
- // 'S_miejscowosc' => $item['S_miejscowosc'],
- // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- // ];
- }, $items),
- ]
- ];
- }
- function fetchFromKRSPerson($wordsQuery) {
- $query = implode(" ", $wordsQuery);
- if (empty($wordsQuery)) throw new Exception("Empty search");
- $searchableFields = [];
- $searchableFields[] = 'nazwisko';
- $searchableFields[] = 'imiona';
- $searchableFields[] = 'pesel';
- $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
- $items = ACL::getAclByNamespace('default_db/BI_audit_KRS_person/BI_audit_KRS_person')->buildQuery(array_merge([
- 'cols' => [ // TODO:? propertyName = []
- 'nazwisko',
- 'imiona',
- 'pesel',
- 'ID',
- // 'dataDokumentu',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
- ],
- // 'f_ID' => "{$id}",
- ], $searchParams))->getItems([
- 'limit' => 10
- ]);
- DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
- return [
- 'type' => 'success',
- 'msg' => 'KRS person',
- '__args' => $args,
- 'body' => [
- 'items' => array_map(function ($item) {
- //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
- //$nazwa = $item['nazwisko'];
- //$item['nazwa'] = $nazwa;
- $item['label'] = "{$item['nazwisko']}, {$item['imiona']}, {$item['pesel']}";
- // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- return $item;
- // return [
- // 'ID' => $item['ID'],
- // 'nazwa' => $shortNazwa,
- // 'nip' => $item['nip'],
- // 'krs' => $item['krs'],
- // 'regon' => $item['regon'],
- // 'S_miejscowosc' => $item['S_miejscowosc'],
- // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- // ];
- }, $items),
- ]
- ];
- }
- function fetchFromVATp($query){
- $ogcSearch = "*{$query}*";
- $searchParams = [];
- $searchParams['ogc:Filter'] = '
- <ogc:Filter>
- <ogc:Or>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>nazwisko</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>imiona</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>pesel</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- </ogc:Or>
- </ogc:Filter>
- ';
- $items = ACL::getAclByNamespace('default_db/BI_audit_taxpayer/BI_audit_taxpayer')->buildQuery(array_merge([
- 'cols' => [ // TODO:? propertyName = []
- 'nip',
- 'ID',
- // 'dataDokumentu',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
- ],
- // 'f_ID' => "{$id}",
- ], $searchParams))->getItems([
- 'limit' => 10
- ]);
- DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
- return [
- 'type' => 'success',
- 'msg' => 'KRS person',
- '__args' => $args,
- 'body' => [
- 'items' => array_map(function ($item) {
- //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
- //$nazwa = $item['nazwisko'];
- //$item['nazwa'] = $nazwa;
- $item['label'] = "{$item['nip']}";
- // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- return $item;
- // return [
- // 'ID' => $item['ID'],
- // 'nazwa' => $shortNazwa,
- // 'nip' => $item['nip'],
- // 'krs' => $item['krs'],
- // 'regon' => $item['regon'],
- // 'S_miejscowosc' => $item['S_miejscowosc'],
- // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- // ];
- }, $items),
- ]
- ];
- }
- function fetchFromMSIG($wordsQuery) {
- $query = implode(" ", $wordsQuery);
- if (empty($wordsQuery)) throw new Exception("Empty search");
- $searchableFields = [];
- $searchableFields[] = 'nazwa';
- $searchableFields[] = 'krs';
- $searchableFields[] = 'nip';
- $searchableFields[] = 'regon';
- $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
- $items = ACL::getAclByNamespace('default_db/BI_audit_MSIG/BI_audit_MSIG')->buildQuery(array_merge([
- 'cols' => [ // TODO:? propertyName = []
- 'A_kod',
- 'A_kraj',
- 'A_miejscowosc',
- 'A_nrDomu',
- 'A_nrLokalu',
- 'A_poczta',
- 'A_ulica',
- 'ID',
- // 'S_gmina',
- 'S_kraj',
- 'S_miejscowosc',
- // 'S_powiat',
- 'S_wojewodztwo',
- // 'dataDokumentu',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
- 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person/ID',
- 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person/imiona',
- 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person/nazwisko',
- 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person/pesel',
- 'krs',
- 'nazwa',
- 'nip',
- 'regon',
- ],
- // 'f_ID' => "{$id}",
- ], $searchParams))->getItems([
- 'limit' => 10
- ]);
- DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
- return [
- 'type' => 'success',
- 'msg' => 'MSIG',
- '__args' => $args,
- 'body' => [
- 'items' => array_map(function ($item) {
- $nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
- $nazwa = str_replace([ '„', '”' ], '', $item['nazwa']);
- $nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", " Sp. z o.o.", $nazwa);
- $item['nazwa'] = $nazwa;
- $item['label'] = "{$nazwa}, " . implode(", ", array_filter([
- $item['A_miejscowosc'],
- $item['krs'],
- $item['nip'],
- $item['regon']
- ], [ 'V', 'filterNotEmpty' ]));
- // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- return $item;
- // return [
- // 'ID' => $item['ID'],
- // 'nazwa' => $shortNazwa,
- // 'nip' => $item['nip'],
- // 'krs' => $item['krs'],
- // 'regon' => $item['regon'],
- // 'S_miejscowosc' => $item['S_miejscowosc'],
- // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- // ];
- }, $items),
- ]
- ];
- }
- function fetchFromMSIGPerson($wordsQuery) {
- $query = implode(" ", $wordsQuery);
- if (empty($wordsQuery)) throw new Exception("Empty search");
- $searchableFields = [];
- $searchableFields[] = 'nazwisko';
- $searchableFields[] = 'imiona';
- $searchableFields[] = 'pesel';
- $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
- $items = ACL::getAclByNamespace('default_db/BI_audit_MSIG_person/BI_audit_MSIG_person')->buildQuery(array_merge([
- 'cols' => [ // TODO:? propertyName = []
- 'nazwisko',
- 'imiona',
- 'pesel',
- 'ID',
- // 'dataDokumentu',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
- // 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
- // 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
- ],
- // 'f_ID' => "{$id}",
- ], $searchParams))->getItems([
- 'limit' => 10
- ]);
- DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
- return [
- 'type' => 'success',
- 'msg' => 'MSIG',
- '__args' => $args,
- 'body' => [
- 'items' => array_map(function ($item) {
- //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
- //$nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
- //$item['nazwa'] = $nazwa;
- $item['label'] = "{$item['nazwisko']}, {$item['imiona']}, {$item['pesel']}";
- // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- return $item;
- // return [
- // 'ID' => $item['ID'],
- // 'nazwa' => $shortNazwa,
- // 'nip' => $item['nip'],
- // 'krs' => $item['krs'],
- // 'regon' => $item['regon'],
- // 'S_miejscowosc' => $item['S_miejscowosc'],
- // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- // ];
- }, $items),
- ]
- ];
- }
- function fetchFromCEIDG($wordsQuery) {
- $query = implode(" ", $wordsQuery);
- if (empty($wordsQuery)) throw new Exception("Empty search");
- $searchableFields = [];
- $searchableFields[] = 'firma';
- $searchableFields[] = 'nazwisko';
- $searchableFields[] = 'imie';
- $searchableFields[] = 'nip';
- $searchableFields[] = 'regon';
- $searchParams = [ 'ogc:Filter' => $this->generateOgcFilterFromWords($wordsQuery, $searchableFields) ];
- $items = ACL::getAclByNamespace('default_db/BI_audit_CEIDG/BI_audit_CEIDG')->buildQuery(array_merge([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'budynek',
- 'firma',
- 'gmina',
- 'identyfikatorWpisu',
- 'imie',
- 'kodPocztowy',
- 'kraj',
- 'lokal',
- 'miejscowosc',
- 'nazwisko',
- 'nip',
- 'poczta',
- 'powiat',
- 'regon',
- 'ulica',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ID',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/budynek',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/gmina',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/kodPocztowy',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/lokal',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/miejscowosc',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nazwa',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nip',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/poczta',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/powiat',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ulica',
- // 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/wojewodztwo',
- // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/ID',
- // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/nip',
- // 'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/regon',
- ],
- // 'f_ID' => "{$id}",
- ], $searchParams))->getItems([
- 'limit' => 10
- ]);
- DBG::log($items, 'array', "DBG: items query({$query}) from '{$baza}'");
- return [
- 'type' => 'success',
- 'msg' => 'CEIDG',
- '__args' => $args,
- 'body' => [
- 'items' => array_map(function ($item) {
- //$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
- //$nazwa = str_replace("SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ", "Sp. z o.o.", $nazwa);
- //$item['nazwa'] = $nazwa;
- $item['label'] = "{$item['firma']} {$item['imie']} {$item['nazwisko']}, {$item['miejscowosc']}, {$item['nip']}, {$item['regon']}";
- // 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- return $item;
- // return [
- // 'ID' => $item['ID'],
- // 'nazwa' => $shortNazwa,
- // 'nip' => $item['nip'],
- // 'krs' => $item['krs'],
- // 'regon' => $item['regon'],
- // 'S_miejscowosc' => $item['S_miejscowosc'],
- // 'label' => "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
- // ];
- }, $items),
- ]
- ];
- }
- public function showTableKontrahenci($labels = []) {
- // TODO: use self::$FIELD_LIST_KONTRAHENCI
- $view = '<form class="form-horizontal" method="post">
- <table class="table table-bordered table-hover table-striped" height=5>
- <thead>
- <tr>
- <td width=1><input type="checkbox" name="checkAll" id="checkAll-KONTRAHENCI" /></td>
- <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
- <td>' . V::get('Nazwa_grupy_kapitalowej', 'Nazwa grupy kapitalowej', $labels) . '</td>
- <td>' . V::get('Pelna_nazwa_kontrahenta', 'Pelna nazwa kontrahenta', $labels) . '</td>
- <td>' . V::get('Numer_kontrahenta', 'Numer kontrahenta', $labels) . '</td>
- <td>' . V::get('Skrocona_Nazwa_Kontrahenta', 'Skrócona nazwa kontrahenta', $labels) . '</td>
- <td>' . V::get('Typ_kontrahenta', 'Typ_kontrahenta', $labels) . '</td>
- <td>' . V::get('NIP', 'NIP', $labels) . '</td>
- <td>' . V::get('KRS', 'KRS', $labels) . '</td>
- <td>' . V::get('REGON', 'Regon', $labels) . '</td>
- <td>' . V::get('PESEL', 'PESEL', $labels) . '</td>
- <td>' . V::get('Forma_prawna_dzialalnosci', 'Forma prawna działalności', $labels) . '</td>
- <td>' . V::get('Ulica', 'Ulica', $labels) . '</td>
- <td>' . V::get('Numer_budynku', 'Numer budynku', $labels) . '</td>
- <td>' . V::get('Numer_mieszkania_lokalu', 'Numer mieszkania lokalu', $labels) . '</td>
- <td>' . V::get('Miejscowosc', 'Miejscowosc', $labels) . '</td>
- <td>' . V::get('Kod_pocztowy', 'Kod pocztowy', $labels) . '</td>
- <td>' . V::get('Kraj', 'Kraj', $labels) . '</td>
- <td>' . V::get('Telefon', 'Telefon', $labels) . '</td>
- <td>' . V::get('Fax', 'Fax', $labels) . '</td>
- <td>' . V::get('Mail', 'Mail', $labels) . '</td>
- <td>' . V::get('A_ADM_COMPANY', 'A_ADM_COMPANY', $labels) . '</td>
- <td>' . V::get('A_CLASSIFIED', 'A_CLASSIFIED', $labels) . '</td>
- <td>' . V::get('Dodano', 'Dodano', $labels) . '</td>
- <td>' . V::get('Podmiot_dominujacy', 'Podmiot dominujacy', $labels) . '</td>
- <td>' . V::get('Tytul_dokumentu', 'Tytul dokumentu', $labels) . '</td>
- <td>' . V::get('ownCompany', 'ownCompany', $labels) . '</td>
- <td>' . V::get('uwagi', 'uwagi', $labels) . '</td>
- </tr>
- <tr>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- </tr>
- </thead>
- <tbody id="body-kontrahenci">
- </tbody></table>
- </form>
- ';
- return $view;
- }
- // tworzenie grupy kontrahentów
- public function createKontrahenciGroupAjaxAction() {
- 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
- }
- public function createKontrahenciGroupAjax($args) {
- $nazwa = V::get('NAZWA', '', $args);
- // TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje
- $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- 'NAZWA' => $nazwa,
- 'ID_USER' => User::getID()
- ]);
- return [
- 'msg' => "Utworzona grupę {$idGroup}",
- 'type' => "success",
- 'body' => [
- 'id' => $idGroup,
- 'nazwa' => $nazwa
- ]
- ];
- }
- // Dodanie do grupy filtra kontrahentów
- public function addKontrahenciToGroupAjaxAction() {
- 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
- }
- public function addKontrahenciToGroupAjax($args) {
- $idGroup = V::get('idGroup', '', $args);
- $type = V::get('type', 'ids', $args);
- $kontrahenciIds = V::get('kontrahenciIds', '', $args);
- $filter = V::get('filter', '', $args);
- // validate
- if (!$idGroup) throw new Exception("Nie wybrano grupa");
- switch ($type) {
- case 'ids': {
- if (!$kontrahenciIds || count($kontrahenciIds) == 0) throw new Exception("Proszę wybrać kontrahentów");
- } break;
- case 'filter': {
- if (!isset($args['filter'])) throw new Exception("Proszę wybrać kontrahentów");
- } break;
- default: throw new Exception("Missing type");
- }
- $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'ID_USER',
- 'NAZWA',
- ],
- // 'f_ID_USER' => User::getID()
- ])->getItem($idGroup);
- if (!$group) throw new Exception("Grupa nie istnieje");
- if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
- if ('filter' === $type) {
- $args__idGroup = V::get('filterIdGroup', 0, $args['filter'], 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
- if ($args__idGroup < 0) $args__idGroup = 0;
- $search = V::get('search', '', $args['filter']);
- $searchParams = [];
- if (!empty($search)) {
- $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
- $searchParams['ogc:Filter'] = '
- <ogc:Filter>
- <ogc:Or>
- <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>NIP</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- </ogc:Or>
- </ogc:Filter>
- ';
- }
- $backRefFilter = [];
- if ($args__idGroup > 0) {
- $backRefFilter['__backRef'] = [
- 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- 'primaryKey' => $args__idGroup,
- 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
- ];
- }
- $filtersParams = [];
- $fieldFilterKeys = array_filter(array_keys($args['filter']), function ($key) {
- return ('f_' === substr($key, 0, 2));
- });
- foreach ($fieldFilterKeys as $key) {
- $filtersParams[ $key ] = '%' . $args['filter'][ $key ] . '%';
- }
- $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
- $query = $acl->buildQuery(array_merge([
- 'cols' => ['ID'],
- ], $searchParams, $filtersParams, $backRefFilter, [
- 'limit' => 0
- ]));
- $items = $query->getItems();
- $kontrahenciIds = array_map(function ($row) {
- return $row['ID'];
- }, $items);
- }
- ACL::addListRef(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
- $refPrimaryKey = $idGroup,
- $refListRemotePrimaryKey = $kontrahenciIds
- );
- return [
- 'msg' => "Powiązano kontrahentów z grupą {$idGroup}",
- 'type' => "success",
- ];
- }
- public function removePracownicyFromGroupAjaxAction(){
- 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
- }
- public function removePracownicyFromGroupAjax($args){
- $idGroup = V::get('idGroup', 0, $args, "int");
- $pracownicyIds = V::get('pracownicyIds', [], $args, 'array');
- if ($idGroup === 0){
- foreach ($pracownicyIds as $pracownikIds) {
- //TO DO Błąd do naprawienia
- //TO DO sprawdzanie czy już DELETED
- $affected = DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY', 'ID', $pracownikIds, [
- 'A_STATUS' => 'DELETED',
- 'A_RECORD_UPDATE_DATE' => 'NOW()',
- 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
- ]);
- }
- return [
- 'msg' => "Usunięto osoby z systemu",
- 'type' => "success",
- ];
- } else {
- $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'ID_USER',
- 'NAZWA',
- ],
- // 'f_ID_USER' => User::getID()
- ])->getItem($idGroup);
- if (!$group) throw new Exception("Grupa nie istnieje");
- if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
- ACL::removeListRef(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- $refPrimaryKey = $idGroup,
- $refListRemotePrimaryKey = $pracownicyIds
- );
- return [
- 'msg' => "Usunięto osoby z grupy {$idGroup}",
- 'type' => "success",
- ];
- }
- }
- public function removeKontrahenciFromGroupAjaxAction() {
- 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
- }
- public function removeKontrahenciFromGroupAjax($args) {
- $idGroup = V::get('idGroup', 0, $args, "int");
- $kontrahenciIds = V::get('kontrahenciIds', [], $args, 'array');
- if ($idGroup === 0) {
- foreach ($kontrahenciIds as $kontrahentIds) {
- $affected = DB::getPDO()->update('BI_audit_ENERGA_RUM_KONTRAHENCI', 'ID', $kontrahentIds, [
- 'A_STATUS' => 'DELETED',
- 'A_RECORD_UPDATE_DATE' => 'NOW()',
- 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
- ]);
- }
- return [
- 'msg' => "Usunięto kontrahentów z systemu",
- 'type' => "success",
- ];
- } else {
- $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'ID_USER',
- 'NAZWA',
- ],
- // 'f_ID_USER' => User::getID()
- ])->getItem($idGroup);
- if (!$group) throw new Exception("Grupa nie istnieje");
- if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
- ACL::removeListRef(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
- $refPrimaryKey = $idGroup,
- $refListRemotePrimaryKey = $kontrahenciIds
- );
- return [
- 'msg' => "Usunięto kontrahentów z grupy {$idGroup}",
- 'type' => "success",
- ];
- }
- }
- public function fetchGroupKontrahenciAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
- }
- public function fetchGroupKontrahenciAjax() {
- $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'ID_USER',
- 'NAZWA',
- ],
- 'f_ID_USER' => "=" . User::getID(),
- 'f_A_STATUS' => "!DELETED",
- ]);
- $itemsKontrahenci = $query->getItems();
- if (empty($itemsKontrahenci)) throw new AlertWarningException("Grupy nie istnieją");
- $arrayGroupKontrahenci = array();
- foreach ($itemsKontrahenci as $item) {
- // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy");
- $arrayGroupKontrahenci[] = [
- 'NAZWA' => $item['NAZWA'],
- 'ID' => $item['ID'],
- ];
- }
- return [
- 'type' => 'success',
- 'msg' => 'fetchGroupKontrahenciAjax',
- '__req_args' => $_REQUEST,
- '__args' => $args,
- 'body' => [
- 'itemsGroupKontrahenci' => $arrayGroupKontrahenci
- ]
- ];
- }
- public function fetchPracownicyIdsAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchPracownicyIdsAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function fetchPracownicyIdsAjax($args) {
- $idGroup = V::get('filter_idGroup', 0, $args, 'int');
- if ($idGroup < 0) $idGroup = 0;
- $backRefFilter = [];
- if ($idGroup > 0) {
- $backRefFilter['__backRef'] = [
- 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- 'primaryKey' => $idGroup,
- 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- ];
- }
- $searchParams = []; // TODO: ???
- $filtersParams = [];
- $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
- return ('f_' === substr($key, 0, 2));
- });
- foreach ($fieldFilterKeys as $key) {
- $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
- }
- $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
- $query = $acl->buildQuery(array_merge([
- 'cols' => [
- 'ID',
- ],
- //'f_ID' => $id,
- 'limit' => 0,
- // 'limitstart' => $limitstart, // offset
- // 'order_by' => 'ID', // sortowanie po kolumnie
- // 'order_dir' => 'DESC', // kierunek sortowania
- // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
- // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
- // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
- // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
- ], $searchParams, $filtersParams, $backRefFilter));
- // $total = $query->getTotal();
- $items = $query->getItems();
- return [
- 'type' => 'success',
- 'msg' => 'pracownicy ids',
- 'body' => [
- 'ids' => array_map( V::makePick('ID'), $items ),
- ],
- '__args' => $args,
- '__DBG_$idGroup' => $idGroup,
- '__DBG_$filtersParams' => $filtersParams,
- '__DBG_$backRefFilter' => $backRefFilter,
- ];
- }
- /*
- * PRACOWNICY
- */
- public function fetchPracownicyAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'), $args = $_REQUEST);
- }
- public function fetchPracownicyAjax($args) {
- $idGroup = V::get('filterIdGroup', 0, $args, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
- if ($idGroup < 0) $idGroup = 0;
- $limit = 20;
- $page = V::get('page', 0, $args, 'int');
- $limitstart = ($page - 1) * $limit;
- $search = V::get('search', '', $args);
- $searchParams = [];
- if (!empty($search)) {
- $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
- $searchParams['ogc:Filter'] = '
- <ogc:Filter>
- <ogc:Or>
- <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>nip</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>nazwisko</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- </ogc:Or>
- </ogc:Filter>
- ';
- }
- $backRefFilter = [];
- if ($idGroup > 0) {
- $backRefFilter['__backRef'] = [
- 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- 'primaryKey' => $idGroup,
- 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- ];
- }
- $filtersParams = [];
- $fieldFilterKeys = array_filter(array_keys($args), function ($key) {
- return ('f_' === substr($key, 0, 2));
- });
- foreach ($fieldFilterKeys as $key) {
- if ('f_ID' === $key) $filtersParams[ $key ] = '=' . $args[ $key ];
- else $filtersParams[ $key ] = '%' . $args[ $key ] . '%';
- }
- $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
- $query = $acl->buildQuery(array_merge([
- 'cols' => array_merge(self::$FIELD_LIST_PRACOWNICY, [
- 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
- ]),
- //'f_ID' => $id,
- 'limit' => $limit,
- 'limitstart' => $limitstart, // offset
- 'order_by' => 'ID', // sortowanie po kolumnie
- 'order_dir' => 'DESC', // kierunek sortowania
- // 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
- // 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
- // 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
- // 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
- ], $searchParams, $filtersParams, $backRefFilter));
- $total = $query->getTotal();
- $items = $query->getItems();
- $pagination = array();
- $pagination['total_items'] = $total;
- $pagination['size'] = ceil($total/$limit); // pages size
- $pagination['current'] = $page;
- $pagination['limit'] = $limit;
- // $idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
- if ($idGroup > 0) $pagination['filter_idGroup'] = $idGroup;
- // { // tworzenie własnego zapytanie mysql
- // $rootTableName = $acl->getRootTableName();
- // DB::getPDO()->fetchAll("
- // select t.*
- // from {$rootTableName} t
- // where t.ID in (
- // select x.ID
- // from ... x
- // where
- // )
- // ");
- // }
- return [
- 'type' => 'success',
- 'msg' => 'showPracownicy',
- 'body' => [
- 'items' => $items,
- //'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
- 'pagination' => $pagination
- ],
- '__DBG_$idGroup' => $idGroup,
- '__DBG_$filtersParams' => $filtersParams,
- '__DBG_$backRefFilter' => $backRefFilter,
- ];
- }
- public function showTablePracownicy($labels = []) {
- // TODO: use self::$FIELD_LIST_PRACOWNICY
- $view = '<form class="form-horizontal" method="post">
- <table class="table table-responsive table-bordered table-hover table-striped" height=5>
- <thead>
- <tr>
- <td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
- <td width=1>' . V::get('ID', 'ID', $labels) . '</td>
- <td>' . V::get('imiona', 'Imię/Imiona', $labels) . '</td>
- <td>' . V::get('nazwisko', 'Nazwisko', $labels) . '</td>
- <td>' . V::get('nip', 'NIP', $labels) . '</td>
- <td>' . V::get('pesel', 'Pesel', $labels) . '</td>
- <td>' . V::get('regon', 'Regon', $labels) . '</td>
- <td>' . V::get('source', 'source', $labels) . '</td>
- <td>' . V::get('jednostka_organizacyjna', 'jednostka_organizacyjna', $labels) . '</td>
- <td>' . V::get('A_STATUS', 'A_STATUS', $labels) . '</td>
- <td>' . V::get('A_STATUS_INFO', 'A_STATUS_INFO', $labels) . '</td>
- <td>' . V::get('L_APPOITMENT_USER', 'L_APPOITMENT_USER', $labels) . '</td>
- <td>' . V::get('Adresy', 'Adresy', $labels) . '</td>
- </tr>
- <tr>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- </tr>
- </thead>
- <tbody id="body-pracownicy">
- </tbody></table>
- </form>';
- return $view;
- }
- // tworzenie grupy pracowników
- public function createPracownicyGroupAjaxAction() {
- 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
- }
- public function createPracownicyGroupAjax($args) {
- $nazwa = V::get('NAZWA', '', $args);
- // validate
- if (!$nazwa) throw new Exception("Nie wybrano grupa");
- $idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_group', [
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- 'NAZWA' => $nazwa,
- 'ID_USER' => User::getID()
- ]);
- return [
- 'msg' => "Utworzona grupę {$nazwa}",
- 'type' => "success",
- 'body' => [
- 'id' => $idGroup,
- 'nazwa' => $nazwa
- ]
- ];
- }
- // Dodanie do grupy filtra pracowników
- public function addPracownicyToGroupAjaxAction() {
- 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
- }
- public function addPracownicyToGroupAjax($args) {
- $idGroup = V::get('idGroup', '', $args);
- $type = V::get('type', 'ids', $args);
- $pracownicyIds = V::get('pracownicyIds', '', $args);
- $filter = V::get('filter', '', $args);
- // validate
- if (!$idGroup) throw new Exception("Nie wybrano grupa");
- switch ($type) {
- case 'ids': {
- if (!$pracownicyIds || count($pracownicyIds) == 0) throw new Exception("Proszę wybrać pracowników");
- } break;
- case 'filter': {
- if (empty($filter)) throw new Exception("Proszę wybrać pracowników");
- } break;
- default: throw new Exception("Missing type");
- }
- // TODO: SPRWADZENIE CZY NIE DODANOU JUZ PRACOWNIKAS
- // default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group
- // default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY
- $group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'ID_USER',
- 'NAZWA',
- ],
- // 'f_ID_USER' => User::getID()
- ])->getItem($idGroup);
- if (!$group) throw new Exception("Grupa nie istnieje");
- if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");
- if ('filter' === $type) {
- $args__idGroup = V::get('filterIdGroup', 0, $filter, 'int'); // dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
- if ($args__idGroup < 0) $args__idGroup = 0;
- $search = V::get('search', '', $filter);
- $searchParams = [];
- if (!empty($search)) {
- $ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
- $searchParams['ogc:Filter'] = '
- <ogc:Filter>
- <ogc:Or>
- <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>nip</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
- <ogc:PropertyName>nazwisko</ogc:PropertyName>
- <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
- </ogc:PropertyIsLike>
- </ogc:Or>
- </ogc:Filter>
- ';
- }
- $backRefFilter = [];
- if ($args__idGroup > 0) {
- $backRefFilter['__backRef'] = [
- 'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- 'primaryKey' => $args__idGroup,
- 'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- ];
- }
- $filtersParams = [];
- $fieldFilterKeys = array_filter(array_keys($filter), function ($key) {
- return ('f_' === substr($key, 0, 2));
- });
- foreach ($fieldFilterKeys as $key) {
- $filtersParams[ $key ] = '%' . $filter[ $key ] . '%';
- }
- $acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
- $query = $acl->buildQuery(array_merge([
- 'cols' => ['ID'],
- ], $searchParams, $filtersParams, $backRefFilter, [
- 'limit' => 0
- ]));
- $items = $query->getItems();
- $pracownicyIds = array_map(function ($row) {
- return $row['ID'];
- }, $items);
- }
- ACL::addListRef(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- $refPrimaryKey = $idGroup,
- $refListRemotePrimaryKey = $pracownicyIds
- );
- return [
- 'msg' => "Powiązano pracowników z grupą {$idGroup}",
- 'type' => "success",
- ];
- }
- public function fetchGroupPracownicyAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
- }
- public function fetchGroupPracownicyAjax() {
- $query = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_group/BI_audit_ENERGA_PRACOWNICY_group')->buildQuery([
- 'cols' => [ // TODO:? propertyName = []
- 'ID',
- 'ID_USER',
- 'NAZWA',
- ],
- 'f_ID_USER' => "=" . User::getID(), // szukamy dokładnie tej wartości - mysql: where ID_USER = "1"
- 'f_A_STATUS' => "!DELETED", // `A_STATUS` != 'DELETED'
- ]);
- $items = $query->getItems();
- DBG::log($items,'array',"grupy");
- if (empty($items)) throw new AlertWarningException("Grupy nie istnieją");
- $arrayGroupPracownicy = array();
- foreach ($items as $item) {
- // if (User::getID() != $item['ID_USER']) throw new Exception("Brak uprawnień do grupy"); // or skip - continue;
- $arrayGroupPracownicy[] = [
- 'ID' => $item['ID'],
- 'NAZWA' => $item['NAZWA'],
- ];
- }
- return [
- 'type' => 'success',
- 'msg' => 'fetchGroupPracownicyAjax',
- '__req_args' => $_REQUEST,
- '__args' => $args,
- 'body' => [
- 'itmesGroupPracownicy' => $arrayGroupPracownicy
- ]
- ];
- }
- function mapShortNs($shortNs) {
- switch ($shortNs) {
- case 'KRS': return 'default_db/BI_audit_KRS/BI_audit_KRS';
- case 'KRS/p': return 'default_db/BI_audit_KRS_person/BI_audit_KRS_person';
- case 'MSIG': return 'default_db/BI_audit_MSIG/BI_audit_MSIG';
- case 'MSIG/p': return 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person';
- case 'CEIDG': return 'default_db/BI_audit_CEIDG/BI_audit_CEIDG';
- default: throw new Exception("Not implemented short Ns '{$shortNs}'");
- }
- }
- public function generateBiAuditRaportAjaxAction() {
- Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- }
- public function generateBiAuditRaportAjax($args) {
- $depthValue = V::get('depthValue', '', $args);
- if (!$depthValue) {
- throw new Exception("Nie podano wartości dla głębokości powiązań");
- }
- $smadReaportTitle = V::get('smadReaportTitle', '', $args);
- if (!$smadReaportTitle) {
- throw new Exception("Nie podano tytułu raportu");
- }
- $analizaOnlyTargets = V::get('analizaOnlyTargets', '', $args);
- if (!$analizaOnlyTargets) {
- throw new Exception("Nie podano wartości czy zwracać wyniki tylko z obiektami docelowymi");
- }
- $pracownicyIds = V::get('pracownicyIds', [], $args, 'uint_array'); // array of int > 0
- $kontrahenciIds = V::get('kontrahenciIds', [], $args, 'uint_array'); // array of int > 0
- $pozostaleOd = V::get('pozostaleOd', [], $args, 'array');
- $pozostaleDo = V::get('pozostaleDo', [], $args, 'array');
- $allOdLength = count($pracownicyIds) + count($pozostaleOd);
- $allDoLength = count($kontrahenciIds) + count($pozostaleDo);
- // walidacja listy kontrahentów i pracowników
- if ( !$allOdLength && !$allDoLength ) {
- throw new Exception("Nie wybrano pozycji do analizy. Wybierz pracowników/kontrahentów.");
- }
- // TODO: analizaOnlyTargets = ( 'y' | 'n' ) - allDoLength should depend of analizaOnlyTargets?
- // Tworzenie rekrodu w bazie - Raport -
- $idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- 'L_APPOITMENT_INFO' => $smadReaportTitle,
- 'FILE_STATUS' => "TO_GENERATE",
- 'A_STATUS' => "NORMAL",
- 'BI_analiza_minDepth' => 1,
- 'BI_analiza_maxDepth' => $depthValue,
- 'BI_analiza_onlyTargets' => $analizaOnlyTargets
- ]);
- if ($idRaport <= 0) throw new Exception("Nie udało się dodać nowego raportu");
- DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_HIST', [
- 'ID_USERS2' => $idRaport,
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- 'L_APPOITMENT_INFO' => $smadReaportTitle,
- 'FILE_STATUS' => "TO_GENERATE",
- 'A_STATUS' => "NORMAL",
- 'BI_analiza_minDepth' => 1,
- 'BI_analiza_maxDepth' => $depthValue,
- 'BI_analiza_onlyTargets' => $analizaOnlyTargets
- ]);
- if (!empty($pracownicyIds)) {
- ACL::addListRef(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
- $refPrimaryKey = $idRaport,
- $refListRemotePrimaryKey = $pracownicyIds
- );
- }
- if (!empty($kontrahenciIds)) {
- ACL::addListRef(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
- $refPrimaryKey = $idRaport,
- $refListRemotePrimaryKey = $kontrahenciIds
- );
- }
- if (!empty($pozostaleOd)) {
- foreach ($pozostaleOd as $featureKey) {
- $idOd = DB::getPDO()->insert('BI_audit_POWIAZANIA_OD', [
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- // TODO: ? add OD_HIST
- ACL::addRef(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_POWIAZANIA_OD:BI_audit_POWIAZANIA_OD',
- $refPrimaryKey = $idRaport,
- $refRemotePrimaryKey = $idOd
- );
- list($shortNs, $featurePk) = explode('.', $featureKey);
- $featureNs = $this->mapShortNs($shortNs);
- ACL::addRef(
- $rootObjectNamespace = 'default_db/BI_audit_POWIAZANIA_OD/BI_audit_POWIAZANIA_OD',
- $fieldTypeName = Api_WfsNs::typeName($featureNs),
- $refPrimaryKey = $idOd,
- $refRemotePrimaryKey = $featurePk
- );
- }
- }
- if (!empty($pozostaleDo)) {
- foreach ($pozostaleDo as $featureKey) {
- $idDo = DB::getPDO()->insert('BI_audit_POWIAZANIA_DO', [
- 'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
- 'A_RECORD_CREATE_DATE' => 'NOW()',
- ]);
- // TODO: ? add DO_HIST
- ACL::addRef(
- $rootObjectNamespace = 'default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
- $fieldTypeName = 'default_db__x3A__BI_audit_POWIAZANIA_DO:BI_audit_POWIAZANIA_DO',
- $refPrimaryKey = $idRaport,
- $refRemotePrimaryKey = $idDo
- );
- list($shortNs, $featurePk) = explode('.', $featureKey);
- $featureNs = $this->mapShortNs($shortNs);
- ACL::addRef(
- $rootObjectNamespace = 'default_db/BI_audit_POWIAZANIA_DO/BI_audit_POWIAZANIA_DO',
- $fieldTypeName = Api_WfsNs::typeName($featureNs),
- $refPrimaryKey = $idDo,
- $refRemotePrimaryKey = $featurePk
- );
- }
- }
- return [
- 'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
- 'type' => "success",
- 'body' => [
- 'id' => $idRaport,
- ]
- ];
- }
- /**
- * Widok formularza dodawania pracowników i kontrahentów
- */
- public function defaultViewFormBiAudit($items, $type) {
- $activeFormSteps = '';
- $fieldLabels = [];
- $currentDate = date("j.n.Y");
- $btnGrafPowiazan = '';
- switch ($type) {
- 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;
- 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;
- }
- $formFilterHeadDesc = '';
- switch ($type) {
- case 'PRACOWNICY': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-pracownicy">0</span>'; break;
- case 'KONTRAHENCI': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span>'; break;
- case 'OPERACYJNA_BAZA_ZGLOSZEN': $formFilterHeadDesc = 'Liczba pozycji na liście: <span id="smad-filter-desc-kontrahenci">0</span>'; break;
- }
- $formAddNewData = '';
- switch($type) {
- case 'KONTRAHENCI':
- $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
- $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci" style="margin-top:0">Wszyscy</h2>';
- $countSelectedItem = '<div>Wybrano: <span id="count-selected-item-kontrahenci">0</span> <span><a title="wyczyść zapamietanych kontrahentów" class="link-primary" onClick="clearListLocalStorageByType(\'kontrahenci\')"><small>(wyczyść)</small></a></span></div>';
- $graphView = '<div class="smad-kontrahenci-graph-view" id="smad-kontrahenci-graph-view" style="display: none;"></div>';
- $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
- // $formAddNewData ='
- // <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
- // <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
- $pagination_form = '<div id="pagination-kontrahenci"></div>';
- $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
- $fieldList = $acl->getRealFieldList();
- $fieldLabels = array_combine(
- $fieldList,
- array_map(function ($fieldName) use ($acl) {
- return $acl->getFieldLabel($fieldName);
- }, $fieldList)
- );
- DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
- break;
- case 'OPERACYJNA_BAZA_ZGLOSZEN':
- $formSmadSelectTarget = '<select class="form-control" id="smad-select-target-kontrahenci"><option value="y">tak</option><option value="n">nie</option></select>';
- $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-kontrahenci" style="margin-top:0">Wszyscy</h2>';
- $countSelectedItem = '<div>Wybrano: <span id="count-selected-item-kontrahenci">0</span> <span><a title="wyczyść zapamietanych kontrahentów" class="link-primary" onClick="clearListLocalStorageByType(\'kontrahenci\')"><small>(wyczyść)</small></a></span></div>';
- $graphView = '<div class="smad-kontrahenci-graph-view" style="display: none;"></div>';
- $csvExampleKontrahenci = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/kontrahenci_example.zip';
- // $formAddNewData ='
- // <li><a title="IMPORT KONTRAHENCI" onClick="showViewUploadFile(event, \'Import podmiotów/kontrahentów\', \'kontrahenci\', \'no\', \''.$csvExampleKontrahenci.'\' )" class="btn btn-info">IMPORT KONTRAHENCI</a></li>
- // <li><a title="DODAJ KONTRAHENCI" onClick="createKontrahentAjax(event)" class="btn btn-info">+ DODAJ PODMIOT</a></li>'; //todo: dodać obsługe doddawania kontrahentow
- $pagination_form = '<div id="pagination-kontrahenci"></div>';
- $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI");
- $fieldList = $acl->getRealFieldList();
- $fieldLabels = array_combine(
- $fieldList,
- array_map(function ($fieldName) use ($acl) {
- return $acl->getFieldLabel($fieldName);
- }, $fieldList)
- );
- DBG::log($fieldLabels, 'array', "fieldLabels (KONTRAHENCI)");
- break;
- case 'PRACOWNICY':
- $formSmadSelectTarget = '<select class="form-control" id="smad-select-target"><option value="y">tak</option><option value="n">nie</option></select>';
- $formFilterHeadTitle = '<h2 class="title" id="smad-filter-head-title-pracownicy" style="margin-top:0">Wszyscy</h2>';
- $countSelectedItem = '<div>Wybrano: <span id="count-selected-item-pracownicy">0</span> <span><a title="wyczyść zapamietanych pracowników" class="link-primary" onClick="clearListLocalStorageByType(\'pracownicy\')"><small>(wyczyść)</small></a></span></div>';
- $graphView = '<div class="smad-pracownicy-graph-view" id="smad-pracownicy-graph-view" style="display: none;"></div>';
- $csvExamplePracownicy = Request::getPathUri() . 'projects/bocian/theme/assets/file_example/pracownicy_example.zip';
- // $formAddNewData ='
- // <li><a title="IMPORT PRACOWNIKÓW" onClick="showViewUploadFile(event, \'Import osób\', \'pracownicy\', \'yes\', \''.$csvExamplePracownicy.'\' )" class="btn btn-info">IMPORT PRACOWNIKÓW</a></li>
- // <li><a title="DODAJ PRACOWNIKÓW" onClick="createPracownikAjax(event)" class="btn btn-info" >+ DODAJ OSOBĘ</a></li>'; //todo: dodać obsługe doddawania pracownikow
- $pagination_form = '<div id="pagination-pracownicy"></div>';
- $acl = ACL::getAclByNamespace("default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY");
- $fieldList = $acl->getRealFieldList();
- $fieldLabels = array_combine(
- $fieldList,
- array_map(function ($fieldName) use ($acl) {
- return $acl->getFieldLabel($fieldName);
- }, $fieldList)
- );
- DBG::log($fieldLabels, 'array', "fieldLabels (PRACOWNICY)");
- break;
- }
- $outLinkOD = $this->getLink() . "#PRACOWNICY";
- $outLinkDO = $this->getLink() . "#KONTRAHENCI";
- $outStepOdCompleted = 'complete';
- $outStepDoCompleted = '';
- switch ($type) {
- case 'KONTRAHENCI': $outStepDoCompleted = 'complete'; break;
- case 'OPERACYJNA_BAZA_ZGLOSZEN': $outStepDoCompleted = 'complete'; break;
- }
- $outHeaderTitle = '';
- switch ($type) {
- case 'KONTRAHENCI': $outHeaderTitle = 'Kontrahenci'; break;
- case 'OPERACYJNA_BAZA_ZGLOSZEN': $outHeaderTitle = 'KONTRAHENCI/PODMIOTY'; break;
- case 'PRACOWNICY': $outHeaderTitle = 'Pracownicy'; break;
- }
- $groupFilterList = '';
- switch($type) {
- case 'PRACOWNICY':
- $groupFilterList .= '
- <a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" >+ STWÓRZ GRUPĘ</a>
- <div id="group-pracownicy" class="btn-group" style="margin-left:12px">
- <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
- </div>
- ';
- break;
- case 'KONTRAHENCI':
- $groupFilterList .= '
- <a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a>
- <div id="group-kontrahenci" class="btn-group" style="margin-left:12px">
- <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
- </div>
- ';
- break;
- case 'OPERACYJNA_BAZA_ZGLOSZEN':
- $groupFilterList .= '
- <a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a>
- <div id="group-kontrahenci" class="btn-group" style="margin-left:12px">
- <button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
- </div>
- ';
- break;
- }
- $groupFilterList = '
- <h4 style="margin-top:0; margin-bottom:24px" class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $outHeaderTitle . ' </h4>
- <div>
- '.$groupFilterList.'
- </div>
- ';
- $buttonMoveToGroup = '';
- switch($type) {
- case 'KONTRAHENCI':
- $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
- $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
- $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
- break;
- case 'OPERACYJNA_BAZA_ZGLOSZEN':
- $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addKontrahenciToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
- $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addKontrahenciAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
- $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removeKontrahenciFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
- break;
- case 'PRACOWNICY':
- $buttonMoveToGroup = '<a title="DODAJ WYBRANE DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">DODAJ WYBRANE DO GRUPY</a>';
- $buttonMoveToGroup .= '<a title="DODAJ WSZYSTKIE DO GRUPY" onClick="addPracownikAllToGroup(event)" class="btn btn-info" style="margin-left:12px">DODAJ WSZYSTKIE DO GRUPY</a>';
- $buttonMoveToGroup .= '<a title="USUN WYBRANE Z GRUPY" onClick="removePracownikFromGroup(event)" class="btn btn-info" style="margin-left:12px">USUŃ WYBRANE Z GRUPY</a>';
- break;
- }
- $view = '';
- $view .= '<div id="smad-employees-section" class="smad-form-' . $type . '" >';
- $view .= '
- <div class="container-fluid" style="margin-bottom:32px; margin-top:32px">
- <div class="row">
- <div class="col-md-12">
- '.$groupFilterList.'
- </div>
- </div>
- </div>
- <div class="container-fluid">
- <div class="padding-0 smad-employees-list-head">
- <div class="col-md-8">
- <header>
- '.$formFilterHeadTitle.'
- </header>
- <div class="desc">
- <p style="text-align:left">'.$formFilterHeadDesc.'</p>
- </div>
- <div class="countSelectedItem">
- '.$countSelectedItem.'
- </div>
- </div>
- <div class="col-md-4">
- <div class="menu-items">
- <div class="menu-item">
- <ul class="padding-0">
- '.$formAddNewData.'
- </ul>
- </div>
- </div>
- <div style="position:absolute; bottom:0; right:24px">
- '.$btnGrafPowiazan.'
- </div>
- </div>
- </div>
- </div>
- <div class="smad-graph-section">
- <div class="container-fluid">
- '.$graphView.'
- </div>
- </div>
- <div class="container-fluid">
- <div class="table-responsive padding-0" id="smad-table-' . $type . '">
- ' . $this->showListDataByType($items, $type, $fieldLabels) . '
- </div>
- </div>
- <div class="container-fluid ">
- <div>
- '. $pagination_form .'
- </div>
- </div>
- <div class="container-fluid smad-employees-bottom-navigation">
- <div class="padding-0">
- <div class="col-md-12">
- '.$buttonMoveToGroup.'
- </div>
- </div>
- </div>
- </div>
- ';
- return $view;
- }
- public function showListDataByType($items, $type='PRACOWNICY', $labels) {
- switch ($type) {
- case 'PRACOWNICY':
- return $this->showTablePracownicy($labels);
- break;
- case 'KONTRAHENCI':
- return $this->showTableKontrahenci($labels);
- break;
- }
- }
- function fetchProgressAjaxAction() {
- Response::sendTryCatchJson(array($this, 'fetchProgressAjax'), $args = 'JSON_FROM_REQUEST_BODY');
- }
- function fetchProgressAjax($args) {
- $DBG_FAKE_ANIM = false;
- if (empty($args['ids'])) return [ 'msg' => "empty ids", 'type' => "success" ];
- $ids = $args['ids'];
- if ('last' === $ids) {
- $ids = [
- DB::getPDO()->fetchValue(" select ID from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA order by ID DESC limit 1 ")
- ];
- }
- // private static function getDirectory($table, $id) {
- $firstId = reset($ids);
- {
- Lib::loadClass('FoldersConfig');
- $folderConf = FoldersConfig::getAll('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_COLUMN');
- if (!isset($folderConf['mount_point'])) throw new HttpException("Błąd danych konfiguracyjnych<br>\n{$errMsg}", 404);
- $rootPath = $folderConf['mount_point'];
- }
- $statuses = array_map(function ($id) {
- return DB::getPDO()->fetchValue(" select FILE_STATUS from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
- }, $ids);
- $statusesInfo = array_map(function ($id) {
- return DB::getPDO()->fetchValue(" select FILE_STATUS_info from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = :id ", [ ':id' => $id ]);
- }, $ids);
- $progress = array_map(function ($id, $idx) use ($rootPath, $statuses, $DBG_FAKE_ANIM) {
- DBG::log("Loop id({$id}) is-eq-82(".(82 == $id).") is-eq-'82'(".("82"==$id).")");
- DBG::log("Loop id({$id}) is-eq-80(".(80 == $id).") is-eq-'80'(".("80"==$id).")");
- $status = $statuses[$idx];
- if ($DBG_FAKE_ANIM && 82 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
- if ($DBG_FAKE_ANIM && 80 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
- if ($DBG_FAKE_ANIM && 77 == $id) $status = 'IN_PROGRESS'; // TODO: DBG
- DBG::log("Loop id({$id}) status({$status})...");
- if ('GENERATED' === $status) return 1;
- if ('IN_PROGRESS' !== $status) return 0;
- if (!file_exists("{$rootPath}/.tasks/generatePowiazania-{$id}.progress")) return 0;
- DBG::log("Loop id({$id}) status({$status}) progress file exists");
- try {
- $cnt = file_get_contents("{$rootPath}/.tasks/generatePowiazania-{$id}.progress");
- $json = @json_decode($cnt, $assoc = true);
- if (null === $json && 0 !== json_last_error()) {
- throw new Exception("Parse json error for restrictions: " . json_last_error());
- }
- // $json['summary']['step']: 'initialize', 'relations', 'reports'
- // $json['summary']['step'] = 'initialize' - recache - skip
- // $json['summary']['step'] = 'relations' - szuka powiązań (@see AVG(details.progress / summary.count))
- // $json['summary']['step'] = 'reports' - generuje pliki (@see summary.created)
- /*
- if ($DBG_FAKE_ANIM && 82 == $id) { // TODO: DBG
- $json = [
- 'summary' => [
- 'count' => 4,
- 'step' => 'relations',
- ],
- 'details' => [
- '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '22' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- ] ];
- }
- */
- if ($DBG_FAKE_ANIM && 80 == $id) { // TODO: DBG
- $json = [
- 'summary' => [
- 'count' => 4,
- 'created' => 2,
- 'step' => 'reports',
- ],
- 'details' => [
- '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '22' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '25' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- ] ];
- }
- if ($DBG_FAKE_ANIM && 77 == $id) { // TODO: DBG
- $json = [
- 'summary' => [
- 'count' => 4,
- 'created' => 2,
- 'step' => 'relations',
- ],
- 'details' => [
- '9' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '19' => [ 'progress' => 1, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '22' => [ 'progress' => 0.25, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- '25' => [ 'progress' => 0, 'results' => 123, 'elapsed' => 45.286203145981, 'estimated' => 0 ],
- ] ];
- }
- DBG::log($json, 'array', "Loop id({$id}) status({$status}) progress json");
- if (empty($json['summary'])) return 0;
- if (empty($json['summary']['count'])) return 0;
- if (empty($json['summary']['step'])) return 0;
- if (empty($json['details'])) return 0;
- $listDetailsProgress = array_map(function ($detail) {
- return floatval($detail['progress']);
- }, $json['details']);
- $relationsProgress = $json['summary']['count'] > 0 ? round(floatval(array_sum($listDetailsProgress)) / floatval($json['summary']['count']), 3) : 0;
- $reportsCount = V::get('reportsCount', 0, $json['summary'], 'float');
- $reportsProgress = $reportsCount > 0 ? round(V::get('reportsCreated', 0, $json['summary'], 'float') / $reportsCount, 3) : 0;
- return round(0.5 * $relationsProgress + 0.5 * $reportsProgress, 3);
- } catch (Exception $e) {
- DBG::log($e);
- }
- return 0;
- }, $ids, array_keys($ids));
- return [ 'msg' => "DBG ids set", 'type' => "success", 'body' => [
- 'ids' => $ids,
- 'progress' => $progress,
- 'statuses' => $statuses,
- 'statusesInfo' => $statusesInfo,
- ] ];
- }
- }
|