priceDifference decimal round
gitea/salix/test This commit looks good
Details
gitea/salix/test This commit looks good
Details
This commit is contained in:
parent
711b94c835
commit
ea531a23f2
|
@ -53,7 +53,7 @@ module.exports = Self => {
|
|||
|
||||
Self.priceDifference = async(ctx, id, landed, addressId, agencyModeId, zoneId, warehouseId) => {
|
||||
const models = Self.app.models;
|
||||
const isEditable = await models.Ticket.isEditable(ctx, id);
|
||||
const isEditable = await Self.isEditable(ctx, id);
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
if (!isEditable)
|
||||
|
@ -67,19 +67,18 @@ module.exports = Self => {
|
|||
throw new UserError(`You don't have privileges to change the zone`);
|
||||
}
|
||||
|
||||
let salesObj = {};
|
||||
salesObj.items = await models.Sale.find({
|
||||
let salesObj = {
|
||||
items: await models.Sale.find({
|
||||
where: {
|
||||
ticketFk: id
|
||||
},
|
||||
order: 'concept ASC',
|
||||
include: [{
|
||||
relation: 'item'
|
||||
}]
|
||||
});
|
||||
salesObj.totalUnitPrice = 0.00;
|
||||
salesObj.totalNewPrice = 0.00;
|
||||
salesObj.totalDifference = 0.00;
|
||||
include: 'item'
|
||||
}),
|
||||
totalUnitPrice: 0.00,
|
||||
totalNewPrice: 0.00,
|
||||
totalDifference: 0.00,
|
||||
};
|
||||
|
||||
const query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
|
||||
const args = [id, landed, addressId, zoneId, warehouseId];
|
||||
|
@ -91,20 +90,25 @@ module.exports = Self => {
|
|||
map.set(difComponent.saleFk, difComponent);
|
||||
});
|
||||
|
||||
function round(value) {
|
||||
return Math.round(value * 100) / 100;
|
||||
}
|
||||
|
||||
salesObj.items.forEach(sale => {
|
||||
const difComponent = map.get(sale.id);
|
||||
|
||||
if (difComponent) {
|
||||
sale.component = difComponent;
|
||||
|
||||
salesObj.totalNewPrice += sale.component.newPrice;
|
||||
salesObj.totalDifference += sale.component.difference;
|
||||
salesObj.totalUnitPrice = Math.round(salesObj.totalUnitPrice * 100) / 100;
|
||||
salesObj.totalNewPrice = Math.round(salesObj.totalNewPrice * 100) / 100;
|
||||
salesObj.totalDifference += difComponent.difference;
|
||||
salesObj.totalDifference = round(salesObj.totalDifference);
|
||||
|
||||
salesObj.totalNewPrice += difComponent.newPrice;
|
||||
salesObj.totalNewPrice = round(salesObj.totalNewPrice);
|
||||
}
|
||||
|
||||
salesObj.totalUnitPrice += sale.price;
|
||||
salesObj.totalDifference = Math.round(salesObj.totalDifference * 100) / 100;
|
||||
salesObj.totalUnitPrice = round(salesObj.totalUnitPrice);
|
||||
});
|
||||
|
||||
return salesObj;
|
||||
|
|
Loading…
Reference in New Issue