add print settings and note to sell invoice

This commit is contained in:
babak alizadeh 2024-07-27 18:05:05 +03:30
parent 0feef787be
commit bc946b6979
6 changed files with 411 additions and 121 deletions

View file

@ -4,7 +4,9 @@ namespace App\Controller;
use App\Entity\Printer; use App\Entity\Printer;
use App\Entity\PrintItem; use App\Entity\PrintItem;
use App\Entity\PrintOptions;
use App\Service\Access; use App\Service\Access;
use App\Service\Explore;
use App\Service\Extractor; use App\Service\Extractor;
use App\Service\Log; use App\Service\Log;
use App\Service\Provider; use App\Service\Provider;
@ -28,7 +30,60 @@ class PrintersController extends AbstractController
return substr(str_shuffle(str_repeat($x = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length); return substr(str_shuffle(str_repeat($x = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
} }
#[Route('/api/printers/options/info', name: 'app_printers_options_info')]
public function app_printers_options_info(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('settings');
if (!$acc)
throw $this->createAccessDeniedException();
$settings = $entityManager->getRepository(PrintOptions::class)->findOneBy(['bid' => $acc['bid']]);
if (!$settings) {
$settings = new PrintOptions;
$settings->setBid($acc['bid']);
$entityManager->persist($settings);
$entityManager->flush();
}
$temp = [];
$temp['sell']['id'] = $settings->getId();
$temp['sell']['bidInfo'] = $settings->isSellBidInfo();
$temp['sell']['taxInfo'] = $settings->isSellTaxInfo();
$temp['sell']['discountInfo'] = $settings->isSellDiscountInfo();
$temp['sell']['note'] = $settings->isSellNote();
$temp['sell']['noteString'] = $settings->getSellNoteString();
$temp['sell']['pays'] = $settings->isSellPays();
return $this->json($temp);
}
#[Route('/api/printers/options/save', name: 'app_printers_options_save')]
public function app_printers_options_save(Extractor $extractor, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('settings');
if (!$acc)
throw $this->createAccessDeniedException();
$settings = $entityManager->getRepository(PrintOptions::class)->findOneBy(['bid' => $acc['bid']]);
if (!$settings) {
$settings = new PrintOptions;
$settings->setBid($acc['bid']);
$entityManager->persist($settings);
$entityManager->flush();
}
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
$settings->setSellBidInfo($params['sell']['bidInfo']);
$settings->setSellTaxInfo($params['sell']['taxInfo']);
$settings->setSellDiscountInfo($params['sell']['discountInfo']);
$settings->setSellNote($params['sell']['note']);
$settings->setSellNoteString($params['sell']['noteString']);
$settings->setSellPays($params['sell']['pays']);
$entityManager->persist($settings);
$entityManager->flush();
$log->insert('تنظیمات چاپ', 'تنظیمات چاپ به روز رسانی شد.', $this->getUser(), $acc['bid']->getId());
return $this->json($extractor->operationSuccess());
}
#[Route('/api/printers/list', name: 'app_printers_list')] #[Route('/api/printers/list', name: 'app_printers_list')]
public function app_printers_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse public function app_printers_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {

View file

@ -13,6 +13,7 @@ use App\Entity\HesabdariRow;
use App\Entity\HesabdariTable; use App\Entity\HesabdariTable;
use App\Entity\InvoiceType; use App\Entity\InvoiceType;
use App\Entity\Person; use App\Entity\Person;
use App\Entity\PrintOptions;
use App\Entity\StoreroomTicket; use App\Entity\StoreroomTicket;
use App\Service\Printers; use App\Service\Printers;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -408,6 +409,33 @@ class SellController extends AbstractController
} }
$pdfPid = 0; $pdfPid = 0;
if ($params['pdf']) { if ($params['pdf']) {
$printOptions = [
'bidInfo' => true,
'pays' =>true,
'taxInfo' =>true,
'discountInfo' =>true,
'note' =>true
];
if(array_key_exists('printOptions',$params)){
if(array_key_exists('bidInfo',$params['printOptions'])){
$printOptions['bidInfo'] = $params['printOptions']['bidInfo'];
}
if(array_key_exists('pays',$params['printOptions'])){
$printOptions['pays'] = $params['printOptions']['pays'];
}
if(array_key_exists('taxInfo',$params['printOptions'])){
$printOptions['taxInfo'] = $params['printOptions']['taxInfo'];
}
if(array_key_exists('discountInfo',$params['printOptions'])){
$printOptions['discountInfo'] = $params['printOptions']['discountInfo'];
}
if(array_key_exists('note',$params['printOptions'])){
$printOptions['note'] = $params['printOptions']['note'];
}
}
$note = '';
$printSettings = $entityManager->getRepository(PrintOptions::class)->findOneBy(['bid'=>$acc['bid']]);
if($printSettings){$note = $printSettings->getSellNoteString();}
$pdfPid = $provider->createPrint( $pdfPid = $provider->createPrint(
$acc['bid'], $acc['bid'],
$this->getUser(), $this->getUser(),
@ -418,7 +446,9 @@ class SellController extends AbstractController
'person' => $person, 'person' => $person,
'printInvoice' => $params['printers'], 'printInvoice' => $params['printers'],
'discount' => $discount, 'discount' => $discount,
'transfer' => $transfer 'transfer' => $transfer,
'printOptions'=> $printOptions,
'note'=> $note
]), ]),
false false
); );

