Merge branch 'dev' into 7187-addPdaFreelancers
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Pablo Natek 2024-05-17 11:33:57 +00:00
commit 4790ae94d1
14 changed files with 502 additions and 417 deletions

View File

@ -1,3 +1,4 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.

View File

@ -54,6 +54,12 @@ For end-to-end tests run from project's root.
$ npm run test:e2e $ npm run test:e2e
``` ```
## Generate changeLog test → master
```
$ bash changelog.sh
```
## Visual Studio Code extensions ## Visual Studio Code extensions
Open Visual Studio Code, press Ctrl+P and paste the following commands. Open Visual Studio Code, press Ctrl+P and paste the following commands.

34
changelog.sh Normal file
View File

@ -0,0 +1,34 @@
features_types=(chore feat style)
changes_types=(refactor perf)
fix_types=(fix revert)
file="CHANGELOG.md"
file_tmp="temp_log.txt"
file_current_tmp="temp_current_log.txt"
setType(){
echo "### $1" >> $file_tmp
arr=("$@")
echo "" > $file_current_tmp
for i in "${arr[@]}"
do
git log --grep="$i" --oneline --no-merges --format="- %s %d by:%an" master..test >> $file_current_tmp
done
# remove duplicates
sort -o $file_current_tmp -u $file_current_tmp
cat $file_current_tmp >> $file_tmp
echo "" >> $file_tmp
# remove tmp current file
[ -e $file_current_tmp ] && rm $file_current_tmp
}
echo "# Version XX.XX - XXXX-XX-XX" >> $file_tmp
echo "" >> $file_tmp
setType "Added 🆕" "${features_types[@]}"
setType "Changed 📦" "${changes_types[@]}"
setType "Fixed 🛠️" "${fix_types[@]}"
cat $file >> $file_tmp
mv $file_tmp $file

View File

@ -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,33 +13,33 @@ 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,
CONCEPTO = vConcept, CONCEPTO = vConcept,
EURODEBE = vDebit, EURODEBE = vDebit,
EUROHABER = vCredit, EUROHABER = vCredit,
BASEEURO = vEuro, BASEEURO = vEuro,
SERIE = vSerie, SERIE = vSerie,
FACTURA = vInvoice, FACTURA = vInvoice,
IVA = vVat, IVA = vVat,
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 ;

View File

