diff --git a/app/Console/Commands/FetchEmailCommand.php b/app/Console/Commands/FetchEmailCommand.php index c734ef1..789991d 100644 --- a/app/Console/Commands/FetchEmailCommand.php +++ b/app/Console/Commands/FetchEmailCommand.php @@ -97,13 +97,15 @@ public function handle(): void } // Get document number - $this->line('- Processing message '.$headers['Subject']); + $subject = $headers['Subject']; + $this->line('- Processing message '.$subject); + $subject = str_replace(['Copy of ', 'สำเนา '], '', $subject); $list = []; - if (preg_match('/(?:สพจ|SMCU)(?:\.|\s){1,2}(\d+)-(25\d\d)\s.+/i', $headers['Subject'], $list, PREG_UNMATCHED_AS_NULL)) { + if (preg_match('/(?:สพจ|SMCU)(?:\.|\s|-){1,2}(\d+)(?:_|-)(25\d\d)(?:\s|-).+/i', $subject, $list, PREG_UNMATCHED_AS_NULL)) { $document = Document::where('number', $list[1])->where('year', $list[2])->first(); if ($document) { $this->line('- Found update of document '.$document->id.' ('.$document->number.'/'.$document->year.') '.$document->title); - if (str_starts_with($headers['Subject'], 'FINALIZED:')) { + if (str_starts_with($subject, 'FINALIZED:')) { // Skip if document is already approved if ($document->status == Document::STATUS_APPROVED and $document->approved_path and Carbon::parse($headers['Date']) ->isBefore($document->updated_at)) { @@ -125,9 +127,12 @@ public function handle(): void break; } } - } elseif (str_starts_with($headers['Subject'], 'REJECTED:') and $document->status != Document::STATUS_REJECTED) { + } elseif (str_starts_with($subject, 'REJECTED:') and $document->status != Document::STATUS_REJECTED) { $document->status = Document::STATUS_REJECTED; $document->save(); + } elseif (str_starts_with($subject, 'Email delivery failure:') and $document->status != Document::STATUS_UNDELIVERED) { + $document->status = Document::STATUS_UNDELIVERED; + $document->save(); } } } diff --git a/app/Models/Document.php b/app/Models/Document.php index 1ca153c..3371cf8 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -33,6 +33,7 @@ class Document extends Model { public const STATUS_APPROVED = 'APPROVED'; public const STATUS_REJECTED = 'REJECTED'; + public const STATUS_UNDELIVERED = 'UNDELIVERED'; // Email delivery failure public function department(): BelongsTo { return $this->belongsTo(Department::class)->select('id', 'name'); diff --git a/resources/js/Pages/DocumentIndex.vue b/resources/js/Pages/DocumentIndex.vue index f1edc08..d2efca8 100644 --- a/resources/js/Pages/DocumentIndex.vue +++ b/resources/js/Pages/DocumentIndex.vue @@ -42,6 +42,7 @@ + @@ -78,7 +79,7 @@ import AppLayout from '@/Layouts/AppLayout.vue' import SearchInput from "@/Components/SearchInput.vue"; import Pagination from "@/Components/Pagination.vue"; import {DocumentChartBarIcon, DocumentTextIcon} from '@heroicons/vue/20/solid'; -import {DocumentCheckIcon, ExclamationCircleIcon} from "@heroicons/vue/24/outline"; +import {DocumentCheckIcon, ExclamationCircleIcon, PaperAirplaneIcon} from "@heroicons/vue/24/outline"; export default { components: { @@ -89,6 +90,7 @@ export default { DocumentCheckIcon, DocumentTextIcon, ExclamationCircleIcon, + PaperAirplaneIcon, }, data() { return { diff --git a/resources/js/Pages/DocumentShow.vue b/resources/js/Pages/DocumentShow.vue index 039c2b4..c493ee9 100644 --- a/resources/js/Pages/DocumentShow.vue +++ b/resources/js/Pages/DocumentShow.vue @@ -60,7 +60,7 @@
สถานะการพิจารณา (DocHub)
{{ - {APPROVED: "อนุมัติ", REJECTED: "ปฏิเสธ"}[item.status] ?? item.status + {APPROVED: "อนุมัติ", REJECTED: "ปฏิเสธ", UNDELIVERED: "ที่อยู่อีเมลผิด"}[item.status] ?? item.status }}
@@ -84,18 +84,17 @@ -
+

เอกสารได้รับการอนุมัติแล้ว

- ดูเอกสาร -

ไม่พบไฟล์