From 329af67e80a704dcd2bea405f9d6ec3083ea5430 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 18 Sep 2026 11:11:35 +0530 Subject: [PATCH] chnaged logic for multi pdf upload in upload daily task report --- app/Console/Commands/SendDailyTaskReport.php | 30 ++++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/SendDailyTaskReport.php b/app/Console/Commands/SendDailyTaskReport.php index 5c02312..10549bd 100644 --- a/app/Console/Commands/SendDailyTaskReport.php +++ b/app/Console/Commands/SendDailyTaskReport.php @@ -90,7 +90,8 @@ class SendDailyTaskReport extends Command $rows[] = [ 'sno' => $sno++, 'name' => $this->extractNameFromFilename($filename), - 'project-name' => $this->extractProjectName($text), + // 'project-name' => $this->extractProjectName($text), + 'project-name' => $pdf ? $this->extractProjectName($pdf) : 'Unknown project', 'task' => $this->extractTaskTitle($text), 'status' => $this->extractStatus($text), 'completed' => $this->extractPercentComplete($text), @@ -214,12 +215,29 @@ class SendDailyTaskReport extends Command return '0%'; } - protected function extractProjectName(string $text): string - { - $normalized = str_replace("\xC2\xA0", ' ', $text); + // protected function extractProjectName(string $text): string + // { + // $normalized = str_replace("\xC2\xA0", ' ', $text); - // Footer pattern: \t at the very end of the PDF text - if (preg_match('/\d{1,2}-\d{2}-\d{4}\s*\t\s*(.+?)\s*$/s', $normalized, $matches)) { + // // Footer pattern: \t at the very end of the PDF text + // if (preg_match('/\d{1,2}-\d{2}-\d{4}\s*\t\s*(.+?)\s*$/s', $normalized, $matches)) { + // return trim($matches[1]); + // } + + // return 'Unknown project'; + // } + + protected function extractProjectName($pdf): string + { + $pages = $pdf->getPages(); + + if (empty($pages)) { + return 'Unknown project'; + } + + $firstPageText = str_replace("\xC2\xA0", ' ', $pages[0]->getText()); + + if (preg_match('/\d{1,2}-\d{2}-\d{4}\s*\t\s*(.+?)\s*$/s', $firstPageText, $matches)) { return trim($matches[1]); }