diff --git a/hesabixCore/src/Controller/BusinessController.php b/hesabixCore/src/Controller/BusinessController.php index 066f565..33272de 100644 --- a/hesabixCore/src/Controller/BusinessController.php +++ b/hesabixCore/src/Controller/BusinessController.php @@ -236,8 +236,12 @@ class BusinessController extends AbstractController $year->setBid($business); $year->setHead(true); $startYearArray = explode('-', $params['year']['start']); + if(count($startYearArray) == 1) $startYearArray = explode('/', $params['year']['start']); + $year->setStart($jdate->jmktime(0, 0, 0, $startYearArray[1], $startYearArray[2], $startYearArray[0])); $endYearArray = explode('-', $params['year']['end']); + if(count($endYearArray) == 1) $startYearArray = explode('/', $params['year']['end']); + $year->setEnd($jdate->jmktime(0, 0, 0, $endYearArray[1], $endYearArray[2], $endYearArray[0])); $year->setLabel($params['year']['label']); $entityManager->persist($year); @@ -248,9 +252,13 @@ class BusinessController extends AbstractController 'bid' => $business, 'head' => true ]); + $startYearArray = explode('-', $params['year']['startShamsi']); + if(count($startYearArray) == 1) $startYearArray = explode('/', $params['year']['startShamsi']); + $year->setStart($jdate->jmktime(0, 0, 0, $startYearArray[1], $startYearArray[2], $startYearArray[0])); $endYearArray = explode('-', $params['year']['endShamsi']); + if(count($endYearArray) == 1) $endYearArray = explode('/', $params['year']['endShamsi']); $year->setEnd($jdate->jmktime(0, 0, 0, $endYearArray[1], $endYearArray[2], $endYearArray[0])); $year->setLabel($params['year']['label']); $entityManager->persist($year); diff --git a/hesabixCore/src/Controller/CommodityController.php b/hesabixCore/src/Controller/CommodityController.php index 392c1b2..665d56b 100644 --- a/hesabixCore/src/Controller/CommodityController.php +++ b/hesabixCore/src/Controller/CommodityController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\Entity\PriceListDetail; use App\Service\Explore; use App\Service\Log; use App\Service\Jdate; @@ -14,6 +15,7 @@ use App\Entity\CommodityCat; use App\Entity\HesabdariRow; use App\Entity\CommodityDrop; use App\Entity\CommodityUnit; +use App\Entity\PriceList; use App\Entity\StoreroomItem; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; @@ -240,8 +242,7 @@ class CommodityController extends AbstractController 'bid' => $acc['bid'], 'code' => $code ]); - $data->setUnit($data->getUnit()->getName()); - $res = $provider->Entity2ArrayJustIncludes($data, ['isSpeedAccess', 'isCommodityCountCheck', 'getName', 'getUnit', 'getPriceBuy', 'getPriceSell', 'getCat', 'getOrderPoint', 'getdes', 'getId', 'getDayLoading', 'isKhadamat', 'getCode', 'getMinOrderCount', 'getLabel', 'isWithoutTax','getBarcodes'], 1); + $res = Explore::ExploreCommodity($data); $res['cat'] = ''; if ($data->getCat()) $res['cat'] = $data->getCat()->getId(); @@ -337,6 +338,28 @@ class CommodityController extends AbstractController } } $entityManager->persist($data); + if (array_key_exists('prices', $params)) { + foreach ($params['prices'] as $item) { + $priceList = $entityManager->getRepository(PriceList::class)->findOneBy([ + 'bid' => $acc['bid'], + 'id' => $item['list']['id'] + ]); + if ($priceList) { + $detail = $entityManager->getRepository(PriceListDetail::class)->findOneBy([ + 'list' => $priceList, + ]); + if (!$detail) { + $detail = new PriceListDetail; + } + $detail->setList($priceList); + $detail->setCommodity($data); + $detail->setPriceSell($item['priceSell']); + $detail->setPriceBuy(0); + $detail->setMoney($acc['bid']->getMoney()); + $entityManager->persist($detail); + } + } + } $entityManager->flush(); $log->insert('کالا و خدمات', 'کالا / خدمات با نام ' . $params['name'] . ' افزوده/ویرایش شد.', $this->getUser(), $request->headers->get('activeBid')); return $this->json(['result' => 1]); @@ -699,4 +722,88 @@ class CommodityController extends AbstractController $log->insert('کالا/خدمات', ' کالا / خدمات با نام ' . $comName . ' حذف شد. ', $this->getUser(), $acc['bid']->getId()); return $this->json(['result' => 1]); } + + #[Route('/api/commodity/pricelist/list', name: 'app_commodity_pricelist_list')] + public function app_commodity_pricelist_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('commodity'); + if (!$acc) + throw $this->createAccessDeniedException(); + $items = $entityManager->getRepository(PriceList::class)->findBy([ + 'bid' => $acc['bid'] + ]); + return $this->json(Explore::ExploreCommodityPriceList($items)); + } + + #[Route('/api/commodity/pricelist/mod/{code}', name: 'app_commodity_pricelist_mod')] + public function app_commodity_pricelist_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse + { + $acc = $access->hasRole('commodity'); + if (!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if (!array_key_exists('label', $params)) + return $this->json(['result' => -1]); + if (count_chars(trim($params['label'])) == 0) + return $this->json(['result' => 3]); + if ($code == 0) { + $data = $entityManager->getRepository(PriceList::class)->findOneBy([ + 'label' => $params['label'], + 'bid' => $acc['bid'] + ]); + //check exist before + if ($data) + return $this->json(['result' => 2]); + $data = new PriceList(); + } else { + $data = $entityManager->getRepository(PriceList::class)->findOneBy([ + 'bid' => $acc['bid'], + 'id' => $code + ]); + if (!$data) + throw $this->createNotFoundException(); + } + $data->setLabel($params['label']); + $data->setBid($acc['bid']); + $entityManager->persist($data); + $entityManager->flush(); + $log->insert('کالا و خدمات', 'فهرست قیمت کالا / خدمات با نام ' . $params['label'] . ' افزوده/ویرایش شد.', $this->getUser(), $request->headers->get('activeBid')); + return $this->json(['result' => 1]); + } + + /** + * @throws \ReflectionException + */ + #[Route('/api/commodity/pricelist/info/{code}', name: 'app_commodity_pricelist_info')] + public function app_commodity_pricelist_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('commodity'); + if (!$acc) + throw $this->createAccessDeniedException(); + $data = $entityManager->getRepository(PriceList::class)->findOneBy([ + 'bid' => $acc['bid'], + 'id' => $code + ]); + return $this->json($provider->Entity2Array($data, 0)); + } + + #[Route('/api/commodity/pricelist/delete/{code}', name: 'app_commodity_pricelist_delete')] + public function app_commodity_pricelist_delete(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse + { + $acc = $access->hasRole('commodity'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $item = $entityManager->getRepository(PriceList::class)->findOneBy(['bid' => $acc['bid'], 'id' => $code]); + if (!$item) + throw $this->createNotFoundException(); + + $comName = $item->getLabel(); + $entityManager->remove($item); + $log->insert('کالا/خدمات', 'فهرست قیمت کالا و خدمات با نام ' . $comName . ' حذف شد. ', $this->getUser(), $acc['bid']->getId()); + return $this->json(['result' => 1]); + } } diff --git a/hesabixCore/src/Controller/PersonsController.php b/hesabixCore/src/Controller/PersonsController.php index ee1c19c..157b90d 100644 --- a/hesabixCore/src/Controller/PersonsController.php +++ b/hesabixCore/src/Controller/PersonsController.php @@ -646,7 +646,7 @@ class PersonsController extends AbstractController #[Route('/api/person/card/list/print', name: 'app_persons_card_list_print')] public function app_persons_card_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { - $acc = $access->hasRole('person_receive'); + $acc = $access->hasRole('person'); if (!$acc) throw $this->createAccessDeniedException(); $params = []; @@ -693,7 +693,7 @@ class PersonsController extends AbstractController #[Route('/api/person/receive/list/print', name: 'app_persons_receive_list_print')] public function app_persons_receive_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { - $acc = $access->hasRole('person_receive'); + $acc = $access->hasRole('getpay'); if (!$acc) throw $this->createAccessDeniedException(); $params = []; @@ -734,7 +734,7 @@ class PersonsController extends AbstractController #[Route('/api/person/receive/list/search', name: 'app_persons_receive_list_search')] public function app_persons_receive_list_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { - $acc = $access->hasRole('person_receive'); + $acc = $access->hasRole('getpay'); if (!$acc) throw $this->createAccessDeniedException(); $params = []; @@ -778,7 +778,7 @@ class PersonsController extends AbstractController #[Route('/api/person/receive/list/excel', name: 'app_persons_receive_list_excel')] public function app_persons_receive_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse { - $acc = $access->hasRole('person_receive'); + $acc = $access->hasRole('getpay'); if (!$acc) throw $this->createAccessDeniedException(); $params = []; @@ -810,7 +810,7 @@ class PersonsController extends AbstractController #[Route('/api/person/send/list/print', name: 'app_persons_send_list_print')] public function app_persons_send_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { - $acc = $access->hasRole('person_send'); + $acc = $access->hasRole('getpay'); if (!$acc) throw $this->createAccessDeniedException(); $params = []; @@ -851,7 +851,7 @@ class PersonsController extends AbstractController #[Route('/api/person/send/list/search', name: 'app_persons_send_list_search')] public function app_persons_send_list_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { - $acc = $access->hasRole('person_send'); + $acc = $access->hasRole('getpay'); if (!$acc) throw $this->createAccessDeniedException(); $params = []; @@ -895,7 +895,7 @@ class PersonsController extends AbstractController #[Route('/api/person/send/list/excel', name: 'app_persons_send_list_excel')] public function app_persons_send_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse { - $acc = $access->hasRole('person_send'); + $acc = $access->hasRole('getpay'); if (!$acc) throw $this->createAccessDeniedException(); $params = []; diff --git a/hesabixCore/src/Entity/Business.php b/hesabixCore/src/Entity/Business.php index ee0e2b2..462ce60 100644 --- a/hesabixCore/src/Entity/Business.php +++ b/hesabixCore/src/Entity/Business.php @@ -228,6 +228,9 @@ class Business #[ORM\OneToMany(mappedBy: 'bid', targetEntity: Note::class, orphanRemoval: true)] private Collection $notes; + #[ORM\OneToMany(mappedBy: 'bid', targetEntity: PriceList::class, orphanRemoval: true)] + private Collection $priceLists; + public function __construct() { $this->logs = new ArrayCollection(); @@ -260,6 +263,7 @@ class Business $this->printers = new ArrayCollection(); $this->printTemplates = new ArrayCollection(); $this->notes = new ArrayCollection(); + $this->priceLists = new ArrayCollection(); } public function getId(): ?int @@ -1622,4 +1626,34 @@ class Business return $this; } + + /** + * @return Collection + */ + public function getPriceLists(): Collection + { + return $this->priceLists; + } + + public function addPriceList(PriceList $priceList): static + { + if (!$this->priceLists->contains($priceList)) { + $this->priceLists->add($priceList); + $priceList->setBid($this); + } + + return $this; + } + + public function removePriceList(PriceList $priceList): static + { + if ($this->priceLists->removeElement($priceList)) { + // set the owning side to null (unless already changed) + if ($priceList->getBid() === $this) { + $priceList->setBid(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/Commodity.php b/hesabixCore/src/Entity/Commodity.php index 1abc863..591777a 100644 --- a/hesabixCore/src/Entity/Commodity.php +++ b/hesabixCore/src/Entity/Commodity.php @@ -83,6 +83,9 @@ class Commodity #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $barcodes = null; + #[ORM\OneToMany(mappedBy: 'commodity', targetEntity: PriceListDetail::class, orphanRemoval: true)] + private Collection $priceListDetails; + public function __construct() { $this->setPriceBuy(0); @@ -91,6 +94,7 @@ class Commodity $this->commodityDropLinks = new ArrayCollection(); $this->storeroomItems = new ArrayCollection(); $this->plugRepserviceOrders = new ArrayCollection(); + $this->priceListDetails = new ArrayCollection(); } public function getId(): ?int @@ -409,4 +413,34 @@ class Commodity return $this; } + + /** + * @return Collection + */ + public function getPriceListDetails(): Collection + { + return $this->priceListDetails; + } + + public function addPriceListDetail(PriceListDetail $priceListDetail): static + { + if (!$this->priceListDetails->contains($priceListDetail)) { + $this->priceListDetails->add($priceListDetail); + $priceListDetail->setCommodity($this); + } + + return $this; + } + + public function removePriceListDetail(PriceListDetail $priceListDetail): static + { + if ($this->priceListDetails->removeElement($priceListDetail)) { + // set the owning side to null (unless already changed) + if ($priceListDetail->getCommodity() === $this) { + $priceListDetail->setCommodity(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/Money.php b/hesabixCore/src/Entity/Money.php index b84589e..bf4034f 100644 --- a/hesabixCore/src/Entity/Money.php +++ b/hesabixCore/src/Entity/Money.php @@ -24,9 +24,13 @@ class Money #[ORM\OneToMany(mappedBy: 'money', targetEntity: Business::class, orphanRemoval: true)] private Collection $businesses; + #[ORM\OneToMany(mappedBy: 'money', targetEntity: PriceListDetail::class, orphanRemoval: true)] + private Collection $priceListDetails; + public function __construct() { $this->businesses = new ArrayCollection(); + $this->priceListDetails = new ArrayCollection(); } public function getId(): ?int @@ -87,4 +91,34 @@ class Money return $this; } + + /** + * @return Collection + */ + public function getPriceListDetails(): Collection + { + return $this->priceListDetails; + } + + public function addPriceListDetail(PriceListDetail $priceListDetail): static + { + if (!$this->priceListDetails->contains($priceListDetail)) { + $this->priceListDetails->add($priceListDetail); + $priceListDetail->setMoney($this); + } + + return $this; + } + + public function removePriceListDetail(PriceListDetail $priceListDetail): static + { + if ($this->priceListDetails->removeElement($priceListDetail)) { + // set the owning side to null (unless already changed) + if ($priceListDetail->getMoney() === $this) { + $priceListDetail->setMoney(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/PriceList.php b/hesabixCore/src/Entity/PriceList.php new file mode 100644 index 0000000..9882e8b --- /dev/null +++ b/hesabixCore/src/Entity/PriceList.php @@ -0,0 +1,91 @@ +priceListDetails = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getBid(): ?business + { + return $this->bid; + } + + public function setBid(?business $bid): static + { + $this->bid = $bid; + + return $this; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(string $label): static + { + $this->label = $label; + + return $this; + } + + /** + * @return Collection + */ + public function getPriceListDetails(): Collection + { + return $this->priceListDetails; + } + + public function addPriceListDetail(PriceListDetail $priceListDetail): static + { + if (!$this->priceListDetails->contains($priceListDetail)) { + $this->priceListDetails->add($priceListDetail); + $priceListDetail->setList($this); + } + + return $this; + } + + public function removePriceListDetail(PriceListDetail $priceListDetail): static + { + if ($this->priceListDetails->removeElement($priceListDetail)) { + // set the owning side to null (unless already changed) + if ($priceListDetail->getList() === $this) { + $priceListDetail->setList(null); + } + } + + return $this; + } +} diff --git a/hesabixCore/src/Entity/PriceListDetail.php b/hesabixCore/src/Entity/PriceListDetail.php new file mode 100644 index 0000000..c293068 --- /dev/null +++ b/hesabixCore/src/Entity/PriceListDetail.php @@ -0,0 +1,98 @@ +id; + } + + public function getList(): ?PriceList + { + return $this->list; + } + + public function setList(?PriceList $list): static + { + $this->list = $list; + + return $this; + } + + public function getCommodity(): ?Commodity + { + return $this->commodity; + } + + public function setCommodity(?Commodity $commodity): static + { + $this->commodity = $commodity; + + return $this; + } + + public function getMoney(): ?Money + { + return $this->money; + } + + public function setMoney(?Money $money): static + { + $this->money = $money; + + return $this; + } + + public function getPriceBuy(): ?string + { + return $this->priceBuy; + } + + public function setPriceBuy(?string $priceBuy): static + { + $this->priceBuy = $priceBuy; + + return $this; + } + + public function getPriceSell(): ?string + { + return $this->priceSell; + } + + public function setPriceSell(?string $priceSell): static + { + $this->priceSell = $priceSell; + + return $this; + } +} diff --git a/hesabixCore/src/Repository/PriceListDetailRepository.php b/hesabixCore/src/Repository/PriceListDetailRepository.php new file mode 100644 index 0000000..01de6a9 --- /dev/null +++ b/hesabixCore/src/Repository/PriceListDetailRepository.php @@ -0,0 +1,48 @@ + + * + * @method PriceListDetail|null find($id, $lockMode = null, $lockVersion = null) + * @method PriceListDetail|null findOneBy(array $criteria, array $orderBy = null) + * @method PriceListDetail[] findAll() + * @method PriceListDetail[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class PriceListDetailRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, PriceListDetail::class); + } + +// /** +// * @return PriceListDetail[] Returns an array of PriceListDetail objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('p') +// ->andWhere('p.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('p.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?PriceListDetail +// { +// return $this->createQueryBuilder('p') +// ->andWhere('p.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/hesabixCore/src/Repository/PriceListRepository.php b/hesabixCore/src/Repository/PriceListRepository.php new file mode 100644 index 0000000..b33ce44 --- /dev/null +++ b/hesabixCore/src/Repository/PriceListRepository.php @@ -0,0 +1,48 @@ + + * + * @method PriceList|null find($id, $lockMode = null, $lockVersion = null) + * @method PriceList|null findOneBy(array $criteria, array $orderBy = null) + * @method PriceList[] findAll() + * @method PriceList[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class PriceListRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, PriceList::class); + } + +// /** +// * @return PriceList[] Returns an array of PriceList objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('p') +// ->andWhere('p.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('p.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?PriceList +// { +// return $this->createQueryBuilder('p') +// ->andWhere('p.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index f5f6a4c..6bfb67d 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -15,10 +15,25 @@ use App\Entity\HesabdariTable; use App\Entity\Money; use App\Entity\Person; use App\Entity\PersonType; +use App\Entity\PriceListDetail; use App\Entity\Salary; class Explore { + public static function ExploreCommodityPriceList($items) + { + $result = []; + foreach ($items as $item) + $result[] = self::ExploreCommodityPriceListOne($item); + return $result; + } + public static function ExploreCommodityPriceListOne($item) + { + return [ + 'id' => $item->getId(), + 'label' => $item->getLabel() + ]; + } public static function ExplorePersonType(PersonType $type) { return [ @@ -162,29 +177,53 @@ class Explore public static function ExploreCommodity(Commodity | null $item, int | null $count = 0, string | null $des = '') { - if ($item) - return [ + if ($item){ + $result = [ 'id' => $item->getId(), 'code' => $item->getCode(), 'name' => $item->getName(), 'des' => $item->getDes(), - 'price_buy' => $item->getPriceBuy(), - 'price_sell' => $item->getPriceSell(), + 'priceBuy' => $item->getPriceBuy(), + 'priceSell' => $item->getPriceSell(), 'khadamat' => $item->isKhadamat(), - 'speed_access' => $item->isSpeedAccess(), - //most be completed 'count' => $count, 'unit' => $item->getUnit()->getName(), - 'des' => $des, - 'withoutTax' => $item->isWithoutTax(), + 'withoutTax' => $item->isWithoutTax(), + 'barcodes' => $item->getBarcodes(), + 'commodityCountCheck' => $item->isCommodityCountCheck(), + 'speedAccess' => $item->isSpeedAccess(), + 'orderPoint' =>$item->getOrderPoint(), + 'dayLoading' =>$item->getDayLoading(), + 'minOrderCount' =>$item->getMinOrderCount(), 'unitData' => [ 'name' => $item->getUnit()->getName(), 'floatNumber' => $item->getUnit()->getFloatNumber(), - ] + ], + 'prices'=>self::ExploreCommodityPriceListDetails($item->getPriceListDetails()) ]; + if($des){ $result['des'] = $des;} + return $result; + } + return null; } + public static function ExploreCommodityPriceListDetail(PriceListDetail | null $item) + { + return [ + 'id' => $item->getId(), + 'list' => self::ExploreCommodityPriceListOne($item->getList()), + 'priceBuy' => $item->getPriceBuy(), + 'priceSell' => $item->getPriceSell(), + ]; + } + public static function ExploreCommodityPriceListDetails($items) + { + $result = []; + foreach ($items as $item) + $result[] = self::ExploreCommodityPriceListDetail($item); + return $result; + } public static function ExploreBank(BankAccount | null $item) { if ($item) @@ -192,7 +231,6 @@ class Explore 'id' => $item->getId(), 'code' => $item->getCode(), 'name' => $item->getName(), - //most be completed ]; return null; }