7167-testToMaster_2414 #2244
|
@ -0,0 +1,103 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`confection_controlSource`(
|
||||
vDated DATE,
|
||||
vScopeDays INT,
|
||||
vMaxAlertLevel INT,
|
||||
vWarehouseFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Obtiene la información para el control de confección,
|
||||
* ya sean tickets y/o entradas.
|
||||
*
|
||||
* @param vDated Fecha a calcular
|
||||
* @param vScopeDays Número de días desde hoy en adelante que entran en el cálculo.
|
||||
* @param vMaxAlertLevel Id nivel de alerta
|
||||
* @param vWarehouseFk Id de almacén
|
||||
*/
|
||||
DECLARE vEndingDate DATETIME DEFAULT util.dayEnd(vDated) + INTERVAL vScopeDays DAY;
|
||||
|
||||
SELECT t.shipped,
|
||||
t.id ticketFk,
|
||||
s.id saleFk,
|
||||
s.quantity,
|
||||
s.concept,
|
||||
ABS(s.reserved) isReserved,
|
||||
i.category,
|
||||
it.name itemType,
|
||||
t.nickname,
|
||||
wh.name warehouse,
|
||||
t.warehouseFk warehouseFk,
|
||||
a.provinceFk,
|
||||
am.agencyFk,
|
||||
ct.description,
|
||||
stock.visible,
|
||||
stock.available
|
||||
FROM ticket t
|
||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
JOIN warehouse wh ON wh.id = t.warehouseFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN confectionType ct ON ct.id = it.making
|
||||
JOIN `address` a on a.id = t.addressFk
|
||||
LEFT JOIN ticketState tls on tls.ticketFk = t.id
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT item_id,
|
||||
SUM(visible) visible,
|
||||
SUM(available) available
|
||||
FROM (
|
||||
SELECT a.item_id,
|
||||
0 visible,
|
||||
a.available
|
||||
FROM cache.cache_calc cc
|
||||
LEFT JOIN cache.available a ON a.calc_id = cc.id
|
||||
WHERE cc.cache_id IN ('visible', 'available')
|
||||
AND cc.params = CONCAT(vWarehouseFk, "/", util.VN_CURDATE())
|
||||
UNION ALL
|
||||
SELECT v.item_id,
|
||||
v.visible,
|
||||
0
|
||||
FROM cache.cache_calc cc
|
||||
LEFT JOIN cache.visible v ON v.calc_id = cc.id
|
||||
WHERE cc.cacheName IN ('visible', 'available')
|
||||
AND cc.params = vWarehouseFk
|
||||
) sub
|
||||
GROUP BY item_id
|
||||
) stock ON stock.item_id = s.itemFk
|
||||
WHERE it.making
|
||||
AND tls.alertLevel < vMaxAlertLevel
|
||||
AND wh.hasConfectionTeam
|
||||
AND t.shipped BETWEEN vDated AND vEndingDate
|
||||
AND s.quantity > 0
|
||||
UNION ALL
|
||||
SELECT tr.shipped,
|
||||
e.id,
|
||||
NULL,
|
||||
b.quantity,
|
||||
i.name,
|
||||
NULL,
|
||||
i.category,
|
||||
NULL,
|
||||
whi.name,
|
||||
who.name,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ct.description,
|
||||
NULL,
|
||||
NULL
|
||||
FROM buy b
|
||||
JOIN `entry` e ON e.id = b.entryFk
|
||||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN warehouse whi ON whi.id = tr.warehouseInFk
|
||||
JOIN warehouse who ON who.id = tr.warehouseOutFk
|
||||
JOIN item i ON i.id = b.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN confectionType ct ON ct.id = it.making
|
||||
WHERE who.hasConfectionTeam
|
||||
AND it.making
|
||||
AND tr.shipped BETWEEN vDated AND vEndingDate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,70 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`remittance_calc`(
|
||||
vDated DATE
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula los datos de remesa, incluyendo el importe,
|
||||
* el vencimiento, y otros datos relevantes.
|
||||
*
|
||||
* @param vDated Fecha a calcular
|
||||
* @return tmp.remittance
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.remittance
|
||||
SELECT CONCAT(s.nif, REPEAT('0', 12 - LENGTH(s.nif))) cif,
|
||||
c.id clientFk,
|
||||
c.name client,
|
||||
c.fi,
|
||||
sub.paymentDate,
|
||||
0 invoiceAmount,
|
||||
CAST(sub.receipt AS DECIMAL(10,2)) receiptAmount,
|
||||
0 currentAmount,
|
||||
sub.companyFk,
|
||||
c.socialName,
|
||||
CAST(sub.receipt AS DECIMAL(10,2)) totalAmount,
|
||||
CAST(sub.receipt AS DECIMAL(10,2)) balance,
|
||||
s.name company,
|
||||
co.code companyCode,
|
||||
c.accountingAccount,
|
||||
c.iban,
|
||||
c.hasSepaVnl,
|
||||
c.hasCoreVnl,
|
||||
c.hasLcr,
|
||||
be.bic,
|
||||
be.`name` entityName
|
||||
FROM client c
|
||||
JOIN (
|
||||
SELECT risk.companyFk,
|
||||
c.id,
|
||||
SUM(risk.amount) receipt,
|
||||
IF((c.dueDay + graceDays) MOD 30.001 <= DAY(vDated),
|
||||
LAST_DAY(vDated - INTERVAL 1 MONTH) + INTERVAL (c.dueDay + graceDays) MOD 30.001 DAY,
|
||||
LAST_DAY(vDated - INTERVAL 2 MONTH) + INTERVAL (c.dueDay + graceDays) MOD 30.001 DAY
|
||||
) paymentDate
|
||||
FROM client c
|
||||
JOIN payMethod pm ON pm.id = c.payMethodFk
|
||||
JOIN (
|
||||
SELECT cr.companyFk, cr.clientFk, cr.amount
|
||||
FROM client c
|
||||
JOIN clientRisk cr ON cr.clientFk = c.id
|
||||
JOIN payMethod pm ON pm.id = c.payMethodFk
|
||||
WHERE pm.code = 'bankDraft'
|
||||
UNION ALL
|
||||
SELECT io.companyFk, io.clientFk, - io.amount
|
||||
FROM invoiceOut io
|
||||
JOIN client c ON c.id = io.clientFk
|
||||
JOIN payMethod pm ON pm.id = c.payMethodFk
|
||||
WHERE io.dued > vDated
|
||||
AND pm.code = 'bankDraft'
|
||||
AND pm.outstandingDebt
|
||||
AND io.amount > 0
|
||||
|
||||
) risk ON risk.clientFk = c.id
|
||||
GROUP BY risk.companyFk, c.id
|
||||
HAVING receipt > 10
|
||||
) sub ON sub.id = c.id
|
||||
JOIN supplier s ON s.id = sub.companyFk
|
||||
JOIN company co ON co.id = sub.companyFk
|
||||
LEFT JOIN bankEntity be ON be.id = c.bankEntityFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,66 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`CalculoRemesas`(IN vFechaRemesa DATE)
|
||||
BEGIN
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS TMP_REMESAS;
|
||||
CREATE TEMPORARY TABLE TMP_REMESAS
|
||||
SELECT
|
||||
CONCAT(p.NIF,REPEAT('0', 12-LENGTH(p.NIF))) as CIF1,
|
||||
cli.Id_Cliente,
|
||||
cli.Cliente,
|
||||
cli.`IF` as NIF,
|
||||
c.PaymentDate as Vencimiento,
|
||||
0 ImporteFac,
|
||||
cast(c.Recibo as decimal(10,2)) as ImporteRec,
|
||||
0 as ImporteActual,
|
||||
c.companyFk empresa_id,
|
||||
cli.RazonSocial,
|
||||
cast(c.Recibo as decimal(10,2)) as ImporteTotal,
|
||||
cast(c.Recibo as decimal(10,2)) as Saldo,
|
||||
p.Proveedor as Empresa,
|
||||
e.abbreviation as EMP,
|
||||
cli.cuenta,
|
||||
iban AS Iban,
|
||||
CONVERT(SUBSTRING(iban,5,4),UNSIGNED INT) AS nrbe,
|
||||
sepavnl as SEPA,
|
||||
corevnl as RecibidoCORE,
|
||||
hasLcr,
|
||||
be.bic,
|
||||
be.`name` entityName
|
||||
FROM Clientes cli
|
||||
JOIN
|
||||
(SELECT risk.companyFk,
|
||||
c.Id_Cliente,
|
||||
sum(risk.amount) as Recibo,
|
||||
IF((c.Vencimiento + graceDays) mod 30.001 <= day(vFechaRemesa)
|
||||
,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-1,vFechaRemesa)))
|
||||
,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-2,vFechaRemesa)))
|
||||
) as PaymentDate
|
||||
FROM Clientes c
|
||||
JOIN pay_met pm on pm.id = pay_met_id
|
||||
JOIN
|
||||
(
|
||||
SELECT companyFk, clientFk, amount
|
||||
FROM Clientes c
|
||||
JOIN vn.clientRisk cr ON cr.clientFk = c.Id_Cliente
|
||||
WHERE pay_met_id = 4
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT io.companyFk, io.clientFk Id_Cliente, - io.amount
|
||||
FROM vn.invoiceOut io
|
||||
JOIN Clientes c ON c.Id_Cliente = io.clientFk
|
||||
JOIN pay_met pm on pm.id = pay_met_id
|
||||
WHERE io.dued > vFechaRemesa
|
||||
AND pay_met_id = 4 AND pm.deudaviva
|
||||
AND io.amount > 0
|
||||
|
||||
) risk ON c.Id_Cliente = risk.clientFk
|
||||
GROUP BY risk.companyFk, Id_Cliente
|
||||
HAVING Recibo > 10
|
||||
) c on c.Id_Cliente = cli.Id_Cliente
|
||||
JOIN Proveedores p on p.Id_Proveedor = c.companyFk
|
||||
JOIN empresa e on e.id = c.companyFk
|
||||
LEFT JOIN vn.bankEntity be ON be.id = cli.bankEntityFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,11 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`cacheReset`(vCacheName VARCHAR(10), vParams VARCHAR(15))
|
||||
BEGIN
|
||||
|
||||
UPDATE cache.cache_calc
|
||||
SET expires = util.VN_NOW()
|
||||
WHERE cacheName = vCacheName collate utf8_unicode_ci
|
||||
AND params = vParams collate utf8_unicode_ci;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,23 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`camiones`(vWarehouse INT, vDate DATE)
|
||||
BEGIN
|
||||
SELECT Temperatura
|
||||
,ROUND(SUM(Etiquetas * volume)) AS cm3
|
||||
,ROUND(SUM(IF(scanned, Etiquetas, 0) * volume)) AS cm3s
|
||||
,ROUND(SUM(Vida * volume)) AS cm3e
|
||||
FROM (
|
||||
SELECT t.Temperatura, c.Etiquetas, b.scanned, c.Vida,
|
||||
IF(cu.Volumen > 0, cu.Volumen, cu.x * cu.y * IF(cu.z > 0, cu.z, a.Medida + 10)) volume
|
||||
FROM Compres c
|
||||
LEFT JOIN buy_edi b ON b.id = c.buy_edi_id
|
||||
JOIN Articles a ON a.Id_Article = c.Id_Article
|
||||
JOIN Tipos t ON t.tipo_id = a.tipo_id
|
||||
JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada
|
||||
JOIN travel tr ON tr.id = e.travel_id
|
||||
JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo
|
||||
WHERE tr.warehouse_id = vWarehouse
|
||||
AND tr.landing = vDate
|
||||
) sub
|
||||
GROUP BY Temperatura;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,79 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`cobro`(IN datFEC DATE
|
||||
, IN idCLI INT
|
||||
, IN dblIMPORTE DOUBLE
|
||||
, IN idCAJA INT
|
||||
, IN idPAYMET INT
|
||||
, IN strCONCEPTO VARCHAR(40)
|
||||
, IN idEMP INT
|
||||
, IN idWH INT
|
||||
, IN idTRABAJADOR INT)
|
||||
BEGIN
|
||||
|
||||
DECLARE bolCASH BOOLEAN;
|
||||
DECLARE cuenta_banco BIGINT;
|
||||
DECLARE cuenta_cliente BIGINT;
|
||||
DECLARE max_asien INT;
|
||||
-- XDIARIO
|
||||
-- No se asientan los cobros directamente, salvo en el caso de las cajas de CASH
|
||||
SELECT (at2.code = 'cash') INTO bolCASH FROM Bancos b JOIN vn.accountingType at2 ON at2.id = b.cash WHERE b.Id_Banco = idCAJA;
|
||||
IF bolCASH THEN
|
||||
SELECT Cuenta INTO cuenta_banco
|
||||
FROM Bancos
|
||||
WHERE Id_Banco = idCAJA;
|
||||
SELECT Cuenta INTO cuenta_cliente
|
||||
FROM Clientes
|
||||
WHERE Id_Cliente = idCLI;
|
||||
CALL vn.ledger_next(max_asien);
|
||||
INSERT INTO vn.XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id)
|
||||
SELECT max_asien,datFEC,SUBCTA,CONTRA,strCONCEPTO,EURODEBE,EUROHABER,idEMP
|
||||
FROM(SELECT cuenta_banco SUBCTA, cuenta_cliente CONTRA, 0 EURODEBE, dblIMPORTE EUROHABER
|
||||
UNION ALL
|
||||
SELECT cuenta_cliente SUBCTA, cuenta_banco CONTRA, dblIMPORTE EURODEBE, 0 EUROHABER
|
||||
) gf;
|
||||
END IF;
|
||||
|
||||
-- CAJERA
|
||||
INSERT INTO Cajas(Id_Trabajador,
|
||||
Id_Banco,
|
||||
Entrada,
|
||||
Concepto,
|
||||
Cajafecha,
|
||||
Serie,
|
||||
Partida,
|
||||
Numero,
|
||||
empresa_id,
|
||||
warehouse_id
|
||||
)
|
||||
VALUES (idTRABAJADOR,
|
||||
idCAJA,
|
||||
dblIMPORTE,
|
||||
strCONCEPTO,
|
||||
datFEC,
|
||||
'A',
|
||||
TRUE,
|
||||
idCLI,
|
||||
idEMP,
|
||||
idWH
|
||||
);
|
||||
|
||||
-- RECIBO
|
||||
INSERT INTO Recibos(Entregado,
|
||||
Fechacobro,
|
||||
Id_Trabajador,
|
||||
Id_Banco,
|
||||
Id_Cliente,
|
||||
Id_Factura,
|
||||
empresa_id
|
||||
)
|
||||
VALUES ( dblIMPORTE,
|
||||
datFEC,
|
||||
idTRABAJADOR,
|
||||
idCAJA,
|
||||
idCLI,
|
||||
strCONCEPTO,
|
||||
idEMP
|
||||
);
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,105 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`confection_control_source`(vDated DATE, vScopeDays TINYINT)
|
||||
BEGIN
|
||||
|
||||
DECLARE vMidnight DATETIME DEFAULT TIMESTAMP(vDated,'23:59:59');
|
||||
DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,vMidnight);
|
||||
DECLARE maxAlertLevel INT DEFAULT 2;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp.production_buffer
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
date(t.Fecha) as Fecha,
|
||||
hour(t.Fecha) as Hora,
|
||||
hour(t.Fecha) as Departure,
|
||||
t.Id_Ticket,
|
||||
m.Id_Movimiento,
|
||||
m.Cantidad,
|
||||
m.Concepte,
|
||||
ABS(m.Reservado) Reservado,
|
||||
i.Categoria,
|
||||
tp.Tipo,
|
||||
t.Alias as Cliente,
|
||||
wh.name as Almacen,
|
||||
t.warehouse_id,
|
||||
cs.province_id,
|
||||
a.agency_id,
|
||||
ct.description as Taller,
|
||||
stock.visible,
|
||||
stock.available
|
||||
FROM vn2008.Tickets t
|
||||
JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
|
||||
JOIN vn.warehouse wh ON wh.id = t.warehouse_id
|
||||
JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket
|
||||
JOIN vn2008.Articles i ON i.Id_Article = m.Id_Article
|
||||
JOIN vn2008.Tipos tp ON tp.tipo_id = i.tipo_id
|
||||
JOIN vn.confectionType ct ON ct.id = tp.confeccion
|
||||
JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
|
||||
LEFT JOIN vn.ticketState tls on tls.ticketFk = t.Id_Ticket
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT item_id, sum(visible) visible, sum(available) available
|
||||
FROM
|
||||
(
|
||||
SELECT a.item_id, 0 as visible, a.available
|
||||
FROM cache.cache_calc cc
|
||||
LEFT JOIN cache.available a ON a.calc_id = cc.id
|
||||
WHERE cc.cache_id IN (2,8)
|
||||
AND cc.params IN (concat("1/", util.VN_CURDATE()),concat("44/", util.VN_CURDATE()))
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT v.item_id, v.visible, 0 as available
|
||||
FROM cache.cache_calc cc
|
||||
LEFT JOIN cache.visible v ON v.calc_id = cc.id
|
||||
where cc.cache_id IN (2,8) and cc.params IN ("1","44")
|
||||
) sub
|
||||
GROUP BY item_id
|
||||
) stock ON stock.item_id = m.Id_Article
|
||||
WHERE tp.confeccion
|
||||
AND tls.alertLevel < maxAlertLevel
|
||||
AND wh.hasConfectionTeam
|
||||
AND t.Fecha BETWEEN vDated AND vEndingDate
|
||||
AND m.Cantidad > 0;
|
||||
|
||||
-- Entradas
|
||||
|
||||
INSERT INTO tmp.production_buffer(
|
||||
Fecha,
|
||||
Id_Ticket,
|
||||
Cantidad,
|
||||
Concepte,
|
||||
Categoria,
|
||||
Cliente,
|
||||
Almacen,
|
||||
Taller
|
||||
)
|
||||
SELECT
|
||||
tr.shipment AS Fecha,
|
||||
e.Id_Entrada AS Id_Ticket,
|
||||
c.Cantidad,
|
||||
a.Article,
|
||||
a.Categoria,
|
||||
whi.name as Cliente,
|
||||
who.name as Almacen,
|
||||
ct.description as Taller
|
||||
FROM vn2008.Compres c
|
||||
JOIN vn2008.Entradas e ON e.Id_Entrada = c.Id_Entrada
|
||||
JOIN vn2008.travel tr ON tr.id = e.travel_id
|
||||
JOIN vn.warehouse whi ON whi.id = tr.warehouse_id
|
||||
JOIN vn.warehouse who ON who.id = tr.warehouse_id_out
|
||||
JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article
|
||||
JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id
|
||||
JOIN vn.confectionType ct ON ct.id = tp.confeccion
|
||||
WHERE who.hasConfectionTeam
|
||||
AND tp.confeccion
|
||||
AND tr.shipment BETWEEN vDated AND vEndingDate;
|
||||
|
||||
|
||||
SELECT * FROM tmp.production_buffer;
|
||||
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,15 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`confection_controlSource`()
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
GRANT EXECUTE ON PROCEDURE vn.confection_controlSource TO handmadeBoss, productionAssi, artificialBoss;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`remittance_calc`()
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
GRANT EXECUTE ON PROCEDURE vn.remittance_calc TO financial;
|
Loading…
Reference in New Issue