diff --git a/hesabixCore/config/services.yaml b/hesabixCore/config/services.yaml index e9e998f..8d2ea79 100644 --- a/hesabixCore/config/services.yaml +++ b/hesabixCore/config/services.yaml @@ -7,6 +7,7 @@ parameters: archiveMediaDir: '%kernel.project_dir%/../hesabixArchive' archiveTempMediaDir: '%kernel.project_dir%/../hesabixArchive/temp' avatarDir: '%kernel.project_dir%/../hesabixArchive/avatars' + sealDir: '%kernel.project_dir%/../hesabixArchive/seal' services: # default configuration for services in *this* file _defaults: diff --git a/hesabixCore/src/Controller/AvatarController.php b/hesabixCore/src/Controller/AvatarController.php index c27efe7..88d9ffb 100644 --- a/hesabixCore/src/Controller/AvatarController.php +++ b/hesabixCore/src/Controller/AvatarController.php @@ -42,6 +42,18 @@ class AvatarController extends AbstractController return new Response('default.png'); } + #[Route('/api/seal/get', name: 'api_seal_get')] + public function api_seal_get(Access $access): Response + { + $acc = $access->hasRole('settings'); + if (!$acc) + throw $this->createAccessDeniedException(); + if ($acc['bid']->getSealFile()) { + return new Response($acc['bid']->getSealFile()); + } + return new Response('default.png'); + } + #[Route('/api/avatar/get/file/{id}', name: 'api_avatar_get_file')] public function api_avatar_get_file(string $id): BinaryFileResponse { @@ -52,6 +64,24 @@ class AvatarController extends AbstractController return $response; } + #[Route('/api/seal/get/file/{id}', name: 'api_seal_get_file')] + public function api_seal_get_file(string $id = null): BinaryFileResponse + { + if ($id) { + $fileAdr = __DIR__ . '/../../../hesabixArchive/seal/' . $id; + if (!file_exists($fileAdr)) + throw $this->createNotFoundException(); + $response = new BinaryFileResponse($fileAdr); + return $response; + } + $fileAdr = __DIR__ . '/../../../hesabixArchive/seal/default.png'; + if (!file_exists($fileAdr)) + throw $this->createNotFoundException(); + $response = new BinaryFileResponse($fileAdr); + return $response; + + } + #[Route('/api/avatar/post', name: 'api_avatar_post')] public function api_avatar_post(Log $log, SluggerInterface $slugger, Request $request, Access $access, EntityManagerInterface $entityManagerInterface): Response { @@ -112,4 +142,64 @@ class AvatarController extends AbstractController } return new Response('default.png'); } + + #[Route('/api/seal/post', name: 'api_seal_post')] + public function api_seal_post(Log $log, SluggerInterface $slugger, Request $request, Access $access, EntityManagerInterface $entityManagerInterface): Response + { + $acc = $access->hasRole('owner'); + if (!$acc) + throw $this->createAccessDeniedException(); + $uploadedFile = $request->files->get('bytes'); + if ($uploadedFile) { + $originalFilename = pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_FILENAME); + // this is needed to safely include the file name as part of the URL + $safeFilename = $slugger->slug($originalFilename); + $newFilename = $safeFilename . '-' . uniqid() . '.' . $uploadedFile->guessExtension(); + $ext = $uploadedFile->getClientOriginalExtension(); + $extOK = false; + if ($ext == 'png' || $ext == 'jpg' || $ext == 'jpeg') { + $extOK = true; + } else { + return new Response('e'); + } + $sizeOK = false; + if ($uploadedFile->getSize() < 1000000) { + $sizeOK = true; + } else { + return new Response('s'); + } + $imgSizeOK = false; + $info = getimagesize($uploadedFile); + list($x, $y) = $info; + if ($x < 513 && $y < 513) { + $imgSizeOK = true; + } else { + return new Response('is'); + } + if ($extOK && $sizeOK && $imgSizeOK) { + // Move the file to the directory where brochures are stored + try { + $uploadedFile->move( + $this->getParameter('sealDir'), + $newFilename + ); + } catch (FileException $e) { + // ... handle exception if something happens during file upload + return $this->json("error"); + } + $acc['bid']->setSealFile($newFilename); + $entityManagerInterface->persist($acc['bid']); + $entityManagerInterface->flush(); + //save log + $log->insert('تنظیمات پایه', 'مهر کسب و کار تغییر یافت', $this->getUser(), $acc['bid']); + + return new Response($acc['bid']->getAvatar()); + } + } + + if ($acc['bid']->getSealFile()) { + return new Response($acc['bid']->getSealFile()); + } + return new Response('default.png'); + } } diff --git a/hesabixCore/src/Entity/Business.php b/hesabixCore/src/Entity/Business.php index f72d386..00d7b29 100644 --- a/hesabixCore/src/Entity/Business.php +++ b/hesabixCore/src/Entity/Business.php @@ -282,6 +282,9 @@ class Business #[ORM\OneToMany(mappedBy: 'bid', targetEntity: HesabdariTable::class)] private Collection $hesabdariTables; + #[ORM\Column(length: 255, nullable: true)] + private ?string $sealFile = null; + public function __construct() { $this->logs = new ArrayCollection(); @@ -1966,4 +1969,16 @@ class Business return $this; } + + public function getSealFile(): ?string + { + return $this->sealFile; + } + + public function setSealFile(?string $sealFile): static + { + $this->sealFile = $sealFile; + + return $this; + } } diff --git a/hesabixCore/src/Service/twigFunctions.php b/hesabixCore/src/Service/twigFunctions.php index 086f2cd..0b8fbb4 100644 --- a/hesabixCore/src/Service/twigFunctions.php +++ b/hesabixCore/src/Service/twigFunctions.php @@ -5,6 +5,7 @@ namespace App\Service; use App\Entity\ChangeReport; +use App\Entity\Plugin; use App\Entity\Settings; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; @@ -19,40 +20,44 @@ class twigFunctions protected RequestStack $requestStack; function __construct( - EntityManagerInterface $entityManager, + EntityManagerInterface $entityManager, RequestStack $request - ) - { + ) { $this->request = $request->getCurrentRequest(); $this->em = $entityManager; } - public function md5($val){ + public function md5($val) + { return md5($val); } - public function gravatarHash($email){ - return md5( strtolower( trim( $email) ) ); + public function gravatarHash($email) + { + return md5(strtolower(trim($email))); } - public function dayToNow($time){ + public function dayToNow($time) + { - $time = $time - time(); // to get the time since that moment - $tokens = array ( + $time = $time - time(); // to get the time since that moment + $tokens = array( 86400 => 'روز', 2592000 => 'ماه' ); foreach ($tokens as $unit => $text) { - if ($time < $unit) continue; + if ($time < $unit) + continue; return floor($time / $unit) . $text; } return 'چند ساعت '; } - public function pastTime($time){ + public function pastTime($time) + { $time = time() - $time; // to get the time since that moment - $tokens = array ( + $tokens = array( 31536000 => 'سال', 2592000 => 'ماه', 604800 => 'هفته', @@ -62,41 +67,47 @@ class twigFunctions 1 => 'ثانیه' ); foreach ($tokens as $unit => $text) { - if ($time < $unit) continue; + if ($time < $unit) + continue; $numberOfUnits = floor($time / $unit); - return $numberOfUnits.' '.$text . ' قبل '; + return $numberOfUnits . ' ' . $text . ' قبل '; } return 'چند ثانیه قبل'; } - public function pastHash($hash){ - $tokens = array ( - 1024 *1024 *1024 *1024 *1024 => 'اگزاهش', - 1024 *1024 *1024 *1024 => 'پتاهش', - 1024 *1024 *1024 => 'تراهش', - 1024 *1024 => 'گیگاهش', - 1024 => 'مگاهش', - 1 => 'کیلوهش', + public function pastHash($hash) + { + $tokens = array( + 1024 * 1024 * 1024 * 1024 * 1024 => 'اگزاهش', + 1024 * 1024 * 1024 * 1024 => 'پتاهش', + 1024 * 1024 * 1024 => 'تراهش', + 1024 * 1024 => 'گیگاهش', + 1024 => 'مگاهش', + 1 => 'کیلوهش', ); foreach ($tokens as $unit => $text) { - if ($hash < $unit) continue; + if ($hash < $unit) + continue; $numberOfUnits = floor($hash / $unit); - return $numberOfUnits.' '.$text; + return $numberOfUnits . ' ' . $text; } } - public function getHesabixLastVersionNumber():string{ - $last = $this->em->getRepository(ChangeReport::class)->findOneBy([],['id'=>'DESC']); - if($last) + public function getHesabixLastVersionNumber(): string + { + $last = $this->em->getRepository(ChangeReport::class)->findOneBy([], ['id' => 'DESC']); + if ($last) return $last->getVersion(); return '0.0.1'; } - public function systemSettings(){ + public function systemSettings() + { return $this->em->getRepository(Settings::class)->findAll()[0]; } - public function getCurrentUrl(){ + public function getCurrentUrl() + { return $this->request->getUri(); } diff --git a/hesabixCore/templates/pdf/posPrinters/sell.html.twig b/hesabixCore/templates/pdf/posPrinters/sell.html.twig index 4dadc8c..131aeb7 100644 --- a/hesabixCore/templates/pdf/posPrinters/sell.html.twig +++ b/hesabixCore/templates/pdf/posPrinters/sell.html.twig @@ -123,6 +123,7 @@ {% if printInvoice%}

