guesstimate/client/src/routes/project/financial-preview.tsx

86 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { FunctionalComponent, h } from "preact";
import { Project } from "../../models/project";
import { useProjectEstimations } from "../../hooks/use-project-estimations";
import { getCurrency, defaults, getTaskCategoryCost, getRoundUpEstimations } from "../../models/params";
import { getMinMaxCosts, Cost } from "../../util/stat";
import * as style from './style.module.css';
import ProjectTimeUnit from "../../components/project-time-unit";
export interface FinancialPreviewProps {
project: Project
}
const FinancialPreview: FunctionalComponent<FinancialPreviewProps> = ({ project }) => {
const estimations = useProjectEstimations(project);
const costs = getMinMaxCosts(project, estimations.p99);
const roundUp = getRoundUpEstimations(project);
return (
<div class="table-container">
<table class="table is-bordered is-striped is-fullwidth">
<thead>
<tr>
<th colSpan={2}>
<span>Prévisionnel financier</span><br />
<span class="is-size-7 has-text-weight-normal">confiance >= 99.7%</span>
</th>
</tr>
<tr>
<th class="is-narrow">Temps</th>
<th>Coût</th>
</tr>
</thead>
<tbody>
<tr>
<td class="is-narrow">Maximum</td>
<td>
<CostDetails project={project} cost={costs.max} roundUp={roundUp} />
</td>
</tr>
<tr>
<td class="is-narrow">Minimum</td>
<td>
<CostDetails project={project} cost={costs.min} roundUp={roundUp} />
</td>
</tr>
</tbody>
</table>
</div>
);
};
export interface CostDetailsProps {
project: Project
cost: Cost
roundUp: boolean
}
export const CostDetails:FunctionalComponent<CostDetailsProps> = ({ project, cost, roundUp }) => {
return (
<details>
<summary><strong>
{cost.totalCost} {getCurrency(project)}</strong>
<span class="is-pulled-right">{ roundUp ? Math.ceil(cost.totalTime) : cost.totalTime.toFixed(2) } <ProjectTimeUnit project={project} /></span>
</summary>
<table class={`table is-fullwidth`}>
<tbody>
{
Object.keys(cost.details).map(taskCategoryId => {
const taskCategory = project.params.taskCategories[taskCategoryId];
const details = cost.details[taskCategoryId];
return (
<tr key={`task-category-cost-${taskCategory.id}`}>
<td class={`${style.noBorder} is-size-6`}>{taskCategory.label}</td>
<td class={`${style.noBorder} is-size-6`}>{details.cost} {getCurrency(project)}</td>
<td class={`${style.noBorder} is-size-6`}>{ roundUp ? Math.ceil(details.time) : details.time.toFixed(2) } <ProjectTimeUnit project={project} /> × {getTaskCategoryCost(taskCategory)} {getCurrency(project)}</td>
</tr>
)
})
}
</tbody>
</table>
</details>
);
};
export default FinancialPreview;