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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user