|
|
@@ -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__);
|