Ver Fonte

added kosztorys routes

Piotr Labudda há 9 anos atrás
pai
commit
929a096254

+ 37 - 335
SE/se-lib/Route/UrlAction/ProjektyKosztorysBase.php → SE/se-lib/Route/ProjektyKosztorysBase.php

@@ -7,7 +7,7 @@ Lib::loadClass('ProjectKosztorysCennik');
 Lib::loadClass('UI');
 Lib::loadClass('Response');
 
-class Route_UrlAction_ProjektyKosztorysBase extends RouteBase {// TODO: UrlActionBase @see Route_UrlAction
+class Route_ProjektyKosztorysBase extends RouteBase {// TODO: UrlActionBase @see Route_UrlAction
 
 	public $_model = array();
 
@@ -17,37 +17,6 @@ class Route_UrlAction_ProjektyKosztorysBase extends RouteBase {// TODO: UrlActio
 		}
 	}
 
-	public function przedmiarAction() {
-		// 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);
-			$this->przedmiar($idProject, $idCompany);
-		} catch (Exception $e) {
-			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
-		}
-		UI::dol();
-	}
-
-	public function zestawienieSwMikRurAction() {
-		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);
-			$this->zestawienieSwMikRur($idProject, $idCompany);
-		} catch (Exception $e) {
-			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
-		}
-		UI::dol();
-	}
-
 	public function ofertaAdminAction() {
 		// TODO: check if user is allowed to run this action
 		UI::gora();
@@ -721,32 +690,35 @@ SQL_FUN;
 		if (User::get('ADM_ADMIN_LEVEL') > 6 || 'Pracownik' != User::getType()) return;// Only for workers with admin level < 6
 		if (1 == V::get('_print', '', $_GET)) return;// print mode
 		$task = V::get('_task', '', $_GET);
-		?>
-<div class="jumbotron">
-  <div class="container">
-		<div class="row">
-			<div class="col-md-12">
-				<?php if ($idProject > 0) : ?>
-					<a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>">Kosztorys</a>
-					<a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=przedmiar&_print=1" target="_blank">Przedmiar</a>
-					<a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=zestawienieSwMikRur&_print=1" target="_blank">zestawienie (światłowód i mikrorurki)</a>
-					<a class="btn btn-warning" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=oferta">oferta</a>
-					<a class="btn btn-warning" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=ofertaAdmin">oferta (Admin)</a>
-					<a class="btn btn-warning" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_task=ofertaCompany">oferta company</a>
-				<?php endif; ?>
-				<a class="btn btn-default" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=ofertaDefaultAdmin" target="_blank">oferta domyślna (Admin)</a>
-			</div>
-		</div>
-		<div class="row">
-			<div class="col-md-12">
-<?php
-	switch ($task) {
-	case 'oferta': break;
-	case '': ?><a class="btn btn-link" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_print=1" target="_blank"><i class="glyphicon glyphicon-print"></i> Wydruk Kosztorysu</a><?php break;
-	}
+
+		//
+		UI::startTag('div', ['class'=>'jumbotron']);
+		UI::startTag('div', ['class'=>'container']);
+			UI::startTag('div');
+			UI::startTag('div', ['class'=>'btn-group']);
+				if ($idProject > 0) {
+					$activeRoute = V::get('_route', '', $_GET);
+					$route = 'UrlAction_ProjektyKosztorys'; UI::link('default', "Kosztorys", "index.php?_route={$route}&ID_PROJECT={$idProject}", ['className'=>['active'=>($route == $activeRoute)]]);
+					UI::link('default', "Przedmiar", "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT={$idProject}&_task=przedmiar&_print=1");
+					UI::link('default', "Przedmiar", "index.php?_route=UrlAction_ProjektyPrzedmiarKosztorys&ID_PROJECT={$idProject}&_print=1");
+					UI::link('default', "zestawienie (światłowód i mikrorurki)", "index.php?_route=UrlAction_ProjektyZestawienieSwMikRurKosztorys&ID_PROJECT={$idProject}&_print=1");
+					// UI::link('warning', "oferta", "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT={$idProject}&_task=oferta", ['target'=>'_blank']);
+					// UI::link('warning', "oferta (Admin)", "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT={$idProject}&_task=ofertaAdmin", ['target'=>'_blank']);
+					// UI::link('warning', "oferta company", "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT={$idProject}&_task=ofertaCompany", ['target'=>'_blank']);
+					$route = 'UrlAction_ProjektyZamowieniaKosztorys'; UI::link('default', "Zamówienia", "index.php?_route={$route}&ID_PROJECT={$idProject}", ['className'=>['active'=>($route == $activeRoute)]]);
+				}
+				UI::link('default', "oferta domyślna (Admin)", "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=ofertaDefaultAdmin", ['target'=>'_blank']);
+			UI::endTag('div');// .btn-group
+			UI::endTag('div');
+			UI::startTag('div');
+				switch ($task) {
+				case 'oferta': break;
+				case '': ?><a class="btn btn-link" href="index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&ID_PROJECT=<?php echo $idProject; ?>&_print=1" target="_blank"><i class="glyphicon glyphicon-print"></i> Wydruk Kosztorysu</a><?php break;
+				}
+			UI::endTag('div');
+		UI::endTag('div');// .container
+		UI::endTag('div');// .jumbotron
 ?>
-		</div>
-		</div>
 		<br>
 		<?php if ('ofertaAdmin' == $task) : ?>
 			<form action="" method="get" class="form-inline">
@@ -1073,7 +1045,7 @@ SQL_FUN;
 		// $defCennik = [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
 		$cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
 		$workCennik = ProjectKosztorysCennik::getWorkCennik($idProject, $idCompany);
-		$data = $this->getData($idProject, $admin = false);
+		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin = false);
 		foreach ($data['summary'] as $idLayer => $layData) {
 			foreach ($layData['data'] as $typeData) {
 				if (!$typeData['idType']) continue;
@@ -1119,227 +1091,6 @@ SQL_FUN;
 		return $this->_model[$idProject];
 	}
 
-	public function fetchBudynki($idProject) {
-		return DB::getPDO()->fetchAll("
-			select b.*
-			from BUILDINGS b
-			where b.ID_PROJECT = '{$idProject}'
-		");
-	}
-	public function fetchProject($idProject) {
-		$rows = DB::getPDO()->fetchAll("
-			select p.*
-			from IN7_MK_BAZA_DYSTRYBUCJI p
-			where p.ID = '{$idProject}'
-		");
-		return reset($rows);
-	}
-
-	public function zestawienieSwMikRur($idProject) {
-		$idCompany = 0;
-		$admin = false;
-		$companyAdmin = false;
-		$model = $this->getModel($idProject);
-		//DBG::table("subProjectList", $model->subProjectList, __CLASS__, __FUNCTION__, __LINE__);
-		$schema = ProjectKosztorysSchema::getSchema();
-
-		$projCost = $this->getProjectCostByCennik($idProject, $idCompany);
-		//DBG::_(true, true, "projCost", $projCost, __CLASS__, __FUNCTION__, __LINE__);
-		$viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'projCost');
-?>
-<div class="container">
-	<h1></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($projCost['cost_total'], 2, ',', ' '); ?></td>
-		</tr>
-	</table>
-	<?php $args = $viewLayerDataArgs;
-		$idProject = $args['idProject'];
-		$idCompany = V::get('idCompany', 0, $args);
-		$admin = V::get('admin', false, $args);
-		$companyAdmin = V::get('companyAdmin', false, $args);
-		$projCosts = V::get('projCosts', array(), $args);
-
-		$schema = ProjectKosztorysSchema::getSchema();
-		$conf = $schema['config'];
-		DBG::_('DBG', '>1', "conf", $conf, __CLASS__, __FUNCTION__, __LINE__);
-
-		$summaryTypeCost = V::get('sub_costs', array(), $projCosts);
-		$subProjCost = V::get('sub_proj', array(), $projCosts);
-
-		$data = $this->getData($idProject, $admin);
-		$dataSummary = $data['summary'];
-		$dataSubProj = $data['by_project'];
-		// $dataSubProj = array();
-		// foreach ($data['by_project'] as $idSubProj => $subProjData) {
-		// 	if ($idProject != $idSubProj) $dataSubProj[$idSubProj] = $subProjData;
-		// }
-		DBG::_('DBG', '>1', "data", $data, __CLASS__, __FUNCTION__, __LINE__);
-
-		$defCennik = ProjectKosztorysCennik::getDefaultCennik($idCompany);
-		$cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
-		$workCennik = ProjectKosztorysCennik::getWorkCennik($idProject, $idCompany);
-		$additionalCosts = array();
-		$additionalCosts[] = array();
-		$additionalCosts[] = array();
-		$additionalCosts[] = array();
-		$additionalSummaryTypeCost = array();
-?>
-<style type="text/css">
-/* Print Styles */
-@media print {
-	body { font-size:10px; }
-	th, td { font-size:10px; }
-	h1 { font-size:2em; }
-	h2 { font-size:1.6em; }
-	h3 { font-size:1.4em; }
-	h4 { font-size:1.2em; }
-}
-</style>
-<?php if (!empty($dataSubProj)) : ?>
-	<table class="table table-bordered">
-	<thead>
-		<tr>
-			<th>ID PROJ.</th>
-			<th>ID BUDYNKU</th>
-			<th>WŁAŚCICIEL</th>
-			<th>ADRES</th>
-			<th>KONTAKT</th>
-			<th>NR DZIAŁKI</th>
-			<th>DŁ. ŚWIATŁOWODU</th>
-			<th>DŁ. MIKRORURKI DO KLIENTA</th>
-		</tr>
-	</thead>
-	<tbody>
-	<?php foreach ($dataSubProj as $idSubProj => $subProjData) : ?>
-		<?php
-		// 22460 Światłowód
-		// 22467 Mikrokanalizacja do klienta
-		$sumSwiatlo = 0;
-		if (!empty($subProjData[22460])) foreach ($subProjData[22460] as $swiatlo) {
-			$sumSwiatlo += $swiatlo['ilosc'];
-		}
-		$sumMikroRur = 0;
-		if (!empty($subProjData[22467])) foreach ($subProjData[22467] as $mikroRur) {
-			$sumMikroRur += $mikroRur['ilosc'];
-		}
-		?>
-		<?php $budynki = $this->fetchBudynki($idSubProj); ?>
-		<?php $proj = $this->fetchProject($idSubProj); ?>
-		<?php if (empty($budynki)) : ?>
-			<tr>
-				<td><?php echo $idSubProj; ?></td>
-				<td>brak</td>
-				<td><?php echo $proj['IN_NAME']; ?></td>
-				<td><?php echo $proj['M_DISTRIBUTOR_ADDRESS']; ?></td>
-				<td><?php echo $proj['M_DISTRIBUTOR_CONTACT']; ?></td>
-				<td><?php echo $proj['INWDZ__obreby_i_nr_dzialek']; ?></td>
-				<td><?php echo $sumSwiatlo; ?></td>
-				<td><?php echo $sumMikroRur; ?></td>
-			</tr>
-		<?php else : ?>
-			<?php foreach ($budynki as $bud) : ?>
-				<tr>
-					<td><?php echo $idSubProj; ?></td>
-					<td><?php echo $bud['ID']; ?></td>
-					<td><?php echo $proj['IN_NAME']; ?></td>
-					<td><?php echo $proj['M_DISTRIBUTOR_ADDRESS']; ?></td>
-					<td><?php echo $proj['M_DISTRIBUTOR_CONTACT']; ?></td>
-					<td><?php echo $proj['INWDZ__obreby_i_nr_dzialek']; ?></td>
-					<td><?php echo $sumSwiatlo; ?></td>
-					<td><?php echo $sumMikroRur; ?></td>
-				</tr>
-			<?php endforeach; ?>
-		<?php endif; ?>
-	<?php endforeach; ?>
-	</tbody>
-	</table>
-<?php endif; ?>
-<?php
-		DBG::_('DBG', '>0', "schema", $schema, __CLASS__, __FUNCTION__, __LINE__);
-		DBG::_('DBG', '>0', "projCosts", $projCosts, __CLASS__, __FUNCTION__, __LINE__);
-	}
-
-	public function kosztorys($idProject) {
-		$idCompany = 0;
-		$admin = false;
-		$companyAdmin = false;
-		$priceEditJs = (1 != V::get('_print', '', $_GET));
-		$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 przedmiar($idProject) {
-		$idCompany = 0;
-		$admin = false;
-		$companyAdmin = 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__);
-		$hidePrices = true;
-		$viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'hidePrices');
-		UI::setTitleJsTag("Przedmiar robót telekomunikacyjnych [{$idProject}]");
-?>
-<div class="container">
-	<h1>Przedmiar robót telekomunikacyjnych</h1>
-	<table class="table">
-		<tr>
-			<th><?php echo $schema['nr']; ?></th>
-			<th><?php echo $schema['title']; ?></th>
-		</tr>
-		<tr>
-			<td><?php echo $model->idProject; ?></td>
-			<td><?php echo $model->title; ?></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 oferta($args) {
 		$idProject = $args['idProject'];
 		$idCompany = V::get('idCompany', 0, $args);
@@ -1388,7 +1139,7 @@ SQL_FUN;
 		$summaryTypeCost = V::get('sub_costs', array(), $projCosts);
 		$subProjCost = V::get('sub_proj', array(), $projCosts);
 
-		$data = $this->getData($idProject, $admin);
+		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin);
 		$dataSummary = $data['summary'];
 		$dataSubProj = $data['by_project'];
 		// $dataSubProj = array();
@@ -1488,11 +1239,7 @@ SQL_FUN;
 					<?php if ($showPrices) : ?>
 						<td
 							<?php if ($priceEditJs) : ?>
-								<?php
-									$updateProjektyOferta = Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=updateProjektyOfertaAjax&idProject={$idProject}&idType={$idType}&unitType=zasob";
-									$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Kosztorys:updateProjektyOferta', { href: '{$updateProjektyOferta}' })";
-								?>
-								onClick="<?= $onClick; ?>"
+								onClick="return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Kosztorys:updateProjektyOferta', { href: '<?= "{$priceEditJs}&idType={$idType}&unitType=zasob"; ?>' })"
 								class="type_price-<?= $typePrice; ?>"
 							<?php endif; ?>
 							style="padding:3px 6px; text-align:right">
@@ -1504,11 +1251,7 @@ SQL_FUN;
 						</td>
 						<td
 							<?php if ($priceEditJs) : ?>
-								<?php
-									$updateProjektyOferta = Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=updateProjektyOfertaAjax&idProject={$idProject}&idType={$idType}&unitType=robocizna";
-									$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Kosztorys:updateProjektyOferta', { href: '{$updateProjektyOferta}' })";
-								?>
-								onClick="<?= $onClick; ?>"
+								onClick="return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Kosztorys:updateProjektyOferta', { href: '<?= "{$priceEditJs}&idType={$idType}&unitType=robocizna"; ?>' })"
 							<?php endif; ?>
 							style="padding:3px 6px; text-align:right">
 						<?php if ($admin || $companyAdmin) : ?>
@@ -1700,9 +1443,10 @@ SQL_FUN;
 	<?php endif; ?>
 	<link rel="stylesheet" type="text/css" href="static/sweetalert2.min.css">
 <script src="static/sweetalert2.min.js"></script>
+<?php if ($priceEditJs) : ?>
 <script>
 (function(){
-	var _updateProjektyOfertaSaveLink = '<?= Request::getPathUri(); ?>index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=updateProjektyOfertaAjax&idProject=<?= $idProject; ?>';
+	var _updateProjektyOfertaSaveLink = '<?= $priceEditJs ?>';
 
 	jQuery(document).on('p5UIBtnAjax:Kosztorys:updateProjektyOferta:click', function(e, n, payload) {
 		<?php if (DBG::isActive()) : ?>console.log('event p5UIBtnAjax:Kosztorys:updateProjektyOferta:click', n, payload);<?php endif; ?>
@@ -1783,52 +1527,10 @@ SQL_FUN;
 
 })();
 </script>
+<?php endif; ?>
 <?php
 	}
 
-	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);
-		if ('robocizna' != $unitType) $response['defaultPrice'] = ProjectKosztorysCennik::getPriceDefaultCennik($idType);
-		$response['price'] = ProjectKosztorysCennik::getPrice($idType, $idProject, $idCompany = 0, $jednostka);
-		$response['msg'] = "";
-		$response['type'] = "success";
-		return $response;
-	}
-
 	public function checkGeomDuplicate() {
 		// TODO: for every schema.layer
 		$sqlTblName = 'Rozdzielcza_Kabel_Swiatlowodowy_wsg84';
@@ -1838,7 +1540,7 @@ SQL_FUN;
 		";
 	}
 
-	public function getData($idProject, $idOrder = 0, $admin = 0) {// TODO: before was: ($idProject, $admin = 0)
+	public function getKosztorysData($idProject, $idOrder = 0, $admin = 0) {// TODO: before was: ($idProject, $admin = 0)
 		static $_data = null;
 		if (null === $_data) {
 			$idSubProject = $this->getModel($idProject)->getSubProjectIds();

+ 111 - 0
SE/se-lib/Route/UrlAction/ProjektyKosztorys.php

@@ -0,0 +1,111 @@
+<?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);
+			$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_ProjektyKosztyWstepnychRobot&_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);
+		if ('robocizna' != $unitType) $response['defaultPrice'] = ProjectKosztorysCennik::getPriceDefaultCennik($idType);
+		$response['price'] = ProjectKosztorysCennik::getPrice($idType, $idProject, $idCompany = 0, $jednostka);
+		$response['msg'] = "";
+		$response['type'] = "success";
+		return $response;
+	}
+
+}

