udate structure db

This commit is contained in:
Bernat 2019-12-04 11:09:36 +01:00
parent 3163dfa19e
commit f38210ddd2
19 changed files with 3370 additions and 35774 deletions

View File

@ -33,7 +33,6 @@ BEGIN
DECLARE vAgencyModeId INT;
DECLARE TICKET_FREE INT DEFAULT 2;
DECLARE SYSTEM_WORKER INT DEFAULT 20;
DECLARE cDates CURSOR FOR
SELECT zgs.shipped, r.warehouse_id
@ -44,9 +43,9 @@ BEGIN
GROUP BY r.warehouse_id;
DECLARE cRows CURSOR FOR
SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate
SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate
FROM order_row r
JOIN vn2008.Articles a ON a.Id_Article = r.item_id
JOIN vn.item i ON i.id = r.item_id
WHERE r.amount != 0
AND r.warehouse_id = vWarehouse
AND r.order_id = vOrder
@ -64,12 +63,12 @@ BEGIN
-- Carga los datos del pedido
SELECT o.date_send, o.address_id, o.note,
o.confirmed, cs.Id_Cliente, o.company_id, o.agency_id
o.confirmed, a.clientFk, o.company_id, o.agency_id
INTO vDelivery, vAddress, vNotes,
vIsConfirmed, vClientId, vCompanyId, vAgencyModeId
FROM hedera.`order` o
JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id
WHERE id = vOrder;
JOIN vn.address a ON a.id = o.address_id
WHERE o.id = vOrder;
-- Comprueba que el pedido no está confirmado
@ -114,19 +113,18 @@ BEGIN
-- Busca un ticket existente que coincida con los parametros
SELECT Id_Ticket INTO vTicket
FROM vn2008.Tickets t
LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket
SELECT t.id INTO vTicket
FROM vn.ticket t
LEFT JOIN vn.ticketState tls on tls.ticket = t.id
JOIN `order` o
ON o.address_id = t.Id_Consigna
AND vWarehouse = t.warehouse_id
AND o.agency_id = t.Id_Agencia
AND t.landing = o.date_send
AND vShipment = DATE(t.Fecha)
ON o.address_id = t.addressFk
AND vWarehouse = t.warehouseFk
AND o.agency_id = t.agencyModeFk
AND o.date_send = t.landed
AND vShipment = DATE(t.shipped)
WHERE o.id = vOrder
AND t.Factura IS NULL
AND t.invoiceOutFk IS NULL
AND IFNULL(tls.alertLevel,0) = 0
AND t.Id_Cliente <> 1118
LIMIT 1;
-- Crea el ticket en el caso de no existir uno adecuado
@ -148,24 +146,24 @@ BEGIN
ELSE
INSERT INTO vncontrol.inter
SET Id_Ticket = vTicket,
Id_Trabajador = SYSTEM_WORKER,
Id_Trabajador = vUserId,
state_id = TICKET_FREE;
END IF;
INSERT IGNORE INTO vn2008.order_Tickets
SET order_id = vOrder,
Id_Ticket = vTicket;
INSERT IGNORE INTO vn.orderTicket
SET orderFk = vOrder,
ticketFk = vTicket;
-- Añade las notas
IF vNotes IS NOT NULL AND vNotes != ''
THEN
INSERT INTO vn2008.ticket_observation SET
Id_Ticket = vTicket,
observation_type_id = 4 /* salesperson */ ,
`text` = vNotes
INSERT INTO vn.ticketObservation SET
ticketFk = vTicket,
observationTypeFk = 4 /* salesperson */ ,
`description` = vNotes
ON DUPLICATE KEY UPDATE
`text` = CONCAT(VALUES(`text`),'. ', `text`);
`description` = CONCAT(VALUES(`description`),'. ', `description`);
END IF;
-- Añade los movimientos y sus componentes
@ -181,20 +179,20 @@ BEGIN
LEAVE lRows;
END IF;
INSERT INTO vn2008.Movimientos
INSERT INTO vn.sale
SET
Id_Article = vItem,
Id_Ticket = vTicket,
Concepte = vConcept,
Cantidad = vAmount,
Preu = vPrice,
CostFixat = 0,
PrecioFijado = TRUE;
itemFk = vItem,
ticketFk = vTicket,
concept = vConcept,
quantity = vAmount,
price = vPrice,
priceFixed = 0,
isPriceFixed = TRUE;
SET vSale = LAST_INSERT_ID();
INSERT INTO vn2008.Movimientos_componentes
(Id_Movimiento, Id_Componente, Valor)
INSERT INTO vn.saleComponent
(saleFk, componentFk, `value`)
SELECT vSale, cm.component_id, cm.price
FROM order_component cm
JOIN bi.tarifa_componentes tc
@ -215,20 +213,20 @@ BEGIN
CREATE TEMPORARY TABLE tComponents
(INDEX (saleFk))
ENGINE = MEMORY
SELECT SUM(mc.Valor) valueSum, mc.Id_Movimiento saleFk
FROM vn2008.Movimientos_componentes mc
JOIN bi.tarifa_componentes tc USING(Id_Componente)
SELECT SUM(sc.`value`) valueSum, sc.saleFk
FROM vn.saleComponent sc
JOIN bi.tarifa_componentes tc ON tc.Id_Componente = sc.componentFk
JOIN bi.tarifa_componentes_series tcs
ON tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id
AND tcs.base
JOIN vn2008.Movimientos m
ON m.Id_Movimiento = mc.Id_Movimiento
WHERE m.Id_Ticket = vTicket
GROUP BY mc.Id_Movimiento;
JOIN vn.sale s
ON s.id = sc.saleFk
WHERE s.ticketFk = vTicket
GROUP BY sc.saleFk;
UPDATE vn2008.Movimientos m
JOIN tComponents mc ON mc.saleFk = m.Id_Movimiento
SET m.CostFixat = valueSum;
UPDATE vn.sale s
JOIN tComponents mc ON mc.saleFk = s.id
SET s.priceFixed = valueSum;
DROP TEMPORARY TABLE tComponents;
END LOOP;

