diff --git a/be/app/Http/Controllers/SubTaskController.php b/be/app/Http/Controllers/SubTaskController.php index 74f4ef6..8c9ea77 100644 --- a/be/app/Http/Controllers/SubTaskController.php +++ b/be/app/Http/Controllers/SubTaskController.php @@ -51,12 +51,15 @@ class SubTaskController extends Controller return response()->json($validator->errors(), 400); } + $start = Carbon::parse($parameters['start']); + $end = Carbon::parse($parameters['end'])->addDay(); + if (isset($parameters['team_id'])) { $subtasks = SubTask::whereHas('mastertask', function ($query) use ($parameters) { $query->where('team_id', $parameters['team_id']); - })->whereHas('timeblocks', function ($query) use ($parameters) { - $query->where('start', '>', $parameters['start']); - $query->where('end', '<=', $parameters['end']); + })->whereHas('timeblocks', function ($query) use ($start, $end) { + $query->where('start', '>', $start); + $query->where('end', '<', $end); })->get(); $userIdArray = User::whereHas('teams', function ($query) use ($parameters) { @@ -64,15 +67,15 @@ class SubTaskController extends Controller })->get()->pluck('id')->toArray(); } else if (isset($parameters['user_id'])) { - $subtasks = SubTask::where('user_id', $parameters['user_id'])->whereHas('timeblocks', function ($query) use ($parameters) { - $query->where('start', '>', $parameters['start']); - $query->where('end', '<=', $parameters['end']); + $subtasks = SubTask::where('user_id', $parameters['user_id'])->whereHas('timeblocks', function ($query) use ($start, $end) { + $query->where('start', '>', $start); + $query->where('end', '<', $end); })->get(); $userIdArray = [$parameters['user_id']]; } - $blockers = Blocker::whereIn('user_id', $userIdArray)->where('start', '>=', $parameters['start'])->where('end', '<=', $parameters['end'])->get(); + $blockers = Blocker::whereIn('user_id', $userIdArray)->where('start', '>', $start)->where('end', '<', $end)->get(); return response()->json([ 'subtasks' => SubTaskResource::collection($subtasks), diff --git a/be/app/Listeners/SendEditedMasterTaskNotification.php b/be/app/Listeners/SendEditedMasterTaskNotification.php index a33b846..97737e4 100644 --- a/be/app/Listeners/SendEditedMasterTaskNotification.php +++ b/be/app/Listeners/SendEditedMasterTaskNotification.php @@ -43,7 +43,7 @@ class SendEditedMasterTaskNotification implements ShouldQueue $modelDiff = array_diff_assoc($editedMasterTaskArray, $originalMasterTaskArray); foreach ( $modelDiff as $key => $diff ) { - if (in_array($key, ['status'])) { + if (in_array($key, ['status', 'tracked_time'])) { continue; } diff --git a/be/app/Listeners/SendEditedSubTaskNotification.php b/be/app/Listeners/SendEditedSubTaskNotification.php index c8f0c18..ff9ac70 100644 --- a/be/app/Listeners/SendEditedSubTaskNotification.php +++ b/be/app/Listeners/SendEditedSubTaskNotification.php @@ -3,11 +3,12 @@ namespace App\Listeners; use App\Events\SubTaskEdited; +use App\Models\User; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Facades\Mail; -class SendEditedSubTaskNotification +class SendEditedSubTaskNotification implements ShouldQueue { /** * Create the event listener. @@ -56,6 +57,15 @@ class SendEditedSubTaskNotification continue; } + // ukoncenie sub tasku - Pokiaľ je sub task ukončený s vyšším počtom vykázaných hodín ako bol pôvodne zadaný, posiela sa e-mailová notifikácia o tejto skutočnosti zadávateľovi master tasku (soft warning). + if ($key == 'is_finished' && $diff == 1 && $event->subtask->tracked_time > $event->subtask->estimated_time) { +// $creatorEmail = User::find($event->subtask->created_by)->email; + +// Mail::to( $creatorEmail )->send( new \App\Mail\SubTaskFinishedWithHigherTrackedTime( $event->subtask ) ); + Mail::to( 'feher@studiotem.com' )->send( new \App\Mail\SubTaskFinishedWithHigherTrackedTime( $event->subtask ) ); + + } + $difference[$key] = $diff; } diff --git a/be/app/Mail/SubTaskFinishedWithHigherTrackedTime.php b/be/app/Mail/SubTaskFinishedWithHigherTrackedTime.php new file mode 100644 index 0000000..02f1a06 --- /dev/null +++ b/be/app/Mail/SubTaskFinishedWithHigherTrackedTime.php @@ -0,0 +1,62 @@ +subtask = $subtask; + } + + /** + * Get the message envelope. + * + * @return \Illuminate\Mail\Mailables\Envelope + */ + public function envelope() + { + return new Envelope( + subject: 'Sub Task Finished With Higher Tracked Time Than Estimated' + ); + } + + /** + * Get the message content definition. + * + * @return \Illuminate\Mail\Mailables\Content + */ + public function content() + { + return new Content( + view: 'emails.task.sub_task_finished_with_higher_tracked_time' + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments() + { + return []; + } +} diff --git a/be/resources/views/emails/task/sub_task_finished_with_higher_tracked_time.blade.php b/be/resources/views/emails/task/sub_task_finished_with_higher_tracked_time.blade.php new file mode 100644 index 0000000..9ea7625 --- /dev/null +++ b/be/resources/views/emails/task/sub_task_finished_with_higher_tracked_time.blade.php @@ -0,0 +1,3 @@ +Sub Task {{$subtask->mastertask->title}} finished with higher tracker time than estimated.

+Estimated: {{$subtask->estimated_time}}
+Tracked: {{$subtask->tracked_time}}