6964-hasItemOlder #2560
|
@ -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.';
|
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
|
@ -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',
|
||||||
|
|||||||
|
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"
|
||||||
carlosap
commented
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")
|
||||||
carlosap
commented
Pasar a una config Pasar a una config
sergiodt
commented
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 [];
|
||||||
|
};
|
||||||
alexm
commented
Si no hi ha resultats de per si ja torna array vuit, no cal ficar el if else
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 []
```
|
|||||||
|
};
|
|
@ -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;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -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() => {
|
||||||
alexm
commented
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Return array