|
@@ -0,0 +1,364 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+Lib::loadClass('RouteBase');
|
|
|
|
|
+Lib::loadClass('ProjectKosztorysSchema');
|
|
|
|
|
+Lib::loadClass('ProjectKosztorysModel');
|
|
|
|
|
+Lib::loadClass('ProjectKosztorysCennik');
|
|
|
|
|
+Lib::loadClass('UI');
|
|
|
|
|
+Lib::loadClass('Response');
|
|
|
|
|
+Lib::loadClass('Route_ProjektyKosztorysBase');
|
|
|
|
|
+
|
|
|
|
|
+class Route_UrlAction_ProjektyOdbiorKosztorys extends Route_ProjektyKosztorysBase {
|
|
|
|
|
+
|
|
|
|
|
+ public $_model = array();
|
|
|
|
|
+ public $_ID_ZASOB_ZAMOWIENIE = 24121;
|
|
|
|
|
+
|
|
|
|
|
+ public function defaultAction() {
|
|
|
|
|
+ // TODO: check if user is allowed to run this action
|
|
|
|
|
+ UI::gora();
|
|
|
|
|
+ if (1 != V::get('_print', '', $_GET)) UI::menu();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
|
|
|
|
|
+ if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
|
|
|
|
|
+ $this->panel($idProject);
|
|
|
|
|
+ $this->odbior($idProject);
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ UI::dol();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function odbior($idProject) {
|
|
|
|
|
+ $idProject = (int)$idProject;
|
|
|
|
|
+ if ($idProject <= 0) throw new Exception("Error Processing Request - wrong param id project");
|
|
|
|
|
+ $idOrder = V::get('ID_ORDER', 0, $_REQUEST, 'int');
|
|
|
|
|
+
|
|
|
|
|
+ $sqlTableZlecenia = "IN7_DZIENNIK_KORESP";
|
|
|
|
|
+ // $sqlTableZlecenia = (DBG::isActive()) ? "IN7_DZIENNIK_KORESP__TEST_ZLECENIA" : "IN7_DZIENNIK_KORESP";
|
|
|
|
|
+ // if (DBG::isActive()) {
|
|
|
|
|
+ // UI::startContainer();
|
|
|
|
|
+ // UI::alert('warning', "<b>Uwaga:</b> Zlecenie z testowej tabeli Koresp (IN7_DZIENNIK_KORESP__TEST_ZLECENIA)");
|
|
|
|
|
+ // UI::endContainer();
|
|
|
|
|
+ /*
|
|
|
|
|
+DROP TABLE IF EXISTS IN7_DZIENNIK_KORESP__TEST_ZLECENIA;
|
|
|
|
|
+CREATE TABLE IN7_DZIENNIK_KORESP__TEST_ZLECENIA
|
|
|
|
|
+ select k.ID
|
|
|
|
|
+ , k.ID_PROJECT
|
|
|
|
|
+ , k.A_STATUS
|
|
|
|
|
+ , k.K_DATA_OTRZYM_KORESP
|
|
|
|
|
+ , k.K_DATA_OTRZYMANEJ_KORESP
|
|
|
|
|
+ , k.K_OD_KOGO
|
|
|
|
|
+ , k.OD_KOGO_ADRES
|
|
|
|
|
+ , k.K_ZAWARTOS
|
|
|
|
|
+ , k.CRM_LISTA_ZASOBOW_ID
|
|
|
|
|
+ , k.K_TYP_KORESP
|
|
|
|
|
+ from IN7_DZIENNIK_KORESP k
|
|
|
|
|
+ where k.CRM_LISTA_ZASOBOW_ID = 24121
|
|
|
|
|
+ and k.K_TYP_KORESP in('OUT','WEW') ;
|
|
|
|
|
+ALTER TABLE `IN7_DZIENNIK_KORESP__TEST_ZLECENIA` ADD PRIMARY KEY ( `ID` ) ;
|
|
|
|
|
+ */
|
|
|
|
|
+ // }
|
|
|
|
|
+ $ordersRaw = DB::getPDO()->fetchAllByKey("
|
|
|
|
|
+ select k.ID
|
|
|
|
|
+ , k.ID_PROJECT
|
|
|
|
|
+ , k.A_STATUS
|
|
|
|
|
+ , k.K_DATA_OTRZYM_KORESP
|
|
|
|
|
+ , k.K_DATA_OTRZYMANEJ_KORESP
|
|
|
|
|
+ , k.K_OD_KOGO
|
|
|
|
|
+ , k.OD_KOGO_ADRES
|
|
|
|
|
+ , k.K_ZAWARTOS
|
|
|
|
|
+ from {$sqlTableZlecenia} k
|
|
|
|
|
+ where k.CRM_LISTA_ZASOBOW_ID = {$this->_ID_ZASOB_ZAMOWIENIE}
|
|
|
|
|
+ and k.ID_PROJECT = {$idProject}
|
|
|
|
|
+ and k.K_TYP_KORESP in('OUT','WEW')
|
|
|
|
|
+ ", $key = 'ID');
|
|
|
|
|
+ $orders = array();
|
|
|
|
|
+ foreach ($ordersRaw as $r) {
|
|
|
|
|
+ $item = array();
|
|
|
|
|
+ $chkd = ($r['ID'] == $idOrder) ? ' checked="checked"' : '';
|
|
|
|
|
+ $item['ID'] = '<label style="white-space:nowrap"><input style="margin:0" type="radio" onClick="this.form.submit()" name="ID_ORDER" value="'.$r['ID'].'" '.$chkd.'> '.$r['ID'].'</label>';
|
|
|
|
|
+ $item['Projekt'] = $r['ID_PROJECT'];
|
|
|
|
|
+ $item['Status'] = $r['A_STATUS'];
|
|
|
|
|
+ $item['K_DATA_OTRZYM_KORESP'] = $r['K_DATA_OTRZYM_KORESP'];
|
|
|
|
|
+ $item['K_DATA_OTRZYMANEJ_KORESP'] = $r['K_DATA_OTRZYMANEJ_KORESP'];
|
|
|
|
|
+ $item['K_OD_KOGO'] = $r['K_OD_KOGO'];
|
|
|
|
|
+ $item['OD_KOGO_ADRES'] = $r['OD_KOGO_ADRES'];
|
|
|
|
|
+ $item['K_ZAWARTOS'] = $r['K_ZAWARTOS'];
|
|
|
|
|
+ $orders[] = $item;
|
|
|
|
|
+ }
|
|
|
|
|
+ $order = ($idOrder > 0 && array_key_exists($idOrder, $ordersRaw)) ? $ordersRaw[$idOrder] : null;
|
|
|
|
|
+
|
|
|
|
|
+ UI::startContainer();
|
|
|
|
|
+ if (1 != V::get('_print', '', $_GET)) {
|
|
|
|
|
+ UI::startTag('form', ['action'=>'', 'method'=>'get']);
|
|
|
|
|
+ UI::tag('input', ['type'=>'hidden', 'name'=>'_route', 'value'=>'UrlAction_ProjektyOdbiorKosztorys']);
|
|
|
|
|
+ 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]);
|
|
|
|
|
+ UI::endTag('form');
|
|
|
|
|
+ UI::tag('hr');
|
|
|
|
|
+ if (null != $order) {
|
|
|
|
|
+ $printLink = Request::getPathUri() . "index.php?_route=UrlAction_ProjektyOdbiorKosztorys";
|
|
|
|
|
+ $printLink .= "&ID_PROJECT={$idProject}";
|
|
|
|
|
+ $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::endTag('div');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (null !== $order) {
|
|
|
|
|
+ $schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
|
|
|
|
|
+ $model = $this->getModel($idProject);
|
|
|
|
|
+ $data = $this->getKosztorysData($idProject, $order['ID']);
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ $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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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();
|
|
|
|
|
+ UI::endContainer();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function checkDBData() {
|
|
|
|
|
+ $schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
|
|
|
|
|
+ foreach ($schema['config']['layer'] as $idLayer => $layer) {
|
|
|
|
|
+ // <div class="panel panel-default">
|
|
|
|
|
+ // <div class="panel-heading">Panel heading without title</div>
|
|
|
|
|
+ // <div class="panel-body">
|
|
|
|
|
+ // Panel content
|
|
|
|
|
+ // </div>
|
|
|
|
|
+ // </div>
|
|
|
|
|
+
|
|
|
|
|
+ UI::startTag('div', ['class'=>'panel panel-default']);
|
|
|
|
|
+ UI::startTag('div', ['class'=>'panel-heading']);
|
|
|
|
|
+ echo "Warstwa: {$layer['label']}";
|
|
|
|
|
+ UI::endTag('div');// .panel-heading
|
|
|
|
|
+ UI::startTag('div', ['class'=>'panel-body']);
|
|
|
|
|
+ try {
|
|
|
|
|
+ $rowsByIdOrder = DB::getPDO()->fetchAllByKey("
|
|
|
|
|
+ select g.ID_KORESP_PROTOK_ODB, g.cnt
|
|
|
|
|
+ -- , k.ID
|
|
|
|
|
+ , k.A_STATUS
|
|
|
|
|
+ , k.K_DATA_OTRZYM_KORESP
|
|
|
|
|
+ , k.K_DATA_OTRZYMANEJ_KORESP
|
|
|
|
|
+ , k.K_OD_KOGO
|
|
|
|
|
+ , k.OD_KOGO_ADRES
|
|
|
|
|
+ , k.K_ZAWARTOS
|
|
|
|
|
+ , k.CRM_LISTA_ZASOBOW_ID
|
|
|
|
|
+ , k.ID_PROJECT
|
|
|
|
|
+ , k.K_TYP_KORESP
|
|
|
|
|
+ from (
|
|
|
|
|
+ select t.ID_KORESP_PROTOK_ODB, count(1) as cnt
|
|
|
|
|
+ from {$layer['tabela_name']} t
|
|
|
|
|
+ where t.ID_KORESP_PROTOK_ODB is not null and t.ID_KORESP_PROTOK_ODB > 0
|
|
|
|
|
+ group by t.ID_KORESP_PROTOK_ODB
|
|
|
|
|
+ ) g
|
|
|
|
|
+ left join IN7_DZIENNIK_KORESP k on(k.ID = g.ID_KORESP_PROTOK_ODB)
|
|
|
|
|
+ ", $key = 'ID_KORESP_PROTOK_ODB');
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ if ("SQLSTATE[42S22]: Column not found: 1054 Unknown column 't.ID_KORESP_PROTOK_ODB' in 'field list'" == $e->getMessage()) {
|
|
|
|
|
+ UI::alert('danger', "Brak komórki `ID_KORESP_PROTOK_ODB` w tabeli `{$layer['tabela_name']}`");
|
|
|
|
|
+ } else UI::alert('danger', $e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($rowsByIdOrder)) UI::tag('span', ['class'=>'text-warning'], "Brak wypełnionego pola ID_KORESP_PROTOK_ODB w tej warstwie");
|
|
|
|
|
+ else {
|
|
|
|
|
+ $rowsByIdOrder = array_map(function($r) {
|
|
|
|
|
+ $item = [];
|
|
|
|
|
+ $item['id'] = $r['ID_KORESP_PROTOK_ODB'];
|
|
|
|
|
+ $item['ile'] = $r['cnt'];
|
|
|
|
|
+ $item['K_OD_KOGO'] = $r['K_OD_KOGO'];
|
|
|
|
|
+ $item['OD_KOGO_ADRES'] = $r['OD_KOGO_ADRES'];
|
|
|
|
|
+ $item['K_ZAWARTOS'] = $r['K_ZAWARTOS'];
|
|
|
|
|
+ $item['Zasób?'] = (int)$r['CRM_LISTA_ZASOBOW_ID'];
|
|
|
|
|
+ $item['id Proj.'] = (int)$r['ID_PROJECT'];
|
|
|
|
|
+ $item['typ'] = $r['K_TYP_KORESP'];
|
|
|
|
|
+ $item['daty'] = "{$r['K_DATA_OTRZYM_KORESP']}<br>{$r['K_DATA_OTRZYMANEJ_KORESP']}";
|
|
|
|
|
+ if ($item['Zasób?'] <= 0) $item['Zasób?'] .= '<br><span class="label label-danger" title="Brak numeru zasobu - powinien być 24121">Brak</span>';
|
|
|
|
|
+ else if (24121 != $item['Zasób?']) $item['Zasób?'] .= '<br><span class="label label-danger" title="Błędny numer zasobu - powinien być 24121">Błąd</span>';
|
|
|
|
|
+ if ($item['id Proj.'] <= 0) $item['id Proj.'] .= '<br><span class="label label-danger" title="Brak id projektu">Brak</span>';
|
|
|
|
|
+ if ('OUT' != $item['typ']) $item['typ'] .= '<br><span class="label label-danger" title="Błędny typ korespondencji - powinien być OUT">Błąd</span>';
|
|
|
|
|
+ return $item;
|
|
|
|
|
+ }, $rowsByIdOrder);
|
|
|
|
|
+ UI::table(['caption'=>"Pole ID_KORESP_PROTOK_ODB", 'rows'=>$rowsByIdOrder]);
|
|
|
|
|
+ }
|
|
|
|
|
+ UI::endTag('div');// .panel-body
|
|
|
|
|
+ UI::endTag('div');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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 {
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+ $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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|