merge upper in commodity cat with pos app

This commit is contained in:
Hesabix 2025-07-11 06:56:42 +00:00
parent dddc648a1f
commit ddbbf1f102

View file

@ -143,7 +143,8 @@ class CommodityController extends AbstractController
$count += $row->getCommdityCount(); $count += $row->getCommdityCount();
} else { } else {
$count -= $row->getCommdityCount(); $count -= $row->getCommdityCount();
} } }
}
$temp['count'] = $count; $temp['count'] = $count;
} }
return $temp; return $temp;
@ -1071,17 +1072,41 @@ class CommodityController extends AbstractController
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $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]); return $this->json(['result' => -1]);
if ($this->isDefaultCategoryName($params['text'])) { if ($this->isDefaultCategoryName($params['text'])) {
return $this->json([ return $this->json([
'result' => 4, 'result' => 4,
'message' => 'این نام برای دسته‌بندی مجاز نیست', 'message' => 'این نام برای دسته‌بندی مجاز نیست',
'errorCode' => 'DEFAULT_CATEGORY_NAME' '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']); $upper = $entityManager->getRepository(CommodityCat::class)->find($params['upper']);
if ($upper) { if ($upper) {
if ($upper->getBid() == $acc['bid']) { if ($upper->getBid() == $acc['bid']) {
@ -1109,22 +1134,22 @@ class CommodityController extends AbstractController
} }
if (!array_key_exists('id', $params) || !array_key_exists('text', $params)) if (!array_key_exists('id', $params) || !array_key_exists('text', $params))
return $this->json(['result' => -1]); return $this->json(['result' => -1]);
if ($this->isDefaultCategoryName($params['text'])) { if ($this->isDefaultCategoryName($params['text'])) {
return $this->json([ return $this->json([
'result' => 4, 'result' => 4,
'message' => 'این نام برای دسته‌بندی مجاز نیست', 'message' => 'این نام برای دسته‌بندی مجاز نیست',
'errorCode' => 'DEFAULT_CATEGORY_NAME' 'errorCode' => 'DEFAULT_CATEGORY_NAME'
]); ]);
} }
$node = $entityManager->getRepository(CommodityCat::class)->find($params['id']); $node = $entityManager->getRepository(CommodityCat::class)->find($params['id']);
if ($node) { if ($node) {
if ($node->getBid() == $acc['bid']) { if ($node->getBid() == $acc['bid']) {
// بررسی دسته‌بندی پیش‌فرض // بررسی دسته‌بندی پیش‌فرض
if ($this->isDefaultCategoryName($node->getName())) { if ($this->isDefaultCategoryName($node->getName())) {
return $this->json([ return $this->json([
'result' => 4, 'result' => 4,
'message' => 'ویرایش دسته‌بندی پیش‌فرض مجاز نیست', 'message' => 'ویرایش دسته‌بندی پیش‌فرض مجاز نیست',
'errorCode' => 'DEFAULT_CATEGORY_EDIT' 'errorCode' => 'DEFAULT_CATEGORY_EDIT'
]); ]);
@ -1588,7 +1613,7 @@ class CommodityController extends AbstractController
// بررسی دسته‌بندی پیش‌فرض // بررسی دسته‌بندی پیش‌فرض
if ($this->isDefaultCategoryName($category->getName())) { if ($this->isDefaultCategoryName($category->getName())) {
return $this->json([ return $this->json([
'Success' => false, 'Success' => false,
'message' => 'حذف دسته‌بندی پیش‌فرض مجاز نیست', 'message' => 'حذف دسته‌بندی پیش‌فرض مجاز نیست',
'errorCode' => 'DEFAULT_CATEGORY_DELETE' 'errorCode' => 'DEFAULT_CATEGORY_DELETE'
], 400); ], 400);