diff --git a/db/routines/edi/procedures/ekt_load.sql b/db/routines/edi/procedures/ekt_load.sql index 920226693..ccdcd1999 100644 --- a/db/routines/edi/procedures/ekt_load.sql +++ b/db/routines/edi/procedures/ekt_load.sql @@ -22,6 +22,7 @@ proc:BEGIN DECLARE vHasItemGroup BOOL; DECLARE vDescription VARCHAR(255); DECLARE vSaleFk INT; + DECLARE vDefaultEntry INT; -- Carga los datos necesarios del EKT SELECT e.ref, qty, package, putOrderFk MOD 1000000, i2.id , NOT ISNULL(eea.addressFk), NOT ISNULL(igto.group_code), @@ -41,6 +42,9 @@ proc:BEGIN CALL vn.mail_insert('pako@verdnatura.es', 'nocontestar@verdnatura.es', CONCAT('Nuevo grupo en Floramondo: ', vDescription), vDescription); LEAVE proc; END IF; + + SELECT defaultEntry INTO vDefaultEntry + FROM vn.entryConfig; -- Asigna la entrada SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; @@ -100,10 +104,9 @@ proc:BEGIN LEFT JOIN ekt l ON l.ref = e.ref LEFT JOIN vn.buy b ON b.ektFk = l.id LEFT JOIN vn.item i ON i.id = b.itemFk - JOIN vn2008.config cfg WHERE e.id = vSelf AND l.id != vSelf - AND b.itemFk != cfg.generic_item + AND b.itemFk != vDefaultEntry AND IF(t.s1, l.s1 = e.s1, TRUE) AND IF(t.s2, l.s2 = e.s2, TRUE) AND IF(t.s3, l.s3 = e.s3, TRUE) @@ -142,7 +145,7 @@ proc:BEGIN SELECT vEntryFk, vSelf, (@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue, - IFNULL(vItem, cfg.generic_item) itemFk, + IFNULL(vItem, vDefaultEntry) itemFk, e.qty stickers, @pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing, IFNULL(b.`grouping`, e.pac), @@ -153,8 +156,7 @@ proc:BEGIN FROM ekt e LEFT JOIN vn.buy b ON b.id = vBuy LEFT JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.supplier s ON e.pro = s.id - JOIN vn2008.config cfg + LEFT JOIN vn.supplier s ON e.pro = s.id WHERE e.id = vSelf LIMIT 1; diff --git a/db/routines/edi/views/ektK2.sql b/db/routines/edi/views/ektK2.sql new file mode 100644 index 000000000..299d26b01 --- /dev/null +++ b/db/routines/edi/views/ektK2.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `edi`.`ektK2` +AS SELECT `eek`.`id` AS `id`, + `eek`.`description` AS `description` +FROM `edi`.`ektK1` `eek` diff --git a/db/routines/vn/triggers/accountReconciliation_beforeInsert.sql b/db/routines/vn/triggers/accountReconciliation_beforeInsert.sql new file mode 100644 index 000000000..c586dc57e --- /dev/null +++ b/db/routines/vn/triggers/accountReconciliation_beforeInsert.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`accountReconciliation_beforeInsert` + BEFORE INSERT ON `accountReconciliation` + FOR EACH ROW + + SET NEW.calculatedCode = REPLACE( + REPLACE( + REPLACE( + REPLACE( + CONCAT(NEW.supplierAccountFk,NEW.operationDated,NEW.amount,NEW.concept,NEW.debitCredit) + ,' ','') + ,":",'') + ,'-','') + ,'.','')$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/awbInvoiceIn_afterDelete.sql b/db/routines/vn/triggers/awbInvoiceIn_afterDelete.sql new file mode 100644 index 000000000..b41d6efd6 --- /dev/null +++ b/db/routines/vn/triggers/awbInvoiceIn_afterDelete.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`awbInvoiceIn_afterDelete` + AFTER DELETE ON `awbInvoiceIn` + FOR EACH ROW +BEGIN + IF (SELECT COUNT(*) FROM invoiceInTax where invoiceInFk = OLD.invoiceInFk) = 0 + AND + (SELECT COUNT(*) FROM invoiceInDueDay where invoiceInFk = OLD.invoiceInFk) = 0 + AND + (SELECT isBooked FROM invoiceIn WHERE id = OLD.invoiceInFk) = 0 + THEN + DELETE FROM invoiceIn WHERE id = OLD.invoiceInFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/views/bankPolicy.sql b/db/routines/vn/views/bankPolicy.sql deleted file mode 100644 index e329d2b2c..000000000 --- a/db/routines/vn/views/bankPolicy.sql +++ /dev/null @@ -1,24 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`bankPolicy` -AS SELECT `bp`.`poliza_id` AS `id`, - `bp`.`referencia` AS `ref`, - `bp`.`importe` AS `amount`, - `bp`.`com_dispuesto` AS `balanceInterestDrawn`, - `bp`.`com_no_dispuesto` AS `commissionAvailableBalances`, - `bp`.`com_anual` AS `openingCommission`, - `bp`.`apertura` AS `started`, - `bp`.`cierre` AS `ended`, - `bp`.`Id_Banco` AS `bankFk`, - `bp`.`empresa_id` AS `companyFk`, - `bp`.`supplierFk` AS `supplierFk`, - `bp`.`description` AS `description`, - `bp`.`hasGuarantee` AS `hasGuarantee`, - `bp`.`dmsFk` AS `dmsFk`, - `bp`.`notaryFk` AS `notaryFk`, - `bp`.`currencyFk` AS `currencyFk`, - `bp`.`amortizationTypeFk` AS `amortizationTypeFk`, - `bp`.`periodicityTypeFk` AS `periodicityTypeFk`, - `bp`.`insuranceExpired` AS `insuranceExpired` -FROM `vn2008`.`Bancos_poliza` `bp` -ORDER BY `bp`.`poliza_id` DESC diff --git a/db/routines/vn2008/triggers/Conteo_afterInsert.sql b/db/routines/vn2008/triggers/Conteo_afterInsert.sql deleted file mode 100644 index 90f2a5edd..000000000 --- a/db/routines/vn2008/triggers/Conteo_afterInsert.sql +++ /dev/null @@ -1,14 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`Conteo_afterInsert` - AFTER INSERT ON `Conteo` - FOR EACH ROW -BEGIN - DECLARE intTravel INTEGER; - SELECT t.id INTO intTravel FROM Compres c JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - WHERE landing = util.VN_CURDATE() AND c.Id_Article = NEW.Id_Article AND warehouse_id = NEW.warehouse_id AND received <> TRUE LIMIT 1; - IF (intTravel) then - UPDATE travel SET received = TRUE WHERE id = intTravel; - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/triggers/account_conciliacion_beforeInsert.sql b/db/routines/vn2008/triggers/account_conciliacion_beforeInsert.sql deleted file mode 100644 index fb6283e1a..000000000 --- a/db/routines/vn2008/triggers/account_conciliacion_beforeInsert.sql +++ /dev/null @@ -1,14 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`account_conciliacion_beforeInsert` - BEFORE INSERT ON `account_conciliacion` - FOR EACH ROW -set new.id_calculated = replace( - replace( - replace( - replace( - concat(new.Id_Proveedores_account,new.Fechaoperacion,new.importe,new.Concepto,new.DebeHaber) - ,' ','') - ,":",'') - ,'-','') - ,'.','')$$ -DELIMITER ; diff --git a/db/routines/vn2008/triggers/agency_hour_afterUpdate.sql b/db/routines/vn2008/triggers/agency_hour_afterUpdate.sql deleted file mode 100644 index 81996137b..000000000 --- a/db/routines/vn2008/triggers/agency_hour_afterUpdate.sql +++ /dev/null @@ -1,18 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`agency_hour_afterUpdate` - AFTER UPDATE ON `agency_hour` - FOR EACH ROW -BEGIN -DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; - - SELECT COUNT(*) INTO vAlreadyExists - FROM vn2008.agency_hour - WHERE NEW.week_day <=> week_day AND NEW.province_id <=> province_id - AND NEW.warehouse_id <=> warehouse_id AND NEW.max_hour <=> max_hour - AND NEW.agency_id <=> agency_id; - - IF vAlreadyExists > 1 THEN - CALL util.throw('ALREADY_EXISTS'); - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/triggers/agency_hour_beforeInsert.sql b/db/routines/vn2008/triggers/agency_hour_beforeInsert.sql deleted file mode 100644 index a6007934e..000000000 --- a/db/routines/vn2008/triggers/agency_hour_beforeInsert.sql +++ /dev/null @@ -1,21 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`agency_hour_beforeInsert` - BEFORE INSERT ON `agency_hour` - FOR EACH ROW -BEGIN - DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; - IF NEW.week_day IS NULL AND NEW.province_id IS NULL AND NEW.subtract_day = 0 AND NEW.max_hour = 0 THEN - CALL util.throw ('FILL_MORE_FIELDS'); - END IF; - - SELECT COUNT(*) INTO vAlreadyExists - FROM vn2008.agency_hour - WHERE NEW.week_day <=> week_day AND NEW.province_id <=> province_id - AND NEW.warehouse_id <=> warehouse_id AND NEW.max_hour <=> max_hour - AND NEW.agency_id <=> agency_id; - - IF vAlreadyExists > 1 THEN - CALL util.throw('ALREADY_EXISTS'); - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/triggers/awb_recibida_afterDelete.sql b/db/routines/vn2008/triggers/awb_recibida_afterDelete.sql deleted file mode 100644 index 6a3380b8f..000000000 --- a/db/routines/vn2008/triggers/awb_recibida_afterDelete.sql +++ /dev/null @@ -1,13 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`awb_recibida_afterDelete` - AFTER DELETE ON `awb_recibida` - FOR EACH ROW -IF (SELECT COUNT(*) FROM recibida_iva where recibida_id = OLD.recibida_id) = 0 - AND - (SELECT COUNT(*) FROM recibida_vencimiento where recibida_id = OLD.recibida_id) = 0 - AND - (SELECT contabilizada FROM recibida WHERE id = OLD.recibida_id) = 0 -THEN - DELETE FROM recibida WHERE id = OLD.recibida_id; -END IF$$ -DELIMITER ; diff --git a/db/routines/vn2008/views/Bancos_poliza.sql b/db/routines/vn2008/views/Bancos_poliza.sql new file mode 100644 index 000000000..4cd443545 --- /dev/null +++ b/db/routines/vn2008/views/Bancos_poliza.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Bancos_poliza` +AS SELECT `bp`.`id` AS `poliza_id`, + `bp`.`ref` AS `referencia`, + `bp`.`amount` AS `importe`, + `bp`.`committedFee` AS `com_dispuesto`, + `bp`.`nonCommittedFee` AS `com_no_dispuesto`, + `bp`.`annualFee` AS `com_anual`, + `bp`.`started` AS `apertura`, + `bp`.`ended` AS `cierre`, + `bp`.`accountingFk` AS `Id_Banco`, + `bp`.`companyFk` AS `empresa_id`, + `bp`.`supplierFk` AS `supplierFk`, + `bp`.`description` AS `description`, + `bp`.`hasGuarantee` AS `hasGuarantee`, + `bp`.`dmsFk` AS `dmsFk`, + `bp`.`notaryFk` AS `notaryFk`, + `bp`.`currencyFk` AS `currencyFk`, + `bp`.`amortizationTypeFk` AS `amortizationTypeFk`, + `bp`.`periodicityTypeFk` AS `periodicityTypeFk`, + `bp`.`insuranceExpired` AS `insuranceExpired` +FROM `vn`.`bankPolicy` `bp` +ORDER BY `bp`.`id` DESC diff --git a/db/routines/vn2008/views/Entradas_orden.sql b/db/routines/vn2008/views/Entradas_orden.sql new file mode 100644 index 000000000..66f46a929 --- /dev/null +++ b/db/routines/vn2008/views/Entradas_orden.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Entradas_orden` +AS SELECT `eo`.`entryFk` AS `Id_Entrada`, + `eo`.`order` AS `orden` +FROM `vn`.`entryOrder` `eo` diff --git a/db/routines/vn2008/views/Proveedores_gestdoc.sql b/db/routines/vn2008/views/Proveedores_gestdoc.sql new file mode 100644 index 000000000..c25623b8b --- /dev/null +++ b/db/routines/vn2008/views/Proveedores_gestdoc.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Proveedores_gestdoc` +AS SELECT `sd`.`supplierFk` AS `Id_Proveedor`, + `sd`.`dmsFk` AS `gestdoc_id` +FROM `vn`.`supplierDms` `sd` diff --git a/db/routines/vn2008/views/Split.sql b/db/routines/vn2008/views/Split.sql index 1b90e5e0e..eec90a5f8 100644 --- a/db/routines/vn2008/views/Split.sql +++ b/db/routines/vn2008/views/Split.sql @@ -1,4 +1,4 @@ -ls CREATE OR REPLACE DEFINER=`root`@`localhost` +CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn2008`.`Splits` AS SELECT `s`.`id` AS `Id_Split`,