, filteredDepartments as Department[])
+ })
+ }
+ return map
+ }
{#if departmentStaff.length}
- {#if mode === CalendarMode.Year}
-
- {:else if mode === CalendarMode.Month}
- {#if display === 'chart'}
-
- {:else if display === 'stats'}
-
+ {#await getDepartmentsForEmployee(departmentStaff) then staffDepartmentMap}
+ {#if mode === CalendarMode.Year}
+
+ {:else if mode === CalendarMode.Month}
+ {#if display === 'chart'}
+
+ {:else if display === 'stats'}
+
+ {/if}
{/if}
- {/if}
+ {/await}
{:else}
diff --git a/plugins/hr-resources/src/components/schedule/CreatePublicHoliday.svelte b/plugins/hr-resources/src/components/schedule/CreatePublicHoliday.svelte
index ccdeb6e078..d3ec655617 100644
--- a/plugins/hr-resources/src/components/schedule/CreatePublicHoliday.svelte
+++ b/plugins/hr-resources/src/components/schedule/CreatePublicHoliday.svelte
@@ -13,8 +13,8 @@
// limitations under the License.
-->
+
+{#await display(value, month) then _value}
+ {_value}
+{/await}
diff --git a/plugins/hr-resources/src/components/schedule/MonthTableView.svelte b/plugins/hr-resources/src/components/schedule/MonthTableView.svelte
index 9b667221ae..d5b4564c62 100644
--- a/plugins/hr-resources/src/components/schedule/MonthTableView.svelte
+++ b/plugins/hr-resources/src/components/schedule/MonthTableView.svelte
@@ -30,6 +30,7 @@
import hr from '../../plugin'
import {
EmployeeReports,
+ getHolidayDatesForEmployee,
getEndDate,
getMonth,
getRequestDates,
@@ -41,6 +42,8 @@
} from '../../utils'
import StatPresenter from './StatPresenter.svelte'
import ReportPresenter from './ReportPresenter.svelte'
+ import HolidayPresenter from './HolidayPresenter.svelte'
+ import { Department } from '@hcengineering/hr'
export let currentDate: Date = new Date()
@@ -49,13 +52,21 @@
export let employeeRequests: Map[, Request[]>
export let timeReports: Map][, EmployeeReports>
- export let holidays: Date[] | undefined = undefined
-
+ export let holidays: Map][, Date[]> = new Map][, Date[]>()
+ export let getHolidays: (month: Date) => Promise]
- it._id) } }}
- config={createConfig(descr, preference, month)}
- options={descr.options}
- />
+ {#await createConfig(descr, preference, month) then config}
+ it._id) } }}
+ {config}
+ options={descr.options}
+ />
+ {/await}
{/if}
{/if}
diff --git a/plugins/hr-resources/src/components/schedule/MonthView.svelte b/plugins/hr-resources/src/components/schedule/MonthView.svelte
index ea4e4e10fb..01adb62bc1 100644
--- a/plugins/hr-resources/src/components/schedule/MonthView.svelte
+++ b/plugins/hr-resources/src/components/schedule/MonthView.svelte
@@ -35,7 +35,7 @@
tooltip
} from '@hcengineering/ui'
import hr from '../../plugin'
- import { EmployeeReports, getRequests, getTotal } from '../../utils'
+ import { EmployeeReports, getHolidayDatesForEmployee, getRequests, getTotal, isHoliday } from '../../utils'
import CreateRequest from '../CreateRequest.svelte'
import RequestsPopup from '../RequestsPopup.svelte'
import ScheduleRequests from '../ScheduleRequests.svelte'
@@ -81,9 +81,16 @@
const noWeekendHolidayType: Ref[] = [hr.ids.PTO, hr.ids.PTO2, hr.ids.Vacation]
- function getTooltip (requests: Request[], day: Date): LabelAndProps | undefined {
+ function getTooltip (requests: Request[], day: Date, staff: Staff): LabelAndProps | undefined {
if (requests.length === 0) return
- if (day && isWeekend(day) && requests.some((req) => noWeekendHolidayType.includes(req.type))) return
+ if (
+ day &&
+ (isWeekend(day) ||
+ (holidays?.size > 0 && isHoliday(getHolidayDatesForEmployee(staffDepartmentMap, staff._id, holidays), day))) &&
+ requests.some((req) => noWeekendHolidayType.includes(req.type))
+ ) {
+ return
+ }
return {
component: RequestsPopup,
props: { requests: requests.map((it) => it._id) }
@@ -124,10 +131,8 @@
showPopup(CreatePublicHoliday, { date, department })
}
- export let holidays: Date[] | undefined = undefined
- function isHoliday (holidays: Date[], day: Date): boolean {
- return holidays && holidays.some((date) => areDatesEqual(day, date))
- }
+ export let staffDepartmentMap: Map[, Department[]>
+ export let holidays: Map][, Date[]>
{#if departmentStaff.length}
@@ -144,7 +149,7 @@
{@const day = getDay(startDate, value)}
] {
@@ -174,7 +179,13 @@
class:firstLine={row === 0}
class:lastLine={row === departmentStaff.length - 1}
>
- {getTotal(requests, startDate, endDate, types, holidays)}
+ {getTotal(
+ requests,
+ startDate,
+ endDate,
+ types,
+ getHolidayDatesForEmployee(staffDepartmentMap, employee._id, holidays)
+ )}
|
|
0} class="h-full w-full">
{#if requests.length}
-
+
{/if}
|
@@ -230,7 +251,13 @@
- {getTotal(Array.from(employeeRequests.values()).flat(), startDate, endDate, types, holidays)}
+ {getTotal(
+ Array.from(employeeRequests.values()).flat(),
+ startDate,
+ endDate,
+ types,
+ [...holidays.values()].flat()
+ )}
|
{floorFractionDigits(
@@ -242,11 +269,10 @@
|
{#each values as value, i}
{@const day = getDay(startDate, value)}
- {@const requests = getRequests(employeeRequests, day)}
{
hoveredColumn = i
@@ -255,7 +281,7 @@
hoveredColumn = -1
}}
>
- {getTotal(requests, day, day, types, holidays)}
+ {getTotal([...employeeRequests.values()].flat(), day, day, types, [...holidays.values()].flat())}
|
{/each}
@@ -329,6 +355,9 @@
&.weekend:not(.today) {
background-color: var(--accent-bg-color);
}
+ &.holiday:not(.today) {
+ background-color: var(--system-error-60-color);
+ }
}
td:not(:last-child) {
border-right: 1px solid var(--divider-color);
diff --git a/plugins/hr-resources/src/components/schedule/StatPresenter.svelte b/plugins/hr-resources/src/components/schedule/StatPresenter.svelte
index adc8c6481d..32e4f106a8 100644
--- a/plugins/hr-resources/src/components/schedule/StatPresenter.svelte
+++ b/plugins/hr-resources/src/components/schedule/StatPresenter.svelte
@@ -18,12 +18,12 @@
import { Request, Staff } from '@hcengineering/hr'
export let value: Staff
- export let display: (requests: Request[]) => number | string
+ export let display: (requests: Request[], staff: Staff) => number | string
export let month: Date
export let getStatRequests: (employee: Ref, date: Date) => Request[]
$: reqs = getStatRequests(value._id, month)
- $: _value = display(reqs)
+ $: _value = display(reqs, value)
{_value}
diff --git a/plugins/hr-resources/src/components/schedule/YearView.svelte b/plugins/hr-resources/src/components/schedule/YearView.svelte
index b0b3c4d7ab..cdd5ef2dd5 100644
--- a/plugins/hr-resources/src/components/schedule/YearView.svelte
+++ b/plugins/hr-resources/src/components/schedule/YearView.svelte
@@ -19,8 +19,17 @@
import type { Request, RequestType, Staff } from '@hcengineering/hr'
import { Label, LabelAndProps, Scroller, tableHRscheduleY, tooltip } from '@hcengineering/ui'
import hr from '../../plugin'
- import { getEndDate, getRequests, getStartDate, getTotal, isToday, weekDays } from '../../utils'
+ import {
+ getHolidayDatesForEmployee,
+ getEndDate,
+ getRequests,
+ getStartDate,
+ getTotal,
+ isToday,
+ weekDays
+ } from '../../utils'
import RequestsPopup from '../RequestsPopup.svelte'
+ import { Department } from '@hcengineering/hr'
export let currentDate: Date = new Date()
@@ -29,7 +38,8 @@
export let employeeRequests: Map[, Request[]>
- export let holidays: Date[] | undefined = undefined
+ export let holidays: Map][, Date[]>
+ export let staffDepartmentMap: Map][, Department[]>
function getTooltip (requests: Request[]): LabelAndProps | undefined {
if (requests.length === 0) return
@@ -102,7 +112,13 @@
{#key tooltipValue}
]
- {getTotal(requests, startDate, endDate, types, holidays)}
+ {getTotal(
+ requests,
+ startDate,
+ endDate,
+ types,
+ getHolidayDatesForEmployee(staffDepartmentMap, employee._id, holidays)
+ )}
|
{/key}
@@ -116,10 +132,15 @@
{#each values as value, i}
{@const startDate = getStartDate(currentDate.getFullYear(), value)}
{@const endDate = getEndDate(currentDate.getFullYear(), value)}
- {@const requests = getRequests(employeeRequests, startDate, endDate)}
- {getTotal(requests, startDate, endDate, types, holidays)}
+ {getTotal(
+ [...employeeRequests.values()].flat(),
+ startDate,
+ endDate,
+ types,
+ [...holidays.values()].flat()
+ )}
|
{/each}
diff --git a/plugins/hr-resources/src/utils.ts b/plugins/hr-resources/src/utils.ts
index d94935b296..00f624ce5c 100644
--- a/plugins/hr-resources/src/utils.ts
+++ b/plugins/hr-resources/src/utils.ts
@@ -226,6 +226,25 @@ export function tableToCSV (tableId: string, separator = ','): string {
return csv.join('\n')
}
+export function getHolidayDatesForEmployee (
+ departmentMap: Map[, Department[]>,
+ employee: Ref,
+ holidays: Map][, Date[]>
+): Date[] {
+ if (departmentMap === undefined || departmentMap.size === 0) return []
+ const deps = departmentMap.get(employee)
+ if (deps === undefined) return []
+ if (holidays.size === 0) return []
+ const dates = []
+ for (const dep of deps) {
+ const depDates = holidays?.get(dep._id)
+ if (depDates !== undefined) {
+ dates.push(...depDates)
+ }
+ }
+ return dates
+}
+
export interface EmployeeReports {
reports: TimeSpendReport[]
tasks: Map][, Issue>
]