Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

49984 Enhancement of the functionality - total price calculator #845

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1045d7d
49984 total price calculator
dai-eastgate Jun 24, 2024
1b7ad08
49984 refactor code
dai-eastgate Jun 28, 2024
b58a459
49984 update unit test
dai-eastgate Jun 28, 2024
e2681b4
49984 change field key
dai-eastgate Jun 28, 2024
73ecc3b
49984 update unit test
dai-eastgate Jun 28, 2024
cd9801f
49984 refactor code
dai-eastgate Jun 28, 2024
3f66a0c
49984 update chart color
dai-eastgate Jul 1, 2024
eabb309
Merge branch 'master' into 49984-total-price-calculator
fredericalpers Jul 26, 2024
ee83986
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Aug 29, 2024
6034750
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Sep 10, 2024
0d22f4f
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Sep 20, 2024
0b2fed8
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Sep 25, 2024
c11eb3d
Merge branch 'master' into 49984-total-price-calculator
fredericalpers Sep 30, 2024
c7b66a7
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Oct 1, 2024
da97d27
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Oct 10, 2024
6ac9c9c
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Oct 21, 2024
a8e65d5
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Oct 22, 2024
e173965
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Oct 24, 2024
a44d495
Merge branch 'master' into 49984-total-price-calculator
yeneastgate Oct 25, 2024
bfe272c
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Oct 28, 2024
595d24e
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Nov 4, 2024
02827a2
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Nov 11, 2024
24fdd0f
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Nov 13, 2024
15e0d2f
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Nov 20, 2024
80f5bdb
Merge branch 'master' into 49984-total-price-calculator
dai-eastgate Nov 25, 2024
cc75a86
Update default_detail.php
miauzjpg Nov 26, 2024
0a4125d
Update onoffice-style.css
miauzjpg Nov 26, 2024
8ecc2e0
Update onoffice-style.css
miauzjpg Nov 26, 2024
ab5788a
Update output_default_detail.html
miauzjpg Nov 26, 2024
b6cdc16
49984 update unit test
dai-eastgate Nov 27, 2024
8f9ea95
Merge branch 'master' into 49984-total-price-calculator
miauzjpg Dec 5, 2024
d3270bb
added svg chart
miauzjpg Dec 18, 2024
618ec4b
changed unit test
miauzjpg Dec 19, 2024
be51cd3
optimized code
miauzjpg Dec 19, 2024
b41a3a9
optimized colors
miauzjpg Dec 19, 2024
b350f78
deleted unused code
miauzjpg Dec 20, 2024
aa6325c
Merge remote-tracking branch 'origin/master' into 49984-total-price-c…
miauzjpg Dec 20, 2024
41aa486
changed css
miauzjpg Dec 23, 2024
4bc60ae
changed unit test
miauzjpg Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/onoffice_defaultview.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/onoffice_defaultview.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}
}]
});

applyGradientToSegments();

function applyGradientToSegments() {
Expand Down
45 changes: 44 additions & 1 deletion plugin/DataView/DataDetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ class DataDetailView
/** @var int */
const SHOW_MAIN_CONTACT_PERSON = '1';

/** */
const FIELD_TOTAL_COSTS_CALCULATOR = 'show_total_costs_calculator';

/** */
const NOTARY_FEES = 1.5;

/** */
const LAND_REGISTER_ENTRY = 0.5;

/** @var string[] */
private $_fields = [
'objekttitel',
Expand Down Expand Up @@ -246,6 +255,9 @@ class DataDetailView
ImageTypes::PASSPORTPHOTO
];

/** @var bool */
private $_showTotalCostsCalculator = false;

/** @var bool */
private $_showEnergyCertificate = false;

Expand All @@ -265,6 +277,26 @@ class DataDetailView
'calculatedPrice'
];

/** @var string[] */
private $_propertyTransferTax = [
'Baden-Württemberg' => 5,
'Bayern' => 3.5,
'Berlin' => 6,
'Brandenburg' => 6.5,
'Bremen' => 5,
'Hamburg' => 5.5,
'Hessen' => 6,
'Mecklenburg-Vorpommern' => 6,
'Niedersachsen' => 5,
'Nordrhein-Westfalen' => 6.5,
'Rheinland-Pfalz' => 5,
'Saarland' => 6.5,
'Sachsen' => 5.5,
'Sachsen-Anhalt' => 5,
'Schleswig-Holstein' => 6.5,
'Thüringen' => 5
];

