From 5728be045a865bd3d95906098f2548ec24176704 Mon Sep 17 00:00:00 2001 From: ajikamaludin Date: Wed, 21 Sep 2022 19:34:11 +0700 Subject: [PATCH] last fixing --- app/Http/Controllers/DocumentController.php | 8 +++++++- app/Http/Controllers/GeneralController.php | 2 +- app/Jobs/DocumentReminder.php | 8 ++++++-- app/Mail/DocumentNotification.php | 5 ++--- app/Models/Document.php | 1 + .../2022_09_18_034528_create_documents_table.php | 4 ++-- resources/js/Pages/Dashboard.jsx | 2 +- resources/js/Pages/Document/Form.jsx | 15 +++++++++++++++ resources/js/Pages/Document/Index.jsx | 2 ++ .../views/emails/document/notification.blade.php | 9 ++++++++- 10 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php index 5376069..a3194a5 100644 --- a/app/Http/Controllers/DocumentController.php +++ b/app/Http/Controllers/DocumentController.php @@ -30,6 +30,7 @@ class DocumentController extends Controller $query->where('no_doc', 'like', '%'.$request->q.'%') ->orWhere('company_name', 'like', '%'.$request->q.'%') ->orWhere('pic_name', 'like', '%'.$request->q.'%') + ->orWhere('name', 'like', '%'.$request->q.'%') ->orWhere('email', 'like', '%'.$request->q.'%'); }); } @@ -77,13 +78,15 @@ class DocumentController extends Controller 'document' => 'required|file', 'note' => 'nullable', 'status' => 'required|numeric', - 'reminders' => 'nullable|array' + 'reminders' => 'nullable|array', + 'name' => 'required|string' ]); $lastDocs = Document::orderBy('created_at', 'desc')->first(); $lastDocs = $lastDocs ? $lastDocs : Document::make(['no' => 0]); $docs = Document::make([ 'no' => $lastDocs->no + 1, + 'name' => $request->name, 'no_doc' => $request->no_doc, 'company_name' => $request->company_name, 'first_person_name' => $request->first_person_name, @@ -141,12 +144,14 @@ class DocumentController extends Controller 'email' => 'required|email', 'document' => 'nullable|file', 'note' => 'nullable', + 'name' => 'required|string', 'status' => 'required|numeric', ]); $doc->fill([ 'no_doc' => $request->no_doc, + 'name' => $request->name, 'company_name' => $request->company_name, 'first_person_name' => $request->first_person_name, 'second_person_name' => $request->second_person_name, @@ -218,6 +223,7 @@ class DocumentController extends Controller foreach ($query->get() as $document) { $collections->add([ 'no dokumen' => $document->no_doc, + 'nama' => $document->name, 'jenis dokumen' => $document->type->name, 'nama perusahaan' => $document->company_name, 'nama pihak pertama' => $document->first_person_name, diff --git a/app/Http/Controllers/GeneralController.php b/app/Http/Controllers/GeneralController.php index 7e5435b..05d36b8 100644 --- a/app/Http/Controllers/GeneralController.php +++ b/app/Http/Controllers/GeneralController.php @@ -15,7 +15,7 @@ class GeneralController extends Controller 'count_update' => Document::where('status', Document::UPDATE)->count(), 'count_expired' => Document::where('status', Document::EXPIRED)->count(), 'count_total' => Document::count(), - 'events' => DocumentReminder::with('document')->get(), + 'events' => DocumentReminder::with('document.type')->get(), ]); } } diff --git a/app/Jobs/DocumentReminder.php b/app/Jobs/DocumentReminder.php index bd0ca58..ff60c52 100644 --- a/app/Jobs/DocumentReminder.php +++ b/app/Jobs/DocumentReminder.php @@ -9,8 +9,10 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; +use Illuminate\Log\Logger; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; class DocumentReminder implements ShouldQueue @@ -36,13 +38,15 @@ class DocumentReminder implements ShouldQueue { $now = now(); $documentIds = ModelsDocumentReminder::whereDate('date', $now)->pluck('document_id'); + Log::info("DocumentReminder:: Schedule Run $now , with $documentIds"); + $documents = Document::whereIn('id', $documentIds)->get(); foreach ($documents as $doc) { - Mail::to($doc->email)->queue(new DocumentNotification($doc)); + Mail::to($doc->email)->send(new DocumentNotification($doc)); if ($doc->shares()->count() > 0) { foreach ($doc->shares as $share) { - Mail::to($share->share_to)->queue(new DocumentNotification($doc)); + Mail::to($share->share_to)->send(new DocumentNotification($doc)); } } } diff --git a/app/Mail/DocumentNotification.php b/app/Mail/DocumentNotification.php index bbd6163..62e537d 100644 --- a/app/Mail/DocumentNotification.php +++ b/app/Mail/DocumentNotification.php @@ -30,9 +30,8 @@ class DocumentNotification extends Mailable public function build() { return $this->markdown('emails.document.notification', [ - 'no_doc' => $this->doc->no_doc, - 'end_date' => $this->doc->end_date->format('d-m-Y'), - 'url' => route('docs.show', $this->doc) + 'doc' => $this->doc->load(['type']), + 'url' => route('docs.show', $this->doc->id) ]); } } diff --git a/app/Models/Document.php b/app/Models/Document.php index 3162cf2..f0921fd 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -25,6 +25,7 @@ class Document extends Model 'document', 'status', 'user_id', + 'name', ]; protected $casts = [ diff --git a/database/migrations/2022_09_18_034528_create_documents_table.php b/database/migrations/2022_09_18_034528_create_documents_table.php index 1c03aa6..2f4109f 100644 --- a/database/migrations/2022_09_18_034528_create_documents_table.php +++ b/database/migrations/2022_09_18_034528_create_documents_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -16,6 +15,7 @@ return new class extends Migration Schema::create('documents', function (Blueprint $table) { $table->id(); $table->integer('no', false); + $table->string('name'); $table->string('no_doc'); $table->foreignId('type_doc_id')->constrained(); $table->string('company_name'); diff --git a/resources/js/Pages/Dashboard.jsx b/resources/js/Pages/Dashboard.jsx index cd53f3f..b95ec50 100644 --- a/resources/js/Pages/Dashboard.jsx +++ b/resources/js/Pages/Dashboard.jsx @@ -13,7 +13,7 @@ export default function Dashboard(props) { const calenderEvents = events.map(e => { return { - title: `${e.document.no_doc} - ${e.document.pic_name}`, + title: `${e.document.type.name} - ${e.document.name}`, date: e.date, id : e.id, url: route('docs.show', e.document) diff --git a/resources/js/Pages/Document/Form.jsx b/resources/js/Pages/Document/Form.jsx index 358bb1b..2318ba5 100644 --- a/resources/js/Pages/Document/Form.jsx +++ b/resources/js/Pages/Document/Form.jsx @@ -20,6 +20,7 @@ export default function FormDocument(props) { const [reminders, setReminders] = useState([]) const { data, setData, post, processing, errors, reset } = useForm({ no_doc: '', + name: '', email: '', type_doc_id: '1', department_id: '1', @@ -40,6 +41,7 @@ export default function FormDocument(props) { if(doc !== undefined) { setData({ no_doc: doc.no_doc, + name: doc.name, email: doc.email, type_doc_id: doc.type_doc_id, department_id: doc.department_id, @@ -130,6 +132,19 @@ export default function FormDocument(props) { +
+ + + +
sort('type_doc_id')}>Jenis + Nama Dokumen Nama PIC sort('end_date')}>Tanggal Berakhir sort('status')}>Status @@ -122,6 +123,7 @@ export default function Document(props) { {docs?.map((doc) => ( {doc.type.name} + {doc.name} {doc.pic_name} {formatDate(doc.end_date)} diff --git a/resources/views/emails/document/notification.blade.php b/resources/views/emails/document/notification.blade.php index 85f0740..14734af 100644 --- a/resources/views/emails/document/notification.blade.php +++ b/resources/views/emails/document/notification.blade.php @@ -1,7 +1,14 @@ @component('mail::message') # Dokumen Notifikasi -Reminder, untuk dokument {{ $no_doc }} akan berakhir pada {{ $end_date }} mohon untuk segera melakukan tindakan +Reminder, untuk dokumen dengan detail : + +No Dokumen : {{ $doc->no_doc }}
+Jenis Dokumen : {{ $doc->type->name }}
+Nama Dokumen : {{ $doc->name }}
+Nama Perusahaan : {{ $doc->company_name }}
+ +Akan berakhir pada {{ $doc->end_date->format('d-m-Y') }} mohon untuk segera melakukan tindakan @component('mail::button', ['url' => $url]) Detail Dokumen