From b23cfe61bdb40266fcc0d03dd8232b9d4c0bdf23 Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Fri, 21 Feb 2025 12:26:48 +0000 Subject: [PATCH] bug fix in shortlinks --- hesabixCore/src/Controller/BusinessController.php | 2 +- .../src/Controller/Front/ShortlinksController.php | 11 ++++++----- hesabixCore/src/Controller/HesabdariController.php | 6 ++++++ hesabixCore/src/Controller/PreinvoiceController.php | 2 +- hesabixCore/src/Controller/SMSController.php | 9 ++++++--- hesabixCore/src/Controller/SellController.php | 8 ++++++-- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/hesabixCore/src/Controller/BusinessController.php b/hesabixCore/src/Controller/BusinessController.php index 6866b65..2258e6d 100644 --- a/hesabixCore/src/Controller/BusinessController.php +++ b/hesabixCore/src/Controller/BusinessController.php @@ -255,7 +255,7 @@ class BusinessController extends AbstractController $business->setMoney($Arzmain); else return $this->json(['result' => 2]); - } + } if (!$business->getDateSubmit()) $business->setDateSubmit(time()); $entityManager->persist($business); diff --git a/hesabixCore/src/Controller/Front/ShortlinksController.php b/hesabixCore/src/Controller/Front/ShortlinksController.php index 7b56f26..60a2eed 100644 --- a/hesabixCore/src/Controller/Front/ShortlinksController.php +++ b/hesabixCore/src/Controller/Front/ShortlinksController.php @@ -27,11 +27,11 @@ class ShortlinksController extends AbstractController ]); if (!$ticket) throw $this->createNotFoundException(); - if(!$ticket->isCanShare()) + if (!$ticket->isCanShare()) throw $this->createAccessDeniedException(); $person = null; - + foreach ($ticket->getDoc()->getHesabdariRows() as $item) { if ($item->getPerson()) { $person = $item->getPerson(); @@ -40,12 +40,12 @@ class ShortlinksController extends AbstractController return $this->render('shortlinks/storeroom.html.twig', [ 'bid' => $bus, 'doc' => $ticket, - 'person'=>$person + 'person' => $person ]); } #[Route('/sl/{type}/{bid}/{link}/{msg}', name: 'shortlinks_show')] - public function shortlinks_show(string $bid, string $type, string $link, EntityManagerInterface $entityManager, string $msg = 'default'): Response + public function shortlinks_show(Provider $provider, string $bid, string $type, string $link, EntityManagerInterface $entityManager, string $msg = 'default'): Response { $bus = $entityManager->getRepository(Business::class)->find($bid); if (!$bus) @@ -55,7 +55,8 @@ class ShortlinksController extends AbstractController if ($type == 'sell') { $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ 'type' => 'sell', - 'shortlink' => $link + 'shortlink' => $link, + 'bid' => $bus ]); if (!$doc) { $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ diff --git a/hesabixCore/src/Controller/HesabdariController.php b/hesabixCore/src/Controller/HesabdariController.php index 5128648..9ed800a 100644 --- a/hesabixCore/src/Controller/HesabdariController.php +++ b/hesabixCore/src/Controller/HesabdariController.php @@ -54,6 +54,12 @@ class HesabdariController extends AbstractController ]); if (!$doc) throw $this->createNotFoundException(); + //add shortlink to doc + if (!$doc->getShortlink()) { + $doc->setShortlink($provider->RandomString(8)); + $entityManager->persist($doc); + $entityManager->flush(); + } $rows = []; $rowsObj = $entityManager->getRepository(HesabdariRow::class)->findBy( ['doc' => $doc] diff --git a/hesabixCore/src/Controller/PreinvoiceController.php b/hesabixCore/src/Controller/PreinvoiceController.php index 733fe57..f910fd7 100644 --- a/hesabixCore/src/Controller/PreinvoiceController.php +++ b/hesabixCore/src/Controller/PreinvoiceController.php @@ -226,7 +226,7 @@ class PreinvoiceController extends AbstractController $entityManager->persist($doc); $entityManager->flush(); if(!$doc->getShortlink()){ - $doc->setShortlink($doc->getId()); + $doc->setShortlink($provider->RandomString(8)); } //add pair docs diff --git a/hesabixCore/src/Controller/SMSController.php b/hesabixCore/src/Controller/SMSController.php index 3336135..adff55d 100644 --- a/hesabixCore/src/Controller/SMSController.php +++ b/hesabixCore/src/Controller/SMSController.php @@ -189,9 +189,12 @@ class SMSController extends AbstractController ]); if (!$doc) return $this->json(['result' => 3]); - $shortLink = $doc->getId(); - if ($doc->getShortlink()) - $shortLink = $doc->getShortlink(); + if(!$doc->getShortlink()){ + $doc->setShortlink($provider->RandomString(8)); + $entityManager->persist($doc); + $entityManager->flush(); + } + $shortLink = $doc->getShortlink(); //find custommer $customer = null; diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index 5b04428..05eadd8 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -249,7 +249,7 @@ class SellController extends AbstractController $entityManager->persist($doc); $entityManager->flush(); if (!$doc->getShortlink()) { - $doc->setShortlink($doc->getId()); + $doc->setShortlink($provider->RandomString(8)); } //add pair docs @@ -437,7 +437,11 @@ class SellController extends AbstractController } else { $temp['profit'] = $temp['profit'] + $item->getBs(); } - } else { + } + else if ($acc['bid']->getProfitCalctype() == 'simple') { + $temp['profit'] = $temp['profit'] + (($item->getCommodity()->getPriceSell() - $item->getCommodity()->getPriceBuy()) * $item->getCommdityCount()); + } + else { $lasts = $entityManager->getRepository(HesabdariRow::class)->findBy([ 'commodity' => $item->getCommodity(), 'bs' => 0