Ver Fonte

updated kosztorysy

Piotr Labudda há 8 anos atrás
pai
commit
206d950c87

+ 4 - 1
SE/se-lib/ProjectKosztorysSchema.php

@@ -4,6 +4,8 @@ Lib::loadClass('UI');
 
 class ProjectKosztorysSchema {
 
+  static $ID_ZASOB_KOSZTORYS_CONFIG = 22444;
+
   public static function getSchema($showErrors = false) {
     static $_schema = null;
 		if (null !== $_schema) return $_schema;
@@ -19,6 +21,7 @@ class ProjectKosztorysSchema {
 		*/
 		{
 			$pdo = DB::getPDO();
+      $idZasobConf = self::$ID_ZASOB_KOSZTORYS_CONFIG;
 			$sth = $pdo->prepare("
 				select z.ID, z.TYPE, z.DESC, z.ALIAS_ID
 					, c.ID as c_ID, c.TYPE as c_TYPE, c.DESC as c_DESC, c.ALIAS_ID as c_ALIAS_ID
@@ -28,7 +31,7 @@ class ProjectKosztorysSchema {
 					left join CRM_LISTA_ZASOBOW c  on(c.PARENT_ID = z.ID)
 					left join CRM_LISTA_ZASOBOW a  on(a.ID  = z.ALIAS_ID and z.ALIAS_ID > 0)
 					left join CRM_LISTA_ZASOBOW za on(za.ID = c.ALIAS_ID and c.ALIAS_ID > 0)
-				where z.PARENT_ID = 22444  -- TODO how to find ID, Typespecial with link (maybe Child of table IN7_MK_BAZA_DYSTRYBUCJI )
+				where z.PARENT_ID = {$idZasobConf}  -- TODO how to find ID, Typespecial with link (maybe Child of table IN7_MK_BAZA_DYSTRYBUCJI)
 			");
 			$sth->execute();
 			$rawConf = $sth->fetchAll();

+ 134 - 13
SE/se-lib/Route/ProjektyKosztorysBase.php

@@ -691,10 +691,11 @@ SQL_FUN;
 		if (1 == V::get('_print', '', $_GET)) return;// print mode
 		$task = V::get('_task', '', $_GET);
 
-		UI::startTag('div', ['class'=>'jumbotron']);
+		UI::startTag('div', ['class'=>'jumbotron', 'style' => "padding-left: 20px; padding-right:20px"]);
 		UI::startTag('div', ['class'=>'container']);
 			UI::startTag('div', ['class'=>'btn-group']);
 				if ($idProject > 0) {
+					echo UI::h('button', [ 'class' => "btn btn-default disabled" ], "Projekt {$idProject}:");
 					$activeRoute = V::get('_route', '', $_GET);
 					$route = 'UrlAction_ProjektyKosztorys'; UI::link('default', "Kosztorys", "index.php?_route={$route}&ID_PROJECT={$idProject}", ['className'=>['active'=>($route == $activeRoute)]]);
 					$route = 'UrlAction_ProjektyPrzedmiarKosztorys'; UI::link('default', "Przedmiar", "index.php?_route={$route}&ID_PROJECT={$idProject}&_print=1", ['className'=>['active'=>($route == $activeRoute)]]);
@@ -706,7 +707,7 @@ SQL_FUN;
 					$route = 'UrlAction_ProjektyOdbiorKosztorys'; UI::link('default', "Odbiory", "index.php?_route={$route}&ID_PROJECT={$idProject}", ['className'=>['active'=>($route == $activeRoute)]]);
 					$route = 'UrlAction_ProjektyOfertaKosztorys'; UI::link('default disabled', "TODO: Oferty", "index.php?_route={$route}&ID_PROJECT={$idProject}", ['className'=>['active'=>($route == $activeRoute)]]);
 				}
-				UI::link('default', "Oferta domyślna (Admin)", "index.php?_route=UrlAction_ProjektyOfertaAdminKosztorys");
+				UI::link('default', "Oferta domyślna", "index.php?_route=UrlAction_ProjektyOfertaAdminKosztorys");
 			UI::endTag('div');// .btn-group
 		UI::endTag('div');// .container
 		$this->additionalPanel($idProject, $idCompany);
@@ -1110,6 +1111,7 @@ SQL_FUN;
 		$subProjCost = V::get('sub_proj', array(), $projCosts);
 
 		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin);
+		DBG::log($data, 'array', "\$data");
 		$dataSummary = $data['summary'];
 		$dataSubProj = $data['by_project'];
 		// $dataSubProj = array();
@@ -1526,24 +1528,24 @@ SQL_FUN;
 		";
 	}
 
-	public function getKosztorysData($idProject, $idOrder = 0, $admin = 0) {// TODO: before was: ($idProject, $admin = 0)
+	public function getKosztorysData($idProject, $korespType = '', $idKoresp = 0, $admin = 0, $fetchAllRows = false) {
 		static $_data = null;
 		if (null === $_data) {
 			$idSubProject = $this->getModel($idProject)->getSubProjectIds();
 			$idSubProject[] = $idProject;
-			$_data = $this->fetchData($idSubProject, $admin);
+			$_data = $this->fetchData($idSubProject, $korespType, $idKoresp, $admin, $fetchAllRows);
 		}
 		return $_data;
 	}
 
-	public function fetchData($idProject, $idOrder = 0, $admin = 0) {// TODO: before was: ($idProject, $admin = 0)
+	public function fetchData($idProject, $korespType = '', $idKoresp = 0, $admin = 0, $fetchAllRows = false) {
+		DBG::log(null, 'string', "fetchData(\$idProject, {$korespType}, {$idKoresp})");
 		$data = array();
 		$data['summary'] = array();// [ $idType ] = ['type', 'jednostka', 'ilosc']
 		$data['rawDataByType'] = array();
 		if (empty($idProject)) return $data;
 		$schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
 		$conf = $schema['config'];
-		$pdo = DB::getPDO();
 		foreach ($conf['layer'] as $idLayer => $layer) {
 			if (!$layer['tabela_name']) continue;// TODO: throw error in validate
 			if ('ZASOB' == $layer['zasob_type']) {
@@ -1558,19 +1560,48 @@ SQL_FUN;
 			$sqlIlosc = ('SZTUKA' == $layer['jednostka'])? "count(1)" : "sum(t.{$sqlIloscField})";
 			$sqlZasobField = (!empty($layer['zasob_field']))? $layer['zasob_field'] : 'ID';
 			$sqlGroupBy = "group by t.ID_PROJECT" . ((!empty($layer['zasob_field']))? ", t.{$sqlZasobField}" : '');
+			if ($fetchAllRows) $sqlGroupBy = "";
 			$sqlIdProject = (is_array($idProject))? implode(",", $idProject) : (int)$idProject;
+			$cols = [
+				"t.{$sqlZasobField}",
+				"t.ID_PROJECT",
+				"{$sqlIlosc} as ilosc",
+				"count(1) as ilosc_sztuk",
+			];
+			if ($fetchAllRows) array_unshift($cols, "t.ID as primaryKey");
+			$sqlCols = implode(", ", $cols);
 			$sql = "
-				select t.{$sqlZasobField}
-						, t.ID_PROJECT
-						, {$sqlIlosc} as ilosc
-						, count(1) as ilosc_sztuk
+				select {$sqlCols}
 				from {$tblName} t
 				where t.ID_PROJECT in({$sqlIdProject})
 					and t.the_geom is not null
+					-- WHERE
 				{$sqlGroupBy}
 			";
 			$data['_DBG_sql'][$idLayer] = $sql;
-			$rawLayData = $pdo->fetchAll($sql);
+			// $rawLayData = DB::getPDO()->fetchAll($sql);
+			$remoteIdKorespField = '';
+			if ($idKoresp > 0) {
+				switch ($korespType) {
+					case 'ZLECENIE': $remoteIdKorespField = "ID_KORESP_ZLECENIE"; break;
+					case 'PROTOK_ODB': $remoteIdKorespField = "ID_KORESP_PROTOK_ODB"; break;
+					default: // throw new Exception("Not implemented koresp type '{$korespType}'");
+				}
+			}
+			DBG::log($remoteIdKorespField, 'string', "\$remoteIdKorespField");
+			try {
+				if ($remoteIdKorespField) {
+					$sqlWithOrder = str_replace("-- WHERE", "and t.{$remoteIdKorespField} = '{$idKoresp}'", $sql);
+					$data['_DBG_sql_idOrder'][$idLayer] = $sqlWithOrder;
+					$rawLayData = DB::getPDO()->fetchAll($sqlWithOrder);
+				} else {
+					$rawLayData = DB::getPDO()->fetchAll($sql);
+				}
+			} catch (Exception $e) {
+				DBG::log($e);
+				if (1 != V::get('_print', '', $_GET)) UI::alert('danger', "Brak pola `{$remoteIdKorespField}` w tabeli `$tblName`");
+				$rawLayData = DB::getPDO()->fetchAll($sql);
+			}
 			$rawLayData = array_filter($rawLayData, function($row) {
 				return ($row['ilosc'] > 0);
 			});
@@ -1603,11 +1634,25 @@ SQL_FUN;
 		}
 		//DBG::_(true, true, "data", $data, __CLASS__, __FUNCTION__, __LINE__);
 		//DBG::table("data['rawDataByType']", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
-		if ($admin) {
+		if (true) { // $admin) {
 			foreach ($data['rawDataByType'] as $row) {
 				$layer = $conf['layer'][$row['idLayer']];
 				if ($row['idType'] <= 0) {
-					UI::alert('warning', "Pomijanie nieznanego oznaczenia '{$row['type']}' w ilości {$row['ilosc']} - warstwa '{$layer['label']}' ({$layer['tabela_name']}), projekt nr {$row['ID_PROJECT']}");
+					echo UI::h('div', [ 'class' => "alert alert-warning" ], [
+						"Pomijanie nieznanego oznaczenia '{$row['type']}' w ilości {$row['ilosc']} - warstwa '{$layer['label']}' ({$layer['tabela_name']}), projekt nr {$row['ID_PROJECT']}",
+						" - ",
+						UI::hButtonPost("dodaj typ '{$row['type']}'", [
+							'class' => "btn btn-warning",
+							'data' => [
+								'_postTask' => 'addTypKosztu',
+								// {$row['type']}' w ilości {$row['ilosc']} - warstwa '{$layer['label']}' ({$layer['tabela_name']}), projekt nr {$row['ID_PROJECT']}",
+								// '1xHDPE 40/3,7' w ilości 10 - warstwa 'Rury osłonowe' (Rozdzielcza_rura_oslonowa_magistralna), projekt nr 6906
+								'koszt' => $row['type'],
+								'idLayer' => $row['idLayer'],
+								'table' => $layer['tabela_name'],
+							]
+						])
+					]);
 				}
 			}
 		}
@@ -1632,6 +1677,10 @@ SQL_FUN;
 			$layData = array();
 			$layData['label'] = $conf['layer'][$idLayer]['label'];
 			$layData['data'] = $iloscByType;
+			// TODO: ProjektyKosztyWstepnychRobot
+			//foreach ($layData['data'] as &$iloscData) {
+			//	$iloscData['jednostka'] = $conf['layer'][$idLayer]['jednostka'];
+			//}
 			$data['summary'][$idLayer] = $layData;
 		}
 		//DBG::_(true, true, "data['summary']", $data['summary'], __CLASS__, __FUNCTION__, __LINE__);
@@ -1653,4 +1702,76 @@ SQL_FUN;
 		return $data;
 	}
 
+	function execPostTasks() {
+		$postTask = V::get('_postTask', '', $_POST);
+		try {
+			switch ($postTask) {
+				case 'addTypKosztu': return $this->addTypKosztu();
+				default: ;
+			}
+		} catch (AlertSuccessException $e) {
+			DBG::log($e);
+			UI::alert('success', $e->getMessage());
+		} catch (Exception $e) {
+			DBG::log($e);
+			UI::alert('danger', $e->getMessage());
+		}
+	}
+	function addTypKosztu() {
+		$koszt = V::get('koszt', '', $_POST);
+		$idLayer = V::get('idLayer', 0, $_POST, 'int');
+		$table = V::get('table', '', $_POST);
+		$schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
+		$conf = $schema['config'];
+		DBG::log($conf, 'array', '$conf');
+		$idType = array_search($koszt, $conf['type']);
+
+		DBG::log("DBG:addTypKosztu \$idType({$idType})");
+		if (!$idType) {
+			$row = [
+				'PARENT_ID' => ProjectKosztorysSchema::$ID_ZASOB_KOSZTORYS_CONFIG,
+				'TYPE' => "TYP_KOSZTU",
+				'DESC' => $koszt,
+				'DESC_PL' => $koszt,
+			];
+			DBG::log($row, 'array', "insert into CRM_LISTA_ZASOBOW type: '{$koszt}' under ROOT");
+			$idType = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', array_merge($row, [
+				'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
+				'A_RECORD_CREATE_DATE' => "NOW()",
+			]));
+			if ($idType > 0) {
+				DB::getPDO()->insert('CRM_LISTA_ZASOBOW_HIST', array_merge($row, [
+					'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
+					'A_RECORD_CREATE_DATE' => "NOW()",
+				]));
+			}
+		}
+		if (!array_key_exists($idLayer, $conf['layer'])) {
+			throw new Exception("Layer id {$idLayer} not exists in schema");
+		}
+		$layConf = $conf['layer'][$idLayer];
+		$layIdType = array_search($koszt, $layConf['type']);
+		DBG::log("DBG:addTypKosztu \$layIdType({$layIdType})");
+		if (!$layIdType) {
+			$row = [
+				'PARENT_ID' => $idLayer,
+				'ALIAS_ID' => $idType,
+				'TYPE' => "INNE",
+				'DESC' => "TYPE",
+			];
+			DBG::log($row, 'array', "insert into CRM_LISTA_ZASOBOW type: '{$koszt}' under idLayer({$idLayer})");
+			$idType = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', array_merge($row, [
+				'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
+				'A_RECORD_CREATE_DATE' => "NOW()",
+			]));
+			if ($idType > 0) {
+				DB::getPDO()->insert('CRM_LISTA_ZASOBOW_HIST', array_merge($row, [
+					'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
+					'A_RECORD_CREATE_DATE' => "NOW()",
+				]));
+			}
+		}
+		throw new AlertSuccessException("Dodano typ '{$koszt}'");
+	}
+
 }

