#739 client.riisk

This commit is contained in:
Gerard 2018-11-14 10:55:15 +01:00
parent 8f7e66dc56
commit de12bda66b
6 changed files with 119 additions and 30 deletions

View File

@ -1,13 +1,9 @@
<vn-crud-model
vn-id="model"
url="/client/api/receipts/filter"
params= "{
params: {
clientFk:$ctrl.$stateParams.id
}
}"
params="$ctrl.params"
limit="20"
data="risks">
data="$ctrl.risks">
</vn-crud-model>
<vn-crud-model
vn-id="riskModel"
@ -18,15 +14,29 @@
<vn-vertical>
<vn-card pad-large>
<vn-horizontal>
<vn-title vn-two>Risk</vn-title>
<div class="totalBox" ng-if="riskTotal.length">
<h6> Total por empresa</h6>
<vn-auto ng-repeat="riskByCompany in riskTotal">
<vn-label-value label={{riskByCompany.company.code}}
value="{{riskByCompany.amount | currency: ' €': 2}}">
</vn-label-value>
</vn-auto>
</div>
<vn-one>
<vn-title>Risk</vn-title>
</vn-one>
<vn-one>
<vn-autocomplete vn-one
field="$ctrl.companyFk"
on-change="$ctrl.setOrder(value)"
url="/client/api/Companies"
show-field="code"
value-field="id"
label="Select company">
</vn-autocomplete>
</vn-one>
<vn-one>
<div class="totalBox" ng-if="riskTotal.length">
<h6> Total por empresa</h6>
<vn-auto ng-repeat="riskByCompany in riskTotal">
<vn-label-value label={{riskByCompany.company.code}}
value="{{riskByCompany.amount | currency: ' €': 2}}">
</vn-label-value>
</vn-auto>
</div>
</vn-one>
</vn-horizontal>
<vn-vertical>
<vn-table model="model">
@ -43,7 +53,7 @@
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="risk in risks">
<vn-tr ng-repeat="risk in $ctrl.risks">
<vn-td>{{::risk.payed | dateTime:'dd/MM/yyyy'}}</vn-td>
<vn-td>{{::risk.created | dateTime:'dd/MM/yyyy HH:mm'}}</vn-td>
<vn-td>{{::risk.firstName}} {{::risk.name}}</vn-td>
@ -51,6 +61,7 @@
<vn-td>{{::risk.bankFk}}</vn-td>
<vn-td>{{::risk.debit | currency: ' €': 2}}</vn-td>
<vn-td>{{::risk.credit | currency: ' €': 2}}</vn-td>
<vn-td>{{risk.balance}}</vn-td>
<vn-td>
<vn-check
field="risk.isConciliate"

View File

@ -1,25 +1,59 @@
import ngModule from '../../module';
import './style.scss';
class Controller {
constructor($stateParams) {
constructor($stateParams, $translate, $scope) {
this.$ = $scope;
this.$stateParams = $stateParams;
this.$translate = $translate;
this.companyFk = window.localStorage.defaultCompanyFk;
this.filter = {
include: {
relation: "company",
relation: 'company',
scope: {
fields: ["code"]
}
fields: ['code'],
},
},
where: {
clientFk: $stateParams.id
}};
clientFk: $stateParams.id,
},
};
this.params = {
params: {
clientFk: this.$stateParams.id,
companyFk: this.companyFk,
},
};
}
setOrder(value) {
this.params.params.companyFk = value;
this.$.model.refresh();
}
set risks(value) {
if (value) {
for (let i = this.$.model.data.length - 1; i >= 0; i--) {
let row = this.$.model.data[i];
let tot;
if (i != this.$.model.data.length - 1)
row.balance = (row.credit - row.debit) + (this.$.model.data[i + 1].balance);
else
row.balance = row.credit - row.debit;
tot = tot + row.balance;
}
this._risks = this.$.model.data;
}
}
get risks() {
return this._risks;
}
}
Controller.$inject = ['$stateParams'];
Controller.$inject = ['$stateParams', '$translate', '$scope'];
ngModule.component('vnClientRiskIndex', {
template: require('./index.html'),
controller: Controller
controller: Controller,
});

View File

@ -0,0 +1,35 @@
import './index';
describe('Client', () => {
describe('Component vnClientRiskIndex', () => {
let $componentController;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
controller = $componentController('vnClientRiskIndex', {$scope: $scope});
}));
describe('risks() setter', () => {
it('should calculate the balance for each line from the oldest date to the newest', () => {
let risks = [
{credit: 100, debit: 0},
{credit: 100, debit: 0},
{credit: 0, debit: 300}
];
controller.$.model = {data: risks};
controller.risks = risks;
expect(controller.risks[0].balance).toEqual(-100);
expect(controller.risks[1].balance).toEqual(-200);
expect(controller.risks[2].balance).toEqual(-300);
});
});
});
});

View File

@ -0,0 +1,6 @@
vn-client-risk-index {
.totalBox {
display: table;
float: right;
}
}

View File

@ -46,7 +46,7 @@ module.exports = Self => {
FROM vn.receipt r
LEFT JOIN vn.worker w ON w.id = r.workerFk
JOIN vn.company c ON c.id = r.companyFk
WHERE clientFk = ?
WHERE r.clientFk = ? AND r.companyFk = ?
UNION ALL
SELECT
i.id,
@ -63,11 +63,13 @@ module.exports = Self => {
i.clientFk
FROM vn.invoiceOut i
JOIN vn.company c ON c.id = i.companyFk
WHERE clientFk = ?
WHERE i.clientFk = ? AND i.companyFk = ?
) t
ORDER BY payed DESC, created DESC`, [
params.clientFk,
params.clientFk
params.companyFk,
params.clientFk,
params.companyFk,
]
);

View File

@ -1,10 +1,11 @@
const app = require(`${servicesDir}/client/server/server`);
xdescribe('receipt filter()', () => {
describe('receipt filter()', () => {
it('should call the filter method', async () => {
let filter = {limit: 20};
let params = {
clientFk: 101
clientFk: 101,
companyFk: 442
};
let result = await app.models.Receipt.filter(filter, params);