Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: invoice cycle changes #1331

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
c67fea4
update create
lohanidamodar Aug 28, 2024
708517a
authorize payment
lohanidamodar Aug 28, 2024
eec5c6f
support taxid and budget while creating
lohanidamodar Aug 29, 2024
414bc60
handle validation
lohanidamodar Aug 29, 2024
c97e372
fix check with cloud
lohanidamodar Sep 3, 2024
b568e85
improve
lohanidamodar Sep 3, 2024
4376c93
Merge remote-tracking branch 'origin/main' into poc-invoice-cycle-ref
lohanidamodar Sep 19, 2024
acff39b
Merge remote-tracking branch 'origin/main' into poc-invoice-cycle-ref
lohanidamodar Nov 11, 2024
81d4ad8
remove unused
lohanidamodar Nov 11, 2024
c7a9e26
allow scale selection
lohanidamodar Nov 11, 2024
f29ca9a
update plan upgrade
lohanidamodar Nov 14, 2024
7b12f36
reset delete message
lohanidamodar Nov 14, 2024
9d7e866
Merge remote-tracking branch 'origin/main' into poc-invoice-cycle-ref
lohanidamodar Nov 27, 2024
6c97f04
fix taxid
lohanidamodar Dec 2, 2024
c1e87a2
updated pricing.
ItzNotABug Dec 16, 2024
660bddd
Merge remote-tracking branch 'origin/main' into poc-invoice-cycle-ref
lohanidamodar Dec 18, 2024
bcbf5c7
address comments.
ItzNotABug Dec 19, 2024
b6a517a
ran: formatter.
ItzNotABug Dec 19, 2024
ed9f145
Merge branch 'appwrite:poc-invoice-cycle-ref' into poc-invoice-cycle-ref
ItzNotABug Dec 19, 2024
8673209
update models
lohanidamodar Dec 22, 2024
8fdf7c5
refactor and get current plan from aggregation
lohanidamodar Dec 22, 2024
1ee29b2
update summary
lohanidamodar Dec 22, 2024
10195f4
Merge remote-tracking branch 'origin/main' into poc-invoice-cycle-ref
lohanidamodar Dec 23, 2024
16705d3
fix rename
lohanidamodar Dec 23, 2024
14a0cac
refactor
lohanidamodar Dec 23, 2024
9f517bd
improvements on error
lohanidamodar Dec 23, 2024
723da2c
Merge remote-tracking branch 'origin/main' into poc-invoice-cycle-ref
lohanidamodar Dec 24, 2024
3c1c4ed
credit support from plan
lohanidamodar Dec 24, 2024
b696c6c
option to cancel downgrade
lohanidamodar Dec 24, 2024
fb926d9
cancel downgrade
lohanidamodar Dec 24, 2024
f09bbc2
Merge branch 'poc-invoice-cycle-ref' into poc-invoice-cycle-ref
ItzNotABug Dec 29, 2024
81e5d0d
refactor types
lohanidamodar Dec 30, 2024
34f0727
ci: empty commit
ItzNotABug Jan 9, 2025
5d84c3b
fix types
lohanidamodar Jan 12, 2025
3ed6edf
Merge pull request #1565 from ItzNotABug/poc-invoice-cycle-ref
lohanidamodar Jan 13, 2025
ff25151
Merge branch 'poc-invoice-cycle-ref' of github.com:appwrite/console i…
lohanidamodar Jan 13, 2025
31b1467
use new estimation api for update plan and create organiation
lohanidamodar Jan 14, 2025
d401ade
fixes
lohanidamodar Jan 15, 2025
293eac0
refactor plan selection
lohanidamodar Jan 15, 2025
1973a23
Merge remote-tracking branch 'origin/main' into poc-invoice-cycle-ref
lohanidamodar Jan 15, 2025
c567681
fix after sync
lohanidamodar Jan 15, 2025
8c9c413
fix coupon
lohanidamodar Jan 15, 2025
9553df7
fix history not showing
lohanidamodar Jan 15, 2025
dee3b53
fix summary
lohanidamodar Jan 15, 2025
654718d
fix errors
lohanidamodar Jan 19, 2025
67aeaed
fixes to applying coupon
lohanidamodar Jan 20, 2025
d64de90
improve estimatie total
lohanidamodar Jan 20, 2025
e696d0c
check estimation before delete flow
lohanidamodar Jan 20, 2025
2f36ff2
remove unused code
lohanidamodar Jan 20, 2025
09ba618
fix check
lohanidamodar Jan 20, 2025
0cb3512
Fix review comments and errors
lohanidamodar Jan 26, 2025
dda2fd8
update review comments
lohanidamodar Jan 26, 2025
8e994cb
remove old component
lohanidamodar Jan 26, 2025
6e6daca
removed unused change
lohanidamodar Jan 26, 2025
27c5453
more review fixes
lohanidamodar Jan 26, 2025
cc0f655
fix component
lohanidamodar Jan 26, 2025
f3a28cd
remove duplicates
lohanidamodar Jan 26, 2025
acb814b
fix function definiation
lohanidamodar Jan 26, 2025
4fbd814
Merge remote-tracking branch 'origin/main' into poc-invoice-cycle-ref
lohanidamodar Jan 26, 2025
dccfb28
fix new org error
lohanidamodar Jan 26, 2025
609cf5f
fix button state
lohanidamodar Jan 26, 2025
4fb76da
fix alert
lohanidamodar Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/commandCenter/searchers/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sdk } from '$lib/stores/sdk';
import type { Searcher } from '../commands';

