fix dividend view
This commit is contained in:
@@ -110,6 +110,7 @@ class TaxesController extends AbstractController
|
||||
if ($gen) {
|
||||
return $this->render("taxes/show.html.twig", [
|
||||
"taxes" => $tax->takeAllByCurrency(),
|
||||
"empty" => $tax->takeAllByCurrencyEmpty()
|
||||
// "error" => $gen->error
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -43,9 +43,8 @@ class CryptoService extends MasterServices
|
||||
$sum = 0;
|
||||
foreach ($this->transactions as $key => $transaction) {
|
||||
$tax = $transaction['income'] - $transaction['cost'];
|
||||
$taxLoss = 0;
|
||||
$profit = $tax;
|
||||
if ($tax < 0) {
|
||||
$taxLoss = $tax;
|
||||
$tax = 0;
|
||||
} else {
|
||||
$tax = round($tax * 0.19,2);
|
||||
@@ -55,7 +54,7 @@ class CryptoService extends MasterServices
|
||||
// "value" => round($transaction,4),
|
||||
"currency" => "",
|
||||
"tax" => $tax,
|
||||
"taxLoss" => $taxLoss
|
||||
"profit" => $profit
|
||||
];
|
||||
$return[$key] = array_merge($return[$key], $transaction);
|
||||
if ($tax > 0) {
|
||||
@@ -67,5 +66,18 @@ class CryptoService extends MasterServices
|
||||
// dd($return, $this->transactionsError);
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function takeAllByCurrencyEmpty() : array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
foreach ($this->transactions as $key => $transaction) {
|
||||
if ($transaction['income'] === 0) {
|
||||
$return[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
//LML, EXY, AMLT, XRP, XLM, OMG, ETH, LTC
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace App\Twig;
|
||||
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter("price", [$this, 'formatPrice'])
|
||||
];
|
||||
}
|
||||
|
||||
public function formatPrice(float $number, string $currency = "PLN", int $decimal = 2): string
|
||||
{
|
||||
return number_format($number, $decimal, ",", " ")." $currency";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user