View file

@ -231,6 +231,9 @@ class Business
#[ORM\OneToMany(mappedBy: 'bid', targetEntity: PriceList::class, orphanRemoval: true)] #[ORM\OneToMany(mappedBy: 'bid', targetEntity: PriceList::class, orphanRemoval: true)]
private Collection $priceLists; private Collection $priceLists;
#[ORM\OneToMany(mappedBy: 'bid', targetEntity: PrintOptions::class, orphanRemoval: true)]
private Collection $printOptions;
public function __construct() public function __construct()
{ {
$this->logs = new ArrayCollection(); $this->logs = new ArrayCollection();
@ -264,6 +267,7 @@ class Business
$this->printTemplates = new ArrayCollection(); $this->printTemplates = new ArrayCollection();
$this->notes = new ArrayCollection(); $this->notes = new ArrayCollection();
$this->priceLists = new ArrayCollection(); $this->priceLists = new ArrayCollection();
$this->printOptions = new ArrayCollection();
} }
public function getId(): ?int public function getId(): ?int
@ -1656,4 +1660,34 @@ class Business
return $this; return $this;
} }
/**
* @return Collection<int, PrintOptions>
*/
public function getPrintOptions(): Collection
{
return $this->printOptions;
}
public function addPrintOption(PrintOptions $printOption): static
{
if (!$this->printOptions->contains($printOption)) {
$this->printOptions->add($printOption);
$printOption->setBid($this);
}
return $this;
}
public function removePrintOption(PrintOptions $printOption): static
{
if ($this->printOptions->removeElement($printOption)) {
// set the owning side to null (unless already changed)
if ($printOption->getBid() === $this) {
$printOption->setBid(null);
}
}
return $this;
}
} }

View file