+ 3 - 117
SE/se-lib/Route/UrlAction/ProjektyKosztyWstepnychRobot.php

@@ -1089,7 +1089,7 @@ SQL_FUN;
 		// $defCennik = [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
 		$cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
 		$workCennik = ProjectKosztorysCennik::getWorkCennik($idProject, $idCompany);
-		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin = false);
+		$data = $this->getKosztorysData($idProject);
 		foreach ($data['summary'] as $idLayer => $layData) {
 			foreach ($layData['data'] as $typeData) {
 				if (!$typeData['idType']) continue;
@@ -1193,7 +1193,7 @@ SQL_FUN;
 		$summaryTypeCost = V::get('sub_costs', array(), $projCosts);
 		$subProjCost = V::get('sub_proj', array(), $projCosts);
 
-		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin);
+		$data = $this->getKosztorysData($idProject, $korespType = '', $idKoresp = 0, $admin);
 		$dataSummary = $data['summary'];
 		$dataSubProj = $data['by_project'];
 		// $dataSubProj = array();
@@ -1404,7 +1404,7 @@ SQL_FUN;
 		$summaryTypeCost = V::get('sub_costs', array(), $projCosts);
 		$subProjCost = V::get('sub_proj', array(), $projCosts);
 
-		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin);
+		$data = $this->getKosztorysData($idProject, $korespType = '', $idKoresp = 0, $admin);
 		$dataSummary = $data['summary'];
 		$dataSubProj = $data['by_project'];
 		// $dataSubProj = array();
