2018-08-20 07:01:38 +00:00
|
|
|
import ngModule from '../module';
|
2020-05-06 12:38:09 +00:00
|
|
|
import Popover from 'core/components/popover';
|
2018-08-20 07:01:38 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-05-06 12:38:09 +00:00
|
|
|
class Controller extends Popover {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
2018-08-20 07:01:38 +00:00
|
|
|
this.totalBasquet = 0;
|
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2018-09-14 12:20:58 +00:00
|
|
|
set prices(value) {
|
|
|
|
this._prices = value;
|
|
|
|
if (value && value[0].grouping)
|
|
|
|
this.calculateTotal();
|
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2018-09-14 12:20:58 +00:00
|
|
|
get prices() {
|
|
|
|
return this._prices;
|
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2018-08-20 07:01:38 +00:00
|
|
|
getTags() {
|
2020-05-06 12:38:09 +00:00
|
|
|
const filter = {
|
|
|
|
where: {
|
|
|
|
itemFk: this.id,
|
|
|
|
priority: {gte: 4}
|
|
|
|
},
|
2018-08-20 07:01:38 +00:00
|
|
|
order: 'priority ASC',
|
|
|
|
include: {relation: 'tag'}
|
|
|
|
};
|
2020-05-06 12:38:09 +00:00
|
|
|
this.$http.get(`ItemTags`, {filter})
|
|
|
|
.then(res => {
|
|
|
|
this.tags = res.data;
|
|
|
|
this.$.$applyAsync(() => this.relocate());
|
2019-02-13 06:57:08 +00:00
|
|
|
});
|
2018-08-20 07:01:38 +00:00
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2020-05-06 12:38:09 +00:00
|
|
|
show(parent, item) {
|
2018-08-20 07:01:38 +00:00
|
|
|
this.item = JSON.parse(JSON.stringify(item));
|
2020-05-06 12:38:09 +00:00
|
|
|
this.id = item.id;
|
2018-08-20 07:01:38 +00:00
|
|
|
this.prices = this.item.prices;
|
|
|
|
this.getTags();
|
2020-05-06 12:38:09 +00:00
|
|
|
super.show(parent);
|
2018-08-20 07:01:38 +00:00
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2020-05-08 11:23:06 +00:00
|
|
|
onClose() {
|
2020-05-06 12:38:09 +00:00
|
|
|
this.id = null;
|
2018-08-20 07:01:38 +00:00
|
|
|
this.item = {};
|
|
|
|
this.tags = {};
|
2018-09-14 12:20:58 +00:00
|
|
|
this._prices = {};
|
|
|
|
this.total = 0;
|
2020-05-08 11:23:06 +00:00
|
|
|
super.onClose();
|
2018-09-14 12:20:58 +00:00
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2018-09-14 12:20:58 +00:00
|
|
|
calculateMax() {
|
|
|
|
this.max = this.item.available - this.total;
|
2018-08-20 07:01:38 +00:00
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2018-09-14 12:20:58 +00:00
|
|
|
calculateTotal() {
|
|
|
|
this.total = 0;
|
|
|
|
|
|
|
|
this.prices.forEach(price => {
|
|
|
|
if (!price.quantity) price.quantity = 0;
|
|
|
|
this.total += price.quantity;
|
|
|
|
});
|
|
|
|
this.calculateMax();
|
|
|
|
}
|
|
|
|
|
2018-08-20 07:01:38 +00:00
|
|
|
addQuantity(price) {
|
2019-01-14 10:35:48 +00:00
|
|
|
if (this.total + price.grouping <= this.max)
|
2018-08-20 07:01:38 +00:00
|
|
|
price.quantity += price.grouping;
|
2018-09-14 12:20:58 +00:00
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2018-09-14 12:20:58 +00:00
|
|
|
getFilledLines() {
|
2020-05-06 12:38:09 +00:00
|
|
|
const filledLines = [];
|
2018-09-17 12:30:39 +00:00
|
|
|
let match;
|
2018-09-14 12:20:58 +00:00
|
|
|
this.prices.forEach(price => {
|
2018-09-17 12:30:39 +00:00
|
|
|
if (price.quantity && price.quantity > 0) {
|
|
|
|
match = filledLines.find(element => {
|
|
|
|
return element.warehouseFk == price.warehouseFk;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
filledLines.push(Object.assign({}, price));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
match.quantity += price.quantity;
|
|
|
|
}
|
2018-09-14 12:20:58 +00:00
|
|
|
});
|
|
|
|
return filledLines;
|
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
|
2018-09-14 12:20:58 +00:00
|
|
|
submit() {
|
|
|
|
this.calculateTotal();
|
2020-05-06 12:38:09 +00:00
|
|
|
const filledLines = this.getFilledLines();
|
2018-09-14 12:20:58 +00:00
|
|
|
|
2018-09-17 12:30:39 +00:00
|
|
|
if (filledLines.length <= 0) {
|
2020-05-06 12:38:09 +00:00
|
|
|
this.vnApp.showError(this.$t('First you must add some quantity'));
|
2018-09-17 12:30:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-09-14 12:20:58 +00:00
|
|
|
|
2020-05-06 12:38:09 +00:00
|
|
|
const params = {
|
2020-02-06 11:46:44 +00:00
|
|
|
orderFk: this.order.id,
|
|
|
|
items: filledLines
|
|
|
|
};
|
2020-05-06 12:38:09 +00:00
|
|
|
this.$http.post(`OrderRows/addToOrder`, params)
|
|
|
|
.then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
this.hide();
|
|
|
|
if (this.card) this.card.reload();
|
|
|
|
});
|
2018-08-20 07:01:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:38:09 +00:00
|
|
|
ngModule.vnComponent('vnOrderPricesPopover', {
|
|
|
|
slotTemplate: require('./index.html'),
|
2018-09-14 12:20:58 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
order: '<'
|
2019-01-14 10:35:48 +00:00
|
|
|
},
|
|
|
|
require: {
|
2019-10-28 16:31:33 +00:00
|
|
|
card: '?^vnOrderCard'
|
2018-09-14 12:20:58 +00:00
|
|
|
}
|
2018-08-20 07:01:38 +00:00
|
|
|
});
|