change request email perregion
parent
51d3962676
commit
dfb27457d2
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Mail\DocumentRegionNotification;
|
||||
use App\Models\Category;
|
||||
use App\Models\Document;
|
||||
use App\Models\Region;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class TestDoc extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'test:doc';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$docs = [];
|
||||
$categories = Category::all();
|
||||
foreach($categories as $category) {
|
||||
foreach($category->documents()->with(['variety'])->get() as $doc) {
|
||||
if ($doc->is_close_due != 0) {
|
||||
$docs[$doc->company->region->id][] = $doc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$regions = Region::all();
|
||||
foreach($regions as $region) {
|
||||
$rdocs = Document::with(['variety'])
|
||||
->whereHas('creator', function ($query) use ($region) {
|
||||
$query->where('region_id', $region->id);
|
||||
})
|
||||
->whereDate('due_date', '<=', now()->toDateString());
|
||||
|
||||
if ($rdocs->count() > 0) {
|
||||
foreach($rdocs->get() as $doc) {
|
||||
$docs[$region->id][] = $doc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($docs as $regionId => $doc) {
|
||||
$region = Region::find($regionId);
|
||||
if ($region != null && $region->email != '') {
|
||||
Mail::to($region->email)->send(new DocumentRegionNotification($doc));
|
||||
}
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DocumentRegionNotification extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
public $docs,
|
||||
)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*
|
||||
* @return \Illuminate\Mail\Mailables\Envelope
|
||||
*/
|
||||
public function envelope()
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Document Region Notification',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->markdown('emails.document.notification', [
|
||||
'documents' => $this->docs,
|
||||
'dueDocuments' => []
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Permission;
|
||||
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::table('regions', function ($table) {
|
||||
$table->string('email')->nullable();
|
||||
});
|
||||
|
||||
$permission = Permission::where('name', 'download-document')->first();
|
||||
if ($permission == null) {
|
||||
Permission::create([
|
||||
'name' => 'download-document',
|
||||
'label' => 'Download Documen'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('regions', function ($table) {
|
||||
$table->dropColumn('email');
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue