feat: refs #7984 add currency in ticket basic-data
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
4e1ab2652c
commit
f4286ec6b3
|
@ -13,9 +13,9 @@ BEGIN
|
|||
CREATE TEMPORARY TABLE tmp.orderTotal
|
||||
(INDEX (orderFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT o.orderFk,
|
||||
SELECT o.orderFk,
|
||||
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
|
||||
LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk
|
||||
GROUP BY orderFk;
|
||||
|
|
|
@ -38,7 +38,7 @@ BEGIN
|
|||
DECLARE vPrice 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
|
||||
UPDATE ticket t
|
||||
|
|
|
@ -4,7 +4,9 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_componentPrevi
|
|||
vLanded DATE,
|
||||
vAddressFk INT,
|
||||
vZoneFk INT,
|
||||
vWarehouseFk SMALLINT)
|
||||
vWarehouseFk SMALLINT,
|
||||
vCurrencyFk SMALLINT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula los componentes de los articulos de un ticket
|
||||
|
@ -21,7 +23,6 @@ BEGIN
|
|||
DECLARE vHasAddressChanged BOOL;
|
||||
DECLARE vHasZoneChanged BOOL DEFAULT FALSE;
|
||||
DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE;
|
||||
DECLARE vCurrencyFk INT;
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vAddressTypeRateFk INT DEFAULT NULL;
|
||||
DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL;
|
||||
|
@ -32,7 +33,7 @@ BEGIN
|
|||
addressFk <> vAddressFk,
|
||||
zoneFk <> vZoneFk,
|
||||
warehouseFk <> vWarehouseFk,
|
||||
currencyFk
|
||||
IFNULL(vCurrencyFk, currencyFk)
|
||||
INTO
|
||||
vHasDataChanged,
|
||||
vHasAddressChanged,
|
||||
|
|
|
@ -4,7 +4,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_priceDifferenc
|
|||
vLanded DATE,
|
||||
vAddressFk INT,
|
||||
vZoneFk INT,
|
||||
vWarehouseFk INT
|
||||
vWarehouseFk INT,
|
||||
vCurrencyFk SMALLINT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
|
@ -16,29 +17,36 @@ BEGIN
|
|||
* @param vZoneFk Id de la zona
|
||||
* @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,
|
||||
i.name,
|
||||
i.size,
|
||||
i.category,
|
||||
IFNULL(s.quantity, 0) quantity,
|
||||
IFNULL(s.price, 0) price,
|
||||
ROUND(SUM(tc.cost), 2) newPrice,
|
||||
s.quantity * (s.price - ROUND(SUM(tc.cost), 2)) difference,
|
||||
s.id saleFk
|
||||
FROM sale s
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk
|
||||
AND tc.warehouseFk = vWarehouseFk
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk = tc.componentFk
|
||||
LEFT JOIN `component` c ON c.id = tc.componentFk
|
||||
WHERE t.id = vTicketFk
|
||||
AND IF(sc.componentFk IS NULL
|
||||
AND c.classRate IS NOT NULL, FALSE, TRUE)
|
||||
GROUP BY s.id ORDER BY s.id;
|
||||
WITH ticketPriceDifference AS (
|
||||
SELECT s.itemFk,
|
||||
i.name,
|
||||
i.size,
|
||||
i.category,
|
||||
IFNULL(s.quantity, 0) quantity,
|
||||
IFNULL(s.price, 0) price,
|
||||
ROUND(SUM(tc.cost), 2) newPrice,
|
||||
s.id saleFk
|
||||
FROM vn.sale s
|
||||
JOIN vn.item i ON i.id = s.itemFk
|
||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||
LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk
|
||||
AND tc.warehouseFk = vWarehouseFk
|
||||
LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk = tc.componentFk
|
||||
LEFT JOIN vn.`component` c ON c.id = tc.componentFk
|
||||
WHERE t.id = vTicketFk
|
||||
AND IF(sc.componentFk IS NULL
|
||||
AND c.classRate IS NOT NULL, FALSE, TRUE)
|
||||
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;
|
||||
END$$
|
||||
|
|
|
@ -211,7 +211,7 @@
|
|||
"Name should be uppercase": "Name should be uppercase",
|
||||
"You cannot update these fields": "You cannot update these fields",
|
||||
"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 already have the mailAlias": "You already have the mailAlias",
|
||||
"This machine is already in use.": "This machine is already in use.",
|
||||
|
@ -250,6 +250,5 @@
|
|||
"Sales already moved": "Sales already moved",
|
||||
"Holidays to past days not available": "Holidays to past days not available",
|
||||
"Price cannot be blank": "Price cannot be blank",
|
||||
"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"
|
||||
"There are tickets to be invoiced": "There are tickets to be invoiced"
|
||||
}
|
||||
|
|
|
@ -398,5 +398,5 @@
|
|||
"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",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -31,15 +31,22 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const ticket = await Self.app.models.Ticket.findOne({
|
||||
where: {id: ticketFk}
|
||||
}, myOptions);
|
||||
const {landed, addressFk, agencyModeFk, companyFk, currencyFk} =
|
||||
await Self.app.models.Ticket.findById(
|
||||
ticketFk,
|
||||
{fields: ['landed', 'addressFk', 'agencyModeFk', 'companyFk', 'currencyFk']},
|
||||
myOptions
|
||||
);
|
||||
|
||||
const landed = ticket.landed;
|
||||
const addressFk = ticket.addressFk;
|
||||
const agencyModeFk = ticket.agencyModeFk;
|
||||
|
||||
const orderID = await Self.app.models.Order.new(ctx, landed, addressFk, agencyModeFk, myOptions);
|
||||
const orderID = await Self.app.models.Order.new(
|
||||
ctx,
|
||||
landed,
|
||||
addressFk,
|
||||
agencyModeFk,
|
||||
companyFk,
|
||||
currencyFk,
|
||||
myOptions
|
||||
);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
|
|
|
@ -205,6 +205,7 @@ module.exports = Self => {
|
|||
const originalTicket = JSON.parse(JSON.stringify(ticketToChange));
|
||||
const ticketChanges = {
|
||||
clientFk: args.clientFk,
|
||||
currencyFk: args.currencyFk,
|
||||
nickname: args.nickname,
|
||||
agencyModeFk: args.agencyModeFk,
|
||||
addressFk: args.addressFk,
|
||||
|
@ -214,7 +215,6 @@ module.exports = Self => {
|
|||
shipped: args.shipped,
|
||||
landed: args.landed,
|
||||
isDeleted: args.isDeleted,
|
||||
currencyFk: args.currencyFk
|
||||
};
|
||||
|
||||
let response;
|
||||
|
|
|
@ -46,6 +46,11 @@ module.exports = Self => {
|
|||
type: 'date',
|
||||
description: 'shipped',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'currencyId',
|
||||
type: 'number',
|
||||
description: 'The currency ticket'
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
|
@ -91,7 +96,7 @@ module.exports = Self => {
|
|||
}
|
||||
}
|
||||
|
||||
const items = await models.Sale.find({
|
||||
const sales = await models.Sale.find({
|
||||
where: {
|
||||
ticketFk: args.id
|
||||
},
|
||||
|
@ -99,19 +104,22 @@ module.exports = Self => {
|
|||
include: 'item'
|
||||
}, myOptions);
|
||||
|
||||
const salesObj = {
|
||||
items: items,
|
||||
const salesTotals = {
|
||||
sales,
|
||||
totalUnitPrice: 0.00,
|
||||
totalNewPrice: 0.00,
|
||||
totalDifference: 0.00,
|
||||
totalForeignUnitPrice: 0.00,
|
||||
totalForeignNewPrice: 0.00,
|
||||
totalForeignDifference: 0.00,
|
||||
};
|
||||
|
||||
// Get items movable
|
||||
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;
|
||||
|
||||
salesObj.haveDifferences = differenceShipped || differenceWarehouse;
|
||||
salesTotals.haveDifferences = differenceShipped || differenceWarehouse;
|
||||
|
||||
let query = `CALL ticket_getMovable(?,?,?)`;
|
||||
let params = [args.id, args.shipped, args.warehouseId];
|
||||
|
@ -124,34 +132,35 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
// Sale price component, one per sale
|
||||
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
|
||||
params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId];
|
||||
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?, ?)`;
|
||||
params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId, args.currencyId];
|
||||
const [difComponents] = await Self.rawSql(query, params, myOptions);
|
||||
|
||||
const map = new Map();
|
||||
for (let difComponent of difComponents)
|
||||
map.set(difComponent.saleFk, difComponent);
|
||||
|
||||
for (sale of salesObj.items) {
|
||||
for (let sale of salesTotals.sales) {
|
||||
const difComponent = map.get(sale.id);
|
||||
if (difComponent) {
|
||||
sale.component = difComponent;
|
||||
|
||||
salesObj.totalDifference += difComponent.difference;
|
||||
salesObj.totalDifference = round(salesObj.totalDifference);
|
||||
salesTotals.totalNewPrice += round(difComponent.newPrice * difComponent.quantity);
|
||||
salesTotals.totalForeignNewPrice += round(difComponent.newForeignPrice * difComponent.quantity);
|
||||
|
||||
salesObj.totalNewPrice += difComponent.newPrice;
|
||||
salesObj.totalNewPrice = round(salesObj.totalNewPrice);
|
||||
salesTotals.totalUnitPrice += round(sale.price * difComponent.quantity);
|
||||
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);
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return salesObj;
|
||||
return salesTotals;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
Loading…
Reference in New Issue