From cc1515345bc6543005d0f16d57232846ff2a4543 Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Fri, 25 Jul 2025 09:54:43 +0000 Subject: [PATCH] progress in salary and add export pdf/excell to that --- .../src/Controller/SalaryController.php | 150 ++++++- .../templates/pdf/salary_card.html.twig | 105 +++++ webUI/src/views/acc/salary/card.vue | 380 +++++++++++----- webUI/src/views/acc/salary/list.vue | 421 ++++++++++++------ 4 files changed, 818 insertions(+), 238 deletions(-) create mode 100644 hesabixCore/templates/pdf/salary_card.html.twig diff --git a/hesabixCore/src/Controller/SalaryController.php b/hesabixCore/src/Controller/SalaryController.php index 0a1a839..1221233 100644 --- a/hesabixCore/src/Controller/SalaryController.php +++ b/hesabixCore/src/Controller/SalaryController.php @@ -14,6 +14,9 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; +use Symfony\Component\HttpFoundation\BinaryFileResponse; class SalaryController extends AbstractController { @@ -66,7 +69,21 @@ class SalaryController extends AbstractController 'bid' => $acc['bid'], 'code' => $code ]); - return $this->json(Explore::ExploreSalary($data)); + $result = Explore::ExploreSalary($data); + // محاسبه بدهکار و بستانکار و تراز + $bs = 0; + $bd = 0; + $items = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'salary' => $data + ]); + foreach ($items as $item) { + $bs += $item->getBs(); + $bd += $item->getBd(); + } + $result['bs'] = $bs; + $result['bd'] = $bd; + $result['balance'] = $bd - $bs; + return $this->json($result); } #[Route('/api/salary/mod/{code}', name: 'app_salary_mod')] @@ -267,4 +284,135 @@ class SalaryController extends AbstractController 'total' => count($transactions) ]); } + + /** + * خروجی اکسل کارت حساب تنخواه گردان + */ + #[Route('/api/salary/card/list/excel', name: 'app_salary_card_list_excel')] + public function app_salary_card_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse|JsonResponse|Response + { + $acc = $access->hasRole('salary'); + if (!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if (!array_key_exists('code', $params)) + throw $this->createNotFoundException(); + $salary = $entityManager->getRepository(Salary::class)->findOneBy(['bid' => $acc['bid'], 'code' => $params['code']]); + if (!$salary) + throw $this->createNotFoundException(); + if (!array_key_exists('items', $params)) { + $transactions = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'bid' => $acc['bid'], + 'salary' => $salary, + 'year' => $acc['year'], + ]); + } else { + $transactions = []; + if (is_array($params['items'])) { + foreach ($params['items'] as $param) { + $id = is_array($param) ? ($param['id'] ?? null) : $param; + if ($id !== null) { + $row = $entityManager->getRepository(HesabdariRow::class)->findOneBy([ + 'id' => $id, + 'bid' => $acc['bid'], + 'salary' => $salary, + 'year' => $acc['year'], + ]); + if ($row) { + $transactions[] = $row; + } + } + } + } + } + $spreadsheet = new Spreadsheet(); + $activeWorksheet = $spreadsheet->getActiveSheet(); + $arrayEntity = [ + [ + 'شماره تراکنش', + 'تاریخ', + 'توضیحات', + 'تفضیل', + 'بستانکار', + 'بدهکار', + 'سال مالی', + ] + ]; + foreach ($transactions as $transaction) { + $arrayEntity[] = [ + $transaction->getId(), + $transaction->getDoc()->getDate(), + $transaction->getDes(), + $transaction->getRef() ? $transaction->getRef()->getName() : '', + $transaction->getBs(), + $transaction->getBd(), + $transaction->getYear() ? $transaction->getYear()->getlabel() : '', + ]; + } + $activeWorksheet->fromArray($arrayEntity, null, 'A1'); + $activeWorksheet->setRightToLeft(true); + $writer = new Xlsx($spreadsheet); + $filePath = __DIR__ . '/../../var/' . uniqid('salary_card_', true) . '.xlsx'; + $writer->save($filePath); + return new BinaryFileResponse($filePath); + } + + /** + * خروجی PDF کارت حساب تنخواه گردان + */ + #[Route('/api/salary/card/list/print', name: 'app_salary_card_list_print')] + public function app_salary_card_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('salary'); + if (!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if (!array_key_exists('code', $params)) + throw $this->createNotFoundException(); + $salary = $entityManager->getRepository(Salary::class)->findOneBy(['bid' => $acc['bid'], 'code' => $params['code']]); + if (!$salary) + throw $this->createNotFoundException(); + if (!array_key_exists('items', $params)) { + $transactions = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'bid' => $acc['bid'], + 'salary' => $salary, + 'year' => $acc['year'], + ]); + } else { + $transactions = []; + if (is_array($params['items'])) { + foreach ($params['items'] as $param) { + $id = is_array($param) ? ($param['id'] ?? null) : $param; + if ($id !== null) { + $row = $entityManager->getRepository(HesabdariRow::class)->findOneBy([ + 'id' => $id, + 'bid' => $acc['bid'], + 'salary' => $salary, + 'year' => $acc['year'], + ]); + if ($row) { + $transactions[] = $row; + } + } + } + } + } + $pid = $provider->createPrint( + $acc['bid'], + $this->getUser(), + $this->renderView('pdf/salary_card.html.twig', [ + 'page_title' => 'کارت حساب تنخواه گردان ' . $salary->getName(), + 'bid' => $acc['bid'], + 'items' => $transactions, + 'salary' => $salary + ]) + ); + return $this->json(['id' => $pid]); + } } diff --git a/hesabixCore/templates/pdf/salary_card.html.twig b/hesabixCore/templates/pdf/salary_card.html.twig new file mode 100644 index 0000000..e0056f7 --- /dev/null +++ b/hesabixCore/templates/pdf/salary_card.html.twig @@ -0,0 +1,105 @@ +{% extends "pdf/base.html.twig" %} +{% block body %} +
+
+ مشخصات تنخواه گردان +
+ + + + + + + + +
+

