Ver Fonte

Implementacja OD i DO

Mariusz Muszyński há 7 anos atrás
pai
commit
07e44adb3b
1 ficheiros alterados com 26 adições e 13 exclusões
  1. 26 13
      SE/se-lib/Route/UrlAction/BiAuditGenerate.php

+ 26 - 13
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -1141,7 +1141,7 @@ function validateCompany(source) {
 				$showDetails .= "<h5>Żadna wartość nie występuje wiele razy</h5>";
 			}
 		} catch (Exception $e) {
-			$showDetails = $e->getMessage();
+			$showDetails = "<h4>{$e->getMessage()}</h4>";
 		}
 		$_SESSION['benford'][$this->SOURCE['TABLE']]['details'][$a][$b] = gzcompress($showDetails);
 		$showDetails .= '<button type="submit" class="btn btn-primary btn-sm" onClick="hideDetails()">Zamknij</button>';
@@ -1467,9 +1467,6 @@ function toggleCheckSecond(check) {
 				'xmlns:'.$namespace($this->SOURCE['TABLE']) => 'https://biuro.biall-net.pl/wfs'
 			];
 			$array[$namespace($mainTable, $mainTable)] = array_merge(['@attributes' => ['fid' => "{$mainTable}.{$benfordId}", 'p5:primaryKey' => $benfordId]], $arrayWithNamespace($mainTable, array_merge(['ID' => $benfordId], $sqlArr)));