View File

@ -39,16 +39,16 @@ BEGIN
CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS');
END IF;
END IF;
INSERT INTO vn2008.Tickets (
Id_Cliente,
Fecha,
Id_Consigna,
Id_Agencia,
Alias,
warehouse_id,
Id_Ruta,
empresa_id,
landing,
INSERT INTO ticket (
clientFk,
shipped,
addressFk,
agencyModeFk,
nickname,
warehouseFk,
routeFk,
companyFk,
landed,
zoneFk
)
SELECT

View File

@ -1,34 +0,0 @@
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 ;

View File

@ -1,149 +0,0 @@
DROP procedure IF EXISTS `vn`.`duaTaxBooking`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`duaTaxBooking`(vDuaFk INT)
BEGIN
DECLARE vBookNumber INT;
DECLARE vBookDated DATE;
DECLARE vDiff DECIMAL(10,2);
DECLARE vApunte BIGINT;
SELECT IFNULL(d.ASIEN,MAX(x.ASIEN) + 1 )
INTO vBookNumber
FROM XDiario x
LEFT JOIN dua d ON d.id = vDuaFk ;
SELECT IFNULL(bookEntried, CURDATE()) INTO vBookDated
FROM dua
WHERE id = vDuaFk;
-- Apunte de la aduana
INSERT INTO XDiario(
ASIEN,
FECHA,
SUBCTA,
CONCEPTO,
EUROHABER,
SERIE,
empresa_id,
CLAVE,
FACTURA)
SELECT
vBookNumber,
d.bookEntried,
'4700000999',
CONCAT('DUA ',d.code),
sum(di.amount * tr.rate / 100) EUROHABER,
'R',
d.companyFk,
vDuaFk,
vDuaFk
FROM duaIntrastat di
JOIN intrastat ist ON ist.id = di.intrastatFk
JOIN (SELECT rate, taxClassFk
FROM
(SELECT rate, taxClassFk
FROM invoiceInTaxBookingAccount ta
WHERE ta.effectived <= vBookDated
ORDER BY ta.effectived DESC
) tba
GROUP BY taxClassFk
) tr ON tr.taxClassFk = ist.taxClassFk
JOIN dua d ON d.id = di.duaFk
WHERE di.duaFk = vDuaFk;
-- Apuntes por tipo de IVA y proveedor
INSERT INTO XDiario(
ASIEN,
FECHA,
SUBCTA,
CONTRA,
EURODEBE,
BASEEURO,
CONCEPTO,
FACTURA,
IVA,
AUXILIAR,
SERIE,
FECHA_EX,
FECHA_OP,
FACTURAEX,
NFACTICK,
L340,
LDIFADUAN,
TIPOCLAVE,
TIPOEXENCI,
TIPONOSUJE,
TIPOFACT,
TIPORECTIF,
TERIDNIF,
TERNIF,
TERNOM,
empresa_id,
FECREGCON
)
SELECT
vBookNumber ASIEN,
vBookDated FECHA,
tr.account SUBCTA,
'4330002067' CONTRA,
sum(dt.tax) EURODEBE,
sum(dt.base) BASEEURO,
CONCAT('DUA nº',d.code) CONCEPTO,
d.id FACTURA,
dt.rate IVA,
'*' AUXILIAR,
'D' SERIE,
d.issued FECHA_EX,
d.operated FECHA_OP,
d.code FACTURAEX,
1 NFACTICK,
1 L340,
TRUE LDIFADUAN,
1 TIPOCLAVE,
1 TIPOEXENCI,
1 TIPONOSUJE,
5 TIPOFACT,
1 TIPORECTIF,
IF(s.countryFk IN (30, 1), 1, 4) TERIDNIF,
s.nif TERNIF,
s.name TERNOM,
d.companyFk,
d.booked FECREGCON
FROM duaTax dt
JOIN dua d ON dt.duaFk = d.id
JOIN (SELECT account, rate
FROM
(SELECT rate, account
FROM invoiceInTaxBookingAccount ta
WHERE ta.effectived <= vBookDated
AND taxAreaFk = 'WORLD'
ORDER BY ta.effectived DESC
) tba
GROUP BY rate
) tr ON tr.rate = dt.rate
JOIN supplier s ON s.id = d.companyFk
WHERE d.id = vDuaFk
GROUP BY dt.rate;
SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte
FROM XDiario
WHERE ASIEN = vBookNumber;
UPDATE XDiario
SET BASEEURO = 100 * (EURODEBE - vDiff) / IVA,
EURODEBE = EURODEBE - vDiff
WHERE id = vApunte;
UPDATE dua
SET ASIEN = vBookNumber
WHERE id = vDuaFk;
END$$
DELIMITER ;

View File

@ -1,119 +0,0 @@
USE `vn`;
DROP procedure IF EXISTS `itemDiary`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `itemDiary`(IN vItemId INT, IN vWarehouse INT)
BEGIN
DECLARE vDateInventory DATETIME;
DECLARE vCurdate DATE DEFAULT CURDATE();
DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate);
-- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance
SELECT Fechainventario INTO vDateInventory FROM vn2008.tblContadores;
SET @a = 0;
SELECT DATE(date) AS date,
alertLevel,
stateName,
origin,
reference,
clientFk,
name,
`in`,
`out`,
@a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance,
isPicked,
isTicket
FROM
( SELECT tr.landed as date,
b.quantity as `in`,
NULL as `out`,
IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel,
st.name AS stateName,
s.name as name,
e.ref as reference,
e.id as origin,
s.id as clientFk,
TRUE isPicked,
FALSE AS isTicket
FROM vn.buy b
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel tr ON tr.id = e.travelFk
JOIN vn.supplier s ON s.id = e.supplierFk
JOIN vn.alertLevel al ON al.alertLevel =
CASE
WHEN tr.isReceived != FALSE THEN 3
WHEN tr.isDelivered THEN 1
ELSE 0
END
JOIN vn.state st ON st.code = al.code
WHERE tr.landed >= vDateInventory
AND vWarehouse = tr.warehouseInFk
AND b.itemFk = vItemId
AND e.isInventory = 0
AND e.isRaid = 0
UNION ALL
SELECT tr.shipped as date,
NULL as `in`,
b.quantity as `out`,
IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel,
st.name AS stateName,
s.name as name,
e.ref as reference,
e.id as origin,
s.id as clientFk,
TRUE isPicked,
FALSE AS isTicket
FROM vn.buy b
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel tr ON tr.id = e.travelFk
JOIN vn.warehouse w ON w.id = tr.warehouseOutFk
JOIN vn.supplier s ON s.id = e.supplierFk
JOIN vn.alertLevel al ON al.alertLevel =
CASE
WHEN tr.isReceived != FALSE THEN 3
WHEN tr.isDelivered THEN 1
ELSE 0
END
JOIN vn.state st ON st.code = al.code
WHERE tr.shipped >= vDateInventory
AND vWarehouse =tr.warehouseOutFk
AND s.id <> 4
AND b.itemFk = vItemId
AND e.isInventory = 0
AND w.isFeedStock = 0
AND e.isRaid = 0
UNION ALL
SELECT t.shipped as date,
NULL as `in`,
s.quantity as `out`,
al.alertLevel as alertLevel,
st.name AS stateName,
t.nickname as name,
t.refFk as reference,
t.id as origin,
t.clientFk,
stk.id as isPicked, -- TRUE as isPicked
TRUE as isTicket
FROM vn.sale s
JOIN vn.ticket t ON t.id = s.ticketFk
LEFT JOIN vn.ticketState ts ON ts.ticket = t.id
LEFT JOIN vn.state st ON st.code = ts.code
JOIN vn.client c ON c.id = t.clientFk
JOIN vn.alertLevel al ON al.alertLevel =
CASE
WHEN t.shipped < vCurdate THEN 3
WHEN t.shipped > vDayEnd THEN 0
ELSE IFNULL(ts.alertLevel, 0)
END
LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = 14 -- comentar
WHERE t.shipped >= vDateInventory
AND s.itemFk = vItemId
AND vWarehouse =t.warehouseFk
) AS itemDiary
ORDER BY date, isTicket, alertLevel DESC, isPicked DESC, `in` DESC, `out` DESC;
END$$
DELIMITER ;

