Mariusz Muszyński před 7 roky
rodič
revize
32fde9c62b
1 změnil soubory, kde provedl 16 přidání a 3 odebrání
  1. 16 3
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 16 - 3
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -2613,11 +2613,24 @@ SQL;
 				if ($notFound) {
 					list($nip, $regon) = self::parseNipRegon($item);
 					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)) {
 							foreach ($result2 as $item) $K_IDs[] = $item['ID'];
 						} 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)) {
 								foreach ($result2 as $item) {
 									$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();
 								}
 							} 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)) {
 									foreach ($result2 as $item) {
 										$query = "insert into BI_audit_ENERGA_RUM_KONTRAHENCI (" . implode(', ', $fields['BI_audit_ENERGA_RUM_KONTRAHENCI']) . ")" .