diff --git a/front/salix/styles/misc.scss b/front/salix/styles/misc.scss index 68f89fbc6..4997cac05 100644 --- a/front/salix/styles/misc.scss +++ b/front/salix/styles/misc.scss @@ -25,6 +25,7 @@ input[type=reset]::-moz-focus-inner { a, .link { color: $color-font-link; text-decoration: none; + outline: 0 } .link { cursor: pointer; diff --git a/modules/client/back/methods/receipt/filter.js b/modules/client/back/methods/receipt/filter.js index aa60e8235..4de7e72f8 100644 --- a/modules/client/back/methods/receipt/filter.js +++ b/modules/client/back/methods/receipt/filter.js @@ -36,13 +36,15 @@ module.exports = Self => { r.payed, c.code company, r.created, - NULL ref, + r.invoiceFk ref, NULL debit, r.amountPaid credit, r.bankFk, u.nickname userNickname, + u.id userId, r.clientFk, - FALSE pdf + FALSE pdf, + FALSE isInvoice FROM vn.receipt r LEFT JOIN vn.worker w ON w.id = r.workerFk LEFT JOIN account.user u ON u.id = w.userFk @@ -60,11 +62,14 @@ module.exports = Self => { NULL, NULL, NULL, + NULL, i.clientFk, - i.pdf + i.pdf, + TRUE isInvoice FROM vn.invoiceOut i JOIN vn.company c ON c.id = i.companyFk WHERE i.clientFk = ? AND i.companyFk = ? + ORDER BY payed DESC, created DESC ) t ORDER BY payed DESC, created DESC`, [ params.clientFk, diff --git a/modules/client/back/methods/receipt/specs/filter.spec.js b/modules/client/back/methods/receipt/specs/filter.spec.js index b0422bb28..5e8ccd807 100644 --- a/modules/client/back/methods/receipt/specs/filter.spec.js +++ b/modules/client/back/methods/receipt/specs/filter.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('receipt filter()', () => { - it('should call the filter method', async () => { + it('should return the receipts', async() => { let filter = {limit: 20}; let params = { clientFk: 101, diff --git a/modules/client/front/risk/index/index.html b/modules/client/front/risk/index/index.html index 97bb26666..4d40582dc 100644 --- a/modules/client/front/risk/index/index.html +++ b/modules/client/front/risk/index/index.html @@ -3,15 +3,13 @@ url="/client/api/receipts/filter" params="$ctrl.params" limit="20" - data="$ctrl.risks" - auto-load="true"> + data="$ctrl.balances"> + data="$ctrl.riskTotal"> @@ -20,6 +18,7 @@ -
+
Total by company
- + @@ -44,7 +43,7 @@ - Date + Date Creation date Employee Reference @@ -57,27 +56,37 @@ - - {{::risk.payed | dateTime:'dd/MM/yyyy'}} - {{::risk.created | dateTime:'dd/MM/yyyy HH:mm'}} - {{::risk.userNickname}} + + {{::balance.payed | dateTime:'dd/MM/yyyy'}} + {{::balance.created | dateTime:'dd/MM/yyyy HH:mm'}} - BILL {{::risk.ref}} + + {{::balance.userNickname}} + - {{::risk.bankFk}} - {{::risk.debit | currency: 'EUR':2}} - {{::risk.credit | currency: 'EUR':2}} - {{risk.balance | currency: 'EUR':2}} + + {{balance.isInvoice ? 'BILL' : balance.ref | translate: {ref: balance.ref} }} + + + {{::balance.bankFk}} + {{::balance.debit | currency: 'EUR':2}} + {{::balance.credit | currency: 'EUR':2}} + {{balance.balance | currency: 'EUR':2}} - + href="api/InvoiceOuts/{{::balance.id}}/download?access_token={{::$ctrl.accessToken}}"> @@ -103,4 +112,14 @@ - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/modules/client/front/risk/index/index.js b/modules/client/front/risk/index/index.js index 6feea8b96..f01e8f776 100644 --- a/modules/client/front/risk/index/index.js +++ b/modules/client/front/risk/index/index.js @@ -2,7 +2,8 @@ import ngModule from '../../module'; import './style.scss'; class Controller { - constructor($stateParams, $translate, $scope, vnToken) { + constructor($stateParams, $translate, $scope, vnToken, $http) { + this.$http = $http; this.$ = $scope; this.$stateParams = $stateParams; this.$translate = $translate; @@ -38,26 +39,46 @@ class Controller { this.$.riskModel.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; + set balances(value) { + this._balances = value; - tot = tot + row.balance; + if (!value) return; + const params = {filter: this.filter}; + this.$http.get(`/client/api/ClientRisks`, {params}).then(response => { + if (response.data) { + this.riskTotal = response.data; + + this.getBalances(); } - this._risks = this.$.model.data; - } + }); } - get risks() { - return this._risks; + get balances() { + return this._balances; } + getCurrentBalance() { + const selectedCompany = this.$.company.selection; + const currentBalance = this.riskTotal.find(balance => { + 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); + } + }); + } + + openCreateDialog() { this.$.riskCreateDialog.companyFk = this.companyFk; this.$.riskCreateDialog.onResponse = () => { @@ -69,9 +90,32 @@ class Controller { onDownload() { alert('Not implemented yet'); } + + showWorkerDescriptor(event, userId) { + if (event.defaultPrevented) return; + + event.preventDefault(); + event.stopPropagation(); + + this.selectedWorker = userId; + 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(); + } } -Controller.$inject = ['$stateParams', '$translate', '$scope', 'vnToken']; +Controller.$inject = ['$stateParams', '$translate', '$scope', 'vnToken', '$http']; ngModule.component('vnClientRiskIndex', { template: require('./index.html'), diff --git a/modules/client/front/risk/index/index.spec.js b/modules/client/front/risk/index/index.spec.js index 77f00c5e8..1db4a7a8b 100644 --- a/modules/client/front/risk/index/index.spec.js +++ b/modules/client/front/risk/index/index.spec.js @@ -4,29 +4,40 @@ describe('Client', () => { describe('Component vnClientRiskIndex', () => { let $componentController; let $scope; + let $httpBackend; + let $httpParamSerializer; let controller; beforeEach(ngModule('client')); - beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); controller = $componentController('vnClientRiskIndex', {$scope}); })); - describe('risks() setter', () => { + describe('balances() setter', () => { it('should calculate the balance for each line from the oldest date to the newest', () => { - let risks = [ + controller.getCurrentBalance = jasmine.createSpy(controller, 'getCurrentBalance').and.returnValue(1000); + let balances = [ + {credit: -100, debit: 0}, + {credit: 0, debit: 300}, {credit: 100, debit: 0}, - {credit: 100, debit: 0}, - {credit: 0, debit: 300} + {credit: 0, debit: -300} ]; - controller.$.model = {data: risks}; - controller.risks = risks; + const params = {filter: controller.filter}; + let serializedParams = $httpParamSerializer(params); + $httpBackend.when('GET', `/client/api/ClientRisks?${serializedParams}`).respond(balances); + $httpBackend.expect('GET', `/client/api/ClientRisks?${serializedParams}`); + controller.balances = balances; + $httpBackend.flush(); - expect(controller.risks[0].balance).toEqual(-100); - expect(controller.risks[1].balance).toEqual(-200); - expect(controller.risks[2].balance).toEqual(-300); + expect(controller.balances[0].balance).toEqual(1000); + expect(controller.balances[1].balance).toEqual(900); + expect(controller.balances[2].balance).toEqual(600); + expect(controller.balances[3].balance).toEqual(700); }); }); }); diff --git a/modules/client/front/risk/index/locale/es.yml b/modules/client/front/risk/index/locale/es.yml index fc9f1c931..05ef7070a 100644 --- a/modules/client/front/risk/index/locale/es.yml +++ b/modules/client/front/risk/index/locale/es.yml @@ -8,4 +8,4 @@ Havings: Haber Balance: Balance Total by company: Total por empresa Download PDF: Descargar PDF -BILL: N/FRA \ No newline at end of file +BILL: N/FRA {{ref}} \ No newline at end of file diff --git a/modules/client/front/routes.json b/modules/client/front/routes.json index 457f75f0b..b000c2d3d 100644 --- a/modules/client/front/routes.json +++ b/modules/client/front/routes.json @@ -3,7 +3,7 @@ "name": "Clients", "icon": "icon-person", "validations" : true, - "dependencies": ["worker"], + "dependencies": ["worker", "invoiceOut"], "menu": [ {"state": "client.card.basicData", "icon": "settings"}, {"state": "client.card.fiscalData", "icon": "account_balance"}, diff --git a/modules/invoiceOut/front/descriptor-popover/index.html b/modules/invoiceOut/front/descriptor-popover/index.html new file mode 100644 index 000000000..c4234535c --- /dev/null +++ b/modules/invoiceOut/front/descriptor-popover/index.html @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor-popover/index.js b/modules/invoiceOut/front/descriptor-popover/index.js new file mode 100644 index 000000000..be55303ad --- /dev/null +++ b/modules/invoiceOut/front/descriptor-popover/index.js @@ -0,0 +1,72 @@ +import ngModule from '../module'; +import Component from 'core/lib/component'; +import './style.scss'; + +class Controller extends Component { + constructor($element, $scope, $http, $timeout, $q) { + super($element, $scope); + this.$timeout = $timeout; + this.$http = $http; + this.$q = $q; + this.worker = null; + } + + set invoiceOutId(id) { + if (id == this._invoiceOutId) return; + + this._invoiceOutId = id; + this.invoiceOut = null; + this.loadData(); + } + + get invoiceOutId() { + return this._invoiceOutId; + } + + set quicklinks(value = {}) { + this._quicklinks = Object.assign(value, this._quicklinks); + } + + get quicklinks() { + return this._quicklinks; + } + + show() { + this.$.popover.parent = this.parent; + this.$.popover.show(); + } + + loadData() { + let query = `api/InvoiceOuts/findOne`; + let filter = { + where: { + id: this._invoiceOutId + }, + include: [ + { + relation: 'company', + scope: { + fields: ['id', 'code'] + } + } + ] + }; + + this.$http.get(query, {params: {filter}}).then(res => { + this.invoiceOut = res.data; + this.$.$applyAsync(() => { + this.$.popover.relocate(); + }); + }); + } +} +Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q']; + +ngModule.component('vnInvoiceOutDescriptorPopover', { + template: require('./index.html'), + controller: Controller, + bindings: { + invoiceOutId: '<', + quicklinks: '<' + } +}); diff --git a/modules/invoiceOut/front/descriptor-popover/style.scss b/modules/invoiceOut/front/descriptor-popover/style.scss new file mode 100644 index 000000000..58e65d320 --- /dev/null +++ b/modules/invoiceOut/front/descriptor-popover/style.scss @@ -0,0 +1,11 @@ +vn-ticket-descriptor-popover { + vn-ticket-descriptor { + display: block; + width: 16em; + max-height: 28em; + + & > vn-card { + margin: 0!important; + } + } +} \ No newline at end of file diff --git a/modules/invoiceOut/front/index.js b/modules/invoiceOut/front/index.js index e037f3d21..239bfd812 100644 --- a/modules/invoiceOut/front/index.js +++ b/modules/invoiceOut/front/index.js @@ -5,3 +5,4 @@ import './search-panel'; import './summary'; import './card'; import './descriptor'; +import './descriptor-popover';