121 lines
3.6 KiB
JavaScript
121 lines
3.6 KiB
JavaScript
import ngModule from '../module';
|
|
import './style.scss';
|
|
|
|
class Controller {
|
|
constructor($state, $scope, $http, $translate, vnApp, aclService) {
|
|
this.$state = $state;
|
|
this.$scope = $scope;
|
|
this.$http = $http;
|
|
this.$translate = $translate;
|
|
this.vnApp = vnApp;
|
|
this.aclService = aclService;
|
|
this.filter = {
|
|
where: {claimFk: $state.params.id},
|
|
include: [
|
|
{
|
|
relation: 'sale',
|
|
scope: {
|
|
fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount', 'itemFk'],
|
|
include: {
|
|
relation: 'ticket'
|
|
}
|
|
}
|
|
}
|
|
]
|
|
};
|
|
}
|
|
|
|
set salesClaimed(value) {
|
|
this._salesClaimed = value;
|
|
|
|
if (value)
|
|
this.calculateTotals();
|
|
}
|
|
|
|
get salesClaimed() {
|
|
return this._salesClaimed;
|
|
}
|
|
|
|
openAddSalesDialog() {
|
|
this.getClaimableFromTicket();
|
|
this.$scope.addSales.show();
|
|
}
|
|
|
|
getClaimableFromTicket() {
|
|
let config = {params: {ticketFk: this.claim.ticketFk}};
|
|
let query = `/api/Sales/getClaimableFromTicket`;
|
|
this.$http.get(query, config).then(res => {
|
|
if (res.data)
|
|
this.salesToClaim = res.data;
|
|
});
|
|
}
|
|
|
|
addClaimedSale(index) {
|
|
let sale = this.salesToClaim[index];
|
|
let saleToAdd = {saleFk: sale.saleFk, claimFk: this.claim.id, quantity: sale.quantity};
|
|
let query = `claim/api/ClaimBeginnings/`;
|
|
this.$http.post(query, saleToAdd).then(() => {
|
|
this.$scope.addSales.hide();
|
|
this.$scope.model.refresh();
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
if (this.aclService.hasAny(['salesAssistant']))
|
|
this.$state.go('claim.card.development');
|
|
});
|
|
}
|
|
|
|
deleteClaimedSale(index) {
|
|
let sale = this.salesClaimed[index];
|
|
let query = `claim/api/ClaimBeginnings/${sale.id}`;
|
|
this.$http.delete(query).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
this.$scope.model.remove(index);
|
|
this.calculateTotals();
|
|
});
|
|
}
|
|
|
|
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!'));
|
|
this.calculateTotals();
|
|
});
|
|
}
|
|
|
|
calculateTotals() {
|
|
this.paidTotal = 0.0;
|
|
this.claimedTotal = 0.0;
|
|
if (!this._salesClaimed) return;
|
|
|
|
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);
|
|
});
|
|
}
|
|
|
|
getSaleTotal(sale) {
|
|
let total = 0.0;
|
|
total += sale.quantity * sale.price - ((sale.discount * (sale.quantity * sale.price)) / 100);
|
|
return total;
|
|
}
|
|
|
|
// Item Descriptor
|
|
showDescriptor(event, itemFk) {
|
|
this.$scope.descriptor.itemFk = itemFk;
|
|
this.$scope.descriptor.parent = event.target;
|
|
this.$scope.descriptor.show();
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp', 'aclService'];
|
|
|
|
ngModule.component('vnClaimDetail', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
claim: '<'
|
|
}
|
|
});
|