Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 4320-notificationQueue

This commit is contained in:
Alex Moreno 2022-07-25 07:45:26 +02:00
commit f432d64f56
29 changed files with 180 additions and 114 deletions

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
@ -15,7 +16,7 @@ module.exports = Self => {
} }
}); });
Self.deleteTrashFiles = async(options) => { Self.deleteTrashFiles = async options => {
const tx = await Self.beginTransaction({}); const tx = await Self.beginTransaction({});
const myOptions = {}; const myOptions = {};
@ -26,6 +27,9 @@ module.exports = Self => {
myOptions.transaction = tx; myOptions.transaction = tx;
try { try {
if (process.env.NODE_ENV == 'test')
throw new UserError(`Action not allowed on the test environment`);
const models = Self.app.models; const models = Self.app.models;
const DmsContainer = models.DmsContainer; const DmsContainer = models.DmsContainer;
@ -33,9 +37,15 @@ module.exports = Self => {
where: {code: 'trash'} where: {code: 'trash'}
}, myOptions); }, myOptions);
const date = new Date();
date.setMonth(date.getMonth() - 4);
const dmsToDelete = await models.Dms.find({ const dmsToDelete = await models.Dms.find({
where: { where: {
dmsTypeFk: trashDmsType.id and: [
{dmsTypeFk: trashDmsType.id},
{created: {lt: date}}
]
} }
}, myOptions); }, myOptions);
@ -43,14 +53,19 @@ module.exports = Self => {
const pathHash = DmsContainer.getHash(dms.id); const pathHash = DmsContainer.getHash(dms.id);
const dmsContainer = await DmsContainer.container(pathHash); const dmsContainer = await DmsContainer.container(pathHash);
const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file); const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file);
const dstFolder = path.join(dmsContainer.client.root, pathHash);
await fs.unlink(dstFile); await fs.unlink(dstFile);
await dms.destroy(myOptions); try {
await fs.rmdir(dstFolder);
await dms.destroy(myOptions);
} catch (err) {
await dms.destroy(myOptions);
}
} }
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;
} }
}; };

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn2008`.`albaran_gestdoc` DROP FOREIGN KEY fk_albaran_gestdoc_gestdoc1;
ALTER TABLE `vn2008`.`albaran_gestdoc` ADD CONSTRAINT albaran_gestdoc_FK FOREIGN KEY (gestdoc_id) REFERENCES `vn`.`dms`(id) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -23,6 +23,7 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `account` /*!40100 DEFAULT CHARACTER SE
USE `account`; USE `account`;
-- --
-- Table structure for table `account` -- Table structure for table `account`
-- --
@ -37167,6 +37168,7 @@ CREATE TABLE `ticket` (
`zoneBonus` decimal(10,2) DEFAULT NULL, `zoneBonus` decimal(10,2) DEFAULT NULL,
`totalWithVat` decimal(10,2) DEFAULT NULL COMMENT 'cache calculada del total con iva', `totalWithVat` decimal(10,2) DEFAULT NULL COMMENT 'cache calculada del total con iva',
`totalWithoutVat` decimal(10,2) DEFAULT NULL COMMENT 'cache calculada del total sin iva', `totalWithoutVat` decimal(10,2) DEFAULT NULL COMMENT 'cache calculada del total sin iva',
`weight` decimal(10,2) DEFAULT NULL COMMENT 'En caso de informar, se utilizará su valor para calcular el peso de la factura',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `Id_Cliente` (`clientFk`), KEY `Id_Cliente` (`clientFk`),
KEY `Id_Consigna` (`addressFk`), KEY `Id_Consigna` (`addressFk`),
@ -37189,7 +37191,7 @@ CREATE TABLE `ticket` (
CONSTRAINT `ticket_ibfk_9` FOREIGN KEY (`routeFk`) REFERENCES `route` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `ticket_ibfk_9` FOREIGN KEY (`routeFk`) REFERENCES `route` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `tickets_fk11` FOREIGN KEY (`collectionFk__`) REFERENCES `collection` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `tickets_fk11` FOREIGN KEY (`collectionFk__`) REFERENCES `collection` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `tickets_zone_fk` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON UPDATE CASCADE CONSTRAINT `tickets_zone_fk` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=InnoDB AUTO_INCREMENT=3750016 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
/*!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 */ ;
@ -43321,6 +43323,40 @@ BEGIN
) t1; ) t1;
RETURN totalAmount; RETURN totalAmount;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
/*!50003 DROP FUNCTION IF EXISTS `invoiceOutAmount` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceOut_getWeight`(vInvoice VARCHAR(15)) RETURNS decimal(10,2)
READS SQL DATA
BEGIN
DECLARE vTotalWeight DECIMAL(10,2);
SELECT SUM(CAST(IFNULL(i.stems, 1) * s.quantity *
IF(ic.grams, ic.grams, i.density * ic.cm3delivery / 1000)
/ 1000 AS DECIMAL(10,2)))
INTO vTotalWeight
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN item i ON i.id = s.itemFk
JOIN itemCost ic ON ic.itemFk = i.id
AND ic.warehouseFk = t.warehouseFk
WHERE t.refFk = vInvoice
AND i.intrastatFk ;
RETURN vTotalWeight;
END ;; END ;;
DELIMITER ; DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET sql_mode = @saved_sql_mode */ ;