+ 4 - 4
SE/se-lib/Route/UrlAction/ProjektyKosztyWstepnychRobot.php

@@ -1089,7 +1089,7 @@ SQL_FUN;
 		// $defCennik = [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
 		$cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
 		$workCennik = ProjectKosztorysCennik::getWorkCennik($idProject, $idCompany);
-		$data = $this->getData($idProject, $idOrder = 0, $admin = false);
+		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin = false);
 		foreach ($data['summary'] as $idLayer => $layData) {
 			foreach ($layData['data'] as $typeData) {
 				if (!$typeData['idType']) continue;
@@ -1193,7 +1193,7 @@ SQL_FUN;
 		$summaryTypeCost = V::get('sub_costs', array(), $projCosts);
 		$subProjCost = V::get('sub_proj', array(), $projCosts);
 
-		$data = $this->getData($idProject, $idOrder = 0, $admin);
+		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin);
 		$dataSummary = $data['summary'];
 		$dataSubProj = $data['by_project'];
 		// $dataSubProj = array();
@@ -1404,7 +1404,7 @@ SQL_FUN;
 		$summaryTypeCost = V::get('sub_costs', array(), $projCosts);
 		$subProjCost = V::get('sub_proj', array(), $projCosts);
 
-		$data = $this->getData($idProject, $idOrder = 0, $admin);
+		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin);
 		$dataSummary = $data['summary'];
 		$dataSubProj = $data['by_project'];
 		// $dataSubProj = array();