@@ -1811,118 +1811,4 @@ SQL_FUN;
 		";
 	}
 
-	public function getKosztorysData($idProject, $idOrder = 0, $admin = 0) {// TODO: before was: ($idProject, $admin = 0)
-		static $_data = null;
-		if (null === $_data) {
-			$idSubProject = $this->getModel($idProject)->getSubProjectIds();
-			$idSubProject[] = $idProject;
-			$_data = $this->fetchData($idSubProject, $idOrder, $admin);
-		}
-		return $_data;
-	}
-
-	public function fetchData($idProject, $idOrder = 0, $admin = 0) {// TODO: before was: ($idProject, $admin = 0)
-		$data = array();
-		$data['summary'] = array();// [ $idType ] = ['type', 'jednostka', 'ilosc']
-		$data['rawDataByType'] = array();
-		if (empty($idProject)) return $data;
-		$schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
-		$conf = $schema['config'];
-		$pdo = DB::getPDO();
-		foreach ($conf['layer'] as $idLayer => $layer) {
-			if (!$layer['tabela_name']) continue;// TODO: throw error in validate
-			if ('ZASOB' == $layer['zasob_type']) {
-			} else if ('ZASOB_ID' == $layer['zasob_type']) {
-			} else {
-				continue;// TODO: validate config error
-			}
-
-			$tblName = $layer['tabela_name'];
-			$sqlIloscField = (!empty($layer['ilosc_field']))? $layer['ilosc_field'] : 'ID';
-			$sqlIlosc = ('SZTUKA' == $layer['jednostka'])? "count(1)" : "sum(t.{$sqlIloscField})";
-			$sqlZasobField = (!empty($layer['zasob_field']))? $layer['zasob_field'] : 'ID';
-			$sqlGroupBy = "group by t.ID_PROJECT" . ((!empty($layer['zasob_field']))? ", t.{$sqlZasobField}" : '');
-			$sqlIdProject = (is_array($idProject))? implode(",", $idProject) : (int)$idProject;
-			$sql = "
-				select t.{$sqlZasobField}
-						, t.ID_PROJECT
-						, {$sqlIlosc} as ilosc
-				from {$tblName} t
-				where t.ID_PROJECT in({$sqlIdProject})
-					and t.the_geom is not null
-				{$sqlGroupBy}
-			";
-			$data['_DBG_sql'][$idLayer] = $sql;
-			$rawLayData = $pdo->fetchAll($sql);
-			$rawLayData = array_filter($rawLayData, function($row) {
-				return ($row['ilosc'] > 0);
-			});
-			foreach ($rawLayData as $idx => &$row) {
-				if ('ZASOB' == $layer['zasob_type']) {
-					$row['type'] = trim($row[$sqlZasobField]);
-					$row['idType'] = array_search($row['type'], $conf['type']);
-				} else if ('ZASOB_ID' == $layer['zasob_type']) {
-					$row['type'] = $layer['zasob_label'];
-					$row['idType'] = (array_key_exists($layer['zasob_id'], $conf['type']))? $layer['zasob_id'] : null;
-				}
-				$row['idLayer'] = $idLayer;
-				unset($row[$sqlZasobField]);
-				$data['rawDataByType'][] = $row;
-			}
-		}
-		//DBG::_(true, true, "data", $data, __CLASS__, __FUNCTION__, __LINE__);
-		//DBG::table("data['rawDataByType']", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
-		if ($admin) {
-			foreach ($data['rawDataByType'] as $row) {
-				$layer = $conf['layer'][$row['idLayer']];
-				if ($row['idType'] <= 0) {
-					UI::alert('warning', "Pomijanie nieznanego oznaczenia '{$row['type']}' w ilości {$row['ilosc']} - warstwa '{$layer['label']}' ({$layer['tabela_name']}), projekt nr {$row['ID_PROJECT']}");
-				}
-			}
-		}
-		$data['rawDataByType'] = array_filter($data['rawDataByType'], function($row) {
-			return ($row['idType'] > 0);
-		});
-		//DBG::table("data['rawDataByType'] - clean", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
-		$data['by_layer'] = array_reduce($data['rawDataByType'], function($result, $row) {
-			$idLayer = $row['idLayer'];
-			$idType = $row['idType'];
-			if (!array_key_exists($idLayer, $result)) $result[$idLayer] = array();
-			if (!array_key_exists($idType, $result[$idLayer])) {
-				$result[$idLayer][$idType] = $row;
-			} else {
-				$result[$idLayer][$idType]['ilosc'] += $row['ilosc'];
-			}
-			return $result;
-		}, array());
-		//DBG::_(true, true, "data['by_layer']", $data['by_layer'], __CLASS__, __FUNCTION__, __LINE__);
-		$data['summary'] = array();
-		foreach ($data['by_layer'] as $idLayer => $iloscByType) {
-			$layData = array();
-			$layData['label'] = $conf['layer'][$idLayer]['label'];
-			$layData['data'] = $iloscByType;
-			foreach ($layData['data'] as &$iloscData) {
-				$iloscData['jednostka'] = $conf['layer'][$idLayer]['jednostka'];
-			}
-			$data['summary'][$idLayer] = $layData;
-		}
-		//DBG::_(true, true, "data['summary']", $data['summary'], __CLASS__, __FUNCTION__, __LINE__);
-
-		$data['by_project'] = array_reduce($data['rawDataByType'], function($result, $row) {
-			$idProj = $row['ID_PROJECT'];
-			$idLayer = $row['idLayer'];
-			$idType = $row['idType'];
-			if (!array_key_exists($idProj, $result)) $result[$idProj] = array();
-			if (!array_key_exists($idLayer, $result[$idProj])) $result[$idProj][$idLayer] = array();
-			if (!array_key_exists($idType, $result[$idProj][$idLayer])) {
-				$result[$idProj][$idLayer][$idType] = $row;
-			} else {
-				$result[$idProj][$idLayer][$idType]['ilosc'] += $row['ilosc'];
-			}
-			return $result;
-		}, array());
-		//DBG::_(true, true, "data['by_project']", $data['by_project'], __CLASS__, __FUNCTION__, __LINE__);
-		return $data;
-	}
-
 }

