feat(Ticket): refs #7984 add currency
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2025-01-22 15:05:45 +01:00
parent 55c8e191f9
commit 630836cd8e
4 changed files with 31 additions and 34 deletions

View File

@ -54,38 +54,31 @@ BEGIN
WHERE tp.id IS NULL WHERE tp.id IS NULL
HAVING resto <> 0) t; HAVING resto <> 0) t;
IF vCode <> 'renewPrices' THEN IF vCode = 'renewPrices' THEN
REPLACE INTO saleComponent(saleFk, componentFk, value) SET vComponentFk = 21;
SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.saleFk <> vComponentFk
GROUP BY s.id
HAVING dif <> 0;
ELSE
UPDATE sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN item i on i.id = s.itemFk
JOIN itemType it on it.id = i.typeFk
JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.price = sumValue / ((100 - s.discount) / 100),
s.foreignPrice = currency_getRate(t.currencyFk, NULL) * (sumValue / ((100 - s.discount) / 100))
WHERE it.code <> 'PRT' ;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.componentFk <> 21
GROUP BY s.id
HAVING ROUND(saleValue, 4) <> 0;
END IF; END IF;
UPDATE sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN item i on i.id = s.itemFk
JOIN itemType it on it.id = i.typeFk
JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.price = IF(vCode <> 'renewPrices', sumValue / ((100 - s.discount) / 100), s.price),
s.foreignPrice = currency_getRate(t.currencyFk, NULL) * (sumValue / ((100 - s.discount) / 100))
WHERE it.code <> 'PRT' ;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.saleFk <> vComponentFk
GROUP BY s.id
HAVING dif <> 0;
UPDATE sale s UPDATE sale s
JOIN ( JOIN (
SELECT SUM(sc.value) sumValue, sc.saleFk SELECT SUM(sc.value) sumValue, sc.saleFk

View File

@ -26,6 +26,7 @@ BEGIN
i.category, i.category,
IFNULL(s.quantity, 0) quantity, IFNULL(s.quantity, 0) quantity,
IFNULL(s.price, 0) price, IFNULL(s.price, 0) price,
IFNULL(s.foreignPrice, 0) foreignPrice,
ROUND(SUM(tc.cost), 2) newPrice, ROUND(SUM(tc.cost), 2) newPrice,
s.id saleFk s.id saleFk
FROM vn.sale s FROM vn.sale s
@ -42,10 +43,9 @@ BEGIN
GROUP BY s.id ORDER BY s.id GROUP BY s.id ORDER BY s.id
) SELECT ) SELECT
*, *,
currency_getRate(vCurrencyFk, NULL) * price foreignPrice,
currency_getRate(vCurrencyFk, NULL) * newPrice newForeignPrice, currency_getRate(vCurrencyFk, NULL) * newPrice newForeignPrice,
quantity * (price - newPrice) difference, quantity * (price - newPrice) difference,
currency_getRate(vCurrencyFk, NULL) * quantity * (price - newPrice) foreignDifference quantity * (foreignPrice - currency_getRate(vCurrencyFk, NULL) * newPrice) foreignDifference
FROM ticketPriceDifference; FROM ticketPriceDifference;
DROP TEMPORARY TABLE tmp.ticketComponentPreview; DROP TEMPORARY TABLE tmp.ticketComponentPreview;

View File

@ -240,6 +240,7 @@ module.exports = Self => {
t.clientFk, t.clientFk,
t.totalWithoutVat, t.totalWithoutVat,
t.totalWithVat, t.totalWithVat,
t.foreignTotalWithVat,
io.id invoiceOutId, io.id invoiceOutId,
a.provinceFk, a.provinceFk,
p.name province, p.name province,
@ -266,7 +267,8 @@ module.exports = Self => {
JOIN item i2 ON i2.id = s2.itemFk JOIN item i2 ON i2.id = s2.itemFk
WHERE s2.ticketFk = t.id WHERE s2.ticketFk = t.id
) AS packing, ) AS packing,
c.credit c.credit,
cu.code currencyCode
FROM ticket t FROM ticket t
LEFT JOIN invoiceOut io ON t.refFk = io.ref LEFT JOIN invoiceOut io ON t.refFk = io.ref
LEFT JOIN zone z ON z.id = t.zoneFk LEFT JOIN zone z ON z.id = t.zoneFk
@ -280,6 +282,7 @@ module.exports = Self => {
LEFT JOIN worker wk ON wk.id = c.salesPersonFk LEFT JOIN worker wk ON wk.id = c.salesPersonFk
LEFT JOIN account.user u ON u.id = wk.id LEFT JOIN account.user u ON u.id = wk.id
LEFT JOIN route r ON r.id = t.routeFk LEFT JOIN route r ON r.id = t.routeFk
JOIN currency cu ON cu.id = t.currencyFk
`); `);
if (args.orderFk) { if (args.orderFk) {

View File

@ -103,7 +103,8 @@ module.exports = Self => {
scope: { scope: {
fields: ['id'] fields: ['id']
} }
} },
{relation: 'currency'}
], ],
where: {id: ticketFk} where: {id: ticketFk}
}; };