add notif expense created
This commit is contained in:
@@ -18,8 +18,10 @@ use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ExpenseApproved;
|
||||
use App\Mail\ExpenseRejected;
|
||||
use App\Mail\FinalApprove;
|
||||
use App\Mail\ExpenseCreated;
|
||||
use App\Helpers\WhatsappHelper;
|
||||
use App\Helpers\AuditTrailHelper;
|
||||
use App\Models\Admin;
|
||||
use App\Rules\FileType;
|
||||
|
||||
class FormEntertainmentPresentationController extends Controller
|
||||
@@ -127,7 +129,6 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$bukti_total->getContent(),
|
||||
$filename
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// Generate sequence number and expense number
|
||||
@@ -136,7 +137,7 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$expense_number = $region->code . '-' . $cabang->code . '-ETY-' . date('ym') . $formatted_sequence_number;
|
||||
|
||||
// Save the form data
|
||||
FormEntertaimentPresentation::create([
|
||||
$form = FormEntertaimentPresentation::create([
|
||||
'expense_number' => $expense_number,
|
||||
'user_id' => auth()->user()->id,
|
||||
'tanggal' => $request->tanggal,
|
||||
@@ -151,6 +152,40 @@ class FormEntertainmentPresentationController extends Controller
|
||||
'status' => 'On Progress',
|
||||
]);
|
||||
|
||||
// Send notification to MIS and Admin Region
|
||||
$roles = ['Marketing Information System', 'Admin Region'];
|
||||
$recipients = [];
|
||||
$phoneNumbers = [];
|
||||
|
||||
$name = auth()->user()->name;
|
||||
$tanggal = $form->tanggal;
|
||||
$total = $form->total;
|
||||
|
||||
// Collect all recipients (emails and phone numbers) for the specified roles
|
||||
foreach ($roles as $role) {
|
||||
$users = Admin::getUserByRoleName($role);
|
||||
foreach ($users as $user) {
|
||||
$recipients[] = $user->email;
|
||||
$phoneNumbers[] = $user->phone;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Generate URL and send WhatsApp notification
|
||||
$url = route('forms.entertainment.view', $form->id);
|
||||
WhatsappHelper::newExpense($phoneNumbers, $expense_number, $url);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseCreated(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total,
|
||||
$url
|
||||
));
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Insert', 'Insert New Expense at Form Entertainment Presentation (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been created.');
|
||||
return redirect()->back();
|
||||
@@ -212,7 +247,6 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$bukti_total->getContent(),
|
||||
$filename
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// Save the form data
|
||||
@@ -253,7 +287,7 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$name = $form->user->name;
|
||||
$expense_number = $form->expense_number;
|
||||
$tanggal = $form->tanggal;
|
||||
$total = $form->total;
|
||||
$total = $form->approved_total;
|
||||
|
||||
// Collect all recipients
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
@@ -273,18 +307,19 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
|
||||
// Send bulk email
|
||||
// Mail::to($recipients)->send(new ExpenseApproved(
|
||||
// $name,
|
||||
// $expense_number,
|
||||
// $tanggal,
|
||||
// $total
|
||||
// ));
|
||||
|
||||
// Send bulk whatsapp
|
||||
$url = route('forms.entertainment.view', $form->id);
|
||||
WhatsappHelper::approveExpense($phoneNumbers, $expense_number, $url);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseApproved(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total,
|
||||
$url
|
||||
));
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Approve', 'Approved Expense at Form Entertainment Presentation (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
@@ -310,7 +345,7 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$name = $form->user->name;
|
||||
$expense_number = $form->expense_number;
|
||||
$tanggal = $form->tanggal;
|
||||
$total = $form->total;
|
||||
$total = $form->approved_total;
|
||||
|
||||
// Collect all recipients
|
||||
$recipients = [$form->user->email, auth()->user()->email];
|
||||
@@ -330,18 +365,19 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$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
|
||||
$url = route('forms.entertainment.view', $form->id);
|
||||
WhatsappHelper::approveExpense($phoneNumbers, $expense_number, $url);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new FinalApprove(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total,
|
||||
$url
|
||||
));
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Final Approve', 'Final Approved Expense at Form Entertainment Presentation (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been final approved.');
|
||||
return redirect()->back();
|
||||
@@ -396,18 +432,19 @@ class FormEntertainmentPresentationController extends Controller
|
||||
$recipients = array_unique($recipients);
|
||||
$phoneNumbers = array_unique($phoneNumbers);
|
||||
|
||||
// Send bulk email
|
||||
// Mail::to($recipients)->send(new ExpenseRejected(
|
||||
// $name,
|
||||
// $expense_number,
|
||||
// $tanggal,
|
||||
// $total
|
||||
// ));
|
||||
|
||||
// Send bulk whatsapp
|
||||
$url = route('forms.entertainment.view', $form->id);
|
||||
WhatsappHelper::approveExpense($phoneNumbers, $expense_number, $url);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseRejected(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total,
|
||||
$url
|
||||
));
|
||||
|
||||
AuditTrailHelper::AddAuditTrail('Reject', 'Reject Expense at Form Entertainment Presentation (' . $expense_number . ')');
|
||||
session()->flash('success', 'Form has been rejected.');
|
||||
return redirect()->back();
|
||||
|
||||
Reference in New Issue
Block a user