fix: refs #7346 invoiceSerial
This commit is contained in:
parent
a8cc3f496f
commit
212e8d1a03
|
@ -1,18 +1,23 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(15))
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceSerial`(
|
||||
vClientFk INT,
|
||||
vCompanyFk INT,
|
||||
vType CHAR(15)
|
||||
)
|
||||
RETURNS char(2) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
/**
|
||||
* Obtiene la serie de una factura
|
||||
* dependiendo del area del cliente.
|
||||
*
|
||||
* @param vClientFk Id del cliente
|
||||
* @param vCompanyFk Id de la empresa
|
||||
* @param vType Tipo de factura ['global','multiple','quick']
|
||||
* @return vSerie de la factura
|
||||
*/
|
||||
/**
|
||||
* Obtiene la serie de una factura
|
||||
* dependiendo del area del cliente.
|
||||
*
|
||||
* @param vClientFk Id del cliente
|
||||
* @param vCompanyFk Id de la empresa
|
||||
* @param vType Tipo de factura (vn.invoiceOutSerial.type[ENUM])
|
||||
* @return vSerie de la factura
|
||||
*/
|
||||
DECLARE vTaxArea VARCHAR(25) COLLATE utf8mb3_general_ci;
|
||||
DECLARE vTransactionCode INT(2);
|
||||
DECLARE vSerie CHAR(2);
|
||||
|
||||
IF (SELECT hasInvoiceSimplified FROM client WHERE id = vClientFk) THEN
|
||||
|
@ -23,9 +28,15 @@ BEGIN
|
|||
FROM client
|
||||
WHERE id = vClientFk;
|
||||
|
||||
SELECT code INTO vSerie
|
||||
FROM invoiceOutSerial
|
||||
WHERE `type` = vType AND taxAreaFk = vTaxArea;
|
||||
SELECT CodigoTransaccion INTO vTransactionCode
|
||||
FROM taxArea
|
||||
WHERE code = vTaxArea;
|
||||
|
||||
SELECT ios.code INTO vSerie
|
||||
FROM invoiceOutSerial ios
|
||||
JOIN taxArea ta ON ta.code = ios.taxAreaFk
|
||||
WHERE ios.`type` = vType
|
||||
AND ta.CodigoTransaccion = vTransactionCode;
|
||||
|
||||
RETURN vSerie;
|
||||
END$$
|
||||
|
|
|
@ -13,23 +13,20 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) {
|
|||
const failedtickets = [];
|
||||
for (const ticket of tickets) {
|
||||
try {
|
||||
await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'M');
|
||||
await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'multiple');
|
||||
await Self.rawSql(
|
||||
`CALL vn.ticket_closeByTicket(?)`,
|
||||
[ticket.id],
|
||||
{userId}
|
||||
);
|
||||
|
||||
const [invoiceOut] = await Self.rawSql(
|
||||
`
|
||||
const [invoiceOut] = await Self.rawSql(`
|
||||
SELECT io.id, io.ref, io.serial, cny.code companyCode, io.issued
|
||||
FROM ticket t
|
||||
JOIN invoiceOut io ON io.ref = t.refFk
|
||||
JOIN company cny ON cny.id = io.companyFk
|
||||
WHERE t.id = ?
|
||||
`,
|
||||
[ticket.id],
|
||||
);
|
||||
`, [ticket.id]);
|
||||
|
||||
const mailOptions = {
|
||||
overrideAttachments: true,
|
||||
|
@ -104,17 +101,14 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) {
|
|||
}
|
||||
|
||||
// Incoterms authorization
|
||||
const [{firstOrder}] = await Self.rawSql(
|
||||
`
|
||||
SELECT COUNT(*) as firstOrder
|
||||
FROM ticket t
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
WHERE t.clientFk = ?
|
||||
AND NOT t.isDeleted
|
||||
AND c.isVies
|
||||
`,
|
||||
[ticket.clientFk],
|
||||
);
|
||||
const [{firstOrder}] = await Self.rawSql(`
|
||||
SELECT COUNT(*) as firstOrder
|
||||
FROM ticket t
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
WHERE t.clientFk = ?
|
||||
AND NOT t.isDeleted
|
||||
AND c.isVies
|
||||
`, [ticket.clientFk]);
|
||||
|
||||
if (firstOrder == 1) {
|
||||
const args = {
|
||||
|
@ -129,26 +123,17 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) {
|
|||
const email = new Email('incoterms-authorization', args);
|
||||
await email.send();
|
||||
|
||||
const [sample] = await Self.rawSql(
|
||||
`SELECT id
|
||||
const [sample] = await Self.rawSql(`
|
||||
SELECT id
|
||||
FROM sample
|
||||
WHERE code = 'incoterms-authorization'
|
||||
`,
|
||||
);
|
||||
WHERE code = 'incoterms-authorization'
|
||||
`);
|
||||
|
||||
await Self.rawSql(
|
||||
`
|
||||
await Self.rawSql(`
|
||||
INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?)
|
||||
`,
|
||||
[ticket.clientFk, sample.id, ticket.companyFk],
|
||||
{userId},
|
||||
);
|
||||
`, [ticket.clientFk, sample.id, ticket.companyFk], {userId});
|
||||
}
|
||||
} catch (error) {
|
||||
await Self.rawSql(`
|
||||
INSERT INTO util.debug (variable, value)
|
||||
VALUES ('invoicingTicketError', ?)
|
||||
`, [ticket.id + ' - ' + error]);
|
||||
// Domain not found
|
||||
if (error.responseCode == 450) {
|
||||
await invalidEmail(ticket);
|
||||
|
|
Loading…
Reference in New Issue