View File

@ -61,7 +61,7 @@ module.exports = Self => {
responseType: 'stream', responseType: 'stream',
params: { params: {
authorization: auth.id, authorization: auth.id,
invoiceId: id refFk: invoiceOut.ref
} }
}).then(async response => { }).then(async response => {
const issued = invoiceOut.issued; const issued = invoiceOut.issued;

View File

@ -84,7 +84,7 @@ class Controller extends Section {
showCsvInvoice() { showCsvInvoice() {
this.vnReport.showCsv('invoice', { this.vnReport.showCsv('invoice', {
recipientId: this.invoiceOut.client.id, recipientId: this.invoiceOut.client.id,
invoiceId: this.id refFk: this.invoiceOut.ref
}); });
} }
@ -95,7 +95,7 @@ class Controller extends Section {
return this.vnEmail.send('invoice', { return this.vnEmail.send('invoice', {
recipientId: this.invoiceOut.client.id, recipientId: this.invoiceOut.client.id,
recipient: $data.email, recipient: $data.email,
invoiceId: this.id refFk: this.invoiceOut.ref
}); });
} }
@ -106,14 +106,14 @@ class Controller extends Section {
return this.vnEmail.sendCsv('invoice', { return this.vnEmail.sendCsv('invoice', {
recipientId: this.invoiceOut.client.id, recipientId: this.invoiceOut.client.id,
recipient: $data.email, recipient: $data.email,
invoiceId: this.id refFk: this.invoiceOut.ref
}); });
} }
showExportationLetter() { showExportationLetter() {
this.vnReport.show('exportation', { this.vnReport.show('exportation', {
recipientId: this.invoiceOut.client.id, recipientId: this.invoiceOut.client.id,
invoiceId: this.id refFk: this.invoiceOut.ref
}); });
} }

View File

@ -6,7 +6,8 @@ describe('vnInvoiceOutDescriptorMenu', () => {
let $httpParamSerializer; let $httpParamSerializer;
const invoiceOut = { const invoiceOut = {
id: 1, id: 1,
client: {id: 1101} client: {id: 1101},
ref: 'T1111111'
}; };
beforeEach(ngModule('invoiceOut')); beforeEach(ngModule('invoiceOut'));
@ -40,8 +41,8 @@ describe('vnInvoiceOutDescriptorMenu', () => {
jest.spyOn(window, 'open').mockReturnThis(); jest.spyOn(window, 'open').mockReturnThis();
const expectedParams = { const expectedParams = {
invoiceId: invoiceOut.id, recipientId: invoiceOut.client.id,
recipientId: invoiceOut.client.id refFk: invoiceOut.ref
}; };
const serializedParams = $httpParamSerializer(expectedParams); const serializedParams = $httpParamSerializer(expectedParams);
const expectedPath = `api/csv/invoice/download?${serializedParams}`; const expectedPath = `api/csv/invoice/download?${serializedParams}`;
@ -84,9 +85,9 @@ describe('vnInvoiceOutDescriptorMenu', () => {
const $data = {email: 'brucebanner@gothamcity.com'}; const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = { const expectedParams = {
invoiceId: invoiceOut.id,
recipient: $data.email, recipient: $data.email,
recipientId: invoiceOut.client.id recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
}; };
const serializedParams = $httpParamSerializer(expectedParams); const serializedParams = $httpParamSerializer(expectedParams);
@ -104,9 +105,9 @@ describe('vnInvoiceOutDescriptorMenu', () => {
const $data = {email: 'brucebanner@gothamcity.com'}; const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = { const expectedParams = {
invoiceId: invoiceOut.id,
recipient: $data.email, recipient: $data.email,
recipientId: invoiceOut.client.id recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
}; };
const serializedParams = $httpParamSerializer(expectedParams); const serializedParams = $httpParamSerializer(expectedParams);

View File

@ -31,7 +31,7 @@ module.exports = {
if (invoiceOut) { if (invoiceOut) {
const args = Object.assign({ const args = Object.assign({
invoiceId: invoiceOut.id, refFk: invoiceOut.ref,
recipientId: ticket.clientFk, recipientId: ticket.clientFk,
recipient: ticket.recipient, recipient: ticket.recipient,
replyTo: ticket.salesPersonEmail replyTo: ticket.salesPersonEmail
@ -118,7 +118,7 @@ module.exports = {
await db.rawSql(` await db.rawSql(`
INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?) INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?)
`, [ticket.clientFk, sample.id, ticket.companyFk]) `, [ticket.clientFk, sample.id, ticket.companyFk]);
} }
} catch (error) { } catch (error) {
// Domain not found // Domain not found

View File

@ -7,13 +7,13 @@ const sqlPath = path.join(__dirname, 'sql');
module.exports = async function(request, response, next) { module.exports = async function(request, response, next) {
try { try {
const reqArgs = request.query; const reqArgs = request.query;
if (!reqArgs.invoiceId) if (!reqArgs.refFk)
throw new Error('The argument invoiceId is required'); throw new Error('The argument refFk is required');
const invoiceId = reqArgs.invoiceId; const refFk = reqArgs.refFk;
const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [invoiceId]); const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [refFk]);
const content = toCSV(sales); const content = toCSV(sales);
const fileName = `invoice_${invoiceId}.csv`; const fileName = `invoice_${refFk}.csv`;
response.setHeader('Content-type', 'text/csv'); response.setHeader('Content-type', 'text/csv');
response.setHeader('Content-Disposition', `inline; filename="${fileName}"`); response.setHeader('Content-Disposition', `inline; filename="${fileName}"`);

View File

@ -8,22 +8,22 @@ const sqlPath = path.join(__dirname, 'sql');
module.exports = async function(request, response, next) { module.exports = async function(request, response, next) {
try { try {
const reqArgs = request.query; const reqArgs = request.query;
if (!reqArgs.invoiceId) if (!reqArgs.refFk)
throw new Error('The argument invoiceId is required'); throw new Error('The argument refFk is required');
const invoiceId = reqArgs.invoiceId; const refFk = reqArgs.refFk;
const invoice = await db.findOneFromDef(`${sqlPath}/invoice`, [invoiceId]); const invoice = await db.findOneFromDef(`${sqlPath}/invoice`, [refFk]);
const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [invoiceId]); const sales = await db.rawSqlFromDef(`${sqlPath}/sales`, [refFk]);
const args = Object.assign({ const args = Object.assign({
invoiceId: (String(invoice.id)), refFk: invoice.refFk,
recipientId: invoice.clientFk, recipientId: invoice.clientFk,
recipient: invoice.recipient, recipient: invoice.recipient,
replyTo: invoice.salesPersonEmail replyTo: invoice.salesPersonEmail
}, response.locals); }, response.locals);
const content = toCSV(sales); const content = toCSV(sales);
const fileName = `invoice_${invoiceId}.csv`; const fileName = `invoice_${refFk}.csv`;
const email = new Email('invoice', args); const email = new Email('invoice', args);
await email.send({ await email.send({
overrideAttachments: true, overrideAttachments: true,

View File

@ -6,4 +6,5 @@ SELECT
FROM invoiceOut io FROM invoiceOut io
JOIN client c ON c.id = io.clientFk JOIN client c ON c.id = io.clientFk
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -31,5 +31,5 @@ FROM sale s
AND itc.countryFk = s2.countryFk AND itc.countryFk = s2.countryFk
JOIN taxClass tc ON tc.id = itc.taxClassFk JOIN taxClass tc ON tc.id = itc.taxClassFk
JOIN invoiceOut io ON io.ref = t.refFk JOIN invoiceOut io ON io.ref = t.refFk
WHERE io.id = ? WHERE t.refFk = ?
ORDER BY s.ticketFk, s.created ORDER BY s.ticketFk, s.created

View File

@ -38,7 +38,7 @@ module.exports = async function(request, response, next) {
connection.query('START TRANSACTION'); connection.query('START TRANSACTION');
const args = Object.assign({ const args = Object.assign({
invoiceId: invoiceOut.id, refFk: invoiceOut.ref,
recipientId: invoiceOut.clientFk, recipientId: invoiceOut.clientFk,
recipient: invoiceOut.recipient, recipient: invoiceOut.recipient,
replyTo: invoiceOut.salesPersonEmail replyTo: invoiceOut.salesPersonEmail

View File

@ -5,11 +5,11 @@ const emailFooter = new Component('email-footer');
module.exports = { module.exports = {
name: 'invoice', name: 'invoice',
async serverPrefetch() { async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId); this.invoice = await this.fetchInvoice(this.refFk);
}, },
methods: { methods: {
fetchInvoice(invoiceId) { fetchInvoice(refFk) {
return this.findOneFromDef('invoice', [invoiceId]); return this.findOneFromDef('invoice', [refFk]);
}, },
}, },
components: { components: {
@ -17,7 +17,7 @@ module.exports = {
'email-footer': emailFooter.build() 'email-footer': emailFooter.build()
}, },
props: { props: {
invoiceId: { refFk: {
type: [Number, String], type: [Number, String],
required: true required: true
} }

View File

@ -4,4 +4,4 @@ SELECT
FROM invoiceOut io FROM invoiceOut io
JOIN ticket t ON t.refFk = io.ref JOIN ticket t ON t.refFk = io.ref
JOIN client c ON c.id = io.clientFk JOIN client c ON c.id = io.clientFk
WHERE io.id = ? WHERE t.refFk = ?

View File

@ -5,14 +5,14 @@ const reportFooter = new Component('report-footer');
module.exports = { module.exports = {
name: 'exportation', name: 'exportation',
async serverPrefetch() { async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId); this.invoice = await this.fetchInvoice(this.refFk);
if (!this.invoice) if (!this.invoice)
throw new Error('Something went wrong'); throw new Error('Something went wrong');
}, },
methods: { methods: {
fetchInvoice(invoiceId) { fetchInvoice(refFk) {
return this.findOneFromDef('invoice', [invoiceId]); return this.findOneFromDef('invoice', [refFk]);
} }
}, },
computed: { computed: {
@ -27,7 +27,7 @@ module.exports = {
'report-footer': reportFooter.build() 'report-footer': reportFooter.build()
}, },
props: { props: {
invoiceId: { refFk: {
type: [Number, String], type: [Number, String],
required: true required: true
} }

View File

@ -3,4 +3,5 @@ SELECT
io.ref, io.ref,
io.issued io.issued
FROM invoiceOut io FROM invoiceOut io
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -5,9 +5,9 @@ const reportFooter = new Component('report-footer');
module.exports = { module.exports = {
name: 'invoice-incoterms', name: 'invoice-incoterms',
async serverPrefetch() { async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId); this.invoice = await this.fetchInvoice(this.refFk);
this.client = await this.fetchClient(this.invoiceId); this.client = await this.fetchClient(this.refFk);
this.incoterms = await this.fetchIncoterms(this.invoiceId); this.incoterms = await this.fetchIncoterms(this.refFk);
if (!this.invoice) if (!this.invoice)
throw new Error('Something went wrong'); throw new Error('Something went wrong');
@ -16,14 +16,14 @@ module.exports = {
}, },
methods: { methods: {
fetchInvoice(invoiceId) { fetchInvoice(refFk) {
return this.findOneFromDef('invoice', [invoiceId]); return this.findOneFromDef('invoice', [refFk]);
}, },
fetchClient(invoiceId) { fetchClient(refFk) {
return this.findOneFromDef('client', [invoiceId]); return this.findOneFromDef('client', [refFk]);
}, },
fetchIncoterms(invoiceId) { fetchIncoterms(refFk) {
return this.findOneFromDef('incoterms', [invoiceId, invoiceId, invoiceId]); return this.findOneFromDef('incoterms', [refFk, refFk, refFk]);
} }
}, },
components: { components: {
@ -31,7 +31,7 @@ module.exports = {
'report-footer': reportFooter.build() 'report-footer': reportFooter.build()
}, },
props: { props: {
invoiceId: { refFk: {
type: [Number, String], type: [Number, String],
required: true required: true
} }

View File

@ -9,4 +9,5 @@ FROM vn.invoiceOut io
JOIN vn.country cty ON cty.id = c.countryFk JOIN vn.country cty ON cty.id = c.countryFk
LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial
AND ios.taxAreaFk = 'CEE' AND ios.taxAreaFk = 'CEE'
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -51,7 +51,7 @@ SELECT io.issued,
FROM vn.invoiceOut io FROM vn.invoiceOut io
JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.ticket t ON t.refFk = io.ref
JOIN vn.saleVolume sv ON sv.ticketFk = t.id JOIN vn.saleVolume sv ON sv.ticketFk = t.id
WHERE io.id = ? WHERE t.refFk = ?
) sub2 ON TRUE ) sub2 ON TRUE
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk AND itc.itemFk = s.itemFk JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk AND itc.itemFk = s.itemFk
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
@ -66,6 +66,7 @@ SELECT io.issued,
JOIN vn.sale s ON t.id = s.ticketFk JOIN vn.sale s ON t.id = s.ticketFk
JOIN vn.item i ON i.id = s.itemFk JOIN vn.item i ON i.id = s.itemFk
JOIN vn.intrastat ir ON ir.id = i.intrastatFk JOIN vn.intrastat ir ON ir.id = i.intrastatFk
WHERE io.id = ? WHERE t.refFk = ?
)sub3 ON TRUE )sub3 ON TRUE
WHERE io.id = ? WHERE t.refFk = ?

View File

@ -14,4 +14,5 @@ FROM invoiceOut io
JOIN company cny ON cny.id = io.companyFk JOIN company cny ON cny.id = io.companyFk
JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk
LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -7,15 +7,15 @@ const invoiceIncoterms = new Report('invoice-incoterms');
module.exports = { module.exports = {
name: 'invoice', name: 'invoice',
async serverPrefetch() { async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId); this.invoice = await this.fetchInvoice(this.refFk);
this.client = await this.fetchClient(this.invoiceId); this.client = await this.fetchClient(this.refFk);
this.taxes = await this.fetchTaxes(this.invoiceId); this.taxes = await this.fetchTaxes(this.refFk);
this.intrastat = await this.fetchIntrastat(this.invoiceId); this.intrastat = await this.fetchIntrastat(this.refFk);
this.rectified = await this.fetchRectified(this.invoiceId); this.rectified = await this.fetchRectified(this.refFk);
this.hasIncoterms = await this.fetchHasIncoterms(this.invoiceId); this.hasIncoterms = await this.fetchHasIncoterms(this.refFk);
const tickets = await this.fetchTickets(this.invoiceId); const tickets = await this.fetchTickets(this.refFk);
const sales = await this.fetchSales(this.invoiceId); const sales = await this.fetchSales(this.refFk);
const map = new Map(); const map = new Map();
@ -65,29 +65,29 @@ module.exports = {
} }
}, },
methods: { methods: {
fetchInvoice(invoiceId) { fetchInvoice(refFk) {
return this.findOneFromDef('invoice', [invoiceId]); return this.findOneFromDef('invoice', [refFk]);
}, },
fetchClient(invoiceId) { fetchClient(refFk) {
return this.findOneFromDef('client', [invoiceId]); return this.findOneFromDef('client', [refFk]);
}, },
fetchTickets(invoiceId) { fetchTickets(refFk) {
return this.rawSqlFromDef('tickets', [invoiceId]); return this.rawSqlFromDef('tickets', [refFk]);
}, },
fetchSales(invoiceId) { fetchSales(refFk) {
return this.rawSqlFromDef('sales', [invoiceId, invoiceId]); return this.rawSqlFromDef('sales', [refFk, refFk]);
}, },
fetchTaxes(invoiceId) { fetchTaxes(refFk) {
return this.rawSqlFromDef(`taxes`, [invoiceId]); return this.rawSqlFromDef(`taxes`, [refFk]);
}, },
fetchIntrastat(invoiceId) { fetchIntrastat(refFk) {
return this.rawSqlFromDef(`intrastat`, [invoiceId]); return this.rawSqlFromDef(`intrastat`, [refFk, refFk, refFk]);
}, },
fetchRectified(invoiceId) { fetchRectified(refFk) {
return this.rawSqlFromDef(`rectified`, [invoiceId]); return this.rawSqlFromDef(`rectified`, [refFk]);
}, },
fetchHasIncoterms(invoiceId) { fetchHasIncoterms(refFk) {
return this.findValueFromDef(`hasIncoterms`, [invoiceId]); return this.findValueFromDef(`hasIncoterms`, [refFk]);
}, },
saleImport(sale) { saleImport(sale) {
const price = sale.quantity * sale.price; const price = sale.quantity * sale.price;
@ -115,9 +115,8 @@ module.exports = {
'invoice-incoterms': invoiceIncoterms.build() 'invoice-incoterms': invoiceIncoterms.build()
}, },
props: { props: {
invoiceId: { refFk: {
type: [Number, String], type: String
required: true
} }
} }
}; };

View File

@ -9,4 +9,5 @@ FROM vn.invoiceOut io
JOIN vn.country cty ON cty.id = c.countryFk JOIN vn.country cty ON cty.id = c.countryFk
LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial
AND ios.taxAreaFk = 'CEE' AND ios.taxAreaFk = 'CEE'
WHERE io.id = ? LEFT JOIN vn.ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -3,6 +3,6 @@ SELECT IF(incotermsFk IS NULL, FALSE, TRUE) AS hasIncoterms
JOIN invoiceOut io ON io.ref = t.refFk JOIN invoiceOut io ON io.ref = t.refFk
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN address a ON a.id = t.addressFk JOIN address a ON a.id = t.addressFk
WHERE io.id = ? WHERE t.refFk = ?
AND IF(c.hasToinvoiceByAddress = FALSE, c.defaultAddressFk, TRUE) AND IF(c.hasToinvoiceByAddress = FALSE, c.defaultAddressFk, TRUE)
LIMIT 1 LIMIT 1

View File

@ -1,18 +1,22 @@
SELECT SELECT
ir.id AS code, ir.id code,
ir.description AS description, ir.description description,
CAST(SUM(IFNULL(i.stems,1) * s.quantity) AS DECIMAL(10,2)) as stems, CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL(10,2)) stems,
CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) netKg, CAST(SUM(CAST(IFNULL(i.stems, 1) * s.quantity * IF(ic.grams, ic.grams, i.density * ic.cm3delivery / 1000) / 1000 AS DECIMAL(10,2)) *
CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) AS subtotal IF(sub.weight, sub.weight / vn.invoiceOut_getWeight(?), 1)) AS DECIMAL(10,2)) netKg,
FROM vn.sale s CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) subtotal
LEFT JOIN (SELECT ic.itemFk, ic.cm3, ic.cm3delivery FROM vn.ticket t
FROM vn.itemCost ic JOIN vn.sale s ON s.ticketFk = t.id
WHERE ic.cm3 JOIN vn.item i ON i.id = s.itemFk
GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk
LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id JOIN vn.intrastat ir ON ir.id = i.intrastatFk
LEFT JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN (
LEFT JOIN vn.invoiceOut io ON io.ref = t.refFk SELECT t2.weight
LEFT JOIN vn.item i ON i.id = s.itemFk FROM vn.ticket t2
JOIN vn.intrastat ir ON ir.id = i.intrastatFk WHERE refFk = ? AND weight
WHERE io.id = ? LIMIT 1
GROUP BY i.intrastatFk; ) sub ON TRUE
WHERE t.refFk = ?
AND i.intrastatFk
GROUP BY i.intrastatFk
ORDER BY i.intrastatFk;

View File

@ -13,4 +13,5 @@ FROM invoiceOut io
JOIN company cny ON cny.id = io.companyFk JOIN company cny ON cny.id = io.companyFk
JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk
LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial
WHERE io.id = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -6,4 +6,5 @@ SELECT
FROM vn.invoiceCorrection ic FROM vn.invoiceCorrection ic
JOIN vn.invoiceOut io ON io.id = ic.correctedFk JOIN vn.invoiceOut io ON io.id = ic.correctedFk
JOIN vn.invoiceCorrectionType ict ON ict.id = ic.invoiceCorrectionTypeFk JOIN vn.invoiceCorrectionType ict ON ict.id = ic.invoiceCorrectionTypeFk
where ic.correctingFk = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?

View File

@ -37,7 +37,7 @@ SELECT
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk
AND itc.itemFk = s.itemFk AND itc.itemFk = s.itemFk
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
WHERE io.id = ? WHERE t.refFk = ?
UNION ALL UNION ALL
SELECT SELECT
io.ref, io.ref,
@ -69,4 +69,4 @@ SELECT
JOIN vn.company co ON co.id = io.companyFk JOIN vn.company co ON co.id = io.companyFk
JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk
JOIN vn.taxClass tc ON tc.id = ts.taxClassFk JOIN vn.taxClass tc ON tc.id = ts.taxClassFk
WHERE io.id = ? WHERE t.refFk = ?

View File

@ -6,6 +6,7 @@ SELECT
FROM invoiceOutTax iot FROM invoiceOutTax iot
JOIN pgc ON pgc.code = iot.pgcFk JOIN pgc ON pgc.code = iot.pgcFk
LEFT JOIN pgcEqu pe ON pe.equFk = pgc.code LEFT JOIN pgcEqu pe ON pe.equFk = pgc.code
JOIN invoiceOut io ON io.id = iot.invoiceOutFk JOIN invoiceOut io ON io.id = iot.invoiceOutFk
WHERE invoiceOutFk = ? LEFT JOIN ticket t ON t.refFk = io.ref
WHERE t.refFk = ?
ORDER BY iot.id ORDER BY iot.id

View File

@ -4,5 +4,5 @@ SELECT
t.nickname t.nickname
FROM invoiceOut io FROM invoiceOut io
JOIN ticket t ON t.refFk = io.ref JOIN ticket t ON t.refFk = io.ref
WHERE io.id = ? WHERE t.refFk = ?
ORDER BY t.shipped ORDER BY t.shipped