feat: refs #7984 add currency in ticket basic-data
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2025-01-20 14:06:08 +01:00
parent 4e1ab2652c
commit f4286ec6b3
9 changed files with 81 additions and 57 deletions

View File

@ -13,9 +13,9 @@ BEGIN
CREATE TEMPORARY TABLE tmp.orderTotal CREATE TEMPORARY TABLE tmp.orderTotal
(INDEX (orderFk)) (INDEX (orderFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT o.orderFk, SELECT o.orderFk,
IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) total, IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) total,
IFNULL(SUM(ot.taxableBase + ot.tax) * ot.currencyFk, 0.0) foreignTotal IFNULL(SUM(ot.foreignTaxableBase + ot.foreignTax), 0.0) foreignTotal
FROM tmp.`order` o FROM tmp.`order` o
LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk
GROUP BY orderFk; GROUP BY orderFk;

View File

@ -38,7 +38,7 @@ BEGIN
DECLARE vPrice DECIMAL(10,2); DECLARE vPrice DECIMAL(10,2);
DECLARE vBonus DECIMAL(10,2); DECLARE vBonus DECIMAL(10,2);
CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk, NULL);
IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN
UPDATE ticket t UPDATE ticket t

View File

@ -4,7 +4,9 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_componentPrevi
vLanded DATE, vLanded DATE,
vAddressFk INT, vAddressFk INT,
vZoneFk INT, vZoneFk INT,
vWarehouseFk SMALLINT) vWarehouseFk SMALLINT,
vCurrencyFk SMALLINT
)
BEGIN BEGIN
/** /**
* Calcula los componentes de los articulos de un ticket * Calcula los componentes de los articulos de un ticket
@ -21,7 +23,6 @@ BEGIN
DECLARE vHasAddressChanged BOOL; DECLARE vHasAddressChanged BOOL;
DECLARE vHasZoneChanged BOOL DEFAULT FALSE; DECLARE vHasZoneChanged BOOL DEFAULT FALSE;
DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE;
DECLARE vCurrencyFk INT;
DECLARE vShipped DATE; DECLARE vShipped DATE;
DECLARE vAddressTypeRateFk INT DEFAULT NULL; DECLARE vAddressTypeRateFk INT DEFAULT NULL;
DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL; DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL;
@ -32,7 +33,7 @@ BEGIN
addressFk <> vAddressFk, addressFk <> vAddressFk,
zoneFk <> vZoneFk, zoneFk <> vZoneFk,
warehouseFk <> vWarehouseFk, warehouseFk <> vWarehouseFk,
currencyFk IFNULL(vCurrencyFk, currencyFk)
INTO INTO
vHasDataChanged, vHasDataChanged,
vHasAddressChanged, vHasAddressChanged,

View File

@ -4,7 +4,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_priceDifferenc
vLanded DATE, vLanded DATE,
vAddressFk INT, vAddressFk INT,
vZoneFk INT, vZoneFk INT,
vWarehouseFk INT vWarehouseFk INT,
vCurrencyFk SMALLINT
) )
BEGIN BEGIN
/** /**
@ -16,29 +17,36 @@ BEGIN
* @param vZoneFk Id de la zona * @param vZoneFk Id de la zona
* @param vWarehouseFk Id del almacén * @param vWarehouseFk Id del almacén
*/ */
CALL vn.ticket_componentPreview(vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); CALL vn.ticket_componentPreview(vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk, vCurrencyFk);
SELECT s.itemFk, WITH ticketPriceDifference AS (
i.name, SELECT s.itemFk,
i.size, i.name,
i.category, i.size,
IFNULL(s.quantity, 0) quantity, i.category,
IFNULL(s.price, 0) price, IFNULL(s.quantity, 0) quantity,
ROUND(SUM(tc.cost), 2) newPrice, IFNULL(s.price, 0) price,
s.quantity * (s.price - ROUND(SUM(tc.cost), 2)) difference, ROUND(SUM(tc.cost), 2) newPrice,
s.id saleFk s.id saleFk
FROM sale s FROM vn.sale s
JOIN item i ON i.id = s.itemFk JOIN vn.item i ON i.id = s.itemFk
JOIN ticket t ON t.id = s.ticketFk JOIN vn.ticket t ON t.id = s.ticketFk
LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk
AND tc.warehouseFk = vWarehouseFk AND tc.warehouseFk = vWarehouseFk
LEFT JOIN saleComponent sc ON sc.saleFk = s.id LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk = tc.componentFk AND sc.componentFk = tc.componentFk
LEFT JOIN `component` c ON c.id = tc.componentFk LEFT JOIN vn.`component` c ON c.id = tc.componentFk
WHERE t.id = vTicketFk WHERE t.id = vTicketFk
AND IF(sc.componentFk IS NULL AND IF(sc.componentFk IS NULL
AND c.classRate IS NOT NULL, FALSE, TRUE) AND c.classRate IS NOT NULL, FALSE, TRUE)
GROUP BY s.id ORDER BY s.id; GROUP BY s.id ORDER BY s.id
) SELECT
*,
currency_getRate(vCurrencyFk, NULL) * price foreignPrice,
currency_getRate(vCurrencyFk, NULL) * newPrice newForeignPrice,
quantity * (price - newPrice) difference,
currency_getRate(vCurrencyFk, NULL) * quantity * (price - newPrice) foreignDifference
FROM ticketPriceDifference;
DROP TEMPORARY TABLE tmp.ticketComponentPreview; DROP TEMPORARY TABLE tmp.ticketComponentPreview;
END$$ END$$