{{ bid.name }}

+
@@ -227,6 +228,7 @@
{% endif %} diff --git a/hesabixCore/templates/pdf/printers/buy.html.twig b/hesabixCore/templates/pdf/printers/buy.html.twig index b2314ec..bedf801 100644 --- a/hesabixCore/templates/pdf/printers/buy.html.twig +++ b/hesabixCore/templates/pdf/printers/buy.html.twig @@ -296,6 +296,8 @@

مهر و امضا خریدار

+
+

diff --git a/hesabixCore/templates/pdf/printers/repservice/invoice.html.twig b/hesabixCore/templates/pdf/printers/repservice/invoice.html.twig index 68017d2..75521b2 100644 --- a/hesabixCore/templates/pdf/printers/repservice/invoice.html.twig +++ b/hesabixCore/templates/pdf/printers/repservice/invoice.html.twig @@ -169,6 +169,8 @@ مهر و امضا تحویل گیرنده
{{ doc.submitter.fullname }} +
+

diff --git a/hesabixCore/templates/pdf/printers/rfbuy.html.twig b/hesabixCore/templates/pdf/printers/rfbuy.html.twig index 04f78f4..7bb795c 100644 --- a/hesabixCore/templates/pdf/printers/rfbuy.html.twig +++ b/hesabixCore/templates/pdf/printers/rfbuy.html.twig @@ -296,6 +296,8 @@

