add person types and person cards
This commit is contained in:
parent
19b701a185
commit
267b28cf87
|
@ -9,6 +9,9 @@ use App\Entity\Business;
|
|||
use App\Service\Provider;
|
||||
use App\Entity\HesabdariDoc;
|
||||
use App\Entity\HesabdariRow;
|
||||
use App\Entity\PersonCard;
|
||||
use App\Entity\PersonType;
|
||||
use App\Service\Explore;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
@ -33,6 +36,19 @@ class PersonsController extends AbstractController
|
|||
return substr(str_shuffle(str_repeat($x='23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
#[Route('/api/person/types/get', name: 'app_persons_types_get')]
|
||||
public function app_persons_types_get(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
$acc = $access->hasRole('person');
|
||||
if(!$acc)
|
||||
throw $this->createAccessDeniedException();
|
||||
$items = $entityManager->getRepository(PersonType::class)->findAll();
|
||||
return $this->json(Explore::ExplorePersonTypes($items));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
|
@ -46,7 +62,8 @@ class PersonsController extends AbstractController
|
|||
'bid'=>$acc['bid'],
|
||||
'code'=>$code
|
||||
]);
|
||||
$response = $provider->Entity2Array($person,0);
|
||||
$types = $entityManager->getRepository(PersonType::class)->findAll();
|
||||
$response = Explore::ExplorePerson($person,$types);
|
||||
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
||||
'person'=>$person
|
||||
]);
|
||||
|
@ -110,6 +127,8 @@ class PersonsController extends AbstractController
|
|||
$person->setDes($params['des']);
|
||||
if(array_key_exists('mobile',$params))
|
||||
$person->setMobile($params['mobile']);
|
||||
if(array_key_exists('mobile2',$params))
|
||||
$person->setMobile2($params['mobile2']);
|
||||
if(array_key_exists('fax',$params))
|
||||
$person->setFax($params['fax']);
|
||||
if(array_key_exists('website',$params))
|
||||
|
@ -132,7 +151,58 @@ class PersonsController extends AbstractController
|
|||
$person->setShenasemeli($params['shenasemeli']);
|
||||
if(array_key_exists('company',$params))
|
||||
$person->setCompany($params['company']);
|
||||
|
||||
//inset cards
|
||||
if(array_key_exists('accounts',$params)){
|
||||
foreach($params['accounts'] as $item){
|
||||
$card = $entityManager->getRepository(PersonCard::class)->findOneBy([
|
||||
'bid'=>$acc['bid'],
|
||||
'person'=>$person,
|
||||
'bank'=>$item['bank']
|
||||
]);
|
||||
if(!$card)
|
||||
$card = new PersonCard();
|
||||
|
||||
$card->setPerson($person);
|
||||
$card->setBid($acc['bid']);
|
||||
$card->setShabaNum($item['shabaNum']);
|
||||
$card->setCardNum($item['cardNum']);
|
||||
$card->setAccountNum($item['accountNum']);
|
||||
$card->setBank($item['bank']);
|
||||
$entityManager->persist($card);
|
||||
}
|
||||
}
|
||||
//remove not sended accounts
|
||||
$accounts = $entityManager->getRepository(PersonCard::class)->findBy([
|
||||
'bid'=>$acc['bid'],
|
||||
'person'=>$person,
|
||||
]);
|
||||
foreach($accounts as $item){
|
||||
$deleted = true;
|
||||
foreach($params['accounts'] as $param){
|
||||
if($item->getBank() == $param['bank']){
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
if($deleted){
|
||||
$entityManager->remove($item);
|
||||
}
|
||||
}
|
||||
$entityManager->persist($person);
|
||||
|
||||
//insert new types
|
||||
$types = $entityManager->getRepository(PersonType::class)->findAll();
|
||||
foreach($params['types'] as $item){
|
||||
if($item['checked'] == true)
|
||||
$person->addType($entityManager->getRepository(PersonType::class)->findOneBy([
|
||||
'code'=>$item['code']
|
||||
]));
|
||||
elseif($item['checked'] == false){
|
||||
$person->removeType($entityManager->getRepository(PersonType::class)->findOneBy([
|
||||
'code'=>$item['code']
|
||||
]));
|
||||
}
|
||||
}
|
||||
$entityManager->flush();
|
||||
$log->insert('اشخاص','شخص با نام مستعار ' . $params['nikename'] . ' افزوده/ویرایش شد.',$this->getUser(),$request->headers->get('activeBid'));
|
||||
return $this->json(['result' => 1]);
|
||||
|
|
|
@ -205,6 +205,9 @@ class Business
|
|||
#[ORM\OneToMany(mappedBy: 'bid', targetEntity: Cheque::class, orphanRemoval: true)]
|
||||
private Collection $cheques;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'bid', targetEntity: PersonCard::class, orphanRemoval: true)]
|
||||
private Collection $personCards;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->logs = new ArrayCollection();
|
||||
|
@ -231,6 +234,7 @@ class Business
|
|||
$this->shareholders = new ArrayCollection();
|
||||
$this->hooks = new ArrayCollection();
|
||||
$this->cheques = new ArrayCollection();
|
||||
$this->personCards = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
|
@ -1389,4 +1393,34 @@ class Business
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, PersonCard>
|
||||
*/
|
||||
public function getPersonCards(): Collection
|
||||
{
|
||||
return $this->personCards;
|
||||
}
|
||||
|
||||
public function addPersonCard(PersonCard $personCard): static
|
||||
{
|
||||
if (!$this->personCards->contains($personCard)) {
|
||||
$this->personCards->add($personCard);
|
||||
$personCard->setBid($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removePersonCard(PersonCard $personCard): static
|
||||
{
|
||||
if ($this->personCards->removeElement($personCard)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($personCard->getBid() === $this) {
|
||||
$personCard->setBid(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,6 +119,15 @@ class Person
|
|||
#[ORM\OneToMany(mappedBy: 'person', targetEntity: Cheque::class)]
|
||||
private Collection $cheques;
|
||||
|
||||
#[ORM\ManyToMany(targetEntity: PersonType::class, inversedBy: 'people')]
|
||||
private Collection $type;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'person', targetEntity: PersonCard::class, orphanRemoval: true)]
|
||||
private Collection $personCards;
|
||||
|
||||
#[ORM\Column(length: 15, nullable: true)]
|
||||
private ?string $mobile2 = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->hesabdariRows = new ArrayCollection();
|
||||
|
@ -127,6 +136,8 @@ class Person
|
|||
$this->storeroomTickets = new ArrayCollection();
|
||||
$this->shareholders = new ArrayCollection();
|
||||
$this->cheques = new ArrayCollection();
|
||||
$this->type = new ArrayCollection();
|
||||
$this->personCards = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
|
@ -625,4 +636,70 @@ class Person
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, PersonType>
|
||||
*/
|
||||
public function getType(): Collection
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function addType(PersonType $type): static
|
||||
{
|
||||
if (!$this->type->contains($type)) {
|
||||
$this->type->add($type);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeType(PersonType $type): static
|
||||
{
|
||||
$this->type->removeElement($type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, PersonCard>
|
||||
*/
|
||||
public function getPersonCards(): Collection
|
||||
{
|
||||
return $this->personCards;
|
||||
}
|
||||
|
||||
public function addPersonCard(PersonCard $personCard): static
|
||||
{
|
||||
if (!$this->personCards->contains($personCard)) {
|
||||
$this->personCards->add($personCard);
|
||||
$personCard->setPerson($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removePersonCard(PersonCard $personCard): static
|
||||
{
|
||||
if ($this->personCards->removeElement($personCard)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($personCard->getPerson() === $this) {
|
||||
$personCard->setPerson(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMobile2(): ?string
|
||||
{
|
||||
return $this->mobile2;
|
||||
}
|
||||
|
||||
public function setMobile2(?string $mobile2): static
|
||||
{
|
||||
$this->mobile2 = $mobile2;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
112
hesabixCore/src/Entity/PersonCard.php
Normal file
112
hesabixCore/src/Entity/PersonCard.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\PersonCardRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PersonCardRepository::class)]
|
||||
class PersonCard
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'personCards')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Business $bid = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'personCards')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Person $person = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $bank = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $cardNum = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $accountNum = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $shabaNum = 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 getPerson(): ?Person
|
||||
{
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
public function setPerson(?Person $person): static
|
||||
{
|
||||
$this->person = $person;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBank(): ?string
|
||||
{
|
||||
return $this->bank;
|
||||
}
|
||||
|
||||
public function setBank(string $bank): static
|
||||
{
|
||||
$this->bank = $bank;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCardNum(): ?string
|
||||
{
|
||||
return $this->cardNum;
|
||||
}
|
||||
|
||||
public function setCardNum(?string $cardNum): static
|
||||
{
|
||||
$this->cardNum = $cardNum;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAccountNum(): ?string
|
||||
{
|
||||
return $this->accountNum;
|
||||
}
|
||||
|
||||
public function setAccountNum(?string $accountNum): static
|
||||
{
|
||||
$this->accountNum = $accountNum;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getShabaNum(): ?string
|
||||
{
|
||||
return $this->shabaNum;
|
||||
}
|
||||
|
||||
public function setShabaNum(?string $shabaNum): static
|
||||
{
|
||||
$this->shabaNum = $shabaNum;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
87
hesabixCore/src/Entity/PersonType.php
Normal file
87
hesabixCore/src/Entity/PersonType.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\PersonTypeRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PersonTypeRepository::class)]
|
||||
class PersonType
|
||||
{
|
||||
#[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;
|
||||
|
||||
#[ORM\ManyToMany(targetEntity: Person::class, mappedBy: 'type')]
|
||||
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->addType($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removePerson(Person $person): static
|
||||
{
|
||||
if ($this->people->removeElement($person)) {
|
||||
$person->removeType($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
48
hesabixCore/src/Repository/PersonCardRepository.php
Normal file
48
hesabixCore/src/Repository/PersonCardRepository.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\PersonCard;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<PersonCard>
|
||||
*
|
||||
* @method PersonCard|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method PersonCard|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method PersonCard[] findAll()
|
||||
* @method PersonCard[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class PersonCardRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, PersonCard::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return PersonCard[] Returns an array of PersonCard 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): ?PersonCard
|
||||
// {
|
||||
// return $this->createQueryBuilder('p')
|
||||
// ->andWhere('p.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
48
hesabixCore/src/Repository/PersonTypeRepository.php
Normal file
48
hesabixCore/src/Repository/PersonTypeRepository.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\PersonType;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<PersonType>
|
||||
*
|
||||
* @method PersonType|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method PersonType|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method PersonType[] findAll()
|
||||
* @method PersonType[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class PersonTypeRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, PersonType::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return PersonType[] Returns an array of PersonType 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): ?PersonType
|
||||
// {
|
||||
// return $this->createQueryBuilder('p')
|
||||
// ->andWhere('p.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
|
@ -13,10 +13,24 @@ use App\Entity\HesabdariRow;
|
|||
use App\Entity\HesabdariTable;
|
||||
use App\Entity\Money;
|
||||
use App\Entity\Person;
|
||||
use App\Entity\PersonType;
|
||||
use App\Entity\Salary;
|
||||
|
||||
class Explore{
|
||||
|
||||
public static function ExplorePersonType(PersonType $type){
|
||||
return [
|
||||
'label'=>$type->getLabel(),
|
||||
'code'=>$type->getCode(),
|
||||
'checked'=>false
|
||||
];
|
||||
}
|
||||
|
||||
public static function ExplorePersonTypes($types){
|
||||
$result = [];
|
||||
foreach($types as $type)
|
||||
$result[] = self::ExplorePersonType($type);
|
||||
return $result;
|
||||
}
|
||||
public static function ExploreSellDoc(HesabdariDoc $hesabdariDoc){
|
||||
$result = self::ExploreHesabdariDoc($hesabdariDoc);
|
||||
$person = [];
|
||||
|
@ -143,17 +157,64 @@ class Explore{
|
|||
];
|
||||
return null;
|
||||
}
|
||||
public static function ExplorePerson(Person | null $person){
|
||||
if($person)
|
||||
return [
|
||||
public static function ExplorePerson(Person | null $person,array $typesAll){
|
||||
if($person){
|
||||
$res = [
|
||||
'id' => $person->getId(),
|
||||
'code' => $person->getCode(),
|
||||
'nikename' => $person->getNikename(),
|
||||
'name' => $person->getName(),
|
||||
//most be completed
|
||||
'tel' => $person->getTel(),
|
||||
'mobile' => $person->getmobile(),
|
||||
'mobile2' => $person->getMobile2(),
|
||||
'des' =>$person->getDes(),
|
||||
'company' => $person->getCompany(),
|
||||
'shenasemeli' => $person->getShenasemeli(),
|
||||
'sabt' => $person->getSabt(),
|
||||
'shahr' => $person->getShahr(),
|
||||
'keshvar' => $person->getKeshvar(),
|
||||
'ostan' => $person->getOstan(),
|
||||
'postalcode' => $person->getPostalcode(),
|
||||
'codeeghtesadi' => $person->getCodeeghtesadi(),
|
||||
'email' => $person->getEmail(),
|
||||
'website' => $person->getWebsite(),
|
||||
'fax' => $person->getFax(),
|
||||
'birthday' => $person->getBirthday(),
|
||||
'speedAccess'=>$person->isSpeedAccess(),
|
||||
|
||||
];
|
||||
$res['accounts'] = self::ExplorePersonCards($person);
|
||||
$res['types'] = self::ExplorePersonTypes($typesAll);
|
||||
|
||||
foreach($res['types'] as $key=>$item){
|
||||
foreach($person->getType() as $type){
|
||||
if($item['code'] == $type->getCode())
|
||||
$res['types'][$key]['checked'] = true;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static function ExplorePersons($items){
|
||||
$result = [];
|
||||
foreach($items as $item)
|
||||
$result[] = self::ExplorePerson($item);
|
||||
return $result;
|
||||
}
|
||||
public static function ExplorePersonCards(Person $person){
|
||||
$res = [];
|
||||
foreach($person->getPersonCards() as $item){
|
||||
$res[] = [
|
||||
'bank'=>$item->getBank(),
|
||||
'shabaNum'=>$item->getShabaNum(),
|
||||
'cardNum'=>$item->getCardNum(),
|
||||
'accountNum'=>$item->getAccountNum()
|
||||
];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function ExploreHesabdariTable(HesabdariTable $table){
|
||||
return [
|
||||
'id' => $table->getId(),
|
||||
|
|
Loading…
Reference in a new issue