From aaeb3cf31e7964b5e8ed3a7cbf97a6e952bb8ee0 Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Fri, 25 Jul 2025 17:12:20 +0000 Subject: [PATCH] progress and some bug fix in commodity,ai --- .../migrations/Version20241201000001.php | 29 + hesabixCore/src/Cog/CommodityService.php | 41 +- .../src/Controller/CommodityController.php | 30 +- hesabixCore/src/Entity/Commodity.php | 15 + hesabixCore/src/Service/Explore.php | 6 +- webUI/src/views/acc/commodity/mod.vue | 936 ++++++++++++------ webUI/src/views/acc/persons/insert.vue | 40 +- webUI/src/views/wizard/home.vue | 205 +++- 8 files changed, 940 insertions(+), 362 deletions(-) create mode 100644 hesabixCore/migrations/Version20241201000001.php diff --git a/hesabixCore/migrations/Version20241201000001.php b/hesabixCore/migrations/Version20241201000001.php new file mode 100644 index 0000000..6ad6989 --- /dev/null +++ b/hesabixCore/migrations/Version20241201000001.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE commodity ADD customCode TINYINT(1) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE commodity DROP customCode'); + } +} \ No newline at end of file diff --git a/hesabixCore/src/Cog/CommodityService.php b/hesabixCore/src/Cog/CommodityService.php index 5ddf79a..00fad2e 100644 --- a/hesabixCore/src/Cog/CommodityService.php +++ b/hesabixCore/src/Cog/CommodityService.php @@ -30,23 +30,62 @@ class CommodityService $em = $this->entityManager; if (!isset($params['name']) || trim($params['name']) === '') return ['result' => -1, 'error' => 'نام کالا الزامی است']; + if ($code == 0) { + // افزودن کالای جدید $data = $em->getRepository(Commodity::class)->findOneBy([ 'name' => $params['name'], 'bid' => $acc['bid'] ]); if (!$data) { $data = new Commodity(); - $data->setCode((new \App\Service\Provider($em))->getAccountingCode($acc['bid'], 'Commodity')); + + // بررسی کد سفارشی + if (isset($params['customCode']) && $params['customCode'] === true && isset($params['code'])) { + // بررسی تکراری نبودن کد سفارشی + $existingCommodity = $em->getRepository(Commodity::class)->findOneBy([ + 'code' => $params['code'], + 'bid' => $acc['bid'] + ]); + if ($existingCommodity) { + return ['result' => 2, 'error' => 'کد کالا تکراری است']; + } + $data->setCode($params['code']); + $data->setCustomCode(true); + } else { + // کد اتوماتیک + $data->setCode((new \App\Service\Provider($em))->getAccountingCode($acc['bid'], 'Commodity')); + $data->setCustomCode(false); + } } } else { + // ویرایش کالای موجود $data = $em->getRepository(Commodity::class)->findOneBy([ 'bid' => $acc['bid'], 'code' => $code ]); if (!$data) return ['result' => -2, 'error' => 'کالا یافت نشد']; + + // بررسی کد سفارشی در زمان ویرایش + if (isset($params['customCode']) && $params['customCode'] === true && isset($params['code'])) { + // بررسی تکراری نبودن کد سفارشی (به جز خود کالا) + $existingCommodity = $em->getRepository(Commodity::class)->findOneBy([ + 'code' => $params['code'], + 'bid' => $acc['bid'] + ]); + if ($existingCommodity && $existingCommodity->getId() !== $data->getId()) { + return ['result' => 2, 'error' => 'کد کالا تکراری است']; + } + $data->setCode($params['code']); + $data->setCustomCode(true); + } elseif (isset($params['customCode']) && $params['customCode'] === false) { + // تغییر به کد اتوماتیک + $data->setCode((new \App\Service\Provider($em))->getAccountingCode($acc['bid'], 'Commodity')); + $data->setCustomCode(false); + } } + $unit = null; if (!isset($params['unit'])) $unit = $em->getRepository(CommodityUnit::class)->findAll()[0]; diff --git a/hesabixCore/src/Controller/CommodityController.php b/hesabixCore/src/Controller/CommodityController.php index aa60d79..fe897d4 100644 --- a/hesabixCore/src/Controller/CommodityController.php +++ b/hesabixCore/src/Controller/CommodityController.php @@ -267,6 +267,7 @@ class CommodityController extends AbstractController $temp['taxCode'] = $item->getTaxCode(); $temp['taxType'] = $item->getTaxType(); $temp['taxUnit'] = $item->getTaxUnit(); + $temp['customCode'] = $item->isCustomCode(); //calculate count if ($item->isKhadamat()) { $temp['count'] = 0; @@ -334,6 +335,7 @@ class CommodityController extends AbstractController $temp['taxCode'] = $item->getTaxCode(); $temp['taxType'] = $item->getTaxType(); $temp['taxUnit'] = $item->getTaxUnit(); + $temp['customCode'] = $item->isCustomCode(); //calculate count if ($item->isKhadamat()) { $temp['count'] = 0; @@ -429,6 +431,7 @@ class CommodityController extends AbstractController $temp['taxCode'] = $item->getTaxCode(); $temp['taxType'] = $item->getTaxType(); $temp['taxUnit'] = $item->getTaxUnit(); + $temp['customCode'] = $item->isCustomCode(); //calculate count if ($item->isKhadamat()) { $temp['count'] = 0; @@ -528,7 +531,8 @@ class CommodityController extends AbstractController $temp[] = $item->getMinOrderCount(); $temp[] = $item->getDes(); $temp[] = $item->getUnit()->getName(); - $temp[] = $item->getCat()->getName(); + $cat = $item->getCat(); + $temp[] = $cat ? $cat->getName() : ''; $array[] = $temp; } $filePath = $provider->createExcellFromArray($array, [ @@ -604,20 +608,28 @@ class CommodityController extends AbstractController return $this->json(['id' => $pid]); } - #[Route('/api/commodity/info/{code}', name: 'app_commodity_info')] - public function app_commodity_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + #[Route('/api/commodity/info/{id}', name: 'app_commodity_info')] + public function app_commodity_info($id, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('commodity'); if (!$acc) throw $this->createAccessDeniedException(); $data = $entityManager->getRepository(Commodity::class)->findOneBy([ 'bid' => $acc['bid'], - 'code' => $code + 'code' => $id ]); + + if (!$data) { + return $this->json(['error' => 'کالا یافت نشد'], 404); + } + $res = Explore::ExploreCommodity($data); $res['cat'] = ''; - if ($data->getCat()) - $res['cat'] = $data->getCat()->getId(); + $cat = $data->getCat(); + if ($cat !== null) { + $res['cat'] = $cat->getId(); + } + $res['customCode'] = $data->isCustomCode(); $count = 0; //calculate count if ($data->isKhadamat()) { @@ -813,8 +825,8 @@ class CommodityController extends AbstractController 'result' => 1, ]); } - #[Route('/api/commodity/mod/{code}', name: 'app_commodity_mod')] - public function app_commodity_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse + #[Route('/api/commodity/mod/{id}', name: 'app_commodity_mod')] + public function app_commodity_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $id = 0): JsonResponse { $acc = $access->hasRole('commodity'); if (!$acc) @@ -824,7 +836,7 @@ class CommodityController extends AbstractController $params = json_decode($content, true); } $commodityService = new \App\Cog\CommodityService($entityManager); - $result = $commodityService->addOrUpdateCommodity($params, $acc, $code); + $result = $commodityService->addOrUpdateCommodity($params, $acc, $id); if (isset($result['error'])) { return $this->json($result, 400); } diff --git a/hesabixCore/src/Entity/Commodity.php b/hesabixCore/src/Entity/Commodity.php index b89dcd4..924dbdc 100644 --- a/hesabixCore/src/Entity/Commodity.php +++ b/hesabixCore/src/Entity/Commodity.php @@ -36,6 +36,9 @@ class Commodity #[ORM\Column(type: 'bigint')] private $code; + #[ORM\Column(nullable: true)] + private ?bool $customCode = null; + #[ORM\Column(type: 'string', length: 255, nullable: true)] private $priceBuy; @@ -178,6 +181,18 @@ class Commodity return $this; } + public function isCustomCode(): ?bool + { + return $this->customCode; + } + + public function setCustomCode(?bool $customCode): static + { + $this->customCode = $customCode; + + return $this; + } + public function getPriceBuy(): ?int { return $this->priceBuy; diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 15444be..baf0542 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -236,6 +236,7 @@ class Explore 'taxCode' => $item->getTaxCode(), 'taxType' => $item->getTaxType(), 'taxUnit' => $item->getTaxUnit(), + 'customCode' => $item->isCustomCode(), 'unitData' => [ 'name' => $item->getUnit()->getName(), 'floatNumber' => $item->getUnit()->getFloatNumber(), @@ -245,8 +246,9 @@ class Explore if ($des) { $result['des'] = $des; } - if ($item->getCat()) { - $result['cat'] = $item->getCat()->getName(); + $cat = $item->getCat(); + if ($cat !== null) { + $result['cat'] = $cat->getName(); } return $result; } diff --git a/webUI/src/views/acc/commodity/mod.vue b/webUI/src/views/acc/commodity/mod.vue index c8a5b35..be58935 100755 --- a/webUI/src/views/acc/commodity/mod.vue +++ b/webUI/src/views/acc/commodity/mod.vue @@ -9,341 +9,470 @@ - + + + mdi-content-save - - - + + + - + + + + + کد کالا + + + + + + + + + + + + + + + + + + + + اطلاعات اصلی کالا/خدمات + + + + + + + + کالا + + + خدمات + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + تنظیمات + + + + + + + + + + + + + + + + + بارکدها + -
-
-
- -
- - -
-
- - -
-
-
-
-
-
- - -
-
-
-
-
-
-
- - -
-
-
-
- - -
-
-
- دسته بندی - -
-
- - + + + + - - - -
-
-
- - -
-
- -
+ + +
+ + + +
+ + - - -
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
+ + + + قیمت‌ها + + + + + + + + + + + + +
+ + - - -
- موجودی کالا - -
-
- - -
-
-
-
-
- + + + موجودی کالا + + + + + تنظیمات بخش موجودی کالا تنها برای نوع کالا اعمال می‌شود و برای نوع خدمات نادیده گرفته می‌شود. + + + + + + + - -
-
-
-
- - -
-
-
-
- - -
-
-
-
+ @keypress="this.$filters.onlyNumber($event)" + > + + + + + + + +
+ + - - -
-
-
- - -
-
-
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
+ + + + اطلاعات مالیاتی + + + + + + + + + + + + +
- - +