@@ -1854,7 +1854,7 @@ SQL_FUN;
 		";
 	}
 
-	public function getData($idProject, $idOrder = 0, $admin = 0) {// TODO: before was: ($idProject, $admin = 0)
+	public function getKosztorysData($idProject, $idOrder = 0, $admin = 0) {// TODO: before was: ($idProject, $admin = 0)
 		static $_data = null;
 		if (null === $_data) {
 			$idSubProject = $this->getModel($idProject)->getSubProjectIds();

+ 63 - 0
SE/se-lib/Route/UrlAction/ProjektyPrzedmiarKosztorys.php

@@ -0,0 +1,63 @@
+<?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_ProjektyPrzedmiarKosztorys 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');
+			if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
+			$this->panel($idProject);
+			$this->przedmiar($idProject);
+		} catch (Exception $e) {
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+		}
+		UI::dol();
+	}
+
+	public function przedmiar($idProject) {
+		$idCompany = 0;
+		$admin = false;
+		$companyAdmin = 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__);
+		$hidePrices = true;
+		$viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'hidePrices');
+		UI::setTitleJsTag("Przedmiar robót telekomunikacyjnych [{$idProject}]");
+?>
+<div class="container">
+	<h1>Przedmiar robót telekomunikacyjnych</h1>
+	<table class="table">
+		<tr>
+			<th><?php echo $schema['nr']; ?></th>
+			<th><?php echo $schema['title']; ?></th>
+		</tr>
+		<tr>
+			<td><?php echo $model->idProject; ?></td>
+			<td><?php echo $model->title; ?></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__);
+	}
+
+}

