40 lines
1.1 KiB
MySQL
40 lines
1.1 KiB
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_scan`(vBarcode VARCHAR(512))
|
||
|
BEGIN
|
||
|
/**
|
||
|
* Busca compras a partir de un código de barras de subasta, las marca como
|
||
|
* escaneadas y como etiquetas impresas y las devuelve.
|
||
|
*
|
||
|
* @param vBarcode Código de compra de una etiqueta de subasta
|
||
|
* @select (buy, do_photo) Identificadores de compra escaneados
|
||
|
*/
|
||
|
CALL edi.ekt_scan(vBarcode);
|
||
|
|
||
|
DROP TEMPORARY TABLE IF EXISTS tBuy;
|
||
|
CREATE TEMPORARY TABLE tBuy
|
||
|
SELECT id buyFk
|
||
|
FROM vn.buy b
|
||
|
LIMIT 0;
|
||
|
|
||
|
INSERT INTO tBuy(buyFk)
|
||
|
SELECT b.id
|
||
|
FROM buy b
|
||
|
JOIN tmp.ekt t ON t.ektFk = b.ektFk
|
||
|
JOIN vn.entry en ON en.id = b.entryFk
|
||
|
JOIN vn.travel tr ON tr.id = en.travelFk
|
||
|
JOIN vn.warehouse w ON w.id = tr.warehouseInFk
|
||
|
JOIN vn.country c ON c.id = w.countryFk AND c.code = 'NL';
|
||
|
|
||
|
SELECT b.id buy, i.doPhoto do_photo, b.stickers - CAST(b.printedStickers AS INT) stickersToPrint
|
||
|
FROM tBuy tb
|
||
|
JOIN vn.buy b ON tb.buyFk = b.id
|
||
|
JOIN vn.item i ON i.id = b.itemFk;
|
||
|
|
||
|
UPDATE vn.buy b
|
||
|
JOIN tBuy tb ON tb.buyFk = b.id
|
||
|
SET b.printedStickers = b.stickers;
|
||
|
|
||
|
DROP TEMPORARY TABLE tmp.ekt, tBuy;
|
||
|
END$$
|
||
|
DELIMITER ;
|