diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f7d5d94f1..5d2eb871d 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1101,11 +1101,11 @@ INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`) (104, 500), (105, 5000); -INSERT INTO `vn`.`supplier`(`id`, `name`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`) +INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`,`isFarmer`,`retAccount`,`commission`, `created`, `postcodeFk`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`) VALUES - (1, 'Plants SL', 4000000001, 1, 'A11111111', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1), - (2, 'Flower King', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2), - (442, 'Verdnatura Levante SL', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2); + (1, 'Plants SL', 'Plants nick', 4000000001, 1, 'A11111111', 0, NULL, 0, CURDATE(), 1111, 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1), + (2, 'Flower King', 'The king', 4000000002, 1, 'B22222222', 0, NULL, 0, CURDATE(), 2222, 1, 'supplier address 2', 'LONDON', 2, 45671, 1, 2), + (442, 'Verdnatura Levante SL', 'Verdnatura', 4000000442, 1, 'C33333333', 0, NULL, 0, CURDATE(), 3333, 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2); INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`) VALUES diff --git a/modules/entry/back/methods/entry/getEntry.js b/modules/entry/back/methods/entry/getEntry.js new file mode 100644 index 000000000..008ee8148 --- /dev/null +++ b/modules/entry/back/methods/entry/getEntry.js @@ -0,0 +1,76 @@ +module.exports = Self => { + Self.remoteMethod('getEntry', { + description: 'Returns an entry', + accessType: 'READ', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'The entry id', + http: {source: 'path'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: `/:id/getEntry`, + verb: 'GET' + } + }); + + Self.getEntry = async id => { + let filter = { + where: {id: id}, + include: [ + { + relation: 'supplier', + scope: { + fields: ['id', 'nickname'] + } + }, + { + relation: 'travel', + scope: { + fields: ['id', 'name', 'shipped', 'landed', 'agencyFk', 'warehouseOutFk', 'warehouseInFk'], + include: [ + { + relation: 'agency', + scope: { + fields: ['name'] + } + }, + { + relation: 'warehouseOut', + scope: { + fields: ['name'] + } + }, + { + relation: 'warehouseIn', + scope: { + fields: ['name'] + } + } + ] + } + }, + { + relation: 'currency', + scope: { + fields: ['id', 'name'] + } + }, + { + relation: 'company', + scope: { + fields: ['id', 'code'] + } + } + ], + }; + + let entry = await Self.app.models.Entry.findOne(filter); + return entry; + }; +}; diff --git a/modules/entry/back/methods/entry/specs/getEntry.spec.js b/modules/entry/back/methods/entry/specs/getEntry.spec.js new file mode 100644 index 000000000..4baf64543 --- /dev/null +++ b/modules/entry/back/methods/entry/specs/getEntry.spec.js @@ -0,0 +1,31 @@ +const app = require('vn-loopback/server/server'); + +describe('travel getEntry()', () => { + const entryId = 1; + it('should check the entry contains the id', async() => { + const entry = await app.models.Entry.getEntry(entryId); + + expect(entry.id).toEqual(1); + }); + + it('should check the entry contains the supplier name', async() => { + const entry = await app.models.Entry.getEntry(entryId); + const supplierName = entry.supplier().nickname; + + expect(supplierName).toEqual('Plants nick'); + }); + + it('should check the entry contains the receiver warehouse name', async() => { + const entry = await app.models.Entry.getEntry(entryId); + const receiverWarehouseName = entry.travel().warehouseIn().name; + + expect(receiverWarehouseName).toEqual('Warehouse One'); + }); + + it('should check the entry contains the company code', async() => { + const entry = await app.models.Entry.getEntry(entryId); + const companyCode = entry.company().code; + + expect(companyCode).toEqual('VNL'); + }); +}); diff --git a/modules/entry/back/models/entry.js b/modules/entry/back/models/entry.js index 4034b7e0a..b1f71b4bd 100644 --- a/modules/entry/back/models/entry.js +++ b/modules/entry/back/models/entry.js @@ -1,4 +1,5 @@ module.exports = Self => { require('../methods/entry/filter')(Self); + require('../methods/entry/getEntry')(Self); }; diff --git a/modules/entry/back/models/entry.json b/modules/entry/back/models/entry.json index a2eef4cd2..c2a7d7c42 100644 --- a/modules/entry/back/models/entry.json +++ b/modules/entry/back/models/entry.json @@ -39,6 +39,9 @@ "commission": { "type": "Number" }, + "isOrdered": { + "type": "Boolean" + }, "created": { "type": "date" }, diff --git a/modules/entry/front/card/index.js b/modules/entry/front/card/index.js index 62fed7db0..83f47c83d 100644 --- a/modules/entry/front/card/index.js +++ b/modules/entry/front/card/index.js @@ -11,11 +11,34 @@ class Controller extends ModuleCard { fields: ['id', 'code'] } }, { - relation: 'travel' + relation: 'travel', + scope: { + fields: ['id', 'landed', 'agencyFk', 'warehouseOutFk'], + include: [ + { + relation: 'agency', + scope: { + fields: ['name'] + } + }, + { + relation: 'warehouseOut', + scope: { + fields: ['name'] + } + }, + { + relation: 'warehouseIn', + scope: { + fields: ['name'] + } + } + ] + } }, { relation: 'supplier', scope: { - fields: ['id', 'name'] + fields: ['id', 'nickname'] } }, { relation: 'currency' @@ -27,7 +50,7 @@ class Controller extends ModuleCard { } } -ngModule.component('vnEntry Card', { +ngModule.component('vnEntryCard', { template: require('./index.html'), controller: Controller }); diff --git a/modules/entry/front/descriptor/index.html b/modules/entry/front/descriptor/index.html index 372479c79..5cb655dc3 100644 --- a/modules/entry/front/descriptor/index.html +++ b/modules/entry/front/descriptor/index.html @@ -13,9 +13,21 @@ - + + + + + + + + + diff --git a/modules/entry/front/descriptor/index.js b/modules/entry/front/descriptor/index.js index a9f5cd679..e3c00f9ad 100644 --- a/modules/entry/front/descriptor/index.js +++ b/modules/entry/front/descriptor/index.js @@ -4,6 +4,48 @@ class Controller { constructor($scope) { this.$ = $scope; } + get entry() { + return this._entry; + } + + set entry(value) { + this._entry = value; + if (!value) return; + + const date = value.travel.landed; + let to = new Date(date); + let from = new Date(date); + to.setDate(to.getDate() + 10); + + to.setHours(0, 0, 0, 0); + + from.setDate(from.getDate() - 10); + from.setHours(0, 0, 0, 0); + + let links = { + btnOne: { + icon: 'local_airport', + state: `travel.index({q: '{"agencyFk": ${value.travel.agencyFk}}'})`, + tooltip: 'All travels with current agency' + }}; + + links.btnTwo = { + icon: 'icon-entry', + state: `entry.index({q: '{"supplierFk": ${value.supplierFk}, "to": "${to}", "from": "${from}"}'})`, + tooltip: 'All entries with current supplier' + }; + + + this._quicklinks = links; + } + + get quicklinks() { + return this._quicklinks; + } + + set quicklinks(value = {}) { + this._quicklinks = Object.assign(value, this._quicklinks); + } } Controller.$inject = ['$scope']; diff --git a/modules/entry/front/descriptor/locale/es.yml b/modules/entry/front/descriptor/locale/es.yml index e5b926f1d..6789a1281 100644 --- a/modules/entry/front/descriptor/locale/es.yml +++ b/modules/entry/front/descriptor/locale/es.yml @@ -1 +1,3 @@ Reference: Referencia +All travels with current agency: Todos los envios con la agencia actual +All entries with current supplier: Todas las entradas con el proveedor actual \ No newline at end of file diff --git a/modules/entry/front/index/index.html b/modules/entry/front/index/index.html index f0f540489..60bbe46d5 100644 --- a/modules/entry/front/index/index.html +++ b/modules/entry/front/index/index.html @@ -16,7 +16,7 @@ - + Id Landed Reference @@ -33,18 +33,18 @@ - + + icon="icon-anonymous"> + icon="icon-net"> {{::entry.id}} diff --git a/modules/entry/front/summary/index.html b/modules/entry/front/summary/index.html index 5397c72ca..771eaaf7a 100644 --- a/modules/entry/front/summary/index.html +++ b/modules/entry/front/summary/index.html @@ -1,140 +1,68 @@ -
{{$ctrl.travelData.id}} - {{$ctrl.travelData.ref}}
+
Entrada #{{$ctrl.entryData.id}} - {{$ctrl.entryData.supplier.nickname}}
- + - + - - - - - + - + - - + + + value="{{$ctrl.entryData.travel.agency.name}}"> - + - + - + + + - -

Entries

- - - - Confirmed - Entry Id - Supplier - Reference - HB - Freight - Package - CC - Pallet - m3 - - - - - - - - - - {{entry.id}} - {{entry.supplierName}} - {{entry.ref}} - {{entry.hb}} - {{entry.freightValue | currency: 'EUR': 2}} - {{entry.packageValue | currency: 'EUR': 2}} - {{entry.cc}} - {{entry.pallet}} - {{entry.m3}} - - - - - - - - - - - - - - - {{$ctrl.total('hb')}} - {{$ctrl.total('freightValue') | currency: 'EUR': 2}} - {{$ctrl.total('packageValue') | currency: 'EUR': 2}} - {{$ctrl.total('cc')}} - {{$ctrl.total('pallet')}} - {{$ctrl.total('m3')}} - - - - -
- -

Thermographs

- - - - Code - Temperature - State - Destination - Created - - - - - {{thermograph.thermographFk}} - {{thermograph.temperature}} - {{thermograph.result}} - {{thermograph.warehouse.name}} - {{thermograph.created | date: 'dd/MM/yyyy'}} - - - -
+ + + + + + + + + + + + + +
- - - - \ No newline at end of file diff --git a/modules/entry/front/summary/index.js b/modules/entry/front/summary/index.js index be17feb29..260715490 100644 --- a/modules/entry/front/summary/index.js +++ b/modules/entry/front/summary/index.js @@ -5,7 +5,6 @@ import Component from 'core/lib/component'; class Controller extends Component { constructor($element, $, $httpParamSerializer) { super($element, $); - this.entries = []; this.$httpParamSerializer = $httpParamSerializer; } @@ -16,33 +15,15 @@ class Controller extends Component { set entry(value) { this._entry = value; - // if (value && value.id) { - // this.getTravel(); - // this.getEntries(); - // this.getThermographs(); - // } + if (value && value.id) + this.getEntry(); } - // getTravel() { - // return this.$http.get(`/api/Travels/${this.travel.id}/getTravel`).then(response => { - // this.travelData = response.data; - // }); - // } - - // getEntries() { - // return this.$http.get(`/api/Travels/${this.travel.id}/getEntries`).then(response => { - // this.entries = response.data; - // }); - // } - - // total(field) { - // let total = 0; - - // for (let entry of this.entries) - // total += entry[field]; - - // return total; - // } + getEntry() { + return this.$http.get(`/api/Entries/${this.entry.id}/getEntry`).then(response => { + this.entryData = response.data; + }); + } } Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; diff --git a/modules/entry/front/summary/index.spec.js b/modules/entry/front/summary/index.spec.js index 5411d8a0d..9a8971b52 100644 --- a/modules/entry/front/summary/index.spec.js +++ b/modules/entry/front/summary/index.spec.js @@ -1,108 +1,48 @@ import './index'; -describe('component vnTravelSummary', () => { +describe('component vnEntrySummary', () => { let controller; let $httpBackend; let $scope; let $element; - let $httpParamSerializer; - beforeEach(angular.mock.module('travel', $translateProvider => { + beforeEach(angular.mock.module('entry', $translateProvider => { $translateProvider.translations('en', {}); })); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); - $element = angular.element(``); - controller = $componentController('vnTravelSummary', {$element, $scope}); + $element = angular.element(``); + controller = $componentController('vnEntrySummary', {$element, $scope}); })); - describe('travel setter/getter', () => { - it('should return the travel', () => { - controller.travel = {id: null}; + describe('entry setter/getter', () => { + it('should return the entry', () => { + controller.entry = {id: 1}; - expect(controller.travel).toEqual(jasmine.any(Object)); + expect(controller.entry).toEqual(jasmine.any(Object)); }); - it('should return the travel and then call both getTravel() and getEntries()', () => { - spyOn(controller, 'getTravel'); - spyOn(controller, 'getEntries'); - spyOn(controller, 'getThermographs'); - controller.travel = {id: 99}; + it('should return the entry and then call getEntry()', () => { + spyOn(controller, 'getEntry'); + controller.entry = {id: 99}; - - expect(controller._travel.id).toEqual(99); - expect(controller.getTravel).toHaveBeenCalledWith(); - expect(controller.getEntries).toHaveBeenCalledWith(); - expect(controller.getThermographs).toHaveBeenCalledWith(); + expect(controller._entry.id).toEqual(99); + expect(controller.getEntry).toHaveBeenCalledWith(); }); }); - describe('getTravel()', () => { + describe('getEntry()', () => { it('should perform a get and then store data on the controller', () => { - controller._travel = {id: 999}; + controller._entry = {id: 999}; - const query = `/api/Travels/${controller._travel.id}/getTravel`; - $httpBackend.expectGET(query).respond('I am the travelData'); - controller.getTravel(); + const query = `/api/Entries/${controller._entry.id}/getEntry`; + $httpBackend.expectGET(query).respond('I am the entryData'); + controller.getEntry(); $httpBackend.flush(); - expect(controller.travelData).toEqual('I am the travelData'); - }); - }); - - describe('getEntries()', () => { - it('should call the getEntries method to get the entries data', () => { - controller._travel = {id: 999}; - - const query = `/api/Travels/${controller._travel.id}/getEntries`; - $httpBackend.expectGET(query).respond('I am the entries'); - controller.getEntries(); - $httpBackend.flush(); - - expect(controller.entries).toEqual('I am the entries'); - }); - }); - - describe('getThermographs()', () => { - it('should call the getThermographs method to get the thermographs', () => { - controller._travel = {id: 2}; - const params = { - filter: { - include: { - relation: 'warehouse', - scope: { - fields: ['id', 'name'] - } - }, - where: { - travelFk: controller._travel.id - } - } - }; - const serializedParams = $httpParamSerializer(params); - const query = `TravelThermographs?${serializedParams}`; - $httpBackend.expectGET(query).respond('I am the thermographs'); - controller.getThermographs(); - $httpBackend.flush(); - - expect(controller.travelThermographs).toEqual('I am the thermographs'); - }); - }); - - describe('total()', () => { - it('should calculate the total amount of a given property for every row', () => { - controller.entries = [ - {id: 1, freightValue: 1, packageValue: 2, cc: 0.01}, - {id: 2, freightValue: 1, packageValue: 2, cc: 0.01}, - {id: 3, freightValue: 1, packageValue: 2, cc: 0.01} - ]; - - expect(controller.total('freightValue')).toEqual(3); - expect(controller.total('packageValue')).toEqual(6); - expect(controller.total('cc')).toEqual(0.03); + expect(controller.entryData).toEqual('I am the entryData'); }); }); }); diff --git a/modules/entry/front/summary/locale/es.yml b/modules/entry/front/summary/locale/es.yml index e69de29bb..528c38830 100644 --- a/modules/entry/front/summary/locale/es.yml +++ b/modules/entry/front/summary/locale/es.yml @@ -0,0 +1,2 @@ +Inventory: Inventario +Virtual: Redada \ No newline at end of file diff --git a/modules/entry/front/summary/style.scss b/modules/entry/front/summary/style.scss index 922b36ad8..8887e15b9 100644 --- a/modules/entry/front/summary/style.scss +++ b/modules/entry/front/summary/style.scss @@ -1,7 +1,7 @@ @import "variables"; -vn-travel-summary .summary { +vn-entry-summary .summary { max-width: $width-lg; vn-icon[icon=insert_drive_file]{