salix/db/routines/vn/procedures/ticket_printLabelPrevious.sql

34 lines
868 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_printLabelPrevious`(vTicketFk INT)
BEGIN
/**
* Calls the report_print procedure and passes it
* the necessary parameters for printing.
*
* @param vTicketFk id ticket to print.
*/
DECLARE vPrinterFk INT;
DECLARE vSaleGroup INT;
DECLARE vUserFk INT DEFAULT account.myUser_getId();
SELECT sg.id, o.labelerFk INTO vSaleGroup, vPrinterFk
FROM saleGroup sg
JOIN sector sc ON sc.id = sg.sectorFk
JOIN saleGroupDetail sgd ON sg.id = sgd.saleGroupFk
JOIN sale s ON sgd.saleFk = s.id
JOIN ticket t ON s.ticketFk = t.id
JOIN operator o ON o.workerFk = vUserFk
WHERE sc.id = o.sectorFk
AND t.id = vTicketFk
LIMIT 1;
CALL report_print(
'LabelPrevia',
vPrinterFk,
vUserFk,
JSON_OBJECT('id', vSaleGroup, 'userFk', vUserFk),
'high'
);
END$$
DELIMITER ;