6964-hasItemOlder #2560

Merged
sergiodt merged 9 commits from 6964-hasItemOlder into test 2024-06-18 14:27:08 +00:00
7 changed files with 112 additions and 117 deletions
Showing only changes of commit cac1278c08 - Show all commits

View File

@ -2,5 +2,4 @@
USE vn; USE vn;
ALTER TABLE vn.sector ADD hasItemOlderReview BIGINT DEFAULT false NULL COMMENT 'Indica si el sector se revisa para comprobar si tiene ítems más viejos'; ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) DEFAULT 0 NOT NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.';
ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.';

View File

@ -358,5 +358,6 @@
"Select ticket or client": "Elija un ticket o un client", "Select ticket or client": "Elija un ticket o un client",
"It was not able to create the invoice": "No se pudo crear la factura", "It was not able to create the invoice": "No se pudo crear la factura",
"This PDA is already assigned to another user": "This PDA is already assigned to another user", "This PDA is already assigned to another user": "This PDA is already assigned to another user",
"ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)" "ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)",
"parkingNotExist": "parkingNotExist"
} }

View File

@ -0,0 +1,68 @@
module.exports = Self => {
Self.remoteMethod('getListItemNewer', {
description:
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
accessType: 'READ',
accepts: [{
arg: 'shelvingFk',
type: 'string',
required: true,
description: 'Shelving code'
},
{
arg: 'parking',
type: 'string',
required: true,
description: 'Parking code'
},
],
returns: {
type: 'Object',
Outdated
Review

Return array

Return array
root: true
},
http: {
path: `/getListItemNewer`,
verb: 'GET'
}
});
Self.getListItemNewer = async(shelvingFk, parking, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const isParkingToReview = await Self.rawSql(`
SELECT COUNT(p.id) parkingToReview
FROM vn.parking p
JOIN vn.sector s ON s.id = p.sectorFk
WHERE p.code = ? AND s.code = "CAMARA SECTOR D";`,
[parking], myOptions);
if (isParkingToReview[0]['parkingToReview'] > 0) {
const result = await Self.rawSql(`
WITH tItemShelving AS(
SELECT is2.itemFk, is2.created, p.sectorFK, is2.id
FROM vn.itemShelving is2
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk
WHERE is2.shelvingFk = ? AND s.code = "NAVE ALGEMESI"
Review

Pasar a una config

Pasar a una config
), tItemInSector AS (
SELECT is2.itemFk, is2.created, is2.shelvingFk
FROM vn.itemShelving is2
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk
WHERE is2.shelvingFk <> ?
AND s.code = "NAVE ALGEMESI")
Review

Pasar a una config

Pasar a una config
Review

Posat els casos en productionConfig

Posat els casos en productionConfig
SELECT ti.itemFK, tis.shelvingFk
FROM tItemShelving ti
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
JOIN vn.productionConfig pc
WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`,
[shelvingFk, shelvingFk], myOptions);
return result;
} else
return [];
};
Outdated
Review

Si no hi ha resultats de per si ja torna array vuit, no cal ficar el if else

const [isParkingToReview] = await Self.rawSql(`
    SELECT COUNT(p.id) parkingToReview
    FROM vn.parking p 
        JOIN vn.sector s ON s.id = p.sectorFk
        JOIN vn.productionConfig pc
    WHERE p.code = ? AND s.code = pc.sectorToCode;`,
[parking], myOptions);

if (isParkingToReview['parkingToReview'] < 1) return []
Si no hi ha resultats de per si ja torna array vuit, no cal ficar el if else ``` const [isParkingToReview] = await Self.rawSql(` SELECT COUNT(p.id) parkingToReview FROM vn.parking p JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.productionConfig pc WHERE p.code = ? AND s.code = pc.sectorToCode;`, [parking], myOptions); if (isParkingToReview['parkingToReview'] < 1) return [] ```
};

View File

