WIP for Reporting. Pulled out calculations to utility functions.

This commit is contained in:
Patrick Fic
2020-10-20 13:55:35 -07:00
parent 4290c8c497
commit 045346ce48
18 changed files with 345 additions and 57 deletions

View File

@@ -0,0 +1,31 @@
import Dinero from "dinero.js";
export function CalculateJobRpsDollars(job) {
if (!job) {
return 0;
}
return job.joblines
.filter((j) => !j.ignore)
.reduce((acc, val) => {
if (val.price_diff > 0) {
return acc.add(
Dinero({ amount: Math.round((val.price_diff || 0) * 100) })
);
} else {
return acc;
}
}, Dinero());
}
export function CalculateJobRpsPc(job, currentRpsDollars) {
//TODO Redo this to do total of db price - act price / db price
if (!job) {
return 0;
}
const dbPriceSum = job.joblines
.filter((j) => !j.ignore)
.reduce((acc, val) => {
return acc + val.db_price;
}, 0);
return (currentRpsDollars.getAmount() / dbPriceSum).toFixed(1);
}

12
src/util/GetJobTarget.js Normal file
View File

@@ -0,0 +1,12 @@
export default function GetJobTarget(group, v_age, targets) {
const targetsForGroup = targets.filter((t) => t.group === group);
if (!targetsForGroup) return 0;
const targetPc = targetsForGroup.filter(
(t) => t.ageGte <= v_age && (t.ageLt ? t.ageLt > v_age : true)
);
if (targetPc.length === 0) return 100;
else if (targetPc.length === 1) return targetPc[0].target;
else {
return 100;
}
}