salix/modules/item/front/request/index.js

146 lines
3.8 KiB
JavaScript
Raw Normal View History

2019-04-05 13:20:12 +00:00
import ngModule from '../module';
import './style.scss';
export default class Controller {
constructor($, vnApp, $translate, $http, $state, $stateParams) {
2019-04-05 13:20:12 +00:00
this.$state = $state;
this.$stateParams = $stateParams;
this.$http = $http;
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 => {
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 => {
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)
this.$.model.applyFilter(null, params);
2019-04-05 13:20:12 +00:00
else
this.$.model.clear();
2019-04-05 13:20:12 +00:00
}
showDenyReason(event, requestId) {
this.denyRequestId = requestId;
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!'));
this.$.model.refresh();
this.$.denyReason.hide();
2019-04-05 13:20:12 +00:00
this.denyObservation = null;
});
}
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();
}
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();
2019-04-05 13:20:12 +00:00
}
onDescriptorLoad() {
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
});