84 lines
2.3 KiB
PHP
84 lines
2.3 KiB
PHP
|
|
<?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);
|
||
|
|
}
|
||
|
|
}
|