salix/modules/claim/front/detail/index.js

124 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-08-30 07:19:09 +00:00
import ngModule from '../module';
import './style.scss';
class Controller {
constructor($state, $scope, $http, $translate, vnApp) {
this.$state = $state;
this.$ = $scope;
this.$http = $http;
this.$translate = $translate;
this.vnApp = vnApp;
this.filter = {
where: {claimFk: $state.params.id},
include: [
{
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'
}
}
}
]
};
}
set salesClaimed(value) {
this._salesClaimed = value;
if (value)
this.calculateTotals();
}
get salesClaimed() {
return this._salesClaimed;
}
2018-08-30 07:19:09 +00:00
openAddSalesDialog() {
this.getClaimableFromTicket();
this.$.addSales.show();
}
getClaimableFromTicket() {
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];
let saleToAdd = {saleFk: sale.saleFk, claimFk: this.claim.id, quantity: 0};
2018-08-30 07:19:09 +00:00
let query = `claim/api/ClaimBeginnings/`;
this.$http.post(query, saleToAdd).then(() => {
this.$.addSales.hide();
2018-11-23 13:30:01 +00:00
this.$.model.refresh();
2018-08-30 07:19:09 +00:00
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
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!'));
2018-11-23 13:30:01 +00:00
this.$.model.remove(index);
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() {
this.paidTotal = 0.0;
this.claimedTotal = 0.0;
if (!this._salesClaimed) return;
2018-11-23 13:30:01 +00:00
this._salesClaimed.forEach(sale => {
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
getSaleTotal(sale) {
return (sale.quantity * sale.price) - ((100 - sale.discount) / 100);
}
2018-11-21 12:29:46 +00:00
// Item Descriptor
showDescriptor(event, itemFk) {
this.quicklinks = {
btnThree: {
icon: 'icon-transaction',
state: `item.card.diary({
id: ${itemFk}
})`,
tooltip: 'Item diary'
}
};
this.$.descriptor.itemFk = itemFk;
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
}
2018-08-30 07:19:09 +00:00
}
Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp'];
ngModule.component('vnClaimDetail', {
template: require('./index.html'),
controller: Controller,
bindings: {
claim: '<'
}
});