From 37b6fd077f2f38fd283d3cd165f74c77e5a3d85a Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Fri, 14 Jun 2024 19:49:57 +0330 Subject: [PATCH] start working on cloud printers --- hesabixCore/create | 1 + .../src/Controller/CommodityController.php | 6 +- .../src/Controller/PrintersController.php | 92 +++++++++++++++ hesabixCore/src/Entity/Business.php | 34 ++++++ hesabixCore/src/Entity/Commodity.php | 16 +++ hesabixCore/src/Entity/PrintItem.php | 66 +++++++++++ hesabixCore/src/Entity/Printer.php | 106 ++++++++++++++++++ .../src/Repository/PrintItemRepository.php | 48 ++++++++ .../src/Repository/PrinterRepository.php | 48 ++++++++ .../templates/printers/index.html.twig | 20 ++++ 10 files changed, 436 insertions(+), 1 deletion(-) create mode 100644 hesabixCore/create create mode 100644 hesabixCore/src/Controller/PrintersController.php create mode 100644 hesabixCore/src/Entity/PrintItem.php create mode 100644 hesabixCore/src/Entity/Printer.php create mode 100644 hesabixCore/src/Repository/PrintItemRepository.php create mode 100644 hesabixCore/src/Repository/PrinterRepository.php create mode 100644 hesabixCore/templates/printers/index.html.twig diff --git a/hesabixCore/create b/hesabixCore/create new file mode 100644 index 0000000..2ed4f22 --- /dev/null +++ b/hesabixCore/create @@ -0,0 +1 @@ +asperacentral diff --git a/hesabixCore/src/Controller/CommodityController.php b/hesabixCore/src/Controller/CommodityController.php index 3c9d144..9400e90 100644 --- a/hesabixCore/src/Controller/CommodityController.php +++ b/hesabixCore/src/Controller/CommodityController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\Service\Explore; use App\Service\Log; use App\Service\Jdate; use App\Service\Access; @@ -236,7 +237,7 @@ class CommodityController extends AbstractController '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'], 1); + $res = $provider->Entity2ArrayJustIncludes($data, ['isSpeedAccess', 'isCommodityCountCheck', 'getName', 'getUnit', 'getPriceBuy', 'getPriceSell', 'getCat', 'getOrderPoint', 'getdes', 'getId', 'getDayLoading', 'isKhadamat', 'getCode', 'getMinOrderCount', 'getLabel', 'isWithoutTax','getBarcodes'], 1); $res['cat'] = ''; if ($data->getCat()) $res['cat'] = $data->getCat()->getId(); @@ -309,6 +310,9 @@ class CommodityController extends AbstractController if (array_key_exists('commodityCountCheck', $params)) { $data->setCommodityCountCheck($params['commodityCountCheck']); } + if (array_key_exists('barcodes', $params)) { + $data->setBarcodes($params['barcodes']); + } $data->setMinOrderCount($params['minOrderCount']); $data->setSpeedAccess($params['speedAccess']); $data->setDayLoading($params['dayLoading']); diff --git a/hesabixCore/src/Controller/PrintersController.php b/hesabixCore/src/Controller/PrintersController.php new file mode 100644 index 0000000..11340b5 --- /dev/null +++ b/hesabixCore/src/Controller/PrintersController.php @@ -0,0 +1,92 @@ +hasRole('owner'); + if (!$acc) + throw $this->createAccessDeniedException(); + $items = $entityManager->getRepository(Printer::class)->findBy(['bid' => $acc['bid']]); + $res = []; + foreach ($items as $item) { + $temp = []; + $temp['id'] = $item->getId(); + $temp['name'] = $item->getName(); + $temp['token'] = $item->getToken(); + $temp['status'] = 'معتبر'; + $res[] = $temp; + } + return $this->json($res); + } + #[Route('/api/printers/delete/{code}', name: 'app_printers_delete')] + public function app_printers_delete(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse + { + $acc = $access->hasRole('owner'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $printer = $entityManager->getRepository(Printer::class)->findOneBy(['bid' => $acc['bid'], 'id' => $code]); + if (!$printer) + throw $this->createNotFoundException(); + //check accounting docs + + $comName = $printer->getName(); + $entityManager->remove($printer); + $log->insert('چاپگر‌های ابری', ' چاپگر با نام ' . $comName . ' حذف شد. ', $this->getUser(), $acc['bid']->getId()); + return $this->json(['result' => 1]); + } + + #[Route('/api/printers/insert', name: 'app_printers_insert')] + public function app_printers_insert(Extractor $extractor, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('owner'); + if (!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if (!array_key_exists('name', $params)) + return $this->json($extractor->paramsNotSend()); + $item = $entityManager->getRepository(Printer::class)->findOneBy(['bid' => $acc['bid'], 'name' => $params['name']]); + if($item) + return $this->json(['result'=>2]); + $item = new Printer(); + $item->setBid($acc['bid']); + $item->setName($params['name']); + $item->setToken($this->RandomString(42)); + $entityManager->persist($item); + $entityManager->flush(); + return $this->json([ + 'result' => 1 + ]); + } +} diff --git a/hesabixCore/src/Entity/Business.php b/hesabixCore/src/Entity/Business.php index ad35a9f..1c42b3a 100644 --- a/hesabixCore/src/Entity/Business.php +++ b/hesabixCore/src/Entity/Business.php @@ -216,6 +216,9 @@ class Business #[ORM\Column(length: 25, nullable: true)] private ?string $plugRepserviceCode = null; + #[ORM\OneToMany(mappedBy: 'bid', targetEntity: Printer::class, orphanRemoval: true)] + private Collection $printers; + public function __construct() { $this->logs = new ArrayCollection(); @@ -245,6 +248,7 @@ class Business $this->personCards = new ArrayCollection(); $this->mostDes = new ArrayCollection(); $this->plugRepserviceOrders = new ArrayCollection(); + $this->printers = new ArrayCollection(); } public function getId(): ?int @@ -1505,4 +1509,34 @@ class Business return $this; } + + /** + * @return Collection + */ + public function getPrinters(): Collection + { + return $this->printers; + } + + public function addPrinter(Printer $printer): static + { + if (!$this->printers->contains($printer)) { + $this->printers->add($printer); + $printer->setBid($this); + } + + return $this; + } + + public function removePrinter(Printer $printer): static + { + if ($this->printers->removeElement($printer)) { + // set the owning side to null (unless already changed) + if ($printer->getBid() === $this) { + $printer->setBid(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/Commodity.php b/hesabixCore/src/Entity/Commodity.php index 24ae201..1abc863 100644 --- a/hesabixCore/src/Entity/Commodity.php +++ b/hesabixCore/src/Entity/Commodity.php @@ -5,6 +5,7 @@ namespace App\Entity; use App\Repository\CommodityRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Ignore; @@ -79,6 +80,9 @@ class Commodity #[ORM\Column(nullable: true)] private ?bool $withoutTax = null; + #[ORM\Column(type: Types::TEXT, nullable: true)] + private ?string $barcodes = null; + public function __construct() { $this->setPriceBuy(0); @@ -393,4 +397,16 @@ class Commodity return $this; } + + public function getBarcodes(): ?string + { + return $this->barcodes; + } + + public function setBarcodes(?string $barcodes): static + { + $this->barcodes = $barcodes; + + return $this; + } } diff --git a/hesabixCore/src/Entity/PrintItem.php b/hesabixCore/src/Entity/PrintItem.php new file mode 100644 index 0000000..5df59db --- /dev/null +++ b/hesabixCore/src/Entity/PrintItem.php @@ -0,0 +1,66 @@ +id; + } + + public function getPrinter(): ?Printer + { + return $this->printer; + } + + public function setPrinter(?Printer $printer): static + { + $this->printer = $printer; + + return $this; + } + + public function getFile(): ?string + { + return $this->file; + } + + public function setFile(string $file): static + { + $this->file = $file; + + return $this; + } + + public function isPrinted(): ?bool + { + return $this->printed; + } + + public function setPrinted(?bool $printed): static + { + $this->printed = $printed; + + return $this; + } +} diff --git a/hesabixCore/src/Entity/Printer.php b/hesabixCore/src/Entity/Printer.php new file mode 100644 index 0000000..09a99fa --- /dev/null +++ b/hesabixCore/src/Entity/Printer.php @@ -0,0 +1,106 @@ +printItems = 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 getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getToken(): ?string + { + return $this->token; + } + + public function setToken(string $token): static + { + $this->token = $token; + + return $this; + } + + /** + * @return Collection + */ + public function getPrintItems(): Collection + { + return $this->printItems; + } + + public function addPrintItem(PrintItem $printItem): static + { + if (!$this->printItems->contains($printItem)) { + $this->printItems->add($printItem); + $printItem->setPrinter($this); + } + + return $this; + } + + public function removePrintItem(PrintItem $printItem): static + { + if ($this->printItems->removeElement($printItem)) { + // set the owning side to null (unless already changed) + if ($printItem->getPrinter() === $this) { + $printItem->setPrinter(null); + } + } + + return $this; + } +} diff --git a/hesabixCore/src/Repository/PrintItemRepository.php b/hesabixCore/src/Repository/PrintItemRepository.php new file mode 100644 index 0000000..47bacfb --- /dev/null +++ b/hesabixCore/src/Repository/PrintItemRepository.php @@ -0,0 +1,48 @@ + + * + * @method PrintItem|null find($id, $lockMode = null, $lockVersion = null) + * @method PrintItem|null findOneBy(array $criteria, array $orderBy = null) + * @method PrintItem[] findAll() + * @method PrintItem[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class PrintItemRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, PrintItem::class); + } + +// /** +// * @return PrintItem[] Returns an array of PrintItem 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): ?PrintItem +// { +// return $this->createQueryBuilder('p') +// ->andWhere('p.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/hesabixCore/src/Repository/PrinterRepository.php b/hesabixCore/src/Repository/PrinterRepository.php new file mode 100644 index 0000000..5f2a9d3 --- /dev/null +++ b/hesabixCore/src/Repository/PrinterRepository.php @@ -0,0 +1,48 @@ + + * + * @method Printer|null find($id, $lockMode = null, $lockVersion = null) + * @method Printer|null findOneBy(array $criteria, array $orderBy = null) + * @method Printer[] findAll() + * @method Printer[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class PrinterRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Printer::class); + } + +// /** +// * @return Printer[] Returns an array of Printer 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): ?Printer +// { +// return $this->createQueryBuilder('p') +// ->andWhere('p.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/hesabixCore/templates/printers/index.html.twig b/hesabixCore/templates/printers/index.html.twig new file mode 100644 index 0000000..67ebbec --- /dev/null +++ b/hesabixCore/templates/printers/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello PrintersController!{% endblock %} + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: + +
+{% endblock %}