add seal to business

This commit is contained in:
Hesabix 2025-02-21 23:29:43 +00:00
parent 01f07129c5
commit a962372289
11 changed files with 160 additions and 29 deletions

View file

@ -7,6 +7,7 @@ parameters:
archiveMediaDir: '%kernel.project_dir%/../hesabixArchive' archiveMediaDir: '%kernel.project_dir%/../hesabixArchive'
archiveTempMediaDir: '%kernel.project_dir%/../hesabixArchive/temp' archiveTempMediaDir: '%kernel.project_dir%/../hesabixArchive/temp'
avatarDir: '%kernel.project_dir%/../hesabixArchive/avatars' avatarDir: '%kernel.project_dir%/../hesabixArchive/avatars'
sealDir: '%kernel.project_dir%/../hesabixArchive/seal'
services: services:
# default configuration for services in *this* file # default configuration for services in *this* file
_defaults: _defaults:

View file

@ -42,6 +42,18 @@ class AvatarController extends AbstractController
return new Response('default.png'); 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')] #[Route('/api/avatar/get/file/{id}', name: 'api_avatar_get_file')]
public function api_avatar_get_file(string $id): BinaryFileResponse public function api_avatar_get_file(string $id): BinaryFileResponse
{ {
@ -52,6 +64,24 @@ class AvatarController extends AbstractController
return $response; 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')] #[Route('/api/avatar/post', name: 'api_avatar_post')]
public function api_avatar_post(Log $log, SluggerInterface $slugger, Request $request, Access $access, EntityManagerInterface $entityManagerInterface): Response 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'); 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');
}
} }

View file

@ -282,6 +282,9 @@ class Business
#[ORM\OneToMany(mappedBy: 'bid', targetEntity: HesabdariTable::class)] #[ORM\OneToMany(mappedBy: 'bid', targetEntity: HesabdariTable::class)]
private Collection $hesabdariTables; private Collection $hesabdariTables;
#[ORM\Column(length: 255, nullable: true)]
private ?string $sealFile = null;
public function __construct() public function __construct()
{ {
$this->logs = new ArrayCollection(); $this->logs = new ArrayCollection();
@ -1966,4 +1969,16 @@ class Business
return $this; return $this;
} }
public function getSealFile(): ?string
{
return $this->sealFile;
}
public function setSealFile(?string $sealFile): static
{
$this->sealFile = $sealFile;
return $this;
}
} }

View file

