Explorar el Código

added override unit in Kosztorys

Piotr Labudda hace 9 años
padre
commit
9d3f72f285

+ 8 - 1
SE/se-lib/ProjectKosztorysSchema.php

@@ -48,6 +48,7 @@ class ProjectKosztorysSchema {
 						$layer['tabela_id'] = $z['a_ID'];
 						$layer['tabela_name'] = $z['a_DESC'];
 						$layer['jednostka'] = '';
+						$layer['jednostka_zasob_id'] = array();
 						$layer['zasob_type'] = '';
 						$layer['zasob_field'] = '';
 						$layer['zasob_id'] = '';
@@ -92,9 +93,15 @@ class ProjectKosztorysSchema {
 							case 'TYPE': {
 								//DBG::_(true, true, "z", $z, __CLASS__, __FUNCTION__, __LINE__);
 								if (empty($z['c_ALIAS_ID'])) throw new Exception("Schema error - brak ALIAS_ID dla typu");
-								if (empty($conf['type'][$z['za_ID']])) ;// TODO: throw exception
+								if (empty($conf['type'][$z['za_ID']])) ;// TODO: throw Exception("Brak typu w conf['type']")
 								$conf['layer'][$z['ID']]['type'][$z['za_ID']] = $z['za_DESC'];
 							} break;
+  						case 'TYPE_SZTUKA': {
+  							//DBG::_(true, true, "z", $z, __CLASS__, __FUNCTION__, __LINE__);
+  							if (empty($z['c_ALIAS_ID'])) throw new Exception("Schema error - brak ALIAS_ID dla typu");
+  							if (empty($conf['type'][$z['za_ID']])) ;// TODO: throw Exception("Brak typu w conf['type']")
+  							$conf['layer'][$z['ID']]['jednostka_zasob_id'][$z['za_ID']] = 'SZTUKA';
+  						} break;
 						}
 					}
 				}

+ 15 - 6
SE/se-lib/Route/ProjektyKosztorysBase.php

@@ -691,7 +691,6 @@ SQL_FUN;
 		if (1 == V::get('_print', '', $_GET)) return;// print mode
 		$task = V::get('_task', '', $_GET);
 
-		//
 		UI::startTag('div', ['class'=>'jumbotron']);
 		UI::startTag('div', ['class'=>'container']);
 			UI::startTag('div');
@@ -1240,7 +1239,7 @@ SQL_FUN;
 						<td style="width:24px"></td>
 						<td style="padding:0 6px" title="[<?php echo $idType; ?>] <?php echo $typeData['type']; ?>"> &ndash; <?php echo $typeData['type']; ?></td>
 						<td style="padding:0 6px; text-align:right"><?php echo $typeData['ilosc']; ?></td>
-						<td style="padding:0 6px; text-align:right"><?php echo ProjectKosztorysSchema::getLayerJednostka($idLayer); ?></td>
+						<td style="padding:0 6px; text-align:right"><?= $typeData['jednostka']; ?></td>
 					<?php if ($showPrices) : ?>
 						<td
 							<?php if ($priceEditJs) : ?>
@@ -1426,7 +1425,7 @@ SQL_FUN;
 									<td style="width:24px"></td>
 									<td style="padding:0 6px" title="[<?php echo $typeData['idType']; ?>] <?php echo $typeData['type']; ?>"> &ndash; <?php echo $typeData['type']; ?></td>
 									<td style="padding:0 6px; text-align:right"><?php echo $typeData['ilosc']; ?></td>
-									<td style="padding:0 6px; text-align:right"><?php echo ProjectKosztorysSchema::getLayerJednostka($idLayer); ?></td>
+									<td style="padding:0 6px; text-align:right"><?= $typeData['jednostka']; ?></td>
 									<?php if ($admin) : ?>
 										<td style="padding:3px 6px; text-align:right">
 											<input type="text" style="text-align:right" class="form-control input-sm" name="price_<?php echo $typeData['idType']; ?>" value="<?php echo $price; ?>"/>
@@ -1585,6 +1584,7 @@ SQL_FUN;
 				select t.{$sqlZasobField}
 						, t.ID_PROJECT
 						, {$sqlIlosc} as ilosc
+						, count(1) as ilosc_sztuk
 				from {$tblName} t
 				where t.ID_PROJECT in({$sqlIdProject})
 					and t.the_geom is not null
