mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 12:34:24 +00:00
100 lines
3.7 KiB
PHP
100 lines
3.7 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||
use App\Models\Document;
|
||
use App\Models\State;
|
||
use App\Http\Helpers\General;
|
||
|
||
use App\Models\Transaction;
|
||
use App\Models\User;
|
||
use Carbon\Carbon;
|
||
use Illuminate\Console\Command;
|
||
use App\Classes\Jobs\FetchContainersStatusUpdateFromVTPortalJob;
|
||
use App\Classes\Jobs\FetchDeliveryListFromVTPortalJob;
|
||
use App\Classes\Jobs\FetchLoadedContainersFromVTPortalJob;
|
||
use App\Classes\Jobs\FetchPackingListFromVTPortalJob;
|
||
use App\Classes\Jobs\FetchWarehouseReceiveListFromVTPortalJob;
|
||
use Illuminate\Support\Facades\Auth;
|
||
use Illuminate\Support\Facades\File;
|
||
use Illuminate\Support\Facades\Mail;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use ZipArchive;
|
||
|
||
class EmailDoToVTCommand extends Command
|
||
{
|
||
/**
|
||
* The name and signature of the console command.
|
||
*
|
||
* @var string
|
||
*/
|
||
|
||
protected $signature = 'mail:EmailDoToVTCommand';
|
||
|
||
/**
|
||
* The console command description.
|
||
*
|
||
* @var string
|
||
*/
|
||
protected $description = 'Send do to vt nation';
|
||
|
||
/**
|
||
* Create a new command instance.
|
||
*
|
||
* @return void
|
||
*/
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
}
|
||
|
||
/**
|
||
* Execute the console command.
|
||
*
|
||
* @return mixed
|
||
*/
|
||
public function handle()
|
||
{
|
||
|
||
Auth::login(User::findOrFail(1));
|
||
$zip_file = 'do_from_11_nov_to_23_nov.zip';
|
||
$attachment = storage_path().'/'.$zip_file;
|
||
$zip = new ZipArchive();
|
||
if ($zip->open($attachment, ZIPARCHIVE::CREATE)) {
|
||
$bookings = \App\Models\Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', '>=', Carbon::parse('12-11-2021'))->whereDate('updated_at', '<=', Carbon::parse('23-11-2021'))
|
||
->whereHas('transactions', function ($query){
|
||
return $query->where('type', TransactionType::BILL)->where('issuer', 2);
|
||
})->get();
|
||
|
||
if(!$bookings){ return; }
|
||
|
||
foreach ($bookings as $booking) {
|
||
$file = $booking->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()->files()->first();
|
||
if(file_exists(Storage::disk('documents')->path($file->file->file_info->original->file))){
|
||
$zip->addFile(Storage::disk('documents')->path($file->file->file_info->original->file), $booking->created_at->format('d_m_Y').'_'.$booking->marking.'.pdf');
|
||
}
|
||
}
|
||
|
||
$zip->close();
|
||
|
||
Mail::raw( "Attention to VT Admin team:\r\n\r\nKindly refer to the attachment for our DAILY DO COMPILATION from 12-11-2021 to 23-11-2021.\r\n\r\n**This is an automatically generated email – please do not reply to it. If you have any queries kindly contact our admin team through Wechat.\r\n\r\n\r\nCIEF WORLDWIDE SDN BHD", function($message) use ($attachment){
|
||
$message->from('exchange@cief-malaysia.com');
|
||
$message->to(['uldvstar@gmail.com']);
|
||
// $message->to(['vtnation16@gmail.com', 'vtnation@gmail.com', 'atvantic04@gmail.com', 'vtnation2@gmail.com']);
|
||
// $message->cc(['shafiqa_sukeri@cief-malaysia.com', 'frontendcief@gmail.com', 'pm@cief-malaysia.com', 'hasan@cief-malaysia.com', 'shipping_admin@cief-malaysia.com', 'hasanakbar27@gmail.com', 'pmwong2019@gmail.com']);
|
||
$message->subject('CIEF DO COMPILATION from 12-11-2021 to 23-11-2021');
|
||
|
||
$message->attach($attachment);
|
||
});
|
||
|
||
File::delete($attachment);
|
||
|
||
echo 'success';
|
||
|
||
}
|
||
}
|
||
}
|