2019-04-05 13:20:12 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-24 16:27:21 +00:00
|
|
|
import Section from 'salix/components/section';
|
2019-04-05 13:20:12 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-24 16:27:21 +00:00
|
|
|
export default class Controller extends Section {
|
2019-10-24 10:44:36 +00:00
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
|
|
|
|
|
|
|
if (!this.$state.q) {
|
2023-01-16 14:18:24 +00:00
|
|
|
const today = Date.vnNew();
|
2020-06-03 10:21:03 +00:00
|
|
|
today.setHours(0, 0, 0, 0);
|
2019-10-22 11:44:36 +00:00
|
|
|
|
2023-01-16 14:18:24 +00:00
|
|
|
const nextWeek = Date.vnNew();
|
2020-06-03 10:21:03 +00:00
|
|
|
nextWeek.setHours(23, 59, 59, 59);
|
|
|
|
nextWeek.setDate(nextWeek.getDate() + 7);
|
2019-10-22 11:44:36 +00:00
|
|
|
|
2020-06-02 12:42:58 +00:00
|
|
|
this.filterParams = {
|
2021-02-23 15:27:18 +00:00
|
|
|
from: today,
|
|
|
|
to: nextWeek,
|
2020-08-31 06:32:30 +00:00
|
|
|
state: 'pending'
|
2019-10-22 11:44:36 +00:00
|
|
|
};
|
|
|
|
}
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 15:09:29 +00:00
|
|
|
fetchParams($params) {
|
|
|
|
if (!Object.entries($params).length)
|
|
|
|
$params.scopeDays = 1;
|
|
|
|
|
|
|
|
if (typeof $params.scopeDays === 'number') {
|
2023-01-16 14:18:24 +00:00
|
|
|
const from = Date.vnNew();
|
2021-02-23 15:09:29 +00:00
|
|
|
from.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
const to = new Date(from.getTime());
|
|
|
|
to.setDate(to.getDate() + $params.scopeDays);
|
|
|
|
to.setHours(23, 59, 59, 999);
|
|
|
|
|
|
|
|
Object.assign($params, {from, to});
|
|
|
|
}
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
2019-04-05 13:20:12 +00:00
|
|
|
getState(isOk) {
|
|
|
|
if (isOk === null)
|
2020-08-31 06:32:30 +00:00
|
|
|
return 'Pending';
|
2020-03-24 16:27:21 +00:00
|
|
|
else if (isOk)
|
2020-08-31 06:32:30 +00:00
|
|
|
return 'Accepted';
|
2019-04-05 13:20:12 +00:00
|
|
|
else
|
2020-08-31 06:32:30 +00:00
|
|
|
return 'Denied';
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
let endpoint = `Sales/${request.saleFk}`;
|
2019-04-05 13:20:12 +00:00
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
this.$http.patch(endpoint, params)
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
|
|
|
.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) {
|
2023-01-16 14:18:24 +00:00
|
|
|
let today = Date.vnNew();
|
2019-04-05 13:20:12 +00:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:27:21 +00:00
|
|
|
onDenyAccept(request) {
|
2019-04-05 13:20:12 +00:00
|
|
|
let params = {
|
|
|
|
observation: this.denyObservation
|
|
|
|
};
|
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
return this.$http.post(`TicketRequests/${request.id}/deny`, params)
|
|
|
|
.then(res => {
|
|
|
|
const newRequest = res.data;
|
|
|
|
request.isOk = newRequest.isOk;
|
|
|
|
request.attenderFk = newRequest.attenderFk;
|
|
|
|
request.response = newRequest.response;
|
2019-04-05 13:20:12 +00:00
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
});
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
2020-08-31 06:32:30 +00:00
|
|
|
|
|
|
|
exprBuilder(param, value) {
|
|
|
|
switch (param) {
|
|
|
|
case 'ticketFk':
|
|
|
|
case 'quantity':
|
|
|
|
case 'price':
|
|
|
|
case 'isOk':
|
|
|
|
return {[`tr.${param}`]: value};
|
|
|
|
case 'attenderName':
|
|
|
|
return {[`ua.name`]: value};
|
|
|
|
case 'shipped':
|
|
|
|
return {'t.shipped': {
|
|
|
|
between: this.dateRange(value)}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dateRange(value) {
|
|
|
|
const minHour = new Date(value);
|
|
|
|
minHour.setHours(0, 0, 0, 0);
|
|
|
|
const maxHour = new Date(value);
|
|
|
|
maxHour.setHours(23, 59, 59, 59);
|
|
|
|
|
|
|
|
return [minHour, maxHour];
|
|
|
|
}
|
2019-04-05 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnItemRequest', {
|
2019-04-05 13:20:12 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|