@ -1,68 +0,0 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('hasItemOlder', {
description:
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
accessType: 'READ',
accepts: [{
arg: 'shelvingFkIn',
type: 'string',
required: true,
description: 'Shelving code'
},
{
arg: 'parking',
type: 'string',
description: 'Parking code'
},
{
arg: 'shelvingFkOut',
type: 'string',
description: 'Shelving code'
},
{
arg: 'itemFk',
type: 'integer',
description: 'Item id'
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/hasItemOlder`,
verb: 'GET'
}
});
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving');
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const result = await Self.rawSql(`
SELECT COUNT(ish.id) countItemOlder
FROM vn.itemShelving ish
JOIN (
SELECT ish.itemFk, created, shelvingFk, pickingOrder
FROM vn.itemShelving ish
JOIN vn.shelving s ON ish.shelvingFk = s.code
LEFT JOIN vn.parking p2 ON p2.id = s.parkingFk
WHERE ish.shelvingFk = ?
)sub ON sub.itemFK = ish.itemFk
JOIN vn.shelving s ON s.code = ish.shelvingFk
JOIN vn.parking p ON p.id = s.parkingFk
JOIN vn.sector s2 ON s2.id = p.sectorFk
JOIN vn.productionConfig pc ON pc.itemOlderReviewHours
WHERE ish.created + INTERVAL pc.itemOlderReviewHours HOUR < sub.created
AND (p.code <> ? OR ? IS NULL)
AND (ish.shelvingFk <> ? OR ? IS NULL)
AND (ish.itemFk = ? OR ? IS NULL)
AND (p.pickingOrder < sub.pickingOrder OR sub.pickingOrder IS NULL)
AND (s2.hasItemOlderReview)`,
[shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions);
return result[0]['countItemOlder'] > 0;
};
};

View File

@ -0,0 +1,40 @@
const {models} = require('vn-loopback/server/server');
describe('itemShelving getListItemNewer()', () => {
fit('should return true because there is an older item', async() => {
Outdated
Review

quitar fit

quitar fit
const shelving = 'NCC';
const parking = 'A-47-1';
const sectorCam = 1;
const sectorCamCode = 'CAMARA SECTOR D';
const sectorCamHigh = 9991;
const sectorCamHighCode = 'NAVE ALGEMESI';
const tx = await models.Sector.beginTransaction({});
const myOptions = {transaction: tx};
const filter = {where: {id: sectorCam}};
const filterHigh = {where: {id: sectorCamHigh}};
try {
const sectorCamBefore = await models.Sector.findOne(filter, myOptions);
await sectorCamBefore.updateAttributes({
code: sectorCamCode
}, myOptions);
const sectorCamHighBefore = await models.Sector.findOne(filterHigh, myOptions);
await sectorCamHighBefore.updateAttributes({
code: sectorCamHighCode
}, myOptions);
const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -1,45 +0,0 @@
const {models} = require('vn-loopback/server/server');
describe('itemShelving hasOlder()', () => {
it('should return false because there are not older items', async() => {
const shelvingFkIn = 'GVC';
const shelvingFkOut = 'HEJ';
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut);
expect(result).toBe(false);
});
it('should return false because there are not older items in parking', async() => {
const shelvingFkIn = 'HEJ';
const parking = '700-01';
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking);
expect(result).toBe(false);
});
it('should return true because there is an older item', async() => {
const shelvingFkIn = 'UXN';
const shelvingFkOut = 'PCC';
const parking = 'A-01-1';
const itemFk = 1;
const tx = await models.ItemShelving.beginTransaction({});
const myOptions = {transaction: tx};
const filter = {where: {shelvingFk: shelvingFkOut}
};
try {
const itemShelvingBefore = await models.ItemShelving.findOne(filter, myOptions);
await itemShelvingBefore.updateAttributes({
itemFk: itemFk
}, myOptions);
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions);
expect(result).toBe(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -4,5 +4,5 @@ module.exports = Self => {
require('../methods/item-shelving/getInventory')(Self); require('../methods/item-shelving/getInventory')(Self);
require('../methods/item-shelving/getAlternative')(Self); require('../methods/item-shelving/getAlternative')(Self);
require('../methods/item-shelving/updateFromSale')(Self); require('../methods/item-shelving/updateFromSale')(Self);
require('../methods/item-shelving/hasItemOlder')(Self); require('../methods/item-shelving/getListItemNewer')(Self);
}; };