mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +00:00
74 lines
2.2 KiB
PHP
74 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console;
|
|
|
|
use App\Http\Controllers\InvoiceController;
|
|
use App\InvoiceStatuses;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use ZipArchive;
|
|
|
|
class Kernel extends ConsoleKernel
|
|
{
|
|
/**
|
|
* The Artisan commands provided by your application.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $commands = [
|
|
//
|
|
];
|
|
|
|
/**
|
|
* Define the application's command schedule.
|
|
*
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
|
* @return void
|
|
*/
|
|
protected function schedule(Schedule $schedule)
|
|
{
|
|
$schedule->call(function(){
|
|
$zipname = 'do_'.Carbon::today()->format('Y_m_d').'.zip';
|
|
$zip = new ZipArchive;
|
|
$zip->open($zipname, ZipArchive::CREATE);
|
|
$approvedInvoices = InvoiceStatuses::where('status', 'approve')->whereDate('created_at', Carbon::today())->distinct()->get(['invoice_id']);
|
|
$bookings = [];
|
|
foreach($approvedInvoices as $approved){
|
|
$bookings[] = $approved->invoice->booking->id;
|
|
}
|
|
foreach ($bookings as $id) {
|
|
$do = app(InvoiceController::class)->generateSupplierDo($id);
|
|
$zip->addFromString('do_'.Carbon::today()->format('Y_m_d').'_'.$id.'.pdf', $do->Output('do.pdf', 'S'));
|
|
}
|
|
|
|
$zip->close();
|
|
$attachment = public_path($zipname);
|
|
|
|
Mail::raw( 'DO for bookings po approved on '.Carbon::today()->format('d/m/Y'), function($message) use ($attachment){
|
|
$message->from('exchange@cief-malaysia.com');
|
|
$message->to('uldvstar@gmail.com');
|
|
$message->subject('DO for bookings on '.Carbon::today()->format('d/m/Y'));
|
|
|
|
$message->attach($attachment);
|
|
});
|
|
|
|
File::delete($zipname);
|
|
})->everyMinute();
|
|
}
|
|
|
|
/**
|
|
* Register the commands for the application.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function commands()
|
|
{
|
|
$this->load(__DIR__.'/Commands');
|
|
|
|
require base_path('routes/console.php');
|
|
}
|
|
}
|