salix/back/methods/collection/updateCollectionSale.js

90 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-03-26 12:12:59 +00:00
module.exports = Self => {
Self.remoteMethodCtx('updateCollectionSale', {
description: 'Update sale of a collection',
accessType: 'WRITE',
accepts: [{
arg: 'sale',
type: 'Number',
required: true,
description: 'The sale id'
}, {
arg: 'originalQuantity',
type: 'Number',
required: true,
description: 'The quantity to sale'
},
{
arg: 'quantity',
type: 'Number',
required: true,
description: 'The quantity to picked'
},
{
arg: 'quantityPicked',
type: 'Number',
required: true,
description: 'The quantity to picked'
}, {
arg: 'ticketFk',
type: 'Number',
required: true,
description: 'The ticket id'
}, {
arg: 'stateFk',
type: 'Number',
required: true,
description: 'The state id'
}, {
arg: 'isNicho',
type: 'Boolean',
required: true,
description: 'Determine if sale is picked from nicho or not'
}, {
arg: 'shelvingFk',
type: 'String',
required: false,
description: 'The shelving id'
}, {
arg: 'itemFk',
type: 'Number',
required: true,
description: 'The item id'
}, {
arg: 'sectorFk',
type: 'Number',
required: true,
description: 'The sector id'
}],
returns: {
type: 'Object',
root: true
},
http: {
path: `/updateCollectionSale`,
verb: 'POST'
}
});
Self.updateCollectionSale = async(ctx, sale, originalQuantity, quantity, quantityPicked, ticketFk, stateFk, isNicho, shelvingFk, itemFk, sectorFk) => {
const userId = ctx.req.accessToken.userId;
if (originalQuantity == quantity) {
query = `CALL vn.collection_updateSale(?,?,?,?,?)`;
await Self.rawSql(query, [sale, originalQuantity, userId, stateFk, ticketFk]);
}
if (!isNicho) {
query = `CALL vn.collection_faults(?,?,?)`;
await Self.rawSql(query, [shelvingFk, quantityPicked, itemFk]);
} else {
query = `CALL vn.sector_getWarehouse(?)`;
const [result] = await Self.rawSql(query, [sectorFk]);
query = `CALL vn.itemPlacementSave(?,?,?)`;
await Self.rawSql(query, [shelvingFk, quantityPicked, result[0]['warehouseFk']]);
}
query = `CALL vn.sale_updateOriginalQuantity(?,?)`;
return await Self.rawSql(query, [sale, quantity]);
};
};