/** @var string */
private $_contactPerson = '0';

Expand Down Expand Up @@ -463,7 +495,6 @@ public function getShowEnergyCertificate(): bool
public function setShowEnergyCertificate(bool $showEnergyCertificate)
{ $this->_showEnergyCertificate = $showEnergyCertificate; }


/**
* @return array
*/
Expand All @@ -472,6 +503,18 @@ public function getListFieldsShowPriceOnRequest(): array
return $this->_priceFields;
}

/** @return array */
public function getPropertyTransferTax(): array
{ return $this->_propertyTransferTax; }

/** @return bool */
public function getShowTotalCostsCalculator(): bool
{ return $this->_showTotalCostsCalculator; }

/** @param bool $costsCalculator */
public function setShowTotalCostsCalculator(bool $costsCalculator)
{ $this->_showTotalCostsCalculator = $costsCalculator; }

/** @return array */
public function getContactImageTypes(): array
{ return $this->_contactImageTypes; }
Expand Down
1 change: 1 addition & 0 deletions plugin/DataView/DataDetailViewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function createDetailViewByValues(array $row): DataDetailView
$pDataDetailView->setShowStatus($row['show_status'] ?? false);
$pDataDetailView->setCustomLabels($row[DataDetailView::FIELD_CUSTOM_LABEL] ?? []);
$pDataDetailView->setShowPriceOnRequest($row[DataDetailView::FIELD_PRICE_ON_REQUEST] ?? false);
$pDataDetailView->setShowTotalCostsCalculator($row[DataDetailView::FIELD_TOTAL_COSTS_CALCULATOR] ?? false);
$pDataDetailView->setContactImageTypes($row['contact_image_types'] ?? []);
$pDataDetailView->setShowEnergyCertificate($row['show_energy_certificate'] ?? false);
$pDataDetailView->setContactPerson($row['contact_person'] ?? '0');
Expand Down
92 changes: 92 additions & 0 deletions plugin/DonutChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

/**
*
* Copyright (C) 2017 onOffice GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace onOffice\WPlugin;

use onOffice\WPlugin\EstateList;
/**
*
* @url http://www.onoffice.de
* @copyright 2003-2017, onOffice(R) GmbH
*
*/
class DonutChart
{
private $values;
private $valuesTitle;
private $colors = ['#3F9DE4', '#3ac411', '#9C27B0', '#D81B60', '#FEC800'];

public function __construct(array $values, array $valuesTitle)
{
$this->values = $values;
$this->valuesTitle = $valuesTitle;
}

private function toRadians($angle)
{
return $angle * pi() / 180;
}

private function polarToCartesian($radius, $angle, $subtractGap = false)
{
$adjustedAngle = $this->toRadians($angle - 90);
if ($subtractGap) {
$adjustedAngle -= asin(0 / $radius);
}
$x = 300+ $radius * cos($adjustedAngle);
$y = 210 + $radius * sin($adjustedAngle);

return sprintf('%0.2f,%0.2f', $x, $y);
}

public function generateSVG()
{
$total = array_sum($this->values);
//$total = getTotalCostsData();
$anglePerValue = 360 / $total;
$angleStart = 0;

$svgContent = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewbox=\"0 0 600 400\" width=\"100%\" height=\"100%\">\n";
$svgContent .= "<g style=\"stroke:black;stroke-width:0\">\n";

$counter = 0;
foreach ($this->values as $value) {
$angleDelta = $value * $anglePerValue;
$largeArcFlag = $angleDelta > 180 ? 1 : 0;
$angleEnd = $angleStart + $angleDelta;

$path = [
"M" . $this->polarToCartesian(190, $angleStart),
"L" . $this->polarToCartesian(130, $angleStart),
"A 130,130,0,{$largeArcFlag},1," . $this->polarToCartesian(130, $angleEnd, true),
"L" . $this->polarToCartesian(190, $angleEnd, true),
"A 190,190,0,{$largeArcFlag},0," . $this->polarToCartesian(190, $angleStart)
];

$svgContent .= '<path d="' . implode(' ', $path) . '" class="oo-donut-chart-color'.$counter.'"><title>'.$this->valuesTitle[$counter].'</title></path>' . "\n";
$angleStart = $angleEnd;
$counter++;
}

$svgContent .= "</g>\n</svg>";
return $svgContent;
}
}
53 changes: 53 additions & 0 deletions plugin/EstateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
use onOffice\WPlugin\WP\WPPluginChecker;
use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilderShort;
use onOffice\WPlugin\Field\FieldParkingLot;
use onOffice\WPlugin\Field\CostsCalculator;

