From 7e861c240d479fa81682b4b2a067ff83b4e4e629 Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Sun, 14 Jul 2024 22:45:22 +0330 Subject: [PATCH] some progress in pdf styles --- .../src/Controller/AdminController.php | 2 +- .../src/Controller/PersonsController.php | 3 +- hesabixCore/src/Service/Twig.php | 16 +++ hesabixCore/src/Service/pdfMGR.php | 15 ++- hesabixCore/templates/pdf/base.html.twig | 65 +++++++-- hesabixCore/templates/pdf/footer.html.twig | 34 +++++ .../templates/pdf/person_card.html.twig | 124 ++++++++++++++---- 7 files changed, 218 insertions(+), 41 deletions(-) create mode 100644 hesabixCore/src/Service/Twig.php create mode 100644 hesabixCore/templates/pdf/footer.html.twig diff --git a/hesabixCore/src/Controller/AdminController.php b/hesabixCore/src/Controller/AdminController.php index ef86e72..4bb2507 100644 --- a/hesabixCore/src/Controller/AdminController.php +++ b/hesabixCore/src/Controller/AdminController.php @@ -503,7 +503,7 @@ class AdminController extends AbstractController #[Route('/api/admin/logs/last', name: 'api_admin_logs_last')] public function api_admin_logs_last(Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse { - $logs = $entityManager->getRepository(\App\Entity\Log::class)->findBy([], ['id' => 'DESC'], 250); + $logs = $entityManager->getRepository(\App\Entity\Log::class)->findBy([], ['id' => 'ASC'], 250); $temps = []; foreach ($logs as $log) { $temp = []; diff --git a/hesabixCore/src/Controller/PersonsController.php b/hesabixCore/src/Controller/PersonsController.php index de61514..ee1c19c 100644 --- a/hesabixCore/src/Controller/PersonsController.php +++ b/hesabixCore/src/Controller/PersonsController.php @@ -683,7 +683,8 @@ class PersonsController extends AbstractController $this->renderView('pdf/person_card.html.twig', [ 'page_title' => 'کارت حساب' . ' ' . $person->getNikename(), 'bid' => $acc['bid'], - 'items' => $transactions + 'items' => $transactions, + 'person' => $person ]) ); return $this->json(['id' => $pid]); diff --git a/hesabixCore/src/Service/Twig.php b/hesabixCore/src/Service/Twig.php new file mode 100644 index 0000000..49bad3b --- /dev/null +++ b/hesabixCore/src/Service/Twig.php @@ -0,0 +1,16 @@ +getProjectDir()); + + parent::__construct($loader); + } +} \ No newline at end of file diff --git a/hesabixCore/src/Service/pdfMGR.php b/hesabixCore/src/Service/pdfMGR.php index 99ae09f..4a3479a 100644 --- a/hesabixCore/src/Service/pdfMGR.php +++ b/hesabixCore/src/Service/pdfMGR.php @@ -3,21 +3,27 @@ namespace App\Service; use App\Entity\PrinterQueue; -use Dompdf\Dompdf; -use Symfony\Component\HttpFoundation\Response; +use App\Service\Twig; + use Twig\Environment; class pdfMGR { private $twig; - public function __construct(Environment $twig) + public function __construct(Twig $twig) { $this->twig = $twig; } public function streamTwig2PDF(PrinterQueue $printQueue,$configs = []){ + // Load Twig File + $template = $this->twig->load('pdf/footer.html.twig'); + // Render HTML + $footer = $template->render([ + + ]); $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; $mpdf = new \Mpdf\Mpdf([ @@ -37,9 +43,10 @@ class pdfMGR 'tempDir' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mpdf', 'autoArabic' => true, ]); - $mpdf->AddFontDirectory(__DIR__ . '../Fonts'); + $mpdf->SetHTMLFooter($footer); $mpdf->WriteHTML($printQueue->getView()); + $mpdf->SetAutoPageBreak(true); $mpdf->Output(); } diff --git a/hesabixCore/templates/pdf/base.html.twig b/hesabixCore/templates/pdf/base.html.twig index 0e2a6c3..04c8ee0 100644 --- a/hesabixCore/templates/pdf/base.html.twig +++ b/hesabixCore/templates/pdf/base.html.twig @@ -1,12 +1,57 @@ - + + + + + - - چاپ + + + - -

{{bid.name}}

-

{{ page_title }}

-
- {% block body %}{% endblock %} -
- \ No newline at end of file + +
+
+
+ + + + + + + + +
+ + +

{{bid.name}}

+
{{ page_title }}
+
+

+ تاریخ: + {{ Jdate.GetTodayDate() }} +

+
+
+ {% block body %}{% endblock %} +
+ + + +
+ diff --git a/hesabixCore/templates/pdf/footer.html.twig b/hesabixCore/templates/pdf/footer.html.twig new file mode 100644 index 0000000..9f191c6 --- /dev/null +++ b/hesabixCore/templates/pdf/footer.html.twig @@ -0,0 +1,34 @@ + + + + + + + +
+
+
+ + + + + + + + +
+ حسابداری آنلاین حسابیکس + + صفحه: + {PAGENO} + از + {nbpg} + + Hesabix.ir +
+
+
+ + + + diff --git a/hesabixCore/templates/pdf/person_card.html.twig b/hesabixCore/templates/pdf/person_card.html.twig index 1b834ac..7ea88ba 100644 --- a/hesabixCore/templates/pdf/person_card.html.twig +++ b/hesabixCore/templates/pdf/person_card.html.twig @@ -1,29 +1,103 @@ {% extends "pdf/base.html.twig" %} {% block body %} - - - - - - - - - - - - - {% for item in items %} - - - - - - - - - - - {% endfor %} - +
+
+ مشخصات طرف حساب +
+
 
ردیفکد تراکنشتاریختوضیحاتتفضیلبدهکاربستانکارسال مالی
{{ loop.index }}{{ item.id }}{{ item.doc.date }}{{ item.des }}{{ item.ref.name }}{{ item.bd | number_format }}{{ item.bs | number_format }}{{ item.year.label }}
+ + + + + + + + + + + + + + +
+

+ نام: + + {{ person.nikename }} +

+
+

+ + شناسه ملی: + + {{ person.shenasemeli }} +

+
+

+ شماره ثبت: + + {{ person.sabt }} +

+
+

+ شماره اقتصادی: + + {{ person.codeeghtesadi }} +

+
+

+ تلفن / نمابر: + {{ person.tel }} +

+
+

+ موبایل: + {{ person.mobile }} +

+
+

+ کد پستی: + {{ person.postalcode }} +

+
+

+ آدرس: + + استان + {{ person.ostan }}، شهر + {{ person.shahr }}، + {{ person.address }} +

+
+
+
+ + + + + + + + + + + + {% for item in items %} + + + + + + + + + + +{% endfor %} + +
ردیفتاریختوضیحاتتفضیلبدهکاربستانکارسال مالی
{{ loop.index }}{{ item.doc.date }}{{ item.des }}{{ item.ref.name }}{{ item.bd | number_format }}{{ item.bs | number_format }}{{ item.year.label }}
+ +
+ {% endblock %} \ No newline at end of file