View File

@ -1,16 +0,0 @@
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 ;

View File

@ -1,20 +0,0 @@
DROP function IF EXISTS `vn`.`botanicExport_isUpdatable`;
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`botanicExport_isUpdatable`(vEdiGenusFk MEDIUMINT,vEdiSpecieFk MEDIUMINT,
vCountryFk MEDIUMINT,vRestriction MEDIUMINT) RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE vIsUpdatable INTEGER;
SELECT COUNT(*) INTO vIsUpdatable
FROM botanicExport
WHERE ediGenusFk = vEdiGenusFk
AND (vEdiSpecieFk = ediSpecieFk OR IFNULL(vEdiSpecieFk,ediSpecieFk) IS NULL)
AND (vCountryFk = countryFk OR IFNULL(vCountryFk,countryFk) IS NULL)
AND vRestriction = restriction;
RETURN vIsUpdatable;
END$$
DELIMITER ;

View File

@ -1,37 +0,0 @@
DROP function IF EXISTS `vn`.`entry_getCommission`;
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`entry_getCommission`(
vTravelFk INT,
vCurrencyFk INT,
vSupplierFk INT
) RETURNS int(11)
READS SQL DATA
BEGIN
DECLARE vCommission INT;
DECLARE vCurrentCommission INT;
DECLARE vIsCurrencyUsd INT;
SELECT count(*) INTO vIsCurrencyUsd
FROM currency c
WHERE c.code = 'USD' AND id = vCurrencyFk;
IF NOT vIsCurrencyUsd THEN
SELECT commission INTO vCurrentCommission
FROM supplier s
WHERE s.id = vSupplierFk;
RETURN vCurrentCommission;
END IF;
SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission
FROM travel t
LEFT JOIN referenceCurrent r ON r.currencyFk = vCurrencyFk AND r.`dated` <= t.shipped
WHERE t.id = vTravelFk
ORDER BY r.`dated` DESC
LIMIT 1;
RETURN IFNULL(vCommission, 0);
END$$
DELIMITER ;

