refactor: refs #7258 Deleted all dependences of vn2008 schema #2362
|
@ -146,7 +146,7 @@ INSERT INTO `vn`.`businessReasonEnd` (`id`, `reason`)
|
||||||
('2', 'No supera PP empresa'),
|
('2', 'No supera PP empresa'),
|
||||||
('3', 'Despido');
|
('3', 'Despido');
|
||||||
|
|
||||||
INSERT INTO `vn2008`.`payroll_categorias` (`codcategoria`, `descripcion`, `Tarifa`)
|
INSERT INTO `vn`.`payrollCategories` (`id`, `description`, `rate`)
|
||||||
VALUES
|
VALUES
|
||||||
('11', 'INFORMATICA', '2'),
|
('11', 'INFORMATICA', '2'),
|
||||||
('12', 'AUX INFORMATICA', '7');
|
('12', 'AUX INFORMATICA', '7');
|
||||||
|
|
|
@ -11,7 +11,6 @@ CREATE ROLE 'salix';
|
||||||
GRANT 'salix' TO 'root'@'%';
|
GRANT 'salix' TO 'root'@'%';
|
||||||
SET DEFAULT ROLE 'salix' FOR 'root'@'%';
|
SET DEFAULT ROLE 'salix' FOR 'root'@'%';
|
||||||
|
|
||||||
CREATE SCHEMA IF NOT EXISTS `vn2008`;
|
|
||||||
CREATE SCHEMA IF NOT EXISTS `tmp`;
|
CREATE SCHEMA IF NOT EXISTS `tmp`;
|
||||||
|
|
||||||
UPDATE `util`.`config`
|
UPDATE `util`.`config`
|
||||||
|
|
|
@ -91,15 +91,15 @@ BEGIN
|
||||||
-- Recobro
|
-- Recobro
|
||||||
UPDATE bi.Greuge_Evolution ge
|
UPDATE bi.Greuge_Evolution ge
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT cs.Id_Cliente, sum(Valor * Cantidad) as Importe
|
SELECT a.clientFk Id_Cliente, sum(sc.value * s.quantity) as Importe
|
||||||
FROM vn.ticket t
|
FROM vn.ticket t
|
||||||
JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.addressFk
|
JOIN vn.address a on a.id = t.addressFk
|
||||||
JOIN vn2008.Movimientos m on m.Id_Ticket = t.id
|
JOIN vn.sale s on s.ticketFk = t.id
|
||||||
JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento
|
JOIN vn.saleComponent sc on sc.saleFk = s.id
|
||||||
WHERE t.shipped >= datFEC
|
WHERE t.shipped >= datFEC
|
||||||
AND t.shipped < datFEC_TOMORROW
|
AND t.shipped < datFEC_TOMORROW
|
||||||
AND mc.Id_Componente = 17 -- Recobro
|
AND sc.componentFk = 17 -- Recobro
|
||||||
GROUP BY cs.Id_Cliente
|
GROUP BY a.clientFk
|
||||||
) sub using(Id_Cliente)
|
) sub using(Id_Cliente)
|
||||||
SET Recobro = Importe
|
SET Recobro = Importe
|
||||||
WHERE ge.Fecha = datFEC;
|
WHERE ge.Fecha = datFEC;
|
||||||
|
|
|
@ -24,7 +24,7 @@ BEGIN
|
||||||
WHERE Periodo < vMaxPeriod;
|
WHERE Periodo < vMaxPeriod;
|
||||||
|
|
||||||
SELECT MIN(period) INTO vCurrentPeriod
|
SELECT MIN(period) INTO vCurrentPeriod
|
||||||
FROM vn2008.time
|
FROM vn.time
|
||||||
WHERE period > vPreviousPeriod;
|
WHERE period > vPreviousPeriod;
|
||||||
|
|
||||||
SET vYear = FLOOR(vCurrentPeriod / 100);
|
SET vYear = FLOOR(vCurrentPeriod / 100);
|
||||||
|
@ -66,7 +66,7 @@ BEGIN
|
||||||
WHERE periodo < vMaxPeriod;
|
WHERE periodo < vMaxPeriod;
|
||||||
|
|
||||||
SELECT MIN(period) INTO vCurrentPeriod
|
SELECT MIN(period) INTO vCurrentPeriod
|
||||||
FROM vn2008.time
|
FROM vn.time
|
||||||
WHERE period > vPreviousPeriod;
|
WHERE period > vPreviousPeriod;
|
||||||
|
|
||||||
SET vYear = FLOOR(vCurrentPeriod / 100);
|
SET vYear = FLOOR(vCurrentPeriod / 100);
|
||||||
|
@ -108,7 +108,7 @@ BEGIN
|
||||||
WHERE periodo < vMaxPeriod;
|
WHERE periodo < vMaxPeriod;
|
||||||
|
|
||||||
SELECT MIN(period) INTO vCurrentPeriod
|
SELECT MIN(period) INTO vCurrentPeriod
|
||||||
FROM vn2008.time
|
FROM vn.time
|
||||||
WHERE period > vPreviousPeriod;
|
WHERE period > vPreviousPeriod;
|
||||||
|
|
||||||
SET vYear = FLOOR(vCurrentPeriod / 100);
|
SET vYear = FLOOR(vCurrentPeriod / 100);
|
||||||
|
@ -156,7 +156,7 @@ BEGIN
|
||||||
WHERE periodo < vMaxPeriod;
|
WHERE periodo < vMaxPeriod;
|
||||||
|
|
||||||
SELECT MIN(period) INTO vCurrentPeriod
|
SELECT MIN(period) INTO vCurrentPeriod
|
||||||
FROM vn2008.time
|
FROM vn.time
|
||||||
WHERE period > vPreviousPeriod;
|
WHERE period > vPreviousPeriod;
|
||||||
|
|
||||||
SET vYear = FLOOR(vCurrentPeriod / 100);
|
SET vYear = FLOOR(vCurrentPeriod / 100);
|
||||||
|
@ -198,7 +198,7 @@ BEGIN
|
||||||
WHERE periodo < vMaxPeriod;
|
WHERE periodo < vMaxPeriod;
|
||||||
|
|
||||||
SELECT MIN(period) INTO vCurrentPeriod
|
SELECT MIN(period) INTO vCurrentPeriod
|
||||||
FROM vn2008.time
|
FROM vn.time
|
||||||
WHERE period > vPreviousPeriod;
|
WHERE period > vPreviousPeriod;
|
||||||
|
|
||||||
SET vYear = FLOOR(vCurrentPeriod / 100);
|
SET vYear = FLOOR(vCurrentPeriod / 100);
|
||||||
|
|
|
@ -23,31 +23,31 @@ BEGIN
|
||||||
Importe
|
Importe
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
tp.Tipo AS Familia,
|
it.name,
|
||||||
r.reino AS Reino,
|
ic.name,
|
||||||
tr.CodigoTrabajador AS Comercial,
|
w.code,
|
||||||
tr2.CodigoTrabajador AS Comprador,
|
w2.code,
|
||||||
p.name AS Provincia,
|
p.name,
|
||||||
w.name AS almacen,
|
wa.name,
|
||||||
tm.year AS Año,
|
tm.year,
|
||||||
tm.month AS Mes,
|
tm.month,
|
||||||
tm.week AS Semana,
|
tm.week,
|
||||||
dm.description AS Vista,
|
dm.description,
|
||||||
bt.importe AS Importe
|
bt.importe
|
||||||
FROM bs.ventas bt
|
FROM bs.ventas bt
|
||||||
LEFT JOIN vn2008.Tipos tp ON tp.tipo_id = bt.tipo_id
|
LEFT JOIN vn.itemType it ON it.id = bt.tipo_id
|
||||||
LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
|
LEFT JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
||||||
LEFT JOIN vn2008.Clientes c on c.Id_Cliente = bt.Id_Cliente
|
LEFT JOIN vn.client c on c.id = bt.Id_Cliente
|
||||||
LEFT JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = c.Id_Trabajador
|
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||||
LEFT JOIN vn2008.Trabajadores tr2 ON tr2.Id_Trabajador = tp.Id_Trabajador
|
LEFT JOIN vn.worker w2 ON w2.id = it.workerFk
|
||||||
JOIN vn2008.time tm ON tm.date = bt.fecha
|
JOIN vn.time tm ON tm.dated = bt.fecha
|
||||||
JOIN vn2008.Movimientos m ON m.Id_Movimiento = bt.Id_Movimiento
|
JOIN vn.sale s ON s.id = bt.Id_Movimiento
|
||||||
LEFT JOIN vn.ticket t ON t.id = m.Id_Ticket
|
LEFT JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
JOIN vn2008.Agencias a ON a.Id_Agencia = t.agencyModeFk
|
JOIN vn.agencyMode am ON am.id = t.agencyModeFk
|
||||||
LEFT JOIN vn.deliveryMethod dm ON dm.id = a.Vista
|
LEFT JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||||
LEFT JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = t.addressFk
|
LEFT JOIN vn.address a ON a.id = t.addressFk
|
||||||
LEFT JOIN vn2008.province p ON p.province_id = cs.province_id
|
LEFT JOIN vn.province p ON p.id = a.provinceFk
|
||||||
LEFT JOIN vn.warehouse w ON w.id = t.warehouseFk
|
LEFT JOIN vn.warehouse wa ON wa.id = t.warehouseFk
|
||||||
WHERE bt.fecha >= vLastMonth AND r.mercancia;
|
WHERE bt.fecha >= vLastMonth AND ic.merchandise;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -13,46 +13,45 @@ BEGIN
|
||||||
|
|
||||||
INSERT INTO vn.greuge(shipped, clientFk, description,
|
INSERT INTO vn.greuge(shipped, clientFk, description,
|
||||||
amount, greugeTypeFk, ticketFk)
|
amount, greugeTypeFk, ticketFk)
|
||||||
SELECT cm.Fecha
|
SELECT c.ticketCreated
|
||||||
, cm.Id_Cliente
|
, c.clientFk
|
||||||
, concat('Claim ',cm.id,' : ', m.Concepte)
|
, concat('Claim ', c.id,' : ', s.concept)
|
||||||
,round( -1 * ((sensib -1)/4) * Cantidad *
|
,round( -1 * ((c.responsibility -1)/4) * s.quantity *
|
||||||
Preu * (100 - Descuento) / 100, 2) AS Reclamaciones
|
s.price * (100 - s.discount) / 100, 2)
|
||||||
, 4
|
, 4
|
||||||
, m.Id_Ticket
|
, s.ticketFk
|
||||||
FROM vn2008.Movimientos m
|
FROM vn.sale s
|
||||||
JOIN vn2008.cl_act ca USING(Id_Movimiento)
|
JOIN vn.claimEnd ce ON ce.saleFk = s.id
|
||||||
JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
|
JOIN vn.claim c ON c.id = ce.claimFk
|
||||||
WHERE ca.cl_sol_id NOT IN (1,5)
|
WHERE ce.claimDestinationFk NOT IN (1,5)
|
||||||
AND ca.greuge = 0
|
AND NOT ce.isGreuge
|
||||||
AND cm.cl_est_id = 3;
|
AND c.claimStateFk = 3;
|
||||||
|
|
||||||
-- Reclamaciones que pasan a Maná
|
-- Reclamaciones que pasan a Maná
|
||||||
|
|
||||||
INSERT INTO vn.greuge(shipped, clientFk, description,
|
INSERT INTO vn.greuge(shipped, clientFk, description,
|
||||||
amount, greugeTypeFk, ticketFk)
|
amount, greugeTypeFk, ticketFk)
|
||||||
SELECT cm.Fecha
|
SELECT c.ticketCreated
|
||||||
, cm.Id_Cliente
|
, c.clientFk
|
||||||
, concat('Claim_mana ',cm.id,' : ', m.Concepte)
|
, concat('Claim_mana ',c.id,' : ', s.concept)
|
||||||
,round( ((sensib -1)/4) * Cantidad * Preu * (100 - Descuento) / 100, 2)
|
,round( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2)
|
||||||
AS Reclamaciones
|
|
||||||
,3
|
,3
|
||||||
,m.Id_Ticket
|
,s.ticketFk
|
||||||
FROM vn2008.Movimientos m
|
FROM vn.sale s
|
||||||
JOIN vn2008.cl_act ca USING(Id_Movimiento)
|
JOIN vn.claimEnd ce ON ce.saleFk = s.id
|
||||||
JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
|
JOIN vn.claim c ON c.id = ce.claimFk
|
||||||
WHERE ca.cl_sol_id NOT IN (1,5)
|
WHERE ce.claimDestinationFk NOT IN (1,5)
|
||||||
AND ca.greuge = 0
|
AND NOT ce.isGreuge
|
||||||
AND cm.cl_est_id = 3
|
AND c.claimStateFk = 3
|
||||||
AND cm.mana;
|
AND c.isChargedToMana;
|
||||||
|
|
||||||
-- Marcamos para no repetir
|
-- Marcamos para no repetir
|
||||||
UPDATE vn2008.cl_act ca
|
UPDATE vn.claimEnd ce
|
||||||
JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
|
JOIN vn.claim c ON c.id = ce.claimFk
|
||||||
SET greuge = 1
|
SET c.isChargedToMana = TRUE
|
||||||
WHERE ca.cl_sol_id NOT IN (1,5)
|
WHERE ce.claimDestinationFk NOT IN (1,5)
|
||||||
AND ca.greuge = 0
|
AND NOT ce.isGreuge
|
||||||
AND cm.cl_est_id = 3;
|
AND c.claimStateFk = 3;
|
||||||
|
|
||||||
-- Recobros
|
-- Recobros
|
||||||
|
|
||||||
|
@ -60,17 +59,17 @@ BEGIN
|
||||||
CREATE TEMPORARY TABLE tmp.ticket_list
|
CREATE TEMPORARY TABLE tmp.ticket_list
|
||||||
(PRIMARY KEY (Id_Ticket))
|
(PRIMARY KEY (Id_Ticket))
|
||||||
SELECT DISTINCT t.id Id_Ticket
|
SELECT DISTINCT t.id Id_Ticket
|
||||||
FROM vn2008.Movimientos_componentes mc
|
FROM vn.saleComponent sc
|
||||||
JOIN vn2008.Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento
|
JOIN vn.sale s ON sc.saleFk = s.id
|
||||||
JOIN vn.ticket t ON t.id = m.Id_Ticket
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
JOIN vn.ticketLastState ts ON ts.ticketFk = t.id
|
JOIN vn.ticketLastState ts ON ts.ticketFk = t.id
|
||||||
JOIN vn.ticketTracking tt ON tt.id = ts.ticketTrackingFk
|
JOIN vn.ticketTracking tt ON tt.id = ts.ticketTrackingFk
|
||||||
JOIN vn.state s ON s.id = tt.stateFk
|
JOIN vn.state st ON st.id = tt.stateFk
|
||||||
WHERE mc.Id_Componente = 17
|
WHERE sc.componentFk = 17
|
||||||
AND mc.greuge = 0
|
AND sc.isGreuge = 0
|
||||||
AND t.shipped >= '2016-10-01'
|
AND t.shipped >= '2016-10-01'
|
||||||
AND t.shipped < util.VN_CURDATE()
|
AND t.shipped < util.VN_CURDATE()
|
||||||
AND s.alertLevel >= 3;
|
AND st.alertLevel >= 3;
|
||||||
|
|
||||||
DELETE g.*
|
DELETE g.*
|
||||||
FROM vn.greuge g
|
FROM vn.greuge g
|
||||||
|
@ -80,24 +79,24 @@ BEGIN
|
||||||
INSERT INTO vn.greuge(clientFk, description, amount,shipped,
|
INSERT INTO vn.greuge(clientFk, description, amount,shipped,
|
||||||
greugeTypeFk, ticketFk)
|
greugeTypeFk, ticketFk)
|
||||||
SELECT t.clientFk
|
SELECT t.clientFk
|
||||||
,concat('recobro ', m.Id_Ticket), - round(SUM(mc.Valor*Cantidad),2)
|
,concat('recobro ', s.ticketFk), - round(SUM(sc.value*s.quantity),2)
|
||||||
AS dif
|
AS dif,
|
||||||
,date(t.shipped)
|
date(t.shipped)
|
||||||
, 2
|
, 2
|
||||||
,tt.Id_Ticket
|
,tt.Id_Ticket
|
||||||
FROM vn2008.Movimientos m
|
FROM vn.sale s
|
||||||
JOIN vn.ticket t ON t.id = m.Id_Ticket
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.id
|
JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.id
|
||||||
JOIN vn2008.Movimientos_componentes mc
|
JOIN vn.saleComponent sc
|
||||||
ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente = 17
|
ON sc.saleFk = s.id AND sc.componentFk = 17
|
||||||
GROUP BY t.id
|
GROUP BY t.id
|
||||||
HAVING ABS(dif) > 1;
|
HAVING ABS(dif) > 1;
|
||||||
|
|
||||||
UPDATE vn2008.Movimientos_componentes mc
|
UPDATE vn.saleComponent sc
|
||||||
JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
|
JOIN vn.sale s ON s.id = sc.saleFk
|
||||||
JOIN tmp.ticket_list tt ON tt.Id_Ticket = m.Id_Ticket
|
JOIN tmp.ticket_list tt ON tt.Id_Ticket = s.ticketFk
|
||||||
SET greuge = 1
|
SET sc.isGreuge = 1
|
||||||
WHERE Id_Componente = 17;
|
WHERE sc.componentFk = 17;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Recalculamos la ratio de las reclamaciones, que luego
|
* Recalculamos la ratio de las reclamaciones, que luego
|
||||||
|
@ -105,26 +104,25 @@ BEGIN
|
||||||
*/
|
*/
|
||||||
|
|
||||||
REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro)
|
REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro)
|
||||||
SELECT Id_Cliente, 0,0,0,0
|
SELECT id, 0,0,0,0
|
||||||
FROM vn2008.Clientes;
|
FROM vn.client;
|
||||||
|
|
||||||
REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro)
|
REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro)
|
||||||
SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones,
|
SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones,
|
||||||
round(Reclamaciones / (12*fm.Consumo),4) AS Ratio, 0
|
round(Reclamaciones / (12*fm.Consumo),4), 0
|
||||||
FROM bi.facturacion_media_anual fm
|
FROM bi.facturacion_media_anual fm
|
||||||
LEFT JOIN(
|
LEFT JOIN(
|
||||||
SELECT cm.Id_Cliente, round(sum(-1 * ((sensib -1)/4) *
|
SELECT c.clientFk, round(sum(-1 * ((c.responsibility -1)/4) *
|
||||||
Cantidad * Preu * (100 - Descuento) / 100))
|
s.quantity * s.price * (100 - s.discount) / 100))
|
||||||
AS Reclamaciones
|
AS Reclamaciones
|
||||||
FROM vn2008.Movimientos m
|
FROM vn.sale s
|
||||||
JOIN vn2008.cl_act ca
|
JOIN vn.claimEnd ce ON ce.saleFk = s.id
|
||||||
ON ca.Id_Movimiento = m.Id_Movimiento
|
JOIN vn.claim c ON c.id = ce.claimFk
|
||||||
JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
|
WHERE ce.claimDestinationFk NOT IN (1,5)
|
||||||
WHERE ca.cl_sol_id NOT IN (1,5)
|
AND c.claimStateFk = 3
|
||||||
AND cm.cl_est_id = 3
|
AND c.ticketCreated >= TIMESTAMPADD(YEAR, -1, util.VN_CURDATE())
|
||||||
AND cm.Fecha >= TIMESTAMPADD(YEAR, -1, util.VN_CURDATE())
|
GROUP BY c.clientFk
|
||||||
GROUP BY cm.Id_Cliente
|
) claims ON claims.clientFk = fm.Id_Cliente;
|
||||||
) claims ON claims.Id_Cliente = fm.Id_Cliente;
|
|
||||||
|
|
||||||
|
|
||||||
-- Calculamos el porcentaje del recobro para añadirlo al precio de venta
|
-- Calculamos el porcentaje del recobro para añadirlo al precio de venta
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`clean_launcher`()
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Borra registros de las principales tablas (excepto de "ticket").
|
|
||||||
*/
|
|
||||||
CALL vn2008.clean(0);
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,32 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`comparativa_add`()
|
|
||||||
BEGIN
|
|
||||||
DECLARE lastCOMP INT; # Se trata de una variable para almacenar el ultimo valor del Periodo
|
|
||||||
DECLARE vMaxPeriod INT;
|
|
||||||
DECLARE vMaxWeek INT;
|
|
||||||
|
|
||||||
SELECT t.period, t.`week` INTO vMaxPeriod, vMaxWeek
|
|
||||||
FROM vn.`time` t
|
|
||||||
WHERE t.dated = util.VN_CURDATE();
|
|
||||||
|
|
||||||
SELECT MAX(Periodo) INTO lastCOMP FROM vn2008.Comparativa;
|
|
||||||
-- Fijaremos las ventas con más de un mes de antiguedad en la tabla Comparativa
|
|
||||||
|
|
||||||
IF lastCOMP < vMaxPeriod - 3 AND vMaxWeek > 3 THEN
|
|
||||||
|
|
||||||
REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
|
|
||||||
SELECT tm.period as Periodo, m.Id_Article, t.warehouseFk, sum(m.Cantidad), sum(v.importe)
|
|
||||||
FROM bs.ventas v
|
|
||||||
JOIN vn2008.time tm ON tm.date = v.fecha
|
|
||||||
JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento
|
|
||||||
JOIN vn2008.Tipos tp ON tp.tipo_id = v.tipo_id
|
|
||||||
JOIN vn2008.reinos r ON r.id = tp.reino_id
|
|
||||||
JOIN vn.ticket t ON t.id = m.Id_Ticket
|
|
||||||
WHERE tm.period BETWEEN lastCOMP AND vMaxPeriod - 3
|
|
||||||
AND t.clientFk NOT IN(400,200)
|
|
||||||
AND t.warehouseFk NOT IN (0,13)
|
|
||||||
GROUP BY m.Id_Article, Periodo, t.warehouseFk;
|
|
||||||
|
|
||||||
END IF;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,40 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`comparativa_add_manual`(IN vStarted DATE, IN vEnded DATE)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Recalcula la tabla Comparativa para dos valores dados
|
|
||||||
*
|
|
||||||
* @param vStarted fecha desde
|
|
||||||
* @param vEnded fecha hasta
|
|
||||||
*/
|
|
||||||
|
|
||||||
DECLARE periodStart INT;
|
|
||||||
DECLARE periodEnd INT;
|
|
||||||
|
|
||||||
-- Seleccionamos la fecha minima/maxima del periodo que vamos a consultar
|
|
||||||
|
|
||||||
SELECT t.period INTO periodStart
|
|
||||||
FROM vn.`time` t
|
|
||||||
WHERE t.dated = vStarted;
|
|
||||||
|
|
||||||
SELECT t.period INTO periodEnd
|
|
||||||
FROM vn.`time` t
|
|
||||||
WHERE t.dated = vEnded;
|
|
||||||
|
|
||||||
DELETE FROM vn2008.Comparativa
|
|
||||||
WHERE Periodo BETWEEN periodStart AND periodEnd;
|
|
||||||
|
|
||||||
INSERT INTO vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
|
|
||||||
SELECT tm.period as Periodo, m.Id_Article, t.warehouseFk, sum(m.Cantidad), sum(v.importe)
|
|
||||||
FROM bs.ventas v
|
|
||||||
JOIN vn2008.time tm ON tm.date = v.fecha
|
|
||||||
JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento
|
|
||||||
JOIN vn2008.Tipos tp ON tp.tipo_id = v.tipo_id
|
|
||||||
JOIN vn2008.reinos r ON r.id = tp.reino_id
|
|
||||||
JOIN vn.ticket t ON t.id = m.Id_Ticket
|
|
||||||
WHERE tm.period BETWEEN periodStart AND periodEnd
|
|
||||||
AND t.clientFk NOT IN(400,200)
|
|
||||||
AND t.warehouseFk NOT IN (0,13)
|
|
||||||
GROUP BY m.Id_Article, Periodo, t.warehouseFk;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -2,7 +2,7 @@ DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`defaultersFromDate`(IN vDate DATE)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`defaultersFromDate`(IN vDate DATE)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
SELECT t1.*, c.Cliente, w.code AS workerCode, c.pay_met_id,c.Vencimiento
|
SELECT t1.*, c.name Cliente, w.code workerCode, c.payMethodFk pay_met_id, c.dueDay Vencimiento
|
||||||
FROM (
|
FROM (
|
||||||
-- Filtramos aquellos clientes cuyo saldo se ha incrementado de ayer a hoy
|
-- Filtramos aquellos clientes cuyo saldo se ha incrementado de ayer a hoy
|
||||||
select * from(
|
select * from(
|
||||||
|
@ -18,7 +18,7 @@ BEGIN
|
||||||
|
|
||||||
having today.amount > 0 and difference <> 0
|
having today.amount > 0 and difference <> 0
|
||||||
) newDefaulters
|
) newDefaulters
|
||||||
)t1 left join vn2008.Clientes c ON t1.client = c.Id_Cliente
|
)t1 left join vn.client c ON c.id = t1.client
|
||||||
left join vn.worker w ON w.id = c.Id_Trabajador;
|
left join vn.worker w ON w.id = c.salesPersonFk;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -8,9 +8,10 @@ BEGIN
|
||||||
DECLARE vAmountInvoice DECIMAL(10,2);
|
DECLARE vAmountInvoice DECIMAL(10,2);
|
||||||
DECLARE vGraceDays INT;
|
DECLARE vGraceDays INT;
|
||||||
DECLARE defaulters CURSOR FOR
|
DECLARE defaulters CURSOR FOR
|
||||||
SELECT client, amount, graceDays FROM bi.defaulters d
|
SELECT d.client, d.amount, pm.graceDays
|
||||||
JOIN vn2008.Clientes c ON c.Id_Cliente = d.client
|
FROM bi.defaulters d
|
||||||
JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id
|
JOIN vn.client c ON c.id = d.client
|
||||||
|
JOIN vn.payMethod pm ON pm.id = c.payMethodFk
|
||||||
WHERE hasChanged AND date = vDate;
|
WHERE hasChanged AND date = vDate;
|
||||||
|
|
||||||
DECLARE invoices CURSOR FOR
|
DECLARE invoices CURSOR FOR
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `bi`.`last_Id_Cubo`
|
|
||||||
AS SELECT `C`.`Id_Compra` AS `Id_Compra`,
|
|
||||||
`C`.`Id_Article` AS `Id_Article`,
|
|
||||||
`tr`.`warehouse_id` AS `warehouse_id`,
|
|
||||||
`C`.`Id_Cubo` AS `Id_Cubo`,
|
|
||||||
`C`.`Packing` AS `Packing`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
`vn2008`.`Compres` `C`
|
|
||||||
JOIN `vn2008`.`Entradas` `E` ON(`C`.`Id_Entrada` = `E`.`Id_Entrada`)
|
|
||||||
)
|
|
||||||
JOIN `vn2008`.`travel` `tr` ON(`E`.`travel_id` = `tr`.`id`)
|
|
||||||
)
|
|
||||||
WHERE `C`.`Id_Cubo` IS NOT NULL
|
|
||||||
AND `C`.`Id_Cubo` <> '--'
|
|
||||||
AND `tr`.`landing` > `util`.`VN_CURDATE`() - INTERVAL 18 MONTH
|
|
||||||
ORDER BY `C`.`Id_Compra` DESC
|
|
|
@ -1,23 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `bi`.`v_ventas_contables`
|
|
||||||
AS SELECT `time`.`year` AS `year`,
|
|
||||||
`time`.`month` AS `month`,
|
|
||||||
cast(
|
|
||||||
sum(
|
|
||||||
`m`.`Cantidad` * `m`.`Preu` * (100 - `m`.`Descuento`) / 100
|
|
||||||
) AS decimal(10, 0)
|
|
||||||
) AS `importe`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
(
|
|
||||||
`vn`.`ticket` `t`
|
|
||||||
JOIN `bi`.`f_tvc` ON(`t`.`id` = `bi`.`f_tvc`.`Id_Ticket`)
|
|
||||||
)
|
|
||||||
JOIN `vn2008`.`Movimientos` `m` ON(`t`.`id` = `m`.`Id_Ticket`)
|
|
||||||
)
|
|
||||||
JOIN `vn2008`.`time` ON(`time`.`date` = cast(`t`.`shipped` AS date))
|
|
||||||
)
|
|
||||||
WHERE `t`.`shipped` >= '2014-01-01'
|
|
||||||
GROUP BY `time`.`year`,
|
|
||||||
`time`.`month`
|
|
|
@ -1,112 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`bancos_evolution_add`(vStartingDate DATE)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Inserta en la tabla bancos_evolution los saldos acumulados de cada banco
|
|
||||||
*
|
|
||||||
* @param vStartingDate Fecha desde la cual se recalculan la tabla bs.bancos_evolution
|
|
||||||
*/
|
|
||||||
DECLARE vCurrentDate DATE;
|
|
||||||
DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 7, util.VN_CURDATE());
|
|
||||||
IF IFNULL(vStartingDate,0) < TIMESTAMPADD(YEAR, -5, util.VN_CURDATE()) THEN
|
|
||||||
CALL util.throw('invalid date');
|
|
||||||
END IF;
|
|
||||||
DELETE FROM bs.bancos_evolution WHERE Fecha >= vStartingDate;
|
|
||||||
|
|
||||||
SET vCurrentDate = vStartingDate;
|
|
||||||
|
|
||||||
INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo)
|
|
||||||
SELECT vCurrentDate, Id_Banco, deuda
|
|
||||||
FROM bs.bancos_evolution
|
|
||||||
WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate);
|
|
||||||
|
|
||||||
WHILE vCurrentDate < vMaxDate DO
|
|
||||||
-- insertar solo el dia de ayer
|
|
||||||
INSERT INTO bs.bancos_evolution(Fecha ,Id_Banco, saldo)
|
|
||||||
SELECT vCurrentDate, Id_Banco, SUM(saldo)
|
|
||||||
FROM (
|
|
||||||
SELECT Id_Banco ,saldo
|
|
||||||
FROM bs.bancos_evolution
|
|
||||||
WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate) -- los saldos acumulados del dia anterior
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT c.Id_Banco, IFNULL(SUM(Entrada),0) - IFNULL(SUM(Salida),0) as saldo
|
|
||||||
FROM vn2008.Cajas c
|
|
||||||
JOIN vn2008.Bancos b using(Id_Banco) -- saldos de las cajas
|
|
||||||
JOIN vn.accountingType at2 ON at2.id = b.cash
|
|
||||||
WHERE at2.code IN ('wireTransfer','fundingLine')
|
|
||||||
AND Cajafecha = vCurrentDate
|
|
||||||
AND (Serie = 'MB' OR at2.code = 'fundingLine')
|
|
||||||
GROUP BY Id_Banco
|
|
||||||
)sub
|
|
||||||
GROUP BY Id_Banco
|
|
||||||
ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo);
|
|
||||||
|
|
||||||
SET vCurrentDate = TIMESTAMPADD(DAY,1,vCurrentDate);
|
|
||||||
|
|
||||||
END WHILE;
|
|
||||||
|
|
||||||
-- Ahora actualizamos la quilla
|
|
||||||
UPDATE bs.bancos_evolution be
|
|
||||||
JOIN
|
|
||||||
(
|
|
||||||
SELECT bp.Id_Banco, - sum(bp.importe) as quilla, t.dated
|
|
||||||
FROM vn.time t
|
|
||||||
JOIN vn2008.Bancos_poliza bp ON t.dated between apertura AND IFNULL(cierre, t.dated)
|
|
||||||
WHERE t.dated BETWEEN vStartingDate AND vMaxDate
|
|
||||||
GROUP BY Id_Banco, t.dated
|
|
||||||
) sub ON be.Id_Banco = sub.Id_Banco AND sub.dated = be.Fecha
|
|
||||||
SET be.quilla = sub.quilla;
|
|
||||||
|
|
||||||
-- pagos futuros no concilidados
|
|
||||||
INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo)
|
|
||||||
SELECT t.dated, p.id_banco, - importe
|
|
||||||
FROM vn.time t
|
|
||||||
join vn2008.pago p ON p.fecha <= t.dated
|
|
||||||
WHERE t.dated BETWEEN util.VN_CURDATE() AND vMaxDate
|
|
||||||
AND p.fecha BETWEEN util.VN_CURDATE() AND vMaxDate
|
|
||||||
AND NOT conciliado
|
|
||||||
ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo);
|
|
||||||
|
|
||||||
-- cobros futuros
|
|
||||||
INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo)
|
|
||||||
SELECT t.dated, r.Id_Banco, SUM(Entregado)
|
|
||||||
FROM vn.time t
|
|
||||||
JOIN vn2008.Recibos r ON r.Fechacobro <= t.dated
|
|
||||||
WHERE r.Fechacobro > util.VN_CURDATE() AND r.Fechacobro <= vMaxDate
|
|
||||||
AND t.dated BETWEEN util.VN_CURDATE() AND vMaxDate
|
|
||||||
GROUP BY t.dated, r.Id_Banco
|
|
||||||
ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo);
|
|
||||||
|
|
||||||
-- saldos de la tabla prevision
|
|
||||||
INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo)
|
|
||||||
SELECT t.dated, sp.Id_Banco, SUM(Importe)
|
|
||||||
FROM vn.time t
|
|
||||||
JOIN vn2008.Saldos_Prevision sp ON sp.Fecha <= t.dated
|
|
||||||
JOIN vn2008.Bancos b ON sp.Id_Banco = b.Id_Banco
|
|
||||||
JOIN vn.accountingType at2 ON at2.id = b.cash
|
|
||||||
WHERE at2.code IN ('wireTransfer','fundingLine')
|
|
||||||
AND t.dated BETWEEN vStartingDate AND vMaxDate
|
|
||||||
GROUP BY t.dated, sp.Id_Banco
|
|
||||||
ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo);
|
|
||||||
|
|
||||||
-- Utilizamos el saldo_auxiliar para calcular lo dispuesto en las polizas
|
|
||||||
UPDATE bs.bancos_evolution be
|
|
||||||
SET saldo_aux = saldo
|
|
||||||
WHERE Fecha >= vStartingDate;
|
|
||||||
|
|
||||||
-- Deuda
|
|
||||||
UPDATE bs.bancos_evolution be
|
|
||||||
JOIN vn2008.Bancos b using(Id_Banco)
|
|
||||||
JOIN vn.accountingType at2 ON at2.id = b.cash
|
|
||||||
SET be.deuda = IF(at2.code = 'fundingLine', be.saldo_aux, 0)
|
|
||||||
, be.saldo = IF(at2.code = 'fundingLine', 0, be.saldo_aux)
|
|
||||||
WHERE Fecha >= vStartingDate;
|
|
||||||
|
|
||||||
-- Liquidez
|
|
||||||
update bs.bancos_evolution set liquidez = saldo - quilla + deuda WHERE Fecha >= vStartingDate;
|
|
||||||
-- Disponibilidad
|
|
||||||
update bs.bancos_evolution set `disponibilidad ajena` = - quilla + deuda WHERE Fecha >= vStartingDate;
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,111 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`comercialesCompleto`(IN vWorker INT, vDate DATE)
|
|
||||||
BEGIN
|
|
||||||
DECLARE vAYearAgoStarted DATE DEFAULT DATE_FORMAT(TIMESTAMPADD(YEAR, - 1, vDate), '%Y-%m-01');
|
|
||||||
DECLARE vAYearAgoEnded DATE DEFAULT TIMESTAMPADD(YEAR, - 1, LAST_DAY(vDate));
|
|
||||||
|
|
||||||
CALL vn.worker_GetHierarchy(vWorker);
|
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.workerHierarchyList (workerFk)
|
|
||||||
SELECT wd2.workerFk
|
|
||||||
FROM vn.workerDepartment wd2
|
|
||||||
WHERE wd2.workerFk = vWorker;
|
|
||||||
|
|
||||||
-- Falta que en algunos casos solo tenga en cuenta los tipos afectados.
|
|
||||||
SELECT
|
|
||||||
c.Id_Cliente id_cliente,
|
|
||||||
c.Cliente cliente,
|
|
||||||
cr.recobro * 100 tarifa,
|
|
||||||
c.Telefono telefono,
|
|
||||||
c.movil,
|
|
||||||
c.POBLACION poblacion,
|
|
||||||
p.`name` provincia,
|
|
||||||
ROUND(f.futur, 2) futur,
|
|
||||||
c.Credito credito,
|
|
||||||
pm.`name` forma_pago,
|
|
||||||
ROUND(c365 / 12, 2) consumo_medio365,
|
|
||||||
ROUND(c365, 2) consumo365,
|
|
||||||
ROUND(CmLy.peso, 2) peso_mes_año_pasado,
|
|
||||||
ROUND(CmLy.peso * 1.19, 2) objetivo,
|
|
||||||
tr.CodigoTrabajador,
|
|
||||||
ROUND(mes_actual.consumo, 2) consumoMes,
|
|
||||||
ROUND(IFNULL(mes_actual.consumo, 0) - IFNULL(CmLy.peso * 1.19, 0), 2) como_lo_llevo,
|
|
||||||
DATE(LastTicket) ultimo_ticket,
|
|
||||||
dead.muerto,
|
|
||||||
g.Greuge,
|
|
||||||
cr.recobro
|
|
||||||
FROM
|
|
||||||
vn2008.Clientes c
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT g.clientFk Id_Cliente, CAST( SUM(g.amount) as DECIMAL(12,2)) AS Greuge
|
|
||||||
FROM vn.greuge g
|
|
||||||
JOIN vn.`client` c ON c.id = g.clientFk
|
|
||||||
LEFT JOIN vn.worker w ON c.salesPersonFk = w.id
|
|
||||||
WHERE (c.salesPersonFk = vWorker OR w.bossFk = vWorker)
|
|
||||||
GROUP BY Id_Cliente
|
|
||||||
) g ON g.Id_Cliente = c.Id_Cliente
|
|
||||||
LEFT JOIN
|
|
||||||
vn2008.province p ON p.province_id = c.province_id
|
|
||||||
JOIN
|
|
||||||
vn2008.pay_met pm ON pm.id = c.pay_met_id
|
|
||||||
LEFT JOIN
|
|
||||||
vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
|
|
||||||
LEFT JOIN
|
|
||||||
bi.claims_ratio cr on cr.Id_Cliente = c.Id_Cliente
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT v.Id_Cliente, SUM(importe) c365 -- optimizat de 6s /5.3s/ 4.7s a 0.3/0.4/0.3
|
|
||||||
FROM bs.ventas v
|
|
||||||
JOIN vn2008.Clientes c ON c.Id_Cliente = v.Id_Cliente
|
|
||||||
WHERE v.fecha BETWEEN TIMESTAMPADD(YEAR, - 1, vDate) AND vDate
|
|
||||||
GROUP BY v.Id_Cliente) c365 ON c365.Id_Cliente = c.Id_Cliente
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT
|
|
||||||
Id_Cliente, SUM(importe) consumo
|
|
||||||
FROM
|
|
||||||
bs.ventas v
|
|
||||||
INNER JOIN vn2008.Clientes c USING (Id_Cliente)
|
|
||||||
LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
|
|
||||||
WHERE
|
|
||||||
(c.Id_Trabajador = vWorker OR tr.boss = vWorker)
|
|
||||||
AND (v.fecha BETWEEN TIMESTAMPADD(DAY, - DAY(vDate) + 1, vDate) AND TIMESTAMPADD(DAY, - 1, vDate))
|
|
||||||
GROUP BY Id_Cliente) mes_actual ON mes_actual.Id_Cliente = c.Id_Cliente
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT t.clientFk Id_Cliente, SUM(m.preu * m.Cantidad * (1 - m.Descuento / 100)) futur
|
|
||||||
FROM vn.ticket t
|
|
||||||
JOIN vn2008.Clientes c ON c.Id_Cliente = t.clientFk
|
|
||||||
JOIN vn2008.Movimientos m ON m.Id_Ticket = t.id
|
|
||||||
LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
|
|
||||||
WHERE
|
|
||||||
(c.Id_Trabajador = vWorker OR tr.boss = vWorker)
|
|
||||||
AND t.shipped BETWEEN vDate AND util.dayEnd(LAST_DAY(vDate))
|
|
||||||
GROUP BY Id_Cliente) f ON c.Id_Cliente = f.Id_Cliente
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT MAX(t.shipped) LastTicket, c.Id_Cliente
|
|
||||||
FROM vn.ticket t
|
|
||||||
JOIN vn2008.Clientes c ON c.Id_cliente = t.clientFk
|
|
||||||
LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
|
|
||||||
WHERE
|
|
||||||
(c.Id_Trabajador = vWorker OR tr.boss = vWorker)
|
|
||||||
GROUP BY t.clientFk) LastTicket ON LastTicket.Id_Cliente = c.Id_Cliente
|
|
||||||
LEFT JOIN
|
|
||||||
(
|
|
||||||
SELECT SUM(importe) peso, c.Id_Cliente
|
|
||||||
FROM bs.ventas v
|
|
||||||
JOIN vn2008.Clientes c ON c.Id_Cliente = v.Id_Cliente
|
|
||||||
LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
|
|
||||||
WHERE fecha BETWEEN vAYearAgoStarted and vAYearAgoEnded
|
|
||||||
AND (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
|
|
||||||
GROUP BY c.Id_Cliente) CmLy ON CmLy.Id_Cliente = c.Id_Cliente
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT c.Id_Cliente,
|
|
||||||
IF(MAX(io.issued) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, vDate), '%Y- %m-01'), TRUE, FALSE) muerto
|
|
||||||
FROM vn.invoiceOut io
|
|
||||||
JOIN vn2008.Clientes c ON c.Id_cliente = io.clientFk
|
|
||||||
LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
|
|
||||||
WHERE (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
|
|
||||||
GROUP BY Id_Cliente) dead ON dead.Id_Cliente = c.Id_Cliente
|
|
||||||
JOIN tmp.workerHierarchyList s ON s.workerFk = c.Id_Trabajador;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.workerHierarchyList;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -15,10 +15,10 @@ BEGIN
|
||||||
SET lastYearSales =
|
SET lastYearSales =
|
||||||
(SELECT SUM(importe + recargo)
|
(SELECT SUM(importe + recargo)
|
||||||
FROM ventas v
|
FROM ventas v
|
||||||
JOIN vn2008.empresa e ON e.id = v.empresa_id
|
JOIN vn.company c ON c.id = v.empresa_id
|
||||||
JOIN vn2008.empresa_grupo eg ON eg.empresa_grupo_id = e.empresa_grupo
|
JOIN vn.companyGroup cg ON cg.id = c.companyGroupFk
|
||||||
WHERE fecha BETWEEN oneYearBefore AND vDated
|
WHERE fecha BETWEEN oneYearBefore AND vDated
|
||||||
AND eg.grupo = 'Verdnatura'
|
AND cg.code = 'Verdnatura'
|
||||||
)
|
)
|
||||||
WHERE updated = vDated;
|
WHERE updated = vDated;
|
||||||
|
|
||||||
|
|
|
@ -67,20 +67,20 @@ BEGIN
|
||||||
vToDated
|
vToDated
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT cs.Id_Cliente, Cantidad * Valor as mana
|
SELECT a.clientFk Id_Cliente, s.quantity * sc.value as mana
|
||||||
FROM vn.ticket t
|
FROM vn.ticket t
|
||||||
JOIN vn2008.Consignatarios cs using(Id_Consigna)
|
JOIN vn.address a ON a.id = t.addressFk
|
||||||
JOIN vn2008.Movimientos m on m.Id_Ticket = t.id
|
JOIN vn.sale s on s.ticketFk = t.id
|
||||||
JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento
|
JOIN vn.saleComponent sc on sc.saleFk = s.id
|
||||||
WHERE Id_Componente IN (vManaAutoId, vManaId, vClaimManaId)
|
WHERE sc.componentFk IN (vManaAutoId, vManaId, vClaimManaId)
|
||||||
AND t.shipped > vFromDated
|
AND t.shipped > vFromDated
|
||||||
AND date(t.shipped) <= vToDated
|
AND date(t.shipped) <= vToDated
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT r.Id_Cliente, - Entregado
|
SELECT clientFk, - amountPaid
|
||||||
FROM vn2008.Recibos r
|
FROM vn.receipt
|
||||||
WHERE Id_Banco = vManaBankId
|
WHERE bankFk = vManaBankId
|
||||||
AND Fechacobro > vFromDated
|
AND payed > vFromDated
|
||||||
AND Fechacobro <= vToDated
|
AND payed <= vToDated
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT clientFk, amount
|
SELECT clientFk, amount
|
||||||
FROM vn.greuge
|
FROM vn.greuge
|
||||||
|
|
|
@ -38,35 +38,35 @@ BEGIN
|
||||||
|
|
||||||
SELECT vYear
|
SELECT vYear
|
||||||
, vMonth
|
, vMonth
|
||||||
, round(sum(Cantidad * Preu * (100 - m.Descuento)/100))
|
, round(sum(s.quantity * s.price * (100 - s.discount)/100))
|
||||||
, IF(
|
, IF(
|
||||||
e.empresa_grupo = e2.empresa_grupo
|
co.companyGroupFk = co2.companyGroupFk
|
||||||
,1
|
,1
|
||||||
,IF(e2.empresa_grupo,2,0)
|
,IF(co2.companyGroupFk,2,0)
|
||||||
) as grupo
|
) as grupo
|
||||||
, tp.reino_id
|
, it.categoryFk
|
||||||
, a.tipo_id
|
, i.typeFk
|
||||||
, t.companyFk
|
, t.companyFk
|
||||||
, a.expenseFk
|
, i.expenseFk
|
||||||
+ IF(e.empresa_grupo = e2.empresa_grupo
|
+ IF(co.companyGroupFk = co2.companyGroupFk
|
||||||
,1
|
,1
|
||||||
,IF(e2.empresa_grupo,2,0)
|
,IF(co2.companyGroupFk,2,0)
|
||||||
) * 100000
|
) * 100000
|
||||||
+ tp.reino_id * 1000 as Gasto
|
+ it.categoryFk * 1000 as Gasto
|
||||||
FROM vn2008.Movimientos m
|
FROM vn.sale s
|
||||||
JOIN vn.ticket t ON t.id = m.Id_Ticket
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.addressFk
|
JOIN vn.address a on a.id = t.addressFk
|
||||||
JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
|
JOIN vn.client c on c.id = a.clientFk
|
||||||
JOIN tmp.ticket_list tt on tt.id = t.id
|
JOIN tmp.ticket_list tt on tt.id = t.id
|
||||||
JOIN vn2008.Articles a on m.Id_Article = a.Id_Article
|
JOIN vn.item i on s.itemFk = i.id
|
||||||
JOIN vn2008.empresa e on e.id = t.companyFk
|
JOIN vn.company co on co.id = t.companyFk
|
||||||
LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente
|
LEFT JOIN vn.company co2 on co2.clientFk = c.id
|
||||||
JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id
|
JOIN vn.itemType it on it.id = i.typeFk
|
||||||
WHERE Cantidad <> 0
|
WHERE s.quantity <> 0
|
||||||
AND Preu <> 0
|
AND s.price <> 0
|
||||||
AND m.Descuento <> 100
|
AND s.discount <> 100
|
||||||
AND a.tipo_id != TIPO_PATRIMONIAL
|
AND i.typeFk <> TIPO_PATRIMONIAL
|
||||||
GROUP BY grupo, reino_id, tipo_id, companyFk, Gasto;
|
GROUP BY grupo, it.categoryFk, i.typeFk, t.companyFk, Gasto;
|
||||||
guillermo marked this conversation as resolved
|
|||||||
|
|
||||||
INSERT INTO bs.ventas_contables(year
|
INSERT INTO bs.ventas_contables(year
|
||||||
, month
|
, month
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`ventas_contables_por_cliente`(IN vYear INT, IN vMonth INT)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Muestra las ventas (€) de cada cliente
|
|
||||||
* dependiendo del año
|
|
||||||
*/
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
|
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE tmp.ticket_list
|
|
||||||
(PRIMARY KEY (id))
|
|
||||||
SELECT t.id
|
|
||||||
FROM vn.ticket t
|
|
||||||
JOIN vn.invoiceOut io ON io.id = t.refFk
|
|
||||||
WHERE year(io.issued) = vYear
|
|
||||||
AND month(io.issued) = vMonth;
|
|
||||||
|
|
||||||
SELECT vYear Año,
|
|
||||||
vMonth Mes,
|
|
||||||
t.clientFk Id_Cliente,
|
|
||||||
round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) Venta,
|
|
||||||
IF(e.empresa_grupo = e2.empresa_grupo,
|
|
||||||
1,
|
|
||||||
IF(e2.empresa_grupo,2,0))
|
|
||||||
AS grupo,
|
|
||||||
t.companyFk empresa
|
|
||||||
FROM vn2008.Movimientos m
|
|
||||||
JOIN vn.ticket t ON t.id = m.Id_Ticket
|
|
||||||
JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = t.addressFk
|
|
||||||
JOIN vn2008.Clientes c ON c.Id_Cliente = cs.Id_Cliente
|
|
||||||
JOIN tmp.ticket_list tt ON tt.id = t.id
|
|
||||||
JOIN vn2008.Articles a ON m.Id_Article = a.Id_Article
|
|
||||||
JOIN vn2008.empresa e ON e.id = t.companyFk
|
|
||||||
LEFT JOIN vn2008.empresa e2 ON e2.Id_Cliente = c.Id_Cliente
|
|
||||||
JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id
|
|
||||||
WHERE Cantidad <> 0
|
|
||||||
AND Preu <> 0
|
|
||||||
AND m.Descuento <> 100
|
|
||||||
AND a.tipo_id != 188
|
|
||||||
GROUP BY t.clientFk, grupo,t.companyFk;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket_list;
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,63 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`vivosMuertos`()
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Devuelve el número de clientes nuevos y muertos,
|
|
||||||
* dependiendo de la fecha actual.
|
|
||||||
*
|
|
||||||
* @param @datSTART Fecha de inicio a buscar
|
|
||||||
* @param @datEND Fecha de finalización a buscar
|
|
||||||
*/
|
|
||||||
|
|
||||||
SET @datSTART = TIMESTAMPADD(YEAR,-2,util.VN_CURDATE());
|
|
||||||
SET @datEND = TIMESTAMPADD(DAY,-DAY(util.VN_CURDATE()),util.VN_CURDATE());
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.VivosMuertos;
|
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE tmp.VivosMuertos
|
|
||||||
SELECT c.Id_Cliente, tm.yearMonth, f.Compra, 0 as Nuevo, 0 as Muerto
|
|
||||||
FROM vn2008.Clientes c
|
|
||||||
JOIN
|
|
||||||
(SELECT DISTINCT yearMonth
|
|
||||||
FROM vn2008.time
|
|
||||||
WHERE date BETWEEN @datSTART
|
|
||||||
AND @datEND ) tm
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT DISTINCT tm.yearMonth, io.clientFk Id_Cliente , 1 as Compra
|
|
||||||
FROM vn.invoiceOut io
|
|
||||||
JOIN vn2008.time tm ON tm.date = io.issued
|
|
||||||
WHERE io.issued BETWEEN @datSTART
|
|
||||||
AND @datEND) f ON f.yearMonth = tm.yearMonth
|
|
||||||
AND f.Id_Cliente = c.Id_Cliente;
|
|
||||||
|
|
||||||
UPDATE tmp.VivosMuertos vm
|
|
||||||
JOIN
|
|
||||||
(SELECT MIN(tm.yearMonth) firstMonth, io.clientFk Id_Cliente
|
|
||||||
FROM vn.invoiceOut io
|
|
||||||
JOIN vn2008.time tm ON tm.date = io.issued
|
|
||||||
WHERE io.issued BETWEEN @datSTART AND @datEND
|
|
||||||
GROUP BY io.clientFk) fm ON fm.firstMonth = vm.yearMonth
|
|
||||||
AND fm.Id_Cliente = vm.Id_Cliente
|
|
||||||
|
|
||||||
SET Nuevo = 1;
|
|
||||||
|
|
||||||
SELECT max(yearMonth) INTO @lastYearMonth FROM tmp.VivosMuertos;
|
|
||||||
|
|
||||||
UPDATE tmp.VivosMuertos vm
|
|
||||||
JOIN (
|
|
||||||
SELECT MAX(tm.yearMonth) firstMonth, io.clientFk Id_Cliente
|
|
||||||
FROM vn.invoiceOut io
|
|
||||||
JOIN vn2008.time tm ON tm.date = io.issued
|
|
||||||
WHERE io.issued BETWEEN @datSTART AND @datEND
|
|
||||||
GROUP BY io.clientFk) fm ON fm.firstMonth = vm.yearMonth
|
|
||||||
AND fm.Id_Cliente = vm.Id_Cliente
|
|
||||||
|
|
||||||
SET Muerto = 1
|
|
||||||
|
|
||||||
WHERE yearMonth < @lastYearMonth;
|
|
||||||
|
|
||||||
SELECT * FROM tmp.VivosMuertos;
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,14 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `bs`.`VentasPorCliente`
|
|
||||||
AS SELECT `v`.`Id_Cliente` AS `Id_Cliente`,
|
|
||||||
round(sum(`v`.`importe`), 0) AS `VentaBasica`,
|
|
||||||
`t`.`year` AS `year`,
|
|
||||||
`t`.`month` AS `month`
|
|
||||||
FROM (
|
|
||||||
`vn2008`.`time` `t`
|
|
||||||
JOIN `bs`.`ventas` `v` ON(`v`.`fecha` = `t`.`date`)
|
|
||||||
)
|
|
||||||
GROUP BY `v`.`Id_Cliente`,
|
|
||||||
`t`.`year`,
|
|
||||||
`t`.`month`
|
|
|
@ -1,31 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `bs`.`bajasLaborales`
|
|
||||||
AS SELECT `w`.`firstName` AS `firstname`,
|
|
||||||
`w`.`lastName` AS `name`,
|
|
||||||
`b`.`id` AS `businessFk`,
|
|
||||||
max(`c`.`dated`) AS `lastDate`,
|
|
||||||
max(IFNULL(`b`.`ended`, `util`.`VN_CURDATE`())) AS `endContract`,
|
|
||||||
`at`.`name` AS `type`,
|
|
||||||
cast(COUNT(0) AS decimal(10, 0)) AS `dias`,
|
|
||||||
`w`.`id` AS `userFk`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
(
|
|
||||||
`vn`.`calendar` `c`
|
|
||||||
JOIN `vn`.`business` `b` ON(`b`.`id` = `c`.`businessFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`worker` `w` ON(`w`.`id` = `b`.`workerFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`absenceType` `at` ON(`at`.`id` = `c`.`dayOffTypeFk`)
|
|
||||||
)
|
|
||||||
WHERE `c`.`dated` >= `util`.`VN_CURDATE`() + INTERVAL -1 year
|
|
||||||
AND `at`.`name` NOT IN (
|
|
||||||
'Vacaciones',
|
|
||||||
'Vacaciones 1/2 día',
|
|
||||||
'Compensar',
|
|
||||||
'Festivo'
|
|
||||||
)
|
|
||||||
GROUP BY `w`.`id`,
|
|
||||||
`at`.`id`
|
|
||||||
HAVING `endContract` >= `util`.`VN_CURDATE`()
|
|
|
@ -1,27 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `bs`.`horasSilla`
|
|
||||||
AS SELECT `wj`.`dated` AS `Fecha`,
|
|
||||||
`d`.`name` AS `Departamento`,
|
|
||||||
cast(sum(`wj`.`total`) AS decimal(10, 2)) AS `Horas`,
|
|
||||||
cast(
|
|
||||||
sum(
|
|
||||||
(`wj`.`total` + `wj`.`lunch`) * `wj`.`priceOrdinaryHour`
|
|
||||||
) AS decimal(10, 2)
|
|
||||||
) AS `Salarios`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
`vn`.`workerJourney` `wj`
|
|
||||||
JOIN `vn`.`business` `b` ON(`b`.`id` = `wj`.`businessFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`department` `d` ON(`d`.`id` = `b`.`departmentFk`)
|
|
||||||
)
|
|
||||||
WHERE `d`.`name` IN (
|
|
||||||
'CAMARA',
|
|
||||||
'ENCAJADO',
|
|
||||||
'PALETIZADORES',
|
|
||||||
'PRODUCCION',
|
|
||||||
'SACADORES'
|
|
||||||
)
|
|
||||||
GROUP BY `wj`.`dated`,
|
|
||||||
`d`.`name`
|
|
|
@ -1,19 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `bs`.`s1_ticketDetail`
|
|
||||||
AS SELECT `s`.`ticketFk` AS `ticketFk`,
|
|
||||||
cast(
|
|
||||||
sum(`s`.`price` * `s`.`quantity`) AS decimal(10, 2)
|
|
||||||
) AS `ticketAmount`,
|
|
||||||
COUNT(`s`.`id`) AS `ticketLines`,
|
|
||||||
cast(sum(`sv`.`volume`) AS decimal(10, 2)) AS `ticketM3`,
|
|
||||||
cast(`t`.`shipped` AS date) AS `shipped`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
`vn`.`ticket` `t`
|
|
||||||
JOIN `vn`.`sale` `s` ON(`s`.`ticketFk` = `t`.`id`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`saleVolume` `sv` ON(`sv`.`saleFk` = `s`.`id`)
|
|
||||||
)
|
|
||||||
WHERE `t`.`shipped` BETWEEN '2021-09-01' AND '2021-10-31 23:59'
|
|
||||||
GROUP BY `s`.`ticketFk`
|
|
|
@ -1,42 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `bs`.`s21_saleDetail`
|
|
||||||
AS SELECT dayofmonth(`t`.`shipped`) AS `dia`,
|
|
||||||
year(`t`.`shipped`) AS `año`,
|
|
||||||
MONTH(`t`.`shipped`) AS `mes`,
|
|
||||||
`s`.`concept` AS `concepto`,
|
|
||||||
`s`.`quantity` AS `unidades`,
|
|
||||||
`s`.`price` AS `precio`,
|
|
||||||
`s`.`quantity` * `s`.`price` AS `venta`,
|
|
||||||
`it`.`name` AS `familia`,
|
|
||||||
`w`.`code` AS `comprador`,
|
|
||||||
`s`.`itemFk` AS `itemFk`,
|
|
||||||
`s`.`ticketFk` AS `ticketFk`,
|
|
||||||
`sv`.`volume` AS `volume`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
`vn`.`sale` `s`
|
|
||||||
JOIN `vn`.`item` `i` ON(`i`.`id` = `s`.`itemFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`itemType` `it` ON(`it`.`id` = `i`.`typeFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`worker` `w` ON(`w`.`id` = `it`.`workerFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`client` `c` ON(`c`.`id` = `t`.`clientFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`saleVolume` `sv` ON(`sv`.`saleFk` = `s`.`id`)
|
|
||||||
)
|
|
||||||
WHERE (
|
|
||||||
`t`.`shipped` BETWEEN '2020-10-21' AND '2020-10-28'
|
|
||||||
OR `t`.`shipped` BETWEEN '2019-10-21' AND '2019-10-28'
|
|
||||||
OR `t`.`shipped` BETWEEN '2021-09-1' AND '2021-10-28'
|
|
||||||
)
|
|
||||||
AND `t`.`warehouseFk` IN (1, 60)
|
|
||||||
AND `c`.`isRelevant` <> 0
|
|
||||||
AND `s`.`quantity` > 0
|
|
|
@ -1,36 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`prod_graphic_refresh`(v_refresh BOOL, wh_id INT)
|
|
||||||
proc: BEGIN
|
|
||||||
DECLARE datEQ DATETIME;
|
|
||||||
DECLARE timDIF TIME;
|
|
||||||
DECLARE v_calc INT;
|
|
||||||
|
|
||||||
CALL cache_calc_start (v_calc, v_refresh, 'prod_graphic', wh_id);
|
|
||||||
|
|
||||||
IF !v_refresh
|
|
||||||
THEN
|
|
||||||
LEAVE proc;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
CALL vn2008.production_control_source(wh_id, 0);
|
|
||||||
|
|
||||||
DELETE FROM prod_graphic_source;
|
|
||||||
|
|
||||||
INSERT INTO prod_graphic_source (warehouse_id, graphCategory, m3, hora, `order`, Agencia)
|
|
||||||
SELECT
|
|
||||||
wh_id,
|
|
||||||
st.graphCategory,
|
|
||||||
CAST(SUM(m3) AS DECIMAL(10,0)) as m3,
|
|
||||||
pb.Hora,
|
|
||||||
pb.state_order,
|
|
||||||
pb.Agencia
|
|
||||||
FROM tmp.production_buffer pb
|
|
||||||
JOIN vn.state st ON st.id = pb.state
|
|
||||||
WHERE Fecha = util.VN_CURDATE()
|
|
||||||
GROUP BY wh_id, graphCategory
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
CALL cache_calc_end (v_calc);
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -70,16 +70,16 @@ proc:BEGIN
|
||||||
|
|
||||||
ELSE
|
ELSE
|
||||||
|
|
||||||
INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z)
|
INSERT IGNORE INTO vn.packaging (id, width, depth, height)
|
||||||
SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10)
|
SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10)
|
||||||
FROM bucket WHERE bucket_id = vPackage;
|
FROM bucket WHERE bucket_id = vPackage;
|
||||||
|
|
||||||
IF ROW_COUNT() > 0
|
IF ROW_COUNT() > 0
|
||||||
THEN
|
THEN
|
||||||
INSERT INTO vn2008.mail SET
|
INSERT INTO vn.mail SET
|
||||||
`subject` = 'Cubo añadido',
|
`subject` = 'Cubo añadido',
|
||||||
`text` = CONCAT('Se ha añadido el cubo: ', vPackage),
|
`body` = CONCAT('Se ha añadido el cubo: ', vPackage),
|
||||||
`to` = 'ekt@verdnatura.es';
|
`receiver` = 'ekt@verdnatura.es';
|
||||||
END IF;
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getAlert3StateTest`(vTicket INT)
|
|
||||||
RETURNS varchar(45) CHARSET latin1 COLLATE latin1_swedish_ci
|
|
||||||
NOT DETERMINISTIC
|
|
||||||
READS SQL DATA
|
|
||||||
BEGIN
|
|
||||||
DECLARE vDeliveryType INTEGER DEFAULT 0;
|
|
||||||
DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE;
|
|
||||||
DECLARE vCode VARCHAR(45);
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
a.Vista
|
|
||||||
INTO vDeliveryType
|
|
||||||
FROM ticket t
|
|
||||||
JOIN vn2008.Agencias a ON a.Id_Agencia = t.agencyModeFk
|
|
||||||
WHERE t.id = vTicket;
|
|
||||||
|
|
||||||
CASE vDeliveryType
|
|
||||||
WHEN 1 THEN -- AGENCIAS
|
|
||||||
SET vCode = 'DELIVERED';
|
|
||||||
|
|
||||||
WHEN 2 THEN -- REPARTO
|
|
||||||
SET vCode = 'ON_DELIVERY';
|
|
||||||
|
|
||||||
ELSE -- MERCADO, OTROS
|
|
||||||
SELECT t.warehouseFk <> w.warehouse_id INTO isWaitingForPickUp
|
|
||||||
FROM ticket t
|
|
||||||
LEFT JOIN vn2008.warehouse_pickup w
|
|
||||||
ON w.agency_id = t.agencyModeFk AND w.warehouse_id = t.warehouseFk
|
|
||||||
WHERE t.id = vTicket;
|
|
||||||
|
|
||||||
IF isWaitingForPickUp THEN
|
|
||||||
SET vCode = 'WAITING_FOR_PICKUP';
|
|
||||||
ELSE
|
|
||||||
SET vCode = 'DELIVERED';
|
|
||||||
END IF;
|
|
||||||
END CASE;
|
|
||||||
RETURN vCode;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -26,11 +26,11 @@ SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0)
|
||||||
LEFT JOIN ticketState ts on ts.ticketFk = t.id
|
LEFT JOIN ticketState ts on ts.ticketFk = t.id
|
||||||
WHERE t.id = vTicketId;
|
WHERE t.id = vTicketId;
|
||||||
|
|
||||||
SELECT (ag.`name` = 'VN_VALENCIA')
|
SELECT (a.`name` = 'VN_VALENCIA')
|
||||||
INTO vIsValenciaPath
|
INTO vIsValenciaPath
|
||||||
FROM `route` r
|
FROM `route` r
|
||||||
JOIN vn2008.Agencias a on a.Id_Agencia = r.agencyModeFk
|
JOIN agencyMode am on am.id = r.agencyModeFk
|
||||||
JOIN vn2008.agency ag on ag.agency_id = a.agency_id
|
JOIN agency a on a.id = am.agencyFk
|
||||||
WHERE r.id = vMyPath;
|
WHERE r.id = vMyPath;
|
||||||
|
|
||||||
IF vIsValenciaPath THEN -- Rutas Valencia
|
IF vIsValenciaPath THEN -- Rutas Valencia
|
||||||
|
|
|
@ -9,9 +9,9 @@ BEGIN
|
||||||
SELECT CONCAT(printedStickers,'/',Total, IF(printedStickers = Total ,' LS','')) INTO vSplitCounter
|
SELECT CONCAT(printedStickers,'/',Total, IF(printedStickers = Total ,' LS','')) INTO vSplitCounter
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT count(l.Id_Movimiento) as printedStickers, COUNT(*) as Total
|
SELECT count(sl.saleFk) as printedStickers, COUNT(*) as Total
|
||||||
FROM vn.sale s
|
FROM sale s
|
||||||
LEFT JOIN vn2008.movement_label l ON l.Id_Movimiento = s.id
|
LEFT JOIN saleLabel sl ON sl.saleFk = s.id
|
||||||
WHERE ticketFk = vTicketFk
|
WHERE ticketFk = vTicketFk
|
||||||
) sub;
|
) sub;
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,17 @@ BEGIN
|
||||||
GREATEST(0,iss.visible - IFNULL(sub3.transit,0)) as Altillo,
|
GREATEST(0,iss.visible - IFNULL(sub3.transit,0)) as Altillo,
|
||||||
s.id as saleFk,
|
s.id as saleFk,
|
||||||
IFNULL(sub3.transit,0) transit,
|
IFNULL(sub3.transit,0) transit,
|
||||||
v.visible, s.isPicked, s.reserved, t.shipped, tst.productionOrder, mm.Id_Movimiento
|
v.visible, s.isPicked, s.reserved, t.shipped, tst.productionOrder, st.saleFk
|
||||||
FROM vn.ticket t
|
FROM ticket t
|
||||||
JOIN vn.ticketState tst ON tst.ticketFk = t.id
|
JOIN ticketState tst ON tst.ticketFk = t.id
|
||||||
JOIN vn.sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN vn.item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
JOIN cache.visible v ON s.itemFk = v.item_id AND v.calc_id = vVisibleCache
|
JOIN cache.visible v ON s.itemFk = v.item_id AND v.calc_id = vVisibleCache
|
||||||
LEFT JOIN vn2008.Movimientos_mark mm ON mm.Id_Movimiento = s.id AND mm.stateFk = 26
|
LEFT JOIN saleTracking st ON st.saleFk = s.id AND st.stateFk = 26
|
||||||
JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id
|
JOIN itemShelvingStock iss ON iss.itemFk = v.item_id
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
(SELECT itemFk, sum(saldo) as transit
|
(SELECT itemFk, sum(saldo) as transit
|
||||||
FROM vn.itemPlacementSupplyList
|
FROM itemPlacementSupplyList
|
||||||
WHERE saldo > 0
|
WHERE saldo > 0
|
||||||
AND sectorFk = vSectorFk
|
AND sectorFk = vSectorFk
|
||||||
GROUP BY itemFk) sub3 ON sub3.itemFk = i.id
|
GROUP BY itemFk) sub3 ON sub3.itemFk = i.id
|
||||||
|
@ -42,7 +42,7 @@ BEGIN
|
||||||
AND tst.isPreviousPreparable = TRUE
|
AND tst.isPreviousPreparable = TRUE
|
||||||
AND t.warehouseFk = vWarehouseFk
|
AND t.warehouseFk = vWarehouseFk
|
||||||
AND iss.sectorFk = vSectorFk
|
AND iss.sectorFk = vSectorFk
|
||||||
AND mm.Id_Movimiento IS NULL
|
AND st.saleFk IS NULL
|
||||||
ORDER BY itemFk;
|
ORDER BY itemFk;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -101,9 +101,6 @@ BEGIN
|
||||||
DELETE FROM itemCost
|
DELETE FROM itemCost
|
||||||
WHERE itemFk = vItemOld;
|
WHERE itemFk = vItemOld;
|
||||||
|
|
||||||
DELETE FROM vn2008.rec_translator
|
|
||||||
WHERE Id_Article = vItemOld;
|
|
||||||
|
|
||||||
DELETE FROM bs.waste
|
DELETE FROM bs.waste
|
||||||
WHERE itemFk = vItemOld;
|
WHERE itemFk = vItemOld;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packingListPrinted`(ticketFk INT)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
UPDATE vn2008.Movimientos_mark mm
|
|
||||||
JOIN vn2008.Movimientos m ON m.Id_Movimiento = mm.Id_Movimiento
|
|
||||||
SET mm.valor = 2 -- Impreso
|
|
||||||
WHERE mm.valor = 1 -- Listo para imprimir
|
|
||||||
AND mm.stateFk = 9 -- Encajando
|
|
||||||
AND m.Id_Ticket = ticketFk;
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -5,14 +5,14 @@ BEGIN
|
||||||
DECLARE valueFk INT;
|
DECLARE valueFk INT;
|
||||||
DECLARE encajando INT DEFAULT 9;
|
DECLARE encajando INT DEFAULT 9;
|
||||||
|
|
||||||
SELECT valor INTO valueFk
|
SELECT isChecked INTO valueFk
|
||||||
FROM vn2008.Movimientos_mark
|
FROM saleTracking
|
||||||
WHERE Id_Movimiento = saleFk
|
WHERE saleFk = saleFk
|
||||||
AND stateFk = encajando;
|
AND stateFk = encajando;
|
||||||
|
|
||||||
SET valueFk = (IFNULL(valueFk,0) + 1) MOD 3;
|
SET valueFk = (IFNULL(valueFk,0) + 1) MOD 3;
|
||||||
|
|
||||||
REPLACE vn2008.Movimientos_mark(Id_Movimiento, valor, Id_Trabajador, stateFk)
|
REPLACE saleTracking(saleFk, isChecked, workerFk, stateFk)
|
||||||
VALUES(saleFk,valueFk,account.myUser_getId(),encajando);
|
VALUES(saleFk,valueFk,account.myUser_getId(),encajando);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_afterInse
|
||||||
AFTER INSERT ON `solunionCAP`
|
AFTER INSERT ON `solunionCAP`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
UPDATE vn2008.Clientes c
|
UPDATE client c
|
||||||
JOIN creditClassification cc ON c.Id_Cliente = cc.client
|
JOIN creditClassification cc ON cc.client = c.id
|
||||||
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
||||||
SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance;
|
SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance;
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -4,13 +4,13 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_afterUpda
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
IF NEW.dateLeaving IS NOT NULL THEN
|
IF NEW.dateLeaving IS NOT NULL THEN
|
||||||
UPDATE vn2008.Clientes c
|
UPDATE client c
|
||||||
JOIN creditClassification cc ON c.Id_Cliente = cc.client
|
JOIN creditClassification cc ON cc.client = c.id
|
||||||
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
||||||
SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
|
SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
|
||||||
ELSE
|
ELSE
|
||||||
UPDATE vn2008.Clientes c
|
UPDATE client c
|
||||||
JOIN creditClassification cc ON c.Id_Cliente = cc.client
|
JOIN creditClassification cc ON cc.client = c.id
|
||||||
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
||||||
SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance;
|
SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
|
@ -3,8 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_beforeDel
|
||||||
BEFORE DELETE ON `solunionCAP`
|
BEFORE DELETE ON `solunionCAP`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
UPDATE vn2008.Clientes c
|
UPDATE client c
|
||||||
JOIN creditClassification cc ON c.Id_Cliente = cc.client
|
JOIN creditClassification cc ON cc.client = c.id
|
||||||
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
||||||
SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
|
SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||||
SQL SECURITY DEFINER
|
SQL SECURITY DEFINER
|
||||||
VIEW `vn`.`especialPrice`
|
VIEW `vn`.`especialPrice`
|
||||||
AS SELECT `p`.`Id_PrecioEspecial` AS `id`,
|
AS SELECT `sp`.`id` AS `id`,
|
||||||
`p`.`Id_Cliente` AS `clientFk`,
|
`sp`.`clientFk` AS `clientFk`,
|
||||||
`p`.`Id_Article` AS `itemFk`,
|
`sp`.`itemFk` AS `itemFk`,
|
||||||
`p`.`PrecioEspecial` AS `value`
|
`sp`.`value` AS `value`
|
||||||
FROM `vn2008`.`PreciosEspeciales` `p`
|
FROM `vn`.`specialPrice` `sp`
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `vn`.`exchangeInsurance`
|
|
||||||
AS SELECT `vn2008`.`pago_sdc`.`pago_sdc_id` AS `id`,
|
|
||||||
`vn2008`.`pago_sdc`.`importe` AS `amount`,
|
|
||||||
`vn2008`.`pago_sdc`.`fecha` AS `dated`,
|
|
||||||
`vn2008`.`pago_sdc`.`vencimiento` AS `finished`,
|
|
||||||
`vn2008`.`pago_sdc`.`entity_id` AS `entityFk`,
|
|
||||||
`vn2008`.`pago_sdc`.`ref` AS `ref`,
|
|
||||||
`vn2008`.`pago_sdc`.`rate` AS `rate`,
|
|
||||||
`vn2008`.`pago_sdc`.`empresa_id` AS `companyFk`,
|
|
||||||
`vn2008`.`pago_sdc`.`financialProductTypefk` AS `financialProductTypefk`,
|
|
||||||
`vn2008`.`pago_sdc`.`upperBarrier` AS `upperBarrier`,
|
|
||||||
`vn2008`.`pago_sdc`.`lowerBarrier` AS `lowerBarrier`,
|
|
||||||
`vn2008`.`pago_sdc`.`strike` AS `strike`
|
|
||||||
FROM `vn2008`.`pago_sdc`
|
|
|
@ -1,16 +1,16 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||||
SQL SECURITY DEFINER
|
SQL SECURITY DEFINER
|
||||||
VIEW `vn`.`paymentExchangeInsurance`
|
VIEW `vn`.`paymentExchangeInsurance`
|
||||||
AS SELECT `p`.`pago_sdc_id` AS `id`,
|
AS SELECT `ei`.`id` AS `pago_sdc_id`,
|
||||||
`p`.`importe` AS `amount`,
|
`ei`.`amount` AS `importe`,
|
||||||
`p`.`fecha` AS `created`,
|
`ei`.`dated` AS `fecha`,
|
||||||
`p`.`vencimiento` AS `dueDay`,
|
`ei`.`dueDated` AS `vencimiento`,
|
||||||
`p`.`entity_id` AS `entityFk`,
|
`ei`.`entityFk` AS `entity_id`,
|
||||||
`p`.`ref` AS `ref`,
|
`ei`.`ref` AS `ref`,
|
||||||
`p`.`rate` AS `rate`,
|
`ei`.`rate` AS `rate`,
|
||||||
`p`.`empresa_id` AS `companyFk`,
|
`ei`.`companyFk` AS `empresa_id`,
|
||||||
`p`.`financialProductTypefk` AS `financialProductTypefk`,
|
`ei`.`financialProductTypefk` AS `financialProductTypefk`,
|
||||||
`p`.`upperBarrier` AS `upperBarrier`,
|
`ei`.`upperBarrier` AS `upperBarrier`,
|
||||||
`p`.`lowerBarrier` AS `lowerBarrier`,
|
`ei`.`lowerBarrier` AS `lowerBarrier`,
|
||||||
`p`.`strike` AS `strike`
|
`ei`.`strike` AS `strike`
|
||||||
FROM `vn2008`.`pago_sdc` `p`
|
FROM `vn`.`exchangeInsurance` `ei`
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `vn`.`promissoryNote`
|
|
||||||
AS SELECT `p`.`Id_Pagare` AS `id`,
|
|
||||||
`p`.`Concepto` AS `Concept`,
|
|
||||||
`p`.`pago_id` AS `paymentFk`
|
|
||||||
FROM `vn2008`.`Pagares` `p`
|
|
|
@ -1,8 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `vn`.`saleLabel`
|
|
||||||
AS SELECT `ml`.`Id_movimiento` AS `saleFk`,
|
|
||||||
`ml`.`label` AS `label`,
|
|
||||||
`ml`.`stem` AS `stem`,
|
|
||||||
`ml`.`created` AS `created`
|
|
||||||
FROM `vn2008`.`movement_label` `ml`
|
|
|
@ -1,47 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `vn`.`ticketMRW`
|
|
||||||
AS SELECT `ticket`.`agencyModeFk` AS `id_Agencia`,
|
|
||||||
`ticket`.`companyFk` AS `empresa_id`,
|
|
||||||
`Consignatarios`.`consignatario` AS `Consignatario`,
|
|
||||||
`Consignatarios`.`domicilio` AS `DOMICILIO`,
|
|
||||||
`Consignatarios`.`poblacion` AS `POBLACION`,
|
|
||||||
`Consignatarios`.`codPostal` AS `CODPOSTAL`,
|
|
||||||
`Consignatarios`.`telefono` AS `telefono`,
|
|
||||||
IFNULL(
|
|
||||||
IFNULL(
|
|
||||||
IFNULL(
|
|
||||||
IFNULL(`Consignatarios`.`movil`, `Clientes`.`movil`),
|
|
||||||
`Consignatarios`.`telefono`
|
|
||||||
),
|
|
||||||
`Clientes`.`telefono`
|
|
||||||
),
|
|
||||||
0
|
|
||||||
) AS `movil`,
|
|
||||||
`Clientes`.`if` AS `IF`,
|
|
||||||
`ticket`.`id` AS `Id_Ticket`,
|
|
||||||
`ticket`.`warehouseFk` AS `warehouse_id`,
|
|
||||||
`Consignatarios`.`id_consigna` AS `Id_Consigna`,
|
|
||||||
`Paises`.`Codigo` AS `CodigoPais`,
|
|
||||||
`ticket`.`shipped` AS `Fecha`,
|
|
||||||
`province`.`province_id` AS `province_id`,
|
|
||||||
`ticket`.`landed` AS `landing`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
`vn2008`.`Clientes`
|
|
||||||
JOIN `vn2008`.`Consignatarios` ON(
|
|
||||||
`Clientes`.`id_cliente` = `Consignatarios`.`Id_cliente`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`ticket` ON(
|
|
||||||
`Consignatarios`.`id_consigna` = `ticket`.`addressFk`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
JOIN `vn2008`.`province` ON(
|
|
||||||
`Consignatarios`.`province_id` = `province`.`province_id`
|
|
||||||
)
|
|
||||||
)
|
|
||||||
JOIN `vn2008`.`Paises` ON(`province`.`Paises_Id` = `Paises`.`Id`)
|
|
||||||
);
|
|
|
@ -1,58 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `vn`.`ticketToPrepare`
|
|
||||||
AS SELECT `m`.`Id_Ticket` AS `Id_Ticket`,
|
|
||||||
`mk`.`Id_Movimiento` AS `Id_Movimiento`,
|
|
||||||
`mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`,
|
|
||||||
`mk`.`Id_Trabajador` AS `Id_Trabjador`,
|
|
||||||
`m`.`Id_Article` AS `Id_Article`,
|
|
||||||
`m`.`Concepte` AS `Concepte`,
|
|
||||||
`art`.`subName` AS `subName`,
|
|
||||||
`mk`.`original_quantity` - IFNULL(`is`.`quantity`, 0) AS `Cantidad`,
|
|
||||||
`mk`.`original_quantity` AS `original_quantity`,
|
|
||||||
IF(
|
|
||||||
HOUR(`t`.`shipped`),
|
|
||||||
HOUR(`t`.`shipped`),
|
|
||||||
HOUR(`z`.`hour`)
|
|
||||||
) AS `Hora`,
|
|
||||||
HOUR(`t`.`shipped`) AS `Departure`,
|
|
||||||
MINUTE(`t`.`shipped`) AS `Minuto`,
|
|
||||||
`am`.`agencyFk` AS `agency_id`,
|
|
||||||
`t`.`warehouseFk` AS `warehouse_id`,
|
|
||||||
`a`.`provinceFk` AS `province_id`,
|
|
||||||
`is`.`quantity` AS `picked`,
|
|
||||||
`t`.`zoneFk` AS `zoneFk`,
|
|
||||||
`p`.`sectorFk` AS `sectorFk`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
`vn2008`.`Movimientos_mark` `mk`
|
|
||||||
JOIN `vn2008`.`Movimientos` `m` ON(`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`ticket` `t` ON(`m`.`Id_Ticket` = `t`.`id`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `t`.`agencyModeFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`)
|
|
||||||
)
|
|
||||||
LEFT JOIN `vn`.`itemShelvingSale` `is` ON(`is`.`saleFk` = `mk`.`Id_Movimiento`)
|
|
||||||
)
|
|
||||||
LEFT JOIN `vn`.`itemShelving` `ish` ON(`ish`.`id` = `is`.`itemShelvingFk`)
|
|
||||||
)
|
|
||||||
LEFT JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`)
|
|
||||||
)
|
|
||||||
LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`)
|
|
||||||
)
|
|
||||||
LEFT JOIN `vn2008`.`Articles` `art` ON(`art`.`Id_Article` = `m`.`Id_Article`)
|
|
||||||
)
|
|
||||||
LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`)
|
|
||||||
)
|
|
||||||
WHERE `mk`.`stateFk` = 26
|
|
||||||
AND `mk`.`valor` <> 1
|
|
|
@ -1,47 +0,0 @@
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `vn`.`ticketeToPreparePrepared`
|
|
||||||
AS SELECT `m`.`Id_Ticket` AS `Id_Ticket`,
|
|
||||||
`mk`.`Id_Movimiento` AS `Id_Movimiento`,
|
|
||||||
`mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`,
|
|
||||||
`mk`.`Id_Trabajador` AS `Id_Trabjador`,
|
|
||||||
`m`.`Id_Article` AS `Id_Article`,
|
|
||||||
`m`.`Concepte` AS `Concepte`,
|
|
||||||
`art`.`subName` AS `subName`,
|
|
||||||
`mk`.`original_quantity` - IFNULL(`is`.`quantity`, 0) AS `Cantidad`,
|
|
||||||
`mk`.`original_quantity` AS `original_quantity`,
|
|
||||||
HOUR(`t`.`shipped`) AS `Hora`,
|
|
||||||
HOUR(`t`.`shipped`) AS `Departure`,
|
|
||||||
MINUTE(`t`.`shipped`) AS `Minuto`,
|
|
||||||
`am`.`agencyFk` AS `agency_id`,
|
|
||||||
`t`.`warehouseFk` AS `warehouse_id`,
|
|
||||||
`a`.`provinceFk` AS `province_id`,
|
|
||||||
`is`.`quantity` AS `picked`,
|
|
||||||
`t`.`CodigoTrabajador` AS `trabajador`,
|
|
||||||
`is`.`sectorFk` AS `sectorFk`
|
|
||||||
FROM (
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
(
|
|
||||||
`vn2008`.`Movimientos_mark` `mk`
|
|
||||||
JOIN `vn`.`state` `st` ON(`st`.`id` = `mk`.`stateFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn2008`.`Movimientos` `m` ON(`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`ticket` `t` ON(`m`.`Id_Ticket` = `t`.`id`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `t`.`agencyModeFk`)
|
|
||||||
)
|
|
||||||
JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`)
|
|
||||||
)
|
|
||||||
LEFT JOIN `vn`.`itemShelvingSaleSum` `is` ON(`is`.`saleFk` = `mk`.`Id_Movimiento`)
|
|
||||||
)
|
|
||||||
JOIN `vn2008`.`Articles` `art` ON(`art`.`Id_Article` = `m`.`Id_Article`)
|
|
||||||
)
|
|
||||||
LEFT JOIN `vn2008`.`Trabajadores` `t` ON(`t`.`Id_Trabajador` = `mk`.`Id_Trabajador`)
|
|
||||||
)
|
|
||||||
WHERE `st`.`code` LIKE 'PREVIOUS_PREPARATION'
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
DROP TABLE cache.prod_graphic_source;
|
||||||
|
RENAME TABLE vn2008.unary TO vn2008.unary__;
|
||||||
|
ALTER TABLE vn2008.unary__ COMMENT='refs #7258 @deprecated 2023-12-13';
|
||||||
|
RENAME TABLE vn2008.jerarquia TO vn2008.jerarquia__;
|
||||||
|
ALTER TABLE vn2008.jerarquia__ COMMENT='refs #7258 @deprecated 2023-12-13';
|
|
@ -288,6 +288,7 @@ localFixtures:
|
||||||
- payDemDetail
|
- payDemDetail
|
||||||
- payMethod
|
- payMethod
|
||||||
- payrollCategories
|
- payrollCategories
|
||||||
|
- payrollWorker
|
||||||
- postCode
|
- postCode
|
||||||
- priceFixed
|
- priceFixed
|
||||||
- printer
|
- printer
|
||||||
|
@ -322,6 +323,7 @@ localFixtures:
|
||||||
- shelving
|
- shelving
|
||||||
- smsConfig
|
- smsConfig
|
||||||
- specie
|
- specie
|
||||||
|
- split
|
||||||
- supplier
|
- supplier
|
||||||
- supplierAccount
|
- supplierAccount
|
||||||
- supplierActivity
|
- supplierActivity
|
||||||
|
@ -393,7 +395,3 @@ localFixtures:
|
||||||
- zoneGeo
|
- zoneGeo
|
||||||
- zoneIncluded
|
- zoneIncluded
|
||||||
- zoneWarehouse
|
- zoneWarehouse
|
||||||
vn2008:
|
|
||||||
- payroll_employee
|
|
||||||
- Splits
|
|
||||||
- zones
|
|
||||||
|
|
Loading…
Reference in New Issue
grupo¿?
Sí, si te fijas hace referencia a un alias, es una columna calculada, no hace referencia a una columna de una tabla en si