مهر و امضا خریدار

+
+

diff --git a/hesabixCore/templates/pdf/printers/rfsell.html.twig b/hesabixCore/templates/pdf/printers/rfsell.html.twig index 9f6158a..4bb7d52 100644 --- a/hesabixCore/templates/pdf/printers/rfsell.html.twig +++ b/hesabixCore/templates/pdf/printers/rfsell.html.twig @@ -301,6 +301,8 @@

مهر و امضا فروشنده:

+
+ diff --git a/hesabixCore/templates/pdf/printers/sell.html.twig b/hesabixCore/templates/pdf/printers/sell.html.twig index 1faa4fd..c8cb3a8 100644 --- a/hesabixCore/templates/pdf/printers/sell.html.twig +++ b/hesabixCore/templates/pdf/printers/sell.html.twig @@ -303,6 +303,8 @@

مهر و امضا فروشنده:

+
+ diff --git a/hesabixCore/templates/pdf/printers/storeroom/input.html.twig b/hesabixCore/templates/pdf/printers/storeroom/input.html.twig index a0d6781..b9599ad 100644 --- a/hesabixCore/templates/pdf/printers/storeroom/input.html.twig +++ b/hesabixCore/templates/pdf/printers/storeroom/input.html.twig @@ -184,6 +184,8 @@
{{doc.storeroom.manager}}
+
+