diff --git a/project/src/Controller/TaxesController.php b/project/src/Controller/TaxesController.php index 73671e2..3a0b4f2 100644 --- a/project/src/Controller/TaxesController.php +++ b/project/src/Controller/TaxesController.php @@ -102,7 +102,8 @@ class TaxesController extends AbstractController "taxes" => $gen->getSummaryByCountry(), "errorDividend" => $gen->getErrorDividend(), "errorString" => $gen->getErrorString(), - "rawCount" => $gen->takeCountRawData() + "rawCount" => $gen->takeCountRawData(), + "markets" => $gen->getMarkets(), ]); } diff --git a/project/src/Logic/Dividends/DividendsSummary.php b/project/src/Logic/Dividends/DividendsSummary.php index d2566a2..2addd11 100644 --- a/project/src/Logic/Dividends/DividendsSummary.php +++ b/project/src/Logic/Dividends/DividendsSummary.php @@ -2,6 +2,7 @@ declare(strict_types=1); namespace App\Logic\Dividends; +use App\Enum\MarketNames; use App\Helper\Currency; use Doctrine\ORM\EntityManager; @@ -18,12 +19,23 @@ class DividendsSummary private array $allData=[]; private array $countryToCurrency=[]; private int $realCalculatedRows = 0; + /** @var array|MarketNames $markets */ + private array $markets=[]; public function __construct(EntityManager $manager) { $this->currencyObj = new Currency($manager); } + public function addMarket(?MarketNames $names) + { + $this->markets[] = $names ?? MarketNames::MBANK; + } + + public function getMarkets(): array + { + return $this->markets; + } public function getSummaryByCountry() : array { $return=[]; diff --git a/project/src/Logic/Dividends/ExanteSheet.php b/project/src/Logic/Dividends/ExanteSheet.php index 5e8fd67..903493c 100644 --- a/project/src/Logic/Dividends/ExanteSheet.php +++ b/project/src/Logic/Dividends/ExanteSheet.php @@ -29,7 +29,6 @@ class ExanteSheet extends SheetDataAll continue; } $operationType = strtolower($rawDatum[$operationKey]); - if (!str_contains($operationType,"dividend")) { continue; } diff --git a/project/src/Logic/Dividends/IbkrSheet.php b/project/src/Logic/Dividends/IbkrSheet.php index f7f863e..18223e1 100644 --- a/project/src/Logic/Dividends/IbkrSheet.php +++ b/project/src/Logic/Dividends/IbkrSheet.php @@ -29,7 +29,7 @@ class IbkrSheet extends SheetDataAll $taxArr = []; $test = []; foreach ($this->getRawData() as $index => $rawDatum) { - if ($index < 2) { + if ($index < 1) { continue; } $row=[]; @@ -39,7 +39,7 @@ class IbkrSheet extends SheetDataAll } } $test[$row['groupId']][] = $row['amount']; - if (strpos($row['type'], "Dividend") !== false) { + if (str_contains($row['type'], "Dividend")) { $dividendArr[$row['groupId']] = $row; } else { if (!isset($taxArr[$row['groupId']])) { @@ -49,16 +49,18 @@ class IbkrSheet extends SheetDataAll } } } + foreach ($dividendArr as $groupId => $dividend) { - if (!isset($taxArr[$groupId])) { - continue; - } - $taxGet = $taxArr[$groupId]['amount']; -// $dividend['amount'] += $taxGet; - $taxPercentage = intval(round(abs($taxGet) / $dividend['amount'], 2) * 100); - if ($taxPercentage === 14) { - $taxPercentage = 15; + if (isset($taxArr[$groupId])) { + $taxGet = $taxArr[$groupId]['amount']; + $taxPercentage = intval(round(abs($taxGet) / $dividend['amount'], 2) * 100); + if ($taxPercentage === 14) { + $taxPercentage = 15; + } + } else { + $taxPercentage = 19; } + $separate = explode(" ", $dividend['description']); $perShare = floatval($separate[4]); if (!$perShare) { @@ -71,6 +73,10 @@ class IbkrSheet extends SheetDataAll if (substr_count($date, "-") !== 2) { $date = substr($date, 0, 4) . "-" . substr($date, 4, 2) . "-" . substr($date, 6, 2); } + $dateObj = new \DateTime($date); + if ($dateObj->format("Y") !== (new \DateTime())->modify("-1 year")->format("Y")) { + continue; + } // trigger_error(var_export($date,true)); $dividendObj = new DividendsData(); $dividendObj->setCount(intval($dividend['amount'] / $perShare)); @@ -78,7 +84,7 @@ class IbkrSheet extends SheetDataAll $dividendObj->setCurrency($dividend['currency']); $dividendObj->setTax($taxPercentage); $dividendObj->setValue($perShare); - $dividendObj->setDateTime(new \DateTime($date)); + $dividendObj->setDateTime($dateObj); $ret[] = $dividendObj; } diff --git a/project/src/Logic/Dividends/SheetDataAll.php b/project/src/Logic/Dividends/SheetDataAll.php index 8df5538..a6943f1 100644 --- a/project/src/Logic/Dividends/SheetDataAll.php +++ b/project/src/Logic/Dividends/SheetDataAll.php @@ -11,6 +11,7 @@ abstract class SheetDataAll * @var array|DividendsData $data */ protected array $data = []; + protected array $dataNotCalculate = []; private array $rawData; /** diff --git a/project/src/Services/DividendsService.php b/project/src/Services/DividendsService.php index 78286f4..53b48f4 100644 --- a/project/src/Services/DividendsService.php +++ b/project/src/Services/DividendsService.php @@ -21,11 +21,6 @@ class DividendsService extends MasterServices $extension = pathinfo($file)['extension']; $market = MarketNames::tryFromCase($file); - - $isExante = str_contains($file, "exante"); - $isIbkr = str_contains($file, "ibkr"); - - if (in_array($extension, ['xlsx','csv'])) { if ($market === MarketNames::EXANTE) { $delimiter = ";"; @@ -48,6 +43,7 @@ class DividendsService extends MasterServices $summaryObj->addSheetData($item); } } + $summaryObj->addMarket($market); } if ($extension === "xml") { $obj = new XMLReader($file); diff --git a/project/templates/taxes/index.html.twig b/project/templates/taxes/index.html.twig index 589136e..e65b1a9 100644 --- a/project/templates/taxes/index.html.twig +++ b/project/templates/taxes/index.html.twig @@ -20,4 +20,4 @@ {{ form(form) }} {{ dump(sheet) }} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/project/templates/taxes/show.html.twig b/project/templates/taxes/show.html.twig index 666869e..0fe2ae7 100644 --- a/project/templates/taxes/show.html.twig +++ b/project/templates/taxes/show.html.twig @@ -5,6 +5,9 @@ {% block body %}