acquisition ui

This commit is contained in:
Sirttas
2026-06-06 15:53:54 +02:00
parent 5506125b2e
commit 653f7dbeeb
7 changed files with 54 additions and 42 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
import { MarketType } from "..";
import { MarbasAcquiredType } from "./acquisition";
import { RawAcquiredType } from "./acquisition";
export type AcquiredType = Omit<MarbasAcquiredType, 'type'> & {
export type AcquiredType = Omit<RawAcquiredType, 'type'> & {
type: MarketType,
buy: number,
sell: number
@@ -6,9 +6,10 @@ import {useStorage} from '@vueuse/core';
import {computed, ref} from 'vue';
import {AcquiredType} from './AcquiredType';
import AcquisitionQuantilsTooltip from './AcquisitionQuantilsTooltip.vue';
import {formatEveDate, formatIsk, percentFormater} from "@/formaters.ts";
type Result = {
id: number;
id: string;
type: MarketType;
name: string;
buy: number;
@@ -97,7 +98,7 @@ const { sortedArray, headerProps, showColumn } = useSort<Result>(computed(() =>
const precentProfit = marketTaxStore.calculateProfit(price, first.sell);
list.push({
id: typeID,
id: typeID.toString(),
type: first.type,
name: first.type.name,
buy: first.buy,
+31 -29
View File
@@ -1,41 +1,43 @@
import { defineStore } from "pinia";
import { computed, ref } from "vue";
import {defineStore} from "pinia";
import {computed, ref} from "vue";
import {acquisitionApi} from "@/mammon";
import {AcquisitionResponse, AcquisitionResponseSourceEnum} from "@/generated/mammon";
export type AcquiredTypeSource = 'bo' | 'so' | 'prod' | 'misc';
export type RawAcquiredType = {
id: string;
type: number;
quantity: number;
remaining: number;
price: number;
date: Date;
source: AcquisitionResponseSourceEnum;
}
const toAcquiredType = (a: AcquisitionResponse): RawAcquiredType => ({
id: a.acquisitionId,
type: a.marketTypeId,
quantity: a.quantity,
remaining: a.remaining,
price: a.unitCost,
date: new Date(a.datetime),
source: a.source,
});
export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
const acquiredTypes = ref<any[]>([]); // TODO
const acquiredTypes = ref<RawAcquiredType[]>([]);
const types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0));
const addAcquiredType = async (type: number, quantity: number, price: number, source?: AcquiredTypeSource) => {
const newItem = [];
acquiredTypes.value = [...acquiredTypes.value, newItem];
};
const removeAcquiredType = async (id: number, quantity: number) => {
const found = acquiredTypes.value.find(t => t.id === id);
// Display-only: the backend exposes no write endpoint yet, so buy/sell are no-ops.
const addAcquiredType = async (_type: number, _quantity: number, _price: number, _source?: AcquiredTypeSource) => {};
const removeAcquiredType = async (_id: string, _quantity: number) => {};
if (!found) {
return 0;
}
const item = {
...found,
remaining: Math.max(0, found.remaining - quantity)
};
acquiredTypes.value = acquiredTypes.value.map(i => {
if (i.id === item.id) {
return item;
} else {
return i;
}
});
};
const refresh = () => {}
const refresh = () => acquisitionApi.findAllAcquisitions()
.then(response => acquiredTypes.value = response.data.map(toAcquiredType));
refresh();
return { acquiredTypes: types, addAcquiredType, removeAcquiredType, refresh };
});
});