add prelabel to persons and some bug fix in labels

This commit is contained in:
Hesabix 2025-02-13 11:00:45 +00:00
parent b62ec65209
commit 37cacfbd3f
12 changed files with 218 additions and 22 deletions

View file

@ -192,6 +192,7 @@ class BankController extends AbstractController
'شماره تراکنش',
'تاریخ',
'توضیحات',
'شرح سند',
'تفضیل',
'بستانکار',
'بدهکار',
@ -203,6 +204,7 @@ class BankController extends AbstractController
$transaction->getId(),
$transaction->getDoc()->getDate(),
$transaction->getDes(),
$transaction->getDoc()->getDes(),
$transaction->getRef()->getName(),
$transaction->getBs(),
$transaction->getBd(),

View file

@ -11,6 +11,7 @@ use App\Service\Jdate;
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;
use App\Entity\Business;
@ -49,20 +50,25 @@ class GeneralController extends AbstractController
}
#[Route('/api/general/get/time', name: 'general_get_time')]
public function general_get_time(Jdate $jdate): JsonResponse
public function general_get_time(Jdate $jdate, Request $request): JsonResponse
{
return $this->json(['timeNow'=>$jdate->jdate('Y/n/d',time())]);
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
if (array_key_exists('format', $params))
return $this->json(['timeNow' => $jdate->jdate($params['format'], time()), 'ts' => time()]);
return $this->json(['timeNow' => $jdate->jdate('Y/n/d', time()), 'ts' => time()]);
}
#[Route('/front/print/{id}', name: 'app_front_print')]
public function app_front_print(Provider $provider,EntityManagerInterface $entityManager,pdfMGR $pdfMGR,String $id)
public function app_front_print(Provider $provider, EntityManagerInterface $entityManager, pdfMGR $pdfMGR, string $id)
{
$print = $entityManager->getRepository(PrinterQueue::class)->findOneBy(['pid' => $id]);
if (!$print)
throw $this->createNotFoundException();
if ($print->isPosprint()) {
$pdfMGR->streamTwig2PDFInvoiceType($print);
}
else{
} else {
$pdfMGR->streamTwig2PDF($print);
}

View file

@ -2,6 +2,7 @@
namespace App\Controller;
use App\Entity\PersonPrelabel;
use App\Service\Extractor;
use App\Service\Log;
use App\Entity\Person;
@ -239,6 +240,7 @@ class PersonsController extends AbstractController
return $this->json(['result' => -1]);
if (count_chars(trim($params['nikename'])) == 0)
return $this->json(['result' => 3]);
if ($code == 0) {
$person = $entityManager->getRepository(Person::class)->findOneBy([
'nikename' => $params['nikename'],
@ -298,7 +300,14 @@ class PersonsController extends AbstractController
$person->setShenasemeli($params['shenasemeli']);
if (array_key_exists('company', $params))
$person->setCompany($params['company']);
if (array_key_exists('prelabel', $params)) {
if ($params['prelabel'] != '') {
$prelabel = $entityManager->getRepository(PersonPrelabel::class)->findOneBy(['code' => $params['prelabel']['code']]);
if ($prelabel) {
$person->setPrelabel($prelabel);
}
}
}
//inset cards
if (array_key_exists('accounts', $params)) {
foreach ($params['accounts'] as $item) {
@ -1233,4 +1242,22 @@ class PersonsController extends AbstractController
$log->insert('اشخاص', ' شخص با نام ' . $comName . ' حذف شد. ', $this->getUser(), $acc['bid']->getId());
return $this->json(['result' => 1]);
}
#[Route('/api/person/prelabels/list', name: 'app_persons_prelabels_list')]
public function app_persons_prelabels_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): Response
{
$acc = $access->hasRole('person');
if (!$acc)
throw $this->createAccessDeniedException();
$labels = $entityManager->getRepository(PersonPrelabel::class)->findAll();
$rows = [];
foreach ($labels as $key => $label) {
$rows[] = [
'label' => $label->getLabel(),
'code' => $label->getCode(),
];
}
return new Response(json_encode($rows));
}
}

View file

@ -149,6 +149,9 @@ class Person
#[ORM\OneToMany(mappedBy: 'salesman', targetEntity: PreInvoiceDoc::class)]
private Collection $preinvoiceDocsSalemans;
#[ORM\ManyToOne(inversedBy: 'people')]
private ?PersonPrelabel $prelabel = null;
public function __construct()
{
$this->hesabdariRows = new ArrayCollection();
@ -847,4 +850,16 @@ class Person
return $this;
}
public function getPrelabel(): ?PersonPrelabel
{
return $this->prelabel;
}
public function setPrelabel(?PersonPrelabel $prelabel): static
{
$this->prelabel = $prelabel;
return $this;
}
}

View file

@ -0,0 +1,93 @@
<?php
namespace App\Entity;
use App\Repository\PersonPrelabelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PersonPrelabelRepository::class)]
class PersonPrelabel
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $label = null;
#[ORM\Column(length: 255)]
private ?string $code = null;
/**
* @var Collection<int, Person>
*/
#[ORM\OneToMany(mappedBy: 'prelabel', targetEntity: Person::class)]
private Collection $people;
public function __construct()
{
$this->people = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): static
{
$this->label = $label;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): static
{
$this->code = $code;
return $this;
}
/**
* @return Collection<int, Person>
*/
public function getPeople(): Collection
{
return $this->people;
}
public function addPerson(Person $person): static
{
if (!$this->people->contains($person)) {
$this->people->add($person);
$person->setPrelabel($this);
}
return $this;
}
public function removePerson(Person $person): static
{
if ($this->people->removeElement($person)) {
// set the owning side to null (unless already changed)
if ($person->getPrelabel() === $this) {
$person->setPrelabel(null);
}
}
return $this;
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\PersonPrelabel;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<PersonPrelabel>
*/
class PersonPrelabelRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PersonPrelabel::class);
}
// /**
// * @return PersonPrelabel[] Returns an array of PersonPrelabel 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): ?PersonPrelabel
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -312,7 +312,11 @@ class Explore
'birthday' => $person->getBirthday(),
'speedAccess' => $person->isSpeedAccess(),
'address' => $person->getAddress(),
'prelabel' => '',
];
if ($person->getPrelabel()) {
$res['prelabel'] = $person->getPrelabel()->getLabel();
}
$res['accounts'] = self::ExplorePersonCards($person);
if (count($typesAll) != 0) {
$res['types'] = self::ExplorePersonTypes($typesAll);

View file

@ -48,6 +48,7 @@
<td class="center item">فاکتور/سند</td>
<td class="center item">تاریخ</td>
<td class="center item">توضیحات</td>
<td class="center item">شرح سند</td>
<td class="center item">تفضیل</td>
<td class="center item">بدهکار</td>
<td class="center item">بستانکار</td>
@ -63,6 +64,7 @@
<td class="center item">{{ item.doc.code }}</td>
<td class="center item">{{ item.doc.date }}</td>
<td class="center item">{{ item.des }}</td>
<td class="center item">{{ item.doc.des }}</td>
<td class="center item">{{ item.ref.name }}</td>
<td class="center item">{{ item.bd | number_format }}</td>
<td class="center item">{{ item.bs | number_format }}</td>

View file

@ -125,6 +125,7 @@
<p>
<b>نام:
</b>
{% if person.prelabel is not null %}{{ person.prelabel.label }}{% endif %}
{{ person.nikename }}
</p>
</td>

View file

@ -125,6 +125,7 @@
<p>
<b>نام:
</b>
{% if person.prelabel is not null %}{{ person.prelabel.label }}{% endif %}
{{ person.nikename }}
</p>
</td>

View file

@ -125,6 +125,7 @@
<p>
<b>نام:
</b>
{% if person.prelabel is not null %}{{ person.prelabel.label }}{% endif %}
{{ person.nikename }}
</p>
</td>

View file

@ -125,6 +125,7 @@
<p>
<b>نام:
</b>
{% if person.prelabel is not null %}{{ person.prelabel.label }}{% endif %}
{{ person.nikename }}
</p>
</td>