feat: refs #7382 Added unique key #2667

Merged
guillermo merged 4 commits from 7382-triggerInvoiceInTax into dev 2024-07-05 10:26:26 +00:00
2 changed files with 18 additions and 8 deletions
Showing only changes of commit 2278b9a05a - Show all commits

View File

@ -13,20 +13,31 @@ BEGIN
* @param vBookEntry Id de asiento, si es NULL se genera uno nuevo
*/
DECLARE vFiscalYear INT;
DECLARE vHasDistinctTransactions INT;
DECLARE vDistinctTransactions INT;
DECLARE vHasRepeatedTransactions BOOL;
SELECT COUNT(DISTINCT transactionTypeSageFk) INTO vHasDistinctTransactions
FROM invoiceIn ii
JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id
SELECT COUNT(DISTINCT iit.transactionTypeSageFk) INTO vDistinctTransactions
FROM invoiceInTax iit
JOIN invoiceInSerial iis ON iis.code = ii.serial
WHERE ii.id = vSelf
WHERE iit.invoiceInFk = vSelf
AND iis.taxAreaFk = 'CEE'
AND transactionTypeSageFk;
AND iit.transactionTypeSageFk;
IF vHasDistinctTransactions > 1 THEN
IF vDistinctTransactions > 1 THEN
CALL util.throw ('This invoice does not allow different types of transactions');
END IF;
SELECT TRUE INTO vHasRepeatedTransactions
FROM invoiceInTax
WHERE invoiceInFk = vSelf
GROUP BY transactionTypeSageFk
HAVING COUNT(transactionTypeSageFk) > 1
LIMIT 1;
IF vHasRepeatedTransactions THEN
CALL util.throw ('This invoice contains repeated types of transactions');
END IF;
CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn
ENGINE = MEMORY
SELECT ii.bookEntried,

View File

@ -1 +0,0 @@
ALTER TABLE vn.invoiceInTax ADD CONSTRAINT invoiceInTax_unique UNIQUE KEY (invoiceInFk,expenseFk);