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";
|
||||
}
|
||||
}
|
||||
@@ -12,26 +12,60 @@
|
||||
<th>L.p.</th>
|
||||
<th>Country</th>
|
||||
<th>Income</th>
|
||||
<th>Cost</th>
|
||||
{% if taxes|first.cost is defined %}
|
||||
<th>Cost</th>
|
||||
{% endif %}
|
||||
{% if taxes|first.destiny_tax is defined %}
|
||||
<th>Origin tax</th>
|
||||
{% endif %}
|
||||
{% if taxes|first.tax_cost is defined %}
|
||||
<th>Deductable tax (15%)</th>
|
||||
{% endif %}
|
||||
{% if taxes|first.profit is defined %}
|
||||
<th>Profit/Loss</th>
|
||||
{% endif %}
|
||||
<th>Tax</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for tax in taxes %}
|
||||
{% if tax.country is defined %}
|
||||
{% set colspan = tax|length %}
|
||||
{% if tax.income > 0 %}
|
||||
<tr class="{% if tax.taxLoss < 0 %}table-danger{% else %}table-success{% endif %}">
|
||||
<tr class="{% if tax.profit is defined and tax.profit < 0 %}table-danger{% else %}table-success{% endif %}">
|
||||
<td>{{ loop.index }}</td>
|
||||
<td>{{ tax.country }}</td>
|
||||
<td>{{ tax.income }}zł</td>
|
||||
<td>{{ tax.cost }}zł</td>
|
||||
<td>{% if tax.taxLoss < 0 %} {{ tax.taxLoss }} {% else %} {{ tax.tax }} zł{% endif %}</td>
|
||||
<td>{{ tax.income|price }}</td>
|
||||
{% if tax.cost is defined %}
|
||||
<td>{{ tax.cost|price }}</td>
|
||||
{% endif %}
|
||||
{% if tax.destiny_tax is defined %}
|
||||
<td>{{ tax.destiny_tax|price }}</td>
|
||||
{% endif %}
|
||||
{% if tax.tax_cost is defined %}
|
||||
<td>{{ tax.tax_cost|price }}</td>
|
||||
{% endif %}
|
||||
{% if tax.profit is defined %}
|
||||
<td>{{ tax.profit|price }}</td>
|
||||
{% endif %}
|
||||
<td>{{ tax.tax|price }}</td>
|
||||
</tr>
|
||||
{% if tax.incomesArray is defined and tax.incomesArray|length > 0 %}
|
||||
{% set colspan = colspan-1 %}
|
||||
{% for incomePerc,value in tax.incomesArray %}
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td></td>
|
||||
<td>{{ incomePerc }}% - {{ value|price }}</td>
|
||||
<td colspan="3"></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<tr class="">
|
||||
<td colspan="4">Summary:</td>
|
||||
<td>{{ tax }}zł</td>
|
||||
<td colspan="{{ colspan-1 }}">Summary:</td>
|
||||
<td>{{ tax|price("PLN",0) }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
@@ -40,4 +74,12 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# {% if empty %}#}
|
||||
{# <div class="col col-md-6">#}
|
||||
{# {% for item in empty %}#}
|
||||
{# <div>{{ item }}</div>#}
|
||||
{# {% endfor %}#}
|
||||
{# </div>#}
|
||||
{# {% endif %}#}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user