Преглед изворни кода

BiauditGenerate - Dodanie minimalnej głębokości analizy

Mariusz Muszyński пре 8 година
родитељ
комит
e5cd80d313

+ 25 - 8
SE/schema/ant-object/default_db.BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA.xsd

@@ -54,6 +54,12 @@
          <xs:enumeration value="No"/>
       </xs:restriction>
    </xs:simpleType>
+   <xs:simpleType name="BI_analiza_onlyTargets">
+      <xs:restriction base="xs:string">
+         <xs:enumeration value="Y"/>
+         <xs:enumeration value="N"/>
+      </xs:restriction>
+   </xs:simpleType>
    <xs:complexType name="BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA">
       <xs:annotation>
          <xs:documentation>Zadania szukania powiązań</xs:documentation>
@@ -64,7 +70,7 @@
             type="default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:A_STATUS_Type"/>
          <xs:element name="A_STATUS_INFO" type="xs:string"/>
          <xs:element name="L_APPOITMENT_USER" type="xs:string"/>
-<!--         <xs:element ref="SystemObjects__x3A__AccessOwner:L_APPOITMENT_USER">
+         <!--         <xs:element ref="SystemObjects__x3A__AccessOwner:L_APPOITMENT_USER">
             <xs:annotation>
                <xs:appinfo>
                   <system_cache__appinfo:flat_relation_cache>
@@ -74,7 +80,7 @@
             </xs:annotation>
          </xs:element>-->
          <xs:element name="A_CLASSIFIED" type="xs:string"/>
-<!--         <xs:element ref="SystemObjects__x3A__AccessGroup:A_CLASSIFIED">
+         <!--         <xs:element ref="SystemObjects__x3A__AccessGroup:A_CLASSIFIED">
             <xs:annotation>
                <xs:appinfo>
                   <system_cache__appinfo:flat_relation_cache>
@@ -84,7 +90,7 @@
             </xs:annotation>
          </xs:element>-->
          <xs:element name="A_ADM_COMPANY" type="xs:string"/>
-<!--         <xs:element ref="SystemObjects__x3A__AccessGroup:A_ADM_COMPANY">
+         <!--         <xs:element ref="SystemObjects__x3A__AccessGroup:A_ADM_COMPANY">
             <xs:annotation>
                <xs:appinfo>
                   <system_cache__appinfo:flat_relation_cache>
@@ -96,7 +102,10 @@
          <xs:element name="FILE_STATUS"
             type="default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:FILE_STATUS_Type"/>
          <xs:element name="FILE_STATUS_info" type="xs:string"/>
-         <xs:element name="BI_analiza_depth" type="xs:int"/>
+         <xs:element name="BI_analiza_minDepth" type="xs:int"/>
+         <xs:element name="BI_analiza_maxDepth" type="xs:int"/>
+         <xs:element name="BI_analiza_onlyTargets"
+            type="default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_analiza_onlyTargets"/>
          <xs:element name="BI_analiza_reloadCache"
             type="default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_analiza_reloadCache_Type"/>
          <xs:element ref="default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY"
@@ -104,7 +113,9 @@
             <xs:annotation>
                <xs:appinfo>
                   <system_cache__appinfo:flat_relation_cache>
-                     <system_cache__appinfo:source system_cache__appinfo:name="ID" system_cache__appinfo:xpath="default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA"/>
+                     <system_cache__appinfo:source system_cache__appinfo:name="ID"
+                        system_cache__appinfo:xpath="default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA"
+                     />
                   </system_cache__appinfo:flat_relation_cache>
                </xs:appinfo>
                <xs:documentation>Relacja do BI_audit_ENERGA_PRACOWNICY</xs:documentation>
@@ -116,7 +127,9 @@
             <xs:annotation>
                <xs:appinfo>
                   <system_cache__appinfo:flat_relation_cache>
