ProjektyKosztorys.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('ProjectKosztorysSchema');
  4. Lib::loadClass('ProjectKosztorysModel');
  5. Lib::loadClass('ProjectKosztorysCennik');
  6. Lib::loadClass('UI');
  7. Lib::loadClass('Response');
  8. Lib::loadClass('Route_ProjektyKosztorysBase');
  9. class Route_UrlAction_ProjektyKosztorys extends Route_ProjektyKosztorysBase {
  10. public $_model = array();
  11. public function defaultAction() {
  12. // TODO: check if user is allowed to run this action
  13. UI::gora();
  14. if (1 != V::get('_print', '', $_GET)) UI::menu();
  15. try {
  16. $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int');
  17. $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');
  18. if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
  19. $this->panel($idProject, $idCompany);
  20. $this->execPostTasks();
  21. if (1 != V::get('_print', '', $_GET)) {
  22. UI::startContainer(['style'=>'text-align:right']);
  23. UI::link('link', "<i class=\"glyphicon glyphicon-print\"></i> Drukuj", Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztorys&ID_PROJECT={$idProject}&_print=1");
  24. UI::endContainer();
  25. }
  26. $this->kosztorys($idProject, $idCompany);
  27. } catch (Exception $e) {
  28. UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
  29. }
  30. UI::dol();
  31. }
  32. public function kosztorys($idProject) {
  33. $idCompany = 0;
  34. $admin = false;
  35. $companyAdmin = false;
  36. $priceEditJs = (1 != V::get('_print', '', $_GET)) ? Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztorys&_task=updateProjektyOfertaAjax&idProject={$idProject}" : false;
  37. $model = $this->getModel($idProject);
  38. //DBG::table("subProjectList", $model->subProjectList, __CLASS__, __FUNCTION__, __LINE__);
  39. $schema = ProjectKosztorysSchema::getSchema($showErrors = true);
  40. $projCosts = $this->getProjectCostByCennik($idProject, $idCompany);
  41. //DBG::_(true, true, "projCosts", $projCosts, __CLASS__, __FUNCTION__, __LINE__);
  42. $viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'projCosts', 'priceEditJs');
  43. UI::setTitleJsTag("Kosztorys wstępny robót telekomunikacyjnych [{$idProject}]");
  44. ?>
  45. <div class="container">
  46. <h1>Kosztorys wstępny robót telekomunikacyjnych</h1>
  47. <table class="table">
  48. <tr>
  49. <th><?php echo $schema['nr']; ?></th>
  50. <th><?php echo $schema['title']; ?></th>
  51. <th><?php echo $schema['ownerName']; ?></th>
  52. <th style="text-align:right"><?php echo $schema['cost_total']; ?></th>
  53. </tr>
  54. <tr>
  55. <td><?php echo $model->idProject; ?></td>
  56. <td><?php echo $model->title; ?></td>
  57. <td><?php echo $model->ownerName; ?></td>
  58. <td style="text-align:right"><?php echo number_format($projCosts['cost_total'], 2, ',', ' '); ?></td>
  59. </tr>
  60. </table>
  61. <?php $this->viewLayersData($viewLayerDataArgs); ?>
  62. </div>
  63. <?php
  64. DBG::_('DBG', '>0', "schema", $schema, __CLASS__, __FUNCTION__, __LINE__);
  65. DBG::_('DBG', '>0', "projCosts", $projCosts, __CLASS__, __FUNCTION__, __LINE__);
  66. }
  67. public function updateProjektyOfertaAjaxAction() {
  68. $args = array();
  69. $args['idProject'] = V::get('idProject', 0, $_GET, 'int');
  70. $args['idType'] = V::get('idType', 0, $_GET, 'int');
  71. $args['unitType'] = V::get('unitType', '', $_GET, 'word');
  72. Response::sendTryCatchJson(array($this, 'updateProjektyOfertaAjax'), $args);
  73. }
  74. public function updateProjektyOfertaAjax($args) {
  75. $idProject = V::get('idProject', 0, $args, 'int');
  76. $idType = V::get('idType', 0, $args, 'int');
  77. $unitType = V::get('unitType', '', $args, 'word');
  78. if (empty($idProject) || $idProject <= 0) throw new Exception("Wrong param idProject");
  79. if (empty($idType) || $idType <= 0) throw new Exception("Wrong param idType");
  80. if (empty($unitType) || !in_array($unitType, array('zasob', 'robocizna'))) throw new Exception("Wrong param unitType");
  81. $response = array();
  82. if (DBG::isActive()) $response['_idProject'] = $idProject;
  83. if (DBG::isActive()) $response['_idType'] = $idType;
  84. $jednostka = '';
  85. if ('robocizna' == $unitType) $jednostka = 'ROBOCIZNA';
  86. else if ('zasob' == $unitType) {
  87. $schema = ProjectKosztorysSchema::getSchema();
  88. foreach ($schema['config']['layer'] as $idLayer => $layData) {
  89. if (array_key_exists($idType, $layData['type'])) $jednostka = $layData['jednostka'];
  90. }
  91. }
  92. if (DBG::isActive()) $response['_unit'] = $jednostka;
  93. $reqJson = Request::getRequestJson();
  94. if (!empty($reqJson)) {
  95. if (!array_key_exists('price', $reqJson)) throw new Exception("Missing param price");
  96. $price = V::get('price', 0, $reqJson, 'float');
  97. DBG::log("updating price '{$price}' for (\$idType: {$idType}, \$idProject: {$idProject}, \$jednostka: {$jednostka})");
  98. ProjectKosztorysCennik::updatePriceProjectCennik($idType, $idProject, $price, $jednostka);
  99. }
  100. $response['id'] = $idType;
  101. $response['unitType'] = $unitType;
  102. $response['label'] = ProjectKosztorysCennik::getTypeLabel($idType);
  103. $response['defaultPrice'] = ProjectKosztorysCennik::getPriceDefaultCennik($idType, 0, $jednostka);
  104. $response['price'] = ProjectKosztorysCennik::getPrice($idType, $idProject, $idCompany = 0, $jednostka);
  105. $response['msg'] = "";
  106. $response['type'] = "success";
  107. DBG::log($response, 'array', "response");
  108. return $response;
  109. }
  110. }