.
This commit is contained in:
@@ -110,8 +110,8 @@ class TaxesController extends AbstractController
|
|||||||
if ($gen) {
|
if ($gen) {
|
||||||
return $this->render("taxes/show.html.twig", [
|
return $this->render("taxes/show.html.twig", [
|
||||||
"taxes" => $tax->takeAllByCurrency(),
|
"taxes" => $tax->takeAllByCurrency(),
|
||||||
"empty" => $tax->takeAllByCurrencyEmpty()
|
"empty" => $tax->takeAllByCurrencyEmpty(),
|
||||||
// "error" => $gen->error
|
"error" => $tax->takeError()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ use Doctrine\ORM\EntityManager;
|
|||||||
|
|
||||||
class Currency
|
class Currency
|
||||||
{
|
{
|
||||||
public static array $currencies = ["USD","GBP","PLN"];
|
public static array $currencies = ["USD","GBP","PLN","EUR"];
|
||||||
|
public static array $currenciesCrypto = ["USDT"];
|
||||||
private static string $apiUrl = "https://api.nbp.pl/api/exchangerates/rates/a/:code/:date/?format=json";
|
private static string $apiUrl = "https://api.nbp.pl/api/exchangerates/rates/a/:code/:date/?format=json";
|
||||||
private EntityManager $manager;
|
private EntityManager $manager;
|
||||||
private array $ratesPerDate;
|
private array $ratesPerDate;
|
||||||
|
|||||||
@@ -7,10 +7,14 @@ use App\Logic\Crypto\MainObject;
|
|||||||
final class CryptoValues
|
final class CryptoValues
|
||||||
{
|
{
|
||||||
private static array $values = [
|
private static array $values = [
|
||||||
"values" => ["Wartość","Values"],
|
"values" => ["Wartość","Values","Amount"],
|
||||||
"currency" => ["Currency", "Waluta"],
|
"currency" => ["Currency", "Waluta"],
|
||||||
"date" => ["Data operacji"],
|
"date" => ["Data operacji","Date(UTC)"],
|
||||||
"desc" => ["Rodzaj"]
|
"desc" => ["Rodzaj"],
|
||||||
|
"price" => ["Price"],
|
||||||
|
"transactionType" => ["Type"],
|
||||||
|
"market" => ["Market"],
|
||||||
|
"realValue" => ["Total"]
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function isValue(string $type, string $text) : bool
|
public static function isValue(string $type, string $text) : bool
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ class Crypto extends Main
|
|||||||
if (!$all || count($all) < 1) {
|
if (!$all || count($all) < 1) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$sum = [
|
$sum = [];
|
||||||
];
|
|
||||||
|
|
||||||
/** @var MainObject $item */
|
/** @var MainObject $item */
|
||||||
foreach ($all as $item) {
|
foreach ($all as $item) {
|
||||||
if ($item->getValue() == 0) {
|
if ($item->getValue() == 0) {
|
||||||
@@ -44,14 +42,15 @@ class Crypto extends Main
|
|||||||
|
|
||||||
$sum[$item->getCurrency()][$date][] = $item;
|
$sum[$item->getCurrency()][$date][] = $item;
|
||||||
}
|
}
|
||||||
$test=[];
|
|
||||||
$realCurrency = [];
|
$realCurrency = [];
|
||||||
|
|
||||||
foreach ($sum as $currency => $itemsAll) {
|
foreach ($sum as $currency => $itemsAll) {
|
||||||
foreach ($itemsAll as $date => $i) {
|
foreach ($itemsAll as $date => $i) {
|
||||||
if (count($i) > 1) {
|
if (count($i) > 1) {
|
||||||
$realObj = $i[0];
|
$realObj = array_pop($i);
|
||||||
$realObj->setValue($i[1]->getValue() + $realObj->getValue());
|
foreach ($i as $item) {
|
||||||
|
$realObj->setValue($item->getValue() + $realObj->getValue());
|
||||||
|
}
|
||||||
$sum[$currency][$date] = $realObj;
|
$sum[$currency][$date] = $realObj;
|
||||||
} else {
|
} else {
|
||||||
$sum[$currency][$date] = $i[0];
|
$sum[$currency][$date] = $i[0];
|
||||||
@@ -59,7 +58,7 @@ class Crypto extends Main
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($sum as $currency => $items) {
|
foreach ($sum as $currency => $items) {
|
||||||
if (in_array($currency, Currency::$currencies)) {
|
if (in_array($currency, Currency::$currencies) || in_array($currency,Currency::$currenciesCrypto)) {
|
||||||
if (!isset($realCurrency[$currency])) {
|
if (!isset($realCurrency[$currency])) {
|
||||||
$realCurrency[$currency] = [];
|
$realCurrency[$currency] = [];
|
||||||
}
|
}
|
||||||
@@ -70,6 +69,19 @@ class Crypto extends Main
|
|||||||
foreach ($keyToDel as $item) {
|
foreach ($keyToDel as $item) {
|
||||||
unset($sum[$item]);
|
unset($sum[$item]);
|
||||||
}
|
}
|
||||||
|
foreach ($realCurrency as $currency => $i) {
|
||||||
|
if (in_array($currency,Currency::$currenciesCrypto)) {
|
||||||
|
$curr=null;
|
||||||
|
foreach ($i as $item) {
|
||||||
|
if (!($curr instanceof MainObject)) {
|
||||||
|
$curr = $realCurrency[$item->getRealCurrency()][array_key_first($realCurrency[$item->getRealCurrency()])];
|
||||||
|
}
|
||||||
|
$item->setRealCurrency("PLN");
|
||||||
|
$item->setPrice(round($curr->getPrice()/$item->getPrice(),4));
|
||||||
|
$item->setRealValue(intval(round(($item->getValue()/100)*$item->getPrice()*100)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
"realCurrency" => $realCurrency,
|
"realCurrency" => $realCurrency,
|
||||||
"transactions" => $sum
|
"transactions" => $sum
|
||||||
@@ -86,18 +98,28 @@ class Crypto extends Main
|
|||||||
/** @var MainObject $item */
|
/** @var MainObject $item */
|
||||||
foreach ($transactions['transactions'] as $currency => $transaction) {
|
foreach ($transactions['transactions'] as $currency => $transaction) {
|
||||||
foreach ($transaction as $date => $item) {
|
foreach ($transaction as $date => $item) {
|
||||||
|
$date = $item->getDateTime()->format("Y-m-d H:i");
|
||||||
|
$yearTrans = intval($item->getDateTime()->format("Y"));
|
||||||
if (isset($transactions['realCurrency']['PLN'][$date])) {
|
if (isset($transactions['realCurrency']['PLN'][$date])) {
|
||||||
$obj = $transactions['realCurrency']['PLN'][$date];
|
$obj = $transactions['realCurrency']['PLN'][$date];
|
||||||
$item->setRealValue($obj->getValue());
|
$item->setRealValue($obj->getValue());
|
||||||
$item->setRealCurrency($obj->getCurrency());
|
$item->setRealCurrency($obj->getCurrency());
|
||||||
|
// unset($transactions['realCurrency']['PLN'][$date]);
|
||||||
|
}
|
||||||
|
if (in_array($item->getRealCurrency(), Currency::$currenciesCrypto) && isset($transactions['realCurrency'][$item->getRealCurrency()])) {
|
||||||
|
$this->changeValue($item, $transactions['realCurrency'][$item->getRealCurrency()]);
|
||||||
|
}
|
||||||
|
if ($currency === "LML" && $yearTrans == "2020") {
|
||||||
|
// dd($item,$transactions['realCurrency']['PLN']);
|
||||||
|
}
|
||||||
|
if ($item->getRealValue() != 0) {
|
||||||
if (!isset($tmp['in'][$currency])) {
|
if (!isset($tmp['in'][$currency])) {
|
||||||
$tmp['in'][$currency] = [];
|
$tmp['in'][$currency] = [];
|
||||||
}
|
}
|
||||||
if (!isset($tmp['out'][$currency])) {
|
if (!isset($tmp['out'][$currency])) {
|
||||||
$tmp['out'][$currency] = [];
|
$tmp['out'][$currency] = [];
|
||||||
}
|
}
|
||||||
$date = $item->getDateTime()->format("Y-m-d H:i");
|
if ($yearTrans === intval(date("Y"))-1 && ($item->getTransactionType() !== "" && $item->getTransactionType() !== "BUY") || $item->getRealValue()>0) {
|
||||||
if ($item->getRealValue() > 0) {
|
|
||||||
$tmp['in'][$currency][$date] = $item;
|
$tmp['in'][$currency][$date] = $item;
|
||||||
} else {
|
} else {
|
||||||
$tmp['out'][$currency][$date] = $item;
|
$tmp['out'][$currency][$date] = $item;
|
||||||
@@ -105,11 +127,13 @@ class Crypto extends Main
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// dd($tmp['out']['LML']);
|
||||||
foreach ($tmp as &$inout) {
|
foreach ($tmp as &$inout) {
|
||||||
foreach ($inout as $currency => &$items) {
|
foreach ($inout as $currency => &$items) {
|
||||||
if (count($items) > 0) {
|
if (count($items) > 0) {
|
||||||
ksort($items,2);
|
ksort($items,2);
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
$item->currencyConversion();
|
||||||
$item->takePrice();
|
$item->takePrice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,12 +144,35 @@ class Crypto extends Main
|
|||||||
if (count($tmp["in"]) === 0) {
|
if (count($tmp["in"]) === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var MainObject $i */
|
||||||
|
foreach ($tmp as $type => $value) {
|
||||||
|
foreach ($value as $cur => $item) {
|
||||||
|
if (in_array($cur, Currency::$currenciesCrypto) && count($item) > 0) {
|
||||||
|
foreach ($item as $i) {
|
||||||
|
if ($i->getRealCurrency() === "PLN") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$real = $transactions['realCurrency'][$i->getRealCurrency()][array_key_first($transactions['realCurrency'][$i->getRealCurrency()])];
|
||||||
|
$i->setRealCurrency($real->getRealCurrency());
|
||||||
|
$newVal = $i->getRealValue()/100 * $real->getPrice();
|
||||||
|
$newVal = intval(round($newVal * 100));
|
||||||
|
$i->setRealValue($newVal);
|
||||||
|
$newPrice = $i->getPrice() * $real->getPrice();
|
||||||
|
$newPrice = intval(round($newPrice * 100));
|
||||||
|
$i->setPrice($newPrice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$arr = [];
|
$arr = [];
|
||||||
foreach ($tmp["in"] as $currency => $items) {
|
foreach ($tmp["in"] as $currency => $items) {
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$arr[$currency] = $this->countTax($item, $tmp['out'][$currency]);
|
$arr[$currency] = $this->countTax($item, $tmp['out'][$currency]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,10 +185,15 @@ class Crypto extends Main
|
|||||||
{
|
{
|
||||||
$needCount = abs($mainObject->getValue());
|
$needCount = abs($mainObject->getValue());
|
||||||
$priceToTax = 0;
|
$priceToTax = 0;
|
||||||
|
$getedValue = 0;
|
||||||
/** @var MainObject $buy */
|
/** @var MainObject $buy */
|
||||||
foreach ($buys as $buy) {
|
foreach ($buys as $buy) {
|
||||||
if ($mainObject->getDateTime()->diff($buy->getDateTime())->invert == 0) {
|
if ($mainObject->getDateTime()->diff($buy->getDateTime())->invert == 0) {
|
||||||
$this->notCount[] = $mainObject;
|
$value = abs($mainObject->getValue())-$getedValue;
|
||||||
|
if ($value > 1) {
|
||||||
|
$value /= MainObject::_CRYPTO_DIVIDER;
|
||||||
|
}
|
||||||
|
$this->notCount[$mainObject->getCurrency()] = $value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($needCount === 0) {
|
if ($needCount === 0) {
|
||||||
@@ -150,8 +202,12 @@ class Crypto extends Main
|
|||||||
if ($buy->getValue() == 0) {
|
if ($buy->getValue() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($mainObject->getCurrency() == "LML") {
|
||||||
|
// dd($needCount - $buy->getValue());
|
||||||
|
}
|
||||||
if ($needCount - $buy->getValue() > 0) {
|
if ($needCount - $buy->getValue() > 0) {
|
||||||
$needCount -= $buy->getValue();
|
$needCount -= $buy->getValue();
|
||||||
|
$getedValue += $buy->getValue();
|
||||||
$priceToTax += abs($buy->getRealValue()/100);
|
$priceToTax += abs($buy->getRealValue()/100);
|
||||||
$buy->setValue(0);
|
$buy->setValue(0);
|
||||||
} else {
|
} else {
|
||||||
@@ -159,6 +215,7 @@ class Crypto extends Main
|
|||||||
$priceToTax += round(abs($buy->getPrice() * $needCount / MainObject::_CRYPTO_DIVIDER),4);
|
$priceToTax += round(abs($buy->getPrice() * $needCount / MainObject::_CRYPTO_DIVIDER),4);
|
||||||
$needCount = 0;
|
$needCount = 0;
|
||||||
$buy->setValue($newVal);
|
$buy->setValue($newVal);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$return = [
|
$return = [
|
||||||
@@ -166,10 +223,46 @@ class Crypto extends Main
|
|||||||
'cost' => 0,
|
'cost' => 0,
|
||||||
];
|
];
|
||||||
if ($needCount > 0) {
|
if ($needCount > 0) {
|
||||||
|
if ($mainObject->getCurrency() == "GRT") {
|
||||||
|
// dd($needCount,$getedValue,$mainObject, $buys);
|
||||||
|
}
|
||||||
|
$value = abs($mainObject->getValue())-$getedValue;
|
||||||
|
if ($value > 1) {
|
||||||
|
$value /= MainObject::_CRYPTO_DIVIDER;
|
||||||
|
}
|
||||||
|
$this->notCount[$mainObject->getCurrency()] = $value;
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
$return['income'] = $mainObject->getRealValue() / 100;
|
$return['income'] = $mainObject->getRealValue() / 100;
|
||||||
$return['cost'] = round($priceToTax,2);
|
$return['cost'] = round($priceToTax,2);
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function changeValue(MainObject $mainObject, array $buys)
|
||||||
|
{
|
||||||
|
$needCount = abs($mainObject->getRealValue());
|
||||||
|
$newCount = 0;
|
||||||
|
/** @var MainObject $buy */
|
||||||
|
foreach ($buys as $buy) {
|
||||||
|
if ($mainObject->getDateTime()->diff($buy->getDateTime())->invert == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($buy->getValue() === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($needCount - $buy->getValue() > 0) {
|
||||||
|
$newCount += $buy->getValue()/100 * $buy->getPrice();
|
||||||
|
$buy->setValue(0);
|
||||||
|
} else {
|
||||||
|
$newCount = $needCount/100 * $buy->getPrice();
|
||||||
|
$buy->setValue(intval($buy->getValue()-$needCount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($newCount > 0) {
|
||||||
|
$mainObject->setRealValue(intval(round($newCount*100)));
|
||||||
|
$mainObject->setRealCurrency("PLN");
|
||||||
|
$mainObject->takePrice(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,50 +10,93 @@ class Main
|
|||||||
{
|
{
|
||||||
protected array $data;
|
protected array $data;
|
||||||
|
|
||||||
public function __construct(array $data)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
}
|
||||||
|
|
||||||
|
public function addData(array $data)
|
||||||
|
{
|
||||||
|
if (isset($data[0]) && $data[0][0]==='Date(UTC)') {
|
||||||
|
$first = array_shift($data);
|
||||||
|
array_unshift($data, $first, [
|
||||||
|
"2021-04-14 13:00:00",
|
||||||
|
"EURPLN",
|
||||||
|
"BUY",
|
||||||
|
4.5755,
|
||||||
|
100,
|
||||||
|
457.55
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$this->data[] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function takeAllRealTransactions(string $abstract): array
|
protected function takeAllRealTransactions(string $abstract): array
|
||||||
{
|
{
|
||||||
$tmp = [];
|
$tmp = [];
|
||||||
$keys = array_shift($this->data);
|
foreach ($this->data as $datum1) {
|
||||||
$names = [];
|
$keys = array_shift($datum1);
|
||||||
|
$names = [];
|
||||||
foreach ($keys as $keyId => $key) {
|
foreach ($keys as $keyId => $key) {
|
||||||
/** @var CryptoValues $abstract */
|
/** @var CryptoValues $abstract */
|
||||||
if ($abstract::isValue("values",$key)) {
|
if ($abstract::isValue("values",$key)) {
|
||||||
$names[$keyId] = "setValue";
|
$names[$keyId] = "setValue";
|
||||||
|
}
|
||||||
|
if ($abstract::isValue("date",$key)) {
|
||||||
|
$names[$keyId] = "setDateTime";
|
||||||
|
}
|
||||||
|
if ($abstract::isValue("currency",$key)) {
|
||||||
|
$names[$keyId] = "setCurrency";
|
||||||
|
}
|
||||||
|
if ($abstract::isValue("desc",$key)) {
|
||||||
|
$names[$keyId] = "setDesc";
|
||||||
|
}
|
||||||
|
if ($abstract::isValue("price",$key)) {
|
||||||
|
$names[$keyId] = "setPrice";
|
||||||
|
}
|
||||||
|
if ($abstract::isValue("transactionType",$key)) {
|
||||||
|
$names[$keyId] = "setTransactionType";
|
||||||
|
}
|
||||||
|
if ($abstract::isValue("market",$key)) {
|
||||||
|
$names[$keyId] = "setMarketName";
|
||||||
|
}
|
||||||
|
if ($abstract::isValue("realValue",$key)) {
|
||||||
|
$names[$keyId] = "setRealValue";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($abstract::isValue("date",$key)) {
|
$i = 0;
|
||||||
$names[$keyId] = "setDateTime";
|
foreach ($datum1 as $key1 => $datum) {
|
||||||
}
|
$obj = new MainObject();
|
||||||
if ($abstract::isValue("currency",$key)) {
|
if ($datum[0] === $keys[0]) {
|
||||||
$names[$keyId] = "setCurrency";
|
continue;
|
||||||
}
|
}
|
||||||
if ($abstract::isValue("desc",$key)) {
|
foreach ($names as $key => $name) {
|
||||||
$names[$keyId] = "setDesc";
|
if ($name === "setCurrency" && is_float($datum[$key])) {
|
||||||
}
|
dd($names,$datum[$key]);
|
||||||
}
|
|
||||||
foreach ($this->data as $datum) {
|
|
||||||
$obj = new MainObject();
|
|
||||||
foreach ($names as $key => $name) {
|
|
||||||
if ($name === "setValue") {
|
|
||||||
$data = "$datum[$key]";
|
|
||||||
if (strpos($data,",") !== false || strpos($data,".") !== false) {
|
|
||||||
$data = str_replace(",",".",$data);
|
|
||||||
}
|
}
|
||||||
$realInt = floatval($data)*MainObject::_CRYPTO_DIVIDER;
|
if ($name === "setValue") {
|
||||||
$datum[$key] = intval($realInt);
|
$data = "$datum[$key]";
|
||||||
|
if (strpos($data,",") !== false || strpos($data,".") !== false) {
|
||||||
|
$data = str_replace(",",".",$data);
|
||||||
|
}
|
||||||
|
$realInt = floatval($data)*MainObject::_CRYPTO_DIVIDER;
|
||||||
|
$datum[$key] = intval($realInt);
|
||||||
|
}
|
||||||
|
if ($name === "setDateTime") {
|
||||||
|
$datum[$key] = new \DateTime($datum[$key]);
|
||||||
|
}
|
||||||
|
if ($name === "setRealValue") {
|
||||||
|
$datum[$key] = intval($datum[$key]*100);
|
||||||
|
}
|
||||||
|
$obj->$name($datum[$key]);
|
||||||
}
|
}
|
||||||
if ($name === "setDateTime") {
|
$obj->trySetCurrencies();
|
||||||
$datum[$key] = new \DateTime($datum[$key]);
|
$obj->checkCurrency();
|
||||||
|
if ($i == 30) {
|
||||||
|
// dd($obj);
|
||||||
}
|
}
|
||||||
$obj->$name($datum[$key]);
|
$tmp[] = $obj;
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
$obj->checkCurrency();
|
|
||||||
$tmp[] = $obj;
|
|
||||||
}
|
}
|
||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ class ReadSheet
|
|||||||
foreach ($spreadsheet->getAllSheets() as $sheetName) {
|
foreach ($spreadsheet->getAllSheets() as $sheetName) {
|
||||||
$this->arr[] = $sheetName->toArray();
|
$this->arr[] = $sheetName->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return count($this->arr) > 0;
|
return count($this->arr) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Logic\Crypto;
|
|||||||
|
|
||||||
use App\Helper\Currency;
|
use App\Helper\Currency;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
|
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||||
|
|
||||||
class MainObject
|
class MainObject
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,16 @@ class MainObject
|
|||||||
private int $realValue=0;
|
private int $realValue=0;
|
||||||
private float $price=0;
|
private float $price=0;
|
||||||
private bool $isCrypto = false;
|
private bool $isCrypto = false;
|
||||||
|
private string $transactionType="";
|
||||||
|
private string $marketName="";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTransactionType(): string
|
||||||
|
{
|
||||||
|
return $this->transactionType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return float
|
* @return float
|
||||||
@@ -34,9 +45,9 @@ class MainObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getRealCurrency(): string
|
public function getRealCurrency(): ?string
|
||||||
{
|
{
|
||||||
return $this->realCurrency;
|
return $this->realCurrency;
|
||||||
}
|
}
|
||||||
@@ -110,12 +121,28 @@ class MainObject
|
|||||||
*/
|
*/
|
||||||
public function setCurrency(string $currency): void
|
public function setCurrency(string $currency): void
|
||||||
{
|
{
|
||||||
if (!in_array($currency, Currency::$currencies)) {
|
if (!in_array($currency, Currency::$currencies) && !in_array($currency, Currency::$currenciesCrypto)) {
|
||||||
$this->isCrypto = true;
|
$this->isCrypto = true;
|
||||||
}
|
}
|
||||||
$this->currency = $currency;
|
$this->currency = $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $transactionType
|
||||||
|
*/
|
||||||
|
public function setTransactionType(string $transactionType): void
|
||||||
|
{
|
||||||
|
$this->transactionType = $transactionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $marketName
|
||||||
|
*/
|
||||||
|
public function setMarketName(string $marketName): void
|
||||||
|
{
|
||||||
|
$this->marketName = $marketName;
|
||||||
|
}
|
||||||
|
|
||||||
public function addValue(int $val) : void
|
public function addValue(int $val) : void
|
||||||
{
|
{
|
||||||
$this->value += $val;
|
$this->value += $val;
|
||||||
@@ -129,19 +156,31 @@ class MainObject
|
|||||||
$this->realValue += $val;
|
$this->realValue += $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function takePrice() : void
|
public function takePrice(bool $force = false) : void
|
||||||
{
|
{
|
||||||
|
if ($this->price && !$force) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$real = $this->getRealValue() / 100;
|
$real = $this->getRealValue() / 100;
|
||||||
$val = $this->getValue();
|
$val = $this->getValue();
|
||||||
if ($this->isCrypto) {
|
if ($this->isCrypto) {
|
||||||
$val = $this->getValueCrypto();
|
$val = $this->getValueCrypto();
|
||||||
}
|
}
|
||||||
$price = round($real/$val,8);
|
$price = round($real/$val,8);
|
||||||
// if ($this->isCrypto) {
|
// if ($this->isCrypto) {
|
||||||
// $price *= self::_CRYPTO_DIVIDER;
|
// $price *= self::_CRYPTO_DIVIDER;
|
||||||
// } else {
|
// } else {
|
||||||
// $price *= 100;
|
// $price *= 100;
|
||||||
// }
|
// }
|
||||||
|
$this->price = $price;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param float|int $price
|
||||||
|
*/
|
||||||
|
public function setPrice($price): void
|
||||||
|
{
|
||||||
$this->price = $price;
|
$this->price = $price;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,4 +205,67 @@ class MainObject
|
|||||||
$this->value = intval($this->value/self::_CRYPTO_DIVIDER*100);
|
$this->value = intval($this->value/self::_CRYPTO_DIVIDER*100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function trySetCurrencies() : void
|
||||||
|
{
|
||||||
|
if ($this->marketName) {
|
||||||
|
if (strlen($this->marketName) === 6) {
|
||||||
|
$cur1 = substr($this->marketName,0,3);
|
||||||
|
$cur2 = substr($this->marketName,3);
|
||||||
|
if ($this->transactionType === "BUY") {
|
||||||
|
$this->setCurrency($cur1);
|
||||||
|
$this->setRealCurrency($cur2);
|
||||||
|
// $this->setPrice(-$this->getPrice());
|
||||||
|
} else {
|
||||||
|
$this->setCurrency($cur2);
|
||||||
|
$this->setRealCurrency($cur1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$cryptoFiat = ["USDT"];
|
||||||
|
foreach ($cryptoFiat as $item) {
|
||||||
|
$currReal = strpos($this->marketName, $item);
|
||||||
|
if ($currReal === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($currReal > 0) {
|
||||||
|
$cur1 = substr($this->marketName, 0,strlen($this->marketName) - strlen($item));
|
||||||
|
$cur2 = $item;
|
||||||
|
} else {
|
||||||
|
$cur1 = $item;
|
||||||
|
$cur2 = substr($this->marketName, 0, strlen($this->marketName) - strlen($item));
|
||||||
|
}
|
||||||
|
if ($this->transactionType === "BUY") {
|
||||||
|
$this->setCurrency($cur1);
|
||||||
|
$this->setRealCurrency($cur2);
|
||||||
|
// $this->setPrice(-$this->getPrice());
|
||||||
|
} else {
|
||||||
|
$this->setCurrency($cur2);
|
||||||
|
$this->setRealCurrency($cur1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->getRealCurrency() === "USDT") {
|
||||||
|
$this->setRealValue(-intval($this->getRealValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function currencyConversion() : void
|
||||||
|
{
|
||||||
|
if ($this->realCurrency === "PLN" || (!in_array($this->realCurrency, Currency::$currencies) && !in_array($this->realCurrency, Currency::$currenciesCrypto))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$eur = 4.5755;
|
||||||
|
if ($this->realCurrency === "EUR") {
|
||||||
|
$this->setRealValue(intval(round($this->getRealValue() * $eur)));
|
||||||
|
$this->setRealCurrency("PLN");
|
||||||
|
$this->takePrice(true);
|
||||||
|
}
|
||||||
|
// if ($this->realCurrency === "USDT") {
|
||||||
|
// dd($this);
|
||||||
|
// $this->setRealValue(intval(round($this->getRealValue() * ($eur/$this->getPrice()))));
|
||||||
|
// $this->setRealCurrency("PLN");
|
||||||
|
// $this->takePrice(true);
|
||||||
|
// }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -28,9 +28,11 @@ class DividendsSummary
|
|||||||
|
|
||||||
if (count($this->allData) > 0) {
|
if (count($this->allData) > 0) {
|
||||||
$sum = 0;
|
$sum = 0;
|
||||||
|
$profitSum = 0;
|
||||||
foreach ($this->allData as $key => $item) {
|
foreach ($this->allData as $key => $item) {
|
||||||
$val = round($item['tax'], 2);
|
$val = round($item['tax'], 2);
|
||||||
$sum += $val;
|
$sum += $val;
|
||||||
|
$profitSum += $item['incomeAll'];
|
||||||
$return[$key] = [
|
$return[$key] = [
|
||||||
"country" => \Locale::getDisplayRegion("-".$key),
|
"country" => \Locale::getDisplayRegion("-".$key),
|
||||||
"income" => $item['incomeAll'],
|
"income" => $item['incomeAll'],
|
||||||
@@ -42,7 +44,10 @@ class DividendsSummary
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
// >
|
// >
|
||||||
$return['sum'] = intval(ceil($sum));
|
$return['sum'] = [
|
||||||
|
"tax" => intval(ceil($sum)),
|
||||||
|
"profit" => $profitSum
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
|||||||
@@ -17,30 +17,24 @@ class CryptoService extends MasterServices
|
|||||||
|
|
||||||
public function generate() : bool
|
public function generate() : bool
|
||||||
{
|
{
|
||||||
$summaryObj = new DividendsSummary($this->manager);
|
|
||||||
$sum = [];
|
$a = new Crypto();
|
||||||
$errorArr = [];
|
|
||||||
foreach ($this->allFiles as $file) {
|
foreach ($this->allFiles as $file) {
|
||||||
$extension = pathinfo($file)['extension'];
|
|
||||||
$tmp = new ReadSheet($file);
|
$tmp = new ReadSheet($file);
|
||||||
$tmp->takeFile();
|
if($tmp->takeFile()){
|
||||||
$a = new Crypto($tmp->getAll()[0]);
|
$a->addData($tmp->getAll()[0]);
|
||||||
$sum = array_merge($sum, $a->takeSumTransactions());
|
}
|
||||||
$errorArr = array_merge($errorArr, $a->getNotCounted());
|
|
||||||
}
|
}
|
||||||
|
$this->transactions = $a->takeSumTransactions();
|
||||||
$this->transactions = $sum;
|
$this->transactionsError = $a->getNotCounted();
|
||||||
$this->transactionsError = $errorArr;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return count($sum) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function takeAllByCurrency() : array
|
public function takeAllByCurrency() : array
|
||||||
{
|
{
|
||||||
$return = [];
|
$return = [];
|
||||||
$sum = 0;
|
$profitSum = 0;
|
||||||
|
|
||||||
foreach ($this->transactions as $key => $transaction) {
|
foreach ($this->transactions as $key => $transaction) {
|
||||||
$tax = $transaction['income'] - $transaction['cost'];
|
$tax = $transaction['income'] - $transaction['cost'];
|
||||||
$profit = $tax;
|
$profit = $tax;
|
||||||
@@ -51,19 +45,17 @@ class CryptoService extends MasterServices
|
|||||||
}
|
}
|
||||||
$return[$key] = [
|
$return[$key] = [
|
||||||
"country" => $key,
|
"country" => $key,
|
||||||
// "value" => round($transaction,4),
|
|
||||||
"currency" => "",
|
"currency" => "",
|
||||||
"tax" => $tax,
|
"tax" => $tax,
|
||||||
"profit" => $profit
|
"profit" => $profit
|
||||||
];
|
];
|
||||||
|
$profitSum += $profit;
|
||||||
$return[$key] = array_merge($return[$key], $transaction);
|
$return[$key] = array_merge($return[$key], $transaction);
|
||||||
if ($tax > 0) {
|
|
||||||
$sum += $tax;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$return['sum'] = intval(ceil($sum));
|
$return['sum'] = [
|
||||||
|
'tax' => intval(ceil($profitSum*0.19)),
|
||||||
// dd($return, $this->transactionsError);
|
'profit' => $profitSum
|
||||||
|
];
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,5 +71,10 @@ class CryptoService extends MasterServices
|
|||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function takeError()
|
||||||
|
{
|
||||||
|
return $this->transactionsError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//LML, EXY, AMLT, XRP, XLM, OMG, ETH, LTC
|
//LML, EXY, AMLT, XRP, XLM, OMG, ETH, LTC
|
||||||
@@ -34,7 +34,6 @@ class MasterServices
|
|||||||
}
|
}
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
$this->allFiles=$fileNames;
|
$this->allFiles=$fileNames;
|
||||||
|
|
||||||
return count($fileNames) > 0;
|
return count($fileNames) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for tax in taxes %}
|
{% for key,tax in taxes %}
|
||||||
{% if tax.country is defined %}
|
{% if tax.country is defined %}
|
||||||
{% set colspan = tax|length %}
|
{% set colspan = tax|length %}
|
||||||
{% if tax.income > 0 %}
|
{% if tax.income > 0 %}
|
||||||
@@ -62,6 +62,12 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% elseif key == "sum" %}
|
||||||
|
<tr class="">
|
||||||
|
<td colspan="{{ colspan-2 }}">Summary:</td>
|
||||||
|
<td>{{ tax.profit|price("PLN",0) }}</td>
|
||||||
|
<td>{{ tax.tax|price("PLN",0) }}</td>
|
||||||
|
</tr>
|
||||||
{% else %}
|
{% else %}
|
||||||
<tr class="">
|
<tr class="">
|
||||||
<td colspan="{{ colspan-1 }}">Summary:</td>
|
<td colspan="{{ colspan-1 }}">Summary:</td>
|
||||||
@@ -72,6 +78,20 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if error %}
|
||||||
|
<table class="table table-dark table-striped">
|
||||||
|
<tr>
|
||||||
|
{% for curr,val in error %}
|
||||||
|
<td>{{ curr }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
{% for curr,val in error %}
|
||||||
|
<td>{{ val }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user