From ee3de886596e8543281ac8a7098257de926265aa Mon Sep 17 00:00:00 2001 From: Jagad R R Date: Wed, 5 Mar 2025 13:44:58 +0700 Subject: [PATCH] update revisi --- .env.example | 10 + app/Helpers/WhatsappHelper.php | 29 ++- ...ormEntertainmentPresentationController.php | 60 ++++- .../Forms/FormMeetingSeminarController.php | 49 +++- .../Controllers/Forms/FormOtherController.php | 60 ++++- .../Forms/FormUpCountryController.php | 59 ++++- .../Forms/FormVehicleController.php | 60 ++++- app/Http/Kernel.php | 1 + app/Http/Middleware/SessionTimeout.php | 31 +++ app/Mail/ExpenseApproved.php | 30 +-- app/Mail/ExpenseApproved2.php | 37 ++- app/Mail/ExpenseCreated.php | 37 ++- app/Mail/ExpenseRejected.php | 37 ++- app/Mail/FinalApprove.php | 37 ++- app/Services/BrevoService.php | 218 ++++++++++++++++++ config/session.php | 2 +- .../pages/report/generate_jurnal.blade.php | 12 +- resources/views/layouts/app.blade.php | 25 ++ 18 files changed, 673 insertions(+), 121 deletions(-) create mode 100644 app/Http/Middleware/SessionTimeout.php create mode 100644 app/Services/BrevoService.php diff --git a/.env.example b/.env.example index 68e96f6..8a8761a 100644 --- a/.env.example +++ b/.env.example @@ -68,3 +68,13 @@ VITE_APP_NAME="${APP_NAME}" NEXT_CLOUD_URL= NEXT_CLOUD_USERNAME= NEXT_CLOUD_PASSWORD= + +WABLAS_HOST= +WABLAS_TOKEN= + +STARTING_DATE='12' +CLOSING_DATE='10' + +BREVO_API_KEY= +BREVO_MAIL_FROM_ADDRESS= +BREVO_MAIL_FROM_NAME= diff --git a/app/Helpers/WhatsappHelper.php b/app/Helpers/WhatsappHelper.php index fa6e2d0..0661815 100644 --- a/app/Helpers/WhatsappHelper.php +++ b/app/Helpers/WhatsappHelper.php @@ -8,6 +8,15 @@ use Illuminate\Support\Str; class WhatsappHelper { + protected $wablasHost; + protected $wablasToken; + + public function __construct() + { + self::$wablasHost = env('WABLAS_HOST'); + self::$wablasToken = env('WABLAS_TOKEN'); + } + public static function approveExpense($phones, $expense_number, $url = null, $tanggal, $total, $name) { $client = new Client(); @@ -39,9 +48,9 @@ class WhatsappHelper try { // Send the request to the WABLAS API - $response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [ + $response = $client->post(self::$wablasHost . '/api/v2/send-message', [ 'headers' => [ - 'Authorization' => env('WABLAS_TOKEN'), + 'Authorization' => self::$wablasToken, 'Content-Type' => 'application/json' ], 'json' => [ @@ -88,9 +97,9 @@ class WhatsappHelper try { // Send the request to the WABLAS API - $response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [ + $response = $client->post(self::$wablasHost . '/api/v2/send-message', [ 'headers' => [ - 'Authorization' => env('WABLAS_TOKEN'), + 'Authorization' => self::$wablasToken, 'Content-Type' => 'application/json' ], 'json' => [ @@ -137,9 +146,9 @@ class WhatsappHelper try { // Send the request to the WABLAS API - $response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [ + $response = $client->post(self::$wablasHost . '/api/v2/send-message', [ 'headers' => [ - 'Authorization' => env('WABLAS_TOKEN'), + 'Authorization' => self::$wablasToken, 'Content-Type' => 'application/json' ], 'json' => [ @@ -186,9 +195,9 @@ class WhatsappHelper try { // Send the request to the WABLAS API - $response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [ + $response = $client->post(self::$wablasHost . '/api/v2/send-message', [ 'headers' => [ - 'Authorization' => env('WABLAS_TOKEN'), + 'Authorization' => self::$wablasToken, 'Content-Type' => 'application/json' ], 'json' => [ @@ -235,9 +244,9 @@ class WhatsappHelper try { // Send the request to the WABLAS API - $response = $client->post(env('WABLAS_HOST') . '/api/v2/send-message', [ + $response = $client->post(self::$wablasHost . '/api/v2/send-message', [ 'headers' => [ - 'Authorization' => env('WABLAS_TOKEN'), + 'Authorization' => self::$wablasToken, 'Content-Type' => 'application/json' ], 'json' => [ diff --git a/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php b/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php index a5a90d2..fa18f9d 100644 --- a/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php +++ b/app/Http/Controllers/Forms/FormEntertainmentPresentationController.php @@ -27,6 +27,7 @@ use App\Rules\FileType; use App\Helpers\BudgetHelper; use App\Helpers\NotificationHelper; use Illuminate\Support\Facades\Log; +use App\Services\BrevoService; class FormEntertainmentPresentationController extends Controller { @@ -232,15 +233,22 @@ class FormEntertainmentPresentationController extends Controller WhatsappHelper::newExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseCreated( + $mail = new ExpenseCreated( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseCreated($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -394,16 +402,23 @@ class FormEntertainmentPresentationController extends Controller $url = route('forms.entertainment.view', $form->id); WhatsappHelper::approveExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved( + $mail = new ExpenseApproved( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -478,16 +493,23 @@ class FormEntertainmentPresentationController extends Controller $url = route('forms.entertainment.view', $form->id); WhatsappHelper::approve2Expense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved2( + $mail = new ExpenseApproved2( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved2($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -571,15 +593,22 @@ class FormEntertainmentPresentationController extends Controller WhatsappHelper::finalApprove($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new FinalApprove( + $mail = new FinalApprove( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseFinalApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -629,15 +658,22 @@ class FormEntertainmentPresentationController extends Controller WhatsappHelper::rejectExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseRejected( + $mail = new ExpenseRejected( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseRejected($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; diff --git a/app/Http/Controllers/Forms/FormMeetingSeminarController.php b/app/Http/Controllers/Forms/FormMeetingSeminarController.php index 2b2e16f..f76b9bf 100644 --- a/app/Http/Controllers/Forms/FormMeetingSeminarController.php +++ b/app/Http/Controllers/Forms/FormMeetingSeminarController.php @@ -27,6 +27,7 @@ use App\Models\Admin; use App\Helpers\BudgetHelper; use App\Helpers\NotificationHelper; use Illuminate\Support\Facades\Log; +use App\Services\BrevoService; class FormMeetingSeminarController extends Controller { @@ -268,15 +269,22 @@ class FormMeetingSeminarController extends Controller WhatsappHelper::newExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseCreated( + $mail = new ExpenseCreated( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseCreated($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -476,16 +484,23 @@ class FormMeetingSeminarController extends Controller $url = route('forms.meeting.view', $form->id); WhatsappHelper::approveExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved( + $mail = new ExpenseApproved( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -560,16 +575,23 @@ class FormMeetingSeminarController extends Controller $url = route('forms.meeting.view', $form->id); WhatsappHelper::approve2Expense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved2( + $mail = new ExpenseApproved2( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved2($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -711,15 +733,22 @@ class FormMeetingSeminarController extends Controller WhatsappHelper::rejectExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseRejected( + $mail = new ExpenseRejected( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseRejected($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; diff --git a/app/Http/Controllers/Forms/FormOtherController.php b/app/Http/Controllers/Forms/FormOtherController.php index 32fc096..35d7e9b 100644 --- a/app/Http/Controllers/Forms/FormOtherController.php +++ b/app/Http/Controllers/Forms/FormOtherController.php @@ -24,6 +24,7 @@ use App\Helpers\BudgetHelper; use App\Helpers\NotificationHelper; use App\Models\Cabang; use Illuminate\Support\Facades\Log; +use App\Services\BrevoService; class FormOtherController extends Controller { @@ -226,15 +227,22 @@ class FormOtherController extends Controller WhatsappHelper::newExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseCreated( + $mail = new ExpenseCreated( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseCreated($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -383,16 +391,23 @@ class FormOtherController extends Controller $url = route('forms.other.view', $form->id); WhatsappHelper::approveExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved( + $mail = new ExpenseApproved( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -466,16 +481,23 @@ class FormOtherController extends Controller $url = route('forms.other.view', $form->id); WhatsappHelper::approve2Expense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved2( + $mail = new ExpenseApproved2( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved2($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -559,15 +581,22 @@ class FormOtherController extends Controller WhatsappHelper::finalApprove($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new FinalApprove( + $mail = new FinalApprove( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseFinalApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -617,15 +646,22 @@ class FormOtherController extends Controller WhatsappHelper::rejectExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseRejected( + $mail = new ExpenseRejected( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseRejected($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; diff --git a/app/Http/Controllers/Forms/FormUpCountryController.php b/app/Http/Controllers/Forms/FormUpCountryController.php index c439a23..f3f898d 100644 --- a/app/Http/Controllers/Forms/FormUpCountryController.php +++ b/app/Http/Controllers/Forms/FormUpCountryController.php @@ -27,6 +27,7 @@ use App\Models\Admin; use App\Helpers\BudgetHelper; use App\Helpers\NotificationHelper; use Illuminate\Support\Facades\Log; +use App\Services\BrevoService; class FormUpCountryController extends Controller { @@ -297,15 +298,22 @@ class FormUpCountryController extends Controller WhatsappHelper::newExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseCreated( + $mail = new ExpenseCreated( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseCreated($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -534,15 +542,23 @@ class FormUpCountryController extends Controller $url = route('forms.up-country.view', $form->id); WhatsappHelper::approveExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved( + $mail = new ExpenseApproved( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -616,16 +632,23 @@ class FormUpCountryController extends Controller $url = route('forms.up-country.view', $form->id); WhatsappHelper::approve2Expense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved2( + $mail = new ExpenseApproved2( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved2($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -709,15 +732,22 @@ class FormUpCountryController extends Controller WhatsappHelper::finalApprove($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new FinalApprove( + $mail = new FinalApprove( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseFinalApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -767,15 +797,22 @@ class FormUpCountryController extends Controller WhatsappHelper::rejectExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseRejected( + $mail = new ExpenseRejected( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseRejected($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; diff --git a/app/Http/Controllers/Forms/FormVehicleController.php b/app/Http/Controllers/Forms/FormVehicleController.php index f547847..2a7a247 100644 --- a/app/Http/Controllers/Forms/FormVehicleController.php +++ b/app/Http/Controllers/Forms/FormVehicleController.php @@ -27,6 +27,7 @@ use App\Models\Admin; use App\Helpers\BudgetHelper; use App\Helpers\NotificationHelper; use Illuminate\Support\Facades\Log; +use App\Services\BrevoService; class FormVehicleController extends Controller { @@ -233,15 +234,22 @@ class FormVehicleController extends Controller WhatsappHelper::newExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseCreated( + $mail = new ExpenseCreated( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseCreated($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -396,16 +404,23 @@ class FormVehicleController extends Controller $url = route('forms.vehicle.view', $form->id); WhatsappHelper::approveExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved( + $mail = new ExpenseApproved( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -480,16 +495,23 @@ class FormVehicleController extends Controller $url = route('forms.vehicle.view', $form->id); WhatsappHelper::approve2Expense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); - // // Send bulk email + // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseApproved2( + $mail = new ExpenseApproved2( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseApproved2($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -574,15 +596,22 @@ class FormVehicleController extends Controller WhatsappHelper::finalApprove($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new FinalApprove( + $mail = new FinalApprove( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseFinalApproved($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; @@ -632,15 +661,22 @@ class FormVehicleController extends Controller WhatsappHelper::rejectExpense($phoneNumbers, $expense_number, $url, $tanggal, $total, $name); // Send bulk email + $brevoService = app(BrevoService::class); foreach ($recipients as $recipient) { try { - Mail::to($recipient)->send(new ExpenseRejected( + $mail = new ExpenseRejected( $name, $expense_number, $tanggal, $total, $url - )); + ); + + $response = $brevoService->expenseRejected($recipient, $name, $mail); + + if (isset($response['success']) && $response['success'] === false) { + Log::warning("Email to {$recipient} failed: " . ($response['message'] ?? 'Unknown error')); + } } catch (\Exception $e) { Log::error("Failed to send email to {$recipient}: " . $e->getMessage()); continue; diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index f23d24a..8e4fe74 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -38,6 +38,7 @@ class Kernel extends HttpKernel \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, + \App\Http\Middleware\SessionTimeout::class, ], 'api' => [ diff --git a/app/Http/Middleware/SessionTimeout.php b/app/Http/Middleware/SessionTimeout.php new file mode 100644 index 0000000..305fda4 --- /dev/null +++ b/app/Http/Middleware/SessionTimeout.php @@ -0,0 +1,31 @@ + $timeout)) { + Auth::logout(); + session()->flush(); + return redirect('/login')->with('message', 'Session expired due to inactivity.'); + } + + // Update session activity time + session(['lastActivityTime' => time()]); + + return $next($request); + } +} diff --git a/app/Mail/ExpenseApproved.php b/app/Mail/ExpenseApproved.php index a6f2d72..1782d62 100644 --- a/app/Mail/ExpenseApproved.php +++ b/app/Mail/ExpenseApproved.php @@ -3,19 +3,16 @@ 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; +use Illuminate\Support\Facades\View; class ExpenseApproved extends Mailable { use Queueable, SerializesModels; - /** - * Create a new message instance. - */ public function __construct( protected string $name, protected string $expense_number, @@ -24,9 +21,6 @@ class ExpenseApproved extends Mailable protected string $url, ) {} - /** - * Get the message envelope. - */ public function envelope(): Envelope { return new Envelope( @@ -34,9 +28,6 @@ class ExpenseApproved extends Mailable ); } - /** - * Get the message content definition. - */ public function content(): Content { return new Content( @@ -51,13 +42,22 @@ class ExpenseApproved extends Mailable ); } - /** - * Get the attachments for the message. - * - * @return array - */ public function attachments(): array { return []; } + + /** + * Render the Blade email template as HTML string (for Brevo API). + */ + public function renderHtml(): string + { + return View::make('mail.approved', [ + 'name' => $this->name, + 'expense_number' => $this->expense_number, + 'tanggal' => $this->tanggal, + 'total' => $this->total, + 'url' => $this->url, + ])->render(); + } } diff --git a/app/Mail/ExpenseApproved2.php b/app/Mail/ExpenseApproved2.php index 9ae246a..5e25286 100644 --- a/app/Mail/ExpenseApproved2.php +++ b/app/Mail/ExpenseApproved2.php @@ -3,26 +3,33 @@ 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; +use Illuminate\Support\Facades\View; class ExpenseApproved2 extends Mailable { use Queueable, SerializesModels; + protected string $name; + protected string $expense_number; + protected string $tanggal; + protected int $total; + protected string $url; + /** * Create a new message instance. */ - public function __construct( - protected string $name, - protected string $expense_number, - protected string $tanggal, - protected int $total, - protected string $url, - ) {} + public function __construct(string $name, string $expense_number, string $tanggal, int $total, string $url) + { + $this->name = $name; + $this->expense_number = $expense_number; + $this->tanggal = $tanggal; + $this->total = $total; + $this->url = $url; + } /** * Get the message envelope. @@ -60,4 +67,18 @@ class ExpenseApproved2 extends Mailable { return []; } + + /** + * Render the Blade email template as an HTML string (for Brevo API). + */ + public function renderHtml(): string + { + return View::make('mail.approved2', [ + 'name' => $this->name, + 'expense_number' => $this->expense_number, + 'tanggal' => $this->tanggal, + 'total' => $this->total, + 'url' => $this->url, + ])->render(); + } } diff --git a/app/Mail/ExpenseCreated.php b/app/Mail/ExpenseCreated.php index 609130f..6c46f30 100644 --- a/app/Mail/ExpenseCreated.php +++ b/app/Mail/ExpenseCreated.php @@ -3,26 +3,33 @@ 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; +use Illuminate\Support\Facades\View; class ExpenseCreated extends Mailable { use Queueable, SerializesModels; + protected string $name; + protected string $expense_number; + protected string $tanggal; + protected int $total; + protected string $url; + /** * Create a new message instance. */ - public function __construct( - protected string $name, - protected string $expense_number, - protected string $tanggal, - protected int $total, - protected string $url, - ) {} + public function __construct(string $name, string $expense_number, string $tanggal, int $total, string $url) + { + $this->name = $name; + $this->expense_number = $expense_number; + $this->tanggal = $tanggal; + $this->total = $total; + $this->url = $url; + } /** * Get the message envelope. @@ -60,4 +67,18 @@ class ExpenseCreated extends Mailable { return []; } + + /** + * Render the Blade email template as an HTML string (for Brevo API). + */ + public function renderHtml(): string + { + return View::make('mail.created', [ + 'name' => $this->name, + 'expense_number' => $this->expense_number, + 'tanggal' => $this->tanggal, + 'total' => $this->total, + 'url' => $this->url, + ])->render(); + } } diff --git a/app/Mail/ExpenseRejected.php b/app/Mail/ExpenseRejected.php index 17aa3a3..15e721f 100644 --- a/app/Mail/ExpenseRejected.php +++ b/app/Mail/ExpenseRejected.php @@ -3,26 +3,33 @@ 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; +use Illuminate\Support\Facades\View; class ExpenseRejected extends Mailable { use Queueable, SerializesModels; + protected string $name; + protected string $expense_number; + protected string $tanggal; + protected int $total; + protected string $url; + /** * Create a new message instance. */ - public function __construct( - protected string $name, - protected string $expense_number, - protected string $tanggal, - protected int $total, - protected string $url, - ) {} + public function __construct(string $name, string $expense_number, string $tanggal, int $total, string $url) + { + $this->name = $name; + $this->expense_number = $expense_number; + $this->tanggal = $tanggal; + $this->total = $total; + $this->url = $url; + } /** * Get the message envelope. @@ -60,4 +67,18 @@ class ExpenseRejected extends Mailable { return []; } + + /** + * Render the Blade email template as an HTML string (for Brevo API). + */ + public function renderHtml(): string + { + return View::make('mail.rejected', [ + 'name' => $this->name, + 'expense_number' => $this->expense_number, + 'tanggal' => $this->tanggal, + 'total' => $this->total, + 'url' => $this->url, + ])->render(); + } } diff --git a/app/Mail/FinalApprove.php b/app/Mail/FinalApprove.php index 6c3ee4c..907da44 100644 --- a/app/Mail/FinalApprove.php +++ b/app/Mail/FinalApprove.php @@ -3,26 +3,33 @@ 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; +use Illuminate\Support\Facades\View; class FinalApprove extends Mailable { use Queueable, SerializesModels; + protected string $name; + protected string $expense_number; + protected string $tanggal; + protected int $total; + protected string $url; + /** * Create a new message instance. */ - public function __construct( - protected string $name, - protected string $expense_number, - protected string $tanggal, - protected int $total, - protected string $url, - ) {} + public function __construct(string $name, string $expense_number, string $tanggal, int $total, string $url) + { + $this->name = $name; + $this->expense_number = $expense_number; + $this->tanggal = $tanggal; + $this->total = $total; + $this->url = $url; + } /** * Get the message envelope. @@ -60,4 +67,18 @@ class FinalApprove extends Mailable { return []; } + + /** + * Render the Blade email template as an HTML string (for Brevo API). + */ + public function renderHtml(): string + { + return View::make('mail.closed', [ + 'name' => $this->name, + 'expense_number' => $this->expense_number, + 'tanggal' => $this->tanggal, + 'total' => $this->total, + 'url' => $this->url, + ])->render(); + } } diff --git a/app/Services/BrevoService.php b/app/Services/BrevoService.php new file mode 100644 index 0000000..6d82b93 --- /dev/null +++ b/app/Services/BrevoService.php @@ -0,0 +1,218 @@ +client = new Client(); + $this->apiKey = env('BREVO_API_KEY'); + $this->mailFromAddress = env('BREVO_MAIL_FROM_ADDRESS'); + $this->mailFromName = env('BREVO_MAIL_FROM_NAME'); + } + + public function expenseCreated($recipientEmail, $recipientName, ExpenseCreated $mail) + { + $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML + + try { + $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ + 'headers' => [ + 'accept' => 'application/json', + 'api-key' => $this->apiKey, + 'content-type' => 'application/json', + ], + 'json' => [ + 'sender' => [ + 'name' => $this->mailFromName, + 'email' => $this->mailFromAddress, + ], + 'to' => [ + [ + 'email' => $recipientEmail, + 'name' => $recipientName, + ], + ], + 'subject' => 'Expense Created', + 'htmlContent' => $htmlContent, + ], + ]); + + return json_decode($response->getBody(), true); + } catch (RequestException $e) { + Log::error('Brevo email failed to send', [ + 'error' => $e->getMessage(), + 'recipient' => $recipientEmail, + ]); + + return null; + } + } + + public function expenseApproved($recipientEmail, $recipientName, ExpenseApproved $mail) + { + $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML + + try { + $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ + 'headers' => [ + 'accept' => 'application/json', + 'api-key' => $this->apiKey, + 'content-type' => 'application/json', + ], + 'json' => [ + 'sender' => [ + 'name' => $this->mailFromName, + 'email' => $this->mailFromAddress, + ], + 'to' => [ + [ + 'email' => $recipientEmail, + 'name' => $recipientName, + ], + ], + 'subject' => 'Expense First Approval', + 'htmlContent' => $htmlContent, + ], + ]); + + return json_decode($response->getBody(), true); + } catch (RequestException $e) { + Log::error('Brevo email failed to send', [ + 'error' => $e->getMessage(), + 'recipient' => $recipientEmail, + ]); + + return null; + } + } + + public function expenseApproved2($recipientEmail, $recipientName, ExpenseApproved2 $mail) + { + $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML + + try { + $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ + 'headers' => [ + 'accept' => 'application/json', + 'api-key' => $this->apiKey, + 'content-type' => 'application/json', + ], + 'json' => [ + 'sender' => [ + 'name' => $this->mailFromName, + 'email' => $this->mailFromAddress, + ], + 'to' => [ + [ + 'email' => $recipientEmail, + 'name' => $recipientName, + ], + ], + 'subject' => 'Expense Second Approval', + 'htmlContent' => $htmlContent, + ], + ]); + + return json_decode($response->getBody(), true); + } catch (RequestException $e) { + Log::error('Brevo email failed to send', [ + 'error' => $e->getMessage(), + 'recipient' => $recipientEmail, + ]); + + return null; + } + } + + public function expenseFinalApproved($recipientEmail, $recipientName, FinalApprove $mail) + { + $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML + + try { + $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ + 'headers' => [ + 'accept' => 'application/json', + 'api-key' => $this->apiKey, + 'content-type' => 'application/json', + ], + 'json' => [ + 'sender' => [ + 'name' => $this->mailFromName, + 'email' => $this->mailFromAddress, + ], + 'to' => [ + [ + 'email' => $recipientEmail, + 'name' => $recipientName, + ], + ], + 'subject' => 'Expense Final Approval', + 'htmlContent' => $htmlContent, + ], + ]); + + return json_decode($response->getBody(), true); + } catch (RequestException $e) { + Log::error('Brevo email failed to send', [ + 'error' => $e->getMessage(), + 'recipient' => $recipientEmail, + ]); + + return null; + } + } + + public function expenseRejected($recipientEmail, $recipientName, ExpenseRejected $mail) + { + $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML + + try { + $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ + 'headers' => [ + 'accept' => 'application/json', + 'api-key' => $this->apiKey, + 'content-type' => 'application/json', + ], + 'json' => [ + 'sender' => [ + 'name' => $this->mailFromName, + 'email' => $this->mailFromAddress, + ], + 'to' => [ + [ + 'email' => $recipientEmail, + 'name' => $recipientName, + ], + ], + 'subject' => 'Expense Rejected', + 'htmlContent' => $htmlContent, + ], + ]); + + return json_decode($response->getBody(), true); + } catch (RequestException $e) { + Log::error('Brevo email failed to send', [ + 'error' => $e->getMessage(), + 'recipient' => $recipientEmail, + ]); + + return null; + } + } +} \ No newline at end of file diff --git a/config/session.php b/config/session.php index 4e0f66c..9292841 100644 --- a/config/session.php +++ b/config/session.php @@ -31,7 +31,7 @@ return [ | */ - 'lifetime' => env('SESSION_LIFETIME', 120), + 'lifetime' => 30, 'expire_on_close' => false, diff --git a/resources/views/backend/pages/report/generate_jurnal.blade.php b/resources/views/backend/pages/report/generate_jurnal.blade.php index c8185b4..094fbc0 100644 --- a/resources/views/backend/pages/report/generate_jurnal.blade.php +++ b/resources/views/backend/pages/report/generate_jurnal.blade.php @@ -67,7 +67,7 @@ @foreach ($kategori as $item) @php $drValue = $nominals[$item->id] ?? 0; - $drFormatted = $drValue == 0 ? '' : number_format($drValue, 0, ',', '.'); + $drFormatted = $drValue == 0 ? '' : number_format($drValue, 0, ',', ','); $totalDr += $drValue; @endphp @@ -89,7 +89,7 @@ @php $crValue = $budget && $budget->amount != 0 ? $budget->amount : 0; $totalCr += $crValue; - echo $crValue == 0 ? '' : number_format($crValue, 0, ',', '.'); + echo $crValue == 0 ? '' : number_format($crValue, 0, ',', ','); @endphp @@ -104,7 +104,7 @@ @php $totalCr += 500000; @endphp - {{ number_format(500000, 0, ',', '.') }} + {{ number_format(500000, 0, ',', ',') }} @@ -116,7 +116,7 @@ @php $totalDr += 500000; @endphp - {{ number_format(500000, 0, ',', '.') }} + {{ number_format(500000, 0, ',', ',') }} @@ -124,8 +124,8 @@ Total - {{ number_format($totalDr, 0, ',', '.') }} - {{ number_format($totalCr, 0, ',', '.') }} + {{ number_format($totalDr, 0, ',', ',') }} + {{ number_format($totalCr, 0, ',', ',') }} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 672fef9..f14ce18 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -281,3 +281,28 @@ periode.textContent = `${month} (12 ${month} - 10 ${nextMonth} ${year})`; + +