View File

@ -1,206 +0,0 @@
DROP procedure IF EXISTS `vn`.`invoiceOutBooking`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`invoiceOutBooking`(IN vInvoice INT)
BEGIN
/* Asienta la factura emitida
*
* param vInvoice factura_id
*/
DECLARE vBookNumber INT;
DECLARE vExpenceConcept VARCHAR(50);
DECLARE vIsUeeMember BOOL DEFAULT TRUE;
DECLARE vSpainCountryFk INT;
DECLARE vOldBookNumber INT;
SELECT id INTO vSpainCountryFk FROM country WHERE code = 'ES';
SELECT ASIEN
INTO vOldBookNumber
FROM XDiario x
JOIN invoiceOut io ON io.id = vInvoice
WHERE x.SERIE = io.serial
AND x.FACTURA = RIGHT(io.ref, LENGTH(io.ref) - 1)
LIMIT 1;
DELETE
FROM XDiario
WHERE ASIEN = vOldBookNumber;
DROP TEMPORARY TABLE IF EXISTS rs;
CREATE TEMPORARY TABLE rs
SELECT
c.accountingAccount AS clientBookingAccount,
io.amount as totalAmount,
CONCAT('n/fra ', io.ref) as simpleConcept,
CONCAT('n/fra ', io.ref, ' ', c.name) as Concept,
io.serial AS SERIE,
io.issued AS FECHA_EX,
opDate.FECHA_OP,
io.issued AS FECHA,
1 AS NFACTICK,
IF(ic.correctingFk,'D','') AS TIPOOPE,
io.cplusTrascendency477Fk AS TIPOCLAVE,
io.cplusTaxBreakFk AS TIPOEXENCI,
io.cplusSubjectOpFk AS TIPONOSUJE,
io.cplusInvoiceType477Fk AS TIPOFACT,
ic.cplusRectificationTypeFk AS TIPORECTIF,
io.companyFk,
RIGHT(io.ref, LENGTH(io.ref) - 1) AS invoiceNum,
IF(ct.politicalCountryFk = vSpainCountryFk, vSpainCountryFk, IF(ct.isUeeMember = vIsUeeMember,2,4)) AS TERIDNIF,
CONCAT(IF(ct.isUeeMember = vIsUeeMember,ct.code,''),c.fi) AS TERNIF,
c.socialName AS TERNOM,
ior.serial AS SERIE_RT,
RIGHT(ior.ref, LENGTH(ior.ref) - 1) AS FACTU_RT,
ior.issued AS FECHA_RT,
IF(ior.id,TRUE,FALSE) AS RECTIFICA
FROM invoiceOut io
JOIN (
SELECT GREATEST(MAX(shipped), TIMESTAMPADD(DAY,-15,io.issued)) as FECHA_OP
FROM ticket t
JOIN invoiceOut io ON io.ref = t.refFk
WHERE io.id = vInvoice ) opDate
JOIN invoiceOutSerial ios ON ios.code = io.serial
JOIN client c ON c.id = io.clientFk
JOIN country ct ON ct.id = c.countryFk
LEFT JOIN invoiceCorrection ic ON ic.correctingFk = io.id
LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
WHERE io.id = vInvoice;
SELECT MAX(ASIEN) + 1
INTO vBookNumber
FROM XDiario;
-- Linea del cliente
INSERT INTO XDiario(
ASIEN,
FECHA,
SUBCTA,
EURODEBE,
CONCEPTO,
FECHA_EX,
FECHA_OP,
empresa_id
)
SELECT
vBookNumber AS ASIEN,
rs.FECHA,
rs.clientBookingAccount AS SUBCTA,
rs.totalAmount AS EURODEBE,
rs.simpleConcept AS CONCEPTO,
rs.FECHA_EX,
rs.FECHA_OP,
rs.companyFk AS empresa_id
FROM rs;
-- Lineas de gasto
INSERT INTO XDiario(
ASIEN,
FECHA,
SUBCTA,
CONTRA,
EUROHABER,
CONCEPTO,
FECHA_EX,
FECHA_OP,
empresa_id
)
SELECT
vBookNumber AS ASIEN,
rs.FECHA,
ioe.expenceFk AS SUBCTA,
rs.clientBookingAccount AS CONTRA,
ioe.amount AS EUROHABER,
rs.Concept AS CONCEPTO,
rs.FECHA_EX,
rs.FECHA_OP,
rs.companyFk AS empresa_id
FROM rs
JOIN invoiceOutExpence ioe
WHERE ioe.invoiceOutFk = vInvoice;
SELECT GROUP_CONCAT(`name` SEPARATOR ',')
INTO vExpenceConcept
FROM expence e
JOIN invoiceOutExpence ioe ON ioe.expenceFk = e.id
WHERE ioe.invoiceOutFk = vInvoice;
-- Lineas de IVA
INSERT INTO XDiario(
ASIEN,
FECHA,
SUBCTA,
CONTRA,
EUROHABER,
BASEEURO,
CONCEPTO,
FACTURA,
IVA,
RECEQUIV,
AUXILIAR,
SERIE,
SERIE_RT,
FACTU_RT,
RECTIFICA,
FECHA_RT,
FECHA_OP,
FECHA_EX,
TIPOOPE,
NFACTICK,
TERIDNIF,
TERNIF,
TERNOM,
L340,
TIPOCLAVE,
TIPOEXENCI,
TIPONOSUJE,
TIPOFACT,
TIPORECTIF,
empresa_id
)
SELECT
vBookNumber AS ASIEN,
rs.FECHA,
iot.pgcFk AS SUBCTA,
rs.clientBookingAccount AS CONTRA,
iot.vat AS EUROHABER,
iot.taxableBase AS BASEEURO,
CONCAT(vExpenceConcept,' : ',rs.Concept) AS CONCEPTO,
rs.invoiceNum AS FACTURA,
IF(pe2.equFk,0,pgc.rate) AS IVA,
IF(pe2.equFk,0,pgce.rate) AS RECEQUIV,
IF(pgc.mod347,'','*') AS AUXILIAR,
rs.SERIE,
rs.SERIE_RT,
rs.FACTU_RT,
rs.RECTIFICA,
rs.FECHA_RT,
rs.FECHA_OP,
rs.FECHA_EX,
rs.TIPOOPE,
rs.NFACTICK,
rs.TERIDNIF,
rs.TERNIF,
rs.TERNOM,
pgc.mod340 AS L340,
pgc.cplusTrascendency477Fk AS TIPOCLAVE,
pgc.cplusTaxBreakFk as TIPOEXENCI,
rs.TIPONOSUJE,
rs.TIPOFACT,
rs.TIPORECTIF,
rs.companyFk AS empresa_id
FROM rs
JOIN invoiceOutTax iot
JOIN pgc ON pgc.code = iot.pgcFk
LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk -- --------------- Comprueba si la linea es de iva con rec.equiv. asociado
LEFT JOIN pgc pgce ON pgce.code = pe.equFk
LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv.
WHERE iot.invoiceOutFk = vInvoice;
UPDATE invoiceOut
SET booked = CURDATE()
WHERE id = vInvoice;
END$$
DELIMITER ;

