Bổ sung check nếu là WFH thì check in cho user

This commit is contained in:
Truong Vo 2024-08-09 14:46:35 +07:00
parent 8b5eadfbcf
commit 688c521986
2 changed files with 61 additions and 31 deletions

View File

@ -13,8 +13,10 @@ use Carbon\Carbon;
use Carbon\CarbonPeriod; use Carbon\CarbonPeriod;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Modules\Admin\app\Models\Admin;
use Modules\Admin\app\Models\Category; use Modules\Admin\app\Models\Category;
use Modules\Admin\app\Models\Ticket; use Modules\Admin\app\Models\Ticket;
use Modules\Admin\app\Models\Tracking;
class TicketController extends Controller class TicketController extends Controller
{ {
@ -288,9 +290,7 @@ class TicketController extends Controller
// Update updated_by and admin_note in tickets table // Update updated_by and admin_note in tickets table
// Send notification email to users // Send notification email to users
if ($action == "confirm") { if ($action == "confirm") {
// dd($results);
foreach ($results as $result) { foreach ($results as $result) {
list($year, $month, $day) = explode('-', $result['date']); list($year, $month, $day) = explode('-', $result['date']);
Notes::create([ Notes::create([
@ -303,35 +303,37 @@ class TicketController extends Controller
'n_note' => $ticket->reason 'n_note' => $ticket->reason
]); ]);
if($ticket->type == "WFH"){ if ($ticket->type == "WFH") {
// $user_ids = $request->users; $type = $result['period'];
// $year = $request->year; $user = Admin::find($ticket->user_id);
// $month = $request->month; $date = Carbon::create($year, $month, $day)->setTimezone(env('TIME_ZONE'));
// $day = $request->day;
// $type = $request->type; //Default: ALL
// foreach ($user_ids as $id) { $start = $date->copy()->setTime(7, 31, 11);
// $user = Admin::find($id); $end = $date->copy()->setTime(17, 1, 11);
// $date = Carbon::create($year, $month, $day)->setTimezone(env('TIME_ZONE'));
// $start = $date->copy()->setTime(7, 31, 11); if ($type == 'S') {
// $end = $type == 'half' ? $date->copy()->setTime(11, 31, 11) : $date->copy()->setTime(17, 1, 11); $end = $date->copy()->setTime(11, 31, 11);
// Tracking::insert([ } else if ($type == 'C') {
// [ $start = $date->copy()->setTime(11, 31, 11);
// 'name' => $user->name, }
// 'user_id' => $user->id,
// 'status' => 'check in', Tracking::insert([
// 'time_string' => $start->format('Y-m-d H:i:s'), [
// 'created_at' => $start->setTimezone('UTC') 'name' => $user->name,
// ], 'user_id' => $user->id,
// [ 'status' => 'check in',
// 'name' => $user->name, 'time_string' => $start->format('Y-m-d H:i:s'),
// 'user_id' => $user->id, 'created_at' => $start->setTimezone('UTC')
// 'status' => 'check out', ],
// 'time_string' => $end->format('Y-m-d H:i:s'), [
// 'created_at' => $end->setTimezone('UTC') 'name' => $user->name,
// ] 'user_id' => $user->id,
// ]); 'status' => 'check out',
// } 'time_string' => $end->format('Y-m-d H:i:s'),
// $this->createOrUpdateRecordForCurrentMonth($month, $year); 'created_at' => $end->setTimezone('UTC')
]
]);
} }
} }

View File

@ -911,6 +911,13 @@ const Timekeeping = () => {
id: user.user.id, id: user.user.id,
name: user.user.name, name: user.user.name,
}, },
notes:
user.history.find(
(h) =>
h.day === d &&
h.notes &&
h.notes.length > 0,
)?.notes ?? [],
}) })
}} }}
/> />
@ -938,6 +945,13 @@ const Timekeeping = () => {
id: user.user.id, id: user.user.id,
name: user.user.name, name: user.user.name,
}, },
notes:
user.history.find(
(h) =>
h.day === d &&
h.notes &&
h.notes.length > 0,
)?.notes ?? [],
}) })
}} }}
/> />
@ -966,6 +980,13 @@ const Timekeeping = () => {
id: user.user.id, id: user.user.id,
name: user.user.name, name: user.user.name,
}, },
notes:
user.history.find(
(h) =>
h.day === d &&
h.notes &&
h.notes.length > 0,
)?.notes ?? [],
}) })
}} }}
/> />
@ -1029,6 +1050,13 @@ const Timekeeping = () => {
id: user.user.id, id: user.user.id,
name: user.user.name, name: user.user.name,
}, },
notes:
user.history.find(
(h) =>
h.day === d &&
h.notes &&
h.notes.length > 0,
)?.notes ?? [],
}) })
}} }}
/> />