2018-09-05 09:34:23 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-16 10:58:14 +00:00
|
|
|
import Section from 'salix/components/section';
|
2018-09-05 09:34:23 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-16 10:58:14 +00:00
|
|
|
export default class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2018-09-05 09:34:23 +00:00
|
|
|
this.filter = {
|
|
|
|
include: [
|
|
|
|
{relation: 'sale',
|
|
|
|
scope: {
|
2018-11-21 12:29:46 +00:00
|
|
|
fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount', 'itemFk'],
|
2018-09-05 09:34:23 +00:00
|
|
|
include: {
|
|
|
|
relation: 'ticket'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-10-21 11:43:17 +00:00
|
|
|
{relation: 'claimBeggining'},
|
|
|
|
{relation: 'claimDestination'}
|
2018-09-05 09:34:23 +00:00
|
|
|
]
|
|
|
|
};
|
2020-05-15 12:47:19 +00:00
|
|
|
this.getResolvedState();
|
2019-04-16 06:09:16 +00:00
|
|
|
this.maxResponsibility = 5;
|
2018-09-05 09:34:23 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 12:47:19 +00:00
|
|
|
getResolvedState() {
|
|
|
|
const query = `ClaimStates/findOne`;
|
|
|
|
const params = {
|
|
|
|
filter: {
|
|
|
|
where: {
|
|
|
|
code: 'resolved'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.$http.get(query, params).then(res =>
|
|
|
|
this.resolvedStateId = res.data.id
|
|
|
|
);
|
2018-09-05 09:34:23 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 12:37:35 +00:00
|
|
|
importToNewRefundTicket() {
|
2020-03-16 10:58:14 +00:00
|
|
|
let query = `ClaimBeginnings/${this.$params.id}/importToNewRefundTicket`;
|
2019-06-20 11:50:58 +00:00
|
|
|
return this.$http.post(query).then(() => {
|
2018-09-25 12:37:35 +00:00
|
|
|
this.$.model.refresh();
|
2020-05-19 07:28:50 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2018-09-25 12:37:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-05 09:34:23 +00:00
|
|
|
focusLastInput() {
|
2018-11-21 12:29:46 +00:00
|
|
|
let inputs = document.querySelectorAll('#claimDestinationFk');
|
|
|
|
inputs[inputs.length - 1].querySelector('input').focus();
|
2018-09-05 09:34:23 +00:00
|
|
|
this.calculateTotals();
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateTotals() {
|
|
|
|
this.claimedTotal = 0;
|
|
|
|
this.salesClaimed.forEach(sale => {
|
2020-05-15 12:47:19 +00:00
|
|
|
const price = sale.sale.quantity * sale.sale.price;
|
|
|
|
const discount = (sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100;
|
|
|
|
this.claimedTotal += price - discount;
|
2018-09-05 09:34:23 +00:00
|
|
|
});
|
|
|
|
}
|
2018-10-02 07:52:38 +00:00
|
|
|
|
|
|
|
showLastTickets(event) {
|
|
|
|
let pastWeek = new Date();
|
|
|
|
pastWeek.setDate(-7);
|
|
|
|
|
|
|
|
let filter = {
|
|
|
|
include: [
|
|
|
|
{relation: 'agencyMode', fields: ['name']},
|
|
|
|
{relation: 'warehouse', fields: ['name']}
|
|
|
|
],
|
|
|
|
where: {
|
2018-12-04 08:48:27 +00:00
|
|
|
created: {gt: pastWeek},
|
2018-12-04 09:11:02 +00:00
|
|
|
clientFk: this.claim.clientFk
|
2018-10-02 07:52:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
this.$.lastTicketsModel.filter = filter;
|
|
|
|
this.$.lastTicketsModel.refresh();
|
2020-05-19 08:51:50 +00:00
|
|
|
this.$.lastTicketsPopover.show(event);
|
2018-10-02 07:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
importTicketLines(ticketFk) {
|
2020-03-16 10:58:14 +00:00
|
|
|
let data = {claimFk: this.$params.id, ticketFk: ticketFk};
|
2018-10-02 07:52:38 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `ClaimEnds/importTicketSales`;
|
2018-10-02 07:52:38 +00:00
|
|
|
this.$http.post(query, data).then(() => {
|
2020-05-19 07:28:50 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2018-10-02 07:52:38 +00:00
|
|
|
this.$.lastTicketsPopover.hide();
|
|
|
|
this.$.model.refresh();
|
|
|
|
});
|
|
|
|
}
|
2018-10-08 05:31:55 +00:00
|
|
|
|
|
|
|
regularize() {
|
2020-05-14 12:01:34 +00:00
|
|
|
const query = `Claims/${this.$params.id}/regularizeClaim`;
|
|
|
|
return this.$http.post(query).then(() => {
|
2019-04-16 06:09:16 +00:00
|
|
|
if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2)
|
|
|
|
this.$.updateGreuge.show();
|
2019-12-19 10:37:53 +00:00
|
|
|
else
|
2020-05-19 07:28:50 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-12-19 10:37:53 +00:00
|
|
|
|
|
|
|
this.card.reload();
|
2018-10-08 05:31:55 +00:00
|
|
|
});
|
|
|
|
}
|
2018-11-21 12:29:46 +00:00
|
|
|
|
2019-12-19 10:37:53 +00:00
|
|
|
getGreugeTypeId() {
|
|
|
|
const params = {filter: {where: {code: 'freightPickUp'}}};
|
2020-03-16 10:58:14 +00:00
|
|
|
const query = `GreugeTypes/findOne`;
|
|
|
|
return this.$http.get(query, {params}).then(res => {
|
2019-12-19 10:37:53 +00:00
|
|
|
this.greugeTypeFreightId = res.data.id;
|
2019-12-20 08:30:35 +00:00
|
|
|
|
|
|
|
return res;
|
2019-12-19 10:37:53 +00:00
|
|
|
});
|
|
|
|
}
|
2019-04-16 06:09:16 +00:00
|
|
|
|
2019-12-19 10:37:53 +00:00
|
|
|
getGreugeConfig() {
|
|
|
|
const query = `GreugeConfigs/findOne`;
|
|
|
|
return this.$http.get(query).then(res => {
|
|
|
|
this.freightPickUpPrice = res.data.freightPickUpPrice;
|
2019-12-20 08:30:35 +00:00
|
|
|
|
|
|
|
return res;
|
2019-04-16 06:09:16 +00:00
|
|
|
});
|
|
|
|
}
|
2019-12-19 10:37:53 +00:00
|
|
|
|
2020-05-19 08:51:50 +00:00
|
|
|
onUpdateGreugeAccept() {
|
|
|
|
const promises = [];
|
|
|
|
promises.push(this.getGreugeTypeId());
|
|
|
|
promises.push(this.getGreugeConfig());
|
|
|
|
|
|
|
|
return Promise.all(promises).then(() => {
|
|
|
|
const data = {
|
|
|
|
clientFk: this.claim.clientFk,
|
|
|
|
description: this.$t('ClaimGreugeDescription', {
|
|
|
|
claimId: this.claim.id
|
|
|
|
}).toUpperCase(),
|
|
|
|
amount: this.freightPickUpPrice,
|
|
|
|
greugeTypeFk: this.greugeTypeFreightId,
|
|
|
|
ticketFk: this.claim.ticketFk
|
|
|
|
};
|
|
|
|
return this.$http.post(`Greuges`, data).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
this.vnApp.showMessage(this.$t('Greuge inserted'));
|
2019-12-19 10:37:53 +00:00
|
|
|
});
|
2020-05-19 08:51:50 +00:00
|
|
|
});
|
2018-12-21 13:52:26 +00:00
|
|
|
}
|
2019-12-19 10:37:53 +00:00
|
|
|
|
2020-05-13 13:04:57 +00:00
|
|
|
save(data) {
|
|
|
|
const query = `Claims/${this.$params.id}/updateClaimAction`;
|
2020-05-19 07:28:50 +00:00
|
|
|
this.$http.patch(query, data)
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
2019-06-04 09:00:05 +00:00
|
|
|
}
|
2020-02-07 06:47:11 +00:00
|
|
|
|
|
|
|
onSave() {
|
2020-05-19 07:28:50 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2020-02-07 06:47:11 +00:00
|
|
|
}
|
2018-09-05 09:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.component('vnClaimAction', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
claim: '<'
|
2018-10-08 05:31:55 +00:00
|
|
|
},
|
|
|
|
require: {
|
|
|
|
card: '^vnClaimCard'
|
2018-09-05 09:34:23 +00:00
|
|
|
}
|
|
|
|
});
|