View File

@ -211,7 +211,7 @@
"Name should be uppercase": "Name should be uppercase", "Name should be uppercase": "Name should be uppercase",
"You cannot update these fields": "You cannot update these fields", "You cannot update these fields": "You cannot update these fields",
"CountryFK cannot be empty": "Country cannot be empty", "CountryFK cannot be empty": "Country cannot be empty",
"No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements", "No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements",
"You are not allowed to modify the alias": "You are not allowed to modify the alias", "You are not allowed to modify the alias": "You are not allowed to modify the alias",
"You already have the mailAlias": "You already have the mailAlias", "You already have the mailAlias": "You already have the mailAlias",
"This machine is already in use.": "This machine is already in use.", "This machine is already in use.": "This machine is already in use.",
@ -250,6 +250,5 @@
"Sales already moved": "Sales already moved", "Sales already moved": "Sales already moved",
"Holidays to past days not available": "Holidays to past days not available", "Holidays to past days not available": "Holidays to past days not available",
"Price cannot be blank": "Price cannot be blank", "Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "There are tickets to be invoiced", "There are tickets to be invoiced": "There are tickets to be invoiced"
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent"
} }

View File

@ -398,5 +398,5 @@
"Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles",
"All tickets have a route order": "Todos los tickets tienen orden de ruta", "All tickets have a route order": "Todos los tickets tienen orden de ruta",
"Price cannot be blank": "Price cannot be blank", "Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "La zona tiene tickets por facturar" "There are tickets to be invoiced": "La zona tiene tickets por facturar"
} }

View File

