From a84bc451b82200d1021efe5b4d7390f6c9ee2d15 Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Sat, 11 May 2024 15:40:28 +0000 Subject: [PATCH] bug fixes --- .../src/Controller/BusinessController.php | 50 +++++++++++++----- .../src/Controller/RfbuyController.php | 2 +- .../src/Controller/RfsellController.php | 52 +++++++++++++++++-- hesabixCore/src/Service/Explore.php | 31 +++++++++++ hesabixCore/src/Service/SMS.php | 2 +- 5 files changed, 117 insertions(+), 20 deletions(-) diff --git a/hesabixCore/src/Controller/BusinessController.php b/hesabixCore/src/Controller/BusinessController.php index 700e75b..48c7f03 100644 --- a/hesabixCore/src/Controller/BusinessController.php +++ b/hesabixCore/src/Controller/BusinessController.php @@ -86,10 +86,10 @@ class BusinessController extends AbstractController $response['walletMatchBank'] = $provider->Entity2Array($bus->getWalletMatchBank(), 0); $year = $entityManager->getRepository(Year::class)->findOneBy([ 'bid' => $bus, - 'head'=>true + 'head' => true ]); $response['year'] = Explore::ExploreYear($year); - + return $this->json($response); } @@ -241,12 +241,11 @@ class BusinessController extends AbstractController $year->setLabel($params['year']['label']); $entityManager->persist($year); $entityManager->flush(); - } - else{ + } else { //not new business update business year $year = $entityManager->getRepository(Year::class)->findOneBy([ 'bid' => $business, - 'head'=>true + 'head' => true ]); $startYearArray = explode('-', $params['year']['startShamsi']); $year->setStart($jdate->jmktime(0, 0, 0, $startYearArray[1], $startYearArray[2], $startYearArray[0])); @@ -357,6 +356,31 @@ class BusinessController extends AbstractController return $this->json(['result' => -1]); } + #[Route('/api/business/removeuser/me', name: 'api_business_remove_user_me')] + public function api_business_remove_user_me(Access $access, Log $log, Request $request, EntityManagerInterface $entityManager): Response + { + $acc = $access->hasRole('join'); + if (!$acc) + throw $this->createAccessDeniedException(); + if ($this->getUser()->getId() == $acc['bid']->getOwner()->getId()) { + throw $this->createNotFoundException(); + } + + $perm = $entityManager->getRepository(Permission::class)->findOneBy([ + 'user' => $this->getUser(), + 'bid' => $acc['bid'] + ]); + if ($perm && !$perm->isOwner()) { + $entityManager->remove($perm); + $entityManager->flush(); + //add log to system + $log->insert('تنظیمات پایه', 'کاربر با پست الکترونیکی ' . $this->getUser()->getEmail() . ' کسب و کار را ترک کرد..', $this->getUser(), $acc['bid']); + return $this->json(['result' => 1]); + } + + return $this->json(['result' => -1]); + } + #[Route('/api/business/my/permission/state', name: 'api_business_my_permission_state')] public function api_business_my_permission_state(Request $request, Access $access): Response { @@ -431,10 +455,10 @@ class BusinessController extends AbstractController 'archiveView' => true, 'active' => $perm->getUser()->isActive(), 'shareholder' => true, - 'plugAccproAccounting'=>true, - 'plugAccproRfsell'=>true, - 'plugAccproRfbuy'=>true, - 'plugAccproCloseYear'=>true, + 'plugAccproAccounting' => true, + 'plugAccproRfsell' => true, + 'plugAccproRfbuy' => true, + 'plugAccproCloseYear' => true, ]; } elseif ($perm) { $result = [ @@ -470,10 +494,10 @@ class BusinessController extends AbstractController 'archiveView' => $perm->isArchiveView(), 'active' => $perm->getUser()->isActive(), 'shareholder' => $perm->isShareholder(), - 'plugAccproAccounting'=>$perm->isPlugAccproAccounting(), - 'plugAccproRfsell'=>$perm->isPlugAccproRfsell(), - 'plugAccproRfbuy'=>$perm->isPlugAccproRfbuy(), - 'plugAccproCloseYear'=>$perm->isPlugAccproCloseYear(), + 'plugAccproAccounting' => $perm->isPlugAccproAccounting(), + 'plugAccproRfsell' => $perm->isPlugAccproRfsell(), + 'plugAccproRfbuy' => $perm->isPlugAccproRfbuy(), + 'plugAccproCloseYear' => $perm->isPlugAccproCloseYear(), ]; } return $this->json($result); diff --git a/hesabixCore/src/Controller/RfbuyController.php b/hesabixCore/src/Controller/RfbuyController.php index 4b0442a..18b1ea6 100644 --- a/hesabixCore/src/Controller/RfbuyController.php +++ b/hesabixCore/src/Controller/RfbuyController.php @@ -54,6 +54,6 @@ class RfbuyController extends AbstractController if(!$doc) throw $this->createNotFoundException(); - return $this->json(Explore::ExploreSellDoc($doc)); + return $this->json(Explore::ExploreRfbuyDoc($doc)); } } diff --git a/hesabixCore/src/Controller/RfsellController.php b/hesabixCore/src/Controller/RfsellController.php index 16b40f3..ad86d26 100644 --- a/hesabixCore/src/Controller/RfsellController.php +++ b/hesabixCore/src/Controller/RfsellController.php @@ -2,17 +2,59 @@ namespace App\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use App\Service\Log; +use App\Service\Access; +use App\Entity\HesabdariDoc; +use App\Entity\StoreroomTicket; +use Doctrine\ORM\EntityManagerInterface; +use App\Service\Explore as ServiceExplore; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + class RfsellController extends AbstractController { - #[Route('/rfsell', name: 'app_rfsell')] - public function index(): Response + #[Route('/api/rfsell/edit/can/{code}', name: 'app_rfsell_can_edit')] + public function app_rfsell_can_edit(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse { - return $this->render('rfsell/index.html.twig', [ - 'controller_name' => 'RfsellController', + $canEdit = true; + $acc = $access->hasRole('plugAccproRfsell'); + if(!$acc) + throw $this->createAccessDeniedException(); + + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'bid'=>$acc['bid'], + 'code'=>$code + ]); + //check related documents + if(count($doc->getRelatedDocs()) != 0) + $canEdit = false; + + //check storeroom tickets + $tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc'=>$doc]); + if(count($tickets) != 0) + $canEdit = false; + return $this->json([ + 'result'=> $canEdit ]); } + + #[Route('/api/rfsell/get/info/{code}', name: 'app_rfsell_get_info')] + public function app_rfsell_get_info(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse + { + $acc = $access->hasRole('plugAccproRfsell'); + if(!$acc) + throw $this->createAccessDeniedException(); + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'bid'=>$acc['bid'], + 'code'=>$code + ]); + if(!$doc) + throw $this->createNotFoundException(); + + return $this->json(ServiceExplore::ExploreRfsellDoc($doc)); + } } diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index c737c40..0c8404d 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -51,6 +51,22 @@ class Explore return $result; } + public static function ExploreRfbuyDoc(HesabdariDoc $hesabdariDoc) + { + $result = self::ExploreHesabdariDoc($hesabdariDoc); + $person = []; + $commodities = []; + foreach ($hesabdariDoc->getHesabdariRows() as $item) { + if ($item->getPerson()) { + $person = self::ExplorePerson($item->getPerson()); + } elseif ($item->getCommodity()) { + $commodities[] = Explore::ExploreCommodity($item->getCommodity(), $item->getCommdityCount(), $item->getDes()); + } + } + $result['person'] = $person; + return $result; + } + public static function ExploreBuyDoc(HesabdariDoc $hesabdariDoc) { $result = self::ExploreHesabdariDoc($hesabdariDoc); @@ -66,6 +82,21 @@ class Explore $result['person'] = $person; return $result; } + public static function ExploreRfsellDoc(HesabdariDoc $hesabdariDoc) + { + $result = self::ExploreHesabdariDoc($hesabdariDoc); + $person = []; + $commodities = []; + foreach ($hesabdariDoc->getHesabdariRows() as $item) { + if ($item->getPerson()) { + $person = self::ExplorePerson($item->getPerson()); + } elseif ($item->getCommodity()) { + $commodities[] = Explore::ExploreCommodity($item->getCommodity(), $item->getCommdityCount(), $item->getDes()); + } + } + $result['person'] = $person; + return $result; + } public static function ExploreHesabdariDoc(HesabdariDoc $doc) { return [ diff --git a/hesabixCore/src/Service/SMS.php b/hesabixCore/src/Service/SMS.php index 76312db..9972adc 100644 --- a/hesabixCore/src/Service/SMS.php +++ b/hesabixCore/src/Service/SMS.php @@ -13,7 +13,7 @@ class SMS private Settings $settings; private registryMGR $registryMGR; - private int $smsPrice = 1250; + private int $smsPrice = 900; /** * @param EntityManagerInterface $entityManager