Forráskód Böngészése

fixed vendor.js version, fixed filterBy, fixed ogc query for multiple words

Piotr Labudda 7 éve
szülő
commit
175494d0ba
2 módosított fájl, 333 hozzáadás és 366 törlés
  1. 310 345
      tools/Bocian.php
  2. 23 21
      tools/Bocian.php.addItemToRaport.js

+ 310 - 345
tools/Bocian.php

@@ -220,7 +220,7 @@ TODO: dodać możliwość wysyłania maila używajac mail()
 				return "f_{$fieldName}";
 			}, self::$FIELD_LIST_KONTRAHENCI),
 		]);
-		echo UI::h('script', ['src'=>"static/vendor.js", 'type'=>"text/javascript"]);
+		echo UI::h('script', ['src'=>"static/vendor.js?v=48ea11d5", 'type'=>"text/javascript"]);
 		UI::inlineJS(__FILE__ . '.addItemToRaport.js', [
 			'URL_FETCH_FROM_BAZA' => $this->getLink('fetchFromBazaAjax'),
 			'URL_SAVE_TO_DB' => $this->getLink('saveToPracownicyAjax'),
@@ -1470,38 +1470,55 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 	public function fetchFromBazaAjax($args) {
 		$baza = V::get('baza', '', $args);
 		$query = V::get('query', '', $args);
+		$query = trim($query);
 		if (strlen($query) < 3) throw new Exception("Query must be more then 2 chars");
-		switch ($baza) {
-			case 'default_db/BI_audit_KRS/BI_audit_KRS': return $this->fetchFromKRS($query);
-			case 'default_db/BI_audit_KRS_person/BI_audit_KRS_person': return $this->fetchFromKRSPerson($query);
-			case 'default_db/BI_audit_MSIG/BI_audit_MSIG': return $this->fetchFromMSIG($query);
-			case 'default_db/BI_audit_MSIG_person/BI_audit_MSIG_person': return $this->fetchFromMSIGPerson($query);
-			case 'default_db/BI_audit_taxpayer/BI_audit_taxpayer': return $this->fetchFromVATp($query);
-			case 'default_db/BI_audit_CEIDG/BI_audit_CEIDG': return $this->fetchFromCEIDG($query);
 
+		$wordsQuery = [];
+		if (false !== strpos($query, ' ')) {
+			$words = explode(' ', $query);
+			DBG::log($words, 'array', "\$words from \$query({$query}) - 1");
+			$words = array_map('trim', $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;
 		}
-}
-function fetchFromKRS($query){
-		$ogcSearch = "*{$query}*";
-		$searchParams = [];
-		$searchParams['ogc:Filter'] = '
-			<ogc:Filter>
-				<ogc:Or>
-					<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
-						<ogc:PropertyName>nazwa</ogc:PropertyName>
-						<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
-					</ogc:PropertyIsLike>
-					<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>S_miejscowosc</ogc:PropertyName>
-						<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
-					</ogc:PropertyIsLike>
-				</ogc:Or>
-			</ogc:Filter>
-		';
+
+		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[] = 'S_miejscowosc';
+		$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',
@@ -1565,7 +1582,65 @@ function fetchFromKRS($query){
 		];
 	}
 
-	function fetchFromKRSPerson($query){
+	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'] = '
@@ -1586,11 +1661,9 @@ function fetchFromKRS($query){
 					</ogc:Or>
 				</ogc:Filter>
 			';
-			$items = ACL::getAclByNamespace('default_db/BI_audit_KRS_person/BI_audit_KRS_person')->buildQuery(array_merge([
+			$items = ACL::getAclByNamespace('default_db/BI_audit_taxpayer/BI_audit_taxpayer')->buildQuery(array_merge([
 				'cols' => [ // TODO:? propertyName = []
-					'nazwisko',
-					'imiona',
-					'pesel',
+					'nip',
 					'ID',
 					// 'dataDokumentu',
 					// 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
@@ -1617,7 +1690,7 @@ function fetchFromKRS($query){
 						//$nazwa = str_replace([ '"', "'" ], '', $item['nazwa']);
 						//$nazwa = $item['nazwisko'];
 						//$item['nazwa'] = $nazwa;
-						$item['label'] = "{$item['nazwisko']}, {$item['imiona']}, {$item['pesel']}";
+						$item['label'] = "{$item['nip']}";
 						// 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
 
 						return $item;
@@ -1636,318 +1709,210 @@ function fetchFromKRS($query){
 			];
 		}
 
-		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[] = 'nip';
+		$searchableFields[] = 'S_miejscowosc';
+		$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}'");
 
-		function fetchFromMSIG($query){
-				$ogcSearch = "*{$query}*";
-				$searchParams = [];
-				$searchParams['ogc:Filter'] = '
-					<ogc:Filter>
-						<ogc:Or>
-							<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
-								<ogc:PropertyName>nazwa</ogc:PropertyName>
-								<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
-							</ogc:PropertyIsLike>
-							<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>S_miejscowosc</ogc:PropertyName>
-								<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
-							</ogc:PropertyIsLike>
-						</ogc:Or>
-					</ogc:Filter>
-				';
-				$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("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),
-					]
-				];
-			}
+		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'] = "{$nazwa}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}";
+					// 'searchLabel' => "{$item['nazwa']}, {$item['A_miejscowosc']}, {$item['krs']}, {$item['nip']}, {$item['regon']}",
 
-			function fetchFromMSIGPerson($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_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),
-						]
-					];
-				}
+					return $item;
 
-				function fetchFromCEIDG($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>imie</ogc:PropertyName>
-										<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
-									</ogc:PropertyIsLike>
-									<ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
-										<ogc:PropertyName>miejscowosc</ogc:PropertyName>
-										<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
-									</ogc:PropertyIsLike>
-								</ogc:Or>
-							</ogc:Filter>
-						';
-						$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['imie']}, {$item['nazwisko']}, {$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),
-							]
-						];
-					}
+					// 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[] = 'nazwisko';
+		$searchableFields[] = 'imie';
+		$searchableFields[] = 'miejscowosc';
+		$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['imie']}, {$item['nazwisko']}, {$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),
+			]
+		];
+	}
 
 
 	public function showTableKontrahenci($labels = []) {

+ 23 - 21
tools/Bocian.php.addItemToRaport.js

@@ -45,6 +45,24 @@ function convertXlinkToObjects(items) {
   })
 }
 
