From 83aed972479740f29680851ad59899b7031f2207 Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Sat, 10 Feb 2024 12:41:47 +0000 Subject: [PATCH] add edit to sell list --- hesabixCore/src/Controller/SellController.php | 51 +++++++++++++++++-- hesabixCore/src/Service/Explore.php | 16 ++++++ 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index b552ddc..2889387 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -2,17 +2,58 @@ namespace App\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use App\Service\Log; +use App\Service\Access; +use App\Service\Explore; +use App\Entity\HesabdariDoc; +use App\Entity\StoreroomTicket; +use Doctrine\ORM\EntityManagerInterface; +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 SellController extends AbstractController { - #[Route('/sell', name: 'app_sell')] - public function index(): Response + #[Route('/api/sell/edit/can/{code}', name: 'app_buy_can_edit')] + public function app_buy_can_edit(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse { - return $this->render('sell/index.html.twig', [ - 'controller_name' => 'SellController', + $canEdit = true; + $acc = $access->hasRole('buy'); + 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/sell/get/info/{code}', name: 'app_buy_get_info')] + public function app_buy_get_info(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse + { + $acc = $access->hasRole('buy'); + if(!$acc) + throw $this->createAccessDeniedException(); + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'bid'=>$acc['bid'], + 'code'=>$code + ]); + if(!$doc) + throw $this->createNotFoundException(); + + return $this->json(Explore::ExploreSellDoc($doc)); + } } diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 3a1c5f8..de80f16 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -16,6 +16,22 @@ use App\Entity\Salary; class Explore{ + public static function ExploreSellDoc(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()); + } + } + $result['person'] = $person; + return $result; + } + public static function ExploreBuyDoc(HesabdariDoc $hesabdariDoc){ $result = self::ExploreHesabdariDoc($hesabdariDoc); $person = [];