add debug for find problems

This commit is contained in:
Hesabix 2025-03-09 19:14:52 +00:00
parent a3008ac02f
commit 8e536f239d
2 changed files with 35 additions and 24 deletions

View file

@ -23,14 +23,14 @@ class GeneralController extends AbstractController
$version = '0.0.1'; $version = '0.0.1';
$lastUpdateDate = '1399'; $lastUpdateDate = '1399';
$lastUpdateDes = ''; $lastUpdateDes = '';
$last = $entityManager->getRepository(ChangeReport::class)->findOneBy([], ['id' => 'DESC']); $last = $entityManager->getRepository(ChangeReport::class)->findOneBy([], ['id' => 'DESC']);
if ($last) { if ($last) {
$version = $last->getVersion(); $version = $last->getVersion();
$lastUpdateDate = $jdate->jdate('Y/n/d', $last->getDateSubmit()); $lastUpdateDate = $jdate->jdate('Y/n/d', $last->getDateSubmit());
$lastUpdateDes = $last->getBody(); $lastUpdateDes = $last->getBody();
} }
return $this->json([ return $this->json([
'version' => $version, 'version' => $version,
'lastUpdateDate' => $lastUpdateDate, 'lastUpdateDate' => $lastUpdateDate,
@ -53,10 +53,10 @@ class GeneralController extends AbstractController
} }
#[Route('/front/print/{id}', name: 'app_front_print')] #[Route('/front/print/{id}', name: 'app_front_print')]
public function app_front_print(Provider $provider, EntityManagerInterface $entityManager, pdfMGR $pdfMGR, string $id): Response public function app_front_print(Provider $provider, EntityManagerInterface $entityManager, PdfMGR $pdfMGR, string $id): Response
{ {
$print = $entityManager->getRepository(PrinterQueue::class)->findOneBy(['pid' => $id]); $print = $entityManager->getRepository(PrinterQueue::class)->findOneBy(['pid' => $id]);
if (!$print) { if (!$print) {
return new JsonResponse(['error' => 'Print job not found'], Response::HTTP_NOT_FOUND); return new JsonResponse(['error' => 'Print job not found'], Response::HTTP_NOT_FOUND);
} }
@ -65,12 +65,21 @@ class GeneralController extends AbstractController
return new JsonResponse(['error' => 'Empty print content'], Response::HTTP_BAD_REQUEST); return new JsonResponse(['error' => 'Empty print content'], Response::HTTP_BAD_REQUEST);
} }
// تولید PDF و گرفتن محتوا به صورت رشته
if ($print->isPosprint()) { if ($print->isPosprint()) {
$pdfMGR->streamTwig2PDFInvoiceType($print); $pdfContent = $pdfMGR->generateTwig2PDFInvoiceType($print); // متد جدید برای گرفتن محتوا
} else { } else {
$pdfMGR->streamTwig2PDF($print); $pdfContent = $pdfMGR->generateTwig2PDF($print); // متد جدید برای گرفتن محتوا
} }
return new Response('Print job completed', Response::HTTP_OK); // برگرداندن PDF به عنوان پاسخ
return new Response(
$pdfContent,
Response::HTTP_OK,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="Hesabix PrintOut.pdf"',
]
);
} }
} }

View file

@ -17,25 +17,24 @@ class pdfMGR
$this->twig = $twig; $this->twig = $twig;
} }
public function streamTwig2PDF(PrinterQueue $printQueue, $configs = []) public function generateTwig2PDF(PrinterQueue $printQueue, $configs = []): string
{ {
// Load Twig File
$template = $this->twig->load('pdf/footer.html.twig'); $template = $this->twig->load('pdf/footer.html.twig');
$footer = $template->render([]); $footer = $template->render([]);
$size = $printQueue->getPaperSize() ?: 'A4-L'; $size = $printQueue->getPaperSize() ?: 'A4-L';
$defaultConfig = (new ConfigVariables())->getDefaults(); $defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir']; $fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new FontVariables())->getDefaults(); $defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata']; $fontData = $defaultFontConfig['fontdata'];
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mpdf'; $tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mpdf';
if (!is_dir($tempDir)) { if (!is_dir($tempDir)) {
mkdir($tempDir, 0777, true); mkdir($tempDir, 0777, true);
} }
$mpdf = new Mpdf([ $mpdf = new Mpdf([
'mode' => 'utf-8', 'mode' => 'utf-8',
'format' => $size, 'format' => $size,
@ -52,31 +51,33 @@ class pdfMGR
'tempDir' => $tempDir, 'tempDir' => $tempDir,
'autoArabic' => true, 'autoArabic' => true,
]); ]);
if ($printQueue->isFooter()) { if ($printQueue->isFooter()) {
$mpdf->SetHTMLFooter($footer); $mpdf->SetHTMLFooter($footer);
} }
$htmlContent = $printQueue->getView() ?: '<p>محتوای PDF در دسترس نیست.</p>'; $htmlContent = $printQueue->getView() ?: '<p>محتوای PDF در دسترس نیست.</p>';
$mpdf->WriteHTML($htmlContent); $mpdf->WriteHTML($htmlContent);
$mpdf->SetAutoPageBreak(true); $mpdf->SetAutoPageBreak(true);
$mpdf->SetTitle('حسابیکس'); $mpdf->SetTitle('حسابیکس');
$mpdf->Output('Hesabix PrintOut.pdf', 'I');
// به جای Output مستقیم، محتوا رو برگردونید
return $mpdf->Output('', 'S'); // 'S' برای برگرداندن به صورت رشته
} }
public function streamTwig2PDFInvoiceType(PrinterQueue $printQueue, $configs = []) public function generateTwig2PDFInvoiceType(PrinterQueue $printQueue, $configs = []): string
{ {
$defaultConfig = (new ConfigVariables())->getDefaults(); $defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir']; $fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new FontVariables())->getDefaults(); $defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata']; $fontData = $defaultFontConfig['fontdata'];
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mpdf'; $tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mpdf';
if (!is_dir($tempDir)) { if (!is_dir($tempDir)) {
mkdir($tempDir, 0777, true); mkdir($tempDir, 0777, true);
} }
$mpdf = new Mpdf([ $mpdf = new Mpdf([
'mode' => 'utf-8', 'mode' => 'utf-8',
'format' => [80, 300], 'format' => [80, 300],
@ -95,17 +96,18 @@ class pdfMGR
'autoArabic' => true, 'autoArabic' => true,
'margin-collapse' => 'collapse|none' 'margin-collapse' => 'collapse|none'
]); ]);
$mpdf->AddPageByArray([ $mpdf->AddPageByArray([
'margin-left' => 0, 'margin-left' => 0,
'margin-right' => 0, 'margin-right' => 0,
'margin-top' => 0, 'margin-top' => 0,
'margin-bottom' => 0, 'margin-bottom' => 0,
]); ]);
$htmlContent = $printQueue->getView() ?: '<p>محتوای PDF در دسترس نیست.</p>'; $htmlContent = $printQueue->getView() ?: '<p>محتوای PDF در دسترس نیست.</p>';
$mpdf->WriteHTML($htmlContent); $mpdf->WriteHTML($htmlContent);
$mpdf->Output();
return $mpdf->Output('', 'S'); // 'S' برای برگرداندن به صورت رشته
} }
public function savePDF(PrinterQueue $printQueue, string $path) public function savePDF(PrinterQueue $printQueue, string $path)