Fix remove from multiple acquisitions

This commit is contained in:
2024-05-19 12:19:43 +02:00
parent 27f146b945
commit 400737dab8
4 changed files with 50 additions and 33 deletions

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import { SortableHeader, useSort } from '@/components/table';
import { formatIsk, percentFormater } from '@/formaters';
import { MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/market";
import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/market";
import { MinusIcon, PlusIcon } from '@heroicons/vue/24/outline';
import { useStorage } from '@vueuse/core';
import { computed, ref } from 'vue';
@@ -9,8 +9,8 @@ import { AcquiredType } from './AcquiredType';
import AcquisitionQuantilsTooltip from './AcquisitionQuantilsTooltip.vue';
type Result = {
type: AcquiredType;
typeID: number;
id: number;
type: MarketType;
name: string;
buy: number;
sell: number;
@@ -19,6 +19,7 @@ type Result = {
quantity: number;
precentProfit: number;
iskProfit: number;
acquisitions: AcquiredType[];
}
interface Props {
@@ -28,8 +29,8 @@ interface Props {
}
interface Emits {
(e: 'buy', type: AcquiredType, price: number, buy: number, sell: number): void;
(e: 'sell', type: AcquiredType): void;
(e: 'buy', type: AcquiredType[], price: number, buy: number, sell: number): void;
(e: 'sell', type: AcquiredType[]): void;
}
const props = withDefaults(defineProps<Props>(), {
@@ -51,16 +52,17 @@ const filteredItems = props.items.filter(r => r.type.name.toLowerCase().includes
const precentProfit = marketTaxStore.calculateProfit(r.price, r.sell);
return {
type: r,
typeID: r.type.id,
name: r.type.name,
id: r.id,
type: r.type,
name: r.name,
buy: r.buy,
sell: r.sell,
price: r.price,
remaining: r.remaining,
quantity: r.quantity,
precentProfit,
iskProfit: r.price * precentProfit * r.remaining
iskProfit: r.price * precentProfit * r.remaining,
acquisitions: [r]
};
});
}
@@ -69,28 +71,29 @@ const filteredItems = props.items.filter(r => r.type.name.toLowerCase().includes
const groups = Map.groupBy(filteredItems, r => r.type.id);
groups.forEach((group, typeID) => {
const oldest = group.reduce((acc: AcquiredType | undefined, r: AcquiredType) => (acc && acc.date < r.date) ? acc : r, undefined);
const first = group[0];
if (!oldest) {
if (!first) {
return;
}
const total = group.reduce((acc, r) => acc + r.quantity, 0);
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, oldest.sell);
const precentProfit = marketTaxStore.calculateProfit(price, first.sell);
list.push({
type: oldest,
typeID,
name: oldest.type.name,
buy: oldest.buy,
sell: oldest.sell,
id: typeID,
type: first.type,
name: first.type.name,
buy: first.buy,
sell: first.sell,
price: price,
remaining: totalRemaining,
quantity: total,
precentProfit,
iskProfit: price * precentProfit * totalRemaining
iskProfit: price * precentProfit * totalRemaining,
acquisitions: group
});
});
return list;
@@ -136,11 +139,11 @@ const getLineColor = (result: Result) => {
</tr>
</thead>
<tbody>
<tr v-for="r in sortedArray" :key="r.type.id" :class="getLineColor(r)">
<tr v-for="r in sortedArray" :key="r.id" :class="getLineColor(r)">
<td>
<div class="flex">
<MarketTypeLabel :id="r.typeID" :name="r.name" />
<AcquisitionQuantilsTooltip :id="r.typeID" :buy="r.buy" :sell="r.sell" />
<MarketTypeLabel :id="r.type.id" :name="r.name" />
<AcquisitionQuantilsTooltip :id="r.type.id" :buy="r.buy" :sell="r.sell" />
</div>
</td>
<td class="text-right">{{ formatIsk(r.buy) }}</td>
@@ -150,8 +153,8 @@ const getLineColor = (result: Result) => {
<td class="text-right">{{ percentFormater.format(r.precentProfit) }}</td>
<td class="text-right">{{ formatIsk(r.iskProfit) }}</td>
<td class="text-right" v-if="!infoOnly">
<button class="btn-icon me-1" @click="$emit('buy', r.type, r.price, r.buy, r.sell)"><PlusIcon /></button>
<button class="btn-icon me-1" @click="$emit('sell', r.type)"><MinusIcon /></button>
<button class="btn-icon me-1" @click="$emit('buy', r.acquisitions, r.price, r.buy, r.sell)"><PlusIcon /></button>
<button class="btn-icon me-1" @click="$emit('sell', r.acquisitions)"><MinusIcon /></button>
</td>
</tr>
</tbody>