fix: refs #195937 refactor incoterms
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Robert Ferrús 2024-06-20 13:45:38 +02:00
parent 46792ba30e
commit 852785b4c1
2 changed files with 38 additions and 53 deletions

View File

@ -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`);
}, },

View File

@ -1,52 +1,37 @@
SELECT calc.packages, WITH tickets AS(
a.incotermsFk, SELECT id, packages, addressFk, weight
ic.name incotermsName, FROM ticket
calc.weight, WHERE refFk='E12400228'
ca.fiscalName customsAgentName, ) , weight AS(
ca.street customsAgentStreet, SELECT weight
ca.nif customsAgentNif, FROM tickets
ca.phone customsAgentPhone, WHERE weight
ca.email customsAgentEmail, LIMIT 1
CAST(vol.volume AS DECIMAL (10,2)) volume, ), volume AS(
intr.intrastat SELECT SUM(volume) volume
FROM vn.invoiceOut io FROM tickets t
JOIN vn.supplier su ON su.id = io.companyFk JOIN vn.saleVolume sv ON sv.ticketFk = t.id
JOIN vn.client c ON c.id = io.clientFk ), intrastat AS(
LEFT JOIN vn.province p ON p.id = c.provinceFk SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '. ' ) intrastat
JOIN vn.ticket t ON t.refFk = io.ref FROM tickets t
JOIN vn.address a ON a.id = t.addressFk JOIN vn.sale s ON t.id = s.ticketFk
JOIN vn.incoterms ic ON ic.code = a.incotermsFk JOIN vn.item i ON i.id = s.itemFk
LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk JOIN vn.intrastat ir ON ir.id = i.intrastatFk
JOIN vn.sale s ON s.ticketFk = t.id )SELECT SUM(t.packages),
JOIN ( a.incotermsFk,
SELECT SUM(volume) volume, COUNT(*) packages ic.name incotermsName,
FROM vn.invoiceOut io w.weight,
JOIN vn.ticket t ON t.refFk = io.ref ca.fiscalName customsAgentName,
JOIN vn.saleVolume sv ON sv.ticketFk = t.id ca.street customsAgentStreet,
WHERE t.refFk = ? ca.nif customsAgentNif,
) vol ca.phone customsAgentPhone,
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk ca.email customsAgentEmail,
AND itc.itemFk = s.itemFk CAST(v.volume AS DECIMAL (10,2)) volume,
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk i.intrastat
JOIN vn.invoiceOutSerial ios ON ios.code = io.serial FROM tickets t
AND ios.taxAreaFk = 'WORLD' JOIN vn.address a ON a.id = t.addressFk
JOIN vn.country cty ON cty.id = c.countryFk JOIN vn.incoterms ic ON ic.code = a.incotermsFk
JOIN vn.payMethod pm ON pm.id = c .payMethodFk LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk
JOIN vn.company co ON co.id=io.companyFk JOIN volume v
JOIN vn.supplierAccount sa ON sa.id=co.supplierAccountFk JOIN intrastat i
JOIN ( LEFT JOIN weight w ON TRUE
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