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';
$lastUpdateDate = '1399';
$lastUpdateDes = '';
$last = $entityManager->getRepository(ChangeReport::class)->findOneBy([], ['id' => 'DESC']);
if ($last) {
$version = $last->getVersion();
$lastUpdateDate = $jdate->jdate('Y/n/d', $last->getDateSubmit());
$lastUpdateDes = $last->getBody();
}
return $this->json([
'version' => $version,
'lastUpdateDate' => $lastUpdateDate,
@ -53,10 +53,10 @@ class GeneralController extends AbstractController
}
#[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]);
if (!$print) {
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);
}
// تولید PDF و گرفتن محتوا به صورت رشته
if ($print->isPosprint()) {
$pdfMGR->streamTwig2PDFInvoiceType($print);
$pdfContent = $pdfMGR->generateTwig2PDFInvoiceType($print); // متد جدید برای گرفتن محتوا
} 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;
}
public function streamTwig2PDF(PrinterQueue $printQueue, $configs = [])
public function generateTwig2PDF(PrinterQueue $printQueue, $configs = []): string
{
// Load Twig File
$template = $this->twig->load('pdf/footer.html.twig');
$footer = $template->render([]);
$size = $printQueue->getPaperSize() ?: 'A4-L';
$defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mpdf';
if (!is_dir($tempDir)) {
mkdir($tempDir, 0777, true);
}
$mpdf = new Mpdf([
'mode' => 'utf-8',
'format' => $size,
@ -52,31 +51,33 @@ class pdfMGR
'tempDir' => $tempDir,
'autoArabic' => true,
]);
if ($printQueue->isFooter()) {
$mpdf->SetHTMLFooter($footer);
}
$htmlContent = $printQueue->getView() ?: '<p>محتوای PDF در دسترس نیست.</p>';
$mpdf->WriteHTML($htmlContent);
$mpdf->SetAutoPageBreak(true);
$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();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mpdf';
if (!is_dir($tempDir)) {
mkdir($tempDir, 0777, true);
}
$mpdf = new Mpdf([
'mode' => 'utf-8',
'format' => [80, 300],
@ -95,17 +96,18 @@ class pdfMGR
'autoArabic' => true,
'margin-collapse' => 'collapse|none'
]);
$mpdf->AddPageByArray([
'margin-left' => 0,
'margin-right' => 0,
'margin-top' => 0,
'margin-bottom' => 0,
]);
$htmlContent = $printQueue->getView() ?: '<p>محتوای PDF در دسترس نیست.</p>';
$mpdf->WriteHTML($htmlContent);
$mpdf->Output();
return $mpdf->Output('', 'S'); // 'S' برای برگرداندن به صورت رشته
}
public function savePDF(PrinterQueue $printQueue, string $path)