revised notification for new approval system
This commit is contained in:
@@ -165,18 +165,28 @@ class FormOtherController extends Controller
|
||||
'status' => 'On Progress',
|
||||
]);
|
||||
|
||||
// Send notification to MIS and Admin Region
|
||||
$roles = ['Marketing Information System', 'Admin Region'];
|
||||
$recipients = [];
|
||||
$phoneNumbers = [];
|
||||
|
||||
$name = auth()->user()->name;
|
||||
$tanggal = $request->tanggal;
|
||||
$total = $request->total;
|
||||
|
||||
// Send notification to MIS and Admin Region and Area Manager Cabang
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang', 'Marketing Operational Manager Region'];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
|
||||
// Collect all recipients (emails and phone numbers) for the specified roles
|
||||
foreach ($roles as $role) {
|
||||
$users = Admin::getUserByRoleName($role);
|
||||
$users = Admin::getUserByRoleName($role)->filter(function ($user) use ($role, $cabang) {
|
||||
// Include 'Marketing Information System' without cabang filtering
|
||||
if ($role === 'Marketing Information System') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Ensure user has a cabang and matches the current cabang ID
|
||||
return $user->cabang && $user->cabang->cabang->id === $cabang->id;
|
||||
});
|
||||
|
||||
// Extract emails and phone numbers
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
@@ -185,6 +195,7 @@ class FormOtherController extends Controller
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
|
||||
// Generate URL and send WhatsApp notification
|
||||
$url = route('forms.other.view', $form->id);
|
||||
@@ -294,17 +305,27 @@ class FormOtherController extends Controller
|
||||
$total = $form->total;
|
||||
|
||||
// Collect all recipients
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang'];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
$phoneNumbers[] = $heads['cabang_head']['phone'];
|
||||
}
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
foreach ($roles as $role) {
|
||||
$users = Admin::getUserByRoleName($role)->filter(function ($user) use ($role, $cabang_id) {
|
||||
// Include 'Marketing Information System' without cabang filtering
|
||||
if ($role === 'Marketing Information System') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
$phoneNumbers[] = $heads['region_head']['phone'];
|
||||
// Ensure user has a cabang and matches the current cabang ID
|
||||
return $user->cabang && $user->cabang->cabang->id === $cabang_id;
|
||||
});
|
||||
|
||||
// Extract emails and phone numbers
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
@@ -340,24 +361,33 @@ class FormOtherController extends Controller
|
||||
'status' => 'Approved 2',
|
||||
]);
|
||||
|
||||
$heads = $form->user->getCabangAndRegionHead();
|
||||
$name = $form->user->name;
|
||||
$expense_number = $form->expense_number;
|
||||
$tanggal = $form->created_at;
|
||||
$total = $form->total;
|
||||
|
||||
// Collect all recipients
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang', 'Marketing Operational Manager Region'];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
$phoneNumbers[] = $heads['cabang_head']['phone'];
|
||||
}
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
$phoneNumbers[] = $heads['region_head']['phone'];
|
||||
foreach ($roles as $role) {
|
||||
$users = Admin::getUserByRoleName($role)->filter(function ($user) use ($role, $cabang_id) {
|
||||
// Include 'Marketing Information System' without cabang filtering
|
||||
if ($role === 'Marketing Information System') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Ensure user has a cabang and matches the current cabang ID
|
||||
return $user->cabang && $user->cabang->cabang->id === $cabang_id;
|
||||
});
|
||||
|
||||
// Extract emails and phone numbers
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
@@ -406,24 +436,31 @@ class FormOtherController extends Controller
|
||||
'approved_total' => $form->total,
|
||||
]);
|
||||
|
||||
$heads = $form->user->getCabangAndRegionHead();
|
||||
$name = $form->user->name;
|
||||
$expense_number = $form->expense_number;
|
||||
$tanggal = $form->created_at;
|
||||
$total = $form->approved_total;
|
||||
|
||||
// Collect all recipients
|
||||
$roles = ['Head of Sales Marketing', 'Marketing Operational Manager Region'];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
$phoneNumbers[] = $heads['cabang_head']['phone'];
|
||||
}
|
||||
foreach ($roles as $role) {
|
||||
$users = Admin::getUserByRoleName($role)->filter(function ($user) use ($role, $cabang_id) {
|
||||
// Include 'Marketing Information System' without cabang filtering
|
||||
if ($role === 'Marketing Information System') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
$phoneNumbers[] = $heads['region_head']['phone'];
|
||||
// Ensure user has a cabang and matches the current cabang ID
|
||||
return $user->cabang && $user->cabang->cabang->id === $cabang_id;
|
||||
});
|
||||
|
||||
// Extract emails and phone numbers
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
|
||||
Reference in New Issue
Block a user