-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8bb99d
commit 2792474
Showing
10 changed files
with
347 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import store from '@/store'; | ||
import backend from './backend'; | ||
|
||
export class ClearingManager { | ||
public static get dailyClearings(): DailyClearing[] { | ||
return store.getters.dailyClearings || []; | ||
} | ||
|
||
public static async loadDailyClearings(): Promise<void> { | ||
if (this.dailyClearings.length > 0) return; | ||
const { data } = await backend.get('clearing/daily'); | ||
store.commit('dailyClearings', data); | ||
} | ||
|
||
public static get sorted(): DailyClearing[] { | ||
return [...this.dailyClearings] | ||
.sort((a, b) => b.year - a.year) | ||
.sort((a, b) => b.month - a.month) | ||
.sort((a, b) => b.day - a.day); | ||
} | ||
} | ||
|
||
export interface DailyClearing { | ||
id: string; | ||
brokerId: string; | ||
orderAmount: number; | ||
volumeBuy: number; | ||
volumeSell: number; | ||
day: number; | ||
month: number; | ||
year: number; | ||
transactionPrice: number; | ||
tradePrice: number; | ||
fixum: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import store from '@/store'; | ||
import backend from './backend'; | ||
import { Broker, BrokerManager } from './BrokerManager'; | ||
|
||
export class InvoiceManager { | ||
public static get invoices(): Invoice[] { | ||
const inv = (store.getters.invoices || []) as Invoice[]; | ||
return inv.sort((a, b) => a.timestamp - b.timestamp); | ||
} | ||
|
||
private static commit(invoices: Invoice[]) { | ||
if (!invoices) return; | ||
invoices = invoices.filter(x => x.amount > 0); | ||
store.commit('invoices', invoices); | ||
} | ||
|
||
public static async loadInvoices(): Promise<void> { | ||
if (this.invoices.length > 0) return; | ||
const { data } = await backend.get('invoice/all'); | ||
this.commit(data); | ||
} | ||
|
||
public static getUniqueBroker(): Broker[] { | ||
const broker = [...(this.invoices || [])].map(x => x.brokerId); | ||
const unqiue = [...new Set(broker)]; | ||
return unqiue | ||
.map(x => BrokerManager.getBroker(x)) | ||
.filter(x => !!x) as Broker[]; | ||
} | ||
|
||
public static get total(): number { | ||
return [...this.invoices] | ||
.filter(x => !x.payed) | ||
.reduce((a, b) => a + b.amount, 0); | ||
} | ||
|
||
public static get due(): number { | ||
return [...this.invoices].filter(x => !x.payed).length; | ||
} | ||
|
||
public static get avg(): number { | ||
return this.total / this.due; | ||
} | ||
} | ||
|
||
export interface Invoice { | ||
brokerId: string; | ||
timestamp: number; | ||
month: number; | ||
year: number; | ||
payed: boolean; | ||
amount: number; | ||
description?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,128 @@ | ||
<template> | ||
<div class="view-clearing" content> | ||
<h1>Clearing</h1> | ||
|
||
<tl-grid minWidth="170" gap="20"> | ||
<BChartWrapper title="Buy Volume" subtitle="Total"> | ||
<span>{{ buy }}</span> | ||
</BChartWrapper> | ||
<BChartWrapper title="Sell Volume" subtitle="Total"> | ||
<span>{{ sell }}</span> | ||
</BChartWrapper> | ||
</tl-grid> | ||
|
||
<div v-for="b in uniqueBroker" :key="b.id"> | ||
<br /> | ||
<h2>{{ b.displayName }}</h2> | ||
<tc-table :dark="true"> | ||
<template slot="head"> | ||
<!-- <tc-th>Tag</tc-th> --> | ||
<tc-th>Monat</tc-th> | ||
<tc-th>Jahr</tc-th> | ||
<tc-th>Buy Volume</tc-th> | ||
<tc-th>Sell Volume</tc-th> | ||
</template> | ||
<tc-tr v-for="d in daily.filter(x => x.brokerId === b.id)" :key="d.id"> | ||
<!-- <tc-td>{{ d.day }}</tc-td> --> | ||
<tc-td>{{ d.month }}</tc-td> | ||
<tc-td>{{ d.year }}</tc-td> | ||
<tc-td tfcolor="success">{{ format(d.volumeBuy) }} €</tc-td> | ||
<tc-td tfcolor="error">{{ format(d.volumeSell) }} €</tc-td> | ||
|
||
<template slot="expander"> | ||
<table class="expander-table"> | ||
<tr> | ||
<th>Transaction</th> | ||
<th>Trade</th> | ||
<th>Fixum</th> | ||
</tr> | ||
<tr> | ||
<td>{{ map(d.transactionPrice) }}</td> | ||
<td>{{ map(d.tradePrice) }}</td> | ||
<td>{{ map(d.fixum) }}</td> | ||
</tr> | ||
</table> | ||
</template> | ||
</tc-tr> | ||
</tc-table> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import BAnimatedNumber from '@/components/BAnimatedNumber.vue'; | ||
import BChartWrapper from '@/components/charts/BChartWrapper.vue'; | ||
import { Broker, BrokerManager } from '@/utils/BrokerManager'; | ||
import { ClearingManager, DailyClearing } from '@/utils/ClearingManager'; | ||
import { Vue, Component } from 'vue-property-decorator'; | ||
@Component | ||
export default class Clearing extends Vue {} | ||
@Component({ | ||
components: { | ||
BAnimatedNumber, | ||
BChartWrapper | ||
} | ||
}) | ||
export default class Clearing extends Vue { | ||
get daily(): DailyClearing[] { | ||
return ClearingManager.sorted; | ||
} | ||
format(n: number): string { | ||
return Intl.NumberFormat('en-GB', { notation: 'compact' }).format(n); | ||
} | ||
map(n: number): number { | ||
return Math.round(n * 100) / 100; | ||
} | ||
get uniqueBroker(): Broker[] { | ||
const broker = [...this.daily].map(x => x.brokerId); | ||
const unique = [...new Set(broker)]; | ||
return unique | ||
.map(x => BrokerManager.getBroker(x)) | ||
.filter(x => !!x) as Broker[]; | ||
} | ||
get buy(): string { | ||
const sum = this.daily.reduce((a, b) => a + b.volumeBuy, 0); | ||
return this.format(sum); | ||
} | ||
get sell(): string { | ||
const sum = this.daily.reduce((a, b) => a + b.volumeSell, 0); | ||
return this.format(sum); | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.view-clearing { | ||
// | ||
.b-chart-wrapper { | ||
position: relative; | ||
i { | ||
position: absolute; | ||
top: 50%; | ||
right: 20px; | ||
font-size: 30px; | ||
transform: translateY(-50%); | ||
opacity: 0.75; | ||
} | ||
span { | ||
font-size: 25px; | ||
font-weight: bold; | ||
color: $error; | ||
} | ||
} | ||
.tc-tr { | ||
cursor: pointer; | ||
} | ||
.expander-table { | ||
width: 100%; | ||
text-align: center; | ||
border-collapse: collapse; | ||
} | ||
} | ||
</style> |
Oops, something went wrong.