feat: combine multiple orderrequests into one order

This commit is contained in:
Luca Haid
2025-04-08 10:06:52 +02:00
parent 4797e2bcb8
commit 7f33125389
9 changed files with 186 additions and 34 deletions
@@ -373,23 +373,26 @@ Vue.component('warehouse-order-modal', {
return;
}
const orderRequest = JSON.parse(localStorage.getItem('WarehouseOrder_create'));
if (!orderRequest) return;
const orderRequests = JSON.parse(localStorage.getItem('WarehouseOrder_create'));
if (!orderRequests) return;
const positions = JSON.parse(orderRequest.positions);
this.order.positions = await Promise.all(positions.map(async p => {
const distributor = (await axios.get(`${window.TT_CONFIG.BASE_PATH}/WarehouseOrder/getArticleDistributorData`,
{params: {articleId: p.articleId}})).data[0];
return {
article: p.articleId,
amount: p.amount,
buyPrice: distributor.purchasePrice,
distributorId: distributor.id,
distributorArticleNumber: distributor.externalArticleNumber,
verwendung: `${p.hasOwnProperty('purpose') ? p.purpose : ''} [Bestellwunsch: #${orderRequest.id}]`,
linkedOrderRequestId: orderRequest.id
};
}));
for (const orderRequest of orderRequests) {
const positions = JSON.parse(orderRequest.positions);
const parsedPositions = await Promise.all(positions.map(async p => {
const distributor = (await axios.get(`${window.TT_CONFIG.BASE_PATH}/WarehouseOrder/getArticleDistributorData`,
{params: {articleId: p.articleId}})).data[0];
return {
article: p.articleId,
amount: p.amount,
buyPrice: distributor.purchasePrice,
distributorId: distributor.id,
distributorArticleNumber: distributor.externalArticleNumber,
verwendung: `${p.hasOwnProperty('purpose') ? p.purpose : ''} [Bestellwunsch: #${orderRequest.id}]`,
linkedOrderRequestId: orderRequest.id
};
}));
this.order.positions = [...this.order.positions, ...parsedPositions];
}
localStorage.removeItem('WarehouseOrder_create');
},
@@ -17,8 +17,8 @@ window.TT_CONFIG["CRUD_CONFIG"]["additionalActions"] = [
condition: (row) => window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1' && row.cancelled === 1,
},
{
key: "createOrder",
title: "Bestellung erstellen",
key: "addOrderToCart",
title: "Bestellung in den Warenkorb",
class: "fas fa-shopping-cart text-primary", // Use shopping-cart to indicate order creation
condition: (row) => window.TT_CONFIG['WAREHOUSE_ADMIN'] === '1'
&& row.cancelled === 0 && (!row.linkedOrderIds || row.linkedOrderIds.length === 0)
@@ -203,7 +203,18 @@ Vue.component('warehouse-order-request', {
@undoneOrder="undoneOrder"
@createLog="createLog"
@createOrder="createOrder"
@addOrderToCart="addOrderToCart"
ref="crud">
<template #table-top-buttons>
<tt-tooltip :text="createOrdersButtonToolTipText">
<tt-button
:disabled="orderShoppingCart.length === 0"
@click="createOrder"
additional-class="btn-outline-success text-center"
:text="createOrdersButtonText" icon="fas fa-shopping-cart"/>
</tt-tooltip>
</template>
<template #linkedorderids="{row}">
<linked-order-status :linkedOrders="row.linkedOrderIds" v-if="row.linkedOrderIds"/>
</template>
@@ -229,7 +240,8 @@ Vue.component('warehouse-order-request', {
addLogModalId: null,
showHiddenRequests: false,
showCanceledRequests: false,
orderRequestModalId: null
orderRequestModalId: null,
orderShoppingCart: [],
}),
methods: {
openHistory(e) {
@@ -263,12 +275,26 @@ Vue.component('warehouse-order-request', {
uncancelRequest(row) {
this.cancelRequest(row, '0');
},
async createOrder(row) {
const res = await axios.get(`${window.TT_CONFIG.BASE_PATH}/WarehouseOrderRequest/getById?id=${row.id}`);
async createOrder() {
if (this.orderShoppingCart.length > 0) {
localStorage.setItem('WarehouseOrder_create', JSON.stringify(this.orderShoppingCart));
window.location.href = `${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrder`;
} else window.notify('warning', 'Warenkorb ist leer');
},
async addOrderToCart(row) {
const res = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseOrderRequest/getById?id=${row.id}`);
if (res.data?.positions && typeof res.data.positions === 'string') {
localStorage.setItem('WarehouseOrder_create', JSON.stringify(res.data));
window.location.href = `${window.TT_CONFIG.BASE_PATH}/WarehouseOrder`;
} else window.notify('error', res.data.message || 'Fehler beim erstellen der Bestellung');
this.orderShoppingCart.push(res.data);
window.notify('success', 'Bestellung in den Warenkorb gelegt');
} else window.notify('error', res.data.message || 'Fehler beim hinzufügen der Bestellung');
}
},
computed: {
createOrdersButtonText: function () {
return this.orderShoppingCart.length > 0 ? `${this.orderShoppingCart.length} Bestellung(en) erstellen` : 'Bestellung(en) erstellen';
},
createOrdersButtonToolTipText: function () {
return this.orderShoppingCart.length > 0 ? `Erstellt ${this.orderShoppingCart.length} Bestellung(en)` : 'Keine Bestellung im Warenkorb';
}
}
});