@ -31,15 +31,22 @@ module.exports = Self => {
} }
try { try {
const ticket = await Self.app.models.Ticket.findOne({ const {landed, addressFk, agencyModeFk, companyFk, currencyFk} =
where: {id: ticketFk} await Self.app.models.Ticket.findById(
}, myOptions); ticketFk,
{fields: ['landed', 'addressFk', 'agencyModeFk', 'companyFk', 'currencyFk']},
myOptions
);
const landed = ticket.landed; const orderID = await Self.app.models.Order.new(
const addressFk = ticket.addressFk; ctx,
const agencyModeFk = ticket.agencyModeFk; landed,
addressFk,
const orderID = await Self.app.models.Order.new(ctx, landed, addressFk, agencyModeFk, myOptions); agencyModeFk,
companyFk,
currencyFk,
myOptions
);
if (tx) await tx.commit(); if (tx) await tx.commit();

View File

@ -205,6 +205,7 @@ module.exports = Self => {
const originalTicket = JSON.parse(JSON.stringify(ticketToChange)); const originalTicket = JSON.parse(JSON.stringify(ticketToChange));
const ticketChanges = { const ticketChanges = {
clientFk: args.clientFk, clientFk: args.clientFk,
currencyFk: args.currencyFk,
nickname: args.nickname, nickname: args.nickname,
agencyModeFk: args.agencyModeFk, agencyModeFk: args.agencyModeFk,
addressFk: args.addressFk, addressFk: args.addressFk,
@ -214,7 +215,6 @@ module.exports = Self => {
shipped: args.shipped, shipped: args.shipped,
landed: args.landed, landed: args.landed,
isDeleted: args.isDeleted, isDeleted: args.isDeleted,
currencyFk: args.currencyFk
}; };
let response; let response;

View File

@ -46,6 +46,11 @@ module.exports = Self => {
type: 'date', type: 'date',
description: 'shipped', description: 'shipped',
required: true required: true
},
{
arg: 'currencyId',
type: 'number',
description: 'The currency ticket'
}], }],
returns: { returns: {
type: ['object'], type: ['object'],
@ -91,7 +96,7 @@ module.exports = Self => {
} }
} }
const items = await models.Sale.find({ const sales = await models.Sale.find({
where: { where: {
ticketFk: args.id ticketFk: args.id
}, },
@ -99,19 +104,22 @@ module.exports = Self => {
include: 'item' include: 'item'
}, myOptions); }, myOptions);
const salesObj = { const salesTotals = {
items: items, sales,
totalUnitPrice: 0.00, totalUnitPrice: 0.00,
totalNewPrice: 0.00, totalNewPrice: 0.00,
totalDifference: 0.00, totalDifference: 0.00,
totalForeignUnitPrice: 0.00,
totalForeignNewPrice: 0.00,
totalForeignDifference: 0.00,
}; };
// Get items movable // Get items movable
const ticketOrigin = await models.Ticket.findById(args.id, null, myOptions); const ticketOrigin = await models.Ticket.findById(args.id, null, myOptions);
const differenceShipped = ticketOrigin.shipped.getTime() > args.shipped.getTime(); const differenceShipped = !ticketOrigin.shipped || ticketOrigin.shipped?.getTime() > args.shipped.getTime();
const differenceWarehouse = ticketOrigin.warehouseFk != args.warehouseId; const differenceWarehouse = ticketOrigin.warehouseFk != args.warehouseId;
salesObj.haveDifferences = differenceShipped || differenceWarehouse; salesTotals.haveDifferences = differenceShipped || differenceWarehouse;
let query = `CALL ticket_getMovable(?,?,?)`; let query = `CALL ticket_getMovable(?,?,?)`;
let params = [args.id, args.shipped, args.warehouseId]; let params = [args.id, args.shipped, args.warehouseId];
@ -124,34 +132,35 @@ module.exports = Self => {
} }
// Sale price component, one per sale // Sale price component, one per sale
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`; query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?, ?)`;
params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId]; params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId, args.currencyId];
const [difComponents] = await Self.rawSql(query, params, myOptions); const [difComponents] = await Self.rawSql(query, params, myOptions);
const map = new Map(); const map = new Map();
for (let difComponent of difComponents) for (let difComponent of difComponents)
map.set(difComponent.saleFk, difComponent); map.set(difComponent.saleFk, difComponent);
for (sale of salesObj.items) { for (let sale of salesTotals.sales) {
const difComponent = map.get(sale.id); const difComponent = map.get(sale.id);
if (difComponent) { if (difComponent) {
sale.component = difComponent; sale.component = difComponent;
salesObj.totalDifference += difComponent.difference; salesTotals.totalNewPrice += round(difComponent.newPrice * difComponent.quantity);
salesObj.totalDifference = round(salesObj.totalDifference); salesTotals.totalForeignNewPrice += round(difComponent.newForeignPrice * difComponent.quantity);
salesObj.totalNewPrice += difComponent.newPrice; salesTotals.totalUnitPrice += round(sale.price * difComponent.quantity);
salesObj.totalNewPrice = round(salesObj.totalNewPrice); salesTotals.totalForeignUnitPrice += round(difComponent.foreignPrice * difComponent.quantity);
salesTotals.totalDifference += round(difComponent.difference);
salesTotals.totalForeignDifference += round(difComponent.foreignDifference);
} }
salesObj.totalUnitPrice += sale.price;
salesObj.totalUnitPrice = round(salesObj.totalUnitPrice);
sale.movable = itemMovable.get(sale.id); sale.movable = itemMovable.get(sale.id);
} }
if (tx) await tx.commit(); if (tx) await tx.commit();
return salesObj; return salesTotals;
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;