Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 1891-worker_time_control_tests
This commit is contained in:
commit
c04640bd62
|
@ -0,0 +1,34 @@
|
|||
DROP procedure IF EXISTS `vn`.`buy_notifyPassport`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`buy_notifyPassport`(
|
||||
IN vBuyFk INT,
|
||||
IN vItemFk INT,
|
||||
IN vStickers SMALLINT,
|
||||
IN vPacking SMALLINT
|
||||
)
|
||||
BEGIN
|
||||
INSERT INTO vn.mail(`subject`,`body`,`sender`)
|
||||
SELECT 'Solicitar pasaporte',
|
||||
CONCAT(
|
||||
'Etiquetas: ', IFNULL(vStickers, 0),
|
||||
', Packing: ', IFNULL(vPacking, 0),
|
||||
', Nombre: ', IFNULL(i.`name`, 0),
|
||||
', buy_edi: ', IFNULL(e.id, 0),
|
||||
', Nombre botánico: ', IFNULL(g.latin_genus_name, ''), ' ', IFNULL(s.latin_species_name, ''),
|
||||
', Productor: ',IFNULL(es.company_name, IFNULL(p.`name`, ''))
|
||||
)
|
||||
,'ekt@verdnatura.es'
|
||||
FROM item i
|
||||
LEFT JOIN itemBotanical ib ON ib.itemFk = i.id
|
||||
LEFT JOIN edi.genus g ON g.genus_id = ib.genusFk
|
||||
LEFT JOIN edi.specie s ON IFNULL(s.specie_id, ib.specieFk) = ib.specieFk
|
||||
LEFT JOIN producer p ON p.id = i.producerFk
|
||||
LEFT JOIN buy b ON b.id = vBuyFk
|
||||
LEFT JOIN edi.ekt e ON b.ektFk = e.id
|
||||
LEFT JOIN edi.supplier es ON es.supplier_id = e.pro
|
||||
WHERE i.id = vItemFk;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
DROP function IF EXISTS `vn`.`clientGetMana`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`clientGetMana`(vClient INT) RETURNS decimal(10,2)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve el mana del cliente.
|
||||
*
|
||||
* @param vClient Id del cliente
|
||||
* @return Mana del cliente
|
||||
*/
|
||||
DECLARE vMana DECIMAL(10,2);
|
||||
DECLARE vFromDated DATE;
|
||||
DECLARE vHasMana BOOLEAN;
|
||||
DECLARE vManaComponent INT;
|
||||
DECLARE vAutoManaComponent INT;
|
||||
DECLARE vManaBank INT;
|
||||
DECLARE vManaGreugeType INT;
|
||||
|
||||
SELECT id INTO vManaGreugeType FROM greugeType WHERE code = 'mana';
|
||||
SELECT id INTO vManaBank FROM bank WHERE code = 'mana';
|
||||
SELECT id INTO vManaComponent FROM component WHERE code = 'mana';
|
||||
SELECT id INTO vAutoManaComponent FROM component WHERE code = 'autoMana';
|
||||
|
||||
SELECT COUNT(*) INTO vHasMana
|
||||
FROM `client` c
|
||||
WHERE c.id = vClient AND c.typeFk = 'normal';
|
||||
|
||||
IF NOT vHasMana THEN
|
||||
RETURN 0;
|
||||
END IF;
|
||||
|
||||
SELECT max(dated) INTO vFromDated
|
||||
FROM clientManaCache;
|
||||
|
||||
SELECT sum(mana) INTO vMana
|
||||
FROM
|
||||
(
|
||||
SELECT mana
|
||||
FROM clientManaCache
|
||||
WHERE clientFk = vClient
|
||||
AND dated = vFromDated
|
||||
UNION ALL
|
||||
SELECT s.quantity * value
|
||||
FROM ticket t
|
||||
JOIN address a ON a.id = t.addressFk
|
||||
JOIN sale s on s.ticketFk = t.id
|
||||
JOIN saleComponent sc on sc.saleFk = s.id
|
||||
WHERE sc.componentFk IN (vManaComponent, vAutoManaComponent)
|
||||
AND t.shipped > vFromDated
|
||||
AND t.shipped < TIMESTAMPADD(DAY,1,CURDATE())
|
||||
AND a.clientFk = vClient
|
||||
UNION ALL
|
||||
SELECT - amountPaid
|
||||
FROM receipt r
|
||||
JOIN `client` c ON c.id = r.clientFk
|
||||
WHERE r.bankFk = vManaBank
|
||||
AND r.payed > vFromDated
|
||||
AND r.payed <= CURDATE()
|
||||
AND c.id = vClient
|
||||
UNION ALL
|
||||
SELECT g.amount
|
||||
FROM greuge g
|
||||
JOIN client c ON c.id = g.clientFk
|
||||
WHERE g.greugeTypeFk = vManaGreugeType
|
||||
AND g.shipped > vFromDated
|
||||
AND g.shipped <= CURDATE()
|
||||
AND c.id = vClient
|
||||
) sub;
|
||||
RETURN IFNULL(vMana,0);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
DROP function IF EXISTS `vn`.`bionicCalcReverse`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`bionicCalcReverse`(vWarehouse INT,
|
||||
vMargin DECIMAL(10,3),
|
||||
vRetailedPrice DECIMAL(10,3),
|
||||
vM3 DECIMAL(10,3),
|
||||
vAddress INT,
|
||||
vAgencyMode INT) RETURNS decimal(10,3)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
DECLARE vGeneralInflationCoeficient INT;
|
||||
DECLARE vVerdnaturaVolumeBox BIGINT;
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vComponentRecovery VARCHAR(50) DEFAULT 'debtCollection';
|
||||
DECLARE vComponentMana VARCHAR(50) DEFAULT 'autoMana';
|
||||
DECLARE vComponentPort VARCHAR(50) DEFAULT 'delivery';
|
||||
DECLARE vComponentMargin VARCHAR(50) DEFAULT 'margin';
|
||||
DECLARE vComponentCost VARCHAR(50) DEFAULT 'purchaseValue';
|
||||
DECLARE vComponentCostValue DECIMAL(10,2);
|
||||
DECLARE vItem INT DEFAULT 98;
|
||||
DECLARE vItemCarryBox INT;
|
||||
|
||||
SELECT generalInflationCoeFicient, verdnaturaVolumeBox, itemCarryBox
|
||||
INTO vGeneralInflationCoeficient, vVerdnaturaVolumeBox, vItemCarryBox
|
||||
FROM bionicConfig;
|
||||
|
||||
SELECT clientFk INTO vClientFk FROM address WHERE id = vAddress;
|
||||
|
||||
-- Creamos la tabla tmp.bionicComponent
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.bionicComponent;
|
||||
CREATE TEMPORARY TABLE tmp.bionicComponent(
|
||||
`warehouseFk` smallint(5) unsigned NOT NULL,
|
||||
`itemFk` int(11) NOT NULL,
|
||||
`componentFk` int(10) unsigned NOT NULL,
|
||||
`value` decimal(10,4) NOT NULL,
|
||||
UNIQUE KEY `itemWarehouseComponent` (`itemFk`,`warehouseFk`,`componentFk`) USING HASH,
|
||||
KEY `itemWarehouse` (`itemFk`,`warehouseFk`) USING BTREE
|
||||
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
-- Margin
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, id, vMargin
|
||||
FROM component
|
||||
WHERE code = vComponentMargin;
|
||||
|
||||
-- Recobro
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, c.id, ROUND(LEAST(cr.recobro,0.25), 3)
|
||||
FROM bi.claims_ratio cr
|
||||
JOIN component c ON c.code = vComponentRecovery
|
||||
WHERE cr.Id_Cliente = vClientFk AND cr.recobro > 0.009;
|
||||
|
||||
-- Componente de maná automático, en función del maná acumulado por el comercial.
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, co.id, ROUND(ms.prices_modifier_rate, 3)
|
||||
FROM client c
|
||||
JOIN bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador
|
||||
JOIN component co ON co.code = vComponentMana
|
||||
WHERE ms.prices_modifier_activated AND c.id = vClientFk LIMIT 1;
|
||||
|
||||
-- Reparto
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, co.id, vGeneralInflationCoeficient
|
||||
* ROUND(
|
||||
vM3
|
||||
* az.price
|
||||
* az.inflation
|
||||
/ vVerdnaturaVolumeBox, 4
|
||||
)
|
||||
FROM agencyMode ag
|
||||
JOIN address a ON a.id = vAddress AND ag.id = vAgencyMode
|
||||
JOIN agencyProvince ap ON ap.agencyFk = ag.agencyFk
|
||||
AND ap.warehouseFk = vWarehouse AND ap.provinceFk = a.provinceFk
|
||||
JOIN agencyModeZone az ON az.agencyModeFk = vAgencyMode
|
||||
AND az.zone = ap.zone AND az.itemFk = 71 AND az.warehouseFk = vWarehouse
|
||||
JOIN component co ON co.code = vComponentPort;
|
||||
|
||||
-- Coste
|
||||
SELECT vRetailedPrice - SUM(`value`) INTO vComponentCostValue
|
||||
FROM tmp.bionicComponent;
|
||||
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, id,vComponentCostValue
|
||||
FROM component
|
||||
WHERE code = vComponentCost;
|
||||
|
||||
RETURN vComponentCostValue;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
DROP procedure IF EXISTS `vn`.`buy_afterUpsert`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`buy_afterUpsert`(vSelf INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Triggered actions when a buy is updated or inserted.
|
||||
*
|
||||
* @param vSelf The buy reference
|
||||
*/
|
||||
DECLARE vEntryFk INT;
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vStickers INT;
|
||||
DECLARE vPacking INT;
|
||||
DECLARE vWarehouse INT;
|
||||
DECLARE vWarehouseOut INT;
|
||||
DECLARE vIsMerchandise BOOL;
|
||||
DECLARE vIsFeedStock BOOL;
|
||||
|
||||
SELECT entryFk, itemFk, stickers, packing
|
||||
INTO vEntryFk, vItemFk, vStickers, vPacking
|
||||
FROM buy
|
||||
WHERE id = vSelf;
|
||||
|
||||
SELECT t.warehouseInFk, t.warehouseOutFk
|
||||
INTO vWarehouse, vWarehouseOut
|
||||
FROM entry e
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
WHERE e.id = vEntryFk;
|
||||
|
||||
SELECT k.merchandise INTO vIsMerchandise
|
||||
FROM itemCategory k
|
||||
JOIN itemType it ON it.categoryFk = k.id
|
||||
JOIN item i ON i.typeFk = it.id
|
||||
WHERE i.id = vItemFk;
|
||||
IF vIsMerchandise THEN
|
||||
REPLACE bi.rotacion SET
|
||||
Id_Article = vItemFk,
|
||||
warehouse_id = vWarehouse,
|
||||
cm3 = buy_getUnitVolume(vSelf);
|
||||
END IF;
|
||||
|
||||
SELECT isFeedStock INTO vIsFeedStock
|
||||
FROM warehouse WHERE id = vWarehouseOut AND id <> 13;
|
||||
|
||||
IF vIsFeedStock AND vn2008.has_notify_passport(vItemFk, vSelf) THEN
|
||||
CALL vn.buy_notifyPassport(vSelf, vItemFk, vStickers, vPacking);
|
||||
INSERT IGNORE INTO producer(`name`)
|
||||
SELECT es.company_name
|
||||
FROM buy b
|
||||
JOIN edi.ekt be ON be.id = b.ektFk
|
||||
JOIN edi.supplier es ON es.supplier_id = be.pro
|
||||
WHERE b.id = 1;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
DROP procedure IF EXISTS `vn2008`.`notify_passport`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn2008`.`notify_passport`(
|
||||
IN vItemFk INT,
|
||||
IN vStickers SMALLINT,
|
||||
IN vPacking SMALLINT,
|
||||
IN vBuyFk INT
|
||||
)
|
||||
BEGIN
|
||||
-- DPRECATED use vn.buy_notifyPassport
|
||||
CALL vn.buy_notifyPassport(vBuyFk, vItemFk, vStickers, vPacking);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -10,6 +10,11 @@ INSERT INTO `account`.`mailConfig` (`id`, `domain`)
|
|||
VALUES
|
||||
('1', 'verdnatura.es');
|
||||
|
||||
INSERT INTO `vn`.`bionicConfig` (`generalInflationCoeficient`, `minimumDensityVolumetricWeight`, `verdnaturaVolumeBox`, `itemCarryBox`)
|
||||
VALUES
|
||||
(1.30, 167.00, 138000, 71);
|
||||
|
||||
|
||||
INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`, `lang`)
|
||||
SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com'), 'es'
|
||||
FROM `account`.`role`;
|
||||
|
@ -562,14 +567,14 @@ INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`,
|
|||
VALUES
|
||||
(1, 'beta-server', 'nightmare@mydomain.com', '200', DATE_ADD(CURDATE(),INTERVAL -1 MONTH));
|
||||
|
||||
INSERT INTO `vn`.`greugeType`(`id`, `name`)
|
||||
INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`)
|
||||
VALUES
|
||||
(1, 'Diff'),
|
||||
(2, 'Recover'),
|
||||
(3, 'Manna'),
|
||||
(4, 'Reclaim'),
|
||||
(5, 'Heritage'),
|
||||
(6, 'Miscellaneous');
|
||||
(1, 'Diff', 'diff'),
|
||||
(2, 'Recover', 'recover'),
|
||||
(3, 'Mana', 'mana'),
|
||||
(4, 'Reclaim', 'reclaim'),
|
||||
(5, 'Heritage', 'heritage'),
|
||||
(6, 'Miscellaneous', 'miscellaneous');
|
||||
|
||||
INSERT INTO `vn`.`greuge`(`id`, `clientFk`, `description`, `amount`, `shipped`, `created`, `greugeTypeFk`, `ticketFk`)
|
||||
VALUES
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
Author : Enrique Blasco BLanquer
|
||||
Date: 27 de mayo de 2019
|
||||
*/
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('checkUuid', {
|
||||
description: 'Check UUID from user',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'data',
|
||||
type: 'object',
|
||||
required: true,
|
||||
description: 'uuid,model',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: [{
|
||||
type: 'Object',
|
||||
root: true
|
||||
}],
|
||||
http: {
|
||||
path: `/checkUuid`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.checkUuid = async(ctx, data) => {
|
||||
const myUserId = ctx.req.accessToken.userId;
|
||||
// 1 Check is a registered user with a uuid
|
||||
let deviceUser = await Self.findOne({where: {userFk: myUserId, sn: data.uuid}});
|
||||
|
||||
if (deviceUser != null)
|
||||
return {'state': true, 'mng': ''};
|
||||
else {
|
||||
// 2 If it does not exist it can be for two reasons:
|
||||
// 2.1 It is the first time that the application enters so we have to register a new user associated with the user
|
||||
// 2.2 Has the user associated with a different uuid, so we deny access.
|
||||
|
||||
let device = await Self.findOne({where: {userFk: myUserId}});
|
||||
if (device != null) {
|
||||
// The device is already registered by another user, access is denied
|
||||
return {'state': false, 'mng': 'Ya estas regisgtrado en otro dispositivo, contacta con los dioses de informática.'};
|
||||
} else {
|
||||
// Check that the device is free
|
||||
let aDevice = await Self.findOne({where: {sn: data.uuid}});
|
||||
if (aDevice != null)
|
||||
return {'state': false, 'mng': 'El dispositivo esta siendo usado por otro usuario'};
|
||||
else {
|
||||
// It's the first time you access the application, insert
|
||||
/* await Self.rawSql('INSERT INTO vn2008.device (sn, model) VALUES (?,?);', [data.uuid, data.model]);*/
|
||||
await Self.create({
|
||||
sn: data.uuid,
|
||||
model: data.model,
|
||||
userFk: myUserId
|
||||
});
|
||||
|
||||
return {'state': true, 'mng': 'Nuevo dispositivo registrado'};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('device checkUuid()', () => {
|
||||
it('should return an state equal to false', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 9}}};
|
||||
let data = {'uuid': '123', 'model': 'ihpne kike molon'};
|
||||
let result = await app.models.Device.checkUuid(ctx, data);
|
||||
|
||||
expect(result.name).toBeFalsy();
|
||||
});
|
||||
});
|
|
@ -1,8 +1,6 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
require('../methods/device/checkUuid')(Self);
|
||||
|
||||
Self.rewriteDbError(function(err) {
|
||||
if (err.code === 'ER_DUP_ENTRY')
|
||||
return new UserError(``);
|
||||
|
|
|
@ -59,7 +59,7 @@ module.exports = {
|
|||
LEFT JOIN ticket t ON t.routeFk = r.id
|
||||
LEFT JOIN address a ON a.id = t.addressFk
|
||||
LEFT JOIN client c ON c.id = t.clientFk
|
||||
LEFT JOIN worker w ON w.id = vn2008.Averiguar_ComercialCliente_Id(t.clientFk, CURDATE())
|
||||
LEFT JOIN worker w ON w.id = client_getSalesPerson(t.clientFk, CURDATE())
|
||||
LEFT JOIN account.user u ON u.id = w.userFk
|
||||
LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 3
|
||||
LEFT JOIN province p ON a.provinceFk = p.id
|
||||
|
|
Loading…
Reference in New Issue