91 lines
2.8 KiB
JavaScript
91 lines
2.8 KiB
JavaScript
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 => {
|
|
const userId = ctx.req.accessToken.userId;
|
|
const args = ctx.args;
|
|
|
|
if (args.originalQuantity == args.quantity) {
|
|
query = `CALL vn.collection_updateSale(?,?,?,?,?)`;
|
|
await Self.rawSql(query, [args.sale, args.originalQuantity, userId, args.stateFk, args.ticketFk]);
|
|
}
|
|
|
|
if (!args.isNicho) {
|
|
query = `CALL vn.collection_faults(?,?,?)`;
|
|
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, args.itemFk]);
|
|
} else {
|
|
query = `CALL vn.sector_getWarehouse(?)`;
|
|
const [result] = await Self.rawSql(query, [args.sectorFk]);
|
|
|
|
query = `CALL vn.itemPlacementSave(?,?,?)`;
|
|
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, result[0]['warehouseFk']]);
|
|
}
|
|
query = `CALL vn.sale_updateOriginalQuantity(?,?)`;
|
|
return await Self.rawSql(query, [args.sale, args.quantity]);
|
|
};
|
|
};
|