From 75d7c79af147c3a46426a299d4223c4dda7948a7 Mon Sep 17 00:00:00 2001 From: Joan Date: Mon, 16 Jul 2018 09:28:32 +0200 Subject: [PATCH] item crud model refactor #372 --- client/item/src/history/index.html | 55 +++++---- client/item/src/history/index.js | 22 +++- client/item/src/last-entries/index.html | 105 ++++++++++-------- client/item/src/last-entries/index.js | 60 ++++------ client/item/src/last-entries/index.spec.js | 71 ------------ .../common/methods/item/getLastEntries.js | 3 +- .../template/payment-update/payment-update.js | 10 +- services/mailer/application/util/format.js | 2 + 8 files changed, 144 insertions(+), 184 deletions(-) delete mode 100644 client/item/src/last-entries/index.spec.js diff --git a/client/item/src/history/index.html b/client/item/src/history/index.html index fe975966de..da07a8e850 100644 --- a/client/item/src/history/index.html +++ b/client/item/src/history/index.html @@ -1,28 +1,41 @@ - + + + Item history - - - - - - - - - {{::itemLog.description}} - {{::itemLog.action}} - {{::itemLog.user.name}} - {{::itemLog.creationDate | date:'dd/MM/yyyy HH:mm'}} - - - No results - + + + + Description + Action + Changed by + Date + + + + + {{::itemLog.description}} + {{::itemLog.action}} + {{::itemLog.user.name}} + {{::itemLog.creationDate | date:'dd/MM/yyyy HH:mm'}} + + + + No results + + + + - diff --git a/client/item/src/history/index.js b/client/item/src/history/index.js index f788bf1da1..910a4f4882 100644 --- a/client/item/src/history/index.js +++ b/client/item/src/history/index.js @@ -1,7 +1,25 @@ import ngModule from '../module'; -import FilterItemList from '../filter-item-list'; + +class Controller { + constructor($stateParams) { + this.$stateParams = $stateParams; + this.filter = { + include: [{ + relation: "item" + }, + { + relation: "user", + scope: { + fields: ["name"] + } + }] + }; + } +} + +Controller.$inject = ['$stateParams']; ngModule.component('vnItemHistory', { template: require('./index.html'), - controller: FilterItemList + controller: Controller }); diff --git a/client/item/src/last-entries/index.html b/client/item/src/last-entries/index.html index cabf821b33..1f427719fb 100644 --- a/client/item/src/last-entries/index.html +++ b/client/item/src/last-entries/index.html @@ -1,3 +1,9 @@ + + @@ -6,62 +12,65 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IgWarehouseLandedEntryP.P.UP.P.PLabelPackingGroupingStemsQuantityCostCubeProvider
+ + + + Ig + Warehouse + Landed + Entry + P.P.U + P.P.P + Label + Packing + Grouping + Stems + Quantity + Cost + Cube + Provider + + + + + - {{entries.warehouse| dashIfEmpty}}{{entries.landed | date:'dd/MM/yyyy HH:mm'}}{{entries.entryFk | dashIfEmpty}}{{entries.price2 | dashIfEmpty}}{{entries.price3 | dashIfEmpty}}{{entries.stickers | dashIfEmpty}} -
{{entries.packing | dashIfEmpty}}
-
-
{{entries.grouping | dashIfEmpty}}
-
{{entries.stems | dashIfEmpty}}{{entries.quantity}}{{entries.buyingValue | dashIfEmpty}}{{entries.packageFk | dashIfEmpty}}{{entries.supplier | dashIfEmpty}}
No results
+ + {{entry.warehouse| dashIfEmpty}} + {{entry.landed | date:'dd/MM/yyyy HH:mm'}} + {{entry.entryFk | dashIfEmpty}} + {{entry.price2 | dashIfEmpty}} + {{entry.price3 | dashIfEmpty}} + {{entry.stickers | dashIfEmpty}} + +
{{entry.packing | dashIfEmpty}}
+
+ + {{entry.grouping | dashIfEmpty}} + + {{entry.stems | dashIfEmpty}} + {{entry.quantity}} + {{entry.buyingValue | dashIfEmpty}} + {{entry.packageFk | dashIfEmpty}} + {{entry.supplier | dashIfEmpty}} + + + + No results + +
+ +
-
diff --git a/client/item/src/last-entries/index.js b/client/item/src/last-entries/index.js index 5fa32e7eb9..3ef89f0862 100644 --- a/client/item/src/last-entries/index.js +++ b/client/item/src/last-entries/index.js @@ -2,50 +2,38 @@ import ngModule from '../module'; import './style.scss'; class Controller { - constructor($scope, $http) { - this.$ = $scope; - this.$http = $http; - this.entries = []; - } + constructor($scope, $stateParams) { + this.$scope = $scope; + this.$stateParams = $stateParams; - set item(value) { - this._item = value; - this._defaultEntriesDate(); - this._getLastEntries(); - } - - get item() { - return this._item; - } - - set entriesDate(value) { - this._entriesDate = value; - this._getLastEntries(); - } - - get entriesDate() { - return this._entriesDate; - } - - _defaultEntriesDate() { - let defaultDate; - defaultDate = new Date(); + let defaultDate = new Date(); defaultDate.setDate(defaultDate.getDate() - 75); defaultDate.setHours(0, 0, 0, 0); - this._entriesDate = defaultDate; + + this.filter = { + where: { + itemFk: $stateParams.id, + date: defaultDate + } + }; + this._date = defaultDate; } - _getLastEntries() { - if (!this.entriesDate || !this.item) - return; - let filter = {itemFk: this.item.id, date: this.entriesDate}; - this.$http.get(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`).then(res => { - this.entries = res.data; - }); + set date(value) { + this._date = value; + + if (!value) return; + + this.filter.where.date = value; + this.$scope.model.refresh(); + } + + get date() { + return this._date; } } -Controller.$inject = ['$scope', '$http']; +Controller.$inject = ['$scope', '$stateParams']; ngModule.component('vnItemLastEntries', { template: require('./index.html'), diff --git a/client/item/src/last-entries/index.spec.js b/client/item/src/last-entries/index.spec.js deleted file mode 100644 index 50e68d4d50..0000000000 --- a/client/item/src/last-entries/index.spec.js +++ /dev/null @@ -1,71 +0,0 @@ -import './index.js'; - -describe('Item', () => { - describe('Component vnItemLastEntries', () => { - let $componentController; - let $scope; - let controller; - let $httpBackend; - let defaultDate; - - beforeEach(() => { - angular.mock.module('item'); - }); - - beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => { - $componentController = _$componentController_; - $httpBackend = _$httpBackend_; - $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); - $scope = $rootScope.$new(); - controller = $componentController('vnItemLastEntries', {$scope: $scope}); - controller.item = {id: 3}; - })); - - describe('set item()', () => { - it(`should set item and call _defaultEntriesDate() and _getLastEntries()`, () => { - spyOn(controller, '_defaultEntriesDate'); - spyOn(controller, '_getLastEntries'); - controller.item = []; - - expect(controller._defaultEntriesDate).toHaveBeenCalledWith(); - expect(controller._getLastEntries).toHaveBeenCalledWith(); - expect(controller.item).toEqual([]); - }); - }); - - describe('set entriesDate()', () => { - it(`should set entriesDate and call _getLastEntries()`, () => { - spyOn(controller, '_getLastEntries'); - controller.item = []; - controller.entriesDate = new Date(); - - expect(controller._getLastEntries).toHaveBeenCalledWith(); - expect(controller.item).toEqual([]); - }); - }); - - describe('_defaultEntriesDate()', () => { - it(`should set entriesDate to a date 75 days ago`, () => { - defaultDate = new Date(); - defaultDate.setDate(defaultDate.getDate() - 75); - defaultDate.setHours(0, 0, 0, 0); - controller._defaultEntriesDate(); - - expect(controller.entriesDate).toEqual(defaultDate); - }); - }); - - describe('_getLastEntries()', () => { - it(`should make a GET if entriesDate and item are defined`, () => { - controller._defaultEntriesDate(); - let filter = {itemFk: controller.item.id, date: controller.entriesDate}; - $httpBackend.whenGET(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`).respond([]); - $httpBackend.expectGET(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`); - controller._getLastEntries(); - $httpBackend.flush(); - // expect(controller.entriesDate).toEqual(defaultDate); - }); - }); - }); -}); - diff --git a/services/loopback/common/methods/item/getLastEntries.js b/services/loopback/common/methods/item/getLastEntries.js index ec414f60f9..bab808cef1 100644 --- a/services/loopback/common/methods/item/getLastEntries.js +++ b/services/loopback/common/methods/item/getLastEntries.js @@ -19,8 +19,9 @@ module.exports = Self => { }); Self.getLastEntries = async filter => { + let where = filter.where; let query = `CALL vn.itemLastEntries(?, ?)`; - let [lastEntries] = await Self.rawSql(query, [filter.itemFk, filter.date]); + let [lastEntries] = await Self.rawSql(query, [where.itemFk, where.date]); return lastEntries; }; }; diff --git a/services/mailer/application/template/payment-update/payment-update.js b/services/mailer/application/template/payment-update/payment-update.js index 565fd8a74b..9d75f20b37 100644 --- a/services/mailer/application/template/payment-update/payment-update.js +++ b/services/mailer/application/template/payment-update/payment-update.js @@ -28,16 +28,16 @@ module.exports = class PaymentUpdate { } get paymentDay() { - if (this.payMethodFk != 5) + if (this.payMethodFk != 5) return `
${this._.paymentDay} ${this.dueDay} ${this._.everyMonth}
`; } get paymentAdvice() { switch (this.payMethodFk) { - case 4: - return `${this._.accountPaymentAdviceBefore} ${format.partialAccountAddress(this.iban)} ${this._.accountPaymentAdviceAfter}`; - case 5: - return this._.cardPaymentAdvice; + case 4: + return `${this._.accountPaymentAdviceBefore} ${format.partialAccountAddress(this.iban)} ${this._.accountPaymentAdviceAfter}`; + case 5: + return this._.cardPaymentAdvice; } } }; diff --git a/services/mailer/application/util/format.js b/services/mailer/application/util/format.js index 681fea72db..52e997a72c 100644 --- a/services/mailer/application/util/format.js +++ b/services/mailer/application/util/format.js @@ -19,6 +19,7 @@ module.exports = { * @return {String} Cuenta bancaria formateada */ accountAddress: function(addressNumber) { + if (!addressNumber) return; var formattedAccountAddress = addressNumber.replace(/(.{4})/g, '$1-'); return formattedAccountAddress.substring(0, formattedAccountAddress.length - 1); }, @@ -29,6 +30,7 @@ module.exports = { * @return {String} Cuenta bancaria formateada */ partialAccountAddress: function(addressNumber) { + if (!addressNumber) return; let address = this.accountAddress(addressNumber); return address.substring(0, 19).replace(/[0-9]/g, 'X') + address.substring(19, 24); },