Implement ordering process
This commit is contained in:
@@ -4,6 +4,7 @@ import { Product } from "../models/product.model";
|
|||||||
import { OrderItem } from "../models/orderItem.model";
|
import { OrderItem } from "../models/orderItem.model";
|
||||||
import { Brand } from "../models/brand.model";
|
import { Brand } from "../models/brand.model";
|
||||||
import { Category } from "../models/category.model";
|
import { Category } from "../models/category.model";
|
||||||
|
import { Sequelize } from "sequelize-typescript";
|
||||||
|
|
||||||
export const order = Router()
|
export const order = Router()
|
||||||
|
|
||||||
@@ -36,25 +37,20 @@ order.get("/:id", (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// Place a new order
|
// Place a new order
|
||||||
order.post("/", (req: Request, res: Response) => {
|
order.post("/", (req: Request, res: Response) => {
|
||||||
let totalPrice = 0
|
|
||||||
|
|
||||||
Order.create(req.body)
|
Order.create(req.body)
|
||||||
.then(async order => {
|
.then(async order => {
|
||||||
for (let orderItem of req.body.orderItems) {
|
for (let orderItem of req.body.orderItems) {
|
||||||
OrderItem.create({
|
OrderItem.create({
|
||||||
"orderId": order.id,
|
orderId: order.id,
|
||||||
"quantity": orderItem.quantity,
|
quantity: orderItem.quantity,
|
||||||
"orderPrice": orderItem.orderPrice,
|
orderPrice: orderItem.orderPrice,
|
||||||
"productId": orderItem.productId
|
productId: orderItem.productId
|
||||||
})
|
})
|
||||||
|
|
||||||
totalPrice += orderItem.quantity * orderItem.orderPrice
|
Product.decrement(
|
||||||
|
"inStock",
|
||||||
Order.update({
|
{ where: { id: orderItem.productId } }
|
||||||
totalPrice: totalPrice
|
)
|
||||||
}, {
|
|
||||||
where: { id: order.id }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Created
|
// Created
|
||||||
|
|||||||
@@ -20,11 +20,17 @@ import brands from "./../data/brands.json"
|
|||||||
* Delete all datasets in every database table
|
* Delete all datasets in every database table
|
||||||
*/
|
*/
|
||||||
export function deleteAllTables() {
|
export function deleteAllTables() {
|
||||||
Category.destroy({ truncate: true })
|
|
||||||
Order.destroy({ truncate: true })
|
|
||||||
OrderItem.destroy({truncate: true })
|
OrderItem.destroy({truncate: true })
|
||||||
|
Order.destroy({ truncate: true })
|
||||||
|
|
||||||
Product.destroy({ truncate: true })
|
Product.destroy({ truncate: true })
|
||||||
|
Brand.destroy({ truncate: true })
|
||||||
|
Category.destroy({ truncate: true })
|
||||||
|
|
||||||
|
Address.destroy({ truncate: true })
|
||||||
|
Payment.destroy({ truncate: true })
|
||||||
Account.destroy({ truncate: true })
|
Account.destroy({ truncate: true })
|
||||||
|
AccountRole.destroy({ truncate: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ app.use(bodyParser.json())
|
|||||||
// Create database and tables
|
// Create database and tables
|
||||||
startDatabase()
|
startDatabase()
|
||||||
|
|
||||||
|
// Add delay for more realistic response times
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
console.log(123)
|
||||||
|
setTimeout(next, Math.floor((Math.random () * 4000) + 100))
|
||||||
|
})
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
app.use("/api", api)
|
app.use("/api", api)
|
||||||
app.use("/categories", category)
|
app.use("/categories", category)
|
||||||
|
|||||||
12
software/src/data/api/mainApi.ts
Normal file
12
software/src/data/api/mainApi.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import axios from "axios"
|
||||||
|
|
||||||
|
const BASE_URL = "http://localhost:3000/api"
|
||||||
|
|
||||||
|
export function getServerState() {
|
||||||
|
return axios.get(BASE_URL)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetDatabase() {
|
||||||
|
return axios.get(BASE_URL + "/resetdatabase")
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
import { OrderModel } from "../models/orderModel"
|
import { OrderModel } from "../models/orderModel"
|
||||||
import { BasketItemModel } from "../models/basketItemModel"
|
import { BasketItemModel } from "../models/basketItemModel"
|
||||||
|
import { calcPrice } from "@/scripts/productScripts"
|
||||||
|
|
||||||
const BASE_URL = "http://localhost:3000/orders"
|
const BASE_URL = "http://localhost:3000/orders"
|
||||||
|
|
||||||
@@ -9,8 +10,18 @@ export async function getUserOrders(userId: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function addOrder(accountId: number, basketItems: Array<BasketItemModel>) {
|
export async function addOrder(accountId: number, basketItems: Array<BasketItemModel>) {
|
||||||
|
let orderItems = []
|
||||||
|
|
||||||
|
for (let basketItem of basketItems) {
|
||||||
|
orderItems.push({
|
||||||
|
productId: basketItem.product.id,
|
||||||
|
quantity: basketItem.quantity,
|
||||||
|
orderPrice: calcPrice(basketItem.product.price, basketItem.product.discount)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return axios.post(BASE_URL, {
|
return axios.post(BASE_URL, {
|
||||||
"accountId": accountId,
|
accountId: accountId,
|
||||||
"orderItem": basketItems
|
orderItems: orderItems
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -4,4 +4,9 @@ export class BasketItemModel {
|
|||||||
id: number = -1
|
id: number = -1
|
||||||
quantity: number = 1
|
quantity: number = 1
|
||||||
product: ProductModel = new ProductModel()
|
product: ProductModel = new ProductModel()
|
||||||
|
|
||||||
|
constructor(quantity: number, product: ProductModel) {
|
||||||
|
this.quantity = quantity
|
||||||
|
this.product = product
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { ProductModel } from "./productModel"
|
import { ProductModel } from "./productModel"
|
||||||
|
|
||||||
export class OrderedItemModel {
|
export class OrderItemModel {
|
||||||
orderId: number = -1
|
orderId: number = -1
|
||||||
product: ProductModel
|
|
||||||
quantity: number = 1
|
quantity: number = 1
|
||||||
totalPrice: number = 0
|
orderPrice: number = 0
|
||||||
|
product: ProductModel
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { OrderedItemModel } from "./orderedItemModel"
|
import { OrderItemModel } from "./orderItemModel"
|
||||||
|
|
||||||
export class OrderModel {
|
export class OrderModel {
|
||||||
|
id: number
|
||||||
accountId: number
|
accountId: number
|
||||||
shippingProgress: number
|
shippingProgress: number
|
||||||
orderItems: Array<OrderedItemModel>
|
orderItems: Array<OrderItemModel>
|
||||||
orderedAt: string
|
orderedAt: string
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ import { useFeedbackStore } from "./feedbackStore";
|
|||||||
import { loginAccount, registerAccount, updateAccount } from "../api/accountApi";
|
import { loginAccount, registerAccount, updateAccount } from "../api/accountApi";
|
||||||
import { getUserOrders } from "../api/orderApi";
|
import { getUserOrders } from "../api/orderApi";
|
||||||
import { BannerStateEnum } from "../enums/bannerStateEnum";
|
import { BannerStateEnum } from "../enums/bannerStateEnum";
|
||||||
|
import { calcPrice } from "@/scripts/productScripts";
|
||||||
|
|
||||||
export const useAccountStore = defineStore("accountStore", {
|
export const useAccountStore = defineStore("accountStore", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -20,18 +21,12 @@ export const useAccountStore = defineStore("accountStore", {
|
|||||||
await loginAccount(username, password)
|
await loginAccount(username, password)
|
||||||
.then(async result => {
|
.then(async result => {
|
||||||
this.userAccount = result.data
|
this.userAccount = result.data
|
||||||
this.loggedIn = true
|
|
||||||
|
|
||||||
feedbackStore.changeBanner(BannerStateEnum.ACCOUNTLOGINSUCCESSFUL)
|
feedbackStore.changeBanner(BannerStateEnum.ACCOUNTLOGINSUCCESSFUL)
|
||||||
|
|
||||||
await getUserOrders(result.data.id)
|
this.refreshOrders()
|
||||||
.then(result => {
|
|
||||||
this.orders = result.data
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.loggedIn = false
|
|
||||||
|
|
||||||
if (error.status == 400) {
|
if (error.status == 400) {
|
||||||
feedbackStore.changeBanner(BannerStateEnum.ACCOUNTLOGINERROR)
|
feedbackStore.changeBanner(BannerStateEnum.ACCOUNTLOGINERROR)
|
||||||
} else if (error.status == 401) {
|
} else if (error.status == 401) {
|
||||||
@@ -76,6 +71,24 @@ export const useAccountStore = defineStore("accountStore", {
|
|||||||
this.loggedIn = false
|
this.loggedIn = false
|
||||||
|
|
||||||
feedbackStore.changeBanner(BannerStateEnum.ACCOUNTLOGOUTSUCCESSFUL)
|
feedbackStore.changeBanner(BannerStateEnum.ACCOUNTLOGOUTSUCCESSFUL)
|
||||||
|
},
|
||||||
|
|
||||||
|
async refreshOrders() {
|
||||||
|
await getUserOrders(this.userAccount.id)
|
||||||
|
.then(result => {
|
||||||
|
this.orders = result.data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getOrderTotalPrice(orderId: number) {
|
||||||
|
let totalPrice = 0
|
||||||
|
let order: OrderModel = this.orders.find((order: OrderModel) => order.id == orderId)
|
||||||
|
|
||||||
|
for (let item of order.orderItems) {
|
||||||
|
totalPrice += calcPrice(item.orderPrice, 0, item.quantity)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.round(totalPrice * 100) / 100
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { useLocalStorage } from "@vueuse/core";
|
import { useLocalStorage } from "@vueuse/core";
|
||||||
import { calcProductPrice } from "@/scripts/productScripts";
|
import { calcPrice } from "@/scripts/productScripts";
|
||||||
import { BasketItemModel } from "../models/basketItemModel";
|
import { BasketItemModel } from "../models/basketItemModel";
|
||||||
import { useFeedbackStore } from "./feedbackStore";
|
import { useFeedbackStore } from "./feedbackStore";
|
||||||
import { BannerStateEnum } from "../enums/bannerStateEnum";
|
import { BannerStateEnum } from "../enums/bannerStateEnum";
|
||||||
import { addOrder } from "../api/orderApi";
|
import { addOrder } from "../api/orderApi";
|
||||||
import { useAccountStore } from "./accountStore";
|
import { useAccountStore } from "./accountStore";
|
||||||
|
import { ProductModel } from "../models/productModel";
|
||||||
|
import { useProductStore } from "./productStore";
|
||||||
|
|
||||||
export const useBasketStore = defineStore('basketStore', {
|
export const useBasketStore = defineStore('basketStore', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -13,11 +15,16 @@ export const useBasketStore = defineStore('basketStore', {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
|
/**
|
||||||
|
* Calculate price of all items in the basket with discount
|
||||||
|
*
|
||||||
|
* @returns Total price of basket
|
||||||
|
*/
|
||||||
getTotalPrice() {
|
getTotalPrice() {
|
||||||
let result = 0
|
let result = 0
|
||||||
|
|
||||||
for (let item of this.itemsInBasket) {
|
for (let item of this.itemsInBasket) {
|
||||||
result += calcProductPrice(item, item.quantity)
|
result += calcPrice(item.product.price, item.product.discount, item.quantity)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math.round(result * 100) / 100
|
return Math.round(result * 100) / 100
|
||||||
@@ -25,6 +32,11 @@ export const useBasketStore = defineStore('basketStore', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
/**
|
||||||
|
* Remove an item from the basket
|
||||||
|
*
|
||||||
|
* @param item Item to remove
|
||||||
|
*/
|
||||||
removeItemFromBasket(item: BasketItemModel) {
|
removeItemFromBasket(item: BasketItemModel) {
|
||||||
const feedbackStore = useFeedbackStore()
|
const feedbackStore = useFeedbackStore()
|
||||||
feedbackStore.changeBanner(BannerStateEnum.BASKETPRODUCTREMOVED)
|
feedbackStore.changeBanner(BannerStateEnum.BASKETPRODUCTREMOVED)
|
||||||
@@ -34,29 +46,39 @@ export const useBasketStore = defineStore('basketStore', {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
addItemToBasket(item: BasketItemModel) {
|
/**
|
||||||
|
* Add an item to the basket. If the product is already in the basket, the quantity will increase
|
||||||
|
*
|
||||||
|
* @param product Product to add
|
||||||
|
* @param quantity Quantity of the product
|
||||||
|
*/
|
||||||
|
addItemToBasket(product: ProductModel, quantity: number) {
|
||||||
const feedbackStore = useFeedbackStore()
|
const feedbackStore = useFeedbackStore()
|
||||||
feedbackStore.changeBanner(BannerStateEnum.BASKETPRODUCTADDED)
|
feedbackStore.changeBanner(BannerStateEnum.BASKETPRODUCTADDED)
|
||||||
|
|
||||||
// Product is already in the basket, increase number of items
|
// Product is already in the basket, increase number of items
|
||||||
if (this.itemsInBasket.find((basketItem) => basketItem.productId == item.product.id)) {
|
if (this.itemsInBasket.find((basketItem: BasketItemModel) =>
|
||||||
this.itemsInBasket.find((basketItem) =>
|
basketItem.product.id == product.id))
|
||||||
basketItem.productId == item.product.id).quantity += item.quantity
|
{
|
||||||
|
this.itemsInBasket.find((basketItem: BasketItemModel) =>
|
||||||
|
basketItem.product.id == product.id).quantity += quantity
|
||||||
} else {
|
} else {
|
||||||
this.itemsInBasket.push(item)
|
this.itemsInBasket.push(new BasketItemModel(quantity, product))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
takeOrder() {
|
/**
|
||||||
|
* Take an order to the server. Sends all articles in the basket and creates an order entry in the backend database
|
||||||
|
*/
|
||||||
|
async takeOrder() {
|
||||||
const accountStore = useAccountStore()
|
const accountStore = useAccountStore()
|
||||||
//
|
const productStore = useProductStore()
|
||||||
// const order = new OrderModel()
|
|
||||||
// order.accountId = userStore.userAccount.id
|
|
||||||
// order.orderItem = this.itemsInBasket
|
|
||||||
//
|
|
||||||
// console.log(order)
|
|
||||||
|
|
||||||
addOrder(accountStore.userAccount.id, this.itemsInBasket)
|
await addOrder(accountStore.userAccount.id, this.itemsInBasket)
|
||||||
|
this.itemsInBasket = []
|
||||||
|
|
||||||
|
await accountStore.refreshOrders()
|
||||||
|
await productStore.fetchAllProducts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,8 +22,7 @@
|
|||||||
"resetConfirm": "Soll die Datenbank wirklich zurückgesetzt werden?"
|
"resetConfirm": "Soll die Datenbank wirklich zurückgesetzt werden?"
|
||||||
},
|
},
|
||||||
"product": {
|
"product": {
|
||||||
"product": "Produkt",
|
"product": "Produkt | Produkte",
|
||||||
"products": "Produkte",
|
|
||||||
"productName": "Produkt Name",
|
"productName": "Produkt Name",
|
||||||
"brand": "Marke",
|
"brand": "Marke",
|
||||||
"productPrice": "Einzelpreis",
|
"productPrice": "Einzelpreis",
|
||||||
@@ -115,5 +114,6 @@
|
|||||||
"exerciseGroup2": "Aufgabengruppe 2: Broken Access Control",
|
"exerciseGroup2": "Aufgabengruppe 2: Broken Access Control",
|
||||||
"exerciseGroup3": "Aufgabengruppe 3: Cross-Site Scripting (XSS)",
|
"exerciseGroup3": "Aufgabengruppe 3: Cross-Site Scripting (XSS)",
|
||||||
"exercise": "Aufgabe {0}"
|
"exercise": "Aufgabe {0}"
|
||||||
}
|
},
|
||||||
|
"serverState": "Server Status"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,7 @@
|
|||||||
"resetConfirm": "Really reset the database?"
|
"resetConfirm": "Really reset the database?"
|
||||||
},
|
},
|
||||||
"product": {
|
"product": {
|
||||||
"product": "Product",
|
"product": "Product | Products",
|
||||||
"products": "Products",
|
|
||||||
"productName": "Product name",
|
"productName": "Product name",
|
||||||
"brand": "Brand",
|
"brand": "Brand",
|
||||||
"productPrice": "Unit price",
|
"productPrice": "Unit price",
|
||||||
@@ -115,5 +114,6 @@
|
|||||||
"exerciseGroup2": "Exercise Group 2: Broken Access Control",
|
"exerciseGroup2": "Exercise Group 2: Broken Access Control",
|
||||||
"exerciseGroup3": "Exercise Group 3: Cross-Site Scripting (XSS)",
|
"exerciseGroup3": "Exercise Group 3: Cross-Site Scripting (XSS)",
|
||||||
"exercise": "Exercise {0}"
|
"exercise": "Exercise {0}"
|
||||||
}
|
},
|
||||||
|
"serverState": "Server State:"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,18 +22,18 @@ const showOrderingDialog = ref()
|
|||||||
</v-row>
|
</v-row>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col>
|
<v-col>
|
||||||
<card-view :title="$t('menu.basket')" prepend-icon="mdi-cart">
|
<card-view
|
||||||
<v-card-subtitle v-if="basketStore.itemsInBasket.length > 0">
|
:title="$t('menu.basket')"
|
||||||
<div v-if="basketStore.itemsInBasket.length == 1">
|
:subtitle="basketStore.itemsInBasket.length + ' ' +
|
||||||
{{ basketStore.itemsInBasket.length }} {{ $t('product.product') }}
|
$tc('product.product', basketStore.itemsInBasket.length)"
|
||||||
</div>
|
v-model="showOrderingDialog"
|
||||||
<div v-else>
|
icon="mdi-cart"
|
||||||
{{ basketStore.itemsInBasket.length }} {{ $t('product.products') }}
|
>
|
||||||
</div>
|
<template #withoutContainer>
|
||||||
</v-card-subtitle>
|
<!-- Display items if card is not empty -->
|
||||||
|
|
||||||
<products-table v-if="basketStore.itemsInBasket.length > 0" />
|
<products-table v-if="basketStore.itemsInBasket.length > 0" />
|
||||||
|
|
||||||
|
<!-- Display empty state if card is empty -->
|
||||||
<v-empty-state v-else
|
<v-empty-state v-else
|
||||||
icon="mdi-basket-off"
|
icon="mdi-basket-off"
|
||||||
:title="$t('emptyBasketTitle')"
|
:title="$t('emptyBasketTitle')"
|
||||||
@@ -43,6 +43,7 @@ const showOrderingDialog = ref()
|
|||||||
<v-card-text class="text-right text-h5" v-if="basketStore.itemsInBasket.length > 0">
|
<v-card-text class="text-right text-h5" v-if="basketStore.itemsInBasket.length > 0">
|
||||||
{{ $t('totalPrice') }}: {{ basketStore.getTotalPrice }} €
|
{{ $t('totalPrice') }}: {{ basketStore.getTotalPrice }} €
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<outlined-button
|
<outlined-button
|
||||||
|
|||||||
@@ -2,21 +2,52 @@
|
|||||||
import actionDialog from '@/components/actionDialog.vue';
|
import actionDialog from '@/components/actionDialog.vue';
|
||||||
import { useBasketStore } from '@/data/stores/basketStore';
|
import { useBasketStore } from '@/data/stores/basketStore';
|
||||||
import outlinedButton from '@/components/outlinedButton.vue';
|
import outlinedButton from '@/components/outlinedButton.vue';
|
||||||
|
import { ModelRef, ref } from 'vue';
|
||||||
|
import { useAccountStore } from '@/data/stores/accountStore';
|
||||||
|
|
||||||
const basketStore = useBasketStore()
|
const basketStore = useBasketStore()
|
||||||
|
const accountStore = useAccountStore()
|
||||||
|
const showDialog: ModelRef<boolean> = defineModel()
|
||||||
|
const orderingInProgress = ref(false)
|
||||||
|
|
||||||
function doOrder() {
|
async function doOrder() {
|
||||||
basketStore.takeOrder()
|
orderingInProgress.value = true
|
||||||
|
await basketStore.takeOrder()
|
||||||
|
|
||||||
|
showDialog.value = false
|
||||||
|
orderingInProgress.value = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<action-dialog
|
<action-dialog
|
||||||
:title="$t('ordering.ordering')"
|
:title="$t('ordering.ordering')"
|
||||||
|
icon="mdi-basket-check"
|
||||||
|
v-model="showDialog"
|
||||||
|
max-width="800"
|
||||||
>
|
>
|
||||||
|
<v-row>
|
||||||
|
<v-col>
|
||||||
|
Address
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
|
||||||
|
<v-row>
|
||||||
|
<v-col>
|
||||||
|
<v-radio-group>
|
||||||
|
<v-radio
|
||||||
|
v-for="address in accountStore.userAccount.addresses"
|
||||||
|
:value="address"
|
||||||
|
:label="address.street + ' ' + address.houseNumber + ', ' + address.postalCode + ' ' + address.city"
|
||||||
|
/>
|
||||||
|
</v-radio-group>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
|
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<outlined-button
|
<outlined-button
|
||||||
@click="doOrder"
|
@click="doOrder"
|
||||||
|
:loading="orderingInProgress"
|
||||||
>
|
>
|
||||||
{{ $t('ordering.takeOrder') }}
|
{{ $t('ordering.takeOrder') }}
|
||||||
</outlined-button>
|
</outlined-button>
|
||||||
|
|||||||
@@ -30,18 +30,22 @@ function editQuantity(basketItem: BasketItemModel) {
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="basketItem in basketStore.itemsInBasket">
|
<tr v-for="basketItem in basketStore.itemsInBasket">
|
||||||
<td><v-icon :icon="basketItem.categoryIcon" />
|
<!-- Category icon and name -->
|
||||||
{{ basketItem.categoryName }}
|
<td><v-icon :icon="basketItem.product.category.icon" />
|
||||||
|
{{ basketItem.product.category.name }}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
<!-- Product brand -->
|
||||||
<td>
|
<td>
|
||||||
{{ basketItem.brand }}
|
{{ basketItem.product.brand.name }}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
<!-- Name of product -->
|
||||||
<td>
|
<td>
|
||||||
{{ basketItem.name }}
|
{{ basketItem.product.name }}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
<!-- Quantity -->
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
{{ basketItem.quantity }}x
|
{{ basketItem.quantity }}x
|
||||||
<v-btn
|
<v-btn
|
||||||
@@ -53,33 +57,35 @@ function editQuantity(basketItem: BasketItemModel) {
|
|||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
<!-- Price per unit -->
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<div v-if="basketItem.discount > 0">
|
<div v-if="basketItem.product.discount > 0">
|
||||||
<strong class="font-weight-bold text-body-1 text-red-lighten-1">
|
<strong class="font-weight-bold text-body-1 text-red-lighten-1">
|
||||||
{{ calcPrice(basketItem.price, basketItem.discount) }} €
|
{{ calcPrice(basketItem.product.price, basketItem.product.discount) }} €
|
||||||
</strong>
|
</strong>
|
||||||
|
|
||||||
<div class="text-decoration-line-through ml-3 mt-1 text-caption">{{ basketItem.price }} €</div>
|
<div class="text-decoration-line-through ml-3 mt-1 text-caption">{{ basketItem.product.price }} €</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else>
|
<div v-else>
|
||||||
{{ basketItem.price }} €
|
{{ basketItem.product.price }} €
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
<!-- Total price -->
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<div v-if="basketItem.discount > 0">
|
<div v-if="basketItem.product.discount > 0">
|
||||||
<strong class="font-weight-bold text-body-1 text-red-lighten-1">
|
<strong class="font-weight-bold text-body-1 text-red-lighten-1">
|
||||||
{{ calcPrice(basketItem.price, basketItem.discount, basketItem.quantity) }} €
|
{{ calcPrice(basketItem.product.price, basketItem.product.discount, basketItem.quantity) }} €
|
||||||
</strong>
|
</strong>
|
||||||
|
|
||||||
<div class="text-decoration-line-through ml-3 mt-1 text-caption">
|
<div class="text-decoration-line-through ml-3 mt-1 text-caption">
|
||||||
{{ calcPrice(basketItem.price, 0, basketItem.quantity) }} €
|
{{ calcPrice(basketItem.product.price, 0, basketItem.quantity) }} €
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else>
|
<div v-else>
|
||||||
{{ calcPrice(basketItem.price, 0, basketItem.quantity) }} €
|
{{ calcPrice(basketItem.product.price, 0, basketItem.quantity) }} €
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import cardView from '@/components/cardView.vue';
|
import cardView from '@/components/cardView.vue';
|
||||||
import { OrderModel } from '@/data/models/orderModel';
|
import { OrderModel } from '@/data/models/orderModel';
|
||||||
|
import { useAccountStore } from '@/data/stores/accountStore';
|
||||||
|
|
||||||
|
const accountStore = useAccountStore()
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
order: OrderModel
|
order: OrderModel
|
||||||
@@ -30,8 +33,9 @@ function formatDateTimeString(string: string) {
|
|||||||
<template>
|
<template>
|
||||||
<card-view
|
<card-view
|
||||||
:title="$t('orders.orderFrom') + ' ' + formatDateTimeString(order.orderedAt) + ' ' + $t('oclock')"
|
:title="$t('orders.orderFrom') + ' ' + formatDateTimeString(order.orderedAt) + ' ' + $t('oclock')"
|
||||||
:subtitle="$t('totalPrice') + ': ' + 0 + ' €'"
|
:subtitle="$t('totalPrice') + ': ' + accountStore.getOrderTotalPrice(order.id) + ' €'"
|
||||||
>
|
>
|
||||||
|
<template #withoutContainer>
|
||||||
<v-timeline direction="horizontal" side="start" size="x-large">
|
<v-timeline direction="horizontal" side="start" size="x-large">
|
||||||
<v-timeline-item :dot-color="getDotColor(order, 1)" icon="mdi-basket-check">
|
<v-timeline-item :dot-color="getDotColor(order, 1)" icon="mdi-basket-check">
|
||||||
{{ $t('orders.ordered') }}
|
{{ $t('orders.ordered') }}
|
||||||
@@ -72,5 +76,6 @@ function formatDateTimeString(string: string) {
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</v-table>
|
</v-table>
|
||||||
|
</template>
|
||||||
</card-view>
|
</card-view>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,19 +1,32 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { BannerStateEnum } from '@/data/enums/bannerStateEnum';
|
import { BannerStateEnum } from '@/data/enums/bannerStateEnum';
|
||||||
import { useFeedbackStore } from '@/data/stores/feedbackStore';
|
import { useFeedbackStore } from '@/data/stores/feedbackStore';
|
||||||
import axios from 'axios';
|
|
||||||
import cardView from '@/components/cardView.vue';
|
import cardView from '@/components/cardView.vue';
|
||||||
import outlinedButton from '@/components/outlinedButton.vue';
|
import outlinedButton from '@/components/outlinedButton.vue';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import confirmDialog from '@/components/confirmDialog.vue';
|
import confirmDialog from '@/components/confirmDialog.vue';
|
||||||
|
import { getServerState, resetDatabase } from '@/data/api/mainApi';
|
||||||
|
|
||||||
const feedbackStore = useFeedbackStore()
|
const feedbackStore = useFeedbackStore()
|
||||||
const showConfirmDialog = ref(false)
|
const showConfirmDialog = ref(false)
|
||||||
|
const serverOnline = ref(false)
|
||||||
|
|
||||||
function resetDb() {
|
getServerState()
|
||||||
axios.get("http://127.0.0.1:3000/api/resetdatabase")
|
.then(result => {
|
||||||
.then(res => {
|
if (result.status == 200) {
|
||||||
if (res.status == 200) {
|
serverOnline.value = true
|
||||||
|
} else {
|
||||||
|
serverOnline.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
serverOnline.value = false
|
||||||
|
})
|
||||||
|
|
||||||
|
async function resetDb() {
|
||||||
|
await resetDatabase()
|
||||||
|
.then(result => {
|
||||||
|
if (result.status == 200) {
|
||||||
feedbackStore.changeBanner(BannerStateEnum.DATABASERESETSUCCESSFUL)
|
feedbackStore.changeBanner(BannerStateEnum.DATABASERESETSUCCESSFUL)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -28,13 +41,31 @@ function resetSettings() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<card-view :title="$t('preferences.systemSetup')" prepend-icon="mdi-engine" elevation="8">
|
<card-view
|
||||||
|
:title="$t('preferences.systemSetup')"
|
||||||
|
prepend-icon="mdi-engine"
|
||||||
|
>
|
||||||
|
<v-row>
|
||||||
|
<v-col>
|
||||||
|
{{ $t('serverState') }}:
|
||||||
|
<span v-if="serverOnline" class="text-green">
|
||||||
|
<v-icon icon="mdi-check" />
|
||||||
|
Online
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span v-else class="text-red">
|
||||||
|
<v-icon icon="mdi-alert-circle" />
|
||||||
|
Offline
|
||||||
|
</span>
|
||||||
|
</v-col>
|
||||||
|
</v-row>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col class="d-flex justify-center align-center">
|
<v-col class="d-flex justify-center align-center">
|
||||||
<outlined-button
|
<outlined-button
|
||||||
@click="showConfirmDialog = true"
|
@click="showConfirmDialog = true"
|
||||||
prepend-icon="mdi-database-refresh"
|
prepend-icon="mdi-database-refresh"
|
||||||
color="red"
|
color="red"
|
||||||
|
:disabled="!serverOnline"
|
||||||
>
|
>
|
||||||
{{ $t('preferences.resetDatabase') }}
|
{{ $t('preferences.resetDatabase') }}
|
||||||
</outlined-button>
|
</outlined-button>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { VNumberInput } from 'vuetify/labs/VNumberInput'
|
import { VNumberInput } from 'vuetify/labs/VNumberInput'
|
||||||
import { ModelRef, ref, watch } from 'vue';
|
import { ModelRef, ref, watch } from 'vue';
|
||||||
import { useBasketStore } from '@/data/stores/basketStore';
|
import { useBasketStore } from '@/data/stores/basketStore';
|
||||||
import { calcProductPrice, productToBasketItem } from '@/scripts/productScripts';
|
import { calcPrice } from '@/scripts/productScripts';
|
||||||
import ActionDialog from '@/components/actionDialog.vue'
|
import ActionDialog from '@/components/actionDialog.vue'
|
||||||
import { ProductModel } from '@/data/models/productModel';
|
import { ProductModel } from '@/data/models/productModel';
|
||||||
import outlinedButton from '@/components/outlinedButton.vue';
|
import outlinedButton from '@/components/outlinedButton.vue';
|
||||||
@@ -20,7 +20,7 @@ const basketStore = useBasketStore()
|
|||||||
const selectedImage = ref("")
|
const selectedImage = ref("")
|
||||||
|
|
||||||
function addProductToBasket() {
|
function addProductToBasket() {
|
||||||
basketStore.addItemToBasket(productToBasketItem(props.product, nrOfArticles.value))
|
basketStore.addItemToBasket(props.product, nrOfArticles.value)
|
||||||
nrOfArticles.value = 1
|
nrOfArticles.value = 1
|
||||||
showDialog.value = false
|
showDialog.value = false
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ watch(() => props.product.images, () => {
|
|||||||
<div v-if="product.discount == 0" class="text-h3">{{ product.price }} €</div>
|
<div v-if="product.discount == 0" class="text-h3">{{ product.price }} €</div>
|
||||||
<div v-else class="d-flex align-center flex-column my-auto">
|
<div v-else class="d-flex align-center flex-column my-auto">
|
||||||
<div class="text-h3">
|
<div class="text-h3">
|
||||||
<span class="text-red-lighten-1"> {{ calcProductPrice(product, nrOfArticles) }} €</span>
|
<span class="text-red-lighten-1"> {{ calcPrice(product.price, product.discount) }} €</span>
|
||||||
<span class="text-h6 ml-2 text-decoration-line-through">{{ product.price }} € </span>
|
<span class="text-h6 ml-2 text-decoration-line-through">{{ product.price }} € </span>
|
||||||
<span class="text-h6 ml-4 mb-1 bg-red">-{{ product.discount }} %</span>
|
<span class="text-h6 ml-4 mb-1 bg-red">-{{ product.discount }} %</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
import { BasketItemModel } from "@/data/models/basketItemModel";
|
|
||||||
import { CategoryModel } from "@/data/models/categoryModel";
|
|
||||||
import { ProductModel } from "@/data/models/productModel";
|
|
||||||
|
|
||||||
export function calcProductPrice(product: ProductModel, quantity: number = 1): number {
|
|
||||||
return calcPrice(product.price, product.discount, quantity)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate a price based on parameters
|
* Calculate a price based on parameters
|
||||||
*
|
*
|
||||||
@@ -18,27 +10,3 @@ export function calcProductPrice(product: ProductModel, quantity: number = 1): n
|
|||||||
export function calcPrice(price: number, discount: number = 0, quantity: number = 1): number {
|
export function calcPrice(price: number, discount: number = 0, quantity: number = 1): number {
|
||||||
return Math.round(quantity * price * ((100 - discount) / 100) * 100) / 100
|
return Math.round(quantity * price * ((100 - discount) / 100) * 100) / 100
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a ProductModel to a BasketModel
|
|
||||||
*
|
|
||||||
* @param product ProductModel to convert
|
|
||||||
* @param productCategory Category of the product
|
|
||||||
* @param quantity Number of units
|
|
||||||
*
|
|
||||||
* @returns BasketItemModel
|
|
||||||
*/
|
|
||||||
export function productToBasketItem(product: ProductModel, quantity: number): BasketItemModel {
|
|
||||||
let result = new BasketItemModel()
|
|
||||||
|
|
||||||
result.productId = product.id
|
|
||||||
result.quantity = quantity
|
|
||||||
result.price = product.price
|
|
||||||
result.brand = product.brand
|
|
||||||
result.discount = product.discount
|
|
||||||
result.name = product.name
|
|
||||||
result.categoryName = product.category.name
|
|
||||||
result.categoryIcon = product.category.icon
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user