2019-04-05 13:20:12 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
export default class Controller {
|
2019-04-18 09:02:28 +00:00
|
|
|
constructor($, vnApp, $translate, $http, $state, $stateParams) {
|
2019-04-05 13:20:12 +00:00
|
|
|
this.$state = $state;
|
|
|
|
this.$stateParams = $stateParams;
|
|
|
|
this.$http = $http;
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$ = $;
|
2019-04-05 13:20:12 +00:00
|
|
|
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 => {
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$.model.refresh();
|
2019-04-05 13:20:12 +00:00
|
|
|
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 => {
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$.model.refresh();
|
2019-04-05 13:20:12 +00:00
|
|
|
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)
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$.model.applyFilter(null, params);
|
2019-04-05 13:20:12 +00:00
|
|
|
else
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$.model.clear();
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
showDenyReason(event, requestId) {
|
|
|
|
this.denyRequestId = requestId;
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$.denyReason.parent = event.target;
|
|
|
|
this.$.denyReason.show();
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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!'));
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$.model.refresh();
|
|
|
|
this.$.denyReason.hide();
|
2019-04-05 13:20:12 +00:00
|
|
|
this.denyObservation = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:02:28 +00:00
|
|
|
showTicketDescriptor(event, ticketFk) {
|
|
|
|
this.$.ticketDescriptor.ticketFk = ticketFk;
|
|
|
|
this.$.ticketDescriptor.parent = event.target;
|
|
|
|
this.$.ticketDescriptor.show();
|
2019-04-05 13:20:12 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
}
|
|
|
|
|
2019-04-18 09:02:28 +00:00
|
|
|
showItemDescriptor(event, itemFk) {
|
|
|
|
this.$.itemDescriptor.itemFk = itemFk;
|
|
|
|
this.$.itemDescriptor.parent = event.target;
|
|
|
|
this.$.itemDescriptor.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
showWorkerDescriptor(event, userId) {
|
|
|
|
this.$.workerDescriptor.userId = userId;
|
|
|
|
this.$.workerDescriptor.parent = event.target;
|
|
|
|
this.$.workerDescriptor.show();
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onDescriptorLoad() {
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$.popover.relocate();
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
preventNavigation(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$scope', 'vnApp', '$translate', '$http', '$state', '$stateParams'];
|
|
|
|
|
|
|
|
ngModule.component('vnItemRequest', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|