some progress in pdf styles

This commit is contained in:
babak alizadeh 2024-07-14 22:45:22 +03:30
parent 6e7c4af78d
commit 7e861c240d
7 changed files with 218 additions and 41 deletions

View file

@ -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 = [];

View file

@ -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]);

View file

@ -0,0 +1,16 @@
<?php
// src/Service/Twig.php
namespace App\Service;
use Symfony\Component\HttpKernel\KernelInterface;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
class Twig extends Environment {
public function __construct(KernelInterface $kernel) {
$loader = new FilesystemLoader("templates", $kernel->getProjectDir());
parent::__construct($loader);
}
}

View file

@ -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();
}

View file

@ -1,12 +1,57 @@
<html dir="rtl">
<!DOCTYPE html>
<html lang="fa" direction="rtl"></html>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>چاپ</title>
<style>
.center {
text-align: center;
}
.text-white {
color: white;
}
.stimol td,
.stimol th {
border: 1px solid black;
}
.item {
height: 40px;
}
</style>
</head>
<body>
<h3 style="text-align: center; margin-top: 0px; padding-top: 0px;">{{bid.name}}</h3>
<p style="text-align: center;">{{ page_title }}</p>
<div style="width: 100%">
<body style="direction:rtl; width:100%">
<div class="block-content pt-1 pb-3 d-none d-sm-block">
<div class="c-print container-xl">
<div class="tg-wrap" style="width:100%; border:1px solid black;border-radius: 8px;">
<table class="rounded" style="width:100%;">
<thead>
<tr>
<td style="width:20%">
<img src="{{ "/api/avatar/get/file/" ~ bid.avatar}}" width="65"/>
</td>
<td style="width:60%; text-align:center">
<h3 class="">{{bid.name}}</h3>
<h5>{{ page_title }}</h5>
</td>
<td style="width:20%; text-align:center">
<p class="">
تاریخ:
{{ Jdate.GetTodayDate() }}
</p>
</td>
</tr>
</thead>
</table>
</div>
{% block body %}{% endblock %}
</div>
</div>
</body>
</body></body></div></body></html>

View file

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="fa" direction="rtl">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<head>
</head>
<body style="direction:rtl; width:100%;margin-bottom:20px;">
<div class="block-content pt-1 pb-3 d-none d-sm-block">
<div class="c-print container-xl">
<div class="tg-wrap" style="width:100%; border:1px solid black;border-radius: 8px;">
<table class="rounded" style="width:100%;">
<thead>
<tr>
<td style="width:30%;text-align:center;">
حسابداری آنلاین حسابیکس
</td>
<td style="width:40%; text-align:center">
صفحه:
{PAGENO}
از
{nbpg}
</td>
<td style="width:30%;text-align:center;">
Hesabix.ir
</td>
</tr>
</thead>
</table>
</div>
</div>
</body>
</body>
</html>

View file

@ -1,29 +1,103 @@
{% extends "pdf/base.html.twig" %}
{% block body %}
<table class="table mt-0 pt-0" style="border:2px solid black"><caption>&nbsp;</caption>
<div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;">
<div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray">
<b style="color:white;">مشخصات طرف حساب</b>
</div>
<table style="width:100%;">
<tbody>
<tr style="text-align: center; background-color: grey; color: white">
<tr style="text-align:center;">
<td class="">
<p>
<b>نام:
</b>
{{ person.nikename }}
</p>
</td>
<td class="center">
<p>
<b>
شناسه ملی:
</b>
{{ person.shenasemeli }}
</p>
</td>
<td class="center">
<p>
<b>شماره ثبت:
</b>
{{ person.sabt }}
</p>
</td>
<td class="center">
<p>
<b>شماره اقتصادی:
</b>
{{ person.codeeghtesadi }}
</p>
</td>
<td class="center">
<p>
<b>تلفن / نمابر:</b>
{{ person.tel }}
</p>
</td>
</tr>
<tr>
<td class="" colspan="1">
<p>
<b>موبایل:</b>
{{ person.mobile }}
</p>
</td>
<td class="" colspan="1">
<p>
<b>کد پستی:</b>
{{ person.postalcode }}
</p>
</td>
<td class="" colspan="3">
<p>
<b>آدرس:
</b>
استان
{{ person.ostan }}، شهر
{{ person.shahr }}،
{{ person.address }}
</p>
</td>
</tr>
</tbody>
</table>
</div>
<div style="width:100%;margin-top:5px;text-align:center;">
<table style="width:100%;">
<tbody>
<tr style="text-align: center; background-color: grey; text-color: white">
<td style="width: 35px;">ردیف</td>
<td style="border:1px solid black">کد تراکنش</td>
<td style="border:1px solid black">تاریخ</td>
<td style="border:1px solid black">توضیحات</td>
<td style="border:1px solid black">تفضیل</td>
<td style="border:1px solid black">بدهکار</td>
<td style="border:1px solid black">بستانکار</td>
<td style="border:1px solid black">سال مالی</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>
{% for item in items %}
<tr style="border:1px solid black" {% if loop.index is even%}class="bg-dark text-light"{% endif%}>
<td style="border:1px solid black">{{ loop.index }}</td>
<td style="border:1px solid black">{{ item.id }}</td>
<td style="border:1px solid black">{{ item.doc.date }}</td>
<td style="border:1px solid black">{{ item.des }}</td>
<td style="border:1px solid black">{{ item.ref.name }}</td>
<td style="border:1px solid black">{{ item.bd | number_format }}</td>
<td style="border:1px solid black">{{ item.bs | number_format }}</td>
<td style="border:1px solid black">{{ item.year.label }}</td>
</tr>
{% endfor %}
</tbody>
<tr class="stimol">
<td class="center item">{{ loop.index }}</td>
<td class="center item">{{ item.doc.date }}</td>
<td class="center item">{{ item.des }}</td>
<td class="center item">{{ item.ref.name }}</td>
<td class="center item">{{ item.bd | number_format }}</td>
<td class="center item">{{ item.bs | number_format }}</td>
<td class="center item">{{ item.year.label }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}