added notifications
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
use App\Models\Notifications;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class NotificationHelper
|
||||
{
|
||||
public static function newExpense($user_id, $expense_number, $receiver_ids = [])
|
||||
{
|
||||
if (!is_array($receiver_ids) || empty($receiver_ids)) {
|
||||
throw new InvalidArgumentException('Receiver IDs must be a non-empty array.');
|
||||
}
|
||||
|
||||
// Buat data untuk batch insert
|
||||
$notifications = [];
|
||||
foreach ($receiver_ids as $receiver_id) {
|
||||
$notifications[] = [
|
||||
'user_id' => $user_id,
|
||||
'receiver_id' => $receiver_id,
|
||||
'title' => 'New Expense',
|
||||
'content' => 'You have new expense waiting for approval (' . $expense_number . ')',
|
||||
'is_read' => 0,
|
||||
'type' => 'new_expense',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
// Lakukan batch insert
|
||||
Notifications::insert($notifications);
|
||||
}
|
||||
|
||||
public static function approveExpense($user_id, $expense_number, $receiver_ids = [])
|
||||
{
|
||||
if (!is_array($receiver_ids) || empty($receiver_ids)) {
|
||||
throw new InvalidArgumentException('Receiver IDs must be a non-empty array.');
|
||||
}
|
||||
|
||||
// Buat data untuk batch insert
|
||||
$notifications = [];
|
||||
foreach ($receiver_ids as $receiver_id) {
|
||||
$notifications[] = [
|
||||
'user_id' => $user_id,
|
||||
'receiver_id' => $receiver_id,
|
||||
'title' => 'New Expense',
|
||||
'content' => 'You have new expense waiting for second approval (' . $expense_number . ')',
|
||||
'is_read' => 0,
|
||||
'type' => 'approve_expense',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
// Lakukan batch insert
|
||||
Notifications::insert($notifications);
|
||||
}
|
||||
|
||||
public static function approve2Expense($user_id, $expense_number, $receiver_ids = [])
|
||||
{
|
||||
if (!is_array($receiver_ids) || empty($receiver_ids)) {
|
||||
throw new InvalidArgumentException('Receiver IDs must be a non-empty array.');
|
||||
}
|
||||
|
||||
// Buat data untuk batch insert
|
||||
$notifications = [];
|
||||
foreach ($receiver_ids as $receiver_id) {
|
||||
$notifications[] = [
|
||||
'user_id' => $user_id,
|
||||
'receiver_id' => $receiver_id,
|
||||
'title' => 'New Expense',
|
||||
'content' => 'You have new expense waiting for final approval (' . $expense_number . ')',
|
||||
'is_read' => 0,
|
||||
'type' => 'approve2_expense',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
|
||||
// Lakukan batch insert
|
||||
Notifications::insert($notifications);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ use App\Models\FormVehicleRunningCost;
|
||||
use App\Models\FormMeetingSeminar;
|
||||
use App\Models\FormOthers;
|
||||
use App\Models\UserHasCabang;
|
||||
use App\Models\Notifications;
|
||||
|
||||
|
||||
class DashboardController extends Controller
|
||||
@@ -99,4 +100,43 @@ class DashboardController extends Controller
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function notifications()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['notification.view']);
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
|
||||
// Mulai dengan query dasar
|
||||
$notifications = Notifications::orderBy('created_at', 'desc')
|
||||
->where('receiver_id', auth()->user()->id)
|
||||
->where('is_read', 0);
|
||||
|
||||
// Tambahkan filter berdasarkan role
|
||||
if ($role == 'Admin Region') {
|
||||
$notifications->where('type', 'new_expense');
|
||||
} elseif ($role == 'Marketing Operational Manager Region') {
|
||||
$notifications->where('type', 'approve2_expense');
|
||||
} elseif ($role == 'Area Manager Cabang' || $role == 'Marketing Information System') {
|
||||
$notifications->where('type', 'approve_expense');
|
||||
} elseif ($role == 'Head of Sales Marketing') {
|
||||
$notifications->where('type', 'approve2_expense');
|
||||
} else {
|
||||
// Jika tidak ada role yang sesuai, kembalikan koleksi kosong
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
// Ambil data dan kembalikan sebagai JSON
|
||||
return response()->json($notifications->limit(6)->get());
|
||||
}
|
||||
|
||||
public function mark_read()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['notification.delete']);
|
||||
$receiver_id = auth()->user()->id;
|
||||
|
||||
Notifications::where('receiver_id', $receiver_id)->update(['is_read' => 1]);
|
||||
|
||||
session()->flash('success', 'Notifications marked as read.');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use App\Helpers\AuditTrailHelper;
|
||||
use App\Models\Admin;
|
||||
use App\Rules\FileType;
|
||||
use App\Helpers\BudgetHelper;
|
||||
use App\Helpers\NotificationHelper;
|
||||
|
||||
class FormEntertainmentPresentationController extends Controller
|
||||
{
|
||||
@@ -175,6 +176,7 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
// Collect all recipients (emails and phone numbers) for the specified roles
|
||||
foreach ($roles as $role) {
|
||||
@@ -192,12 +194,14 @@ class FormEntertainmentPresentationController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// Generate URL and send WhatsApp notification
|
||||
$url = route('forms.entertainment.view', $form->id);
|
||||
@@ -212,6 +216,8 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::newExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Insert', 'Insert New Expense at Form Entertainment Presentation (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been created.');
|
||||
return redirect()->back();
|
||||
@@ -312,6 +318,7 @@ class FormEntertainmentPresentationController extends Controller
|
||||
|
||||
// Collect all recipients
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang'];
|
||||
$receiver_ids = [];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
|
||||
@@ -331,12 +338,14 @@ class FormEntertainmentPresentationController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.entertainment.view', $form->id);
|
||||
@@ -351,6 +360,8 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approveExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Entertainment (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
@@ -367,13 +378,13 @@ class FormEntertainmentPresentationController 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;
|
||||
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang', 'Marketing Operational Manager Region'];
|
||||
$receiver_ids = [];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
|
||||
@@ -394,12 +405,14 @@ class FormEntertainmentPresentationController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.entertainment.view', $form->id);
|
||||
@@ -414,6 +427,8 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approve2Expense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Entertainment (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
|
||||
@@ -25,6 +25,7 @@ use App\Helpers\AuditTrailHelper;
|
||||
use App\Rules\FileType;
|
||||
use App\Models\Admin;
|
||||
use App\Helpers\BudgetHelper;
|
||||
use App\Helpers\NotificationHelper;
|
||||
|
||||
class FormMeetingSeminarController extends Controller
|
||||
{
|
||||
@@ -213,6 +214,7 @@ class FormMeetingSeminarController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
// Collect all recipients (emails and phone numbers) for the specified roles
|
||||
foreach ($roles as $role) {
|
||||
@@ -230,11 +232,14 @@ class FormMeetingSeminarController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// Generate URL and send WhatsApp notification
|
||||
$url = route('forms.meeting.view', $form->id);
|
||||
@@ -249,6 +254,8 @@ class FormMeetingSeminarController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::newExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Insert', 'Insert New Expense at Form Meeting Seminar (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been created.');
|
||||
return redirect()->back();
|
||||
@@ -385,6 +392,7 @@ class FormMeetingSeminarController extends Controller
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang'];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
$receiver_ids = [];
|
||||
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
foreach ($roles as $role) {
|
||||
@@ -402,12 +410,14 @@ class FormMeetingSeminarController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.meeting.view', $form->id);
|
||||
@@ -422,6 +432,8 @@ class FormMeetingSeminarController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approveExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Meeting Seminar (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
@@ -446,6 +458,7 @@ class FormMeetingSeminarController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
|
||||
@@ -464,12 +477,14 @@ class FormMeetingSeminarController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.meeting.view', $form->id);
|
||||
@@ -484,6 +499,8 @@ class FormMeetingSeminarController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approve2Expense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Meeting Seminar (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
|
||||
@@ -5,11 +5,7 @@ namespace App\Http\Controllers\Forms;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\FormOthers;
|
||||
use App\Models\Rayon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\Region;
|
||||
use App\Models\Cabang;
|
||||
use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -25,6 +21,7 @@ use App\Helpers\AuditTrailHelper;
|
||||
use App\Rules\FileType;
|
||||
use App\Models\Admin;
|
||||
use App\Helpers\BudgetHelper;
|
||||
use App\Helpers\NotificationHelper;
|
||||
|
||||
class FormOtherController extends Controller
|
||||
{
|
||||
@@ -173,6 +170,7 @@ class FormOtherController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
// Collect all recipients (emails and phone numbers) for the specified roles
|
||||
foreach ($roles as $role) {
|
||||
@@ -190,12 +188,14 @@ class FormOtherController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// Generate URL and send WhatsApp notification
|
||||
$url = route('forms.other.view', $form->id);
|
||||
@@ -210,6 +210,9 @@ class FormOtherController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
// Send notification to the user
|
||||
NotificationHelper::newExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Insert', 'Insert New Expense at Form Other (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been created.');
|
||||
return redirect()->back();
|
||||
@@ -298,7 +301,6 @@ class FormOtherController extends Controller
|
||||
'status' => 'Approved 1',
|
||||
]);
|
||||
|
||||
$heads = $form->user->getCabangAndRegionHead();
|
||||
$name = $form->user->name;
|
||||
$expense_number = $form->expense_number;
|
||||
$tanggal = $form->created_at;
|
||||
@@ -308,6 +310,7 @@ class FormOtherController extends Controller
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang'];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
$receiver_ids = [];
|
||||
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
foreach ($roles as $role) {
|
||||
@@ -325,12 +328,14 @@ class FormOtherController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.other.view', $form->id);
|
||||
@@ -345,6 +350,8 @@ class FormOtherController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approveExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Other (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
@@ -369,6 +376,7 @@ class FormOtherController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
|
||||
@@ -387,12 +395,14 @@ class FormOtherController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.other.view', $form->id);
|
||||
@@ -407,6 +417,8 @@ class FormOtherController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approve2Expense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Other (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
|
||||
@@ -25,6 +25,7 @@ use App\Helpers\NextCloudHelper;
|
||||
use App\Rules\FileType;
|
||||
use App\Models\Admin;
|
||||
use App\Helpers\BudgetHelper;
|
||||
use App\Helpers\NotificationHelper;
|
||||
|
||||
class FormUpCountryController extends Controller
|
||||
{
|
||||
@@ -240,6 +241,7 @@ class FormUpCountryController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
$name = auth()->user()->name;
|
||||
$tanggal = $form->tanggal;
|
||||
@@ -261,12 +263,14 @@ class FormUpCountryController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// Generate URL and send WhatsApp notification
|
||||
$url = route('forms.up-country.view', $form->id);
|
||||
@@ -281,6 +285,8 @@ class FormUpCountryController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::newExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Insert', 'Insert New Expense at Form Up Country (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been created.');
|
||||
return redirect()->back();
|
||||
@@ -443,6 +449,7 @@ class FormUpCountryController extends Controller
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang'];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
$receiver_ids = [];
|
||||
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
foreach ($roles as $role) {
|
||||
@@ -460,12 +467,14 @@ class FormUpCountryController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.up-country.view', $form->id);
|
||||
@@ -480,6 +489,8 @@ class FormUpCountryController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approveExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Up Country (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
@@ -504,6 +515,7 @@ class FormUpCountryController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
|
||||
@@ -522,6 +534,7 @@ class FormUpCountryController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,6 +555,8 @@ class FormUpCountryController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approve2Expense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Up Country (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
|
||||
@@ -25,6 +25,7 @@ use App\Helpers\AuditTrailHelper;
|
||||
use App\Rules\FileType;
|
||||
use App\Models\Admin;
|
||||
use App\Helpers\BudgetHelper;
|
||||
use App\Helpers\NotificationHelper;
|
||||
|
||||
class FormVehicleController extends Controller
|
||||
{
|
||||
@@ -177,6 +178,7 @@ class FormVehicleController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
// Collect all recipients (emails and phone numbers) for the specified roles
|
||||
foreach ($roles as $role) {
|
||||
@@ -194,12 +196,14 @@ class FormVehicleController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// Generate URL and send WhatsApp notification
|
||||
$url = route('forms.vehicle.view', $form->id);
|
||||
@@ -214,6 +218,8 @@ class FormVehicleController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::newExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Insert', 'Insert New Expense at Form Vehicle Running Cost (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been created.');
|
||||
return redirect()->back();
|
||||
@@ -317,6 +323,7 @@ class FormVehicleController extends Controller
|
||||
$roles = ['Marketing Information System', 'Admin Region', 'Area Manager Cabang'];
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
|
||||
$receiver_ids = [];
|
||||
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
foreach ($roles as $role) {
|
||||
@@ -334,12 +341,14 @@ class FormVehicleController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.vehicle.view', $form->id);
|
||||
@@ -354,6 +363,8 @@ class FormVehicleController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approveExpense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Vehicle Running Cost (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
@@ -378,6 +389,7 @@ class FormVehicleController extends Controller
|
||||
$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];
|
||||
$receiver_ids = [];
|
||||
|
||||
$cabang_id = UserHasCabang::where('user_id', $form->user_id)->first()->cabang_id;
|
||||
|
||||
@@ -396,12 +408,14 @@ class FormVehicleController extends Controller
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
$receiver_ids[] = $user->id;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate data, if any
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
$receiver_ids = array_unique($receiver_ids);
|
||||
|
||||
// send whatsapp message
|
||||
$url = route('forms.vehicle.view', $form->id);
|
||||
@@ -416,6 +430,8 @@ class FormVehicleController extends Controller
|
||||
$url
|
||||
));
|
||||
|
||||
NotificationHelper::approve2Expense($form->user_id, $expense_number, $receiver_ids);
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approve Expense at Form Vehicle Running Cost (' . $form->expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Notifications extends Model
|
||||
{
|
||||
protected $table = 'notifications';
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'receiver_id',
|
||||
'title',
|
||||
'content',
|
||||
'is_read',
|
||||
'type',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('notifications', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained('admins')->onDelete('cascade');
|
||||
$table->foreignId('receiver_id')->constrained('admins')->onDelete('cascade');
|
||||
$table->string('title');
|
||||
$table->text('content');
|
||||
$table->boolean('is_read')->default(false);
|
||||
$table->string('type');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('notifications');
|
||||
}
|
||||
};
|
||||
@@ -33,12 +33,37 @@
|
||||
</div>
|
||||
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link" data-toggle="dropdown" href="#" role="button" data-widget="notification">
|
||||
<i class="fas fa-bell"></i>
|
||||
</a>
|
||||
<div class="dropdown-menu dropdown-menu-xl dropdown-menu-right">
|
||||
<div id="notification">
|
||||
<span class="dropdown-item dropdown-header" id="notification_title">Notifications</span>
|
||||
<div id="loading-bar" style="text-align: center; padding: 10px; display: none;">
|
||||
<div class="spinner-border text-primary" style="width: 2rem; height: 2rem;" role="status">
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="notification-list"></div>
|
||||
<div class="dropdown-divider"></div>
|
||||
<form action="{{ route('dashboard.mark_read') }}" method="POST">
|
||||
@csrf
|
||||
@include('backend.layouts.partials.messages')
|
||||
<button type="submit" class="dropdown-item dropdown-footer" id="notification_mark">Mark all as read</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<!-- Fullscreen Icon -->
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-widget="fullscreen" href="#" role="button">
|
||||
<i class="fas fa-expand-arrows-alt"></i>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<!-- Profile Section -->
|
||||
<li class="nav-item dropdown" title="Account Profile">
|
||||
<a class="nav-link" data-toggle="dropdown" href="#">
|
||||
{{ Auth::guard('admin')->user()->name }} <i class="far fa-user"></i>
|
||||
@@ -145,4 +170,57 @@
|
||||
|
||||
// Initialize the clock on page load
|
||||
updateDateTime();
|
||||
|
||||
document.querySelector('[data-widget="notification"]').addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const loadingBar = document.getElementById('loading-bar');
|
||||
const notificationList = document.getElementById('notification-list');
|
||||
|
||||
// Show loading bar and hide notification list
|
||||
loadingBar.style.display = 'block';
|
||||
notificationList.classList.add('d-none');
|
||||
|
||||
fetch('/api/notifications')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
notificationList.innerHTML = ''; // Clear existing notifications
|
||||
|
||||
data.forEach(notification => {
|
||||
const item = document.createElement('a');
|
||||
item.href = notification.link || '#';
|
||||
item.classList.add('dropdown-item');
|
||||
item.innerHTML = `
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<div style="display: flex; align-items: center;">
|
||||
<i class="fas fa-bell" style="font-size: 16px; margin-right: 5px;"></i>
|
||||
<strong style="font-size: 12px;">${notification.title}</strong>
|
||||
</div>
|
||||
<span class="text-muted text-sm" style="font-size: 12px !important;">
|
||||
${new Date(notification.created_at).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
<span class="text-muted text-sm" style="font-size: 12px !important;">${notification.content || ''}</span>
|
||||
`;
|
||||
notificationList.appendChild(item);
|
||||
});
|
||||
|
||||
// Hide loading bar and show notification list
|
||||
loadingBar.style.display = 'none';
|
||||
notificationList.classList.remove('d-none');
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching notifications:', error);
|
||||
loadingBar.style.display = 'none';
|
||||
notificationList.innerHTML = '<span class="dropdown-item text-danger">Failed to load notifications.</span>';
|
||||
notificationList.classList.remove('d-none');
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
@@ -307,7 +307,7 @@
|
||||
<tr>
|
||||
<td class="wrapper">
|
||||
<p>Halo {{ $name }},</p>
|
||||
<p>Pengajuan Expense anda telah di periksa & setujui oleh <b>Area Manager Anda</b> Anda:</p>
|
||||
<p>Pengajuan Expense anda telah di periksa & setujui oleh <b>Area Manager</b> Anda:</p>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\Master\CabangController;
|
||||
use App\Http\Controllers\Backend\DashboardController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -20,3 +21,7 @@ use App\Http\Controllers\Master\CabangController;
|
||||
// });
|
||||
|
||||
Route::get('/api/cabang-by-region/{regionCode}', [CabangController::class, 'getCabangByRegion']);
|
||||
|
||||
Route::middleware(['auth:admin', 'menu'])->group(function () {
|
||||
Route::get('/api/notifications', [DashboardController::class, 'notifications']);
|
||||
});
|
||||
@@ -90,6 +90,7 @@ Route::group(['prefix' => 'admin', 'as' => 'admin.', 'middleware' => ['auth:admi
|
||||
|
||||
Route::middleware(['auth:admin', 'menu'])->group(function () {
|
||||
Route::get('/', [DashboardController::class, 'index'])->name('dashboard.index');
|
||||
Route::post('/mark_read', [DashboardController::class, 'mark_read'])->name('dashboard.mark_read');
|
||||
|
||||
Route::prefix('budgets')->group(function () {
|
||||
Route::get('/', [BudgetControlController::class, 'index'])->name('budget_control');
|
||||
|
||||
Reference in New Issue
Block a user