Skip to content

Commit

Permalink
Calculate vat
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed May 14, 2024
1 parent aef6945 commit f5cb739
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 78 deletions.
10 changes: 9 additions & 1 deletion apps/dashboard/src/components/transaction-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function TransactionDetails({
)}
</h2>
<div className="flex justify-between items-center">
<div className="flex flex-col w-full">
<div className="flex flex-col w-full space-y-1">
{isLoading ? (
<Skeleton className="w-[50%] h-[30px] rounded-md mb-2" />
) : (
Expand All @@ -203,6 +203,14 @@ export function TransactionDetails({
/>
</span>
)}
<div className="h-3">
{data?.vat > 0 && (
<span className="text-[#606060] text-xs">
VAT{" "}
<FormatAmount amount={data.vat} currency={data.currency} />
</span>
)}
</div>
</div>
</div>
</div>
Expand Down
15 changes: 14 additions & 1 deletion packages/jobs/src/transactions/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ client.defineJob({
.from("decrypted_transactions")
.select(
`
*,
id,
date,
name:decrypted_name,
amount,
note,
balance,
currency,
vat:calculated_vat,
attachments:transaction_attachments(*)
`,
{ count: "exact" }
Expand Down Expand Up @@ -115,6 +121,12 @@ client.defineJob({
style: "currency",
currency: transaction.currency,
}).format(transaction.amount),
transaction?.vat
? Intl.NumberFormat(locale, {
style: "currency",
currency: transaction.currency,
}).format(transaction?.vat)
: "",
transaction?.attachments?.length > 0 ? "✔️" : "❌",
transaction?.note ?? "",
transaction?.balance ?? "",
Expand All @@ -126,6 +138,7 @@ client.defineJob({
"Date",
"Description",
"Amount",
"VAT",
"Attachment",
"Note",
"Balance",
Expand Down
4 changes: 3 additions & 1 deletion packages/supabase/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export async function getTransactionsQuery(
"category:transaction_categories(id, name, color, slug)",
"bank_account:decrypted_bank_accounts(id, name:decrypted_name, currency, bank_connection:decrypted_bank_connections(id, logo_url))",
"attachments:transaction_attachments(id, name, size, path, type)",
"vat:calculated_vat",
];

const query = supabase
Expand Down Expand Up @@ -311,7 +312,8 @@ export async function getTransactionQuery(supabase: Client, id: string) {
assigned:assigned_id(*),
category:category_slug(id, name, vat),
attachments:transaction_attachments(*),
bank_account:decrypted_bank_accounts(id, name:decrypted_name, currency, bank_connection:decrypted_bank_connections(id, logo_url))
bank_account:decrypted_bank_accounts(id, name:decrypted_name, currency, bank_connection:decrypted_bank_connections(id, logo_url)),
vat:calculated_vat
`
)
.eq("id", id)
Expand Down
127 changes: 52 additions & 75 deletions packages/supabase/src/types/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,33 +590,56 @@ export type Database = {
transaction_enrichments: {
Row: {
category: Database["public"]["Enums"]["transactionCategories"] | null
category_slug: string | null
created_at: string
created_by: string | null
id: string
name: string | null
system: boolean | null
team_id: string | null
}
Insert: {
category?: Database["public"]["Enums"]["transactionCategories"] | null
category_slug?: string | null
created_at?: string
created_by?: string | null
id?: string
name?: string | null
system?: boolean | null
team_id?: string | null
}
Update: {
category?: Database["public"]["Enums"]["transactionCategories"] | null
category_slug?: string | null
created_at?: string
created_by?: string | null
id?: string
name?: string | null
system?: boolean | null
team_id?: string | null
}
Relationships: [
{
foreignKeyName: "transaction_enrichments_category_slug_team_id_fkey"
columns: ["category_slug", "team_id"]
isOneToOne: false
referencedRelation: "transaction_categories"
referencedColumns: ["slug", "team_id"]
},
{
foreignKeyName: "transaction_enrichments_created_by_fkey"
columns: ["created_by"]
isOneToOne: false
referencedRelation: "users"
referencedColumns: ["id"]
},
{
foreignKeyName: "transaction_enrichments_team_id_fkey"
columns: ["team_id"]
isOneToOne: false
referencedRelation: "teams"
referencedColumns: ["id"]
},
]
}
transactions: {
Expand Down Expand Up @@ -985,36 +1008,59 @@ export type Database = {
decrypted_transaction_enrichments: {
Row: {
category: Database["public"]["Enums"]["transactionCategories"] | null
category_slug: string | null
created_at: string | null
created_by: string | null
decrypted_name: string | null
id: string | null
name: string | null
system: boolean | null
team_id: string | null
}
Insert: {
category?: Database["public"]["Enums"]["transactionCategories"] | null
category_slug?: string | null
created_at?: string | null
created_by?: string | null
decrypted_name?: never
id?: string | null
name?: string | null
system?: boolean | null
team_id?: string | null
}
Update: {
category?: Database["public"]["Enums"]["transactionCategories"] | null
category_slug?: string | null
created_at?: string | null
created_by?: string | null
decrypted_name?: never
id?: string | null
name?: string | null
system?: boolean | null
team_id?: string | null
}
Relationships: [
{
foreignKeyName: "transaction_enrichments_category_slug_team_id_fkey"
columns: ["category_slug", "team_id"]
isOneToOne: false
referencedRelation: "transaction_categories"
referencedColumns: ["slug", "team_id"]
},
{
foreignKeyName: "transaction_enrichments_created_by_fkey"
columns: ["created_by"]
isOneToOne: false
referencedRelation: "users"
referencedColumns: ["id"]
},
{
foreignKeyName: "transaction_enrichments_team_id_fkey"
columns: ["team_id"]
isOneToOne: false
referencedRelation: "teams"
referencedColumns: ["id"]
},
]
}
decrypted_transactions: {
Expand Down Expand Up @@ -1136,6 +1182,12 @@ export type Database = {
}
Returns: string
}
calculated_vat: {
Args: {
"": unknown
}
Returns: number
}
extract_product_names: {
Args: {
products_json: Json
Expand Down Expand Up @@ -1198,32 +1250,13 @@ export type Database = {
value: number
}[]
}
get_burn_rate_v2: {
Args: {
team_id: string
date_from: string
date_to: string
currency: string
}
Returns: {
date: string
value: number
}[]
}
get_current_burn_rate: {
Args: {
team_id: string
currency: string
}
Returns: number
}
get_current_burn_rate_v2: {
Args: {
team_id: string
currency: string
}
Returns: number
}
get_profit: {
Args: {
team_id: string
Expand All @@ -1236,18 +1269,6 @@ export type Database = {
value: number
}[]
}
get_profit_v2: {
Args: {
team_id: string
date_from: string
date_to: string
currency: string
}
Returns: {
date: string
value: number
}[]
}
get_revenue: {
Args: {
team_id: string
Expand All @@ -1260,18 +1281,6 @@ export type Database = {
value: number
}[]
}
get_revenue_v2: {
Args: {
team_id: string
date_from: string
date_to: string
currency: string
}
Returns: {
date: string
value: number
}[]
}
get_runway: {
Args: {
team_id: string
Expand All @@ -1282,20 +1291,6 @@ export type Database = {
Returns: number
}
get_spending: {
Args: {
team_id: string
date_from: string
date_to: string
currency_target: string
}
Returns: {
category: string
amount: number
currency: string
percentage: number
}[]
}
get_spending_v2: {
Args: {
team_id: string
date_from: string
Expand All @@ -1311,24 +1306,6 @@ export type Database = {
percentage: number
}[]
}
get_total_amount: {
Args: {
team_id: string
}
Returns: {
currency: string
total_amount: number
}[]
}
get_total_amount_v2: {
Args: {
team_id: string
}
Returns: {
currency: string
total_amount: number
}[]
}
get_total_balance: {
Args: {
team_id: string
Expand Down

0 comments on commit f5cb739

Please sign in to comment.