Compare commits

...

25 Commits

Author SHA1 Message Date
Robert Ferrús 31e680231c Merge branch '6822-entryTransfer' of https://gitea.verdnatura.es/verdnatura/salix into 7709-supplierPackaging_ReportSource
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-10-16 07:23:11 +02:00
Robert Ferrús d2a4a84728 Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-10-16 05:22:03 +00:00
Robert Ferrús 18a055f28a Merge branch '6822-entryTransfer' of https://gitea.verdnatura.es/verdnatura/salix into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-09-11 09:59:05 +02:00
Robert Ferrús e999201969 feat: refs #6822 entry_clone 2024-09-11 09:59:01 +02:00
Robert Ferrús 400226f955 Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-09-11 07:47:53 +00:00
Robert Ferrús 07c4fa4b1d Merge branch 'dev' of https: refs #6822//gitea.verdnatura.es/verdnatura/salix into 6822-entryTransfer
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-09-11 09:46:13 +02:00
Robert Ferrús 5f63017853 feat: refs #6822 changes transaction
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-08-06 07:20:30 +02:00
Robert Ferrús bb36667616 Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-08-05 11:12:44 +02:00
Robert Ferrús 24e64fe607 Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-19 05:21:27 +00:00
Robert Ferrús 8b106a0cbc Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-18 05:08:10 +00:00
Robert Ferrús 5a742ada5c Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-17 12:54:19 +02:00
Robert Ferrús 2cb8d07aef feat: refs #6822
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-17 10:30:23 +02:00
Robert Ferrús 109770b0a3 feat: refs #6822 return newEntry
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-07-17 10:28:22 +02:00
Robert Ferrús 1332aef213 Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-15 05:31:08 +00:00
Robert Ferrús d60a1a3424 feat: refs #6822 entry_clone
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-11 09:39:06 +02:00
Robert Ferrús 5a7d5787f7 feat: refs #6822 clonar travel con warehouseInFk
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-11 07:38:13 +02:00
Robert Ferrús 1ffe41c23e Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-10 11:35:01 +00:00
Robert Ferrús c286dd780f Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-10 05:45:02 +00:00
Robert Ferrús a34376f4d2 feat: refs #6822
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-10 07:31:49 +02:00
Robert Ferrús 22c83b6b56 Merge branch 'dev' into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-03 10:04:55 +00:00
Robert Ferrús 04f6059d6f feat: refs #6822
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-03 12:03:28 +02:00
Robert Ferrús eb17d66986 Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6822-entryTransfer
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
2024-07-03 11:30:58 +02:00
Robert Ferrús b5f8ad77f1 Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6822-entryTransfer
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-07-03 10:18:34 +02:00
Robert Ferrús bac07fe265 feat: refs #6822
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-05-23 12:41:59 +02:00
Robert Ferrús 9585af8e77 feat: refs #6822 create entryTransfer 2024-05-23 12:39:30 +02:00
6 changed files with 178 additions and 5 deletions

View File

@ -15,7 +15,7 @@ BEGIN
DELETE FROM bs.ventas_contables
WHERE year = vYear
AND month = vMonth;
AND month = vMonth;
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
CREATE TEMPORARY TABLE tmp.ticket_list

View File

@ -1,5 +1,5 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`(vSelf INT)
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`(vSelf INT, OUT newEntryFk INT)
BEGIN
/**
* clones an entry.
@ -8,13 +8,19 @@ BEGIN
*/
DECLARE vNewEntryFk INT;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
CALL entry_cloneHeader(vSelf, vNewEntryFk, NULL);
CALL entry_copyBuys(vSelf, vNewEntryFk);
COMMIT;
SET newEntryFk = vNewEntryFk;
SELECT vNewEntryFk;
END$$
DELIMITER ;

View File

@ -33,14 +33,14 @@ BEGIN
read_loop: LOOP
SET vDone = FALSE;
FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers;
IF vDone THEN
LEAVE read_loop;
END IF;
IF vIshStickers = vBuyStickers THEN
IF vIshStickers = vBuyStickers THEN
UPDATE buy
SET entryFk = vToEntryFk
WHERE id = vBuyFk;

