refs #4617 use temporary instead of vn #1451
|
@ -8,7 +8,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`(
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Creación de facturas emitidas.
|
* Creación de facturas emitidas.
|
||||||
* requiere previamente tabla ticketToInvoice(id).
|
* requiere previamente tabla tmp.ticketToInvoice(id).
|
||||||
*
|
*
|
||||||
* @param vSerial serie a la cual se hace la factura
|
* @param vSerial serie a la cual se hace la factura
|
||||||
* @param vInvoiceDate fecha de la factura
|
* @param vInvoiceDate fecha de la factura
|
||||||
|
@ -36,13 +36,13 @@ BEGIN
|
||||||
|
|
||||||
SELECT t.clientFk, t.companyFk
|
SELECT t.clientFk, t.companyFk
|
||||||
INTO vClient, vCompany
|
INTO vClient, vCompany
|
||||||
FROM ticketToInvoice tt
|
FROM tmp.ticketToInvoice tt
|
||||||
JOIN ticket t ON t.id = tt.id
|
JOIN ticket t ON t.id = tt.id
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
-- Eliminem de ticketToInvoice els tickets que no han de ser facturats
|
-- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats
|
||||||
DELETE ti.*
|
DELETE ti.*
|
||||||
FROM ticketToInvoice ti
|
FROM tmp.ticketToInvoice ti
|
||||||
JOIN ticket t ON t.id = ti.id
|
JOIN ticket t ON t.id = ti.id
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
@ -57,7 +57,7 @@ BEGIN
|
||||||
|
|
||||||
SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id
|
SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id
|
||||||
INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice
|
INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice
|
||||||
FROM ticketToInvoice t
|
FROM tmp.ticketToInvoice t
|
||||||
LEFT JOIN sale s ON s.ticketFk = t.id
|
LEFT JOIN sale s ON s.ticketFk = t.id
|
||||||
LEFT JOIN ticketService ts ON ts.ticketFk = t.id;
|
LEFT JOIN ticketService ts ON ts.ticketFk = t.id;
|
||||||
|
|
||||||
|
@ -100,13 +100,13 @@ BEGIN
|
||||||
WHERE id = vNewInvoiceId;
|
WHERE id = vNewInvoiceId;
|
||||||
|
|
||||||
UPDATE ticket t
|
UPDATE ticket t
|
||||||
JOIN ticketToInvoice ti ON ti.id = t.id
|
JOIN tmp.ticketToInvoice ti ON ti.id = t.id
|
||||||
SET t.refFk = vNewRef;
|
SET t.refFk = vNewRef;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
|
DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
|
||||||
CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
|
CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
|
||||||
SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
|
SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
|
||||||
FROM ticketToInvoice ti
|
FROM tmp.ticketToInvoice ti
|
||||||
LEFT JOIN ticketState ts ON ti.id = ts.ticket
|
LEFT JOIN ticketState ts ON ti.id = ts.ticket
|
||||||
JOIN state s
|
JOIN state s
|
||||||
WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id);
|
WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id);
|
||||||
|
@ -116,7 +116,7 @@ BEGIN
|
||||||
|
|
||||||
INSERT INTO ticketLog (action, userFk, originFk, description)
|
INSERT INTO ticketLog (action, userFk, originFk, description)
|
||||||
SELECT 'UPDATE', account.myUser_getId(), ti.id, CONCAT('Crea factura ', vNewRef)
|
SELECT 'UPDATE', account.myUser_getId(), ti.id, CONCAT('Crea factura ', vNewRef)
|
||||||
FROM ticketToInvoice ti;
|
FROM tmp.ticketToInvoice ti;
|
||||||
|
|
||||||
CALL invoiceExpenceMake(vNewInvoiceId);
|
CALL invoiceExpenceMake(vNewInvoiceId);
|
||||||
CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
|
CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
|
||||||
|
@ -159,7 +159,7 @@ BEGIN
|
||||||
(KEY (ticketFk))
|
(KEY (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id ticketFk
|
SELECT id ticketFk
|
||||||
FROM ticketToInvoice;
|
FROM tmp.ticketToInvoice;
|
||||||
|
|
||||||
CALL `ticket_getTax`('NATIONAL');
|
CALL `ticket_getTax`('NATIONAL');
|
||||||
|
|
||||||
|
@ -220,6 +220,6 @@ BEGIN
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE `ticketToInvoice`;
|
DROP TEMPORARY TABLE `tmp`.`ticketToInvoice`;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -10,14 +10,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`(
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Creación de facturas emitidas.
|
* Creación de facturas emitidas.
|
||||||
* requiere previamente tabla ticketToInvoice(id).
|
* requiere previamente tabla tmp.ticketToInvoice(id).
|
||||||
*
|
*
|
||||||
* @param vSerial serie a la cual se hace la factura
|
* @param vSerial serie a la cual se hace la factura
|
||||||
* @param vInvoiceDate fecha de la factura
|
* @param vInvoiceDate fecha de la factura
|
||||||
* @param vTaxArea tipo de iva en relacion a la empresa y al cliente
|
* @param vTaxArea tipo de iva en relacion a la empresa y al cliente
|
||||||
* @param vNewInvoiceId id de la factura que se acaba de generar
|
* @param vNewInvoiceId id de la factura que se acaba de generar
|
||||||
* @return vNewInvoiceId
|
* @return vNewInvoiceId
|
||||||
*/
|
*/
|
||||||
DECLARE vIsAnySaleToInvoice BOOL;
|
DECLARE vIsAnySaleToInvoice BOOL;
|
||||||
DECLARE vIsAnyServiceToInvoice BOOL;
|
DECLARE vIsAnyServiceToInvoice BOOL;
|
||||||
DECLARE vNewRef VARCHAR(255);
|
DECLARE vNewRef VARCHAR(255);
|
||||||
|
@ -37,32 +37,32 @@ BEGIN
|
||||||
DECLARE vMaxShipped DATE;
|
DECLARE vMaxShipped DATE;
|
||||||
|
|
||||||
SET vInvoiceDate = IFNULL(vInvoiceDate, util.CURDATE());
|
SET vInvoiceDate = IFNULL(vInvoiceDate, util.CURDATE());
|
||||||
|
|
||||||
SELECT t.clientFk,
|
SELECT t.clientFk,
|
||||||
t.companyFk,
|
t.companyFk,
|
||||||
MAX(DATE(t.shipped)),
|
MAX(DATE(t.shipped)),
|
||||||
DATE(vInvoiceDate) >= invoiceOut_getMaxIssued(
|
DATE(vInvoiceDate) >= invoiceOut_getMaxIssued(
|
||||||
vSerial,
|
vSerial,
|
||||||
t.companyFk,
|
t.companyFk,
|
||||||
YEAR(vInvoiceDate))
|
YEAR(vInvoiceDate))
|
||||||
INTO vClientFk,
|
INTO vClientFk,
|
||||||
vCompanyFk,
|
vCompanyFk,
|
||||||
vMaxShipped,
|
vMaxShipped,
|
||||||
vIsCorrectInvoiceDate
|
vIsCorrectInvoiceDate
|
||||||
FROM ticketToInvoice tt
|
FROM tmp.ticketToInvoice tt
|
||||||
JOIN ticket t ON t.id = tt.id;
|
JOIN ticket t ON t.id = tt.id;
|
||||||
|
|
||||||
IF(vMaxShipped > vInvoiceDate) THEN
|
IF(vMaxShipped > vInvoiceDate) THEN
|
||||||
CALL util.throw("Invoice date can't be less than max date");
|
CALL util.throw("Invoice date can't be less than max date");
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF NOT vIsCorrectInvoiceDate THEN
|
IF NOT vIsCorrectInvoiceDate THEN
|
||||||
CALL util.throw('Exists an invoice with a previous date');
|
CALL util.throw('Exists an invoice with a previous date');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Eliminem de ticketToInvoice els tickets que no han de ser facturats
|
-- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats
|
||||||
DELETE ti.*
|
DELETE ti.*
|
||||||
FROM ticketToInvoice ti
|
FROM tmp.ticketToInvoice ti
|
||||||
JOIN ticket t ON t.id = ti.id
|
JOIN ticket t ON t.id = ti.id
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
@ -77,11 +77,11 @@ BEGIN
|
||||||
|
|
||||||
SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0
|
SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0
|
||||||
INTO vIsAnySaleToInvoice
|
INTO vIsAnySaleToInvoice
|
||||||
FROM ticketToInvoice t
|
FROM tmp.ticketToInvoice t
|
||||||
JOIN sale s ON s.ticketFk = t.id;
|
JOIN sale s ON s.ticketFk = t.id;
|
||||||
|
|
||||||
SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice
|
SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice
|
||||||
FROM ticketToInvoice t
|
FROM tmp.ticketToInvoice t
|
||||||
JOIN ticketService ts ON ts.ticketFk = t.id;
|
JOIN ticketService ts ON ts.ticketFk = t.id;
|
||||||
|
|
||||||
IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice)
|
IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice)
|
||||||
|
@ -121,13 +121,13 @@ BEGIN
|
||||||
WHERE id = vNewInvoiceId;
|
WHERE id = vNewInvoiceId;
|
||||||
|
|
||||||
UPDATE ticket t
|
UPDATE ticket t
|
||||||
JOIN ticketToInvoice ti ON ti.id = t.id
|
JOIN tmp.ticketToInvoice ti ON ti.id = t.id
|
||||||
SET t.refFk = vNewRef;
|
SET t.refFk = vNewRef;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
|
DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
|
||||||
CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
|
CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
|
||||||
SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
|
SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
|
||||||
FROM ticketToInvoice ti
|
FROM tmp.ticketToInvoice ti
|
||||||
LEFT JOIN ticketState ts ON ti.id = ts.ticket
|
LEFT JOIN ticketState ts ON ti.id = ts.ticket
|
||||||
JOIN state s
|
JOIN state s
|
||||||
WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id);
|
WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id);
|
||||||
|
@ -137,7 +137,7 @@ BEGIN
|
||||||
|
|
||||||
INSERT INTO ticketLog (action, userFk, originFk, description)
|
INSERT INTO ticketLog (action, userFk, originFk, description)
|
||||||
SELECT 'UPDATE', account.myUser_getId(), ti.id, CONCAT('Crea factura ', vNewRef)
|
SELECT 'UPDATE', account.myUser_getId(), ti.id, CONCAT('Crea factura ', vNewRef)
|
||||||
FROM ticketToInvoice ti;
|
FROM tmp.ticketToInvoice ti;
|
||||||
|
|
||||||
CALL invoiceExpenceMake(vNewInvoiceId);
|
CALL invoiceExpenceMake(vNewInvoiceId);
|
||||||
CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
|
CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
|
||||||
|
@ -157,12 +157,12 @@ BEGIN
|
||||||
WHERE io.id = vNewInvoiceId;
|
WHERE io.id = vNewInvoiceId;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.updateInter;
|
DROP TEMPORARY TABLE tmp.updateInter;
|
||||||
|
|
||||||
SELECT COUNT(*), id
|
SELECT COUNT(*), id
|
||||||
INTO vIsInterCompany, vInterCompanyFk
|
INTO vIsInterCompany, vInterCompanyFk
|
||||||
FROM company
|
FROM company
|
||||||
WHERE clientFk = vClientFk;
|
WHERE clientFk = vClientFk;
|
||||||
|
|
||||||
IF (vIsInterCompany) THEN
|
IF (vIsInterCompany) THEN
|
||||||
|
|
||||||
INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk)
|
INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk)
|
||||||
|
@ -175,7 +175,7 @@ BEGIN
|
||||||
(KEY (ticketFk))
|
(KEY (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id ticketFk
|
SELECT id ticketFk
|
||||||
FROM ticketToInvoice;
|
FROM tmp.ticketToInvoice;
|
||||||
|
|
||||||
CALL `ticket_getTax`('NATIONAL');
|
CALL `ticket_getTax`('NATIONAL');
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ BEGIN
|
||||||
) sub;
|
) sub;
|
||||||
|
|
||||||
INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk)
|
INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk)
|
||||||
SELECT vNewInvoiceInFk,
|
SELECT vNewInvoiceInFk,
|
||||||
SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral,
|
SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral,
|
||||||
@vTaxableBaseServices, 0) taxableBase,
|
@vTaxableBaseServices, 0) taxableBase,
|
||||||
i.expenceFk,
|
i.expenceFk,
|
||||||
|
@ -215,13 +215,13 @@ BEGIN
|
||||||
ORDER BY tt.priority;
|
ORDER BY tt.priority;
|
||||||
|
|
||||||
CALL invoiceInDueDay_calculate(vNewInvoiceInFk);
|
CALL invoiceInDueDay_calculate(vNewInvoiceInFk);
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vIsCEESerial
|
SELECT COUNT(*) INTO vIsCEESerial
|
||||||
FROM invoiceOutSerial
|
FROM invoiceOutSerial
|
||||||
WHERE code = vSerial;
|
WHERE code = vSerial;
|
||||||
|
|
||||||
IF vIsCEESerial THEN
|
IF vIsCEESerial THEN
|
||||||
|
|
||||||
INSERT INTO invoiceInIntrastat (
|
INSERT INTO invoiceInIntrastat (
|
||||||
invoiceInFk,
|
invoiceInFk,
|
||||||
intrastatFk,
|
intrastatFk,
|
||||||
|
@ -253,6 +253,6 @@ BEGIN
|
||||||
DROP TEMPORARY TABLE tmp.ticketServiceTax;
|
DROP TEMPORARY TABLE tmp.ticketServiceTax;
|
||||||
END IF;
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
DROP TEMPORARY TABLE `ticketToInvoice`;
|
DROP TEMPORARY TABLE tmp.`ticketToInvoice`;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -42776,7 +42776,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `hasAnyNegativeBase`() RETURNS tinyin
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
/* Calcula si existe alguna base imponible negativa
|
/* Calcula si existe alguna base imponible negativa
|
||||||
* Requiere la tabla temporal vn.ticketToInvoice(id)
|
* Requiere la tabla temporal tmp.ticketToInvoice(id)
|
||||||
*
|
*
|
||||||
* returns BOOLEAN
|
* returns BOOLEAN
|
||||||
*/
|
*/
|
||||||
|
@ -42787,7 +42787,7 @@ BEGIN
|
||||||
(KEY (ticketFk))
|
(KEY (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id ticketFk
|
SELECT id ticketFk
|
||||||
FROM ticketToInvoice;
|
FROM tmp.ticketToInvoice;
|
||||||
|
|
||||||
CALL ticket_getTax(NULL);
|
CALL ticket_getTax(NULL);
|
||||||
|
|
||||||
|
@ -55223,7 +55223,7 @@ DELIMITER ;;
|
||||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceExpenceMake`(IN vInvoice INT)
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceExpenceMake`(IN vInvoice INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
/* Inserta las partidas de gasto correspondientes a la factura
|
/* Inserta las partidas de gasto correspondientes a la factura
|
||||||
* REQUIERE tabla ticketToInvoice
|
* REQUIERE tabla tmp.ticketToInvoice
|
||||||
* @param vInvoice Numero de factura
|
* @param vInvoice Numero de factura
|
||||||
*/
|
*/
|
||||||
DELETE FROM invoiceOutExpence
|
DELETE FROM invoiceOutExpence
|
||||||
|
@ -55233,7 +55233,7 @@ BEGIN
|
||||||
SELECT vInvoice,
|
SELECT vInvoice,
|
||||||
expenceFk,
|
expenceFk,
|
||||||
SUM(ROUND(quantity * price * (100 - discount)/100,2)) amount
|
SUM(ROUND(quantity * price * (100 - discount)/100,2)) amount
|
||||||
FROM ticketToInvoice t
|
FROM tmp.ticketToInvoice t
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
GROUP BY i.expenceFk
|
GROUP BY i.expenceFk
|
||||||
|
@ -55243,7 +55243,7 @@ BEGIN
|
||||||
SELECT vInvoice,
|
SELECT vInvoice,
|
||||||
tst.expenceFk,
|
tst.expenceFk,
|
||||||
SUM(ROUND(ts.quantity * ts.price ,2)) amount
|
SUM(ROUND(ts.quantity * ts.price ,2)) amount
|
||||||
FROM ticketToInvoice t
|
FROM tmp.ticketToInvoice t
|
||||||
JOIN ticketService ts ON ts.ticketFk = t.id
|
JOIN ticketService ts ON ts.ticketFk = t.id
|
||||||
JOIN ticketServiceType tst ON tst.id = ts.ticketServiceTypeFk
|
JOIN ticketServiceType tst ON tst.id = ts.ticketServiceTypeFk
|
||||||
HAVING amount != 0;
|
HAVING amount != 0;
|
||||||
|
@ -55270,9 +55270,9 @@ BEGIN
|
||||||
|
|
||||||
SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate);
|
SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
|
DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE `ticketToInvoice`
|
CREATE TEMPORARY TABLE `tmp`.`ticketToInvoice`
|
||||||
(PRIMARY KEY (`id`))
|
(PRIMARY KEY (`id`))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT Id_Ticket id FROM vn2008.Tickets WHERE (Fecha BETWEEN vMinDateTicket
|
SELECT Id_Ticket id FROM vn2008.Tickets WHERE (Fecha BETWEEN vMinDateTicket
|
||||||
|
@ -55305,8 +55305,8 @@ BEGIN
|
||||||
SET vMinTicketDate = util.firstDayOfYear(vMaxTicketDate - INTERVAL 1 YEAR);
|
SET vMinTicketDate = util.firstDayOfYear(vMaxTicketDate - INTERVAL 1 YEAR);
|
||||||
SET vMaxTicketDate = util.dayend(vMaxTicketDate);
|
SET vMaxTicketDate = util.dayend(vMaxTicketDate);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
|
DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`;
|
||||||
CREATE TEMPORARY TABLE `ticketToInvoice`
|
CREATE TEMPORARY TABLE `tmp`.`ticketToInvoice`
|
||||||
(PRIMARY KEY (`id`))
|
(PRIMARY KEY (`id`))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id FROM ticket t
|
SELECT id FROM ticket t
|
||||||
|
@ -55333,9 +55333,9 @@ DELIMITER ;;
|
||||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceFromTicket`(IN vTicket INT)
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceFromTicket`(IN vTicket INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
|
DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE `ticketToInvoice`
|
CREATE TEMPORARY TABLE `tmp`.`ticketToInvoice`
|
||||||
(PRIMARY KEY (`id`))
|
(PRIMARY KEY (`id`))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id FROM vn.ticket
|
SELECT id FROM vn.ticket
|
||||||
|
@ -55931,9 +55931,9 @@ BEGIN
|
||||||
JOIN invoiceOut io ON io.companyFk = s.id
|
JOIN invoiceOut io ON io.companyFk = s.id
|
||||||
WHERE io.id = vInvoiceFk;
|
WHERE io.id = vInvoiceFk;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE ticketToInvoice
|
CREATE TEMPORARY TABLE tmp.ticketToInvoice
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM ticket
|
FROM ticket
|
||||||
WHERE refFk = vInvoiceRef;
|
WHERE refFk = vInvoiceRef;
|
||||||
|
@ -56408,9 +56408,9 @@ BEGIN
|
||||||
JOIN client c ON c.id = io.clientFk
|
JOIN client c ON c.id = io.clientFk
|
||||||
WHERE io.id = vInvoice;
|
WHERE io.id = vInvoice;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE ticketToInvoice
|
CREATE TEMPORARY TABLE tmp.ticketToInvoice
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM ticket
|
FROM ticket
|
||||||
WHERE refFk = vInvoiceRef;
|
WHERE refFk = vInvoiceRef;
|
||||||
|
@ -56456,7 +56456,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_exportationFromClient`(
|
||||||
vCompanyFk INT)
|
vCompanyFk INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Genera tabla temporal ticketToInvoice necesaría para el proceso de facturación
|
* Genera tabla temporal tmp.ticketToInvoice necesaría para el proceso de facturación
|
||||||
* Los abonos quedan excluidos en las exportaciones
|
* Los abonos quedan excluidos en las exportaciones
|
||||||
*
|
*
|
||||||
* @param vMaxTicketDate Fecha hasta la cual cogerá tickets para facturar
|
* @param vMaxTicketDate Fecha hasta la cual cogerá tickets para facturar
|
||||||
|
@ -56467,8 +56467,8 @@ BEGIN
|
||||||
SET vMinTicketDate = util.firstDayOfYear(vMaxTicketDate - INTERVAL 1 YEAR);
|
SET vMinTicketDate = util.firstDayOfYear(vMaxTicketDate - INTERVAL 1 YEAR);
|
||||||
SET vMaxTicketDate = util.dayend(vMaxTicketDate);
|
SET vMaxTicketDate = util.dayend(vMaxTicketDate);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
|
DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`;
|
||||||
CREATE TEMPORARY TABLE `ticketToInvoice`
|
CREATE TEMPORARY TABLE `tmp`.`ticketToInvoice`
|
||||||
(PRIMARY KEY (`id`))
|
(PRIMARY KEY (`id`))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id
|
SELECT t.id
|
||||||
|
@ -56503,7 +56503,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_new`(
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Creación de facturas emitidas.
|
* Creación de facturas emitidas.
|
||||||
* requiere previamente tabla ticketToInvoice(id).
|
* requiere previamente tabla tmp.ticketToInvoice(id).
|
||||||
*
|
*
|
||||||
* @param vSerial serie a la cual se hace la factura
|
* @param vSerial serie a la cual se hace la factura
|
||||||
* @param vInvoiceDate fecha de la factura
|
* @param vInvoiceDate fecha de la factura
|
||||||
|
@ -56531,13 +56531,13 @@ BEGIN
|
||||||
|
|
||||||
SELECT t.clientFk, t.companyFk
|
SELECT t.clientFk, t.companyFk
|
||||||
INTO vClientFk, vCompanyFk
|
INTO vClientFk, vCompanyFk
|
||||||
FROM ticketToInvoice tt
|
FROM tmp.ticketToInvoice tt
|
||||||
JOIN ticket t ON t.id = tt.id
|
JOIN ticket t ON t.id = tt.id
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
-- Eliminem de ticketToInvoice els tickets que no han de ser facturats
|
-- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats
|
||||||
DELETE ti.*
|
DELETE ti.*
|
||||||
FROM ticketToInvoice ti
|
FROM tmp.ticketToInvoice ti
|
||||||
JOIN ticket t ON t.id = ti.id
|
JOIN ticket t ON t.id = ti.id
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
@ -56552,7 +56552,7 @@ BEGIN
|
||||||
|
|
||||||
SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id
|
SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id
|
||||||
INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice
|
INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice
|
||||||
FROM ticketToInvoice t
|
FROM tmp.ticketToInvoice t
|
||||||
LEFT JOIN sale s ON s.ticketFk = t.id
|
LEFT JOIN sale s ON s.ticketFk = t.id
|
||||||
LEFT JOIN ticketService ts ON ts.ticketFk = t.id;
|
LEFT JOIN ticketService ts ON ts.ticketFk = t.id;
|
||||||
|
|
||||||
|
@ -56593,13 +56593,13 @@ BEGIN
|
||||||
WHERE id = vNewInvoiceId;
|
WHERE id = vNewInvoiceId;
|
||||||
|
|
||||||
UPDATE ticket t
|
UPDATE ticket t
|
||||||
JOIN ticketToInvoice ti ON ti.id = t.id
|
JOIN tmp.ticketToInvoice ti ON ti.id = t.id
|
||||||
SET t.refFk = vNewRef;
|
SET t.refFk = vNewRef;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
|
DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
|
||||||
CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
|
CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
|
||||||
SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
|
SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
|
||||||
FROM ticketToInvoice ti
|
FROM tmp.ticketToInvoice ti
|
||||||
LEFT JOIN ticketState ts ON ti.id = ts.ticket
|
LEFT JOIN ticketState ts ON ti.id = ts.ticket
|
||||||
JOIN state s
|
JOIN state s
|
||||||
WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id);
|
WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id);
|
||||||
|
@ -56609,7 +56609,7 @@ BEGIN
|
||||||
|
|
||||||
INSERT INTO ticketLog (action, userFk, originFk, description)
|
INSERT INTO ticketLog (action, userFk, originFk, description)
|
||||||
SELECT 'UPDATE', account.myUser_getId(), ti.id, CONCAT('Crea factura ', vNewRef)
|
SELECT 'UPDATE', account.myUser_getId(), ti.id, CONCAT('Crea factura ', vNewRef)
|
||||||
FROM ticketToInvoice ti;
|
FROM tmp.ticketToInvoice ti;
|
||||||
|
|
||||||
CALL invoiceExpenceMake(vNewInvoiceId);
|
CALL invoiceExpenceMake(vNewInvoiceId);
|
||||||
CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
|
CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
|
||||||
|
@ -56647,7 +56647,7 @@ BEGIN
|
||||||
(KEY (ticketFk))
|
(KEY (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id ticketFk
|
SELECT id ticketFk
|
||||||
FROM ticketToInvoice;
|
FROM tmp.ticketToInvoice;
|
||||||
|
|
||||||
CALL `ticket_getTax`('NATIONAL');
|
CALL `ticket_getTax`('NATIONAL');
|
||||||
|
|
||||||
|
@ -56725,7 +56725,7 @@ BEGIN
|
||||||
DROP TEMPORARY TABLE tmp.ticketServiceTax;
|
DROP TEMPORARY TABLE tmp.ticketServiceTax;
|
||||||
END IF;
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
DROP TEMPORARY TABLE `ticketToInvoice`;
|
DROP TEMPORARY TABLE `tmp`.`ticketToInvoice`;
|
||||||
END ;;
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
@ -56876,7 +56876,7 @@ BEGIN
|
||||||
(KEY (ticketFk))
|
(KEY (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id ticketFk
|
SELECT id ticketFk
|
||||||
FROM ticketToInvoice;
|
FROM tmp.ticketToInvoice;
|
||||||
|
|
||||||
CALL ticket_getTax(vTaxArea);
|
CALL ticket_getTax(vTaxArea);
|
||||||
|
|
||||||
|
@ -68689,7 +68689,7 @@ DELIMITER ;
|
||||||
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
/*!50003 DROP PROCEDURE IF EXISTS `ticketToInvoiceByAddress` */;
|
/*!50003 DROP PROCEDURE IF EXISTS `tmp`.`ticketToInvoiceByAddress` */;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
@ -68709,9 +68709,9 @@ BEGIN
|
||||||
|
|
||||||
SET vEnded = util.dayEnd(vEnded);
|
SET vEnded = util.dayEnd(vEnded);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE vn.ticketToInvoice
|
CREATE TEMPORARY TABLE tmp.ticketToInvoice
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM vn.ticket
|
FROM vn.ticket
|
||||||
WHERE addressFk = vAddress
|
WHERE addressFk = vAddress
|
||||||
|
@ -68745,9 +68745,9 @@ BEGIN
|
||||||
|
|
||||||
SET vEnded = util.dayEnd(vEnded);
|
SET vEnded = util.dayEnd(vEnded);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE vn.ticketToInvoice
|
CREATE TEMPORARY TABLE tmp.ticketToInvoice
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM vn.ticket
|
FROM vn.ticket
|
||||||
WHERE clientFk = vClient
|
WHERE clientFk = vClient
|
||||||
|
@ -68808,9 +68808,9 @@ BEGIN
|
||||||
JOIN vn.client c ON c.id = io.clientFk
|
JOIN vn.client c ON c.id = io.clientFk
|
||||||
WHERE io.id = vInvoice;
|
WHERE io.id = vInvoice;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE vn.ticketToInvoice
|
CREATE TEMPORARY TABLE tmp.ticketToInvoice
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM vn.ticket
|
FROM vn.ticket
|
||||||
WHERE refFk = vInvoiceRef;
|
WHERE refFk = vInvoiceRef;
|
||||||
|
|
|
@ -75,8 +75,8 @@ module.exports = function(Self) {
|
||||||
serial = result.serial;
|
serial = result.serial;
|
||||||
|
|
||||||
await Self.rawSql(`
|
await Self.rawSql(`
|
||||||
DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice;
|
||||||
CREATE TEMPORARY TABLE ticketToInvoice
|
CREATE TEMPORARY TABLE tmp.ticketToInvoice
|
||||||
(PRIMARY KEY (id))
|
(PRIMARY KEY (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id FROM vn.ticket
|
SELECT id FROM vn.ticket
|
||||||
|
|
Loading…
Reference in New Issue