2018-06-28 13:21:04 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
|
|
|
|
class Controller {
|
|
|
|
constructor($scope, $http, $state, vnApp, $translate) {
|
|
|
|
this.$scope = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$state = $state;
|
|
|
|
this.vnApp = vnApp;
|
2018-08-02 13:34:48 +00:00
|
|
|
this.$translate = $translate;
|
2018-06-28 13:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set edit(value) {
|
|
|
|
this._edit = value;
|
|
|
|
this.clear();
|
|
|
|
this.setNewDiscount();
|
|
|
|
}
|
|
|
|
|
|
|
|
get edit() {
|
|
|
|
return this._edit;
|
|
|
|
}
|
|
|
|
|
|
|
|
set bulk(value) {
|
|
|
|
this._bulk = value;
|
|
|
|
this.setNewDiscount();
|
|
|
|
}
|
|
|
|
|
|
|
|
get bulk() {
|
|
|
|
return this._bulk;
|
|
|
|
}
|
|
|
|
|
|
|
|
setNewDiscount() {
|
|
|
|
if (!this.newDiscount && this.edit[0])
|
|
|
|
this.newDiscount = this.edit[0].discount;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDiscount() {
|
|
|
|
let editLines = [];
|
|
|
|
let modified = false;
|
|
|
|
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) {
|
2018-06-28 13:21:04 +00:00
|
|
|
editLines.push({id: this.edit[i].id, discount: this.newDiscount, ticketFk: this.$state.params.id});
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (modified) {
|
|
|
|
this.$http.post(`/ticket/api/Sales/updateDiscount`, {editLines}).then(() => {
|
2019-02-14 19:18:10 +00:00
|
|
|
this.onHide();
|
2018-08-02 13:34:48 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
2018-07-04 12:42:02 +00:00
|
|
|
this.clear();
|
|
|
|
modified = false;
|
|
|
|
}).catch(e => {
|
2018-08-02 13:34:48 +00:00
|
|
|
this.vnApp.showError(e.data.error.message);
|
2018-06-28 13:21:04 +00:00
|
|
|
});
|
2019-02-14 11:06:14 +00:00
|
|
|
} else
|
2018-08-02 13:34:48 +00:00
|
|
|
this.vnApp.showError(this.$translate.instant('There is no changes to save'));
|
2018-06-28 13:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
this.newDiscount = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$scope', '$http', '$state', 'vnApp', '$translate'];
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|