View File

@ -1,2 +0,0 @@
DROP TRIGGER IF EXISTS `bs`.`mana_spellers_AFTER_INSERT`;

View File

@ -1,81 +0,0 @@
DROP TRIGGER IF EXISTS `vncontrol`.`ticketTracking_afterInsert`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vncontrol`.`ticketTracking_afterInsert`
AFTER INSERT ON `inter`
FOR EACH ROW
BEGIN
REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name)
SELECT NEW.Id_Ticket, NEW.inter_id, `name`
FROM vn.state
WHERE id = NEW.state_id;
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vncontrol`.`ticketTracking_afterUpdate`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vncontrol`.`ticketTracking_afterUpdate`
AFTER UPDATE ON `inter`
FOR EACH ROW
BEGIN
DECLARE vTicketFk INT;
DECLARE vTicketTrackingFk INT;
DECLARE vStateName VARCHAR(15);
IF NEW.state_id <> OLD.state_id THEN
REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name)
SELECT NEW.Id_Ticket, NEW.inter_id, `name`
FROM vn.state
WHERE id = NEW.state_id;
END IF;
IF NEW.Id_Ticket <> OLD.Id_Ticket THEN
SELECT i.Id_Ticket, i.inter_id, s.`name`
INTO vTicketFk, vTicketTrackingFk, vStateName
FROM vncontrol.inter i
JOIN vn.state s ON i.state_id = s.id
WHERE Id_Ticket = NEW.Id_Ticket
ORDER BY odbc_date DESC
LIMIT 1;
IF vTicketFk > 0 THEN
REPLACE INTO vn.ticketLastState(ticketFk, ticketTrackingFk,name)
VALUES(vTicketFk, vTicketTrackingFk, vStateName);
END IF;
END IF;
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vncontrol`.`ticketTracking_afterDelete`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vncontrol`.`ticketTracking_afterDelete`
AFTER DELETE ON `inter`
FOR EACH ROW
BEGIN
DECLARE vTicketFk INT;
DECLARE vTicketTrackingFk INT;
DECLARE vStateName VARCHAR(15);
DECLARE CONTINUE HANDLER FOR SQLSTATE '23000'
BEGIN
DELETE FROM vn.ticketLastState
WHERE ticketFk = OLD.Id_Ticket;
END;
SELECT i.Id_Ticket, i.inter_id, s.`name`
INTO vTicketFk, vTicketTrackingFk, vStateName
FROM vncontrol.inter i
JOIN vn.state s ON i.state_id = s.id
WHERE Id_Ticket = OLD.Id_Ticket
ORDER BY odbc_date DESC
LIMIT 1;
IF vTicketFk > 0 THEN
REPLACE INTO vn.ticketLastState(ticketFk, ticketTrackingFk,name)
VALUES(vTicketFk, vTicketTrackingFk, vStateName);
END IF;
END$$
DELIMITER ;

View File

@ -1,18 +0,0 @@
DROP TRIGGER IF EXISTS `account`.`user_afterUpdate`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `account`.`user_afterUpdate`
AFTER UPDATE ON `user`
FOR EACH ROW
BEGIN
IF !(NEW.`role` <=> OLD.`role`)
THEN
INSERT INTO vn.mail SET
`sender` = 'jgallego@verdnatura.es',
`replyTo` = 'jgallego@verdnatura.es',
`subject` = 'Rol modificado',
`body` = CONCAT(myUserGetName(), ' ha modificado el rol del usuario ',
NEW.`name`, ' de ', OLD.role, ' a ', NEW.role);
END IF;
END$$
DELIMITER ;

View File

@ -1,36 +0,0 @@
DROP function IF EXISTS `vn`.`buy_hasNotifyPassport`;
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`buy_hasNotifyPassport`(vBuyFk INT, vItemFk INT) RETURNS tinyint(1)
READS SQL DATA
BEGIN
DECLARE vHasPassport BOOL;
DECLARE vIsAlreadySent BOOL;
DECLARE vItemCategoryFk INT;
SELECT id INTO vItemCategoryFk FROM itemCategory WHERE code = 'plant';
SELECT COUNT(*) INTO vHasPassport
FROM botanicExport be
JOIN itemBotanical ib
ON be.ediGenusFk = ib.genusFk
AND IFNULL(be.ediSpecieFk, ib.specieFk) = ib.specieFk
AND be.restriction = 'pasaporte fitosanitario'
JOIN item i ON i.id = ib.itemFk
JOIN itemType it ON it.id = i.typeFk
WHERE ib.itemFk = vItemFk
AND it.categoryFk = vItemCategoryFk;
IF vHasPassport THEN
SELECT COUNT(*) INTO vIsAlreadySent
FROM mail m
JOIN buy b ON b.id = vBuyFk
WHERE m.`body` LIKE CONCAT('%', b.ektFk, '%')
LIMIT 1;
END IF;
RETURN vHasPassport AND NOT vIsAlreadySent;
END$$
DELIMITER ;

View File

@ -1,13 +0,0 @@
DROP function IF EXISTS `vn2008`.`botanic_export_is_updatable`;
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `vn2008`.`botanic_export_is_updatable`(v_edi_genus_id MEDIUMINT,v_edi_specie_id MEDIUMINT,v_id_Paises MEDIUMINT,v_restriction MEDIUMINT) RETURNS int(11)
DETERMINISTIC
BEGIN
-- DEPRECATED: use vn.botanicExport_isUpdatable
RETURN botanicExport_isUpdatable (v_edi_genus_id, v_edi_specie_id, v_id_Paises, v_restriction);
END$$
DELIMITER ;

View File

@ -1,60 +0,0 @@
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 buy_hasNotifyPassport(vSelf, vItemFk) THEN
CALL 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 = vSelf;
END IF;
END$$
DELIMITER ;

View File

@ -1,3 +1,6 @@
-- FIXME: cuando se eliminen los procedimientos de la cache, se podra eliminar esta linea
CREATE SCHEMA `vn2008`;
ALTER TABLE `vn`.`itemTaxCountry` AUTO_INCREMENT = 1;
ALTER TABLE `vn`.`address` AUTO_INCREMENT = 1;
ALTER TABLE `vn`.`zoneGeo` AUTO_INCREMENT = 1;
@ -17,7 +20,7 @@ INSERT INTO `vn`.`bionicConfig` (`generalInflationCoeficient`, `minimumDensityVo
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`;
FROM `account`.`role` WHERE id <> 20;
INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `userFk`, `bossFk`)
SELECT id,UPPER(LPAD(role, 3, '0')), name, name, id, 9
@ -885,6 +888,11 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`)
(32, 36, -92.324),
(32, 39, 0.994);
INSERT INTO `vncontrol`.`accion`(`accion_id`, `accion`)
VALUES
(3, 'ACTION ONE'),
(4, 'ACTIOn TWO');
INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuantity`, `workerFk`, `actionFk`, `id`, `stateFk`)
VALUES
(1, 0, CURDATE(), 5, 55, 3, 1, 14),

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,6 @@ SCHEMAS=(
stock
util
vn
vn2008
vncontrol
)

View File

@ -49,7 +49,6 @@ module.exports = function(Self) {
let query = `SELECT vn.invoiceSerial(?, ?, ?) AS serial`;
let [result] = await Self.rawSql(query, [ticket.clientFk, ticket.companyFk, 'R'], options);
let serial = result.serial;
let stmts = [];
stmt = new ParameterizedSQL('CALL vn.invoiceOut_newFromTicket(?, ?, ?, @invoiceId)', [