From c417aadee44465d1406aa80e9c19dddfee00a3e1 Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Fri, 25 Oct 2024 20:16:26 +0330 Subject: [PATCH] bug fix --- hesabixCore/src/Controller/SellController.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index 6e03f92..beb20d1 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -96,8 +96,14 @@ class SellController extends AbstractController $avg = $avg + $last->getBd(); $count = $count + $last->getCommdityCount(); } - $price = $avg / $count; - $profit = $profit + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount()); + if ($count != 0) { + $price = $avg / $count; + $profit = $profit + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount()); + } + else{ + $profit = $profit + $item->getBs(); + } + } //round output @@ -419,8 +425,13 @@ class SellController extends AbstractController $avg = $avg + $last->getBd(); $count = $count + $last->getCommdityCount(); } - $price = $avg / $count; - $temp['profit'] = $temp['profit'] + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount()); + if ($count != 0) { + $price = $avg / $count; + $temp['profit'] = $temp['profit'] + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount()); + } + else{ + $temp['profit'] = $temp['profit'] + $item->getBs(); + } } //round output