TSK-485: Calendar Year/Month summary (#2465)

Signed-off-by: Denis Maslennikov <denis.maslennikov@gmail.com>
This commit is contained in:
Denis Maslennikov 2022-12-23 00:48:46 +07:00 committed by GitHub
parent 4479c65796
commit d7dd260016
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 8 deletions

View File

@ -22,6 +22,7 @@
"RequestType": "Type", "RequestType": "Type",
"CreateRequest": "Create {type}", "CreateRequest": "Create {type}",
"Today": "Today", "Today": "Today",
"Summary": "Total",
"NoEmployeesInDepartment": "There are no employees in the selected department", "NoEmployeesInDepartment": "There are no employees in the selected department",
"Vacation": "Vacation", "Vacation": "Vacation",
"Sick": "Sick", "Sick": "Sick",

View File

@ -22,6 +22,7 @@
"RequestType": "Тип", "RequestType": "Тип",
"CreateRequest": "Создать {type}", "CreateRequest": "Создать {type}",
"Today": "Сегодня", "Today": "Сегодня",
"Summary": "Итого",
"NoEmployeesInDepartment": "Нет сотрудников в выбранном департаменте", "NoEmployeesInDepartment": "Нет сотрудников в выбранном департаменте",
"Vacation": "Отпуск", "Vacation": "Отпуск",
"Sick": "Больничный", "Sick": "Больничный",

View File

@ -92,8 +92,10 @@
for (const request of res) { for (const request of res) {
const requests = employeeRequests.get(request.attachedTo) ?? [] const requests = employeeRequests.get(request.attachedTo) ?? []
requests.push(request) requests.push(request)
if (request.attachedTo) {
employeeRequests.set(request.attachedTo, requests) employeeRequests.set(request.attachedTo, requests)
} }
}
employeeRequests = employeeRequests employeeRequests = employeeRequests
} }
) )

View File

