4221-intrastat #1022
|
@ -61,7 +61,8 @@ module.exports = Self => {
|
||||||
responseType: 'stream',
|
responseType: 'stream',
|
||||||
params: {
|
params: {
|
||||||
authorization: auth.id,
|
authorization: auth.id,
|
||||||
invoiceId: id
|
invoiceId: id,
|
||||||
|
refFk: invoiceOut.ref
|
||||||
}
|
}
|
||||||
}).then(async response => {
|
}).then(async response => {
|
||||||
const issued = invoiceOut.issued;
|
const issued = invoiceOut.issued;
|
||||||
|
|
|
@ -10,7 +10,7 @@ module.exports = {
|
||||||
this.invoice = await this.fetchInvoice(this.invoiceId);
|
this.invoice = await this.fetchInvoice(this.invoiceId);
|
||||||
this.client = await this.fetchClient(this.invoiceId);
|
this.client = await this.fetchClient(this.invoiceId);
|
||||||
this.taxes = await this.fetchTaxes(this.invoiceId);
|
this.taxes = await this.fetchTaxes(this.invoiceId);
|
||||||
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.invoiceId);
|
||||||
this.hasIncoterms = await this.fetchHasIncoterms(this.invoiceId);
|
this.hasIncoterms = await this.fetchHasIncoterms(this.invoiceId);
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ module.exports = {
|
||||||
fetchTaxes(invoiceId) {
|
fetchTaxes(invoiceId) {
|
||||||
return this.rawSqlFromDef(`taxes`, [invoiceId]);
|
return this.rawSqlFromDef(`taxes`, [invoiceId]);
|
||||||
},
|
},
|
||||||
fetchIntrastat(invoiceId) {
|
fetchIntrastat(refFk) {
|
||||||
return this.rawSqlFromDef(`intrastat`, [invoiceId]);
|
return this.rawSqlFromDef(`intrastat`, [refFk, refFk, refFk]);
|
||||||
},
|
},
|
||||||
fetchRectified(invoiceId) {
|
fetchRectified(invoiceId) {
|
||||||
return this.rawSqlFromDef(`rectified`, [invoiceId]);
|
return this.rawSqlFromDef(`rectified`, [invoiceId]);
|
||||||
|
@ -118,6 +118,9 @@ module.exports = {
|
||||||
invoiceId: {
|
invoiceId: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
refFk: {
|
||||||
|
type: String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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
|
|
||||||
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
|
JOIN vn.intrastat ir ON ir.id = i.intrastatFk
|
||||||
WHERE io.id = ?
|
LEFT JOIN (
|
||||||
GROUP BY i.intrastatFk;
|
SELECT t2.weight
|
||||||
|
FROM vn.ticket t2
|
||||||
|
WHERE refFk = ? AND weight
|
||||||
|
LIMIT 1
|
||||||
|
) sub ON TRUE
|
||||||
|
WHERE t.refFk = ?
|
||||||
|
AND i.intrastatFk
|
||||||
|
GROUP BY i.intrastatFk
|
||||||
|
ORDER BY i.intrastatFk;
|
Loading…
Reference in New Issue