progress in persons

This commit is contained in:
Hesabix 2025-03-15 20:23:06 +00:00
parent 9b7a037514
commit 9df5a5864b
2 changed files with 239 additions and 92 deletions

View file

@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\PersonPrelabel; use App\Entity\PersonPrelabel;
use App\Service\Extractor; use App\Service\Extractor;
use App\Service\Jdate;
use App\Service\Log; use App\Service\Log;
use App\Entity\Person; use App\Entity\Person;
use App\Service\Access; use App\Service\Access;
@ -991,11 +992,226 @@ class PersonsController extends AbstractController
$acc = $access->hasRole('getpay'); $acc = $access->hasRole('getpay');
if (!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if (!array_key_exists('items', $params)) {
// پارامترهای صفحه‌بندی
$page = $params['page'] ?? 1;
$limit = $params['limit'] ?? 10;
$offset = ($page - 1) * $limit;
$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();
// دریافت داده‌های صفحه فعلی
$items = $queryBuilder->select('d')
->setFirstResult($offset)
->setMaxResults($limit)
->getQuery()
->getResult();
// اضافه کردن اطلاعات اشخاص به هر آیتم
foreach ($items as $item) {
$personNames = [];
foreach ($item->getHesabdariRows() as $row) {
if ($row->getPerson()) {
$personNames[] = $row->getPerson()->getNikename();
}
}
$item->personNames = implode('، ', array_unique($personNames));
}
$pid = $provider->createPrint(
$acc['bid'],
$this->getUser(),
$this->renderView('pdf/persons_receive.html.twig', [
'page_title' => 'لیست دریافت‌ها',
'bid' => $acc['bid'],
'items' => $items,
'totalItems' => $totalItems,
'currentPage' => $page,
'totalPages' => ceil($totalItems / $limit)
])
);
return $this->json([
'id' => $pid,
'totalItems' => $totalItems,
'currentPage' => $page,
'totalPages' => ceil($totalItems / $limit)
]);
}
#[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 {
$acc = $access->hasRole('getpay');
if (!$acc) {
throw $this->createAccessDeniedException();
}
// دریافت پارامترها
$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')
->setParameters([
'bid' => $acc['bid'],
'type' => 'person_receive',
'year' => $acc['year'],
'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')
->setParameters(['start' => $startOfWeek, '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')
->setParameters(['start' => $startOfMonth, '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'],
];
}
}
}
// ساختاردهی خروجی
$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']] ?? [],
];
}
return $this->json([
'items' => $items,
'total' => $total,
]);
}
#[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 {
$acc = $access->hasRole('getpay');
if (!$acc) {
throw $this->createAccessDeniedException();
}
$params = json_decode($request->getContent(), true) ?? [];
if (!array_key_exists('items', $params) || empty($params['items'])) {
$items = $entityManager->getRepository(HesabdariDoc::class)->findBy([ $items = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'type' => 'person_receive', 'type' => 'person_receive',
@ -1005,105 +1221,30 @@ class PersonsController extends AbstractController
} else { } else {
$items = []; $items = [];
foreach ($params['items'] as $param) { foreach ($params['items'] as $param) {
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ if (!is_array($param) || !isset($param['id'])) {
throw new \InvalidArgumentException('Invalid item format in request');
}
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'id' => $param['id'], 'id' => $param['id'],
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'type' => 'person_receive', 'type' => 'person_receive',
'year' => $acc['year'], 'year' => $acc['year'],
'money' => $acc['money'] 'money' => $acc['money'],
]); ]);
if ($prs) if ($doc) {
$items[] = $prs; // اضافه کردن اطلاعات اشخاص
} $personNames = [];
} foreach ($doc->getHesabdariRows() as $row) {
$pid = $provider->createPrint( if ($row->getPerson()) {
$acc['bid'], $personNames[] = $row->getPerson()->getNikename();
$this->getUser(), }
$this->renderView('pdf/persons_receive.html.twig', [ }
'page_title' => 'لیست دریافت‌ها', $doc->personNames = implode('، ', array_unique($personNames));
'bid' => $acc['bid'], $items[] = $doc;
'items' => $items
])
);
return $this->json(['id' => $pid]);
}
#[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
{
$acc = $access->hasRole('getpay');
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',
'year' => $acc['year'],
'money' => $acc['money']
],
['id' => 'DESC']
);
$res = [];
foreach ($items as $item) {
$temp = [
'id' => $item->getId(),
'date' => $item->getDate(),
'code' => $item->getCode(),
'des' => $item->getDes(),
'amount' => $item->getAmount()
];
$persons = [];
foreach ($item->getHesabdariRows() as $row) {
if ($row->getPerson()) {
$persons[] = Explore::ExplorePerson($row->getPerson());
} }
} }
$temp['persons'] = $persons;
$res[] = $temp;
} }
return $this->json($res);
}
/**
* @throws Exception
*/
#[Route('/api/person/receive/list/excel', name: 'app_persons_receive_list_excel')]
public function app_persons_receive_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse|JsonResponse|StreamedResponse
{
$acc = $access->hasRole('getpay');
if (!$acc)
throw $this->createAccessDeniedException();
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
if (!array_key_exists('items', $params)) {
$items = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid' => $acc['bid'],
'type' => 'person_receive',
'year' => $acc['year'],
'money' => $acc['money']
]);
} else {
$items = [];
foreach ($params['items'] as $param) {
$prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'id' => $param['id'],
'bid' => $acc['bid'],
'type' => 'person_receive',
'year' => $acc['year'],
'money' => $acc['money']
]);
if ($prs)
$items[] = $prs;
}
}
return new BinaryFileResponse($provider->createExcell($items, ['type', 'dateSubmit'])); return new BinaryFileResponse($provider->createExcell($items, ['type', 'dateSubmit']));
} }

View file

@ -8,18 +8,24 @@
<td class="center item">کد حسابداری</td> <td class="center item">کد حسابداری</td>
<td class="center item">تاریخ</td> <td class="center item">تاریخ</td>
<td class="center item">مبلغ</td> <td class="center item">مبلغ</td>
<td class="center item">اشخاص</td>
<td class="center item">شرح</td> <td class="center item">شرح</td>
</tr> </tr>
{% for item in items %} {% for item in items %}
<tr class="stimol {% if loop.index is even%}bg-dark text-light{% endif%}"> <tr class="stimol {% if loop.index is even%}bg-dark text-light{% endif%}">
<td class="center item">{{ loop.index }}</td> <td class="center item">{{ loop.index + ((currentPage - 1) * 10) }}</td>
<td class="center item">{{ item.code }}</td> <td class="center item">{{ item.code }}</td>
<td class="center item">{{ item.date }}</td> <td class="center item">{{ item.date }}</td>
<td class="center item">{{ item.amount | number_format }}</td> <td class="center item">{{ item.amount | number_format }}</td>
<td class="center item">{{ item.personNames }}</td>
<td class="center item">{{ item.des }}</td> <td class="center item">{{ item.des }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div style="margin-top: 20px; text-align: left;">
<small>صفحه {{ currentPage }} از {{ totalPages }} - تعداد کل: {{ totalItems }}</small>
</div>
</div> </div>
{% endblock %} {% endblock %}