refs #6287 clean changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2023-10-20 11:53:48 +02:00
parent 699a24a20b
commit 24c934ca8b
93 changed files with 136 additions and 2 deletions

View File

@ -0,0 +1,135 @@
REVOKE EXECUTE ON PROCEDURE `vn`.`ticket_add` TO `employee`;
REVOKE EXECUTE ON PROCEDURE `vn`.`ticket_add` TO `administrative`;
GRANT EXECUTE ON PROCEDURE `vn`.`ticket_add` FROM `developer`;
DROP PROCEDURE IF EXISTS `vn`.`ticket_add`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_add`(
vClientId INT
,vShipped DATE
,vWarehouseFk INT
,vCompanyFk INT
,vAddressFk INT
,vAgencyModeFk INT
,vRouteFk INT
,vlanded DATE
,vUserId INT
,vIsRequiredZone INT
,OUT vNewTicket INT)
BEGIN
/**
* Crea un ticket,
* ¡¡NO se debe llamar directamente, llamar a salix que hace comprobaciones previas!!
*
* @param vClientId id del cliente
* @param vShipped dia preparacion
* @param vWarehouseFk id del warehouse
* @param vCompanyFk id la empresa
* @param vAddressFk id del consignatario
* @param vAgencyModeFk id de la agencia
* @param vRouteFk id de la ruta | NULL
* @param vlanded dia llegada
* @param vUserId que crea el ticket
* @param vIsRequiredZone Indica si tiene que tener zona valida para ser creado
* @return vNewTicket id del ticket creado
*/
DECLARE vZoneFk INT;
DECLARE vPrice DECIMAL(10,2);
DECLARE vBonus DECIMAL(10,2);
DECLARE vIsActive BOOL;
DECLARE vNickname VARCHAR(100);
IF vClientId IS NULL THEN
CALL util.throw ('CLIENT_NOT_ESPECIFIED');
END IF;
SELECT isActive INTO vIsActive
FROM vn.client
WHERE id = vClientId;
IF NOT vIsActive THEN
CALL util.throw ('CLIENT_NOT_ACTIVE');
END IF;
IF NOT vAddressFk OR vAddressFk IS NULL THEN
SELECT id INTO vAddressFk
FROM address
WHERE clientFk = vClientId
AND isDefaultAddress;
END IF;
IF vAgencyModeFk IS NOT NULL THEN
CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE);
SELECT zoneFk, price, bonus
INTO vZoneFk, vPrice, vBonus
FROM tmp.zoneGetShipped
WHERE shipped = vShipped
AND warehouseFk = vWarehouseFk
LIMIT 1;
IF (vZoneFk IS NULL OR vZoneFk = 0) AND vIsRequiredZone THEN
CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS');
END IF;
END IF;
INSERT INTO ticket (
clientFk,
shipped,
addressFk,
agencyModeFk,
nickname,
warehouseFk,
routeFk,
companyFk,
landed,
zoneFk,
zonePrice,
zoneBonus
)
SELECT vClientId,
vShipped,
a.id,
vAgencyModeFk,
a.nickname,
vWarehouseFk,
IF(vRouteFk,vRouteFk,NULL),
vCompanyFk,
vlanded,
vZoneFk,
vPrice,
vBonus
FROM address a
JOIN agencyMode am ON am.id = a.agencyModeFk
WHERE a.id = vAddressFk;
SELECT a.nickname INTO vNickname
FROM address a
WHERE a.id = vAddressFk;
SET vNewTicket = LAST_INSERT_ID();
INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
SELECT vNewTicket, ao.observationTypeFk, ao.description
FROM addressObservation ao
JOIN address a ON a.id = ao.addressFk
WHERE a.id = vAddressFk;
IF (SELECT COUNT(*)
FROM bs.clientNewBorn cnb
WHERE cnb.clientFk = vClientId
AND NOT cnb.isRookie) = 0 THEN
CALL vn.ticketObservation_addNewBorn(vNewTicket);
END IF;
IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN
INSERT INTO ticketTracking(stateFk, ticketFk, workerFk)
SELECT id, vNewTicket, account.myUser_getId()
FROM state
WHERE `code` = 'DELIVERED';
END IF;
END$$
DELIMITER ;

View File

@ -48,7 +48,7 @@ module.exports = Self => {
description: `The route id filter` description: `The route id filter`
}], }],
returns: { returns: {
type: 'number', type: 'object',
root: true root: true
}, },
http: { http: {
@ -125,7 +125,6 @@ module.exports = Self => {
true, true,
userId userId
], myOptions); ], myOptions);
const ticket = await models.Ticket.findById(result[1][0].newTicketId, null, myOptions); const ticket = await models.Ticket.findById(result[1][0].newTicketId, null, myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();