diff --git a/db/changes/10080-september/00-zoneGetLanded.sql b/db/changes/10080-september/00-zoneGetLanded.sql
new file mode 100644
index 000000000..5a50a6171
--- /dev/null
+++ b/db/changes/10080-september/00-zoneGetLanded.sql
@@ -0,0 +1,47 @@
+DROP procedure IF EXISTS `vn`.`zoneGetLanded`;
+
+DELIMITER $$
+CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zoneGetLanded`(vShipped DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT)
+BEGIN
+/**
+* Devuelve una tabla temporal con el dia de recepcion para vShipped.
+*
+* @param vShipped Fecha de preparacion de mercancia
+* @param vAddressFk Id de consignatario, %NULL para recogida
+* @param vAgencyModeFk Id agencia
+* @table tmp.zoneGetLanded Datos de recepción
+*/
+ DECLARE vPostalCode varchar(10);
+
+ SELECT postalCode INTO vPostalCode
+ FROM address WHERE id = vAddressFk;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded;
+ CREATE TEMPORARY TABLE tmp.zoneGetLanded
+ ENGINE = MEMORY
+ SELECT
+ id zoneFk,
+ vShipped shipped,
+ delivered landed,
+ vWarehouseFk warehouseFk,
+ agencyModeFk,
+ isIncluded
+ FROM (
+ SELECT zi.isIncluded, zc.delivered, z.id, z.agencyModeFk
+ FROM vn.zoneGeo zgSon
+ JOIN vn.zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt
+ JOIN zoneIncluded zi ON zi.geoFk = zgFather.id
+ JOIN zone z ON z.id = zi.zoneFk
+ JOIN zoneCalendar zc ON zc.zoneFk = z.id
+ WHERE zgSon.`name` LIKE vPostalCode
+ AND zc.delivered = TIMESTAMPADD(DAY,z.travelingDays, vShipped)
+ AND IF(vShipped = CURDATE(), hour(now()) < hour(z.`hour`),TRUE)
+ AND z.agencyModeFk = vAgencyModeFk
+ AND z.warehouseFk = vWarehouseFk
+ ORDER BY zgFather.depth DESC) t
+ GROUP BY zoneFk
+ HAVING isIncluded > 0
+ LIMIT 1;
+END$$
+
+DELIMITER ;
diff --git a/db/changes/10080-september/00-zoneGetShipped.sql b/db/changes/10080-september/00-zoneGetShipped.sql
new file mode 100644
index 000000000..e44435797
--- /dev/null
+++ b/db/changes/10080-september/00-zoneGetShipped.sql
@@ -0,0 +1,47 @@
+DROP procedure IF EXISTS `vn`.`zoneGetShipped`;
+
+DELIMITER $$
+CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zoneGetShipped`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT)
+BEGIN
+/**
+ * Devuelve la mínima fecha de envía para cada warehouse
+ *
+ * @param vLanded La fecha de recepcion
+ * @param vAddressFk Id del consignatario
+ * @param vAgencyModeFk Id de la agencia
+ * @return tmp.zoneGetShipped
+ */
+
+ DECLARE vPostalCode varchar(10);
+
+ SELECT postalCode INTO vPostalCode
+ FROM address WHERE id = vAddressFk;
+
+ SELECT * FROM (
+ SELECT * FROM (
+ SELECT z.id zoneFk,
+ TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped,
+ vLanded landed,
+ vWarehouseFk warehouseFk,
+ z.agencyModeFk,
+ zi.isIncluded
+ FROM zoneGeo zgSon
+ JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt
+ JOIN zoneIncluded zi ON zi.geoFk = zgFather.id
+ JOIN zone z ON z.id = zi.zoneFk
+ JOIN zoneCalendar zc ON zc.zoneFk = z.id
+ WHERE zgSon.`name` LIKE vPostalCode
+ AND zc.delivered = vLanded
+ AND z.agencyModeFk = vAgencyModeFk
+ AND z.warehouseFk = vWarehouseFk
+ AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE)
+ ORDER BY z.id, zgFather.depth DESC, isIncluded DESC) t
+ GROUP BY zoneFk
+ HAVING isIncluded > 0
+ ORDER BY shipped)
+ t
+ GROUP BY agencyModeFk;
+END$$
+
+DELIMITER ;
+
diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js
index e20727d72..d9af2f6a1 100644
--- a/modules/ticket/back/methods/ticket/componentUpdate.js
+++ b/modules/ticket/back/methods/ticket/componentUpdate.js
@@ -91,9 +91,9 @@ module.exports = Self => {
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
if (!isProductionBoss) {
- const zone = await models.Agency.getShipped(landed, addressId, agencyModeId, warehouseId);
+ const zoneShipped = await models.Agency.getShipped(landed, addressId, agencyModeId, warehouseId);
- if (zone.id != zoneId)
+ if (!zoneShipped || zoneShipped.zoneFk != zoneId)
throw new UserError(`You don't have privileges to change the zone`);
}
diff --git a/modules/ticket/back/methods/ticket/priceDifference.js b/modules/ticket/back/methods/ticket/priceDifference.js
index f881a6c08..a303412fe 100644
--- a/modules/ticket/back/methods/ticket/priceDifference.js
+++ b/modules/ticket/back/methods/ticket/priceDifference.js
@@ -61,9 +61,9 @@ module.exports = Self => {
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss');
if (!isProductionBoss) {
- const zone = await models.Agency.getShipped(landed, addressId, agencyModeId, warehouseId);
+ const zoneShipped = await models.Agency.getShipped(landed, addressId, agencyModeId, warehouseId);
- if (!zone || zone.id != zoneId)
+ if (!zoneShipped || zoneShipped.zoneFk != zoneId)
throw new UserError(`You don't have privileges to change the zone`);
}
@@ -86,6 +86,7 @@ module.exports = Self => {
const map = new Map();
+ // Sale price component, one per sale
difComponents.forEach(difComponent => {
map.set(difComponent.saleFk, difComponent);
});
diff --git a/modules/ticket/front/basic-data/step-one/index.js b/modules/ticket/front/basic-data/step-one/index.js
index 379fc7148..862a7a315 100644
--- a/modules/ticket/front/basic-data/step-one/index.js
+++ b/modules/ticket/front/basic-data/step-one/index.js
@@ -46,10 +46,15 @@ class Controller {
return null;
}
- set warehouseId(id) {
- if (id != this.ticket.warehouseFk) {
- this.ticket.warehouseFk = id;
- this.onChangeWarehouse(id);
+ set warehouseId(value) {
+ if (value != this.ticket.warehouseFk) {
+ this.ticket.warehouseFk = value;
+ this.getShipped({
+ landed: this.ticket.landed,
+ addressFk: this.ticket.addressFk,
+ agencyModeFk: this.ticket.agencyModeFk,
+ warehouseFk: value
+ });
}
}
@@ -63,7 +68,12 @@ class Controller {
set shipped(value) {
this.ticket.shipped = value;
- this.onChangeShipped(value);
+ this.getLanded({
+ shipped: value,
+ addressFk: this.ticket.addressFk,
+ agencyModeFk: this.ticket.agencyModeFk,
+ warehouseFk: this.ticket.warehouseFk
+ });
}
get landed() {
@@ -75,7 +85,12 @@ class Controller {
set landed(value) {
this.ticket.landed = value;
- this.onChangeLanded(value);
+ this.getShipped({
+ landed: value,
+ addressFk: this.ticket.addressFk,
+ agencyModeFk: this.ticket.agencyModeFk,
+ warehouseFk: this.ticket.warehouseFk
+ });
}
get agencyModeId() {
@@ -85,10 +100,15 @@ class Controller {
return null;
}
- set agencyModeId(id) {
- if (id != this.ticket.agencyModeFk) {
- this.ticket.agencyModeFk = id;
- this.onChangeAgencyMode(id);
+ set agencyModeId(value) {
+ if (value != this.ticket.agencyModeFk) {
+ this.ticket.agencyModeFk = value;
+ this.getShipped({
+ landed: this.ticket.landed,
+ addressFk: this.ticket.addressFk,
+ agencyModeFk: value,
+ warehouseFk: this.ticket.warehouseFk
+ });
}
}
@@ -99,10 +119,10 @@ class Controller {
return null;
}
- set zoneId(id) {
- if (id != this.ticket.zoneFk) {
- this.ticket.zoneFk = id;
- this.onChangeZone(id);
+ set zoneId(value) {
+ if (value != this.ticket.zoneFk) {
+ this.ticket.zoneFk = value;
+ this.onChangeZone(value);
}
}
@@ -135,50 +155,6 @@ class Controller {
});
}
- onChangeShipped(shipped) {
- let params = {
- shipped: shipped,
- addressFk: this.ticket.addressFk,
- agencyModeFk: this.ticket.agencyModeFk,
- warehouseFk: this.ticket.warehouseFk
- };
- this.ticket.zoneFk = null;
-
- let query = `/api/Agencies/getLanded`;
- this.$http.get(query, {params}).then(res => {
- if (res.data && res.data.landed) {
- this.ticket.zoneFk = res.data.zoneFk;
- this.ticket.landed = res.data.landed;
- } else {
- return this.vnApp.showError(
- this.$translate.instant(`No delivery zone available for this shipping date`)
- );
- }
- });
- }
-
- onChangeLanded(landed) {
- let params = {
- landed: landed,
- addressFk: this.ticket.addressFk,
- agencyModeFk: this.ticket.agencyModeFk,
- warehouseFk: this.ticket.warehouseFk
- };
- this.ticket.zoneFk = null;
-
- let query = `/api/Agencies/getShipped`;
- this.$http.get(query, {params}).then(res => {
- if (res.data) {
- this.ticket.zoneFk = res.data.id;
- this.ticket.shipped = res.data.shipped;
- } else {
- return this.vnApp.showError(
- this.$translate.instant(`No delivery zone available for this landing date`)
- );
- }
- });
- }
-
/*
* Gets an agency from an specified zone
*/
@@ -193,56 +169,6 @@ class Controller {
});
}
- /*
- * Gets a zone from an agency
- */
- onChangeAgencyMode(agencyModeId) {
- let params = {
- landed: this.ticket.landed,
- addressFk: this.ticket.addressFk,
- agencyModeFk: agencyModeId,
- warehouseFk: this.ticket.warehouseFk
- };
-
- this.ticket.zoneFk = null;
- let query = `/api/Agencies/getShipped`;
- this.$http.get(query, {params}).then(res => {
- if (res.data)
- this.ticket.zoneFk = res.data.id;
-
- if (!res.data) {
- this.vnApp.showMessage(
- this.$translate.instant('No delivery zone available for this parameters')
- );
- }
- });
- }
-
- /*
- * Gets a zone from an agency
- */
- onChangeWarehouse(warehouseId) {
- let params = {
- landed: this.ticket.landed,
- addressFk: this.ticket.addressFk,
- agencyModeFk: this.ticket.agencyModeFk,
- warehouseFk: warehouseId
- };
-
- this.ticket.zoneFk = null;
- let query = `/api/Agencies/getShipped`;
- this.$http.get(query, {params}).then(res => {
- if (res.data)
- this.ticket.zoneFk = res.data.id;
-
- if (!res.data) {
- this.vnApp.showMessage(
- this.$translate.instant('No delivery zone available for this parameters')
- );
- }
- });
- }
-
async onStepChange() {
if (this.isFormInvalid()) {
return this.vnApp.showError(
@@ -275,16 +201,40 @@ class Controller {
* Returns a landing date
*/
getLanded(params) {
- let query = `/api/Agencies/getLanded`;
- return this.$http.get(query, {params});
+ this.ticket.zoneFk = null;
+ const query = `/api/Agencies/getLanded`;
+ this.$http.get(query, {params}).then(res => {
+ if (res.data) {
+ this.ticket.zoneFk = res.data.zoneFk;
+ this.ticket.landed = res.data.landed;
+ this.ticket.agencyModeFk = res.data.agencyModeFk;
+ this.ticket.warehouseFk = res.data.warehouseFk;
+ } else {
+ return this.vnApp.showError(
+ this.$translate.instant(`No delivery zone available for this landing date`)
+ );
+ }
+ });
}
/*
* Returns a shipment date
*/
getShipped(params) {
- let query = `/api/Agencies/getShipped`;
- return this.$http.get(query, {params});
+ this.ticket.zoneFk = null;
+ const query = `/api/Agencies/getShipped`;
+ this.$http.get(query, {params}).then(res => {
+ if (res.data) {
+ this.ticket.zoneFk = res.data.zoneFk;
+ this.ticket.shipped = res.data.shipped;
+ this.ticket.agencyModeFk = res.data.agencyModeFk;
+ this.ticket.warehouseFk = res.data.warehouseFk;
+ } else {
+ return this.vnApp.showError(
+ this.$translate.instant(`No delivery zone available for this landing date`)
+ );
+ }
+ });
}
isFormInvalid() {
diff --git a/modules/ticket/front/basic-data/step-one/index.spec.js b/modules/ticket/front/basic-data/step-one/index.spec.js
index 0a02acfd9..1ebce7bf1 100644
--- a/modules/ticket/front/basic-data/step-one/index.spec.js
+++ b/modules/ticket/front/basic-data/step-one/index.spec.js
@@ -5,16 +5,18 @@ describe('Ticket', () => {
let $state;
let controller;
let $httpBackend;
- let $httpParamSerializer;
-
beforeEach(ngModule('ticket'));
- beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
+ beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
$state = _$state_;
$httpBackend = _$httpBackend_;
- $httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnTicketBasicDataStepOne', {$state});
+ controller.ticket = {
+ addressFk: 121,
+ agencyModeFk: 7,
+ warehouseFk: 1
+ };
}));
describe('ticket() setter', () => {
@@ -44,44 +46,70 @@ describe('Ticket', () => {
});
describe('shipped() setter', () => {
- it('should set shipped property and call onChangeShipped() method ', () => {
- let shipped = new Date();
- spyOn(controller, 'onChangeShipped');
- controller.ticket = {id: 1};
+ it('should set shipped property and call getLanded() method ', () => {
+ spyOn(controller, 'getLanded');
+ const shipped = new Date();
+ const spectedResult = {
+ shipped: shipped,
+ addressFk: 121,
+ agencyModeFk: 7,
+ warehouseFk: 1
+ };
controller.shipped = shipped;
- expect(controller.onChangeShipped).toHaveBeenCalledWith(shipped);
+
+ expect(controller.getLanded).toHaveBeenCalledWith(spectedResult);
});
});
describe('landed() setter', () => {
- it('should set landed property and call onChangeLanded() method ', () => {
- let landed = new Date();
- spyOn(controller, 'onChangeLanded');
- controller.ticket = {id: 1};
+ it('should set shipped property and call getShipped() method ', () => {
+ spyOn(controller, 'getShipped');
+ const landed = new Date();
+ const spectedResult = {
+ landed: landed,
+ addressFk: 121,
+ agencyModeFk: 7,
+ warehouseFk: 1
+ };
controller.landed = landed;
- expect(controller.onChangeLanded).toHaveBeenCalledWith(landed);
+
+ expect(controller.getShipped).toHaveBeenCalledWith(spectedResult);
});
});
describe('agencyModeId() setter', () => {
it('should set agencyModeId property and call onChangeAgencyMode() method', () => {
+ spyOn(controller, 'getShipped');
+ const landed = new Date();
const agencyModeId = 8;
- spyOn(controller, 'onChangeAgencyMode');
- controller.ticket = {id: 1};
+ const spectedResult = {
+ landed: landed,
+ addressFk: 121,
+ agencyModeFk: agencyModeId,
+ warehouseFk: 1
+ };
+ controller.ticket.landed = landed;
controller.agencyModeId = 8;
- expect(controller.onChangeAgencyMode).toHaveBeenCalledWith(agencyModeId);
+ expect(controller.getShipped).toHaveBeenCalledWith(spectedResult);
});
it('should do nothing if attempting to set the same agencyMode id', () => {
- spyOn(controller, 'onChangeAgencyMode');
- const agencyModeId = 8;
- controller.ticket = {agencyModeFk: agencyModeId};
- controller.agencyModeId = agencyModeId;
+ spyOn(controller, 'getShipped');
+ const landed = new Date();
+ const agencyModeId = 7;
+ const spectedResult = {
+ landed: landed,
+ addressFk: 121,
+ agencyModeFk: agencyModeId,
+ warehouseFk: 1
+ };
+ controller.ticket.landed = landed;
+ controller.agencyModeId = 7;
- expect(controller.onChangeAgencyMode).not.toHaveBeenCalledWith();
+ expect(controller.getShipped).not.toHaveBeenCalledWith(spectedResult);
});
});
@@ -134,59 +162,6 @@ describe('Ticket', () => {
});
});
- describe('onChangeShipped()', () => {
- it('should return an available landing date', async() => {
- let shipped = new Date();
-
- controller._ticket = {
- id: 1,
- shipped: shipped,
- addressFk: 121,
- agencyModeFk: 2,
- warehouseFk: 1
- };
- let params = {
- shipped: shipped,
- addressFk: 121,
- agencyModeFk: 2,
- warehouseFk: 1
- };
-
- let serializedParams = $httpParamSerializer(params);
- $httpBackend.when('GET', `/api/Agencies/getLanded?${serializedParams}`).respond(200);
- $httpBackend.expect('GET', `/api/Agencies/getLanded?${serializedParams}`);
-
- controller.onChangeShipped(shipped);
- $httpBackend.flush();
- });
- });
-
- describe('onChangeLanded()', () => {
- it('should return an available shipment date', async() => {
- let landed = new Date();
- controller._ticket = {
- id: 1,
- landed: landed,
- addressFk: 121,
- agencyModeFk: 2,
- warehouseFk: 1
- };
- let params = {
- landed: landed,
- addressFk: 121,
- agencyModeFk: 2,
- warehouseFk: 1
- };
-
- let serializedParams = $httpParamSerializer(params);
- $httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(200);
- $httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`);
-
- controller.onChangeLanded(landed);
- $httpBackend.flush();
- });
- });
-
describe('onChangeZone()', () => {
it('should return an available zone', async() => {
const zoneId = 5;
@@ -206,61 +181,60 @@ describe('Ticket', () => {
});
});
- describe('onChangeAgencyMode()', () => {
- it('should return an available agency', async() => {
- const landed = new Date();
- const agencyModeId = 7;
- controller._ticket = {
- id: 1,
- landed: landed,
- addressFk: 121,
- agencyModeFk: agencyModeId,
- warehouseFk: 1
- };
- let params = {
- landed: landed,
- addressFk: 121,
- agencyModeFk: agencyModeId,
- warehouseFk: 1
- };
- let serializedParams = $httpParamSerializer(params);
- $httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(200);
- $httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`);
+ /* it('should return an available agency', async() => {
+ const landed = new Date();
+ const agencyModeId = 7;
+ controller._ticket = {
+ id: 1,
+ landed: landed,
+ addressFk: 121,
+ agencyModeFk: agencyModeId,
+ warehouseFk: 1
+ };
+ let params = {
+ landed: landed,
+ addressFk: 121,
+ agencyModeFk: agencyModeId,
+ warehouseFk: 1
+ };
- controller.onChangeAgencyMode(agencyModeId);
- $httpBackend.flush();
- });
+ let serializedParams = $httpParamSerializer(params);
+ $httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(200);
+ $httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`);
- it('should throw a user error', async() => {
- spyOn(controller.vnApp, 'showMessage');
- const landed = new Date();
- const agencyModeId = 7;
- controller._ticket = {
- id: 1,
- landed: landed,
- addressFk: 121,
- agencyModeFk: agencyModeId,
- warehouseFk: 1
- };
- let params = {
- landed: landed,
- addressFk: 121,
- agencyModeFk: agencyModeId,
- warehouseFk: 1
- };
-
- let serializedParams = $httpParamSerializer(params);
- $httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(null);
- $httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`);
-
- controller.onChangeAgencyMode(agencyModeId);
- $httpBackend.flush();
-
- expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No delivery zone available for this parameters');
- });
+ controller.onChangeAgencyMode(agencyModeId);
+ $httpBackend.flush();
});
+ it('should throw a user error', async() => {
+ spyOn(controller.vnApp, 'showMessage');
+ const landed = new Date();
+ const agencyModeId = 7;
+ controller._ticket = {
+ id: 1,
+ landed: landed,
+ addressFk: 121,
+ agencyModeFk: agencyModeId,
+ warehouseFk: 1
+ };
+ let params = {
+ landed: landed,
+ addressFk: 121,
+ agencyModeFk: agencyModeId,
+ warehouseFk: 1
+ };
+
+ let serializedParams = $httpParamSerializer(params);
+ $httpBackend.when('GET', `/api/Agencies/getShipped?${serializedParams}`).respond(null);
+ $httpBackend.expect('GET', `/api/Agencies/getShipped?${serializedParams}`);
+
+ controller.onChangeAgencyMode(agencyModeId);
+ $httpBackend.flush();
+
+ expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No delivery zone available for this parameters');
+ }); */
+
describe('isFormInvalid()', () => {
it('should check if all form fields are valid', () => {
controller.ticket = {
diff --git a/print/report/rpt-claim-pickup-order/locale.js b/print/report/rpt-claim-pickup-order/locale.js
index e257b712a..523ac5379 100644
--- a/print/report/rpt-claim-pickup-order/locale.js
+++ b/print/report/rpt-claim-pickup-order/locale.js
@@ -15,7 +15,7 @@ module.exports = {
sections: {
agency: {
description: `Para agilizar tu recogida, por favor, pónte en contacto con la oficina de integrados.
- Tlf: 96 166 77 88 - Ana Gómez (Ext. 2113) (agomezf@integra2.es) `
+ Tlf: 96 166 77 88 - Ana Gómez (Ext. 2133) (agomezf@integra2.es) `
}
}
},