updates on the profitability for the testing
This commit is contained in:
@@ -1604,36 +1604,43 @@ const Dispatch = ({
|
||||
|
||||
const totalDailyProfit = useMemo(() => {
|
||||
let profit = 0;
|
||||
const slotRiders = {};
|
||||
const riderDailyData = {};
|
||||
|
||||
liveRows.forEach(r => {
|
||||
// Filter by selectedDate to align with daily slot aggregations
|
||||
const dateStr = r.assigntime
|
||||
? dayjs(r.assigntime).format('YYYY-MM-DD')
|
||||
: r.deliverydate
|
||||
? dayjs(r.deliverydate).format('YYYY-MM-DD')
|
||||
: 'unknown';
|
||||
if (selectedDate && dateStr !== selectedDate) return;
|
||||
|
||||
const batch = getRowBatch(r, selectedTimeField, BATCHES);
|
||||
if (!batch || batch === 'all') return;
|
||||
|
||||
const riderKey = String(r.userid || r.rider_id || 'unassigned');
|
||||
if (riderKey === 'unassigned' || riderKey === '0') return;
|
||||
|
||||
if (!slotRiders[batch]) slotRiders[batch] = {};
|
||||
if (!slotRiders[batch][riderKey]) {
|
||||
slotRiders[batch][riderKey] = { revenue: 0, kms: 0 };
|
||||
if (!riderDailyData[riderKey]) {
|
||||
riderDailyData[riderKey] = { revenue: 0, kms: 0, batches: new Set() };
|
||||
}
|
||||
|
||||
const kms = parseFloat(r.kms || r.actualkms || 0);
|
||||
slotRiders[batch][riderKey].kms += kms;
|
||||
slotRiders[batch][riderKey].revenue += (kms <= 8 ? 30 : 30 + (kms - 8) * 6);
|
||||
riderDailyData[riderKey].kms += kms;
|
||||
riderDailyData[riderKey].revenue += (kms <= 8 ? 30 : 30 + (kms - 8) * 6);
|
||||
riderDailyData[riderKey].batches.add(batch);
|
||||
});
|
||||
|
||||
Object.values(slotRiders).forEach(riderMap => {
|
||||
Object.values(riderMap).forEach(stats => {
|
||||
const variableCost = stats.kms * 2.5;
|
||||
const fixedCost = 166.67;
|
||||
const totalCost = variableCost + fixedCost;
|
||||
profit += (stats.revenue - totalCost);
|
||||
});
|
||||
Object.values(riderDailyData).forEach(stats => {
|
||||
const variableCost = stats.kms * 2.5;
|
||||
const slotCount = Math.min(stats.batches.size, 3);
|
||||
const fixedCost = slotCount * (500 / 3);
|
||||
const totalCost = variableCost + fixedCost;
|
||||
profit += (stats.revenue - totalCost);
|
||||
});
|
||||
|
||||
return profit;
|
||||
}, [liveRows, selectedTimeField, BATCHES]);
|
||||
}, [liveRows, selectedTimeField, BATCHES, selectedDate]);
|
||||
|
||||
// Reshape flat delivery rows into the zones/riders/orders structure Dispatch consumes.
|
||||
const liveData = useMemo(() => {
|
||||
@@ -3830,7 +3837,14 @@ const Dispatch = ({
|
||||
)}
|
||||
|
||||
{viewMode === 'profitability' ? (
|
||||
<ProfitabilitySection riders={riders} handleRiderFocus={handleRiderFocus} focusedRider={focusedRider} totalDailyProfit={totalDailyProfit} />
|
||||
<ProfitabilitySection
|
||||
riders={riders}
|
||||
handleRiderFocus={handleRiderFocus}
|
||||
focusedRider={focusedRider}
|
||||
totalDailyProfit={totalDailyProfit}
|
||||
selectedDate={selectedDate}
|
||||
batches={BATCHES}
|
||||
/>
|
||||
) : viewMode === 'rider-info' ? (
|
||||
<div className="rider-info-mode">
|
||||
<div className="ri-sidebar">
|
||||
|
||||
Reference in New Issue
Block a user