146 lines
3.8 KiB
JavaScript
146 lines
3.8 KiB
JavaScript
import ngModule from '../module';
|
|
import './style.scss';
|
|
|
|
export default class Controller {
|
|
constructor($, vnApp, $translate, $http, $state, $stateParams) {
|
|
this.$state = $state;
|
|
this.$stateParams = $stateParams;
|
|
this.$http = $http;
|
|
this.$ = $;
|
|
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.$.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.$.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.$.model.applyFilter(null, params);
|
|
else
|
|
this.$.model.clear();
|
|
}
|
|
|
|
showDenyReason(event, requestId) {
|
|
this.denyRequestId = requestId;
|
|
this.$.denyReason.parent = event.target;
|
|
this.$.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.$.model.refresh();
|
|
this.$.denyReason.hide();
|
|
this.denyObservation = null;
|
|
});
|
|
}
|
|
|
|
showTicketDescriptor(event, ticketFk) {
|
|
this.$.ticketDescriptor.ticketFk = ticketFk;
|
|
this.$.ticketDescriptor.parent = event.target;
|
|
this.$.ticketDescriptor.show();
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
}
|
|
|
|
showItemDescriptor(event, itemFk) {
|
|
this.$.itemDescriptor.itemFk = itemFk;
|
|
this.$.itemDescriptor.parent = event.target;
|
|
this.$.itemDescriptor.show();
|
|
}
|
|
|
|
showWorkerDescriptor(event, workerFk) {
|
|
this.$.workerDescriptor.workerFk = workerFk;
|
|
this.$.workerDescriptor.parent = event.target;
|
|
this.$.workerDescriptor.show();
|
|
}
|
|
|
|
onDescriptorLoad() {
|
|
this.$.popover.relocate();
|
|
}
|
|
|
|
preventNavigation(event) {
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope', 'vnApp', '$translate', '$http', '$state', '$stateParams'];
|
|
|
|
ngModule.component('vnItemRequest', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|