class EstateList
implements EstateListBase
Expand Down Expand Up @@ -114,12 +115,16 @@ class EstateList
/** @var Redirector */
private $_redirectIfOldUrl;

/** @var array */
private $_totalCostsData = [];

/** @var FieldsCollection */
private $_pFieldsCollection;

/** @var string */
private $_energyCertificate = '';


/**
* @param DataView $pDataView
* @param EstateListEnvironment $pEnvironment
Expand Down Expand Up @@ -247,6 +252,11 @@ private function loadRecords(int $currentPage)
$estateParametersRaw['data'] []= 'vermarktungsart';
$estateParametersRaw['data'] []= 'preisAufAnfrage';

if ($this->getShowTotalCostsCalculator()) {
$fields = ['kaufpreis', 'aussen_courtage', 'bundesland', 'waehrung'];
$estateParametersRaw['data'] = array_merge($estateParametersRaw['data'], $fields);
}

if ($this->getShowEnergyCertificate()) {
$energyCertificateFields = ['energieausweistyp', 'energyClass'];
$estateParametersRaw['data'] = array_merge($estateParametersRaw['data'], $energyCertificateFields);
Expand Down Expand Up @@ -681,6 +691,15 @@ public function estateIterator($modifier = EstateViewFieldModifierTypes::MODIFIE
$recordModified['vermarktungsstatus'] = $pEstateStatusLabel->getLabel($recordRaw);
}

if ($this->getShowTotalCostsCalculator()) {
$externalCommission = $this->getExternalCommission($recordRaw['aussen_courtage'] ?? '');
$propertyTransferTax = $this->_pDataView->getPropertyTransferTax();
if (!empty((float) $recordRaw['kaufpreis']) && !empty($recordRaw['bundesland']) && $externalCommission !== null) {
$costsCalculator = $this->_pEnvironment->getContainer()->get(CostsCalculator::class);
$this->_totalCostsData = $costsCalculator->getTotalCosts($recordRaw, $propertyTransferTax, $externalCommission);
}
}

if ($modifier === EstateViewFieldModifierTypes::MODIFIER_TYPE_MAP && $this->_pDataView instanceof DataListView) {
$recordModified['showGoogleMap'] = $this->getShowMapConfig();
}
Expand Down Expand Up @@ -717,6 +736,7 @@ public function estateIterator($modifier = EstateViewFieldModifierTypes::MODIFIE
foreach ($priceFields as $priceField) {
$this->displayTextPriceOnRequest($recordModified, $priceField);
}
$this->_totalCostsData = [];
}
}
// do not show priceOnRequest as single Field
Expand All @@ -725,6 +745,27 @@ public function estateIterator($modifier = EstateViewFieldModifierTypes::MODIFIE
return $recordModified;
}

/**
* @param string $externalCommission
* @return mixed
*/
private function getExternalCommission(string $externalCommission)
{
if (preg_match('/(\d+[,]?\d*)\s*%/', $externalCommission, $matches)) {
return floatval(str_replace(',', '.', $matches[1]));
}

return null;
}

/**
* @return array
*/
public function getTotalCostsData(): array
{
return $this->_totalCostsData;
}

/**
* @param ArrayContainerEscape $recordModified
* @param string $field
Expand Down Expand Up @@ -1348,4 +1389,16 @@ public function getListViewId()

return 'estate_detail';
}

/**
* @return bool
*/
public function getShowTotalCostsCalculator(): bool
{
if ($this->_pDataView instanceof DataDetailView) {
return $this->_pDataView->getShowTotalCostsCalculator();
}

return false;
}
}
Loading
Loading