feat(#14): Wire manual buy/sell to the mammon acquire/consume endpoints

This commit is contained in:
Sirttas
2026-07-06 22:02:27 +02:00
parent 2a145bbbe7
commit d2a3a22ddf
11 changed files with 442 additions and 54 deletions
+38 -12
View File
@@ -1,8 +1,9 @@
<script setup lang="ts">
import { Modal } from '@/components';
import { MarketType, MarketTypeLabel } from '@/market';
import { ref } from 'vue';
import { AcquiredType, acquiredTypesToSorted } from './AcquiredType';
import { Ledger, LedgerSelect } from '@/ledger';
import { computed, ref } from 'vue';
import { AcquiredType, acquiredTypesToSorted, fromEveDatetimeInput, toEveDatetimeInput } from './AcquiredType';
import { useAcquiredTypesStore } from './acquisition';
@@ -11,9 +12,14 @@ const acquiredTypesStore = useAcquiredTypesStore();
const modalOpen = ref<boolean>(false);
const type = ref<MarketType>();
const count = ref(1);
const date = ref('');
const types = ref<AcquiredType[]>([]);
const contextLedgerId = ref<string>();
const ledger = ref<Ledger>();
const open = (t: AcquiredType[]) => {
const ledgerId = computed(() => contextLedgerId.value ?? ledger.value?.ledgerId);
const open = (t: AcquiredType[], ledgerId?: string) => {
if (t.length === 0) {
return;
}
@@ -21,25 +27,37 @@ const open = (t: AcquiredType[]) => {
types.value = acquiredTypesToSorted(t);
type.value = t[0].type;
count.value = 1;
date.value = toEveDatetimeInput(new Date());
contextLedgerId.value = ledgerId;
ledger.value = undefined;
modalOpen.value = true;
}
const remove = async () => {
if (!types.value) {
const remove = async () => {
if (types.value.length === 0) {
modalOpen.value = false;
return;
}
let c = count.value;
const lid = ledgerId.value;
for (const type of types.value) {
const remaining = type.remaining;
if (!lid) {
return;
}
await acquiredTypesStore.removeAcquiredType(type.id, c);
c -= remaining;
if (c <= 0) {
const datetime = fromEveDatetimeInput(date.value);
let remaining = count.value;
for (const t of types.value) {
if (remaining <= 0) {
break;
}
const quantity = Math.min(remaining, t.remaining);
await acquiredTypesStore.removeAcquiredType(t.id, quantity, lid, datetime);
remaining -= quantity;
}
await acquiredTypesStore.processNewActivities();
modalOpen.value = false;
}
@@ -61,7 +79,15 @@ defineExpose({ open });
</div>
</div>
</div>
<button class="mb-auto" @click="remove">Remove</button>
<div class="flex me-2 mb-auto">
<span>Eve Time: </span>
<input class="ms-2" type="datetime-local" v-model="date" />
</div>
<div v-if="!contextLedgerId" class="flex me-2 mb-auto">
<span>Ledger: </span>
<LedgerSelect class="ms-2" v-model="ledger" />
</div>
<button class="mb-auto" :disabled="!ledgerId" @click="remove">Remove</button>
</div>
</div>
</Modal>