#739 client.riisk
This commit is contained in:
parent
8f7e66dc56
commit
de12bda66b
|
@ -1,13 +1,9 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="/client/api/receipts/filter"
|
url="/client/api/receipts/filter"
|
||||||
params= "{
|
params="$ctrl.params"
|
||||||
params: {
|
|
||||||
clientFk:$ctrl.$stateParams.id
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
limit="20"
|
limit="20"
|
||||||
data="risks">
|
data="$ctrl.risks">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="riskModel"
|
vn-id="riskModel"
|
||||||
|
@ -18,15 +14,29 @@
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-card pad-large>
|
<vn-card pad-large>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-title vn-two>Risk</vn-title>
|
<vn-one>
|
||||||
<div class="totalBox" ng-if="riskTotal.length">
|
<vn-title>Risk</vn-title>
|
||||||
<h6> Total por empresa</h6>
|
</vn-one>
|
||||||
<vn-auto ng-repeat="riskByCompany in riskTotal">
|
<vn-one>
|
||||||
<vn-label-value label={{riskByCompany.company.code}}
|
<vn-autocomplete vn-one
|
||||||
value="{{riskByCompany.amount | currency: ' €': 2}}">
|
field="$ctrl.companyFk"
|
||||||
</vn-label-value>
|
on-change="$ctrl.setOrder(value)"
|
||||||
</vn-auto>
|
url="/client/api/Companies"
|
||||||
</div>
|
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-horizontal>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-table model="model">
|
<vn-table model="model">
|
||||||
|
@ -43,7 +53,7 @@
|
||||||
</vn-tr>
|
</vn-tr>
|
||||||
</vn-thead>
|
</vn-thead>
|
||||||
<vn-tbody>
|
<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.payed | dateTime:'dd/MM/yyyy'}}</vn-td>
|
||||||
<vn-td>{{::risk.created | dateTime:'dd/MM/yyyy HH:mm'}}</vn-td>
|
<vn-td>{{::risk.created | dateTime:'dd/MM/yyyy HH:mm'}}</vn-td>
|
||||||
<vn-td>{{::risk.firstName}} {{::risk.name}}</vn-td>
|
<vn-td>{{::risk.firstName}} {{::risk.name}}</vn-td>
|
||||||
|
@ -51,6 +61,7 @@
|
||||||
<vn-td>{{::risk.bankFk}}</vn-td>
|
<vn-td>{{::risk.bankFk}}</vn-td>
|
||||||
<vn-td>{{::risk.debit | currency: ' €': 2}}</vn-td>
|
<vn-td>{{::risk.debit | currency: ' €': 2}}</vn-td>
|
||||||
<vn-td>{{::risk.credit | currency: ' €': 2}}</vn-td>
|
<vn-td>{{::risk.credit | currency: ' €': 2}}</vn-td>
|
||||||
|
<vn-td>{{risk.balance}}</vn-td>
|
||||||
<vn-td>
|
<vn-td>
|
||||||
<vn-check
|
<vn-check
|
||||||
field="risk.isConciliate"
|
field="risk.isConciliate"
|
||||||
|
|
|
@ -1,25 +1,59 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
|
import './style.scss';
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
constructor($stateParams) {
|
constructor($stateParams, $translate, $scope) {
|
||||||
|
this.$ = $scope;
|
||||||
this.$stateParams = $stateParams;
|
this.$stateParams = $stateParams;
|
||||||
|
this.$translate = $translate;
|
||||||
|
this.companyFk = window.localStorage.defaultCompanyFk;
|
||||||
this.filter = {
|
this.filter = {
|
||||||
include: {
|
include: {
|
||||||
relation: "company",
|
relation: 'company',
|
||||||
scope: {
|
scope: {
|
||||||
fields: ["code"]
|
fields: ['code'],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
where: {
|
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', {
|
ngModule.component('vnClientRiskIndex', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: Controller
|
controller: Controller,
|
||||||
});
|
});
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,6 @@
|
||||||
|
vn-client-risk-index {
|
||||||
|
.totalBox {
|
||||||
|
display: table;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,7 @@ module.exports = Self => {
|
||||||
FROM vn.receipt r
|
FROM vn.receipt r
|
||||||
LEFT JOIN vn.worker w ON w.id = r.workerFk
|
LEFT JOIN vn.worker w ON w.id = r.workerFk
|
||||||
JOIN vn.company c ON c.id = r.companyFk
|
JOIN vn.company c ON c.id = r.companyFk
|
||||||
WHERE clientFk = ?
|
WHERE r.clientFk = ? AND r.companyFk = ?
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
i.id,
|
i.id,
|
||||||
|
@ -63,11 +63,13 @@ module.exports = Self => {
|
||||||
i.clientFk
|
i.clientFk
|
||||||
FROM vn.invoiceOut i
|
FROM vn.invoiceOut i
|
||||||
JOIN vn.company c ON c.id = i.companyFk
|
JOIN vn.company c ON c.id = i.companyFk
|
||||||
WHERE clientFk = ?
|
WHERE i.clientFk = ? AND i.companyFk = ?
|
||||||
) t
|
) t
|
||||||
ORDER BY payed DESC, created DESC`, [
|
ORDER BY payed DESC, created DESC`, [
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
params.clientFk
|
params.companyFk,
|
||||||
|
params.clientFk,
|
||||||
|
params.companyFk,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
const app = require(`${servicesDir}/client/server/server`);
|
const app = require(`${servicesDir}/client/server/server`);
|
||||||
|
|
||||||
xdescribe('receipt filter()', () => {
|
describe('receipt filter()', () => {
|
||||||
it('should call the filter method', async () => {
|
it('should call the filter method', async () => {
|
||||||
let filter = {limit: 20};
|
let filter = {limit: 20};
|
||||||
let params = {
|
let params = {
|
||||||
clientFk: 101
|
clientFk: 101,
|
||||||
|
companyFk: 442
|
||||||
};
|
};
|
||||||
let result = await app.models.Receipt.filter(filter, params);
|
let result = await app.models.Receipt.filter(filter, params);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue