2018-08-30 07:19:09 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2019-06-12 06:19:02 +00:00
|
|
|
constructor($state, $, $http, $translate, vnApp, aclService) {
|
2018-08-30 07:19:09 +00:00
|
|
|
this.$state = $state;
|
2019-06-12 06:19:02 +00:00
|
|
|
this.$ = $;
|
2018-08-30 07:19:09 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
2019-04-08 07:01:10 +00:00
|
|
|
this.aclService = aclService;
|
2019-06-12 06:19:02 +00:00
|
|
|
this.edit = {};
|
2018-08-30 07:19:09 +00:00
|
|
|
this.filter = {
|
|
|
|
where: {claimFk: $state.params.id},
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-22 09:31:12 +00:00
|
|
|
set salesClaimed(value) {
|
|
|
|
this._salesClaimed = value;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
this.calculateTotals();
|
|
|
|
}
|
|
|
|
|
|
|
|
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}};
|
|
|
|
let query = `/api/Sales/getClaimableFromTicket`;
|
|
|
|
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};
|
2018-08-30 07:19:09 +00:00
|
|
|
let query = `claim/api/ClaimBeginnings/`;
|
|
|
|
this.$http.post(query, saleToAdd).then(() => {
|
2019-06-12 06:19:02 +00:00
|
|
|
this.$.addSales.hide();
|
|
|
|
this.$.model.refresh();
|
2018-08-30 07:19:09 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
2019-04-08 07:01:10 +00:00
|
|
|
|
|
|
|
if (this.aclService.hasAny(['salesAssistant']))
|
|
|
|
this.$state.go('claim.card.development');
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-23 13:30:01 +00:00
|
|
|
deleteClaimedSale(index) {
|
|
|
|
let sale = this.salesClaimed[index];
|
|
|
|
let query = `claim/api/ClaimBeginnings/${sale.id}`;
|
2018-08-30 07:19:09 +00:00
|
|
|
this.$http.delete(query).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
2019-06-12 06:19:02 +00:00
|
|
|
this.$.model.remove(index);
|
2018-11-23 13:30:01 +00:00
|
|
|
this.calculateTotals();
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setClaimedQuantity(id, claimedQuantity) {
|
|
|
|
let params = {id: id, quantity: claimedQuantity};
|
|
|
|
let query = `claim/api/ClaimBeginnings/`;
|
|
|
|
this.$http.patch(query, params).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('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);
|
|
|
|
this.claimedTotal += sale.quantity * orgSale.price - ((orgSale.discount * (sale.quantity * orgSale.price)) / 100);
|
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;
|
|
|
|
total += sale.quantity * sale.price - ((sale.discount * (sale.quantity * sale.price)) / 100);
|
|
|
|
return total;
|
2018-12-20 13:37:29 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 12:29:46 +00:00
|
|
|
// Item Descriptor
|
|
|
|
showDescriptor(event, itemFk) {
|
2019-06-12 06:19:02 +00:00
|
|
|
this.$.descriptor.itemFk = itemFk;
|
|
|
|
this.$.descriptor.parent = event.target;
|
|
|
|
this.$.descriptor.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
showEditPopover(event, saleClaimed) {
|
|
|
|
this.saleClaimed = saleClaimed;
|
|
|
|
|
|
|
|
if (!this.aclService.hasAny(['salesAssistant']))
|
|
|
|
return this.vnApp.showError(this.$translate.instant('Insuficient permisos'));
|
|
|
|
|
|
|
|
this.$.editPopover.parent = event.target;
|
|
|
|
this.$.editPopover.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
getManaSalespersonMana() {
|
|
|
|
this.$http.get(`/api/Tickets/${this.claim.ticketFk}/getSalesPersonMana`).then(res => {
|
|
|
|
this.mana = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDiscount() {
|
|
|
|
if (this.newDiscount != this.saleClaimed.sale.discount) {
|
|
|
|
const params = {salesIds: [this.saleClaimed.sale.id], newDiscount: this.newDiscount};
|
|
|
|
const query = `/api/Tickets/${this.saleClaimed.sale.ticketFk}/updateDiscount`;
|
|
|
|
|
|
|
|
this.$http.post(query, params).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
this.clearDiscount();
|
|
|
|
this.$.model.refresh();
|
|
|
|
}).catch(err => {
|
|
|
|
this.vnApp.showError(err.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-04-08 07:01:10 +00:00
|
|
|
Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp', 'aclService'];
|
2018-08-30 07:19:09 +00:00
|
|
|
|
|
|
|
ngModule.component('vnClaimDetail', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
claim: '<'
|
|
|
|
}
|
|
|
|
});
|