@ -2,122 +2,116 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaTaxBooking`(vDuaFk INT) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaTaxBooking`(vDuaFk INT)
BEGIN BEGIN
DECLARE vBookNumber INT; DECLARE vBookNumber INT;
DECLARE vBookDated DATE; DECLARE vBookDated DATE;
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,
SUBCTA, SUBCTA,
CONCEPTO, CONCEPTO,
EUROHABER, EUROHABER,
SERIE, SERIE,
empresa_id, empresa_id,
CLAVE, CLAVE,
FACTURA) FACTURA)
SELECT vBookNumber,
d.bookEntried,
'4700000999',
CONCAT('DUA ',d.`code`),
sum(dt.base * dt.rate / 100) EUROHABER,
'R',
d.companyFk,
vDuaFk,
vDuaFk
FROM duaTax dt
JOIN dua d ON d.id = dt.duaFk
WHERE dt.duaFk = vDuaFk;
SELECT -- Apuntes por tipo de IVA y proveedor
vBookNumber, INSERT INTO XDiario(
d.bookEntried, ASIEN,
'4700000999', FECHA,
CONCAT('DUA ',d.`code`), SUBCTA,
sum(dt.base * dt.rate / 100) EUROHABER, CONTRA,
'R', EURODEBE,
d.companyFk, BASEEURO,
vDuaFk, CONCEPTO,
vDuaFk FACTURA,
FROM duaTax dt IVA,
JOIN dua d ON d.id = dt.duaFk AUXILIAR,
WHERE dt.duaFk = vDuaFk; SERIE,
FECHA_EX,
-- Apuntes por tipo de IVA y proveedor FECHA_OP,
FACTURAEX,
INSERT INTO XDiario( NFACTICK,
ASIEN, L340,
FECHA, LDIFADUAN,
SUBCTA, TIPOCLAVE,
CONTRA, TIPOEXENCI,
EURODEBE, TIPONOSUJE,
BASEEURO, TIPOFACT,
CONCEPTO, TIPORECTIF,
FACTURA, TERIDNIF,
IVA, TERNIF,
AUXILIAR, TERNOM,
SERIE, empresa_id,
FECHA_EX, FECREGCON)
FECHA_OP, SELECT vBookNumber ASIEN,
FACTURAEX, vBookDated FECHA,
NFACTICK, tr.account SUBCTA,
L340, '4330002067' CONTRA,
LDIFADUAN, SUM(dt.tax) EURODEBE,
TIPOCLAVE, SUM(dt.base) BASEEURO,
TIPOEXENCI, CONCAT('DUA nº',d.code) CONCEPTO,
TIPONOSUJE, d.id FACTURA,
TIPOFACT, dt.rate IVA,
TIPORECTIF, '*' AUXILIAR,
TERIDNIF, 'D' SERIE,
TERNIF, d.issued FECHA_EX,
TERNOM, d.operated FECHA_OP,
empresa_id, d.code FACTURAEX,
FECREGCON 1 NFACTICK,
) 1 L340,
TRUE LDIFADUAN,
SELECT 1 TIPOCLAVE,
vBookNumber ASIEN, 1 TIPOEXENCI,
vBookDated FECHA, 1 TIPONOSUJE,
tr.account SUBCTA, 5 TIPOFACT,
'4330002067' CONTRA, 1 TIPORECTIF,
sum(dt.tax) EURODEBE, IF(c.code = 'ES', 1, 4) TERIDNIF,
sum(dt.base) BASEEURO, s.nif TERNIF,
CONCAT('DUA nº',d.code) CONCEPTO, s.name TERNOM,
d.id FACTURA, d.companyFk,
dt.rate IVA, d.booked FECREGCON
'*' AUXILIAR, FROM duaTax dt
'D' SERIE, JOIN dua d ON dt.duaFk = d.id
d.issued FECHA_EX, JOIN (SELECT account, rate
d.operated FECHA_OP, FROM
d.code FACTURAEX, (SELECT rate, account
1 NFACTICK, FROM invoiceInTaxBookingAccount ta
1 L340, WHERE ta.effectived <= vBookDated
TRUE LDIFADUAN, AND taxAreaFk = 'WORLD'
1 TIPOCLAVE, ORDER BY ta.effectived DESC
1 TIPOEXENCI, LIMIT 10000000000000000000
1 TIPONOSUJE, ) tba
5 TIPOFACT, GROUP BY rate
1 TIPORECTIF,
IF(c.code = 'ES', 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
LIMIT 10000000000000000000
) tba
GROUP BY rate
) tr ON tr.rate = dt.rate ) tr ON tr.rate = dt.rate
JOIN supplier s ON s.id = d.companyFk JOIN supplier s ON s.id = d.companyFk
JOIN country c ON c.id = s.countryFk JOIN country c ON c.id = s.countryFk
WHERE d.id = vDuaFk WHERE d.id = vDuaFk
GROUP BY dt.rate; GROUP BY dt.rate;
SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte
FROM XDiario FROM XDiario
@ -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 ;

View File

@ -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,
vExpenseFk, expenseFk,
IF(ii.currencyFk = 1,NULL,SUM(b.buyingValue * b.quantity )) divisa, foreignValue,
taxTypeSageFk, taxTypeSageFk,
transactionTypeSageFk transactionTypeSageFk
)SELECT ii.id,
SUM(b.buyingValue * b.quantity) / vRate taxableBase,
vExpenseFk,
IF(ii.currencyFk = 1,
NULL,
SUM(b.buyingValue * b.quantity )),
taxTypeSageFk,
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$$

View File

