feat: refs #7984 add currency option
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Carlos Andrés 2024-11-27 18:20:20 +01:00
parent d111599c59
commit 727b170b66
2 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,29 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`currency_getRate`(
vSelf VARCHAR(3),
vDated DATE
)
RETURNS DECIMAL(10,2)
NOT DETERMINISTIC
READS SQL DATA
BEGIN
/**
* Returns the rate exchange based on the specified currency
* and yesterday's exchange rate.
*
* @param vSelf The currency code
* @param vDated The date of exchangue
* @return vForeignRate The rate e of currency exchange
*/
DECLARE vForeignRate DECIMAL(10,2);
SELECT value INTO vForeignRate
FROM referenceRate
WHERE dated = IFNULL(vDated, util.yesterday())
AND id = vSelf
ORDER BY dated DESC
LIMIT 1;
RETURN vForeignRate;
END$$
DELIMITER ;

View File

@ -0,0 +1,54 @@
ALTER TABLE hedera.order ADD `currencyFk` tinyint(3) UNSIGNED DEFAULT 1 NOT NULL AFTER total;
ALTER TABLE hedera.order ADD `foreignTaxableBase` decimal(10,2) NULL AFTER currencyFk;
ALTER TABLE hedera.order ADD `foreignTax` decimal(10,2) NULL AFTER foreignTaxableBase;
ALTER TABLE hedera.order ADD `foreignTotal` decimal(10,2) NULL AFTER foreignTax;
ALTER TABLE hedera.order DROP FOREIGN KEY IF EXISTS order_currency_FK;
ALTER TABLE hedera.order ADD CONSTRAINT order_currency_FK FOREIGN KEY (currencyFk)
REFERENCES vn.currency(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE hedera.orderRow ADD `foreignPrice` decimal(10,2) NULL AFTER price;
ALTER TABLE vn.company ADD `currencyFk` tinyint(3) UNSIGNED DEFAULT 1 NOT NULL;
ALTER TABLE vn.company DROP FOREIGN KEY IF EXISTS company_currency_FK;
ALTER TABLE vn.company ADD CONSTRAINT company_currency_FK FOREIGN KEY (currencyFk)
REFERENCES vn.currency(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE vn.ticket ADD `currencyFk` tinyint(3) UNSIGNED DEFAULT 1 NOT NULL AFTER totalWithoutVat;
ALTER TABLE vn.ticket ADD `foreignTotalWithVat` decimal(10,2) NULL AFTER currencyFk;
ALTER TABLE vn.ticket ADD `foreignTotalWithoutVat` decimal(10,2) NULL AFTER foreignTotalWithVat;
ALTER TABLE vn.ticket DROP FOREIGN KEY IF EXISTS ticket_currency_FK;
ALTER TABLE vn.ticket ADD CONSTRAINT ticket_currency_FK FOREIGN KEY (currencyFk)
REFERENCES vn.currency(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE vn.sale ADD `foreignPrice` decimal(10,2) NULL AFTER price;
ALTER TABLE vn.sale ADD `foreignTotal` decimal(10,2) NULL AFTER total;
ALTER TABLE vn.ticketService ADD `foreignPrice` decimal(10,2) NULL AFTER price;
ALTER TABLE vn.invoiceOut ADD `foreignAmount` decimal(10,2) NULL AFTER amount;
ALTER TABLE vn.invoiceOutExpense ADD `foreignAmount` DECIMAL(10,2) DEFAULT NULL AFTER amount;
ALTER TABLE vn.invoiceOutTax ADD `foreignTaxableBase` DECIMAL(10,2) DEFAULT NULL AFTER vat;
ALTER TABLE vn.invoiceOutTax ADD `foreignVat` DECIMAL(10,2) DEFAULT NULL AFTER foreignTaxableBase;
CREATE OR REPLACE DEFINER=`vn`@`localhost`
SQL SECURITY DEFINER
VIEW `hedera`.`order_row`
AS SELECT `t`.`id` AS `id`,
`t`.`orderFk` AS `order_id`,
`t`.`itemFk` AS `item_id`,
`t`.`warehouseFk` AS `warehouse_id`,
`t`.`shipment` AS `shipment`,
`t`.`amount` AS `amount`,
`t`.`price` AS `price`,
`t`.`foreignPrice` AS `foreignPrice`,
`t`.`rate` AS `rate`,
`t`.`created` AS `created`,
`t`.`saleFk` AS `Id_Movimiento`
FROM `hedera`.`orderRow` `t`;