+ 1 - 138
SE/se-lib/Route/UrlAction/ProjektyOdbiorKosztorys.php

@@ -111,7 +111,7 @@ ALTER TABLE  `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
 		if (null !== $order) {
 			$schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
 			$model = $this->getModel($idProject);
-			$data = $this->getKosztorysData($idProject, $order['ID']);
+			$data = $this->getKosztorysData($idProject, $korespType = 'PROTOK_ODB', $idKoresp = $order['ID']);
 
 			{
 				$idCompany = null;
@@ -228,141 +228,4 @@ ALTER TABLE  `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
 		}
 	}
 
-	public function getKosztorysData($idProject, $idOrder = 0, $admin = 0) {
-		static $_data = null;
-		if (null === $_data) {
-			$idSubProject = $this->getModel($idProject)->getSubProjectIds();
-			$idSubProject[] = $idProject;
-			$_data = $this->fetchData($idSubProject, $idOrder, $admin);
-		}
-		return $_data;
-	}
-
-	public function fetchData($idProject, $idOrder = 0, $admin = 0) {
-		$data = array();
-		$data['summary'] = array();// [ $idType ] = ['type', 'jednostka', 'ilosc']
-		$data['rawDataByType'] = array();
-		if (empty($idProject)) return $data;
-		$schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
-		$conf = $schema['config'];
-		foreach ($conf['layer'] as $idLayer => $layer) {
-			if (!$layer['tabela_name']) continue;// TODO: throw error in validate
-			if ('ZASOB' == $layer['zasob_type']) {
-			} else if ('ZASOB_ID' == $layer['zasob_type']) {
-			} else if ('ID_ZASOB' == $layer['zasob_type']) {
-			} else {
-				continue;// TODO: validate config error
-			}
-
-			$tblName = $layer['tabela_name'];
-			$sqlIloscField = (!empty($layer['ilosc_field']))? $layer['ilosc_field'] : 'ID';
-			$sqlIlosc = ('SZTUKA' == $layer['jednostka'])? "count(1)" : "sum(t.{$sqlIloscField})";
-			$sqlZasobField = (!empty($layer['zasob_field']))? $layer['zasob_field'] : 'ID';
-			$sqlGroupBy = "group by t.ID_PROJECT" . ((!empty($layer['zasob_field']))? ", t.{$sqlZasobField}" : '');
-			$sqlIdProject = (is_array($idProject))? implode(",", $idProject) : (int)$idProject;
-			$sql = "
-				select t.{$sqlZasobField}
-						, t.ID_PROJECT
-						, {$sqlIlosc} as ilosc
-						, count(1) as ilosc_sztuk
-				from {$tblName} t
-				where t.ID_PROJECT in({$sqlIdProject})
-					and t.the_geom is not null
-				-- WHERE
-				{$sqlGroupBy}
-			";
-			$data['_DBG_sql'][$idLayer] = $sql;
-			try {
-				if ($idOrder > 0) {
-					$sqlWithOrder = str_replace("-- WHERE", "and t.ID_KORESP_PROTOK_ODB = '{$idOrder}'", $sql);
-					$data['_DBG_sql_idOrder'][$idLayer] = $sqlWithOrder;
-					$rawLayData = DB::getPDO()->fetchAll($sqlWithOrder);
-				}
-			} catch (Exception $e) {
-				UI::alert('danger', "Error: " .  $e->getMessage());
-				if (1 != V::get('_print', '', $_GET)) UI::alert('danger', "Brak pola `ID_KORESP_PROTOK_ODB` w tabeli `$tblName`");
-				$rawLayData = DB::getPDO()->fetchAll($sql);
-			}
-			$rawLayData = array_filter($rawLayData, function($row) {
-				return ($row['ilosc'] > 0);
-			});
-			foreach ($rawLayData as $idx => &$row) {
-				if ('ZASOB' == $layer['zasob_type']) {
-					$row['type'] = trim($row[$sqlZasobField]);
-					$row['idType'] = array_search($row['type'], $conf['type']);
-				} else if ('ZASOB_ID' == $layer['zasob_type']) {
-					$row['type'] = $layer['zasob_label'];
-					$row['idType'] = (array_key_exists($layer['zasob_id'], $conf['type']))? $layer['zasob_id'] : null;
-				} else if ('ID_ZASOB' == $layer['zasob_type']) {
-					$row['type'] = (array_key_exists($row[$sqlZasobField], $conf['type']))? $conf['type'][ $row[$sqlZasobField] ] : null;
-					$row['idType'] = $row[$sqlZasobField];
-				}
-				$idType = $row['idType'];
-				$row['idLayer'] = $idLayer;
-
-				$row['jednostka'] = $conf['layer'][$idLayer]['jednostka'];
-				if (!empty($conf['layer'][$idLayer]['jednostka_zasob_id'][$idType])) {
-					$row['jednostka'] = $conf['layer'][$idLayer]['jednostka_zasob_id'][$idType];
-					if ('SZTUKA' == $row['jednostka']) {
-						$row['ilosc'] = $row['ilosc_sztuk'];
-					}
-				}
-				unset($row['ilosc_sztuk']);
-
-				unset($row[$sqlZasobField]);
-				$data['rawDataByType'][] = $row;
-			}
-		}
-		//DBG::_(true, true, "data", $data, __CLASS__, __FUNCTION__, __LINE__);
-		//DBG::table("data['rawDataByType']", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
-		if ($admin) {
-			foreach ($data['rawDataByType'] as $row) {
-				$layer = $conf['layer'][$row['idLayer']];
-				if ($row['idType'] <= 0) {
-					UI::alert('warning', "Pomijanie nieznanego oznaczenia '{$row['type']}' w ilości {$row['ilosc']} - warstwa '{$layer['label']}' ({$layer['tabela_name']}), projekt nr {$row['ID_PROJECT']}");
-				}
-			}
-		}
-		$data['rawDataByType'] = array_filter($data['rawDataByType'], function($row) {
-			return ($row['idType'] > 0);
-		});
-		//DBG::table("data['rawDataByType'] - clean", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
-		$data['by_layer'] = array_reduce($data['rawDataByType'], function($result, $row) {
-			$idLayer = $row['idLayer'];
-			$idType = $row['idType'];
-			if (!array_key_exists($idLayer, $result)) $result[$idLayer] = array();
-			if (!array_key_exists($idType, $result[$idLayer])) {
-				$result[$idLayer][$idType] = $row;
-			} else {
-				$result[$idLayer][$idType]['ilosc'] += $row['ilosc'];
-			}
-			return $result;
-		}, array());
-		//DBG::_(true, true, "data['by_layer']", $data['by_layer'], __CLASS__, __FUNCTION__, __LINE__);
-		$data['summary'] = array();
-		foreach ($data['by_layer'] as $idLayer => $iloscByType) {
-			$layData = array();
-			$layData['label'] = $conf['layer'][$idLayer]['label'];
-			$layData['data'] = $iloscByType;
-			$data['summary'][$idLayer] = $layData;
-		}
-		//DBG::_(true, true, "data['summary']", $data['summary'], __CLASS__, __FUNCTION__, __LINE__);
-
-		$data['by_project'] = array_reduce($data['rawDataByType'], function($result, $row) {
-			$idProj = $row['ID_PROJECT'];
-			$idLayer = $row['idLayer'];
-			$idType = $row['idType'];
-			if (!array_key_exists($idProj, $result)) $result[$idProj] = array();
-			if (!array_key_exists($idLayer, $result[$idProj])) $result[$idProj][$idLayer] = array();
-			if (!array_key_exists($idType, $result[$idProj][$idLayer])) {
-				$result[$idProj][$idLayer][$idType] = $row;
-			} else {
-				$result[$idProj][$idLayer][$idType]['ilosc'] += $row['ilosc'];
-			}
-			return $result;
-		}, array());
-		//DBG::_(true, true, "data['by_project']", $data['by_project'], __CLASS__, __FUNCTION__, __LINE__);
-		return $data;
-	}
-
 }

