|
@@ -1677,7 +1677,7 @@ if(`Wartosc_przedmiotu_umowy_netto_w_walucie__pierwotna_` not in ('0', '0,1', ''
|
|
|
SQL;
|
|
SQL;
|
|
|
DB::getPDO()->query($query);
|
|
DB::getPDO()->query($query);
|
|
|
|
|
|
|
|
- $query = "select `ID`, `Strony_umowy` from `BI_audit_ENERGA_RUM_UMOWY` where `A_STATUS` = 'WAITING'";
|
|
|
|
|
|
|
+ $query = "select `ID`, `Kontrahenci` from `BI_audit_ENERGA_RUM_UMOWY` where `A_STATUS` = 'WAITING'";
|
|
|
$result = DB::getPDO()->fetchAll($query);
|
|
$result = DB::getPDO()->fetchAll($query);
|
|
|
foreach ($result as $row) {
|
|
foreach ($result as $row) {
|
|
|
$ID = $row['ID'];
|
|
$ID = $row['ID'];
|
|
@@ -1685,24 +1685,24 @@ SQL;
|
|
|
$query = "delete from `{$refTableUmowyToKontrahenci}` where PRIMARY_KEY = '{$ID}'";
|
|
$query = "delete from `{$refTableUmowyToKontrahenci}` where PRIMARY_KEY = '{$ID}'";
|
|
|
DB::getPDO()->query($query);
|
|
DB::getPDO()->query($query);
|
|
|
}
|
|
}
|
|
|
- $strony = array_map('trim', explode("|", $row['Strony_umowy']));
|
|
|
|
|
|
|
+ $kontrahenci = array_map('trim', explode("|", $row['Kontrahenci']));
|
|
|
$K_IDs = [];
|
|
$K_IDs = [];
|
|
|
|
|
|
|
|
- foreach ($strony as $item) {
|
|
|
|
|
- $strona = array_map('trim', explode(";", $item));
|
|
|
|
|
|
|
+ foreach ($kontrahenci as $item) {
|
|
|
|
|
+ $kontrahent = array_map('trim', explode(";", $item));
|
|
|
$nr = null;
|
|
$nr = null;
|
|
|
- if (count($strona) == 3) $i = 1;//$nr = $strona[1];
|
|
|
|
|
- elseif (count($strona) == 4) $i = 2;//$nr = $strona[2];
|
|
|
|
|
- elseif (count($strona) >= 5 && count($strona) <= 6) $i = 3;//$nr = $strona[3];
|
|
|
|
|
|
|
+ if (count($kontrahent) == 3) $i = 1;//$nr = $kontrahent[1];
|
|
|
|
|
+ elseif (count($kontrahent) == 4) $i = 2;//$nr = $kontrahent[2];
|
|
|
|
|
+ elseif (count($kontrahent) >= 5 && count($kontrahent) <= 6) $i = 3;//$nr = $kontrahent[3];
|
|
|
else $i = null;
|
|
else $i = null;
|
|
|
- if ($i) $nr = $strona[$i];
|
|
|
|
|
|
|
+ if ($i) $nr = $kontrahent[$i];
|
|
|
$notFound = false;
|
|
$notFound = false;
|
|
|
if (is_numeric($nr)) {
|
|
if (is_numeric($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)";
|
|
$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)) {
|
|
if ($K_ID = DB::getPDO()->fetchValue($query)) {
|
|
|
$K_IDs[] = $K_ID;
|
|
$K_IDs[] = $K_ID;
|
|
|
} else {
|
|
} else {
|
|
|
- $nazwa = $strona[$i+1];
|
|
|
|
|
|
|
+ $nazwa = $kontrahent[$i+1];
|
|
|
$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)";
|
|
$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)) {
|
|
if ($result2 = DB::getPDO()->fetchAll($query)) {
|
|
|
foreach ($result2 as $item) $K_IDs[] = $item['ID'];
|
|
foreach ($result2 as $item) $K_IDs[] = $item['ID'];
|
|
@@ -2193,14 +2193,19 @@ SQL;
|
|
|
|
|
|
|
|
foreach ($tablesConf as $table => $tableConf) {
|
|
foreach ($tablesConf as $table => $tableConf) {
|
|
|
if ($onlyBase && (!$tableConf['base'])) continue;
|
|
if ($onlyBase && (!$tableConf['base'])) continue;
|
|
|
- $where = "where `cached` = 0";
|
|
|
|
|
|
|
+ $where = "where `{$table}`.`cached` = 0";
|
|
|
if (!empty($tableConf['where'])) $where .= " {$tableConf['where']}";
|
|
if (!empty($tableConf['where'])) $where .= " {$tableConf['where']}";
|
|
|
// $queries[] = "insert into `BI_audit_ALL` (`REMOTE_TABLE`, `REMOTE_ID`, `BASE`, " . implode(", ", array_keys($tableConf['fields'])) .
|
|
// $queries[] = "insert into `BI_audit_ALL` (`REMOTE_TABLE`, `REMOTE_ID`, `BASE`, " . implode(", ", array_keys($tableConf['fields'])) .
|
|
|
// ") select '{$table}', ID, '{$tableConf['base']}', " . implode(", ", $tableConf['fields']) . " from `{$table}` {$where}";
|
|
// ") select '{$table}', ID, '{$tableConf['base']}', " . implode(", ", $tableConf['fields']) . " from `{$table}` {$where}";
|
|
|
$fields = ["`REMOTE_TABLE`", "`REMOTE_ID`", "`BASE`"];
|
|
$fields = ["`REMOTE_TABLE`", "`REMOTE_ID`", "`BASE`"];
|
|
|
- foreach (array_keys($tableConf['fields']) as $field) $fields[] = "`{$field}`";
|
|
|
|
|
$values = ["'{$table}'", "`ID`", "'{$tableConf['base']}'"];
|
|
$values = ["'{$table}'", "`ID`", "'{$tableConf['base']}'"];
|
|
|
- foreach ($tableConf['fields'] as $value) $values[] = "`{$value}`";
|
|
|
|
|
|
|
+ $updates = ["`BI_audit_ALL`.`reffed` = 0", "`{$table}`.`cached` = 1"];
|
|
|
|
|
+ foreach ($tableConf['fields'] as $field => $value) {
|
|
|
|
|
+ $fields[] = "`{$field}`";
|
|
|
|
|
+ $values[] = "`{$value}`";
|
|
|
|
|
+ $updates[] = "`BI_audit_ALL`.`{$field}` = `{$table}`.`{$value}`";
|
|
|
|
|
+ }
|
|
|
|
|
+ $queries[] = "update `BI_audit_ALL` join `{$table}` on `BI_audit_ALL`.`REMOTE_ID` = `{$table}`.`ID` set " . implode(", ", $updates) . " {$where}";
|
|
|
$queries[] = "insert into `BI_audit_ALL` (" . implode(", ", $fields) . ") select " . implode(", ", $values) . " from `{$table}` {$where}";
|
|
$queries[] = "insert into `BI_audit_ALL` (" . implode(", ", $fields) . ") select " . implode(", ", $values) . " from `{$table}` {$where}";
|
|
|
$queries[] = "update `{$table}` set `cached` = 1 {$where}";
|
|
$queries[] = "update `{$table}` set `cached` = 1 {$where}";
|
|
|
}
|
|
}
|