Sfoglia il codice sorgente

updated Kosztorysy - fixed post task and additional columns in Zamowienie

Piotr Labudda 8 anni fa
parent
commit
3b8430cc3b

+ 25 - 10
SE/se-lib/Route/ProjektyKosztorysBase.php

@@ -1557,10 +1557,10 @@ SQL_FUN;
 
 			$tblName = $layer['tabela_name'];
 			$sqlIloscField = (!empty($layer['ilosc_field']))? $layer['ilosc_field'] : 'ID';
-			$sqlIlosc = ('SZTUKA' == $layer['jednostka'])? "count(1)" : "sum(t.{$sqlIloscField})";
+			$sqlIlosc = (!empty($layer['ilosc_field'])) ? "sum(t.{$sqlIloscField})" : "count(1)";
 			$sqlZasobField = (!empty($layer['zasob_field']))? $layer['zasob_field'] : 'ID';
 			$sqlGroupBy = "group by t.ID_PROJECT" . ((!empty($layer['zasob_field']))? ", t.{$sqlZasobField}" : '');
-			if ($fetchAllRows) $sqlGroupBy = "";
+			if ($fetchAllRows) $sqlGroupBy = "group by t.ID";
 			$sqlIdProject = (is_array($idProject))? implode(",", $idProject) : (int)$idProject;
 			$cols = [
 				"t.{$sqlZasobField}",
@@ -1568,7 +1568,11 @@ SQL_FUN;
 				"{$sqlIlosc} as ilosc",
 				"count(1) as ilosc_sztuk",
 			];
-			if ($fetchAllRows) array_unshift($cols, "t.ID as primaryKey");
+			// if ($fetchAllRows) array_unshift($cols, "t.ID as primaryKey"); // DBG
+			if ($fetchAllRows && 'Rozdzielcza_Kabel_Swiatlowodowy_wsg84' === $layer['tabela_name']) { // TODO: to config - additional columns
+				$cols[] = "sum(t.ZapasA) as Suma_ZapasA";
+				$cols[] = "sum(t.ZapasB) as Suma_ZapasB";
+			}
 			$sqlCols = implode(", ", $cols);
 			$sql = "
 				select {$sqlCols}
@@ -1588,7 +1592,7 @@ SQL_FUN;
 					default: // throw new Exception("Not implemented koresp type '{$korespType}'");
 				}
 			}
-			DBG::log($remoteIdKorespField, 'string', "\$remoteIdKorespField");
+			DBG::log($remoteIdKorespField, 'string', "'{$tblName}' \$remoteIdKorespField");
 			try {
 				if ($remoteIdKorespField) {
 					$sqlWithOrder = str_replace("-- WHERE", "and t.{$remoteIdKorespField} = '{$idKoresp}'", $sql);
@@ -1660,15 +1664,26 @@ SQL_FUN;
 			return ($row['idType'] > 0);
 		});
 		//DBG::table("data['rawDataByType'] - clean", $data['rawDataByType'], __CLASS__, __FUNCTION__, __LINE__);
