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');
|
$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
|
// 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) {
|
$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;
|
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());
|
$values = array_values($hasEntry->toArray());
|
||||||
$last_checkin = null;
|
$last_checkin = null;
|
||||||
$total = 0;
|
$total = 0;
|
||||||
|
|
@ -71,4 +73,37 @@ class TimekeepingController extends Controller
|
||||||
}
|
}
|
||||||
return response()->json(['status'=> true, 'data'=>$result]);
|
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',
|
'prefix' => 'timekeeping',
|
||||||
], function () {
|
], function () {
|
||||||
Route::get('/', [TimekeepingController::class, 'get'])->middleware('check.permission:admin.hr.staff');
|
Route::get('/', [TimekeepingController::class, 'get'])->middleware('check.permission:admin.hr.staff');
|
||||||
|
Route::post('/addMutilple', [TimekeepingController::class, 'addWorkingTimeForMultipleUser'])->middleware('check.permission:admin.hr');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::group([
|
Route::group([
|
||||||
|
|
|
||||||
|
|
@ -65,4 +65,5 @@ export const getAllIssuesByProject = API_URL + 'v1/admin/jira/all-issue-by-proje
|
||||||
export const getAllUserWorklogs = API_URL + 'v1/admin/jira/worklogs'
|
export const getAllUserWorklogs = API_URL + 'v1/admin/jira/worklogs'
|
||||||
|
|
||||||
//Timekeeping
|
//Timekeeping
|
||||||
export const getTheTimesheet = API_URL + 'v1/admin/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 { 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 { IconCheck, IconExclamationMark, IconX } from '@tabler/icons-react'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import classes from './Timekeeping.module.css'
|
import classes from './Timekeeping.module.css'
|
||||||
import { notifications } from '@mantine/notifications'
|
import { notifications } from '@mantine/notifications'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
import { update } from '@/rtk/helpers/CRUD'
|
||||||
|
|
||||||
interface User {
|
interface User {
|
||||||
id: number
|
id: number
|
||||||
|
|
@ -60,7 +61,7 @@ const Timekeeping = () => {
|
||||||
if (res.status) {
|
if (res.status) {
|
||||||
setData(
|
setData(
|
||||||
res.data.filter((u: UserData) =>
|
res.data.filter((u: UserData) =>
|
||||||
!u.user.email.includes('admin'),
|
u.user.permission.includes('staff'),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
setDaysInMonth(
|
setDaysInMonth(
|
||||||
|
|
@ -101,6 +102,20 @@ const Timekeeping = () => {
|
||||||
return days.getDate()
|
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(() => {
|
useEffect(() => {
|
||||||
getTimeSheet()
|
getTimeSheet()
|
||||||
}, [date])
|
}, [date])
|
||||||
|
|
@ -149,7 +164,7 @@ const Timekeeping = () => {
|
||||||
}}/>
|
}}/>
|
||||||
</Box>
|
</Box>
|
||||||
</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'}}>
|
<Box style={{display:'flex', alignItems:'center'}}>
|
||||||
<IconCheck
|
<IconCheck
|
||||||
size={20}
|
size={20}
|
||||||
|
|
@ -219,9 +234,24 @@ const Timekeeping = () => {
|
||||||
<Table.Th></Table.Th>
|
<Table.Th></Table.Th>
|
||||||
{daysInMonth.map((d) => {
|
{daysInMonth.map((d) => {
|
||||||
return (
|
return (
|
||||||
<Table.Th key={d} ta={'center'}>
|
<Menu width={200} shadow="md">
|
||||||
{d}
|
<Menu.Target>
|
||||||
</Table.Th>
|
<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>
|
</Table.Tr>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue