feat: refs #7936 add currency handling in invoiceIn trigger
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
9ece52c5ce
commit
163c6ddd20
|
@ -3,24 +3,30 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`invoiceIn_afterUpdate`
|
||||||
AFTER UPDATE ON `invoiceIn`
|
AFTER UPDATE ON `invoiceIn`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
IF NEW.issued != OLD.issued
|
DECLARE vIsEuro BOOL;
|
||||||
OR NEW.currencyFk != OLD.currencyFk THEN
|
|
||||||
|
SELECT if(`code` = 'EUR', TRUE, FALSE) INTO vIsEuro
|
||||||
|
FROM currency
|
||||||
|
WHERE id = NEW.currencyFk;
|
||||||
|
|
||||||
|
IF (NOT NEW.issued <=> OLD.issued
|
||||||
|
OR NEW.currencyFk <> OLD.currencyFk) THEN
|
||||||
|
|
||||||
UPDATE invoiceInTax iit
|
UPDATE invoiceInTax iit
|
||||||
JOIN invoiceIn ii ON ii.id = iit.invoiceInFk
|
JOIN invoiceIn ii ON ii.id = iit.invoiceInFk
|
||||||
LEFT JOIN referenceRate rr ON rr.dated = ii.issued
|
LEFT JOIN referenceRate rr ON rr.dated = ii.issued
|
||||||
AND rr.currencyFk = ii.currencyFk
|
AND rr.currencyFk = ii.currencyFk
|
||||||
SET iit.taxableBase = IF(iit.foreignValue IS NULL, iit.taxableBase, iit.foreignValue / rr.value)
|
SET iit.taxableBase = IF(vIsEuro, iit.taxableBase, iit.foreignValue / rr.value),
|
||||||
|
iit.foreignValue = IF(vIsEuro, NULL, iit.foreignValue)
|
||||||
WHERE ii.id = NEW.id;
|
WHERE ii.id = NEW.id;
|
||||||
|
|
||||||
UPDATE invoiceInDueDay iidd
|
UPDATE invoiceInDueDay iidd
|
||||||
JOIN invoiceIn ii ON ii.id = iidd.invoiceInFk
|
JOIN invoiceIn ii ON ii.id = iidd.invoiceInFk
|
||||||
LEFT JOIN referenceRate rr ON rr.dated = ii.issued
|
LEFT JOIN referenceRate rr ON rr.dated = ii.issued
|
||||||
AND rr.currencyFk = ii.currencyFk
|
AND rr.currencyFk = ii.currencyFk
|
||||||
SET iidd.amount = IF(iidd.foreignValue IS NULL, iidd.amount, iidd.foreignValue / rr.value)
|
SET iidd.amount = IF(vIsEuro, iidd.amount, iidd.foreignValue / rr.value),
|
||||||
|
iidd.foreignValue = IF(vIsEuro, NULL, iidd.foreignValue)
|
||||||
WHERE ii.id = NEW.id;
|
WHERE ii.id = NEW.id;
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -96,17 +96,6 @@ module.exports = Self => {
|
||||||
withholdingSageFk
|
withholdingSageFk
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (currencyFk) {
|
|
||||||
const currency = await models.Currency.findById(currencyFk, null, myOptions);
|
|
||||||
if (currency.code === 'EUR') {
|
|
||||||
const invoiceInTaxes = await models.InvoiceInTax.find(
|
|
||||||
{where: {invoiceInFk: id}}, myOptions);
|
|
||||||
|
|
||||||
for (const invoiceInTax of invoiceInTaxes)
|
|
||||||
await invoiceInTax.updateAttribute('foreignValue', null, myOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
return invoiceIn;
|
return invoiceIn;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue