Add praisal to totals
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { SessionContext } from "@/app/context/Context";
|
||||||
import { PI_TYPES_MAP } from "@/const";
|
import { PI_TYPES_MAP } from "@/const";
|
||||||
import { planetCalculations } from "@/planets";
|
import { planetCalculations } from "@/planets";
|
||||||
import { AccessToken } from "@/types";
|
import { AccessToken } from "@/types";
|
||||||
@@ -15,6 +16,7 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
styled,
|
styled,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { useContext } from "react";
|
||||||
|
|
||||||
const StackItem = styled(Stack)(({ theme }) => ({
|
const StackItem = styled(Stack)(({ theme }) => ({
|
||||||
...theme.typography.body2,
|
...theme.typography.body2,
|
||||||
@@ -28,7 +30,13 @@ interface Grouped {
|
|||||||
[key: number]: number;
|
[key: number]: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const displayValue = (valueInMillions: number): string =>
|
||||||
|
valueInMillions >= 1000
|
||||||
|
? `${(valueInMillions / 1000).toFixed(2)} B`
|
||||||
|
: `${valueInMillions.toFixed(2)} M`;
|
||||||
|
|
||||||
export const Summary = ({ characters }: { characters: AccessToken[] }) => {
|
export const Summary = ({ characters }: { characters: AccessToken[] }) => {
|
||||||
|
const { piPrices, alertMode } = useContext(SessionContext);
|
||||||
const exports = characters.flatMap((char) => {
|
const exports = characters.flatMap((char) => {
|
||||||
return char.planets.flatMap((planet) => {
|
return char.planets.flatMap((planet) => {
|
||||||
const { localExports } = planetCalculations(planet);
|
const { localExports } = planetCalculations(planet);
|
||||||
@@ -46,11 +54,20 @@ export const Summary = ({ characters }: { characters: AccessToken[] }) => {
|
|||||||
const withProductNameAndPrice = Object.keys(groupedByMaterial).map(
|
const withProductNameAndPrice = Object.keys(groupedByMaterial).map(
|
||||||
(typeIdString) => {
|
(typeIdString) => {
|
||||||
const typeId = parseInt(typeIdString);
|
const typeId = parseInt(typeIdString);
|
||||||
|
const amount = groupedByMaterial[typeId];
|
||||||
|
const valueInMillions =
|
||||||
|
(((piPrices?.appraisal.items.find((a) => a.typeID === typeId)?.prices
|
||||||
|
.sell.min ?? 0) *
|
||||||
|
amount) /
|
||||||
|
1000000) *
|
||||||
|
24 *
|
||||||
|
30;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
typeId,
|
typeId,
|
||||||
amount: groupedByMaterial[typeId],
|
amount,
|
||||||
materialName: PI_TYPES_MAP[typeId].name,
|
materialName: PI_TYPES_MAP[typeId].name,
|
||||||
price: 0,
|
price: valueInMillions,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -93,6 +110,13 @@ export const Summary = ({ characters }: { characters: AccessToken[] }) => {
|
|||||||
price={product.price}
|
price={product.price}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
<SummaryRow
|
||||||
|
material="Total"
|
||||||
|
price={withProductNameAndPrice.reduce(
|
||||||
|
(amount, p) => amount + p.price,
|
||||||
|
0,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
@@ -106,7 +130,7 @@ const SummaryRow = ({
|
|||||||
price,
|
price,
|
||||||
}: {
|
}: {
|
||||||
material: string;
|
material: string;
|
||||||
amount: number;
|
amount?: number;
|
||||||
price: number;
|
price: number;
|
||||||
}) => (
|
}) => (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
@@ -114,6 +138,6 @@ const SummaryRow = ({
|
|||||||
{material}
|
{material}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{amount}</TableCell>
|
<TableCell>{amount}</TableCell>
|
||||||
<TableCell align="right">{price}</TableCell>
|
<TableCell align="right">{displayValue(price)}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user