6287-Ticket.create-no-usarlo #1806
|
@ -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 ;
|
|
@ -90,24 +90,21 @@ module.exports = Self => {
|
|||
where: {code: 'DELIVERED'}
|
||||
}, myOptions);
|
||||
|
||||
const zone = await models.Zone.findOne({
|
||||
where: {agencyModeFk: agencyMode.id}
|
||||
}, myOptions);
|
||||
|
||||
const claim = await models.Claim.findOne(filter, myOptions);
|
||||
const today = Date.vnNew();
|
||||
|
||||
const newRefundTicket = await models.Ticket.create({
|
||||
clientFk: claim.ticket().clientFk,
|
||||
ctx.args = {
|
||||
clientId: claim.ticket().clientFk,
|
||||
shipped: today,
|
||||
landed: today,
|
||||
nickname: claim.ticket().address().nickname,
|
||||
warehouseFk: claim.ticket().warehouseFk,
|
||||
companyFk: claim.ticket().companyFk,
|
||||
addressFk: claim.ticket().addressFk,
|
||||
agencyModeFk: agencyMode.id,
|
||||
zoneFk: zone.id
|
||||
}, myOptions);
|
||||
warehouseId: claim.ticket().warehouseFk,
|
||||
companyId: claim.ticket().companyFk,
|
||||
addressId: claim.ticket().addressFk,
|
||||
agencyModeId: agencyMode.id
|
||||
};
|
||||
|
||||
const newRefundTicket = await models.Ticket.new(ctx, myOptions);
|
||||
|
||||
await models.TicketRefund.create({
|
||||
refundTicketFk: newRefundTicket.id,
|
||||
|
|
|
@ -72,7 +72,7 @@ module.exports = Self => {
|
|||
const [firstTicketId] = ticketsIds;
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions);
|
||||
refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions, ctx);
|
||||
|
||||
for (const sale of sales) {
|
||||
const createdSale = await models.Sale.create({
|
||||
|
@ -101,7 +101,7 @@ module.exports = Self => {
|
|||
const now = Date.vnNew();
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions);
|
||||
refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions, ctx);
|
||||
}
|
||||
|
||||
if (servicesIds && servicesIds.length > 0) {
|
||||
|
@ -133,23 +133,24 @@ module.exports = Self => {
|
|||
}
|
||||
};
|
||||
|
||||
async function createTicketRefund(ticketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions) {
|
||||
async function createTicketRefund(ticketId, now, refundAgencyMode, refoundZoneId, withWarehouse, myOptions, ctx) {
|
||||
const models = Self.app.models;
|
||||
|
||||
const filter = {include: {relation: 'address'}};
|
||||
const ticket = await models.Ticket.findById(ticketId, filter, myOptions);
|
||||
|
||||
const refundTicket = await models.Ticket.create({
|
||||
clientFk: ticket.clientFk,
|
||||
ctx.args = {
|
||||
clientId: ticket.clientFk,
|
||||
shipped: now,
|
||||
addressFk: ticket.address().id,
|
||||
agencyModeFk: refundAgencyMode.id,
|
||||
addressId: ticket.address().id,
|
||||
agencyModeId: refundAgencyMode.id,
|
||||
nickname: ticket.address().nickname,
|
||||
warehouseFk: withWarehouse ? ticket.warehouseFk : null,
|
||||
companyFk: ticket.companyFk,
|
||||
landed: now,
|
||||
zoneFk: refoundZoneId
|
||||
}, myOptions);
|
||||
warehouseId: withWarehouse ? ticket.warehouseFk : null,
|
||||
companyId: ticket.companyFk,
|
||||
landed: now
|
||||
};
|
||||
|
||||
const refundTicket = await models.Ticket.new(ctx, myOptions);
|
||||
|
||||
await models.TicketRefund.create({
|
||||
refundTicketFk: refundTicket.id,
|
||||
|
|
|
@ -125,7 +125,6 @@ module.exports = Self => {
|
|||
true,
|
||||
userId
|
||||
], myOptions);
|
||||
|
||||
const ticket = await models.Ticket.findById(result[1][0].newTicketId, null, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
|
Loading…
Reference in New Issue