feat: add totals in reports
This commit is contained in:
parent
ab5e977b96
commit
baa39e81f0
|
|
@ -48,13 +48,21 @@ export async function loader({ request }: LoaderArgs) {
|
||||||
|
|
||||||
await updateDuration(user.id);
|
await updateDuration(user.id);
|
||||||
|
|
||||||
return json({
|
const timeByProject = await getTimeEntriesByDateAndProject({
|
||||||
user,
|
|
||||||
timeByProject: await getTimeEntriesByDateAndProject({
|
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
dateFrom,
|
dateFrom,
|
||||||
dateTo
|
dateTo
|
||||||
}),
|
});
|
||||||
|
|
||||||
|
const total = timeByProject.reduce(
|
||||||
|
(acc, curr) => acc + (curr._sum.duration || 0),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
return json({
|
||||||
|
user,
|
||||||
|
timeByProject,
|
||||||
|
total,
|
||||||
projects: await getProjects({ userId: user.id })
|
projects: await getProjects({ userId: user.id })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -228,8 +236,8 @@ export default function ReportPage() {
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Project</th>
|
<th>Project</th>
|
||||||
<th>Time</th>
|
<th scope="col">Time</th>
|
||||||
{hourlyRate && <th>Billing</th>}
|
{hourlyRate && <th scope="col">Billing</th>}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
@ -240,7 +248,7 @@ export default function ReportPage() {
|
||||||
}[]
|
}[]
|
||||||
).map((projectData) => (
|
).map((projectData) => (
|
||||||
<tr key={projectData.projectId}>
|
<tr key={projectData.projectId}>
|
||||||
<td>
|
<td scope="row">
|
||||||
<Flex align="center">
|
<Flex align="center">
|
||||||
<ColorSwatch
|
<ColorSwatch
|
||||||
mr="sm"
|
mr="sm"
|
||||||
|
|
@ -272,6 +280,25 @@ export default function ReportPage() {
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
{!!reports.data?.timeByProject?.length && (
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Totals</th>
|
||||||
|
<th>{(reports.data.total / 1000 / 60 / 60).toFixed(2)} h</th>
|
||||||
|
{hourlyRate && (
|
||||||
|
<th>
|
||||||
|
{(
|
||||||
|
(reports.data.total * hourlyRate) /
|
||||||
|
1000 /
|
||||||
|
60 /
|
||||||
|
60
|
||||||
|
).toFixed(2)}{' '}
|
||||||
|
{reports.data?.user?.currency ?? '€'}
|
||||||
|
</th>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
)}
|
||||||
</Table>
|
</Table>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue