72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
|
import ngModule from '../module';
|
||
|
|
||
|
class Controller {
|
||
|
constructor($scope, $http, $state, vnApp, $translate) {
|
||
|
this.$scope = $scope;
|
||
|
this.$http = $http;
|
||
|
this.$state = $state;
|
||
|
this.vnApp = vnApp;
|
||
|
this.translate = $translate;
|
||
|
}
|
||
|
|
||
|
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++) {
|
||
|
if (this.newDiscount != this.edit[0].discount || this.bulk) {
|
||
|
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(() => {
|
||
|
this.hide();
|
||
|
});
|
||
|
} else {
|
||
|
this.vnApp.showError(this.translate.instant('There is no changes to save'));
|
||
|
}
|
||
|
this.clear();
|
||
|
}
|
||
|
|
||
|
clear() {
|
||
|
this.newDiscount = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Controller.$inject = ['$scope', '$http', '$state', 'vnApp', '$translate'];
|
||
|
|
||
|
ngModule.component('vnTicketSaleEditDiscount', {
|
||
|
template: require('./editDiscount.html'),
|
||
|
controller: Controller,
|
||
|
bindings: {
|
||
|
edit: '<?',
|
||
|
mana: '<?',
|
||
|
bulk: '<?',
|
||
|
hide: '&'
|
||
|
}
|
||
|
});
|