143 lines
3.8 KiB
JavaScript
143 lines
3.8 KiB
JavaScript
import ngModule from '../module';
|
|
import './style.scss';
|
|
|
|
export default class Controller {
|
|
constructor($scope, vnApp, $translate, $http, $state, $stateParams) {
|
|
this.$state = $state;
|
|
this.$stateParams = $stateParams;
|
|
this.$http = $http;
|
|
this.$scope = $scope;
|
|
this.vnApp = vnApp;
|
|
this._ = $translate;
|
|
if (!$stateParams.q)
|
|
this.filter = {isOk: false, mine: true};
|
|
}
|
|
|
|
$postLink() {
|
|
if (this.filter)
|
|
this.onSearch(this.filter);
|
|
}
|
|
|
|
getState(isOk) {
|
|
if (isOk === null)
|
|
return 'Nueva';
|
|
else if (isOk === -1 || isOk === 1)
|
|
return 'Aceptada';
|
|
else
|
|
return 'Denegada';
|
|
}
|
|
|
|
confirmRequest(request) {
|
|
if (request.itemFk && request.quantity) {
|
|
let params = {
|
|
itemFk: request.itemFk,
|
|
quantity: request.quantity || request.saleQuantity
|
|
};
|
|
|
|
let endpoint = `/api/TicketRequests/${request.id}/confirm`;
|
|
|
|
this.$http.post(endpoint, params).then(() => {
|
|
this.vnApp.showSuccess(this._.instant('Data saved!'));
|
|
}).catch( e => {
|
|
this.$scope.model.refresh();
|
|
throw e;
|
|
});
|
|
}
|
|
}
|
|
|
|
changeQuantity(request) {
|
|
if (request.saleFk) {
|
|
let params = {
|
|
quantity: request.saleQuantity
|
|
};
|
|
|
|
let endpoint = `/api/Sales/${request.saleFk}/`;
|
|
|
|
this.$http.patch(endpoint, params).then(() => {
|
|
this.vnApp.showSuccess(this._.instant('Data saved!'));
|
|
}).catch( e => {
|
|
this.$scope.model.refresh();
|
|
throw e;
|
|
});
|
|
}
|
|
}
|
|
|
|
compareDate(date) {
|
|
let today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
let timeTicket = new Date(date);
|
|
timeTicket.setHours(0, 0, 0, 0);
|
|
|
|
let comparation = today - timeTicket;
|
|
|
|
if (comparation == 0)
|
|
return 'warning';
|
|
if (comparation < 0)
|
|
return 'success';
|
|
}
|
|
|
|
onSearch(params) {
|
|
if (params)
|
|
this.$scope.model.applyFilter(null, params);
|
|
else
|
|
this.$scope.model.clear();
|
|
}
|
|
|
|
showDenyReason(event, requestId) {
|
|
this.denyRequestId = requestId;
|
|
this.$scope.denyReason.parent = event.target;
|
|
this.$scope.denyReason.show();
|
|
}
|
|
|
|
clear() {
|
|
delete this.denyRequestId;
|
|
}
|
|
|
|
denyRequest() {
|
|
let params = {
|
|
observation: this.denyObservation
|
|
};
|
|
|
|
let endpoint = `/api/TicketRequests/${this.denyRequestId}/deny`;
|
|
|
|
this.$http.post(endpoint, params).then(() => {
|
|
this.vnApp.showSuccess(this._.instant('Data saved!'));
|
|
this.$scope.model.refresh();
|
|
this.$scope.denyReason.hide();
|
|
this.denyObservation = null;
|
|
});
|
|
}
|
|
|
|
showClientDescriptor(event, clientFk) {
|
|
this.$scope.clientDescriptor.clientFk = clientFk;
|
|
this.$scope.clientDescriptor.parent = event.target;
|
|
this.$scope.clientDescriptor.show();
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
}
|
|
|
|
showTicketDescriptor(event, ticketFk) {
|
|
this.$scope.ticketDescriptor.ticketFk = ticketFk;
|
|
this.$scope.ticketDescriptor.parent = event.target;
|
|
this.$scope.ticketDescriptor.show();
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
}
|
|
|
|
onDescriptorLoad() {
|
|
this.$scope.popover.relocate();
|
|
}
|
|
|
|
preventNavigation(event) {
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope', 'vnApp', '$translate', '$http', '$state', '$stateParams'];
|
|
|
|
ngModule.component('vnItemRequest', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|