diff --git a/db/install/changes/00-ticketComponentMakeUpdate.sql b/db/install/changes/00-ticketComponentMakeUpdate.sql new file mode 100644 index 000000000..3e73651c1 --- /dev/null +++ b/db/install/changes/00-ticketComponentMakeUpdate.sql @@ -0,0 +1,42 @@ +USE `vn`; +DROP procedure IF EXISTS `ticketComponentMakeUpdate`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketComponentMakeUpdate`( + vTicketFk INT, + vClientFk INT, + vAgencyModeFk INT, + vAddressFk INT, + vWarehouseFk TINYINT, + vCompanyFk SMALLINT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption INT) +BEGIN + + + CALL vn.ticketComponentPreview (vTicketFk, vLanded, vAddressFk, vAgencyModeFk, vWarehouseFk); + CALL vn.ticketComponentUpdate ( + vTicketFk, + vClientFk, + vAgencyModeFk, + vAddressFk, + vWarehouseFk, + vCompanyFk, + vShipped, + vLanded, + vIsDeleted, + vHasToBeUnrouted, + vOption + ); + + DROP TEMPORARY TABLE + tmp.ticketComponent, + tmp.ticketComponentPrice; +END$$ + +DELIMITER ; + diff --git a/db/install/changes/00-ticketComponentPreview.sql b/db/install/changes/00-ticketComponentPreview.sql new file mode 100644 index 000000000..f7af9dcc8 --- /dev/null +++ b/db/install/changes/00-ticketComponentPreview.sql @@ -0,0 +1,134 @@ +USE `vn`; +DROP procedure IF EXISTS `ticketComponentPreview`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPreview`( + vTicketFk INT, + vLanded DATE, + vAddressFk INT, + vAgencyModeFk INT, + vWarehouseFk SMALLINT) +BEGIN +/** + * Devuelve un listado previo de + * componentes para un ticket + * + * @param vTicketFk Id del ticket + * @param vLanded Fecha de recepcion + * @param vAddressFk Id del consignatario + * @param vAgencyModeFk Id del modo de agencia + * @param vWarehouseFk Id del almacén + */ + + DECLARE vAgencyFk INT; + DECLARE vShipped DATE; + DECLARE vBuyOrderItem INT DEFAULT 100; + + DECLARE vHasDataChanged BOOL DEFAULT FALSE; + DECLARE vHasAddressChanged BOOL; + DECLARE vHasAgencyModeChanged BOOL DEFAULT FALSE; + DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; + + DECLARE vAddressTypeRateFk INT DEFAULT NULL; + DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL; + + DECLARE vHasChangeAll BOOL DEFAULT FALSE; + + SELECT DATE(landed) <> vLanded, + addressFk <> vAddressFk, + agencyModeFk <> vAgencyModeFk, + warehouseFk <> vWarehouseFk + INTO + vHasDataChanged, + vHasAddressChanged, + vHasAgencyModeChanged, + vHasWarehouseChanged + FROM vn.ticket t + WHERE t.id = vTicketFk; +/*SELECT vHasDataChanged, + vHasAddressChanged, + vHasAgencyModeChanged, + vHasWarehouseChanged; + */ + IF vHasDataChanged OR vHasWarehouseChanged THEN + SET vHasChangeAll = TRUE; + END IF; + + IF vHasAddressChanged THEN + SET vAddressTypeRateFk = 5; + END IF; + + IF vHasAgencyModeChanged THEN + SET vAgencyModeTypeRateFk = 6; + END IF; + + SELECT agencyFk INTO vAgencyFk + FROM agencyMode + WHERE id = vAgencyModeFk; + + CALL agencyHourGetShipped(vLanded, vAddressFk, vAgencyFk); + + SELECT shipped INTO vShipped + FROM tmp.agencyHourGetShipped + WHERE warehouseFk = vWarehouseFk; + + CALL buyUltimate(vWarehouseFk, vShipped); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; + CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( + SELECT + vWarehouseFk AS warehouseFk, + NULL AS available, + s.itemFk, + bu.buyFk + FROM sale s + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + AND s.itemFk != vBuyOrderItem + GROUP BY bu.warehouseFk, bu.itemFk); + + CALL ticketComponentCalculate(vAddressFk, vAgencyModeFk); + +/*SELECT *,vHasChangeAll,cr.isRenewable = FALSE,vHasChangeAll, + NOT (cr.componentTypeRate <=> vAddressTypeRateFk),NOT (cr.componentTypeRate <=> vAgencyModeTypeRateFk), + NOT (cr.componentTypeRate <=> vAddressTypeRateFk) OR NOT (cr.componentTypeRate <=> vAgencyModeTypeRateFk) + FROM saleComponent sc + JOIN sale s ON s.id = sc.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN componentRate cr ON cr.id = sc.componentFk + WHERE s.ticketFk = vTicketFk + AND (cr.isRenewable = FALSE + OR + (NOT vHasChangeAll + AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk + OR cr.componentTypeRate <=> vAgencyModeTypeRateFk))));*/ +/*SELECT * FROM tmp.ticketComponent;*/ + -- Inserta los componentes que NO seran modificados + REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value + FROM saleComponent sc + JOIN sale s ON s.id = sc.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN componentRate cr ON cr.id = sc.componentFk + WHERE s.ticketFk = vTicketFk + AND (cr.isRenewable = FALSE + OR + (NOT vHasChangeAll + AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk + OR cr.componentTypeRate <=> vAgencyModeTypeRateFk)))); +/*SELECT * FROM tmp.ticketComponent;*/ + SET @shipped = vShipped; + + DROP TEMPORARY TABLE + tmp.agencyHourGetShipped, + tmp.buyUltimate, + tmp.ticketLot; + + IF IFNULL(vShipped, CURDATE() - 1) < CURDATE() THEN + CALL util.throw('NO_AGENCY_AVAILABLE'); + END IF; +END$$ + +DELIMITER ; + diff --git a/db/install/changes/00-ticketComponentUpdate.sql b/db/install/changes/00-ticketComponentUpdate.sql new file mode 100644 index 000000000..d65c59713 --- /dev/null +++ b/db/install/changes/00-ticketComponentUpdate.sql @@ -0,0 +1,62 @@ +USE `vn`; +DROP procedure IF EXISTS `ticketComponentUpdate`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdate`( + vTicketFk INT, + vClientFk INT, + vAgencyModeFk INT, + vAddressFk INT, + vWarehouseFk TINYINT, + vCompanyFk SMALLINT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption INT) +BEGIN + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + IF vOption <> 8 THEN + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + END IF; + COMMIT; +END$$ + +DELIMITER ; + diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index c74dc36f9..294509f05 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -30,7 +30,7 @@ value="{{$ctrl.summary.item.itemType.name}}"> + value="{{$ctrl.summary.item.size}}"> diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 712bd47ae..728b80523 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -38,13 +38,14 @@ module.exports = Self => { if (!hasDeliveryRole) data.hasToBeUnrouted = true; - let query = 'CALL vn.ticketComponentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + let query = 'CALL vn.ticketComponentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; let res = await Self.rawSql(query, [ ticketFk, data.clientFk, data.agencyModeFk, data.addressFk, data.warehouseFk, + data.companyFk, data.shipped, data.landed, data.isDeleted, diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 48d4cc968..598bb8abd 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -27,6 +27,7 @@ describe('ticket componentUpdate()', () => { agencyModeFk: 8, addressFk: 121, warehouseFk: 1, + companyFk: 442, shipped: today, landed: today, isDeleted: false, @@ -54,6 +55,7 @@ describe('ticket componentUpdate()', () => { agencyModeFk: 7, addressFk: 121, warehouseFk: 1, + companyFk: 442, shipped: today, landed: today, isDeleted: false, @@ -62,7 +64,7 @@ describe('ticket componentUpdate()', () => { }; let ctx = {req: {accessToken: {userId: 101}}}; - await app.models.Ticket.componentUpdate(11, data, ctx); + await app.models.Ticket.componentUpdate(ticketId, data, ctx); [componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven); let firstvalueAfterChange = componentValue.value; diff --git a/modules/ticket/front/data/step-three/index.js b/modules/ticket/front/data/step-three/index.js index dcde1e838..67df50c97 100644 --- a/modules/ticket/front/data/step-three/index.js +++ b/modules/ticket/front/data/step-three/index.js @@ -23,10 +23,11 @@ class Controller { } onSubmit() { - if (!this.ticket.option) + if (!this.ticket.option) { return this.vnApp.showError( this.$translate.instant('Choose an option') ); + } let query = `/ticket/api/tickets/${this.ticket.id}/componentUpdate`; let data = { @@ -34,6 +35,7 @@ class Controller { agencyModeFk: this.ticket.agencyModeFk, addressFk: this.ticket.addressFk, warehouseFk: this.ticket.warehouseFk, + companyFk: this.ticket.companyFk, shipped: this.ticket.shipped, landed: this.ticket.landed, isDeleted: this.ticket.isDeleted,