Commit cc004fe3 by Azhan Hannan

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

parent 8cfcc7e7
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<a class="ui blue left ribbon label">List of Project Team</a> <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> <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> <br>
<table class="ui celled structured unstackable table"> <table class="ui celled structured unstackable table" style="margin-bottom: 0px;">
<thead> <thead>
<tr> <tr>
<th>No</th> <th>No</th>
...@@ -71,10 +71,20 @@ ...@@ -71,10 +71,20 @@
@endforeach @endforeach
</tbody> </tbody>
</table> </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 ]) }}';"> <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> <i class="angle double left icon"></i>
Back Back
</button> </button>
<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> </div>
@endsection @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 ...@@ -629,57 +629,57 @@ class MaintenanceController extends Controller
// dd($staffs); // dd($staffs);
// email start // 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) // $project = Project::where('id', $request->pid)
->with('projectManager') // ->with('projectManager')
->with('projectDirector') // ->with('projectDirector')
->first(); // ->first();
$pteam = Pteam::where('fk_project_id', $request->pid) // $pteam = Pteam::where('fk_project_id', $request->pid)
->whereIn('pt_staff_id', $staffs) // ->whereIn('pt_staff_id', $staffs)
->with('toRole') // ->with('toRole')
->with('editor') // ->with('editor')
->get(); // ->get();
if (env('EMAIL_ENV') == 'local') // if (env('EMAIL_ENV') == 'local')
{ // {
$mailTo = '143hannan@gmail.com'; // $mailTo = '143hannan@gmail.com';
} // }
elseif (env('EMAIL_ENV') == 'DEVELOPMENT') // elseif (env('EMAIL_ENV') == 'DEVELOPMENT')
{ // {
$mailTo = '3fetimesheet@gmail.com'; // $mailTo = '3fetimesheet@gmail.com';
} // }
elseif (env('EMAIL_ENV') == 'PRODUCTION') // elseif (env('EMAIL_ENV') == 'PRODUCTION')
{ // {
$mailTo = data_get($project,'projectDirector.email'); // $mailTo = data_get($project,'projectDirector.email');
} // }
// dd($pteam); // dd($pteam);
$data_staffs = []; // $data_staffs = [];
foreach ($pteam as $key => $team) { // foreach ($pteam as $key => $team) {
$data_staffs[] = [ // $data_staffs[] = [
'no' => $key, // 'no' => $key,
'name' => data_get($team,'pt_team'), // 'name' => data_get($team,'pt_team'),
'role' => data_get($team,'toRole.role'), // 'role' => data_get($team,'toRole.role'),
'status' => data_get($team,'pt_project_task_sts'), // 'status' => data_get($team,'pt_project_task_sts'),
'editor' => data_get($team,'editor.fullname'), // 'editor' => data_get($team,'editor.fullname'),
]; // ];
} // }
$data_email = [ // $data_email = [
'subject' => 'Timesheet Project: New Project Team Added', // 'subject' => 'Timesheet Project: New Project Team Added',
'sender_name' => '3fetimesheet@gmail.com', // 'sender_name' => '3fetimesheet@gmail.com',
'pcode' => data_get($project,'p_project_code'), // 'pcode' => data_get($project,'p_project_code'),
'projectmanager' => data_get($project,'projectManager.fullname'), // 'projectmanager' => data_get($project,'projectManager.fullname'),
'projectdirector' => data_get($project,'projectDirector.fullname'), // 'projectdirector' => data_get($project,'projectDirector.fullname'),
'projectname' => data_get($project,'p_project_description'), // 'projectname' => data_get($project,'p_project_description'),
'username' => data_get($user,'fullname'), // 'username' => data_get($user,'fullname'),
'status' => data_get($project,'p_project_sts'), // '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); // return new AddProjectTeam($data_email, $data_staffs);
} }
...@@ -1081,18 +1081,22 @@ class MaintenanceController extends Controller ...@@ -1081,18 +1081,22 @@ class MaintenanceController extends Controller
// return redirect()->route('timesheet::dashboard.index')->withSuccess('Project has been edited'); // 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(); $user = Staff_info::where('fk_users', Auth::id())->first();
$project = Project::where('id', 1) $project = Project::where('id', $request->id)
->with('projectManager') ->with('projectManager')
->with('projectDirector') ->with('projectDirector')
->first(); ->first();
$pteam = Pteam::where('fk_project_id', 1) $pteam = Pteam::where('fk_project_id', $request->id)
// ->where('role_id', 12) ->where('role_id', '<>', 7)
->with('toRole') ->with('toRole')
->with('editor')
->get(); ->get();
// dd($pteam); // dd($pteam);
...@@ -1103,10 +1107,11 @@ class MaintenanceController extends Controller ...@@ -1103,10 +1107,11 @@ class MaintenanceController extends Controller
$data_staffs = []; $data_staffs = [];
foreach ($pteam as $key => $team) { foreach ($pteam as $key => $team) {
$data_staffs[] = [ $data_staffs[] = [
'no' => $key, 'no' => $key+1,
'name' => data_get($team,'pt_team'), 'name' => data_get($team,'pt_team'),
'role' => data_get($team,'toRole.role'), 'role' => data_get($team,'toRole.role'),
'status' => data_get($team,'pt_project_task_sts'), 'status' => data_get($team,'pt_project_task_sts'),
'editor' => data_get($team,'editor.fullname'),
]; ];
} }
...@@ -1124,7 +1129,9 @@ class MaintenanceController extends Controller ...@@ -1124,7 +1129,9 @@ class MaintenanceController extends Controller
'status' => data_get($project,'p_project_sts'), '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); // 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> ...@@ -44,7 +44,7 @@ New project @if(count($data_staffs) > 1)members @else member @endif : <br>
<tbody> <tbody>
@foreach($data_staffs as $key => $staff) @foreach($data_staffs as $key => $staff)
<tr> <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['name'])) !!} </td>
<td style="border: black 1px solid;"> {!! ucwords(strtolower($staff['role'])) !!} </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> <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