This commit is contained in:
2022-03-31 16:24:11 +02:00
parent 98c6814863
commit a29ee0d5b7
7 changed files with 146 additions and 47 deletions
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class IndexController extends AbstractController
{
/**
* @Route("/", name="homepage")
*/
public function index() : Response
{
return $this->render("index/index.html.twig");
}
}
+46 -27
View File
@@ -3,10 +3,6 @@
namespace App\Controller;
use App\Helper\Currency;
use App\Helper\MyReader;
use App\Helper\ReaderSheet;
use App\Helper\SheetData;
use App\Helper\DividendsSummary;
use App\Services\CryptoService;
use App\Services\DividendsService;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
@@ -24,10 +20,14 @@ use Symfony\Component\Validator\Constraints\File;
class TaxesController extends AbstractController
{
/**
* @Route("/taxes", name="app_taxes")
* @Route("/taxes/{type}", name="app_taxes")
*/
public function index(Request $request): Response
public function index(Request $request, string $type): Response
{
if (!in_array($type, ["crypto", "dividend"])) {
return $this->redirectToRoute("homepage");
}
$a=[];
$form = $this->createFormBuilder([])
->add("uploads",FileType::class, [
@@ -36,24 +36,26 @@ class TaxesController extends AbstractController
'attr'=>[
'multiple' => 'multiple',
],
// 'constraints' => [
// new All([
// 'constraints' => [
// new File([
// 'maxSize' => '2048k',
// 'mimeTypes' => [
// 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
// 'application/atom+xml',
// 'application/xml',
// 'text/xml',
// 'text/xml-external-parsed-entity',
//// 'application/x-pdf',
// ],
// 'mimeTypesMessage' => 'Please upload a valid XLSX or XML document',
// ])
// ]
// ])
// ],
'constraints' => [
new All([
'constraints' => [
new File([
'maxSize' => '2048k',
'mimeTypes' => [
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/atom+xml',
'application/xml',
'text/xml',
'text/xml-external-parsed-entity',
'text/csv',
'text/plain',
// 'application/x-pdf',
],
'mimeTypesMessage' => 'Please upload a valid XLSX or XML document',
])
]
])
],
])
->add("upload",SubmitType::class)
->getForm();
@@ -71,7 +73,7 @@ class TaxesController extends AbstractController
);
$i++;
}
return $this->redirectToRoute("app_taxes_show",["hash" => $hash]);
return $this->redirectToRoute("app_taxes_{$type}_show",["hash" => $hash]);
}
}
@@ -83,9 +85,9 @@ class TaxesController extends AbstractController
}
/**
* @Route("/taxes/{hash}", name="app_taxes_show")
* @Route("/taxes/dividend/{hash}", name="app_taxes_dividend_show")
*/
public function show(DividendsService $tax) : Response
public function showDividend(DividendsService $tax) : Response
{
if ($tax->readFiles()) {
$gen = $tax->generate();
@@ -98,4 +100,21 @@ class TaxesController extends AbstractController
}
return new Response("error");
}
/**
* @Route("/taxes/crypto/{hash}", name="app_taxes_crypto_show")
*/
public function showCrypto(CryptoService $tax) : Response
{
if ($tax->readFiles()) {
$gen = $tax->generate();
if ($gen) {
return $this->render("taxes/show.html.twig", [
"taxes" => $tax->takeAllByCurrency(),
// "error" => $gen->error
]);
}
}
return new Response("error");
}
}
+28 -10
View File
@@ -40,10 +40,22 @@ class Crypto extends Main
$sum[$item->getCurrency()][$date] = [];
}
$sum[$item->getCurrency()][$date] = $item;
$sum[$item->getCurrency()][$date][] = $item;
}
$test=[];
$realCurrency = [];
foreach ($sum as $currency => $itemsAll) {
foreach ($itemsAll as $date => $i) {
if (count($i) > 1) {
$realObj = $i[0];
$realObj->setValue($i[1]->getValue() + $realObj->getValue());
$sum[$currency][$date] = $realObj;
} else {
$sum[$currency][$date] = $i[0];
}
}
}
foreach ($sum as $currency => $items) {
if (in_array($currency, Currency::$currencies)) {
if (!isset($realCurrency[$currency])) {
@@ -56,7 +68,6 @@ class Crypto extends Main
foreach ($keyToDel as $item) {
unset($sum[$item]);
}
return [
"realCurrency" => $realCurrency,
"transactions" => $sum
@@ -75,7 +86,9 @@ class Crypto extends Main
foreach ($transactions['transactions'] as $currency => $transaction) {
foreach ($transaction as $date => $item) {
if (isset($transactions['realCurrency']['PLN'][$date])) {
$item->setRealValue($transactions['realCurrency']['PLN'][$date]->getValue());
$obj = $transactions['realCurrency']['PLN'][$date];
$item->setRealValue($obj->getValue());
$item->setRealCurrency($obj->getCurrency());
if (!isset($tmp['in'][$currency])) {
$tmp['in'][$currency] = [];
}
@@ -91,13 +104,18 @@ class Crypto extends Main
}
}
}
foreach ($tmp as &$inout) {
foreach ($inout as $currency => &$items) {
ksort($items,2);
if (count($items) > 0) {
ksort($items,2);
foreach ($items as $item) {
$item->takePrice();
}
}
}
}
unset($items);
unset($inout);
if (count($tmp["in"]) === 0) {
return [];
}
@@ -118,7 +136,7 @@ class Crypto extends Main
private function countTax(MainObject $mainObject, array $buys)
{
$needCount = abs($mainObject->getValue());
$needCount = $mainObject->getValue();
$priceToTax = 0;
/** @var MainObject $buy */
foreach ($buys as $buy) {
@@ -132,16 +150,16 @@ class Crypto extends Main
if ($buy->getValue() == 0) {
continue;
}
if ($needCount > $buy->getValue()) {
if ($needCount - $buy->getValue() > 0) {
$needCount -= $buy->getValue();
$priceToTax += $buy->getRealValue();
} else {
$newVal = abs($buy->getValue())-$needCount;
$newVal = $buy->getValue() - $needCount;
$priceToTax += $buy->getPrice() * $needCount;
$needCount = 0;
$buy->setValue($newVal);
}
}
return $mainObject->getRealValue()-$priceToTax;
return $mainObject->getRealValue() + $priceToTax;
}
}
+6 -1
View File
@@ -40,7 +40,12 @@ class Main
$obj = new MainObject();
foreach ($names as $key => $name) {
if ($name === "setValue") {
$datum[$key] = floatval($datum[$key]);
// if ($datum[$key]!=="0,00") dd();
$data = $datum[$key];
if (is_string($data)) {
$data = strtr($data,",",".");
}
$datum[$key] = floatval($data);
}
if ($name === "setDateTime") {
$datum[$key] = new \DateTime($datum[$key]);
+1 -1
View File
@@ -125,7 +125,7 @@ class MainObject
public function takePrice() : void
{
$this->price = abs(round($this->realValue / $this->getValue(),4));
$this->price = floatval(abs(round($this->realValue / $this->getValue(),4)));
}
public function getPrice() : float
+32 -7
View File
@@ -4,6 +4,7 @@ namespace App\Services;
use App\Helper\FIFO\Crypto;
use App\Helper\Sheets\ReadSheet;
use App\Logic\Crypto\MainObject;
use App\Logic\Dividends\DividendsSummary;
use App\Logic\Dividends\SheetData;
use App\Logic\Dividends\XMLReader;
@@ -11,25 +12,49 @@ use Doctrine\ORM\EntityManager;
class CryptoService extends MasterServices
{
public function generate() : array
private array $transactions = [];
private array $transactionsError = [];
public function generate() : bool
{
$summaryObj = new DividendsSummary($this->manager);
$sum = 0;
$sum = [];
$errorArr = [];
foreach ($this->allFiles as $file) {
$extension = pathinfo($file)['extension'];
$tmp = new ReadSheet($file);
$tmp->takeFile();
$a = new Crypto($tmp->getAll()[0]);
$sum += array_sum($a->takeSumTransactions());
$sum = array_merge($sum, $a->takeSumTransactions());
$errorArr = array_merge($errorArr, $a->getNotCounted());
}
$this->transactions = $sum;
$this->transactionsError = $errorArr;
return [
"sum" => $sum,
"error" => $errorArr
];
return count($sum) > 0;
}
public function takeAllByCurrency() : array
{
$return = [];
$sum = 0;
foreach ($this->transactions as $key => $transaction) {
$return[$key] = [
"country" => $key,
"value" => round($transaction,4),
"currency" => ""
];
if ($transaction > 0) {
$sum += round($transaction,4);
}
}
$return['sum'] = intval(ceil($sum));
// dd($return, $this->transactionsError);
return $return;
}
}
//LML, EXY, AMLT, XRP, XLM, OMG, ETH, LTC
+14
View File
@@ -0,0 +1,14 @@
{% extends 'base.html.twig' %}
{% block title %}Index{% endblock %}
{% block body %}
<div class="row justify-content-md-center" style="margin: 50px 0;">
<div class="col-md-1">
<a class="btn btn-primary" href="{{ path('app_taxes',{type:"dividend"}) }}">Dividends</a>
</div>
<div class="col-md-1">
<a class="btn btn-primary" href="{{ path('app_taxes',{type:"crypto"}) }}">Cryptocurrency</a>
</div>
</div>
{% endblock %}