2018-09-05 09:34:23 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2018-10-02 07:52:38 +00:00
|
|
|
constructor($stateParams, $scope, $http, $translate, vnApp) {
|
|
|
|
this.$stateParams = $stateParams;
|
2018-09-05 09:34:23 +00:00
|
|
|
this.$ = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
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: {
|
|
|
|
fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount'],
|
|
|
|
include: {
|
|
|
|
relation: 'ticket'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{relation: 'claimBeggining'}
|
|
|
|
]
|
|
|
|
};
|
2018-10-08 05:31:55 +00:00
|
|
|
this.resolvedState = 3;
|
2018-09-05 09:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
openAddSalesDialog() {
|
|
|
|
this.getClaimedSales();
|
|
|
|
this.$.addSales.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
getClaimedSales() {
|
|
|
|
let json = encodeURIComponent(JSON.stringify(this.claim.id));
|
|
|
|
|
|
|
|
let query = `/claim/api/ClaimBeginnings/${json}`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
if (res.data) {
|
|
|
|
this.claimedSales = res.data;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addClaimedSale(saleFk) {
|
|
|
|
let saleToAdd = {saleFk: saleFk, claimFk: this.claim.id, workerFk: this.claim.workerFk, claimDestinationFk: 1};
|
|
|
|
let query = `claim/api/ClaimEnds/`;
|
|
|
|
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));
|
|
|
|
let query = `claim/api/ClaimEnds/${json}`;
|
|
|
|
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() {
|
2018-10-02 07:52:38 +00:00
|
|
|
let query = `claim/api/ClaimBeginnings/${this.$stateParams.id}/importToNewRefundTicket`;
|
2018-09-25 12:37:35 +00:00
|
|
|
this.$http.post(query).then(() => {
|
|
|
|
this.$.model.refresh();
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-05 09:34:23 +00:00
|
|
|
focusLastInput() {
|
|
|
|
let inputs = document.querySelectorAll("#claimDestinationFk");
|
|
|
|
inputs[inputs.length - 1].querySelector("input").focus();
|
|
|
|
this.calculateTotals();
|
|
|
|
}
|
|
|
|
|
|
|
|
setClaimDestination(id, claimDestinationFk) {
|
|
|
|
let params = {id: id, claimDestinationFk: claimDestinationFk};
|
|
|
|
let query = `claim/api/ClaimEnds/`;
|
|
|
|
this.$http.patch(query, params).then(() => {
|
|
|
|
this.$.model.refresh();
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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: {
|
|
|
|
created: {gt: pastWeek}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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};
|
|
|
|
|
|
|
|
let query = `/claim/api/ClaimEnds/importTicketSales`;
|
|
|
|
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};
|
|
|
|
let query = `/claim/api/Claims/regularizeClaim`;
|
|
|
|
this.$http.post(query, data).then(() => {
|
|
|
|
this.card.reload();
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
2018-09-05 09:34:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 07:52:38 +00:00
|
|
|
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
|
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
|
|
|
}
|
|
|
|
});
|