Bổ sung tooltip ngày nghỉ , tổng ngày nghỉ, custom màu cho cột total, off, remaining
This commit is contained in:
		
							parent
							
								
									f87db7cda5
								
							
						
					
					
						commit
						5e0c48e3b9
					
				| 
						 | 
					@ -31,25 +31,41 @@ class LeaveManagementController extends Controller
 | 
				
			||||||
            $join->on('notes.n_time_type', '=', 'categories.c_code')
 | 
					            $join->on('notes.n_time_type', '=', 'categories.c_code')
 | 
				
			||||||
                ->where('categories.c_type', 'TIME_TYPE');
 | 
					                ->where('categories.c_type', 'TIME_TYPE');
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					            ->leftJoin("categories as reason", function ($join) {
 | 
				
			||||||
 | 
					                $join->on('n_reason', '=', 'reason.c_code');
 | 
				
			||||||
 | 
					                $join->on('reason.c_type', DB::raw("CONCAT('REASON')"));
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
            ->select(
 | 
					            ->select(
 | 
				
			||||||
                DB::raw('notes.n_user_id as n_user_id'),
 | 
					                DB::raw('notes.n_user_id as n_user_id'),
 | 
				
			||||||
 | 
					                DB::raw('notes.n_time_type as time_type'),
 | 
				
			||||||
                DB::raw('notes.n_year as year'),
 | 
					                DB::raw('notes.n_year as year'),
 | 
				
			||||||
                DB::raw('notes.n_month as month'),
 | 
					                DB::raw('notes.n_month as month'),
 | 
				
			||||||
                DB::raw('SUM(categories.c_value) as leave_days')
 | 
					                DB::raw('categories.c_value as leave_days'),
 | 
				
			||||||
 | 
					                DB::raw('notes.n_day as day'),
 | 
				
			||||||
 | 
					                'reason.c_name as reason_name',
 | 
				
			||||||
 | 
					                'categories.c_name as time_type_name',
 | 
				
			||||||
 | 
					                // DB::raw('SUM(categories.c_value) as leave_days')
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					            // ->where('notes.n_user_id', "1")
 | 
				
			||||||
            ->where('notes.n_year', $year)
 | 
					            ->where('notes.n_year', $year)
 | 
				
			||||||
            ->where('notes.n_reason', 'ONLEAVE')
 | 
					            ->where('notes.n_reason', 'ONLEAVE')
 | 
				
			||||||
            ->groupBy("notes.n_user_id", DB::raw('notes.n_month'), DB::raw('notes.n_year'))
 | 
					            // ->groupBy("notes.n_user_id")
 | 
				
			||||||
 | 
					            ->orderBy('notes.n_month')
 | 
				
			||||||
 | 
					            ->orderBy('notes.n_day')
 | 
				
			||||||
            ->get()
 | 
					            ->get()
 | 
				
			||||||
            ->map(function ($item) {
 | 
					            ->map(function ($item) {
 | 
				
			||||||
                return [
 | 
					                return [
 | 
				
			||||||
 | 
					                    "day" => $item->day,
 | 
				
			||||||
                    "n_user_id" => $item->n_user_id,
 | 
					                    "n_user_id" => $item->n_user_id,
 | 
				
			||||||
 | 
					                    // "time_type" => $item->time_type,
 | 
				
			||||||
 | 
					                    "reason_name" => $item->reason_name,
 | 
				
			||||||
 | 
					                    "time_type_name" => $item->time_type_name,
 | 
				
			||||||
                    "month" => $item->month,
 | 
					                    "month" => $item->month,
 | 
				
			||||||
                    "leave_days" => $item->leave_days
 | 
					                    "leave_days" => $item->leave_days
 | 
				
			||||||
                ];
 | 
					                ];
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            ->toArray();
 | 
					            ->toArray();
 | 
				
			||||||
 | 
					        // dd($totalLeaveDaysByMonth);
 | 
				
			||||||
        $leaveDays = LeaveDays::join('users', 'leave_days.ld_user_id', '=', 'users.id')
 | 
					        $leaveDays = LeaveDays::join('users', 'leave_days.ld_user_id', '=', 'users.id')
 | 
				
			||||||
            ->select(
 | 
					            ->select(
 | 
				
			||||||
                'leave_days.*',
 | 
					                'leave_days.*',
 | 
				
			||||||
| 
						 | 
					@ -65,7 +81,6 @@ class LeaveManagementController extends Controller
 | 
				
			||||||
            ->where('leave_days.ld_year', $year)
 | 
					            ->where('leave_days.ld_year', $year)
 | 
				
			||||||
            ->get()
 | 
					            ->get()
 | 
				
			||||||
            ->map(function ($item) use ($totalLeaveDaysByMonth) {
 | 
					            ->map(function ($item) use ($totalLeaveDaysByMonth) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
                $monthlyLeaveDays = [];
 | 
					                $monthlyLeaveDays = [];
 | 
				
			||||||
                foreach ($totalLeaveDaysByMonth as $key => $totalDays) {
 | 
					                foreach ($totalLeaveDaysByMonth as $key => $totalDays) {
 | 
				
			||||||
                    if ($item->ld_user_id == $totalDays["n_user_id"]) {
 | 
					                    if ($item->ld_user_id == $totalDays["n_user_id"]) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,8 +46,12 @@ interface LeaveDay {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface MonthlyLeaveDays {
 | 
					interface MonthlyLeaveDays {
 | 
				
			||||||
  month: number
 | 
					  day: number
 | 
				
			||||||
  leave_days: number
 | 
					  leave_days: number
 | 
				
			||||||
 | 
					  month: number
 | 
				
			||||||
 | 
					  n_user_id: number
 | 
				
			||||||
 | 
					  reason_name: string
 | 
				
			||||||
 | 
					  time_type_name: string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface UserData {
 | 
					interface UserData {
 | 
				
			||||||
| 
						 | 
					@ -198,6 +202,28 @@ const LeaveManagement = () => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // console.log(customAddNotes, 'customAddNotes')
 | 
					  // console.log(customAddNotes, 'customAddNotes')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const getDetailLeaveDay = (monthlyLeaveDays: MonthlyLeaveDays[]) => {
 | 
				
			||||||
 | 
					    type MonthlyLeaveDaysAcc = {
 | 
				
			||||||
 | 
					      [key: string]: { n_user_id: number; month: number; leave_days: number }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const summedLeaveDaysByUserAndMonth = monthlyLeaveDays.reduce(
 | 
				
			||||||
 | 
					      (acc: MonthlyLeaveDaysAcc, record) => {
 | 
				
			||||||
 | 
					        const { n_user_id, month, leave_days } = record
 | 
				
			||||||
 | 
					        const key = `${month}`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!acc[key]) {
 | 
				
			||||||
 | 
					          acc[key] = { n_user_id, month, leave_days: 0 }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        acc[key].leave_days += Number(leave_days)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return acc
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {},
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    return summedLeaveDaysByUserAndMonth
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
      <div className={classes.title}>
 | 
					      <div className={classes.title}>
 | 
				
			||||||
| 
						 | 
					@ -279,7 +305,7 @@ const LeaveManagement = () => {
 | 
				
			||||||
          onClick={() => {
 | 
					          onClick={() => {
 | 
				
			||||||
            setDisableBtn(true)
 | 
					            setDisableBtn(true)
 | 
				
			||||||
            if (
 | 
					            if (
 | 
				
			||||||
              customAddNotes.id === 0 
 | 
					              customAddNotes.id === 0
 | 
				
			||||||
              // ||
 | 
					              // ||
 | 
				
			||||||
              // customAddNotes.totalLeave === '' ||
 | 
					              // customAddNotes.totalLeave === '' ||
 | 
				
			||||||
              // customAddNotes.totalLeave === '0'
 | 
					              // customAddNotes.totalLeave === '0'
 | 
				
			||||||
| 
						 | 
					@ -409,28 +435,95 @@ const LeaveManagement = () => {
 | 
				
			||||||
                  </Table.Td>
 | 
					                  </Table.Td>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  {monthInYear.map((d, i) => {
 | 
					                  {monthInYear.map((d, i) => {
 | 
				
			||||||
                    let total =
 | 
					                    let leaveDataByMonth = getDetailLeaveDay(
 | 
				
			||||||
                      user.monthlyLeaveDays.find((item) => {
 | 
					                      user.monthlyLeaveDays,
 | 
				
			||||||
                        return item.month == d.value
 | 
					                    )
 | 
				
			||||||
                      })?.leave_days ?? 0
 | 
					
 | 
				
			||||||
 | 
					                    const monthData = leaveDataByMonth[d.value]
 | 
				
			||||||
 | 
					                    let total = monthData ? monthData.leave_days : 0
 | 
				
			||||||
                    totalDayOff = totalDayOff + total
 | 
					                    totalDayOff = totalDayOff + total
 | 
				
			||||||
                    return (
 | 
					                    return (
 | 
				
			||||||
                      <Table.Td bg={total > 0 ? '#ffb5b5' : ''} key={i} ta={'center'}>
 | 
					                      <Table.Td
 | 
				
			||||||
                        {total === 0 ? '' : total}
 | 
					                        bg={total > 0 ? '#ffb5b5' : ''}
 | 
				
			||||||
 | 
					                        key={i}
 | 
				
			||||||
 | 
					                        ta={'center'}
 | 
				
			||||||
 | 
					                      >
 | 
				
			||||||
 | 
					                        <Tooltip
 | 
				
			||||||
 | 
					                          multiline
 | 
				
			||||||
 | 
					                          label={user.monthlyLeaveDays
 | 
				
			||||||
 | 
					                            .filter((item) => item.month === d.value)
 | 
				
			||||||
 | 
					                            .map((itemDay, indexDay) => {
 | 
				
			||||||
 | 
					                              return (
 | 
				
			||||||
 | 
					                                <p key={indexDay}>
 | 
				
			||||||
 | 
					                                  - Xin {itemDay.reason_name} (
 | 
				
			||||||
 | 
					                                  {itemDay.time_type_name}) {itemDay.day}/
 | 
				
			||||||
 | 
					                                  {itemDay.month}
 | 
				
			||||||
 | 
					                                </p>
 | 
				
			||||||
 | 
					                              )
 | 
				
			||||||
 | 
					                            })}
 | 
				
			||||||
 | 
					                        >
 | 
				
			||||||
 | 
					                          <p>{total === 0 ? '' : total}</p>
 | 
				
			||||||
 | 
					                        </Tooltip>
 | 
				
			||||||
                      </Table.Td>
 | 
					                      </Table.Td>
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                  })}
 | 
					                  })}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                  <Table.Td ta={'center'}>{totalDayLeave}</Table.Td>
 | 
					                  <Table.Td
 | 
				
			||||||
                  <Table.Td ta={'center'} bg={'#ffb5b5'}>{totalDayOff}</Table.Td>
 | 
					                    ta={'center'}
 | 
				
			||||||
                  <Table.Td ta={'center'} bg={'#c3ffc3'}>
 | 
					                    bg={totalDayLeave > 0 ? '#92e6f2' : ''}
 | 
				
			||||||
 | 
					                  >
 | 
				
			||||||
 | 
					                    {totalDayLeave}
 | 
				
			||||||
 | 
					                  </Table.Td>
 | 
				
			||||||
 | 
					                  <Table.Td ta={'center'} bg={totalDayOff > 0 ? '#ffb5b5' : ''}>
 | 
				
			||||||
 | 
					                    {totalDayOff > 0 ? (
 | 
				
			||||||
 | 
					                      <Tooltip
 | 
				
			||||||
 | 
					                        multiline
 | 
				
			||||||
 | 
					                        label={user.monthlyLeaveDays.map(
 | 
				
			||||||
 | 
					                          (itemDay, indexDay) => {
 | 
				
			||||||
 | 
					                            return (
 | 
				
			||||||
 | 
					                              <p key={indexDay}>
 | 
				
			||||||
 | 
					                                - Xin {itemDay.reason_name} (
 | 
				
			||||||
 | 
					                                {itemDay.time_type_name}) {itemDay.day}/
 | 
				
			||||||
 | 
					                                {itemDay.month}
 | 
				
			||||||
 | 
					                              </p>
 | 
				
			||||||
 | 
					                            )
 | 
				
			||||||
 | 
					                          },
 | 
				
			||||||
 | 
					                        )}
 | 
				
			||||||
 | 
					                      >
 | 
				
			||||||
 | 
					                        <p> {totalDayOff}</p>
 | 
				
			||||||
 | 
					                      </Tooltip>
 | 
				
			||||||
 | 
					                    ) : (
 | 
				
			||||||
 | 
					                      <></>
 | 
				
			||||||
 | 
					                    )}
 | 
				
			||||||
 | 
					                  </Table.Td>
 | 
				
			||||||
 | 
					                  <Table.Td
 | 
				
			||||||
 | 
					                    ta={'center'}
 | 
				
			||||||
 | 
					                    bg={
 | 
				
			||||||
 | 
					                      totalDayLeave - totalDayOff == 0
 | 
				
			||||||
 | 
					                        ? ''
 | 
				
			||||||
 | 
					                        : totalDayLeave - totalDayOff > 0
 | 
				
			||||||
 | 
					                        ? '#c3ffc3'
 | 
				
			||||||
 | 
					                        : '#ffb5b5'
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                  >
 | 
				
			||||||
                    {totalDayLeave - totalDayOff}
 | 
					                    {totalDayLeave - totalDayOff}
 | 
				
			||||||
                  </Table.Td>
 | 
					                  </Table.Td>
 | 
				
			||||||
                  <Table.Td>
 | 
					                  <Table.Td>
 | 
				
			||||||
                    <Box style={{display: ld_note === "" || ld_note === null? 'none' : 'block'}}>
 | 
					                    <Box
 | 
				
			||||||
                      <HoverCard width={280} shadow="md" >
 | 
					                      style={{
 | 
				
			||||||
 | 
					                        display:
 | 
				
			||||||
 | 
					                          ld_note === '' || ld_note === null ? 'none' : 'block',
 | 
				
			||||||
 | 
					                      }}
 | 
				
			||||||
 | 
					                    >
 | 
				
			||||||
 | 
					                      <HoverCard width={280} shadow="md">
 | 
				
			||||||
                        <HoverCard.Target>
 | 
					                        <HoverCard.Target>
 | 
				
			||||||
                          <Text fz={'sm'}>{ld_note !== null && ld_note !== "" &&  ld_note.length > 25 ?ld_note.slice(0,25)+"..." : ld_note}</Text>
 | 
					                          <Text fz={'sm'}>
 | 
				
			||||||
 | 
					                            {ld_note !== null &&
 | 
				
			||||||
 | 
					                            ld_note !== '' &&
 | 
				
			||||||
 | 
					                            ld_note.length > 25
 | 
				
			||||||
 | 
					                              ? ld_note.slice(0, 25) + '...'
 | 
				
			||||||
 | 
					                              : ld_note}
 | 
				
			||||||
 | 
					                          </Text>
 | 
				
			||||||
                        </HoverCard.Target>
 | 
					                        </HoverCard.Target>
 | 
				
			||||||
                        <HoverCard.Dropdown>
 | 
					                        <HoverCard.Dropdown>
 | 
				
			||||||
                          <Textarea size="sm" autosize>
 | 
					                          <Textarea size="sm" autosize>
 | 
				
			||||||
| 
						 | 
					@ -444,7 +537,7 @@ const LeaveManagement = () => {
 | 
				
			||||||
                    <IconEdit
 | 
					                    <IconEdit
 | 
				
			||||||
                      color="green"
 | 
					                      color="green"
 | 
				
			||||||
                      width={20}
 | 
					                      width={20}
 | 
				
			||||||
                      style={{cursor:'pointer'}}
 | 
					                      style={{ cursor: 'pointer' }}
 | 
				
			||||||
                      onClick={() => {
 | 
					                      onClick={() => {
 | 
				
			||||||
                        let totalLeave =
 | 
					                        let totalLeave =
 | 
				
			||||||
                          user.leaveDay.ld_day == 0
 | 
					                          user.leaveDay.ld_day == 0
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue