From c2bb80099e2d6b71761f0c907525578a204ba937 Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Thu, 13 Jun 2024 15:01:57 +0330 Subject: [PATCH] almost finish sell part and bug fix --- .../src/Controller/HesabdariController.php | 110 +++++++++++++++++- .../src/Controller/PersonsController.php | 33 ++++++ hesabixCore/src/Controller/SellController.php | 12 +- hesabixCore/src/Service/Explore.php | 12 +- 4 files changed, 158 insertions(+), 9 deletions(-) diff --git a/hesabixCore/src/Controller/HesabdariController.php b/hesabixCore/src/Controller/HesabdariController.php index e814a84..a431922 100644 --- a/hesabixCore/src/Controller/HesabdariController.php +++ b/hesabixCore/src/Controller/HesabdariController.php @@ -503,7 +503,15 @@ class HesabdariController extends AbstractController foreach ($items as $item) $entityManager->remove($item); $entityManager->remove($relatedDoc); - $log->insert('حسابداری', 'سند حسابداری شماره ' . $relatedDoc->getCode() . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid')); + $logs = $entityManager->getRepository(EntityLog::class)->findBy(['doc' => $relatedDoc]); + foreach ($logs as $item) { + $item->setDoc(null); + $entityManager->persist($item); + $entityManager->flush(); + } + $code = $doc->getCode(); + $entityManager->remove($relatedDoc); + $log->insert('حسابداری', 'سند حسابداری شماره ' . $code . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid')); } } @@ -514,9 +522,107 @@ class HesabdariController extends AbstractController $entityManager->persist($item); $entityManager->flush(); } + $code = $doc->getCode(); $entityManager->remove($doc); $entityManager->flush(); - $log->insert('حسابداری', 'سند حسابداری شماره ' . $doc->getCode() . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid')); + $log->insert('حسابداری', 'سند حسابداری شماره ' . $code . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid')); + return $this->json(['result' => 1]); + } + + #[Route('/api/accounting/remove/group', name: 'app_accounting_remove_doc_group')] + public function app_accounting_remove_doc_group(Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if (!array_key_exists('items', $params)) + $this->createNotFoundException(); + foreach($params['items'] as $item){ + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'code' => $item['code'], + 'bid' => $request->headers->get('activeBid') + ]); + if (!$doc) throw $this->createNotFoundException(); + $roll = ''; + if ($doc->getType() == 'person_receive' || $doc->getType() == 'person_send') $roll = 'person'; + elseif ($doc->getType() == 'sell_receive') $roll = 'sell'; + elseif ($doc->getType() == 'buy_send') $roll = 'buy'; + else + $roll = $doc->getType(); + $acc = $access->hasRole($roll); + if (!$acc) + throw $this->createAccessDeniedException(); + $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'doc' => $doc + ]); + if ($doc->getPlugin() == 'plugNoghreOrder') { + $order = $entityManager->getRepository(PlugNoghreOrder::class)->findOneBy([ + 'doc' => $doc + ]); + if ($order) + $entityManager->remove($order); + } + //check wallet online transactions + $tempPays = $entityManager->getRepository(PayInfoTemp::class)->findOneBy(['doc' => $doc]); + if ($tempPays) { + //doc has transaction + return $this->json([ + 'result' => 2, + 'message' => 'سند به دلیل داشتن تراکنش پرداخت آنلاین قابل حذف نیست.' + ]); + } + //check storeroom tickets + $tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc' => $doc]); + foreach ($tickets as $ticket) + $entityManager->remove($ticket); + //remove rows and check sub systems + foreach ($rows as $row) { + if ($row->getCheque()) { + if ($row->getCheque()->isLocked()) { + //doc has transaction + return $this->json([ + 'result' => 2, + 'message' => 'سند به دلیل داشتن تراکنش مرتبط با چک بانکی قابل حذف نیست.' + ]); + } + $log->insert('بانکداری', 'چک شماره شماره ' . $row->getCheque()->getNumber() . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid')); + $entityManager->remove($row->getCheque()); + } + $entityManager->remove($row); + } + + foreach ($doc->getRelatedDocs() as $relatedDoc) { + if ($relatedDoc->getType() != 'walletPay') { + $items = $entityManager->getRepository(HesabdariRow::class)->findBy(['doc' => $relatedDoc]); + foreach ($items as $item) + $entityManager->remove($item); + $entityManager->remove($relatedDoc); + $logs = $entityManager->getRepository(EntityLog::class)->findBy(['doc' => $relatedDoc]); + foreach ($logs as $item) { + $item->setDoc(null); + $entityManager->persist($item); + $entityManager->flush(); + } + $code = $doc->getCode(); + $entityManager->remove($relatedDoc); + $log->insert('حسابداری', 'سند حسابداری شماره ' . $code . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid')); + } + } + + //delete logs from documents + $logs = $entityManager->getRepository(EntityLog::class)->findBy(['doc' => $doc]); + foreach ($logs as $item) { + $item->setDoc(null); + $entityManager->persist($item); + $entityManager->flush(); + } + $code = $doc->getCode(); + $entityManager->remove($doc); + $entityManager->flush(); + $log->insert('حسابداری', 'سند حسابداری شماره ' . $code . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid')); + + } return $this->json(['result' => 1]); } diff --git a/hesabixCore/src/Controller/PersonsController.php b/hesabixCore/src/Controller/PersonsController.php index b23f445..3e22643 100644 --- a/hesabixCore/src/Controller/PersonsController.php +++ b/hesabixCore/src/Controller/PersonsController.php @@ -11,6 +11,9 @@ use App\Entity\HesabdariDoc; use App\Entity\HesabdariRow; use App\Entity\PersonCard; use App\Entity\PersonType; +use App\Entity\Storeroom; +use App\Entity\StoreroomItem; +use App\Entity\StoreroomTicket; use App\Service\Explore; use Doctrine\ORM\EntityManagerInterface; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -984,4 +987,34 @@ class PersonsController extends AbstractController $log->insert('اشخاص', 'تعداد ' . count($data) . ' شخص به صورت گروهی وارد شد.', $this->getUser(), $request->headers->get('activeBid')); return $this->json(['result' => 1]); } + + #[Route('/api/person/delete/{code}', name: 'app_person_delete')] + public function app_person_delete(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse + { + $acc = $access->hasRole('person'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $person = $entityManager->getRepository(Person::class)->findOneBy(['bid' => $acc['bid'], 'code' => $code]); + if (!$person) + throw $this->createNotFoundException(); + //check accounting docs + $docs = $entityManager->getRepository(HesabdariRow::class)->findby(['bid' => $acc['bid'], 'person' => $person]); + if (count($docs) > 0) + return $this->json(['result' => 2]); + //check for storeroom docs + $storeDocs = $entityManager->getRepository(StoreroomTicket::class)->findby(['bid' => $acc['bid'], 'Person' => $person]); + if (count($storeDocs) > 0) + return $this->json(['result' => 2]); + //check in repservice + + $comName = $person->getName(); + try { + $entityManager->remove($person); + } catch (Exception $e) { + return $this->json(['result' => 2]); + } + $log->insert('کالا/خدمات', ' شخص با نام ' . $comName . ' حذف شد. ', $this->getUser(), $acc['bid']->getId()); + return $this->json(['result' => 1]); + } } diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index a2b2790..c5ca027 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -162,7 +162,7 @@ class SellController extends AbstractController $entityManager->persist($hesabdariRow); } //set amount of document - $doc->setAmount($sumTax + $sumTotal); + $doc->setAmount($sumTax + $sumTotal - $params['discountAll'] + $params['transferCost']); //set person buyer $hesabdariRow = new HesabdariRow(); $hesabdariRow->setDes('فاکتور فروش'); @@ -299,6 +299,16 @@ class SellController extends AbstractController $pays += $relatedDoc->getAmount(); } $temp['relatedDocsPays'] = $pays; + + foreach ($item->getHesabdariRows() as $item) { + if ($item->getRef()->getCode() == '104') { + $temp['discountAll'] = $item->getBd(); + } elseif ($item->getRef()->getCode() == '61') { + $temp['transferCost'] = $item->getBs(); + } + } + if(!array_key_exists('discountAll',$temp)) $temp['discountAll'] = 0; + if(!array_key_exists('transferCost',$temp)) $temp['transferCost'] = 0; $dataTemp[] = $temp; } return $this->json($dataTemp); diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 16a7f02..55d1ce7 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -39,18 +39,18 @@ class Explore { $result = self::ExploreHesabdariDoc($hesabdariDoc); $person = []; - $comms = []; foreach ($hesabdariDoc->getHesabdariRows() as $item) { if ($item->getPerson()) { $person = self::ExplorePerson($item->getPerson()); } - elseif($item->getCommodity()){ - $comms[] = self::ExploreHesabdariRow($item); - } - elseif($item->getRef()->getCode() == '53'){ + elseif($item->getRef()->getCode() == '104'){ $result['discountAll'] = $item->getBd(); + } elseif ($item->getRef()->getCode() == '61') { + $result['transferCost'] = $item->getBs(); } } + if (!array_key_exists('discountAll', $result)) $result['discountAll'] = 0; + if (!array_key_exists('transferCost', $result)) $result['transferCost'] = 0; $result['person'] = $person; return $result; } @@ -156,7 +156,7 @@ class Explore return $temp; } - public static function ExploreCommodity(Commodity | null $item, int | null $count = 0, string $des = '') + public static function ExploreCommodity(Commodity | null $item, int | null $count = 0, string | null $des = '') { if ($item) return [