ProjektyKosztorys.php 4.9 KB

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