fix dividend view

This commit is contained in:
2022-04-01 17:32:29 +02:00
parent 7e55e5097f
commit 2c5a40eb28
5 changed files with 141 additions and 20 deletions
@@ -29,14 +29,19 @@ class DividendsSummary
if (count($this->allData) > 0) {
$sum = 0;
foreach ($this->allData as $key => $item) {
$val = round($item, 2);
$val = round($item['tax'], 2);
$sum += $val;
$return[$key] = [
"country" => \Locale::getDisplayRegion("-".$key),
"value" => $val,
"currency" => $this->countryToCurrency[$key]
"income" => $item['incomeAll'],
"currency" => $this->countryToCurrency[$key],
"tax" => $item['tax'],
"destiny_tax" => $item['destiny_tax'],
"tax_cost" => $item['tax_cost'],
"incomesArray" => $item['incomes']
];
}
// >
$return['sum'] = intval(ceil($sum));
}
@@ -56,16 +61,36 @@ class DividendsSummary
foreach ($all as $country => $item) {
/** @var DividendsData $val */
foreach ($item as $val) {
if (!isset($test[$country])) $test[$country] = 0;
$test[$country] += $this->count($val);
if (!isset($test[$country])){
$test[$country] = [
"incomeAll" => 0,
"tax" => 0,
"destiny_tax" => 0,
"tax_cost" => 0,
"incomes" => []
];
}
if (!isset($test[$country]['incomes'][$val->getTax()])) {
$test[$country]['incomes'][$val->getTax()] = 0;
}
$income = round($val->getCount()*$val->getValue()*$this->getRate($val),5);
$test[$country]['incomeAll'] += $income;
$test[$country]['tax'] += round($this->count($val),5);
$test[$country]['destiny_tax'] += round($this->count($val,true),5);
$test[$country]['tax_cost'] += round($this->countTaxPrice($val),5);
$test[$country]['incomes'][$val->getTax()] += $income;
if (!isset($countryToCurrency[$country])) {
$countryToCurrency[$country] = $val->getCurrency();
}
}
}
}
$this->allData = array_merge($this->allData,$test);
foreach ($test as &$item) {
ksort($item['incomes']);
}
unset($item);
$this->allData = $test;
$this->countryToCurrency = array_merge($this->countryToCurrency,$countryToCurrency);
}
@@ -74,14 +99,18 @@ class DividendsSummary
return $this->currencyObj->getRate($data->getCurrency(),$data->getDateTime(),$this->error);
}
private function count(DividendsData $data) : float
private function count(DividendsData $data, bool $fromDestiny = false) : float
{
$value = round($data->getCount()*$data->getValue(),2);
$value = round($data->getCount()*$data->getValue(),5);
$tax = 19;
if ($data->getTax() > 0) {
$tax = 4;
}
$valueTax = round($value * $tax / 100);
if ($fromDestiny) {
$tax = $data->getTax();
}
$valueTax = round($value * $tax / 100,5);
$rate = $this->getRate($data);
if ($rate > 0) {
return $valueTax * $rate;
@@ -90,6 +119,21 @@ class DividendsSummary
return 0;
}
private function countTaxPrice(DividendsData $data) : float
{
if ($data->getTax() == 0) {
return 0;
}
$value = round($data->getCount()*$data->getValue(),5);
$tax = min($data->getTax(),15);
$valueTax = round($value * $tax / 100,5);
$rate = $this->getRate($data);
if ($rate > 0) {
return $valueTax * $rate;
}
return 0;
}
/**
* @param SheetData $sheetData
*/