2018-12-27 11:54:16 +00:00
|
|
|
let UserError = require('vn-loopback/util/user-error');
|
2018-03-13 13:46:39 +00:00
|
|
|
|
2018-05-04 09:46:03 +00:00
|
|
|
module.exports = Self => {
|
2018-07-06 14:32:23 +00:00
|
|
|
require('../methods/item/filter')(Self);
|
2018-05-04 09:46:03 +00:00
|
|
|
require('../methods/item/clone')(Self);
|
|
|
|
require('../methods/item/updateTaxes')(Self);
|
2020-05-06 16:42:50 +00:00
|
|
|
require('../methods/item/getBalance')(Self);
|
2020-08-31 13:03:00 +00:00
|
|
|
require('../methods/item/lastEntriesFilter')(Self);
|
2018-07-23 07:58:07 +00:00
|
|
|
require('../methods/item/getSummary')(Self);
|
2018-08-08 12:44:45 +00:00
|
|
|
require('../methods/item/getCard')(Self);
|
2018-11-12 12:12:25 +00:00
|
|
|
require('../methods/item/regularize')(Self);
|
2019-02-18 06:57:15 +00:00
|
|
|
require('../methods/item/getVisibleAvailable')(Self);
|
2019-01-16 07:46:40 +00:00
|
|
|
require('../methods/item/new')(Self);
|
2021-03-30 08:28:44 +00:00
|
|
|
require('../methods/item/getWasteByWorker')(Self);
|
|
|
|
require('../methods/item/getWasteByItem')(Self);
|
2020-02-17 11:47:03 +00:00
|
|
|
require('../methods/item/createIntrastat')(Self);
|
2021-11-16 12:56:09 +00:00
|
|
|
require('../methods/item/activeBuyers')(Self);
|
2018-01-10 11:49:52 +00:00
|
|
|
|
|
|
|
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
2018-03-13 13:46:39 +00:00
|
|
|
|
|
|
|
Self.observe('before save', async function(ctx) {
|
|
|
|
await Self.availableId(ctx);
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.availableId = async function(ctx) {
|
|
|
|
if (ctx.isNewInstance) {
|
|
|
|
try {
|
|
|
|
let query = `SELECT i1.id + 1 as id FROM vn.item i1
|
|
|
|
LEFT JOIN vn.item i2 ON i1.id + 1 = i2.id
|
|
|
|
WHERE i2.id IS NULL ORDER BY i1.id LIMIT 1`;
|
|
|
|
|
|
|
|
let newId = await Self.rawSql(query);
|
|
|
|
|
|
|
|
ctx.instance.id = newId[0].id;
|
2018-08-20 08:06:00 +00:00
|
|
|
return ctx.instance.id;
|
2018-03-13 13:46:39 +00:00
|
|
|
} catch (e) {
|
|
|
|
throw new UserError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-12-19 11:29:35 +00:00
|
|
|
};
|