updates on the profitability for the testing
This commit is contained in:
@@ -291,7 +291,7 @@ export default function ProfitabilityReport() {
|
||||
.map((r) => {
|
||||
let rRevenue = 0;
|
||||
let rKms = 0;
|
||||
const activeSlots = new Set();
|
||||
const slotsByDate = {};
|
||||
let ordersInSlots = 0;
|
||||
|
||||
r.orders.forEach((o) => {
|
||||
@@ -301,8 +301,18 @@ export default function ProfitabilityReport() {
|
||||
const oKms = parseFloat(o.kms || o.actualkms || 0);
|
||||
rKms += oKms;
|
||||
rRevenue += oKms <= 8 ? 30 : 30 + (oKms - 8) * 6;
|
||||
const dateStr = o.assigntime ? dayjs(o.assigntime).format('YYYY-MM-DD') : 'unknown';
|
||||
activeSlots.add(`${dateStr}_${slot}`);
|
||||
|
||||
const dateStr = o.assigntime
|
||||
? dayjs(o.assigntime).format('YYYY-MM-DD')
|
||||
: o.deliverydate
|
||||
? dayjs(o.deliverydate).format('YYYY-MM-DD')
|
||||
: null;
|
||||
if (!dateStr) return;
|
||||
|
||||
if (!slotsByDate[dateStr]) {
|
||||
slotsByDate[dateStr] = new Set();
|
||||
}
|
||||
slotsByDate[dateStr].add(slot);
|
||||
ordersInSlots++;
|
||||
});
|
||||
|
||||
@@ -310,9 +320,14 @@ export default function ProfitabilityReport() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Sum unique slots per day, capping at 3 slots max per day
|
||||
let slotCount = 0;
|
||||
Object.values(slotsByDate).forEach((set) => {
|
||||
slotCount += Math.min(set.size, 3);
|
||||
});
|
||||
|
||||
const rVarCost = rKms * 2.5;
|
||||
const slotCount = activeSlots.size;
|
||||
const rFixedCost = slotCount * 166.67;
|
||||
const rFixedCost = slotCount * (500 / 3);
|
||||
const rTotalCost = rVarCost + rFixedCost;
|
||||
const rNet = rRevenue - rTotalCost;
|
||||
const rMargin = rRevenue > 0 ? (rNet / rRevenue) * 100 : 0;
|
||||
|
||||
Reference in New Issue
Block a user