+ نام: + {{ salary.name }} +

+
+

+ کد حسابداری: + {{ salary.code }} +

+
+

+ شرح: + {{ salary.des }} +

+
+
+
+ + + + + + + + + + + + + {% set sumBs = 0 %} + {% set sumBd = 0 %} + {% for item in items %} + {% set sumBs = sumBs + item.bs %} + {% set sumBd = sumBd + item.bd %} + + + + + + + + + + + {% endfor %} + +
ردیفشماره سندتاریختوضیحاتتفضیلبدهکاربستانکارشرح سند
{{ loop.index }}{{ item.doc.code }}{{ item.doc.date }}{{ item.des }}{{ item.ref ? item.ref.name : '' }}{{ item.bd | number_format }}{{ item.bs | number_format }}{{ item.doc.des }}
+
+
+
+ وضعیت حساب +
+ + + + + + + + + +
+

+ جمع بستانکار: + {{ sumBs | number_format }} +

+
+

+ جمع بدهکار: + {{ sumBd | number_format }} +

+
+

+ تراز حساب: + {{ (sumBs - sumBd) | abs |number_format }} +

+
+

+ وضعیت: + {% if sumBs > sumBd%} + بستانکار + {% elseif sumBs == sumBd %} + تسویه شده + {% else %} + بدهکار + {% endif %} +

+
+
+{% endblock %} \ No newline at end of file diff --git a/webUI/src/views/acc/salary/card.vue b/webUI/src/views/acc/salary/card.vue index 32a5ebf..204b02e 100755 --- a/webUI/src/views/acc/salary/card.vue +++ b/webUI/src/views/acc/salary/card.vue @@ -1,65 +1,147 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/webUI/src/views/acc/salary/list.vue b/webUI/src/views/acc/salary/list.vue index 6c5990e..b209cd0 100755 --- a/webUI/src/views/acc/salary/list.vue +++ b/webUI/src/views/acc/salary/list.vue @@ -1,138 +1,299 @@