refs #5914 feat: create getTaxBases and use in negatives and positives procedures
This commit is contained in:
parent
824ca1d70a
commit
e634a5e213
|
@ -0,0 +1,33 @@
|
|||
DELIMITER $$
|
||||
$$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`getTaxBases`()
|
||||
BEGIN
|
||||
|
||||
/* Calcula y devuelve en número de bases imponibles postivas y negativas
|
||||
* Requiere la tabla temporal tmp.ticketToInvoice(id)
|
||||
*
|
||||
* returns tmp.taxBases
|
||||
*/
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id ticketFk
|
||||
FROM tmp.ticketToInvoice;
|
||||
|
||||
CALL ticket_getTax(NULL);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.taxBases;
|
||||
CREATE TEMPORARY TABLE tmp.taxBases
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
SUM(CASE WHEN taxableBase > 0 THEN 1 ELSE 0 END) as positive,
|
||||
SUM(CASE WHEN taxableBase < 0 THEN 1 ELSE 0 END) as negative
|
||||
FROM(
|
||||
SELECT SUM(taxableBase) as taxableBase
|
||||
FROM tmp.ticketTax
|
||||
GROUP BY pgcFk
|
||||
) t;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,28 @@
|
|||
DELIMITER $$
|
||||
$$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasAnyPositiveBase`() RETURNS tinyint(1)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
|
||||
/* Calcula si existe alguna base imponible positiva
|
||||
* Requiere la tabla temporal tmp.ticketToInvoice(id) para getTaxBases()
|
||||
*
|
||||
* returns BOOLEAN
|
||||
*/
|
||||
|
||||
DECLARE hasAnyPositiveBase BOOLEAN;
|
||||
|
||||
CALL getTaxBases();
|
||||
|
||||
SELECT positive > 0 INTO hasAnyPositiveBase
|
||||
FROM tmp.taxBases;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticketTax,
|
||||
tmp.ticket,
|
||||
tmp.taxBases;
|
||||
|
||||
RETURN hasAnyPositiveBase;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,28 @@
|
|||
DELIMITER $$
|
||||
$$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasAnyNegativeBase`() RETURNS tinyint(1)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
|
||||
/* Calcula si existe alguna base imponible negativa
|
||||
* Requiere la tabla temporal tmp.ticketToInvoice(id) para getTaxBases()
|
||||
*
|
||||
* returns BOOLEAN
|
||||
*/
|
||||
|
||||
DECLARE hasAnyNegativeBase BOOLEAN;
|
||||
|
||||
CALL getTaxBases();
|
||||
|
||||
SELECT negative > 0 INTO hasAnyNegativeBase
|
||||
FROM tmp.taxBases;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticketTax,
|
||||
tmp.ticket,
|
||||
tmp.taxBases;
|
||||
|
||||
RETURN hasAnyNegativeBase;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -598,18 +598,19 @@ INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`
|
|||
|
||||
INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`)
|
||||
VALUES
|
||||
('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'),
|
||||
('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'),
|
||||
('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'),
|
||||
('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'quick'),
|
||||
('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick');
|
||||
('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'),
|
||||
('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'),
|
||||
('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'),
|
||||
('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'quick'),
|
||||
('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL),
|
||||
('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick');
|
||||
|
||||
INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`)
|
||||
VALUES
|
||||
(1, 'T', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0),
|
||||
(2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0),
|
||||
(3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0),
|
||||
(4, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0),
|
||||
(4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0),
|
||||
(5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0);
|
||||
|
||||
UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1;
|
||||
|
|
Loading…
Reference in New Issue