+ 1 - 0
SE/se-lib/Route/UrlAction/ProjektyPrzedmiarKosztorys.php

@@ -39,6 +39,7 @@ class Route_UrlAction_ProjektyPrzedmiarKosztorys extends Route_ProjektyKosztorys
 		$model = $this->getModel($idProject);
 		//DBG::table("subProjectList", $model->subProjectList, __CLASS__, __FUNCTION__, __LINE__);
 		$schema = ProjectKosztorysSchema::getSchema();
+		DBG::log($schema, 'array', "\$schema");
 
 		$projCosts = $this->getProjectCostByCennik($idProject, $idCompany);
 		//DBG::_(true, true, "projCosts", $projCosts, __CLASS__, __FUNCTION__, __LINE__);

+ 124 - 167
SE/se-lib/Route/UrlAction/ProjektyZamowieniaKosztorys.php

@@ -21,6 +21,7 @@ class Route_UrlAction_ProjektyZamowieniaKosztorys extends Route_ProjektyKosztory
 			$idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
 			if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
 			$this->panel($idProject);
+			$this->execPostTasks();
 			$this->zamowienia($idProject);
 		} catch (Exception $e) {
 			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
@@ -94,7 +95,7 @@ ALTER TABLE  `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
 				UI::tag('input', ['type'=>'hidden', 'name'=>'_route', 'value'=>'UrlAction_ProjektyZamowieniaKosztorys']);
 				UI::tag('input', ['type'=>'hidden', 'name'=>'ID_PROJECT', 'value'=>$idProject]);
 				if (empty($orders)) UI::alert('info', "Brak zamówień w korespondencji dotyczących projektu {$idProject}");
-				else UI::table(['caption'=>"Wybierz zamówienie", 'rows'=>$orders]);
+				else UI::table(['caption'=>"Wybierz zamówienie/zlecenie", 'rows'=>$orders]);
 			UI::endTag('form');
 			UI::tag('hr');
 			if (null != $order) {
@@ -103,61 +104,153 @@ ALTER TABLE  `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
 				$printLink .= "&ID_ORDER={$order['ID']}";
 				$printLink .= "&_print=1";
 				UI::startTag('div', ['style'=>'text-align:right']);
-					UI::tag('a', ['_target'=>'blank', 'href'=>$printLink], '<i class="glyphicon glyphicon-print"></i>'. "Drukuj zamówienie");
+					UI::tag('a', ['_target'=>'blank', 'href'=>$printLink], '<i class="glyphicon glyphicon-print"></i>'. "Drukuj");
 				UI::endTag('div');
 			}
 		}
 
