added email notifications on expense approved/rejected (whatsapp tmr)
This commit is contained in:
@@ -14,6 +14,9 @@ use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ExpenseApproved;
|
||||
use App\Mail\ExpenseRejected;
|
||||
|
||||
class FormEntertainmentPresentationController extends Controller
|
||||
{
|
||||
@@ -245,6 +248,34 @@ class FormEntertainmentPresentationController extends Controller
|
||||
'status' => 'Approved'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseApproved(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
}
|
||||
@@ -293,6 +324,34 @@ class FormEntertainmentPresentationController extends Controller
|
||||
'status' => 'Rejected'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseRejected(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been rejected.');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ExpenseApproved;
|
||||
use App\Mail\ExpenseRejected;
|
||||
|
||||
class FormMeetingSeminarController extends Controller
|
||||
{
|
||||
@@ -231,6 +234,34 @@ class FormMeetingSeminarController extends Controller
|
||||
'status' => 'Approved'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseApproved(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
}
|
||||
@@ -279,6 +310,34 @@ class FormMeetingSeminarController extends Controller
|
||||
'status' => 'Rejected'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseRejected(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been rejected.');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ExpenseApproved;
|
||||
use App\Mail\ExpenseRejected;
|
||||
|
||||
|
||||
class FormOtherController extends Controller
|
||||
{
|
||||
@@ -236,6 +240,34 @@ class FormOtherController extends Controller
|
||||
'status' => 'Approved'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseApproved(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
}
|
||||
@@ -284,6 +316,34 @@ class FormOtherController extends Controller
|
||||
'status' => 'Rejected'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseRejected(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been rejected.');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ExpenseApproved;
|
||||
use App\Mail\ExpenseRejected;
|
||||
|
||||
class FormUpCountryController extends Controller
|
||||
{
|
||||
@@ -253,6 +256,34 @@ class FormUpCountryController extends Controller
|
||||
'status' => 'Approved'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseApproved(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
}
|
||||
@@ -266,6 +297,34 @@ class FormUpCountryController extends Controller
|
||||
'status' => 'Rejected'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseRejected(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been rejected.');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ use App\Models\UserHasCabang;
|
||||
use App\Models\Kategori;
|
||||
use App\Helpers\NextCloudHelper;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ExpenseApproved;
|
||||
use App\Mail\ExpenseRejected;
|
||||
|
||||
class FormVehicleController extends Controller
|
||||
{
|
||||
@@ -246,6 +249,34 @@ class FormVehicleController extends Controller
|
||||
'status' => 'Approved'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseApproved(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->back();
|
||||
}
|
||||
@@ -294,6 +325,34 @@ class FormVehicleController extends Controller
|
||||
'status' => 'Rejected'
|
||||
]);
|
||||
|
||||
$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];
|
||||
|
||||
if ($heads['cabang_head']) {
|
||||
$recipients[] = $heads['cabang_head']['email'];
|
||||
}
|
||||
|
||||
if ($heads['region_head']) {
|
||||
$recipients[] = $heads['region_head']['email'];
|
||||
}
|
||||
|
||||
// Remove duplicate email addresses, if any
|
||||
$recipients = array_unique($recipients);
|
||||
|
||||
// Send bulk email
|
||||
Mail::to($recipients)->send(new ExpenseRejected(
|
||||
$name,
|
||||
$expense_number,
|
||||
$tanggal,
|
||||
$total
|
||||
));
|
||||
|
||||
session()->flash('success', 'Form has been rejected.');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ExpenseApproved extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $name,
|
||||
protected string $expense_number,
|
||||
protected string $tanggal,
|
||||
protected int $total,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Expense Approved',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'mail.approved',
|
||||
with: [
|
||||
'name' => $this->name,
|
||||
'expense_number' => $this->expense_number,
|
||||
'tanggal' => $this->tanggal,
|
||||
'total' => $this->total,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ExpenseRejected extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $name,
|
||||
protected string $expense_number,
|
||||
protected string $tanggal,
|
||||
protected int $total,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Expense Rejected',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'mail.rejected',
|
||||
with: [
|
||||
'name' => $this->name,
|
||||
'expense_number' => $this->expense_number,
|
||||
'tanggal' => $this->tanggal,
|
||||
'total' => $this->total,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -77,4 +77,31 @@ class Admin extends Authenticatable
|
||||
}
|
||||
return $hasPermission;
|
||||
}
|
||||
|
||||
public function getCabangAndRegionHead()
|
||||
{
|
||||
// Fetch the UserHasCabang entry for this admin
|
||||
$userHasCabang = $this->hasOne(UserHasCabang::class, 'user_id')->with('cabang')->first();
|
||||
|
||||
if ($userHasCabang && $userHasCabang->cabang) {
|
||||
$cabang = $userHasCabang->cabang;
|
||||
|
||||
// Fetch the cabang head
|
||||
$cabangHead = $cabang->head;
|
||||
|
||||
// Fetch the region and its head
|
||||
$region = $cabang->region;
|
||||
$regionHead = $region ? $region->head : null;
|
||||
|
||||
return [
|
||||
'cabang_head' => $cabangHead,
|
||||
'region_head' => $regionHead,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'cabang_head' => null,
|
||||
'region_head' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,20 @@ class Cabang extends Model
|
||||
|
||||
protected $table = 'cabang';
|
||||
protected $fillable = [
|
||||
'head_id',
|
||||
'region_id',
|
||||
'cost_id',
|
||||
'code',
|
||||
'name',
|
||||
];
|
||||
|
||||
public function head()
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'head_id');
|
||||
}
|
||||
|
||||
public function region()
|
||||
{
|
||||
return $this->belongsTo(Region::class, 'region_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,13 @@ class Region extends Model
|
||||
|
||||
protected $table = 'region';
|
||||
protected $fillable = [
|
||||
'head_id',
|
||||
'code',
|
||||
'name',
|
||||
];
|
||||
|
||||
public function head()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Admin');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user