|
@@ -2613,11 +2613,24 @@ SQL;
|
|
|
if ($notFound) {
|
|
if ($notFound) {
|
|
|
list($nip, $regon) = self::parseNipRegon($item);
|
|
list($nip, $regon) = self::parseNipRegon($item);
|
|
|
if ($nip || $regon) {
|
|
if ($nip || $regon) {
|
|
|
- $query = "select ID from BI_audit_ENERGA_RUM_KONTRAHENCI where NIP = '{$nip}' or REGON = '{$regon}'";
|
|
|
|
|
|
|
+ $where1 = [];
|
|
|
|
|
+ $where2 = [];
|
|
|
|
|
+ if ($nip) {
|
|
|
|
|
+ $where1[] = "NIP = '{$nip}'";
|
|
|
|
|
+ $where2[] = "nip = '{$nip}'";
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($regon) {
|
|
|
|
|
+ $where1[] = "REGON = '{$regon}'";
|
|
|
|
|
+ $where2[] = "regon = '{$regon}'";
|
|
|
|
|
+ }
|
|
|
|
|
+ $where1 = implode(' or ', $where1);
|
|
|
|
|
+ $where2 = implode(' or ', $where2);
|
|
|
|
|
+
|
|
|
|
|
+ $query = "select ID from BI_audit_ENERGA_RUM_KONTRAHENCI where {$where1}";
|
|
|
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'];
|
|
|
} else {
|
|
} else {
|
|
|
- $query = "select ID from BI_audit_KRS where nip = '{$nip}' or regon = '{$regon}' order by `ID` desc limit 1";
|
|
|
|
|
|
|
+ $query = "select ID from BI_audit_KRS where {$where2} order by `ID` desc limit 1";
|
|
|
if ($result2 = DB::getPDO()->fetchall($query)) {
|
|
if ($result2 = DB::getPDO()->fetchall($query)) {
|
|
|
foreach ($result2 as $item) {
|
|
foreach ($result2 as $item) {
|
|
|
$query = "insert into BI_audit_ENERGA_RUM_KONTRAHENCI (" . implode(', ', $fields['BI_audit_ENERGA_RUM_KONTRAHENCI']) . ")" .
|
|
$query = "insert into BI_audit_ENERGA_RUM_KONTRAHENCI (" . implode(', ', $fields['BI_audit_ENERGA_RUM_KONTRAHENCI']) . ")" .
|
|
@@ -2625,7 +2638,7 @@ SQL;
|
|
|
if (DB::getPDO()->query($query)) $K_IDs[] = DB::getPDO()->lastInsertId();
|
|
if (DB::getPDO()->query($query)) $K_IDs[] = DB::getPDO()->lastInsertId();
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- $query = "select ID from BI_audit_CEIDG where nip = '{$nip}' or regon = '{$regon}' order by `ID` desc limit 1";
|
|
|
|
|
|
|
+ $query = "select ID from BI_audit_CEIDG where {$where2} order by `ID` desc limit 1";
|
|
|
if ($result2 = DB::getPDO()->fetchall($query)) {
|
|
if ($result2 = DB::getPDO()->fetchall($query)) {
|
|
|
foreach ($result2 as $item) {
|
|
foreach ($result2 as $item) {
|
|
|
$query = "insert into BI_audit_ENERGA_RUM_KONTRAHENCI (" . implode(', ', $fields['BI_audit_ENERGA_RUM_KONTRAHENCI']) . ")" .
|
|
$query = "insert into BI_audit_ENERGA_RUM_KONTRAHENCI (" . implode(', ', $fields['BI_audit_ENERGA_RUM_KONTRAHENCI']) . ")" .
|