Fix: Improve revenue performance indicator
The revenue performance indicator now correctly calculates and displays the performance based on price per unit, comparing expected and actual revenue per item sold. It also handles cases where produced or sold quantities are zero.
This commit is contained in:
@@ -28,13 +28,19 @@ const JobCardMetrics: React.FC<JobCardMetricsProps> = ({ job }) => {
|
||||
const profit = totalIncome - totalExpenditure;
|
||||
const margin = totalIncome > 0 ? ((profit / totalIncome) * 100) : 0;
|
||||
|
||||
// Calculate performance metrics - Fixed logic
|
||||
// Calculate performance metrics - Simple price per unit comparison
|
||||
const itemsSold = sortedIncome.reduce((sum, tx) => sum + tx.quantity, 0);
|
||||
const revenuePerformanceRatio = job.projectedRevenue > 0 ? (totalIncome / job.projectedRevenue) : 0;
|
||||
const revenuePerformancePercentage = revenuePerformanceRatio * 100;
|
||||
|
||||
// Show performance indicator only if we have the necessary data and have sold items
|
||||
const showPerformanceIndicator = job.projectedRevenue > 0 && itemsSold > 0;
|
||||
const produced = job.produced || 0;
|
||||
|
||||
// Only show performance if we have produced items and sold items
|
||||
const showPerformanceIndicator = produced > 0 && itemsSold > 0 && job.projectedRevenue > 0;
|
||||
|
||||
let performancePercentage = 0;
|
||||
if (showPerformanceIndicator) {
|
||||
const expectedPPU = job.projectedRevenue / produced;
|
||||
const actualPPU = totalIncome / itemsSold;
|
||||
performancePercentage = (actualPPU / expectedPPU) * 100;
|
||||
}
|
||||
|
||||
const handleFieldClick = (fieldName: string, currentValue: number, e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
@@ -158,15 +164,15 @@ const JobCardMetrics: React.FC<JobCardMetricsProps> = ({ job }) => {
|
||||
{showPerformanceIndicator && (
|
||||
<div
|
||||
className={`text-xs font-medium px-2 py-0.5 rounded-full inline-block ${
|
||||
revenuePerformancePercentage >= 100
|
||||
performancePercentage >= 100
|
||||
? 'bg-green-900/50 text-green-400'
|
||||
: revenuePerformancePercentage >= 90
|
||||
: performancePercentage >= 90
|
||||
? 'bg-yellow-900/50 text-yellow-400'
|
||||
: 'bg-red-900/50 text-red-400'
|
||||
}`}
|
||||
title={`Performance: ${formatISK(totalIncome)} actual vs ${formatISK(job.projectedRevenue)} expected (${revenuePerformancePercentage.toFixed(1)}%)`}
|
||||
title={`Price performance: ${formatISK(totalIncome / itemsSold)}/unit vs ${formatISK(job.projectedRevenue / produced)}/unit expected (${performancePercentage.toFixed(1)}%)`}
|
||||
>
|
||||
{revenuePerformancePercentage >= 100 ? '📈' : revenuePerformancePercentage >= 90 ? '⚠️' : '📉'} {revenuePerformancePercentage.toFixed(0)}%
|
||||
{performancePercentage >= 100 ? '📈' : performancePercentage >= 90 ? '⚠️' : '📉'} {performancePercentage.toFixed(0)}%
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user