Files
thetool/public/js/pages/WarehouseArticle/WarehouseArticle.js
2024-11-21 09:12:44 +00:00

368 lines
18 KiB
JavaScript

Vue.component('warehouse-distributor-modal', {
//language=Vue
template: `
<tt-modal :show.sync="showModal" title="Lieferanten" :delete="false" :save="false"
@close="$emit('update:show', false)">
<div v-for="(row, index) in rows" :key="index" style="display:grid;grid-template-columns: auto auto">
<div style="display:grid; grid-template-columns: auto auto auto">
<tt-autocomplete v-model="row.distributorId"
:api-url="window['TT_CONFIG']['BASE_PATH'] + '/WarehouseDistributor/autocomplete'"></tt-autocomplete>
<tt-input v-model="row.purchasePrice" placeholder="Price" type="number" sm></tt-input>
<tt-input v-model="row.externalArticleNumber" placeholder="External Article Number" sm></tt-input>
</div>
<div class="btn-group mb-4">
<a class="btn btn-sm btn-primary" href="#" @click="saveRow(index)" title="Save Row">
<i class="fas fa-check"></i>
</a>
<a class="btn btn-sm btn-danger" href="#" @click="deleteRow(index)" title="Delete Row">
<i class="fas fa-trash"></i>
</a>
</div>
</div>
<a href="#" @click="addRow"><i class="fas fa-plus"></i>Lieferant hinzufügen</a>
</tt-modal>
`, props: {
show: {type: Boolean, default: false}, id: {type: Number, default: null},
}, data() {
return {
window: window, showModal: false, rows: []
};
}, async mounted() {
}, methods: {
async fetchArticleDistributor() {
const response = await axios.post(window['TT_CONFIG']['BASE_PATH'] + '/WarehouseArticleDistributor/get', {filters: {articleId: this.id}});
this.rows = response.data.rows
}, addRow() {
this.rows.push({distributorId: undefined, price: null, externalArticleNumber: null});
}, async saveRow(index) {
// post to /WarehouseArticleDistributor/save with rows data and articleId
const row = this.rows[index];
const data = {
articleId: this.id, distributorId: row.distributorId, purchasePrice: row.purchasePrice, externalArticleNumber: row.externalArticleNumber
}
if (row.id) {
data.id = row.id;
}
const response = await axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticleDistributor/${row.id ? 'update' : 'create'}`, data);
this.$emit('doUpdate');
this.window.notify(response.data.success ? 'success' : 'error',
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message);
await this.fetchArticleDistributor();
}, async deleteRow(index) {
const row = this.rows[index];
if (!row.id) {
this.window.notify('error', 'Eintrag hat keine ID');
}
const response = axios.post(window['TT_CONFIG']['BASE_PATH'] + '/WarehouseArticleDistributor/delete', {id: row.id});
this.$emit('doUpdate');
this.window.notify(response.data.success ? 'success' : 'error',
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message);
await this.fetchArticleDistributor();
}
}, watch: {
show(newVal) {
this.showModal = newVal;
if (!newVal) {
this.rows = [];
return;
}
this.rows = [];
this.fetchArticleDistributor().then();
}
}
});
Vue.component('warehouse-threshold-modal', {
//language=Vue
template: `
<tt-modal :show.sync="showModal" title="Schwellenwerte" :delete="false" :save="false" @close="$emit('update:show', false)">
<div v-for="(row, index) in rows" :key="index" style="display:grid;grid-template-columns: auto auto">
<div style="display:grid; grid-template-columns: auto auto auto">
<tt-autocomplete v-model="row.locationId"
:api-url="window['TT_CONFIG']['BASE_PATH'] + '/WarehouseLocation/autocomplete'"></tt-autocomplete>
<tt-input v-model="row.warningAmount" placeholder="Warnmenge" type="number" sm></tt-input>
<tt-input v-model="row.criticalAmount" placeholder="Kritische Menge" type="number" sm></tt-input>
</div>
<div class="btn-group mb-4">
<a class="btn btn-sm btn-primary" href="#" @click="saveRow(index)" title="Save Row">
<i class="fas fa-check"></i>
</a>
<a class="btn btn-sm btn-danger" href="#" @click="deleteRow(index)" title="Delete Row">
<i class="fas fa-trash"></i>
</a>
</div>
</div>
<a href="#" @click="addRow"><i class="fas fa-plus"></i>Schwellenwert hinzufügen</a>
</tt-modal>
`, props: {
show: {type: Boolean, default: false}, id: {type: Number, default: null},
}, data() {
return {
window: window, showModal: false, rows: []
};
}, async mounted() {
}, methods: {
async fetchLocationThreshold() {
const response = await axios.post(window['TT_CONFIG']['BASE_PATH'] + '/WarehouseLocationThresholdOverride/get', {filters: {articleId: this.id}});
this.rows = response.data.rows
}, addRow() {
this.rows.push({distributor: null, price: null, externalArticleNumber: null});
}, async saveRow(index) {
// post to /WarehouseArticleDistributor/save with rows data and articleId
const row = this.rows[index];
const data = {
articleId: this.id, locationId: row.locationId, warningAmount: row.warningAmount, criticalAmount: row.criticalAmount
}
if (row.id) {
data.id = row.id;
}
const response = await axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseLocationThresholdOverride/${row.id ? 'update' : 'create'}`, data);
this.$emit('doUpdate');
this.window.notify(response.data.success ? 'success' : 'error',
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message);
await this.fetchLocationThreshold()
}, async deleteRow(index) {
const row = this.rows[index];
if (!row.id) {
this.window.notify('error', 'Eintrag hat keine ID');
}
const response = axios.post(window['TT_CONFIG']['BASE_PATH'] + '/WarehouseLocationThresholdOverride/delete', {id: row.id});
this.$emit('doUpdate');
this.window.notify(response.data.success ? 'success' : 'error',
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message);
await this.fetchLocationThreshold();
}
}, watch: {
show(newVal) {
this.showModal = newVal;
if (!newVal) {
this.rows = [];
return;
}
this.rows = [];
this.fetchLocationThreshold().then();
}
}
});
Vue.component('warehouse-article-price-modal', {
//language=Vue
template: `
<tt-modal :show.sync="showModal" title="Artikel-Preise" :delete="false" :save="false" @close="$emit('update:show', false)">
<div v-for="(row, index) in rows" :key="index" style="display:grid;grid-template-columns: auto auto">
<div style="display:grid; grid-template-columns: auto auto auto">
<tt-autocomplete v-model="row.articlePriceTypeId"
:api-url="window['TT_CONFIG']['BASE_PATH'] + '/WarehouseArticlePriceType/autocomplete'"></tt-autocomplete>
<tt-input v-model="row.priceMultiplier" placeholder="Preis Multiplikator" type="number" sm></tt-input>
<tt-input v-model="row.priceOverride" placeholder="Preis" type="number" sm></tt-input>
</div>
<div class="btn-group mb-4">
<a class="btn btn-sm btn-primary" href="#" @click="saveRow(index)" title="Save Row">
<i class="fas fa-check"></i>
</a>
<a class="btn btn-sm btn-danger" href="#" @click="deleteRow(index)" title="Delete Row">
<i class="fas fa-trash"></i>
</a>
</div>
</div>
<a href="#" @click="addRow"><i class="fas fa-plus"></i>Preis hinzufügen</a>
</tt-modal>
`, props: {
show: {type: Boolean, default: false}, id: {type: Number, default: null},
}, data() {
return {
window: window, showModal: false, rows: []
};
}, async mounted() {
}, methods: {
async fetchLocationThreshold() {
const response = await axios.post(window['TT_CONFIG']['BASE_PATH'] + '/WarehouseArticlePrice/get', {filters: {articleId: this.id}});
this.rows = response.data.rows
}, addRow() {
this.rows.push({articlePriceTypeId: null, priceMultiplier: null, priceOverride: null});
}, async saveRow(index) {
// post to /WarehouseArticleDistributor/save with rows data and articleId
const row = this.rows[index];
const data = {
articleId: this.id, articlePriceTypeId: row.articlePriceTypeId, priceMultiplier: row.priceMultiplier, priceOverride: row.priceOverride
}
if (row.id) {
data.id = row.id;
}
const response = await axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticlePrice/${row.id ? 'update' : 'create'}`, data);
this.$emit('doUpdate');
this.window.notify(response.data.success ? 'success' : 'error',
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message);
await this.fetchLocationThreshold()
}, async deleteRow(index) {
const row = this.rows[index];
if (!row.id) {
this.window.notify('error', 'Eintrag hat keine ID');
}
const response = axios.post(window['TT_CONFIG']['BASE_PATH'] + '/WarehouseArticlePrice/delete', {id: row.id});
this.$emit('doUpdate');
this.window.notify(response.data.success ? 'success' : 'error',
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message);
await this.fetchLocationThreshold();
}
}, watch: {
show(newVal) {
this.showModal = newVal;
if (!newVal) {
this.rows = [];
return;
}
this.rows = [];
this.fetchLocationThreshold().then();
}
}
})
// noinspection EqualityComparisonWithCoercionJS
Vue.component('warehouse-article', {
//language=Vue
template: `
<tt-card>
<tt-table-crud ref="table"
@openHistory="historyModal = true; historyModalId = $event.id"
@editDistributorEntries="distributorModal = true; distributorModalId = $event.id"
@editPricesEntries="priceModal = true; priceModalId = $event.id"
@editThresholdEntries="thresholdModal = true; thresholdModalId = $event.id"
@addToCart="addShoppingCartModal = true; addShoppingCartModalId = $event.id"
>
<template v-slot:cheapestsellprice="{ row }">
<template v-for="price in JSON.parse(row.cheapestSellPrice)">
<span v-if="price && window.TT_CONFIG['WAREHOUSE_ADMIN'] == true">{{price.title}}: {{(price.price)}} €<br></span>
<span v-if="price && price.title === 'Verkauf'">{{(price.price)}} €</span>
</template>
</template>
<template v-slot:cheapestPurchasePrice="{ row }">
<span>{{(row.cheapestPurchasePrice * row.sellPriceMultiplier).toFixed(2)}} €</span>
</template>
</tt-table-crud>
<tt-expandable-shopping-cart v-if="window.TT_CONFIG['WAREHOUSE_ADMIN'] === true" :cart-items="shoppingCart" @submitOrder="prepareOrder"/>
<tt-modal :show.sync="addShoppingCartModal" title="Artikel zur Bestellung hinzufügen" :delete="false" @submit="addToShoppingCart"
@close="addShoppingCartModal = false">
<tt-input v-model="addShoppingCartModalCount" placeholder="Menge" type="number" sm></tt-input>
</tt-modal>
<tt-modal :show.sync="confirmOrderModal" title="Bestellung bestätigen" :delete="false"
save-text="Bestätigen" @submit="createOrder"
@close="confirmOrderModal = false; confirmOrderModalData = null">
<span>
Es werden Bestellungen an folgende Lieferanten gesendet:
</span>
<div v-for="(order, index) in confirmOrderModalData" :key="index">
<h4>{{order.distributor[0].name}} - {{order.orderAmount}} €
</h4>
<table class="table table-bordered">
<tr>
<th>Artikel</th>
<th>Menge</th>
<th>Preis</th>
<th>Summe</th>
</tr>
<tr v-for="(item, index) in order.orders" :key="index">
<td>{{item.title}}</td>
<td>{{item.amount}}</td>
<td>{{item.purchasePrice}} €</td>
<td>{{item.sum.toFixed(2)}} €</td>
</tr>
</table>
</div>
</tt-modal>
<warehouse-distributor-modal :show.sync="distributorModal" :id="distributorModalId" @doUpdate="refreshTable"/>
<warehouse-threshold-modal :show.sync="thresholdModal" :id="thresholdModalId" @doUpdate="refreshTable"/>
<warehouse-article-price-modal :show.sync="priceModal" :id="priceModalId" @doUpdate="refreshTable"/>
<warehouse-history-modal :show.sync="historyModal" :id="historyModalId"/>
</tt-card>
`, data() {
return {
window: window,
historyModal: false,
historyModalId: null,
distributorModal: false,
distributorModalId: null,
thresholdModal: false,
thresholdModalId: null,
priceModal: false,
priceModalId: null,
shoppingCart: [],
addShoppingCartModal: false,
addShoppingCartModalId: null,
addShoppingCartModalCount: '',
confirmOrderModal: false,
confirmOrderModalData: null,
}
}, methods: {
refreshTable() {
this.$refs.table.$refs.table.refreshTable();
}, async addToShoppingCart() {
if (this.addShoppingCartModalCount < 1) { // Check if amount is set
window.notify('error', 'Bitte geben Sie eine Menge ein.');
return;
}
if (this.shoppingCart.some(item => item.itemId === this.addShoppingCartModalId)) { // Check if same article is already in cart
window.notify('error', 'Artikel bereits im Warenkorb.');
return;
}
const response = await axios.get(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticle/getById?id=${this.addShoppingCartModalId}`);
this.shoppingCart.push({amount: parseInt(this.addShoppingCartModalCount), itemId: this.addShoppingCartModalId, title: response.data.title});
this.addShoppingCartModal = false;
this.addShoppingCartModalId = null;
this.addShoppingCartModalCount = '';
window.notify('success', 'Artikel erfolgreich hinzugefügt.');
}, async prepareOrder() {
const response = await axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseArticle/prepareOrder`, this.shoppingCart);
this.confirmOrderModal = true;
this.confirmOrderModalData = response.data;
},
async createOrder() {
const response = await axios.post(`${window['TT_CONFIG']['BASE_PATH']}/WarehouseOrder/createOrder`, this.confirmOrderModalData);
this.confirmOrderModal = false;
this.confirmOrderModalData = null;
this.shoppingCart = [];
window.notify(response.data.success ? 'success' : 'error', response.data.message);
setTimeout(() => {
window.location.href = `${window['TT_CONFIG']['BASE_PATH']}/WarehouseOrder`;
}, 2000);
}
}
})