Initial commit

This commit is contained in:
2022-03-25 16:42:41 +01:00
commit 34685838bc
235 changed files with 12766 additions and 0 deletions
@@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
namespace App\Logic\Dividends;
use App\Helper\Currency;
use Doctrine\ORM\EntityManager;
class DividendsSummary
{
/** @var SheetData|array $sheetData */
private array $sheetData=[];
/** @var XMLReader|array $sheetData */
private array $xmlData=[];
private Currency $currencyObj;
public array $error=[];
private array $allData=[];
private array $countryToCurrency=[];
public function __construct(EntityManager $manager)
{
$this->currencyObj = new Currency($manager);
}
public function getSummaryByCountry() : array
{
$return=[];
$this->countFromSheets();
if (count($this->allData) > 0) {
$sum = 0;
foreach ($this->allData as $key => $item) {
$val = round($item, 2);
$sum += $val;
$return[$key] = [
"country" => \Locale::getDisplayRegion("-".$key),
"value" => $val,
"currency" => $this->countryToCurrency[$key]
];
}
$return['sum'] = intval(ceil($sum));
}
return $return;
}
private function countFromSheets() : void
{
if (!count($this->sheetData)) {
return;
}
$test=[];
$countryToCurrency=[];
/** @var SheetData $sheetDatum */
foreach ($this->sheetData as $sheetDatum) {
$all = $sheetDatum->getByCountry();
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($countryToCurrency[$country])) {
$countryToCurrency[$country] = $val->getCurrency();
}
}
}
}
$this->allData = array_merge($this->allData,$test);
$this->countryToCurrency = array_merge($this->countryToCurrency,$countryToCurrency);
}
private function getRate(DividendsData $data) : float
{
return $this->currencyObj->getRate($data->getCurrency(),$data->getDateTime(),$this->error);
}
private function count(DividendsData $data) : float
{
$value = round($data->getCount()*$data->getValue(),2);
$tax = 19;
if ($data->getTax() > 0) {
$tax = 4;
}
$valueTax = round($value * $tax / 100);
$rate = $this->getRate($data);
if ($rate > 0) {
return $valueTax * $rate;
}
$this->error[]=$data;
return 0;
}
/**
* @param SheetData $sheetData
*/
public function addSheetData(SheetData $sheetData): void
{
$this->sheetData[] = $sheetData;
}
/**
* @param XMLReader $reader
*/
public function addXml(XMLReader $reader)
{
$this->xmlData[] = $reader;
}
}