Add more invoice statistics
This commit is contained in:
@@ -10,6 +10,7 @@ type Invoice = {
|
|||||||
time: string
|
time: string
|
||||||
amount: number
|
amount: number
|
||||||
vat: number
|
vat: number
|
||||||
|
processing_fee: number
|
||||||
country: string
|
country: string
|
||||||
payment_method: string
|
payment_method: string
|
||||||
status: string
|
status: string
|
||||||
@@ -26,16 +27,26 @@ type Total = {
|
|||||||
count: number
|
count: number
|
||||||
amount: number
|
amount: number
|
||||||
vat: number
|
vat: number
|
||||||
|
fee: number
|
||||||
}
|
}
|
||||||
let totals: { [id: string]: Total } = {}
|
let totals_provider: { [id: string]: Total } = {}
|
||||||
|
let totals_country: { [id: string]: Total } = {}
|
||||||
const add_total = (i: Invoice) => {
|
const add_total = (i: Invoice) => {
|
||||||
if (totals[i.payment_method] === undefined) {
|
if (totals_provider[i.payment_method] === undefined) {
|
||||||
totals[i.payment_method] = {count: 0, amount: 0, vat: 0}
|
totals_provider[i.payment_method] = {count: 0, amount: 0, vat: 0, fee: 0}
|
||||||
|
}
|
||||||
|
if (totals_country[i.country] === undefined) {
|
||||||
|
totals_country[i.country] = {count: 0, amount: 0, vat: 0, fee: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
totals[i.payment_method].count++
|
totals_provider[i.payment_method].count++
|
||||||
totals[i.payment_method].amount += i.amount
|
totals_provider[i.payment_method].amount += i.amount
|
||||||
totals[i.payment_method].vat += i.vat
|
totals_provider[i.payment_method].vat += i.vat
|
||||||
|
totals_provider[i.payment_method].fee += i.processing_fee
|
||||||
|
totals_country[i.country].count++
|
||||||
|
totals_country[i.country].amount += i.amount
|
||||||
|
totals_country[i.country].vat += i.vat
|
||||||
|
totals_country[i.country].fee += i.processing_fee
|
||||||
}
|
}
|
||||||
|
|
||||||
const get_invoices = async () => {
|
const get_invoices = async () => {
|
||||||
@@ -59,7 +70,8 @@ const get_invoices = async () => {
|
|||||||
return date_a.getTime() - date_b.getTime()
|
return date_a.getTime() - date_b.getTime()
|
||||||
})
|
})
|
||||||
|
|
||||||
totals = {}
|
totals_provider = {}
|
||||||
|
totals_country = {}
|
||||||
resp_json.forEach(row => {
|
resp_json.forEach(row => {
|
||||||
if (row.status === "paid") {
|
if (row.status === "paid") {
|
||||||
add_total(row)
|
add_total(row)
|
||||||
@@ -120,11 +132,59 @@ onMount(() => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#each Object.entries(totals) as [key, tot]}
|
<h4>Invoices per payment processor</h4>
|
||||||
{key} ({tot.count})<br/>
|
<div class="table_scroll" style="text-align: initial;">
|
||||||
Amount:<Euro amount={tot.amount}/><br/>
|
<table>
|
||||||
VAT: <Euro amount={tot.vat}/><br/>
|
<thead>
|
||||||
{/each}
|
<tr>
|
||||||
|
<td>Provider</td>
|
||||||
|
<td>Count</td>
|
||||||
|
<td>Amount</td>
|
||||||
|
<td>VAT</td>
|
||||||
|
<td>Fee</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each Object.entries(totals_provider) as [key, tot]}
|
||||||
|
<tr>
|
||||||
|
<td>{key}</td>
|
||||||
|
<td>{tot.count}</td>
|
||||||
|
<td><Euro amount={tot.amount}/></td>
|
||||||
|
<td><Euro amount={tot.vat}/></td>
|
||||||
|
<td><Euro amount={tot.fee}/></td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h4>Invoices per country</h4>
|
||||||
|
<div class="table_scroll" style="text-align: initial;">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>Country</td>
|
||||||
|
<td>Count</td>
|
||||||
|
<td>Amount</td>
|
||||||
|
<td>VAT</td>
|
||||||
|
<td>Fee</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each Object.entries(totals_country) as [key, tot]}
|
||||||
|
<tr>
|
||||||
|
<td>{key}</td>
|
||||||
|
<td>{tot.count}</td>
|
||||||
|
<td><Euro amount={tot.amount}/></td>
|
||||||
|
<td><Euro amount={tot.vat}/></td>
|
||||||
|
<td><Euro amount={tot.fee}/></td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h4>All invoices</h4>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div class="table_scroll" style="text-align: initial;">
|
<div class="table_scroll" style="text-align: initial;">
|
||||||
@@ -135,6 +195,7 @@ onMount(() => {
|
|||||||
<td>ID</td>
|
<td>ID</td>
|
||||||
<td>Amount</td>
|
<td>Amount</td>
|
||||||
<td>VAT</td>
|
<td>VAT</td>
|
||||||
|
<td>Fee</td>
|
||||||
<td>Country</td>
|
<td>Country</td>
|
||||||
<td>Method</td>
|
<td>Method</td>
|
||||||
<td>Status</td>
|
<td>Status</td>
|
||||||
@@ -147,6 +208,7 @@ onMount(() => {
|
|||||||
<td>{row.id}</td>
|
<td>{row.id}</td>
|
||||||
<td><Euro amount={row.amount}/></td>
|
<td><Euro amount={row.amount}/></td>
|
||||||
<td><Euro amount={row.vat}/></td>
|
<td><Euro amount={row.vat}/></td>
|
||||||
|
<td><Euro amount={row.processing_fee}/></td>
|
||||||
<td>{row.country}</td>
|
<td>{row.country}</td>
|
||||||
<td>{row.payment_method}</td>
|
<td>{row.payment_method}</td>
|
||||||
<td>{row.status}</td>
|
<td>{row.status}</td>
|
||||||
|
Reference in New Issue
Block a user