+
+
+
+
+
@@ -12,7 +17,7 @@
-
+
{{$t('title')}}
@@ -52,122 +57,105 @@
+
+
+
+ {{$t('rectifiedInvoices')}}
+
+
+
+ {{$t('invoice')}} |
+ {{$t('issued')}} |
+ {{$t('amount')}} |
+ {{$t('description')}} |
+
+
+
+
+ {{row.ref}} |
+ {{row.issued | date}} |
+ {{row.amount | currency('EUR', $i18n.locale)}} |
+ {{row.description}} |
+
+
+
+
+
- {{$t('saleLines')}}
-
-
-
- {{$t('reference')}} |
- {{$t('quantity')}} |
- {{$t('concept')}} |
- {{$t('price')}} |
- {{$t('discount')}} |
- {{$t('vat')}} |
- {{$t('amount')}} |
-
-
-
-
- {{sale.itemFk | zerofill('000000')}} |
- {{sale.quantity}} |
- {{sale.concept}} |
- {{sale.price | currency('EUR', $i18n.locale)}} |
- {{(sale.discount / 100) | percentage}} |
- {{sale.vatType}} |
- {{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', $i18n.locale)}} |
-
-
-
-
- {{sale.tag5}} {{sale.value5}}
-
-
- {{sale.tag6}} {{sale.value6}}
-
-
- {{sale.tag7}} {{sale.value7}}
-
- |
-
-
-
-
-
- {{$t('subtotal')}}
- |
- {{getSubTotal() | currency('EUR', $i18n.locale)}} |
-
-
-
+
+
+
+ {{$t('deliveryNote')}}
+
+
+
+ Shipped
+
+
+
+ {{ticket.shipped | date}}
+
+
+
+ {{ticket.nickname}}
+
+
+
+
+
+ {{$t('reference')}} |
+ {{$t('quantity')}} |
+ {{$t('concept')}} |
+ {{$t('price')}} |
+ {{$t('discount')}} |
+ {{$t('vat')}} |
+ {{$t('amount')}} |
+
+
+
+
+ {{sale.itemFk | zerofill('000000')}} |
+ {{sale.quantity}} |
+ {{sale.concept}} |
+ {{sale.price | currency('EUR', $i18n.locale)}} |
+ {{(sale.discount / 100) | percentage}} |
+ {{sale.vatType}} |
+ {{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', $i18n.locale)}} |
+
+
+
+
+ {{sale.tag5}} {{sale.value5}}
+
+
+ {{sale.tag6}} {{sale.value6}}
+
+
+ {{sale.tag7}} {{sale.value7}}
+
+ |
+
+
+
+
+
+ {{$t('subtotal')}}
+ |
+ {{subTotal(ticket) | currency('EUR', $i18n.locale)}} |
+
+
+
+
-
-
-
- {{$t('services')}}
-
-
-
- |
- {{$t('quantity')}} |
- {{$t('concept')}} |
- {{$t('price')}} |
- |
- {{$t('vat')}} |
- {{$t('amount')}} |
-
-
-
-
- |
- {{service.quantity}} |
- {{service.description}} |
- {{service.price | currency('EUR', $i18n.locale)}} |
- |
- {{service.taxDescription}} |
- {{service.price | currency('EUR', $i18n.locale)}} |
-
-
-
-
-
- {{$t('subtotal')}}
- |
- {{serviceTotal | currency('EUR', $i18n.locale)}} |
-
-
-
-
-
-
-
-
-
- {{$t('packagings')}}
-
-
-
- {{$t('reference')}} |
- {{$t('quantity')}} |
- {{$t('concept')}} |
-
-
-
-
- {{packaging.itemFk | zerofill('000000')}} |
- {{packaging.quantity}} |
- {{packaging.name}} |
-
-
-
-
-
-
-
@@ -188,32 +176,39 @@
{{tax.name}} |
- {{tax.Base | currency('EUR', $i18n.locale)}}
+ {{tax.base | currency('EUR', $i18n.locale)}}
|
{{tax.vatPercent | percentage}} |
- {{tax.tax | currency('EUR', $i18n.locale)}} |
+ {{tax.vat | currency('EUR', $i18n.locale)}} |
{{$t('subtotal')}} |
- {{getTotalBase() | currency('EUR', $i18n.locale)}}
+ {{sumTotal(taxes, 'base') | currency('EUR', $i18n.locale)}}
|
|
- {{getTotalTax()| currency('EUR', $i18n.locale)}} |
+ {{sumTotal(taxes, 'vat') | currency('EUR', $i18n.locale)}} |
{{$t('total')}} |
- {{getTotal() | currency('EUR', $i18n.locale)}} |
+ {{taxTotal | currency('EUR', $i18n.locale)}} |
+
+
+
+
+ {{invoice.footNotes}}
+
+
-
+
-
-
-
+
+ {{$t('intrastat')}}
+
+
+
+ {{$t('code')}} |
+ {{$t('description')}} |
+ {{$t('stems')}} |
+ {{$t('netKg')}} |
+ {{$t('amount')}} |
+
+
+
+
+ {{row.code}} |
+ {{row.description}} |
+ {{row.stems | number($i18n.locale)}} |
+ {{row.netKg | number($i18n.locale)}} |
+ {{row.subtotal | currency('EUR', $i18n.locale)}} |
+
+
+
+
+ |
+
+ {{sumTotal(intrastat, 'stems') | number($i18n.locale)}}
+ |
+
+ {{sumTotal(intrastat, 'netKg') | number($i18n.locale)}}
+ |
+
+ {{sumTotal(intrastat, 'subtotal') | currency('EUR', $i18n.locale)}}
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+ {{$t('wireTransfer')}}
+ {{$t('accountNumber', [invoice.iban])}}
- -->
-
+
+
+
diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js
index eee4eec96c..72f27a69a5 100755
--- a/print/templates/reports/invoice/invoice.js
+++ b/print/templates/reports/invoice/invoice.js
@@ -1,30 +1,34 @@
-const config = require(`${appPath}/core/config`);
const Component = require(`${appPath}/core/component`);
+const Report = require(`${appPath}/core/report`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
-const md5 = require('md5');
-const fs = require('fs-extra');
+const db = require(`${appPath}/core/database`);
module.exports = {
name: 'invoice',
async serverPrefetch() {
this.invoice = await this.fetchInvoice(this.invoiceId);
this.client = await this.fetchClient(this.invoiceId);
- this.address = {};
- this.sales = [];
- this.services = [];
- this.taxes = [];
- this.packagings = [];
- /* this.client = await this.fetchClient(this.ticketId);
- this.ticket = await this.fetchTicket(this.ticketId);
- this.sales = await this.fetchSales(this.ticketId);
- this.address = await this.fetchAddress(this.ticketId);
- this.services = await this.fetchServices(this.ticketId);
- this.taxes = await this.fetchTaxes(this.ticketId);
- this.packagings = await this.fetchPackagings(this.ticketId);
- this.signature = await this.fetchSignature(this.ticketId);
+ this.taxes = await this.fetchTaxes(this.invoiceId);
+ this.intrastat = await this.fetchIntrastat(this.invoiceId);
+ this.rectified = await this.fetchRectified(this.invoiceId);
+
+ const tickets = await this.fetchTickets(this.invoiceId);
+ const sales = await this.fetchSales(this.invoiceId);
+
+ const map = new Map();
+
+ for (let ticket of tickets)
+ map.set(ticket.id, ticket);
+
+ for (let sale of sales) {
+ const ticket = map.get(sale.ticketFk);
+ if (!ticket.sales) ticket.sales = [];
+ ticket.sales.push(sale);
+ }
+
+ this.tickets = tickets;
- */
if (!this.invoice)
throw new Error('Something went wrong');
},
@@ -32,16 +36,30 @@ module.exports = {
return {totalBalance: 0.00};
},
computed: {
- /* dmsPath() {
- if (!this.signature) return;
+ ticketsId() {
+ const tickets = this.tickets.map(ticket => ticket.id);
- const hash = md5(this.signature.id.toString()).substring(0, 3);
- const file = `${config.storage.root}/${hash}/${this.signature.id}.png`;
- const src = fs.readFileSync(file);
- const base64 = Buffer.from(src, 'utf8').toString('base64');
-
- return `data:image/png;base64, ${base64}`;
+ return tickets.join(', ');
},
+ botanical() {
+ let phytosanitary = [];
+ for (let ticket of this.tickets) {
+ for (let sale of ticket.sales) {
+ if (sale.botanical)
+ phytosanitary.push(sale.botanical);
+ }
+ }
+
+ return phytosanitary.filter((item, index) =>
+ phytosanitary.indexOf(item) == index
+ ).join(', ');
+ },
+ taxTotal() {
+ const base = this.sumTotal(this.taxes, 'base');
+ const vat = this.sumTotal(this.taxes, 'vat');
+ return base + vat;
+ }
+ /*
serviceTotal() {
let total = 0.00;
this.services.forEach(service => {
@@ -55,65 +73,50 @@ module.exports = {
fetchInvoice(invoiceId) {
return this.findOneFromDef('invoice', [invoiceId]);
},
- fetchClient(ticketId) {
- return this.findOneFromDef('client', [ticketId]);
+ fetchClient(invoiceId) {
+ return this.findOneFromDef('client', [invoiceId]);
},
- fetchAddress(ticketId) {
- return this.findOneFromDef(`address`, [ticketId]);
- },
- fetchSignature(ticketId) {
- return this.findOneFromDef('signature', [ticketId]);
- },
- fetchTaxes(ticketId) {
- return this.findOneFromDef(`taxes`, [ticketId]);
- },
- fetchSales(ticketId) {
- return this.rawSqlFromDef('sales', [ticketId]);
- },
- fetchPackagings(ticketId) {
- return this.rawSqlFromDef('packagings', [ticketId]);
- },
- fetchServices(ticketId) {
- return this.rawSqlFromDef('services', [ticketId]);
+ fetchTickets(invoiceId) {
+ return this.rawSqlFromDef('tickets', [invoiceId]);
},
+ async fetchSales(invoiceId) {
+ const connection = await db.pool.getConnection();
+ await this.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.invoiceTickets`, connection);
+ await this.rawSqlFromDef('invoiceTickets', [invoiceId], connection);
- getSubTotal() {
+ const sales = this.rawSqlFromDef('sales', connection);
+
+ await this.rawSql(`DROP TEMPORARY TABLE tmp.invoiceTickets`, connection);
+ await connection.release();
+
+ return sales;
+ },
+ fetchTaxes(invoiceId) {
+ return this.rawSqlFromDef(`taxes`, [invoiceId]);
+ },
+ fetchIntrastat(invoiceId) {
+ return this.rawSqlFromDef(`intrastat`, [invoiceId]);
+ },
+ fetchRectified(invoiceId) {
+ return this.rawSqlFromDef(`rectified`, [invoiceId]);
+ },
+ subTotal(ticket) {
let subTotal = 0.00;
- this.sales.forEach(sale => {
+ ticket.sales.forEach(sale => {
subTotal += sale.quantity * sale.price * (1 - sale.discount / 100);
});
return subTotal;
},
- getTotalBase() {
- let totalBase = 0.00;
- this.taxes.forEach(tax => {
- totalBase += parseFloat(tax.Base);
- });
-
- return totalBase;
- },
- getTotalTax() {
- let totalTax = 0.00;
- this.taxes.forEach(tax => {
- totalTax += parseFloat(tax.tax);
- });
-
- return totalTax;
- },
getTotal() {
return this.getTotalBase() + this.getTotalTax();
},
- getBotanical() {
- let phytosanitary = [];
- this.sales.forEach(sale => {
- if (sale.botanical)
- phytosanitary.push(sale.botanical);
- });
+ sumTotal(rows, prop) {
+ let total = 0.00;
+ for (let row of rows)
+ total += parseFloat(row[prop]);
- return phytosanitary.filter((item, index) =>
- phytosanitary.indexOf(item) == index
- ).join(', ');
+ return total;
}
},
components: {
diff --git a/print/templates/reports/invoice/locale/es.yml b/print/templates/reports/invoice/locale/es.yml
index 9b5694e3c0..6fdfc8a14c 100644
--- a/print/templates/reports/invoice/locale/es.yml
+++ b/print/templates/reports/invoice/locale/es.yml
@@ -4,7 +4,8 @@ clientId: Cliente
invoiceData: Datos de facturación
fiscalId: CIF / NIF
invoiceRef: Factura {0}
-saleLines: Líneas de pedido
+deliveryNote: Albarán
+shipped: F. envío
date: Fecha
reference: Ref.
quantity: Cant.
@@ -20,6 +21,15 @@ fee: Cuota
total: Total
subtotal: Subtotal
taxBreakdown: Desglose impositivo
-packagings: Cubos y embalajes
-services: Servicios
-plantPassport: Pasaporte fitosanitario
\ No newline at end of file
+notes: Notas
+intrastat: Intrastat
+code: Código
+description: Descripción
+stems: Tallos
+netKg: KG Neto
+rectifiedInvoices: Facturas rectificadas
+issued: F. emisión
+plantPassport: Pasaporte fitosanitario
+observations: Observaciones
+wireTransfer: "Forma de pago: Transferencia"
+accountNumber: "Número de cuenta: {0}"
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/address.sql b/print/templates/reports/invoice/sql/address.sql
deleted file mode 100644
index 86414635ae..0000000000
--- a/print/templates/reports/invoice/sql/address.sql
+++ /dev/null
@@ -1,11 +0,0 @@
-SELECT
- a.nickname,
- a.street,
- a.postalCode,
- a.city,
- p.name province
-FROM ticket t
- JOIN address a ON a.clientFk = t.clientFk
- AND a.id = t.addressFk
- LEFT JOIN province p ON p.id = a.provinceFk
-WHERE t.id = ?
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/corrected.sql b/print/templates/reports/invoice/sql/corrected.sql
deleted file mode 100644
index 4ea56f38d6..0000000000
--- a/print/templates/reports/invoice/sql/corrected.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-SELECT io.amount, io.ref, io.issued, ict.description
-FROM vn.invoiceCorrection ic
- JOIN vn.invoiceOut io ON io.id = ic.correctedFk
- JOIN vn.invoiceCorrectionType ict ON ict.id = ic.invoiceCorrectionTypeFk
-where ic.correctingFk = #
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/intrastat.sql b/print/templates/reports/invoice/sql/intrastat.sql
new file mode 100644
index 0000000000..ca2ed3f333
--- /dev/null
+++ b/print/templates/reports/invoice/sql/intrastat.sql
@@ -0,0 +1,88 @@
+SELECT
+ ir.id AS code,
+ ir.description AS description,
+ CAST(SUM(IFNULL(i.stems,1) * s.quantity) AS DECIMAL(10,2)) as stems,
+ CAST(SUM( weight) AS DECIMAL(10,2)) as netKg,
+ CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) AS subtotal
+ FROM vn.sale s
+ LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
+ LEFT JOIN vn.ticket t ON t.id = s.ticketFk
+ LEFT JOIN vn.invoiceOut io ON io.ref = t.refFk
+ LEFT JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.intrastat ir ON ir.id = i.intrastatFk
+ WHERE io.id = ?
+ GROUP BY i.intrastatFk;
+
+
+/* SELECT io.issued,
+ c.socialName,
+ c.street postalAddress,
+ IF (ios.taxAreaFk IS NOT NULL, CONCAT(cty.code, c.fi), c.fi) fi,
+ io.clientFk,
+ c.postcode,
+ c.city,
+ io.companyFk,
+ io.ref,
+ tc.code,
+ s.concept,
+ s.quantity,
+ s.price,
+ s.discount,
+ s.ticketFk,
+ t.shipped,
+ t.refFk,
+ a.nickname,
+ s.itemFk,
+ s.id saleFk,
+ pm.name AS pmname,
+ sa.iban,
+ c.phone,
+ MAX(t.packages) packages,
+ a.incotermsFk,
+ ic.name incotermsName ,
+ sub.description weight,
+ t.observations,
+ ca.fiscalName customsAgentName,
+ ca.street customsAgentStreet,
+ ca.nif customsAgentNif,
+ ca.phone customsAgentPhone,
+ ca.email customsAgentEmail,
+ CAST(sub2.volume AS DECIMAL (10,2)) volume,
+ sub3.intrastat
+ FROM vn.invoiceOut io
+ JOIN vn.supplier su ON su.id = io.companyFk
+ JOIN vn.client c ON c.id = io.clientFk
+ LEFT JOIN vn.province p ON p.id = c.provinceFk
+ JOIN vn.ticket t ON t.refFk = io.ref
+ LEFT JOIN (SELECT tob.ticketFk,tob.description
+ FROM vn.ticketObservation tob
+ LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk
+ WHERE ot.description = "Peso Aduana"
+ )sub ON sub.ticketFk = t.id
+ JOIN vn.address a ON a.id = t.addressFk
+ LEFT JOIN vn.incoterms ic ON ic.code = a.incotermsFk
+ LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk
+ JOIN vn.sale s ON s.ticketFk = t.id
+ JOIN (SELECT SUM(volume) volume
+ FROM vn.invoiceOut io
+ JOIN vn.ticket t ON t.refFk = io.ref
+ JOIN vn.saleVolume sv ON sv.ticketFk = t.id
+ WHERE io.id = :invoiceId
+ )sub2 ON TRUE
+ JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk AND itc.itemFk = s.itemFk
+ JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
+ LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial AND ios.taxAreaFk = 'CEE'
+ JOIN vn.country cty ON cty.id = c.countryFk
+ 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
+ LEFT JOIN (SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '. ' ) as intrastat
+ FROM vn.ticket t
+ JOIN vn.invoiceOut io ON io.ref = t.refFk
+ JOIN vn.sale s ON t.id = s.ticketFk
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.intrastat ir ON ir.id = i.intrastatFk
+ WHERE io.id = :invoiceId
+ )sub3 ON TRUE
+ WHERE io.id = :invoiceId
+ */
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/invoice.sql b/print/templates/reports/invoice/sql/invoice.sql
index 599e34db17..aacbb00163 100644
--- a/print/templates/reports/invoice/sql/invoice.sql
+++ b/print/templates/reports/invoice/sql/invoice.sql
@@ -3,8 +3,14 @@ SELECT
io.clientFk,
io.companyFk,
io.ref,
- cny.code companyCode
-FROM vn.invoiceOut io
- JOIN vn.client c ON c.id = io.clientFk
+ pm.code AS payMethodCode,
+ cny.code companyCode,
+ sa.iban,
+ ios.footNotes
+FROM invoiceOut io
+ JOIN client c ON c.id = io.clientFk
+ JOIN payMethod pm ON pm.id = c.payMethodFk
JOIN company cny ON cny.id = io.companyFk
+ JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk
+ LEFT JOIN invoiceOutSerial ios ON ios.code = io.serial
WHERE io.id = ?
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/invoiceTickets.sql b/print/templates/reports/invoice/sql/invoiceTickets.sql
new file mode 100644
index 0000000000..089911a630
--- /dev/null
+++ b/print/templates/reports/invoice/sql/invoiceTickets.sql
@@ -0,0 +1,20 @@
+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 = ?
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/packagings.sql b/print/templates/reports/invoice/sql/packagings.sql
deleted file mode 100644
index 75a82a0aad..0000000000
--- a/print/templates/reports/invoice/sql/packagings.sql
+++ /dev/null
@@ -1,9 +0,0 @@
-SELECT
- tp.quantity,
- i.name,
- p.itemFk
-FROM ticketPackaging tp
- JOIN packaging p ON p.id = tp.packagingFk
- JOIN item i ON i.id = p.itemFk
-WHERE tp.ticketFk = ?
-ORDER BY itemFk
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/phytosanitary.sql b/print/templates/reports/invoice/sql/phytosanitary.sql
new file mode 100644
index 0000000000..1ae178975a
--- /dev/null
+++ b/print/templates/reports/invoice/sql/phytosanitary.sql
@@ -0,0 +1,14 @@
+SELECT CONCAT( 'A ', GROUP_CONCAT(DISTINCT(ib.ediBotanic) SEPARATOR ', '), CHAR(13,10), CHAR(13,10),
+ 'B ES17462130', CHAR(13,10), CHAR(13,10),
+ 'C ', GROUP_CONCAT(DISTINCT(t.id) SEPARATOR ', '), CHAR(13,10), CHAR(13,10),
+ 'D ES' ) phytosanitary
+ FROM vn.ticket t
+ JOIN vn.sale s ON s.ticketFk = t.id
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.itemType it ON it.id = i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ JOIN vn.itemBotanicalWithGenus ib ON ib.itemfk = i.id
+ WHERE t.refFk = # AND
+ ic.`code` = 'plant' AND
+ ib.ediBotanic IS NOT NULL
+ ORDER BY ib.ediBotanic
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/rectified.sql b/print/templates/reports/invoice/sql/rectified.sql
new file mode 100644
index 0000000000..1255b973c7
--- /dev/null
+++ b/print/templates/reports/invoice/sql/rectified.sql
@@ -0,0 +1,9 @@
+SELECT
+ io.amount,
+ io.ref,
+ io.issued,
+ ict.description
+FROM vn.invoiceCorrection ic
+ JOIN vn.invoiceOut io ON io.id = ic.correctedFk
+ JOIN vn.invoiceCorrectionType ict ON ict.id = ic.invoiceCorrectionTypeFk
+where ic.correctingFk = ?
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/sales.sql b/print/templates/reports/invoice/sql/sales.sql
index d17f6feeeb..0665fc0ff3 100644
--- a/print/templates/reports/invoice/sql/sales.sql
+++ b/print/templates/reports/invoice/sql/sales.sql
@@ -1,42 +1,59 @@
-SELECT
- s.id,
- s.itemFk,
- s.concept,
- s.quantity,
- s.price,
- s.price - SUM(IF(ctr.id = 6, sc.value, 0)) netPrice,
- s.discount,
- i.size,
- i.stems,
- i.category,
- it.id itemTypeId,
- o.code AS origin,
- i.inkFk,
- s.ticketFk,
- tcl.code vatType,
- ib.ediBotanic botanical,
- i.tag5,
- i.value5,
- i.tag6,
- i.value6,
- i.tag7,
- i.value7
-FROM vn.sale s
- LEFT JOIN saleComponent sc ON sc.saleFk = s.id
- LEFT JOIN component cr ON cr.id = sc.componentFk
- LEFT JOIN componentType ctr ON ctr.id = cr.typeFk
- LEFT JOIN item i ON i.id = s.itemFk
- LEFT JOIN ticket t ON t.id = s.ticketFk
- LEFT JOIN origin o ON o.id = i.originFk
- LEFT JOIN country c ON c.id = o.countryFk
- LEFT JOIN supplier sp ON sp.id = t.companyFk
+SELECT
+ it.ref,
+ it.socialName,
+ it.iban,
+ it.payMethod,
+ it.clientFk,
+ it.shipped,
+ it.nickname,
+ s.ticketFk,
+ s.itemFk,
+ s.concept,
+ s.quantity,
+ s.price,
+ s.discount,
+ i.tag5,
+ i.value5,
+ i.tag6,
+ i.value6,
+ i.tag7,
+ i.value7,
+ tc.code AS vatType,
+ ib.ediBotanic botanical
+ FROM tmp.invoiceTickets it
+ JOIN vn.sale s ON s.ticketFk = it.ticketFk
+ JOIN item i ON i.id = s.itemFk
LEFT JOIN itemType it ON it.id = i.typeFk
LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
- LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id
- AND itc.countryFk = sp.countryFk
- LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk
LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id
AND ic.code = 'plant'
-WHERE s.ticketFk = ?
-GROUP BY s.id
-ORDER BY (it.isPackaging), s.concept, s.itemFk
\ No newline at end of file
+ AND ib.ediBotanic IS NOT NULL
+ JOIN vn.itemTaxCountry itc ON itc.countryFk = it.supplierCountryFk
+ AND itc.itemFk = s.itemFk
+ JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
+UNION ALL
+SELECT
+ it.ref,
+ it.socialName,
+ it.iban,
+ it.payMethod,
+ it.clientFk,
+ it.shipped,
+ it.nickname,
+ it.ticketFk,
+ '',
+ ts.description concept,
+ ts.quantity,
+ ts.price,
+ 0 discount,
+ NULL AS tag5,
+ NULL AS value5,
+ NULL AS tag6,
+ NULL AS value6,
+ NULL AS tag7,
+ NULL AS value7,
+ tc.code AS vatType,
+ NULL AS botanical
+ FROM tmp.invoiceTickets it
+ JOIN vn.ticketService ts ON ts.ticketFk = it.ticketFk
+ JOIN vn.taxClass tc ON tc.id = ts.taxClassFk
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/services.sql b/print/templates/reports/invoice/sql/services.sql
deleted file mode 100644
index d64e8dc26d..0000000000
--- a/print/templates/reports/invoice/sql/services.sql
+++ /dev/null
@@ -1,8 +0,0 @@
-SELECT
- tc.code taxDescription,
- ts.description,
- ts.quantity,
- ts.price
-FROM ticketService ts
- JOIN taxClass tc ON tc.id = ts.taxClassFk
-WHERE ts.ticketFk = ?
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/signature.sql b/print/templates/reports/invoice/sql/signature.sql
deleted file mode 100644
index 2eb83b3acd..0000000000
--- a/print/templates/reports/invoice/sql/signature.sql
+++ /dev/null
@@ -1,8 +0,0 @@
-SELECT
- d.id,
- d.created
-FROM ticket t
- JOIN ticketDms dt ON dt.ticketFk = t.id
- JOIN dms d ON d.id = dt.dmsFk
- AND d.file LIKE '%.png'
-WHERE t.id = ?
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/taxes.sql b/print/templates/reports/invoice/sql/taxes.sql
index 576074df70..19b1cc00e3 100644
--- a/print/templates/reports/invoice/sql/taxes.sql
+++ b/print/templates/reports/invoice/sql/taxes.sql
@@ -1,8 +1,11 @@
-SELECT iot.* , pgc.*, IF(pe.equFk IS NULL, taxableBase, 0) AS Base, pgc.rate / 100 as vatPercent, ios.footNotes
- FROM vn.invoiceOutTax iot
- JOIN vn.pgc ON pgc.code = iot.pgcFk
- LEFT JOIN vn.pgcEqu pe ON pe.equFk = pgc.code
- JOIN vn.invoiceOut io ON io.id = iot.invoiceOutFk
- LEFT JOIN vn.invoiceOutSerial ios ON ios.code = io.serial
- WHERE invoiceOutFk = #
+SELECT
+ iot.vat,
+ pgc.name,
+ IF(pe.equFk IS NULL, taxableBase, 0) AS base,
+ pgc.rate / 100 AS vatPercent
+ FROM invoiceOutTax iot
+ JOIN pgc ON pgc.code = iot.pgcFk
+ LEFT JOIN pgcEqu pe ON pe.equFk = pgc.code
+ JOIN invoiceOut io ON io.id = iot.invoiceOutFk
+ WHERE invoiceOutFk = ?
ORDER BY iot.id
\ No newline at end of file
diff --git a/print/templates/reports/invoice/sql/tickets.sql b/print/templates/reports/invoice/sql/tickets.sql
new file mode 100644
index 0000000000..feca81ead6
--- /dev/null
+++ b/print/templates/reports/invoice/sql/tickets.sql
@@ -0,0 +1,7 @@
+SELECT
+ t.id,
+ t.shipped,
+ t.nickname
+FROM invoiceOut io
+ JOIN ticket t ON t.refFk = io.ref
+WHERE io.id = ?
\ No newline at end of file
|