added final approval (close) expense notification

This commit is contained in:
Jagad R R
2024-12-26 13:49:00 +07:00
parent 4c6d6859a0
commit 87714a7738
10 changed files with 629 additions and 6 deletions
@@ -17,6 +17,7 @@ use App\Helpers\NextCloudHelper;
use Illuminate\Support\Facades\Mail;
use App\Mail\ExpenseApproved;
use App\Mail\ExpenseRejected;
use App\Mail\FinalApprove;
use App\Helpers\WhatsappHelper;
class FormOtherController extends Controller
@@ -296,6 +297,41 @@ class FormOtherController extends Controller
'status' => 'Closed'
]);
$heads = $form->user->getCabangAndRegionHead();
$name = $form->user->name;
$expense_number = $form->expense_number;
$tanggal = $form->tanggal;
$total = $form->total;
// Collect all recipients
$recipients = [$form->user->email, auth()->user()->email];
$phoneNumbers = [$form->user->phone, auth()->user()->phone];
if ($heads['cabang_head']) {
$recipients[] = $heads['cabang_head']['email'];
$phoneNumbers[] = $heads['cabang_head']['phone'];
}
if ($heads['region_head']) {
$recipients[] = $heads['region_head']['email'];
$phoneNumbers[] = $heads['region_head']['phone'];
}
// Remove duplicate email addresses, if any
$recipients = array_unique($recipients);
$phoneNumbers = array_unique($phoneNumbers);
// Send bulk email
Mail::to($recipients)->send(new FinalApprove(
$name,
$expense_number,
$tanggal,
$total
));
// send whatsapp message
WhatsappHelper::finalApprove($phoneNumbers, $expense_number);
session()->flash('success', 'Form has been final approved.');
return redirect()->back();
}