mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-26 04:23:58 +03:00
HR minor fixes (#2245)
This commit is contained in:
parent
1f2ab841b1
commit
29775429d5
@ -21,7 +21,7 @@
|
||||
import view, { BuildModelKey, Viewlet, ViewletPreference } from '@anticrm/view'
|
||||
import { Table, ViewletSettingButton } from '@anticrm/view-resources'
|
||||
import hr from '../../plugin'
|
||||
import { fromTzDate, getMonth, getTotal, tableToCSV, weekDays } from '../../utils'
|
||||
import { fromTzDate, getMonth, getRequestDays, getTotal, tableToCSV, weekDays } from '../../utils'
|
||||
import NumberPresenter from './StatPresenter.svelte'
|
||||
|
||||
export let currentDate: Date = new Date()
|
||||
@ -35,21 +35,14 @@
|
||||
$: wDays = weekDays(month.getUTCFullYear(), month.getUTCMonth())
|
||||
|
||||
function getDateRange (request: Request): string {
|
||||
const st = new Date(fromTzDate(request.tzDate)).getDate()
|
||||
const days =
|
||||
Math.floor(Math.abs((1 + fromTzDate(request.tzDueDate) - fromTzDate(request.tzDate)) / 1000 / 60 / 60 / 24)) + 1
|
||||
const stDate = new Date(fromTzDate(request.tzDate))
|
||||
let ds = Array.from(Array(days).keys()).map((it) => st + it)
|
||||
const type = types.get(request.type)
|
||||
if ((type?.value ?? -1) < 0) {
|
||||
ds = ds.filter((it) => ![0, 6].includes(new Date(stDate.setDate(it)).getDay()))
|
||||
}
|
||||
const ds = getRequestDays(request, types, month.getMonth())
|
||||
return ds.join(' ')
|
||||
}
|
||||
|
||||
function getEndDate (date: Date): number {
|
||||
return new Date(date).setMonth(date.getMonth() + 1)
|
||||
}
|
||||
|
||||
function getRequests (employee: Ref<Staff>, date: Date): Request[] {
|
||||
const requests = employeeRequests.get(employee)
|
||||
if (requests === undefined) return []
|
||||
@ -64,80 +57,89 @@
|
||||
return res
|
||||
}
|
||||
|
||||
$: typevals = new Map<string, BuildModelKey>(
|
||||
Array.from(types.values()).map((it) => [
|
||||
it.label as string,
|
||||
{
|
||||
key: '',
|
||||
label: it.label,
|
||||
presenter: NumberPresenter,
|
||||
props: {
|
||||
month: month ?? getMonth(currentDate, currentDate.getMonth()),
|
||||
display: (req: Request[]) =>
|
||||
req
|
||||
.filter((r) => r.type === it._id)
|
||||
.map((it) => getDateRange(it))
|
||||
.join(' '),
|
||||
getRequests
|
||||
function getTypeVals (month: Date): Map<string, BuildModelKey> {
|
||||
return new Map(
|
||||
Array.from(types.values()).map((it) => [
|
||||
it.label as string,
|
||||
{
|
||||
key: '',
|
||||
label: it.label,
|
||||
presenter: NumberPresenter,
|
||||
props: {
|
||||
month: month ?? getMonth(currentDate, currentDate.getMonth()),
|
||||
display: (req: Request[]) =>
|
||||
req
|
||||
.filter((r) => r.type === it._id)
|
||||
.map((it) => getDateRange(it))
|
||||
.join(' '),
|
||||
getRequests
|
||||
}
|
||||
}
|
||||
}
|
||||
])
|
||||
)
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
$: overrideConfig = new Map<string, BuildModelKey>([
|
||||
[
|
||||
'@wdCount',
|
||||
{
|
||||
key: '',
|
||||
label: getEmbeddedLabel('Working days'),
|
||||
presenter: NumberPresenter,
|
||||
props: {
|
||||
month: month ?? getMonth(currentDate, currentDate.getMonth()),
|
||||
display: (req: Request[]) => wDays + getTotal(req, types),
|
||||
getRequests
|
||||
},
|
||||
sortingKey: '@wdCount',
|
||||
sortingFunction: (a: Doc, b: Doc) =>
|
||||
getTotal(getRequests(b._id as Ref<Staff>, month), types) -
|
||||
getTotal(getRequests(a._id as Ref<Staff>, month), types)
|
||||
}
|
||||
],
|
||||
[
|
||||
'@ptoCount',
|
||||
{
|
||||
key: '',
|
||||
label: getEmbeddedLabel('PTOs'),
|
||||
presenter: NumberPresenter,
|
||||
props: {
|
||||
month: month ?? getMonth(currentDate, currentDate.getMonth()),
|
||||
display: (req: Request[]) => getTotal(req, types, (a) => (a < 0 ? Math.abs(a) : 0)),
|
||||
getRequests
|
||||
},
|
||||
sortingKey: '@ptoCount',
|
||||
sortingFunction: (a: Doc, b: Doc) =>
|
||||
getTotal(getRequests(b._id as Ref<Staff>, month), types, (a) => (a < 0 ? Math.abs(a) : 0)) -
|
||||
getTotal(getRequests(a._id as Ref<Staff>, month), types, (a) => (a < 0 ? Math.abs(a) : 0))
|
||||
}
|
||||
],
|
||||
[
|
||||
'@extraCount',
|
||||
{
|
||||
key: '',
|
||||
label: getEmbeddedLabel('EXTRa'),
|
||||
presenter: NumberPresenter,
|
||||
props: {
|
||||
month: month ?? getMonth(currentDate, currentDate.getMonth()),
|
||||
display: (req: Request[]) => getTotal(req, types, (a) => (a > 0 ? Math.abs(a) : 0)),
|
||||
getRequests
|
||||
},
|
||||
sortingKey: '@extraCount',
|
||||
sortingFunction: (a: Doc, b: Doc) =>
|
||||
getTotal(getRequests(b._id as Ref<Staff>, month), types, (a) => (a > 0 ? Math.abs(a) : 0)) -
|
||||
getTotal(getRequests(a._id as Ref<Staff>, month), types, (a) => (a > 0 ? Math.abs(a) : 0))
|
||||
}
|
||||
],
|
||||
...typevals
|
||||
])
|
||||
function getOverrideConfig (month: Date): Map<string, BuildModelKey> {
|
||||
const typevals = getTypeVals(month)
|
||||
return new Map<string, BuildModelKey>([
|
||||
[
|
||||
'@wdCount',
|
||||
{
|
||||
key: '',
|
||||
label: getEmbeddedLabel('Working days'),
|
||||
presenter: NumberPresenter,
|
||||
props: {
|
||||
month: month ?? getMonth(currentDate, currentDate.getMonth()),
|
||||
display: (req: Request[]) => wDays + getTotal(req, month.getMonth(), types),
|
||||
getRequests
|
||||
},
|
||||
sortingKey: '@wdCount',
|
||||
sortingFunction: (a: Doc, b: Doc) =>
|
||||
getTotal(getRequests(b._id as Ref<Staff>, month), month.getMonth(), types) -
|
||||
getTotal(getRequests(a._id as Ref<Staff>, month), month.getMonth(), types)
|
||||
}
|
||||
],
|
||||
[
|
||||
'@ptoCount',
|
||||
{
|
||||
key: '',
|
||||
label: getEmbeddedLabel('PTOs'),
|
||||
presenter: NumberPresenter,
|
||||
props: {
|
||||
month: month ?? getMonth(currentDate, currentDate.getMonth()),
|
||||
display: (req: Request[]) => getTotal(req, month.getMonth(), types, (a) => (a < 0 ? Math.abs(a) : 0)),
|
||||
getRequests
|
||||
},
|
||||
sortingKey: '@ptoCount',
|
||||
sortingFunction: (a: Doc, b: Doc) =>
|
||||
getTotal(getRequests(b._id as Ref<Staff>, month), month.getMonth(), types, (a) =>
|
||||
a < 0 ? Math.abs(a) : 0
|
||||
) -
|
||||
getTotal(getRequests(a._id as Ref<Staff>, month), month.getMonth(), types, (a) => (a < 0 ? Math.abs(a) : 0))
|
||||
}
|
||||
],
|
||||
[
|
||||
'@extraCount',
|
||||
{
|
||||
key: '',
|
||||
label: getEmbeddedLabel('EXTRa'),
|
||||
presenter: NumberPresenter,
|
||||
props: {
|
||||
month: month ?? getMonth(currentDate, currentDate.getMonth()),
|
||||
display: (req: Request[]) => getTotal(req, month.getMonth(), types, (a) => (a > 0 ? Math.abs(a) : 0)),
|
||||
getRequests
|
||||
},
|
||||
sortingKey: '@extraCount',
|
||||
sortingFunction: (a: Doc, b: Doc) =>
|
||||
getTotal(getRequests(b._id as Ref<Staff>, month), month.getMonth(), types, (a) =>
|
||||
a > 0 ? Math.abs(a) : 0
|
||||
) -
|
||||
getTotal(getRequests(a._id as Ref<Staff>, month), month.getMonth(), types, (a) => (a > 0 ? Math.abs(a) : 0))
|
||||
}
|
||||
],
|
||||
...typevals
|
||||
])
|
||||
}
|
||||
|
||||
const preferenceQuery = createQuery()
|
||||
let preference: ViewletPreference | undefined
|
||||
@ -173,14 +175,16 @@
|
||||
})
|
||||
}
|
||||
|
||||
function createConfig (descr: Viewlet, preference: ViewletPreference | undefined): (string | BuildModelKey)[] {
|
||||
function createConfig (
|
||||
descr: Viewlet,
|
||||
preference: ViewletPreference | undefined,
|
||||
month: Date
|
||||
): (string | BuildModelKey)[] {
|
||||
const base = preference?.config ?? descr.config
|
||||
const result: (string | BuildModelKey)[] = []
|
||||
const overrideConfig = getOverrideConfig(month)
|
||||
|
||||
for (const c of overrideConfig.values()) {
|
||||
base.push(c)
|
||||
}
|
||||
for (const key of base) {
|
||||
for (const key of [...base, ...overrideConfig.values()]) {
|
||||
if (typeof key === 'string') {
|
||||
result.push(overrideConfig.get(key) ?? key)
|
||||
} else {
|
||||
@ -213,7 +217,7 @@
|
||||
link.setAttribute('target', '_blank')
|
||||
link.setAttribute(
|
||||
'href',
|
||||
'data:text/csv;charset=utf-8,' + encodeURIComponent(tableToCSV('exportableData'))
|
||||
'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURIComponent(tableToCSV('exportableData'))
|
||||
)
|
||||
link.setAttribute('download', filename)
|
||||
document.body.appendChild(link)
|
||||
@ -226,7 +230,7 @@
|
||||
tableId={'exportableData'}
|
||||
_class={hr.mixin.Staff}
|
||||
query={{ _id: { $in: departmentStaff.map((it) => it._id) } }}
|
||||
config={createConfig(descr, preference)}
|
||||
config={createConfig(descr, preference, month)}
|
||||
options={descr.options}
|
||||
/>
|
||||
{/if}
|
||||
|
@ -136,7 +136,7 @@
|
||||
<EmployeePresenter value={employee} />
|
||||
</td>
|
||||
<td class="flex-center p-1" class:firstLine={row === 0} class:lastLine={row === departmentStaff.length - 1}>
|
||||
{getTotal(requests, types)}
|
||||
{getTotal(requests, startDate.getMonth(), types)}
|
||||
</td>
|
||||
{#each values as value, i}
|
||||
{@const date = getDay(startDate, value)}
|
||||
|
@ -127,7 +127,7 @@
|
||||
use:tooltip={tooltipValue}
|
||||
>
|
||||
<div class="flex-center">
|
||||
{getTotal(requests, types)}
|
||||
{getTotal(requests, value, types)}
|
||||
</div>
|
||||
</td>
|
||||
{/key}
|
||||
|
@ -2,7 +2,7 @@ import { Employee, formatName } from '@anticrm/contact'
|
||||
import { Ref, TxOperations } from '@anticrm/core'
|
||||
import { Department, Request, RequestType, TzDate } from '@anticrm/hr'
|
||||
import { MessageBox } from '@anticrm/presentation'
|
||||
import { showPopup } from '@anticrm/ui'
|
||||
import { isWeekend, showPopup } from '@anticrm/ui'
|
||||
import hr from './plugin'
|
||||
|
||||
export async function addMember (client: TxOperations, employee?: Employee, value?: Department): Promise<void> {
|
||||
@ -98,22 +98,34 @@ export function getMonth (date: Date, m: number): Date {
|
||||
return date
|
||||
}
|
||||
|
||||
export function getRequestDays (request: Request, types: Map<Ref<RequestType>, RequestType>, month: number): number[] {
|
||||
const type = types.get(request.type)
|
||||
const startDate =
|
||||
request.tzDate.month === month ? fromTzDate(request.tzDate) : fromTzDate({ ...request.tzDate, month, day: 1 })
|
||||
const endDate =
|
||||
request.tzDueDate.month === month
|
||||
? fromTzDate(request.tzDueDate)
|
||||
: fromTzDate({ ...request.tzDueDate, month: month + 1, day: -1 })
|
||||
const days = Math.floor(Math.abs((1 + endDate - startDate) / 1000 / 60 / 60 / 24)) + 1
|
||||
const stDate = new Date(startDate)
|
||||
const stDateDate = stDate.getDate()
|
||||
let ds = Array.from(Array(days).keys()).map((it) => stDateDate + it)
|
||||
if ((type?.value ?? -1) < 0) {
|
||||
ds = ds.filter((it) => !isWeekend(new Date(stDate.setDate(it))))
|
||||
}
|
||||
return ds
|
||||
}
|
||||
|
||||
export function getTotal (
|
||||
requests: Request[],
|
||||
month: number,
|
||||
types: Map<Ref<RequestType>, RequestType>,
|
||||
f: (v: number) => number = (f) => f
|
||||
): number {
|
||||
let total = 0
|
||||
for (const request of requests) {
|
||||
const ds = getRequestDays(request, types, month)
|
||||
const type = types.get(request.type)
|
||||
const days =
|
||||
Math.floor(Math.abs((1 + fromTzDate(request.tzDueDate) - fromTzDate(request.tzDate)) / 1000 / 60 / 60 / 24)) + 1
|
||||
const stDate = new Date(fromTzDate(request.tzDate))
|
||||
const stDateDate = stDate.getDate()
|
||||
let ds = Array.from(Array(days).keys()).map((it) => stDateDate + it)
|
||||
if ((type?.value ?? -1) < 0) {
|
||||
ds = ds.filter((it) => ![0, 6].includes(new Date(stDate.setDate(it)).getDay()))
|
||||
}
|
||||
const val = Math.ceil(ds.length) * (type?.value ?? 0)
|
||||
total += f(val)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user