8030-newPriceComponent #3012

Merged
pako merged 4 commits from 8030-newPriceComponent into dev 2024-09-24 10:39:06 +00:00
8 changed files with 94 additions and 71 deletions
Showing only changes of commit ed656836b1 - Show all commits

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),
(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),
(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`)
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, ''),
(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, ''),
(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`)
VALUES (2, 4, 1);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,6 +11,7 @@ module.exports = Self => {
arg: 'dated',
type: 'string',
description: 'The date to filter',
required: true,
}
],
returns: {
@ -24,35 +25,50 @@ module.exports = Self => {
});
Self.getStockBoughtDetail = async(workerFk, dated) => {
if (!dated) {
dated = Date.vnNew();
dated.setHours(0, 0, 0, 0);
const models = Self.app.models;
const myOptions = {};
let tx;
let result;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated], myOptions);
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], myOptions
);
await Self.rawSql(`DROP TEMPORARY TABLE tmp.item, tmp.buyUltimate;`, [], myOptions);
if (tx) await tx.commit();
return result;
} catch (e) {
await tx.rollback();
throw e;
}
return Self.rawSql(
`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]
);
};
};

View File

@ -1,6 +1,6 @@
const {models} = require('vn-loopback/server/server');
describe('item lastEntriesFilter()', () => {
it('should return one entry for the given item', async() => {
it('should return two entry for the given item', async() => {
const minDate = Date.vnNew();
minDate.setHours(0, 0, 0, 0);
const maxDate = Date.vnNew();
@ -13,7 +13,7 @@ describe('item lastEntriesFilter()', () => {
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
const result = await models.Item.lastEntriesFilter(filter, options);
expect(result.length).toEqual(1);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
@ -22,7 +22,7 @@ describe('item lastEntriesFilter()', () => {
}
});
it('should return five entries for the given item', async() => {
it('should return six entries for the given item', async() => {
const minDate = Date.vnNew();
minDate.setHours(0, 0, 0, 0);
minDate.setMonth(minDate.getMonth() - 2, 1);
@ -37,7 +37,7 @@ describe('item lastEntriesFilter()', () => {
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
const result = await models.Item.lastEntriesFilter(filter, options);
expect(result.length).toEqual(5);
expect(result.length).toEqual(6);
await tx.rollback();
} catch (e) {