2018-09-05 09:34:23 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2019-12-19 10:37:53 +00:00
|
|
|
constructor($stateParams, $scope, $http, $translate, vnApp, $httpParamSerializer) {
|
2018-10-02 07:52:38 +00:00
|
|
|
this.$stateParams = $stateParams;
|
2018-09-05 09:34:23 +00:00
|
|
|
this.$ = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
2019-12-19 10:37:53 +00:00
|
|
|
this.$httpParamSerializer = $httpParamSerializer;
|
2018-09-05 09:34:23 +00:00
|
|
|
this.filter = {
|
2018-10-02 07:52:38 +00:00
|
|
|
where: {claimFk: $stateParams.id},
|
2018-09-05 09:34:23 +00:00
|
|
|
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
|
|
|
]
|
|
|
|
};
|
2018-10-08 05:31:55 +00:00
|
|
|
this.resolvedState = 3;
|
2019-04-16 06:09:16 +00:00
|
|
|
this.maxResponsibility = 5;
|
2018-09-05 09:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
openAddSalesDialog() {
|
|
|
|
this.getClaimedSales();
|
|
|
|
this.$.addSales.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
getClaimedSales() {
|
|
|
|
let json = encodeURIComponent(JSON.stringify(this.claim.id));
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `ClaimBeginnings/${json}`;
|
2018-09-05 09:34:23 +00:00
|
|
|
this.$http.get(query).then(res => {
|
2018-11-21 12:29:46 +00:00
|
|
|
if (res.data)
|
2018-09-05 09:34:23 +00:00
|
|
|
this.claimedSales = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addClaimedSale(saleFk) {
|
|
|
|
let saleToAdd = {saleFk: saleFk, claimFk: this.claim.id, workerFk: this.claim.workerFk, claimDestinationFk: 1};
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `ClaimEnds/`;
|
2018-09-05 09:34:23 +00:00
|
|
|
this.$http.post(query, saleToAdd).then(() => {
|
|
|
|
this.$.model.refresh();
|
|
|
|
this.$.addSales.hide();
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteClaimedSale(id) {
|
|
|
|
let json = encodeURIComponent(JSON.stringify(id));
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `ClaimEnds/${json}`;
|
2018-09-05 09:34:23 +00:00
|
|
|
this.$http.delete(query).then(() => {
|
|
|
|
this.$.model.refresh();
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-25 12:37:35 +00:00
|
|
|
importToNewRefundTicket() {
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `ClaimBeginnings/${this.$stateParams.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();
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-21 12:48:34 +00:00
|
|
|
showTicketDescriptor(event, ticketFk) {
|
|
|
|
this.$.ticketDescriptor.ticketFk = ticketFk;
|
|
|
|
this.$.ticketDescriptor.parent = event.target;
|
|
|
|
this.$.ticketDescriptor.show();
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
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 => {
|
|
|
|
this.claimedTotal += (sale.sale.quantity * sale.sale.price) - ((sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100);
|
|
|
|
});
|
|
|
|
}
|
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();
|
|
|
|
this.$.lastTicketsPopover.parent = event.target;
|
|
|
|
this.$.lastTicketsPopover.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
importTicketLines(ticketFk) {
|
|
|
|
let data = {claimFk: this.$stateParams.id, ticketFk: ticketFk};
|
|
|
|
|
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(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
this.$.lastTicketsPopover.hide();
|
|
|
|
this.$.model.refresh();
|
|
|
|
});
|
|
|
|
}
|
2018-10-08 05:31:55 +00:00
|
|
|
|
|
|
|
regularize() {
|
|
|
|
let data = {claimFk: this.$stateParams.id};
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Claims/regularizeClaim`;
|
2019-06-20 11:50:58 +00:00
|
|
|
return this.$http.post(query, data).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
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
|
|
|
|
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'}}};
|
|
|
|
const serializedParams = this.$httpParamSerializer(params);
|
|
|
|
const query = `GreugeTypes/findOne?${serializedParams}`;
|
|
|
|
return this.$http.get(query).then(res => {
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
onUpdateGreugeResponse(response) {
|
|
|
|
if (response == 'accept') {
|
|
|
|
const promises = [];
|
|
|
|
promises.push(this.getGreugeTypeId());
|
|
|
|
promises.push(this.getGreugeConfig());
|
|
|
|
|
2019-12-20 08:30:35 +00:00
|
|
|
return Promise.all(promises).then(() => {
|
2019-12-19 10:37:53 +00:00
|
|
|
const data = {
|
|
|
|
clientFk: this.claim.clientFk,
|
|
|
|
description: this.$translate.instant('ClaimGreugeDescription', {
|
|
|
|
claimId: this.claim.id
|
|
|
|
}).toUpperCase(),
|
|
|
|
amount: this.freightPickUpPrice,
|
|
|
|
greugeTypeFk: this.greugeTypeFreightId,
|
|
|
|
ticketFk: this.claim.ticketFk
|
|
|
|
};
|
2019-12-20 08:30:35 +00:00
|
|
|
return this.$http.post(`Greuges/`, data).then(() => {
|
2019-12-19 10:37:53 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
this.vnApp.showMessage(this.$translate.instant('Greuge inserted'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
}
|
|
|
|
|
2018-11-21 12:29:46 +00:00
|
|
|
// Item Descriptor
|
|
|
|
showDescriptor(event, itemFk) {
|
|
|
|
this.$.descriptor.itemFk = itemFk;
|
|
|
|
this.$.descriptor.parent = event.target;
|
|
|
|
this.$.descriptor.show();
|
|
|
|
}
|
2018-12-21 13:52:26 +00:00
|
|
|
|
2019-01-15 11:06:19 +00:00
|
|
|
saveResponsibility(value) {
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Claims/${this.$stateParams.id}/updateClaimAction`;
|
2018-12-21 13:52:26 +00:00
|
|
|
|
2019-01-15 11:06:19 +00:00
|
|
|
this.$http.post(query, {responsibility: value}).then(() => {
|
2018-12-21 13:52:26 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
2019-12-19 10:37:53 +00:00
|
|
|
|
2019-06-04 09:00:05 +00:00
|
|
|
saveMana(value) {
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Claims/${this.$stateParams.id}/updateClaimAction`;
|
2019-06-04 09:00:05 +00:00
|
|
|
|
|
|
|
this.$http.post(query, {isChargedToMana: value}).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
2018-09-05 09:34:23 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 10:37:53 +00:00
|
|
|
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp', '$httpParamSerializer'];
|
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
|
|
|
}
|
|
|
|
});
|