-		$data['by_layer'] = array_reduce($data['rawDataByType'], function($result, $row) {
+		$data['by_layer'] = array_reduce($data['rawDataByType'], function($result, $row) use ($fetchAllRows, $conf) {
 			$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'];
-			}
+			// TODO: if $dontGroupByZasobType then $result[$idLayer][] = $row;
+			// if ($fetchAllRows) {
+			// 	$result[$idLayer][] = $row;
+			// } else {
+				if (!array_key_exists($idType, $result[$idLayer])) {
+					$result[$idLayer][$idType] = $row;
+				} else {
+					$result[$idLayer][$idType]['ilosc'] += $row['ilosc'];
+					// TODO: sum ZapasA, ZapasB
+					$layer = $conf['layer'][$idLayer];
+					if ($fetchAllRows && 'Rozdzielcza_Kabel_Swiatlowodowy_wsg84' === $layer['tabela_name']) {
+						$result[$idLayer][$idType]['Suma_ZapasA'] += $row['Suma_ZapasA'];
+						$result[$idLayer][$idType]['Suma_ZapasB'] += $row['Suma_ZapasB'];
+					}
+				}
+			// }
 			return $result;
 		}, array());
 		//DBG::_(true, true, "data['by_layer']", $data['by_layer'], __CLASS__, __FUNCTION__, __LINE__);

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

@@ -21,6 +21,7 @@ class Route_UrlAction_ProjektyKosztorys extends Route_ProjektyKosztorysBase {
 			$idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
 			if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
 			$this->panel($idProject, $idCompany);
+			$this->execPostTasks();
 
 			if (1 != V::get('_print', '', $_GET)) {
 				UI::startContainer(['style'=>'text-align:right']);

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

@@ -21,6 +21,7 @@ class Route_UrlAction_ProjektyOdbiorKosztorys extends Route_ProjektyKosztorysBas
 			$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->odbior($idProject);
 		} catch (Exception $e) {
 			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());

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

@@ -20,6 +20,7 @@ class Route_UrlAction_ProjektyOfertaAdminKosztorys extends Route_ProjektyKosztor
 			$idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
 			$idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
 			$this->panel($idProject, $idCompany);
+			$this->execPostTasks();
 
 			if (1 != V::get('_print', '', $_GET)) {
 				UI::startContainer(['style'=>'text-align:right']);

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

@@ -20,6 +20,7 @@ class Route_UrlAction_ProjektyPrzedmiarKosztorys extends Route_ProjektyKosztorys
 			$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();
 			if (1 != V::get('_print', '', $_GET)) {
 				UI::startContainer(['style'=>'text-align:right']);
 				UI::link('link', "<i class=\"glyphicon glyphicon-print\"></i> Drukuj", Request::getPathUri() . "index.php?_route=UrlAction_ProjektyPrzedmiarKosztorys&ID_PROJECT={$idProject}&_print=1");

+ 5 - 18
SE/se-lib/Route/UrlAction/ProjektyZamowieniaKosztorys.php

@@ -171,11 +171,11 @@ ALTER TABLE  `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
 				//         [idType] => int(48415)
 				//         [idLayer] => int(22478)
 				//         [jednostka] => string(4) "METR"
-				echo UI::h('div', [], array_map(function ($summary, $idLayer) use ($conf, $data) {
+				echo UI::h('div', [], array_map(function ($summary, $idLayer) use ($conf, $data, $order) {
 					$rows = $data['summary'][$idLayer]['data'];
 					$layer = $conf['layer'][$idLayer];
 					$cols = [
-						'primaryKey' => "Nr",// string(4) "6906"
+						// 'primaryKey' => "Nr",// string(4) "6906" // grouped data by ID_ZASOB, so primaryKey is not correct
 						'ID_PROJECT' => "Nr projektu",// string(4) "6906"
 						'ilosc' => "ilosc",// string(2) "10"
 						'type' => "typ",// string(13) "1xHDPE 40/3,7"
@@ -184,22 +184,9 @@ ALTER TABLE  `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
 						'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);
-						});
+					if ('Rozdzielcza_Kabel_Swiatlowodowy_wsg84' === $layer['tabela_name']) { // TODO: to config - additional columns
+						$addCols['Suma_ZapasA'] = "Suma_ZapasA";
+						$addCols['Suma_ZapasB'] = "Suma_ZapasB";
 					}
 
 					// $tableName = $layer['tabela_name'];

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

@@ -20,6 +20,7 @@ class Route_UrlAction_ProjektyZestawienieSwMikRurKosztorys extends Route_Projekt
 			$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();
 			if (1 != V::get('_print', '', $_GET)) {
 				UI::startContainer(['style'=>'text-align:right']);
 				UI::link('link', "<i class=\"glyphicon glyphicon-print\"></i> Drukuj", Request::getPathUri() . "index.php?_route=UrlAction_ProjektyZestawienieSwMikRurKosztorys&ID_PROJECT={$idProject}&_print=1");