ProjektyKosztorys.php 4.6 KB

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