update add multiple record
This commit is contained in:
parent
2b60501980
commit
0151d29450
|
|
@ -43,10 +43,12 @@ class TimekeepingController extends Controller
|
|||
$date = Carbon::create($now->year, $now->month, $i)->setTimezone(env('TIME_ZONE'))->format('Y-m-d');
|
||||
// Kiểm tra xem có mục nào trong $history có created_at trùng với $date
|
||||
$hasEntry = $history->filter(function ($entry) use ($date, $admin) {
|
||||
// echo($hasEntry);
|
||||
return Carbon::parse($entry->created_at)->setTimezone(env('TIME_ZONE'))->format('Y-m-d') === $date && $entry->user_id == $admin->id;
|
||||
});
|
||||
});
|
||||
// echo($hasEntry);
|
||||
|
||||
if (count($hasEntry) > 0) {
|
||||
if (count($hasEntry) > 0) {
|
||||
$values = array_values($hasEntry->toArray());
|
||||
$last_checkin = null;
|
||||
$total = 0;
|
||||
|
|
@ -71,4 +73,37 @@ class TimekeepingController extends Controller
|
|||
}
|
||||
return response()->json(['status'=> true, 'data'=>$result]);
|
||||
}
|
||||
|
||||
public function addWorkingTimeForMultipleUser(Request $request)
|
||||
{
|
||||
$user_ids = $request->users;
|
||||
$year = $request->year;
|
||||
$month = $request->month;
|
||||
$day = $request->day;
|
||||
$type = $request->type;
|
||||
foreach($user_ids as $id){
|
||||
$user = Admin::find($id);
|
||||
$date = Carbon::create($year, $month, $day)->setTimezone(env('TIME_ZONE'));
|
||||
$start = $date->copy()->setTime(7, 31, 11);
|
||||
$end = $type == 'half' ? $date->copy()->setTime(11, 31, 11) : $date->copy()->setTime(17, 1, 11);
|
||||
Tracking::insert([
|
||||
[
|
||||
'name' => $user->name,
|
||||
'user_id' => $user->id,
|
||||
'status' => 'check in',
|
||||
'time_string' => $start ->format('Y-m-d H:i:s'),
|
||||
'created_at' => $start->setTimezone('UTC')
|
||||
],
|
||||
[
|
||||
'name' => $user->name,
|
||||
'user_id' => $user->id,
|
||||
'status' => 'check out',
|
||||
'time_string' => $end->format('Y-m-d H:i:s'),
|
||||
'created_at' => $end->setTimezone('UTC')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json(['status'=> true, 'message'=> 'Add successfully']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ Route::middleware('api')
|
|||
'prefix' => 'timekeeping',
|
||||
], function () {
|
||||
Route::get('/', [TimekeepingController::class, 'get'])->middleware('check.permission:admin.hr.staff');
|
||||
Route::post('/addMutilple', [TimekeepingController::class, 'addWorkingTimeForMultipleUser'])->middleware('check.permission:admin.hr');
|
||||
});
|
||||
|
||||
Route::group([
|
||||
|
|
|
|||
|
|
@ -66,3 +66,4 @@ export const getAllUserWorklogs = API_URL + 'v1/admin/jira/worklogs'
|
|||
|
||||
//Timekeeping
|
||||
export const getTheTimesheet = API_URL + 'v1/admin/timekeeping'
|
||||
export const updateMultipleUserWorkingTime = API_URL + 'v1/admin/timekeeping/addMutilple'
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
import { getTheTimesheet } from '@/api/Admin'
|
||||
import { getTheTimesheet, updateMultipleUserWorkingTime } from '@/api/Admin'
|
||||
import { get } from '@/rtk/helpers/apiService'
|
||||
import { Box, Image, Select, Table, Text, TextInput, Tooltip } from '@mantine/core'
|
||||
import { Box, Image, Menu, Select, Table, Text, TextInput, Tooltip } from '@mantine/core'
|
||||
import { IconCheck, IconExclamationMark, IconX } from '@tabler/icons-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import classes from './Timekeeping.module.css'
|
||||
import { notifications } from '@mantine/notifications'
|
||||
import moment from 'moment'
|
||||
import { update } from '@/rtk/helpers/CRUD'
|
||||
|
||||
interface User {
|
||||
id: number
|
||||
|
|
@ -60,7 +61,7 @@ const Timekeeping = () => {
|
|||
if (res.status) {
|
||||
setData(
|
||||
res.data.filter((u: UserData) =>
|
||||
!u.user.email.includes('admin'),
|
||||
u.user.permission.includes('staff'),
|
||||
),
|
||||
)
|
||||
setDaysInMonth(
|
||||
|
|
@ -101,6 +102,20 @@ const Timekeeping = () => {
|
|||
return days.getDate()
|
||||
}
|
||||
|
||||
const updateMultipleUser = async(users:number[], day:number, type:string)=>{
|
||||
try {
|
||||
await update(updateMultipleUserWorkingTime, {
|
||||
users: users,
|
||||
year: date.year,
|
||||
month: date.month,
|
||||
day:day,
|
||||
type: type
|
||||
}, getTimeSheet)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getTimeSheet()
|
||||
}, [date])
|
||||
|
|
@ -149,7 +164,7 @@ const Timekeeping = () => {
|
|||
}}/>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box w="70%" style={{display:'flex', alignItems:'end', justifyContent:"space-evenly"}}>
|
||||
<Box w="70%" pl={200} style={{display:'flex', alignItems:'end', justifyContent:"space-evenly"}}>
|
||||
<Box style={{display:'flex', alignItems:'center'}}>
|
||||
<IconCheck
|
||||
size={20}
|
||||
|
|
@ -219,9 +234,24 @@ const Timekeeping = () => {
|
|||
<Table.Th></Table.Th>
|
||||
{daysInMonth.map((d) => {
|
||||
return (
|
||||
<Table.Th key={d} ta={'center'}>
|
||||
{d}
|
||||
</Table.Th>
|
||||
<Menu width={200} shadow="md">
|
||||
<Menu.Target>
|
||||
<Table.Th key={d} ta={'center'} style={{cursor:"pointer"}}>
|
||||
<span>{d}</span>
|
||||
</Table.Th>
|
||||
</Menu.Target>
|
||||
|
||||
<Menu.Dropdown>
|
||||
<Menu.Item onClick={()=>updateMultipleUser(data.map((u)=>u.user.id), d, 'half')}>
|
||||
+ Add half a day's work
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
onClick={()=>updateMultipleUser(data.map((u)=>u.user.id), d, 'one')}
|
||||
>
|
||||
+ Add 1 day of work
|
||||
</Menu.Item>
|
||||
</Menu.Dropdown>
|
||||
</Menu>
|
||||
)
|
||||
})}
|
||||
</Table.Tr>
|
||||
|
|
|
|||
Loading…
Reference in New Issue