2018-08-30 07:19:09 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-16 10:58:14 +00:00
|
|
|
import Section from 'salix/components/section';
|
2018-08-30 07:19:09 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-16 10:58:14 +00:00
|
|
|
class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2019-06-12 06:19:02 +00:00
|
|
|
this.edit = {};
|
2018-08-30 07:19:09 +00:00
|
|
|
this.filter = {
|
2020-03-16 10:58:14 +00:00
|
|
|
where: {claimFk: this.$params.id},
|
2018-08-30 07:19:09 +00:00
|
|
|
include: [
|
2018-12-20 13:37:29 +00:00
|
|
|
{
|
|
|
|
relation: 'sale',
|
2018-08-30 07:19:09 +00:00
|
|
|
scope: {
|
2018-11-21 12:29:46 +00:00
|
|
|
fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount', 'itemFk'],
|
2018-08-30 07:19:09 +00:00
|
|
|
include: {
|
|
|
|
relation: 'ticket'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-09 11:24:56 +00:00
|
|
|
get claim() {
|
|
|
|
return this._claim;
|
|
|
|
}
|
|
|
|
|
|
|
|
set claim(value) {
|
|
|
|
this._claim = value;
|
2019-01-22 09:31:12 +00:00
|
|
|
|
2020-01-07 12:03:45 +00:00
|
|
|
if (value) {
|
|
|
|
this.isClaimEditable();
|
2020-06-11 10:31:52 +00:00
|
|
|
this.isTicketEditable();
|
2020-01-07 12:03:45 +00:00
|
|
|
}
|
2019-01-22 09:31:12 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 11:24:56 +00:00
|
|
|
set salesClaimed(value) {
|
|
|
|
this._salesClaimed = value;
|
|
|
|
|
|
|
|
if (value) this.calculateTotals();
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:31:12 +00:00
|
|
|
get salesClaimed() {
|
|
|
|
return this._salesClaimed;
|
|
|
|
}
|
|
|
|
|
2019-06-17 10:13:05 +00:00
|
|
|
get newDiscount() {
|
|
|
|
return this._newDiscount;
|
|
|
|
}
|
|
|
|
|
|
|
|
set newDiscount(value) {
|
|
|
|
this._newDiscount = value;
|
|
|
|
this.updateNewPrice();
|
|
|
|
}
|
|
|
|
|
2018-08-30 07:19:09 +00:00
|
|
|
openAddSalesDialog() {
|
|
|
|
this.getClaimableFromTicket();
|
2019-06-12 06:19:02 +00:00
|
|
|
this.$.addSales.show();
|
2018-08-30 07:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getClaimableFromTicket() {
|
2018-12-20 13:37:29 +00:00
|
|
|
let config = {params: {ticketFk: this.claim.ticketFk}};
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Sales/getClaimableFromTicket`;
|
2018-12-20 13:37:29 +00:00
|
|
|
this.$http.get(query, config).then(res => {
|
2018-11-21 12:29:46 +00:00
|
|
|
if (res.data)
|
2018-08-30 07:19:09 +00:00
|
|
|
this.salesToClaim = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-23 13:30:01 +00:00
|
|
|
addClaimedSale(index) {
|
|
|
|
let sale = this.salesToClaim[index];
|
2019-04-01 07:03:05 +00:00
|
|
|
let saleToAdd = {saleFk: sale.saleFk, claimFk: this.claim.id, quantity: sale.quantity};
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `ClaimBeginnings/`;
|
2018-08-30 07:19:09 +00:00
|
|
|
this.$http.post(query, saleToAdd).then(() => {
|
2019-06-12 06:19:02 +00:00
|
|
|
this.$.addSales.hide();
|
|
|
|
this.$.model.refresh();
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-04-08 07:01:10 +00:00
|
|
|
|
2020-10-26 11:16:57 +00:00
|
|
|
if (this.aclService.hasAny(['claimManager']))
|
2019-04-08 07:01:10 +00:00
|
|
|
this.$state.go('claim.card.development');
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-18 08:10:42 +00:00
|
|
|
showDeleteConfirm(index) {
|
|
|
|
this.sale = this.salesClaimed[index];
|
|
|
|
this.$.confirm.show();
|
|
|
|
}
|
|
|
|
|
2020-06-23 10:46:24 +00:00
|
|
|
deleteClaimedSale() {
|
|
|
|
let query = `ClaimBeginnings/${this.sale.id}`;
|
|
|
|
this.$http.delete(query).then(() => {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2020-06-23 10:46:24 +00:00
|
|
|
this.$.model.remove(this.sale);
|
|
|
|
this.calculateTotals();
|
|
|
|
});
|
2018-08-30 07:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setClaimedQuantity(id, claimedQuantity) {
|
|
|
|
let params = {id: id, quantity: claimedQuantity};
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `ClaimBeginnings/`;
|
2018-08-30 07:19:09 +00:00
|
|
|
this.$http.patch(query, params).then(() => {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2018-11-23 13:30:01 +00:00
|
|
|
this.calculateTotals();
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
}
|
2018-09-05 09:45:33 +00:00
|
|
|
|
|
|
|
calculateTotals() {
|
2018-12-20 13:37:29 +00:00
|
|
|
this.paidTotal = 0.0;
|
|
|
|
this.claimedTotal = 0.0;
|
2019-01-22 09:31:12 +00:00
|
|
|
if (!this._salesClaimed) return;
|
2018-11-23 13:30:01 +00:00
|
|
|
|
2019-01-22 09:31:12 +00:00
|
|
|
this._salesClaimed.forEach(sale => {
|
2018-12-20 13:37:29 +00:00
|
|
|
let orgSale = sale.sale;
|
|
|
|
this.paidTotal += this.getSaleTotal(orgSale);
|
2020-06-16 06:50:59 +00:00
|
|
|
|
|
|
|
const price = sale.quantity * orgSale.price;
|
|
|
|
const discount = ((orgSale.discount * price) / 100);
|
|
|
|
|
|
|
|
this.claimedTotal += price - discount;
|
2018-09-05 09:45:33 +00:00
|
|
|
});
|
|
|
|
}
|
2018-11-21 12:29:46 +00:00
|
|
|
|
2018-12-20 13:37:29 +00:00
|
|
|
getSaleTotal(sale) {
|
2019-01-22 11:24:19 +00:00
|
|
|
let total = 0.0;
|
2020-06-16 06:50:59 +00:00
|
|
|
|
|
|
|
const price = sale.quantity * sale.price;
|
|
|
|
const discount = ((sale.discount * price) / 100);
|
|
|
|
|
|
|
|
total += price - discount;
|
2019-01-22 11:24:19 +00:00
|
|
|
return total;
|
2018-12-20 13:37:29 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 06:19:02 +00:00
|
|
|
showEditPopover(event, saleClaimed) {
|
2020-01-08 09:08:27 +00:00
|
|
|
if (this.isEditable) {
|
2020-10-26 11:16:57 +00:00
|
|
|
if (!this.aclService.hasAny(['claimManager']))
|
2020-07-23 14:07:08 +00:00
|
|
|
return this.vnApp.showError(this.$t('Insuficient permisos'));
|
2019-06-12 06:19:02 +00:00
|
|
|
|
2020-01-08 09:08:27 +00:00
|
|
|
this.saleClaimed = saleClaimed;
|
|
|
|
this.$.editPopover.parent = event.target;
|
|
|
|
this.$.editPopover.show();
|
|
|
|
}
|
2019-06-12 06:19:02 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 07:01:13 +00:00
|
|
|
getSalespersonMana() {
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.get(`Tickets/${this.claim.ticketFk}/getSalesPersonMana`).then(res => {
|
2019-06-12 06:19:02 +00:00
|
|
|
this.mana = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-11 10:31:52 +00:00
|
|
|
isTicketEditable() {
|
2020-06-16 06:50:59 +00:00
|
|
|
if (!this.claim) return;
|
|
|
|
|
2020-01-07 12:03:45 +00:00
|
|
|
this.$http.get(`Tickets/${this.claim.ticketFk}/isEditable`).then(res => {
|
|
|
|
this.isEditable = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-16 05:47:46 +00:00
|
|
|
isClaimEditable() {
|
2020-06-16 09:36:06 +00:00
|
|
|
if (!this.claim) return;
|
|
|
|
|
2020-06-16 05:47:46 +00:00
|
|
|
this.$http.get(`Claims/${this.claim.id}/isEditable`).then(res => {
|
|
|
|
this.isRewritable = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-12 06:19:02 +00:00
|
|
|
updateDiscount() {
|
2019-12-13 07:01:13 +00:00
|
|
|
const claimedSale = this.saleClaimed.sale;
|
|
|
|
if (this.newDiscount != claimedSale.discount) {
|
|
|
|
const params = {salesIds: [claimedSale.id], newDiscount: this.newDiscount};
|
|
|
|
const query = `Tickets/${claimedSale.ticketFk}/updateDiscount`;
|
2019-06-12 06:19:02 +00:00
|
|
|
|
|
|
|
this.$http.post(query, params).then(() => {
|
2019-12-13 07:01:13 +00:00
|
|
|
claimedSale.discount = this.newDiscount;
|
|
|
|
this.calculateTotals();
|
2019-06-12 06:19:02 +00:00
|
|
|
this.clearDiscount();
|
2019-12-13 07:01:13 +00:00
|
|
|
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-06-12 06:19:02 +00:00
|
|
|
}).catch(err => {
|
|
|
|
this.vnApp.showError(err.message);
|
|
|
|
});
|
|
|
|
}
|
2019-12-13 07:01:13 +00:00
|
|
|
|
|
|
|
this.$.editPopover.hide();
|
2019-06-12 06:19:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 10:13:05 +00:00
|
|
|
updateNewPrice() {
|
|
|
|
this.newPrice = (this.saleClaimed.quantity * this.saleClaimed.sale.price) -
|
|
|
|
((this.newDiscount * (this.saleClaimed.quantity * this.saleClaimed.sale.price)) / 100);
|
|
|
|
}
|
|
|
|
|
2019-06-12 06:19:02 +00:00
|
|
|
clearDiscount() {
|
|
|
|
this.newDiscount = null;
|
2018-11-21 12:29:46 +00:00
|
|
|
}
|
2018-08-30 07:19:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 10:58:14 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
2018-08-30 07:19:09 +00:00
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnClaimDetail', {
|
2018-08-30 07:19:09 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
claim: '<'
|
|
|
|
}
|
|
|
|
});
|