refs #6276 itemShelvingMake_multi
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
25a0ffcfde
commit
40236fdb7b
|
@ -0,0 +1,74 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('makeMulti', {
|
||||||
|
description: 'Add a record or update it if it already exists.',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'shelvingFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'items',
|
||||||
|
type: ['number'],
|
||||||
|
required: true,
|
||||||
|
description: 'array of item foreign keys'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'warehouseFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
}],
|
||||||
|
|
||||||
|
http: {
|
||||||
|
path: `/makeMulti`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.makeMulti = async(shelvingFk, items, warehouseFk, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
const discardItems = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (let item of items) {
|
||||||
|
if (!discardItems.includes(item)) {
|
||||||
|
let quantity = items.reduce((acc, cur) => {
|
||||||
|
return acc + (cur === item ? 1 : 0);
|
||||||
|
}, 0);
|
||||||
|
discardItems.push(item);
|
||||||
|
|
||||||
|
let [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?)', [item, warehouseFk]);
|
||||||
|
let packing;
|
||||||
|
|
||||||
|
if (result) packing = Object.values(result)[0];
|
||||||
|
if (!packing) packing = 1;
|
||||||
|
|
||||||
|
quantity = quantity * packing;
|
||||||
|
|
||||||
|
await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, ?, ?)',
|
||||||
|
[shelvingFk,
|
||||||
|
item,
|
||||||
|
quantity,
|
||||||
|
packing,
|
||||||
|
warehouseFk]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,4 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/item-shelving/deleteItemShelvings')(Self);
|
require('../methods/item-shelving/deleteItemShelvings')(Self);
|
||||||
require('../methods/item-shelving/getInventory')(Self);
|
require('../methods/item-shelving/getInventory')(Self);
|
||||||
|
require('../methods/item-shelving/makeMulti')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ItemShelving",
|
"name": "ItemShelving",
|
||||||
"base": "Loggable",
|
"base": "VnModel",
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "itemShelving"
|
"table": "itemShelving"
|
||||||
|
|
Loading…
Reference in New Issue