done
parent
112955a782
commit
02f5286ede
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Mail\DocumentNotification;
|
||||
use App\Models\DocumentReminder as ModelsDocumentReminder;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class DocumentReminder implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$now = now();
|
||||
$documentIds = ModelsDocumentReminder::whereDate('date', $now)->pluck('document_id');
|
||||
$documents = Document::whereIn('id', $documentIds)->get();
|
||||
|
||||
foreach ($documents as $doc) {
|
||||
Mail::to($doc->email)->queue(new DocumentNotification($doc));
|
||||
if ($doc->shares()->count() > 0) {
|
||||
foreach ($doc->shares as $share) {
|
||||
Mail::to($share->share_to)->queue(new DocumentNotification($doc));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Document;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DocumentNotification extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
public Document $doc
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
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)
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Document;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DocumentShare extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
public Document $doc
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->markdown('emails.document.share', [
|
||||
'no_doc' => $this->doc->no_doc,
|
||||
'end_date' => $this->doc->end_date->format('d-m-Y'),
|
||||
'url' => route('docs.show', $this->doc)
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
}
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
@component('mail::message')
|
||||
# Dokumen Notifikasi
|
||||
|
||||
Reminder, untuk dokument <b>{{ $no_doc }}</b> akan berakhir pada {{ $end_date }} mohon untuk segera melakukan tindakan
|
||||
|
||||
@component('mail::button', ['url' => $url])
|
||||
Detail Dokumen
|
||||
@endcomponent
|
||||
|
||||
Terima kasih , <br>
|
||||
{{ config('app.name') }}
|
||||
@endcomponent
|
@ -0,0 +1,12 @@
|
||||
@component('mail::message')
|
||||
# Berbagi Dokumen
|
||||
|
||||
Saya membagikan dokumen dengan anda, untuk dokument <b>{{ $no_doc }}</b> akan berakhir pada {{ $end_date }} mohon untuk segera melakukan tindakan
|
||||
|
||||
@component('mail::button', ['url' => $url])
|
||||
Detail Dokumen
|
||||
@endcomponent
|
||||
|
||||
Terima kasih , <br>
|
||||
{{ config('app.name') }}
|
||||
@endcomponent
|
Loading…
Reference in New Issue