add exante and ibkr

This commit is contained in:
2023-04-12 15:13:55 +02:00
parent 90952d883e
commit fc1ef6f3ec
17 changed files with 439 additions and 75 deletions
+45 -43
View File
@@ -3,43 +3,36 @@ declare(strict_types=1);
namespace App\Logic\Dividends;
use App\Helper\Currency;
use App\Helper\DataNeed\DividendValues;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class SheetData
class SheetData extends SheetDataAll
{
private array $rawData;
// eg. 0 -> name, 1 -> ISIN
private array $dataIndex;
private array $data;
public function __construct(array $data)
{
$this->rawData = $data;
}
public function get() : array
public function takeData() : array
{
if (isset($this->data)) {
return $this->data;
}
$needIndex = [];
foreach ($this->rawData as $index => $rawDatum) {
foreach ($this->getRawData() as $index => $rawDatum) {
if ($index === 0) {
$this->dataIndex = $rawDatum;
continue;
}
$setDatas=[];
foreach ($rawDatum as $i => $data) {
$dataType = $this->getDataType($data,$setDatas);
if ($dataType){
$needIndex[$i] = $dataType;
foreach ($rawDatum as $i => $item) {
if (!$item) {
continue;
}
$keyName = DividendValues::searchForKeyName($item);
if ($keyName) {
$needIndex[$i] = $keyName;
}
}
break;
// continue;
}
unset($setDatas);
break;
// trigger_error(var_export($rawDatum,true));
}
$ret = [];
foreach ($this->rawData as $index => $datum) {
foreach ($this->getRawData() as $index => $datum) {
if ($index === 0) {
continue;
}
@@ -49,35 +42,30 @@ class SheetData
$row[$needIndex[$i]] = $d;
}
}
if (count($row) < 1) {
continue;
}
$date = &$row['date'];
if (is_int($date)) {
$date = Date::excelToDateTimeObject($date);
} else if (is_string($date)) {
$date = new \DateTime(str_replace(".", "-", $date));
}
if (is_float($row['tax'])) {
$row['tax'] = intval(round($row['tax']*100));
}
$dividendObj = new DividendsData();
$dividendObj->setCount($row['count']);
$dividendObj->setIsin($row['isin']);
$dividendObj->setCurrency($row['currency']);
$dividendObj->setTax($row['tax']);
$dividendObj->setValue($row['value']);
$dividendObj->setDateTime(new \DateTime(str_replace(".","-",$row['date'])));
$dividendObj->setDateTime($date);
$ret[] = $dividendObj;
}
$this->data = $ret;
return $ret;
}
public function getByCountry() : array
{
$data = $this->get();
if (!$data) {
return [];
}
$newArr = [];
/** @var DividendsData $datum */
foreach ($data as $datum) {
$key = mb_substr($datum->getIsin(), 0, 2);
$newArr[$key][] = $datum;
}
return $newArr;
}
public function takeColumnNames() : array
{
return $this->dataIndex;
@@ -118,10 +106,24 @@ class SheetData
if (in_array($data, Currency::$currencies)) {
return "currency";
}
if (count(explode(".", $data)) === 3) {
if (count(explode(".", $data)) === 3 || count(explode("-", $data)) === 3) {
return "date";
}
return null;
}
private function searchForDateIndex() : int
{
$ret = -1;
foreach ($this->takeColumnNames() as $index => $takeColumnName) {
if (strpos($takeColumnName,"DATE") !== false || strpos($takeColumnName,"DATA") !== false) {
$ret = $index;
break;
}
}
return $ret;
}
}