Tweak subscriptions some more
This commit is contained in:
1 parent
1f7238841a
commit
a50ac7310f
9 files changed
+107
-372
No files matched your search
@@ -1,7 +1,33 @@
|
||||
<script lang="ts">
|
||||
import { days_per_month, subscription_periods } from "lib/NovaAPI";
|
||||
import { user } from "lib/UserStore";
|
||||
import Euro from "util/Euro.svelte";
|
||||
import { formatDataVolume } from "util/Formatting";
|
||||
import { formatDataVolume, formatDate, formatEuros } from "util/Formatting";
|
||||
|
||||
// What the account costs per day at its current usage, the same sum the server
|
||||
// charges every night. Data transfer above the plan is left out, it can't be
|
||||
// predicted
|
||||
let daily_cost = $derived.by(() => {
|
||||
if ($user === null || $user.subscription.type !== "subscription") {
|
||||
return 0
|
||||
}
|
||||
|
||||
const sub = $user.subscription
|
||||
const discount = subscription_periods.find(
|
||||
p => p.months === $user.subscription_months,
|
||||
)?.discount ?? 1
|
||||
const extra_storage = $user.usage_based_billing ?
|
||||
Math.max(0, $user.storage_space_used - sub.storage_limit) *
|
||||
sub.price_per_tb_storage / 1e12 : 0
|
||||
|
||||
return (sub.monthly_fee * discount + extra_storage) / days_per_month
|
||||
})
|
||||
|
||||
let credit_until = $derived.by(() => {
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() + Math.floor($user.balance_micro_eur / daily_cost))
|
||||
return formatDate(date, false, false, false)
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if $user !== null}
|
||||
@@ -16,6 +42,18 @@ import { formatDataVolume } from "util/Formatting";
|
||||
<li>
|
||||
Current account balance: <Euro amount={$user.balance_micro_eur}></Euro><br/>
|
||||
|
||||
{#if daily_cost > 0}
|
||||
Your plan costs {formatEuros(daily_cost, 4)} per day at your
|
||||
current usage.
|
||||
{#if $user.balance_micro_eur > 0}
|
||||
Your credit lasts until about {credit_until}.
|
||||
{/if}
|
||||
{#if $user.usage_based_billing}
|
||||
Data transfer above your plan is not included.
|
||||
{/if}
|
||||
<br/>
|
||||
{/if}
|
||||
|
||||
<i class="icon">account_balance_wallet</i>
|
||||
<a href="/user/subscription/manage">Deposit credit</a><br/>
|
||||
|
||||
|
||||
Reference in new issue
Block a user