Compare commits
No commits in common. "d328311ed606405700c0c09d38c2aa7ee791fc0f" and "41f30abcb446e6b0c0e6e4004cb5511b98a4dbe1" have entirely different histories.
d328311ed6
...
41f30abcb4
|
@ -18,8 +18,6 @@ export interface Card {
|
||||||
have_credit_line: boolean;
|
have_credit_line: boolean;
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
last_digits: string;
|
|
||||||
currency_id: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Category {
|
export interface Category {
|
||||||
|
@ -105,13 +103,6 @@ export interface Metric {
|
||||||
short: string;
|
short: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Currency {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
iso_name: string;
|
|
||||||
symbol: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const EntityTypes = {
|
export const EntityTypes = {
|
||||||
card: "Card",
|
card: "Card",
|
||||||
type: "Type",
|
type: "Type",
|
||||||
|
@ -121,7 +112,6 @@ export const EntityTypes = {
|
||||||
transfer: "Transfer",
|
transfer: "Transfer",
|
||||||
payment: "Payment",
|
payment: "Payment",
|
||||||
metric: "Metric",
|
metric: "Metric",
|
||||||
currency: "Currency",
|
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type EntityName = keyof typeof EntityTypes;
|
export type EntityName = keyof typeof EntityTypes;
|
||||||
|
@ -134,7 +124,6 @@ export type EntityType<T extends EntityName> =
|
||||||
T extends "transfer" ? Transfer :
|
T extends "transfer" ? Transfer :
|
||||||
T extends "payment" ? Payment :
|
T extends "payment" ? Payment :
|
||||||
T extends "metric" ? Metric :
|
T extends "metric" ? Metric :
|
||||||
T extends "currency" ? Currency :
|
|
||||||
never;
|
never;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { type Card, type Currency } from "$lib/entities";
|
import { type Card } from "$lib/entities";
|
||||||
import { NumberToFPA } from "$lib/util/fpa";
|
import { NumberToFPA } from "$lib/util/fpa";
|
||||||
|
|
||||||
let cards: Card[] = $state([]);
|
let cards: Card[] = $state([]);
|
||||||
let currencies: Currency[] = $state([]);
|
|
||||||
let error: string | null = $state(null);
|
let error: string | null = $state(null);
|
||||||
let editingCard: Card | null = $state(null);
|
let editingCard: Card | null = $state(null);
|
||||||
let newCard: Partial<Card> = $state({
|
let newCard: Partial<Card> = $state({
|
||||||
|
@ -17,7 +16,6 @@
|
||||||
// Fetch all cards on page load
|
// Fetch all cards on page load
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await fetchCards();
|
await fetchCards();
|
||||||
await fetchCurrencies();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function fetchCards() {
|
async function fetchCards() {
|
||||||
|
@ -29,15 +27,6 @@
|
||||||
cards = await result.json();
|
cards = await result.json();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function fetchCurrencies() {
|
|
||||||
const result = await fetch("/api/currency/all");
|
|
||||||
if (!result.ok) {
|
|
||||||
const obj = await result.json();
|
|
||||||
error = obj.message;
|
|
||||||
} else {
|
|
||||||
currencies = await result.json();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function saveCard() {
|
async function saveCard() {
|
||||||
const endpoint = editingCard ? `/api/card/update` : "/api/card/create";
|
const endpoint = editingCard ? `/api/card/update` : "/api/card/create";
|
||||||
|
@ -145,28 +134,6 @@
|
||||||
class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md focus:ring focus:ring-indigo-200 focus:border-indigo-500"
|
class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md focus:ring focus:ring-indigo-200 focus:border-indigo-500"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label class="block">
|
|
||||||
<span class="text-gray-700">Currency:</span>
|
|
||||||
<select
|
|
||||||
bind:value={currentCard.currency_id}
|
|
||||||
class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md focus:ring focus:ring-indigo-200 focus:border-indigo-500"
|
|
||||||
>
|
|
||||||
{#each currencies as currency}
|
|
||||||
<option value={currency.id}
|
|
||||||
>{`${currency.symbol} (${currency.iso_name})`}</option
|
|
||||||
>
|
|
||||||
{/each}
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<label class="block">
|
|
||||||
<span class="text-gray-700">Last 4 digits:</span>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
bind:value={currentCard.last_digits}
|
|
||||||
required
|
|
||||||
class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md focus:ring focus:ring-indigo-200 focus:border-indigo-500"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
<label class="flex items-center">
|
<label class="flex items-center">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -213,11 +180,7 @@
|
||||||
class="bg-white p-4 rounded-lg shadow-md flex justify-between items-center"
|
class="bg-white p-4 rounded-lg shadow-md flex justify-between items-center"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<strong class="text-lg">{card.name}</strong>
|
<strong class="block text-lg">{card.name}</strong>
|
||||||
<span class="text-gray-600 text-sm">{`•${card.last_digits}`}</span>
|
|
||||||
<span
|
|
||||||
>{` ${currencies.find((curr) => curr.id == card.currency_id)?.symbol}`}</span
|
|
||||||
>
|
|
||||||
<div class="text-sm text-gray-600">
|
<div class="text-sm text-gray-600">
|
||||||
<span>
|
<span>
|
||||||
Balance: {NumberToFPA(card.balance)},
|
Balance: {NumberToFPA(card.balance)},
|
||||||
|
|
|
@ -162,6 +162,17 @@
|
||||||
{editingExpense ? "Edit Expense" : "Add New Expense"}
|
{editingExpense ? "Edit Expense" : "Add New Expense"}
|
||||||
</h2>
|
</h2>
|
||||||
<form onsubmit={saveExpense} class="space-y-4">
|
<form onsubmit={saveExpense} class="space-y-4">
|
||||||
|
<label class="block">
|
||||||
|
<span class="text-gray-700">Value:</span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
oninput={handleValueInput}
|
||||||
|
bind:this={valueRef}
|
||||||
|
required
|
||||||
|
class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md focus:ring focus:ring-indigo-200 focus:border-indigo-500"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
<label class="block">
|
<label class="block">
|
||||||
<span class="text-gray-700">Card:</span>
|
<span class="text-gray-700">Card:</span>
|
||||||
<select
|
<select
|
||||||
|
@ -187,27 +198,6 @@
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label class="block">
|
|
||||||
<span class="text-gray-700">Value:</span>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
oninput={handleValueInput}
|
|
||||||
bind:this={valueRef}
|
|
||||||
required
|
|
||||||
class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md focus:ring focus:ring-indigo-200 focus:border-indigo-500"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label class="block">
|
|
||||||
<span class="text-gray-700">Comment:</span>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
bind:value={currentExpense.comment}
|
|
||||||
required
|
|
||||||
class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md focus:ring focus:ring-indigo-200 focus:border-indigo-500"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex items-center space-x-4">
|
||||||
<label>
|
<label>
|
||||||
Date:
|
Date:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user