From 2f9f7c020d0c2c5e81f4a1e2d5a8b02c14516604 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 16 Sep 2026 08:49:32 +0530 Subject: [PATCH 1/4] Added send daily task report command file --- app/Console/Commands/SendDailyTaskReport.php | 229 +++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 app/Console/Commands/SendDailyTaskReport.php diff --git a/app/Console/Commands/SendDailyTaskReport.php b/app/Console/Commands/SendDailyTaskReport.php new file mode 100644 index 0000000..5c02312 --- /dev/null +++ b/app/Console/Commands/SendDailyTaskReport.php @@ -0,0 +1,229 @@ +argument('schedule_type'); + + $mailRules = AlertMailRule::where('module', 'DailyTaskReport') + ->where('rule_name', 'DailyTaskReportMail') + ->where('schedule_type', $scheduleType) + ->get(); + + if (!$mailRules) { + $this->error('Daily Task Report mail rule not found.'); + return self::FAILURE; + } + + // Get all PDF files + $pdfFiles = collect(Storage::disk('local')->files($directory)) + ->filter(function ($file) { + return strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'pdf'; + }) + ->values(); + + if ($pdfFiles->isEmpty()) { + $this->info('No PDF files found.'); + return self::SUCCESS; + } + + $parser = new Parser(); + $attachments = []; + $rows = []; + $sno = 1; + + $attachments = []; + + foreach ($pdfFiles as $file) { + $fullPath = Storage::disk('local')->path($file); + $filename = basename($file, '.pdf'); + + $attachments[] = [ + 'path' => Storage::disk('local')->path($file), + 'name' => basename($file), + ]; + + // Read PDF content for name/task/status + try { + $pdf = $parser->parseFile($fullPath); + $text = $pdf->getText(); + + \Log::info('PDF RAW TEXT: ' . $text); + } catch (\Throwable $e) { + $text = ''; + } + + $rows[] = [ + 'sno' => $sno++, + 'name' => $this->extractNameFromFilename($filename), + 'project-name' => $this->extractProjectName($text), + 'task' => $this->extractTaskTitle($text), + 'status' => $this->extractStatus($text), + 'completed' => $this->extractPercentComplete($text), + ]; + + $this->info('Attached: ' . basename($file)); + } + + $toEmails = []; + $ccEmails = []; + + foreach ($mailRules as $mailRule) { + + // TO email + if (!empty($mailRule->email)) { + $toEmails[] = trim($mailRule->email); + } + + // CC emails + if (!empty($mailRule->cc_emails)) { + + $ccEmails = array_merge( + $ccEmails, + array_map( + 'trim', + explode(',', $mailRule->cc_emails) + ) + ); + } + } + + // Remove duplicate emails + $toEmails = array_values(array_unique(array_filter($toEmails))); + $ccEmails = array_values(array_unique(array_filter($ccEmails))); + + + try { + + $mail = Mail::to($toEmails); + + if (!empty($ccEmails)) { + $mail->cc($ccEmails); + } + + $mail->send( + new DailyTaskReportMail($attachments, $rows) + ); + + foreach ($pdfFiles as $file) { + + if (Storage::disk('local')->exists($file)) { + Storage::disk('local')->delete($file); + + $this->info('Deleted: ' . basename($file)); + } + } + + $this->info( + $pdfFiles->count() . ' PDF(s) mailed and deleted successfully.' + ); + + return self::SUCCESS; + + } catch (\Throwable $e) { + + // Mail failed -> DO NOT delete PDFs + $this->error('Mail sending failed.'); + $this->error($e->getMessage()); + + return self::FAILURE; + } + } + + protected function extractNameFromFilename(string $filename): string + { + $name = preg_replace('/[-_]?task.*$/i', '', $filename); + $name = preg_replace('/[-_]+/', ' ', $name); + $name = preg_replace('/(?knownStatuses as $status) { + $pos = stripos($title, $status); + if ($pos != false) { + $title = trim(substr($title, 0, $pos)); + break; + } + } + return $title; + } + return 'Unknown task'; + } + + protected function extractStatus(string $text): string + { + // Replace non-breaking spaces (common in OpenProject PDF exports) with regular spaces + $normalized = str_replace("\xC2\xA0", ' ', $text); + $normalized = preg_replace('/\s+/', ' ', $normalized); + + foreach ($this->knownStatuses as $status) { + if (stripos($normalized, $status) !== false) { + return ucwords($status); + } + } + return 'Unknown'; + } + + protected function extractPercentComplete(string $text): string + { + $normalized = str_replace("\xC2\xA0", ' ', $text); + $normalized = preg_replace('/[ \t]+/', ' ', $normalized); + + if (preg_match('/%\s*Complete\s*([0-9]{1,3}\s*%)/i', $normalized, $matches)) { + return trim(str_replace(' ', '', $matches[1])); + } + + return '0%'; + } + + 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)) { + return trim($matches[1]); + } + + return 'Unknown project'; + } + +} From 1cf677c190ecdbab7bb3b6526f2e573ff8e94eb9 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 16 Sep 2026 08:50:28 +0530 Subject: [PATCH 2/4] Added daily task report mail page --- app/Mail/DailyTaskReportMail.php | 69 ++++++ .../views/mail/daily-task-report.blade.php | 225 ++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 app/Mail/DailyTaskReportMail.php create mode 100644 resources/views/mail/daily-task-report.blade.php diff --git a/app/Mail/DailyTaskReportMail.php b/app/Mail/DailyTaskReportMail.php new file mode 100644 index 0000000..3328deb --- /dev/null +++ b/app/Mail/DailyTaskReportMail.php @@ -0,0 +1,69 @@ +pdfAttachments = $pdfAttachments; + $this->rows = $rows; + } + /** + * Get the message envelope. + */ + public function envelope(): Envelope + { + return new Envelope( + subject: 'Daily Task Report Mail', + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + view: 'mail.daily-task-report', + with: [ + 'rows' => $this->rows, + ], + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return collect($this->pdfAttachments) + ->map(function ($attachment) { + + return Attachment::fromPath($attachment['path']) + ->as($attachment['name']) + ->withMime('application/pdf'); + + }) + ->toArray(); + } +} diff --git a/resources/views/mail/daily-task-report.blade.php b/resources/views/mail/daily-task-report.blade.php new file mode 100644 index 0000000..30ac7ef --- /dev/null +++ b/resources/views/mail/daily-task-report.blade.php @@ -0,0 +1,225 @@ + + + + + Daily Task Report + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ CRI Digital Manufacturing IIOT +
+ +
+ Daily Task Report - {{ now()->format('d M Y') }} +
+ +
+ +

