Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
This commit is contained in:
commit
5cdb0b7eb6
|
@ -1,52 +1,52 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
||||||
PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT)
|
PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Set amount = 0 to avoid overbooking sales
|
* Set amount = 0 to avoid overbooking sales
|
||||||
*
|
*
|
||||||
* @param vOrderFk hedera.order.id
|
* @param vOrderFk hedera.order.id
|
||||||
*/
|
*/
|
||||||
DECLARE vCalcFk INT;
|
DECLARE vCalcFk INT;
|
||||||
DECLARE vDone BOOL;
|
DECLARE vDone BOOL;
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
|
|
||||||
DECLARE cWarehouses CURSOR FOR
|
DECLARE cWarehouses CURSOR FOR
|
||||||
SELECT DISTINCT warehouseFk
|
SELECT DISTINCT warehouseFk
|
||||||
FROM orderRow
|
FROM orderRow
|
||||||
WHERE orderFk = vOrderFk
|
WHERE orderFk = vOrderFk
|
||||||
AND shipment = util.VN_CURDATE();
|
AND shipment = util.VN_CURDATE();
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
BEGIN
|
BEGIN
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
RESIGNAL;
|
RESIGNAL;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
OPEN cWarehouses;
|
OPEN cWarehouses;
|
||||||
checking: LOOP
|
checking: LOOP
|
||||||
SET vDone = FALSE;
|
SET vDone = FALSE;
|
||||||
|
|
||||||
FETCH cWarehouses INTO vWarehouseFk;
|
FETCH cWarehouses INTO vWarehouseFk;
|
||||||
|
|
||||||
IF vDone THEN
|
IF vDone THEN
|
||||||
LEAVE checking;
|
LEAVE checking;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, util.VN_CURDATE());
|
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, util.VN_CURDATE());
|
||||||
|
|
||||||
UPDATE orderRow r
|
UPDATE orderRow r
|
||||||
JOIN `order` o ON o.id = r.orderFk
|
JOIN `order` o ON o.id = r.orderFk
|
||||||
JOIN orderConfig oc
|
JOIN orderConfig oc
|
||||||
JOIN cache.available a ON a.calc_id = vCalcFk AND a.item_id = r.itemFk
|
JOIN cache.available a ON a.calc_id = vCalcFk AND a.item_id = r.itemFk
|
||||||
SET r.amount = 0
|
SET r.amount = 0
|
||||||
WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < util.VN_NOW()
|
WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < util.VN_NOW()
|
||||||
AND a.available <= 0
|
AND a.available <= 0
|
||||||
AND r.warehouseFk = vWarehouseFk
|
AND r.warehouseFk = vWarehouseFk
|
||||||
AND r.orderFk = vOrderFk;
|
AND r.orderFk = vOrderFk;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
CLOSE cWarehouses;
|
CLOSE cWarehouses;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -14,6 +14,7 @@ BEGIN
|
||||||
DECLARE vHasRows BOOL;
|
DECLARE vHasRows BOOL;
|
||||||
DECLARE vHas0Amount BOOL;
|
DECLARE vHas0Amount BOOL;
|
||||||
DECLARE vDone BOOL;
|
DECLARE vDone BOOL;
|
||||||
|
DECLARE vHas0Amount BOOL;
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
DECLARE vShipment DATE;
|
DECLARE vShipment DATE;
|
||||||
DECLARE vShipmentDayEnd DATETIME;
|
DECLARE vShipmentDayEnd DATETIME;
|
||||||
|
@ -111,7 +112,7 @@ BEGIN
|
||||||
IF vHas0Amount THEN
|
IF vHas0Amount THEN
|
||||||
CALL util.throw('Remove lines with quantity = 0 before confirming');
|
CALL util.throw('Remove lines with quantity = 0 before confirming');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
START TRANSACTION;
|
START TRANSACTION;
|
||||||
|
|
||||||
CALL order_checkEditable(vSelf);
|
CALL order_checkEditable(vSelf);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterInsert`
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterInsert`
|
||||||
AFTER INSERT ON `orderRow`
|
AFTER INSERT ON `orderRow`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
UPDATE `order`
|
UPDATE `order`
|
||||||
SET rowUpdated = NOW()
|
SET rowUpdated = NOW()
|
||||||
WHERE id = NEW.orderFk;
|
WHERE id = NEW.orderFk;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -45,7 +45,7 @@ BEGIN
|
||||||
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
||||||
WHERE t.id = vParamFk
|
WHERE t.id = vParamFk
|
||||||
AND t.shipped >= vYesterday
|
AND t.shipped >= vYesterday
|
||||||
UNION ALL
|
UNION
|
||||||
SELECT t.id ticketFk,
|
SELECT t.id ticketFk,
|
||||||
IF(NOT(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
IF(NOT(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
||||||
am.name agencyName,
|
am.name agencyName,
|
||||||
|
@ -66,7 +66,7 @@ BEGIN
|
||||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||||
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
||||||
WHERE tc.collectionFk = vParamFk
|
WHERE tc.collectionFk = vParamFk
|
||||||
UNION ALL
|
UNION
|
||||||
SELECT sg.ticketFk,
|
SELECT sg.ticketFk,
|
||||||
NULL `level`,
|
NULL `level`,
|
||||||
am.name agencyName,
|
am.name agencyName,
|
||||||
|
@ -83,6 +83,7 @@ BEGIN
|
||||||
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
||||||
LEFT JOIN vn.client c ON c.id = t.clientFk
|
LEFT JOIN vn.client c ON c.id = t.clientFk
|
||||||
WHERE sc.id = vParamFk
|
WHERE sc.id = vParamFk
|
||||||
AND t.shipped >= vYesterday;
|
AND t.shipped >= vYesterday
|
||||||
|
GROUP BY ticketFk;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingSale_deleteAdded`(
|
||||||
|
vSelf INT(11)
|
||||||
|
)
|
||||||
|
proc: BEGIN
|
||||||
|
/**
|
||||||
|
* Borra una reservea devolviendo la cantidad al itemShelving
|
||||||
|
*
|
||||||
|
* @param vSelf Identificador del itemShelvingSale
|
||||||
|
*/
|
||||||
|
DECLARE vSaleFk INT;
|
||||||
|
DECLARE vHasSalesPicked BOOL;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
ROLLBACK;
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
|
START TRANSACTION;
|
||||||
|
|
||||||
|
SELECT iss.saleFk INTO vSaleFk
|
||||||
|
FROM itemShelvingSale iss
|
||||||
|
JOIN sale s ON s.id = iss.saleFk
|
||||||
|
WHERE iss.id = vSelf AND s.isAdded
|
||||||
|
FOR UPDATE;
|
||||||
|
|
||||||
|
IF vSaleFk IS NULL THEN
|
||||||
|
CALL util.throw('The sale can not be deleted');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT COUNT(*) INTO vHasSalesPicked
|
||||||
|
FROM itemShelvingSale
|
||||||
|
WHERE saleFk = vSaleFk AND isPicked;
|
||||||
|
|
||||||
|
IF vHasSalesPicked THEN
|
||||||
|
CALL util.throw('A sale with picked sales cannot be deleted');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
UPDATE itemShelvingSale iss
|
||||||
|
JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
|
||||||
|
SET ish.available = ish.available + iss.quantity
|
||||||
|
WHERE iss.saleFk = vSaleFk;
|
||||||
|
|
||||||
|
DELETE FROM sale WHERE id = vSaleFk;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,3 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
ALTER TABLE hedera.`order` ADD IF NOT EXISTS rowUpdated DATETIME NULL
|
||||||
|
COMMENT 'Timestamp for last updated record in orderRow table';
|
|
@ -0,0 +1,45 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('getWithPackaging', {
|
||||||
|
description: 'Returns the list of suppliers with an entry of type packaging',
|
||||||
|
accessType: 'READ',
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/getWithPackaging`,
|
||||||
|
verb: 'GET'
|
||||||
|
},
|
||||||
|
nolimit: true
|
||||||
|
});
|
||||||
|
Self.getWithPackaging = async options => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
const oneYearAgo = new Date();
|
||||||
|
oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1);
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const entries = await models.Entry.find({
|
||||||
|
where: {
|
||||||
|
typeFk: 'packaging',
|
||||||
|
created: {gte: oneYearAgo}
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
relation: 'supplier',
|
||||||
|
scope: {
|
||||||
|
fields: ['id', 'name']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fields: {supplierFk: true}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const result = entries.map(item => ({
|
||||||
|
id: item.supplier().id,
|
||||||
|
name: item.supplier().name
|
||||||
|
}));
|
||||||
|
return Array.from(new Map(result.map(entry => [entry.id, entry])).values());
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('Supplier getWithPackaging()', () => {
|
||||||
|
it('should return a list of suppliers with an entry of type packaging', async() => {
|
||||||
|
const typeFk = 'packaging';
|
||||||
|
|
||||||
|
const tx = await models.Supplier.beginTransaction({});
|
||||||
|
const myOptions = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const entry = await models.Entry.findOne(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
id: 1
|
||||||
|
},
|
||||||
|
myOptions
|
||||||
|
});
|
||||||
|
|
||||||
|
await entry.updateAttributes({
|
||||||
|
typeFk: typeFk,
|
||||||
|
created: new Date()
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await models.Supplier.getWithPackaging(myOptions);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(1);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -12,6 +12,7 @@ module.exports = Self => {
|
||||||
require('../methods/supplier/campaignMetricsEmail')(Self);
|
require('../methods/supplier/campaignMetricsEmail')(Self);
|
||||||
require('../methods/supplier/newSupplier')(Self);
|
require('../methods/supplier/newSupplier')(Self);
|
||||||
require('../methods/supplier/getItemsPackaging')(Self);
|
require('../methods/supplier/getItemsPackaging')(Self);
|
||||||
|
require('../methods/supplier/getWithPackaging')(Self);
|
||||||
|
|
||||||
Self.validatesPresenceOf('name', {
|
Self.validatesPresenceOf('name', {
|
||||||
message: 'The social name cannot be empty'
|
message: 'The social name cannot be empty'
|
||||||
|
|
Loading…
Reference in New Issue