fix: refs #7404 fix back data source

This commit is contained in:
Pablo Natek 2024-09-20 11:06:38 +02:00
parent c9db888266
commit fb1e77f9c4
7 changed files with 83 additions and 69 deletions

View File

@ -1506,7 +1506,8 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO
(7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7),
(8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10), (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10),
(10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10), (10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10),
(11, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4); (11, util.VN_CURDATE() - INTERVAL 1 DAY , util.VN_CURDATE(), 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4),
(12, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4);
INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`)
VALUES VALUES
@ -1520,7 +1521,7 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed
(8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''), (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''),
(9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''), (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''),
(10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, 1, ''), (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, 1, ''),
(99, 69, '2000-12-01 00:00:00.000', 11, 0, 442, 'IN2009', 'Movement 99', 1, 1, ''); (99, 69, '2000-12-01 00:00:00.000', 11, 0, 442, 'IN2009', 'Movement 99', 0, 0, '');
INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`) INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`)
VALUES (2, 4, 1); VALUES (2, 4, 1);

View File

@ -1,15 +1,13 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockTraslation`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_calculateStock`(
vDated DATE vDated DATE
) )
BEGIN BEGIN
/** /**
* Calcula el stock del almacén de subasta desde FechaInventario hasta vDated * Calculate the stock of the auction warehouse from the inventory date to vDated
* sin tener en cuenta las salidas del mismo dia vDated
* para ver el transporte a reservar
* *
* @param vDated Fecha hasta la cual calcula el stock * @param vDated Date to calculate the stock.
* @return tmp.item * @return tmp.item, tmp.buyUltimate
*/ */
DECLARE vAuctionWarehouseFk INT; DECLARE vAuctionWarehouseFk INT;

View File

@ -1,12 +1,16 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBought_calculate`() CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBought_calculate`(
BEGIN vDated DATE
)BEGIN
/** /**
* Inserts the purchase volume per buyer * Calculate the stock of the auction warehouse from the inventory date to vDated
* into stockBought according to the current date. * without taking into account the outputs of the same day vDated
*
* @param vDated Date to calculate the stock.
*/ */
DECLARE vDated DATE; IF vDated < util.VN_CURDATE() THEN
SET vDated = util.VN_CURDATE(); CALL util.error('The date to calculate the stock is less than the current date');
END IF;
CREATE OR REPLACE TEMPORARY TABLE tStockBought CREATE OR REPLACE TEMPORARY TABLE tStockBought
SELECT workerFk, reserve SELECT workerFk, reserve
@ -16,26 +20,27 @@ BEGIN
DELETE FROM stockBought WHERE dated = vDated; DELETE FROM stockBought WHERE dated = vDated;
INSERT INTO stockBought (workerFk, bought, dated) CALL item_calculateStock(vDated);
INSERT INTO stockBought(workerFk, bought, dated)
SELECT it.workerFk, SELECT it.workerFk,
ROUND(SUM( SUM(
(ac.conversionCoefficient * (ti.quantity / b.packing) *
(b.quantity / b.packing) * buy_getVolume(b.id)
buy_getVolume(b.id) ) / vc.palletM3 / 1000000 bought,
) / (vc.trolleyM3 * 1000000)
), 1),
vDated vDated
FROM entry e FROM itemType it
JOIN travel t ON t.id = e.travelFk JOIN item i ON i.typeFk = it.id
JOIN warehouse w ON w.id = t.warehouseInFk LEFT JOIN tmp.item ti ON ti.itemFk = i.id
JOIN buy b ON b.entryFk = e.id JOIN itemCategory ic ON ic.id = it.categoryFk
JOIN item i ON i.id = b.itemFk JOIN warehouse wh ON wh.code = 'VNH'
JOIN itemType it ON it.id = i.typeFk JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
JOIN auctionConfig ac AND bu.warehouseFk = wh.id
JOIN buy b ON b.id = bu.buyFk
JOIN volumeConfig vc JOIN volumeConfig vc
WHERE t.shipped = vDated WHERE ic.display
AND t.warehouseInFk = ac.warehouseFk GROUP BY it.workerFk
GROUP BY it.workerFk; HAVING bought;
UPDATE stockBought s UPDATE stockBought s
JOIN tStockBought ts ON ts.workerFk = s.workerFk JOIN tStockBought ts ON ts.workerFk = s.workerFk
@ -45,8 +50,12 @@ BEGIN
INSERT INTO stockBought (workerFk, reserve, dated) INSERT INTO stockBought (workerFk, reserve, dated)
SELECT ts.workerFk, ts.reserve, vDated SELECT ts.workerFk, ts.reserve, vDated
FROM tStockBought ts FROM tStockBought ts
WHERE ts.workerFk NOT IN (SELECT workerFk FROM stockBought WHERE dated = vDated); WHERE ts.workerFk NOT IN (
SELECT workerFk
FROM stockBought
WHERE dated = vDated
);
DROP TEMPORARY TABLE tStockBought; DROP TEMPORARY TABLE tStockBought, tmp.item, tmp.buyUltimate;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -23,7 +23,7 @@ BEGIN
WHERE dated = vDated WHERE dated = vDated
AND userFk = vWorker; AND userFk = vWorker;
CALL stockTraslation(vDated); CALL item_calculateStock(vDated);
INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description) INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description)
SELECT it.workerFk, SELECT it.workerFk,

View File

@ -18,7 +18,7 @@ BEGIN
DELETE FROM stockBuyed WHERE dated = vDated; DELETE FROM stockBuyed WHERE dated = vDated;
CALL stockTraslation(vDated); CALL item_calculateStock(vDated);
INSERT INTO stockBuyed(userFk, buyed, `dated`, description) INSERT INTO stockBuyed(userFk, buyed, `dated`, description)
SELECT it.workerFk, SELECT it.workerFk,

View File

@ -29,15 +29,14 @@ module.exports = Self => {
dated.setHours(0, 0, 0, 0); dated.setHours(0, 0, 0, 0);
today.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0);
if (dated.getTime() === today.getTime()) if (dated.getTime() >= today.getTime())
await models.StockBought.rawSql(`CALL vn.stockBought_calculate()`); await models.StockBought.rawSql(`CALL vn.stockBought_calculate(?)`, [dated]);
const filter = { const filter = {
where: { where: {dated},
dated: dated
},
include: [ include: [
{ {
fields: ['workerFk', 'reserve', 'bought'],
relation: 'worker', relation: 'worker',
scope: { scope: {
include: [ include: [

View File

@ -11,6 +11,7 @@ module.exports = Self => {
arg: 'dated', arg: 'dated',
type: 'string', type: 'string',
description: 'The date to filter', description: 'The date to filter',
required: true,
} }
], ],
returns: { returns: {
@ -24,35 +25,41 @@ module.exports = Self => {
}); });
Self.getStockBoughtDetail = async(workerFk, dated) => { Self.getStockBoughtDetail = async(workerFk, dated) => {
if (!dated) { const models = Self.app.models;
dated = Date.vnNew(); await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated]);
dated.setHours(0, 0, 0, 0); const tx = await models.Collection.beginTransaction({});
const options = {transaction: tx};
let result;
try {
await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated], options);
result = await Self.rawSql(
`SELECT b.entryFk entryFk,
i.id itemFk,
i.name itemName,
ti.quantity,
(ac.conversionCoefficient * (ti.quantity / b.packing) * buy_getVolume(b.id))
/ (vc.trolleyM3 * 1000000) volume,
b.packagingFk packagingFk,
b.packing
FROM tmp.item ti
JOIN item i ON i.id = ti.itemFk
JOIN itemType it ON i.typeFk = it.id
JOIN itemCategory ic ON ic.id = it.categoryFk
JOIN worker w ON w.id = it.workerFk
JOIN auctionConfig ac
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
AND bu.warehouseFk = ac.warehouseFk
JOIN buy b ON b.id = bu.buyFk
JOIN volumeConfig vc
WHERE ic.display
AND w.id = ?`,
[workerFk], options
);
await Self.rawSql(`DROP TEMPORARY TABLE tmp.item, tmp.buyUltimate;`, [], options);
} catch (e) {
await tx.rollback();
throw e;
} }
return Self.rawSql( return result;
`SELECT e.id entryFk,
i.id itemFk,
i.longName itemName,
b.quantity,
ROUND((ac.conversionCoefficient *
(b.quantity / b.packing) *
buy_getVolume(b.id)
) / (vc.trolleyM3 * 1000000),
2
) volume,
b.packagingFk,
b.packing
FROM entry e
JOIN travel t ON t.id = e.travelFk
JOIN buy b ON b.entryFk = e.id
JOIN item i ON i.id = b.itemFk
JOIN itemType it ON it.id = i.typeFk
JOIN worker w ON w.id = it.workerFk
JOIN auctionConfig ac
JOIN volumeConfig vc
WHERE t.warehouseInFk = ac.warehouseFk
AND it.workerFk = ?
AND t.shipped = util.VN_CURDATE()`,
[workerFk]
);
}; };
}; };