158 lines
4.2 KiB
JavaScript
158 lines
4.2 KiB
JavaScript
import ngModule from '../module';
|
|
import Component from 'core/lib/component';
|
|
import './style.scss';
|
|
|
|
export default class Controller extends Component {
|
|
constructor($element, $) {
|
|
super($element, $);
|
|
|
|
if (!this.$state.q) {
|
|
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
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
$postLink() {
|
|
if (this.filter)
|
|
this.onSearch(this.filter);
|
|
}
|
|
|
|
getState(isOk) {
|
|
if (isOk === null)
|
|
return 'Nueva';
|
|
else if (isOk === -1 || isOk)
|
|
return 'Aceptada';
|
|
else
|
|
return 'Denegada';
|
|
}
|
|
|
|
confirmRequest(request) {
|
|
if (request.itemFk && request.saleQuantity) {
|
|
let params = {
|
|
itemFk: request.itemFk,
|
|
quantity: request.saleQuantity
|
|
};
|
|
|
|
let query = `TicketRequests/${request.id}/confirm`;
|
|
this.$http.post(query, params).then(res => {
|
|
request.itemDescription = res.data.concept;
|
|
request.isOk = true;
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
});
|
|
}
|
|
}
|
|
|
|
changeQuantity(request) {
|
|
if (request.saleFk) {
|
|
let params = {
|
|
quantity: request.saleQuantity
|
|
};
|
|
|
|
let endpoint = `Sales/${request.saleFk}/`;
|
|
|
|
this.$http.patch(endpoint, params).then(() => {
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
}).then(() => this.confirmRequest(request));
|
|
} else
|
|
this.confirmRequest(request);
|
|
}
|
|
|
|
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.selectedRequest = requestId;
|
|
this.$.denyReason.parent = event.target;
|
|
this.$.denyReason.show();
|
|
document.querySelector('vn-item-request vn-textarea textArea').focus();
|
|
}
|
|
|
|
clear() {
|
|
delete this.denyRequestId;
|
|
}
|
|
|
|
denyRequest(response) {
|
|
if (response !== 'accept') return;
|
|
|
|
let params = {
|
|
observation: this.denyObservation
|
|
};
|
|
|
|
let query = `TicketRequests/${this.selectedRequest.id}/deny`;
|
|
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;
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
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();
|
|
}
|
|
}
|
|
|
|
ngModule.component('vnItemRequest', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|