From 5cd788c7651afa50b5d4b8468c9744a1e410be61 Mon Sep 17 00:00:00 2001 From: Ryjek Date: Fri, 25 Mar 2022 17:41:26 +0100 Subject: [PATCH] ./ --- project/src/Helper/FIFO/Crypto.php | 59 +++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/project/src/Helper/FIFO/Crypto.php b/project/src/Helper/FIFO/Crypto.php index d9fc44a..67ba599 100644 --- a/project/src/Helper/FIFO/Crypto.php +++ b/project/src/Helper/FIFO/Crypto.php @@ -20,20 +20,61 @@ class Crypto extends Main /** @var MainObject $item */ foreach ($all as $item) { - if (!in_array($item->getCurrency(), Currency::$currencies)) { - if ($item->getValue() == 0) { - continue; + if ($item->getValue() == 0) { + continue; + } +// if (!isset($sum[$item->getCurrency()])) { +// $sum[$item->getCurrency()] = []; +// if (!isset($sum[$item->getCurrency()][$item->getDateTime()->format("Y-m-d")])){ +// $sum[$item->getCurrency()][$item->getDateTime()->format("Y-m-d")] = []; +// } +// } +// $sum[$item->getCurrency()][$item->getDateTime()->format("Y-m-d")][] = $item; + $date = $item->getDateTime()->format("Y-m-d"); + if (!isset($sum[$date])) { + $sum[$date] = []; + } + if (!isset($sum[$date][$item->getCurrency()])){ + $sum[$date][$item->getCurrency()] = []; + } + + $sum[$date][$item->getCurrency()][] = $item; + } + $test=[]; + foreach ($sum as $date => $items) { + $keys = array_keys($items); + $crypto=""; + $succ=false; + foreach ($keys as $key) { + if ($key === "PLN") { + $succ = true; + } else { + $crypto = $key; } - if (!isset($sum[$item->getCurrency()])) { - $sum[$item->getCurrency()] = []; - if (!isset($sum[$item->getCurrency()][$item->getDateTime()->format("Y-m-d")])){ - $sum[$item->getCurrency()][$item->getDateTime()->format("Y-m-d")] = []; + } + if (!$succ) { + continue; + } + if (!isset($test[$crypto])) { + $test[$crypto] = []; + } + $arr = [ + "crypto" => 0, + "pln" => 0 + ]; + /** @var MainObject $obj */ + foreach ($items as $currency => $obj1) { + foreach ($obj1 as $obj) { + if ($currency === $crypto) { + $arr['crypto'] += $obj->getValue(); + } else { + $arr['pln'] += $obj->getValue(); } } - $sum[$item->getCurrency()][$item->getDateTime()->format("Y-m-d")][] = $item; } + $test[$crypto] = $arr; } - return $sum; + return $test; } } \ No newline at end of file