From ddbbf1f102281e1ec6366afc483c989626d037fb Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Fri, 11 Jul 2025 06:56:42 +0000 Subject: [PATCH] merge upper in commodity cat with pos app --- .../src/Controller/CommodityController.php | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/hesabixCore/src/Controller/CommodityController.php b/hesabixCore/src/Controller/CommodityController.php index e2c2d4c0..f7ba64ed 100644 --- a/hesabixCore/src/Controller/CommodityController.php +++ b/hesabixCore/src/Controller/CommodityController.php @@ -143,7 +143,8 @@ class CommodityController extends AbstractController $count += $row->getCommdityCount(); } else { $count -= $row->getCommdityCount(); - } } + } + } $temp['count'] = $count; } return $temp; @@ -1071,17 +1072,41 @@ class CommodityController extends AbstractController if ($content = $request->getContent()) { $params = json_decode($content, true); } - if (!array_key_exists('upper', $params) || !array_key_exists('text', $params)) + + if (!array_key_exists('text', $params)) return $this->json(['result' => -1]); - + if ($this->isDefaultCategoryName($params['text'])) { return $this->json([ - 'result' => 4, + 'result' => 4, 'message' => 'این نام برای دسته‌بندی مجاز نیست', 'errorCode' => 'DEFAULT_CATEGORY_NAME' ]); } - + if (!array_key_exists('upper', $params)) { + $upper = $entityManager->getRepository(CommodityCat::class)->findOneBy([ + 'upper' => null, + 'bid' => $acc['bid'] + ]); + if (!$upper) { + $upper = new CommodityCat(); + $upper->setBid($acc['bid']); + $upper->setUpper(null); + $upper->setName('دسته بندی ها'); + $upper->setRoot(true); + $entityManager->persist($upper); + $entityManager->flush(); + } + $cat = new CommodityCat(); + $cat->setBid($acc['bid']); + $cat->setRoot(false); + $cat->setName($params['text']); + $cat->setUpper($upper->getId()); + $entityManager->persist($cat); + $entityManager->flush(); + return $this->json(['result' => 1, 'id' => $cat->getId()]); + } + $upper = $entityManager->getRepository(CommodityCat::class)->find($params['upper']); if ($upper) { if ($upper->getBid() == $acc['bid']) { @@ -1109,22 +1134,22 @@ class CommodityController extends AbstractController } if (!array_key_exists('id', $params) || !array_key_exists('text', $params)) return $this->json(['result' => -1]); - + if ($this->isDefaultCategoryName($params['text'])) { return $this->json([ - 'result' => 4, + 'result' => 4, 'message' => 'این نام برای دسته‌بندی مجاز نیست', 'errorCode' => 'DEFAULT_CATEGORY_NAME' ]); } - + $node = $entityManager->getRepository(CommodityCat::class)->find($params['id']); if ($node) { if ($node->getBid() == $acc['bid']) { // بررسی دسته‌بندی پیش‌فرض if ($this->isDefaultCategoryName($node->getName())) { return $this->json([ - 'result' => 4, + 'result' => 4, 'message' => 'ویرایش دسته‌بندی پیش‌فرض مجاز نیست', 'errorCode' => 'DEFAULT_CATEGORY_EDIT' ]); @@ -1588,7 +1613,7 @@ class CommodityController extends AbstractController // بررسی دسته‌بندی پیش‌فرض if ($this->isDefaultCategoryName($category->getName())) { return $this->json([ - 'Success' => false, + 'Success' => false, 'message' => 'حذف دسته‌بندی پیش‌فرض مجاز نیست', 'errorCode' => 'DEFAULT_CATEGORY_DELETE' ], 400);