add new table view

This commit is contained in:
2026-07-08 14:47:53 +02:00
parent a23f3587ab
commit 8b3f3e4608
6 changed files with 213 additions and 80 deletions
+58 -70
View File
@@ -23,57 +23,57 @@ use Symfony\Component\Validator\Constraints\File;
class TaxesController extends AbstractController
{
#[Route(path: '/taxes/{type}', name: 'app_taxes')]
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, [
'data_class' => null,
'multiple' => true,
'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',
'text/csv',
'text/plain',
// 'application/x-pdf',
],
'mimeTypesMessage' => 'Please upload a valid XLSX or XML document',
])
]
])
],
])
->add("upload",SubmitType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$files = $form->get('uploads')->getData();
$hash = $this->saveFiles($files);
return $this->redirectToRoute("app_taxes_{$type}_show",["hash" => $hash]);
}
return $this->renderForm('taxes/index.html.twig', [
'controller_name' => 'TaxesController',
'form' => $form,
'sheet' => $a
]);
}
// #[Route(path: '/taxes/{type}', name: 'app_taxes')]
// 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, [
// 'data_class' => null,
// 'multiple' => true,
// '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',
// 'text/csv',
// 'text/plain',
//// 'application/x-pdf',
// ],
// 'mimeTypesMessage' => 'Please upload a valid XLSX or XML document',
// ])
// ]
// ])
// ],
// ])
// ->add("upload",SubmitType::class)
// ->getForm();
// $form->handleRequest($request);
// if ($form->isSubmitted() && $form->isValid()) {
// $files = $form->get('uploads')->getData();
// $hash = $this->saveFiles($files);
// return $this->redirectToRoute("app_taxes_{$type}_show",["hash" => $hash]);
// }
//
// return $this->renderForm('taxes/index.html.twig', [
// 'controller_name' => 'TaxesController',
// 'form' => $form,
// 'sheet' => $a
// ]);
// }
private function saveFiles(array $files) : string
{
@@ -99,28 +99,13 @@ class TaxesController extends AbstractController
return $hash;
}
#[Route(path: '/taxes/summary/{type}', name: 'app_taxes_summary', methods: ['POST'])]
#[Route(path: '/taxes/{type}', name: 'app_taxes_summary', methods: ['POST'])]
public function takeSummary(string $type, Request $request, DividendsService $tax, ?MarketNames $market): Response
{
$files = $request->files->all()['pliki'];
$hash = $this->saveFiles($files);
if ($hash) {
$tax->setHash($hash);
if ($tax->readFiles($market)) {
$gen = $tax->generate();
// dd($gen);
return $this->render("taxes/show.html.twig", [
"taxes" => $gen->getSummaryByCountry(),
"errorDividend" => $gen->getErrorDividend(),
"errorString" => $gen->getErrorString(),
"rawCount" => $gen->takeCountRawData(),
"markets" => $gen->getMarkets(),
"markets_all" => MarketNames::cases(),
"hash_param" => $tax->takeHash(),
"current_market" => $market,
]);
}
return $this->redirectToRoute("app_taxes_{$type}_show", ["hash" => $hash]);
}
return $this->json([
"type" => $type,
@@ -133,8 +118,10 @@ class TaxesController extends AbstractController
{
if ($tax->readFiles($market)) {
$gen = $tax->generate();
// dd($gen);
return $this->render("taxes/show.html.twig", [
$taxes = $gen->getSummaryByCountry();
$sum = $taxes['sum'];
unset($taxes['sum']);
return $this->render("taxes/table.html.twig", [
"taxes" => $gen->getSummaryByCountry(),
"errorDividend" => $gen->getErrorDividend(),
"errorString" => $gen->getErrorString(),
@@ -143,6 +130,7 @@ class TaxesController extends AbstractController
"markets_all" => MarketNames::cases(),
"hash_param" => $tax->takeHash(),
"current_market" => $market,
"sum" => $sum,
]);
}
return new Response("Brak danych do wyświetlenia.");
@@ -42,12 +42,19 @@ class DividendsSummary
$this->countFromSheets();
if (count($this->allData) > 0) {
$sum = 0;
$profitSum = 0;
$summaryRow = [
"tax" => 0,
"profit" => 0,
"origin" => 0,
"destiny" => 0,
];
foreach ($this->allData as $key => $item) {
$val = round($item['tax'], 2);
$sum += $val;
$profitSum += $item['incomeAll'];
$summaryRow["tax"] += $val;
$summaryRow["profit"] += $item['incomeAll'];
$summaryRow["origin"] += $item['destiny_tax'];
$summaryRow["destiny"] += $item['tax_cost'];
$return[$key] = [
"country" => \Locale::getDisplayRegion("-".$key),
"income" => $item['incomeAll'],
@@ -58,11 +65,11 @@ class DividendsSummary
"incomesArray" => $item['incomes']
];
}
$summaryRow = array_map(function ($item) {
return intval(ceil($item));
}, $summaryRow);
// >
$return['sum'] = [
"tax" => intval(ceil($sum)),
"profit" => $profitSum
];
$return['sum'] = $summaryRow;
}
return $return;