@@ -1603,7 +1603,19 @@ SQL_FUN;
 					$row['type'] = $layer['zasob_label'];
 					$row['idType'] = (array_key_exists($layer['zasob_id'], $conf['type']))? $layer['zasob_id'] : null;
 				}
+				$idType = $row['idType'];
 				$row['idLayer'] = $idLayer;
+
+				// TODO: fix $row['jednostka']
+				$row['jednostka'] = $conf['layer'][$idLayer]['jednostka'];
+				if (!empty($conf['layer'][$idLayer]['jednostka_zasob_id'][$idType])) {
+					$row['jednostka'] = $conf['layer'][$idLayer]['jednostka_zasob_id'][$idType];
+					if ('SZTUKA' == $row['jednostka']) {
+						$row['ilosc'] = $row['ilosc_sztuk'];
+					}
+				}
+				unset($row['ilosc_sztuk']);
+
 				unset($row[$sqlZasobField]);
 				$data['rawDataByType'][] = $row;
 			}
@@ -1639,9 +1651,6 @@ SQL_FUN;
 			$layData = array();
 			$layData['label'] = $conf['layer'][$idLayer]['label'];
 			$layData['data'] = $iloscByType;
-			foreach ($layData['data'] as &$iloscData) {
-				$iloscData['jednostka'] = $conf['layer'][$idLayer]['jednostka'];
-			}
 			$data['summary'][$idLayer] = $layData;
 		}
 		//DBG::_(true, true, "data['summary']", $data['summary'], __CLASS__, __FUNCTION__, __LINE__);

+ 1 - 1
SE/se-lib/Route/UrlAction/ProjektyKosztorys.php

@@ -38,7 +38,7 @@ class Route_UrlAction_ProjektyKosztorys extends Route_ProjektyKosztorysBase {
 		$idCompany = 0;
 		$admin = false;
 		$companyAdmin = false;
-		$priceEditJs = (1 != V::get('_print', '', $_GET)) ? Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=updateProjektyOfertaAjax&idProject={$idProject}" : 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();

+ 3 - 46
SE/se-lib/Route/UrlAction/ProjektyKosztyWstepnychRobot.php

@@ -1505,7 +1505,7 @@ SQL_FUN;
 						<td
 							<?php if ($priceEditJs) : ?>
 								<?php
-									$updateProjektyOferta = Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=updateProjektyOfertaAjax&idProject={$idProject}&idType={$idType}&unitType=zasob";
+									$updateProjektyOferta = Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztorys&_task=updateProjektyOfertaAjax&idProject={$idProject}&idType={$idType}&unitType=zasob";
 									$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Kosztorys:updateProjektyOferta', { href: '{$updateProjektyOferta}' })";
 								?>
 								onClick="<?= $onClick; ?>"
@@ -1521,7 +1521,7 @@ SQL_FUN;
 						<td
 							<?php if ($priceEditJs) : ?>
 								<?php
-									$updateProjektyOferta = Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=updateProjektyOfertaAjax&idProject={$idProject}&idType={$idType}&unitType=robocizna";
+									$updateProjektyOferta = Request::getPathUri() . "index.php?_route=UrlAction_ProjektyKosztorys&_task=updateProjektyOfertaAjax&idProject={$idProject}&idType={$idType}&unitType=robocizna";
 									$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Kosztorys:updateProjektyOferta', { href: '{$updateProjektyOferta}' })";
 								?>
 								onClick="<?= $onClick; ?>"
@@ -1718,7 +1718,7 @@ SQL_FUN;
 <script src="static/sweetalert2.min.js"></script>
 <script>
 (function(){
-	var _updateProjektyOfertaSaveLink = '<?= Request::getPathUri(); ?>index.php?_route=UrlAction_ProjektyKosztyWstepnychRobot&_task=updateProjektyOfertaAjax&idProject=<?= $idProject; ?>';
+	var _updateProjektyOfertaSaveLink = '<?= Request::getPathUri(); ?>index.php?_route=UrlAction_ProjektyKosztorys&_task=updateProjektyOfertaAjax&idProject=<?= $idProject; ?>';
 
 	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; ?>
@@ -1802,49 +1802,6 @@ SQL_FUN;
 <?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';