draft acquisition
This commit is contained in:
8
src/market/acquisition/AcquiredItem.ts
Normal file
8
src/market/acquisition/AcquiredItem.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { MarketType } from "..";
|
||||
import { AcquiredMarketItem } from "./acquisition";
|
||||
|
||||
export type AcquiredItem = Omit<AcquiredMarketItem, 'type'> & {
|
||||
type: MarketType,
|
||||
buy: number,
|
||||
sell: number
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/mark
|
||||
import { MinusIcon, PlusIcon } from '@heroicons/vue/24/outline';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { computed, ref } from 'vue';
|
||||
import { TrackedItem } from '.';
|
||||
import TrackQuantilsTooltip from './TrackQuantilsTooltip.vue';
|
||||
import { AcquiredItem } from './AcquiredItem';
|
||||
import AcquisitionQuantilsTooltip from './AcquisitionQuantilsTooltip.vue';
|
||||
|
||||
type Result = {
|
||||
type: MarketType;
|
||||
@@ -21,7 +21,7 @@ type Result = {
|
||||
}
|
||||
|
||||
interface Props {
|
||||
items?: TrackedItem[];
|
||||
items?: AcquiredItem[];
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
@@ -36,12 +36,12 @@ defineEmits<Emits>();
|
||||
|
||||
const marketTaxStore = useMarketTaxStore();
|
||||
|
||||
const threshold = useStorage('market-track-threshold', 10);
|
||||
const threshold = useStorage('market-axquisition-threshold', 10);
|
||||
const filter = ref("");
|
||||
const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items
|
||||
.filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase()))
|
||||
.map(r => {
|
||||
const precentProfit = marketTaxStore.calculateProfit(r.averagePrice, r.sell);
|
||||
const precentProfit = marketTaxStore.calculateProfit(r.price, r.sell);
|
||||
|
||||
return {
|
||||
type: r.type,
|
||||
@@ -49,10 +49,10 @@ const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items
|
||||
name: r.type.name,
|
||||
buy: r.buy,
|
||||
sell: r.sell,
|
||||
price: r.averagePrice,
|
||||
count: r.count,
|
||||
price: r.price,
|
||||
count: r.remaining,
|
||||
precentProfit,
|
||||
iskProfit: r.averagePrice * precentProfit * r.count
|
||||
iskProfit: r.price * precentProfit * r.remaining
|
||||
};
|
||||
})), {
|
||||
defaultSortKey: 'precentProfit',
|
||||
@@ -100,7 +100,7 @@ const getLineColor = (result: Result) => {
|
||||
<td>
|
||||
<div class="flex">
|
||||
<MarketTypeLabel :id="r.typeID" :name="r.name" />
|
||||
<TrackQuantilsTooltip :id="r.typeID" :buy="r.buy" :sell="r.sell" />
|
||||
<AcquisitionQuantilsTooltip :id="r.typeID" :buy="r.buy" :sell="r.sell" />
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-right">{{ formatIsk(r.buy) }}</td>
|
||||
@@ -3,10 +3,10 @@ import { Modal } from '@/components';
|
||||
import { formatIsk } from '@/formaters';
|
||||
import { MarketType, MarketTypeLabel } from '@/market';
|
||||
import { ref } from 'vue';
|
||||
import { useTrackedItemStore } from './track';
|
||||
import { useAcquiredItemStore } from './acquisition';
|
||||
|
||||
|
||||
const trackedItemStore = useTrackedItemStore();
|
||||
const acquiredItemStore = useAcquiredItemStore();
|
||||
|
||||
const modalOpen = ref<boolean>(false);
|
||||
const type = ref<MarketType>();
|
||||
@@ -38,7 +38,7 @@ const add = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
trackedItemStore.addTrackedItem(id, count.value, price.value);
|
||||
acquiredItemStore.addAcquiredItem(id, count.value, price.value);
|
||||
modalOpen.value = false;
|
||||
}
|
||||
|
||||
@@ -66,4 +66,4 @@ defineExpose({ open });
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
</template>./acquisitions
|
||||
@@ -2,10 +2,10 @@
|
||||
import { Modal } from '@/components';
|
||||
import { MarketType, MarketTypeLabel } from '@/market';
|
||||
import { ref } from 'vue';
|
||||
import { useTrackedItemStore } from './track';
|
||||
import { useAcquiredItemStore } from './acquisition';
|
||||
|
||||
|
||||
const trackedItemStore = useTrackedItemStore();
|
||||
const acquiredItemStore = useAcquiredItemStore();
|
||||
|
||||
const modalOpen = ref<boolean>(false);
|
||||
const type = ref<MarketType>();
|
||||
@@ -24,7 +24,7 @@ const remove = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
trackedItemStore.removeTrackedItem(id, count.value);
|
||||
acquiredItemStore.removeAcquiredItem(id, count.value);
|
||||
modalOpen.value = false;
|
||||
}
|
||||
|
||||
@@ -45,4 +45,4 @@ defineExpose({ open });
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
</template>./acquisitions
|
||||
65
src/market/acquisition/acquisition.ts
Normal file
65
src/market/acquisition/acquisition.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { marbasAxiosInstance } from "@/service";
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
|
||||
export type AcquiredMarketItem = {
|
||||
id: number;
|
||||
type: number;
|
||||
quantity: number;
|
||||
remaining: number;
|
||||
price: number;
|
||||
date: Date;
|
||||
source: 'bo' | 'so' | 'prod';
|
||||
user: number;
|
||||
}
|
||||
|
||||
const endpoint = '/api/acquisitions';
|
||||
|
||||
export const useAcquiredItemStore = defineStore('market-acquisition', () => {
|
||||
const _acquiredItems = ref<AcquiredMarketItem[]>([]);
|
||||
|
||||
const items = computed(() => _acquiredItems.value);
|
||||
const addAcquiredItem = async (type: number, quantity: number, price: number) => {
|
||||
_acquiredItems.value = [..._acquiredItems.value, (await marbasAxiosInstance.post<AcquiredMarketItem>(endpoint, {
|
||||
type: type,
|
||||
quantity: quantity,
|
||||
remaining: quantity,
|
||||
price: price,
|
||||
date: new Date(),
|
||||
source: 'bo',
|
||||
user: 0 // TODO: get user id
|
||||
})).data];
|
||||
};
|
||||
const removeAcquiredItem = async (type: number, quantity: number) => {
|
||||
const found = _acquiredItems.value.find(item => item.type === type);
|
||||
|
||||
if (!found) {
|
||||
return;
|
||||
}
|
||||
if (found.remaining <= 0) {
|
||||
_acquiredItems.value = _acquiredItems.value.filter(i => i.type !== type);
|
||||
|
||||
await marbasAxiosInstance.delete(`${endpoint}/${found.id}`);
|
||||
} else {
|
||||
const item = {
|
||||
...found,
|
||||
remaining: found.remaining - quantity
|
||||
};
|
||||
|
||||
_acquiredItems.value = _acquiredItems.value.map(i => {
|
||||
if (i.type === item.type) {
|
||||
return item;
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
});
|
||||
await marbasAxiosInstance.put(`${endpoint}/${item.id}`, item);
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
_acquiredItems.value = (await marbasAxiosInstance.get<AcquiredMarketItem[]>(endpoint)).data;
|
||||
});
|
||||
|
||||
return { items, addAcquiredItem, removeAcquiredItem };
|
||||
});
|
||||
7
src/market/acquisition/index.ts
Normal file
7
src/market/acquisition/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export * from './AcquiredItem';
|
||||
export * from './acquisition';
|
||||
|
||||
export { default as AcquisitionResultTable } from './AcquisitionResultTable.vue';
|
||||
export { default as BuyModal } from './BuyModal.vue';
|
||||
export { default as SellModal } from './SellModal.vue';
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { MarketType } from "@/market";
|
||||
|
||||
export type TrackedItem = {
|
||||
type: MarketType;
|
||||
count: number;
|
||||
averagePrice: number;
|
||||
buy: number,
|
||||
sell: number
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export * from './TrackedItem';
|
||||
export * from './track';
|
||||
|
||||
export { default as BuyModal } from './BuyModal.vue';
|
||||
export { default as SellModal } from './SellModal.vue';
|
||||
export { default as TrackResultTable } from './TrackResultTable.vue';
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import { useCollection, usePocketBase } from "@/pocketbase";
|
||||
import { createSharedComposable, useLocalStorage } from '@vueuse/core';
|
||||
import { defineStore } from "pinia";
|
||||
import { RecordModel } from "pocketbase";
|
||||
import { computed } from "vue";
|
||||
|
||||
export type TrackedMarketItemStorage = {
|
||||
typeID: number;
|
||||
count: number;
|
||||
averagePrice: number;
|
||||
}
|
||||
|
||||
interface TrackedMarketItem extends RecordModel {
|
||||
owner: string;
|
||||
typeID: number;
|
||||
count: number;
|
||||
averagePrice: number;
|
||||
}
|
||||
|
||||
const marketTrackings = 'marketTrackings';
|
||||
|
||||
export const useTrackedItemsStorage = createSharedComposable(() => useLocalStorage<TrackedMarketItemStorage[]>('market-track-items', []));
|
||||
|
||||
export const useTrackedItemStore = defineStore(marketTrackings, () => {
|
||||
const pb = usePocketBase();
|
||||
const trackedItems = useCollection<TrackedMarketItem>(marketTrackings);
|
||||
|
||||
const items = computed(() => trackedItems);
|
||||
const addTrackedItem = async (typeID: number, count: number, averagePrice: number) => {
|
||||
const oldItem = trackedItems.value.find(i => i.typeID === typeID);
|
||||
|
||||
if (oldItem?.id) {
|
||||
pb.collection(marketTrackings).update(oldItem.id, {
|
||||
...oldItem,
|
||||
count: count + oldItem.count,
|
||||
averagePrice: ((averagePrice * count) + (oldItem.averagePrice * oldItem.count)) / (count + oldItem.count)
|
||||
});
|
||||
} else {
|
||||
pb.collection(marketTrackings).create({ owner: pb.authStore.model!.id, typeID, count, averagePrice});
|
||||
}
|
||||
};
|
||||
const removeTrackedItem = async (typeID: number, count: number) => {
|
||||
const oldItem = trackedItems.value.find(i => i.typeID === typeID);
|
||||
|
||||
if (!oldItem?.id) {
|
||||
return;
|
||||
} else if (oldItem.count > count) {
|
||||
pb.collection(marketTrackings).update(oldItem.id, {
|
||||
...oldItem,
|
||||
count: oldItem.count - count
|
||||
});
|
||||
} else {
|
||||
pb.collection(marketTrackings).delete(oldItem.id);
|
||||
}
|
||||
};
|
||||
|
||||
return { items, addTrackedItem, removeTrackedItem };
|
||||
});
|
||||
@@ -12,8 +12,8 @@ import { RouterLink, RouterView } from 'vue-router';
|
||||
<RouterLink to="/market/scan" class="tab">
|
||||
<span>Scan</span>
|
||||
</RouterLink>
|
||||
<RouterLink to="/market/track" class="tab">
|
||||
<span>Tracking</span>
|
||||
<RouterLink to="/market/acquisition" class="tab">
|
||||
<span>Acquisitions</span>
|
||||
</RouterLink>
|
||||
</div>
|
||||
<RouterView />
|
||||
|
||||
43
src/pages/market/Acquisitions.vue
Normal file
43
src/pages/market/Acquisitions.vue
Normal file
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import { MarketTypePrice, getMarketTypes, useApraisalStore } from "@/market";
|
||||
import { AcquiredItem, AcquisitionResultTable, BuyModal, SellModal, useAcquiredItemStore } from '@/market/acquisition';
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
const buyModal = ref<typeof BuyModal>();
|
||||
const sellModal = ref<typeof SellModal>();
|
||||
|
||||
|
||||
const apraisalStore = useApraisalStore();
|
||||
const acquiredItemStore = useAcquiredItemStore();
|
||||
const items = ref<AcquiredItem[]>([]);
|
||||
|
||||
watch(() => acquiredItemStore.items, async itms => {
|
||||
if (itms.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const prices = await apraisalStore.getPrices(await getMarketTypes(itms.map(i => i.type)));
|
||||
|
||||
items.value = itms.map(i => {
|
||||
const price = prices.find(p => p.type.id === i.type) as MarketTypePrice;
|
||||
|
||||
return {
|
||||
...i,
|
||||
type: price.type,
|
||||
buy: price.buy,
|
||||
sell: price.sell
|
||||
};
|
||||
});
|
||||
}, { immediate: true })
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mt-4">
|
||||
<template v-if="items.length > 0">
|
||||
<AcquisitionResultTable :items="items" @buy="(type, price, buy, sell) => buyModal?.open(type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="type => sellModal?.open(type)" />
|
||||
<BuyModal ref="buyModal" />
|
||||
<SellModal ref="sellModal" />
|
||||
</template>
|
||||
</div>
|
||||
</template>@/market/acquisition
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { MarketType, MarketTypeInput, MarketTypePrice, getHistory, getMarketTypes, jitaId, useApraisalStore } from "@/market";
|
||||
import { ScanResult, ScanResultTable, createResult, useMarketScanStore } from '@/market/scan';
|
||||
import { BuyModal } from '@/market/track';
|
||||
import { BuyModal } from '@/market/acquisition';
|
||||
import { ScanResult, ScanResultTable, useMarketScanStore } from '@/market/scan';
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
|
||||
@@ -73,4 +73,4 @@ watch(() => markeyScanStore.types, async t => {
|
||||
<ScanResultTable :items="items" @buy="(type, buy, sell) => buyModal?.open(type, { 'Buy': buy, 'Sell': sell })" @remove="removeItem" />
|
||||
<BuyModal ref="buyModal" />
|
||||
</template>
|
||||
</template>
|
||||
</template>@/market/acquisition
|
||||
@@ -1,38 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { MarketTypePrice, getMarketTypes, useApraisalStore } from "@/market";
|
||||
import { BuyModal, SellModal, TrackResultTable, TrackedItem, useTrackedItemStore } from '@/market/track';
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
const buyModal = ref<typeof BuyModal>();
|
||||
const sellModal = ref<typeof SellModal>();
|
||||
|
||||
|
||||
const apraisalStore = useApraisalStore();
|
||||
const trackedItemStore = useTrackedItemStore();
|
||||
const items = ref<TrackedItem[]>([]);
|
||||
|
||||
watch(() => trackedItemStore.items.value, async itms => {
|
||||
if (itms.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const prices = await apraisalStore.getPrices(await getMarketTypes(itms.map(i => i.typeID)));
|
||||
|
||||
items.value = itms.map(i => {
|
||||
const price = prices.find(p => p.type.id === i.typeID) as MarketTypePrice;
|
||||
|
||||
return { ...i, ...price };
|
||||
});
|
||||
}, { immediate: true })
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mt-4">
|
||||
<template v-if="items.length > 0">
|
||||
<TrackResultTable :items="items" @buy="(type, price, buy, sell) => buyModal?.open(type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="type => sellModal?.open(type)" />
|
||||
<BuyModal ref="buyModal" />
|
||||
<SellModal ref="sellModal" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -8,7 +8,7 @@ export const routes: RouteRecordRaw[] = [
|
||||
{ path: '', redirect: '/market/type' },
|
||||
{ path: 'type/:type?', name: 'market-type', component: () => import('@/pages/market/TypeInfo.vue') },
|
||||
{ path: 'scan', component: () => import('@/pages/market/Scan.vue') },
|
||||
{ path: 'track', component: () => import('@/pages/market/Track.vue') },
|
||||
{ path: 'acquisitions', component: () => import('@/pages/market/Acquisitions.vue') },
|
||||
] },
|
||||
{ path: '/tools', component: () => import('@/pages/Tools.vue') },
|
||||
{ path: '/about', component: () => import('@/pages/About.vue') },
|
||||
|
||||
Reference in New Issue
Block a user