@ -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(

View File

@ -1,22 +1,24 @@
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
FROM XDiario x FROM XDiario x
JOIN invoiceOut io ON io.id = vInvoice JOIN invoiceOut io ON io.id = vInvoice
WHERE x.SERIE = io.serial WHERE x.SERIE = io.serial
AND x.FACTURA = RIGHT(io.ref, LENGTH(io.ref) - 1) AND x.FACTURA = RIGHT(io.ref, LENGTH(io.ref) - 1)
LIMIT 1; LIMIT 1;
@ -26,140 +28,133 @@ 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
JOIN country ct ON ct.id = c.countryFk JOIN country ct ON ct.id = c.countryFk
LEFT JOIN invoiceCorrection ic ON ic.correctingFk = io.id LEFT JOIN invoiceCorrection ic ON ic.correctingFk = io.id
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,
FECHA, FECHA,
SUBCTA, SUBCTA,
EURODEBE, EURODEBE,
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
INSERT INTO XDiario( INSERT INTO XDiario(
ASIEN, ASIEN,
FECHA, FECHA,
SUBCTA, SUBCTA,
CONTRA, CONTRA,
EUROHABER, EUROHABER,
CONCEPTO, CONCEPTO,
FECHA_EX, FECHA_EX,
FECHA_OP, FECHA_OP,
empresa_id empresa_id)
) SELECT vBookNumber,
SELECT rs.FECHA,
vBookNumber AS ASIEN, ioe.expenseFk,
rs.FECHA, rs.clientBookingAccount,
ioe.expenseFk AS SUBCTA, ioe.amount,
rs.clientBookingAccount AS CONTRA, rs.Concept,
ioe.amount AS EUROHABER, rs.FECHA_EX,
rs.Concept AS CONCEPTO, rs.FECHA_OP,
rs.FECHA_EX, rs.companyFk
rs.FECHA_OP, FROM rs
rs.companyFk AS empresa_id JOIN invoiceOutExpense ioe
FROM rs WHERE ioe.invoiceOutFk = vInvoice;
JOIN invoiceOutExpense ioe
WHERE ioe.invoiceOutFk = vInvoice;
SELECT GROUP_CONCAT(`name` SEPARATOR ',') SELECT GROUP_CONCAT(`name` SEPARATOR ',')
INTO vExpenseConcept INTO vExpenseConcept
FROM expense e FROM expense e
JOIN invoiceOutExpense ioe ON ioe.expenseFk = e.id JOIN invoiceOutExpense ioe ON ioe.expenseFk = e.id
WHERE ioe.invoiceOutFk = vInvoice; WHERE ioe.invoiceOutFk = vInvoice;
-- Lineas de IVA -- Lineas de IVA
INSERT INTO XDiario( INSERT INTO XDiario(
ASIEN, ASIEN,
FECHA, FECHA,
SUBCTA, SUBCTA,
CONTRA, CONTRA,
EUROHABER, EUROHABER,
BASEEURO, BASEEURO,
CONCEPTO, CONCEPTO,
FACTURA, FACTURA,
IVA, IVA,
RECEQUIV, RECEQUIV,
AUXILIAR, AUXILIAR,
SERIE, SERIE,
SERIE_RT, SERIE_RT,
FACTU_RT, FACTU_RT,
RECTIFICA, RECTIFICA,
FECHA_RT, FECHA_RT,
FECHA_OP, FECHA_OP,
FECHA_EX, FECHA_EX,
TIPOOPE, TIPOOPE,
NFACTICK, NFACTICK,
TERIDNIF, TERIDNIF,
TERNIF, TERNIF,
TERNOM, TERNOM,
L340, L340,
TIPOCLAVE, TIPOCLAVE,
TIPOEXENCI, TIPOEXENCI,
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,23 +167,23 @@ 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
LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk -- --------------- Comprueba si la linea es de iva con rec.equiv. asociado 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 pgc pgce ON pgce.code = pe.equFk
LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv. LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv.
WHERE iot.invoiceOutFk = vInvoice; WHERE iot.invoiceOutFk = vInvoice;
UPDATE invoiceOut UPDATE invoiceOut
SET booked = util.VN_CURDATE() SET booked = util.VN_CURDATE()
WHERE id = vInvoice; WHERE id = vInvoice;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -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,20 +17,22 @@ 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
* *
*/ */
DECLARE vNewBookEntry INT; DECLARE vNewBookEntry INT;
DECLARE vIsClientCompensation INT; DECLARE vIsClientCompensation INT;
DECLARE vClientFk INT; DECLARE vClientFk INT;
DECLARE vSupplierFk INT; DECLARE vSupplierFk INT;
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
@ -31,7 +41,7 @@ BEGIN
SET @vAmount1:= 0.0; SET @vAmount1:= 0.0;
SET @vAmount2:= 0.0; SET @vAmount2:= 0.0;
INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id) INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id)
VALUES ( vNewBookEntry, VALUES ( vNewBookEntry,
vDated, vDated,
vOriginalAccount, vOriginalAccount,
@ -49,30 +59,51 @@ BEGIN
), ),
vCompanyFk vCompanyFk
), ),
( vNewBookEntry, ( vNewBookEntry,
vDated, vDated,
vCompensationAccount, vCompensationAccount,
vOriginalAccount, vOriginalAccount,
vConcept, vConcept,
@vAmount2, @vAmount2,
@vAmount1, @vAmount1,
vCompanyFk); vCompanyFk);
IF vIsClientCompensation THEN IF vIsClientCompensation THEN
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);
ELSE
IF NOT vIsOriginalAClient THEN
SET vAmount = -vAmount;
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) INSERT INTO receipt
VALUES(vDated, vDated, vSupplierFk, vAmount, vBankFk, vPayMethodCompensation, vConcept, vCompanyFk, TRUE); SET invoiceFk = vConcept,
END IF; amountPaid = vAmount,
payed = vDated,
bankFk = vBankFk,
companyFk = vCompanyFk,
clientFk = vClientFk,
isConciliate = TRUE;
ELSE
IF NOT vIsOriginalAClient THEN
SET vAmount = -vAmount;
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
SET received = vDated,
dueDated = vDated,
supplierFk = vSupplierFk,
amount = vAmount,
bankFk = vBankFk,
payMethodFk = vPayMethodCompensation,
concept = vConcept,
companyFk = vCompanyFk,
isConciliated = TRUE;
END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -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 ;

View File

@ -3,92 +3,93 @@ 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 vNewBookEntry INT; DECLARE vSupplierAccount DOUBLE;
DECLARE bolCASH BOOLEAN; DECLARE vNewBookEntry INT;
DECLARE isSupplierActive BOOLEAN; DECLARE vIsCash 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
FROM accounting
WHERE id = NEW.bankFk;
SELECT account INTO cuenta_banco SELECT account INTO vSupplierAccount
FROM accounting
WHERE id = NEW.bankFk;
SELECT account INTO cuenta_proveedor
FROM supplier
WHERE id = NEW.supplierFk;
CALL ledger_next(vNewBookEntry);
INSERT INTO XDiario ( ASIEN,
FECHA,
SUBCTA,
CONTRA,
CONCEPTO,
EURODEBE,
EUROHABER,
empresa_id)
SELECT vNewBookEntry,
NEW.received,
SUBCTA,
CONTRA,
NEW.concept,
EURODEBE,
EUROHABER,
NEW.companyFk
FROM ( SELECT cuenta_banco SUBCTA,
cuenta_proveedor CONTRA,
0 EURODEBE,
NEW.amount + NEW.bankingFees EUROHABER
UNION ALL
SELECT cuenta_proveedor SUBCTA,
cuenta_banco CONTRA,
NEW.amount EURODEBE,
0 EUROHABER) gf;
IF NEW.bankingFees <> 0 THEN
INSERT INTO XDiario ( ASIEN,
FECHA,
SUBCTA,
CONTRA,
CONCEPTO,
EURODEBE,
EUROHABER,
empresa_id)
SELECT vNewBookEntry,
NEW.received,
IF(c.id = 1,6260000002,
IF(CEE = 1,6260000003,6260000004)),
cuenta_banco,
NEW.concept,
NEW.bankingFees,
0,
NEW.companyFk
FROM supplier s
JOIN country c ON s.countryFk = c.id
WHERE s.id = NEW.supplierFk;
END IF;
END IF;
SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received);
SELECT isActive INTO isSupplierActive
FROM supplier FROM supplier
WHERE id = NEW.supplierFk; WHERE id = NEW.supplierFk;
IF isSupplierActive = FALSE THEN CALL ledger_next(YEAR(NEW.received), NEW.companyFk, vNewBookEntry);
CALL util.throw('SUPPLIER_INACTIVE');
END IF;
IF ISNULL(NEW.workerFk) THEN INSERT INTO XDiario (
SET NEW.workerFk = account.myUser_getId(); ASIEN,
END IF; FECHA,
SUBCTA,
CONTRA,
CONCEPTO,
EURODEBE,
EUROHABER,
empresa_id)
SELECT vNewBookEntry,
NEW.received,
SUBCTA,
CONTRA,
NEW.concept,
EURODEBE,
EUROHABER,
NEW.companyFk
FROM (SELECT vBankAccount SUBCTA,
vSupplierAccount CONTRA,
0 EURODEBE,
NEW.amount + NEW.bankingFees EUROHABER
UNION ALL
SELECT vSupplierAccount SUBCTA,
vBankAccount CONTRA,
NEW.amount EURODEBE,
0 EUROHABER) gf;
END$$ IF NEW.bankingFees <> 0 THEN
INSERT INTO XDiario (
ASIEN,
FECHA,
SUBCTA,
CONTRA,
CONCEPTO,
EURODEBE,
EUROHABER,
empresa_id)
SELECT vNewBookEntry,
NEW.received,
IF(c.id = 1,6260000002,
IF(CEE = 1,6260000003,6260000004)),
vBankAccount,
NEW.concept,
NEW.bankingFees,
0,
NEW.companyFk
FROM supplier s
JOIN country c ON s.countryFk = c.id
WHERE s.id = NEW.supplierFk;
END IF;
END IF;
SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received);
SELECT isActive INTO vIsSupplierActive
FROM supplier
WHERE id = NEW.supplierFk;
IF vIsSupplierActive = FALSE THEN
CALL util.throw('SUPPLIER_INACTIVE');
END IF;
IF ISNULL(NEW.workerFk) THEN
SET NEW.workerFk = account.myUser_getId();
END IF;
END$$
DELIMITER ; DELIMITER ;

View File

@ -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

View File

@ -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`
) )

View File

@ -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';