From 79296ac8572f22694f68472897fbb5bf46f0cbc7 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 22 Jun 2021 11:57:43 +0200 Subject: [PATCH 1/2] 2974 - Client balance default company and fixes --- .../client/front/balance/create/index.html | 11 ++++-- modules/client/front/balance/create/index.js | 37 ++++++++++++++++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/modules/client/front/balance/create/index.html b/modules/client/front/balance/create/index.html index 89ec3b049..f975b06ba 100644 --- a/modules/client/front/balance/create/index.html +++ b/modules/client/front/balance/create/index.html @@ -20,9 +20,8 @@ label="Company" show-field="code" value-field="id" - ng-model="$ctrl.receipt.companyFk" - required="true" - rule> + ng-model="$ctrl.companyFk" + required="true"> @@ -78,6 +77,12 @@ on-change="$ctrl.accountShortToStandard(value)"> + + + + diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index 22426a269..95f9d72a8 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -2,9 +2,10 @@ import ngModule from '../../module'; import Dialog from 'core/components/dialog'; class Controller extends Dialog { - constructor($element, $, $transclude) { + constructor($element, $, $transclude, vnReport) { super($element, $, $transclude); + this.vnReport = vnReport; this.receipt = { payed: new Date() }; @@ -31,6 +32,12 @@ class Controller extends Dialog { return this.receipt.clientFk; } + get companyFk() { + if (!this.receipt.companyFk) + this.receipt.companyFk = this.vnConfig.companyFk; + return this.receipt.companyFk; + } + set companyFk(value) { this.receipt.companyFk = value; this.getAmountPaid(); @@ -62,6 +69,22 @@ class Controller extends Dialog { this.amountToReturn = value - this.receipt.amountPaid; } + get amountToReturn() { + return this._amountToReturn; + } + + set amountToReturn(value) { + if (!value) return; + + value = value.toFixed(2); + + if (Number.isInteger(value)) + value = parseInt(value); + else value = parseFloat(value); + + this._amountToReturn = value; + } + get deliveredAmount() { return this._deliveredAmount; } @@ -100,10 +123,20 @@ class Controller extends Dialog { return this.$http.post(`Clients/${this.clientFk}/createReceipt`, this.receipt) .then(() => super.responseHandler(response)) - .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) + .then(() => { + if (this.viewReceipt) { + this.vnReport.show('receipt', { + receiptId: 1, + companyId: 442 + }); + } + }); } } +Controller.$inject = ['$element', '$scope', '$transclude', 'vnReport']; + ngModule.vnComponent('vnClientBalanceCreate', { slotTemplate: require('./index.html'), controller: Controller, From a1b4164b5d09f5b15bbca17783b2503d0303a6ed Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 22 Jun 2021 13:57:32 +0200 Subject: [PATCH 2/2] 2974 - Client balance default company and fixes --- .../client/front/balance/create/index.html | 2 +- modules/client/front/balance/create/index.js | 10 +++++-- .../client/front/balance/create/index.spec.js | 28 +++++++++++++++++++ .../client/front/balance/create/locale/es.yml | 1 + 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 modules/client/front/balance/create/locale/es.yml diff --git a/modules/client/front/balance/create/index.html b/modules/client/front/balance/create/index.html index f975b06ba..81be14382 100644 --- a/modules/client/front/balance/create/index.html +++ b/modules/client/front/balance/create/index.html @@ -77,7 +77,7 @@ on-change="$ctrl.accountShortToStandard(value)"> - + diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index 95f9d72a8..be05983ca 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -121,14 +121,18 @@ class Controller extends Dialog { if (response !== 'accept') return super.responseHandler(response); + let receiptId; return this.$http.post(`Clients/${this.clientFk}/createReceipt`, this.receipt) - .then(() => super.responseHandler(response)) + .then(res => { + receiptId = res.data.id; + super.responseHandler(response); + }) .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) .then(() => { if (this.viewReceipt) { this.vnReport.show('receipt', { - receiptId: 1, - companyId: 442 + receiptId: receiptId, + companyId: this.companyFk }); } }); diff --git a/modules/client/front/balance/create/index.spec.js b/modules/client/front/balance/create/index.spec.js index 90015be19..df3613cad 100644 --- a/modules/client/front/balance/create/index.spec.js +++ b/modules/client/front/balance/create/index.spec.js @@ -40,6 +40,14 @@ describe('Client', () => { }); }); + describe('amountToReturn() setter', () => { + it('should set the amount to return with a maximum of two decimals', () => { + controller.amountToReturn = 200.1451789; + + expect(controller.amountToReturn).toEqual(200.15); + }); + }); + describe('getAmountPaid()', () => { it('should make an http GET query and then set the receipt amountPaid property', () => { controller.$params = {id: 101}; @@ -62,6 +70,7 @@ describe('Client', () => { describe('responseHandler()', () => { it('should make an http POST query and then call to the parent responseHandler() method', () => { jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnReport, 'show'); controller.$params = {id: 101}; @@ -70,6 +79,25 @@ describe('Client', () => { $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.vnReport.show).not.toHaveBeenCalled(); + }); + + it('should make an http POST query and then call to the report show() method', () => { + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnReport, 'show'); + window.open = jest.fn(); + + controller.$params = {id: 101}; + controller.viewReceipt = true; + + $httpBackend.expect('POST', `Clients/101/createReceipt`).respond({id: 1}); + controller.responseHandler('accept'); + $httpBackend.flush(); + + const expectedParams = {receiptId: 1, companyId: 442}; + + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.vnReport.show).toHaveBeenCalledWith('receipt', expectedParams); }); }); diff --git a/modules/client/front/balance/create/locale/es.yml b/modules/client/front/balance/create/locale/es.yml new file mode 100644 index 000000000..266e4365c --- /dev/null +++ b/modules/client/front/balance/create/locale/es.yml @@ -0,0 +1 @@ +View receipt: Ver recibo \ No newline at end of file