2020-04-20 11:14:46 +02:00
|
|
|
|
import { FunctionalComponent, h } from "preact";
|
|
|
|
|
import { Project } from "../../models/project";
|
2020-04-21 14:10:50 +02:00
|
|
|
|
import { useProjectEstimations } from "../../hooks/use-project-estimations";
|
2020-04-23 14:00:56 +02:00
|
|
|
|
import { getCurrency, defaults, getTaskCategoryCost, getRoundUpEstimations } from "../../models/params";
|
2020-04-23 13:29:24 +02:00
|
|
|
|
import { getMinMaxCosts, Cost } from "../../util/stat";
|
|
|
|
|
import * as style from './style.module.css';
|
|
|
|
|
import ProjectTimeUnit from "../../components/project-time-unit";
|
2020-04-20 11:14:46 +02:00
|
|
|
|
|
|
|
|
|
export interface FinancialPreviewProps {
|
|
|
|
|
project: Project
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FinancialPreview: FunctionalComponent<FinancialPreviewProps> = ({ project }) => {
|
2020-04-21 14:10:50 +02:00
|
|
|
|
const estimations = useProjectEstimations(project);
|
2020-04-23 13:29:24 +02:00
|
|
|
|
const costs = getMinMaxCosts(project, estimations.p99);
|
2020-04-23 14:00:56 +02:00
|
|
|
|
const roundUp = getRoundUpEstimations(project);
|
2020-04-20 11:14:46 +02:00
|
|
|
|
return (
|
|
|
|
|
<div class="table-container">
|
|
|
|
|
<table class="table is-bordered is-striped is-fullwidth">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
2020-04-23 13:29:24 +02:00
|
|
|
|
<th colSpan={2}>
|
|
|
|
|
<span>Prévisionnel financier</span><br />
|
2020-06-11 09:29:09 -04:00
|
|
|
|
<span class="is-size-7 has-text-weight-normal">confiance {'>'}= 99.7%</span>
|
2020-04-23 13:29:24 +02:00
|
|
|
|
</th>
|
2020-04-20 11:14:46 +02:00
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2020-04-21 14:10:50 +02:00
|
|
|
|
<th class="is-narrow">Temps</th>
|
2020-04-20 11:14:46 +02:00
|
|
|
|
<th>Coût</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
2020-04-21 14:10:50 +02:00
|
|
|
|
<td class="is-narrow">Maximum</td>
|
2020-04-22 23:18:18 +02:00
|
|
|
|
<td>
|
2020-04-23 14:00:56 +02:00
|
|
|
|
<CostDetails project={project} cost={costs.max} roundUp={roundUp} />
|
2020-04-22 23:18:18 +02:00
|
|
|
|
</td>
|
2020-04-20 11:14:46 +02:00
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2020-04-21 14:10:50 +02:00
|
|
|
|
<td class="is-narrow">Minimum</td>
|
2020-04-22 23:18:18 +02:00
|
|
|
|
<td>
|
2020-04-23 14:00:56 +02:00
|
|
|
|
<CostDetails project={project} cost={costs.min} roundUp={roundUp} />
|
2020-04-22 23:18:18 +02:00
|
|
|
|
</td>
|
2020-04-20 11:14:46 +02:00
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-23 13:29:24 +02:00
|
|
|
|
export interface CostDetailsProps {
|
|
|
|
|
project: Project
|
|
|
|
|
cost: Cost
|
2020-04-23 14:00:56 +02:00
|
|
|
|
roundUp: boolean
|
2020-04-23 13:29:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 14:00:56 +02:00
|
|
|
|
export const CostDetails:FunctionalComponent<CostDetailsProps> = ({ project, cost, roundUp }) => {
|
2020-04-23 13:29:24 +02:00
|
|
|
|
return (
|
|
|
|
|
<details>
|
|
|
|
|
<summary><strong>
|
|
|
|
|
≈ {cost.totalCost} {getCurrency(project)}</strong>
|
2020-04-23 14:00:56 +02:00
|
|
|
|
<span class="is-pulled-right">{ roundUp ? Math.ceil(cost.totalTime) : cost.totalTime.toFixed(2) } <ProjectTimeUnit project={project} /></span>
|
2020-04-23 13:29:24 +02:00
|
|
|
|
</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>
|
2020-04-23 14:00:56 +02:00
|
|
|
|
<td class={`${style.noBorder} is-size-6`}>{ roundUp ? Math.ceil(details.time) : details.time.toFixed(2) } <ProjectTimeUnit project={project} /> × {getTaskCategoryCost(taskCategory)} {getCurrency(project)}</td>
|
2020-04-23 13:29:24 +02:00
|
|
|
|
</tr>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</details>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-20 11:14:46 +02:00
|
|
|
|
export default FinancialPreview;
|