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
1 changed files with 17 additions and 5 deletions

View File

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