-                     <system_cache__appinfo:source system_cache__appinfo:name="ID" system_cache__appinfo:xpath="default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA"/>
+                     <system_cache__appinfo:source system_cache__appinfo:name="ID"
+                        system_cache__appinfo:xpath="default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA"
+                     />
                   </system_cache__appinfo:flat_relation_cache>
                </xs:appinfo>
                <xs:documentation>Relacja do BI_audit_ENERGA_RUM_KONTRAHENCI</xs:documentation>
@@ -128,7 +141,9 @@
             <xs:annotation>
                <xs:appinfo>
                   <system_cache__appinfo:flat_relation_cache>
-                     <system_cache__appinfo:source system_cache__appinfo:name="ID" system_cache__appinfo:xpath="default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA"/>
+                     <system_cache__appinfo:source system_cache__appinfo:name="ID"
+                        system_cache__appinfo:xpath="default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA"
+                     />
                   </system_cache__appinfo:flat_relation_cache>
                </xs:appinfo>
                <xs:documentation>Relacja do BI_audit_KW_requested_person</xs:documentation>
@@ -140,7 +155,9 @@
             <xs:annotation>
                <xs:appinfo>
                   <system_cache__appinfo:flat_relation_cache>
-                     <system_cache__appinfo:source system_cache__appinfo:name="ID" system_cache__appinfo:xpath="default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA"/>
+                     <system_cache__appinfo:source system_cache__appinfo:name="ID"
+                        system_cache__appinfo:xpath="default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA"
+                     />
                   </system_cache__appinfo:flat_relation_cache>
                </xs:appinfo>
                <xs:documentation>Relacja do

+ 97 - 40
SE/se-lib/Route/UrlAction/BiAuditGenerate.php

