HOTFIX: Invoice regeneration error
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-05-27 10:49:19 +02:00
parent 95073183e9
commit c533973398
3 changed files with 45 additions and 62 deletions

View File

@ -3,7 +3,6 @@ const Report = require(`${appPath}/core/report`);
const reportHeader = new Component('report-header'); const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer'); const reportFooter = new Component('report-footer');
const invoiceIncoterms = new Report('invoice-incoterms'); const invoiceIncoterms = new Report('invoice-incoterms');
const db = require(`${appPath}/core/database`);
module.exports = { module.exports = {
name: 'invoice', name: 'invoice',
@ -72,17 +71,8 @@ module.exports = {
fetchTickets(invoiceId) { fetchTickets(invoiceId) {
return this.rawSqlFromDef('tickets', [invoiceId]); return this.rawSqlFromDef('tickets', [invoiceId]);
}, },
async fetchSales(invoiceId) { fetchSales(invoiceId) {
const connection = await db.pool.getConnection(); return this.rawSqlFromDef('sales', [invoiceId, invoiceId]);
await this.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.invoiceTickets`, connection);
await this.rawSqlFromDef('invoiceTickets', [invoiceId], connection);
const sales = this.rawSqlFromDef('sales', connection);
await this.rawSql(`DROP TEMPORARY TABLE tmp.invoiceTickets`, connection);
await connection.release();
return sales;
}, },
fetchTaxes(invoiceId) { fetchTaxes(invoiceId) {
return this.rawSqlFromDef(`taxes`, [invoiceId]); return this.rawSqlFromDef(`taxes`, [invoiceId]);

View File

@ -1,20 +0,0 @@
CREATE TEMPORARY TABLE tmp.invoiceTickets
ENGINE = MEMORY
SELECT
t.id AS ticketFk,
t.clientFk,
t.shipped,
t.nickname,
io.ref,
c.socialName,
sa.iban,
pm.name AS payMethod,
su.countryFk AS supplierCountryFk
FROM vn.invoiceOut io
JOIN vn.supplier su ON su.id = io.companyFk
JOIN vn.ticket t ON t.refFk = io.ref
JOIN vn.client c ON c.id = t.clientFk
JOIN vn.payMethod pm ON pm.id = c.payMethodFk
JOIN vn.company co ON co.id = io.companyFk
JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk
WHERE io.id = ?

View File

@ -1,11 +1,11 @@
SELECT SELECT
it.ref, io.ref,
it.socialName, c.socialName,
it.iban, sa.iban,
it.payMethod, pm.name AS payMethod,
it.clientFk, t.clientFk,
it.shipped, t.shipped,
it.nickname, t.nickname,
s.ticketFk, s.ticketFk,
s.itemFk, s.itemFk,
s.concept, s.concept,
@ -20,27 +20,34 @@ SELECT
i.value7, i.value7,
tc.code AS vatType, tc.code AS vatType,
ib.ediBotanic botanical ib.ediBotanic botanical
FROM tmp.invoiceTickets it FROM vn.invoiceOut io
JOIN vn.sale s ON s.ticketFk = it.ticketFk JOIN vn.ticket t ON t.refFk = io.ref
JOIN item i ON i.id = s.itemFk JOIN vn.supplier su ON su.id = io.companyFk
LEFT JOIN itemType it ON it.id = i.typeFk JOIN vn.client c ON c.id = t.clientFk
LEFT JOIN itemCategory ic ON ic.id = it.categoryFk JOIN vn.payMethod pm ON pm.id = c.payMethodFk
LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id JOIN vn.company co ON co.id = io.companyFk
AND ic.code = 'plant' JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk
AND ib.ediBotanic IS NOT NULL JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.itemTaxCountry itc ON itc.countryFk = it.supplierCountryFk JOIN item i ON i.id = s.itemFk
AND itc.itemFk = s.itemFk LEFT JOIN itemType it ON it.id = i.typeFk
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
UNION ALL LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id
AND ic.code = 'plant'
AND ib.ediBotanic IS NOT NULL
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk
AND itc.itemFk = s.itemFk
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
WHERE io.id = ?
UNION ALL
SELECT SELECT
it.ref, io.ref,
it.socialName, c.socialName,
it.iban, sa.iban,
it.payMethod, pm.name AS payMethod,
it.clientFk, t.clientFk,
it.shipped, t.shipped,
it.nickname, t.nickname,
it.ticketFk, t.id AS ticketFk,
'', '',
ts.description concept, ts.description concept,
ts.quantity, ts.quantity,
@ -54,6 +61,12 @@ SELECT
NULL AS value7, NULL AS value7,
tc.code AS vatType, tc.code AS vatType,
NULL AS botanical NULL AS botanical
FROM tmp.invoiceTickets it FROM vn.invoiceOut io
JOIN vn.ticketService ts ON ts.ticketFk = it.ticketFk JOIN vn.ticket t ON t.refFk = io.ref
JOIN vn.taxClass tc ON tc.id = ts.taxClassFk JOIN vn.ticketService ts ON ts.ticketFk = t.id
JOIN vn.client c ON c.id = t.clientFk
JOIN vn.payMethod pm ON pm.id = c.payMethodFk
JOIN vn.company co ON co.id = io.companyFk
JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk
JOIN vn.taxClass tc ON tc.id = ts.taxClassFk
WHERE io.id = ?