+function filterByHelper(option, text) {
+  var label = option.label.toLowerCase();
+  var words = ( (text.indexOf(' ') > 0)
+    ? text.split(' ')
+    : [ text ]
+  ).map(function (word) { return word.trim().toLowerCase(); })
+  .filter(function (word) { return word.length > 2; });
+  var foundWords = words.filter(function (word) {
+    return (label.indexOf(word) > -1);
+  })
+  return (foundWords.length === words.length);
+}
+// function (option, text) {
+//   if (option.ID == 161323) return false;
+//   console.log('TODO: filterBy...', {option, text});
+//   return true;
+// },
+
 var P5UI_AddItemToReport_SelectKrsPerson = createReactClass({
   // h(SelectKrsPerson, { krs: this.state.selected })
   // this.props.krs: {
@@ -285,10 +303,7 @@ var P5UI_AddItemToReport = createReactClass({
                 placeholder: "Wyszukaj...",
                 onChange: handleSelected,
                 autoFocus: true,
-                // filterBy: function (option, text) {
-                //   console.log('TODO: filterBy...', {option, text});
-                //   return true;
-                // },
+                filterBy: filterByHelper,
                 renderMenuItemChildren: function (option, props) {
                     return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
                 }
@@ -315,10 +330,7 @@ var P5UI_AddItemToReport = createReactClass({
                 placeholder: "Wyszukaj...",
                 onChange: handleSelected,
                 autoFocus: true,
-                // filterBy: function (option, text) {
-                //   console.log('TODO: filterBy...', {option, text});
-                //   return true;
-                // },
+                filterBy: filterByHelper,
                 renderMenuItemChildren: function (option, props) {
                     return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
                 }
@@ -345,10 +357,7 @@ var P5UI_AddItemToReport = createReactClass({
                 placeholder: "Wyszukaj...",
                 onChange: handleSelected,
                 autoFocus: true,
-                // filterBy: function (option, text) {
-                //   console.log('TODO: filterBy...', {option, text});
-                //   return true;
-                // },
+                filterBy: filterByHelper,
                 renderMenuItemChildren: function (option, props) {
                     return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
                 }
@@ -375,10 +384,7 @@ var P5UI_AddItemToReport = createReactClass({
                 placeholder: "Wyszukaj...",
                 onChange: handleSelected,
                 autoFocus: true,
-                // filterBy: function (option, text) {
-                //   console.log('TODO: filterBy...', {option, text});
-                //   return true;
-                // },
+                filterBy: filterByHelper,
                 renderMenuItemChildren: function (option, props) {
                     return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
                 }
@@ -405,10 +411,7 @@ var P5UI_AddItemToReport = createReactClass({
                 placeholder: "Wyszukaj...",
                 onChange: handleSelected,
                 autoFocus: true,
-                // filterBy: function (option, text) {
-                //   console.log('TODO: filterBy...', {option, text});
-                //   return true;
-                // },
+                filterBy: filterByHelper,
                 renderMenuItemChildren: function (option, props) {
                     return h(P5UI_AddItemToReport_BazaMenuItem, { key: option.ID, baza: selectedBaza, data: option });
                 }
@@ -506,7 +509,6 @@ var P5UI_AddItemToReport = createReactClass({
                   companyPostCode: document.getElementById('companyPostCode').value,
                   companyCity: document.getElementById('companyCity').value,
                   companyKrs: document.getElementById('companyKrs').value,
-
                 })
               }.bind(this) }, "Dodaj podmiot")
             ]),