From d44c24770701c73f522cc0ef545154dda39a1ef4 Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Fri, 25 Oct 2024 19:51:36 +0330 Subject: [PATCH] some progress --- hesabixCore/src/Controller/SellController.php | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index 5fa6e69..c0657d0 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -65,8 +65,47 @@ class SellController extends AbstractController ]); if (!$doc) throw $this->createNotFoundException(); + $result = Explore::ExploreSellDoc($doc); + $profit = 0; + //calculate profit + foreach ($doc->getHesabdariRows() as $item) { + if ($item->getCommodity()) { + if ($acc['bid']->getProfitCalctype() == 'lis') { + $last = $entityManager->getRepository(HesabdariRow::class)->findOneBy([ + 'commodity' => $item->getCommodity(), + 'bs' => 0 + ], [ + 'id' => 'DESC' + ]); + if ($last) { + $price = $last->getBd() / $last->getCommdityCount(); + $profit = $profit + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount()); + } else { + $profit = $profit + $item->getBs(); + } + } else { + $lasts = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'commodity' => $item->getCommodity(), + 'bs' => 0 + ], [ + 'id' => 'DESC' + ]); + $avg = 0; + $count = 0; + foreach ($lasts as $last) { + $avg = $avg + $last->getBd(); + $count = $count + $last->getCommdityCount(); + } + $price = $avg / $count; + $profit = $profit + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount()); + } - return $this->json(Explore::ExploreSellDoc($doc)); + //round output + $profit = round($profit); + } + } + $result['profit'] = $profit; + return $this->json($result); } #[Route('/api/sell/mod', name: 'app_sell_mod')]