This commit is contained in:
parent
46792ba30e
commit
852785b4c1
|
@ -9,7 +9,7 @@ module.exports = {
|
||||||
this.checkMainEntity(this.invoice);
|
this.checkMainEntity(this.invoice);
|
||||||
this.client = await this.findOneFromDef('client', [this.reference]);
|
this.client = await this.findOneFromDef('client', [this.reference]);
|
||||||
this.incoterms =
|
this.incoterms =
|
||||||
await this.findOneFromDef('incoterms', [this.reference, this.reference, this.reference, this.reference]);
|
await this.findOneFromDef('incoterms', [this.reference]);
|
||||||
if (!this.incoterms)
|
if (!this.incoterms)
|
||||||
throw new UserError(`The address of the customer must have information about Incoterms and Customs Agent`);
|
throw new UserError(`The address of the customer must have information about Incoterms and Customs Agent`);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,52 +1,37 @@
|
||||||
SELECT calc.packages,
|
WITH tickets AS(
|
||||||
|
SELECT id, packages, addressFk, weight
|
||||||
|
FROM ticket
|
||||||
|
WHERE refFk='E12400228'
|
||||||
|
) , weight AS(
|
||||||
|
SELECT weight
|
||||||
|
FROM tickets
|
||||||
|
WHERE weight
|
||||||
|
LIMIT 1
|
||||||
|
), volume AS(
|
||||||
|
SELECT SUM(volume) volume
|
||||||
|
FROM tickets t
|
||||||
|
JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
||||||
|
), intrastat AS(
|
||||||
|
SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '. ' ) intrastat
|
||||||
|
FROM tickets t
|
||||||
|
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
|
||||||
|
)SELECT SUM(t.packages),
|
||||||
a.incotermsFk,
|
a.incotermsFk,
|
||||||
ic.name incotermsName,
|
ic.name incotermsName,
|
||||||
calc.weight,
|
w.weight,
|
||||||
ca.fiscalName customsAgentName,
|
ca.fiscalName customsAgentName,
|
||||||
ca.street customsAgentStreet,
|
ca.street customsAgentStreet,
|
||||||
ca.nif customsAgentNif,
|
ca.nif customsAgentNif,
|
||||||
ca.phone customsAgentPhone,
|
ca.phone customsAgentPhone,
|
||||||
ca.email customsAgentEmail,
|
ca.email customsAgentEmail,
|
||||||
CAST(vol.volume AS DECIMAL (10,2)) volume,
|
CAST(v.volume AS DECIMAL (10,2)) volume,
|
||||||
intr.intrastat
|
i.intrastat
|
||||||
FROM vn.invoiceOut io
|
FROM tickets t
|
||||||
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
|
|
||||||
JOIN vn.address a ON a.id = t.addressFk
|
JOIN vn.address a ON a.id = t.addressFk
|
||||||
JOIN vn.incoterms ic ON ic.code = a.incotermsFk
|
JOIN vn.incoterms ic ON ic.code = a.incotermsFk
|
||||||
LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk
|
LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk
|
||||||
JOIN vn.sale s ON s.ticketFk = t.id
|
JOIN volume v
|
||||||
JOIN (
|
JOIN intrastat i
|
||||||
SELECT SUM(volume) volume, COUNT(*) packages
|
LEFT JOIN weight w ON TRUE
|
||||||
FROM vn.invoiceOut io
|
|
||||||
JOIN vn.ticket t ON t.refFk = io.ref
|
|
||||||
JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
|
||||||
WHERE t.refFk = ?
|
|
||||||
) vol
|
|
||||||
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.invoiceOutSerial ios ON ios.code = io.serial
|
|
||||||
AND ios.taxAreaFk = 'WORLD'
|
|
||||||
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
|
|
||||||
JOIN (
|
|
||||||
SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '. ' ) 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 t.refFk = ?
|
|
||||||
) intr
|
|
||||||
JOIN (
|
|
||||||
SELECT SUM(packages) packages, SUM(weight) weight
|
|
||||||
FROM ticket
|
|
||||||
WHERE refFk = ?
|
|
||||||
) calc
|
|
||||||
WHERE t.refFk = ?
|
|
||||||
LIMIT 1
|
|
||||||
|
|
Loading…
Reference in New Issue