+ Dear Sir, +

+ +

+ Please find attached the Daily Task Report + for your review and reference. +

+ +

+ The attached report contains the task details recorded + for the day. Kindly review the report and take any + necessary follow-up actions. +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + @forelse($rows as $row) + + + + + + + + + + + + + + + + + + @empty + + + + + + @endforelse + + + +
+ S.No + + Name + + Project Name + + Task + + Status + + Completed(%) +
+ {{ $row['sno'] }} + + {{ $row['name'] }} + + {{ $row['project-name'] }} + + {{ $row['task'] }} + + {{ $row['status'] }} + + {{ $row['completed'] }} +
+ No tasks found. +
+ +
+ + + + + + + +
+ +
+ 📎 Report Attached +
+ +
+ The daily task report PDF is attached to this email. + Please download and review the attached document. +
+ +
+ +
+ +

+ Thank you +

+ +
+
+
+ +
+ CRI Digital Manufacturing IIOT Solutions +
+ +
+ This is an automated email. Please do not reply directly + to this message. +
+ +
+ © {{ date('Y') }} CRI Digital Manufacturing IIOT. All rights reserved. +
+ +
+ +
+ + + From f78c2262e3eef9c0c74a565f21368104ba1d86a6 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 16 Sep 2026 08:51:13 +0530 Subject: [PATCH 3/4] Added task report option in alert mail page --- app/Filament/Resources/AlertMailRuleResource.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Filament/Resources/AlertMailRuleResource.php b/app/Filament/Resources/AlertMailRuleResource.php index a88096a..49223de 100644 --- a/app/Filament/Resources/AlertMailRuleResource.php +++ b/app/Filament/Resources/AlertMailRuleResource.php @@ -86,6 +86,7 @@ class AlertMailRuleResource extends Resource 'LaserStopReport' => 'LaserStopReport', 'PanelBoxAlert' => 'PanelBoxAlert', 'PanelBoxReport' => 'PanelBoxReport', + 'DailyTaskReport' => 'DailyTaskReport', ]), Forms\Components\Select::make('rule_name') ->label('Rule Name') @@ -104,7 +105,8 @@ class AlertMailRuleResource extends Resource 'LaserStopAlertMail' => 'Laser Stop Alert Mail', 'LaserStopMail' => 'Laser Stop Report Mail', 'PanelBoxAlertMail' => 'Panel Box Alert Mail', - 'PanelBoxNotOkReportMail' => 'Panel Box Not Ok Report Mail' + 'PanelBoxNotOkReportMail' => 'Panel Box Not Ok Report Mail', + 'DailyTaskReportMail' => 'Daily Task Report Mail', ]) ->required(), Forms\Components\TextInput::make('email') From 86c3bda2fc4c01eaaf9e64e5510478799f8ba96e Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 16 Sep 2026 08:52:55 +0530 Subject: [PATCH 4/4] changed report date in task report mail --- resources/views/mail/daily-task-report.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/mail/daily-task-report.blade.php b/resources/views/mail/daily-task-report.blade.php index 30ac7ef..2f48026 100644 --- a/resources/views/mail/daily-task-report.blade.php +++ b/resources/views/mail/daily-task-report.blade.php @@ -24,7 +24,7 @@
- Daily Task Report - {{ now()->format('d M Y') }} + Daily Task Report - {{ now()->subDay()->format('d M Y') }}