| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?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_ProjektyKosztorys extends Route_ProjektyKosztorysBase {
- public $_model = array();
- 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');
- $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
- if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
- $this->panel($idProject, $idCompany);
- 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_ProjektyKosztorys&ID_PROJECT={$idProject}&_print=1");
- UI::endContainer();
- }
- $this->kosztorys($idProject, $idCompany);
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- UI::dol();
- }
- public function kosztorys($idProject) {
- $idCompany = 0;
- $admin = false;
- $companyAdmin = false;
- $priceEditJs = (1 != V::get('_print', '', $_GET)) ? Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztorys&_task=updateProjektyOfertaAjax&idProject={$idProject}" : false;
- $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', 'priceEditJs');
- UI::setTitleJsTag("Kosztorys wstępny robót telekomunikacyjnych [{$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['ownerName']; ?></th>
- <th style="text-align:right"><?php echo $schema['cost_total']; ?></th>
- </tr>
- <tr>
- <td><?php echo $model->idProject; ?></td>
- <td><?php echo $model->title; ?></td>
- <td><?php echo $model->ownerName; ?></td>
- <td style="text-align:right"><?php echo number_format($projCosts['cost_total'], 2, ',', ' '); ?></td>
- </tr>
- </table>
- <?php $this->viewLayersData($viewLayerDataArgs); ?>
- </div>
- <?php
- DBG::_('DBG', '>0', "schema", $schema, __CLASS__, __FUNCTION__, __LINE__);
- DBG::_('DBG', '>0', "projCosts", $projCosts, __CLASS__, __FUNCTION__, __LINE__);
- }
- public function updateProjektyOfertaAjaxAction() {
- $args = array();
- $args['idProject'] = V::get('idProject', 0, $_GET, 'int');
- $args['idType'] = V::get('idType', 0, $_GET, 'int');
- $args['unitType'] = V::get('unitType', '', $_GET, 'word');
- Response::sendTryCatchJson(array($this, 'updateProjektyOfertaAjax'), $args);
- }
- public function updateProjektyOfertaAjax($args) {
- $idProject = V::get('idProject', 0, $args, 'int');
- $idType = V::get('idType', 0, $args, 'int');
- $unitType = V::get('unitType', '', $args, 'word');
- if (empty($idProject) || $idProject <= 0) throw new Exception("Wrong param idProject");
- if (empty($idType) || $idType <= 0) throw new Exception("Wrong param idType");
- if (empty($unitType) || !in_array($unitType, array('zasob', 'robocizna'))) throw new Exception("Wrong param unitType");
- $response = array();
- if (DBG::isActive()) $response['_idProject'] = $idProject;
- if (DBG::isActive()) $response['_idType'] = $idType;
- $jednostka = '';
- if ('robocizna' == $unitType) $jednostka = 'ROBOCIZNA';
- else if ('zasob' == $unitType) {
- $schema = ProjectKosztorysSchema::getSchema();
- foreach ($schema['config']['layer'] as $idLayer => $layData) {
- if (array_key_exists($idType, $layData['type'])) $jednostka = $layData['jednostka'];
- }
- }
- if (DBG::isActive()) $response['_unit'] = $jednostka;
- $reqJson = Request::getRequestJson();
- if (!empty($reqJson)) {
- if (!array_key_exists('price', $reqJson)) throw new Exception("Missing param price");
- $price = V::get('price', 0, $reqJson, 'float');
- ProjectKosztorysCennik::updatePriceProjectCennik($idType, $idProject, $price, $jednostka);
- }
- $response['id'] = $idType;
- $response['unitType'] = $unitType;
- $response['label'] = ProjectKosztorysCennik::getTypeLabel($idType);
- $response['defaultPrice'] = ProjectKosztorysCennik::getPriceDefaultCennik($idType, 0, $jednostka);
- $response['price'] = ProjectKosztorysCennik::getPrice($idType, $idProject, $idCompany = 0, $jednostka);
- $response['msg'] = "";
- $response['type'] = "success";
- return $response;
- }
- }
|