+ 13 - 17
SE/se-lib/Route/UrlAction/ProjektyZamowieniaKosztorys.php

@@ -6,9 +6,9 @@ Lib::loadClass('ProjectKosztorysModel');
 Lib::loadClass('ProjectKosztorysCennik');
 Lib::loadClass('UI');
 Lib::loadClass('Response');
-Lib::loadClass('Route_UrlAction_ProjektyKosztorysBase');
+Lib::loadClass('Route_ProjektyKosztorysBase');
 
-class Route_UrlAction_ProjektyZamowieniaKosztorys extends Route_UrlAction_ProjektyKosztorysBase {// TODO: UrlActionBase @see Route_UrlAction
+class Route_UrlAction_ProjektyZamowieniaKosztorys extends Route_ProjektyKosztorysBase {
 
 	public $_model = array();
 	public $_ID_ZASOB_ZAMOWIENIE = 24121;
@@ -66,10 +66,11 @@ class Route_UrlAction_ProjektyZamowieniaKosztorys extends Route_UrlAction_Projek
 			UI::startTag('form', ['action'=>'', 'method'=>'get']);
 				UI::tag('input', ['type'=>'hidden', 'name'=>'_route', 'value'=>'UrlAction_ProjektyZamowieniaKosztorys']);
 				UI::tag('input', ['type'=>'hidden', 'name'=>'ID_PROJECT', 'value'=>$idProject]);
-				UI::table(['caption'=>"Wybierz zamówienie", 'rows'=>$orders]);
+				if (empty($orders)) UI::alert('info', "Brak zamówień w korespondencji dotyczących projektu {$idProject}");
+				else UI::table(['caption'=>"Wybierz zamówienie", 'rows'=>$orders]);
 			UI::endTag('form');
 			UI::tag('hr');
-			if (null != $order)  {
+			if (null != $order) {
 				$printLink = Request::getPathUri() . "index.php?_route=UrlAction_ProjektyZamowieniaKosztorys";
 				$printLink .= "&ID_PROJECT={$idProject}";
 				$printLink .= "&ID_ORDER={$order['ID']}";
@@ -83,26 +84,21 @@ class Route_UrlAction_ProjektyZamowieniaKosztorys extends Route_UrlAction_Projek
 		if (null !== $order) {
 			$schema = ProjectKosztorysSchema::getSchema();// OK only 'config'
 			$model = $this->getModel($idProject);
-			$data = $this->getData($idProject, $order['ID']);
+			$data = $this->getKosztorysData($idProject, $order['ID']);
 
 			{
-				$idCompany = 0;
+				$idCompany = null;
 				$admin = false;
-				$companyAdmin = false;
-				$priceEditJs = (1 != V::get('_print', '', $_GET));
+				$companyAdmin = null;
+				$projCosts = null;
+				$hidePrices = true;
+
 				$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__);
-				$idCompany = null;
-				$admin = null;
-				$companyAdmin = null;
-				$projCosts = null;
-				$priceEditJs = null;
-				$hidePrices = true;
-				$viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'projCosts', 'priceEditJs', 'hidePrices');
+				$viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'projCosts', 'hidePrices');
 				UI::startTag('h1', ['style'=>'margin-bottom:1em']);
 					echo "Zamówienie nr {$order['ID']}";
 					UI::tag('small', ['style'=>"display:block"], $order['K_ZAWARTOS']);
@@ -205,7 +201,7 @@ class Route_UrlAction_ProjektyZamowieniaKosztorys extends Route_UrlAction_Projek
 		}
 	}
 
-	public function getData($idProject, $idOrder = 0, $admin = 0) {
+	public function getKosztorysData($idProject, $idOrder = 0, $admin = 0) {
 		static $_data = null;
 		if (null === $_data) {
 			$idSubProject = $this->getModel($idProject)->getSubProjectIds();

+ 182 - 0
SE/se-lib/Route/UrlAction/ProjektyZestawienieSwMikRurKosztorys.php

@@ -0,0 +1,182 @@
+<?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_ProjektyZestawienieSwMikRurKosztorys 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');
+			if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");
+			$this->panel($idProject);
+			$this->zestawienieSwMikRur($idProject);
+		} catch (Exception $e) {
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+		}
+		UI::dol();
+	}
+
+	public function zestawienieSwMikRur($idProject) {
+		$idCompany = 0;
+		$admin = false;
+		$companyAdmin = false;
+		$model = $this->getModel($idProject);
+		//DBG::table("subProjectList", $model->subProjectList, __CLASS__, __FUNCTION__, __LINE__);
+		$schema = ProjectKosztorysSchema::getSchema();
+
+		$projCost = $this->getProjectCostByCennik($idProject, $idCompany);
+		//DBG::_(true, true, "projCost", $projCost, __CLASS__, __FUNCTION__, __LINE__);
+		$viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin', 'projCost');
+?>
+<div class="container">
+	<h1></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($projCost['cost_total'], 2, ',', ' '); ?></td>
+		</tr>
+	</table>
+	<?php $args = $viewLayerDataArgs;
+		$idProject = $args['idProject'];
+		$idCompany = V::get('idCompany', 0, $args);
+		$admin = V::get('admin', false, $args);
+		$companyAdmin = V::get('companyAdmin', false, $args);
+		$projCosts = V::get('projCosts', array(), $args);
+
+		$schema = ProjectKosztorysSchema::getSchema();
+		$conf = $schema['config'];
+		DBG::_('DBG', '>1', "conf", $conf, __CLASS__, __FUNCTION__, __LINE__);
+
+		$summaryTypeCost = V::get('sub_costs', array(), $projCosts);
+		$subProjCost = V::get('sub_proj', array(), $projCosts);
+
+		$data = $this->getKosztorysData($idProject, $idOrder = 0, $admin);
+		$dataSummary = $data['summary'];
+		$dataSubProj = $data['by_project'];
+		// $dataSubProj = array();
+		// foreach ($data['by_project'] as $idSubProj => $subProjData) {
+		// 	if ($idProject != $idSubProj) $dataSubProj[$idSubProj] = $subProjData;
+		// }
+		DBG::_('DBG', '>1', "data", $data, __CLASS__, __FUNCTION__, __LINE__);
+
+		$defCennik = ProjectKosztorysCennik::getDefaultCennik($idCompany);
+		$cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany);
+		$workCennik = ProjectKosztorysCennik::getWorkCennik($idProject, $idCompany);
+		$additionalCosts = array();
+		$additionalCosts[] = array();
+		$additionalCosts[] = array();
+		$additionalCosts[] = array();
+		$additionalSummaryTypeCost = array();
+?>
+<style type="text/css">
+/* Print Styles */
+@media print {
+	body { font-size:10px; }
+	th, td { font-size:10px; }
+	h1 { font-size:2em; }
+	h2 { font-size:1.6em; }
+	h3 { font-size:1.4em; }
+	h4 { font-size:1.2em; }
+}
+</style>
+<?php if (!empty($dataSubProj)) : ?>
+	<table class="table table-bordered">
+	<thead>
+		<tr>
+			<th>ID PROJ.</th>
+			<th>ID BUDYNKU</th>
+			<th>WŁAŚCICIEL</th>
+			<th>ADRES</th>
+			<th>KONTAKT</th>
+			<th>NR DZIAŁKI</th>
+			<th>DŁ. ŚWIATŁOWODU</th>
+			<th>DŁ. MIKRORURKI DO KLIENTA</th>
+		</tr>
+	</thead>
+	<tbody>
+	<?php foreach ($dataSubProj as $idSubProj => $subProjData) : ?>
+		<?php
+		// 22460 Światłowód
+		// 22467 Mikrokanalizacja do klienta
+		$sumSwiatlo = 0;
+		if (!empty($subProjData[22460])) foreach ($subProjData[22460] as $swiatlo) {
+			$sumSwiatlo += $swiatlo['ilosc'];
+		}
+		$sumMikroRur = 0;
+		if (!empty($subProjData[22467])) foreach ($subProjData[22467] as $mikroRur) {
+			$sumMikroRur += $mikroRur['ilosc'];
+		}
+		?>
+		<?php $budynki = $this->fetchBudynki($idSubProj); ?>
+		<?php $proj = $this->fetchProject($idSubProj); ?>
+		<?php if (empty($budynki)) : ?>
+			<tr>
+				<td><?php echo $idSubProj; ?></td>
+				<td>brak</td>
+				<td><?php echo $proj['IN_NAME']; ?></td>
+				<td><?php echo $proj['M_DISTRIBUTOR_ADDRESS']; ?></td>
+				<td><?php echo $proj['M_DISTRIBUTOR_CONTACT']; ?></td>
+				<td><?php echo $proj['INWDZ__obreby_i_nr_dzialek']; ?></td>
+				<td><?php echo $sumSwiatlo; ?></td>
+				<td><?php echo $sumMikroRur; ?></td>
+			</tr>
+		<?php else : ?>
+			<?php foreach ($budynki as $bud) : ?>
+				<tr>
+					<td><?php echo $idSubProj; ?></td>
+					<td><?php echo $bud['ID']; ?></td>
+					<td><?php echo $proj['IN_NAME']; ?></td>
+					<td><?php echo $proj['M_DISTRIBUTOR_ADDRESS']; ?></td>
+					<td><?php echo $proj['M_DISTRIBUTOR_CONTACT']; ?></td>
+					<td><?php echo $proj['INWDZ__obreby_i_nr_dzialek']; ?></td>
+					<td><?php echo $sumSwiatlo; ?></td>
+					<td><?php echo $sumMikroRur; ?></td>
+				</tr>
+			<?php endforeach; ?>
+		<?php endif; ?>
+	<?php endforeach; ?>
+	</tbody>
+	</table>
+<?php endif; ?>
+<?php
+		DBG::_('DBG', '>0', "schema", $schema, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::_('DBG', '>0', "projCosts", $projCosts, __CLASS__, __FUNCTION__, __LINE__);
+	}
+
+	public function fetchBudynki($idProject) {
+		return DB::getPDO()->fetchAll("
+			select b.*
+			from BUILDINGS b
+			where b.ID_PROJECT = '{$idProject}'
+		");
+	}
+
+	public function fetchProject($idProject) {
+		$rows = DB::getPDO()->fetchAll("
+			select p.*
+			from IN7_MK_BAZA_DYSTRYBUCJI p
+			where p.ID = '{$idProject}'
+		");
+		return reset($rows);
+	}
+
+}

+ 12 - 0
SE/se-lib/UI.php

@@ -191,6 +191,18 @@ class UI {
 		if (is_scalar($childrens)) echo $childrens;
 		self::endTag($tag);
 	}
+	public static function link($type, $content, $href, $attrs = array()) {
+		$attrs['class'] = V::get('class', '', $attrs);
+		$attrs['class'] .= "btn btn-{$type}";
+		if (!empty($attrs['className'])) {
+			foreach ($attrs['className'] as $cls => $bool) {
+				if ($bool) $attrs['class'] .= " {$cls}";
+			}
+			unset($attrs['className']);
+		}
+		$attrs['href'] = $href;
+		UI::tag('a', $attrs, $content);
+	}
 
 	public static function jsAjaxTable($params) {