Changes made
This commit is contained in:
parent
20d9a99f6b
commit
bb45d78062
|
@ -36,13 +36,14 @@ module.exports = {
|
|||
* Makes a query from a SQL file
|
||||
* @param {String} queryName - The SQL file name
|
||||
* @param {Object} params - Parameterized values
|
||||
* @param {Object} connection - Optional pool connection
|
||||
*
|
||||
* @return {Object} - Result promise
|
||||
*/
|
||||
rawSqlFromDef(queryName, params) {
|
||||
rawSqlFromDef(queryName, params, connection) {
|
||||
const query = fs.readFileSync(`${queryName}.sql`, 'utf8');
|
||||
|
||||
return this.rawSql(query, params);
|
||||
return this.rawSql(query, params, connection);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,12 +19,13 @@ const dbHelper = {
|
|||
* Makes a query from a SQL file
|
||||
* @param {String} queryName - The SQL file name
|
||||
* @param {Object} params - Parameterized values
|
||||
* @param {Object} connection - Optional pool connection
|
||||
*
|
||||
* @return {Object} - Result promise
|
||||
*/
|
||||
rawSqlFromDef(queryName, params) {
|
||||
rawSqlFromDef(queryName, params, connection) {
|
||||
const absolutePath = path.join(__dirname, '../', this.tplPath, 'sql', queryName);
|
||||
return db.rawSqlFromDef(absolutePath, params);
|
||||
return db.rawSqlFromDef(absolutePath, params, connection);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,11 +6,16 @@ module.exports = app => {
|
|||
const reportName = req.params.name;
|
||||
const fileName = getFileName(reportName, req.args);
|
||||
const report = new Report(reportName, req.args);
|
||||
const stream = await report.toPdfStream();
|
||||
if (req.args.preview) {
|
||||
const template = await report.render();
|
||||
res.send(template);
|
||||
} else {
|
||||
const stream = await report.toPdfStream();
|
||||
|
||||
res.setHeader('Content-type', 'application/pdf');
|
||||
res.setHeader('Content-Disposition', `inline; filename="${fileName}"`);
|
||||
res.end(stream);
|
||||
res.setHeader('Content-type', 'application/pdf');
|
||||
res.setHeader('Content-Disposition', `inline; filename="${fileName}"`);
|
||||
res.end(stream);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ FROM vn.sale s
|
|||
LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk
|
||||
LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id
|
||||
AND ic.code = 'plant'
|
||||
AND ib.ediBotanic IS NOT NULL
|
||||
WHERE s.ticketFk = ?
|
||||
GROUP BY s.id
|
||||
ORDER BY (it.isPackaging), s.concept, s.itemFk
|
|
@ -1,23 +1,16 @@
|
|||
#signature {
|
||||
padding-right: 10px
|
||||
}
|
||||
|
||||
#signature img {
|
||||
-webkit-filter: brightness(0%);
|
||||
filter: brightness(0%);
|
||||
margin-bottom: 10px;
|
||||
max-width: 150px
|
||||
}
|
||||
|
||||
.description strong {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-weight: 100;
|
||||
color: #555
|
||||
}
|
||||
|
||||
.table-title {
|
||||
margin-bottom: 15px
|
||||
}
|
||||
|
||||
.table-title h2 {
|
||||
margin: 0 15px 0 0
|
||||
}
|
||||
|
||||
.ticket-info {
|
||||
font-size: 26px
|
||||
}
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<!-- Header block -->
|
||||
<delivery-note v-bind="$props"></delivery-note>
|
||||
|
||||
|
||||
<!-- Header block -->
|
||||
<report-header v-bind="$props"
|
||||
v-bind:company-code="invoice.companyCode">
|
||||
|
@ -12,7 +17,7 @@
|
|||
<!-- Block -->
|
||||
<div class="grid-row">
|
||||
<div class="grid-block">
|
||||
<div class="columns">
|
||||
<div class="columns vn-mb-lg">
|
||||
<div class="size50">
|
||||
<div class="size75 vn-mt-ml">
|
||||
<h1 class="title uppercase">{{$t('title')}}</h1>
|
||||
|
@ -52,122 +57,105 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Rectified invoices block -->
|
||||
<div class="size100 no-page-break" v-if="rectified.length > 0">
|
||||
<h2>{{$t('rectifiedInvoices')}}</h2>
|
||||
<table class="column-oriented">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{$t('invoice')}}</th>
|
||||
<th>{{$t('issued')}}</th>
|
||||
<th class="number">{{$t('amount')}}</th>
|
||||
<th width="50%">{{$t('description')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in rectified">
|
||||
<td>{{row.ref}}</td>
|
||||
<td>{{row.issued | date}}</td>
|
||||
<td class="number">{{row.amount | currency('EUR', $i18n.locale)}}</td>
|
||||
<td width="50%">{{row.description}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- End of rectified invoices block -->
|
||||
|
||||
<!-- Sales block -->
|
||||
<h2>{{$t('saleLines')}}</h2>
|
||||
<table class="column-oriented">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%">{{$t('reference')}}</th>
|
||||
<th class="number">{{$t('quantity')}}</th>
|
||||
<th width="50%">{{$t('concept')}}</th>
|
||||
<th class="number">{{$t('price')}}</th>
|
||||
<th class="centered" width="5%">{{$t('discount')}}</th>
|
||||
<th class="centered">{{$t('vat')}}</th>
|
||||
<th class="number">{{$t('amount')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-for="sale in sales" class="no-page-break">
|
||||
<tr>
|
||||
<td width="5%">{{sale.itemFk | zerofill('000000')}}</td>
|
||||
<td class="number">{{sale.quantity}}</td>
|
||||
<td width="50%">{{sale.concept}}</td>
|
||||
<td class="number">{{sale.price | currency('EUR', $i18n.locale)}}</td>
|
||||
<td class="centered" width="5%">{{(sale.discount / 100) | percentage}}</td>
|
||||
<td class="centered">{{sale.vatType}}</td>
|
||||
<td class="number">{{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
<tr class="description font light-gray">
|
||||
<td colspan="7">
|
||||
<span v-if="sale.value5">
|
||||
<strong>{{sale.tag5}}</strong> {{sale.value5}}
|
||||
</span>
|
||||
<span v-if="sale.value6">
|
||||
<strong>{{sale.tag6}}</strong> {{sale.value6}}
|
||||
</span>
|
||||
<span v-if="sale.value7">
|
||||
<strong>{{sale.tag7}}</strong> {{sale.value7}}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="6" class="font bold">
|
||||
<span class="pull-right">{{$t('subtotal')}}</span>
|
||||
</td>
|
||||
<td class="number">{{getSubTotal() | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="vn-mt-lg no-page-break" v-for="ticket in tickets">
|
||||
<div class="table-title clearfix">
|
||||
<div class="pull-left">
|
||||
<h2>{{$t('deliveryNote')}}</strong>
|
||||
</div>
|
||||
<div class="pull-left vn-mr-md">
|
||||
<div class="field rectangle">
|
||||
<span>{{ticket.id}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<h2>Shipped</h2>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="field rectangle">
|
||||
<span>{{ticket.shipped | date}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span class="pull-right">
|
||||
<h2 style="max-width: 400px; text-overflow: ellipsis;white-space: nowrap;overflow: hidden;">{{ticket.nickname}}</h2>
|
||||
</span>
|
||||
</div>
|
||||
<table class="column-oriented">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%">{{$t('reference')}}</th>
|
||||
<th class="number">{{$t('quantity')}}</th>
|
||||
<th width="50%">{{$t('concept')}}</th>
|
||||
<th class="number">{{$t('price')}}</th>
|
||||
<th class="centered" width="5%">{{$t('discount')}}</th>
|
||||
<th class="centered">{{$t('vat')}}</th>
|
||||
<th class="number">{{$t('amount')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-for="sale in ticket.sales" class="no-page-break">
|
||||
<tr>
|
||||
<td width="5%">{{sale.itemFk | zerofill('000000')}}</td>
|
||||
<td class="number">{{sale.quantity}}</td>
|
||||
<td width="50%">{{sale.concept}}</td>
|
||||
<td class="number">{{sale.price | currency('EUR', $i18n.locale)}}</td>
|
||||
<td class="centered" width="5%">{{(sale.discount / 100) | percentage}}</td>
|
||||
<td class="centered">{{sale.vatType}}</td>
|
||||
<td class="number">{{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
<tr class="description font light-gray">
|
||||
<td colspan="7">
|
||||
<span v-if="sale.value5">
|
||||
<strong>{{sale.tag5}}</strong> {{sale.value5}}
|
||||
</span>
|
||||
<span v-if="sale.value6">
|
||||
<strong>{{sale.tag6}}</strong> {{sale.value6}}
|
||||
</span>
|
||||
<span v-if="sale.value7">
|
||||
<strong>{{sale.tag7}}</strong> {{sale.value7}}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="6" class="font bold">
|
||||
<span class="pull-right">{{$t('subtotal')}}</span>
|
||||
</td>
|
||||
<td class="number">{{subTotal(ticket) | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<!-- End of sales block -->
|
||||
|
||||
<div class="columns">
|
||||
<!-- Services block-->
|
||||
<div class="size100 no-page-break" v-if="services.length > 0">
|
||||
<h2>{{$t('services')}}</h2>
|
||||
<table class="column-oriented">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5%"></th>
|
||||
<th class="number">{{$t('quantity')}}</th>
|
||||
<th width="50%">{{$t('concept')}}</th>
|
||||
<th class="number">{{$t('price')}}</th>
|
||||
<th class="centered" width="5%"></th>
|
||||
<th class="centered">{{$t('vat')}}</th>
|
||||
<th class="number">{{$t('amount')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="service in services">
|
||||
<td width="5%"></td>
|
||||
<td class="number">{{service.quantity}}</td>
|
||||
<td width="50%">{{service.description}}</td>
|
||||
<td class="number">{{service.price | currency('EUR', $i18n.locale)}}</td>
|
||||
<td class="centered" width="5%"></td>
|
||||
<td class="centered">{{service.taxDescription}}</td>
|
||||
<td class="number">{{service.price | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="6" class="font bold">
|
||||
<span class="pull-right">{{$t('subtotal')}}</span>
|
||||
</td>
|
||||
<td class="number">{{serviceTotal | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<!-- End of services block -->
|
||||
</div>
|
||||
<div class="columns">
|
||||
<!-- Packages block -->
|
||||
<div id="packagings" class="size100 no-page-break" v-if="packagings.length > 0">
|
||||
<h2>{{$t('packagings')}}</h2>
|
||||
<table class="column-oriented">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{$t('reference')}}</th>
|
||||
<th class="number">{{$t('quantity')}}</th>
|
||||
<th wihth="75%">{{$t('concept')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="packaging in packagings">
|
||||
<td>{{packaging.itemFk | zerofill('000000')}}</td>
|
||||
<td class="number">{{packaging.quantity}}</td>
|
||||
<td width="85%">{{packaging.name}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- End of packages block -->
|
||||
</div>
|
||||
<div class="columns vn-mt-xl">
|
||||
<!-- Taxes block -->
|
||||
<div id="taxes" class="size50 pull-right no-page-break" v-if="taxes">
|
||||
<!-- <h2>{{$t('taxBreakdown')}}</h2> -->
|
||||
<table class="column-oriented">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -188,32 +176,39 @@
|
|||
<tr v-for="tax in taxes">
|
||||
<td width="45%">{{tax.name}}</td>
|
||||
<td width="25%" class="number">
|
||||
{{tax.Base | currency('EUR', $i18n.locale)}}
|
||||
{{tax.base | currency('EUR', $i18n.locale)}}
|
||||
</td>
|
||||
<td>{{tax.vatPercent | percentage}}</td>
|
||||
<td class="number">{{tax.tax | currency('EUR', $i18n.locale)}}</td>
|
||||
<td class="number">{{tax.vat | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr class="font bold">
|
||||
<td width="45%">{{$t('subtotal')}}</td>
|
||||
<td width="20%" class="number">
|
||||
{{getTotalBase() | currency('EUR', $i18n.locale)}}
|
||||
{{sumTotal(taxes, 'base') | currency('EUR', $i18n.locale)}}
|
||||
</td>
|
||||
<td></td>
|
||||
<td class="number">{{getTotalTax()| currency('EUR', $i18n.locale)}}</td>
|
||||
<td class="number">{{sumTotal(taxes, 'vat') | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
<tr class="font bold">
|
||||
<td colspan="2">{{$t('total')}}</td>
|
||||
<td colspan="2" class="number">{{getTotal() | currency('EUR', $i18n.locale)}}</td>
|
||||
<td colspan="2" class="number">{{taxTotal | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
||||
<div class="panel" v-if="invoice.footNotes">
|
||||
<div class="header">{{$t('notes')}}</div>
|
||||
<div class="body">
|
||||
<span>{{invoice.footNotes}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- End of taxes block -->
|
||||
|
||||
<!-- Phytosanitary block -->
|
||||
<!-- <div id="phytosanitary" class="size50 pull-left no-page-break">
|
||||
<div id="phytosanitary" class="size50 pull-left no-page-break">
|
||||
<div class="panel">
|
||||
<div class="body">
|
||||
<div class="flag">
|
||||
|
@ -229,7 +224,7 @@
|
|||
<div class="phytosanitary-info">
|
||||
<div>
|
||||
<strong>A</strong>
|
||||
<span>{{getBotanical()}}</span>
|
||||
<span>{{botanical}}</span>
|
||||
</div>
|
||||
<div>
|
||||
<strong>B</strong>
|
||||
|
@ -237,7 +232,7 @@
|
|||
</div>
|
||||
<div>
|
||||
<strong>C</strong>
|
||||
<span>{{ticket.id}}</span>
|
||||
<span>{{ticketsId}}</span>
|
||||
</div>
|
||||
<div>
|
||||
<strong>D</strong>
|
||||
|
@ -246,22 +241,65 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
<!-- End of phytosanitary block -->
|
||||
</div>
|
||||
<div class="columns">
|
||||
<!-- Signature block -->
|
||||
<!-- <div class="size50 pull-left no-page-break">
|
||||
<div id="signature" class="panel" v-if="signature && signature.id">
|
||||
<div class="header">{{$t('digitalSignature')}}</div>
|
||||
<div class="body centered">
|
||||
<img v-bind:src="dmsPath"/>
|
||||
<div>{{signature.created | date('%d-%m-%Y')}}</div>
|
||||
|
||||
|
||||
<!-- Intrastat block -->
|
||||
<div class="size100 no-page-break" v-if="intrastat.length > 0">
|
||||
<h2>{{$t('intrastat')}}</h2>
|
||||
<table class="column-oriented">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{$t('code')}}</th>
|
||||
<th width="50%">{{$t('description')}}</th>
|
||||
<th class="number">{{$t('stems')}}</th>
|
||||
<th class="number">{{$t('netKg')}}</th>
|
||||
<th class="number">{{$t('amount')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in intrastat">
|
||||
<td>{{row.code}}</td>
|
||||
<td width="50%">{{row.description}}</td>
|
||||
<td class="number">{{row.stems | number($i18n.locale)}}</td>
|
||||
<td class="number">{{row.netKg | number($i18n.locale)}}</td>
|
||||
<td class="number">{{row.subtotal | currency('EUR', $i18n.locale)}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2"></td>
|
||||
<td class="number">
|
||||
<strong>{{sumTotal(intrastat, 'stems') | number($i18n.locale)}}</strong>
|
||||
</td>
|
||||
<td class="number">
|
||||
<strong>{{sumTotal(intrastat, 'netKg') | number($i18n.locale)}}</strong>
|
||||
</td>
|
||||
<td class="number">
|
||||
<strong>{{sumTotal(intrastat, 'subtotal') | currency('EUR', $i18n.locale)}}</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<!-- End of intrastat block -->
|
||||
|
||||
<!-- Observations block -->
|
||||
<div class="columns vn-mt-xl" v-if="invoice.payMethodCode == 'wireTransfer'">
|
||||
<div class="size50 pull-left no-page-break" >
|
||||
<div class="panel" >
|
||||
<div class="header">{{$t('observations')}}</div>
|
||||
<div class="body">
|
||||
<div>{{$t('wireTransfer')}}</div>
|
||||
<div>{{$t('accountNumber', [invoice.iban])}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- End of signature block -->
|
||||
</div>
|
||||
</div>
|
||||
<!-- End of observations block -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- Footer block -->
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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
|
||||
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}"
|
|
@ -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 = ?
|
|
@ -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 = #
|
|
@ -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
|
||||
*/
|
|
@ -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 = ?
|
|
@ -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 = ?
|
|
@ -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
|
|
@ -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
|
|
@ -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 = ?
|
|
@ -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
|
||||
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
|
|
@ -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 = ?
|
|
@ -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 = ?
|
|
@ -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
|
|
@ -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 = ?
|
Loading…
Reference in New Issue