@@ -184,7 +184,8 @@ function toggle(source) {
 		} else { // wyzwolone z poziomu tabeli BI_audit_ENERGA_PRACOWNICY - dodajemy nowy rekord
 			if (count($prID) != 1) throw new Exception("Błąd formularza!");
 			if (!($lAppoitmentInfo = V::get('info', false, $_POST))) throw new Exception("Błąd formularza!");
-			if (!($BiAnalizaDepth = V::get('depth', false, $_POST))) throw new Exception("Błąd formularza!");
+			if (!($BiAnalizaMinDepth = V::get('minDepth', false, $_POST))) throw new Exception("Błąd formularza!");
+			if (!($BiAnalizaMaxDepth = V::get('maxDepth', false, $_POST))) throw new Exception("Błąd formularza!");
 			$query = "select * from BI_audit_ENERGA_PRACOWNICY where ID='{$prID[0]}'";
 			$result = DB::getPDO()->fetchFirst($query);
 			if (!$result) throw new Exception("Błąd formularza!");
@@ -197,7 +198,8 @@ function toggle(source) {
 				'FILE_STATUS' => 'NONE',
 				'FILE_STATUS_info' => 'Oczekuję na zdefiniowanie danych wejściowych',
 				'BI_analiza_reloadCache' => $sqlUpdate['BI_analiza_reloadCache'],
-				'BI_analiza_depth' => $BiAnalizaDepth,
+				'BI_analiza_minDepth' => $BiAnalizaMinDepth,
+				'BI_analiza_maxDepth' => $BiAnalizaMaxDepth,
 			];
 			$powiazanieID = DB::getDB()->ADD_NEW_OBJ('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', (object)$sqlInsert);
 			if ($powiazanieID) SE_Layout::alert('success','Dodano rekord do wygenerowania powiązań');
@@ -316,7 +318,8 @@ function toggle(source) {
           <tr style="text-align:center; background-color:lightgray">
             <td width=1>ID</td>
             <td>Adnotacje</td>
-            <td>Głębokość analizy</td>
+            <td>Minimalna głębokość analizy</td>
+            <td>Maksymalna głębokość analizy</td>
             <td>Status raportu</td>
             <td>Status raportu - informacje</td>
             <td>Indywidualny raport</td>
@@ -334,7 +337,7 @@ join `{$refPowiazaniaToPracownicy}` on `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZAN
 where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
 		$result = DB::getPDO()->fetchAll($query);
 
-		if (!$result) echo '<tr><td align="center" colspan="7">Brak znalezionych powiązań</td></tr>';
+		if (!$result) echo '<tr><td align="center" colspan="8">Brak znalezionych powiązań</td></tr>';
 		else {
 	                foreach ($result as $row) {
 				$query = "select count(*) from `{$refPowiazaniaToPracownicy}` where `PRIMARY_KEY` = '{$row['ID']}'";
@@ -343,7 +346,8 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
           <tr>
             <td align="right"><?=$row['ID']?></td>
             <td><?=$row['L_APPOITMENT_INFO']?></td>
-            <td><?=$row['BI_analiza_depth']?></td>
+            <td><?=$row['BI_analiza_minDepth']?></td>
+            <td><?=$row['BI_analiza_maxDepth']?></td>
             <td><?=$row['FILE_STATUS']?></td>
             <td><?=$row['FILE_STATUS_info']?></td>
             <td><?=($count > 1 ? 'Nie' : 'Tak')?></td>
@@ -364,9 +368,15 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
   </div>
   <form class="form-horizontal" method="post">
     <div class="form-group">
-      <label class="col-sm-4 control-label">Głębokość poszukiwań (liczba rekurencji)</label>
+      <label class="col-sm-4 control-label">Minimalna głębokość poszukiwań (liczba rekurencji)</label>
       <div class="col-sm-1">
-        <input type="number" class="form-control" name="depth" data-bind="value:replyNumber" min="1" max="9" value="6" required/>
+        <input type="number" class="form-control" name="minDepth" id="minDepth"  data-bind="value:replyNumber" min="1" max="9" value="1" required/>
+      </div>
+    </div>
+    <div class="form-group">
+      <label class="col-sm-4 control-label">Maksymalna głębokość poszukiwań (liczba rekurencji)</label>
+      <div class="col-sm-1">
+        <input type="number" class="form-control" name="maxDepth" id="maxDepth" data-bind="value:replyNumber" min="1" max="9" value="6" required/>
       </div>
     </div>
     <div class="form-group">
@@ -396,7 +406,7 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
     <div class="form-group">
       <div class="col-sm-12">
         <div class="containter" style="text-align:center">
-          <button type="submit" class="btn btn-primary" name="action" value="initialize">Generuj</button>
+          <button type="submit" class="btn btn-primary" name="action" value="initialize" onClick="return validate()">Generuj</button>
           <a href="<?=$this->REFERER?>" class="btn btn-default">Powrót</a>
         </div>
       </div>
@@ -405,6 +415,16 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
     <input type="hidden" name="prID[]" value="<?=$pracownik['ID']?>">
   </form>
 </div>
+DUPA
+<script language="JavaScript">
+<!--
+function validate() {
+  result = (document.getElementById('minDepth').value <= document.getElementById('maxDepth').value);
+  if (!result) alert('Wartość minimalnej głębokości analizy nie może być większa od wartości maksymalnej głębokości analizy!');
+  return result;
+}
+-->
+</script>
 <?php
 	}
 
@@ -463,7 +483,7 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
 ?>
 <div class="container" style="margin-top:20px">
   <legend>
-    Importowanie osób z KRS do tabeli pracowników
+    Importowanie podmiotów z KRS do tabel kontrahentów i pracowników
   </legend>
   <div class="form-group">
     <div class="col-sm-12">
@@ -498,15 +518,22 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
     <div class="form-group">
       <div class="col-sm-offset-1 col-sm-11">
         <button type="submit" class="btn btn-primary" name="action" value="search">Szukaj</button>
+        <a href="<?=$this->REFERER?>" class="btn btn-default">Powrót</a>
       </div>
     </div>
-    <input type="hidden" name="REFERER" value="<?=$this->REFERER?>"/>
   </form>
 </div>
 <?php
 	}
 
 	private function importKrsToPracownicySearch($krsId = null) {
+		$formItems = [
+			"nazwa" => 'like',
+			"krs" => '=',
+			"nip" => '=',
+			"regon" => '=',
+		];
+
 		try {
 			$subaction = V::get('subaction', '', $_POST);
 			switch ($subaction) {
@@ -514,32 +541,27 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
 					$krsId = V::get('krsId', 0, $_POST, int);
 					break;
 				case "addKrsPersonToPracownicy":
+					$krsId = V::get('krsId', 0, $_POST, int);
 					$personId = V::get('personId', [], $_POST);
 					if (!$personId) throw new Exception("Błąd formularza");
 					$query = "insert into BI_audit_ENERGA_PRACOWNICY (source, imiona, nazwisko, pesel) select 'KRS', imiona, nazwisko, pesel from BI_audit_KRS_person where ID in (" . implode(", ", $personId) . ")";
 					DB::getPDO()->query($query);
 					SE_Layout::alert('success', "Pomyślnie zaimportowano " . count($personId) . " pracownik" . ((count($personId) == 1) ? "a" : "ów"));
-					$this->importKrsToPracownicyForm();
-					return;
-				case "addKrsCompanyToKontrachenci":
+					break;
+				case "addKrsToKontrahenci":
 					$krsId = V::get('krsId', 0, $_POST, int);
 					if (!$krsId) throw new Exception("Błąd formularza");
 					$query = "insert into BI_audit_ENERGA_RUM_KONTRAHENCI (uwagi, Pelna_nazwa_kontrahenta, REGON, NIP, KRS) select 'import z KRS', nazwa, regon, nip, krs from BI_audit_KRS where ID = ".$krsId." ";
-					DB::getPDO()->query($query);	
-					return;
+					DB::getPDO()->query($query);
+					SE_Layout::alert('success', "Pomyślnie zaimportowano kontrahenta");
+					break;
 			}
 
 			if ($krsId) {
 				$where = ["ID = '{$krsId}'"];
 			} else {
-				$items = [
-					"nazwa" => 'like',
-					"krs" => '=',
-					"nip" => '=',
-					"regon" => '=',
-				];
 				$form = [];
-				foreach ($items as $item => $type) {
+				foreach ($formItems as $item => $type) {
 					if ($param = V::get($item, '', $_POST)) {
 						if ($type == 'like') $param = "%{$param}%";
 						$form[$item] = DB::getPDO()->quote($param);
@@ -548,7 +570,7 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
 				if (!$form) throw new Exception("Nie wypełniono żadnego pola wyszukiwania!");
 
 				$where = [];
-				foreach ($form as $name => $value) $where[] = "`{$name}` {$items[$name]} {$value}";
+				foreach ($form as $name => $value) $where[] = "`{$name}` {$formItems[$name]} {$value}";
 			}
 		} catch (Exception $e) {
 			SE_Layout::alert('danger', $e->getMessage());
@@ -569,7 +591,7 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
 <div class="container" style="margin-top:20px">
   <form method="post">
     <legend>
-      Importowanie osób z KRS do tabeli pracowników
+      Importowanie podmiotów z KRS do tabel kontrahentów i pracowników
     </legend>
     <div class="form-group">
       <div class="col-sm-12">
@@ -587,7 +609,6 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
               <td>KRS</td>
               <td>NIP</td>
               <td>Regon</td>
-              <td>(Akcja)</td>
 <?php
 		if (count($result) > 1) {
 ?>
@@ -600,7 +621,7 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
           <tbody>
 
 <?php
-		if (!$result) echo '<tr><td align="center" colspan="7">Nie znaleziono podmiotu</td></tr>';
+		if (!$result) echo '<tr><td align="center" colspan="6">Nie znaleziono podmiotu</td></tr>';
 		else {
 			$lp = 1;
 			foreach ($result as $row) {
@@ -618,14 +639,11 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
               <td><?=$row['krs']?></td>
               <td><?=$row['nip']?></td>
               <td><?=$row['regon']?></td>
-              <td>
-	              <button type="submit" class="btn btn-primary" name="subaction" value="addKrsCompanyToKontrachenci">Dodaj firme do kontrachentow.</button>
-			  </td>
 <?php
 		if (count($result) > 1) {
 ?>
               <td align="center">
-               <input type="radio" name="krsId" value="<?=$row['ID']?>"/>
+               <input type="radio" name="krsId" id="krsId" value="<?=$row['ID']?>"/>
              </td>
 <?php
 		}
@@ -645,14 +663,15 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
     <div class="form-group">
       <div class="col-sm-12">
 <?php
-			foreach (array_keys($items) as $item) {
+			foreach (array_keys($formItems) as $item) {
 ?>
         <input type="hidden" name="<?=$item?>" value="<?=V::get($item, '', $_POST)?>"/>
 <?php
 			}
 ?>
+	<input type="hidden" name="back" value="search"/>
         <div class="containter" style="text-align:center">
-          <button type="submit" class="btn btn-primary" name="subaction" value="listKrsPerson">Znajdź osoby powiązane z podmiotem</button>
+          <button type="submit" class="btn btn-primary" name="subaction" value="listKrsPerson" onClick="return validateCompany(this)">Wybierz zaznaczony podmiot</button>
           <a href="" class="btn btn-default">Powrót</a>
         </div>
       </div>
@@ -680,6 +699,9 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
           <tbody>
 
 <?php
+			$query = "select count(*) from BI_audit_ENERGA_RUM_KONTRAHENCI kh join BI_audit_KRS krs on (kh.NIP = krs.nip or kh.REGON = krs.regon or kh.KRS = krs.krs) where krs.ID = '{$krsId}'";
+			$kontrahentExists = DB::getPDO()->fetchValue($query);
+
 			$refKrsToKrsPerson = ACL::getRefTable('default_db/BI_audit_KRS/BI_audit_KRS', "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person");
 			$query = "select person.*, pracownicy.ID as pracownicyId from `{$refKrsToKrsPerson}` ref join `BI_audit_KRS_person` person on ref.REMOTE_PRIMARY_KEY = person.ID left join BI_audit_ENERGA_PRACOWNICY pracownicy on person.pesel = pracownicy.pesel where ref.PRIMARY_KEY = '{$krsId}'";
 			$result = DB::getPDO()->fetchAll($query);
@@ -702,8 +724,26 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
           </tbody>
         </table>
         <div class="containter" style="text-align:center">
-          <button type="submit" class="btn btn-primary" name="subaction" value="addKrsPersonToPracownicy" onClick="return validate(this)">Dodaj zaznaczone osoby do tabeli pracowników</button>
-          <a href="<?=$_SERVER['HTTP_REFERER']?>" class="btn btn-default">Powrót</a>
+          <button type="submit" class="btn btn-primary" name="subaction" value="addKrsToKontrahenci"<?=($kontrahentExists ? " disabled" : "")?>>Dodaj firmę do tabeli kontrahentów</button>
+          <button type="submit" class="btn btn-primary" name="subaction" value="addKrsPersonToPracownicy" onClick="return validatePerson(this)">Dodaj zaznaczone osoby do tabeli pracowników</button>
+          <input type="hidden" name="krsId" value="<?=$krsId?>"/>
+          <input type="hidden" name="REFERER" value="<?=$this->REFERER?>"/>
+<?php
+			if (V::get('back', '', $_POST) == 'search') {
+				foreach (array_keys($formItems) as $item) {
+?>
+          <input type="hidden" name="<?=$item?>" value="<?=V::get($item, '', $_POST)?>"/>
+<?php
+				}
+?>
+          <button type="submit" class="btn btn-default" name="action" value="search">Powrót</button>
+<?php
+			} else {
+?>
+          <a href="<?=$this->REFERER?>" class="btn btn-default">Powrót</a>
+<?php
+			}
+?>
         </div>
       </div>
     </div>
@@ -732,13 +772,18 @@ function toggle(source) {
   for(var i=0, n=checkboxes.length;i<n;i++) if(!checkboxes[i].disabled && checkboxes[i].checked == false) all = false;
   source.form['checkAll'].checked = all;
 }
-function validate(source) {
+function validatePerson(source) {
   checkboxes = document.getElementsByName('personId[]');
   checked = false;
   for(var i=0, n=checkboxes.length;i<n;i++) if(checkboxes[i].checked) checked = true;
   if (!checked) alert('Nie wybrano żadnej osoby!');
   return checked;
 }
+function validateCompany(source) {
+  checked = document.getElementById('krsId').checked;
+  if (!checked) alert('Nie wybrano żadnej firmy!');
+  return checked;
+}
 -->
 </script>
 <?php
@@ -1433,6 +1478,15 @@ UPDATE `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` SET `BI_analiza_reloadCache`
 SQL;
 		$sqlList['ChangeStructure3'] = <<<SQL
 ALTER TABLE `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` CHANGE `BI_analiza_reloadCache` `BI_analiza_reloadCache` ENUM('Full','Part','No') NOT NULL DEFAULT 'No';
+SQL;
+		$sqlList['ChangeStructure4'] = <<<SQL
+ALTER TABLE `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` CHANGE `BI_analiza_depth` `BI_analiza_maxDepth` INT(2) NULL DEFAULT '9';
+SQL;
+		$sqlList['ChangeStructure5'] = <<<SQL
+ALTER TABLE `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` ADD `BI_analiza_minDepth` INT(2) NOT NULL DEFAULT '0' AFTER `FILE_STATUS_info`;
+SQL;
+		$sqlList['ChangeStructure6'] = <<<SQL
+ALTER TABLE `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` ADD `BI_analiza_onlyTargets` ENUM('Y','N') NOT NULL DEFAULT 'Y' AFTER `BI_analiza_maxDepth`;
 SQL;
 
 
@@ -1534,7 +1588,8 @@ class BiAuditRelations {
 
 class BiAuditPowiazania {
 
-	private $DEPTH;
+	private $minDepth;
+	private $maxDepth;
 	private $ID;
 	private $endNodes;
 	private $path = [];
@@ -1545,10 +1600,12 @@ class BiAuditPowiazania {
 
 	public function __construct($ID = 0) {
 		if (!$ID) throw new Exception("Wrong ID parameter");
-		$query = "select BI_analiza_depth from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = '{$ID}' and FILE_STATUS = 'IN_PROGRESS' and BI_analiza_reloadCache not in ('Full', 'Part')";
+		$query = "select BI_analiza_minDepth, BI_analiza_maxDepth from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where ID = '{$ID}' and FILE_STATUS = 'IN_PROGRESS' and BI_analiza_reloadCache not in ('Full', 'Part')";
 		$result = DB::getPDO()->fetchAll($query);
 		if (!$result) throw new Exception("Błąd danych");
-		$this->DEPTH = (int) $result[0]['BI_analiza_depth'];
+		$this->minDepth = (int) $result[0]['BI_analiza_minDepth'];
+		$this->maxDepth = (int) $result[0]['BI_analiza_maxDepth'];
+		if ($this->minDepth > $this->maxDepth) throw new Exception("Wartość minimalnej głębokości analizy jest większa od wartości maksymalnej głębokości analizy");
 		$this->ID = $ID;
 
 		$subQueries = [];
@@ -1576,12 +1633,12 @@ class BiAuditPowiazania {
 		if (!$relation) $relation = 0;
 
 		if ($end) {
-			if (in_array($ID, $this->endNodes)) $this->results[] = $this->path;
+			if (in_array($ID, $this->endNodes) && count($this->path) >= $this->minDepth) $this->results[] = $this->path;
 			array_pop($this->path);
 			return true;
 		}
 
-		if (count($this->path) > $this->DEPTH) {
+		if (count($this->path) > $this->maxDepth) {
 			array_pop($this->path);
 			return false;
 		}