added notifications

This commit is contained in:
Jagad R R
2025-01-17 16:17:53 +07:00
parent 47eb2950ef
commit f4a8972a1d
13 changed files with 344 additions and 9 deletions
+83
View File
@@ -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);
}
}