diff --git a/client/client/src/credit-classification-list/credit-classification-list.spec.js b/client/client/src/credit-classification-list/credit-classification-list.spec.js index c233b6dc89..812c420d0d 100644 --- a/client/client/src/credit-classification-list/credit-classification-list.spec.js +++ b/client/client/src/credit-classification-list/credit-classification-list.spec.js @@ -19,7 +19,7 @@ describe('Client', () => { describe('_getClassifications()', () => { it('should perform a GET query to define the classifications property in the controller', () => { let res = ['some classifications']; - let query = '/client/api/CreditClassifications?filter=%7B%22include%22%3A%5B%7B%22relation%22%3A%22creditInsurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D'; + let query = '/client/api/CreditClassifications?filter=%7B%22order%22%3A%22finished%20ASC%2C%20started%20DESC%22%2C%22include%22%3A%5B%7B%22relation%22%3A%22creditInsurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D'; $httpBackend.whenGET(query).respond(res); $httpBackend.expectGET(query); @@ -61,20 +61,15 @@ describe('Client', () => { }); describe('closeContract()', () => { - it('should perform a GET query to set a due date to a contract', () => { - let res = ['pepinillos']; - controller.client = {id: 101}; - let classification = {id: 1}; - let query = '/client/api/CreditClassifications/1'; - spyOn(controller, '_getClassifications'); + it('should define the classificationId property of the controller and then call the show method()', () => { + controller.$scope.closeContract = {show: () => {}}; + spyOn(controller.$scope.closeContract, 'show'); + expect(controller.classificationId).toBeFalsy(); + controller.closeContract({id: 1}); - $httpBackend.whenPATCH(query).respond(res); - $httpBackend.expectPATCH(query); - controller.closeContract(classification); - $httpBackend.flush(); - - expect(controller._getClassifications).toHaveBeenCalledWith(101); - }); + expect(controller.classificationId).toEqual(1); + expect(controller.$scope.closeContract.show).toHaveBeenCalledWith(); + }); }); }); }); diff --git a/client/ticket/src/fetched-tags/fetched-tags.html b/client/ticket/src/fetched-tags/fetched-tags.html index 334f89c093..9402a318d6 100644 --- a/client/ticket/src/fetched-tags/fetched-tags.html +++ b/client/ticket/src/fetched-tags/fetched-tags.html @@ -1,7 +1,7 @@ {{::$ctrl.sale.concept}} - + {{::fetchedTag.tag.name}} {{::fetchedTag.value}} diff --git a/client/ticket/src/package/index/package.spec.js b/client/ticket/src/package/index/package.spec.js index 1ff4442274..50aa0c23e6 100644 --- a/client/ticket/src/package/index/package.spec.js +++ b/client/ticket/src/package/index/package.spec.js @@ -17,7 +17,8 @@ describe('Ticket', () => { $scope = { index: { accept: function() {} - } + }, + form: {} }; controller = $componentController('vnTicketPackageIndex', {$scope: $scope}); })); @@ -33,24 +34,22 @@ describe('Ticket', () => { describe('submit()', () => { it('should perform a post', () => { - spyOn(angular, 'equals').and.returnValue(true); - let query = '/ticket/api/TicketPackagings/crudTicketPackaging'; - controller.removedPackages = []; - controller.oldPackages = [ - {id: 1, packagingFk: 1, quantity: 5, ticketFk: 1} - ]; - controller.packages = [ - {quantity: 5, packagingFk: 2, ticketFk: 1}, - {id: 1, packagingFk: 1, quantity: 25, ticketFk: 1} - ]; + spyOn(controller.$.index, 'accept'); let packagesObj = { delete: controller.removedPackages, create: [], update: [] }; + let query = '/ticket/api/TicketPackagings/crudTicketPackaging'; + controller.removedPackages = []; + controller.oldPackages = []; + controller.oldPackages[1] = {id: 1, packagingFk: 1, quantity: 5, ticketFk: 1}; + controller.packages = [ + {quantity: 5, packagingFk: 2, ticketFk: 1}, + {id: 1, packagingFk: 1, quantity: 25, ticketFk: 1} + ]; - $httpBackend.whenPOST(query, packagesObj).respond('omg YEAH'); - $httpBackend.expectPOST(query, packagesObj); + $httpBackend.expectPOST(query, {delete: [], create: [{quantity: 5, packagingFk: 2, ticketFk: 1}], update: [{id: 1, packagingFk: 1, quantity: 25, ticketFk: 1}]}).respond('ok'); controller.submit(); $httpBackend.flush(); }); diff --git a/client/ticket/src/sale-checked/sale-checked.html b/client/ticket/src/sale-checked/sale-checked.html index 6785f33913..8eb4aecb3c 100644 --- a/client/ticket/src/sale-checked/sale-checked.html +++ b/client/ticket/src/sale-checked/sale-checked.html @@ -17,16 +17,7 @@ {{::sale.itemFk}} - - - {{::sale.concept}} - - - {{::fetchedTag.tag.name}} {{::fetchedTag.value}} - - - - + {{::sale.quantity}} diff --git a/client/ticket/src/volume/ticket-volume.html b/client/ticket/src/volume/ticket-volume.html index 17ee5c9eda..3e9ff00bf4 100644 --- a/client/ticket/src/volume/ticket-volume.html +++ b/client/ticket/src/volume/ticket-volume.html @@ -1,10 +1,30 @@ -
+ + - + Volumes - + + + + + + + + + + + + + + + + + + + + + +
ItemDescriptionQuantitym³ per unitm³ per quantitytotal m³
{{::sale.itemFk}}{{::sale.quantity}}{{::sale.volume.m3_uni}}{{::sale.volume.volumeTimesQuantity}}{{::sale.volume.m3_total}}
+
- - - -
\ No newline at end of file +
diff --git a/client/ticket/src/volume/ticket-volume.js b/client/ticket/src/volume/ticket-volume.js index 2c41ef28e1..b326300e96 100644 --- a/client/ticket/src/volume/ticket-volume.js +++ b/client/ticket/src/volume/ticket-volume.js @@ -1,27 +1,35 @@ import ngModule from '../module'; +import FilterTicketList from '../filter-ticket-list'; -class Controller { - constructor($stateParams, $scope, $http, $translate, vnApp) { - this.params = $stateParams; +class Controller extends FilterTicketList { + constructor($scope, $http, $translate, $timeout, $state) { + super($scope, $timeout, $state); this.$scope = $scope; this.$http = $http; this.$translate = $translate; - this.vnApp = vnApp; + this.onOrder('itemFk', 'ASC'); this.ticketVolumes = []; - this.oldVolumes = {}; - this.removedVolumes = []; } - _getTicketVolumes(ticketFk) { - this.$http.get(`/tcket/api/Volumes/${ticketFk}/getVolumes`) + setVolumes() { + if (!this.$scope.index) return; + + this.$http.get(`/api/tickets/${this.ticket.id}/getVolume`) .then(response => { - this.ticketVolumes = response.data; + if (response.data) { + this.$scope.index.model.instances.forEach(sale => { + response.data.volumes.forEach(volume => { + if (sale.id === volume.saleFk) + sale.volume = volume; + }); + }); + } }); } } -Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp']; +Controller.$inject = ['$scope', '$http', '$translate', '$timeout', '$state']; ngModule.component('vnTicketVolume', { template: require('./ticket-volume.html'), diff --git a/client/ticket/src/volume/ticket-volume.spec.js b/client/ticket/src/volume/ticket-volume.spec.js index 66bff3566b..e69de29bb2 100644 --- a/client/ticket/src/volume/ticket-volume.spec.js +++ b/client/ticket/src/volume/ticket-volume.spec.js @@ -1,143 +0,0 @@ -// import './ticket-observations.js'; - -// describe('ticket', () => { -// describe('Component vnTicketObservations', () => { -// let $componentController; -// let $state; -// let controller; -// let $httpBackend; - -// beforeEach(() => { -// angular.mock.module('ticket'); -// }); - -// beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => { -// $componentController = _$componentController_; -// $state = _$state_; -// $httpBackend = _$httpBackend_; -// controller = $componentController('vnTicketObservations', {$state: $state}); -// })); - -// describe('add / remove observation', () => { -// it('should add one empty observation into controller observations collection and call _setIconAdd()', () => { -// controller.ticketObservations = []; -// spyOn(controller, '_setIconAdd').and.callThrough(); -// controller.addObservation(); - -// expect(controller._setIconAdd).toHaveBeenCalledWith(); -// expect(controller.ticketObservations.length).toEqual(1); -// expect(controller.ticketObservations[0].id).toBe(undefined); -// expect(controller.ticketObservations[0].showAddIcon).toBeTruthy(); -// }); - -// it('should remove an observation that occupies the position in the index given and call _setIconAdd()', () => { -// let index = 2; -// controller.ticketObservations = [ -// {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false}, -// {id: 2, observationTypeFk: 2, description: 'two', showAddIcon: false}, -// {id: 3, observationTypeFk: 3, description: 'three', showAddIcon: true} -// ]; - -// spyOn(controller, '_setIconAdd').and.callThrough(); - -// controller.removeObservation(index); - -// expect(controller._setIconAdd).toHaveBeenCalledWith(); -// expect(controller.ticketObservations.length).toEqual(2); -// expect(controller.ticketObservations[0].showAddIcon).toBeFalsy(); -// expect(controller.ticketObservations[1].showAddIcon).toBeTruthy(); -// expect(controller.ticketObservations[index]).toBe(undefined); -// }); -// }); - -// describe('_equalObservations()', () => { -// it('should return true if two observations are equals independent of control attributes', () => { -// let observationOne = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: true}; -// let observationTwo = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false}; -// let equals = controller._equalObservations(observationOne, observationTwo); - -// expect(equals).toBeTruthy(); -// }); - -// it('should return false if two observations aint equals independent of control attributes', () => { -// let observationOne = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: true}; -// let observationTwo = {id: 1, observationTypeFk: 1, description: 'two', showAddIcon: true}; -// let equals = controller._equalObservations(observationOne, observationTwo); - -// expect(equals).toBeFalsy(); -// }); -// }); - -// describe('get Observations()', () => { -// it('should perform a GET query to receive the ticket observations', () => { -// let res = [{id: 1, observationTypeFk: 1, description: 'one'}]; - -// $httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond(res); -// $httpBackend.expectGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`); -// controller.getObservations(); -// $httpBackend.flush(); -// }); -// }); - -// describe('submit()', () => { -// it("should return an error message 'The observation type must be unique'", () => { -// controller.$scope.form = {}; -// spyOn(controller.vnApp, 'showMessage').and.callThrough(); -// controller.ticketObservations = [ -// {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}, -// {observationTypeFk: 1, description: 'one', itemFk: 1} -// ]; -// controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}}; -// controller.submit(); - -// expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The observation type must be unique'); -// }); - -// it("should perfom a query to delete observations", () => { -// controller.$scope.form = {$setPristine: () => {}}; -// controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}}; -// controller.ticketObservations = []; -// controller.removedObservations = [1]; - -// $httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]); -// $httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!'); -// controller.submit(); -// $httpBackend.flush(); -// }); - -// it("should perfom a query to update observations", () => { -// controller.$scope.form = {$setPristine: () => {}}; -// controller.ticketObservations = [{id: 1, observationTypeFk: 1, description: 'number one!'}]; -// controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}}; - -// $httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]); -// $httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!'); -// controller.submit(); -// $httpBackend.flush(); -// }); - -// it("should perfom a query to create new observation", () => { -// controller.$scope.form = {$setPristine: () => {}}; -// controller.ticketObservations = [{observationTypeFk: 2, description: 'two'}]; - -// $httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]); -// $httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!'); -// controller.submit(); -// $httpBackend.flush(); -// }); - -// it("should return a message 'No changes to save' when there are no changes to apply", () => { -// controller.$scope.form = {$setPristine: () => {}}; -// spyOn(controller.vnApp, 'showMessage').and.callThrough(); -// controller.oldObservations = [ -// {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false}, -// {id: 2, observationTypeFk: 2, description: 'two', showAddIcon: true} -// ]; -// controller.ticketObservations = []; -// controller.submit(); - -// expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save'); -// }); -// }); -// }); -// }); diff --git a/e2e/paths/item-module/04_create_item_tags.spec.js b/e2e/paths/item-module/04_create_item_tags.spec.js index e83725bfaa..ca2dfe2f7c 100644 --- a/e2e/paths/item-module/04_create_item_tags.spec.js +++ b/e2e/paths/item-module/04_create_item_tags.spec.js @@ -50,6 +50,7 @@ describe('create item tags path', () => { .waitToClick(selectors.itemTags.fifthTagSelect) .waitToClick(selectors.itemTags.fifthTagSelectOptionFive) .type(selectors.itemTags.fifthValueInput, 'Thanos') + .clearInput(selectors.itemTags.fifthRelevancyInput) .type(selectors.itemTags.fifthRelevancyInput, '1') .click(selectors.itemTags.submitItemTagsButton) .waitForSnackbar() diff --git a/services/client/common/methods/greuge/specs/sumAmount.spec.js b/services/client/common/methods/greuge/specs/sumAmount.spec.js index 41339702ac..fc84bca981 100644 --- a/services/client/common/methods/greuge/specs/sumAmount.spec.js +++ b/services/client/common/methods/greuge/specs/sumAmount.spec.js @@ -1,19 +1,14 @@ const totalGreuge = require('../sumAmount'); -const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; describe('Greuge totalGreuge()', () => { - it('should call the sumAmount method', done => { + it('should call the sumAmount method', async() => { let clientFk = 1; let self = jasmine.createSpyObj('self', ['remoteMethod', 'rawSql']); self.rawSql.and.returnValue(Promise.resolve([{sumAmount: 6000}])); totalGreuge(self); - let callback = (error, result) => { - if (error) return catchErrors(done)(error); + let result = await self.sumAmount(clientFk); - expect(result).toBe(6000); - done(); - }; - self.sumAmount(clientFk, callback); + expect(result).toBe(6000); }); }); diff --git a/services/db/changes/1.0.2/08-ticketVolume.sql b/services/db/changes/1.0.2/08-ticketVolume.sql new file mode 100644 index 0000000000..ad871f0201 --- /dev/null +++ b/services/db/changes/1.0.2/08-ticketVolume.sql @@ -0,0 +1,28 @@ +USE `vn`; +DROP procedure IF EXISTS `ticketVolume`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticketVolume`(IN vTicketId INT) +BEGIN + DECLARE vWarehouseId INTEGER; + DECLARE vShippedDate DATE; + + DROP TEMPORARY TABLE IF EXISTS ticketVolume; + SELECT warehouseFk, shipped INTO vWarehouseId,vShippedDate FROM vn.ticket WHERE id = vTicketId; + + CREATE TEMPORARY TABLE IF NOT EXISTS ticketVolume ENGINE MEMORY + + SELECT itemFk, saleFk, quantity, concept, VolUd as m3_uni, volume as m3, volume * quantity as volumeTimesQuantity, @m3:= @m3 + ifnull(volume,0) as m3_total + FROM + ( + SELECT round(r.cm3 / 1000000,3) as VolUd ,s.quantity, round(r.cm3 * s.quantity / 1000000,3) as volume, + s.itemFk, s.id AS saleFk, s.concept, @m3:= 0, @vol:=0, t.agencyModeFk + FROM sale s + JOIN vn.ticket t on t.id = s.ticketFk + JOIN bi.rotacion r ON r.Id_Article = s.itemFk AND r.warehouse_id = t.warehouseFk + WHERE s.ticketFk = vTicketId + ) sub; +END$$ + +DELIMITER ; \ No newline at end of file diff --git a/services/item/server/model-config.json b/services/item/server/model-config.json index 779816c199..e3d4fe9ad1 100644 --- a/services/item/server/model-config.json +++ b/services/item/server/model-config.json @@ -8,12 +8,6 @@ "TaxType": { "dataSource": "vn" }, - "ItemTag": { - "dataSource": "vn" - }, - "Tag": { - "dataSource": "vn" - }, "ItemNiche": { "dataSource": "vn" }, diff --git a/services/item/common/methods/item-tag/crudItemTags.js b/services/loopback/common/methods/item-tag/crudItemTags.js similarity index 100% rename from services/item/common/methods/item-tag/crudItemTags.js rename to services/loopback/common/methods/item-tag/crudItemTags.js diff --git a/services/loopback/common/methods/ticket/get-volume.js b/services/loopback/common/methods/ticket/get-volume.js index 9eb5d3943b..9a2f3deecb 100644 --- a/services/loopback/common/methods/ticket/get-volume.js +++ b/services/loopback/common/methods/ticket/get-volume.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('getVolumes', { + Self.remoteMethod('getVolume', { description: 'Returns the volumes of a ticket', accessType: 'READ', accepts: [{ @@ -10,17 +10,20 @@ module.exports = Self => { http: {source: 'path'} }], returns: { - type: 'object' + arg: 'volumes' }, http: { - path: `/:id/getVolumes`, + path: `/:id/getVolume`, verb: 'GET' } }); - Self.getVolumes = async ticketFk => { - let query = `SELECT vn.ticketVolume(?) AS ticketVolumes`; + Self.getVolume = async ticketFk => { + let callMethod = `CALL vn.ticketVolume(?);`; + await Self.rawSql(callMethod, [ticketFk]); + + let query = `SELECT * from vn.ticketVolume;`; let response = await Self.rawSql(query, [ticketFk]); - return response[0]; + return response; }; }; diff --git a/services/loopback/common/methods/ticket/specs/get-volume.spec.js b/services/loopback/common/methods/ticket/specs/get-volume.spec.js index 9998414e9e..c45421e2a9 100644 --- a/services/loopback/common/methods/ticket/specs/get-volume.spec.js +++ b/services/loopback/common/methods/ticket/specs/get-volume.spec.js @@ -1,16 +1,16 @@ -// const getDebt = require('../getDebt'); +const getVolume = require('../get-volume'); -// describe('client getDebt()', () => { -// it('should call the getDebt method', done => { -// let clientFk = 109; -// let self = jasmine.createSpyObj('self', ['remoteMethod', 'rawSql']); -// self.rawSql.and.returnValue(Promise.resolve([{debt: 100}])); -// getDebt(self); -// self.getDebt(clientFk) -// .then(result => { -// expect(result.debt).toEqual(100); -// done(); -// }); -// }); -// }); +describe('client getVolume()', () => { + it('should call the getVolume method', done => { + let ticketFk = 1; + let self = jasmine.createSpyObj('self', ['remoteMethod', 'rawSql']); + self.rawSql.and.returnValue(Promise.resolve([{volumeData: 100}])); + getVolume(self); + self.getVolume(ticketFk) + .then(result => { + expect(result).toEqual([{volumeData: 100}]); + done(); + }); + }); +}); diff --git a/services/item/common/models/item-tag.js b/services/loopback/common/models/item-tag.js similarity index 100% rename from services/item/common/models/item-tag.js rename to services/loopback/common/models/item-tag.js diff --git a/services/item/common/models/item-tag.json b/services/loopback/common/models/item-tag.json similarity index 100% rename from services/item/common/models/item-tag.json rename to services/loopback/common/models/item-tag.json diff --git a/services/item/common/models/tag.json b/services/loopback/common/models/tag.json similarity index 100% rename from services/item/common/models/tag.json rename to services/loopback/common/models/tag.json diff --git a/services/loopback/common/models/ticket.js b/services/loopback/common/models/ticket.js index a9d930903a..6576578950 100644 --- a/services/loopback/common/models/ticket.js +++ b/services/loopback/common/models/ticket.js @@ -1,4 +1,3 @@ - module.exports = function(Self) { require('../methods/ticket/change-time.js')(Self); require('../methods/ticket/change-worker.js')(Self); diff --git a/services/loopback/server/model-config.json b/services/loopback/server/model-config.json index d04d340708..597f45c4b4 100644 --- a/services/loopback/server/model-config.json +++ b/services/loopback/server/model-config.json @@ -72,6 +72,12 @@ "Item": { "dataSource": "vn" }, + "ItemTag": { + "dataSource": "vn" + }, + "Tag": { + "dataSource": "vn" + }, "Origin": { "dataSource": "vn" }, diff --git a/services/ticket/common/methods/sale/filter.js b/services/ticket/common/methods/sale/filter.js index 66d73b6b24..f9b6304f66 100644 --- a/services/ticket/common/methods/sale/filter.js +++ b/services/ticket/common/methods/sale/filter.js @@ -10,15 +10,22 @@ module.exports = Self => { limit: params.size, order: params.order || 'concept ASC', include: [{ - relation: "itemTag", + relation: "item", scope: { - fields: ["id", "value", "priority", "tagFk"], include: { - relation: "tag", + relation: "itemTag", scope: { - fields: ["name"] + fields: ["tagFk", "value"], + include: { + relation: "tag", + scope: { + fields: ["name"] + } + }, + limit: 6 } - } + }, + fields: ["itemFk", "name"] } }, { diff --git a/services/ticket/common/models/sale.json b/services/ticket/common/models/sale.json index f1bf0eab8c..fec1f2dd95 100644 --- a/services/ticket/common/models/sale.json +++ b/services/ticket/common/models/sale.json @@ -41,11 +41,6 @@ "foreignKey": "itemFk", "required": true }, - "itemTag": { - "type": "hasMany", - "model": "ItemTag", - "foreignKey": "itemFk" - }, "ticket": { "type": "belongsTo", "model": "Ticket",