added whastapp notification

This commit is contained in:
Jagad R R
2024-12-25 13:37:49 +07:00
parent 0030c0f48e
commit 8c451d0d7a
7 changed files with 142 additions and 3 deletions
@@ -17,6 +17,7 @@ use Illuminate\Support\Str;
use Illuminate\Support\Facades\Mail;
use App\Mail\ExpenseApproved;
use App\Mail\ExpenseRejected;
use App\Helpers\WhatsappHelper;
class FormUpCountryController extends Controller
{
@@ -264,19 +265,23 @@ class FormUpCountryController extends Controller
// Collect all recipients
$recipients = [$form->user->email];
$phoneNumbers = [$form->user->phone];
if ($heads['cabang_head']) {
$recipients[] = $heads['cabang_head']['email'];
$phoneNumbers[] = $heads['cabang_head']['phone'];
}
if ($heads['region_head']) {
$recipients[] = $heads['region_head']['email'];
$phoneNumbers[] = $heads['region_head']['phone'];
}
// Remove duplicate email addresses, if any
// Remove duplicate data, if any
$recipients = array_unique($recipients);
$phoneNumbers = array_unique($phoneNumbers);
// Send bulk email
// // Send bulk email
Mail::to($recipients)->send(new ExpenseApproved(
$name,
$expense_number,
@@ -284,6 +289,9 @@ class FormUpCountryController extends Controller
$total
));
// send whatsapp message
WhatsappHelper::approveExpense($phoneNumbers, $expense_number);
session()->flash('success', 'Form has been approved.');
return redirect()->back();
}
@@ -305,17 +313,21 @@ class FormUpCountryController extends Controller
// Collect all recipients
$recipients = [$form->user->email];
$phoneNumbers = [$form->user->phone];
if ($heads['cabang_head']) {
$recipients[] = $heads['cabang_head']['email'];
$phoneNumbers[] = $heads['cabang_head']['phone'];
}
if ($heads['region_head']) {
$recipients[] = $heads['region_head']['email'];
$phoneNumbers[] = $heads['region_head']['phone'];
}
// Remove duplicate email addresses, if any
$recipients = array_unique($recipients);
$phoneNumbers = array_unique($phoneNumbers);
// Send bulk email
Mail::to($recipients)->send(new ExpenseRejected(
@@ -325,6 +337,9 @@ class FormUpCountryController extends Controller
$total
));
// send whatsapp message
WhatsappHelper::rejectExpense($phoneNumbers, $expense_number);
session()->flash('success', 'Form has been rejected.');
return redirect()->back();
}