View File

@ -0,0 +1,121 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT)
BEGIN
/**
* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén
*
* @param vOriginalEntry entrada que se quiera adelantar
*/
DECLARE vNewEntryFk INT;
DECLARE vTravelFk INT;
DECLARE vWarehouseFk INT;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
-- Clonar la entrada
CALL entry_clone(vOriginalEntry,vNewEntryFk);
START TRANSACTION;
-- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel.
INSERT INTO travel(
shipped,
landed,
warehouseInFk,
warehouseOutFk,
`ref`,
isReceived,
agencyModeFk)
SELECT util.VN_CURDATE(),
util.VN_CURDATE() + INTERVAL 1 DAY,
t.warehouseInFk,
t.warehouseInFk,
t.`ref`,
t.isReceived,
t.agencyModeFk
FROM travel t
JOIN entry e ON e.travelFk = t.id
WHERE e.id = vOriginalEntry;
SET vTravelFk = LAST_INSERT_ID();
UPDATE entry
SET travelFk = vTravelFk
WHERE id = vNewEntryFk;
-- Poner a 0 las cantidades
UPDATE buy b
SET b.quantity = 0, b.stickers = 0
WHERE b.entryFk = vNewEntryFk;
-- Eliminar duplicados
DELETE b.*
FROM buy b
LEFT JOIN (SELECT b.id, b.itemFk
FROM buy b
WHERE b.entryFk = vNewEntryFk
GROUP BY b.itemFk) tBuy ON tBuy.id = b.id
WHERE b.entryFk = vNewEntryFk
AND tBuy.id IS NULL;
SELECT t.warehouseInFk INTO vWarehouseFk
FROM travel t
JOIN entry e ON e.travelFk = t.id
WHERE e.id = vOriginalEntry;
-- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones
CREATE OR REPLACE TEMPORARY TABLE tBuy
ENGINE = MEMORY
SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold
FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity
FROM buy b
WHERE b.entryFk = vOriginalEntry
GROUP BY b.itemFk
) tBuy
LEFT JOIN (
SELECT ish.itemFk, SUM(visible) visible
FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk
WHERE s.warehouseFk = vWarehouseFk
AND sh.parked = util.VN_CURDATE()
GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk
LEFT JOIN (
SELECT s.itemFk, SUM(s.quantity) sold
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN itemShelvingSale iss ON iss.saleFk = s.id
JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk
JOIN shelving s2 ON s2.code = is2.shelvingFk
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
AND s2.parked = util.VN_CURDATE()
GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk
WHERE visible = tBuy.totalQuantity
OR iss.itemFk IS NULL;
UPDATE buy b
JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk
SET b.quantity = sub.totalQuantity - sub.visible - sub.sold
WHERE b.entryFk = vNewEntryFk;
-- Limpia la nueva entrada
DELETE b.*
FROM buy b
WHERE b.entryFk = vNewEntryFk
AND b.quantity = 0;
COMMIT;
SET vNewEntry = vNewEntryFk;
CALL cache.visible_refresh(@c,TRUE,7);
CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE());
END$$
DELIMITER ;

View File

@ -0,0 +1,45 @@
module.exports = Self => {
Self.remoteMethodCtx('transfer', {
description: 'Trasladar la mercancia de una entrada al dia siguiente',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
http: {source: 'path'}
}
],
http: {
path: '/:id/transfer',
verb: 'POST'
},
returns: {
arg: 'newEntryFk',
type: 'number'
}
});
Self.transfer = async(ctx, id, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await Self.rawSql('CALL vn.entry_transfer(?, @vNewEntry)', [id], myOptions);
const newEntryFk = await Self.rawSql('SELECT @vNewEntry AS newEntryFk', [], myOptions);
if (tx) await tx.commit();
return newEntryFk;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -11,6 +11,7 @@ module.exports = Self => {
require('../methods/entry/addFromPackaging')(Self);
require('../methods/entry/addFromBuy')(Self);
require('../methods/entry/buyLabel')(Self);
require('../methods/entry/transfer')(Self);
require('../methods/entry/print')(Self);
Self.observe('before save', async function(ctx, options) {