Files

90 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2025-01-17 16:17:53 +07:00
<?php
namespace App\Helpers;
use App\Models\Notifications;
use InvalidArgumentException;
class NotificationHelper
{
2025-01-23 17:46:38 +07:00
public static function newExpense($expense_type, $expense_id, $user_id, $expense_number, $receiver_ids = [])
2025-01-17 16:17:53 +07:00
{
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',
2025-01-23 17:46:38 +07:00
'expense_type' => $expense_type,
'expense_id' => $expense_id,
2025-01-17 16:17:53 +07:00
'created_at' => now(),
'updated_at' => now(),
];
}
// Lakukan batch insert
Notifications::insert($notifications);
}
2025-01-23 17:46:38 +07:00
public static function approveExpense($expense_type, $expense_id, $user_id, $expense_number, $receiver_ids = [])
2025-01-17 16:17:53 +07:00
{
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',
2025-01-23 17:46:38 +07:00
'expense_type' => $expense_type,
'expense_id' => $expense_id,
2025-01-17 16:17:53 +07:00
'created_at' => now(),
'updated_at' => now(),
];
}
// Lakukan batch insert
Notifications::insert($notifications);
}
2025-01-23 17:46:38 +07:00
public static function approve2Expense($expense_type, $expense_id, $user_id, $expense_number, $receiver_ids = [])
2025-01-17 16:17:53 +07:00
{
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',
2025-01-23 17:46:38 +07:00
'expense_type' => $expense_type,
'expense_id' => $expense_id,
2025-01-17 16:17:53 +07:00
'created_at' => now(),
'updated_at' => now(),
];
}
// Lakukan batch insert
Notifications::insert($notifications);
}
}