2018-06-28 13:21:04 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-18 07:35:59 +00:00
|
|
|
import Component from 'core/lib/component';
|
2018-06-28 13:21:04 +00:00
|
|
|
|
2020-03-18 07:35:59 +00:00
|
|
|
class Controller extends Component {
|
2018-06-28 13:21:04 +00:00
|
|
|
set edit(value) {
|
|
|
|
this._edit = value;
|
2019-06-06 07:34:36 +00:00
|
|
|
this.clearDiscount();
|
2018-06-28 13:21:04 +00:00
|
|
|
this.setNewDiscount();
|
|
|
|
}
|
|
|
|
|
|
|
|
get edit() {
|
|
|
|
return this._edit;
|
|
|
|
}
|
|
|
|
|
|
|
|
set bulk(value) {
|
|
|
|
this._bulk = value;
|
|
|
|
this.setNewDiscount();
|
|
|
|
}
|
|
|
|
|
|
|
|
get bulk() {
|
|
|
|
return this._bulk;
|
|
|
|
}
|
|
|
|
|
2019-06-17 10:13:05 +00:00
|
|
|
get newDiscount() {
|
|
|
|
return this._newDiscount;
|
|
|
|
}
|
|
|
|
|
|
|
|
set newDiscount(value) {
|
|
|
|
this._newDiscount = value;
|
|
|
|
this.updateNewPrice();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateNewPrice() {
|
|
|
|
if (this.newDiscount && this.edit[0])
|
|
|
|
this.newPrice = (this.edit[0].quantity * this.edit[0].price) - ((this.newDiscount * (this.edit[0].quantity * this.edit[0].price)) / 100);
|
|
|
|
}
|
|
|
|
|
2018-06-28 13:21:04 +00:00
|
|
|
setNewDiscount() {
|
|
|
|
if (!this.newDiscount && this.edit[0])
|
|
|
|
this.newDiscount = this.edit[0].discount;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDiscount() {
|
2019-06-05 11:39:15 +00:00
|
|
|
let salesIds = [];
|
2018-06-28 13:21:04 +00:00
|
|
|
let modified = false;
|
2020-05-25 11:49:24 +00:00
|
|
|
|
2020-06-22 09:49:44 +00:00
|
|
|
if (this.newDiscount == null) return;
|
2020-05-25 11:49:24 +00:00
|
|
|
|
2018-06-28 13:21:04 +00:00
|
|
|
for (let i = 0; i < this.edit.length; i++) {
|
2018-08-02 13:34:48 +00:00
|
|
|
if (this.newDiscount != this.edit[0].discount || this.bulk || !this.newDiscount) {
|
2019-06-05 11:39:15 +00:00
|
|
|
salesIds.push(this.edit[i].id);
|
2018-06-28 13:21:04 +00:00
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
}
|
2019-05-29 09:11:54 +00:00
|
|
|
|
2018-06-28 13:21:04 +00:00
|
|
|
if (modified) {
|
2019-06-05 11:39:15 +00:00
|
|
|
const params = {salesIds: salesIds, newDiscount: this.newDiscount};
|
2020-03-18 07:35:59 +00:00
|
|
|
const query = `Tickets/${this.$params.id}/updateDiscount`;
|
2019-06-05 11:39:15 +00:00
|
|
|
this.$http.post(query, params).then(() => {
|
2018-08-02 13:34:48 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
2019-06-06 07:34:36 +00:00
|
|
|
this.clearDiscount();
|
2018-07-04 12:42:02 +00:00
|
|
|
modified = false;
|
|
|
|
}).catch(e => {
|
2019-06-06 07:48:08 +00:00
|
|
|
this.vnApp.showError(e.message);
|
2018-06-28 13:21:04 +00:00
|
|
|
});
|
2019-05-06 05:40:59 +00:00
|
|
|
|
|
|
|
this.onHide();
|
2019-02-14 11:06:14 +00:00
|
|
|
} else
|
2019-05-29 09:11:54 +00:00
|
|
|
this.vnApp.showError(this.$translate.instant('There are no changes to save'));
|
2018-06-28 13:21:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 07:34:36 +00:00
|
|
|
clearDiscount() {
|
2018-06-28 13:21:04 +00:00
|
|
|
this.newDiscount = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.component('vnTicketSaleEditDiscount', {
|
|
|
|
template: require('./editDiscount.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
edit: '<?',
|
|
|
|
mana: '<?',
|
|
|
|
bulk: '<?',
|
2019-02-14 19:18:10 +00:00
|
|
|
onHide: '&'
|
2018-06-28 13:21:04 +00:00
|
|
|
}
|
|
|
|
});
|