diff --git a/client/client/src/risk/index/index.html b/client/client/src/risk/index/index.html index cc0135599..072ecae37 100644 --- a/client/client/src/risk/index/index.html +++ b/client/client/src/risk/index/index.html @@ -1,13 +1,9 @@ + data="$ctrl.risks"> - Risk - - Total por empresa - - - - - + + Risk + + + + + + + + Total por empresa + + + + + + @@ -43,7 +53,7 @@ - + {{::risk.payed | dateTime:'dd/MM/yyyy'}} {{::risk.created | dateTime:'dd/MM/yyyy HH:mm'}} {{::risk.firstName}} {{::risk.name}} @@ -51,6 +61,7 @@ {{::risk.bankFk}} {{::risk.debit | currency: ' €': 2}} {{::risk.credit | currency: ' €': 2}} + {{risk.balance}} = 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, }); diff --git a/client/client/src/risk/index/index.spec.js b/client/client/src/risk/index/index.spec.js new file mode 100644 index 000000000..86e3ab1d2 --- /dev/null +++ b/client/client/src/risk/index/index.spec.js @@ -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); + }); + }); + }); +}); diff --git a/client/client/src/risk/index/style.scss b/client/client/src/risk/index/style.scss new file mode 100644 index 000000000..a6758e2e6 --- /dev/null +++ b/client/client/src/risk/index/style.scss @@ -0,0 +1,6 @@ +vn-client-risk-index { + .totalBox { + display: table; + float: right; + } +} \ No newline at end of file diff --git a/client/item/src/diary/index.html b/client/item/src/diary/index.html index e69d1904c..f56b89376 100644 --- a/client/item/src/diary/index.html +++ b/client/item/src/diary/index.html @@ -40,7 +40,8 @@ + ng-click="$ctrl.showDescriptor($event, sale)" + class="id"> {{::sale.origin | dashIfEmpty}} diff --git a/client/item/src/diary/index.js b/client/item/src/diary/index.js index 6c42daaf6..b8574fbf0 100644 --- a/client/item/src/diary/index.js +++ b/client/item/src/diary/index.js @@ -34,14 +34,16 @@ class Controller { } set warehouseFk(value) { - this._warehouseFk = value; + if (value && value != this._warehouseFk) { + this._warehouseFk = value; - this.$state.go(this.$state.current.name, { - warehouseFk: value - }); + this.$state.go(this.$state.current.name, { + warehouseFk: value + }); - this.filter.where.warehouseFk = value; - this.$scope.model.refresh(); + this.filter.where.warehouseFk = value; + this.$scope.model.refresh(); + } } get warehouseFk() { @@ -64,7 +66,7 @@ class Controller { get onPreparationLineIndex() { let lines = this.$scope.model.data; - for (let i = this.freeLineIndex; i > 0; i--) { + for (let i = this.freeLineIndex; i >= 0; i--) { let line = lines[i]; let currentDate = new Date(); currentDate.setHours(0, 0, 0); @@ -73,7 +75,7 @@ class Controller { let isPicked = line.alertLevel == 1 && line.isPicked; if ((isPicked) || line.alertLevel > 1 || isPastDate) - return i; + return i + 1; } } @@ -90,32 +92,41 @@ class Controller { scrollToLine() { let body = this.$window.document.body; - - let lineIndex; - if (this.ticketFk) - lineIndex = this.givenTicketIndex; - else - lineIndex = this.onPreparationLineIndex; + let selectedTicketLineIndex = this.givenTicketIndex; + let lineIndex = this.onPreparationLineIndex; let lines = body.querySelector('vn-tbody').children; - if (!lineIndex || !lines.length) return; + if (lineIndex == undefined || !lines.length) return; + let onPreparationLine = lines[lineIndex]; + let balance = onPreparationLine.querySelector('.balanceSpan'); balance.classList.add('counter'); balance.title = this.$translate.instant('Visible quantity'); let headerOffset = body.querySelector('header').getBoundingClientRect(); let headerHeight = headerOffset.height; - let offsetTop = onPreparationLine.offsetTop - headerHeight; + + let offsetTop; + if (this.ticketFk) { + console.log(selectedTicketLineIndex); + let selectedTicketLine = lines[selectedTicketLineIndex]; + let id = selectedTicketLine.querySelector('.id'); + id.classList.add('counter'); + offsetTop = selectedTicketLine.offsetTop - headerHeight; + } else + offsetTop = onPreparationLine.offsetTop - headerHeight; body.querySelector('ui-view').scrollTop = offsetTop; + + this.ticketFk = null; } -/** + /** * Compares a date with the current one * @param {Object} date - Date to compare * @return {Boolean} - Returns true if the two dates equals diff --git a/client/item/src/diary/index.spec.js b/client/item/src/diary/index.spec.js index 3a8e710c9..ba4d6b566 100644 --- a/client/item/src/diary/index.spec.js +++ b/client/item/src/diary/index.spec.js @@ -58,14 +58,14 @@ describe('Item', () => { let currentDate = new Date(); currentDate.setDate(currentDate.getDate() + 1); controller.$scope.model = {data: [ - {name: 'My item 1', alertLevel: 3, isPicked: true, date: '2018-05-02'}, - {name: 'My item 3', alertLevel: 1, isPicked: true, date: '2018-05-03'}, - {name: 'My item 4', alertLevel: 1, isPicked: false, date: '2018-05-03'}, + {name: 'My item 1', alertLevel: 3, isPicked: true, date: currentDate}, + {name: 'My item 3', alertLevel: 1, isPicked: true, date: currentDate}, + {name: 'My item 4', alertLevel: 1, isPicked: false, date: currentDate}, {name: 'My item 5', alertLevel: 0, isPicked: false, date: currentDate}] }; let result = controller.onPreparationLineIndex; - expect(result).toEqual(2); + expect(result).toEqual(1); }); }); diff --git a/client/item/src/diary/style.scss b/client/item/src/diary/style.scss index e19c0690f..91d7367fe 100644 --- a/client/item/src/diary/style.scss +++ b/client/item/src/diary/style.scss @@ -33,5 +33,5 @@ vn-item-diary { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; - } + } } \ No newline at end of file diff --git a/services/client/common/methods/receipt/filter.js b/services/client/common/methods/receipt/filter.js index f63bac66d..d6b03001b 100644 --- a/services/client/common/methods/receipt/filter.js +++ b/services/client/common/methods/receipt/filter.js @@ -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, ] ); diff --git a/services/client/common/methods/receipt/specs/filter.spec.js b/services/client/common/methods/receipt/specs/filter.spec.js index aa48f473d..5691ed089 100644 --- a/services/client/common/methods/receipt/specs/filter.spec.js +++ b/services/client/common/methods/receipt/specs/filter.spec.js @@ -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);