-echo "<pre>";
-print_r($array);
-echo "</pre>";
 			$checked = [
 				'firstStep' => V::get('checkFirstStep', [], $_POST),
 				'secondStep' => V::get('checkSecondStep', [], $_POST),
@@ -3059,8 +3056,22 @@ class BiAuditPowiazania {
 	private $results = [];
 	private $items_results = [];
 	private $relations = [];
-	private $srcTables = ['BI_audit_ENERGA_PRACOWNICY']; //, ['BI_audit_POWIAZANIA_OD', 'BI_audit_POWIAZANIA_OBIEKTY']];
-	private $destTables = ['BI_audit_ENERGA_RUM_KONTRAHENCI', 'BI_audit_KW_requested_person']; //, ['BI_audit_POWIAZANIA_DO', 'BI_audit_POWIAZANIA_OBIEKTY']];
+	private $srcTables = ['BI_audit_ENERGA_PRACOWNICY',
+		['BI_audit_POWIAZANIA_OD', 'BI_audit_KRS'],
+		['BI_audit_POWIAZANIA_OD', 'BI_audit_KRS_person'],
+		['BI_audit_POWIAZANIA_OD', 'BI_audit_MSIG'],
+		['BI_audit_POWIAZANIA_OD', 'BI_audit_MSIG_person'],
+		['BI_audit_POWIAZANIA_OD', 'BI_audit_CEIDG'],
+		['BI_audit_POWIAZANIA_OD', 'BI_audit_CEIDG_pelnomocnicy'],
+	];
+	private $destTables = ['BI_audit_ENERGA_RUM_KONTRAHENCI', 'BI_audit_KW_requested_person'
+		['BI_audit_POWIAZANIA_DO', 'BI_audit_KRS'],
+		['BI_audit_POWIAZANIA_DO', 'BI_audit_KRS_person'],
+		['BI_audit_POWIAZANIA_DO', 'BI_audit_MSIG'],
+		['BI_audit_POWIAZANIA_DO', 'BI_audit_MSIG_person'],
+		['BI_audit_POWIAZANIA_DO', 'BI_audit_CEIDG'],
+		['BI_audit_POWIAZANIA_DO', 'BI_audit_CEIDG_pelnomocnicy'],
+	];
 	private $step = 0;
 	private $tasksDirLocation;
 	private $progressFile;
@@ -3161,7 +3172,7 @@ class BiAuditPowiazania {
 		$resultDest = [];
 		foreach ($this->destTables as $destTable) {
 			if ($refTable = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $destTable)) {
-				$subQueries[] = "select `all`.`ID` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$destTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
+				$subQueries[] = "select `all`.`ID`, `all`.`REMOTE_TABLE` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$destTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
 			}
 		}
 		if ($subQueries) {
@@ -3174,7 +3185,7 @@ class BiAuditPowiazania {
 		$resultSrc = [];
 		foreach ($this->srcTables as $srcTable) {
 			if ($refTable = BiAuditRefTables::getRefTable('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', $srcTable)) {
-				$subQueries[] = "select `all`.`ID` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$srcTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
+				$subQueries[] = "select `all`.`ID`, `all`.`REMOTE_TABLE` from `BI_audit_ALL` `all` join `{$refTable}` `ref` on `all`.`REMOTE_TABLE` = '{$srcTable}' and `all`.`REMOTE_ID` = `ref`.`REMOTE_PRIMARY_KEY` and `ref`.`PRIMARY_KEY` = '{$this->ID}'";
 			}
 		}
 		if ($subQueries) {
@@ -3198,6 +3209,7 @@ class BiAuditPowiazania {
 
 		self::saveToLog("Rozpoczynam wyszukiwanie powiązań");
 
+		$externalTables = array_filter(array_merge($this->srcTables, $this->destTables), function($x) {if (!is_array($x)) return true;});
 		$this->count = count($result);
 		$this->progress['summary']['count'] = $this->count;
 		$this->origMaxDepth = $this->maxDepth;
@@ -3215,7 +3227,8 @@ class BiAuditPowiazania {
 					$this->maxDepth = $this->origMaxDepth;
 					self::saveToLog("Przywrócono oryginalną maksymalną głębokość przeszukiwania ({$this->origMaxDepth})");
 				}
-				$this->findPowiazania($row['ID']);
+				$weight = in_array($row['REMOTE_TABLE'], $externalTables) ? 0 : 1;
+				$this->findPowiazania($row['ID'], $weight);
 				$this->saveProgress(['progress' => 1, 'message' => "Zakończono wyszukiwanie powiązań dla obiektu {$this->i}/{$this->count}"]);
 				$this->lastResults = count($this->results);
 			}
@@ -3270,7 +3283,7 @@ class BiAuditPowiazania {
 		return 10;
 	}
 
-	public function findPowiazania($ID, $progress = 0, $steps = 1, $relation = "", $weight = 0) {
+	public function findPowiazania($ID, $weight = 0, $progress = 0, $steps = 1, $relation = "") {
 		$this->step++;
 
 		if ($this->maxDepth > $this->minDepth) {
@@ -3305,12 +3318,12 @@ class BiAuditPowiazania {
 		if (!$relation) $relation = 0;
 
 		if (in_array($ID, $this->endNodes)) {
-			if (count($this->path) > $this->minDepth) $this->addResult($progress);
+			if ($weight) > $this->minDepth) $this->addResult($progress);
 			array_pop($this->path);
 			return;
 		}
 
-		if (count($this->path) > $this->maxDepth) {
+		if ($weight) > $this->maxDepth) {
 			if (!$this->onlyTargets) $this->addResult($progress);
 			array_pop($this->path);
 			return;
@@ -3329,7 +3342,7 @@ class BiAuditPowiazania {
 		$count = count($nodes);
 		$weight += self::weightCalc($count);
 		if ($weight <= $this->maxDepth) {
-			foreach ($nodes as $i => $node) $this->findPowiazania($node['ID'], ($progress + ($i / ($count * $steps))), ($count * $steps), $node['RELATION_ID'], $weight);
+			foreach ($nodes as $i => $node) $this->findPowiazania($node['ID'], $weight, ($progress + ($i / ($count * $steps))), ($count * $steps), $node['RELATION_ID']);
 		}
 
 		array_pop($this->path);