2023-09-21 23:04:08 +03:30
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
2025-02-13 14:30:45 +03:30
|
|
|
use App\Entity\PersonPrelabel;
|
2024-11-03 14:40:50 +03:30
|
|
|
use App\Service\Extractor;
|
2024-02-13 12:09:20 +03:30
|
|
|
use App\Service\Log;
|
2023-09-21 23:04:08 +03:30
|
|
|
use App\Entity\Person;
|
|
|
|
use App\Service\Access;
|
2024-02-13 12:09:20 +03:30
|
|
|
use App\Entity\Business;
|
2023-09-21 23:04:08 +03:30
|
|
|
use App\Service\Provider;
|
2024-02-13 12:09:20 +03:30
|
|
|
use App\Entity\HesabdariDoc;
|
|
|
|
use App\Entity\HesabdariRow;
|
2024-04-20 11:03:47 +03:30
|
|
|
use App\Entity\PersonCard;
|
|
|
|
use App\Entity\PersonType;
|
2024-06-13 15:01:57 +03:30
|
|
|
use App\Entity\Storeroom;
|
|
|
|
use App\Entity\StoreroomItem;
|
|
|
|
use App\Entity\StoreroomTicket;
|
2024-04-20 11:03:47 +03:30
|
|
|
use App\Service\Explore;
|
2023-09-21 23:04:08 +03:30
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2024-02-13 12:09:20 +03:30
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
2023-09-21 23:04:08 +03:30
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2024-02-13 12:09:20 +03:30
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Exception;
|
2023-09-21 23:04:08 +03:30
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2024-02-13 12:09:20 +03:30
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
2023-09-21 23:04:08 +03:30
|
|
|
use Symfony\Component\Serializer\SerializerInterface;
|
2024-02-13 12:09:20 +03:30
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2024-04-22 18:55:12 +03:30
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2023-09-21 23:04:08 +03:30
|
|
|
|
|
|
|
class PersonsController extends AbstractController
|
|
|
|
{
|
2024-02-13 12:09:20 +03:30
|
|
|
|
|
|
|
/**
|
|
|
|
* function to generate random strings
|
|
|
|
* @param int $length number of characters in the generated string
|
|
|
|
* @return string a new string is created with random characters of the desired length
|
|
|
|
*/
|
2024-04-27 23:45:38 +03:30
|
|
|
private function RandomString($length = 32)
|
|
|
|
{
|
|
|
|
return substr(str_shuffle(str_repeat($x = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
|
2024-02-13 12:09:20 +03:30
|
|
|
}
|
|
|
|
|
2024-04-27 23:45:38 +03:30
|
|
|
/**
|
2024-04-20 11:03:47 +03:30
|
|
|
* @throws \ReflectionException
|
|
|
|
*/
|
|
|
|
#[Route('/api/person/types/get', name: 'app_persons_types_get')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_types_get(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2024-04-20 11:03:47 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2024-04-20 11:03:47 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$items = $entityManager->getRepository(PersonType::class)->findAll();
|
|
|
|
return $this->json(Explore::ExplorePersonTypes($items));
|
|
|
|
}
|
|
|
|
|
2023-11-10 18:55:20 +03:30
|
|
|
/**
|
|
|
|
* @throws \ReflectionException
|
|
|
|
*/
|
2023-09-21 23:04:08 +03:30
|
|
|
#[Route('/api/person/info/{code}', name: 'app_persons_info')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2023-09-21 23:04:08 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-09-21 23:04:08 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'code' => $code
|
2023-09-21 23:04:08 +03:30
|
|
|
]);
|
2024-04-20 11:03:47 +03:30
|
|
|
$types = $entityManager->getRepository(PersonType::class)->findAll();
|
2024-04-27 23:45:38 +03:30
|
|
|
$response = Explore::ExplorePerson($person, $types);
|
2023-11-07 16:46:26 +03:30
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'person' => $person
|
2023-11-07 16:46:26 +03:30
|
|
|
]);
|
|
|
|
$bs = 0;
|
|
|
|
$bd = 0;
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($rows as $row) {
|
2024-11-11 19:11:27 +03:30
|
|
|
if ($row->getDoc()->getMoney() == $acc['money']) {
|
|
|
|
$bs += $row->getBs();
|
|
|
|
$bd += $row->getBd();
|
|
|
|
}
|
2023-11-07 16:46:26 +03:30
|
|
|
}
|
|
|
|
$response['bs'] = $bs;
|
|
|
|
$response['bd'] = $bd;
|
|
|
|
$response['balance'] = $bs - $bd;
|
|
|
|
return $this->json($response);
|
2023-09-21 23:04:08 +03:30
|
|
|
}
|
2024-11-03 14:40:50 +03:30
|
|
|
|
|
|
|
#[Route('/api/person/group/mod', name: 'app_persons_group_mod')]
|
|
|
|
public function app_persons_group_mod(Provider $provider, Extractor $extractor, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
|
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
|
|
|
if (!$acc)
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$paramsAll = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$paramsAll = json_decode($content, true);
|
|
|
|
}
|
|
|
|
if (!array_key_exists('items', $paramsAll))
|
|
|
|
return $this->json($extractor->paramsNotSend());
|
|
|
|
foreach ($paramsAll['items'] as $params) {
|
|
|
|
if (!array_key_exists('nikename', $params))
|
|
|
|
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'],
|
|
|
|
'bid' => $acc['bid']
|
|
|
|
]);
|
|
|
|
//check exist before
|
|
|
|
if (!$person) {
|
|
|
|
$person = new Person();
|
|
|
|
$person->setCode($provider->getAccountingCode($acc['bid'], 'person'));
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'code' => $code
|
|
|
|
]);
|
|
|
|
if (!$person)
|
|
|
|
throw $this->createNotFoundException();
|
|
|
|
}
|
|
|
|
$person->setBid($acc['bid']);
|
|
|
|
$person->setNikename($params['nikename']);
|
|
|
|
if (array_key_exists('name', $params))
|
|
|
|
$person->setName($params['name']);
|
|
|
|
if (array_key_exists('birthday', $params))
|
|
|
|
$person->setBirthday($params['birthday']);
|
|
|
|
if (array_key_exists('tel', $params))
|
|
|
|
$person->setTel($params['tel']);
|
|
|
|
if (array_key_exists('speedAccess', $params))
|
|
|
|
$person->setSpeedAccess($params['speedAccess']);
|
|
|
|
if (array_key_exists('address', $params))
|
|
|
|
$person->setAddress($params['address']);
|
|
|
|
if (array_key_exists('des', $params))
|
|
|
|
$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))
|
|
|
|
$person->setWebsite($params['website']);
|
|
|
|
if (array_key_exists('email', $params))
|
|
|
|
$person->setEmail($params['email']);
|
|
|
|
if (array_key_exists('postalcode', $params))
|
|
|
|
$person->setPostalcode($params['postalcode']);
|
|
|
|
if (array_key_exists('shahr', $params))
|
|
|
|
$person->setShahr($params['shahr']);
|
|
|
|
if (array_key_exists('ostan', $params))
|
|
|
|
$person->setOstan($params['ostan']);
|
|
|
|
if (array_key_exists('keshvar', $params))
|
|
|
|
$person->setKeshvar($params['keshvar']);
|
|
|
|
if (array_key_exists('sabt', $params))
|
|
|
|
$person->setSabt($params['sabt']);
|
|
|
|
if (array_key_exists('codeeghtesadi', $params))
|
|
|
|
$person->setCodeeghtesadi($params['codeeghtesadi']);
|
|
|
|
if (array_key_exists('shenasemeli', $params))
|
|
|
|
$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(), $acc['bid']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->json([
|
|
|
|
'Success' => true,
|
|
|
|
'result' => 1,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-09-21 23:04:08 +03:30
|
|
|
#[Route('/api/person/mod/{code}', name: 'app_persons_mod')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
|
2023-09-21 23:04:08 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-09-21 23:04:08 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('nikename', $params))
|
|
|
|
return $this->json(['result' => -1]);
|
|
|
|
if (count_chars(trim($params['nikename'])) == 0)
|
|
|
|
return $this->json(['result' => 3]);
|
2025-02-13 14:30:45 +03:30
|
|
|
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($code == 0) {
|
2023-09-21 23:04:08 +03:30
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'nikename' => $params['nikename'],
|
|
|
|
'bid' => $acc['bid']
|
2023-09-21 23:04:08 +03:30
|
|
|
]);
|
|
|
|
//check exist before
|
2024-11-03 14:40:50 +03:30
|
|
|
if (!$person) {
|
|
|
|
$person = new Person();
|
|
|
|
$person->setCode($provider->getAccountingCode($acc['bid'], 'person'));
|
|
|
|
}
|
|
|
|
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2023-09-21 23:04:08 +03:30
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'code' => $code
|
2023-09-21 23:04:08 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$person)
|
2023-09-21 23:04:08 +03:30
|
|
|
throw $this->createNotFoundException();
|
|
|
|
}
|
|
|
|
$person->setBid($acc['bid']);
|
|
|
|
$person->setNikename($params['nikename']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('name', $params))
|
2023-09-21 23:04:08 +03:30
|
|
|
$person->setName($params['name']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('birthday', $params))
|
2023-11-06 00:18:12 +03:30
|
|
|
$person->setBirthday($params['birthday']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('tel', $params))
|
2023-09-21 23:04:08 +03:30
|
|
|
$person->setTel($params['tel']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('speedAccess', $params))
|
2023-11-27 11:44:05 +03:30
|
|
|
$person->setSpeedAccess($params['speedAccess']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('address', $params))
|
2023-09-21 23:04:08 +03:30
|
|
|
$person->setAddress($params['address']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('des', $params))
|
2023-09-21 23:04:08 +03:30
|
|
|
$person->setDes($params['des']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('mobile', $params))
|
2023-09-21 23:04:08 +03:30
|
|
|
$person->setMobile($params['mobile']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('mobile2', $params))
|
2024-04-20 11:03:47 +03:30
|
|
|
$person->setMobile2($params['mobile2']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('fax', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setFax($params['fax']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('website', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setWebsite($params['website']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('email', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setEmail($params['email']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('postalcode', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setPostalcode($params['postalcode']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('shahr', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setShahr($params['shahr']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('ostan', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setOstan($params['ostan']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('keshvar', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setKeshvar($params['keshvar']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('sabt', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setSabt($params['sabt']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('codeeghtesadi', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setCodeeghtesadi($params['codeeghtesadi']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('shenasemeli', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setShenasemeli($params['shenasemeli']);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('company', $params))
|
2023-09-30 21:01:00 +03:30
|
|
|
$person->setCompany($params['company']);
|
2025-02-13 14:30:45 +03:30
|
|
|
if (array_key_exists('prelabel', $params)) {
|
|
|
|
if ($params['prelabel'] != '') {
|
|
|
|
$prelabel = $entityManager->getRepository(PersonPrelabel::class)->findOneBy(['code' => $params['prelabel']['code']]);
|
|
|
|
if ($prelabel) {
|
|
|
|
$person->setPrelabel($prelabel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-20 11:03:47 +03:30
|
|
|
//inset cards
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('accounts', $params)) {
|
|
|
|
foreach ($params['accounts'] as $item) {
|
2024-04-20 11:03:47 +03:30
|
|
|
$card = $entityManager->getRepository(PersonCard::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'person' => $person,
|
|
|
|
'bank' => $item['bank']
|
2024-04-20 11:03:47 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$card)
|
|
|
|
$card = new PersonCard();
|
|
|
|
|
2024-04-20 11:03:47 +03:30
|
|
|
$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([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'person' => $person,
|
2024-04-20 11:03:47 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($accounts as $item) {
|
2024-04-20 11:03:47 +03:30
|
|
|
$deleted = true;
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['accounts'] as $param) {
|
|
|
|
if ($item->getBank() == $param['bank']) {
|
2024-04-20 11:03:47 +03:30
|
|
|
$deleted = false;
|
|
|
|
}
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($deleted) {
|
2024-04-20 11:03:47 +03:30
|
|
|
$entityManager->remove($item);
|
|
|
|
}
|
|
|
|
}
|
2023-09-21 23:04:08 +03:30
|
|
|
$entityManager->persist($person);
|
2024-04-20 11:03:47 +03:30
|
|
|
|
|
|
|
//insert new types
|
|
|
|
$types = $entityManager->getRepository(PersonType::class)->findAll();
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['types'] as $item) {
|
|
|
|
if ($item['checked'] == true)
|
2024-04-20 11:03:47 +03:30
|
|
|
$person->addType($entityManager->getRepository(PersonType::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'code' => $item['code']
|
2024-04-20 11:03:47 +03:30
|
|
|
]));
|
2024-04-27 23:45:38 +03:30
|
|
|
elseif ($item['checked'] == false) {
|
2024-04-20 11:03:47 +03:30
|
|
|
$person->removeType($entityManager->getRepository(PersonType::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'code' => $item['code']
|
2024-04-20 11:03:47 +03:30
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
2023-09-21 23:04:08 +03:30
|
|
|
$entityManager->flush();
|
2024-06-21 22:20:12 +03:30
|
|
|
$log->insert('اشخاص', 'شخص با نام مستعار ' . $params['nikename'] . ' افزوده/ویرایش شد.', $this->getUser(), $acc['bid']);
|
2024-11-03 14:40:50 +03:30
|
|
|
return $this->json([
|
|
|
|
'Success' => true,
|
|
|
|
'result' => 1,
|
|
|
|
]);
|
2023-09-21 23:04:08 +03:30
|
|
|
}
|
|
|
|
|
2024-04-27 23:45:38 +03:30
|
|
|
#[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 = [
|
2024-11-03 14:40:50 +03:30
|
|
|
'id' => $person->getId(),
|
2024-04-27 23:45:38 +03:30
|
|
|
'nikename' => $person->getNikename(),
|
2024-11-03 14:40:50 +03:30
|
|
|
'code' => $person->getCode(),
|
2024-04-27 23:45:38 +03:30
|
|
|
'mobile' => $person->getMobile()
|
|
|
|
];
|
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-11-11 19:11:27 +03:30
|
|
|
'person' => $person,
|
2024-04-27 23:45:38 +03:30
|
|
|
]);
|
|
|
|
$bs = 0;
|
|
|
|
$bd = 0;
|
|
|
|
foreach ($rows as $row) {
|
2024-11-11 19:11:27 +03:30
|
|
|
//check for that calulate is in match money type
|
|
|
|
if ($row->getDoc()->getMoney() == $acc['money']) {
|
|
|
|
$bs += $row->getBs();
|
|
|
|
$bd += $row->getBd();
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
}
|
|
|
|
$temp['bs'] = $bs;
|
|
|
|
$temp['bd'] = $bd;
|
|
|
|
$temp['balance'] = $bs - $bd;
|
|
|
|
$response[] = $temp;
|
|
|
|
}
|
|
|
|
return $this->json($response);
|
|
|
|
}
|
|
|
|
|
2024-04-22 18:55:12 +03:30
|
|
|
#[Route('/api/person/list/limit', name: 'app_persons_list_limit')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_list_limit(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2024-04-22 18:55:12 +03:30
|
|
|
{
|
2024-06-21 22:20:12 +03:30
|
|
|
$acc = $access->hasRole('person');
|
|
|
|
if (!$acc)
|
2024-04-22 18:55:12 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('speedAccess', $params)) {
|
2024-04-22 18:55:12 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid'],
|
2024-04-27 23:45:38 +03:30
|
|
|
'speedAccess' => true
|
2024-04-22 18:55:12 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2024-04-22 18:55:12 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid']
|
2024-04-22 18:55:12 +03:30
|
|
|
]);
|
|
|
|
}
|
|
|
|
$response = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($persons as $key => $person) {
|
|
|
|
$temp = [
|
2024-11-03 14:40:50 +03:30
|
|
|
'id' => $person->getId(),
|
2024-04-27 23:45:38 +03:30
|
|
|
'nikename' => $person->getNikename(),
|
2024-11-03 14:40:50 +03:30
|
|
|
'code' => $person->getCode(),
|
2024-04-27 23:45:38 +03:30
|
|
|
'mobile' => $person->getMobile()
|
2024-04-22 18:55:12 +03:30
|
|
|
];
|
2024-04-27 23:45:38 +03:30
|
|
|
$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;
|
2024-04-22 18:55:12 +03:30
|
|
|
}
|
|
|
|
return $this->json($response);
|
|
|
|
}
|
|
|
|
|
2023-09-21 23:04:08 +03:30
|
|
|
#[Route('/api/person/list', name: 'app_persons_list')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): Response
|
2023-09-21 23:04:08 +03:30
|
|
|
{
|
2024-06-21 22:20:12 +03:30
|
|
|
$acc = $access->hasRole('person');
|
2024-11-03 14:40:50 +03:30
|
|
|
if (!$acc)
|
2023-09-21 23:04:08 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
2023-11-28 10:49:29 +03:30
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('speedAccess', $params)) {
|
2023-11-28 10:49:29 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid'],
|
2024-04-27 23:45:38 +03:30
|
|
|
'speedAccess' => true
|
2023-11-28 10:49:29 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2023-11-28 10:49:29 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid']
|
2023-11-28 10:49:29 +03:30
|
|
|
]);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
$response = Explore::ExplorePersons($persons, $entityManager->getRepository(PersonType::class)->findAll());
|
|
|
|
foreach ($persons as $key => $person) {
|
2023-11-07 16:46:26 +03:30
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'person' => $person
|
2023-11-07 16:46:26 +03:30
|
|
|
]);
|
|
|
|
$bs = 0;
|
|
|
|
$bd = 0;
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($rows as $row) {
|
2023-11-07 16:46:26 +03:30
|
|
|
$bs += $row->getBs();
|
|
|
|
$bd += $row->getBd();
|
|
|
|
}
|
|
|
|
$response[$key]['bs'] = $bs;
|
|
|
|
$response[$key]['bd'] = $bd;
|
|
|
|
$response[$key]['balance'] = $bs - $bd;
|
|
|
|
}
|
2024-04-22 18:55:12 +03:30
|
|
|
return new Response(json_encode($response));
|
2023-09-21 23:04:08 +03:30
|
|
|
}
|
|
|
|
|
2024-04-16 10:29:17 +03:30
|
|
|
#[Route('/api/person/list/debtors/{amount}', name: 'app_persons_list_debtors')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_list_debtors(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2024-04-16 10:29:17 +03:30
|
|
|
{
|
2024-06-21 22:20:12 +03:30
|
|
|
$acc = $access->hasRole('person');
|
|
|
|
if (!$acc)
|
2024-04-16 10:29:17 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('speedAccess', $params)) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid'],
|
2024-04-27 23:45:38 +03:30
|
|
|
'speedAccess' => true
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2024-04-16 10:29:17 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid']
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-04-27 23:45:38 +03:30
|
|
|
$response = $provider->ArrayEntity2Array($persons, 0);
|
|
|
|
foreach ($persons as $key => $person) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'person' => $person
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
|
|
|
$bs = 0;
|
|
|
|
$bd = 0;
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($rows as $row) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$bs += $row->getBs();
|
|
|
|
$bd += $row->getBd();
|
|
|
|
}
|
|
|
|
$response[$key]['bs'] = $bs;
|
|
|
|
$response[$key]['bd'] = $bd;
|
|
|
|
$response[$key]['balance'] = $bs - $bd;
|
|
|
|
}
|
|
|
|
$result = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($response as $key => $person) {
|
|
|
|
if ($person['bd'] - $person['bs'] > $amount) {
|
|
|
|
array_push($result, $person);
|
|
|
|
}
|
2024-04-16 10:29:17 +03:30
|
|
|
}
|
|
|
|
return $this->json($result);
|
|
|
|
}
|
|
|
|
#[Route('/api/person/list/debtors/print/{amount}', name: 'app_persons_debtors_list_print')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_debtors_list_print(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2024-04-16 10:29:17 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2024-04-16 10:29:17 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid']
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
$response = $provider->ArrayEntity2Array($persons, 0);
|
|
|
|
foreach ($persons as $key => $person) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'person' => $person
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
|
|
|
$bs = 0;
|
|
|
|
$bd = 0;
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($rows as $row) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$bs += $row->getBs();
|
|
|
|
$bd += $row->getBd();
|
|
|
|
}
|
|
|
|
$response[$key]['bs'] = $bs;
|
|
|
|
$response[$key]['bd'] = $bd;
|
|
|
|
$response[$key]['balance'] = $bs - $bd;
|
|
|
|
}
|
|
|
|
$result = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($response as $key => $person) {
|
|
|
|
if ($person['bd'] - $person['bs'] > $amount) {
|
|
|
|
array_push($result, $person);
|
|
|
|
}
|
2024-04-16 10:29:17 +03:30
|
|
|
}
|
|
|
|
$pid = $provider->createPrint(
|
|
|
|
$acc['bid'],
|
|
|
|
$this->getUser(),
|
2024-04-27 23:45:38 +03:30
|
|
|
$this->renderView('pdf/personsDebtors.html.twig', [
|
|
|
|
'page_title' => 'فهرست بدهکاران',
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'persons' => $result
|
|
|
|
])
|
|
|
|
);
|
|
|
|
return $this->json(['id' => $pid]);
|
2024-04-16 10:29:17 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/api/person/list/depositors/{amount}', name: 'app_persons_list_depoistors')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_list_depoistors(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2024-04-16 10:29:17 +03:30
|
|
|
{
|
2024-06-21 22:20:12 +03:30
|
|
|
$acc = $access->hasRole('person');
|
|
|
|
if (!$acc)
|
2024-04-16 10:29:17 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists('speedAccess', $params)) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid'],
|
2024-04-27 23:45:38 +03:30
|
|
|
'speedAccess' => true
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2024-04-16 10:29:17 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid']
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-04-27 23:45:38 +03:30
|
|
|
$response = $provider->ArrayEntity2Array($persons, 0);
|
|
|
|
foreach ($persons as $key => $person) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'person' => $person
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
|
|
|
$bs = 0;
|
|
|
|
$bd = 0;
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($rows as $row) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$bs += $row->getBs();
|
|
|
|
$bd += $row->getBd();
|
|
|
|
}
|
|
|
|
$response[$key]['bs'] = $bs;
|
|
|
|
$response[$key]['bd'] = $bd;
|
|
|
|
$response[$key]['balance'] = $bs - $bd;
|
|
|
|
}
|
|
|
|
$result = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($response as $key => $person) {
|
|
|
|
if ($person['bs'] - $person['bd'] > $amount) {
|
|
|
|
array_push($result, $person);
|
|
|
|
}
|
2024-04-16 10:29:17 +03:30
|
|
|
}
|
|
|
|
return $this->json($result);
|
|
|
|
}
|
|
|
|
|
2024-11-03 14:40:50 +03:30
|
|
|
#[Route('/api/person/list/salesmen', name: 'app_persons_list_salesmen')]
|
|
|
|
public function app_persons_list_salesmen(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): Response
|
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
|
|
|
if (!$acc)
|
|
|
|
throw $this->createAccessDeniedException();
|
2024-11-11 19:11:27 +03:30
|
|
|
|
2024-11-03 14:40:50 +03:30
|
|
|
$personType = $entityManager->getRepository(PersonType::class)->findOneBy([
|
|
|
|
'code' => 'salesman',
|
|
|
|
]);
|
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
]);
|
|
|
|
$res = [];
|
|
|
|
foreach ($persons as $key => $person) {
|
2024-11-11 19:11:27 +03:30
|
|
|
foreach ($person->getType() as $type) {
|
|
|
|
if ($type->getCode() == $personType->getCode()) {
|
2024-11-03 14:40:50 +03:30
|
|
|
$res[] = $person;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$response = Explore::ExplorePersons($res, $entityManager->getRepository(PersonType::class)->findAll());
|
|
|
|
foreach ($res as $key => $person) {
|
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
|
|
|
'person' => $person
|
|
|
|
]);
|
|
|
|
$bs = 0;
|
|
|
|
$bd = 0;
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
$bs += $row->getBs();
|
|
|
|
$bd += $row->getBd();
|
|
|
|
}
|
|
|
|
$response[$key]['bs'] = $bs;
|
|
|
|
$response[$key]['bd'] = $bd;
|
|
|
|
$response[$key]['balance'] = $bs - $bd;
|
|
|
|
}
|
|
|
|
return new Response(json_encode([
|
|
|
|
'Success' => true,
|
|
|
|
'result' => $response
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
2024-04-16 10:29:17 +03:30
|
|
|
#[Route('/api/person/list/depositors/print/{amount}', name: 'app_persons_depositors_list_print')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_depositors_list_print(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2024-04-16 10:29:17 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2024-04-16 10:29:17 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-06-21 22:20:12 +03:30
|
|
|
'bid' => $acc['bid']
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
$response = $provider->ArrayEntity2Array($persons, 0);
|
|
|
|
foreach ($persons as $key => $person) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'person' => $person
|
2024-04-16 10:29:17 +03:30
|
|
|
]);
|
|
|
|
$bs = 0;
|
|
|
|
$bd = 0;
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($rows as $row) {
|
2024-04-16 10:29:17 +03:30
|
|
|
$bs += $row->getBs();
|
|
|
|
$bd += $row->getBd();
|
|
|
|
}
|
|
|
|
$response[$key]['bs'] = $bs;
|
|
|
|
$response[$key]['bd'] = $bd;
|
|
|
|
$response[$key]['balance'] = $bs - $bd;
|
|
|
|
}
|
|
|
|
$result = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($response as $key => $person) {
|
|
|
|
if ($person['bs'] - $person['bd'] > $amount) {
|
|
|
|
array_push($result, $person);
|
|
|
|
}
|
2024-04-16 10:29:17 +03:30
|
|
|
}
|
|
|
|
$pid = $provider->createPrint(
|
|
|
|
$acc['bid'],
|
|
|
|
$this->getUser(),
|
2024-04-27 23:45:38 +03:30
|
|
|
$this->renderView('pdf/personsDepositors.html.twig', [
|
|
|
|
'page_title' => 'فهرست بستانکاران',
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'persons' => $result
|
|
|
|
])
|
|
|
|
);
|
|
|
|
return $this->json(['id' => $pid]);
|
2024-04-16 10:29:17 +03:30
|
|
|
}
|
|
|
|
|
2023-09-21 23:04:08 +03:30
|
|
|
#[Route('/api/person/list/print', name: 'app_persons_list_print')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2023-09-21 23:04:08 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-09-21 23:04:08 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
2023-09-30 21:01:00 +03:30
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('items', $params)) {
|
2023-09-30 21:01:00 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid']
|
2023-09-30 21:01:00 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2023-09-30 21:01:00 +03:30
|
|
|
$persons = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['items'] as $param) {
|
2023-09-30 21:01:00 +03:30
|
|
|
$prs = $entityManager->getRepository(Person::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'id' => $param['id'],
|
|
|
|
'bid' => $acc['bid']
|
2023-09-30 21:01:00 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($prs)
|
2023-09-30 21:01:00 +03:30
|
|
|
$persons[] = $prs;
|
|
|
|
}
|
|
|
|
}
|
2023-09-21 23:04:08 +03:30
|
|
|
$pid = $provider->createPrint(
|
|
|
|
$acc['bid'],
|
|
|
|
$this->getUser(),
|
2024-04-27 23:45:38 +03:30
|
|
|
$this->renderView('pdf/persons.html.twig', [
|
|
|
|
'page_title' => 'فهرست اشخاص',
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'persons' => $persons
|
|
|
|
])
|
|
|
|
);
|
|
|
|
return $this->json(['id' => $pid]);
|
2023-09-21 23:04:08 +03:30
|
|
|
}
|
2023-09-30 21:01:00 +03:30
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2023-09-30 21:01:00 +03:30
|
|
|
#[Route('/api/person/list/excel', name: 'app_persons_list_excel')]
|
2024-11-03 14:40:50 +03:30
|
|
|
public function app_persons_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse|JsonResponse|StreamedResponse
|
2023-09-30 21:01:00 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-09-30 21:01:00 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('items', $params)) {
|
2023-09-30 21:01:00 +03:30
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid']
|
2023-09-30 21:01:00 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2023-09-30 21:01:00 +03:30
|
|
|
$persons = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['items'] as $param) {
|
2023-09-30 21:01:00 +03:30
|
|
|
$prs = $entityManager->getRepository(Person::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'id' => $param['id'],
|
|
|
|
'bid' => $acc['bid']
|
2023-09-30 21:01:00 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($prs)
|
2023-09-30 21:01:00 +03:30
|
|
|
$persons[] = $prs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new BinaryFileResponse($provider->createExcell($persons));
|
|
|
|
}
|
2023-10-02 17:43:51 +03:30
|
|
|
|
2024-02-13 12:09:20 +03:30
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
#[Route('/api/person/card/list/excel', name: 'app_persons_card_list_excel')]
|
2024-11-03 14:40:50 +03:30
|
|
|
public function app_persons_card_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse|JsonResponse|StreamedResponse
|
2024-02-13 12:09:20 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2024-02-13 12:09:20 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('code', $params))
|
2024-02-13 12:09:20 +03:30
|
|
|
throw $this->createNotFoundException();
|
2024-04-27 23:45:38 +03:30
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy(['bid' => $acc['bid'], 'code' => $params['code']]);
|
|
|
|
if (!$person)
|
2024-02-13 12:09:20 +03:30
|
|
|
throw $this->createNotFoundException();
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('items', $params)) {
|
2024-02-13 12:09:20 +03:30
|
|
|
$transactions = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
2025-02-09 01:45:04 +03:30
|
|
|
'person' => $person,
|
|
|
|
'year' => $acc['year'],
|
|
|
|
'money' => $acc['money'],
|
2024-02-13 12:09:20 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2024-02-13 12:09:20 +03:30
|
|
|
$transactions = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['items'] as $param) {
|
2024-02-13 12:09:20 +03:30
|
|
|
$prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'id' => $param['id'],
|
|
|
|
'bid' => $acc['bid'],
|
2025-02-09 01:45:04 +03:30
|
|
|
'person' => $person,
|
|
|
|
'year' => $acc['year'],
|
|
|
|
'money' => $acc['money'],
|
2024-02-13 12:09:20 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($prs) {
|
2024-02-13 12:09:20 +03:30
|
|
|
$transactions[] = $prs;
|
2024-04-27 23:45:38 +03:30
|
|
|
}
|
2024-02-13 12:09:20 +03:30
|
|
|
}
|
|
|
|
}
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
$activeWorksheet = $spreadsheet->getActiveSheet();
|
2024-11-03 14:40:50 +03:30
|
|
|
$arrayEntity = [
|
|
|
|
[
|
|
|
|
'شماره تراکنش',
|
|
|
|
'تاریخ',
|
|
|
|
'توضیحات',
|
|
|
|
'تفضیل',
|
|
|
|
'بستانکار',
|
|
|
|
'بدهکار',
|
|
|
|
'سال مالی',
|
|
|
|
]
|
|
|
|
];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($transactions as $transaction) {
|
|
|
|
$arrayEntity[] = [
|
2024-02-13 12:09:20 +03:30
|
|
|
$transaction->getId(),
|
|
|
|
$transaction->getDoc()->getDate(),
|
|
|
|
$transaction->getDes(),
|
|
|
|
$transaction->getRef()->getName(),
|
|
|
|
$transaction->getBs(),
|
|
|
|
$transaction->getBd(),
|
|
|
|
$transaction->getYear()->getlabel()
|
|
|
|
];
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
$activeWorksheet->fromArray($arrayEntity, null, 'A1');
|
2024-02-13 12:09:20 +03:30
|
|
|
$activeWorksheet->setRightToLeft(true);
|
|
|
|
$writer = new Xlsx($spreadsheet);
|
2024-04-27 23:45:38 +03:30
|
|
|
$filePath = __DIR__ . '/../../var/' . $this->RandomString(12) . '.xlsx';
|
|
|
|
$writer->save($filePath);
|
2024-02-13 12:09:20 +03:30
|
|
|
return new BinaryFileResponse($filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/api/person/card/list/print', name: 'app_persons_card_list_print')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_card_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2024-02-13 12:09:20 +03:30
|
|
|
{
|
2024-07-18 12:15:09 +03:30
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2024-02-13 12:09:20 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('code', $params))
|
2024-02-13 12:09:20 +03:30
|
|
|
throw $this->createNotFoundException();
|
2024-04-27 23:45:38 +03:30
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy(['bid' => $acc['bid'], 'code' => $params['code']]);
|
|
|
|
if (!$person)
|
2024-02-13 12:09:20 +03:30
|
|
|
throw $this->createNotFoundException();
|
|
|
|
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('items', $params)) {
|
2024-02-13 12:09:20 +03:30
|
|
|
$transactions = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
2025-02-09 01:45:04 +03:30
|
|
|
'person' => $person,
|
|
|
|
'year' => $acc['year'],
|
|
|
|
'money' => $acc['money'],
|
2024-02-13 12:09:20 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2024-02-13 12:09:20 +03:30
|
|
|
$transactions = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['items'] as $param) {
|
2024-02-13 12:09:20 +03:30
|
|
|
$prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'id' => $param['id'],
|
|
|
|
'bid' => $acc['bid'],
|
2025-02-09 01:45:04 +03:30
|
|
|
'person' => $person,
|
|
|
|
'year' => $acc['year'],
|
|
|
|
'money' => $acc['money'],
|
2024-02-13 12:09:20 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($prs) {
|
2024-02-13 12:09:20 +03:30
|
|
|
$transactions[] = $prs;
|
2024-04-27 23:45:38 +03:30
|
|
|
}
|
2024-02-13 12:09:20 +03:30
|
|
|
}
|
|
|
|
}
|
|
|
|
$pid = $provider->createPrint(
|
|
|
|
$acc['bid'],
|
|
|
|
$this->getUser(),
|
2024-04-27 23:45:38 +03:30
|
|
|
$this->renderView('pdf/person_card.html.twig', [
|
2024-11-03 14:40:50 +03:30
|
|
|
'page_title' => 'کارت حساب' . ' ' . $person->getNikename(),
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
2024-07-14 22:45:22 +03:30
|
|
|
'items' => $transactions,
|
|
|
|
'person' => $person
|
2024-04-27 23:45:38 +03:30
|
|
|
])
|
|
|
|
);
|
|
|
|
return $this->json(['id' => $pid]);
|
2024-02-13 12:09:20 +03:30
|
|
|
}
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
#[Route('/api/person/receive/list/print', name: 'app_persons_receive_list_print')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_receive_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2023-10-02 17:43:51 +03:30
|
|
|
{
|
2024-07-18 12:15:09 +03:30
|
|
|
$acc = $access->hasRole('getpay');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-10-02 17:43:51 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('items', $params)) {
|
2023-10-02 17:43:51 +03:30
|
|
|
$items = $entityManager->getRepository(HesabdariDoc::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_receive',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2025-02-09 01:45:04 +03:30
|
|
|
'money' => $acc['money'],
|
2023-10-02 17:43:51 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2023-10-02 17:43:51 +03:30
|
|
|
$items = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['items'] as $param) {
|
2023-10-02 17:43:51 +03:30
|
|
|
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'id' => $param['id'],
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_receive',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2023-10-02 17:43:51 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($prs)
|
2023-10-02 17:43:51 +03:30
|
|
|
$items[] = $prs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pid = $provider->createPrint(
|
|
|
|
$acc['bid'],
|
|
|
|
$this->getUser(),
|
2024-04-27 23:45:38 +03:30
|
|
|
$this->renderView('pdf/persons_receive.html.twig', [
|
|
|
|
'page_title' => 'لیست دریافتها',
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'items' => $items
|
|
|
|
])
|
|
|
|
);
|
|
|
|
return $this->json(['id' => $pid]);
|
2023-10-02 17:43:51 +03:30
|
|
|
}
|
|
|
|
|
2024-06-04 14:23:07 +03:30
|
|
|
#[Route('/api/person/receive/list/search', name: 'app_persons_receive_list_search')]
|
|
|
|
public function app_persons_receive_list_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
|
|
|
{
|
2024-07-18 12:15:09 +03:30
|
|
|
$acc = $access->hasRole('getpay');
|
2024-06-04 14:23:07 +03:30
|
|
|
if (!$acc)
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = $entityManager->getRepository(HesabdariDoc::class)->findBy(
|
|
|
|
[
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_receive',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2024-06-04 14:23:07 +03:30
|
|
|
],
|
|
|
|
['id' => 'DESC']
|
|
|
|
);
|
|
|
|
$res = [];
|
2024-11-03 14:40:50 +03:30
|
|
|
foreach ($items as $item) {
|
2024-06-04 14:23:07 +03:30
|
|
|
$temp = [
|
2024-11-03 14:40:50 +03:30
|
|
|
'id' => $item->getId(),
|
|
|
|
'date' => $item->getDate(),
|
|
|
|
'code' => $item->getCode(),
|
|
|
|
'des' => $item->getDes(),
|
|
|
|
'amount' => $item->getAmount()
|
2024-06-04 14:23:07 +03:30
|
|
|
];
|
|
|
|
$persons = [];
|
2024-11-03 14:40:50 +03:30
|
|
|
foreach ($item->getHesabdariRows() as $row) {
|
|
|
|
if ($row->getPerson()) {
|
2024-06-04 14:23:07 +03:30
|
|
|
$persons[] = Explore::ExplorePerson($row->getPerson());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$temp['persons'] = $persons;
|
|
|
|
$res[] = $temp;
|
|
|
|
}
|
2024-11-03 14:40:50 +03:30
|
|
|
|
2024-06-04 14:23:07 +03:30
|
|
|
return $this->json($res);
|
|
|
|
}
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
#[Route('/api/person/receive/list/excel', name: 'app_persons_receive_list_excel')]
|
2024-11-03 14:40:50 +03:30
|
|
|
public function app_persons_receive_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse|JsonResponse|StreamedResponse
|
2023-10-02 17:43:51 +03:30
|
|
|
{
|
2024-07-18 12:15:09 +03:30
|
|
|
$acc = $access->hasRole('getpay');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-10-02 17:43:51 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('items', $params)) {
|
2023-10-02 17:43:51 +03:30
|
|
|
$items = $entityManager->getRepository(HesabdariDoc::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_receive',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2023-10-02 17:43:51 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2023-10-02 17:43:51 +03:30
|
|
|
$items = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['items'] as $param) {
|
2023-10-02 17:43:51 +03:30
|
|
|
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'id' => $param['id'],
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_receive',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2023-10-02 17:43:51 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($prs)
|
2023-10-02 17:43:51 +03:30
|
|
|
$items[] = $prs;
|
|
|
|
}
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
return new BinaryFileResponse($provider->createExcell($items, ['type', 'dateSubmit']));
|
2023-10-02 17:43:51 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/api/person/send/list/print', name: 'app_persons_send_list_print')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_send_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
2023-10-02 17:43:51 +03:30
|
|
|
{
|
2024-07-18 12:15:09 +03:30
|
|
|
$acc = $access->hasRole('getpay');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-10-02 17:43:51 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('items', $params)) {
|
2023-10-02 17:43:51 +03:30
|
|
|
$items = $entityManager->getRepository(HesabdariDoc::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_send',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2023-10-02 17:43:51 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2023-10-02 17:43:51 +03:30
|
|
|
$items = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['items'] as $param) {
|
2023-10-02 17:43:51 +03:30
|
|
|
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'id' => $param['id'],
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_send',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2023-10-02 17:43:51 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($prs)
|
2023-10-02 17:43:51 +03:30
|
|
|
$items[] = $prs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pid = $provider->createPrint(
|
|
|
|
$acc['bid'],
|
|
|
|
$this->getUser(),
|
2024-04-27 23:45:38 +03:30
|
|
|
$this->renderView('pdf/persons_receive.html.twig', [
|
|
|
|
'page_title' => 'لیست پرداختها',
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'items' => $items
|
|
|
|
])
|
|
|
|
);
|
|
|
|
return $this->json(['id' => $pid]);
|
2023-10-02 17:43:51 +03:30
|
|
|
}
|
|
|
|
|
2024-06-04 14:23:07 +03:30
|
|
|
#[Route('/api/person/send/list/search', name: 'app_persons_send_list_search')]
|
|
|
|
public function app_persons_send_list_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
|
|
|
{
|
2024-07-18 12:15:09 +03:30
|
|
|
$acc = $access->hasRole('getpay');
|
2024-06-04 14:23:07 +03:30
|
|
|
if (!$acc)
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = $entityManager->getRepository(HesabdariDoc::class)->findBy(
|
|
|
|
[
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_send',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2024-06-04 14:23:07 +03:30
|
|
|
],
|
|
|
|
['id' => 'DESC']
|
|
|
|
);
|
|
|
|
$res = [];
|
2024-11-03 14:40:50 +03:30
|
|
|
foreach ($items as $item) {
|
2024-06-04 14:23:07 +03:30
|
|
|
$temp = [
|
2024-11-03 14:40:50 +03:30
|
|
|
'id' => $item->getId(),
|
|
|
|
'date' => $item->getDate(),
|
|
|
|
'code' => $item->getCode(),
|
|
|
|
'des' => $item->getDes(),
|
|
|
|
'amount' => $item->getAmount()
|
2024-06-04 14:23:07 +03:30
|
|
|
];
|
|
|
|
$persons = [];
|
2024-11-03 14:40:50 +03:30
|
|
|
foreach ($item->getHesabdariRows() as $row) {
|
|
|
|
if ($row->getPerson()) {
|
2024-06-04 14:23:07 +03:30
|
|
|
$persons[] = Explore::ExplorePerson($row->getPerson());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$temp['persons'] = $persons;
|
|
|
|
$res[] = $temp;
|
|
|
|
}
|
2024-11-03 14:40:50 +03:30
|
|
|
|
2024-06-04 14:23:07 +03:30
|
|
|
return $this->json($res);
|
|
|
|
}
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
#[Route('/api/person/send/list/excel', name: 'app_persons_send_list_excel')]
|
2024-11-03 14:40:50 +03:30
|
|
|
public function app_persons_send_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse|JsonResponse|StreamedResponse
|
2023-10-02 17:43:51 +03:30
|
|
|
{
|
2024-07-18 12:15:09 +03:30
|
|
|
$acc = $access->hasRole('getpay');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-10-02 17:43:51 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$params = [];
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!array_key_exists('items', $params)) {
|
2023-10-02 17:43:51 +03:30
|
|
|
$items = $entityManager->getRepository(HesabdariDoc::class)->findBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_send',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2023-10-02 17:43:51 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
} else {
|
2023-10-02 17:43:51 +03:30
|
|
|
$items = [];
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($params['items'] as $param) {
|
2023-10-02 17:43:51 +03:30
|
|
|
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'id' => $param['id'],
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
'type' => 'person_send',
|
2024-11-07 15:28:20 +03:30
|
|
|
'year' => $acc['year'],
|
2024-11-11 19:11:27 +03:30
|
|
|
'money' => $acc['money']
|
2023-10-02 17:43:51 +03:30
|
|
|
]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if ($prs)
|
2023-10-02 17:43:51 +03:30
|
|
|
$items[] = $prs;
|
|
|
|
}
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
return new BinaryFileResponse($provider->createExcell($items, ['type', 'dateSubmit']));
|
2023-10-02 17:43:51 +03:30
|
|
|
}
|
|
|
|
|
2023-12-31 01:42:57 +03:30
|
|
|
#[Route('/api/person/import/excel', name: 'app_persons_import_excel')]
|
2024-04-27 23:45:38 +03:30
|
|
|
public function app_persons_import_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
|
2023-12-31 01:42:57 +03:30
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$acc)
|
2023-12-31 01:42:57 +03:30
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
$file = $request->files->get('file');
|
|
|
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
|
|
|
$reader->setReadDataOnly(true);
|
|
|
|
$spreadsheet = $reader->load($file);
|
|
|
|
$sheet = $spreadsheet->getSheet($spreadsheet->getFirstSheetIndex());
|
|
|
|
$data = $sheet->toArray();
|
|
|
|
unset($data[0]);
|
2024-04-27 23:45:38 +03:30
|
|
|
foreach ($data as $item) {
|
2023-12-31 01:42:57 +03:30
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
2024-04-27 23:45:38 +03:30
|
|
|
'nikename' => $item[0],
|
|
|
|
'bid' => $acc['bid']
|
2023-12-31 01:42:57 +03:30
|
|
|
]);
|
|
|
|
//check exist before
|
2024-04-27 23:45:38 +03:30
|
|
|
if (!$person) {
|
2023-12-31 23:56:35 +03:30
|
|
|
$person = new Person();
|
2024-06-21 22:20:12 +03:30
|
|
|
$person->setCode($provider->getAccountingCode($acc['bid'], 'person'));
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setNikename($item[0]);
|
|
|
|
$person->setBid($acc['bid']);
|
2024-04-27 23:45:38 +03:30
|
|
|
|
|
|
|
if (array_key_exists(1, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setName($item[1]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(4, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setBirthday($item[4]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(10, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setTel($item[10]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(2, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setSpeedAccess($item[2]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(18, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setAddress($item[18]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(5, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setDes($item[5]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(9, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setMobile($item[9]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(11, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setFax($item[11]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(13, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setWebsite($item[13]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(12, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setEmail($item[12]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(17, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setPostalcode($item[17]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(16, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setShahr($item[16]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(15, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setOstan($item[15]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(14, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setKeshvar($item[14]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(7, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setSabt($item[7]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(8, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setCodeeghtesadi($item[8]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(6, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setShenasemeli($item[6]);
|
2024-04-27 23:45:38 +03:30
|
|
|
if (array_key_exists(3, $item))
|
2023-12-31 01:42:57 +03:30
|
|
|
$person->setCompany($item[3]);
|
|
|
|
$entityManager->persist($person);
|
|
|
|
}
|
2024-04-27 23:45:38 +03:30
|
|
|
$entityManager->flush();
|
2023-12-31 01:42:57 +03:30
|
|
|
}
|
2024-06-21 22:20:12 +03:30
|
|
|
$log->insert('اشخاص', 'تعداد ' . count($data) . ' شخص به صورت گروهی وارد شد.', $this->getUser(), $acc['bid']);
|
2023-12-31 01:42:57 +03:30
|
|
|
return $this->json(['result' => 1]);
|
|
|
|
}
|
2024-06-13 15:01:57 +03:30
|
|
|
|
|
|
|
#[Route('/api/person/delete/{code}', name: 'app_person_delete')]
|
|
|
|
public function app_person_delete(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
|
|
|
|
{
|
|
|
|
$acc = $access->hasRole('person');
|
|
|
|
if (!$acc)
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy(['bid' => $acc['bid'], 'code' => $code]);
|
|
|
|
if (!$person)
|
|
|
|
throw $this->createNotFoundException();
|
|
|
|
//check accounting docs
|
|
|
|
$docs = $entityManager->getRepository(HesabdariRow::class)->findby(['bid' => $acc['bid'], 'person' => $person]);
|
|
|
|
if (count($docs) > 0)
|
|
|
|
return $this->json(['result' => 2]);
|
|
|
|
//check for storeroom docs
|
|
|
|
$storeDocs = $entityManager->getRepository(StoreroomTicket::class)->findby(['bid' => $acc['bid'], 'Person' => $person]);
|
|
|
|
if (count($storeDocs) > 0)
|
|
|
|
return $this->json(['result' => 2]);
|
|
|
|
//check in repservice
|
|
|
|
|
|
|
|
$comName = $person->getName();
|
|
|
|
try {
|
|
|
|
$entityManager->remove($person);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return $this->json(['result' => 2]);
|
|
|
|
}
|
2024-06-13 15:08:39 +03:30
|
|
|
$log->insert('اشخاص', ' شخص با نام ' . $comName . ' حذف شد. ', $this->getUser(), $acc['bid']->getId());
|
2024-06-13 15:01:57 +03:30
|
|
|
return $this->json(['result' => 1]);
|
|
|
|
}
|
2025-02-13 14:30:45 +03:30
|
|
|
|
|
|
|
#[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));
|
|
|
|
}
|
2023-09-21 23:04:08 +03:30
|
|
|
}
|