Skip to content

Commit

Permalink
feat: support undelivered document status
Browse files Browse the repository at this point in the history
  • Loading branch information
keenthekeen committed Oct 23, 2023
1 parent 54e31e8 commit 7e132d6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
13 changes: 9 additions & 4 deletions app/Console/Commands/FetchEmailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion resources/js/Pages/DocumentIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<DocumentChartBarIcon v-if="item.tag === 'summary'" class="text-yellow-700 h-4 w-4 inline-block"/>
<DocumentCheckIcon v-if="item.status === 'APPROVED'" class="text-green-700 h-4 w-4 inline-block"/>
<ExclamationCircleIcon v-if="item.status === 'REJECTED'" class="text-amber-700 h-4 w-4 inline-block"/>
<PaperAirplaneIcon v-if="item.status === 'UNDELIVERED'" class="text-red-600 h-4 w-4 inline-block"/>
</span>
</td>
<td v-if="hasDepartment" class="px-2 py-2 md:px-4 md:py-3 text-sm">
Expand Down Expand Up @@ -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: {
Expand All @@ -89,6 +90,7 @@ export default {
DocumentCheckIcon,
DocumentTextIcon,
ExclamationCircleIcon,
PaperAirplaneIcon,
},
data() {
return {
Expand Down
7 changes: 3 additions & 4 deletions resources/js/Pages/DocumentShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<div v-if="item.status" class="px-3 py-4 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium text-gray-500">สถานะการพิจารณา (DocHub)</dt>
<dd class="mt-1 text-sm sm:mt-0 sm:col-span-2">{{
{APPROVED: "อนุมัติ", REJECTED: "ปฏิเสธ"}[item.status] ?? item.status
{APPROVED: "อนุมัติ", REJECTED: "ปฏิเสธ", UNDELIVERED: "ที่อยู่อีเมลผิด"}[item.status] ?? item.status
}}
</dd>
</div>
Expand All @@ -84,18 +84,17 @@
</div>
</div>

<div v-if="item.status === 'APPROVED'" class="bg-white shadow overflow-hidden sm:rounded-lg my-4">
<div v-if="item.has_approved" class="bg-white shadow overflow-hidden sm:rounded-lg my-4">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">
เอกสารได้รับการอนุมัติแล้ว
</h3>
</div>
<div class="border-t border-gray-200 p-4 sm:px-6">
<inertia-link v-if="item.has_approved" :href="route('documents.downloadApproved', {document: item.id})"
<inertia-link :href="route('documents.downloadApproved', {document: item.id})"
class="inline-block items-center px-4 py-2 mb-2 bg-blue-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-blue-700 active:bg-blue-900 focus:outline-none focus:border-blue-900 focus:ring focus:ring-blue-300 disabled:opacity-25 transition">
ดูเอกสาร
</inertia-link>
<p v-else class="text-gray-500">ไม่พบไฟล์</p>
</div>
</div>
<!-- File Naming Instruction -->
Expand Down

0 comments on commit 7e132d6

Please sign in to comment.