updateson the profitability page
This commit is contained in:
@@ -50,7 +50,7 @@ function getStatusConfig(raw) {
|
||||
}
|
||||
|
||||
function orderRevenue(order) {
|
||||
const km = parseFloat(order.kms || order.actualkms || 0);
|
||||
const km = parseFloat(order.riderkms || 0);
|
||||
return km <= BASE_KM_LIMIT ? BASE_REVENUE : BASE_REVENUE + (km - BASE_KM_LIMIT) * EXTRA_RATE_KM;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ function calcRiderMetrics(rider, selectedDate, batches) {
|
||||
|
||||
for (const o of orders) {
|
||||
revenue += orderRevenue(o);
|
||||
kms += parseFloat(o.kms || o.actualkms || 0);
|
||||
kms += parseFloat(o.riderkms || 0);
|
||||
|
||||
const slot = getRowBatch(o, batches);
|
||||
if (!slot) continue;
|
||||
@@ -125,6 +125,15 @@ function calcRiderMetrics(rider, selectedDate, batches) {
|
||||
return { revenue, kms, varCost, fixedCost, totalCost, net, margin, orders };
|
||||
}
|
||||
|
||||
/** Format a km value, switching to metres below 1 km so short hops don't round to "0.0 km". */
|
||||
function formatDistance(km) {
|
||||
const value = Number.isFinite(km) ? km : 0;
|
||||
if (value > 0 && value < 1) {
|
||||
return { value: String(Math.round(value * 1000)), unit: 'm' };
|
||||
}
|
||||
return { value: value.toFixed(1), unit: 'km' };
|
||||
}
|
||||
|
||||
function rupees(v, decimals = 0) {
|
||||
if (v == null) return '—';
|
||||
return `₹${parseFloat(v).toFixed(decimals)}`;
|
||||
@@ -202,7 +211,9 @@ function OrdersBreakdownTable({ orders, getRevenue }) {
|
||||
<tr>
|
||||
<th scope="col">Customer</th>
|
||||
<th scope="col">Status</th>
|
||||
<th scope="col">Distance</th>
|
||||
<th scope="col">Planned KMs</th>
|
||||
<th scope="col">Actual KMs</th>
|
||||
<th scope="col">Trip KMs</th>
|
||||
<th scope="col" style={{ textAlign: 'right' }}>
|
||||
Revenue
|
||||
</th>
|
||||
@@ -210,7 +221,10 @@ function OrdersBreakdownTable({ orders, getRevenue }) {
|
||||
</thead>
|
||||
<tbody>
|
||||
{orders.map((order, idx) => {
|
||||
const km = parseFloat(order.kms ?? order.actualkms ?? 0);
|
||||
const km = parseFloat(order.riderkms ?? 0);
|
||||
const dist = formatDistance(km);
|
||||
const plannedDist = formatDistance(parseFloat(order.kms ?? 0));
|
||||
const actualDist = formatDistance(parseFloat(order.actualkms ?? 0));
|
||||
const rev = getRevenue(order);
|
||||
return (
|
||||
<tr key={`${order.orderid ?? 'order'}-${idx}`}>
|
||||
@@ -221,8 +235,16 @@ function OrdersBreakdownTable({ orders, getRevenue }) {
|
||||
<OrderStatusPill status={order.orderstatus ?? order.status} />
|
||||
</td>
|
||||
<td>
|
||||
<span className="distance-value">{km.toFixed(1)}</span>
|
||||
<span className="distance-unit">km</span>
|
||||
<span className="distance-value">{plannedDist.value}</span>
|
||||
<span className="distance-unit">{plannedDist.unit}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span className="distance-value">{actualDist.value}</span>
|
||||
<span className="distance-unit">{actualDist.unit}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span className="distance-value">{dist.value}</span>
|
||||
<span className="distance-unit">{dist.unit}</span>
|
||||
</td>
|
||||
<td style={{ textAlign: 'right' }}>
|
||||
<span className="revenue-amount">{rupees(rev)}</span>
|
||||
|
||||
Reference in New Issue
Block a user