Skip to content

Commit b6629d0

Browse files
committed
team totals
1 parent 572b7e6 commit b6629d0

File tree

2 files changed

+63
-46
lines changed

2 files changed

+63
-46
lines changed

Makefile.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
[tasks.web]
2-
workspace = false
3-
cwd = "usr-web"
4-
script_runner = "@shell"
5-
script = '''
6-
npm run dev -- -- --host
7-
'''
81

92
[tasks.backend]
103
workspace = false

usr-web/src/routes/(apps)/manifest/+page.svelte

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
interface OrderStatus {
3333
order_id: number;
3434
instance_id: number;
35-
date: string;
35+
date: string | Date;
3636
status: 'New' | 'Submitted' | 'Shipped' | 'Delivered' | 'InStorage' | 'In Storage';
3737
}
3838
let statuses: OrderStatus[] = $state([]);
@@ -49,12 +49,7 @@
4949
});
5050
statuses = body.statuses;
5151
statuses = statuses.map((status) => {
52-
status.date = new Date(status.date).toLocaleString('en-US', {
53-
weekday: 'short',
54-
year: 'numeric',
55-
month: 'long',
56-
day: 'numeric'
57-
});
52+
status.date = new Date(status.date);
5853
if (status.status === 'InStorage') {
5954
status.status = 'In Storage';
6055
}
@@ -110,6 +105,45 @@
110105
out.sort((a, b) => (a.instance_id < b.instance_id ? -1 : 1));
111106
return out;
112107
}
108+
109+
function exportCSV() {
110+
const header = ['Name', 'Vendor', 'Link', 'Count', 'Unit Cost', 'Store In', 'Team', 'Reason', 'Subtotal', 'Status'];
111+
const lines = [header.join(',')];
112+
113+
for (const o of orders) {
114+
const st = statuses
115+
.filter(s => s.order_id === o.id)
116+
.map(s => {
117+
const date = s.date as Date;
118+
const day = String(date.getDate()).padStart(2, '0');
119+
const month = String(date.getMonth() + 1).padStart(2, '0');
120+
const year = String(date.getFullYear()).slice(-2);
121+
return `${s.status}: ${day}/${month}/${year}`;
122+
})
123+
.join(',');
124+
const sub = (o.count * (o.unit_cost as number)).toFixed(2);
125+
lines.push([
126+
o.name,
127+
o.vendor,
128+
o.link,
129+
o.count,
130+
o.unit_cost,
131+
o.store_in,
132+
o.team,
133+
o.reason,
134+
sub,
135+
st,
136+
].map(String).join(','));
137+
}
138+
139+
const csv = new Blob([lines.join('\n')], { type: 'text/csv' });
140+
const url = URL.createObjectURL(csv);
141+
const link = document.createElement('a');
142+
link.href = url;
143+
link.download = 'manifest.csv';
144+
link.click();
145+
URL.revokeObjectURL(url);
146+
}
113147
</script>
114148

115149
<svelte:head>
@@ -123,11 +157,14 @@
123157
Hide "In Storage"
124158
</label>
125159

126-
{#if fetching}
127-
<button disabled> Fetching... </button>
128-
{:else}
129-
<button onclick={refreshOrders}> Refresh </button>
130-
{/if}
160+
<div class="flex flex-row gap-4">
161+
{#if fetching}
162+
<button disabled> Fetching... </button>
163+
{:else}
164+
<button onclick={refreshOrders}> Refresh </button>
165+
{/if}
166+
<button onclick={exportCSV}> Export CSV </button>
167+
</div>
131168
</div>
132169
<table>
133170
<thead>
@@ -160,7 +197,12 @@
160197
<td class="order-name">{order.name}</td>
161198
<td class="order-status">
162199
{#each statusesOf(order.id) as status}
163-
<p>{status.status}: {status.date}</p>
200+
<p><span class="italic">{status.status}</span>: {status.date.toLocaleString('en-US', {
201+
weekday: 'short',
202+
year: 'numeric',
203+
month: 'long',
204+
day: 'numeric'
205+
})}</p>
164206
{/each}
165207
</td>
166208
<td class="order-vendor">{order.vendor}</td>
@@ -459,32 +501,14 @@
459501
<output>{orderOperationOutput}</output>
460502
{/if}
461503
{:else if tabIndex === 4}
462-
{#if selectedOrderId === null}
463-
{@render selectAnOrder()}
464-
{:else}
465-
<button
466-
onclick={async () => {
467-
const response = await fetch(`${PUBLIC_API_ENDPOINT}/api/manifest/del/order`, {
468-
method: 'DELETE',
469-
headers: {
470-
'Content-Type': 'application/json'
471-
},
472-
body: JSON.stringify({
473-
id: selectedOrderId
474-
})
475-
});
476-
if (response.ok) {
477-
orderOperationOutput = '';
478-
refreshOrders();
479-
} else {
480-
orderOperationOutput = await response.text();
481-
}
482-
}}
483-
>
484-
Cancel Order
485-
</button>
486-
<output>{orderOperationOutput}</output>
487-
{/if}
504+
{#snippet cost(team: string)}
505+
<p>{team} Total: {orders
506+
.filter(o => o.team === team)
507+
.reduce((acc, cur) => acc + cur.count * (cur.unit_cost as number), 0).toLocaleString('en-US', { style: 'currency', currency: 'USD' })}</p>
508+
{/snippet}
509+
{@render cost("Software")}
510+
{@render cost("Mechanical")}
511+
{@render cost("Electrical")}
488512
{/if}
489513
</section>
490514
</section>

0 commit comments

Comments
 (0)