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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-11-09 13:53:26 +00:00
|
|
|
Self.updateCollectionSale = async ctx => {
|
2020-03-26 12:12:59 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
2020-11-09 13:53:26 +00:00
|
|
|
const args = ctx.args;
|
2020-03-26 12:12:59 +00:00
|
|
|
|
2020-11-09 13:53:26 +00:00
|
|
|
if (args.originalQuantity == args.quantity) {
|
2020-03-26 12:12:59 +00:00
|
|
|
query = `CALL vn.collection_updateSale(?,?,?,?,?)`;
|
2020-11-09 13:53:26 +00:00
|
|
|
await Self.rawSql(query, [args.sale, args.originalQuantity, userId, args.stateFk, args.ticketFk]);
|
2020-03-26 12:12:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 13:53:26 +00:00
|
|
|
if (!args.isNicho) {
|
2020-03-26 12:12:59 +00:00
|
|
|
query = `CALL vn.collection_faults(?,?,?)`;
|
2020-11-09 13:53:26 +00:00
|
|
|
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, args.itemFk]);
|
2020-03-26 12:12:59 +00:00
|
|
|
} else {
|
|
|
|
query = `CALL vn.sector_getWarehouse(?)`;
|
2020-11-09 13:53:26 +00:00
|
|
|
const [result] = await Self.rawSql(query, [args.sectorFk]);
|
2020-03-26 12:12:59 +00:00
|
|
|
|
|
|
|
query = `CALL vn.itemPlacementSave(?,?,?)`;
|
2020-11-09 13:53:26 +00:00
|
|
|
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, result[0]['warehouseFk']]);
|
2020-03-26 12:12:59 +00:00
|
|
|
}
|
|
|
|
query = `CALL vn.sale_updateOriginalQuantity(?,?)`;
|
2020-11-09 13:53:26 +00:00
|
|
|
return await Self.rawSql(query, [args.sale, args.quantity]);
|
2020-03-26 12:12:59 +00:00
|
|
|
};
|
|
|
|
};
|