update revisi
This commit is contained in:
@@ -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' => [
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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' => [
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SessionTimeout
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
// Get last activity time
|
||||
$lastActivity = session('lastActivityTime');
|
||||
|
||||
// Set logout time in minutes (30 minutes)
|
||||
$timeout = 30 * 60;
|
||||
|
||||
if ($lastActivity && (time() - $lastActivity > $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);
|
||||
}
|
||||
}
|
||||
@@ -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<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use App\Mail\ExpenseCreated;
|
||||
use App\Mail\ExpenseApproved;
|
||||
use App\Mail\ExpenseApproved2;
|
||||
use App\Mail\ExpenseRejected;
|
||||
use App\Mail\FinalApprove;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BrevoService
|
||||
{
|
||||
protected $client;
|
||||
protected $apiKey;
|
||||
protected $mailFromAddress;
|
||||
protected $mailFromName;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user