@ -5,6 +5,7 @@ namespace App\Service;
use App\Entity\ChangeReport; use App\Entity\ChangeReport;
use App\Entity\Plugin;
use App\Entity\Settings; use App\Entity\Settings;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -21,38 +22,42 @@ class twigFunctions
function __construct( function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
RequestStack $request RequestStack $request
) ) {
{
$this->request = $request->getCurrentRequest(); $this->request = $request->getCurrentRequest();
$this->em = $entityManager; $this->em = $entityManager;
} }
public function md5($val){ public function md5($val)
{
return md5($val); return md5($val);
} }
public function gravatarHash($email){ public function gravatarHash($email)
return md5( strtolower( trim( $email) ) ); {
return md5(strtolower(trim($email)));
} }
public function dayToNow($time){ public function dayToNow($time)
{
$time = $time - time(); // to get the time since that moment $time = $time - time(); // to get the time since that moment
$tokens = array ( $tokens = array(
86400 => 'روز', 86400 => 'روز',
2592000 => 'ماه' 2592000 => 'ماه'
); );
foreach ($tokens as $unit => $text) { foreach ($tokens as $unit => $text) {
if ($time < $unit) continue; if ($time < $unit)
continue;
return floor($time / $unit) . $text; return floor($time / $unit) . $text;
} }
return 'چند ساعت '; return 'چند ساعت ';
} }
public function pastTime($time){ public function pastTime($time)
{
$time = time() - $time; // to get the time since that moment $time = time() - $time; // to get the time since that moment
$tokens = array ( $tokens = array(
31536000 => 'سال', 31536000 => 'سال',
2592000 => 'ماه', 2592000 => 'ماه',
604800 => 'هفته', 604800 => 'هفته',
@ -62,41 +67,47 @@ class twigFunctions
1 => 'ثانیه' 1 => 'ثانیه'
); );
foreach ($tokens as $unit => $text) { foreach ($tokens as $unit => $text) {
if ($time < $unit) continue; if ($time < $unit)
continue;
$numberOfUnits = floor($time / $unit); $numberOfUnits = floor($time / $unit);
return $numberOfUnits.' '.$text . ' قبل '; return $numberOfUnits . ' ' . $text . ' قبل ';
} }
return 'چند ثانیه قبل'; return 'چند ثانیه قبل';
} }
public function pastHash($hash){ public function pastHash($hash)
$tokens = array ( {
1024 *1024 *1024 *1024 *1024 => 'اگزاهش', $tokens = array(
1024 *1024 *1024 *1024 => 'پتاهش', 1024 * 1024 * 1024 * 1024 * 1024 => 'اگزاهش',
1024 *1024 *1024 => 'تراهش', 1024 * 1024 * 1024 * 1024 => 'پتاهش',
1024 *1024 => 'گیگاهش', 1024 * 1024 * 1024 => 'تراهش',
1024 * 1024 => 'گیگاهش',
1024 => 'مگاهش', 1024 => 'مگاهش',
1 => 'کیلوهش', 1 => 'کیلوهش',
); );
foreach ($tokens as $unit => $text) { foreach ($tokens as $unit => $text) {
if ($hash < $unit) continue; if ($hash < $unit)
continue;
$numberOfUnits = floor($hash / $unit); $numberOfUnits = floor($hash / $unit);
return $numberOfUnits.' '.$text; return $numberOfUnits . ' ' . $text;
} }
} }
public function getHesabixLastVersionNumber():string{ public function getHesabixLastVersionNumber(): string
$last = $this->em->getRepository(ChangeReport::class)->findOneBy([],['id'=>'DESC']); {
if($last) $last = $this->em->getRepository(ChangeReport::class)->findOneBy([], ['id' => 'DESC']);
if ($last)
return $last->getVersion(); return $last->getVersion();
return '0.0.1'; return '0.0.1';
} }
public function systemSettings(){ public function systemSettings()
{
return $this->em->getRepository(Settings::class)->findAll()[0]; return $this->em->getRepository(Settings::class)->findAll()[0];
} }
public function getCurrentUrl(){ public function getCurrentUrl()
{
return $this->request->getUri(); return $this->request->getUri();
} }

View file

@ -123,6 +123,7 @@
{% if printInvoice%} {% if printInvoice%}
<header> <header>
<p style="text-align:center;">{{ bid.name }}</p> <p style="text-align:center;">{{ bid.name }}</p>
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
</header> </header>
<table class="bill-details"> <table class="bill-details">
<tbody style="text-align:right"> <tbody style="text-align:right">
@ -227,6 +228,7 @@
</table> </table>
<footer style="text-align:center"> <footer style="text-align:center">
<p>{{ bid.name }}</p> <p>{{ bid.name }}</p>
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
</footer> </footer>
{% endif %} {% endif %}
</body> </body>

View file

@ -296,6 +296,8 @@
<h4> <h4>
مهر و امضا خریدار مهر و امضا خریدار
</h4> </h4>
<br>
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
</td> </td>
<td class="center" style="height:90px"> <td class="center" style="height:90px">
<h4> <h4>

View file

@ -169,6 +169,8 @@
مهر و امضا تحویل گیرنده مهر و امضا تحویل گیرنده
<br> <br>
<b>{{ doc.submitter.fullname }}</b> <b>{{ doc.submitter.fullname }}</b>
<br>
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
</h4> </h4>
</td> </td>
</tr> </tr>

View file

@ -296,6 +296,8 @@
<h4> <h4>
مهر و امضا خریدار مهر و امضا خریدار
</h4> </h4>
<br>
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
</td> </td>
<td class="center" style="height:90px"> <td class="center" style="height:90px">
<h4> <h4>

View file

@ -301,6 +301,8 @@
<h4> <h4>
مهر و امضا فروشنده: مهر و امضا فروشنده:
</h4> </h4>
<br>
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View file

@ -303,6 +303,8 @@
<h4> <h4>
مهر و امضا فروشنده: مهر و امضا فروشنده:
</h4> </h4>
<br>
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View file

@ -184,6 +184,8 @@
<h5> <h5>
{{doc.storeroom.manager}} {{doc.storeroom.manager}}
</h5> </h5>
<br>
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
</td> </td>
</tr> </tr>
</tbody> </tbody>