@ -0,0 +1,127 @@
<?php
namespace App\Entity;
use App\Repository\PrintOptionsRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PrintOptionsRepository::class)]
class PrintOptions
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'printOptions')]
#[ORM\JoinColumn(nullable: false)]
private ?Business $bid = null;
#[ORM\Column(nullable: true)]
private ?bool $sellBidInfo = null;
#[ORM\Column(nullable: true)]
private ?bool $sellNote = null;
#[ORM\Column(nullable: true)]
private ?bool $sellTaxInfo = null;
#[ORM\Column(nullable: true)]
private ?bool $sellDiscountInfo = null;
#[ORM\Column(nullable: true)]
private ?bool $sellPays = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $sellNoteString = null;
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 isSellBidInfo(): ?bool
{
return $this->sellBidInfo;
}
public function setSellBidInfo(?bool $sellBidInfo): static
{
$this->sellBidInfo = $sellBidInfo;
return $this;
}
public function isSellNote(): ?bool
{
return $this->sellNote;
}
public function setSellNote(?bool $sellNote): static
{
$this->sellNote = $sellNote;
return $this;
}
public function isSellTaxInfo(): ?bool
{
return $this->sellTaxInfo;
}
public function setSellTaxInfo(?bool $sellTaxInfo): static
{
$this->sellTaxInfo = $sellTaxInfo;
return $this;
}
public function isSellDiscountInfo(): ?bool
{
return $this->sellDiscountInfo;
}
public function setSellDiscountInfo(?bool $sellDiscountInfo): static
{
$this->sellDiscountInfo = $sellDiscountInfo;
return $this;
}
public function isSellPays(): ?bool
{
return $this->sellPays;
}
public function setSellPays(?bool $sellPays): static
{
$this->sellPays = $sellPays;
return $this;
}
public function getSellNoteString(): ?string
{
return $this->sellNoteString;
}
public function setSellNoteString(?string $sellNoteString): static
{
$this->sellNoteString = $sellNoteString;
return $this;
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace App\Repository;
use App\Entity\PrintOptions;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<PrintOptions>
*
* @method PrintOptions|null find($id, $lockMode = null, $lockVersion = null)
* @method PrintOptions|null findOneBy(array $criteria, array $orderBy = null)
* @method PrintOptions[] findAll()
* @method PrintOptions[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PrintOptionsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PrintOptions::class);
}
// /**
// * @return PrintOptions[] Returns an array of PrintOptions 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): ?PrintOptions
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -14,7 +14,7 @@
border: 1px solid black; border: 1px solid black;
} }
.item { .item {
height: 40px; height: 30px;
} }
</style> </style>
</head> </head>
@ -45,69 +45,75 @@
</thead> </thead>
</table> </table>
</div> </div>
<div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;"> {% if printOptions.bidInfo %}
<div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray">
<b style="color:white;">فروشنده</b> <div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;">
</div> <div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray">
<table style="width:100%;"> <b style="color:white;">فروشنده</b>
<tbody> </div>
<tr style="text-align:center;"> <table style="width:100%;">
<td class=""> <tbody>
<p> <tr style="text-align:center;">
<b>نام: <td class="">
</b> <p>
{{ bid.legalName }} <b>نام:
</p> </b>
</td> {{ bid.legalName }}
<td class="center"> </p>
<p> </td>
<b> شناسه ملی: <td class="center">
</b> <p>
{{ bid.shenasemeli }} <b>
</p> شناسه ملی:
</td> </b>
<td class="center"> {{ bid.shenasemeli }}
<p> </p>
<b>شماره ثبت: </td>
</b> <td class="center">
{{ bid.shomaresabt }} <p>
</p> <b>شماره ثبت:
</td> </b>
<td class="center"> {{ bid.shomaresabt }}
<p> </p>
<b>شماره اقتصادی: </td>
</b> <td class="center">
{{ bid.codeeghtesadi }} <p>
</p> <b>شماره اقتصادی:
</td> </b>
<td class="center"> {{ bid.codeeghtesadi }}
<p> </p>
<b>تلفن / نمابر:</b> </td>
{{ bid.tel }} <td class="center">
</p> <p>
</td> <b>تلفن / نمابر:</b>
</tr> {{ bid.tel }}
<tr> </p>
<td class="" colspan="1"> </td>
<p> </tr>
<b>کد پستی:</b> <tr>
{{ bid.postalcode }} <td class="" colspan="1">
</p> <p>
</td> <b>کد پستی:</b>
<td class="" colspan="3"> {{ bid.postalcode }}
<p> </p>
<b>آدرس: </td>
</b> <td class="" colspan="3">
استان <p>
{{ bid.ostan }}، شهر <b>آدرس:
{{ bid.shahrestan }}، </b>
{{ bid.address }} استان
</p> {{ bid.ostan }}، شهر
</td> {{ bid.shahrestan }}،
</tr> {{ bid.address }}
</tbody> </p>
</table> </td>
</div> </tr>
</tbody>
</table>
</div>
{% endif %}
<div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;"> <div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;">
<div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray"> <div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray">
<b style="color:white;">خریدار</b> <b style="color:white;">خریدار</b>
@ -180,8 +186,12 @@
<th class="text-white">شرح</th> <th class="text-white">شرح</th>
<th class="text-white">تعداد / مقدار</th> <th class="text-white">تعداد / مقدار</th>
<th class="text-white">مبلغ واحد</th> <th class="text-white">مبلغ واحد</th>
<th class="text-white">تخفیف</th> {% if printOptions.discountInfo %}
<th class="text-white">مالیات</th> <th class="text-white">تخفیف</th>
{% endif %}
{% if printOptions.taxInfo %}
<th class="text-white">مالیات</th>
{% endif %}
<th class="text-white">مبلغ کل</th> <th class="text-white">مبلغ کل</th>
</tr> </tr>
</thead> </thead>
@ -204,8 +214,12 @@
{{ item.commodity.unit.name }} {{ item.commodity.unit.name }}
</td> </td>
<td class="center item">{{ ((item.bs - item.tax + item.discount) / item.commdityCount) | number_format }}</td> <td class="center item">{{ ((item.bs - item.tax + item.discount) / item.commdityCount) | number_format }}</td>
<td class="center item">{{ item.discount | number_format }}</td> {% if printOptions.discountInfo %}
<td class="center item">{{ item.tax | number_format}}</td> <td class="center item">{{ item.discount | number_format }}</td>
{% endif %}
{% if printOptions.taxInfo %}
<td class="center item">{{ item.tax | number_format}}</td>
{% endif %}
<td class="center item">{{ item.bs| number_format }}</td> <td class="center item">{{ item.bs| number_format }}</td>
</tr> </tr>
{% endif %} {% endif %}
@ -217,81 +231,63 @@
<table style="width:100%;"> <table style="width:100%;">
<tbody> <tbody>
<tr class="stimol"> <tr class="stimol">
<td class="item"> <td class="item" style="width:70%;padding:1%">
<h4>
توضیحات:
{{doc.des}}
<br>
{% if (doc.relatedDocs | length != 0) and (printOptions.pays == true) %}
<h4 class="">
پرداخت‌ها:
</h4>
<ul class="">
{% for item in doc.relatedDocs%}
<li class="">
{{item.date}} - {{ item.amount | number_format }} - {{ item.des }}
</li>
{% endfor %}
</ul>
{% if printOptions.note == true %}
<h4 class="">
یاداشت:
</h4>
<ul class="">
<li class="">
{{note}}
</li>
</ul>
{% endif %}
</div>
{% endif %}
</h4>
</td>
<td class="item" style="width:15%;padding:1%">
<h4> <h4>
تخفیف: تخفیف:
{{discount | number_format}} {{discount | number_format}}
</h4> </h4>
</td>
<td class="item">
<h4> <h4>
مالیات: مالیات:
{{taxAll | number_format}} {{taxAll | number_format}}
</h4> </h4>
</td>
<td class="item">
<h4> <h4>
حمل و نقل: حمل و نقل:
{{transfer | number_format}} {{transfer | number_format}}
</h4> </h4>
</td>
<td class="item">
<h4> <h4>
مبلغ کل بدون تخفیف: مبلغ کل بدون تخفیف:
{{ (doc.amount + discount) | number_format}} {{ (doc.amount + discount) | number_format}}
</h4> </h4>
</td>
<td class="item">
<h4> <h4>
جمع کل قابل پرداخت: جمع کل قابل پرداخت:
{{doc.amount | number_format}} {{ doc.amount | number_format }}
</h4>
</td>
</tr>
<tr class="stimol">
<td class="item" colspan="5">
<h4>
توضیحات:
{{doc.des}}
</h4> </h4>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
{% if doc.relatedDocs | length != 0 %} <div style="width:40%;margin-top:0px;text-align:center;float:left;">
<h4 class="">
پرداخت‌ها:
</h4>
<div style="width:60%;margin-top:0px;text-align:center;">
<table style="width:100%;">
<thead>
<tr class="stimol" style="background-color:gray;">
<th class="text-white" style="width:80px">ردیف</th>
<th class="text-white">تاریخ</th>
<th class="text-white">مبلغ</th>
<th class="text-white">شرح</th>
</tr>
</thead>
<tbody>
<tbody>
{% set rowIndex = 0 %}
{% for item in doc.relatedDocs%}
{% set rowIndex = rowIndex + 1 %}
<tr class="stimol">
<td class="center item">{{rowIndex}}</td>
<td class="center item">{{item.date}}</td>
<td class="center item">{{ item.amount | number_format }}</td>
<td class="center item">{{ item.des }}</td>
</tr>
{% endfor %}
</tbody>
</tbody>
</table>
</div>
{% endif %}
<div style="width:40%;margin-top:20px;text-align:center;float:left;">
<table style="width:100%;"> <table style="width:100%;">
<tbody> <tbody>
<tr class=""> <tr class="">