start working on cloud printers

This commit is contained in:
babak alizadeh 2024-06-14 19:49:57 +03:30
parent a350efa203
commit 37b6fd077f
10 changed files with 436 additions and 1 deletions

1
hesabixCore/create Normal file
View file

@ -0,0 +1 @@
asperacentral

View file

@ -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']);

View file

@ -0,0 +1,92 @@
<?php
namespace App\Controller;
use App\Entity\Printer;
use App\Service\Access;
use App\Service\Extractor;
use App\Service\Log;
use App\Service\Provider;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PrintersController extends AbstractController
{
/**
* function to generate random strings
* @param int $length number of characters in the generated string
* @return string a new string is created with random characters of the desired length
*/
private function RandomString($length = 32)
{
return substr(str_shuffle(str_repeat($x = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
}
#[Route('/api/printers/list', name: 'app_printers_list')]
public function app_printers_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->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
]);
}
}

View file

@ -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<int, Printer>
*/
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;
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,66 @@
<?php
namespace App\Entity;
use App\Repository\PrintItemRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PrintItemRepository::class)]
class PrintItem
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'printItems')]
#[ORM\JoinColumn(nullable: false)]
private ?Printer $printer = null;
#[ORM\Column(length: 255)]
private ?string $file = null;
#[ORM\Column(nullable: true)]
private ?bool $printed = null;
public function getId(): ?int
{
return $this->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;
}
}

View file

@ -0,0 +1,106 @@
<?php
namespace App\Entity;
use App\Repository\PrinterRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PrinterRepository::class)]
class Printer
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'printers')]
#[ORM\JoinColumn(nullable: false)]
private ?Business $bid = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 255)]
private ?string $token = null;
#[ORM\OneToMany(mappedBy: 'printer', targetEntity: PrintItem::class, orphanRemoval: true)]
private Collection $printItems;
public function __construct()
{
$this->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<int, PrintItem>
*/
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;
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace App\Repository;
use App\Entity\PrintItem;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<PrintItem>
*
* @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()
// ;
// }
}

View file

@ -0,0 +1,48 @@
<?php
namespace App\Repository;
use App\Entity\Printer;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Printer>
*
* @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()
// ;
// }
}

View file

@ -0,0 +1,20 @@
{% extends 'base.html.twig' %}
{% block title %}Hello PrintersController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ 'C:/xampp/htdocs/hesabixCore/src/Controller/PrintersController.php'|file_link(0) }}">src/Controller/PrintersController.php</a></code></li>
<li>Your template at <code><a href="{{ 'C:/xampp/htdocs/hesabixCore/templates/printers/index.html.twig'|file_link(0) }}">templates/printers/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}