From d451893bc7bc5c1d1bc631100df3806a070fa8de Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Mon, 19 Feb 2024 10:36:57 +0000 Subject: [PATCH] progress in cheque and some bug fix --- .../src/Controller/ChequeController.php | 46 +++++++++++++++++-- .../src/Controller/HesabdariController.php | 5 +- .../src/Controller/SupportController.php | 2 +- hesabixCore/src/Entity/Cheque.php | 15 ++++++ hesabixCore/src/Service/Explore.php | 4 +- 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/hesabixCore/src/Controller/ChequeController.php b/hesabixCore/src/Controller/ChequeController.php index 68460e0..7b6c7f2 100644 --- a/hesabixCore/src/Controller/ChequeController.php +++ b/hesabixCore/src/Controller/ChequeController.php @@ -32,9 +32,49 @@ class ChequeController extends AbstractController 'bid'=>$acc['bid'], 'type'=>'input' ]); - return $this->json([ - 'input'=>Explore::SerializeCheques(array_reverse($chequesInput)) + $chequesOutput = $entityManager->getRepository(Cheque::class)->findBy([ + 'bid'=>$acc['bid'], + 'type'=>'output' ]); + return $this->json([ + 'input'=>Explore::SerializeCheques(array_reverse($chequesInput)), + 'output'=>Explore::SerializeCheques(array_reverse($chequesOutput)) + ]); + } + + #[Route('/api/cheque/info/{id}', name: 'app_cheque_info')] + public function app_cheque_info(string $id, Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,Jdate $jdate): JsonResponse + { + $acc = $access->hasRole('cheque'); + if(!$acc) + throw $this->createAccessDeniedException(); + $cheque = $entityManager->getRepository(Cheque::class)->findOneBy([ + 'bid'=>$acc['bid'], + 'id'=>$id + ]); + if(!$cheque) + throw $this->createNotFoundException('cheque not found'); + return $this->json(Explore::SerializeCheque($cheque)); + } + + #[Route('/api/cheque/reject/{id}', name: 'app_cheque_reject')] + public function app_cheque_reject(string $id, Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,Jdate $jdate): JsonResponse + { + $acc = $access->hasRole('cheque'); + if(!$acc) + throw $this->createAccessDeniedException(); + $cheque = $entityManager->getRepository(Cheque::class)->findOneBy([ + 'bid'=>$acc['bid'], + 'id'=>$id + ]); + if(!$cheque) + throw $this->createNotFoundException('cheque not found'); + $cheque->setStatus('برگشت خورده'); + $cheque->setRejected(true); + $log->insert('بانکداری','چک شماره شماره ' . $cheque->getNumber() . ' به برگشت خورده تغییر یافت. ',$this->getUser(),$request->headers->get('activeBid')); + $entityManager->persist($cheque); + $entityManager->flush(); + return $this->json(['result'=>'ok']); } #[Route('/api/cheque/pass/{id}', name: 'app_cheque_pass')] @@ -62,7 +102,7 @@ class ChequeController extends AbstractController throw $this->createNotFoundException(); if($cheque->isLocked()) throw $this->createAccessDeniedException('cheque operation not permitted'); - + //edit cheque info $cheque->setBank($bank); $cheque->setStatus('پاس شده'); diff --git a/hesabixCore/src/Controller/HesabdariController.php b/hesabixCore/src/Controller/HesabdariController.php index b9b2883..bff3f97 100644 --- a/hesabixCore/src/Controller/HesabdariController.php +++ b/hesabixCore/src/Controller/HesabdariController.php @@ -347,10 +347,10 @@ class HesabdariController extends AbstractController elseif ($person->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('person is not in this business'); $hesabdariRow->setPerson($person); } - if($row['type'] == 'cheque'){ + elseif($row['type'] == 'cheque'){ $person = $entityManager->getRepository(Person::class)->findOneBy([ 'bid'=> $acc['bid'], - 'id'=>$row['person'] + 'id'=>$row['chequeOwner'] ]); $cheque = new Cheque(); $cheque->setBid($acc['bid']); @@ -373,6 +373,7 @@ class HesabdariController extends AbstractController else $cheque->setAmount($hesabdariRow->getBs()); $cheque->setLocked(false); + $cheque->setRejected(false); $cheque->setStatus('پاس نشده'); $entityManager->persist($cheque); $entityManager->flush(); diff --git a/hesabixCore/src/Controller/SupportController.php b/hesabixCore/src/Controller/SupportController.php index 8ad5972..15e2a8f 100644 --- a/hesabixCore/src/Controller/SupportController.php +++ b/hesabixCore/src/Controller/SupportController.php @@ -49,7 +49,7 @@ class SupportController extends AbstractController ]); } #[Route('/api/admin/support/mod/{id}', name: 'app_admin_support_mod')] - public function app_admin_support_mod(SMS $SMS,Request $request, EntityManagerInterface $entityManager,string $id = '',Notification $notifi): JsonResponse + public function app_admin_support_mod(SMS $SMS,Request $request, EntityManagerInterface $entityManager,Notification $notifi,string $id = ''): JsonResponse { $params = []; if ($content = $request->getContent()) { diff --git a/hesabixCore/src/Entity/Cheque.php b/hesabixCore/src/Entity/Cheque.php index 29ca7a5..678ce89 100644 --- a/hesabixCore/src/Entity/Cheque.php +++ b/hesabixCore/src/Entity/Cheque.php @@ -71,6 +71,9 @@ class Cheque #[ORM\Column(length: 255, nullable: true)] private ?string $date = null; + #[ORM\Column(nullable: true)] + private ?bool $rejected = null; + public function __construct() { $this->hesabdariRows = new ArrayCollection(); @@ -315,4 +318,16 @@ class Cheque return $this; } + public function isRejected(): ?bool + { + return $this->rejected; + } + + public function setRejected(?bool $rejected): static + { + $this->rejected = $rejected; + + return $this; + } + } diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 357adf5..7ceb8e1 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -223,8 +223,8 @@ class Explore{ 'amount'=>$cheque->getAmount(), 'status'=>$cheque->getStatus(), 'date'=>$cheque->getDate(), - 'locked'=>$cheque->isLocked() - + 'locked'=>$cheque->isLocked(), + 'rejected'=>$cheque->isRejected() ]; }