Ver código fonte

pobieranie z krs

michalzmijewski 7 anos atrás
pai
commit
43a0ab59c6
2 arquivos alterados com 144 adições e 28 exclusões
  1. 54 0
      tools/Bocian.php
  2. 90 28
      tools/Bocian.php.addItemToRaport.js

+ 54 - 0
tools/Bocian.php

@@ -222,6 +222,9 @@ TODO: dodać możliwość wysyłania maila używajac mail()
 		]);
 		echo UI::h('script', ['src'=>"static/vendor.js", 'type'=>"text/javascript"]);
 		UI::inlineJS(__FILE__ . '.addItemToRaport.js', [
+			'URL_FETCH_FROM_BAZA' => $this->getLink('fetchFromBazaAjax'),
+			'URL_SAVE_TO_PRACOWNICY' => $this->getLink('saveToPracownicyAjax'),
+			'URL_SAVE_TO_KONTRAHENCI' =>$this->getLink('saveToKontrahenciAjax')
 		]);
 
 		echo '</div>'; // #smad-wrapper
@@ -915,6 +918,57 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 	}
 
 
+	public function fetchFromBazaAjaxAction() {
+		Response::sendTryCatchJson(array($this, 'fetchFromBazaAjax'), $args = $_REQUEST);
+	}
+	public function fetchFromBazaAjax($args) {
+		$baza= V::get('baza', 1, $args);
+		$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 showTableKontrahenci($labels = []) {
 		// TODO: use self::$FIELD_LIST_KONTRAHENCI
 		$view = '<form class="form-horizontal" method="post">

+ 90 - 28
tools/Bocian.php.addItemToRaport.js

@@ -33,34 +33,67 @@ var P5UI_AddItemToReport = createReactClass({
     },
     _handleSearch: function (query) {
         this.setState({ isSearching: true });
+        var options= [];
         //Baza= this.state.baza;
-        setTimeout(function () {
-            var options = [];
-            options.push({
-                ID: 601900,
-                nazwa: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA",
-                krs: "0000721712", nip: "5862328735", regon: "369609850",
-                S_kraj: "POLSKA", S_miejscowosc: "GDYNIA", A_kod: "81-310", A_ulica: "ŚLĄSKA", A_nrDomu: "35/37",
-                searchLabel: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA, ŚLĄSKA 35/37, 81-310 GDYNIA, krs: 0000721712, nip: 5862328735, regon: 369609850",
-                label: "ADEGROUP SPÓŁKA ..., ŚLĄSKA 35/37, 81-310 GDYNIA"
-            })
-            options.push({
-                ID: 601900,
-                nazwa: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ",
-                krs: "0000721708", nip: "9452218050", regon: "369608402",
-                S_kraj: "POLSKA", S_miejscowosc: "KRAKÓW", A_kod: "31-315", A_ulica: "ELIASZA RADZIKOWSKIEGO", A_nrLokalu: "16", A_nrDomu: "74",
-                searchLabel: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW 0000721708 9452218050 369608402",
-                label: "BIZNESLIMIT.PL ..., ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW"
-            })
-            this.setState({ isSearching: false, options: options });
-        }.bind(this), 1000);
-        // makeAndHandleRequest(query)
-        //   .then(({ options }) => {
-        //     this.setState({
-        //       isLoading: false,
-        //       options,
-        //     });
-        //   });
+        window.fetch(URL_FETCH_FROM_BAZA, {
+					method: 'POST',
+					header: {
+						'contentType': 'applications/json'
+					},
+					credentials: 'same-origin',
+					body: JSON.stringify({
+						'baza': this.state.baza,
+
+					})
+          .then(function(responseText) {
+
+  					try {
+  						return JSON.parse(responseText);
+  					} catch (e) {
+  						throw responseText;
+  					}
+  				})
+  				.then(function(result) {
+
+  					if (result.type == 'success') {
+
+  						p5UI__notifyAjaxCallback(result);
+  						resolve(result.body);
+              options=result.body.items;
+              this.setState({ isSearching: false, options: options });
+  					}
+  				})
+  				.catch(function(error) {
+  					if(DBG) console.log('request failed', error);
+  				})
+				})
+        // setTimeout(function () {
+        //     var options = [];
+        //     options.push({
+        //         ID: 601900,
+        //         nazwa: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA",
+        //         krs: "0000721712", nip: "5862328735", regon: "369609850",
+        //         S_kraj: "POLSKA", S_miejscowosc: "GDYNIA", A_kod: "81-310", A_ulica: "ŚLĄSKA", A_nrDomu: "35/37",
+        //         searchLabel: "ADEGROUP SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ SPÓŁKA KOMANDYTOWA, ŚLĄSKA 35/37, 81-310 GDYNIA, krs: 0000721712, nip: 5862328735, regon: 369609850",
+        //         label: "ADEGROUP SPÓŁKA ..., ŚLĄSKA 35/37, 81-310 GDYNIA"
+        //     })
+        //     options.push({
+        //         ID: 601900,
+        //         nazwa: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ",
+        //         krs: "0000721708", nip: "9452218050", regon: "369608402",
+        //         S_kraj: "POLSKA", S_miejscowosc: "KRAKÓW", A_kod: "31-315", A_ulica: "ELIASZA RADZIKOWSKIEGO", A_nrLokalu: "16", A_nrDomu: "74",
+        //         searchLabel: "BIZNESLIMIT.PL SPÓŁKA Z OGRANICZONĄ ODPOWIEDZIALNOŚCIĄ ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW 0000721708 9452218050 369608402",
+        //         label: "BIZNESLIMIT.PL ..., ELIASZA RADZIKOWSKIEGO 74/16, 31-315 KRAKÓW"
+        //     })
+        //     this.setState({ isSearching: false, options: options });
+        // }.bind(this), 1000);
+        makeAndHandleRequest(query)
+          .then(({ options }) => {
+            this.setState({
+              isLoading: false,
+              options,
+            });
+          });
     },
     componentWillUnmount: function () {
         DBG && console.log("DBG: conponentDidUnmount...");
@@ -159,12 +192,41 @@ var P5UI_AddItemToReport = createReactClass({
                 }
             }),
             selectedNewItem && h('p', {}, "Dodaj nowy ... " + selectedNewItem),
+            //TODO dlaczego to nie działa
+            // selectedNewItem && h('div', {className='form-group'},[
+              // h('input',{
+              //   className:'form-control required',
+              //   id:'personName',
+              //   placeholder:'Imię'
+              // }),
+              // h('input',{
+              //   className:'form-control required',
+              //   id:'personSurname',
+              //   placeholder:'Nazwisko'
+              // },[]),
+              // h('input',{
+              //   className:'form-control required',
+              //   id:'personNip',
+              //   placeholder:'NIP'
+              // },[]),
+              // h('input',{
+              //   className:'form-control required',
+              //   id:'personPesel',
+              //   placeholder:'personPesel'
+              // },[]),
+              // h('input',{
+              //   className:'form-control required',
+              //   id:'personRegon',
+              //   placeholder:'REGON'
+              // },[])
+            // ]
+            // ),
             // '' === selectedNewItem && h
             (selectedBaza && this.state.selected) && h('div', { style: { marginTop: '22px' } }, [
                 h('button', {
                     className: "btn btn-success active",
                     onClick: function () {
-                        //this.props.onSelect(this.state.baza, this.state.selected)
+                        this.props.onSelect(this.state.baza, this.state.selected);
                         ReactDOM.unmountComponentAtNode(document.getElementById('createPracownikAjax__searchBaza'));
                         swal.close()
                     }