Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
e26eed5d30
|
@ -66,70 +66,77 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isEditable = await Self.isEditable(ctx, args.id, myOptions);
|
try {
|
||||||
|
const isEditable = await Self.isEditable(ctx, args.id, myOptions);
|
||||||
|
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
throw new UserError(`The sales of this ticket can't be modified`);
|
||||||
|
|
||||||
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss', myOptions);
|
const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss', myOptions);
|
||||||
if (!isProductionBoss) {
|
if (!isProductionBoss) {
|
||||||
const zoneShipped = await models.Agency.getShipped(
|
const zoneShipped = await models.Agency.getShipped(
|
||||||
args.landed,
|
args.landed,
|
||||||
args.addressId,
|
args.addressId,
|
||||||
args.agencyModeId,
|
args.agencyModeId,
|
||||||
args.warehouseId,
|
args.warehouseId,
|
||||||
myOptions);
|
myOptions);
|
||||||
|
|
||||||
if (!zoneShipped || zoneShipped.zoneFk != args.zoneId)
|
if (!zoneShipped || zoneShipped.zoneFk != args.zoneId)
|
||||||
throw new UserError(`You don't have privileges to change the zone`);
|
throw new UserError(`You don't have privileges to change the zone`);
|
||||||
}
|
|
||||||
|
|
||||||
const items = await models.Sale.find({
|
|
||||||
where: {
|
|
||||||
ticketFk: args.id
|
|
||||||
},
|
|
||||||
order: 'concept ASC',
|
|
||||||
include: 'item'
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const salesObj = {
|
|
||||||
items: items,
|
|
||||||
totalUnitPrice: 0.00,
|
|
||||||
totalNewPrice: 0.00,
|
|
||||||
totalDifference: 0.00,
|
|
||||||
};
|
|
||||||
|
|
||||||
const query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
|
|
||||||
const params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId];
|
|
||||||
const [difComponents] = await Self.rawSql(query, params, myOptions);
|
|
||||||
|
|
||||||
const map = new Map();
|
|
||||||
|
|
||||||
// Sale price component, one per sale
|
|
||||||
for (difComponent of difComponents)
|
|
||||||
map.set(difComponent.saleFk, difComponent);
|
|
||||||
|
|
||||||
function round(value) {
|
|
||||||
return Math.round(value * 100) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (sale of salesObj.items) {
|
|
||||||
const difComponent = map.get(sale.id);
|
|
||||||
|
|
||||||
if (difComponent) {
|
|
||||||
sale.component = difComponent;
|
|
||||||
|
|
||||||
salesObj.totalDifference += difComponent.difference;
|
|
||||||
salesObj.totalDifference = round(salesObj.totalDifference);
|
|
||||||
|
|
||||||
salesObj.totalNewPrice += difComponent.newPrice;
|
|
||||||
salesObj.totalNewPrice = round(salesObj.totalNewPrice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
salesObj.totalUnitPrice += sale.price;
|
const items = await models.Sale.find({
|
||||||
salesObj.totalUnitPrice = round(salesObj.totalUnitPrice);
|
where: {
|
||||||
}
|
ticketFk: args.id
|
||||||
|
},
|
||||||
|
order: 'concept ASC',
|
||||||
|
include: 'item'
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
return salesObj;
|
const salesObj = {
|
||||||
|
items: items,
|
||||||
|
totalUnitPrice: 0.00,
|
||||||
|
totalNewPrice: 0.00,
|
||||||
|
totalDifference: 0.00,
|
||||||
|
};
|
||||||
|
|
||||||
|
const query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
|
||||||
|
const params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId];
|
||||||
|
const [difComponents] = await Self.rawSql(query, params, myOptions);
|
||||||
|
|
||||||
|
const map = new Map();
|
||||||
|
|
||||||
|
// Sale price component, one per sale
|
||||||
|
for (difComponent of difComponents)
|
||||||
|
map.set(difComponent.saleFk, difComponent);
|
||||||
|
|
||||||
|
for (sale of salesObj.items) {
|
||||||
|
const difComponent = map.get(sale.id);
|
||||||
|
|
||||||
|
if (difComponent) {
|
||||||
|
sale.component = difComponent;
|
||||||
|
|
||||||
|
salesObj.totalDifference += difComponent.difference;
|
||||||
|
salesObj.totalDifference = round(salesObj.totalDifference);
|
||||||
|
|
||||||
|
salesObj.totalNewPrice += difComponent.newPrice;
|
||||||
|
salesObj.totalNewPrice = round(salesObj.totalNewPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
salesObj.totalUnitPrice += sale.price;
|
||||||
|
salesObj.totalUnitPrice = round(salesObj.totalUnitPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return salesObj;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function round(value) {
|
||||||
|
return Math.round(value * 100) / 100;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue