diff --git a/src/lib/elements/HistoryRow.svelte b/src/lib/elements/HistoryRow.svelte new file mode 100644 index 0000000..ca4ed18 --- /dev/null +++ b/src/lib/elements/HistoryRow.svelte @@ -0,0 +1,67 @@ + + +
+ {#if cost} + +

+ {cost.name} +

+

+ {cost.final_price.toFixed(2)} + + ({(cost.final_price + get40Percent(cost.final_price)).toFixed(2)}) + +

+

+ {dayjs(cost.created_at).format('DD-MM-YYYY')} +

+ +
+ + + {#if deleteConfirm == cost.id} + + + {/if} +
+
+ {/if} +
diff --git a/src/lib/elements/Result.svelte b/src/lib/elements/Result.svelte index 27ba864..ce125a7 100644 --- a/src/lib/elements/Result.svelte +++ b/src/lib/elements/Result.svelte @@ -1,20 +1,22 @@

Total:

- {total.toFixed(3)} + {total.toFixed(2)}

Total with (40%):

- {(total + _40Percent).toFixed(3)} + {(total + _40Percent).toFixed(2)}

diff --git a/src/lib/utils/services.ts b/src/lib/utils/services.ts index bb2ac9c..c38beb3 100644 --- a/src/lib/utils/services.ts +++ b/src/lib/utils/services.ts @@ -27,6 +27,16 @@ export const calculateCost = (paper: Paper): number => { return result * parseFloat(paper.rate) } +// export const calculateCost = (paper: Paper): number => { +// const paperSize = parseFloat(paper.length) * parseFloat(paper.width) * parseFloat(paper.thickness) +// const result: number = parseFloat(paperSize.toFixed(2)) / PAPER_FIXED +// return result * parseFloat(parseFloat(paper.rate).toFixed(2)) +// } + +export const get40Percent = (cost: number) => { + return (cost * 40) / 100 +} + export const addHistory = async (history: CostHistoryType) => { const { data, error } = await supabase.from('history').insert({ name: history.name || '', diff --git a/src/lib/utils/tools.ts b/src/lib/utils/tools.ts index 46f5bad..fac69e0 100644 --- a/src/lib/utils/tools.ts +++ b/src/lib/utils/tools.ts @@ -27,3 +27,15 @@ export const [send, receive] = crossfade({ } } }) + +export const sortedByCreatedAt = (data: any) => { + return data.sort((a: any, b: any) => { + // Convert 'created_at' strings to Date objects + let dateA = new Date(a.created_at) + let dateB = new Date(b.created_at) + + if (dateA > dateB) return -1 + if (dateA < dateB) return 1 + return 0 + }) +} diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 0cd4568..9aa2980 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -27,6 +27,7 @@
diff --git a/src/routes/(app)/history/+page.svelte b/src/routes/(app)/history/+page.svelte index bfbef12..0f87f8c 100644 --- a/src/routes/(app)/history/+page.svelte +++ b/src/routes/(app)/history/+page.svelte @@ -1,15 +1,14 @@ @@ -60,56 +47,13 @@
{#if !isLoading} {#if data.histories.length} - {#each sortedByCreatedAt(data.histories) as { name, id, final_price, created_at }} - + {#each sortedByCreatedAt(data.histories) as cost} + handleRestore(e.detail)} + on:delete={(e) => handleDelete(e.detail)} + /> {/each} {:else}

Trash is empty