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;
|
2025-03-15 23:53:06 +03:30
|
|
|
|
use App\Service\Jdate;
|
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([
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
2023-11-07 16:46:26 +03:30
|
|
|
|
]);
|
|
|
|
|
$bs = 0;
|
|
|
|
|
$bd = 0;
|
2024-04-27 23:45:38 +03:30
|
|
|
|
foreach ($rows as $row) {
|
2025-04-12 18:50:34 +03:30
|
|
|
|
try {
|
|
|
|
|
$doc = $row->getDoc();
|
|
|
|
|
if ($doc && $doc->getMoney() && $doc->getYear() &&
|
|
|
|
|
$doc->getMoney()->getId() == $acc['money']->getId() &&
|
|
|
|
|
$doc->getYear()->getId() == $acc['year']->getId()) {
|
|
|
|
|
$bs += (float) $row->getBs(); // بستانکار
|
|
|
|
|
$bd += (float) $row->getBd(); // بدهکار
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
// در صورت بروز خطا، این ردیف را نادیده میگیریم و به ردیف بعدی میرویم
|
|
|
|
|
continue;
|
2024-11-11 19:11:27 +03:30
|
|
|
|
}
|
2023-11-07 16:46:26 +03:30
|
|
|
|
}
|
|
|
|
|
$response['bs'] = $bs;
|
|
|
|
|
$response['bd'] = $bd;
|
|
|
|
|
$response['balance'] = $bs - $bd;
|
2025-05-29 20:00:54 +03:30
|
|
|
|
|
2023-11-07 16:46:26 +03:30
|
|
|
|
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();
|
2025-06-01 11:48:12 +03:30
|
|
|
|
$maxAttempts = 10; // حداکثر تعداد تلاش برای تولید کد جدید
|
|
|
|
|
$code = null;
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < $maxAttempts; $i++) {
|
2025-05-13 16:15:44 +03:30
|
|
|
|
$code = $provider->getAccountingCode($acc['bid'], 'person');
|
|
|
|
|
$exist = $entityManager->getRepository(Person::class)->findOneBy([
|
|
|
|
|
'code' => $code
|
|
|
|
|
]);
|
2025-06-01 11:48:12 +03:30
|
|
|
|
if (!$exist) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($code === null) {
|
|
|
|
|
throw new \Exception('نمیتوان کد جدیدی برای شخص تولید کرد');
|
2025-05-13 16:15:44 +03:30
|
|
|
|
}
|
2025-06-01 11:48:12 +03:30
|
|
|
|
|
2025-05-13 16:15:44 +03:30
|
|
|
|
$person->setCode($code);
|
2024-11-03 14:40:50 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} 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();
|
2025-06-01 11:48:12 +03:30
|
|
|
|
$maxAttempts = 10; // حداکثر تعداد تلاش برای تولید کد جدید
|
|
|
|
|
$code = null;
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < $maxAttempts; $i++) {
|
2025-05-13 16:15:44 +03:30
|
|
|
|
$code = $provider->getAccountingCode($acc['bid'], 'person');
|
|
|
|
|
$exist = $entityManager->getRepository(Person::class)->findOneBy([
|
|
|
|
|
'code' => $code
|
|
|
|
|
]);
|
2025-06-01 11:48:12 +03:30
|
|
|
|
if (!$exist) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-05-13 16:15:44 +03:30
|
|
|
|
}
|
2025-06-01 11:48:12 +03:30
|
|
|
|
|
|
|
|
|
if ($code === null) {
|
|
|
|
|
throw new \Exception('نمیتوان کد جدیدی برای شخص تولید کرد');
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-13 16:15:44 +03:30
|
|
|
|
$person->setCode($code);
|
2024-11-03 14:40:50 +03:30
|
|
|
|
}
|
|
|
|
|
|
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'] != '') {
|
2025-02-28 22:01:39 +03:30
|
|
|
|
$prelabel = $entityManager->getRepository(PersonPrelabel::class)->findOneBy(['label' => $params['prelabel']]);
|
2025-02-13 14:30:45 +03:30
|
|
|
|
if ($prelabel) {
|
|
|
|
|
$person->setPrelabel($prelabel);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-04 01:07:39 +03:30
|
|
|
|
elseif ($params['prelabel'] == null) {
|
|
|
|
|
$person->setPrelabel(null);
|
|
|
|
|
}
|
2025-02-13 14:30:45 +03:30
|
|
|
|
}
|
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,
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'bid' => $acc['bid']
|
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([
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
2024-04-27 23:45:38 +03:30
|
|
|
|
]);
|
|
|
|
|
$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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 19:35:39 +03:30
|
|
|
|
#[Route('/api/person/list', name: 'app_persons_list', methods: ['POST'])]
|
|
|
|
|
public function app_persons_list(
|
|
|
|
|
Provider $provider,
|
|
|
|
|
Request $request,
|
|
|
|
|
Access $access,
|
|
|
|
|
Log $log,
|
|
|
|
|
EntityManagerInterface $entityManager
|
|
|
|
|
): JsonResponse {
|
2024-06-21 22:20:12 +03:30
|
|
|
|
$acc = $access->hasRole('person');
|
2025-03-13 19:35:39 +03:30
|
|
|
|
if (!$acc) {
|
2025-05-29 20:00:54 +03:30
|
|
|
|
var_dump($acc);
|
2023-09-21 23:04:08 +03:30
|
|
|
|
throw $this->createAccessDeniedException();
|
2023-11-28 10:49:29 +03:30
|
|
|
|
}
|
2025-03-13 19:35:39 +03:30
|
|
|
|
|
|
|
|
|
$params = json_decode($request->getContent(), true) ?? [];
|
|
|
|
|
$page = $params['page'] ?? 1;
|
|
|
|
|
$itemsPerPage = $params['itemsPerPage'] ?? 10;
|
|
|
|
|
$search = $params['search'] ?? '';
|
|
|
|
|
$types = $params['types'] ?? null;
|
|
|
|
|
$transactionFilters = $params['transactionFilters'] ?? null;
|
|
|
|
|
|
2025-03-19 22:52:33 +03:30
|
|
|
|
// کوئری اصلی برای گرفتن همه اشخاص
|
|
|
|
|
$queryBuilder = $entityManager->getRepository(\App\Entity\Person::class)
|
2025-03-13 19:35:39 +03:30
|
|
|
|
->createQueryBuilder('p')
|
|
|
|
|
->where('p.bid = :bid')
|
|
|
|
|
->setParameter('bid', $acc['bid']);
|
|
|
|
|
|
2025-03-19 22:52:33 +03:30
|
|
|
|
// جستوجو (بهبود دادهشده)
|
|
|
|
|
if (!empty($search) || $search === '0') { // برای اطمینان از کار با "0" یا خالی
|
|
|
|
|
$search = trim($search); // حذف فضای خالی اضافی
|
2025-06-01 11:48:12 +03:30
|
|
|
|
$queryBuilder->andWhere('p.nikename LIKE :search OR p.name LIKE :search OR p.code LIKE :search OR p.mobile LIKE :search')
|
2025-03-19 22:52:33 +03:30
|
|
|
|
->setParameter('search', "%$search%");
|
2023-11-28 10:49:29 +03:30
|
|
|
|
}
|
2025-03-13 19:35:39 +03:30
|
|
|
|
|
|
|
|
|
// فیلتر نوع اشخاص
|
|
|
|
|
if ($types && !empty($types)) {
|
2025-03-19 22:52:33 +03:30
|
|
|
|
$queryBuilder->leftJoin('p.type', 't')
|
|
|
|
|
->andWhere('t.code IN (:types)')
|
2025-03-13 19:35:39 +03:30
|
|
|
|
->setParameter('types', $types);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 22:52:33 +03:30
|
|
|
|
// تعداد کل (قبل از فیلتر تراکنشها)
|
|
|
|
|
$totalItems = (clone $queryBuilder)
|
|
|
|
|
->select('COUNT(p.id)')
|
2025-03-13 19:35:39 +03:30
|
|
|
|
->getQuery()
|
2025-03-19 22:52:33 +03:30
|
|
|
|
->getSingleScalarResult();
|
2025-03-13 19:35:39 +03:30
|
|
|
|
|
2025-03-19 22:52:33 +03:30
|
|
|
|
// گرفتن اشخاص با صفحهبندی
|
2025-03-13 19:35:39 +03:30
|
|
|
|
$persons = $queryBuilder
|
2025-03-19 22:52:33 +03:30
|
|
|
|
->select('p')
|
2025-03-13 19:35:39 +03:30
|
|
|
|
->setFirstResult(($page - 1) * $itemsPerPage)
|
|
|
|
|
->setMaxResults($itemsPerPage)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getResult();
|
|
|
|
|
|
2025-03-19 22:52:33 +03:30
|
|
|
|
// محاسبه تراکنشها و اعمال فیلتر تراکنشها
|
|
|
|
|
$response = [];
|
|
|
|
|
foreach ($persons as $person) {
|
|
|
|
|
$rows = $entityManager->getRepository(\App\Entity\HesabdariRow::class)->findBy([
|
|
|
|
|
'person' => $person,
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'bid' => $acc['bid']
|
2025-03-19 22:52:33 +03:30
|
|
|
|
]);
|
|
|
|
|
$bs = 0; // بستانکار
|
|
|
|
|
$bd = 0; // بدهکار
|
2024-04-27 23:45:38 +03:30
|
|
|
|
foreach ($rows as $row) {
|
2025-04-12 18:50:34 +03:30
|
|
|
|
$doc = $row->getDoc();
|
|
|
|
|
if ($doc && $doc->getMoney() && $doc->getYear() &&
|
|
|
|
|
$doc->getMoney()->getId() == $acc['money']->getId() &&
|
|
|
|
|
$doc->getYear()->getId() == $acc['year']->getId()) {
|
2025-03-19 22:52:33 +03:30
|
|
|
|
$bs += (float) $row->getBs(); // بستانکار
|
|
|
|
|
$bd += (float) $row->getBd(); // بدهکار
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$balance = $bs - $bd; // تراز = بستانکار - بدهکار
|
|
|
|
|
|
|
|
|
|
// اعمال فیلتر transactionFilters
|
|
|
|
|
$include = true;
|
|
|
|
|
if ($transactionFilters && !empty($transactionFilters)) {
|
|
|
|
|
$include = false;
|
|
|
|
|
if (in_array('debtors', $transactionFilters) && $balance < 0) { // بدهکارها (تراز منفی)
|
|
|
|
|
$include = true;
|
|
|
|
|
}
|
|
|
|
|
if (in_array('creditors', $transactionFilters) && $balance > 0) { // بستانکارها (تراز مثبت)
|
|
|
|
|
$include = true;
|
|
|
|
|
}
|
|
|
|
|
if (in_array('zero', $transactionFilters) && $balance == 0) { // تسویهشدهها
|
|
|
|
|
$include = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($include) {
|
2025-04-03 02:42:48 +03:30
|
|
|
|
$result = Explore::ExplorePerson($person, $entityManager->getRepository(PersonType::class)->findAll());
|
|
|
|
|
$result['bs'] = $bs;
|
|
|
|
|
$result['bd'] = $bd;
|
|
|
|
|
$result['balance'] = $balance;
|
|
|
|
|
$response[] = $result;
|
2023-11-07 16:46:26 +03:30
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-13 19:35:39 +03:30
|
|
|
|
|
2025-03-19 22:52:33 +03:30
|
|
|
|
// تعداد آیتمهای فیلترشده
|
|
|
|
|
$filteredTotal = count($response);
|
|
|
|
|
|
|
|
|
|
return new JsonResponse([
|
|
|
|
|
'items' => array_slice($response, 0, $itemsPerPage), // فقط تعداد درخواستی
|
|
|
|
|
'total' => $filteredTotal, // تعداد کل فیلترشده
|
|
|
|
|
'unfilteredTotal' => $totalItems, // تعداد کل بدون فیلتر (اختیاری)
|
2025-03-13 19:35:39 +03:30
|
|
|
|
]);
|
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([
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
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();
|
|
|
|
|
|
2025-06-02 10:41:53 +03:30
|
|
|
|
$data = json_decode($request->getContent(), true);
|
|
|
|
|
$selectedItems = $data['items'] ?? [];
|
|
|
|
|
|
|
|
|
|
// اگر آیتمهای انتخاب شده وجود دارند، فقط آنها را دریافت کن
|
|
|
|
|
if (!empty($selectedItems)) {
|
|
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
|
'code' => $selectedItems
|
|
|
|
|
]);
|
|
|
|
|
} 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
|
|
|
|
]);
|
2025-06-02 10:41:53 +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([
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
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
|
|
|
|
}
|
2025-06-02 10:41:53 +03:30
|
|
|
|
|
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
|
|
|
|
|
])
|
|
|
|
|
);
|
2025-06-02 10:41:53 +03:30
|
|
|
|
|
2024-04-27 23:45:38 +03:30
|
|
|
|
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([
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
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([
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
2024-11-03 14:40:50 +03:30
|
|
|
|
]);
|
|
|
|
|
$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([
|
2025-04-12 18:50:34 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
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)) {
|
2025-02-14 09:10:40 +03:30
|
|
|
|
$transactions = $entityManager->getRepository(HesabdariRow::class)->findByJoinMoney([
|
2024-04-27 23:45:38 +03:30
|
|
|
|
'bid' => $acc['bid'],
|
2025-02-09 01:45:04 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'year' => $acc['year'],
|
2025-02-14 09:10:40 +03:30
|
|
|
|
], $acc['money']);
|
2024-04-27 23:45:38 +03:30
|
|
|
|
} else {
|
2024-02-13 12:09:20 +03:30
|
|
|
|
$transactions = [];
|
2025-06-08 05:12:08 +03:30
|
|
|
|
if (is_array($params['items'])) {
|
|
|
|
|
foreach ($params['items'] as $param) {
|
|
|
|
|
$id = is_array($param) ? ($param['id'] ?? null) : $param;
|
|
|
|
|
if ($id !== null) {
|
|
|
|
|
$prs = $entityManager->getRepository(HesabdariRow::class)->findByJoinMoney([
|
|
|
|
|
'id' => $id,
|
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
|
'person' => $person,
|
|
|
|
|
'year' => $acc['year'],
|
|
|
|
|
], $acc['money']);
|
|
|
|
|
if (count($prs) != 0) {
|
|
|
|
|
$transactions[] = $prs[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
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)) {
|
2025-02-14 09:10:40 +03:30
|
|
|
|
$transactions = $entityManager->getRepository(HesabdariRow::class)->findByJoinMoney([
|
2024-04-27 23:45:38 +03:30
|
|
|
|
'bid' => $acc['bid'],
|
2025-02-09 01:45:04 +03:30
|
|
|
|
'person' => $person,
|
|
|
|
|
'year' => $acc['year'],
|
2025-02-14 09:10:40 +03:30
|
|
|
|
], $acc['money']);
|
2024-04-27 23:45:38 +03:30
|
|
|
|
} else {
|
2024-02-13 12:09:20 +03:30
|
|
|
|
$transactions = [];
|
2025-06-08 05:12:08 +03:30
|
|
|
|
if (is_array($params['items'])) {
|
|
|
|
|
foreach ($params['items'] as $param) {
|
|
|
|
|
$id = is_array($param) ? ($param['id'] ?? null) : $param;
|
|
|
|
|
if ($id !== null) {
|
|
|
|
|
$prs = $entityManager->getRepository(HesabdariRow::class)->findByJoinMoney([
|
|
|
|
|
'id' => $id,
|
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
|
'person' => $person,
|
|
|
|
|
'year' => $acc['year'],
|
|
|
|
|
], $acc['money']);
|
|
|
|
|
if (count($prs) != 0) {
|
|
|
|
|
$transactions[] = $prs[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
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();
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
|
$params = [];
|
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
|
}
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
|
|
|
|
$queryBuilder = $entityManager->getRepository(HesabdariDoc::class)->createQueryBuilder('d')
|
|
|
|
|
->where('d.bid = :bid')
|
|
|
|
|
->andWhere('d.type = :type')
|
|
|
|
|
->andWhere('d.year = :year')
|
|
|
|
|
->andWhere('d.money = :money')
|
|
|
|
|
->setParameter('bid', $acc['bid'])
|
|
|
|
|
->setParameter('type', 'person_receive')
|
|
|
|
|
->setParameter('year', $acc['year'])
|
|
|
|
|
->setParameter('money', $acc['money']);
|
|
|
|
|
|
|
|
|
|
// اگر آیتمهای خاصی درخواست شدهاند
|
|
|
|
|
if (array_key_exists('items', $params)) {
|
|
|
|
|
$ids = array_map(function($item) { return $item['id']; }, $params['items']);
|
|
|
|
|
$queryBuilder->andWhere('d.id IN (:ids)')
|
|
|
|
|
->setParameter('ids', $ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// دریافت تعداد کل رکوردها
|
|
|
|
|
$totalItems = $queryBuilder->select('COUNT(d.id)')
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getSingleScalarResult();
|
|
|
|
|
|
2025-05-04 01:07:39 +03:30
|
|
|
|
// اگر درخواست با صفحهبندی است
|
|
|
|
|
if (array_key_exists('page', $params) && array_key_exists('limit', $params)) {
|
|
|
|
|
$page = $params['page'];
|
|
|
|
|
$limit = $params['limit'];
|
|
|
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
|
|
|
|
|
|
$items = $queryBuilder->select('d')
|
|
|
|
|
->setFirstResult($offset)
|
|
|
|
|
->setMaxResults($limit)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getResult();
|
|
|
|
|
} else {
|
|
|
|
|
// دریافت همه آیتمها بدون صفحهبندی
|
|
|
|
|
$items = $queryBuilder->select('d')
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getResult();
|
|
|
|
|
}
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
|
|
|
|
// اضافه کردن اطلاعات اشخاص به هر آیتم
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
$personNames = [];
|
|
|
|
|
foreach ($item->getHesabdariRows() as $row) {
|
|
|
|
|
if ($row->getPerson()) {
|
|
|
|
|
$personNames[] = $row->getPerson()->getNikename();
|
|
|
|
|
}
|
2023-10-02 17:43:51 +03:30
|
|
|
|
}
|
2025-03-15 23:53:06 +03:30
|
|
|
|
$item->personNames = implode('، ', array_unique($personNames));
|
2023-10-02 17:43:51 +03:30
|
|
|
|
}
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
|
$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'],
|
2025-03-15 23:53:06 +03:30
|
|
|
|
'items' => $items,
|
|
|
|
|
'totalItems' => $totalItems,
|
2025-05-04 01:07:39 +03:30
|
|
|
|
'currentPage' => $params['page'] ?? 1,
|
|
|
|
|
'totalPages' => array_key_exists('limit', $params) ? ceil($totalItems / $params['limit']) : 1
|
2024-04-27 23:45:38 +03:30
|
|
|
|
])
|
|
|
|
|
);
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
|
|
|
|
return $this->json([
|
|
|
|
|
'id' => $pid,
|
|
|
|
|
'totalItems' => $totalItems,
|
2025-05-04 01:07:39 +03:30
|
|
|
|
'currentPage' => $params['page'] ?? 1,
|
|
|
|
|
'totalPages' => array_key_exists('limit', $params) ? ceil($totalItems / $params['limit']) : 1
|
2025-03-15 23:53:06 +03:30
|
|
|
|
]);
|
2023-10-02 17:43:51 +03:30
|
|
|
|
}
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
#[Route('/api/person/receive/list/search', name: 'app_persons_receive_list_search', methods: ['POST'])]
|
|
|
|
|
public function app_persons_receive_list_search(
|
|
|
|
|
Request $request,
|
|
|
|
|
Access $access,
|
|
|
|
|
EntityManagerInterface $entityManager,
|
|
|
|
|
Jdate $jdate
|
|
|
|
|
): JsonResponse {
|
2024-07-18 12:15:09 +03:30
|
|
|
|
$acc = $access->hasRole('getpay');
|
2025-03-15 23:53:06 +03:30
|
|
|
|
if (!$acc) {
|
2024-06-04 14:23:07 +03:30
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
}
|
2025-04-03 02:42:48 +03:30
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
// دریافت پارامترها
|
|
|
|
|
$params = json_decode($request->getContent(), true) ?? [];
|
|
|
|
|
$page = (int) ($params['page'] ?? 1);
|
|
|
|
|
$itemsPerPage = (int) ($params['itemsPerPage'] ?? 10);
|
|
|
|
|
$search = $params['search'] ?? '';
|
|
|
|
|
$dateFilter = $params['dateFilter'] ?? 'all';
|
2025-04-03 02:42:48 +03:30
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
// کوئری پایه برای اسناد
|
|
|
|
|
$queryBuilder = $entityManager->getRepository(HesabdariDoc::class)
|
|
|
|
|
->createQueryBuilder('d')
|
|
|
|
|
->select('DISTINCT d.id, d.date, d.code, d.des, d.amount')
|
|
|
|
|
->leftJoin('d.hesabdariRows', 'hr')
|
|
|
|
|
->leftJoin('hr.person', 'p')
|
|
|
|
|
->where('d.bid = :bid')
|
|
|
|
|
->andWhere('d.type = :type')
|
|
|
|
|
->andWhere('d.year = :year')
|
|
|
|
|
->andWhere('d.money = :money')
|
2025-04-27 16:02:26 +03:30
|
|
|
|
->setParameter('bid', $acc['bid'])
|
|
|
|
|
->setParameter('type', 'person_receive')
|
|
|
|
|
->setParameter('year', $acc['year'])
|
|
|
|
|
->setParameter('money', $acc['money'])
|
2025-03-15 23:53:06 +03:30
|
|
|
|
->orderBy('d.id', 'DESC');
|
2025-04-03 02:42:48 +03:30
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
// جستوجو
|
|
|
|
|
if (!empty($search)) {
|
|
|
|
|
$queryBuilder->andWhere(
|
|
|
|
|
$queryBuilder->expr()->orX(
|
|
|
|
|
'd.code LIKE :search',
|
|
|
|
|
'd.des LIKE :search',
|
|
|
|
|
'p.nikename LIKE :search'
|
|
|
|
|
)
|
|
|
|
|
)->setParameter('search', "%$search%");
|
|
|
|
|
}
|
2025-04-03 02:42:48 +03:30
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
// فیلتر تاریخ
|
|
|
|
|
$today = $jdate->GetTodayDate();
|
|
|
|
|
switch ($dateFilter) {
|
|
|
|
|
case 'today':
|
|
|
|
|
$queryBuilder->andWhere('d.date = :today')
|
|
|
|
|
->setParameter('today', $today);
|
|
|
|
|
break;
|
|
|
|
|
case 'thisWeek':
|
|
|
|
|
$dayOfWeek = (int) $jdate->jdate('w', time());
|
|
|
|
|
$startOfWeek = $jdate->shamsiDate(0, 0, -$dayOfWeek);
|
|
|
|
|
$endOfWeek = $jdate->shamsiDate(0, 0, 6 - $dayOfWeek);
|
|
|
|
|
$queryBuilder->andWhere('d.date BETWEEN :start AND :end')
|
2025-04-27 16:02:26 +03:30
|
|
|
|
->setParameter('start', $startOfWeek)
|
|
|
|
|
->setParameter('end', $endOfWeek);
|
2025-03-15 23:53:06 +03:30
|
|
|
|
break;
|
|
|
|
|
case 'thisMonth':
|
|
|
|
|
$currentYear = (int) $jdate->jdate('Y', time());
|
|
|
|
|
$currentMonth = (int) $jdate->jdate('n', time());
|
|
|
|
|
$daysInMonth = (int) $jdate->jdate('t', time());
|
|
|
|
|
$startOfMonth = sprintf('%d/%02d/01', $currentYear, $currentMonth);
|
|
|
|
|
$endOfMonth = sprintf('%d/%02d/%02d', $currentYear, $currentMonth, $daysInMonth);
|
|
|
|
|
$queryBuilder->andWhere('d.date BETWEEN :start AND :end')
|
2025-04-27 16:02:26 +03:30
|
|
|
|
->setParameter('start', $startOfMonth)
|
|
|
|
|
->setParameter('end', $endOfMonth);
|
2025-03-15 23:53:06 +03:30
|
|
|
|
break;
|
|
|
|
|
case 'all':
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-04-03 02:42:48 +03:30
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
// محاسبه تعداد کل
|
|
|
|
|
$totalQuery = (clone $queryBuilder)
|
|
|
|
|
->select('COUNT(DISTINCT d.id) as total')
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getSingleResult();
|
|
|
|
|
$total = (int) $totalQuery['total'];
|
2025-04-03 02:42:48 +03:30
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
// گرفتن اسناد با صفحهبندی
|
|
|
|
|
$docs = $queryBuilder
|
|
|
|
|
->setFirstResult(($page - 1) * $itemsPerPage)
|
|
|
|
|
->setMaxResults($itemsPerPage)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getArrayResult();
|
|
|
|
|
|
|
|
|
|
// گرفتن اشخاص مرتبط
|
|
|
|
|
$docIds = array_column($docs, 'id');
|
|
|
|
|
$persons = [];
|
|
|
|
|
if (!empty($docIds)) {
|
|
|
|
|
$personQuery = $entityManager->createQueryBuilder()
|
|
|
|
|
->select('IDENTITY(hr.doc) as doc_id, p.code as person_code, p.nikename as person_nikename')
|
|
|
|
|
->from('App\Entity\HesabdariRow', 'hr')
|
|
|
|
|
->leftJoin('hr.person', 'p')
|
|
|
|
|
->where('hr.doc IN (:docIds)')
|
|
|
|
|
->setParameter('docIds', $docIds)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getArrayResult();
|
|
|
|
|
|
|
|
|
|
foreach ($personQuery as $row) {
|
|
|
|
|
if (!empty($row['person_code'])) {
|
|
|
|
|
$persons[$row['doc_id']][] = [
|
|
|
|
|
'code' => $row['person_code'],
|
|
|
|
|
'nikename' => $row['person_nikename'],
|
|
|
|
|
];
|
2024-06-04 14:23:07 +03:30
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
|
|
|
|
// ساختاردهی خروجی
|
|
|
|
|
$items = [];
|
|
|
|
|
foreach ($docs as $doc) {
|
|
|
|
|
$items[] = [
|
|
|
|
|
'id' => $doc['id'],
|
|
|
|
|
'date' => $doc['date'],
|
|
|
|
|
'code' => $doc['code'],
|
|
|
|
|
'des' => $doc['des'],
|
|
|
|
|
'amount' => $doc['amount'],
|
|
|
|
|
'persons' => $persons[$doc['id']] ?? [],
|
|
|
|
|
];
|
|
|
|
|
}
|
2025-04-03 02:42:48 +03:30
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
return $this->json([
|
|
|
|
|
'items' => $items,
|
|
|
|
|
'total' => $total,
|
|
|
|
|
]);
|
2024-06-04 14:23:07 +03:30
|
|
|
|
}
|
|
|
|
|
|
2025-03-15 23:53:06 +03:30
|
|
|
|
#[Route('/api/person/receive/list/excel', name: 'app_persons_receive_list_excel', methods: ['POST'])]
|
|
|
|
|
public function app_persons_receive_list_excel(
|
|
|
|
|
Provider $provider,
|
|
|
|
|
Request $request,
|
|
|
|
|
Access $access,
|
|
|
|
|
Log $log,
|
|
|
|
|
EntityManagerInterface $entityManager
|
|
|
|
|
): BinaryFileResponse {
|
2024-07-18 12:15:09 +03:30
|
|
|
|
$acc = $access->hasRole('getpay');
|
2025-03-15 23:53:06 +03:30
|
|
|
|
if (!$acc) {
|
2023-10-02 17:43:51 +03:30
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
}
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
|
|
|
|
$params = json_decode($request->getContent(), true) ?? [];
|
|
|
|
|
if (!array_key_exists('items', $params) || empty($params['items'])) {
|
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-03-15 23:53:06 +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) {
|
2025-03-15 23:53:06 +03:30
|
|
|
|
if (!is_array($param) || !isset($param['id'])) {
|
|
|
|
|
throw new \InvalidArgumentException('Invalid item format in request');
|
|
|
|
|
}
|
|
|
|
|
$doc = $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'],
|
2025-03-15 23:53:06 +03:30
|
|
|
|
'money' => $acc['money'],
|
2023-10-02 17:43:51 +03:30
|
|
|
|
]);
|
2025-03-15 23:53:06 +03:30
|
|
|
|
if ($doc) {
|
|
|
|
|
// اضافه کردن اطلاعات اشخاص
|
|
|
|
|
$personNames = [];
|
|
|
|
|
foreach ($doc->getHesabdariRows() as $row) {
|
|
|
|
|
if ($row->getPerson()) {
|
|
|
|
|
$personNames[] = $row->getPerson()->getNikename();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$doc->personNames = implode('، ', array_unique($personNames));
|
|
|
|
|
$items[] = $doc;
|
|
|
|
|
}
|
2023-10-02 17:43:51 +03:30
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-15 23:53:06 +03:30
|
|
|
|
|
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();
|
2025-05-22 04:45:44 +03:30
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
|
$params = [];
|
|
|
|
|
if ($content = $request->getContent()) {
|
|
|
|
|
$params = json_decode($content, true);
|
|
|
|
|
}
|
2025-05-22 04:45:44 +03:30
|
|
|
|
|
|
|
|
|
$queryBuilder = $entityManager->getRepository(HesabdariDoc::class)->createQueryBuilder('d')
|
|
|
|
|
->where('d.bid = :bid')
|
|
|
|
|
->andWhere('d.type = :type')
|
|
|
|
|
->andWhere('d.year = :year')
|
|
|
|
|
->andWhere('d.money = :money')
|
|
|
|
|
->setParameter('bid', $acc['bid'])
|
|
|
|
|
->setParameter('type', 'person_send')
|
|
|
|
|
->setParameter('year', $acc['year'])
|
|
|
|
|
->setParameter('money', $acc['money']);
|
|
|
|
|
|
|
|
|
|
// اگر آیتمهای خاصی درخواست شدهاند
|
|
|
|
|
if (array_key_exists('items', $params)) {
|
|
|
|
|
$ids = array_map(function($item) { return $item['id']; }, $params['items']);
|
|
|
|
|
$queryBuilder->andWhere('d.id IN (:ids)')
|
|
|
|
|
->setParameter('ids', $ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// دریافت تعداد کل رکوردها
|
|
|
|
|
$totalItems = $queryBuilder->select('COUNT(d.id)')
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getSingleScalarResult();
|
|
|
|
|
|
|
|
|
|
// اگر درخواست با صفحهبندی است
|
|
|
|
|
if (array_key_exists('page', $params) && array_key_exists('limit', $params)) {
|
|
|
|
|
$page = $params['page'];
|
|
|
|
|
$limit = $params['limit'];
|
|
|
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
|
|
|
|
|
|
$items = $queryBuilder->select('d')
|
|
|
|
|
->setFirstResult($offset)
|
|
|
|
|
->setMaxResults($limit)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getResult();
|
2024-04-27 23:45:38 +03:30
|
|
|
|
} else {
|
2025-05-22 04:45:44 +03:30
|
|
|
|
// دریافت همه آیتمها بدون صفحهبندی
|
|
|
|
|
$items = $queryBuilder->select('d')
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// اضافه کردن اطلاعات اشخاص به هر آیتم
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
$personNames = [];
|
|
|
|
|
foreach ($item->getHesabdariRows() as $row) {
|
|
|
|
|
if ($row->getPerson()) {
|
|
|
|
|
$personNames[] = $row->getPerson()->getNikename();
|
|
|
|
|
}
|
2023-10-02 17:43:51 +03:30
|
|
|
|
}
|
2025-05-22 04:45:44 +03:30
|
|
|
|
$item->personNames = implode('، ', array_unique($personNames));
|
2023-10-02 17:43:51 +03:30
|
|
|
|
}
|
2025-05-22 04:45:44 +03:30
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
|
$pid = $provider->createPrint(
|
|
|
|
|
$acc['bid'],
|
|
|
|
|
$this->getUser(),
|
2025-05-22 04:45:44 +03:30
|
|
|
|
$this->renderView('pdf/persons_send.html.twig', [
|
2024-04-27 23:45:38 +03:30
|
|
|
|
'page_title' => 'لیست پرداختها',
|
|
|
|
|
'bid' => $acc['bid'],
|
2025-05-22 04:45:44 +03:30
|
|
|
|
'items' => $items,
|
|
|
|
|
'totalItems' => $totalItems,
|
|
|
|
|
'currentPage' => $params['page'] ?? 1,
|
|
|
|
|
'totalPages' => array_key_exists('limit', $params) ? ceil($totalItems / $params['limit']) : 1
|
2024-04-27 23:45:38 +03:30
|
|
|
|
])
|
|
|
|
|
);
|
2025-05-22 04:45:44 +03:30
|
|
|
|
|
|
|
|
|
return $this->json([
|
|
|
|
|
'id' => $pid,
|
|
|
|
|
'totalItems' => $totalItems,
|
|
|
|
|
'currentPage' => $params['page'] ?? 1,
|
|
|
|
|
'totalPages' => array_key_exists('limit', $params) ? ceil($totalItems / $params['limit']) : 1
|
|
|
|
|
]);
|
2023-10-02 17:43:51 +03:30
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 04:45:44 +03:30
|
|
|
|
#[Route('/api/person/send/list/search', name: 'app_persons_send_list_search', methods: ['POST'])]
|
|
|
|
|
public function app_persons_send_list_search(
|
|
|
|
|
Request $request,
|
|
|
|
|
Access $access,
|
|
|
|
|
EntityManagerInterface $entityManager,
|
|
|
|
|
Jdate $jdate
|
|
|
|
|
): JsonResponse {
|
2024-07-18 12:15:09 +03:30
|
|
|
|
$acc = $access->hasRole('getpay');
|
2025-05-22 04:45:44 +03:30
|
|
|
|
if (!$acc) {
|
2024-06-04 14:23:07 +03:30
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 04:45:44 +03:30
|
|
|
|
// دریافت پارامترها
|
|
|
|
|
$params = json_decode($request->getContent(), true) ?? [];
|
|
|
|
|
$page = (int) ($params['page'] ?? 1);
|
|
|
|
|
$itemsPerPage = (int) ($params['itemsPerPage'] ?? 10);
|
|
|
|
|
$search = $params['search'] ?? '';
|
|
|
|
|
$dateFilter = $params['dateFilter'] ?? 'all';
|
|
|
|
|
|
|
|
|
|
// کوئری پایه برای اسناد
|
|
|
|
|
$queryBuilder = $entityManager->getRepository(HesabdariDoc::class)
|
|
|
|
|
->createQueryBuilder('d')
|
|
|
|
|
->select('DISTINCT d.id, d.date, d.code, d.des, d.amount')
|
|
|
|
|
->leftJoin('d.hesabdariRows', 'hr')
|
|
|
|
|
->leftJoin('hr.person', 'p')
|
|
|
|
|
->where('d.bid = :bid')
|
|
|
|
|
->andWhere('d.type = :type')
|
|
|
|
|
->andWhere('d.year = :year')
|
|
|
|
|
->andWhere('d.money = :money')
|
|
|
|
|
->setParameter('bid', $acc['bid'])
|
|
|
|
|
->setParameter('type', 'person_send')
|
|
|
|
|
->setParameter('year', $acc['year'])
|
|
|
|
|
->setParameter('money', $acc['money'])
|
|
|
|
|
->orderBy('d.id', 'DESC');
|
|
|
|
|
|
|
|
|
|
// جستوجو
|
|
|
|
|
if (!empty($search)) {
|
|
|
|
|
$queryBuilder->andWhere(
|
|
|
|
|
$queryBuilder->expr()->orX(
|
|
|
|
|
'd.code LIKE :search',
|
|
|
|
|
'd.des LIKE :search',
|
|
|
|
|
'p.nikename LIKE :search'
|
|
|
|
|
)
|
|
|
|
|
)->setParameter('search', "%$search%");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// فیلتر تاریخ
|
|
|
|
|
$today = $jdate->GetTodayDate();
|
|
|
|
|
switch ($dateFilter) {
|
|
|
|
|
case 'today':
|
|
|
|
|
$queryBuilder->andWhere('d.date = :today')
|
|
|
|
|
->setParameter('today', $today);
|
|
|
|
|
break;
|
|
|
|
|
case 'thisWeek':
|
|
|
|
|
$dayOfWeek = (int) $jdate->jdate('w', time());
|
|
|
|
|
$startOfWeek = $jdate->shamsiDate(0, 0, -$dayOfWeek);
|
|
|
|
|
$endOfWeek = $jdate->shamsiDate(0, 0, 6 - $dayOfWeek);
|
|
|
|
|
$queryBuilder->andWhere('d.date BETWEEN :start AND :end')
|
|
|
|
|
->setParameter('start', $startOfWeek)
|
|
|
|
|
->setParameter('end', $endOfWeek);
|
|
|
|
|
break;
|
|
|
|
|
case 'thisMonth':
|
|
|
|
|
$currentYear = (int) $jdate->jdate('Y', time());
|
|
|
|
|
$currentMonth = (int) $jdate->jdate('n', time());
|
|
|
|
|
$daysInMonth = (int) $jdate->jdate('t', time());
|
|
|
|
|
$startOfMonth = sprintf('%d/%02d/01', $currentYear, $currentMonth);
|
|
|
|
|
$endOfMonth = sprintf('%d/%02d/%02d', $currentYear, $currentMonth, $daysInMonth);
|
|
|
|
|
$queryBuilder->andWhere('d.date BETWEEN :start AND :end')
|
|
|
|
|
->setParameter('start', $startOfMonth)
|
|
|
|
|
->setParameter('end', $endOfMonth);
|
|
|
|
|
break;
|
|
|
|
|
case 'all':
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// محاسبه تعداد کل
|
|
|
|
|
$totalQuery = (clone $queryBuilder)
|
|
|
|
|
->select('COUNT(DISTINCT d.id) as total')
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getSingleResult();
|
|
|
|
|
$total = (int) $totalQuery['total'];
|
|
|
|
|
|
|
|
|
|
// گرفتن اسناد با صفحهبندی
|
|
|
|
|
$docs = $queryBuilder
|
|
|
|
|
->setFirstResult(($page - 1) * $itemsPerPage)
|
|
|
|
|
->setMaxResults($itemsPerPage)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getArrayResult();
|
|
|
|
|
|
|
|
|
|
// گرفتن اشخاص مرتبط
|
|
|
|
|
$docIds = array_column($docs, 'id');
|
|
|
|
|
$persons = [];
|
|
|
|
|
if (!empty($docIds)) {
|
|
|
|
|
$personQuery = $entityManager->createQueryBuilder()
|
|
|
|
|
->select('IDENTITY(hr.doc) as doc_id, p.code as person_code, p.nikename as person_nikename')
|
|
|
|
|
->from('App\Entity\HesabdariRow', 'hr')
|
|
|
|
|
->leftJoin('hr.person', 'p')
|
|
|
|
|
->where('hr.doc IN (:docIds)')
|
|
|
|
|
->setParameter('docIds', $docIds)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getArrayResult();
|
|
|
|
|
|
|
|
|
|
foreach ($personQuery as $row) {
|
|
|
|
|
if (!empty($row['person_code'])) {
|
|
|
|
|
$persons[$row['doc_id']][] = [
|
|
|
|
|
'code' => $row['person_code'],
|
|
|
|
|
'nikename' => $row['person_nikename'],
|
|
|
|
|
];
|
2024-06-04 14:23:07 +03:30
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-22 04:45:44 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ساختاردهی خروجی
|
|
|
|
|
$items = [];
|
|
|
|
|
foreach ($docs as $doc) {
|
|
|
|
|
$items[] = [
|
|
|
|
|
'id' => $doc['id'],
|
|
|
|
|
'date' => $doc['date'],
|
|
|
|
|
'code' => $doc['code'],
|
|
|
|
|
'des' => $doc['des'],
|
|
|
|
|
'amount' => $doc['amount'],
|
|
|
|
|
'persons' => $persons[$doc['id']] ?? [],
|
|
|
|
|
];
|
2024-06-04 14:23:07 +03:30
|
|
|
|
}
|
2024-11-03 14:40:50 +03:30
|
|
|
|
|
2025-05-22 04:45:44 +03:30
|
|
|
|
return $this->json([
|
|
|
|
|
'items' => $items,
|
|
|
|
|
'total' => $total,
|
|
|
|
|
]);
|
2024-06-04 14:23:07 +03:30
|
|
|
|
}
|
|
|
|
|
|
2023-10-02 17:43:51 +03:30
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2025-05-22 04:45:44 +03:30
|
|
|
|
#[Route('/api/person/send/list/excel', name: 'app_persons_send_list_excel', methods: ['POST'])]
|
|
|
|
|
public function app_persons_send_list_excel(
|
|
|
|
|
Provider $provider,
|
|
|
|
|
Request $request,
|
|
|
|
|
Access $access,
|
|
|
|
|
Log $log,
|
|
|
|
|
EntityManagerInterface $entityManager
|
|
|
|
|
): BinaryFileResponse {
|
2024-07-18 12:15:09 +03:30
|
|
|
|
$acc = $access->hasRole('getpay');
|
2025-05-22 04:45:44 +03:30
|
|
|
|
if (!$acc) {
|
2023-10-02 17:43:51 +03:30
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
}
|
2025-05-22 04:45:44 +03:30
|
|
|
|
|
|
|
|
|
$params = json_decode($request->getContent(), true) ?? [];
|
|
|
|
|
if (!array_key_exists('items', $params) || empty($params['items'])) {
|
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'],
|
2025-05-22 04:45:44 +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) {
|
2025-05-22 04:45:44 +03:30
|
|
|
|
if (!is_array($param) || !isset($param['id'])) {
|
|
|
|
|
throw new \InvalidArgumentException('Invalid item format in request');
|
|
|
|
|
}
|
|
|
|
|
$doc = $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'],
|
2025-05-22 04:45:44 +03:30
|
|
|
|
'money' => $acc['money'],
|
2023-10-02 17:43:51 +03:30
|
|
|
|
]);
|
2025-05-22 04:45:44 +03:30
|
|
|
|
if ($doc) {
|
|
|
|
|
// اضافه کردن اطلاعات اشخاص
|
|
|
|
|
$personNames = [];
|
|
|
|
|
foreach ($doc->getHesabdariRows() as $row) {
|
|
|
|
|
if ($row->getPerson()) {
|
|
|
|
|
$personNames[] = $row->getPerson()->getNikename();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$doc->personNames = implode('، ', array_unique($personNames));
|
|
|
|
|
$items[] = $doc;
|
|
|
|
|
}
|
2023-10-02 17:43:51 +03:30
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-22 04:45:44 +03:30
|
|
|
|
|
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();
|
2025-06-01 11:48:12 +03:30
|
|
|
|
$maxAttempts = 10; // حداکثر تعداد تلاش برای تولید کد جدید
|
|
|
|
|
$code = null;
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < $maxAttempts; $i++) {
|
2025-05-13 16:15:44 +03:30
|
|
|
|
$code = $provider->getAccountingCode($acc['bid'], 'person');
|
|
|
|
|
$exist = $entityManager->getRepository(Person::class)->findOneBy([
|
|
|
|
|
'code' => $code
|
|
|
|
|
]);
|
2025-06-01 11:48:12 +03:30
|
|
|
|
if (!$exist) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($code === null) {
|
|
|
|
|
throw new \Exception('نمیتوان کد جدیدی برای شخص تولید کرد');
|
2025-05-13 16:15:44 +03:30
|
|
|
|
}
|
2025-06-01 11:48:12 +03:30
|
|
|
|
|
2025-05-13 16:15:44 +03:30
|
|
|
|
$person->setCode($code);
|
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
|
2025-04-12 18:50:34 +03:30
|
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
|
|
|
|
]);
|
|
|
|
|
if (count($rows) > 0)
|
2024-06-13 15:01:57 +03:30
|
|
|
|
return $this->json(['result' => 2]);
|
|
|
|
|
//check for storeroom docs
|
2025-04-12 18:50:34 +03:30
|
|
|
|
$storeDocs = $entityManager->getRepository(StoreroomTicket::class)->findBy([
|
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
|
'Person' => $person
|
|
|
|
|
]);
|
2024-06-13 15:01:57 +03:30
|
|
|
|
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));
|
|
|
|
|
}
|
2025-04-04 00:27:13 +03:30
|
|
|
|
|
|
|
|
|
#[Route('/api/person/deletegroup', name: 'app_persons_delete_group', methods: ['POST'])]
|
|
|
|
|
public function app_persons_delete_group(
|
|
|
|
|
Extractor $extractor,
|
|
|
|
|
Request $request,
|
|
|
|
|
Access $access,
|
|
|
|
|
Log $log,
|
|
|
|
|
EntityManagerInterface $entityManager
|
|
|
|
|
): JsonResponse {
|
|
|
|
|
$acc = $access->hasRole('person');
|
|
|
|
|
if (!$acc) {
|
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$params = json_decode($request->getContent(), true);
|
|
|
|
|
if (!isset($params['codes']) || !is_array($params['codes'])) {
|
|
|
|
|
return $this->json(['Success' => false, 'message' => 'لیست کدهای اشخاص ارسال نشده است'], 400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$hasIgnored = false;
|
|
|
|
|
$deletedCount = 0;
|
|
|
|
|
|
|
|
|
|
foreach ($params['codes'] as $code) {
|
|
|
|
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
|
'code' => $code
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if (!$person) {
|
|
|
|
|
$hasIgnored = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// بررسی اسناد حسابداری
|
2025-04-12 18:50:34 +03:30
|
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
|
|
|
|
]);
|
|
|
|
|
if (count($rows) > 0) {
|
2025-04-04 00:27:13 +03:30
|
|
|
|
$hasIgnored = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// بررسی اسناد انبار
|
2025-04-12 18:50:34 +03:30
|
|
|
|
$storeDocs = $entityManager->getRepository(StoreroomTicket::class)->findBy([
|
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
|
'Person' => $person
|
|
|
|
|
]);
|
2025-04-04 00:27:13 +03:30
|
|
|
|
if (count($storeDocs) > 0) {
|
|
|
|
|
$hasIgnored = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$personName = $person->getNikename();
|
|
|
|
|
$entityManager->remove($person);
|
|
|
|
|
$log->insert('اشخاص', 'شخص با نام ' . $personName . ' حذف شد.', $this->getUser(), $acc['bid']->getId());
|
|
|
|
|
$deletedCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$entityManager->flush();
|
|
|
|
|
|
|
|
|
|
return $this->json([
|
|
|
|
|
'Success' => true,
|
|
|
|
|
'result' => [
|
|
|
|
|
'ignored' => $hasIgnored,
|
|
|
|
|
'deletedCount' => $deletedCount,
|
|
|
|
|
'message' => $hasIgnored ? 'برخی اشخاص به دلیل استفاده در اسناد حذف نشدند' : 'همه اشخاص با موفقیت حذف شدند'
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
}
|
2025-06-02 10:41:53 +03:30
|
|
|
|
|
|
|
|
|
#[Route('/api/person/list/debtors/excel/{id}', name: 'app_persons_debtors_list_excel', methods: ['POST'])]
|
|
|
|
|
public function app_persons_debtors_list_excel(Request $request, $id, Access $access, EntityManagerInterface $entityManager): Response
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$acc = $access->hasRole('person');
|
|
|
|
|
if (!$acc)
|
|
|
|
|
throw $this->createAccessDeniedException();
|
|
|
|
|
|
|
|
|
|
$data = json_decode($request->getContent(), true);
|
|
|
|
|
$selectedItems = $data['items'] ?? [];
|
|
|
|
|
|
|
|
|
|
// اگر آیتمهای انتخاب شده وجود دارند، فقط آنها را دریافت کن
|
|
|
|
|
if (!empty($selectedItems)) {
|
|
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
|
|
|
|
'bid' => $acc['bid'],
|
|
|
|
|
'code' => $selectedItems
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
$persons = $entityManager->getRepository(Person::class)->findBy([
|
|
|
|
|
'bid' => $acc['bid']
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = [];
|
|
|
|
|
foreach ($persons as $key => $person) {
|
|
|
|
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
|
|
|
|
'person' => $person,
|
|
|
|
|
'bid' => $acc['bid']
|
|
|
|
|
]);
|
|
|
|
|
$bs = 0;
|
|
|
|
|
$bd = 0;
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
|
$bs += $row->getBs();
|
|
|
|
|
$bd += $row->getBd();
|
|
|
|
|
}
|
|
|
|
|
$response[$key] = [
|
|
|
|
|
'code' => $person->getCode(),
|
|
|
|
|
'nikename' => $person->getNikename(),
|
|
|
|
|
'name' => $person->getName(),
|
|
|
|
|
'birthday' => $person->getBirthday(),
|
|
|
|
|
'company' => $person->getCompany(),
|
|
|
|
|
'shenasemeli' => $person->getShenasemeli(),
|
|
|
|
|
'codeeghtesadi' => $person->getCodeeghtesadi(),
|
|
|
|
|
'sabt' => $person->getSabt(),
|
|
|
|
|
'keshvar' => $person->getKeshvar(),
|
|
|
|
|
'ostan' => $person->getOstan(),
|
|
|
|
|
'shahr' => $person->getShahr(),
|
|
|
|
|
'postalcode' => $person->getPostalcode(),
|
|
|
|
|
'tel' => $person->getTel(),
|
|
|
|
|
'mobile' => $person->getMobile(),
|
|
|
|
|
'email' => $person->getEmail(),
|
|
|
|
|
'website' => $person->getWebsite(),
|
|
|
|
|
'fax' => $person->getFax(),
|
|
|
|
|
'bs' => $bs,
|
|
|
|
|
'bd' => $bd,
|
|
|
|
|
'balance' => $bs - $bd
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ایجاد فایل اکسل
|
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
|
|
|
|
|
|
|
// تنظیم راست به چپ
|
|
|
|
|
$sheet->setRightToLeft(true);
|
|
|
|
|
|
|
|
|
|
// تنظیم هدرها
|
|
|
|
|
$headers = [
|
|
|
|
|
'A1' => 'کد',
|
|
|
|
|
'B1' => 'نام مستعار',
|
|
|
|
|
'C1' => 'وضعیت حساب',
|
|
|
|
|
'D1' => 'تراز حساب',
|
|
|
|
|
'E1' => 'نام و نام خانوادگی',
|
|
|
|
|
'F1' => 'تاریخ تولد/ثبت',
|
|
|
|
|
'G1' => 'شرکت',
|
|
|
|
|
'H1' => 'شناسه ملی',
|
|
|
|
|
'I1' => 'کد اقتصادی',
|
|
|
|
|
'J1' => 'شماره ثبت',
|
|
|
|
|
'K1' => 'کشور',
|
|
|
|
|
'L1' => 'استان',
|
|
|
|
|
'M1' => 'شهر',
|
|
|
|
|
'N1' => 'کد پستی',
|
|
|
|
|
'O1' => 'تلفن',
|
|
|
|
|
'P1' => 'تلفن همراه',
|
|
|
|
|
'Q1' => 'ایمیل',
|
|
|
|
|
'R1' => 'وب سایت',
|
|
|
|
|
'S1' => 'فکس'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// اعمال هدرها
|
|
|
|
|
foreach ($headers as $cell => $value) {
|
|
|
|
|
$sheet->setCellValue($cell, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// اضافه کردن دادهها
|
|
|
|
|
$row = 2;
|
|
|
|
|
foreach ($response as $item) {
|
|
|
|
|
$sheet->setCellValue('A' . $row, $item['code']);
|
|
|
|
|
$sheet->setCellValue('B' . $row, $item['nikename']);
|
|
|
|
|
$sheet->setCellValue('C' . $row, $item['balance'] < 0 ? 'بدهکار' : 'بستانکار');
|
|
|
|
|
$sheet->setCellValue('D' . $row, $item['balance']);
|
|
|
|
|
$sheet->setCellValue('E' . $row, $item['name']);
|
|
|
|
|
$sheet->setCellValue('F' . $row, $item['birthday']);
|
|
|
|
|
$sheet->setCellValue('G' . $row, $item['company']);
|
|
|
|
|
$sheet->setCellValue('H' . $row, $item['shenasemeli']);
|
|
|
|
|
$sheet->setCellValue('I' . $row, $item['codeeghtesadi']);
|
|
|
|
|
$sheet->setCellValue('J' . $row, $item['sabt']);
|
|
|
|
|
$sheet->setCellValue('K' . $row, $item['keshvar']);
|
|
|
|
|
$sheet->setCellValue('L' . $row, $item['ostan']);
|
|
|
|
|
$sheet->setCellValue('M' . $row, $item['shahr']);
|
|
|
|
|
$sheet->setCellValue('N' . $row, $item['postalcode']);
|
|
|
|
|
$sheet->setCellValue('O' . $row, $item['tel']);
|
|
|
|
|
$sheet->setCellValue('P' . $row, $item['mobile']);
|
|
|
|
|
$sheet->setCellValue('Q' . $row, $item['email']);
|
|
|
|
|
$sheet->setCellValue('R' . $row, $item['website']);
|
|
|
|
|
$sheet->setCellValue('S' . $row, $item['fax']);
|
|
|
|
|
$row++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// تنظیم عرض ستونها
|
|
|
|
|
foreach (range('A', 'S') as $col) {
|
|
|
|
|
$sheet->getColumnDimension($col)->setAutoSize(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ایجاد فایل اکسل
|
|
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
|
|
$fileName = 'گزارش_بدهکاران_' . date('Y-m-d') . '.xlsx';
|
|
|
|
|
|
|
|
|
|
// تنظیم هدرهای پاسخ
|
|
|
|
|
$response = new Response();
|
|
|
|
|
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
|
|
$response->headers->set('Content-Disposition', 'attachment;filename="' . $fileName . '"');
|
|
|
|
|
$response->headers->set('Cache-Control', 'max-age=0');
|
|
|
|
|
|
|
|
|
|
// ذخیره فایل در حافظه
|
|
|
|
|
ob_start();
|
|
|
|
|
$writer->save('php://output');
|
|
|
|
|
$response->setContent(ob_get_clean());
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return new JsonResponse(['error' => $e->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-04 12:09:44 +03:30
|
|
|
|
|
2023-09-21 23:04:08 +03:30
|
|
|
|
}
|