add seal to business
This commit is contained in:
parent
01f07129c5
commit
a962372289
|
@ -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:
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -21,21 +22,23 @@ class twigFunctions
|
|||
function __construct(
|
||||
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){
|
||||
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(
|
||||
|
@ -43,13 +46,15 @@ class twigFunctions
|
|||
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(
|
||||
|
@ -62,14 +67,16 @@ class twigFunctions
|
|||
1 => 'ثانیه'
|
||||
);
|
||||
foreach ($tokens as $unit => $text) {
|
||||
if ($time < $unit) continue;
|
||||
if ($time < $unit)
|
||||
continue;
|
||||
$numberOfUnits = floor($time / $unit);
|
||||
return $numberOfUnits . ' ' . $text . ' قبل ';
|
||||
}
|
||||
return 'چند ثانیه قبل';
|
||||
}
|
||||
|
||||
public function pastHash($hash){
|
||||
public function pastHash($hash)
|
||||
{
|
||||
$tokens = array(
|
||||
1024 * 1024 * 1024 * 1024 * 1024 => 'اگزاهش',
|
||||
1024 * 1024 * 1024 * 1024 => 'پتاهش',
|
||||
|
@ -79,24 +86,28 @@ class twigFunctions
|
|||
1 => 'کیلوهش',
|
||||
);
|
||||
foreach ($tokens as $unit => $text) {
|
||||
if ($hash < $unit) continue;
|
||||
if ($hash < $unit)
|
||||
continue;
|
||||
$numberOfUnits = floor($hash / $unit);
|
||||
return $numberOfUnits . ' ' . $text;
|
||||
}
|
||||
}
|
||||
|
||||
public function getHesabixLastVersionNumber():string{
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@
|
|||
{% if printInvoice%}
|
||||
<header>
|
||||
<p style="text-align:center;">{{ bid.name }}</p>
|
||||
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
|
||||
</header>
|
||||
<table class="bill-details">
|
||||
<tbody style="text-align:right">
|
||||
|
@ -227,6 +228,7 @@
|
|||
</table>
|
||||
<footer style="text-align:center">
|
||||
<p>{{ bid.name }}</p>
|
||||
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
|
||||
</footer>
|
||||
{% endif %}
|
||||
</body>
|
||||
|
|
|
@ -296,6 +296,8 @@
|
|||
<h4>
|
||||
مهر و امضا خریدار
|
||||
</h4>
|
||||
<br>
|
||||
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
|
||||
</td>
|
||||
<td class="center" style="height:90px">
|
||||
<h4>
|
||||
|
|
|
@ -169,6 +169,8 @@
|
|||
مهر و امضا تحویل گیرنده
|
||||
<br>
|
||||
<b>{{ doc.submitter.fullname }}</b>
|
||||
<br>
|
||||
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
|
||||
</h4>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -296,6 +296,8 @@
|
|||
<h4>
|
||||
مهر و امضا خریدار
|
||||
</h4>
|
||||
<br>
|
||||
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
|
||||
</td>
|
||||
<td class="center" style="height:90px">
|
||||
<h4>
|
||||
|
|
|
@ -301,6 +301,8 @@
|
|||
<h4>
|
||||
مهر و امضا فروشنده:
|
||||
</h4>
|
||||
<br>
|
||||
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -303,6 +303,8 @@
|
|||
<h4>
|
||||
مهر و امضا فروشنده:
|
||||
</h4>
|
||||
<br>
|
||||
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -184,6 +184,8 @@
|
|||
<h5>
|
||||
{{doc.storeroom.manager}}
|
||||
</h5>
|
||||
<br>
|
||||
<img src="{{ "/api/seal/get/file/" ~ bid.sealFile}}" width="80"/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in a new issue