|
|
@@ -907,6 +907,9 @@ SQL_FUN;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @returns [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
|
|
|
+ */
|
|
|
public function getDefaultCennik($idCompany = 0) {
|
|
|
$schema = $this->getSchema();
|
|
|
$typeIdList = array_keys($schema['config']['type']);
|
|
|
@@ -942,6 +945,9 @@ SQL_FUN;
|
|
|
return $cennik;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @returns [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
|
|
|
+ */
|
|
|
public function getCennik($idProject, $idCompany = 0) {
|
|
|
$schema = $this->getSchema();
|
|
|
$typeIdList = array_keys($schema['config']['type']);
|
|
|
@@ -1018,35 +1024,108 @@ SQL_FUN;
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @returns [ 'cost_total' => :numeric, 'sub_costs' => [ $id_zasob => 'price' ] ]
|
|
|
+ */
|
|
|
+ public function getProjectCostForCennik($idProject, $idCompany = 0) {
|
|
|
+ $projCost = array();
|
|
|
+ $projCost['cost_total'] = 0;
|
|
|
+ $projCost['sub_costs'] = array();
|
|
|
+
|
|
|
+ $defCennik = $this->getDefaultCennik($idCompany);
|
|
|
+ // $defCennik = [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
|
|
|
+ $cennik = $this->getCennik($idProject, $idCompany);
|
|
|
+ $data = $this->getData($idProject, $admin);
|
|
|
+ foreach ($data as $idLayer => $layData) {
|
|
|
+ foreach ($layData['data'] as $typeData) {
|
|
|
+ if (!$typeData['idType']) continue;
|
|
|
+ $price = (!empty($cennik[$typeData['idType']]['price']))? $cennik[$typeData['idType']]['price'] : 0;
|
|
|
+ $defPrice = (!empty($defCennik[$typeData['idType']]['price']))? $defCennik[$typeData['idType']]['price'] : 0;
|
|
|
+ $cost = ($price > 0)? $price : $defPrice;
|
|
|
+ $cost = $typeData['ilosc'] * $cost;
|
|
|
+ $projCost['sub_costs'][$typeData['idType']] = $cost;
|
|
|
+ $projCost['cost_total'] += $cost;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $projCost;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function kosztorys($idProject) {
|
|
|
+ $schema = $this->getSchema();
|
|
|
+ $data = $this->_fetchKosztorysData($idProject);
|
|
|
+ $projCost = $this->getProjectCostForCennik($idProject, $idCompany = 0);
|
|
|
+?>
|
|
|
+<div class="container">
|
|
|
+ <h1>Kosztorys wstępny robót telekomunikacyjnych</h1>
|
|
|
+ <table class="table">
|
|
|
+ <tr>
|
|
|
+ <th><?php echo $schema['nr']; ?></th>
|
|
|
+ <th><?php echo $schema['title']; ?></th>
|
|
|
+ <th><?php echo $schema['owner_name']; ?></th>
|
|
|
+ <th style="text-align:right"><?php echo $schema['cost_total']; ?></th>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td><?php echo $data['nr']; ?></td>
|
|
|
+ <td><?php echo $data['title']; ?></td>
|
|
|
+ <td><?php echo $data['owner_name']; ?></td>
|
|
|
+ <td style="text-align:right"><?php echo number_format($projCost['cost_total'], 2, ',', ' '); ?></td>
|
|
|
+ </tr>
|
|
|
+ </table>
|
|
|
+ <?php $this->viewLayersData($idProject, $idCompany = 0, $admin = false, $projCost['sub_costs']); ?>
|
|
|
+</div>
|
|
|
+<?php
|
|
|
+ DBG::_('DBG', '>0', "data", $data, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ DBG::_('DBG', '>0', "schema", $schema, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ DBG::_('DBG', '>0', "projCost", $projCost, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ }
|
|
|
+
|
|
|
public function oferta($idProject, $idCompany = 0, $admin = false) {
|
|
|
if ($admin && '1' == V::get('save_offer', '', $_POST)) {
|
|
|
$this->saveOffer($idProject, $idCompany, $_POST, $admin);
|
|
|
}
|
|
|
+ ?>
|
|
|
+<div class="container">
|
|
|
+ <?php if ($admin) : ?>
|
|
|
+ <form action="" method="post">
|
|
|
+ <?php endif; ?>
|
|
|
+ <?php $this->viewLayersData($idProject, $idCompany, $admin); ?>
|
|
|
+ <?php if ($admin) : ?>
|
|
|
+ <?php foreach ($cennik as $item) : ?>
|
|
|
+ <input type="hidden" name="edit_price_id_<?php echo $item['id_zasob']; ?>" value="<?php echo $item['ID']; ?>">
|
|
|
+ <?php endforeach; ?>
|
|
|
+ <input type="hidden" name="save_offer" value="1">
|
|
|
+ <hr><input class="btn btn-primary" type="submit" value="Zapisz ofertę">
|
|
|
+ </form>
|
|
|
+ <?php endif; ?>
|
|
|
+</div>
|
|
|
+<?php
|
|
|
+ }
|
|
|
+
|
|
|
+ public function viewLayersData($idProject, $idCompany = 0, $admin = false, $projSubCost = array()) {
|
|
|
$schema = $this->getSchema();
|
|
|
$conf = $schema['config'];
|
|
|
DBG::_('DBG', '>1', "conf", $conf, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
|
- $data = $this->fetchData($idProject, $admin);
|
|
|
+ $data = $this->getData($idProject, $admin);
|
|
|
DBG::_('DBG', '>1', "data", $data, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
|
$defCennik = $this->getDefaultCennik($idCompany);
|
|
|
$cennik = $this->getCennik($idProject, $idCompany);
|
|
|
?>
|
|
|
-<div class="container">
|
|
|
- <?php if ($admin) : ?>
|
|
|
- <form action="" method="post">
|
|
|
- <?php endif; ?>
|
|
|
<?php foreach ($data as $idLayer => $layData) : ?>
|
|
|
<h4 style="padding:0 6px"><?php echo $layData['label']; ?></h4>
|
|
|
<table class="tabel table-bordered" style="width:100%">
|
|
|
<tbody>
|
|
|
<tr>
|
|
|
<th style="padding:0 6px">typ</th>
|
|
|
- <th style="padding:0 6px">ilość</th>
|
|
|
- <th style="padding:0 6px">jednotka miary</th>
|
|
|
- <th style="padding:0 6px">cena jednostkowa</th>
|
|
|
+ <th style="padding:0 6px; text-align:right">ilość</th>
|
|
|
+ <th style="padding:0 6px; text-align:right">jednotka miary</th>
|
|
|
+ <th style="padding:0 6px; text-align:right">cena jednostkowa</th>
|
|
|
<?php if ($admin) : ?>
|
|
|
- <th style="padding:0 6px">cena jednostkowa (domyślna)</th>
|
|
|
+ <th style="padding:0 6px; text-align:right">cena jednostkowa (domyślna)</th>
|
|
|
+ <?php endif; ?>
|
|
|
+ <?php if (!empty($projSubCost)) : ?>
|
|
|
+ <th style="padding:0 6px; text-align:right">szacowany koszt [zł]</th>
|
|
|
<?php endif; ?>
|
|
|
</tr>
|
|
|
<?php foreach ($layData['data'] as $typeData) : ?>
|
|
|
@@ -1066,15 +1145,24 @@ SQL_FUN;
|
|
|
</td>
|
|
|
</tr>
|
|
|
<?php else : ?>
|
|
|
- <?php $price = (!empty($cennik[$typeData['idType']]['price']))? $cennik[$typeData['idType']]['price'] : 0; ?>
|
|
|
<?php $defPrice = (!empty($defCennik[$typeData['idType']]['price']))? $defCennik[$typeData['idType']]['price'] : 0; ?>
|
|
|
+ <?php $price = (!empty($cennik[$typeData['idType']]['price']))? $cennik[$typeData['idType']]['price'] : $defPrice; ?>
|
|
|
<tr>
|
|
|
<td style="padding:0 6px" title="[<?php echo $typeData['idType']; ?>] <?php echo $typeData['type']; ?>"><?php echo $typeData['type']; ?></td>
|
|
|
- <td style="padding:0 6px"><?php echo $typeData['ilosc']; ?></td>
|
|
|
- <td style="padding:0 6px"><?php echo $typeData['jednostka']; ?></td>
|
|
|
- <td style="padding:3px 6px"><input type="text" class="form-control input-sm" name="price_<?php echo $typeData['idType']; ?>" value="<?php echo $price; ?>"/></td>
|
|
|
+ <td style="padding:0 6px; text-align:right"><?php echo $typeData['ilosc']; ?></td>
|
|
|
+ <td style="padding:0 6px; text-align:right"><?php echo $typeData['jednostka']; ?></td>
|
|
|
+ <td style="padding:3px 6px; text-align:right">
|
|
|
+ <?php if ($admin) : ?>
|
|
|
+ <input type="text" style="text-align:right" class="form-control input-sm" name="price_<?php echo $typeData['idType']; ?>" value="<?php echo $price; ?>"/>
|
|
|
+ <?php else : ?>
|
|
|
+ <?php echo $price; ?>
|
|
|
+ <?php endif; ?>
|
|
|
+ </td>
|
|
|
<?php if ($admin) : ?>
|
|
|
- <td style="padding:3px 6px"><?php echo $defPrice; ?></td>
|
|
|
+ <td style="padding:3px 6px; text-align:right"><?php echo $defPrice; ?></td>
|
|
|
+ <?php endif; ?>
|
|
|
+ <?php if (!empty($projSubCost)) : ?>
|
|
|
+ <td style="padding:3px 6px; text-align:right"><?php echo number_format(V::get($typeData['idType'], 0, $projSubCost), 2, ',', ' '); ?></td>
|
|
|
<?php endif; ?>
|
|
|
</tr>
|
|
|
<?php endif; ?>
|
|
|
@@ -1082,75 +1170,9 @@ SQL_FUN;
|
|
|
</tbody>
|
|
|
</table>
|
|
|
<?php endforeach; ?>
|
|
|
- <?php if ($admin) : ?>
|
|
|
- <?php foreach ($cennik as $item) : ?>
|
|
|
- <input type="hidden" name="edit_price_id_<?php echo $item['id_zasob']; ?>" value="<?php echo $item['ID']; ?>">
|
|
|
- <?php endforeach; ?>
|
|
|
- <input type="hidden" name="save_offer" value="1">
|
|
|
- <hr><input class="btn btn-primary" type="submit" value="Zapisz ofertę">
|
|
|
- </form>
|
|
|
- <?php endif; ?>
|
|
|
-</div>
|
|
|
<?php
|
|
|
}
|
|
|
|
|
|
- public function kosztorys($idProject) {
|
|
|
- $schema = $this->getSchema();
|
|
|
- $data = $this->_fetchKosztorysData($idProject);
|
|
|
-?>
|
|
|
-<div class="container">
|
|
|
- <h1>Kosztorys wstępny robót telekomunikacyjnych</h1>
|
|
|
- <table class="table">
|
|
|
- <tr>
|
|
|
- <th><?php echo $schema['nr']; ?></th>
|
|
|
- <th><?php echo $schema['title']; ?></th>
|
|
|
- <th><?php echo $schema['owner_name']; ?></th>
|
|
|
- <th><?php echo $schema['cost_total']; ?></th>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td><?php echo $data['nr']; ?></td>
|
|
|
- <td><?php echo $data['title']; ?></td>
|
|
|
- <td><?php echo $data['owner_name']; ?></td>
|
|
|
- <td><?php echo $data['cost_total']; ?></td>
|
|
|
- </tr>
|
|
|
- </table>
|
|
|
- <?php foreach ($schema['sub_costs'] as $layerName => $layerConf) : ?>
|
|
|
- <h4><?php echo $layerConf['label']; ?>:</h4>
|
|
|
- <table class="table" style="width:auto">
|
|
|
- <tr>
|
|
|
- <?php foreach ($layerConf['_agr_fields_to_cols'] as $fldName => $label) : ?>
|
|
|
- <th><?php echo $label; ?></th>
|
|
|
- <?php endforeach; ?>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <?php foreach ($layerConf['_agr_fields_to_cols'] as $fldName => $label) : ?>
|
|
|
- <td><?php echo V::get($fldName, '', $data['sub_costs'][$layerName]); ?></td>
|
|
|
- <?php endforeach; ?>
|
|
|
- </tr>
|
|
|
- </table>
|
|
|
- <?php if (!empty($layerConf['sub_costs'])) : ?>
|
|
|
- <table class="table" style="width:auto">
|
|
|
- <tr>
|
|
|
- <?php foreach ($layerConf['sub_costs']['labels'] as $fldName => $label) : ?>
|
|
|
- <th><?php echo $label; ?></th>
|
|
|
- <?php endforeach; ?>
|
|
|
- </tr>
|
|
|
- <?php foreach ($data['sub_costs'][$layerName]['sub_costs'] as $subCost) : ?>
|
|
|
- <tr>
|
|
|
- <?php foreach ($layerConf['sub_costs']['labels'] as $fldName => $label) : ?>
|
|
|
- <td><?php echo V::get($fldName, '', $subCost); ?></td>
|
|
|
- <?php endforeach; ?>
|
|
|
- </tr>
|
|
|
- <?php endforeach; ?>
|
|
|
- </table>
|
|
|
- <?php endif; ?>
|
|
|
- <?php endforeach; ?>
|
|
|
-</div>
|
|
|
- <?php
|
|
|
- DBG::_('DBG', '>0', "data", $data, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- DBG::_('DBG', '>0', "schema", $schema, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- }
|
|
|
-
|
|
|
public function checkGeomDuplicate() {
|
|
|
// TODO: for every schema.layer
|
|
|
$sqlTblName = 'Rozdzielcza_Kabel_Swiatlowodowy_wsg84';
|
|
|
@@ -1374,7 +1396,14 @@ SQL_FUN;
|
|
|
return $_schema;
|
|
|
}
|
|
|
|
|
|
- public function fetchData($idProject, $admin = false) {
|
|
|
+ public function getData($idProject, $admin = 0) {
|
|
|
+ static $_data = null;
|
|
|
+ if (!is_array($_data)) $_data = array();
|
|
|
+ if (!array_key_exists($idProject, $_data)) $_data[$idProject] = $this->fetchData($idProject, $admin);
|
|
|
+ return $_data[$idProject];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fetchData($idProject, $admin = 0) {
|
|
|
$data = array();
|
|
|
$schema = $this->getSchema();
|
|
|
$conf = $schema['config'];
|
|
|
@@ -1412,25 +1441,38 @@ SQL_FUN;
|
|
|
foreach ($rawLayData as $d) {
|
|
|
if ($d['ilosc'] <= 0) continue;
|
|
|
$hasIlosc = true;
|
|
|
+ $idType = 0;
|
|
|
+ $iloscType = null;
|
|
|
DBG::_('DBG', '>1', "layer", $layer, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
DBG::_('DBG', '>1', "conf", $conf, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
if ('ZASOB' == $layer['zasob_type']) {
|
|
|
$iloscType = array();
|
|
|
$iloscType['type'] = trim($d[$sqlZasobField]);
|
|
|
- $iloscType['idType'] = array_search($iloscType['type'], $conf['type']);
|
|
|
+ $idType = array_search($iloscType['type'], $conf['type']);
|
|
|
+ $iloscType['idType'] = $idType;
|
|
|
$iloscType['jednostka'] = $layer['jednostka'];
|
|
|
$iloscType['ilosc'] = $d['ilosc'];
|
|
|
- $iloscByType[] = $iloscType;
|
|
|
} else if ('ZASOB_ID' == $layer['zasob_type']) {
|
|
|
$iloscType = array();
|
|
|
- $iloscType['idType'] = (array_key_exists($layer['zasob_id'], $conf['type']))? $layer['zasob_id'] : null;
|
|
|
$iloscType['type'] = $layer['zasob_label'];
|
|
|
+ $idType = (array_key_exists($layer['zasob_id'], $conf['type']))? $layer['zasob_id'] : null;
|
|
|
+ $iloscType['idType'] = $idType;
|
|
|
$iloscType['jednostka'] = $layer['jednostka'];
|
|
|
$iloscType['ilosc'] = $d['ilosc'];
|
|
|
- $iloscByType[] = $iloscType;
|
|
|
} else {
|
|
|
// TODO: BUG
|
|
|
}
|
|
|
+ if (!empty($iloscType) && $idType) {
|
|
|
+ if (!array_key_exists($idType, $iloscByType)) {
|
|
|
+ $iloscByType[$idType] = $iloscType;
|
|
|
+ } else {
|
|
|
+ DBG::_('DBG', '>1', "merge stats {$idType}", array($iloscByType[$idType], $iloscType), __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ $iloscByType[$idType]['ilosc'] += $iloscType['ilosc'];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DBG::_('DBG', '>1', "skip stats", $d, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ if ($admin) SE_Layout::alert('warning', "Pomijanie nieznanego oznaczenia '{$iloscType['type']}' w ilości {$iloscType['ilosc']}");
|
|
|
+ }
|
|
|
}
|
|
|
if ($hasIlosc) $layData['data'] = $iloscByType;
|
|
|
}
|