+		DBG::log($order, 'array', '$order');
 		if (null !== $order) {
 			$schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
 			$model = $this->getModel($idProject);
-			$data = $this->getKosztorysData($idProject, $order['ID']);
+			$data = $this->getKosztorysData($idProject, $korespType = 'ZLECENIE', $idKoresp = $order['ID'], $admin = 0, $fetchAllRows = true);
 
 			{
-				$idCompany = null;
-				$admin = false;
-				$companyAdmin = null;
-				$projCosts = null;
-				$hidePrices = true;
-
 				$model = $this->getModel($idProject);
 				//DBG::table("subProjectList", $model->subProjectList, __CLASS__, __FUNCTION__, __LINE__);
 				$schema = ProjectKosztorysSchema::getSchema();
 				// $projCosts = $this->getProjectCostByCennik($idProject, $idCompany);
 				//DBG::_(true, true, "projCosts", $projCosts, __CLASS__, __FUNCTION__, __LINE__);
-				$viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'projCosts', 'hidePrices');
 				UI::startTag('h1', ['style'=>'margin-bottom:1em']);
 					echo "Zamówienie nr {$order['ID']}";
 					UI::tag('small', ['style'=>"display:block"], $order['K_ZAWARTOS']);
 				UI::endTag('h1');
 				UI::setTitleJsTag("Zamówienie nr {$order['ID']} (Kosztorys projektu [{$idProject}])");
 
-				UI::startTag('table', ['class'=>'table']);
-					UI::startTag('tr');
-						UI::tag('th', null, "Nr zamówienia");
-						UI::tag('th', null, $schema['nr']);
-						UI::tag('th', null, $schema['title']);
-						UI::tag('th', null, $schema['ownerName']);
-						// UI::tag('th', ['style'=>'text-align:right'], $schema['cost_total']);
-					UI::endTag('tr');
-					UI::startTag('tr');
-						UI::tag('td', null, $order['ID']);
-						UI::tag('td', null, $model->idProject);
-						UI::tag('td', null, $model->title);
-						UI::tag('td', null, $model->ownerName);
-						// UI::tag('td', ['style'=>'text-align:right'], number_format($projCosts['cost_total'], 2, ',', ' '));
-					UI::endTag('tr');
-				UI::endTag('table');
-				$this->viewLayersData($viewLayerDataArgs);
+				echo UI::h('table', [ 'style' => "width:100%; margin-bottom: 12px" ], [
+					UI::h('tr', [], [
+						UI::h('th', [ 'style' => "padding-bottom: 8px; text-align:center" ], "ZLECENIE WEWNĘTRZNE PRAC BUDOWLANYCH BIALL-NET"),
+						UI::h('th', [], ""),
+						UI::h('th', [ 'style' => "padding-bottom: 8px; text-align:center" ], "PROTOKÓŁ ODBIORU PRAC BUDOWLANYCH BIALL-NET"),
+					]),
+					UI::h('tr', [], [
+						UI::h('td', [ 'style' => "width:44%; padding: 3px 6px; border: 1px solid #ddd; vertical-align:top" ], [
+							UI::h('div', [], "NR KRESPONDENCJI: {$order['ID']}"),
+							UI::h('div', [], "ADRES ZLECENIA: "),
+							UI::h('div', [], "DATA ZLECENIA: "),
+							UI::h('div', [], "WYKONAWCA/Y ZLECENIA: {$order['K_OD_KOGO']}"),
+							UI::h('div', [], "ROZPOCZĘCIE PRAC: "),
+							UI::h('div', [], "ZAKOŃCZENIE PRAC: "),
+							UI::h('div', [], "PRACE ZLECA: {$order['ID']}"),
+							UI::h('div', [], "PRACE PRZYJMUJE: "),
+						]),
+						UI::h('td', [ 'style' => "width:10%" ], [
+						]),
+						UI::h('td', [ 'style' => "width:44%; padding: 3px 6px; border: 1px solid #ddd; vertical-align:top" ], [
+							UI::h('div', [], "NR KRESPONDENCJI: "),
+							UI::h('div', [], "DATA ODBIORU: "),
+							UI::h('div', [], "WYKONAWCA/Y ZLECENIA: "),
+							UI::h('div', [], "ROZPOCZĘCIE PRAC: "),
+							UI::h('div', [], "ZAKOŃCZENIE PRAC: "),
+							UI::h('div', [], "PRACE PRZEKAZUJE: "),
+							UI::h('div', [], "PRACE ODBIERA: "),
+							UI::h('div', [], "UWAGI: <br><br>"),
+						]),
+					]),
+				]);
+
+				$conf = $schema['config'];
+				// [summary] => array(1) {
+				//   [22478] => array(2) {
+				//     [label] => string(14) "Rury osłonowe"
+				//     [data] => array(1) {
+				//       [48415] => array(6) {
+				//         [ID_PROJECT] => string(4) "6906"
+				//         [ilosc] => string(2) "10"
+				//         [type] => string(13) "1xHDPE 40/3,7"
+				//         [idType] => int(48415)
+				//         [idLayer] => int(22478)
+				//         [jednostka] => string(4) "METR"
+				echo UI::h('div', [], array_map(function ($summary, $idLayer) use ($conf, $data) {
+					$rows = $data['summary'][$idLayer]['data'];
+					$layer = $conf['layer'][$idLayer];
+					$cols = [
+						'primaryKey' => "Nr",// string(4) "6906"
+						'ID_PROJECT' => "Nr projektu",// string(4) "6906"
+						'ilosc' => "ilosc",// string(2) "10"
+						'type' => "typ",// string(13) "1xHDPE 40/3,7"
+						// 'idType' => "idType",// int(48415)
+						// 'idLayer' => "idLayer",// int(22478)
+						'jednostka' => "jednostka",// string(4) "METR"
+					];
+					$addCols = [];
+					if ('Rozdzielcza_Kabel_Swiatlowodowy_wsg84' === $layer['tabela_name']) {
+						$addCols['ZapasA'] = "ZapasA";
+						$addCols['ZapasB'] = "ZapasB";
+						$addCols['wlokien_j'] = "wlokien_j";
+					}
+					if (!empty($rows) && !empty($addCols)) {
+						$tableName = $layer['tabela_name'];
+						array_walk($rows, function (&$row, $key) use ($addCols, $tableName) {
+							$sqlCols = implode(", ", array_map(function ($col) { return "t.`{$col}`"; }, array_keys($addCols)));
+							$moreInfo = DB::getPDO()->fetchFirst("
+								select {$sqlCols}
+								from `{$tableName}` as t
+								where ID = :id
+							", [ ':id' => $row['primaryKey'] ]);
+							$row = array_merge($row, $moreInfo);
+						});
+					}
+
+					// $tableName = $layer['tabela_name'];
+					// $cols = [];
+					// if ('Rozdzielcza_rura_oslonowa_magistralna' === $tableName) {
+					// 	$cols = [
+					// 		'ID' => "Nr",
+					// 		'ID_PROJECT' => "Nr projektu",
+					// 		'Dlugosc' => "Długość",
+					// 		'PROJECT_INFO_FULL' => "Nazwa",
+					// 	];
+					// }
+					// if ('Rozdzielcza_koszty_dodatkowe_wsg84' === $tableName) {
+					// 	$cols = [
+					// 		'ID' => "Nr",
+					// 		'ID_PROJECT' => "Nr projektu",
+					// 		'Przeznaczenie' => "Przeznaczenie",
+					// 		'ilosc' => "Ilość",
+					// 		'ilosc' => "Ilość",
+					// 	];
+					// }
+					$allCols = array_merge($cols, $addCols);
+					return UI::h('div', [], [
+						UI::h('table', [ 'class' => "table table-bordered table-condensed", 'style' => "width:auto" ], [
+							UI::h('thead', [], [
+								UI::h('tr', [], [
+									UI::h('td', [ 'colspan' => count($allCols), 'style' => "padding:0 6px; font-size:1.2em; line-height:2em" ], " &mdash; {$summary['label']}"),
+								]),
+								UI::h('tr', [], array_map(function ($label, $fieldName) {
+									return UI::h('th', [ 'style' => "padding:1px 3px" ], $label);
+								}, $allCols, array_keys($allCols)))
+							]),
+							UI::h('tbody', [], array_map(function ($row) use ($allCols) {
+								return UI::h('tr', [], array_map(function ($label, $fieldName) use ($row) {
+									return UI::h('td', [ 'style' => "padding:1px 3px" ], $row[$fieldName]);
+								}, $allCols, array_keys($allCols)));
+							}, $rows)),
+						])
+					]);
+				}, $data['summary'], array_keys($data['summary'])));
+
+				echo UI::h('div', [ 'style' => "border: 1px solid #ddd; padding: 3px 6px 120px 6px" ], "UWAGI - PRACE DODATKOWE:");
 			}
 
-			if (DBG::isActive()) DBG::nicePrint($data, '$data');
+			// if (DBG::isActive()) DBG::nicePrint($data, '$data');
 			// if (DBG::isActive()) DBG::nicePrint($schema, '$schema');
 			// if (DBG::isActive()) DBG::nicePrint($model, '$model');
 		}
 
