add taxes

This commit is contained in:
2023-10-02 09:52:11 +02:00
parent 0026cba23d
commit 2b513a91b0
8 changed files with 54 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
export * from './tax';
export * from './type'; export * from './type';
export * from './MarketOrderHistory'; export * from './MarketOrderHistory';

View File

@@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { formatIsk, percentFormater } from '@/formaters'; import { formatIsk, percentFormater } from '@/formaters';
import { MarketType, MarketTypeLabel } from "@/market"; import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/market";
import { SortableHeader, useSort } from '@/table'; import { SortableHeader, useSort } from '@/table';
import { ShoppingCartIcon, TrashIcon } from '@heroicons/vue/24/outline'; import { ShoppingCartIcon, TrashIcon } from '@heroicons/vue/24/outline';
import { useStorage } from '@vueuse/core'; import { useStorage } from '@vueuse/core';
@@ -33,6 +33,8 @@ const props = withDefaults(defineProps<Props>(), {
}); });
defineEmits<Emits>(); defineEmits<Emits>();
const marketTaxStore = useMarketTaxStore();
const days = useStorage('market-scan-days', 365); const days = useStorage('market-scan-days', 365);
const threshold = useStorage('market-scan-threshold', 10); const threshold = useStorage('market-scan-threshold', 10);
const filter = ref(""); const filter = ref("");
@@ -50,7 +52,7 @@ const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items
q1: quartils.q1, q1: quartils.q1,
mmedian: quartils.median, mmedian: quartils.median,
q3: quartils.q3, q3: quartils.q3,
profit: (quartils.q3 / quartils.q1) -1 profit: marketTaxStore.calculateProfit(quartils.q1, quartils.q3)
}; };
})), { })), {
defaultSortKey: 'name', defaultSortKey: 'name',
@@ -71,6 +73,7 @@ const getLineColor = (result: Result) => {
<template> <template>
<div class="flex"> <div class="flex">
<div class="flex justify-self-end mb-2 mt-4 ms-auto"> <div class="flex justify-self-end mb-2 mt-4 ms-auto">
<TaxInput />
<div class="end"> <div class="end">
<span>Profit Threshold: </span> <span>Profit Threshold: </span>
<input type="number" min="0" max="1000" step="1" v-model="threshold" /> <input type="number" min="0" max="1000" step="1" v-model="threshold" />

View File

@@ -18,7 +18,7 @@ interface MarketScan extends RecordModel {
const marketScans = 'marketScans'; const marketScans = 'marketScans';
export const useMarkeyScanStore = defineStore(marketScans, () => { export const useMarketScanStore = defineStore(marketScans, () => {
const pb = usePocketBase(); const pb = usePocketBase();
const marketScan = ref<MarketScan>(); const marketScan = ref<MarketScan>();

View File

@@ -0,0 +1,24 @@
<script setup lang="ts">
import { storeToRefs } from "pinia";
import { useMarketTaxStore } from "./tax";
const { brokerFee, scc } = storeToRefs(useMarketTaxStore());
</script>
<template>
<div class="end">
<span>Broker Fee: </span>
<input type="number" min="1" max="3" step="0.01" v-model="brokerFee" />
</div>
<div class="end">
<span>SCC: </span>
<input type="number" min="3.6" max="8" step="0.01" v-model="scc" >
</div>
</template>
<style scoped lang="postcss">
div.end {
@apply justify-self-end ms-2;
}
</style>

4
src/market/tax/index.ts Normal file
View File

@@ -0,0 +1,4 @@
export * from './tax';
export { default as TaxInput } from './TaxInput.vue';

12
src/market/tax/tax.ts Normal file
View File

@@ -0,0 +1,12 @@
import { useLocalStorage } from "@vueuse/core";
import { defineStore } from "pinia";
export const useMarketTaxStore = defineStore("marketTax", () => {
const brokerFee = useLocalStorage("market-brokerFee", 1.5);
const scc = useLocalStorage("market-scc", 3.6);
const applyTaxes = (price: number, sellOrder?: boolean) => sellOrder ? price * (1 - (brokerFee.value + scc.value) / 100) : price * (1 + brokerFee.value / 100);
const calculateProfit = (buy: number, sell: number) => (applyTaxes(sell, true) / applyTaxes(buy)) - 1;
return { brokerFee, scc, applyTaxes, calculateProfit };
});

View File

@@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { formatIsk, percentFormater } from '@/formaters'; import { formatIsk, percentFormater } from '@/formaters';
import { MarketType, MarketTypeLabel } from "@/market"; import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/market";
import { SortableHeader, useSort } from '@/table'; import { SortableHeader, useSort } from '@/table';
import { MinusIcon, PlusIcon } from '@heroicons/vue/24/outline'; import { MinusIcon, PlusIcon } from '@heroicons/vue/24/outline';
import { useStorage } from '@vueuse/core'; import { useStorage } from '@vueuse/core';
@@ -33,12 +33,14 @@ const props = withDefaults(defineProps<Props>(), {
}); });
defineEmits<Emits>(); defineEmits<Emits>();
const marketTaxStore = useMarketTaxStore();
const threshold = useStorage('market-track-threshold', 10); const threshold = useStorage('market-track-threshold', 10);
const filter = ref(""); const filter = ref("");
const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items
.filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase())) .filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase()))
.map(r => { .map(r => {
const precentProfit = (r.sell / r.averagePrice) - 1; const precentProfit = marketTaxStore.calculateProfit(r.averagePrice, r.sell);
return { return {
type: r.type, type: r.type,
@@ -68,6 +70,7 @@ const getLineColor = (result: Result) => {
<template> <template>
<div class="flex"> <div class="flex">
<div class="flex justify-self-end mb-2 mt-4 ms-auto"> <div class="flex justify-self-end mb-2 mt-4 ms-auto">
<TaxInput />
<div class="end"> <div class="end">
<span>Profit Threshold: </span> <span>Profit Threshold: </span>
<input type="number" min="0" max="1000" step="1" v-model="threshold" /> <input type="number" min="0" max="1000" step="1" v-model="threshold" />

View File

@@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { MarketType, MarketTypePrice, getHistory, getMarketType, getMarketTypes, jitaId, useApraisalStore } from "@/market"; import { MarketType, MarketTypePrice, getHistory, getMarketType, getMarketTypes, jitaId, useApraisalStore } from "@/market";
import { ScanResult, ScanResultTable, useMarkeyScanStore } from '@/market/scan'; import { ScanResult, ScanResultTable, useMarketScanStore } from '@/market/scan';
import { BuyModal } from '@/market/track'; import { BuyModal } from '@/market/track';
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
@@ -10,7 +10,7 @@ const buyModal = ref<typeof BuyModal>();
const item = ref(""); const item = ref("");
const apraisalStore = useApraisalStore(); const apraisalStore = useApraisalStore();
const markeyScanStore = useMarkeyScanStore(); const markeyScanStore = useMarketScanStore();
const items = ref<ScanResult[]>([]); const items = ref<ScanResult[]>([]);
const addOrRelaod = async (type: MarketType) => { const addOrRelaod = async (type: MarketType) => {
const typeID = type.id; const typeID = type.id;