From 28ad56d972703aa380d1d6eb2c5a341108ea49de Mon Sep 17 00:00:00 2001 From: Gloomy Date: Wed, 20 Aug 2025 08:11:52 +0000 Subject: [PATCH] update for two-step system --- .../src/Controller/ApprovalController.php | 92 ++++++------------- hesabixCore/src/Controller/SellController.php | 4 +- .../src/Repository/HesabdariDocRepository.php | 16 ++-- webUI/src/views/acc/sell/list.vue | 20 ++-- .../src/views/acc/storeroom/io/ticketList.vue | 16 +++- 5 files changed, 63 insertions(+), 85 deletions(-) diff --git a/hesabixCore/src/Controller/ApprovalController.php b/hesabixCore/src/Controller/ApprovalController.php index f3814d8..5307646 100644 --- a/hesabixCore/src/Controller/ApprovalController.php +++ b/hesabixCore/src/Controller/ApprovalController.php @@ -50,7 +50,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'حواله انبار یافت نشد']); } - $canApprove = $this->canUserApproveStoreroomTicket($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'storeroom'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این حواله را ندارید']); } @@ -112,7 +112,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'حواله انبار یافت نشد']); } - $canApprove = $this->canUserApproveStoreroomTicket($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'storeroom'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این حواله را ندارید']); } @@ -174,7 +174,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'فاکتور فروش یافت نشد']); } - $canApprove = $this->canUserApproveSalesInvoice($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'sell'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این فاکتور را ندارید']); } @@ -240,7 +240,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'تأیید دو مرحله‌ای فعال نیست']); } - $canApprove = $this->canUserApproveSalesInvoice($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'sell'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این فاکتورها را ندارید']); } @@ -333,7 +333,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'فاکتور فروش یافت نشد']); } - $canApprove = $this->canUserApproveSalesInvoice($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'sell'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این فاکتور را ندارید']); } @@ -408,7 +408,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'فاکتور خرید یافت نشد']); } - $canApprove = $this->canUserApproveBuyInvoice($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'buy'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این فاکتور را ندارید']); } @@ -461,7 +461,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'تأیید دو مرحله‌ای فعال نیست']); } - $canApprove = $this->canUserApproveBuyInvoice($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'buy'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این فاکتورها را ندارید']); } @@ -489,7 +489,7 @@ class ApprovalController extends AbstractController $entityManager->persist($document); } - + $entityManager->flush(); $logService->insert( @@ -542,7 +542,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'فاکتور خرید یافت نشد']); } - $canApprove = $this->canUserApproveBuyInvoice($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'buy'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این فاکتور را ندارید']); } @@ -595,7 +595,7 @@ class ApprovalController extends AbstractController return $this->json(['success' => false, 'message' => 'تأیید دو مرحله‌ای فعال نیست']); } - $canApprove = $this->canUserApproveBuyInvoice($user, $businessSettings); + $canApprove = $this->canUserApproveDocument($user, $businessSettings, 'buy'); if (!$canApprove) { return $this->json(['success' => false, 'message' => 'شما مجوز تأیید این فاکتورها را ندارید']); } @@ -623,7 +623,7 @@ class ApprovalController extends AbstractController $entityManager->persist($document); } - + $entityManager->flush(); $logService->insert( @@ -646,67 +646,29 @@ class ApprovalController extends AbstractController } } - private function canUserApproveDocument(User $user, Business $business, HesabdariDoc $document): bool + private function canUserApproveDocument(User $user, Business $business, string $documentType): bool { if ($user->getEmail() === $business->getOwner()->getEmail()) { return true; } - $documentType = $this->getDocumentType($document); + $approversMap = [ + 'sell' => 'getApproverSellInvoice', + 'buy' => 'getApproverBuyInvoice', + 'storeroom' => 'getApproverWarehouseTransfer', + 'rfsell' => 'getApproverReturnSell', + 'rfbuy' => 'getApproverReturnBuy', + 'sell_receive' => 'getApproverReceiveFromPersons', + 'buy_send' => 'getApproverPayToPersons', + 'hesabdari' => 'getApproverAccountingDocs', + 'transfer' => 'getApproverBankTransfers', + ]; - switch ($documentType) { - case 'invoice': - return $business->getApproverSellInvoice() === $user->getEmail(); - case 'warehouse': - return $business->getApproverWarehouseTransfer() === $user->getEmail(); - default: - return false; - } - } - - private function getDocumentType(HesabdariDoc $document): string - { - $type = $document->getType(); - - if (strpos($type, 'sell') !== false || strpos($type, 'invoice') !== false) { - return 'invoice'; + if (!isset($approversMap[$documentType])) { + return false; } - if (strpos($type, 'warehouse') !== false || strpos($type, 'storeroom') !== false) { - return 'warehouse'; - } - - if (strpos($type, 'payment') !== false || strpos($type, 'receipt') !== false || strpos($type, 'hesabdari') !== false) { - return 'financial'; - } - - return 'unknown'; - } - - private function canUserApproveStoreroomTicket(User $user, Business $business): bool - { - if ($user->getEmail() === $business->getOwner()->getEmail()) { - return true; - } - - return $business->getApproverWarehouseTransfer() === $user->getEmail(); - } - - private function canUserApproveSalesInvoice(User $user, Business $business): bool - { - if ($user->getEmail() === $business->getOwner()->getEmail()) { - return true; - } - - return $business->getApproverSellInvoice() === $user->getEmail(); - } - - private function canUserApproveBuyInvoice(User $user, Business $business): bool - { - if ($user->getEmail() === $business->getOwner()->getEmail()) { - return true; - } - - return $business->getApproverBuyInvoice() === $user->getEmail(); + $method = $approversMap[$documentType]; + return $business->$method() === $user->getEmail(); } } diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index b14fecd..8c7a02f 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -45,7 +45,7 @@ class SellController extends AbstractController if (!$acc) throw $this->createAccessDeniedException(); - $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneByIncludePreview([ 'bid' => $acc['bid'], 'code' => $code, 'money' => $acc['money'] @@ -1431,7 +1431,7 @@ class SellController extends AbstractController throw $this->createAccessDeniedException(); } - $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneByIncludePreview([ 'bid' => $acc['bid'], 'year' => $acc['year'], 'code' => $id, diff --git a/hesabixCore/src/Repository/HesabdariDocRepository.php b/hesabixCore/src/Repository/HesabdariDocRepository.php index b993e18..2089da4 100644 --- a/hesabixCore/src/Repository/HesabdariDocRepository.php +++ b/hesabixCore/src/Repository/HesabdariDocRepository.php @@ -98,13 +98,13 @@ class HesabdariDocRepository extends ServiceEntityRepository { return $this->createQueryBuilder('h') ->andWhere('h.id = :id') - ->andWhere('(h.isApproved = 1 OR (h.isApproved = 0 AND h.isPreview = 0))') + ->andWhere('h.isApproved = 1') ->setParameter('id', $id) ->getQuery() ->getOneOrNullResult(); } - public function findOneBy(array $criteria, array $orderBy = null): ?object + public function findOneBy(array $criteria, ?array $orderBy = null): ?object { $qb = $this->createQueryBuilder('h'); @@ -116,7 +116,7 @@ class HesabdariDocRepository extends ServiceEntityRepository } } - $qb->andWhere('(h.isApproved = 1 OR (h.isApproved = 0 AND h.isPreview = 0))'); + $qb->andWhere('h.isApproved = 1'); if ($orderBy) { foreach ($orderBy as $field => $direction) { @@ -128,7 +128,7 @@ class HesabdariDocRepository extends ServiceEntityRepository } //include preview - public function findOneByIncludePreview(array $criteria, array $orderBy = null): ?object + public function findOneByIncludePreview(array $criteria, ?array $orderBy = null): ?object { $qb = $this->createQueryBuilder('h'); @@ -149,7 +149,7 @@ class HesabdariDocRepository extends ServiceEntityRepository return $qb->getQuery()->getOneOrNullResult(); } - public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array { $qb = $this->createQueryBuilder('h'); @@ -161,7 +161,7 @@ class HesabdariDocRepository extends ServiceEntityRepository } } - $qb->andWhere('(h.isApproved = 1 OR (h.isApproved = 0 AND h.isPreview = 0))'); + $qb->andWhere('h.isApproved = 1'); if ($orderBy) { foreach ($orderBy as $field => $direction) { @@ -183,13 +183,13 @@ class HesabdariDocRepository extends ServiceEntityRepository public function findAll(): array { return $this->createQueryBuilder('h') - ->andWhere('(h.isApproved = 1 OR (h.isApproved = 0 AND h.isPreview = 0))') + ->andWhere('h.isApproved = 1') ->getQuery() ->getResult(); } //include preview - public function findByIncludePreview(array $criteria, array $orderBy = null, $limit = null, $offset = null): array + public function findByIncludePreview(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array { $qb = $this->createQueryBuilder('h'); diff --git a/webUI/src/views/acc/sell/list.vue b/webUI/src/views/acc/sell/list.vue index 4ba6c9c..9e96e78 100755 --- a/webUI/src/views/acc/sell/list.vue +++ b/webUI/src/views/acc/sell/list.vue @@ -129,7 +129,7 @@ - -