Skip to content

Commit 3f99d35

Browse files
authored
added compability for wine in overview (#1112)
* added compability for wine in overview * fixed calc for nrbottles
1 parent 0b3218e commit 3f99d35

File tree

9 files changed

+72
-37
lines changed

9 files changed

+72
-37
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `nrBottles` on the `drinkitembatch` table. All the data in the column will be lost.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "drinkitem" ADD COLUMN "nr_bottles" INTEGER DEFAULT 0;
9+
10+
-- AlterTable
11+
ALTER TABLE "drinkitembatch" DROP COLUMN "nrBottles";

src/database/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ model DrinkItem {
470470
bottleEmptyWeight Int? @map("bottle_empty_weight")
471471
bottleFullWeight Int? @map("bottle_full_weight")
472472
quantityAvailable Int? @default(0) @map("quantity_available")
473+
nrBottles Int? @default(0) @map("nr_bottles")
473474
stockLists DrinkItemBatch[]
474475
475476
@@map("drinkitem")
@@ -482,7 +483,6 @@ model DrinkItemBatch {
482483
quantityDelta Int @map("quantity_delta")
483484
user String
484485
date DateTime
485-
nrBottles Int?
486486
487487
@@map("drinkitembatch")
488488
}

src/database/schema.zmodel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ model DrinkItem {
553553
bottleEmptyWeight Int? @map("bottle_empty_weight")
554554
bottleFullWeight Int? @map("bottle_full_weight")
555555
quantityAvailable Int? @map("quantity_available") @default(0)
556+
nrBottles Int? @map("nr_bottles") @default(0)
556557

557558
stockLists DrinkItemBatch[]
558559

@@ -570,7 +571,7 @@ model DrinkItemBatch {
570571
quantityDelta Int @map("quantity_delta")
571572
user String
572573
date DateTime
573-
nrBottles Int?
574+
574575

575576
@@allow("read", true)
576577
@@allow("create", has(auth().policies, "drinkitembatch:create"))

src/database/seed/.snaplet/dataModel.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4054,6 +4054,20 @@
40544054
"isId": false,
40554055
"maxLength": null
40564056
},
4057+
{
4058+
"id": "public.drinkitem.nr_bottles",
4059+
"name": "nr_bottles",
4060+
"columnName": "nr_bottles",
4061+
"type": "int4",
4062+
"isRequired": false,
4063+
"kind": "scalar",
4064+
"isList": false,
4065+
"isGenerated": false,
4066+
"sequence": false,
4067+
"hasDefaultValue": true,
4068+
"isId": false,
4069+
"maxLength": null
4070+
},
40574071
{
40584072
"name": "drinkitembatch",
40594073
"type": "drinkitembatch",
@@ -4140,20 +4154,6 @@
41404154
"isId": false,
41414155
"maxLength": null
41424156
},
4143-
{
4144-
"id": "public.drinkitembatch.nrBottles",
4145-
"name": "nrBottles",
4146-
"columnName": "nrBottles",
4147-
"type": "int4",
4148-
"isRequired": false,
4149-
"kind": "scalar",
4150-
"isList": false,
4151-
"isGenerated": false,
4152-
"sequence": false,
4153-
"hasDefaultValue": false,
4154-
"isId": false,
4155-
"maxLength": null
4156-
},
41574157
{
41584158
"id": "public.drinkitembatch.quantity_delta",
41594159
"name": "quantity_delta",

src/lib/utils/stocklistUtils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export async function inventoryValue(prisma: ExtendedPrisma) {
2323
for (const item of items) {
2424
if (item.quantityType === "COUNTS") {
2525
value += (item.price / 100) * item.quantityAvailable!;
26+
} else if (
27+
(item.quantityType === "WEIGHT" && item.bottleEmptyWeight == 0) ||
28+
item.bottleFullWeight == 0
29+
) {
30+
continue;
2631
} else {
2732
const bottleWeight = item.bottleEmptyWeight!;
2833
const liquidWeight = item.quantityAvailable! - bottleWeight;

src/routes/(app)/admin/stocklist/+page.svelte

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@
33
import SetPageTitle from "$lib/components/nav/SetPageTitle.svelte";
44
import SEO from "$lib/seo/SEO.svelte";
55
export let data: PageData;
6+
import type { DrinkItem } from "@prisma/client";
67
import Navbuttons from "./navbuttons.svelte";
8+
9+
function calcBottles(item: DrinkItem) {
10+
if (item.bottleEmptyWeight != 0 && item.bottleFullWeight != 0) {
11+
return (
12+
(
13+
(item.quantityAvailable! -
14+
item.nrBottles! * item.bottleEmptyWeight!) /
15+
(item.bottleFullWeight! - item.bottleEmptyWeight!)
16+
).toFixed(2) + " flaskor"
17+
);
18+
} else {
19+
return item.quantityAvailable + " g (flaskvikt saknas)";
20+
}
21+
}
722
</script>
823

924
<SetPageTitle title="Stocklist" />
@@ -16,19 +31,23 @@
1631
}}
1732
/>
1833
<div
19-
style="display: flex; justify-content: space-between; align-items: center;"
34+
style="display: flex; justify-content: space-between; align-items: center; "
2035
>
2136
<div
22-
style="display: flex; justify-content: space-between; align-items: center;"
37+
style="display: flex; justify-content: space-between; align-items: center; size: "
2338
>
2439
<Navbuttons currentPage="overview"></Navbuttons>
2540
<form method="POST" enctype="multipart/form-data" action="?/readFile">
26-
<input type="file" name="upload" class="file-input file-input-primary" />
27-
<button type="submit" class="btn btn-primary">Upload</button>
41+
<input
42+
type="file"
43+
name="upload"
44+
class="file-input file-input-primary h-8 w-32"
45+
/>
46+
<button type="submit" class="btn btn-primary btn-sm">Upload</button>
2847
</form>
2948
</div>
3049
<h1 style="font-size: large;">
31-
Totalt lagervärde: {data.currentInventoryValue.toFixed(0)} kr
50+
Totalt estimerat lagervärde: {data.currentInventoryValue.toFixed(0)} kr
3251
</h1>
3352
</div>
3453
<div class="overflow-x-auto">
@@ -49,7 +68,7 @@
4968
<tr>
5069
<th>{item.systembolagetID}</th>
5170
<td>{item.name}</td>
52-
<td>Öl/Cider</td>
71+
<td>{item.group === "S3" ? "Vin" : "Öl/Cider"}</td>
5372
<td>{item.price / 100} kr</td>
5473
<td>{item.quantityAvailable} st</td>
5574
<td>{item.group}</td>
@@ -60,12 +79,7 @@
6079
<td>{item.name}</td>
6180
<td>Sprit</td>
6281
<td>{item.price / 100} kr</td>
63-
<td
64-
>{(
65-
(item.quantityAvailable! - item.bottleEmptyWeight!) /
66-
(item.bottleFullWeight! - item.bottleEmptyWeight!)
67-
).toFixed(2)} flaskor</td
68-
>
82+
<td> {calcBottles(item)}</td>
6983
<td>{item.group}</td>
7084
</tr>
7185
{/if}

src/routes/(app)/admin/stocklist/addproduct/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
name="selectType"
2323
role="tab"
2424
class="tab text-base"
25-
aria-label="Öl/Cider"
25+
aria-label="Öl/Cider/Vin"
2626
checked
2727
on:click={() => {
2828
reset();

src/routes/(app)/admin/stocklist/navbuttons.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@
44

55
<div>
66
<ul style="list-style: none;">
7-
<a href="/admin/stocklist" style="margin-right:15px">
7+
<a href="/admin/stocklist" style="margin-right:5px">
88
<button
99
class="btn btn-primary"
1010
class:btn-outline={currentPage !== "overview"}
1111
>
1212
Överblick
1313
</button>
1414
</a>
15-
<a href="/admin/stocklist/showproducts" style="margin-right:15px">
15+
<a href="/admin/stocklist/showproducts" style="margin-right:5px">
1616
<button
1717
class="btn btn-primary"
1818
class:btn-outline={currentPage !== "showproducts"}
1919
>
2020
Produkter
2121
</button>
2222
</a>
23-
<a href="/admin/stocklist/stockchange" style="margin-right:15px">
23+
<a href="/admin/stocklist/stockchange" style="margin-right:5px">
2424
<button
2525
class="btn btn-primary"
2626
class:btn-outline={currentPage !== "stockchange"}
2727
>
2828
Skriv in/ut
2929
</button>
3030
</a>
31-
<a href="/admin/stocklist/treasury" style="margin-right:15px">
31+
<a href="/admin/stocklist/treasury" style="margin-right:10px">
3232
<button
3333
class="btn btn-primary"
3434
class:btn-outline={currentPage !== "treasury"}

src/routes/(app)/admin/stocklist/stockchange/+page.server.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const createOutBatchSchema = z.object({
2525
.string()
2626
.date()
2727
.default(() => new Date().toLocaleDateString("se-SE")),
28-
nrBottles: z.number().nonnegative(),
28+
nrBottles: z.number().nonnegative().default(0),
2929
});
3030

3131
const createInBatchSchema = z.object({
@@ -35,7 +35,7 @@ const createInBatchSchema = z.object({
3535
.string()
3636
.date()
3737
.default(() => new Date().toLocaleDateString("se-SE")),
38-
nrBottles: z.number().nonnegative(),
38+
nrBottles: z.number().nonnegative().default(0),
3939
});
4040

4141
export const actions: Actions = {
@@ -53,7 +53,6 @@ export const actions: Actions = {
5353
data: {
5454
drinkItemId: form.data.drinkItemId,
5555
quantityDelta: form.data.quantityDelta,
56-
nrBottles: form.data.nrBottles,
5756
date: dayjs(form.data.date).toDate(),
5857
user: user.studentId!,
5958
},
@@ -65,6 +64,9 @@ export const actions: Actions = {
6564
quantityAvailable: {
6665
increment: form.data.quantityDelta,
6766
},
67+
nrBottles: {
68+
increment: form.data.nrBottles,
69+
},
6870
},
6971
});
7072
return message(form, { message: "Antal inskrivet" });
@@ -89,6 +91,9 @@ export const actions: Actions = {
8991
quantityAvailable: {
9092
decrement: form.data.quantityDelta,
9193
},
94+
nrBottles: {
95+
decrement: form.data.nrBottles,
96+
},
9297
},
9398
});
9499

@@ -100,7 +105,6 @@ export const actions: Actions = {
100105
data: {
101106
drinkItemId: form.data.drinkItemId,
102107
quantityDelta: -form.data.quantityDelta,
103-
nrBottles: form.data.nrBottles,
104108
date: dayjs(form.data.date).toDate(),
105109
user: user.studentId!,
106110
},

0 commit comments

Comments
 (0)