Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6598-getUserAcls
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
97084cb0f2
|
@ -1,5 +1,6 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`xdiario_new`(vAsiento INT,
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`xdiario_new`(
|
||||||
|
vBookNumber INT,
|
||||||
vDated DATE,
|
vDated DATE,
|
||||||
vSubaccount VARCHAR(12),
|
vSubaccount VARCHAR(12),
|
||||||
vAccount VARCHAR(12),
|
vAccount VARCHAR(12),
|
||||||
|
@ -12,18 +13,18 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`xdiario_new`(vAsient
|
||||||
vVat DOUBLE,
|
vVat DOUBLE,
|
||||||
vRe DOUBLE,
|
vRe DOUBLE,
|
||||||
vAux TINYINT,
|
vAux TINYINT,
|
||||||
vCompany INT
|
vCompanyFk INT
|
||||||
)
|
)
|
||||||
RETURNS int(11)
|
RETURNS int(11)
|
||||||
NOT DETERMINISTIC
|
NOT DETERMINISTIC
|
||||||
NO SQL
|
NO SQL
|
||||||
BEGIN
|
BEGIN
|
||||||
IF vAsiento IS NULL THEN
|
IF vBookNumber IS NULL THEN
|
||||||
CALL vn.ledger_next(vAsiento);
|
CALL ledger_next(YEAR(vDated), vBookNumber);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
INSERT INTO XDiario
|
INSERT INTO XDiario
|
||||||
SET ASIEN = vAsiento,
|
SET ASIEN = vBookNumber,
|
||||||
FECHA = vDated,
|
FECHA = vDated,
|
||||||
SUBCTA = vSubaccount,
|
SUBCTA = vSubaccount,
|
||||||
CONTRA = vAccount,
|
CONTRA = vAccount,
|
||||||
|
@ -37,8 +38,8 @@ BEGIN
|
||||||
RECEQUIV = vRe,
|
RECEQUIV = vRe,
|
||||||
AUXILIAR = IF(vAux = FALSE, NULL, '*'),
|
AUXILIAR = IF(vAux = FALSE, NULL, '*'),
|
||||||
MONEDAUSO = 2,
|
MONEDAUSO = 2,
|
||||||
empresa_id = vCompany;
|
empresa_id = vCompanyFk;
|
||||||
|
|
||||||
RETURN vAsiento;
|
RETURN vBookNumber;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -6,16 +6,16 @@ BEGIN
|
||||||
DECLARE vDiff DECIMAL(10,2);
|
DECLARE vDiff DECIMAL(10,2);
|
||||||
DECLARE vApunte BIGINT;
|
DECLARE vApunte BIGINT;
|
||||||
|
|
||||||
SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE()) INTO vBookNumber, vBookDated
|
SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE())
|
||||||
|
INTO vBookNumber, vBookDated
|
||||||
FROM dua
|
FROM dua
|
||||||
WHERE id = vDuaFk;
|
WHERE id = vDuaFk;
|
||||||
|
|
||||||
IF vBookNumber IS NULL OR NOT vBookNumber THEN
|
IF vBookNumber IS NULL OR NOT vBookNumber THEN
|
||||||
CALL ledger_next(vBookNumber);
|
CALL ledger_next(YEAR(vBookDated), vBookNumber);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Apunte de la aduana
|
-- Apunte de la aduana
|
||||||
|
|
||||||
INSERT INTO XDiario(
|
INSERT INTO XDiario(
|
||||||
ASIEN,
|
ASIEN,
|
||||||
FECHA,
|
FECHA,
|
||||||
|
@ -26,9 +26,7 @@ BEGIN
|
||||||
empresa_id,
|
empresa_id,
|
||||||
CLAVE,
|
CLAVE,
|
||||||
FACTURA)
|
FACTURA)
|
||||||
|
SELECT vBookNumber,
|
||||||
SELECT
|
|
||||||
vBookNumber,
|
|
||||||
d.bookEntried,
|
d.bookEntried,
|
||||||
'4700000999',
|
'4700000999',
|
||||||
CONCAT('DUA ',d.`code`),
|
CONCAT('DUA ',d.`code`),
|
||||||
|
@ -42,7 +40,6 @@ BEGIN
|
||||||
WHERE dt.duaFk = vDuaFk;
|
WHERE dt.duaFk = vDuaFk;
|
||||||
|
|
||||||
-- Apuntes por tipo de IVA y proveedor
|
-- Apuntes por tipo de IVA y proveedor
|
||||||
|
|
||||||
INSERT INTO XDiario(
|
INSERT INTO XDiario(
|
||||||
ASIEN,
|
ASIEN,
|
||||||
FECHA,
|
FECHA,
|
||||||
|
@ -70,16 +67,13 @@ BEGIN
|
||||||
TERNIF,
|
TERNIF,
|
||||||
TERNOM,
|
TERNOM,
|
||||||
empresa_id,
|
empresa_id,
|
||||||
FECREGCON
|
FECREGCON)
|
||||||
)
|
SELECT vBookNumber ASIEN,
|
||||||
|
|
||||||
SELECT
|
|
||||||
vBookNumber ASIEN,
|
|
||||||
vBookDated FECHA,
|
vBookDated FECHA,
|
||||||
tr.account SUBCTA,
|
tr.account SUBCTA,
|
||||||
'4330002067' CONTRA,
|
'4330002067' CONTRA,
|
||||||
sum(dt.tax) EURODEBE,
|
SUM(dt.tax) EURODEBE,
|
||||||
sum(dt.base) BASEEURO,
|
SUM(dt.base) BASEEURO,
|
||||||
CONCAT('DUA nº',d.code) CONCEPTO,
|
CONCAT('DUA nº',d.code) CONCEPTO,
|
||||||
d.id FACTURA,
|
d.id FACTURA,
|
||||||
dt.rate IVA,
|
dt.rate IVA,
|
||||||
|
@ -131,6 +125,5 @@ BEGIN
|
||||||
UPDATE dua
|
UPDATE dua
|
||||||
SET ASIEN = vBookNumber
|
SET ASIEN = vBookNumber
|
||||||
WHERE id = vDuaFk;
|
WHERE id = vDuaFk;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_getFromEntries`(IN vInvoiceInFk INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_getFromEntries`(
|
||||||
|
IN vInvoiceInFk INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vRate DOUBLE DEFAULT 1;
|
DECLARE vRate DOUBLE DEFAULT 1;
|
||||||
DECLARE vDated DATE;
|
|
||||||
DECLARE vExpenseFk VARCHAR(10);
|
DECLARE vExpenseFk VARCHAR(10);
|
||||||
|
|
||||||
SELECT MAX(rr.dated) INTO vDated
|
WITH rate AS(
|
||||||
FROM referenceRate rr
|
SELECT MAX(rr.dated) dated, ii.currencyFk
|
||||||
JOIN invoiceIn ii ON ii.id = vInvoiceInFk
|
FROM vn.invoiceIn ii
|
||||||
WHERE rr.dated <= ii.issued
|
JOIN vn.referenceRate rr ON rr.currencyFk = ii.currencyFk
|
||||||
AND rr.currencyFk = ii.currencyFk ;
|
WHERE ii.id = vInvoiceInFk
|
||||||
|
AND rr.dated <= ii.issued
|
||||||
IF vDated THEN
|
) SELECT `value` INTO vRate
|
||||||
SELECT `value` INTO vRate
|
FROM vn.referenceRate rr
|
||||||
FROM referenceRate
|
JOIN rate r ON r.dated = rr.dated
|
||||||
WHERE dated = vDated;
|
AND r.currencyFk = rr.currencyFk;
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT id INTO vExpenseFk
|
SELECT id INTO vExpenseFk
|
||||||
FROM vn.expense
|
FROM expense
|
||||||
WHERE `name` = 'Adquisición mercancia Extracomunitaria'
|
WHERE `name` = 'Adquisición mercancia Extracomunitaria'
|
||||||
GROUP BY id
|
GROUP BY id
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
@ -26,19 +26,25 @@ BEGIN
|
||||||
DELETE FROM invoiceInTax
|
DELETE FROM invoiceInTax
|
||||||
WHERE invoiceInFk = vInvoiceInFk;
|
WHERE invoiceInFk = vInvoiceInFk;
|
||||||
|
|
||||||
INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, foreignValue, taxTypeSageFk, transactionTypeSageFk)
|
INSERT INTO invoiceInTax(
|
||||||
SELECT ii.id,
|
invoiceInFk,
|
||||||
SUM(b.buyingValue * b.quantity) / IFNULL(vRate,1) taxableBase,
|
taxableBase,
|
||||||
|
expenseFk,
|
||||||
|
foreignValue,
|
||||||
|
taxTypeSageFk,
|
||||||
|
transactionTypeSageFk
|
||||||
|
)SELECT ii.id,
|
||||||
|
SUM(b.buyingValue * b.quantity) / vRate taxableBase,
|
||||||
vExpenseFk,
|
vExpenseFk,
|
||||||
IF(ii.currencyFk = 1,NULL,SUM(b.buyingValue * b.quantity )) divisa,
|
IF(ii.currencyFk = 1,
|
||||||
|
NULL,
|
||||||
|
SUM(b.buyingValue * b.quantity )),
|
||||||
taxTypeSageFk,
|
taxTypeSageFk,
|
||||||
transactionTypeSageFk
|
transactionTypeSageFk
|
||||||
FROM invoiceIn ii
|
FROM invoiceIn ii
|
||||||
JOIN entry e ON e.invoiceInFk = ii.id
|
JOIN entry e ON e.invoiceInFk = ii.id
|
||||||
JOIN supplier s ON s.id = e.supplierFk
|
JOIN supplier s ON s.id = e.supplierFk
|
||||||
JOIN buy b ON b.entryFk = e.id
|
JOIN buy b ON b.entryFk = e.id
|
||||||
LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk
|
|
||||||
AND rr.dated = ii.issued
|
|
||||||
WHERE ii.id = vInvoiceInFk
|
WHERE ii.id = vInvoiceInFk
|
||||||
HAVING taxableBase IS NOT NULL;
|
HAVING taxableBase IS NOT NULL;
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -2,6 +2,7 @@ DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_booking`(vSelf INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_booking`(vSelf INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vBookNumber INT;
|
DECLARE vBookNumber INT;
|
||||||
|
DECLARE vFiscalYear INT;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn
|
CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
|
@ -56,7 +57,8 @@ BEGIN
|
||||||
LEFT JOIN sage.taxType tt ON tt.id = ti.CodigoIva
|
LEFT JOIN sage.taxType tt ON tt.id = ti.CodigoIva
|
||||||
WHERE ii.id = vSelf;
|
WHERE ii.id = vSelf;
|
||||||
|
|
||||||
CALL vn.ledger_next(vBookNumber);
|
SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1;
|
||||||
|
CALL ledger_next(vFiscalYear, vBookNumber);
|
||||||
|
|
||||||
-- Apunte del proveedor
|
-- Apunte del proveedor
|
||||||
INSERT INTO XDiario(
|
INSERT INTO XDiario(
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutBooking`(IN vInvoice INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutBooking`(IN vInvoice INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
/* Asienta la factura emitida
|
/**
|
||||||
*
|
* Asienta una factura emitida
|
||||||
* param vInvoice factura_id
|
*
|
||||||
*/
|
* @param vInvoice Id invoiceOut
|
||||||
|
*/
|
||||||
DECLARE vBookNumber INT;
|
DECLARE vBookNumber INT;
|
||||||
DECLARE vExpenseConcept VARCHAR(50);
|
DECLARE vExpenseConcept VARCHAR(50);
|
||||||
DECLARE vSpainCountryFk INT;
|
DECLARE vSpainCountryFk INT;
|
||||||
DECLARE vOldBookNumber INT;
|
DECLARE vOldBookNumber INT;
|
||||||
|
DECLARE vFiscalYear INT;
|
||||||
|
|
||||||
SELECT id INTO vSpainCountryFk FROM country WHERE code = 'ES';
|
SELECT id INTO vSpainCountryFk FROM country WHERE `code` = 'ES';
|
||||||
|
|
||||||
SELECT ASIEN
|
SELECT ASIEN
|
||||||
INTO vOldBookNumber
|
INTO vOldBookNumber
|
||||||
|
@ -26,31 +28,30 @@ BEGIN
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS rs;
|
DROP TEMPORARY TABLE IF EXISTS rs;
|
||||||
CREATE TEMPORARY TABLE rs
|
CREATE TEMPORARY TABLE rs
|
||||||
SELECT
|
SELECT c.accountingAccount clientBookingAccount,
|
||||||
c.accountingAccount AS clientBookingAccount,
|
io.amount totalAmount,
|
||||||
io.amount as totalAmount,
|
CONCAT('n/fra ', io.ref) simpleConcept,
|
||||||
CONCAT('n/fra ', io.ref) as simpleConcept,
|
CONCAT('n/fra ', io.ref, ' ', c.name) Concept,
|
||||||
CONCAT('n/fra ', io.ref, ' ', c.name) as Concept,
|
io.serial SERIE,
|
||||||
io.serial AS SERIE,
|
io.issued FECHA_EX,
|
||||||
io.issued AS FECHA_EX,
|
io.issued FECHA_OP,
|
||||||
io.issued AS FECHA_OP,
|
io.issued FECHA,
|
||||||
io.issued AS FECHA,
|
1 NFACTICK,
|
||||||
1 AS NFACTICK,
|
IF(ic.correctingFk,'D','') TIPOOPE,
|
||||||
IF(ic.correctingFk,'D','') AS TIPOOPE,
|
io.siiTrascendencyInvoiceOutFk TIPOCLAVE,
|
||||||
io.siiTrascendencyInvoiceOutFk AS TIPOCLAVE,
|
io.cplusTaxBreakFk TIPOEXENCI,
|
||||||
io.cplusTaxBreakFk AS TIPOEXENCI,
|
io.cplusSubjectOpFk TIPONOSUJE,
|
||||||
io.cplusSubjectOpFk AS TIPONOSUJE,
|
io.siiTypeInvoiceOutFk TIPOFACT,
|
||||||
io.siiTypeInvoiceOutFk AS TIPOFACT,
|
ic.cplusRectificationTypeFk TIPORECTIF,
|
||||||
ic.cplusRectificationTypeFk AS TIPORECTIF,
|
|
||||||
io.companyFk,
|
io.companyFk,
|
||||||
RIGHT(io.ref, LENGTH(io.ref) - 1) AS invoiceNum,
|
RIGHT(io.ref, LENGTH(io.ref) - 1) invoiceNum,
|
||||||
IF(c.countryFk = vSpainCountryFk, vSpainCountryFk, IF(ct.isUeeMember,2,4)) AS TERIDNIF,
|
IF(c.countryFk = vSpainCountryFk, vSpainCountryFk, IF(ct.isUeeMember,2,4)) TERIDNIF,
|
||||||
CONCAT(IF(ct.isUeeMember AND c.countryFk <> vSpainCountryFk,ct.code,''),c.fi) AS TERNIF,
|
CONCAT(IF(ct.isUeeMember AND c.countryFk <> vSpainCountryFk,ct.code,''),c.fi) TERNIF,
|
||||||
c.socialName AS TERNOM,
|
c.socialName TERNOM,
|
||||||
ior.serial AS SERIE_RT,
|
ior.serial SERIE_RT,
|
||||||
RIGHT(ior.ref, LENGTH(ior.ref) - 1) AS FACTU_RT,
|
RIGHT(ior.ref, LENGTH(ior.ref) - 1) FACTU_RT,
|
||||||
ior.issued AS FECHA_RT,
|
ior.issued FECHA_RT,
|
||||||
IF(ior.id,TRUE,FALSE) AS RECTIFICA
|
IF(ior.id,TRUE,FALSE) RECTIFICA
|
||||||
FROM invoiceOut io
|
FROM invoiceOut io
|
||||||
JOIN invoiceOutSerial ios ON ios.code = io.serial
|
JOIN invoiceOutSerial ios ON ios.code = io.serial
|
||||||
JOIN client c ON c.id = io.clientFk
|
JOIN client c ON c.id = io.clientFk
|
||||||
|
@ -59,8 +60,8 @@ BEGIN
|
||||||
LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
|
LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
|
||||||
WHERE io.id = vInvoice;
|
WHERE io.id = vInvoice;
|
||||||
|
|
||||||
CALL vn.ledger_next(vBookNumber);
|
SELECT YEAR(FECHA) INTO vFiscalYear FROM rs LIMIT 1;
|
||||||
|
CALL ledger_next(vFiscalYear, vBookNumber);
|
||||||
-- Linea del cliente
|
-- Linea del cliente
|
||||||
INSERT INTO XDiario(
|
INSERT INTO XDiario(
|
||||||
ASIEN,
|
ASIEN,
|
||||||
|
@ -70,17 +71,15 @@ BEGIN
|
||||||
CONCEPTO,
|
CONCEPTO,
|
||||||
FECHA_EX,
|
FECHA_EX,
|
||||||
FECHA_OP,
|
FECHA_OP,
|
||||||
empresa_id
|
empresa_id)
|
||||||
)
|
SELECT vBookNumber,
|
||||||
SELECT
|
|
||||||
vBookNumber AS ASIEN,
|
|
||||||
rs.FECHA,
|
rs.FECHA,
|
||||||
rs.clientBookingAccount AS SUBCTA,
|
rs.clientBookingAccount,
|
||||||
rs.totalAmount AS EURODEBE,
|
rs.totalAmount,
|
||||||
rs.simpleConcept AS CONCEPTO,
|
rs.simpleConcept,
|
||||||
rs.FECHA_EX,
|
rs.FECHA_EX,
|
||||||
rs.FECHA_OP,
|
rs.FECHA_OP,
|
||||||
rs.companyFk AS empresa_id
|
rs.companyFk
|
||||||
FROM rs;
|
FROM rs;
|
||||||
|
|
||||||
-- Lineas de gasto
|
-- Lineas de gasto
|
||||||
|
@ -93,18 +92,16 @@ BEGIN
|
||||||
CONCEPTO,
|
CONCEPTO,
|
||||||
FECHA_EX,
|
FECHA_EX,
|
||||||
FECHA_OP,
|
FECHA_OP,
|
||||||
empresa_id
|
empresa_id)
|
||||||
)
|
SELECT vBookNumber,
|
||||||
SELECT
|
|
||||||
vBookNumber AS ASIEN,
|
|
||||||
rs.FECHA,
|
rs.FECHA,
|
||||||
ioe.expenseFk AS SUBCTA,
|
ioe.expenseFk,
|
||||||
rs.clientBookingAccount AS CONTRA,
|
rs.clientBookingAccount,
|
||||||
ioe.amount AS EUROHABER,
|
ioe.amount,
|
||||||
rs.Concept AS CONCEPTO,
|
rs.Concept,
|
||||||
rs.FECHA_EX,
|
rs.FECHA_EX,
|
||||||
rs.FECHA_OP,
|
rs.FECHA_OP,
|
||||||
rs.companyFk AS empresa_id
|
rs.companyFk
|
||||||
FROM rs
|
FROM rs
|
||||||
JOIN invoiceOutExpense ioe
|
JOIN invoiceOutExpense ioe
|
||||||
WHERE ioe.invoiceOutFk = vInvoice;
|
WHERE ioe.invoiceOutFk = vInvoice;
|
||||||
|
@ -146,20 +143,18 @@ BEGIN
|
||||||
TIPONOSUJE,
|
TIPONOSUJE,
|
||||||
TIPOFACT,
|
TIPOFACT,
|
||||||
TIPORECTIF,
|
TIPORECTIF,
|
||||||
empresa_id
|
empresa_id)
|
||||||
)
|
SELECT vBookNumber ASIEN,
|
||||||
SELECT
|
|
||||||
vBookNumber AS ASIEN,
|
|
||||||
rs.FECHA,
|
rs.FECHA,
|
||||||
iot.pgcFk AS SUBCTA,
|
iot.pgcFk SUBCTA,
|
||||||
rs.clientBookingAccount AS CONTRA,
|
rs.clientBookingAccount CONTRA,
|
||||||
iot.vat AS EUROHABER,
|
iot.vat EUROHABER,
|
||||||
iot.taxableBase AS BASEEURO,
|
iot.taxableBase BASEEURO,
|
||||||
CONCAT(vExpenseConcept,' : ',rs.Concept) AS CONCEPTO,
|
CONCAT(vExpenseConcept,' : ',rs.Concept) CONCEPTO,
|
||||||
rs.invoiceNum AS FACTURA,
|
rs.invoiceNum FACTURA,
|
||||||
IF(pe2.equFk,0,pgc.rate) AS IVA,
|
IF(pe2.equFk,0,pgc.rate) IVA,
|
||||||
IF(pe2.equFk,0,pgce.rate) AS RECEQUIV,
|
IF(pe2.equFk,0,pgce.rate) RECEQUIV,
|
||||||
IF(pgc.mod347,'','*') AS AUXILIAR,
|
IF(pgc.mod347,'','*') AUXILIAR,
|
||||||
rs.SERIE,
|
rs.SERIE,
|
||||||
rs.SERIE_RT,
|
rs.SERIE_RT,
|
||||||
rs.FACTU_RT,
|
rs.FACTU_RT,
|
||||||
|
@ -172,13 +167,13 @@ BEGIN
|
||||||
rs.TERIDNIF,
|
rs.TERIDNIF,
|
||||||
rs.TERNIF,
|
rs.TERNIF,
|
||||||
rs.TERNOM,
|
rs.TERNOM,
|
||||||
pgc.mod340 AS L340,
|
pgc.mod340 L340,
|
||||||
pgc.siiTrascendencyInvoiceOutFk AS TIPOCLAVE,
|
pgc.siiTrascendencyInvoiceOutFk TIPOCLAVE,
|
||||||
pgc.cplusTaxBreakFk as TIPOEXENCI,
|
pgc.cplusTaxBreakFk TIPOEXENCI,
|
||||||
rs.TIPONOSUJE,
|
rs.TIPONOSUJE,
|
||||||
rs.TIPOFACT,
|
rs.TIPOFACT,
|
||||||
rs.TIPORECTIF,
|
rs.TIPORECTIF,
|
||||||
rs.companyFk AS empresa_id
|
rs.companyFk
|
||||||
FROM rs
|
FROM rs
|
||||||
JOIN invoiceOutTax iot
|
JOIN invoiceOutTax iot
|
||||||
JOIN pgc ON pgc.code = iot.pgcFk
|
JOIN pgc ON pgc.code = iot.pgcFk
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_doCompensation`(vDated DATE, vCompensationAccount VARCHAR(10) , vBankFk VARCHAR(10), vConcept VARCHAR(255), vAmount DECIMAL(10,2), vCompanyFk INT, vOriginalAccount VARCHAR(10))
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_doCompensation`(
|
||||||
|
vDated DATE,
|
||||||
|
vCompensationAccount VARCHAR(10),
|
||||||
|
vBankFk VARCHAR(10),
|
||||||
|
vConcept VARCHAR(255),
|
||||||
|
vAmount DECIMAL(10,2),
|
||||||
|
vCompanyFk INT,
|
||||||
|
vOriginalAccount VARCHAR(10)
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Compensa un pago o un recibo insertando en contabilidad
|
* Compensa un pago o un recibo insertando en contabilidad
|
||||||
|
@ -9,7 +17,7 @@ BEGIN
|
||||||
* @param vBankFk banco de la compensacion
|
* @param vBankFk banco de la compensacion
|
||||||
* @param vConcept descripcion
|
* @param vConcept descripcion
|
||||||
* @param vAmount cantidad que se compensa
|
* @param vAmount cantidad que se compensa
|
||||||
* @param vCompany empresa
|
* @param vCompanyFk empresa
|
||||||
* @param vOriginalAccount cuenta contable desde la cual se compensa
|
* @param vOriginalAccount cuenta contable desde la cual se compensa
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -20,9 +28,11 @@ BEGIN
|
||||||
DECLARE vIsOriginalAClient BOOL;
|
DECLARE vIsOriginalAClient BOOL;
|
||||||
DECLARE vPayMethodCompensation INT;
|
DECLARE vPayMethodCompensation INT;
|
||||||
|
|
||||||
CALL ledger_next(vNewBookEntry);
|
CALL ledger_next(YEAR(vDated), vNewBookEntry);
|
||||||
|
|
||||||
SELECT COUNT(id) INTO vIsOriginalAClient FROM client WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci;
|
SELECT COUNT(id) INTO vIsOriginalAClient
|
||||||
|
FROM client
|
||||||
|
WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci;
|
||||||
|
|
||||||
SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation
|
SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation
|
||||||
FROM client
|
FROM client
|
||||||
|
@ -62,17 +72,38 @@ BEGIN
|
||||||
IF vIsOriginalAClient THEN
|
IF vIsOriginalAClient THEN
|
||||||
SET vAmount = -vAmount;
|
SET vAmount = -vAmount;
|
||||||
END IF;
|
END IF;
|
||||||
INSERT INTO receipt(invoiceFk, amountPaid, payed, bankFk, companyFk, clientFk, isConciliate)
|
|
||||||
VALUES (vConcept, vAmount, vDated, vBankFk, vCompanyFk, vClientFk, TRUE);
|
INSERT INTO receipt
|
||||||
|
SET invoiceFk = vConcept,
|
||||||
|
amountPaid = vAmount,
|
||||||
|
payed = vDated,
|
||||||
|
bankFk = vBankFk,
|
||||||
|
companyFk = vCompanyFk,
|
||||||
|
clientFk = vClientFk,
|
||||||
|
isConciliate = TRUE;
|
||||||
ELSE
|
ELSE
|
||||||
IF NOT vIsOriginalAClient THEN
|
IF NOT vIsOriginalAClient THEN
|
||||||
SET vAmount = -vAmount;
|
SET vAmount = -vAmount;
|
||||||
END IF;
|
END IF;
|
||||||
SELECT id INTO vSupplierFk FROM supplier WHERE `account` LIKE vCompensationAccount COLLATE utf8_general_ci;
|
|
||||||
SELECT id INTO vPayMethodCompensation FROM payMethod WHERE `code` = 'compensation';
|
|
||||||
|
|
||||||
INSERT INTO payment (received, dueDated, supplierFk, amount, bankFk, payMethodFk, concept, companyFk, isConciliated)
|
SELECT id INTO vSupplierFk
|
||||||
VALUES(vDated, vDated, vSupplierFk, vAmount, vBankFk, vPayMethodCompensation, vConcept, vCompanyFk, TRUE);
|
FROM supplier
|
||||||
|
WHERE `account` LIKE vCompensationAccount COLLATE utf8_general_ci;
|
||||||
|
|
||||||
|
SELECT id INTO vPayMethodCompensation
|
||||||
|
FROM payMethod
|
||||||
|
WHERE `code` = 'compensation';
|
||||||
|
|
||||||
|
INSERT INTO payment
|
||||||
|
SET received = vDated,
|
||||||
|
dueDated = vDated,
|
||||||
|
supplierFk = vSupplierFk,
|
||||||
|
amount = vAmount,
|
||||||
|
bankFk = vBankFk,
|
||||||
|
payMethodFk = vPayMethodCompensation,
|
||||||
|
concept = vConcept,
|
||||||
|
companyFk = vCompanyFk,
|
||||||
|
isConciliated = TRUE;
|
||||||
END IF;
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(OUT vNewBookEntry INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(
|
||||||
|
IN vFiscalYear INT,
|
||||||
|
OUT vNewBookEntry INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
UPDATE ledgerCompany
|
||||||
|
SET bookEntry = LAST_INSERT_ID(bookEntry + 1)
|
||||||
|
WHERE fiscalYear = vFiscalYear;
|
||||||
|
|
||||||
UPDATE vn.ledgerConfig SET lastBookEntry = LAST_INSERT_ID(lastBookEntry + 1);
|
|
||||||
SET vNewBookEntry = LAST_INSERT_ID();
|
SET vNewBookEntry = LAST_INSERT_ID();
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -3,30 +3,31 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`payment_beforeInsert`
|
||||||
BEFORE INSERT ON `payment`
|
BEFORE INSERT ON `payment`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE cuenta_banco,cuenta_proveedor DOUBLE;
|
DECLARE vBankAccount DOUBLE;
|
||||||
|
DECLARE vSupplierAccount DOUBLE;
|
||||||
DECLARE vNewBookEntry INT;
|
DECLARE vNewBookEntry INT;
|
||||||
DECLARE bolCASH BOOLEAN;
|
DECLARE vIsCash BOOLEAN;
|
||||||
DECLARE isSupplierActive BOOLEAN;
|
DECLARE vIsSupplierActive BOOLEAN;
|
||||||
|
|
||||||
-- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH
|
-- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH
|
||||||
SELECT (at2.code = 'cash') INTO bolCASH
|
SELECT (at2.code = 'cash') INTO vIsCash
|
||||||
FROM accounting a
|
FROM accounting a
|
||||||
JOIN accountingType at2 ON at2.id = a.accountingTypeFk
|
JOIN accountingType at2 ON at2.id = a.accountingTypeFk
|
||||||
WHERE a.id = NEW.bankFk;
|
WHERE a.id = NEW.bankFk;
|
||||||
|
|
||||||
IF bolCASH THEN
|
IF vIsCash THEN
|
||||||
|
SELECT account INTO vBankAccount
|
||||||
SELECT account INTO cuenta_banco
|
|
||||||
FROM accounting
|
FROM accounting
|
||||||
WHERE id = NEW.bankFk;
|
WHERE id = NEW.bankFk;
|
||||||
|
|
||||||
SELECT account INTO cuenta_proveedor
|
SELECT account INTO vSupplierAccount
|
||||||
FROM supplier
|
FROM supplier
|
||||||
WHERE id = NEW.supplierFk;
|
WHERE id = NEW.supplierFk;
|
||||||
|
|
||||||
CALL ledger_next(vNewBookEntry);
|
CALL ledger_next(YEAR(NEW.received), NEW.companyFk, vNewBookEntry);
|
||||||
|
|
||||||
INSERT INTO XDiario ( ASIEN,
|
INSERT INTO XDiario (
|
||||||
|
ASIEN,
|
||||||
FECHA,
|
FECHA,
|
||||||
SUBCTA,
|
SUBCTA,
|
||||||
CONTRA,
|
CONTRA,
|
||||||
|
@ -42,18 +43,19 @@ BEGIN
|
||||||
EURODEBE,
|
EURODEBE,
|
||||||
EUROHABER,
|
EUROHABER,
|
||||||
NEW.companyFk
|
NEW.companyFk
|
||||||
FROM ( SELECT cuenta_banco SUBCTA,
|
FROM (SELECT vBankAccount SUBCTA,
|
||||||
cuenta_proveedor CONTRA,
|
vSupplierAccount CONTRA,
|
||||||
0 EURODEBE,
|
0 EURODEBE,
|
||||||
NEW.amount + NEW.bankingFees EUROHABER
|
NEW.amount + NEW.bankingFees EUROHABER
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT cuenta_proveedor SUBCTA,
|
SELECT vSupplierAccount SUBCTA,
|
||||||
cuenta_banco CONTRA,
|
vBankAccount CONTRA,
|
||||||
NEW.amount EURODEBE,
|
NEW.amount EURODEBE,
|
||||||
0 EUROHABER) gf;
|
0 EUROHABER) gf;
|
||||||
|
|
||||||
IF NEW.bankingFees <> 0 THEN
|
IF NEW.bankingFees <> 0 THEN
|
||||||
INSERT INTO XDiario ( ASIEN,
|
INSERT INTO XDiario (
|
||||||
|
ASIEN,
|
||||||
FECHA,
|
FECHA,
|
||||||
SUBCTA,
|
SUBCTA,
|
||||||
CONTRA,
|
CONTRA,
|
||||||
|
@ -65,7 +67,7 @@ BEGIN
|
||||||
NEW.received,
|
NEW.received,
|
||||||
IF(c.id = 1,6260000002,
|
IF(c.id = 1,6260000002,
|
||||||
IF(CEE = 1,6260000003,6260000004)),
|
IF(CEE = 1,6260000003,6260000004)),
|
||||||
cuenta_banco,
|
vBankAccount,
|
||||||
NEW.concept,
|
NEW.concept,
|
||||||
NEW.bankingFees,
|
NEW.bankingFees,
|
||||||
0,
|
0,
|
||||||
|
@ -78,17 +80,16 @@ BEGIN
|
||||||
|
|
||||||
SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received);
|
SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received);
|
||||||
|
|
||||||
SELECT isActive INTO isSupplierActive
|
SELECT isActive INTO vIsSupplierActive
|
||||||
FROM supplier
|
FROM supplier
|
||||||
WHERE id = NEW.supplierFk;
|
WHERE id = NEW.supplierFk;
|
||||||
|
|
||||||
IF isSupplierActive = FALSE THEN
|
IF vIsSupplierActive = FALSE THEN
|
||||||
CALL util.throw('SUPPLIER_INACTIVE');
|
CALL util.throw('SUPPLIER_INACTIVE');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF ISNULL(NEW.workerFk) THEN
|
IF ISNULL(NEW.workerFk) THEN
|
||||||
SET NEW.workerFk = account.myUser_getId();
|
SET NEW.workerFk = account.myUser_getId();
|
||||||
END IF;
|
END IF;
|
||||||
|
END$$
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -19,11 +19,6 @@ BEGIN
|
||||||
`changedModelId` = OLD.id,
|
`changedModelId` = OLD.id,
|
||||||
`userFk` = account.myUser_getId();
|
`userFk` = account.myUser_getId();
|
||||||
|
|
||||||
CALL util.debugAdd('deletedState',
|
|
||||||
CONCAT('interFk: ', OLD.id,
|
|
||||||
' ticketFk: ', OLD.ticketFk,
|
|
||||||
' stateFk: ', OLD.stateFk));
|
|
||||||
|
|
||||||
SELECT i.ticketFk, i.id, s.`name`
|
SELECT i.ticketFk, i.id, s.`name`
|
||||||
INTO vTicketFk, vTicketTrackingFk, vStateName
|
INTO vTicketFk, vTicketTrackingFk, vStateName
|
||||||
FROM ticketTracking i
|
FROM ticketTracking i
|
||||||
|
|
|
@ -37,7 +37,7 @@ FROM (
|
||||||
)
|
)
|
||||||
JOIN `vn`.`volumeConfig` `vc`
|
JOIN `vn`.`volumeConfig` `vc`
|
||||||
)
|
)
|
||||||
JOIN `vn`.`itemCost` `ic` ON(
|
JOIN `vn`.`itemCost` `ic` FORCE INDEX (`PRIMARY`) ON(
|
||||||
`ic`.`itemFk` = `s`.`itemFk`
|
`ic`.`itemFk` = `s`.`itemFk`
|
||||||
AND `ic`.`warehouseFk` = `t`.`warehouseFk`
|
AND `ic`.`warehouseFk` = `t`.`warehouseFk`
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
CREATE OR REPLACE TABLE vn.ledgerCompany (
|
||||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`fiscalYear` int(10) unsigned NOT NULL COMMENT 'Año del ejercicio contable',
|
||||||
|
`bookEntry` int(10) unsigned NOT NULL DEFAULT 1 COMMENT 'Contador asiento contable',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `ledgerCompany_unique` (`fiscalYear`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci
|
||||||
|
COMMENT='Contador para asientos contables';
|
||||||
|
|
||||||
|
INSERT IGNORE INTO vn.ledgerCompany (fiscalYear, bookEntry)
|
||||||
|
SELECT YEAR(util.VN_CURDATE()), lastBookEntry
|
||||||
|
FROM vn.ledgerConfig;
|
||||||
|
|
||||||
|
ALTER TABLE vn.ledgerConfig CHANGE IF EXISTS lastBookEntry lastBookEntry__ int(11) NOT NULL
|
||||||
|
COMMENT '@deprecated 2024-05-28 refs #7400 Modificar contador asientos contables';
|
||||||
|
|
Loading…
Reference in New Issue