Commit cc004fe3 by Azhan Hannan

Email function → send email to project director when successfully add new project team.

parent 8cfcc7e7
......@@ -6,7 +6,7 @@
<a class="ui blue left ribbon label">List of Project Team</a>
<a href="{{ route('timesheet::maintenance.penambahanProjectTeam', ['id' => $pid]) }} " class="ui right floated small primary labeled icon button"><i class="plus icon"></i>Add New Project Team</a>
<br>
<table class="ui celled structured unstackable table">
<table class="ui celled structured unstackable table" style="margin-bottom: 0px;">
<thead>
<tr>
<th>No</th>
......@@ -71,10 +71,20 @@
@endforeach
</tbody>
</table>
<i><p style="margin-bottom: 11px;"><a style="color: red"><strong>*</strong></a>Please click the 'Send Email Notification' button after finished adding the project team to infom the project director.</p></i>
<button class="center aligned ui teal compact labeled icon button" onclick="window.location.href='{{ route('timesheet::maintenance.senaraiProject', [ 'id' => $pid ]) }}';">
<i class="angle double left icon"></i>
Back
</button>
</div>
<a href="{{ route('timesheet::maintenance.mailAddProjectTeam', ['id' => $pid]) }}" class="ui right floated small orange labeled icon button" onclick="email()"><i class="envelope icon"></i>Send Email Notification</a>
</div>
@endsection
@push('script')
<script type="text/javascript">
function email() {
alert('Are you sure you have finished add all project team?');
}
</script>
@endpush
\ No newline at end of file
......@@ -629,57 +629,57 @@ class MaintenanceController extends Controller
// dd($staffs);
// email start
$user = Staff_info::where('fk_users', Auth::id())->first();
// $user = Staff_info::where('fk_users', Auth::id())->first();
$project = Project::where('id', $request->pid)
->with('projectManager')
->with('projectDirector')
->first();
// $project = Project::where('id', $request->pid)
// ->with('projectManager')
// ->with('projectDirector')
// ->first();
$pteam = Pteam::where('fk_project_id', $request->pid)
->whereIn('pt_staff_id', $staffs)
->with('toRole')
->with('editor')
->get();
// $pteam = Pteam::where('fk_project_id', $request->pid)
// ->whereIn('pt_staff_id', $staffs)
// ->with('toRole')
// ->with('editor')
// ->get();
if (env('EMAIL_ENV') == 'local')
{
$mailTo = '143hannan@gmail.com';
}
elseif (env('EMAIL_ENV') == 'DEVELOPMENT')
{
$mailTo = '3fetimesheet@gmail.com';
}
elseif (env('EMAIL_ENV') == 'PRODUCTION')
{
$mailTo = data_get($project,'projectDirector.email');
}
// if (env('EMAIL_ENV') == 'local')
// {
// $mailTo = '143hannan@gmail.com';
// }
// elseif (env('EMAIL_ENV') == 'DEVELOPMENT')
// {
// $mailTo = '3fetimesheet@gmail.com';
// }
// elseif (env('EMAIL_ENV') == 'PRODUCTION')
// {
// $mailTo = data_get($project,'projectDirector.email');
// }
// dd($pteam);
$data_staffs = [];
foreach ($pteam as $key => $team) {
$data_staffs[] = [
'no' => $key,
'name' => data_get($team,'pt_team'),
'role' => data_get($team,'toRole.role'),
'status' => data_get($team,'pt_project_task_sts'),
'editor' => data_get($team,'editor.fullname'),
];
}
// $data_staffs = [];
// foreach ($pteam as $key => $team) {
// $data_staffs[] = [
// 'no' => $key,
// 'name' => data_get($team,'pt_team'),
// 'role' => data_get($team,'toRole.role'),
// 'status' => data_get($team,'pt_project_task_sts'),
// 'editor' => data_get($team,'editor.fullname'),
// ];
// }
$data_email = [
'subject' => 'Timesheet Project: New Project Team Added',
'sender_name' => '3fetimesheet@gmail.com',
'pcode' => data_get($project,'p_project_code'),
'projectmanager' => data_get($project,'projectManager.fullname'),
'projectdirector' => data_get($project,'projectDirector.fullname'),
'projectname' => data_get($project,'p_project_description'),
'username' => data_get($user,'fullname'),
'status' => data_get($project,'p_project_sts'),
];
// $data_email = [
// 'subject' => 'Timesheet Project: New Project Team Added',
// 'sender_name' => '3fetimesheet@gmail.com',
// 'pcode' => data_get($project,'p_project_code'),
// 'projectmanager' => data_get($project,'projectManager.fullname'),
// 'projectdirector' => data_get($project,'projectDirector.fullname'),
// 'projectname' => data_get($project,'p_project_description'),
// 'username' => data_get($user,'fullname'),
// 'status' => data_get($project,'p_project_sts'),
// ];
Mail::to($mailTo)->send(new AddProjectTeam($data_email, $data_staffs));
// Mail::to($mailTo)->send(new AddProjectTeam($data_email, $data_staffs));
// return new AddProjectTeam($data_email, $data_staffs);
}
......@@ -1081,18 +1081,22 @@ class MaintenanceController extends Controller
// return redirect()->route('timesheet::dashboard.index')->withSuccess('Project has been edited');
}
public function mailAddProjectTeam()
public function mailAddProjectTeam(Request $request)
{
// dd($request->id);
$id = $request->id;
$user = Staff_info::where('fk_users', Auth::id())->first();
$project = Project::where('id', 1)
$project = Project::where('id', $request->id)
->with('projectManager')
->with('projectDirector')
->first();
$pteam = Pteam::where('fk_project_id', 1)
// ->where('role_id', 12)
$pteam = Pteam::where('fk_project_id', $request->id)
->where('role_id', '<>', 7)
->with('toRole')
->with('editor')
->get();
// dd($pteam);
......@@ -1103,10 +1107,11 @@ class MaintenanceController extends Controller
$data_staffs = [];
foreach ($pteam as $key => $team) {
$data_staffs[] = [
'no' => $key,
'no' => $key+1,
'name' => data_get($team,'pt_team'),
'role' => data_get($team,'toRole.role'),
'status' => data_get($team,'pt_project_task_sts'),
'editor' => data_get($team,'editor.fullname'),
];
}
......@@ -1124,7 +1129,9 @@ class MaintenanceController extends Controller
'status' => data_get($project,'p_project_sts'),
];
// Mail::to($mailTo)->send(new AddProjectTeam($data_email, $data_staffs));
return new AddProjectTeam($data_email, $data_staffs);
Mail::to($mailTo)->send(new AddProjectTeam($data_email, $data_staffs));
// return new AddProjectTeam($data_email, $data_staffs);
return redirect()->route('timesheet::maintenance.senaraiProjectTeam', compact('id'))->withSuccess('You have successfully added all project team. The list of project team have been forwarded to the Project Director.');
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ New project @if(count($data_staffs) > 1)members @else member @endif : <br>
<tbody>
@foreach($data_staffs as $key => $staff)
<tr>
<td style="border: black 1px solid;"> {!! $key+1 !!} </td>
<td style="border: black 1px solid; width: 4%;"> {!! $key+1 !!} </td>
<td style="border: black 1px solid;"> {!! ucwords(strtolower($staff['name'])) !!} </td>
<td style="border: black 1px solid;"> {!! ucwords(strtolower($staff['role'])) !!} </td>
<td style="border: black 1px solid; width: 10%;"> @if( $staff['status'] == 1) Active @else Inactive @endif </td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment