feat: refs #4460 invoiceIn refund
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
48c387be75
commit
ca3ac64072
|
@ -4,10 +4,10 @@ BEGIN
|
||||||
/**
|
/**
|
||||||
* Traslada la info de contabilidad relacionada con las facturas recibidas
|
* Traslada la info de contabilidad relacionada con las facturas recibidas
|
||||||
*
|
*
|
||||||
* @vInvoiceInFk Factura recibida
|
* @param vInvoiceInFk Factura recibida
|
||||||
* @vXDiarioFk Id tabla XDiario
|
* @param vXDiarioFk Id tabla XDiario
|
||||||
*/
|
*/
|
||||||
DECLARE vInvoiceInOriginalFk INT;
|
DECLARE vInvoiceInOriginalFk INT;
|
||||||
DECLARE vDone BOOL DEFAULT FALSE;
|
DECLARE vDone BOOL DEFAULT FALSE;
|
||||||
DECLARE vBase DOUBLE;
|
DECLARE vBase DOUBLE;
|
||||||
DECLARE vVat DOUBLE;
|
DECLARE vVat DOUBLE;
|
||||||
|
@ -204,9 +204,9 @@ BEGIN
|
||||||
WHERE correctingFk = vInvoiceInFk;
|
WHERE correctingFk = vInvoiceInFk;
|
||||||
|
|
||||||
IF vInvoiceInOriginalFk THEN
|
IF vInvoiceInOriginalFk THEN
|
||||||
|
|
||||||
UPDATE movContaIVA mci
|
UPDATE movContaIVA mci
|
||||||
JOIN vn.invoiceInRefund iir ON iir.invoiceInRefundFk = vInvoiceInFk
|
JOIN vn.invoiceInCorrection iic ON iic.correctingFk = vInvoiceInFk
|
||||||
|
JOIN vn.siiTypeInvoiceOut st ON st.id = iic.siiTypeInvoiceOutFk
|
||||||
JOIN (SELECT issued,
|
JOIN (SELECT issued,
|
||||||
SUM(sub.taxableBase) taxableBase,
|
SUM(sub.taxableBase) taxableBase,
|
||||||
SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat
|
SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat
|
||||||
|
@ -215,20 +215,20 @@ BEGIN
|
||||||
ti.PorcentajeIva
|
ti.PorcentajeIva
|
||||||
FROM vn.invoiceIn i
|
FROM vn.invoiceIn i
|
||||||
JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id
|
JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id
|
||||||
JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
|
JOIN TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
|
||||||
WHERE i.id = vInvoiceInOriginalFk
|
WHERE i.id = vInvoiceInOriginalFk
|
||||||
GROUP BY ti.CodigoIva)sub
|
GROUP BY ti.CodigoIva)sub
|
||||||
)invoiceInOriginal
|
)invoiceInOriginal
|
||||||
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
|
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
|
||||||
SET mci.TipoRectificativa = iir.refundCategoryFk,
|
SET mci.TipoRectificativa = iic.cplusRectificationTypeFk,
|
||||||
mci.ClaseAbonoRectificativas = iir.refundType,
|
mci.ClaseAbonoRectificativas = REGEXP_REPLACE(st.`code`, '[^0-9]', ''),
|
||||||
mci.FechaFacturaOriginal = invoiceInOriginal.issued,
|
mci.FechaFacturaOriginal = invoiceInOriginal.issued,
|
||||||
mci.FechaOperacion = invoiceInOriginal.issued,
|
mci.FechaOperacion = invoiceInOriginal.issued,
|
||||||
mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase,
|
mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase,
|
||||||
mci.CuotaIvaOriginal = invoiceInOriginal.vat,
|
mci.CuotaIvaOriginal = invoiceInOriginal.vat,
|
||||||
mci.ClaveOperacionFactura = co.ClaveOperacionFactura_
|
mci.ClaveOperacionFactura = co.ClaveOperacionFactura_
|
||||||
WHERE mci.id = vXDiarioFk;
|
WHERE mci.id = vXDiarioFk;
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
|
$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -169,6 +169,7 @@ BEGIN
|
||||||
UPDATE movContaIVA mci
|
UPDATE movContaIVA mci
|
||||||
JOIN vn.invoiceOut i ON i.id = vInvoiceOutCorrectedFk
|
JOIN vn.invoiceOut i ON i.id = vInvoiceOutCorrectedFk
|
||||||
JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk
|
JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk
|
||||||
|
JOIN vn.siiTypeInvoiceOut st ON st.id = ic.siiTypeInvoiceOutFk
|
||||||
JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase,
|
JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase,
|
||||||
SUM(IF(IFNULL(e.vatFk, TRUE), iot.vat, 0)) vat,
|
SUM(IF(IFNULL(e.vatFk, TRUE), iot.vat, 0)) vat,
|
||||||
SUM(IF(IFNULL(e.vatFk, TRUE), 0, iot.vat)) equ
|
SUM(IF(IFNULL(e.vatFk, TRUE), 0, iot.vat)) equ
|
||||||
|
@ -177,8 +178,8 @@ BEGIN
|
||||||
WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk
|
WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk
|
||||||
) tax
|
) tax
|
||||||
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
|
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
|
||||||
SET mci.TipoRectificativa = 2,
|
SET mci.TipoRectificativa = ic.cplusRectificationTypeFk,
|
||||||
mci.ClaseAbonoRectificativas = 1,
|
mci.ClaseAbonoRectificativas = REGEXP_REPLACE(st.`code`, '[^0-9]', ''),
|
||||||
mci.FechaFacturaOriginal = i.issued,
|
mci.FechaFacturaOriginal = i.issued,
|
||||||
mci.FechaOperacion = i.issued,
|
mci.FechaOperacion = i.issued,
|
||||||
mci.BaseImponibleOriginal = tax.taxableBase,
|
mci.BaseImponibleOriginal = tax.taxableBase,
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
USE vn;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS invoiceIn_beforeUpdate;
|
||||||
|
|
||||||
|
UPDATE vn.invoiceIn
|
||||||
|
SET cplusRectificationTypeFk = NULL
|
||||||
|
WHERE cplusRectificationTypeFk = 1;
|
||||||
|
|
||||||
|
DELETE IGNORE FROM vn.cplusRectificationType WHERE id = 1;
|
||||||
|
|
||||||
|
UPDATE vn.cplusRectificationType
|
||||||
|
SET id = 1
|
||||||
|
WHERE id = 3;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`invoiceIn_beforeUpdate`
|
||||||
|
BEFORE UPDATE ON `invoiceIn`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
DECLARE vWithholdingSageFk INT;
|
||||||
|
|
||||||
|
IF NOT (NEW.supplierRef <=> OLD.supplierRef) AND NOT util.checkPrintableChars(NEW.supplierRef) THEN
|
||||||
|
CALL util.throw('The invoiceIn reference contains invalid characters');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
|
||||||
|
IF (SELECT COUNT(*) FROM vn.invoiceIn
|
||||||
|
WHERE supplierRef = NEW.supplierRef
|
||||||
|
AND supplierFk = NEW.supplierFk
|
||||||
|
AND YEAR(issued) = YEAR(NEW.issued)
|
||||||
|
AND id <> NEW.id
|
||||||
|
) THEN
|
||||||
|
CALL util.throw('reference duplicated');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NEW.supplierFk != OLD.supplierFk THEN
|
||||||
|
CALL supplier_checkIsActive(NEW.supplierFk);
|
||||||
|
SELECT withholdingSageFk INTO vWithholdingSageFk
|
||||||
|
FROM vn.supplier
|
||||||
|
WHERE id = NEW.supplierFk;
|
||||||
|
SET NEW.withholdingSageFk = vWithholdingSageFk;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue