|
|
@@ -951,6 +951,7 @@ function validateCompany(source) {
|
|
|
case "BI_audit_ENERGA_RUM_KONTRAHENCI":
|
|
|
$backRefs[] = 'BI_audit_ENERGA_RUM_UMOWY';
|
|
|
$backRefs[] = 'BI_audit_ENERGA_FAKTURY';
|
|
|
+ $queries[] = "update `BI_audit_ENERGA_RUM_UMOWY` set `A_STATUS` = 'WAITING'";
|
|
|
break;
|
|
|
case "BI_audit_ENERGA_RUM_UMOWY":
|
|
|
$refs[] = 'BI_audit_ENERGA_RUM_KONTRAHENCI';
|
|
|
@@ -976,9 +977,10 @@ function validateCompany(source) {
|
|
|
default: throw new Exception('Błąd parametru');
|
|
|
}
|
|
|
|
|
|
- $queries[] = "delete from `{$this->SOURCE['TABLE']}`";
|
|
|
- foreach ($refs as $ref) $queries[] = 'truncate table `' . BiAuditRefTables::getRefTable($this->SOURCE['TABLE'], $ref, true) . '`';
|
|
|
- foreach ($backRefs as $backRef) $queries[] = 'truncate table `' . BiAuditRefTables::getRefTable($backRef, $this->SOURCE['TABLE'], true) . '`';
|
|
|
+ $tables[] = $this->SOURCE['TABLE'];
|
|
|
+ foreach ($refs as $ref) $tables[] = BiAuditRefTables::getRefTable($this->SOURCE['TABLE'], $ref, true);
|
|
|
+ foreach ($backRefs as $backRef) $tables[] = BiAuditRefTables::getRefTable($backRef, $this->SOURCE['TABLE'], true);
|
|
|
+ foreach ($tables as $table) $queries[] = "delete from `{$table}`";
|
|
|
foreach ($queries as $query) DB::getPDO()->query($query);
|
|
|
?>
|
|
|
<div style="text-align: center;">
|
|
|
@@ -1483,53 +1485,86 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static function importPracownicy() { //TODO
|
|
|
+ private static function importPracownicy($full = false) {
|
|
|
$fields = [
|
|
|
'BI_audit_ENERGA_PRACOWNICY' => [
|
|
|
- 'PERNR',
|
|
|
- 'imiona',
|
|
|
- 'nazwisko',
|
|
|
- 'pesel',
|
|
|
- 'nr_konta',
|
|
|
- 'jednostka_organizacyjna',
|
|
|
- 'nip',
|
|
|
- 'regon',
|
|
|
- 'krs',
|
|
|
- 'source',
|
|
|
+ 'imiona' => 'imiona',
|
|
|
+ 'nazwisko' => 'nazwisko',
|
|
|
+ 'pesel' => 'pesel',
|
|
|
+ 'jednostka_organizacyjna' => 'jednostka_organizacyjna',
|
|
|
+ 'GUID' => 'GUID',
|
|
|
],
|
|
|
'BI_audit_ENERGA_PRACOWNICY_adresy' => [
|
|
|
- 'kodPocztowy',
|
|
|
- 'miejscowosc',
|
|
|
- 'ulica',
|
|
|
- 'nrBudynku',
|
|
|
- 'nrLokalu',
|
|
|
+ 'kodPocztowy' => 'kodPocztowy',
|
|
|
+ 'miejscowosc' => 'miejscowosc',
|
|
|
+ 'ulica' => 'ulica',
|
|
|
+ 'nrBudynku' => 'nr',
|
|
|
+ 'nrLokalu' => 'nrLokalu',
|
|
|
],
|
|
|
];
|
|
|
|
|
|
- $query = "select * from `BI_audit_ENERGA_PRACOWNICY_import` where `importResult` = 'none'";
|
|
|
- //$pracownicy = DB::getPDO()->queryNotBuffered($query);
|
|
|
+ $refTable = BiAuditRefTables::getRefTable('BI_audit_ENERGA_PRACOWNICY', 'BI_audit_ENERGA_PRACOWNICY_adresy', true);
|
|
|
+
|
|
|
+ if ($full) DB::getPDO()->query("update `BI_audit_ENERGA_PRACOWNICY_import` set `A_STATUS` = 'WAITING'");
|
|
|
+ DB::getPDO()->query("update `BI_audit_ENERGA_PRACOWNICY_import` set `pesel` = null where `A_STATUS` = 'WAITING' and isPesel(`pesel`) = 0");
|
|
|
+
|
|
|
+ $query = "select * from `BI_audit_ENERGA_PRACOWNICY_import` where `A_STATUS` = 'WAITING'";
|
|
|
$pracownicy = DB::getPDO()->query($query);
|
|
|
while ($pracownik = $pracownicy->fetch()) {
|
|
|
- $ID_pracownik = DB::getPDO()->fetchValue("select `ID` from `BI_audit_ENERGA_PRACOWNICY` where `pesel` = '{$pracownik['pesel']}'");
|
|
|
+ if ($pracownik['pesel']) {
|
|
|
+ $ID_pracownik = DB::getPDO()->fetchValue("select `ID` from `BI_audit_ENERGA_PRACOWNICY` where `pesel` = '{$pracownik['pesel']}' or (coalesce(`pesel`, '') = '' and `GUID` = '{$pracownik['GUID']}')");
|
|
|
+ } elseif ($pracownik['GUID']) {
|
|
|
+ $ID_pracownik = DB::getPDO()->fetchValue("select `ID` from `BI_audit_ENERGA_PRACOWNICY` where `GUID` = '{$pracownik['GUID']}'");
|
|
|
+ } else {
|
|
|
+ DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY_import', 'ID', $pracownik['ID'], ['A_STATUS' => 'OFF_SOFT']);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
$sqlArr = [];
|
|
|
- foreach ($fields['BI_audit_ENERGA_PRACOWNICY'] as $field) $sqlArr[$field] = trim($pracownik[$field]);
|
|
|
- if ($ID_pracownik) DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY', 'ID', $ID, $sqlArr);
|
|
|
+ $sqlArr['source'] = 'import';
|
|
|
+ $sqlArr['cached'] = '0';
|
|
|
+ foreach ($fields['BI_audit_ENERGA_PRACOWNICY'] as $tableField => $importField) {
|
|
|
+ $sqlArr[$tableField] = trim($pracownik[$importField]);
|
|
|
+ if (!$sqlArr[$tableField]) unset($sqlArr[$tableField]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($ID_pracownik) {
|
|
|
+ DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY', 'ID', $ID_pracownik, $sqlArr);
|
|
|
+ $full = true;
|
|
|
+ }
|
|
|
+
|
|
|
else $ID_pracownik = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY', $sqlArr);
|
|
|
|
|
|
$sqlArr = [];
|
|
|
- foreach ($fields['BI_audit_ENERGA_PRACOWNICY_adresy'] as $field) {
|
|
|
- $sqlArr[$field] = trim($pracownik[$field]);
|
|
|
- if (!$sqlArr[$field]) unset($sqlArr[$field]);
|
|
|
+ foreach ($fields['BI_audit_ENERGA_PRACOWNICY_adresy'] as $tableField => $importField) {
|
|
|
+ $sqlArr[$tableField] = trim($pracownik[$importField]);
|
|
|
+ if (!$sqlArr[$tableField]) unset($sqlArr[$tableField]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$sqlArr) {
|
|
|
+ DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY_import', 'ID', $pracownik['ID'], ['A_STATUS' => 'OFF_SOFT']);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $sqlWhereArr = [];
|
|
|
+ $sqlWhereArr[] = "`{$refTable}`.`PRIMARY_KEY` = '{$ID_pracownik}'";
|
|
|
+ foreach ($fields['BI_audit_ENERGA_PRACOWNICY_adresy'] as $tableField => $importField) {
|
|
|
+ if (isset($sqlArr[$tableField])) $sqlWhereArr[] = "`BI_audit_ENERGA_PRACOWNICY_adresy`.`{$tableField}` = " . DB::getPDO()->quote($sqlArr[$tableField]);
|
|
|
+ else $sqlWhereArr[] = "`{$tableField}` is null";
|
|
|
+ }
|
|
|
+ $query = "select count(*) from `{$refTable}` join `BI_audit_ENERGA_PRACOWNICY_adresy` on `{$refTable}`.`REMOTE_PRIMARY_KEY` = `BI_audit_ENERGA_PRACOWNICY_adresy`.`ID` where " . implode(' and ', $sqlWhereArr);
|
|
|
+ if (!(DB::getPDO()->fetchValue($query))) {
|
|
|
+ $ID_adres = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_adresy', $sqlArr);
|
|
|
+ DB::getPDO()->insert($refTable, ['PRIMARY_KEY' => $ID_pracownik, 'REMOTE_PRIMARY_KEY' => $ID_adres]);
|
|
|
}
|
|
|
- if (!$sqlArr) break;
|
|
|
- $sql = [];
|
|
|
-// foreach ($fields['BI_audit_ENERGA_PRACOWNICY_adresy'] as $field) {
|
|
|
-// if (isset($sqlArr[$field])) $sql[] = "`{$field}` = " . DUPA;
|
|
|
-// }
|
|
|
+
|
|
|
+ DB::getPDO()->update('BI_audit_ENERGA_PRACOWNICY_import', 'ID', $pracownik['ID'], ['A_STATUS' => 'NORMAL']);
|
|
|
}
|
|
|
+
|
|
|
+ return $full;
|
|
|
}
|
|
|
|
|
|
- private static function reloadCache_parseUmowy($full = false) {
|
|
|
+ private static function reloadCache_parseFakturyUmowy($full = false) {
|
|
|
$fields = [
|
|
|
'BI_audit_ENERGA_RUM_KONTRAHENCI' => [
|
|
|
'Tytul_dokumentu',
|
|
|
@@ -1578,12 +1613,59 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
],
|
|
|
];
|
|
|
|
|
|
- $refTable = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_UMOWY', 'BI_audit_ENERGA_RUM_KONTRAHENCI', true);
|
|
|
+ $refTableFakturyToKontrahenci = BiAuditRefTables::getRefTable('BI_audit_ENERGA_FAKTURY', 'BI_audit_ENERGA_RUM_KONTRAHENCI', true);
|
|
|
+ $refTableUmowyToKontrahenci = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_UMOWY', 'BI_audit_ENERGA_RUM_KONTRAHENCI', true);
|
|
|
if ($full) {
|
|
|
- DB::getPDO()->query("truncate table `{$refTable}`");
|
|
|
+ DB::getPDO()->query("truncate table `{$refTableFakturyToKontrahenci}`");
|
|
|
+ DB::getPDO()->query("truncate table `{$refTableUmowyToKontrahenci}`");
|
|
|
+ DB::getPDO()->query("update `BI_audit_ENERGA_FAKTURY` set `A_STATUS` = 'WAITING' where `A_STATUS` = 'NORMAL'");
|
|
|
DB::getPDO()->query("update `BI_audit_ENERGA_RUM_UMOWY` set `A_STATUS` = 'WAITING' where `A_STATUS` = 'NORMAL'");
|
|
|
}
|
|
|
|
|
|
+ $query = "select `ID`, `NIP` from `BI_audit_ENERGA_FAKTURY` where `A_STATUS` = 'WAITING'";
|
|
|
+ $result = DB::getPDO()->fetchAll($query);
|
|
|
+ foreach ($result as $row) {
|
|
|
+ $ID = $row['ID'];
|
|
|
+ $nip = trim($row['NIP']);
|
|
|
+ if (!$full) {
|
|
|
+ $query = "delete from `{$refTableFakturyToKontrahenci}` where PRIMARY_KEY = '{$row['ID']}'";
|
|
|
+ DB::getPDO()->query($query);
|
|
|
+ }
|
|
|
+ if (!$nip) continue;
|
|
|
+
|
|
|
+ $K_IDs = [];
|
|
|
+ $query = "select `ID` from `BI_audit_ENERGA_RUM_KONTRAHENCI` where `NIP` = '{$nip}'";
|
|
|
+ if ($result2 = DB::getPDO()->fetchall($query)) {
|
|
|
+ foreach ($result2 as $item) $K_IDs[] = $item['ID'];
|
|
|
+ } else {
|
|
|
+ $query = "select ID from BI_audit_KRS where nip = '{$nip}'";
|
|
|
+ if ($result2 = DB::getPDO()->fetchall($query)) {
|
|
|
+ foreach ($result2 as $item) {
|
|
|
+ $query = "insert into `BI_audit_ENERGA_RUM_KONTRAHENCI` (" . implode(', ', $fields['BI_audit_ENERGA_RUM_KONTRAHENCI']) . ")" .
|
|
|
+ " select " . implode(', ', $fields['BI_audit_KRS']) . " from `BI_audit_KRS` where `ID` = '{$item['ID']}'";
|
|
|
+ if (DB::getPDO()->query($query)) $K_IDs[] = DB::getPDO()->lastInsertId();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $query = "select `ID` from `BI_audit_CEIDG` where `nip` = '{$nip}'";
|
|
|
+ if ($result2 = DB::getPDO()->fetchall($query)) {
|
|
|
+ foreach ($result2 as $item) {
|
|
|
+ $query = "insert into `BI_audit_ENERGA_RUM_KONTRAHENCI` (" . implode(', ', $fields['BI_audit_ENERGA_RUM_KONTRAHENCI']) . ")" .
|
|
|
+ " select " . implode(', ', $fields['BI_audit_CEIDG']) . " from `BI_audit_CEIDG` where `ID` = '{$item['ID']}'";
|
|
|
+ if (DB::getPDO()->query($query)) $K_IDs[] = DB::getPDO()->lastInsertId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($K_IDs as $K_ID) {
|
|
|
+ if (!(DB::getPDO()->fetchValue("select count(*) from `{$refTableFakturyToKontrahenci}` where `PRIMARY_KEY` = {$ID} and `REMOTE_PRIMARY_KEY` = {$K_ID}"))) {
|
|
|
+ DB::getPDO()->query("insert into `{$refTableFakturyToKontrahenci}` (`PRIMARY_KEY`, `REMOTE_PRIMARY_KEY`) values ({$ID}, {$K_ID})");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DB::getPDO()->update('BI_audit_ENERGA_FAKTURY', "ID", $ID, ['A_STATUS' => 'NORMAL']);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
$query = <<<SQL
|
|
|
update `BI_audit_ENERGA_RUM_UMOWY` set `Wartosc` = replace(
|
|
|
if(`Wartosc_przedmiotu_umowy_netto_w_PLN__aktualna_` not in ('0', '0,1', ''), `Wartosc_przedmiotu_umowy_netto_w_PLN__aktualna_`,
|
|
|
@@ -1600,7 +1682,7 @@ SQL;
|
|
|
foreach ($result as $row) {
|
|
|
$ID = $row['ID'];
|
|
|
if (!$full) {
|
|
|
- $query = "delete from `{$refTable}` where PRIMARY_KEY = '{$ID}'";
|
|
|
+ $query = "delete from `{$refTableUmowyToKontrahenci}` where PRIMARY_KEY = '{$ID}'";
|
|
|
DB::getPDO()->query($query);
|
|
|
}
|
|
|
$strony = array_map('trim', explode("|", $row['Strony_umowy']));
|
|
|
@@ -1616,12 +1698,12 @@ SQL;
|
|
|
if ($i) $nr = $strona[$i];
|
|
|
$notFound = false;
|
|
|
if (is_numeric($nr)) {
|
|
|
- $query = "select ID from BI_audit_ENERGA_RUM_KONTRAHENCI where Numer_kontrahenta = '{$nr}'";
|
|
|
+ $query = "select ID from BI_audit_ENERGA_RUM_KONTRAHENCI where Numer_kontrahenta = '{$nr}' and not (NIP is null and REGON is null and KRS is null)";
|
|
|
if ($K_ID = DB::getPDO()->fetchValue($query)) {
|
|
|
$K_IDs[] = $K_ID;
|
|
|
} else {
|
|
|
$nazwa = $strona[$i+1];
|
|
|
- $query = "select ID from BI_audit_ENERGA_RUM_KONTRAHENCI where Pelna_nazwa_kontrahenta = '" . addslashes($nazwa) . "'";
|
|
|
+ $query = "select ID from BI_audit_ENERGA_RUM_KONTRAHENCI where Pelna_nazwa_kontrahenta = '" . addslashes($nazwa) . "' and not (NIP is null and REGON is null and KRS is null)";
|
|
|
if ($result2 = DB::getPDO()->fetchAll($query)) {
|
|
|
foreach ($result2 as $item) $K_IDs[] = $item['ID'];
|
|
|
} else $notFound = true;
|
|
|
@@ -1658,8 +1740,8 @@ SQL;
|
|
|
}
|
|
|
|
|
|
foreach ($K_IDs as $K_ID) {
|
|
|
- if (!(DB::getPDO()->fetchValue("select count(*) from `{$refTable}` where `PRIMARY_KEY` = {$ID} and `REMOTE_PRIMARY_KEY` = {$K_ID}"))) {
|
|
|
- DB::getPDO()->query("insert into `{$refTable}` (PRIMARY_KEY, REMOTE_PRIMARY_KEY) values ({$ID}, {$K_ID})");
|
|
|
+ if (!(DB::getPDO()->fetchValue("select count(*) from `{$refTableUmowyToKontrahenci}` where `PRIMARY_KEY` = {$ID} and `REMOTE_PRIMARY_KEY` = {$K_ID}"))) {
|
|
|
+ DB::getPDO()->query("insert into `{$refTableUmowyToKontrahenci}` (PRIMARY_KEY, REMOTE_PRIMARY_KEY) values ({$ID}, {$K_ID})");
|
|
|
}
|
|
|
}
|
|
|
DB::getPDO()->update('BI_audit_ENERGA_RUM_UMOWY', "ID", $ID, ['A_STATUS' => 'NORMAL']);
|
|
|
@@ -2028,7 +2110,7 @@ SQL;
|
|
|
'BI_audit_ENERGA_PRACOWNICY' => [
|
|
|
'refTablesTo' => [
|
|
|
'BI_audit_ENERGA_PRACOWNICY_adresy',
|
|
|
- 'TERYT_adresy',
|
|
|
+ //'TERYT_adresy',
|
|
|
],
|
|
|
'base' => 0,
|
|
|
],
|
|
|
@@ -2166,18 +2248,22 @@ SQL;
|
|
|
$onlyBase = false;
|
|
|
}
|
|
|
|
|
|
+ $setFull = function() {
|
|
|
+ BiAuditPowiazania::saveToLog("Wykryto niespójność tabel - uruchamiam pełne odświeżenie cache");
|
|
|
+ $sqlArr = [
|
|
|
+ 'BI_analiza_reloadCache' => 'Full',
|
|
|
+ 'FILE_STATUS_info' => 'Odświeżam w pełni cache',
|
|
|
+ ];
|
|
|
+ DB::getPDO()->update('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', "ID", $this->POWIAZANIA_ID, $sqlArr);
|
|
|
+ };
|
|
|
+
|
|
|
if ($this->POWIAZANIA_ID && (!$full)) {
|
|
|
- $checkTables = ['BI_audit_ENERGA_PRACOWNICY', 'BI_audit_ENERGA_RUM_KONTRAHENCI'];
|
|
|
+ $checkTables = ['BI_audit_ENERGA_PRACOWNICY', 'BI_audit_ENERGA_PRACOWNICY_adresy', 'BI_audit_ENERGA_RUM_KONTRAHENCI'];
|
|
|
foreach ($checkTables as $table) {
|
|
|
- $query = "select count(*) from `BI_audit_ALL` `all` left join `{$table}` `t` on `all`.`REMOTE_ID`=`t`.`ID` where `all`.`REMOTE_TABLE`='{$table}' and `t`.`ID` is null";
|
|
|
+ $query = "select count(*) from `BI_audit_ALL` `all` left join `{$table}` `t` on `all`.`REMOTE_ID`=`t`.`ID` and `t`.`cached` = '1' where `all`.`REMOTE_TABLE`='{$table}' and `t`.`ID` is null";
|
|
|
if (DB::getPDO()->fetchValue($query)) {
|
|
|
$full = true;
|
|
|
- BiAuditPowiazania::saveToLog("Wykryto niespójność tabel - uruchamiam pełne odświeżenie cache");
|
|
|
- $sqlArr = [
|
|
|
- 'BI_analiza_reloadCache' => 'Full',
|
|
|
- 'FILE_STATUS_info' => 'Odświeżam w pełni cache',
|
|
|
- ];
|
|
|
- DB::getPDO()->update('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', "ID", $this->POWIAZANIA_ID, $sqlArr);
|
|
|
+ $setFull();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -2187,11 +2273,16 @@ SQL;
|
|
|
$tasksDirLocation = $powiazaniaDirLocation . "/.tasks";
|
|
|
$reloadCachePidFile = $tasksDirLocation . "/reloadCache.pid";
|
|
|
$reloadCacheResultFile = $tasksDirLocation . "/reloadCache.result";
|
|
|
- if ($full) file_put_contents($reloadCachePidFile, getmypid());
|
|
|
+ if (!$this->POWIAZANIA_ID) file_put_contents($reloadCachePidFile, getmypid());
|
|
|
try {
|
|
|
- //self::importPracownicy(); //TODO
|
|
|
- error_log('now: self::reloadCache_parseUmowy');
|
|
|
- self::reloadCache_parseUmowy($full);
|
|
|
+ error_log('now: self::importPracownicy');
|
|
|
+ $_full = self::importPracownicy($full);
|
|
|
+ if ((!$full) && $_full) {
|
|
|
+ $full = true;
|
|
|
+ if ($this->POWIAZANIA_ID) $setFull();
|
|
|
+ }
|
|
|
+ error_log('now: self::reloadCache_parseFakturyUmowy');
|
|
|
+ self::reloadCache_parseFakturyUmowy($full);
|
|
|
error_log('now: self::reloadCache_reTeryt');
|
|
|
self::reloadCache_reTeryt($full);
|
|
|
error_log('now: self::reloadCache_updateAll');
|
|
|
@@ -2213,7 +2304,7 @@ SQL;
|
|
|
$pidFile = "{$tasksDirLocation}/generatePowiazania-{$ID}.pid";
|
|
|
file_put_contents($pidFile, getmypid());
|
|
|
|
|
|
- $tablesConf = [
|
|
|
+/* $tablesConf = [
|
|
|
'BI_audit_CEIDG' => ['ID', 'imie', 'nazwisko', 'nip', 'regon', 'firma', 'miejscowosc'],
|
|
|
'BI_audit_CEIDG_pelnomocnicy' => ['ID', 'nazwa', 'nip', 'miejscowosc'],
|
|
|
'BI_audit_CEIDG_powiazania' => ['ID', 'nip', 'regon'],
|
|
|
@@ -2224,7 +2315,7 @@ SQL;
|
|
|
'BI_audit_KRS_company' => ['ID', 'nazwa', 'regon', 'krs'],
|
|
|
'BI_audit_KRS_person' => ['ID', 'nazwisko', 'imiona', 'pesel'],
|
|
|
'BI_audit_KW_requested_person' => ['ID', 'Seller_person', 'Seller_person_pesel', 'Seller_person_KRS', 'Seller_person_NIP', 'Seller_person_REGON'],
|
|
|
- ];
|
|
|
+ ];*/
|
|
|
|
|
|
try {
|
|
|
$BiAuditPowiazania = new BiAuditPowiazania($ID, $tasksDirLocation);
|
|
|
@@ -2896,6 +2987,7 @@ class BiAuditPowiazania {
|
|
|
$_items_results = [];
|
|
|
|
|
|
$refUmowyToKontrahenci = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_UMOWY', 'BI_audit_ENERGA_RUM_KONTRAHENCI', true);
|
|
|
+ $refFakturyToKontrahenci = BiAuditRefTables::getRefTable('BI_audit_ENERGA_FAKTURY', 'BI_audit_ENERGA_RUM_KONTRAHENCI', true);
|
|
|
$refKwRequestedToKwRequestedPerson = BiAuditRefTables::getRefTable('BI_audit_KW_requested', 'BI_audit_KW_requested_person', true);
|
|
|
|
|
|
$this->items_results[$resultsPart] = [];
|
|
|
@@ -2939,18 +3031,34 @@ class BiAuditPowiazania {
|
|
|
|
|
|
if ($row['REMOTE_TABLE'] == "BI_audit_ENERGA_RUM_KONTRAHENCI" && (!in_array($row['REMOTE_ID'], $kontrahenci))) {
|
|
|
$kontrahenci[] = $row['REMOTE_ID'];
|
|
|
+
|
|
|
+ $query = "select faktury.* from BI_audit_ENERGA_FAKTURY faktury join `{$refFakturyToKontrahenci}` ref on faktury.ID = ref.PRIMARY_KEY where ref.REMOTE_PRIMARY_KEY = '{$row['REMOTE_ID']}'";
|
|
|
+ $res = DB::query($query);
|
|
|
+ $faktury = [];
|
|
|
+ if (mysql_num_rows($res)) {
|
|
|
+ while ($obj = DB::fetch($res)) {
|
|
|
+ $faktura = (array) $obj;
|
|
|
+ $faktura = array_merge(['@attributes' => ['fid' => "BI_audit_ENERGA_FAKTURY.{$faktura['ID']}"]], $faktura);
|
|
|
+ $faktury[] = $faktura;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$query = "select umowy.* from BI_audit_ENERGA_RUM_UMOWY umowy join `{$refUmowyToKontrahenci}` ref on umowy.ID = ref.PRIMARY_KEY where ref.REMOTE_PRIMARY_KEY = '{$row['REMOTE_ID']}'";
|
|
|
$res = DB::query($query);
|
|
|
+ $umowy = [];
|
|
|
if (mysql_num_rows($res)) {
|
|
|
- $umowy = [];
|
|
|
while ($obj = DB::fetch($res)) {
|
|
|
$umowa = (array) $obj;
|
|
|
$umowa = array_merge(['@attributes' => ['fid' => "BI_audit_ENERGA_RUM_UMOWY.{$umowa['ID']}"]], $umowa);
|
|
|
$umowy[] = $umowa;
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($faktury || $umowy) {
|
|
|
$item_kontrahenci['@attributes'] = ['fid' => "{$row['REMOTE_TABLE']}.{$row['REMOTE_ID']}"];
|
|
|
$item_kontrahenci['ID'] = $row['REMOTE_ID'];
|
|
|
- $item_kontrahenci['BI_audit_ENERGA_RUM_UMOWY'] = $umowy;
|
|
|
+ if ($faktury) $item_kontrahenci['BI_audit_ENERGA_FAKTURY'] = $faktury;
|
|
|
+ if ($umowy) $item_kontrahenci['BI_audit_ENERGA_RUM_UMOWY'] = $umowy;
|
|
|
$items_kontrahenci[] = $item_kontrahenci;
|
|
|
}
|
|
|
} elseif ($row['REMOTE_TABLE'] == "BI_audit_KW_requested_person" && (!in_array($row['REMOTE_ID'], $kw_person))) {
|