|
@@ -2511,17 +2511,17 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
$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:Or>
|
|
|
+ <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
|
|
|
+ <ogc:PropertyName>nip</ogc:PropertyName>
|
|
|
<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
|
|
|
- </ogc:PropertyIsLike>
|
|
|
- </ogc:Or>
|
|
|
- </ogc:Filter>
|
|
|
+ </ogc:PropertyIsLike>
|
|
|
+ <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
|
|
|
+ <ogc:PropertyName>nazwisko</ogc:PropertyName>
|
|
|
+ <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
|
|
|
+ </ogc:PropertyIsLike>
|
|
|
+ </ogc:Or>
|
|
|
+ </ogc:Filter>
|
|
|
';
|
|
|
}
|
|
|
|
|
@@ -2534,16 +2534,102 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- $filtersParams = [];
|
|
|
$fieldFilterKeys = array_filter(array_keys($args), function ($key) {
|
|
|
+ if ('f_Adresy' === $key) return false;
|
|
|
return ('f_' === substr($key, 0, 2));
|
|
|
});
|
|
|
+
|
|
|
+ $filtersParams = [];
|
|
|
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');
|
|
|
+ // @doc 2020-06-18
|
|
|
+ // $acl - AntAclBase
|
|
|
+ // $query = $acl->buildQuery => new AclQueryFeatures($acl, $params);
|
|
|
+ // $query->getTotal() => $query->getQuery()->fetchTotal()
|
|
|
+ // - getQuery params: 'f_@externalFunction' - first used in se-biall:SE/se-lib/Route/UrlAction/BiallUslugiWzorcowaniaPowiaz.php
|
|
|
+ $externaFunctionParam = []; // f_@externalFunction
|
|
|
+ if (!empty($args['f_Adresy'])) {
|
|
|
+ $adresQuery = $args['f_Adresy'];
|
|
|
+ $adresyRefConf = ACL::getRefConfig(
|
|
|
+ $rootObjectNamespace = 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY',
|
|
|
+ $childName = 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy'
|
|
|
+ );
|
|
|
+ // id: 27,
|
|
|
+ // source: "table",
|
|
|
+ // status: "NORMAL",
|
|
|
+ // version: "6",
|
|
|
+ // tableName: "CRM__#REF_TABLE__27"
|
|
|
+ $refTableName = $adresyRefConf->tableName;
|
|
|
+ $adresyTableName = 'BI_audit_ENERGA_PRACOWNICY_adresy';
|
|
|
+
|
|
|
+ $externaFunctionParam['f_@externalFunction'] = function ($query) use ($adresQuery, $refTableName, $adresyTableName) {
|
|
|
+ // table struct `BI_audit_ENERGA_PRACOWNICY_adresy` @2020-06-18:
|
|
|
+ // `ID` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
+ // `typAdresu` varchar(255) DEFAULT NULL,
|
|
|
+ // `kodPocztowy` varchar(255) DEFAULT NULL, 80-809
|
|
|
+ // `miejscowosc` varchar(255) DEFAULT NULL,
|
|
|
+ // `ulica` varchar(255) DEFAULT NULL,
|
|
|
+ // `nrBudynku` varchar(255) DEFAULT NULL,
|
|
|
+ // `nrLokalu` varchar(255) DEFAULT NULL,
|
|
|
+ // `TERYT_SYM` int(11) DEFAULT NULL,
|
|
|
+ // `TERYT_SYM_UL` int(11) DEFAULT NULL,
|
|
|
+ // `cached` tinyint(1) NOT NULL DEFAULT '0',
|
|
|
+ $sqlAndWhere = [];
|
|
|
+ Lib::loadClass('SqlQueryWhereBuilder');
|
|
|
+ $queryWhereBuilder = new SqlQueryWhereBuilder();
|
|
|
+ $searchWords = $queryWhereBuilder->splitQueryToWords($adresQuery);
|
|
|
+ DBG::log($searchWords, 'array', 'TODO: f_Adresy $searchWords');
|
|
|
+
|
|
|
+ if (empty($searchWords)) return;
|
|
|
+
|
|
|
+ foreach ($searchWords as $word) {
|
|
|
+ $sqlWord = DB::getPDO()->quote("%{$word}%");
|
|
|
+ $sqlWordOr = [];
|
|
|
+ if (is_numeric(str_replace('-', '', $word))) { // TODO: better validation for 'kod pocztowy'
|
|
|
+ $sqlWordOr[] = "t_adresy.`kodPocztowy` = " . DB::getPDO()->quote($word);
|
|
|
+ }
|
|
|
+ if (is_numeric($word)) { // TODO: more formats like '34C' | '10-14'
|
|
|
+ $sqlWordOr[] = "t_adresy.`nrBudynku` = " . (int)$word;
|
|
|
+ $sqlWordOr[] = "t_adresy.`nrLokalu` = " . (int)$word;
|
|
|
+ } else {
|
|
|
+ $sqlWordOr[] = "t_adresy.`miejscowosc` like {$sqlWord}";
|
|
|
+ $sqlWordOr[] = "t_adresy.`ulica` like {$sqlWord}";
|
|
|
+ }
|
|
|
+
|
|
|
+ $sqlAndWhere[] = "(" . implode(" or ", $sqlWordOr) . ")";
|
|
|
+ }
|
|
|
+ $sqlWhere = implode(" and ", $sqlAndWhere);
|
|
|
+
|
|
|
+ // BUG: cant use t alias in where subquery
|
|
|
+ // $query->where("
|
|
|
+ // (
|
|
|
+ // select count(*)
|
|
|
+ // from `{$adresyTableName}` t_adresy
|
|
|
+ // join `{$refTableName}` ref_adresy on (
|
|
|
+ // ref_adresy.PRIMARY_KEY = t.ID
|
|
|
+ // and ref_adresy.REMOTE_PRIMARY_KEY = t_adresy.ID
|
|
|
+ // and 'NORMAL' = ref_adresy.A_STATUS
|
|
|
+ // )
|
|
|
+ // where {$sqlWhere}
|
|
|
+ // ) > 0
|
|
|
+ // ");
|
|
|
+
|
|
|
+ $query->where("
|
|
|
+ exists (
|
|
|
+ select t_adresy.ID
|
|
|
+ from `{$refTableName}` ref_adresy
|
|
|
+ join `{$adresyTableName}` t_adresy on ( t_adresy.ID = ref_adresy.REMOTE_PRIMARY_KEY )
|
|
|
+ where ref_adresy.PRIMARY_KEY = t.ID
|
|
|
+ and {$sqlWhere}
|
|
|
+ )
|
|
|
+ ");
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
$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/*'
|
|
@@ -2557,7 +2643,7 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
|
|
|
// '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));
|
|
|
+ ], $searchParams, $filtersParams, $backRefFilter, $externaFunctionParam));
|
|
|
$total = $query->getTotal();
|
|
|
$items = $query->getItems();
|
|
|
|