group acquisitions
This commit is contained in:
@@ -41,24 +41,36 @@ const marketTaxStore = useMarketTaxStore();
|
|||||||
|
|
||||||
const threshold = useStorage('market-acquisition-threshold', 10);
|
const threshold = useStorage('market-acquisition-threshold', 10);
|
||||||
const filter = ref("");
|
const filter = ref("");
|
||||||
const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items
|
const { sortedArray, headerProps } = useSort<Result>(computed(() => {
|
||||||
.filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase()))
|
const list: Result[] = [];
|
||||||
.map(r => {
|
const groups = Map.groupBy(props.items.filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase())), r => r.type);
|
||||||
const precentProfit = marketTaxStore.calculateProfit(r.price, r.sell);
|
|
||||||
|
|
||||||
return {
|
groups.forEach((group, type) => {
|
||||||
type: r,
|
const oldest = group.reduce((acc: AcquiredType | undefined, r: AcquiredType) => (acc && acc.date < r.date) ? acc : r, undefined);
|
||||||
typeID: r.type.id,
|
|
||||||
name: r.type.name,
|
if (!oldest) {
|
||||||
buy: r.buy,
|
return;
|
||||||
sell: r.sell,
|
}
|
||||||
price: r.price,
|
|
||||||
remaining: r.remaining,
|
const total = group.reduce((acc, r) => acc + r.quantity, 0);
|
||||||
quantity: r.quantity,
|
const totalRemaining = group.reduce((acc, r) => acc + r.remaining, 0);
|
||||||
|
const price = group.reduce((acc, r) => acc + r.price * r.remaining, 0) / totalRemaining;
|
||||||
|
const precentProfit = marketTaxStore.calculateProfit(price, group[0].sell);
|
||||||
|
list.push({
|
||||||
|
type: oldest,
|
||||||
|
typeID: type.id,
|
||||||
|
name: type.name,
|
||||||
|
buy: group[0].buy,
|
||||||
|
sell: group[0].sell,
|
||||||
|
price: price,
|
||||||
|
remaining: totalRemaining,
|
||||||
|
quantity: total,
|
||||||
precentProfit,
|
precentProfit,
|
||||||
iskProfit: r.price * precentProfit * r.remaining
|
iskProfit: price * precentProfit * totalRemaining
|
||||||
};
|
});
|
||||||
})), {
|
});
|
||||||
|
return list;
|
||||||
|
}), {
|
||||||
defaultSortKey: 'precentProfit',
|
defaultSortKey: 'precentProfit',
|
||||||
defaultSortDirection: 'desc'
|
defaultSortDirection: 'desc'
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "ESNext",
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|
||||||
/* Bundler mode */
|
/* Bundler mode */
|
||||||
|
|||||||
Reference in New Issue
Block a user