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-10-09 22:47:29 +00:00
|
|
|
constructor($stateParams, $translate, $scope, vnToken, $http, vnConfig) {
|
2019-04-05 11:20:34 +00:00
|
|
|
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
|
|
|
|
2019-01-23 12:11:44 +00:00
|
|
|
this.accessToken = vnToken.token;
|
2019-10-15 11:18:56 +00:00
|
|
|
this.vnConfig = vnConfig;
|
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'],
|
|
|
|
},
|
2020-01-02 13:44:51 +00:00
|
|
|
}
|
2018-11-14 09:55:15 +00:00
|
|
|
};
|
|
|
|
}
|
2019-10-15 11:18:56 +00:00
|
|
|
|
2020-01-03 11:29:13 +00:00
|
|
|
get companyId() {
|
|
|
|
if (!this._companyId)
|
|
|
|
this.companyId = this.vnConfig.companyFk;
|
2019-10-15 11:18:56 +00:00
|
|
|
|
2020-01-03 11:29:13 +00:00
|
|
|
return this._companyId;
|
2019-10-15 11:18:56 +00:00
|
|
|
}
|
|
|
|
|
2020-01-03 11:29:13 +00:00
|
|
|
set companyId(value) {
|
|
|
|
this._companyId = value;
|
2019-02-05 15:46:02 +00:00
|
|
|
|
2020-01-03 11:29:13 +00:00
|
|
|
if (value) this.getData();
|
2018-11-14 09:55:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 13:44:51 +00:00
|
|
|
getData() {
|
|
|
|
return this.$.model.applyFilter(null, {
|
2020-01-03 11:29:13 +00:00
|
|
|
clientId: this.$stateParams.id,
|
|
|
|
companyId: this.companyId
|
2020-01-02 13:44:51 +00:00
|
|
|
}).then(() => this.$.riskModel.applyFilter({
|
|
|
|
where: {
|
|
|
|
clientFk: this.$stateParams.id,
|
2020-01-03 11:29:13 +00:00
|
|
|
companyFk: this.companyId
|
2018-11-14 09:55:15 +00:00
|
|
|
}
|
2020-01-02 13:44:51 +00:00
|
|
|
})).then(() => this.getBalances());
|
2018-11-14 09:55:15 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 11:20:34 +00:00
|
|
|
|
|
|
|
getCurrentBalance() {
|
2020-01-02 13:44:51 +00:00
|
|
|
const clientRisks = this.$.riskModel.data;
|
2020-01-03 11:29:13 +00:00
|
|
|
const selectedCompany = this.companyId;
|
2020-01-02 13:44:51 +00:00
|
|
|
const currentBalance = clientRisks.find(balance => {
|
|
|
|
return balance.companyFk === selectedCompany;
|
2019-04-05 11:20:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return currentBalance.amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
getBalances() {
|
2020-01-02 13:44:51 +00:00
|
|
|
const balances = this.$.model.data;
|
|
|
|
balances.forEach((balance, index) => {
|
2019-04-05 11:20:34 +00:00
|
|
|
if (index === 0)
|
|
|
|
balance.balance = this.getCurrentBalance();
|
|
|
|
if (index > 0) {
|
2020-01-02 13:44:51 +00:00
|
|
|
let previousBalance = balances[index - 1];
|
2019-04-05 11:20:34 +00:00
|
|
|
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() {
|
2020-01-03 11:29:13 +00:00
|
|
|
this.$.balanceCreateDialog.companyFk = this.companyId;
|
2020-01-02 13:44:51 +00:00
|
|
|
this.$.balanceCreateDialog.onResponse = () => this.getData();
|
2019-04-16 11:40:26 +00:00
|
|
|
this.$.balanceCreateDialog.show();
|
2019-02-05 15:46:02 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 12:24:02 +00:00
|
|
|
showWorkerDescriptor(event, workerFk) {
|
2019-04-05 11:20:34 +00:00
|
|
|
if (event.defaultPrevented) return;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2019-04-25 12:24:02 +00:00
|
|
|
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-10-09 22:47:29 +00:00
|
|
|
Controller.$inject = ['$stateParams', '$translate', '$scope', 'vnToken', '$http', 'vnConfig'];
|
2018-10-19 06:40:32 +00:00
|
|
|
|
2019-04-16 11:40:26 +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
|
|
|
});
|