export const orgSearcher = (async (query: string) => {
const { teams } = await sdk.forConsole.teams.list();
const { teams } = await sdk.forConsole.billing.listOrganization();
return teams
.filter((organization) => organization.name.toLowerCase().includes(query.toLowerCase()))
.map((organization) => {
Expand Down
25 changes: 25 additions & 0 deletions src/lib/components/billing/discountsApplied.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts">
import { tooltip } from '$lib/actions/tooltip';
import { formatCurrency } from '$lib/helpers/numbers';

export let label: string;
export let value: number;
</script>

{#if value > 0}
<span class="u-flex u-main-space-between">
<div class="u-flex u-cross-center u-gap-4">
<p class="text">
<span class="icon-tag u-color-text-success" aria-hidden="true" />
<span use:tooltip={{ content: label }}>
{label}
</span>
</p>
</div>
{#if value >= 100}
<p class="inline-tag">Credits applied</p>
{:else}
<span class="u-color-text-success">-{formatCurrency(value)}</span>
{/if}
</span>
{/if}
113 changes: 113 additions & 0 deletions src/lib/components/billing/estimatedTotal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<script lang="ts">
import { FormList, InputChoice, InputNumber } from '$lib/elements/forms';
import { formatCurrency } from '$lib/helpers/numbers';
import type { Estimation } from '$lib/sdk/billing';
import { sdk } from '$lib/stores/sdk';
import Alert from '../alert.svelte';
import Card from '../card.svelte';
import DiscountsApplied from './discountsApplied.svelte';

export let organizationId: string | undefined = undefined;
export let billingPlan: string;
export let collaborators: string[];
export let couponId: string;
export let fixedCoupon = false;
export let error = '';

export let billingBudget: number;

let budgetEnabled = false;
let estimation: Estimation;

async function getEstimate(billingPlan: string, collaborators: string[], couponId: string) {
try {
estimation = await sdk.forConsole.billing.estimationCreateOrganization(
billingPlan,
couponId === '' ? null : couponId,
collaborators ?? []
);
error = '';
} catch (e) {
error = e.message;
}
}

async function getUpdatePlanEstimate(
organizationId: string,
billingPlan: string,
collaborators: string[],
couponId: string | undefined
) {
try {
error = '';
estimation = await sdk.forConsole.billing.estimationUpdatePlan(
organizationId,
billingPlan,
couponId && couponId.length > 0 ? couponId : null,
collaborators ?? []
);
} catch (e) {
error = e.message;
}
}

$: organizationId
? getUpdatePlanEstimate(organizationId, billingPlan, collaborators, couponId)
: getEstimate(billingPlan, collaborators, couponId);
</script>

{#if estimation || error.length}
<Card>
{#if error.length}
<p class="u-color-text-danger">
{error}
</p>
{/if}

{#if estimation}
{#each estimation.items ?? [] as item}
<span class="u-flex u-main-space-between">
<p class="text">{item.label}</p>
<p class="text">{formatCurrency(item.value)}</p>
</span>
{/each}
{#each estimation.discounts ?? [] as item}
<DiscountsApplied {...item} />
{/each}
<div class="u-sep-block-start" />
<span class="u-flex u-main-space-between">
<p class="text">Total due</p>
<p class="text">
{formatCurrency(estimation.grossAmount)}
</p>
</span>

<p class="text u-margin-block-start-16">
You'll pay <span class="u-bold">{formatCurrency(estimation.grossAmount)}</span> now.
Once your credits run out, you'll be charged
<span class="u-bold">{formatCurrency(estimation.grossAmount)}</span> every 30 days.
</p>
{/if}

<FormList class="u-margin-block-start-24">
<InputChoice
type="switchbox"
id="budget"
label="Enable budget cap"
tooltip="If enabled, you will be notified when your spending reaches 75% of the set cap. Update cap alerts in your organization settings."
fullWidth
bind:value={budgetEnabled}>
{#if budgetEnabled}
<div class="u-margin-block-start-16">
<InputNumber
id="budget"
label="Budget cap (USD)"
placeholder="0"
min={0}
bind:value={billingBudget} />
</div>
{/if}
</InputChoice>
</FormList>
</Card>
{/if}
99 changes: 0 additions & 99 deletions src/lib/components/billing/estimatedTotalBox.svelte

This file was deleted.

3 changes: 2 additions & 1 deletion src/lib/components/billing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ export { default as PaymentBoxes } from './paymentBoxes.svelte';
export { default as CouponInput } from './couponInput.svelte';
export { default as SelectPaymentMethod } from './selectPaymentMethod.svelte';
export { default as UsageRates } from './usageRates.svelte';
export { default as EstimatedTotalBox } from './estimatedTotalBox.svelte';
export { default as PlanComparisonBox } from './planComparisonBox.svelte';
export { default as EmptyCardCloud } from './emptyCardCloud.svelte';
export { default as CreditsApplied } from './creditsApplied.svelte';
export { default as PlanSelection } from './planSelection.svelte';
export { default as EstimatedTotal } from './estimatedTotal.svelte';
export { default as SelectPlan } from './selectPlan.svelte';
51 changes: 51 additions & 0 deletions src/lib/components/billing/selectPlan.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script lang="ts">
import { BillingPlan } from '$lib/constants';
import { formatCurrency } from '$lib/helpers/numbers';
import { plansInfo } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { LabelCard } from '..';

export let billingPlan: string;
export let anyOrgFree = false;
export let isNewOrg = false;
let classes: string = '';
export { classes as class };
</script>

{#if billingPlan}
<ul class="u-flex u-flex-vertical u-gap-16 u-margin-block-start-8 {classes}">
{#each $plansInfo.values() as plan}
<li>
<LabelCard
name="plan"
bind:group={billingPlan}
disabled={ (plan.$id === BillingPlan.FREE && anyOrgFree) || !plan.selfService}
value={plan.$id}
tooltipShow={plan.$id === BillingPlan.FREE && anyOrgFree}
tooltipText={plan.$id === BillingPlan.FREE
? 'You are limited to 1 Free organization per account.'
: ''}
padding={1.5}>
<svelte:fragment slot="custom" let:disabled>
<div
class="u-flex u-flex-vertical u-gap-4 u-width-full-line"
class:u-opacity-50={disabled}>
<h4 class="body-text-2 u-bold">
{plan.name}
{#if $organization?.billingPlan === plan.$id && !isNewOrg}
<span class="inline-tag">Current plan</span>
{/if}
</h4>
<p class="u-color-text-offline u-small">
{plan.desc}
</p>
<p>
{formatCurrency(plan?.price ?? 0)}
</p>
</div>
</svelte:fragment>
</LabelCard>
</li>
{/each}
</ul>
{/if}
6 changes: 3 additions & 3 deletions src/lib/components/billing/usageRates.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@
<TableRow>
<TableCellText title="resource">{usage.resource}</TableCellText>
<TableCellText title="limit">
{plan[usage.id] || 'Unlimited'}
{plan.addons.seats.limit || 0}
</TableCellText>
{#if !isFree}
<TableCellText title="rate">
{formatCurrency(plan.addons.member.price)}/{usage?.unit}
{formatCurrency(plan.addons.seats.price)}/{usage?.unit}
</TableCellText>
{/if}
</TableRow>
{:else}
{@const addon = plan.addons[usage.id]}
{@const addon = plan.usage[usage.id]}
<TableRow>
<TableCellText title="resource">{usage.resource}</TableCellText>
<TableCellText title="limit">
Expand Down
Loading
Loading