85 lines
2.5 KiB
JavaScript
85 lines
2.5 KiB
JavaScript
|
import ngModule from '../module';
|
||
|
import './style.scss';
|
||
|
|
||
|
class Controller {
|
||
|
constructor($state, $scope, $http, $translate, vnApp) {
|
||
|
this.$state = $state;
|
||
|
this.$ = $scope;
|
||
|
this.$http = $http;
|
||
|
this.$translate = $translate;
|
||
|
this.vnApp = vnApp;
|
||
|
this.filter = {
|
||
|
where: {claimFk: $state.params.id},
|
||
|
include: [
|
||
|
{relation: 'sale',
|
||
|
scope: {
|
||
|
fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount'],
|
||
|
include: {
|
||
|
relation: 'ticket'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
};
|
||
|
}
|
||
|
|
||
|
openAddSalesDialog() {
|
||
|
this.getClaimableFromTicket();
|
||
|
this.$.addSales.show();
|
||
|
}
|
||
|
|
||
|
getClaimableFromTicket() {
|
||
|
let json = encodeURIComponent(JSON.stringify(this.claim.ticketFk));
|
||
|
|
||
|
let query = `/api/Sales/getClaimableFromTicket?ticketFk=${json}`;
|
||
|
this.$http.get(query).then(res => {
|
||
|
if (res.data) {
|
||
|
this.salesToClaim = res.data;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
addClaimedSale(saleFk) {
|
||
|
let saleToAdd = {saleFk: saleFk, claimFk: this.claim.id, quantity: 0};
|
||
|
let query = `claim/api/ClaimBeginnings/`;
|
||
|
this.$http.post(query, saleToAdd).then(() => {
|
||
|
this.$.model.refresh();
|
||
|
this.$.addSales.hide();
|
||
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
deleteClaimedSale(id) {
|
||
|
let json = encodeURIComponent(JSON.stringify(id));
|
||
|
let query = `claim/api/ClaimBeginnings/${json}`;
|
||
|
this.$http.delete(query).then(() => {
|
||
|
this.$.model.refresh();
|
||
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||
|
});
|
||
|
}
|
||
|
|
||
|
focusLastInput() {
|
||
|
let inputs = document.querySelectorAll("#claimedQuantity");
|
||
|
inputs[inputs.length - 1].querySelector("input").select();
|
||
|
}
|
||
|
|
||
|
setClaimedQuantity(id, claimedQuantity) {
|
||
|
let params = {id: id, quantity: claimedQuantity};
|
||
|
let query = `claim/api/ClaimBeginnings/`;
|
||
|
this.$http.patch(query, params).then(() => {
|
||
|
this.$.model.refresh();
|
||
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp'];
|
||
|
|
||
|
ngModule.component('vnClaimDetail', {
|
||
|
template: require('./index.html'),
|
||
|
controller: Controller,
|
||
|
bindings: {
|
||
|
claim: '<'
|
||
|
}
|
||
|
});
|