feat: refs #4460 invoiceIn refund #3047
|
@ -4,8 +4,8 @@ BEGIN
|
|||
/**
|
||||
* Traslada la info de contabilidad relacionada con las facturas recibidas
|
||||
*
|
||||
* @vInvoiceInFk Factura recibida
|
||||
* @vXDiarioFk Id tabla XDiario
|
||||
* @param vInvoiceInFk Factura recibida
|
||||
* @param vXDiarioFk Id tabla XDiario
|
||||
*/
|
||||
DECLARE vInvoiceInOriginalFk INT;
|
||||
DECLARE vDone BOOL DEFAULT FALSE;
|
||||
|
@ -204,9 +204,9 @@ BEGIN
|
|||
WHERE correctingFk = vInvoiceInFk;
|
||||
|
||||
IF vInvoiceInOriginalFk THEN
|
||||
|
||||
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,
|
||||
SUM(sub.taxableBase) taxableBase,
|
||||
SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat
|
||||
|
@ -215,20 +215,20 @@ BEGIN
|
|||
ti.PorcentajeIva
|
||||
FROM vn.invoiceIn i
|
||||
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
|
||||
GROUP BY ti.CodigoIva)sub
|
||||
)invoiceInOriginal
|
||||
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
|
||||
SET mci.TipoRectificativa = iir.refundCategoryFk,
|
||||
mci.ClaseAbonoRectificativas = iir.refundType,
|
||||
SET mci.TipoRectificativa = iic.cplusRectificationTypeFk,
|
||||
mci.ClaseAbonoRectificativas = REGEXP_REPLACE(st.`code`, '[^0-9]', ''),
|
||||
mci.FechaFacturaOriginal = invoiceInOriginal.issued,
|
||||
mci.FechaOperacion = invoiceInOriginal.issued,
|
||||
mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase,
|
||||
mci.CuotaIvaOriginal = invoiceInOriginal.vat,
|
||||
mci.ClaveOperacionFactura = co.ClaveOperacionFactura_
|
||||
WHERE mci.id = vXDiarioFk;
|
||||
|
||||
END IF;
|
||||
END$$
|
||||
$$
|
||||
DELIMITER ;
|
|
@ -169,6 +169,7 @@ BEGIN
|
|||
UPDATE movContaIVA mci
|
||||
JOIN vn.invoiceOut i ON i.id = 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,
|
||||
SUM(IF(IFNULL(e.vatFk, TRUE), iot.vat, 0)) vat,
|
||||
SUM(IF(IFNULL(e.vatFk, TRUE), 0, iot.vat)) equ
|
||||
|
@ -177,8 +178,8 @@ BEGIN
|
|||
WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk
|
||||
) tax
|
||||
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
|
||||
SET mci.TipoRectificativa = 2,
|
||||
mci.ClaseAbonoRectificativas = 1,
|
||||
SET mci.TipoRectificativa = ic.cplusRectificationTypeFk,
|
||||
mci.ClaseAbonoRectificativas = REGEXP_REPLACE(st.`code`, '[^0-9]', ''),
|
||||
mci.FechaFacturaOriginal = i.issued,
|
||||
mci.FechaOperacion = i.issued,
|
||||
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