2019-04-05 13:20:12 +00:00
|
|
|
import ngModule from '../module';
|
2019-10-24 10:44:36 +00:00
|
|
|
import Component from 'core/lib/component';
|
2019-04-05 13:20:12 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2019-10-24 10:44:36 +00:00
|
|
|
export default class Controller extends Component {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
|
|
|
|
|
|
|
if (!this.$state.q) {
|
2019-10-22 11:44:36 +00:00
|
|
|
const today = new Date();
|
|
|
|
today.setHours(23, 59, 59, 59);
|
|
|
|
|
|
|
|
const lastWeek = new Date();
|
|
|
|
lastWeek.setHours(0, 0, 0, 0);
|
|
|
|
lastWeek.setDate(lastWeek.getDate() - 7);
|
|
|
|
|
|
|
|
this.filter = {
|
|
|
|
where: {
|
|
|
|
isOk: false,
|
|
|
|
mine: true,
|
|
|
|
from: lastWeek,
|
|
|
|
to: today
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$postLink() {
|
|
|
|
if (this.filter)
|
|
|
|
this.onSearch(this.filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
getState(isOk) {
|
|
|
|
if (isOk === null)
|
|
|
|
return 'Nueva';
|
2019-10-22 11:44:36 +00:00
|
|
|
else if (isOk === -1 || isOk)
|
2019-04-05 13:20:12 +00:00
|
|
|
return 'Aceptada';
|
|
|
|
else
|
|
|
|
return 'Denegada';
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmRequest(request) {
|
2019-07-25 07:55:09 +00:00
|
|
|
if (request.itemFk && request.saleQuantity) {
|
2019-04-05 13:20:12 +00:00
|
|
|
let params = {
|
|
|
|
itemFk: request.itemFk,
|
2019-07-25 07:55:09 +00:00
|
|
|
quantity: request.saleQuantity
|
2019-04-05 13:20:12 +00:00
|
|
|
};
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `TicketRequests/${request.id}/confirm`;
|
2019-10-22 11:44:36 +00:00
|
|
|
this.$http.post(query, params).then(res => {
|
|
|
|
request.itemDescription = res.data.concept;
|
|
|
|
request.isOk = true;
|
2019-04-05 13:20:12 +00:00
|
|
|
|
2019-10-24 10:44:36 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-04-05 13:20:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
changeQuantity(request) {
|
|
|
|
if (request.saleFk) {
|
|
|
|
let params = {
|
|
|
|
quantity: request.saleQuantity
|
|
|
|
};
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
let endpoint = `Sales/${request.saleFk}/`;
|
2019-04-05 13:20:12 +00:00
|
|
|
|
|
|
|
this.$http.patch(endpoint, params).then(() => {
|
2019-10-24 10:44:36 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-10-22 11:44:36 +00:00
|
|
|
}).then(() => this.confirmRequest(request));
|
2019-07-25 07:55:09 +00:00
|
|
|
} else
|
|
|
|
this.confirmRequest(request);
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2019-10-22 11:44:36 +00:00
|
|
|
this.selectedRequest = requestId;
|
2019-04-18 09:02:28 +00:00
|
|
|
this.$.denyReason.parent = event.target;
|
|
|
|
this.$.denyReason.show();
|
2019-07-25 07:55:09 +00:00
|
|
|
document.querySelector('vn-item-request vn-textarea textArea').focus();
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
delete this.denyRequestId;
|
|
|
|
}
|
|
|
|
|
2019-10-22 11:44:36 +00:00
|
|
|
denyRequest(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response !== 'accept') return;
|
2019-10-22 11:44:36 +00:00
|
|
|
|
2019-04-05 13:20:12 +00:00
|
|
|
let params = {
|
|
|
|
observation: this.denyObservation
|
|
|
|
};
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `TicketRequests/${this.selectedRequest.id}/deny`;
|
2019-10-22 11:44:36 +00:00
|
|
|
this.$http.post(query, params).then(res => {
|
|
|
|
const request = res.data;
|
|
|
|
this.selectedRequest.isOk = request.isOk;
|
|
|
|
this.selectedRequest.attenderFk = request.attenderFk;
|
|
|
|
this.selectedRequest.response = request.response;
|
2019-04-05 13:20:12 +00:00
|
|
|
|
2019-10-24 10:44:36 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
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();
|
|
|
|
}
|
|
|
|
|
2019-04-25 12:24:02 +00:00
|
|
|
showWorkerDescriptor(event, workerFk) {
|
|
|
|
this.$.workerDescriptor.workerFk = workerFk;
|
2019-04-18 09:02:28 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.component('vnItemRequest', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|