salix/modules/client/front/balance/index/index.js

120 lines
3.2 KiB
JavaScript
Raw Normal View History

2018-10-19 06:40:32 +00:00
import ngModule from '../../module';
2018-11-14 09:55:15 +00:00
import './style.scss';
2018-10-19 06:40:32 +00:00
class Controller {
2019-04-05 11:20:34 +00:00
constructor($stateParams, $translate, $scope, vnToken, $http) {
this.$http = $http;
2018-11-14 09:55:15 +00:00
this.$ = $scope;
2018-10-19 06:40:32 +00:00
this.$stateParams = $stateParams;
2018-11-14 09:55:15 +00:00
this.$translate = $translate;
2019-01-14 16:26:59 +00:00
this.accessToken = vnToken.token;
2018-11-14 09:55:15 +00:00
this.companyFk = window.localStorage.defaultCompanyFk;
2018-10-19 06:40:32 +00:00
this.filter = {
include: {
2018-11-14 09:55:15 +00:00
relation: 'company',
2018-10-19 06:40:32 +00:00
scope: {
2018-11-14 09:55:15 +00:00
fields: ['code'],
},
2018-10-19 06:40:32 +00:00
},
where: {
2018-11-14 09:55:15 +00:00
clientFk: $stateParams.id,
2019-01-25 07:50:13 +00:00
companyFk: this.companyFk
2018-11-14 09:55:15 +00:00
},
};
this.params = {
params: {
clientFk: this.$stateParams.id,
companyFk: this.companyFk,
},
};
}
setOrder(value) {
this.params.params.companyFk = value;
2019-01-25 07:50:13 +00:00
this.filter.where.companyFk = value;
2019-02-05 15:46:02 +00:00
}
refresh() {
2018-11-14 09:55:15 +00:00
this.$.model.refresh();
2019-01-25 07:50:13 +00:00
this.$.riskModel.refresh();
2018-11-14 09:55:15 +00:00
}
2019-04-05 11:20:34 +00:00
set balances(value) {
this._balances = value;
if (!value) return;
const params = {filter: this.filter};
this.$http.get(`/client/api/ClientRisks`, {params}).then(response => {
if (response.data) {
this.clientRisks = response.data;
2019-04-05 11:20:34 +00:00
this.getBalances();
2018-11-14 09:55:15 +00:00
}
2019-04-05 11:20:34 +00:00
});
2018-11-14 09:55:15 +00:00
}
2019-04-05 11:20:34 +00:00
get balances() {
return this._balances;
}
getCurrentBalance() {
const selectedCompany = this.$.company.selection;
const currentBalance = this.clientRisks.find(balance => {
2019-04-05 11:20:34 +00:00
return balance.companyFk === selectedCompany.id;
});
return currentBalance.amount;
}
getBalances() {
this.balances.forEach((balance, index) => {
if (index === 0)
balance.balance = this.getCurrentBalance();
if (index > 0) {
let previousBalance = this.balances[index - 1];
balance.balance = previousBalance.balance - (previousBalance.debit - previousBalance.credit);
}
});
2018-10-19 06:40:32 +00:00
}
2019-01-14 16:26:59 +00:00
2019-04-05 11:20:34 +00:00
2019-02-05 15:46:02 +00:00
openCreateDialog() {
this.$.balanceCreateDialog.companyFk = this.companyFk;
this.$.balanceCreateDialog.onResponse = () => {
2019-02-05 15:46:02 +00:00
this.refresh();
};
this.$.balanceCreateDialog.show();
2019-02-05 15:46:02 +00:00
}
showWorkerDescriptor(event, workerFk) {
2019-04-05 11:20:34 +00:00
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
this.selectedWorker = workerFk;
2019-04-05 11:20:34 +00:00
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
showInvoiceOutDescriptor(event, balance) {
if (!balance.isInvoice) return;
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
this.selectedInvoiceOut = balance.id;
this.$.invoiceOutDescriptor.parent = event.target;
this.$.invoiceOutDescriptor.show();
}
2018-10-19 06:40:32 +00:00
}
2019-04-05 11:20:34 +00:00
Controller.$inject = ['$stateParams', '$translate', '$scope', 'vnToken', '$http'];
2018-10-19 06:40:32 +00:00
ngModule.component('vnClientBalanceIndex', {
2018-10-19 06:40:32 +00:00
template: require('./index.html'),
2018-11-14 09:55:15 +00:00
controller: Controller,
2018-10-19 06:40:32 +00:00
});