-		if (DBG::isActive()) UI::tag('hr');
-		if (DBG::isActive()) $this->checkDBData();
+		// if (DBG::isActive()) UI::tag('hr');
+		// if (DBG::isActive()) $this->checkDBData();
 		UI::endContainer();
 	}
 
@@ -198,6 +291,7 @@ ALTER TABLE  `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
 								left join IN7_DZIENNIK_KORESP k on(k.ID = g.ID_KORESP_ZLECENIE)
 						", $key = 'ID_KORESP_ZLECENIE');
 					} catch (Exception $e) {
+						DBG::log($e);
 						if ("SQLSTATE[42S22]: Column not found: 1054 Unknown column 't.ID_KORESP_ZLECENIE' in 'field list'" == $e->getMessage()) {
 							UI::alert('danger', "Brak komórki `ID_KORESP_ZLECENIE` w tabeli `{$layer['tabela_name']}`");
 						} else UI::alert('danger', $e->getMessage());
@@ -228,141 +322,4 @@ ALTER TABLE  `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
 		}
 	}
 
-	public function getKosztorysData($idProject, $idOrder = 0, $admin = 0) {
-		static $_data = null;
-		if (null === $_data) {
-			$idSubProject = $this->getModel($idProject)->getSubProjectIds();
-			$idSubProject[] = $idProject;
-			$_data = $this->fetchData($idSubProject, $idOrder, $admin);
-		}
-		return $_data;
-	}
-
-	public function fetchData($idProject, $idOrder = 0, $admin = 0) {
-		$data = array();
-		$data['summary'] = array();// [ $idType ] = ['type', 'jednostka', 'ilosc']
-		$data['rawDataByType'] = array();
-		if (empty($idProject)) return $data;
-		$schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
-		$conf = $schema['config'];
-		foreach ($conf['layer'] as $idLayer => $layer) {
-			if (!$layer['tabela_name']) continue;// TODO: throw error in validate
-			if ('ZASOB' == $layer['zasob_type']) {
-			} else if ('ZASOB_ID' == $layer['zasob_type']) {
-			} else if ('ID_ZASOB' == $layer['zasob_type']) {
-			} else {
-				continue;// TODO: validate config error
-			}
-
-			$tblName = $layer['tabela_name'];
-			$sqlIloscField = (!empty($layer['ilosc_field']))? $layer['ilosc_field'] : 'ID';
-			$sqlIlosc = ('SZTUKA' == $layer['jednostka'])? "count(1)" : "sum(t.{$sqlIloscField})";
-			$sqlZasobField = (!empty($layer['zasob_field']))? $layer['zasob_field'] : 'ID';
-			$sqlGroupBy = "group by t.ID_PROJECT" . ((!empty($layer['zasob_field']))? ", t.{$sqlZasobField}" : '');
-			$sqlIdProject = (is_array($idProject))? implode(",", $idProject) : (int)$idProject;
-			$sql = "
-				select t.{$sqlZasobField}
-						, t.ID_PROJECT
-						, {$sqlIlosc} as ilosc
-						, count(1) as ilosc_sztuk
-				from {$tblName} t
-				where t.ID_PROJECT in({$sqlIdProject})
-					and t.the_geom is not null
-				-- WHERE
-				{$sqlGroupBy}
-			";
-			$data['_DBG_sql'][$idLayer] = $sql;
-			try {
-				if ($idOrder > 0) {
-					$sqlWithOrder = str_replace("-- WHERE", "and t.ID_KORESP_ZLECENIE = '{$idOrder}'", $sql);
-					$data['_DBG_sql_idOrder'][$idLayer] = $sqlWithOrder;
-					$rawLayData = DB::getPDO()->fetchAll($sqlWithOrder);
-				}
-			} catch (Exception $e) {
-				UI::alert('danger', "Error: " .  $e->getMessage());
-				if (1 != V::get('_print', '', $_GET)) UI::alert('danger', "Brak pola `ID_KORESP_ZLECENIE` w tabeli `$tblName`");
-				$rawLayData = DB::getPDO()->fetchAll($sql);
-			}
-			$rawLayData = array_filter($rawLayData, function($row) {
-				return ($row['ilosc'] > 0);
-			});
-			foreach ($rawLayData as $idx => &$row) {
-				if ('ZASOB' == $layer['zasob_type']) {
-					$row['type'] = trim($row[$sqlZasobField]);
-					$row['idType'] = array_search($row['type'], $conf['type']);
-				} else if ('ZASOB_ID' == $layer['zasob_type']) {
-					$row['type'] = $layer['zasob_label'];
-					$row['idType'] = (array_key_exists($layer['zasob_id'], $conf['type']))? $layer['zasob_id'] : null;
-				} else if ('ID_ZASOB' == $layer['zasob_type']) {
-					$row['type'] = (array_key_exists($row[$sqlZasobField], $conf['type']))? $conf['type'][ $row[$sqlZasobField] ] : null;
-					$row['idType'] = $row[$sqlZasobField];
-				}
-				$idType = $row['idType'];
-				$row['idLayer'] = $idLayer;
-
-				$row['jednostka'] = $conf['layer'][$idLayer]['jednostka'];
-				if (!empty($conf['layer'][$idLayer]['jednostka_zasob_id'][$idType])) {
-					$row['jednostka'] = $conf['layer'][$idLayer]['jednostka_zasob_id'][$idType];
-					if ('SZTUKA' == $row['jednostka']) {
-						$row['ilosc'] = $row['ilosc_sztuk'];
-					}
-				}
-				unset($row['ilosc_sztuk']);
-
-				unset($row[$sqlZasobField]);
-				$data['rawDataByType'][] = $row;
-			}
-		}
-		//DBG::_(true, true, "data", $data, __CLASS__, __FUNCTION__, __LINE__);
-		//DBG::table("data['rawDataByType']", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
-		if ($admin) {
-			foreach ($data['rawDataByType'] as $row) {
-				$layer = $conf['layer'][$row['idLayer']];
-				if ($row['idType'] <= 0) {
-					UI::alert('warning', "Pomijanie nieznanego oznaczenia '{$row['type']}' w ilości {$row['ilosc']} - warstwa '{$layer['label']}' ({$layer['tabela_name']}), projekt nr {$row['ID_PROJECT']}");
-				}
-			}
-		}
-		$data['rawDataByType'] = array_filter($data['rawDataByType'], function($row) {
-			return ($row['idType'] > 0);
-		});
-		//DBG::table("data['rawDataByType'] - clean", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
-		$data['by_layer'] = array_reduce($data['rawDataByType'], function($result, $row) {
-			$idLayer = $row['idLayer'];
-			$idType = $row['idType'];
-			if (!array_key_exists($idLayer, $result)) $result[$idLayer] = array();
-			if (!array_key_exists($idType, $result[$idLayer])) {
-				$result[$idLayer][$idType] = $row;
-			} else {
-				$result[$idLayer][$idType]['ilosc'] += $row['ilosc'];
-			}
-			return $result;
-		}, array());
-		//DBG::_(true, true, "data['by_layer']", $data['by_layer'], __CLASS__, __FUNCTION__, __LINE__);
-		$data['summary'] = array();
-		foreach ($data['by_layer'] as $idLayer => $iloscByType) {
-			$layData = array();
-			$layData['label'] = $conf['layer'][$idLayer]['label'];
-			$layData['data'] = $iloscByType;
-			$data['summary'][$idLayer] = $layData;
-		}
-		//DBG::_(true, true, "data['summary']", $data['summary'], __CLASS__, __FUNCTION__, __LINE__);
-
-		$data['by_project'] = array_reduce($data['rawDataByType'], function($result, $row) {
-			$idProj = $row['ID_PROJECT'];
-			$idLayer = $row['idLayer'];
-			$idType = $row['idType'];
-			if (!array_key_exists($idProj, $result)) $result[$idProj] = array();
-			if (!array_key_exists($idLayer, $result[$idProj])) $result[$idProj][$idLayer] = array();
-			if (!array_key_exists($idType, $result[$idProj][$idLayer])) {
-				$result[$idProj][$idLayer][$idType] = $row;
-			} else {
-				$result[$idProj][$idLayer][$idType]['ilosc'] += $row['ilosc'];
-			}
-			return $result;
-		}, array());
-		//DBG::_(true, true, "data['by_project']", $data['by_project'], __CLASS__, __FUNCTION__, __LINE__);
-		return $data;
-	}
-
 }

+ 1 - 1
SE/se-lib/Route/UrlAction/ProjektyZestawienieSwMikRurKosztorys.php

@@ -74,7 +74,7 @@ class Route_UrlAction_ProjektyZestawienieSwMikRurKosztorys extends Route_Projekt
 		$summaryTypeCost = V::get('sub_costs', array(), $projCosts);
 		$subProjCost = V::get('sub_proj', array(), $projCosts);
 
-		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin);
+		$data = $this->getKosztorysData($idProject, $korespType = '', $idKoresp = 0, $admin);
 		$dataSummary = $data['summary'];
 		$dataSubProj = $data['by_project'];
 		// $dataSubProj = array();