@ -52,8 +52,13 @@
const todayDate = new Date() const todayDate = new Date()
function getRequests (employee: Ref<Staff>, date: Date): Request[] { function getRequests (date: Date, employee?: Ref<Staff>): Request[] {
const requests = employeeRequests.get(employee) let requests = undefined
if (employee) {
requests = employeeRequests.get(employee)
} else {
requests = Array.from(employeeRequests.values()).flat()
}
if (requests === undefined) return [] if (requests === undefined) return []
const res: Request[] = [] const res: Request[] = []
const time = date.getTime() const time = date.getTime()
@ -176,7 +181,7 @@
</td> </td>
{#each values as value, i} {#each values as value, i}
{@const date = getDay(startDate, value)} {@const date = getDay(startDate, value)}
{@const requests = getRequests(employee._id, date)} {@const requests = getRequests(date, employee._id)}
{@const editable = isEditable(employee)} {@const editable = isEditable(employee)}
{@const tooltipValue = getTooltip(requests)} {@const tooltipValue = getTooltip(requests)}
{@const ww = findReports(employee, date, timeReports)} {@const ww = findReports(employee, date, timeReports)}
@ -208,6 +213,40 @@
{/each} {/each}
</tr> </tr>
{/each} {/each}
<tr>
<td class="summary">
<Label label={hr.string.Summary} />
</td>
<td class="flex-center p-1 whitespace-nowrap text-center summary">
{getTotal(Array.from(employeeRequests.values()).flat(), startDate.getMonth(), types)}
</td>
<td class="p-1 text-center summary">
{floorFractionDigits(
Array.from(timeReports.values())
.flat()
.reduce((a, b) => a + b.value, 0),
3
)}
</td>
{#each values as value, i}
{@const date = getDay(startDate, value)}
{@const requests = getRequests(date)}
<td
class="p-1 text-center summary"
class:hovered={i === hoveredIndex}
class:weekend={isWeekend(date)}
class:today={areDatesEqual(todayDate, date)}
on:mousemove={() => {
hoveredColumn = i
}}
on:mouseleave={() => {
hoveredColumn = -1
}}
>
{getTotal(requests, startDate.getMonth(), types)}
</td>
{/each}
</tr>
</tbody> </tbody>
</table> </table>
</Scroller> </Scroller>
@ -269,6 +308,9 @@
&.today { &.today {
background-color: var(--theme-bg-accent-hover); background-color: var(--theme-bg-accent-hover);
} }
&.summary {
font-weight: 600;
}
&.weekend:not(.today) { &.weekend:not(.today) {
background-color: var(--theme-bg-accent-color); background-color: var(--theme-bg-accent-color);
} }

View File

@ -14,11 +14,12 @@
--> -->
<script lang="ts"> <script lang="ts">
import { Staff } from '@hcengineering/hr' import { Staff } from '@hcengineering/hr'
import { floorFractionDigits } from '@hcengineering/ui'
export let value: Staff export let value: Staff
export let display: (staff: Staff) => number | string export let display: (staff: Staff) => number | string
$: _value = display(value) $: _value = floorFractionDigits(display(value), 3)
</script> </script>
<span class="select-text flex lines-limit-2">{_value}</span> <span class="select-text flex lines-limit-2">{_value}</span>

View File

@ -31,8 +31,13 @@
const todayDate = new Date() const todayDate = new Date()
function getRequests (employeeRequests: Map<Ref<Staff>, Request[]>, employee: Ref<Staff>, date: Date): Request[] { function getRequests (employeeRequests: Map<Ref<Staff>, Request[]>, date: Date, employee?: Ref<Staff>): Request[] {
const requests = employeeRequests.get(employee) let requests = undefined
if (employee) {
requests = employeeRequests.get(employee)
} else {
requests = Array.from(employeeRequests.values()).flat()
}
if (requests === undefined) return [] if (requests === undefined) return []
const res: Request[] = [] const res: Request[] = []
const time = date.getTime() const time = date.getTime()
@ -117,7 +122,7 @@
</td> </td>
{#each values as value, i} {#each values as value, i}
{@const month = getMonth(currentDate, value)} {@const month = getMonth(currentDate, value)}
{@const requests = getRequests(employeeRequests, employee._id, month)} {@const requests = getRequests(employeeRequests, month, employee._id)}
{@const tooltipValue = getTooltip(requests)} {@const tooltipValue = getTooltip(requests)}
{#key tooltipValue} {#key tooltipValue}
<td <td
@ -134,6 +139,23 @@
{/each} {/each}
</tr> </tr>
{/each} {/each}
<tr class="tr-body">
<td class="fixed td-body summary">
<Label label={hr.string.Summary} />
</td>
{#each values as value, i}
{@const month = getMonth(currentDate, value)}
{@const requests = getRequests(employeeRequests, month)}
<td
class:today={month.getFullYear() === todayDate.getFullYear() && month.getMonth() === todayDate.getMonth()}
class="fixed td-body summary"
>
<div class="flex-center">
{getTotal(requests, value, types)}
</div>
</td>
{/each}
</tr>
</tbody> </tbody>
</table> </table>
</Scroller> </Scroller>
@ -196,6 +218,9 @@
&.today { &.today {
background-color: var(--theme-bg-accent-hover); background-color: var(--theme-bg-accent-hover);
} }
&.summary {
font-weight: 600;
}
&.td-body { &.td-body {
border-bottom: 1px solid var(--divider-color); border-bottom: 1px solid var(--divider-color);
&:not(:last-child) { &:not(:last-child) {

View File

@ -39,6 +39,7 @@ export default mergeIds(hrId, hr, {
CreateRequest: '' as IntlString, CreateRequest: '' as IntlString,
Today: '' as IntlString, Today: '' as IntlString,
NoEmployeesInDepartment: '' as IntlString, NoEmployeesInDepartment: '' as IntlString,
Summary: '' as IntlString,
Staff: '' as IntlString, Staff: '' as IntlString,
Members: '' as IntlString, Members: '' as IntlString,
NoMembers: '' as IntlString, NoMembers: '' as IntlString,