some progress in show persons list
This commit is contained in:
parent
efba33d10a
commit
f1f18b9561
|
@ -33,7 +33,8 @@ class PersonsController extends AbstractController
|
||||||
* @param int $length number of characters in the generated string
|
* @param int $length number of characters in the generated string
|
||||||
* @return string a new string is created with random characters of the desired length
|
* @return string a new string is created with random characters of the desired length
|
||||||
*/
|
*/
|
||||||
private function RandomString($length = 32) {
|
private function RandomString($length = 32)
|
||||||
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +104,7 @@ class PersonsController extends AbstractController
|
||||||
return $this->json(['result' => 2]);
|
return $this->json(['result' => 2]);
|
||||||
$person = new Person();
|
$person = new Person();
|
||||||
$person->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'person'));
|
$person->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'person'));
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'code' => $code
|
'code' => $code
|
||||||
|
@ -209,6 +209,45 @@ class PersonsController extends AbstractController
|
||||||
return $this->json(['result' => 1]);
|
return $this->json(['result' => 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/api/person/list/search', name: 'app_persons_list_search')]
|
||||||
|
public function app_persons_list_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
||||||
|
{
|
||||||
|
$acc = $access->hasRole('person');
|
||||||
|
if (!$acc)
|
||||||
|
throw $this->createAccessDeniedException();
|
||||||
|
$params = [];
|
||||||
|
if ($content = $request->getContent()) {
|
||||||
|
$params = json_decode($content, true);
|
||||||
|
}
|
||||||
|
if (array_key_exists('search', $params))
|
||||||
|
$persons = $entityManager->getRepository(Person::class)->searchByNikename($acc['bid'], $params['search'], 10);
|
||||||
|
else
|
||||||
|
$persons = $entityManager->getRepository(Person::class)->getLasts($acc['bid'], 10);
|
||||||
|
$response = [];
|
||||||
|
foreach ($persons as $key => $person) {
|
||||||
|
$temp = [
|
||||||
|
'id' => $person->getId(),
|
||||||
|
'nikename' => $person->getNikename(),
|
||||||
|
'code' => $person->getCode(),
|
||||||
|
'mobile' => $person->getMobile()
|
||||||
|
];
|
||||||
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
||||||
|
'person' => $person
|
||||||
|
]);
|
||||||
|
$bs = 0;
|
||||||
|
$bd = 0;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$bs += $row->getBs();
|
||||||
|
$bd += $row->getBd();
|
||||||
|
}
|
||||||
|
$temp['bs'] = $bs;
|
||||||
|
$temp['bd'] = $bd;
|
||||||
|
$temp['balance'] = $bs - $bd;
|
||||||
|
$response[] = $temp;
|
||||||
|
}
|
||||||
|
return $this->json($response);
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/api/person/list/limit', name: 'app_persons_list_limit')]
|
#[Route('/api/person/list/limit', name: 'app_persons_list_limit')]
|
||||||
public function app_persons_list_limit(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
public function app_persons_list_limit(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
|
@ -223,19 +262,32 @@ class PersonsController extends AbstractController
|
||||||
'bid' => $request->headers->get('activeBid'),
|
'bid' => $request->headers->get('activeBid'),
|
||||||
'speedAccess' => true
|
'speedAccess' => true
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$persons = $entityManager->getRepository(Person::class)->findBy([
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
||||||
'bid' => $request->headers->get('activeBid')
|
'bid' => $request->headers->get('activeBid')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$response = [];
|
$response = [];
|
||||||
foreach ($persons as $key => $person) {
|
foreach ($persons as $key => $person) {
|
||||||
$response[] = [
|
$temp = [
|
||||||
'id' => $person->getId(),
|
'id' => $person->getId(),
|
||||||
'nikename' => $person->getNikename(),
|
'nikename' => $person->getNikename(),
|
||||||
'code' => $person->getCode(),
|
'code' => $person->getCode(),
|
||||||
|
'mobile' => $person->getMobile()
|
||||||
];
|
];
|
||||||
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
||||||
|
'person' => $person
|
||||||
|
]);
|
||||||
|
$bs = 0;
|
||||||
|
$bd = 0;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$bs += $row->getBs();
|
||||||
|
$bd += $row->getBd();
|
||||||
|
}
|
||||||
|
$temp['bs'] = $bs;
|
||||||
|
$temp['bd'] = $bd;
|
||||||
|
$temp['balance'] = $bs - $bd;
|
||||||
|
$response[] = $temp;
|
||||||
}
|
}
|
||||||
return $this->json($response);
|
return $this->json($response);
|
||||||
}
|
}
|
||||||
|
@ -254,8 +306,7 @@ class PersonsController extends AbstractController
|
||||||
'bid' => $request->headers->get('activeBid'),
|
'bid' => $request->headers->get('activeBid'),
|
||||||
'speedAccess' => true
|
'speedAccess' => true
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$persons = $entityManager->getRepository(Person::class)->findBy([
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
||||||
'bid' => $request->headers->get('activeBid')
|
'bid' => $request->headers->get('activeBid')
|
||||||
]);
|
]);
|
||||||
|
@ -292,8 +343,7 @@ class PersonsController extends AbstractController
|
||||||
'bid' => $request->headers->get('activeBid'),
|
'bid' => $request->headers->get('activeBid'),
|
||||||
'speedAccess' => true
|
'speedAccess' => true
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$persons = $entityManager->getRepository(Person::class)->findBy([
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
||||||
'bid' => $request->headers->get('activeBid')
|
'bid' => $request->headers->get('activeBid')
|
||||||
]);
|
]);
|
||||||
|
@ -360,7 +410,8 @@ class PersonsController extends AbstractController
|
||||||
'page_title' => 'فهرست بدهکاران',
|
'page_title' => 'فهرست بدهکاران',
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'persons' => $result
|
'persons' => $result
|
||||||
]));
|
])
|
||||||
|
);
|
||||||
return $this->json(['id' => $pid]);
|
return $this->json(['id' => $pid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,8 +429,7 @@ class PersonsController extends AbstractController
|
||||||
'bid' => $request->headers->get('activeBid'),
|
'bid' => $request->headers->get('activeBid'),
|
||||||
'speedAccess' => true
|
'speedAccess' => true
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$persons = $entityManager->getRepository(Person::class)->findBy([
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
||||||
'bid' => $request->headers->get('activeBid')
|
'bid' => $request->headers->get('activeBid')
|
||||||
]);
|
]);
|
||||||
|
@ -447,7 +497,8 @@ class PersonsController extends AbstractController
|
||||||
'page_title' => 'فهرست بستانکاران',
|
'page_title' => 'فهرست بستانکاران',
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'persons' => $result
|
'persons' => $result
|
||||||
]));
|
])
|
||||||
|
);
|
||||||
return $this->json(['id' => $pid]);
|
return $this->json(['id' => $pid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,8 +516,7 @@ class PersonsController extends AbstractController
|
||||||
$persons = $entityManager->getRepository(Person::class)->findBy([
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
||||||
'bid' => $acc['bid']
|
'bid' => $acc['bid']
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$persons = [];
|
$persons = [];
|
||||||
foreach ($params['items'] as $param) {
|
foreach ($params['items'] as $param) {
|
||||||
$prs = $entityManager->getRepository(Person::class)->findOneBy([
|
$prs = $entityManager->getRepository(Person::class)->findOneBy([
|
||||||
|
@ -484,7 +534,8 @@ class PersonsController extends AbstractController
|
||||||
'page_title' => 'فهرست اشخاص',
|
'page_title' => 'فهرست اشخاص',
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'persons' => $persons
|
'persons' => $persons
|
||||||
]));
|
])
|
||||||
|
);
|
||||||
return $this->json(['id' => $pid]);
|
return $this->json(['id' => $pid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,8 +556,7 @@ class PersonsController extends AbstractController
|
||||||
$persons = $entityManager->getRepository(Person::class)->findBy([
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
||||||
'bid' => $acc['bid']
|
'bid' => $acc['bid']
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$persons = [];
|
$persons = [];
|
||||||
foreach ($params['items'] as $param) {
|
foreach ($params['items'] as $param) {
|
||||||
$prs = $entityManager->getRepository(Person::class)->findOneBy([
|
$prs = $entityManager->getRepository(Person::class)->findOneBy([
|
||||||
|
@ -543,8 +593,7 @@ class PersonsController extends AbstractController
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'person' => $person
|
'person' => $person
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$transactions = [];
|
$transactions = [];
|
||||||
foreach ($params['items'] as $param) {
|
foreach ($params['items'] as $param) {
|
||||||
$prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
|
$prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
|
||||||
|
@ -608,8 +657,7 @@ class PersonsController extends AbstractController
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'person' => $person
|
'person' => $person
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$transactions = [];
|
$transactions = [];
|
||||||
foreach ($params['items'] as $param) {
|
foreach ($params['items'] as $param) {
|
||||||
$prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
|
$prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
|
||||||
|
@ -629,7 +677,8 @@ class PersonsController extends AbstractController
|
||||||
'page_title' => 'کارت حساب' . ' ' . $person->getNikename(),
|
'page_title' => 'کارت حساب' . ' ' . $person->getNikename(),
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'items' => $transactions
|
'items' => $transactions
|
||||||
]));
|
])
|
||||||
|
);
|
||||||
return $this->json(['id' => $pid]);
|
return $this->json(['id' => $pid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,8 +698,7 @@ class PersonsController extends AbstractController
|
||||||
'type' => 'person_receive',
|
'type' => 'person_receive',
|
||||||
'year' => $acc['year']
|
'year' => $acc['year']
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$items = [];
|
$items = [];
|
||||||
foreach ($params['items'] as $param) {
|
foreach ($params['items'] as $param) {
|
||||||
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
||||||
|
@ -670,7 +718,8 @@ class PersonsController extends AbstractController
|
||||||
'page_title' => 'لیست دریافتها',
|
'page_title' => 'لیست دریافتها',
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'items' => $items
|
'items' => $items
|
||||||
]));
|
])
|
||||||
|
);
|
||||||
return $this->json(['id' => $pid]);
|
return $this->json(['id' => $pid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,8 +742,7 @@ class PersonsController extends AbstractController
|
||||||
'type' => 'person_receive',
|
'type' => 'person_receive',
|
||||||
'year' => $acc['year']
|
'year' => $acc['year']
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$items = [];
|
$items = [];
|
||||||
foreach ($params['items'] as $param) {
|
foreach ($params['items'] as $param) {
|
||||||
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
||||||
|
@ -726,8 +774,7 @@ class PersonsController extends AbstractController
|
||||||
'type' => 'person_send',
|
'type' => 'person_send',
|
||||||
'year' => $acc['year']
|
'year' => $acc['year']
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$items = [];
|
$items = [];
|
||||||
foreach ($params['items'] as $param) {
|
foreach ($params['items'] as $param) {
|
||||||
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
||||||
|
@ -747,7 +794,8 @@ class PersonsController extends AbstractController
|
||||||
'page_title' => 'لیست پرداختها',
|
'page_title' => 'لیست پرداختها',
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'items' => $items
|
'items' => $items
|
||||||
]));
|
])
|
||||||
|
);
|
||||||
return $this->json(['id' => $pid]);
|
return $this->json(['id' => $pid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,8 +818,7 @@ class PersonsController extends AbstractController
|
||||||
'type' => 'person_send',
|
'type' => 'person_send',
|
||||||
'year' => $acc['year']
|
'year' => $acc['year']
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$items = [];
|
$items = [];
|
||||||
foreach ($params['items'] as $param) {
|
foreach ($params['items'] as $param) {
|
||||||
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
||||||
|
@ -855,5 +902,4 @@ class PersonsController extends AbstractController
|
||||||
$log->insert('اشخاص', 'تعداد ' . count($data) . ' شخص به صورت گروهی وارد شد.', $this->getUser(), $request->headers->get('activeBid'));
|
$log->insert('اشخاص', 'تعداد ' . count($data) . ' شخص به صورت گروهی وارد شد.', $this->getUser(), $request->headers->get('activeBid'));
|
||||||
return $this->json(['result' => 1]);
|
return $this->json(['result' => 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
use App\Entity\Person;
|
use App\Entity\Person;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use App\Entity\Business;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends ServiceEntityRepository<Person>
|
* @extends ServiceEntityRepository<Person>
|
||||||
|
@ -39,6 +40,36 @@ class PersonRepository extends ServiceEntityRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Person[] Returns an array of Person objects
|
||||||
|
*/
|
||||||
|
public function searchByNikename(Business $bid,string $search,int $maxResults = 10): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('p')
|
||||||
|
->andWhere('p.bid = :val')
|
||||||
|
->andWhere("p.nikename LIKE :search")
|
||||||
|
->setParameter('val', $bid)
|
||||||
|
->setParameter('search', '%' . $search . '%')
|
||||||
|
->setMaxResults($maxResults)
|
||||||
|
->orderBy('p.id', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Person[] Returns an array of Person objects
|
||||||
|
*/
|
||||||
|
public function getLasts(Business $bid,int $maxResults = 10): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('p')
|
||||||
|
->andWhere('p.bid = :val')
|
||||||
|
->setParameter('val', $bid)
|
||||||
|
->setMaxResults($maxResults)
|
||||||
|
->orderBy('p.id', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Person[] Returns an array of Person objects
|
* @return Person[] Returns an array of Person objects
|
||||||
*/
|
*/
|
||||||
|
@ -53,8 +84,7 @@ class PersonRepository extends ServiceEntityRepository
|
||||||
->setParameter('val', $bid)
|
->setParameter('val', $bid)
|
||||||
->orderBy('p.id', 'ASC')
|
->orderBy('p.id', 'ASC')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult()
|
->getResult();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function findOneBySomeField($value): ?Person
|
// public function findOneBySomeField($value): ?Person
|
||||||
|
|
Loading…
Reference in a new issue