feat: refs #7346 #2864
|
@ -1,5 +1,5 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(1))
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(15))
|
||||||
RETURNS char(1) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
RETURNS char(1) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
||||||
DETERMINISTIC
|
DETERMINISTIC
|
||||||
BEGIN
|
BEGIN
|
||||||
|
@ -9,18 +9,24 @@ BEGIN
|
||||||
*
|
*
|
||||||
* @param vClientFk Id del cliente
|
* @param vClientFk Id del cliente
|
||||||
* @param vCompanyFk Id de la empresa
|
* @param vCompanyFk Id de la empresa
|
||||||
* @param vType Tipo de factura ["R", "M", "G"]
|
* @param vType Tipo de factura ['global','multiple','quick']
|
||||||
* @return Serie de la factura
|
* @return vSerie de la factura
|
||||||
*/
|
*/
|
||||||
DECLARE vTaxArea VARCHAR(25);
|
DECLARE vTaxArea VARCHAR(25);
|
||||||
DECLARE vSerie CHAR(1);
|
DECLARE vSerie CHAR(2);
|
||||||
|
|
||||||
IF (SELECT hasInvoiceSimplified FROM client WHERE id = vClientFk) THEN
|
IF (SELECT hasInvoiceSimplified FROM client WHERE id = vClientFk) THEN
|
||||||
RETURN 'S';
|
RETURN 'S';
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SELECT clientTaxArea(vClientFk, vCompanyFk) INTO vTaxArea;
|
SELECT addressTaxArea(defaultAddressFk, vCompanyFk) INTO vTaxArea
|
||||||
SELECT invoiceSerialArea(vType,vTaxArea) INTO vSerie;
|
FROM client
|
||||||
|
WHERE id = vClientFk;
|
||||||
|
|
||||||
|
SELECT code INTO vSerie
|
||||||
|
FROM invoiceOutSerial
|
||||||
|
WHERE `type` = vType AND taxAreaFk = vTaxArea;
|
||||||
|
|
||||||
RETURN vSerie;
|
RETURN vSerie;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceSerialArea`(vType CHAR(1), vTaxArea VARCHAR(25))
|
|
||||||
RETURNS char(1) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci
|
|
||||||
DETERMINISTIC
|
|
||||||
BEGIN
|
|
||||||
DECLARE vSerie CHAR(1);
|
|
||||||
|
|
||||||
IF vType = 'R' THEN
|
|
||||||
SELECT
|
|
||||||
CASE vTaxArea
|
|
||||||
WHEN 'CEE' THEN 'H'
|
|
||||||
WHEN 'WORLD' THEN 'E'
|
|
||||||
ELSE 'T'
|
|
||||||
END INTO vSerie;
|
|
||||||
-- Factura multiple
|
|
||||||
ELSEIF vType = 'M' THEN
|
|
||||||
SELECT
|
|
||||||
CASE vTaxArea
|
|
||||||
WHEN 'CEE' THEN 'H'
|
|
||||||
WHEN 'WORLD' THEN 'E'
|
|
||||||
ELSE 'M'
|
|
||||||
END INTO vSerie;
|
|
||||||
-- Factura global
|
|
||||||
ELSEIF vType = 'G' THEN
|
|
||||||
SELECT
|
|
||||||
CASE vTaxArea
|
|
||||||
WHEN 'CEE' THEN 'V'
|
|
||||||
WHEN 'WORLD' THEN 'X'
|
|
||||||
ELSE 'A'
|
|
||||||
END INTO vSerie;
|
|
||||||
END IF;
|
|
||||||
RETURN vSerie;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -90,7 +90,7 @@ BEGIN
|
||||||
IF vIsTaxDataChecked THEN
|
IF vIsTaxDataChecked THEN
|
||||||
CALL invoiceOut_newFromClient(
|
CALL invoiceOut_newFromClient(
|
||||||
vClientFk,
|
vClientFk,
|
||||||
(SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')),
|
(SELECT invoiceSerial(vClientFk, vCompanyFk, 'multiple')),
|
||||||
vShipped,
|
vShipped,
|
||||||
vCompanyFk,
|
vCompanyFk,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
|
@ -111,7 +111,7 @@ module.exports = Self => {
|
||||||
LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id
|
LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id
|
||||||
AND itc.countryFk = su.countryFk
|
AND itc.countryFk = su.countryFk
|
||||||
LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD'
|
LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD'
|
||||||
AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'M')
|
AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'multiple')
|
||||||
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered'))
|
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered'))
|
||||||
AND DATE(t.shipped) BETWEEN ? - INTERVAL 2 DAY AND util.dayEnd(?)
|
AND DATE(t.shipped) BETWEEN ? - INTERVAL 2 DAY AND util.dayEnd(?)
|
||||||
AND t.refFk IS NULL
|
AND t.refFk IS NULL
|
||||||
|
|
|
@ -95,7 +95,7 @@ module.exports = function(Self) {
|
||||||
FROM vn.ticket
|
FROM vn.ticket
|
||||||
WHERE id IN (?)
|
WHERE id IN (?)
|
||||||
`, [ticketsIds], myOptions);
|
`, [ticketsIds], myOptions);
|
||||||
return models.Ticket.makeInvoice(ctx, 'R', companyId, Date.vnNew(), invoiceCorrection, myOptions);
|
return models.Ticket.makeInvoice(ctx, 'quick', companyId, Date.vnNew(), invoiceCorrection, myOptions);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket makeInvoice()', () => {
|
describe('ticket makeInvoice()', () => {
|
||||||
const userId = 19;
|
const userId = 19;
|
||||||
const invoiceType = 'R';
|
const invoiceType = 'quick';
|
||||||
const companyFk = 442;
|
const companyFk = 442;
|
||||||
const invoiceDate = Date.vnNew();
|
const invoiceDate = Date.vnNew();
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
|
|
Loading…
Reference in New Issue