Merge branch 'dev' into 6930_scopedToken_Multimedia
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
6c06f70121
|
@ -0,0 +1,31 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('assign', {
|
||||
description: 'Assign a collection',
|
||||
accessType: 'WRITE',
|
||||
http: {
|
||||
path: `/assign`,
|
||||
verb: 'POST'
|
||||
},
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
});
|
||||
|
||||
Self.assign = async(ctx, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {userId};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const [,, {collectionFk}] = await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk); SELECT @vCollectionFk collectionFk',
|
||||
[userId], myOptions);
|
||||
|
||||
if (!collectionFk) throw new UserError('There are not picking tickets');
|
||||
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);
|
||||
|
||||
return collectionFk;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,157 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getSales', {
|
||||
description: 'Get sales from ticket or collection',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'collectionOrTicketFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
}, {
|
||||
arg: 'print',
|
||||
type: 'boolean',
|
||||
required: true
|
||||
}, {
|
||||
arg: 'source',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
|
||||
],
|
||||
returns: {
|
||||
type: 'Object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getSales`,
|
||||
verb: 'GET'
|
||||
},
|
||||
});
|
||||
|
||||
Self.getSales = async(ctx, collectionOrTicketFk, print, source, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {userId};
|
||||
const $t = ctx.req.__;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const [{id}] = await Self.rawSql('SELECT vn.ticket_get(?) as id',
|
||||
[collectionOrTicketFk],
|
||||
myOptions);
|
||||
|
||||
const [tickets] = await Self.rawSql('CALL vn.collection_getTickets(?)', [id], myOptions);
|
||||
|
||||
if (source) {
|
||||
await Self.rawSql(
|
||||
'CALL vn.ticketStateToday_setState(?,?)', [id, source], myOptions
|
||||
);
|
||||
}
|
||||
|
||||
const [sales] = await Self.rawSql('CALL vn.sale_getFromTicketOrCollection(?)',
|
||||
[id], myOptions);
|
||||
|
||||
const isPicker = source != 'CHECKER';
|
||||
const [placements] = await Self.rawSql('CALL vn.collectionPlacement_get(?, ?)',
|
||||
[id, isPicker], myOptions
|
||||
);
|
||||
|
||||
if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions);
|
||||
|
||||
for (let ticket of tickets) {
|
||||
let observations = ticket.observaciones.split(' ');
|
||||
|
||||
for (let observation of observations) {
|
||||
const salesPerson = ticket.salesPersonFk;
|
||||
if (observation.startsWith('#') || observation.startsWith('@')) {
|
||||
await models.Chat.send(ctx,
|
||||
observation,
|
||||
$t('ticketCommercial', {ticket: ticket.ticketFk, salesPerson})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getCollection(id, tickets, sales, placements, myOptions);
|
||||
};
|
||||
|
||||
async function getCollection(id, tickets, sales, placements, options) {
|
||||
const collection = {
|
||||
collectionFk: id,
|
||||
tickets: [],
|
||||
};
|
||||
for (let ticket of tickets) {
|
||||
const {ticketFk} = ticket;
|
||||
ticket.sales = [];
|
||||
|
||||
const barcodes = await getBarcodes(ticketFk, options);
|
||||
await Self.rawSql(
|
||||
'CALL util.log_add(?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null],
|
||||
options
|
||||
);
|
||||
|
||||
for (let sale of sales) {
|
||||
if (sale.ticketFk == ticketFk) {
|
||||
sale.placements = [];
|
||||
for (const salePlacement of placements) {
|
||||
if (salePlacement.saleFk == sale.saleFk && salePlacement.order) {
|
||||
const placement = {
|
||||
saleFk: salePlacement.saleFk,
|
||||
itemFk: salePlacement.itemFk,
|
||||
placement: salePlacement.placement,
|
||||
shelving: salePlacement.shelving,
|
||||
created: salePlacement.created,
|
||||
visible: salePlacement.visible,
|
||||
order: salePlacement.order,
|
||||
grouping: salePlacement.grouping,
|
||||
priority: salePlacement.priority,
|
||||
saleOrder: salePlacement.saleOrder,
|
||||
isPreviousPrepared: salePlacement.isPreviousPrepared,
|
||||
itemShelvingSaleFk: salePlacement.itemShelvingSaleFk,
|
||||
ticketFk: salePlacement.ticketFk,
|
||||
id: salePlacement.id
|
||||
};
|
||||
sale.placements.push(placement);
|
||||
}
|
||||
}
|
||||
|
||||
sale.barcodes = [];
|
||||
for (const barcode of barcodes) {
|
||||
if (barcode.movementId == sale.saleFk) {
|
||||
if (barcode.code) {
|
||||
sale.barcodes.push(barcode.code);
|
||||
sale.barcodes.push(`0 ${barcode.code}`);
|
||||
}
|
||||
|
||||
if (barcode.id) {
|
||||
sale.barcodes.push(barcode.id);
|
||||
sale.barcodes.push(`0 ${barcode.id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ticket.sales.push(sale);
|
||||
}
|
||||
}
|
||||
collection.tickets.push(ticket);
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
async function getBarcodes(ticketId, options) {
|
||||
const query =
|
||||
`SELECT s.id movementId,
|
||||
b.code,
|
||||
c.id
|
||||
FROM vn.sale s
|
||||
LEFT JOIN vn.itemBarcode b ON b.itemFk = s.itemFk
|
||||
LEFT JOIN vn.buy c ON c.itemFk = s.itemFk
|
||||
LEFT JOIN vn.entry e ON e.id = c.entryFk
|
||||
LEFT JOIN vn.travel tr ON tr.id = e.travelFk
|
||||
WHERE s.ticketFk = ?
|
||||
AND tr.landed >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)`;
|
||||
return Self.rawSql(query, [ticketId], options);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('ticket assign()', () => {
|
||||
let ctx;
|
||||
let options;
|
||||
let tx;
|
||||
beforeEach(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 1106},
|
||||
headers: {origin: 'http://localhost'},
|
||||
__: value => value
|
||||
},
|
||||
args: {}
|
||||
};
|
||||
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: ctx.req
|
||||
});
|
||||
|
||||
options = {transaction: tx};
|
||||
tx = await models.Sale.beginTransaction({});
|
||||
options.transaction = tx;
|
||||
});
|
||||
|
||||
afterEach(async() => {
|
||||
await tx.rollback();
|
||||
});
|
||||
|
||||
it('should throw an error when there is not picking tickets', async() => {
|
||||
try {
|
||||
await models.Collection.assign(ctx, options);
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual('There are not picking tickets');
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,62 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('collection getSales()', () => {
|
||||
const collectionOrTicketFk = 999999;
|
||||
const print = true;
|
||||
const source = 'CHECKER';
|
||||
|
||||
beforeAll(() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 9},
|
||||
headers: {origin: 'http://localhost'},
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should return a collection with tickets, placements and barcodes settled correctly', async() => {
|
||||
const tx = await models.Collection.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
try {
|
||||
const collection = await models.Collection.getSales(ctx,
|
||||
collectionOrTicketFk, print, source, options);
|
||||
|
||||
const [firstTicket] = collection.tickets;
|
||||
const [firstSale] = firstTicket.sales;
|
||||
const [firstPlacement] = firstSale.placements;
|
||||
|
||||
expect(collection.tickets.length).toBeTruthy();
|
||||
expect(collection.collectionFk).toEqual(firstTicket.ticketFk);
|
||||
|
||||
expect(firstSale.ticketFk).toEqual(firstTicket.ticketFk);
|
||||
expect(firstSale.placements.length).toBeTruthy();
|
||||
expect(firstSale.barcodes.length).toBeTruthy();
|
||||
|
||||
expect(firstSale.saleFk).toEqual(firstPlacement.saleFk);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should print a sticker', async() => {
|
||||
const tx = await models.Collection.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const query = 'SELECT * FROM printQueue pq JOIN printQueueArgs pqa ON pqa.printQueueFk = pq.id';
|
||||
try {
|
||||
const printQueueBefore = await models.Collection.rawSql(
|
||||
query, [], options);
|
||||
await models.Collection.getSales(ctx,
|
||||
collectionOrTicketFk, true, source, options);
|
||||
const printQueueAfter = await models.Collection.rawSql(
|
||||
query, [], options);
|
||||
|
||||
expect(printQueueAfter.length).toEqual(printQueueBefore.length + 1);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,132 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('machineWorker updateInTime()', () => {
|
||||
const itBoss = 104;
|
||||
const davidCharles = 1106;
|
||||
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {},
|
||||
headers: {origin: 'http://localhost'},
|
||||
__: value => value
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should throw an error if the plate does not exist', async() => {
|
||||
const tx = await models.MachineWorker.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const plate = 'RE-123';
|
||||
ctx.req.accessToken.userId = 1106;
|
||||
try {
|
||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toContain('the plate does not exist');
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
it('should grab a machine where is not in use', async() => {
|
||||
const tx = await models.MachineWorker.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const plate = 'RE-003';
|
||||
ctx.req.accessToken.userId = 1107;
|
||||
try {
|
||||
const totalBefore = await models.MachineWorker.find(null, options);
|
||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||
const totalAfter = await models.MachineWorker.find(null, options);
|
||||
|
||||
expect(totalAfter.length).toEqual(totalBefore.length + 1);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
describe('less than 12h', () => {
|
||||
const plate = 'RE-001';
|
||||
it('should trow an error if it is not himself', async() => {
|
||||
const tx = await models.MachineWorker.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
ctx.req.accessToken.userId = davidCharles;
|
||||
|
||||
try {
|
||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toContain('This machine is already in use');
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error if it is himself with a different machine', async() => {
|
||||
const tx = await models.MachineWorker.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
ctx.req.accessToken.userId = itBoss;
|
||||
const plate = 'RE-003';
|
||||
try {
|
||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toEqual('You are already using a machine');
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
it('should set the out time if it is himself', async() => {
|
||||
const tx = await models.MachineWorker.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
ctx.req.accessToken.userId = itBoss;
|
||||
|
||||
try {
|
||||
const isNotParked = await models.MachineWorker.findOne({
|
||||
where: {workerFk: itBoss}
|
||||
}, options);
|
||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||
const isParked = await models.MachineWorker.findOne({
|
||||
where: {workerFk: itBoss}
|
||||
}, options);
|
||||
|
||||
expect(isNotParked.outTime).toBeNull();
|
||||
expect(isParked.outTime).toBeDefined();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('equal or more than 12h', () => {
|
||||
const plate = 'RE-002';
|
||||
it('should set the out time and grab the machine', async() => {
|
||||
const tx = await models.MachineWorker.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
ctx.req.accessToken.userId = davidCharles;
|
||||
const filter = {
|
||||
where: {workerFk: davidCharles, machineFk: 2}
|
||||
};
|
||||
try {
|
||||
const isNotParked = await models.MachineWorker.findOne(filter, options);
|
||||
const totalBefore = await models.MachineWorker.find(null, options);
|
||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||
const isParked = await models.MachineWorker.findOne(filter, options);
|
||||
const totalAfter = await models.MachineWorker.find(null, options);
|
||||
|
||||
expect(isNotParked.outTime).toBeNull();
|
||||
expect(isParked.outTime).toBeDefined();
|
||||
expect(totalAfter.length).toEqual(totalBefore.length + 1);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,77 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateInTime', {
|
||||
description: 'Updates the corresponding registry if the worker has been registered in the last few hours',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'plate',
|
||||
type: 'string',
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: `/updateInTime`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateInTime = async(ctx, plate, options) => {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const $t = ctx.req.__;
|
||||
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const machine = await models.Machine.findOne({
|
||||
fields: ['id', 'plate'],
|
||||
where: {plate}
|
||||
}, myOptions);
|
||||
|
||||
if (!machine)
|
||||
throw new Error($t('the plate does not exist', {plate}));
|
||||
|
||||
const machineWorker = await Self.findOne({
|
||||
where: {
|
||||
or: [{machineFk: machine.id}, {workerFk: userId}],
|
||||
outTime: null,
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
||||
const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000);
|
||||
|
||||
if (machineWorker) {
|
||||
const isHimself = userId == machineWorker.workerFk;
|
||||
const isSameMachine = machine.id == machineWorker.machineFk;
|
||||
|
||||
if (hoursDifference < maxHours && !isHimself)
|
||||
throw new UserError($t('This machine is already in use.'));
|
||||
|
||||
if (hoursDifference < maxHours && isHimself && !isSameMachine)
|
||||
throw new UserError($t('You are already using a machine'));
|
||||
|
||||
await machineWorker.updateAttributes({
|
||||
outTime: Date.vnNew()
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
if (!machineWorker || hoursDifference >= maxHours)
|
||||
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,45 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getVersion', {
|
||||
description: 'gets app version data',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'app',
|
||||
type: 'string',
|
||||
required: true
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getVersion`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getVersion = async(ctx, app) => {
|
||||
const {models} = Self.app;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
const workerFk = await models.WorkerAppTester.findOne({
|
||||
where: {
|
||||
workerFk: userId
|
||||
}
|
||||
});
|
||||
let fields = ['id', 'appName'];
|
||||
|
||||
if (workerFk)
|
||||
fields = fields.concat(['isVersionBetaCritical', 'versionBeta', 'urlBeta']);
|
||||
else
|
||||
fields = fields.concat(['isVersionCritical', 'version', 'urlProduction']);
|
||||
|
||||
const filter = {
|
||||
where: {
|
||||
appName: app
|
||||
},
|
||||
fields,
|
||||
};
|
||||
|
||||
return Self.findOne(filter);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('mobileAppVersionControl getVersion()', () => {
|
||||
const appName = 'delivery';
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {},
|
||||
headers: {origin: 'http://localhost'},
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should get the version app', async() => {
|
||||
ctx.req.accessToken.userId = 9;
|
||||
const {version, versionBeta} = await models.MobileAppVersionControl.getVersion(ctx, appName);
|
||||
|
||||
expect(version).toEqual('9.2');
|
||||
expect(versionBeta).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should get the beta version app', async() => {
|
||||
ctx.req.accessToken.userId = 66;
|
||||
const {version, versionBeta} = await models.MobileAppVersionControl.getVersion(ctx, appName);
|
||||
|
||||
expect(versionBeta).toBeDefined();
|
||||
expect(version).toBeUndefined();
|
||||
});
|
||||
});
|
|
@ -79,9 +79,15 @@
|
|||
"Language": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"Machine": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"MachineWorker": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"MachineWorkerConfig": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"MobileAppVersionControl": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -3,4 +3,6 @@ module.exports = Self => {
|
|||
require('../methods/collection/setSaleQuantity')(Self);
|
||||
require('../methods/collection/previousLabel')(Self);
|
||||
require('../methods/collection/getTickets')(Self);
|
||||
require('../methods/collection/assign')(Self);
|
||||
require('../methods/collection/getSales')(Self);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "MachineWorkerConfig",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "vn.machineWorkerConfig"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true
|
||||
},
|
||||
"maxHours": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/machine-worker/updateInTime')(Self);
|
||||
};
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "Machine",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "vn.machine"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true
|
||||
},
|
||||
"plate": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/mobile-app-version-control/getVersion')(Self);
|
||||
};
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "MobileAppVersionControl",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "vn.mobileAppVersionControl"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"id": true
|
||||
},
|
||||
"appName": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
"version": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
"isVersionCritical": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
"urlProduction": {
|
||||
"type": "string"
|
||||
},
|
||||
"urlBeta": {
|
||||
"type": "string"
|
||||
},
|
||||
"versionBeta": {
|
||||
"type": "string"
|
||||
},
|
||||
"isVersionBetaCritical": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1356,8 +1356,6 @@ INSERT INTO `ACL` VALUES (385,'Route','driverRoutePdf','READ','ALLOW','ROLE','em
|
|||
INSERT INTO `ACL` VALUES (386,'Route','driverRouteEmail','WRITE','ALLOW','ROLE','employee');
|
||||
INSERT INTO `ACL` VALUES (387,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','customer');
|
||||
INSERT INTO `ACL` VALUES (388,'Supplier','newSupplier','WRITE','ALLOW','ROLE','administrative');
|
||||
INSERT INTO `ACL` VALUES (389,'ClaimRma','*','READ','ALLOW','ROLE','claimManager');
|
||||
INSERT INTO `ACL` VALUES (390,'ClaimRma','*','WRITE','ALLOW','ROLE','claimManager');
|
||||
INSERT INTO `ACL` VALUES (391,'Notification','*','WRITE','ALLOW','ROLE','system');
|
||||
INSERT INTO `ACL` VALUES (392,'Boxing','*','*','ALLOW','ROLE','employee');
|
||||
INSERT INTO `ACL` VALUES (393,'Url','*','READ','ALLOW','ROLE','employee');
|
||||
|
|
|
@ -564,13 +564,13 @@ INSERT INTO `vn`.`supplierActivity`(`code`, `name`)
|
|||
|
||||
INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`, `commission`, `created`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `payDay`, `taxTypeSageFk`, `withholdingSageFk`, `transactionTypeSageFk`, `workerFk`, `supplierActivityFk`, `isPayMethodChecked`, `healthRegister`)
|
||||
VALUES
|
||||
(1, 'PLANTS SL', 'Plants nick', 4100000001, 1, '06089160W', 0, util.VN_CURDATE(), 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'),
|
||||
(2, 'FARMER KING', 'The farmer', 4000020002, 1, '87945234L', 0, util.VN_CURDATE(), 1, 'supplier address 2', 'GOTHAM', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'),
|
||||
(1, 'PLANTS SL', 'Plants nick', 4100000001, 1, '06089160W', 0, util.VN_CURDATE(), 1, 'supplier address 1', 'GOTHAM', 1, 46000, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'),
|
||||
(2, 'FARMER KING', 'The farmer', 4000020002, 1, '87945234L', 0, util.VN_CURDATE(), 1, 'supplier address 2', 'GOTHAM', 2, 46000, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'),
|
||||
(69, 'PACKAGING', 'Packaging nick', 4100000069, 1, '94935005K', 0, util.VN_CURDATE(), 1, 'supplier address 5', 'ASGARD', 3, 46600, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'),
|
||||
(442, 'VERDNATURA LEVANTE SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, util.VN_CURDATE(), 1, 'supplier address 3', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'),
|
||||
(442, 'VERDNATURA LEVANTE SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, util.VN_CURDATE(), 1, 'supplier address 3', 'GOTHAM', 1, 46000, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'),
|
||||
(567, 'HOLLAND', 'Holland nick', 4000020567, 1, '14364089Z', 0, util.VN_CURDATE(), 1, 'supplier address 6', 'ASGARD', 3, 46600, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'),
|
||||
(791, 'BROS SL', 'Bros nick', 5115000791, 1, '37718083S', 0, util.VN_CURDATE(), 1, 'supplier address 7', 'ASGARD', 3, 46600, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'),
|
||||
(1381, 'ORNAMENTALES', 'Ornamentales', 7185001381, 1, '07972486L', 0, util.VN_CURDATE(), 1, 'supplier address 4', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V');
|
||||
(1381, 'ORNAMENTALES', 'Ornamentales', 7185001381, 1, '07972486L', 0, util.VN_CURDATE(), 1, 'supplier address 4', 'GOTHAM', 1, 46000, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V');
|
||||
|
||||
INSERT INTO `vn`.`supplierAddress`(`id`, `supplierFk`, `nickname`, `street`, `provinceFk`, `postalCode`, `city`, `phone`, `mobile`)
|
||||
VALUES
|
||||
|
@ -1239,6 +1239,7 @@ INSERT INTO `vn`.`train`(`id`, `name`)
|
|||
INSERT INTO `vn`.`operator` (`workerFk`, `numberOfWagons`, `trainFk`, `itemPackingTypeFk`, `warehouseFk`, `sectorFk`, `labelerFk`)
|
||||
VALUES
|
||||
('1106', '1', '1', 'H', '1', '1', '1'),
|
||||
('9', '2', '1', 'H', '1', '1', '1'),
|
||||
('1107', '1', '1', 'V', '1', '1', '1');
|
||||
|
||||
INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`, `trainFk`)
|
||||
|
@ -1819,19 +1820,16 @@ INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk
|
|||
INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`, `hasToNotify`)
|
||||
VALUES
|
||||
( 1, 'pending', 'Pendiente', 1, 1, 0),
|
||||
( 2, 'managed', 'Gestionado', 72, 5, 0),
|
||||
( 3, 'resolved', 'Resuelto', 72, 7, 0),
|
||||
( 4, 'canceled', 'Anulado', 72, 6, 1),
|
||||
( 5, 'incomplete', 'Incompleta', 1, 3, 1),
|
||||
( 6, 'mana', 'Mana', 72, 4, 0),
|
||||
( 7, 'lack', 'Faltas', 72, 2, 0);
|
||||
( 5, 'incomplete', 'Incompleta', 1, 3, 1);
|
||||
|
||||
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`, `ticketFk`)
|
||||
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `ticketFk`)
|
||||
VALUES
|
||||
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183', 11),
|
||||
(2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL, 16),
|
||||
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL, 7),
|
||||
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL, 8);
|
||||
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, 11),
|
||||
(2, util.VN_CURDATE(), 4, 1101, 18, 3, 0, util.VN_CURDATE(), 1, 16),
|
||||
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, 7),
|
||||
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8);
|
||||
|
||||
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
|
||||
VALUES
|
||||
|
@ -1880,14 +1878,6 @@ INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRa
|
|||
(1103, 2000, 0.00, 0.00, 0.02, 1.00),
|
||||
(1104, 2500, 150.00, 0.02, 0.10, 1.00);
|
||||
|
||||
INSERT INTO vn.claimRma (`id`, `code`, `created`, `workerFk`)
|
||||
VALUES
|
||||
(1, '02676A049183', DEFAULT, 1106),
|
||||
(2, '02676A049183', DEFAULT, 1106),
|
||||
(3, '02676A049183', DEFAULT, 1107),
|
||||
(4, '02676A049183', DEFAULT, 1107),
|
||||
(5, '01837B023653', DEFAULT, 1106);
|
||||
|
||||
INSERT INTO `vn`.`claimLog` (`originFk`, userFk, `action`, changedModel, oldInstance, newInstance, changedModelId, `description`)
|
||||
VALUES
|
||||
(1, 18, 'update', 'Claim', '{"hasToPickUp":false}', '{"hasToPickUp":true}', 1, NULL),
|
||||
|
@ -2737,10 +2727,10 @@ INSERT INTO `vn`.`chat` (`senderFk`, `recipient`, `dated`, `checkUserStatus`, `m
|
|||
(1101, '@PetterParker', util.VN_CURDATE(), 0, 'Second test message', 0, 'pending');
|
||||
|
||||
|
||||
INSERT INTO `vn`.`mobileAppVersionControl` (`appName`, `version`, `isVersionCritical`)
|
||||
INSERT INTO `vn`.`mobileAppVersionControl` (`appName`, `version`, `isVersionCritical`,`versionBeta`)
|
||||
VALUES
|
||||
('delivery', '9.2', 0),
|
||||
('warehouse', '8.1', 0);
|
||||
('delivery', '9.2', 0,'9.7'),
|
||||
('warehouse', '8.1', 0,'8.3');
|
||||
|
||||
INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmentFk`, `type`, `use`, `productionYear`, `workerFk`, `companyFk`)
|
||||
VALUES
|
||||
|
@ -3077,3 +3067,666 @@ INSERT INTO `vn`.`cmr` (id,truckPlate,observations,senderInstruccions,paymentIns
|
|||
|
||||
UPDATE vn.department
|
||||
SET workerFk = null;
|
||||
|
||||
-- NEW WAREHOUSE
|
||||
|
||||
INSERT INTO vn.packaging
|
||||
VALUES('--', 2745600.00, 100.00, 120.00, 220.00, 0.00, 1, '2001-01-01 00:00:00.000', NULL, NULL, NULL, 0.00, 16, 0.00, 0, NULL, 0.00, NULL, NULL, 0, NULL, 0, 0);
|
||||
|
||||
|
||||
INSERT IGNORE INTO vn.intrastat
|
||||
SET id = 44219999,
|
||||
description = 'Manufacturas de madera',
|
||||
taxClassFk = 1,
|
||||
taxCodeFk = 1;
|
||||
|
||||
INSERT IGNORE INTO vn.warehouse
|
||||
SET id = 999,
|
||||
name = 'TestingWarehouse',
|
||||
hasAvailable = TRUE,
|
||||
isForTicket = TRUE,
|
||||
isInventory = TRUE,
|
||||
hasUbications = TRUE,
|
||||
hasProduction = TRUE;
|
||||
|
||||
INSERT IGNORE INTO vn.sector
|
||||
SET id = 9991,
|
||||
description = 'NormalSector',
|
||||
warehouseFk = 999,
|
||||
code = 'NS',
|
||||
isPackagingArea = FALSE,
|
||||
sonFk = NULL,
|
||||
isMain = TRUE,
|
||||
itemPackingTypeFk = NULL;
|
||||
|
||||
INSERT IGNORE INTO vn.sector
|
||||
SET id = 9992,
|
||||
description = 'PreviousSector',
|
||||
warehouseFk = 999,
|
||||
code = 'PS',
|
||||
isPackagingArea = FALSE,
|
||||
sonFk = NULL,
|
||||
isMain = TRUE,
|
||||
itemPackingTypeFk = NULL;
|
||||
|
||||
INSERT IGNORE INTO vn.sector
|
||||
SET id = 9993,
|
||||
description = 'MezaninneSector',
|
||||
warehouseFk = 999,
|
||||
code = 'MS',
|
||||
isPackagingArea = FALSE,
|
||||
sonFk = 9991,
|
||||
isMain = TRUE,
|
||||
itemPackingTypeFk = NULL;
|
||||
|
||||
|
||||
INSERT INTO vn.parking (id,sectorFk, code, pickingOrder)
|
||||
VALUES (4,9991, 'A-01-1', 1),
|
||||
(5,9991, 'A-02-2', 2),
|
||||
(6,9991, 'A-03-3', 3),
|
||||
(7,9991, 'A-04-4', 4),
|
||||
(8,9991, 'A-05-5', 5),
|
||||
(9,9992, 'P-01-1', 6),
|
||||
(10,9992, 'P-02-2', 7),
|
||||
(11,9992, 'P-03-3', 8),
|
||||
(12,9993, 'M-01-1', 9),
|
||||
(13,9993, 'M-02-2', 10),
|
||||
(14,9993, 'M-03-3', 11);
|
||||
|
||||
INSERT INTO vn.shelving (code, parkingFk, priority)
|
||||
VALUES ('NAA', 4, 1),
|
||||
('NBB', 5, 1),
|
||||
('NCC', 6, 1),
|
||||
('NDD', 7, 1),
|
||||
('NEE', 8, 1),
|
||||
('PAA', 9, 1),
|
||||
('PBB', 10, 1),
|
||||
('PCC', 11, 1),
|
||||
('MAA', 12, 1),
|
||||
('MBB', 13, 1),
|
||||
('MCC', 14, 1);
|
||||
|
||||
INSERT IGNORE INTO vn.itemType
|
||||
SET id = 999,
|
||||
code = 'WOO',
|
||||
name = 'Wood Objects',
|
||||
categoryFk = 3,
|
||||
workerFk = 103,
|
||||
isInventory = TRUE,
|
||||
life = 10,
|
||||
density = 250,
|
||||
itemPackingTypeFk = NULL,
|
||||
temperatureFk = 'warm';
|
||||
|
||||
INSERT IGNORE INTO vn.travel
|
||||
SET id = 99,
|
||||
shipped = CURDATE(),
|
||||
landed = CURDATE(),
|
||||
warehouseInFk = 999,
|
||||
warehouseOutFk = 1,
|
||||
isReceived = TRUE;
|
||||
|
||||
INSERT INTO vn.entry
|
||||
SET id = 999,
|
||||
supplierFk = 791,
|
||||
isConfirmed = TRUE,
|
||||
dated = CURDATE(),
|
||||
travelFk = 99,
|
||||
companyFk = 442;
|
||||
|
||||
INSERT INTO vn.ticket
|
||||
SET id = 999999,
|
||||
clientFk = 2,
|
||||
warehouseFk = 999,
|
||||
shipped = CURDATE(),
|
||||
nickname = 'Cliente',
|
||||
addressFk = 1,
|
||||
companyFk = 442,
|
||||
agencyModeFk = 10,
|
||||
landed = CURDATE();
|
||||
|
||||
INSERT INTO vn.collection
|
||||
SET id = 10101010,
|
||||
workerFk = 9;
|
||||
|
||||
INSERT IGNORE INTO vn.ticketCollection
|
||||
SET id = 10101010,
|
||||
ticketFk = 999999,
|
||||
collectionFk = 10101010;
|
||||
|
||||
INSERT INTO vn.item
|
||||
SET id = 999991,
|
||||
name = 'Palito para pinchos',
|
||||
`size` = 25,
|
||||
stems = NULL,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Palito para pinchos',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 6,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 9999991,
|
||||
entryFk = 999,
|
||||
itemFk = 999991,
|
||||
quantity = 8,
|
||||
buyingValue = 0.61,
|
||||
stickers = 1,
|
||||
packing = 20,
|
||||
`grouping` = 1,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 50;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 99991,
|
||||
itemFk = 999991,
|
||||
ticketFk = 999999,
|
||||
concept = 'Palito para pinchos',
|
||||
quantity = 3,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
INSERT INTO vn.item
|
||||
SET id = 999992,
|
||||
name = 'Madera verde',
|
||||
`size` = 10,
|
||||
stems = NULL,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Madera verde',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 50,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 9999992,
|
||||
entryFk = 999,
|
||||
itemFk = 999992,
|
||||
quantity = 40,
|
||||
buyingValue = 0.62,
|
||||
stickers = 1,
|
||||
packing = 40,
|
||||
`grouping` = 5,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 25;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 99992,
|
||||
itemFk = 999992,
|
||||
ticketFk = 999999,
|
||||
concept = 'Madera Verde',
|
||||
quantity = 10,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
INSERT INTO vn.item
|
||||
SET id = 999993,
|
||||
name = 'Madera Roja/Morada',
|
||||
`size` = 12,
|
||||
stems = 2,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Madera Roja/Morada',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 35,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 9999993,
|
||||
entryFk = 999,
|
||||
itemFk = 999993,
|
||||
quantity = 20,
|
||||
buyingValue = 0.63,
|
||||
stickers = 2,
|
||||
packing = 10,
|
||||
`grouping` = 5,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 25;
|
||||
|
||||
INSERT INTO vn.itemShelving
|
||||
SET id = 9931,
|
||||
itemFk = 999993,
|
||||
shelvingFk = 'NCC',
|
||||
visible = 10,
|
||||
`grouping` = 5,
|
||||
packing = 10;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 99993,
|
||||
itemFk = 999993,
|
||||
ticketFk = 999999,
|
||||
concept = 'Madera Roja/Morada',
|
||||
quantity = 15,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
INSERT INTO vn.item
|
||||
SET id = 999994,
|
||||
name = 'Madera Naranja',
|
||||
`size` = 18,
|
||||
stems = 1,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Madera Naranja',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 160,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 9999994,
|
||||
entryFk = 999,
|
||||
itemFk = 999994,
|
||||
quantity = 20,
|
||||
buyingValue = 0.64,
|
||||
stickers = 1,
|
||||
packing = 20,
|
||||
`grouping` = 4,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 25;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 99994,
|
||||
itemFk = 999994,
|
||||
ticketFk = 999999,
|
||||
concept = 'Madera Naranja',
|
||||
quantity = 4,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
INSERT INTO vn.item
|
||||
SET id = 999995,
|
||||
name = 'Madera Amarilla',
|
||||
`size` = 11,
|
||||
stems = 5,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Madera Amarilla',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 78,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 9999995,
|
||||
entryFk = 999,
|
||||
itemFk = 999995,
|
||||
quantity = 4,
|
||||
buyingValue = 0.65,
|
||||
stickers = 1,
|
||||
packing = 20,
|
||||
`grouping` = 1,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 35;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 99995,
|
||||
itemFk = 999995,
|
||||
ticketFk = 999999,
|
||||
concept = 'Madera Amarilla',
|
||||
quantity = 5,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
-- Palito naranja
|
||||
INSERT INTO vn.item
|
||||
SET id = 999998,
|
||||
name = 'Palito naranja',
|
||||
`size` = 11,
|
||||
stems = 1,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Palito naranja',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 78,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 9999998,
|
||||
entryFk = 999,
|
||||
itemFk = 999998,
|
||||
quantity = 80,
|
||||
buyingValue = 0.65,
|
||||
stickers = 1,
|
||||
packing = 200,
|
||||
`grouping` = 30,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 35;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 99998,
|
||||
itemFk = 999998,
|
||||
ticketFk = 999999,
|
||||
concept = 'Palito naranja',
|
||||
quantity = 60,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
-- Palito amarillo
|
||||
INSERT INTO vn.item
|
||||
SET id = 999999,
|
||||
name = 'Palito amarillo',
|
||||
`size` = 11,
|
||||
stems = 1,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Palito amarillo',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 78,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 9999999,
|
||||
entryFk = 999,
|
||||
itemFk = 999999,
|
||||
quantity = 70,
|
||||
buyingValue = 0.65,
|
||||
stickers = 1,
|
||||
packing = 500,
|
||||
`grouping` = 10,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 35;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 99999,
|
||||
itemFk = 999999,
|
||||
ticketFk = 999999,
|
||||
concept = 'Palito amarillo',
|
||||
quantity = 50,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
-- Palito azul
|
||||
INSERT INTO vn.item
|
||||
SET id = 1000000,
|
||||
name = 'Palito azul',
|
||||
`size` = 10,
|
||||
stems = 1,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Palito azul',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 78,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 10000000,
|
||||
entryFk = 999,
|
||||
itemFk = 1000000,
|
||||
quantity = 75,
|
||||
buyingValue = 0.65,
|
||||
stickers = 2,
|
||||
packing = 300,
|
||||
`grouping` = 50,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 35;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 100000,
|
||||
itemFk = 1000000,
|
||||
ticketFk = 999999,
|
||||
concept = 'Palito azul',
|
||||
quantity = 50,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
-- Palito rojo
|
||||
INSERT INTO vn.item
|
||||
SET id = 1000001,
|
||||
name = 'Palito rojo',
|
||||
`size` = 10,
|
||||
stems = NULL,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Palito rojo',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 78,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT INTO vn.buy
|
||||
SET id = 10000001,
|
||||
entryFk = 999,
|
||||
itemFk = 1000001,
|
||||
quantity = 12,
|
||||
buyingValue = 0.65,
|
||||
stickers = 2,
|
||||
packing = 50,
|
||||
`grouping` = 5,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 1,
|
||||
price2 = 1,
|
||||
price3 = 1,
|
||||
minPrice = 1,
|
||||
weight = 35;
|
||||
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET id = 100001,
|
||||
itemFk = 1000001,
|
||||
ticketFk = 999999,
|
||||
concept = 'Palito rojo',
|
||||
quantity = 10,
|
||||
price = 1,
|
||||
discount = 0;
|
||||
|
||||
-- Previa
|
||||
INSERT IGNORE INTO vn.item
|
||||
SET id = 999996,
|
||||
name = 'Bolas de madera',
|
||||
`size` = 2,
|
||||
stems = 4,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Bolas de madera',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 20,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT vn.buy
|
||||
SET id = 9999996,
|
||||
entryFk = 999,
|
||||
itemFk = 999996,
|
||||
quantity = 5,
|
||||
buyingValue = 3,
|
||||
stickers = 1,
|
||||
packing = 5,
|
||||
`grouping` = 2,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 7,
|
||||
price2 = 7,
|
||||
price3 = 7,
|
||||
minPrice = 7,
|
||||
weight = 80;
|
||||
|
||||
INSERT vn.sale
|
||||
SET id = 99996,
|
||||
itemFk = 999996,
|
||||
ticketFk = 999999,
|
||||
concept = 'Bolas de madera',
|
||||
quantity = 4,
|
||||
price = 7,
|
||||
discount = 0,
|
||||
isPicked = TRUE;
|
||||
|
||||
INSERT IGNORE INTO vn.item
|
||||
SET id = 999997,
|
||||
name = 'Palitos de polo MIX',
|
||||
`size` = 14,
|
||||
stems = NULL,
|
||||
category = 'EXT',
|
||||
typeFk = 999,
|
||||
longName = 'Palitos de polo MIX',
|
||||
itemPackingTypeFk = NULL,
|
||||
originFk = 1,
|
||||
weightByPiece = 20,
|
||||
intrastatFk = 44219999;
|
||||
|
||||
INSERT vn.buy
|
||||
SET id = 9999997,
|
||||
entryFk = 999,
|
||||
itemFk = 999997,
|
||||
quantity = 100,
|
||||
buyingValue = 3.2,
|
||||
stickers = 1,
|
||||
packing = 100,
|
||||
`grouping` = 5,
|
||||
groupingMode = 1,
|
||||
packageFk = 94,
|
||||
price1 = 7,
|
||||
price2 = 7,
|
||||
price3 = 7,
|
||||
minPrice = 7,
|
||||
weight = 80;
|
||||
|
||||
INSERT vn.sale
|
||||
SET id = 99997,
|
||||
itemFk = 999997,
|
||||
ticketFk = 999999,
|
||||
concept = 'Palitos de polo MIX',
|
||||
quantity = 5,
|
||||
price = 7,
|
||||
discount = 0;
|
||||
|
||||
USE vn;
|
||||
DELETE ish.* FROM vn.itemShelving ish
|
||||
JOIN vn.shelving sh ON sh.code = ish.shelvingFk
|
||||
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
JOIN vn.sector s ON s.id = p.sectorFk
|
||||
JOIN vn.warehouse w ON w.id = s.warehouseFk
|
||||
WHERE w.name = 'TestingWarehouse';
|
||||
|
||||
INSERT INTO vn.itemShelving
|
||||
(itemFk, shelvingFk, visible, created, `grouping`, packing, packagingFk, userFk, isChecked)
|
||||
VALUES
|
||||
(999991, 'NAA', 8, '2023-09-20', 1, 20, NULL, 103, NULL),
|
||||
(999998, 'NAA', 80, '2023-09-20', 10, 30, NULL, 103, NULL),
|
||||
(1000001, 'NAA', 6, '2023-09-20', 3, 50, NULL, 103, NULL),
|
||||
(1000000, 'NBB', 50, '2023-09-18', 25, 500, NULL, 103, NULL),
|
||||
(999993, 'NBB', 25, '2023-09-18', NULL, 10, NULL, 103, NULL),
|
||||
(999999, 'NBB', 30, '2023-09-18', 10, 500, NULL, 103, NULL),
|
||||
(999993, 'NCC', 25, '2023-09-20', 5, 10, NULL, 103, NULL),
|
||||
(999997, 'NCC', 10, '2023-09-20', NULL, 100, NULL, 103, NULL),
|
||||
(999999, 'NCC', 40, '2023-09-20', 10, 500, NULL, 103, NULL),
|
||||
(999995, 'NDD', 10, '2023-09-19', NULL, 20, NULL, 103, NULL),
|
||||
(999994, 'NDD', 48, '2023-09-19', 4, 20, NULL, 103, NULL),
|
||||
(1000001, 'NEE', 6, '2023-09-21', 3, 50, NULL, 103, NULL),
|
||||
(999992, 'NEE', 50, '2023-09-21', NULL, 1, NULL, 103, NULL),
|
||||
(1000000, 'NEE', 25, '2023-09-21', 25, 500, NULL, 103, NULL),
|
||||
(999996, 'PAA', 5, '2023-09-27', 1, 5, NULL, 103, NULL),
|
||||
(999997, 'PCC', 10, '2023-09-27', 5, 100, NULL, 103, NULL);
|
||||
|
||||
-- Previous for Bolas de madera
|
||||
INSERT IGNORE INTO vn.sectorCollection
|
||||
SET id = 99,
|
||||
userFk = 1,
|
||||
sectorFk = 9992;
|
||||
|
||||
INSERT IGNORE INTO vn.saleGroup
|
||||
SET id = 4,
|
||||
userFk = 1,
|
||||
parkingFk = 9,
|
||||
sectorFk = 9992;
|
||||
|
||||
INSERT IGNORE INTO vn.sectorCollectionSaleGroup
|
||||
SET id = 9999,
|
||||
sectorCollectionFk = 99,
|
||||
saleGroupFk = 999;
|
||||
|
||||
INSERT vn.saleGroupDetail
|
||||
SET id = 99991,
|
||||
saleFk = 99996,
|
||||
saleGroupFk = 999;
|
||||
|
||||
INSERT INTO vn.saleTracking
|
||||
SET id = 7,
|
||||
saleFk = 99996,
|
||||
isChecked = TRUE,
|
||||
workerFk = 103,
|
||||
stateFk = 28;
|
||||
|
||||
INSERT IGNORE INTO vn.itemShelvingSale
|
||||
SET id = 991,
|
||||
itemShelvingFk = 9962,
|
||||
saleFk = 99996,
|
||||
quantity = 5,
|
||||
userFk = 1;
|
||||
|
||||
UPDATE vn.ticket
|
||||
SET zoneFk=1
|
||||
WHERE id=999999;
|
||||
|
||||
UPDATE vn.collection
|
||||
SET workerFk=9
|
||||
WHERE id=10101010;
|
||||
|
||||
UPDATE vn.sale
|
||||
SET isPicked =FALSE;
|
||||
|
||||
INSERT INTO vn.machineWorkerConfig(maxHours)
|
||||
VALUES(12);
|
||||
|
||||
INSERT INTO vn.workerAppTester(workerFk) VALUES(66);
|
||||
|
||||
INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmentFk`, `type`, `use`, `productionYear`, `workerFk`, `companyFk`)
|
||||
VALUES
|
||||
('RE-003', 'IRON', 'JPH-24', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442);
|
||||
|
||||
|
||||
INSERT INTO vn.machineWorker(workerFk,machineFk,inTimed) VALUES (104,1,'2001-01-01 10:00:00.00.000');
|
||||
|
||||
UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1;
|
||||
|
||||
UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5;
|
||||
|
||||
INSERT INTO vn.report (name) VALUES ('LabelCollection');
|
|
@ -1,10 +1,6 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`clean`()
|
||||
BEGIN
|
||||
DECLARE vDateShort DATETIME;
|
||||
|
||||
SET vDateShort = TIMESTAMPADD(MONTH, -1, util.VN_CURDATE());
|
||||
|
||||
DELETE FROM cache.departure_limit WHERE Fecha < vDateShort;
|
||||
DELETE FROM cache.departure_limit WHERE Fecha < util.VN_CURDATE() - INTERVAL 1 MONTH;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`sale_checkWithoutComponents`
|
||||
ON SCHEDULE EVERY 10 MINUTE
|
||||
STARTS '2020-05-04 11:56:23.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO call sale_checkNoComponents(DATE_ADD(util.VN_NOW(), INTERVAL -10 MINUTE),DATE_ADD(util.VN_NOW(), INTERVAL -1 MINUTE))$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,52 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balanceNestTree_addChild`(
|
||||
vSelf INT,
|
||||
vName VARCHAR(45)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Agrega un nuevo nodo hijo a un nodo existente dentro de la estructura
|
||||
* de árbol de vn.balanceNestTree.
|
||||
*
|
||||
* @param vSelf Identificador del nodo
|
||||
* @param vName Nombre del nuevo nodo hijo
|
||||
*/
|
||||
DECLARE vTable VARCHAR(45) DEFAULT util.quoteIdentifier('balanceNestTree');
|
||||
DECLARE vLeft INT;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tAux
|
||||
SELECT 0 lft;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE tAux
|
||||
SET lft = (SELECT lft
|
||||
FROM ', vTable,
|
||||
' WHERE id = ?)')
|
||||
USING vSelf;
|
||||
|
||||
SELECT lft INTO vLeft FROM tAux;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable, '
|
||||
SET rgt = rgt + 2
|
||||
WHERE rgt > ?
|
||||
ORDER BY rgt DESC')
|
||||
USING vLeft;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable, '
|
||||
SET lft = lft + 2
|
||||
WHERE lft > ?
|
||||
ORDER BY lft DESC')
|
||||
USING vLeft;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'INSERT INTO ', vTable, ' (name, lft, rgt)
|
||||
VALUES(?, ? + 1, ? + 2)')
|
||||
USING vName,
|
||||
vLeft,
|
||||
vLeft;
|
||||
|
||||
DROP TEMPORARY TABLE tAux;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,53 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balanceNestTree_delete`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Elimina un nodo dentro de la estructura de árbol de vn.balanceNestTree.
|
||||
*
|
||||
* @param vSelf Identificador del nodo
|
||||
*/
|
||||
DECLARE vTable VARCHAR(45) DEFAULT util.quoteIdentifier('balanceNestTree');
|
||||
DECLARE vRight INT;
|
||||
DECLARE vLeft INT;
|
||||
DECLARE vWidth INT;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tAux
|
||||
SELECT 0 rgt, 0 lft, 0 wdt;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE tAux a
|
||||
JOIN ', vTable, ' t
|
||||
SET a.rgt = t.rgt,
|
||||
a.lft = t.lft,
|
||||
a.wdt = t.rgt - t.lft + 1
|
||||
WHERE t.id = ?')
|
||||
USING vSelf;
|
||||
|
||||
SELECT rgt, lft, wdt
|
||||
INTO vRight, vLeft, vWidth
|
||||
FROM tAux;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'DELETE FROM ', vTable,
|
||||
' WHERE lft BETWEEN ? AND ?')
|
||||
USING vLeft, vRight;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
' SET rgt = rgt - ?
|
||||
WHERE rgt > ?
|
||||
ORDER BY rgt')
|
||||
USING vWidth,vRight;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
' SET lft = lft - ?
|
||||
WHERE lft > ?
|
||||
ORDER BY lft')
|
||||
USING vWidth, vRight;
|
||||
|
||||
DROP TEMPORARY TABLE tAux;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,117 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balanceNestTree_move`(
|
||||
vSelf INT,
|
||||
vFather INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Mueve un nodo dentro de la estructura de árbol de vn.balanceNestTree.
|
||||
*
|
||||
* @param vSelf Identificador del nodo
|
||||
* @param vFather Identificador del nuevo padre del nodo
|
||||
*/
|
||||
DECLARE vTable VARCHAR(45) DEFAULT util.quoteIdentifier('balanceNestTree');
|
||||
DECLARE vRight INT;
|
||||
DECLARE vLeft INT;
|
||||
DECLARE vWidth INT;
|
||||
DECLARE vFatherRight INT;
|
||||
DECLARE vFatherLeft INT;
|
||||
DECLARE vGap INT;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tAux
|
||||
SELECT 0 rgt, 0 lft, 0 wdt, 0 frg, 0 flf;
|
||||
|
||||
-- Averiguamos el ancho de la rama
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE tAux a
|
||||
JOIN ', vTable, ' t
|
||||
SET a.wdt = t.rgt - t.lft + 1
|
||||
WHERE t.id = ?')
|
||||
USING vSelf;
|
||||
|
||||
-- Averiguamos la posicion del nuevo padre
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE tAux a
|
||||
JOIN ', vTable, ' t
|
||||
SET a.frg = t.rgt,
|
||||
a.flf = t.lft
|
||||
WHERE t.id = ?')
|
||||
USING vFather;
|
||||
|
||||
SELECT wdt, frg, flf
|
||||
INTO vWidth, vFatherRight, vFatherLeft
|
||||
FROM tAux;
|
||||
|
||||
-- 1º Incrementamos los valores de todos los nodos a la derecha
|
||||
-- del punto de inserción (vFatherRight) , para hacer sitio
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET rgt = rgt + ?
|
||||
WHERE rgt >= ?
|
||||
ORDER BY rgt DESC')
|
||||
USING vWidth,
|
||||
vFatherRight;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET lft = lft + ?
|
||||
WHERE lft >= ?
|
||||
ORDER BY lft DESC')
|
||||
USING vWidth,
|
||||
vFatherRight;
|
||||
|
||||
-- Es preciso recalcular los valores del nodo en el
|
||||
-- caso de que estuviera a la derecha del nuevo padre
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE tAux a
|
||||
JOIN ', vTable, ' t
|
||||
SET a.rgt = t.rgt,
|
||||
a.lft = t.lft
|
||||
WHERE t.id = ?')
|
||||
USING vSelf;
|
||||
|
||||
SELECT lft, rgt, frg - lft
|
||||
INTO vLeft, vRight, vGap
|
||||
FROM tAux;
|
||||
|
||||
-- 2º Incrementamos el valor de todos los nodos a
|
||||
-- trasladar hasta alcanzar su nueva posicion
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET lft = lft + ?
|
||||
WHERE lft BETWEEN ? AND ?
|
||||
ORDER BY lft DESC')
|
||||
USING vGap,
|
||||
vLeft,
|
||||
vRight;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET rgt = rgt + ?
|
||||
WHERE rgt BETWEEN ? AND ?
|
||||
ORDER BY rgt DESC')
|
||||
USING vGap,
|
||||
vLeft,
|
||||
vRight;
|
||||
|
||||
-- 3º Restaremos a todos los nodos resultantes, a la derecha
|
||||
-- de la posicion arrancada el ancho de la rama escindida
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET lft = lft - ?
|
||||
WHERE lft > ?
|
||||
ORDER BY lft')
|
||||
USING vWidth,
|
||||
vLeft;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET rgt = rgt - ?
|
||||
WHERE rgt > ?
|
||||
ORDER BY rgt')
|
||||
USING vWidth,
|
||||
vRight;
|
||||
|
||||
DROP TEMPORARY TABLE tAux;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -39,11 +39,11 @@ BEGIN
|
|||
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||
AND b.price2 > 0
|
||||
AND b.quantity > 0
|
||||
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
||||
LIMIT 10000000000000000000) sub
|
||||
GROUP BY itemFk, warehouseFk;
|
||||
|
||||
|
||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||
SELECT
|
||||
b.itemFk,
|
||||
|
|
|
@ -1,48 +1,42 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clean`()
|
||||
BEGIN
|
||||
DECLARE vDateShort DATETIME;
|
||||
DECLARE vOneYearAgo DATE;
|
||||
DECLARE vFourYearsAgo DATE;
|
||||
DECLARE vFiveYearsAgo DATE;
|
||||
DECLARE v18Month DATE;
|
||||
DECLARE v26Month DATE;
|
||||
DECLARE v3Month DATE;
|
||||
/**
|
||||
* Purges outdated data to optimize performance.
|
||||
* Exercise caution when executing.
|
||||
*/
|
||||
DECLARE v2Months DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 MONTH;
|
||||
DECLARE v3Months DATE DEFAULT util.VN_CURDATE() - INTERVAL 3 MONTH;
|
||||
DECLARE v18Months DATE DEFAULT util.VN_CURDATE() - INTERVAL 18 MONTH;
|
||||
DECLARE v26Months DATE DEFAULT util.VN_CURDATE() - INTERVAL 26 MONTH;
|
||||
DECLARE v1Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR;
|
||||
DECLARE v2Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR;
|
||||
DECLARE v4Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR;
|
||||
DECLARE v5Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 5 YEAR;
|
||||
DECLARE vTrashId VARCHAR(15);
|
||||
DECLARE v2Years DATE;
|
||||
DECLARE v5Years DATE;
|
||||
|
||||
SET vDateShort = util.VN_CURDATE() - INTERVAL 2 MONTH;
|
||||
SET vOneYearAgo = util.VN_CURDATE() - INTERVAL 1 YEAR;
|
||||
SET vFourYearsAgo = util.VN_CURDATE() - INTERVAL 4 YEAR;
|
||||
SET vFiveYearsAgo = util.VN_CURDATE() - INTERVAL 5 YEAR;
|
||||
SET v18Month = util.VN_CURDATE() - INTERVAL 18 MONTH;
|
||||
SET v26Month = util.VN_CURDATE() - INTERVAL 26 MONTH;
|
||||
SET v3Month = util.VN_CURDATE() - INTERVAL 3 MONTH;
|
||||
SET v2Years = util.VN_CURDATE() - INTERVAL 2 YEAR;
|
||||
SET v5Years = util.VN_CURDATE() - INTERVAL 5 YEAR;
|
||||
DECLARE vCompanyBlk INT;
|
||||
|
||||
DELETE FROM workerActivity WHERE created < v2Years;
|
||||
DELETE FROM ticketParking WHERE created < vDateShort;
|
||||
DELETE FROM routesMonitor WHERE dated < vDateShort;
|
||||
DELETE FROM workerTimeControlLog WHERE created < vDateShort;
|
||||
DELETE FROM `message` WHERE sendDate < vDateShort;
|
||||
DELETE FROM messageInbox WHERE sendDate < vDateShort;
|
||||
DELETE FROM messageInbox WHERE sendDate < vDateShort;
|
||||
DELETE FROM workerTimeControl WHERE timed < vFourYearsAgo;
|
||||
DELETE FROM ticketParking WHERE created < v2Months;
|
||||
DELETE FROM routesMonitor WHERE dated < v2Months;
|
||||
DELETE FROM workerTimeControlLog WHERE created < v2Months;
|
||||
DELETE FROM `message` WHERE sendDate < v2Months;
|
||||
DELETE FROM messageInbox WHERE sendDate < v2Months;
|
||||
DELETE FROM messageInbox WHERE sendDate < v2Months;
|
||||
DELETE FROM workerTimeControl WHERE timed < v4Years;
|
||||
DELETE FROM itemShelving WHERE created < util.VN_CURDATE() AND visible = 0;
|
||||
DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,util.VN_CURDATE());
|
||||
DELETE FROM entryLog WHERE creationDate < vDateShort;
|
||||
DELETE IGNORE FROM expedition WHERE created < v26Month;
|
||||
DELETE FROM sms WHERE created < v18Month;
|
||||
DELETE FROM saleTracking WHERE created < vOneYearAgo;
|
||||
DELETE FROM ticketTracking WHERE created < v18Month;
|
||||
DELETE FROM ticketDown WHERE created < util.yesterday();
|
||||
DELETE FROM entryLog WHERE creationDate < v2Months;
|
||||
DELETE IGNORE FROM expedition WHERE created < v26Months;
|
||||
DELETE FROM sms WHERE created < v18Months;
|
||||
DELETE FROM saleTracking WHERE created < v1Years;
|
||||
DELETE FROM ticketTracking WHERE created < v18Months;
|
||||
DELETE tobs FROM ticketObservation tobs
|
||||
JOIN ticket t ON tobs.ticketFk = t.id
|
||||
WHERE t.shipped < v5Years;
|
||||
DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < vOneYearAgo;
|
||||
DELETE FROM sharingCart where ended < vDateShort;
|
||||
DELETE FROM sharingClient where ended < vDateShort;
|
||||
DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < v1Years;
|
||||
DELETE FROM sharingCart where ended < v2Months;
|
||||
DELETE FROM sharingClient where ended < v2Months;
|
||||
DELETE tw.* FROM ticketWeekly tw
|
||||
LEFT JOIN sale s ON s.ticketFk = tw.ticketFk
|
||||
LEFT JOIN ticketRequest tr ON tr.ticketFk = tw.ticketFk
|
||||
|
@ -50,144 +44,174 @@ BEGIN
|
|||
WHERE s.id IS NULL
|
||||
AND tr.id IS NULL
|
||||
AND ts.id IS NULL;
|
||||
DELETE FROM claim WHERE ticketCreated < vFourYearsAgo;
|
||||
DELETE FROM message WHERE sendDate < vDateShort;
|
||||
-- Robert ubicacion anterior de trevelLog comentario para debug
|
||||
DELETE FROM zoneEvent WHERE `type` = 'day' AND dated < v3Month;
|
||||
DELETE FROM claim WHERE ticketCreated < v4Years;
|
||||
-- Robert ubicacion anterior de travelLog comentario para debug
|
||||
DELETE FROM zoneEvent WHERE `type` = 'day' AND dated < v3Months;
|
||||
DELETE bm
|
||||
FROM buyMark bm
|
||||
JOIN buy b ON b.id = bm.id
|
||||
JOIN entry e ON e.id = b.entryFk
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
WHERE t.landed <= vDateShort;
|
||||
DELETE b FROM vn.buy b
|
||||
JOIN vn.entryConfig e ON e.defaultEntry = b.entryFk
|
||||
WHERE b.created < vDateShort;
|
||||
DELETE FROM vn.itemShelvingLog WHERE created < vDateShort;
|
||||
DELETE FROM vn.stockBuyed WHERE creationDate < vDateShort;
|
||||
DELETE FROM vn.itemCleanLog WHERE created < util.VN_NOW() - INTERVAL 1 YEAR;
|
||||
DELETE FROM printQueue WHERE statusCode = 'printed' AND created < vDateShort;
|
||||
DELETE FROM ticketLog WHERE creationDate <= vFiveYearsAgo;
|
||||
WHERE t.landed <= v2Months;
|
||||
DELETE b FROM buy b
|
||||
JOIN entryConfig e ON e.defaultEntry = b.entryFk
|
||||
WHERE b.created < v2Months;
|
||||
DELETE FROM itemShelvingLog WHERE created < v2Months;
|
||||
DELETE FROM stockBuyed WHERE creationDate < v2Months;
|
||||
DELETE FROM itemCleanLog WHERE created < util.VN_NOW() - INTERVAL 1 YEAR;
|
||||
DELETE FROM printQueue WHERE statusCode = 'printed' AND created < v2Months;
|
||||
DELETE FROM ticketLog WHERE creationDate <= v5Years;
|
||||
-- Equipos duplicados
|
||||
DELETE w.*
|
||||
FROM workerTeam w
|
||||
JOIN (SELECT id, team, workerFk, COUNT(*) - 1 as duplicated
|
||||
JOIN (
|
||||
SELECT id, team, workerFk, COUNT(*) - 1 duplicated
|
||||
FROM workerTeam
|
||||
GROUP BY team,workerFk
|
||||
HAVING duplicated
|
||||
) d ON d.team = w.team AND d.workerFk = w.workerFk AND d.id != w.id;
|
||||
) d ON d.team = w.team
|
||||
AND d.workerFk = w.workerFk
|
||||
AND d.id <> w.id;
|
||||
|
||||
DELETE sc
|
||||
FROM saleComponent sc
|
||||
JOIN sale s ON s.id= sc.saleFk
|
||||
JOIN ticket t ON t.id= s.ticketFk
|
||||
WHERE t.shipped < v18Month;
|
||||
WHERE t.shipped < v18Months;
|
||||
|
||||
DELETE c
|
||||
FROM vn.claim c
|
||||
JOIN vn.claimState cs ON cs.id = c.claimStateFk
|
||||
WHERE cs.description = "Anulado" AND
|
||||
c.created < vDateShort;
|
||||
DELETE
|
||||
FROM vn.expeditionTruck
|
||||
WHERE eta < v3Month;
|
||||
FROM claim c
|
||||
JOIN claimState cs ON cs.id = c.claimStateFk
|
||||
WHERE cs.description = 'Anulado'
|
||||
AND c.created < v2Months;
|
||||
|
||||
DELETE FROM XDiario WHERE FECHA < v3Month OR FECHA IS NULL;
|
||||
-- borrar travels sin entradas
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete;
|
||||
CREATE TEMPORARY TABLE tmp.thermographToDelete
|
||||
DELETE FROM expeditionTruck WHERE eta < v3Months;
|
||||
DELETE FROM XDiario WHERE FECHA < v3Months OR FECHA IS NULL;
|
||||
|
||||
-- Borrar travels sin entradas
|
||||
CREATE OR REPLACE TEMPORARY TABLE tThermographToDelete
|
||||
SELECT th.id,th.dmsFk
|
||||
FROM vn.travel t
|
||||
LEFT JOIN vn.entry e ON e.travelFk = t.id
|
||||
JOIN vn.travelThermograph th ON th.travelFk = t.id
|
||||
WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL;
|
||||
FROM travel t
|
||||
LEFT JOIN entry e ON e.travelFk = t.id
|
||||
JOIN travelThermograph th ON th.travelFk = t.id
|
||||
WHERE t.shipped < v3Months
|
||||
AND e.travelFk IS NULL;
|
||||
|
||||
SELECT dt.id INTO vTrashId
|
||||
FROM vn.dmsType dt
|
||||
FROM dmsType dt
|
||||
WHERE dt.code = 'trash';
|
||||
|
||||
UPDATE tmp.thermographToDelete th
|
||||
JOIN vn.dms d ON d.id = th.dmsFk
|
||||
UPDATE tThermographToDelete th
|
||||
JOIN dms d ON d.id = th.dmsFk
|
||||
SET d.dmsTypeFk = vTrashId;
|
||||
|
||||
DELETE th
|
||||
FROM tmp.thermographToDelete tmp
|
||||
JOIN vn.travelThermograph th ON th.id = tmp.id;
|
||||
FROM tThermographToDelete tmp
|
||||
JOIN travelThermograph th ON th.id = tmp.id;
|
||||
|
||||
DELETE t
|
||||
FROM vn.travel t
|
||||
LEFT JOIN vn.entry e ON e.travelFk = t.id
|
||||
WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL;
|
||||
FROM travel t
|
||||
LEFT JOIN entry e ON e.travelFk = t.id
|
||||
WHERE t.shipped < v3Months AND e.travelFk IS NULL;
|
||||
|
||||
UPDATE dms d
|
||||
JOIN dmsType dt ON dt.id = d.dmsTypeFk
|
||||
SET d.dmsTypeFk = vTrashId
|
||||
WHERE created < TIMESTAMPADD(MONTH, -dt.monthToDelete, util.VN_CURDATE());
|
||||
WHERE created < util.VN_CURDATE() - INTERVAL dt.monthToDelete MONTH;
|
||||
|
||||
-- borrar entradas sin compras
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete;
|
||||
CREATE TEMPORARY TABLE tmp.entryToDelete
|
||||
CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete
|
||||
SELECT e.*
|
||||
FROM vn.entry e
|
||||
LEFT JOIN vn.buy b ON b.entryFk = e.id
|
||||
JOIN vn.entryConfig ec ON e.id != ec.defaultEntry
|
||||
WHERE e.dated < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND b.entryFK IS NULL;
|
||||
FROM entry e
|
||||
LEFT JOIN buy b ON b.entryFk = e.id
|
||||
JOIN entryConfig ec ON e.id <> ec.defaultEntry
|
||||
WHERE e.dated < v3Months
|
||||
AND b.entryFK IS NULL;
|
||||
|
||||
DELETE e
|
||||
FROM vn.entry e
|
||||
JOIN tmp.entryToDelete tmp ON tmp.id = e.id;
|
||||
FROM entry e
|
||||
JOIN tEntryToDelete tmp ON tmp.id = e.id;
|
||||
|
||||
-- borrar de route registros menores a 4 años
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.routeToDelete;
|
||||
CREATE TEMPORARY TABLE tmp.routeToDelete
|
||||
CREATE OR REPLACE TEMPORARY TABLE tRouteToDelete
|
||||
SELECT *
|
||||
FROM vn.route r
|
||||
WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE());
|
||||
FROM route r
|
||||
WHERE created < v4Years;
|
||||
|
||||
UPDATE tmp.routeToDelete tmp
|
||||
JOIN vn.dms d ON d.id = tmp.gestdocFk
|
||||
UPDATE tRouteToDelete tmp
|
||||
JOIN dms d ON d.id = tmp.gestdocFk
|
||||
SET d.dmsTypeFk = vTrashId;
|
||||
|
||||
DELETE r
|
||||
FROM tmp.routeToDelete tmp
|
||||
JOIN vn.route r ON r.id = tmp.id;
|
||||
FROM tRouteToDelete tmp
|
||||
JOIN route r ON r.id = tmp.id;
|
||||
|
||||
-- borrar registros de dua y awb menores a 2 años
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete;
|
||||
CREATE TEMPORARY TABLE tmp.duaToDelete
|
||||
CREATE OR REPLACE TEMPORARY TABLE tDuaToDelete
|
||||
SELECT *
|
||||
FROM vn.dua
|
||||
WHERE operated < TIMESTAMPADD(YEAR,-2,CURDATE());
|
||||
FROM dua
|
||||
WHERE operated < v2Years;
|
||||
|
||||
UPDATE tmp.duaToDelete tm
|
||||
JOIN vn.dms d ON d.id = tm.gestdocFk
|
||||
UPDATE tDuaToDelete tm
|
||||
JOIN dms d ON d.id = tm.gestdocFk
|
||||
SET d.dmsTypeFk = vTrashId;
|
||||
|
||||
DELETE d
|
||||
FROM tmp.duaToDelete tmp
|
||||
JOIN vn.dua d ON d.id = tmp.id;
|
||||
FROM tDuaToDelete tmp
|
||||
JOIN dua d ON d.id = tmp.id;
|
||||
|
||||
DELETE a
|
||||
FROM vn.awb a
|
||||
LEFT JOIN vn.travel t ON t.awbFk = a.id
|
||||
FROM awb a
|
||||
LEFT JOIN travel t ON t.awbFk = a.id
|
||||
WHERE a.created < v2Years
|
||||
AND t.id IS NULL;
|
||||
|
||||
-- Borra los registros de collection y ticketcollection
|
||||
DELETE FROM vn.collection WHERE created < vDateShort;
|
||||
DELETE FROM collection WHERE created < v2Months;
|
||||
DELETE FROM travelLog WHERE creationDate < v3Months;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete;
|
||||
|
||||
DELETE FROM travelLog WHERE creationDate < v3Month;
|
||||
|
||||
CALL shelving_clean;
|
||||
CALL shelving_clean();
|
||||
|
||||
DELETE FROM chat WHERE dated < v5Years;
|
||||
DELETE tt FROM ticketTracking tt
|
||||
JOIN ticket t ON tt.ticketFk = t.id
|
||||
WHERE t.shipped <= v2Months;
|
||||
|
||||
DELETE tt FROM ticketTracking tt JOIN vn.ticket t ON tt.ticketFk = t.id
|
||||
WHERE t.shipped <= vDateShort;
|
||||
DELETE FROM mail WHERE creationDate < v2Months;
|
||||
DELETE FROM split WHERE dated < v18Months;
|
||||
DELETE FROM remittance WHERE dated < v18Months;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tTicketDelete
|
||||
SELECT DISTINCT tl.originFk ticketFk
|
||||
FROM ticketLog tl
|
||||
JOIN (
|
||||
SELECT MAX(tl.id)ids
|
||||
FROM ticket t
|
||||
JOIN ticketLog tl ON tl.originFk = t.id
|
||||
WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31'
|
||||
AND t.isDeleted
|
||||
GROUP BY t.id
|
||||
) sub ON sub.ids = tl.id
|
||||
WHERE tl.creationDate <= util.VN_CURDATE() - INTERVAL 60 DAY;
|
||||
DELETE t
|
||||
FROM ticket t
|
||||
JOIN tTicketDelete tmp ON tmp.ticketFk = t.id;
|
||||
|
||||
-- Tickets Nulos PAK 11/10/2016
|
||||
SELECT id INTO vCompanyBlk FROM company WHERE code = 'BLK';
|
||||
UPDATE ticket
|
||||
SET companyFk = vCompanyBlk
|
||||
WHERE clientFk = (SELECT id FROM client WHERE name = 'AUTOCONSUMO')
|
||||
AND companyFk <> vCompanyBlk;
|
||||
|
||||
DROP TEMPORARY TABLE tTicketDelete,
|
||||
tThermographToDelete,
|
||||
tEntryToDelete,
|
||||
tDuaToDelete,
|
||||
tRouteToDelete;
|
||||
|
||||
-- Other schemas
|
||||
DELETE FROM hedera.`order` WHERE date_send < v18Months;
|
||||
DELETE FROM pbx.cdr WHERE call_date < v18Months;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`confection_controlSource`(
|
||||
vDated DATE,
|
||||
vScopeDays INT,
|
||||
vMaxAlertLevel INT,
|
||||
vWarehouseFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Obtiene la información para el control de confección,
|
||||
* ya sean tickets y/o entradas.
|
||||
*
|
||||
* @param vDated Fecha a calcular
|
||||
* @param vScopeDays Número de días desde hoy en adelante que entran en el cálculo.
|
||||
* @param vMaxAlertLevel Id nivel de alerta
|
||||
* @param vWarehouseFk Id de almacén
|
||||
*/
|
||||
DECLARE vEndingDate DATETIME DEFAULT util.dayEnd(vDated) + INTERVAL vScopeDays DAY;
|
||||
|
||||
SELECT t.shipped,
|
||||
t.id ticketFk,
|
||||
s.id saleFk,
|
||||
s.quantity,
|
||||
s.concept,
|
||||
ABS(s.reserved) isReserved,
|
||||
i.category,
|
||||
it.name itemType,
|
||||
t.nickname,
|
||||
wh.name warehouse,
|
||||
t.warehouseFk warehouseFk,
|
||||
a.provinceFk,
|
||||
am.agencyFk,
|
||||
ct.description,
|
||||
stock.visible,
|
||||
stock.available
|
||||
FROM ticket t
|
||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
JOIN warehouse wh ON wh.id = t.warehouseFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN confectionType ct ON ct.id = it.making
|
||||
JOIN `address` a on a.id = t.addressFk
|
||||
LEFT JOIN ticketState tls on tls.ticketFk = t.id
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT item_id,
|
||||
SUM(visible) visible,
|
||||
SUM(available) available
|
||||
FROM (
|
||||
SELECT a.item_id,
|
||||
0 visible,
|
||||
a.available
|
||||
FROM cache.cache_calc cc
|
||||
LEFT JOIN cache.available a ON a.calc_id = cc.id
|
||||
WHERE cc.cache_id IN ('visible', 'available')
|
||||
AND cc.params = CONCAT(vWarehouseFk, "/", util.VN_CURDATE())
|
||||
UNION ALL
|
||||
SELECT v.item_id,
|
||||
v.visible,
|
||||
0
|
||||
FROM cache.cache_calc cc
|
||||
LEFT JOIN cache.visible v ON v.calc_id = cc.id
|
||||
WHERE cc.cacheName IN ('visible', 'available')
|
||||
AND cc.params = vWarehouseFk
|
||||
) sub
|
||||
GROUP BY item_id
|
||||
) stock ON stock.item_id = s.itemFk
|
||||
WHERE it.making
|
||||
AND tls.alertLevel < vMaxAlertLevel
|
||||
AND wh.hasConfectionTeam
|
||||
AND t.shipped BETWEEN vDated AND vEndingDate
|
||||
AND s.quantity > 0
|
||||
UNION ALL
|
||||
SELECT tr.shipped,
|
||||
e.id,
|
||||
NULL,
|
||||
b.quantity,
|
||||
i.name,
|
||||
NULL,
|
||||
i.category,
|
||||
NULL,
|
||||
whi.name,
|
||||
who.name,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ct.description,
|
||||
NULL,
|
||||
NULL
|
||||
FROM buy b
|
||||
JOIN `entry` e ON e.id = b.entryFk
|
||||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN warehouse whi ON whi.id = tr.warehouseInFk
|
||||
JOIN warehouse who ON who.id = tr.warehouseOutFk
|
||||
JOIN item i ON i.id = b.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN confectionType ct ON ct.id = it.making
|
||||
WHERE who.hasConfectionTeam
|
||||
AND it.making
|
||||
AND tr.shipped BETWEEN vDated AND vEndingDate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -13,15 +13,15 @@ BEGIN
|
|||
DECLARE vWarehouseIn INT;
|
||||
DECLARE vWarehouseOut INT;
|
||||
DECLARE vCalcVisible INT;
|
||||
DECLARE vInventoryDate DATE DEFAULT vn.getInventoryDate();
|
||||
DECLARE vInventoryDate DATE DEFAULT getInventoryDate();
|
||||
|
||||
SELECT shipped, landed, warehouseInFk, warehouseOutFk
|
||||
INTO vDateShipped, vDateLanded, vWarehouseIn, vWarehouseOut
|
||||
FROM vn.travel t
|
||||
JOIN vn.entry e ON e.travelFk = t.id
|
||||
FROM travel t
|
||||
JOIN entry e ON e.travelFk = t.id
|
||||
WHERE e.id = vSelf;
|
||||
|
||||
CALL vn.rate_getPrices(vDateShipped, vWarehouseIn);
|
||||
CALL rate_getPrices(vDateShipped, vWarehouseIn);
|
||||
|
||||
-- Traslado en almacen origen
|
||||
CREATE OR REPLACE TEMPORARY TABLE tBuy
|
||||
|
@ -84,7 +84,7 @@ BEGIN
|
|||
WHERE a.available
|
||||
ON DUPLICATE KEY UPDATE availableLanding = a.available;
|
||||
ELSE
|
||||
CALL vn.item_getStock(vWarehouseOut, vDateShipped, NULL);
|
||||
CALL item_getStock(vWarehouseOut, vDateShipped, NULL);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tItem
|
||||
(UNIQUE INDEX i USING HASH (itemFk))
|
||||
|
@ -97,7 +97,7 @@ BEGIN
|
|||
FROM tmp.itemList;
|
||||
END IF;
|
||||
|
||||
CALL vn.buyUltimateFromInterval(vWarehouseIn,vInventoryDate, vDateLanded);
|
||||
CALL buyUltimateFromInterval(vWarehouseIn,vInventoryDate, vDateLanded);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tTransfer
|
||||
ENGINE = MEMORY
|
||||
|
@ -145,26 +145,26 @@ BEGIN
|
|||
b.id buyFkOrigin,
|
||||
pa.returnCost,
|
||||
b.weight
|
||||
FROM vn.item i
|
||||
FROM item i
|
||||
JOIN tItem ti ON ti.itemFk = i.id
|
||||
LEFT JOIN vn.producer p ON p.id = i.producerFk
|
||||
LEFT JOIN vn.itemType it ON it.id = i.typeFk
|
||||
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN vn.origin o ON o.id = i.originFk
|
||||
LEFT JOIN producer p ON p.id = i.producerFk
|
||||
LEFT JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN origin o ON o.id = i.originFk
|
||||
LEFT JOIN tBuy lb ON lb.itemFk = i.id
|
||||
LEFT JOIN vn.buy b ON b.id = lb.buyFk
|
||||
LEFT JOIN vn.packaging pa ON pa.id = b.packagingFk
|
||||
LEFT JOIN vn.entry e2 ON e2.id = b.entryFk
|
||||
LEFT JOIN vn.supplier s ON s.id = e2.supplierFk
|
||||
LEFT JOIN vn.entry e ON e.id = vSelf
|
||||
LEFT JOIN vn.travel tr ON tr.id = e.travelFk
|
||||
LEFT JOIN vn.agencyMode am ON am.id = tr.agencyModeFk
|
||||
LEFT JOIN vn.buy b2 ON b2.itemFk = i.id
|
||||
LEFT JOIN buy b ON b.id = lb.buyFk
|
||||
LEFT JOIN packaging pa ON pa.id = b.packagingFk
|
||||
LEFT JOIN entry e2 ON e2.id = b.entryFk
|
||||
LEFT JOIN supplier s ON s.id = e2.supplierFk
|
||||
LEFT JOIN entry e ON e.id = vSelf
|
||||
LEFT JOIN travel tr ON tr.id = e.travelFk
|
||||
LEFT JOIN agencyMode am ON am.id = tr.agencyModeFk
|
||||
LEFT JOIN buy b2 ON b2.itemFk = i.id
|
||||
AND b2.entryFk = vSelf
|
||||
LEFT JOIN vn.packaging pa2 ON pa2.id = b.packagingFk
|
||||
LEFT JOIN packaging pa2 ON pa2.id = b.packagingFk
|
||||
LEFT JOIN tmp.rate r ON TRUE
|
||||
LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = i.id
|
||||
LEFT JOIN vn.buy b3 ON b3.id = bufi.buyFk
|
||||
LEFT JOIN buy b3 ON b3.id = bufi.buyFk
|
||||
WHERE ic.display
|
||||
AND NOT e.isRaid
|
||||
AND (ti.visible OR ti.available)
|
||||
|
@ -172,11 +172,6 @@ BEGIN
|
|||
|
||||
CREATE INDEX tIndex USING HASH ON tTransfer (itemFk);
|
||||
|
||||
SET @carriage := 0;
|
||||
SET @comission := 0;
|
||||
SET @packaging := 0;
|
||||
SET @rate3 := 0;
|
||||
SET @cost := 0;
|
||||
SELECT *,
|
||||
quantity - MOD(quantity , `grouping`) subQuantity,
|
||||
MOD(quantity, `grouping`) soll,
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal`(vItemFk INT, vTicketFk INT,vShowType BOOL)
|
||||
BEGIN
|
||||
|
||||
/**
|
||||
* Propone articulos disponible ordenado, con la cantidad de veces usado y segun sus caracteristicas
|
||||
*
|
||||
* @param vItemFk item id
|
||||
* @param vTicketFk ticket id
|
||||
* @param vShowType mostrar tipos
|
||||
*/
|
||||
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vCalcFk INT;
|
||||
DECLARE vTypeFk INT;
|
||||
|
||||
DECLARE vTag1 VARCHAR(25);
|
||||
DECLARE vTag5 VARCHAR(25);
|
||||
DECLARE vTag6 VARCHAR(25);
|
||||
DECLARE vTag7 VARCHAR(25);
|
||||
DECLARE vTag8 VARCHAR(25);
|
||||
|
||||
DECLARE vValue1 VARCHAR(50);
|
||||
DECLARE vValue5 VARCHAR(50);
|
||||
DECLARE vValue6 VARCHAR(50);
|
||||
DECLARE vValue7 VARCHAR(50);
|
||||
DECLARE vValue8 VARCHAR(50);
|
||||
|
||||
SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped
|
||||
FROM vn.ticket
|
||||
WHERE id = vTicketFk;
|
||||
|
||||
SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value
|
||||
INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1
|
||||
FROM vn.item i
|
||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
||||
WHERE i.id = vItemFk;
|
||||
|
||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped);
|
||||
|
||||
SELECT i.id itemFk,
|
||||
i.longName,
|
||||
i.subName,
|
||||
i.tag5,
|
||||
i.value5,
|
||||
(i.value5 <=> vValue5 COLLATE utf8_general_ci) match5,
|
||||
i.tag6,
|
||||
i.value6,
|
||||
(i.value6 <=> vValue6 COLLATE utf8_general_ci) match6,
|
||||
i.tag7,
|
||||
i.value7,
|
||||
(i.value7 <=> vValue7 COLLATE utf8_general_ci) match7,
|
||||
i.tag8,
|
||||
i.value8,
|
||||
(i.value8 <=> vValue8 COLLATE utf8_general_ci) match8,
|
||||
a.available,
|
||||
IFNULL(ip.counter,0) counter,
|
||||
IF(b.groupingMode = 1, b.grouping, b.packing) as minQuantity,
|
||||
iss.visible located
|
||||
FROM item i
|
||||
JOIN cache.available a ON a.item_id = i.id
|
||||
LEFT JOIN itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk
|
||||
LEFT JOIN itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
||||
LEFT JOIN tag t1 ON t1.id = it1.tagFk
|
||||
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN buy b ON b.id = lb.buy_id
|
||||
LEFT JOIN itemShelvingStock iss ON iss.itemFk = i.id AND iss.warehouseFk = vWarehouseFk
|
||||
WHERE a.calc_id = vCalcFk
|
||||
AND available > 0
|
||||
AND IF(vShowType,i.typeFk = vTypeFk,true)
|
||||
AND i.id != vItemFk
|
||||
ORDER BY counter DESC,
|
||||
(t1.name = vTag1 COLLATE utf8_general_ci) DESC,
|
||||
(it1.value = vValue1 COLLATE utf8_general_ci) DESC,
|
||||
(i.tag5 = vTag5 COLLATE utf8_general_ci) DESC,
|
||||
(i.value5 = vValue5 COLLATE utf8_general_ci) DESC,
|
||||
(i.tag6 = vTag6 COLLATE utf8_general_ci) DESC,
|
||||
(i.value6 = vValue6 COLLATE utf8_general_ci) DESC,
|
||||
(i.tag7 = vTag7 COLLATE utf8_general_ci) DESC,
|
||||
(i.value7 = vValue7 COLLATE utf8_general_ci) DESC,
|
||||
(i.tag8 = vTag8 COLLATE utf8_general_ci) DESC,
|
||||
(i.value8 = vValue8 COLLATE utf8_general_ci) DESC;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,76 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal_beta`(vItemFk INT, vTicketFk INT)
|
||||
BEGIN
|
||||
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vCalcFk INT;
|
||||
DECLARE vTypeFk INT;
|
||||
DECLARE vResultsMax INT DEFAULT 10;
|
||||
|
||||
DECLARE vTag1 VARCHAR(25);
|
||||
DECLARE vTag5 VARCHAR(25);
|
||||
DECLARE vTag6 VARCHAR(25);
|
||||
DECLARE vTag7 VARCHAR(25);
|
||||
DECLARE vTag8 VARCHAR(25);
|
||||
|
||||
DECLARE vValue1 VARCHAR(50);
|
||||
DECLARE vValue5 VARCHAR(50);
|
||||
DECLARE vValue6 VARCHAR(50);
|
||||
DECLARE vValue7 VARCHAR(50);
|
||||
DECLARE vValue8 VARCHAR(50);
|
||||
|
||||
SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped
|
||||
FROM vn.ticket
|
||||
WHERE id = vTicketFk;
|
||||
|
||||
SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value
|
||||
INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1
|
||||
FROM vn.item i
|
||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
||||
WHERE i.id = vItemFk;
|
||||
|
||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped);
|
||||
|
||||
SELECT i.id itemFk,
|
||||
i.longName,
|
||||
i.subName,
|
||||
i.tag5,
|
||||
i.value5,
|
||||
(i.value5 <=> vValue5 COLLATE utf8_general_ci) match5,
|
||||
i.tag6,
|
||||
i.value6,
|
||||
(i.value6 <=> vValue6 COLLATE utf8_general_ci) match6,
|
||||
i.tag7,
|
||||
i.value7,
|
||||
(i.value7 <=> vValue7 COLLATE utf8_general_ci) match7,
|
||||
i.tag8,
|
||||
i.value8,
|
||||
(i.value8 <=> vValue8 COLLATE utf8_general_ci) match8,
|
||||
a.available,
|
||||
IFNULL(ip.counter,0) counter
|
||||
FROM vn.item i
|
||||
JOIN cache.available a ON a.item_id = i.id
|
||||
LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk
|
||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
||||
WHERE a.calc_id = vCalcFk
|
||||
AND available > 0
|
||||
AND i.typeFk = vTypeFk
|
||||
AND i.id != vItemFk
|
||||
ORDER BY counter DESC,
|
||||
(t1.name = vTag1 COLLATE utf8_general_ci) DESC,
|
||||
(it1.value = vValue1 COLLATE utf8_general_ci) DESC,
|
||||
(i.tag5 = vTag5 COLLATE utf8_general_ci) DESC,
|
||||
(i.value5 = vValue5 COLLATE utf8_general_ci) DESC,
|
||||
(i.tag6 = vTag6 COLLATE utf8_general_ci) DESC,
|
||||
(i.value6 = vValue6 COLLATE utf8_general_ci) DESC,
|
||||
(i.tag7 = vTag7 COLLATE utf8_general_ci) DESC,
|
||||
(i.value7 = vValue7 COLLATE utf8_general_ci) DESC,
|
||||
(i.tag8 = vTag8 COLLATE utf8_general_ci) DESC,
|
||||
(i.value8 = vValue8 COLLATE utf8_general_ci) DESC
|
||||
LIMIT vResultsMax;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -30,10 +30,11 @@ BEGIN
|
|||
ish.visible,
|
||||
p.sectorFk,
|
||||
it.workerFk buyer,
|
||||
CONCAT('http:',ic.url, '/catalog/1600x900/',i.image) urlImage,
|
||||
ic.url,
|
||||
i.image,
|
||||
ish.isChecked,
|
||||
CASE
|
||||
WHEN s.notPrepared > sm.parked THEN 0
|
||||
WHEN IFNULL (s.notPrepared, 0) > sm.parked THEN 0
|
||||
WHEN sm.visible > sm.parked THEN 1
|
||||
ELSE 2
|
||||
END priority
|
||||
|
@ -43,7 +44,7 @@ BEGIN
|
|||
JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk
|
||||
JOIN shelving sh ON sh.code = ish.shelvingFk
|
||||
JOIN parking p ON p.id = sh.parkingFk
|
||||
JOIN (
|
||||
LEFT JOIN (
|
||||
SELECT s.itemFk, sum(s.quantity) notPrepared
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getSimilar`(vItemFk INT, vWarehouseFk INT, vDate DATE, vIsShowedByType BOOL)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getSimilar`(
|
||||
vSelf INT,
|
||||
vWarehouseFk INT,
|
||||
vDated DATE,
|
||||
vShowType BOOL
|
||||
)
|
||||
BEGIN
|
||||
|
||||
/**
|
||||
* Propone articulos similares para posible cambio,
|
||||
* ordenado con la cantidad de veces usado y segun sus caracteristicas
|
||||
*
|
||||
* @param vItemFk item id
|
||||
* @param vWarehouseFk warehouse id
|
||||
* @param vDate fecha para revisar disponible
|
||||
* @param vIsShowedByType para mostrar solo artículos de ese tipo
|
||||
*/
|
||||
* Propone articulos disponibles ordenados, con la cantidad
|
||||
* de veces usado y segun sus caracteristicas.
|
||||
*
|
||||
* @param vSelf Id de artículo
|
||||
* @param vWarehouseFk Id de almacen
|
||||
* @param vDated Fecha
|
||||
* @param vShowType Mostrar tipos
|
||||
*/
|
||||
DECLARE vCalcFk INT;
|
||||
DECLARE vTypeFk INT;
|
||||
DECLARE vPriority INT DEFAULT 1;
|
||||
|
||||
DECLARE vCalcFk INT;
|
||||
DECLARE vTypeFk INT;
|
||||
|
||||
DECLARE vTag1 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||
DECLARE vTag5 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||
DECLARE vTag6 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||
|
@ -27,58 +31,81 @@ BEGIN
|
|||
DECLARE vValue7 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||
DECLARE vValue8 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||
|
||||
|
||||
SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value
|
||||
INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1
|
||||
FROM vn.item i
|
||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
||||
WHERE i.id = vItemFk;
|
||||
|
||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDate);
|
||||
|
||||
SELECT i.id itemFk,
|
||||
i.longName,
|
||||
i.subName,
|
||||
i.tag5,
|
||||
i.value5,
|
||||
(i.value5 <=> vValue5) match5,
|
||||
i.tag6,
|
||||
i.value6,
|
||||
(i.value6 <=> vValue6) match6,
|
||||
i.tag7,
|
||||
i.value7,
|
||||
(i.value7 <=> vValue7) match7,
|
||||
i.tag8,
|
||||
i.value8,
|
||||
(i.value8 <=> vValue8) match8,
|
||||
a.available,
|
||||
IFNULL(ip.counter,0) counter,
|
||||
IF(b.groupingMode = 1, b.grouping, b.packing) as minQuantity
|
||||
FROM vn.item i
|
||||
JOIN cache.available a ON a.item_id = i.id
|
||||
LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk
|
||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
||||
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN vn.buy b ON b.id = lb.buy_id
|
||||
WHERE a.calc_id = vCalcFk
|
||||
AND available > 0
|
||||
AND IF(vIsShowedByType, i.typeFk = vTypeFk, TRUE)
|
||||
AND i.id != vItemFk
|
||||
ORDER BY counter DESC,
|
||||
(t1.name = vTag1) DESC,
|
||||
(it1.value = vValue1) DESC,
|
||||
(i.tag6 = vTag6) DESC,
|
||||
(i.value6 = vValue6) DESC,
|
||||
(i.tag5 = vTag5) DESC,
|
||||
(i.value5 = vValue5) DESC,
|
||||
(i.tag7 = vTag7) DESC,
|
||||
(i.value7 = vValue7) DESC,
|
||||
(i.tag8 = vTag8) DESC,
|
||||
(i.value8 = vValue8) DESC
|
||||
LIMIT 30;
|
||||
|
||||
SELECT typeFk,
|
||||
tag5,
|
||||
value5,
|
||||
tag6,
|
||||
value6,
|
||||
tag7,
|
||||
value7,
|
||||
tag8,
|
||||
value8,
|
||||
t.name,
|
||||
it.value
|
||||
INTO vTypeFk,
|
||||
vTag5,
|
||||
vValue5,
|
||||
vTag6,
|
||||
vValue6,
|
||||
vTag7,
|
||||
vValue7,
|
||||
vTag8,
|
||||
vValue8,
|
||||
vTag1,
|
||||
vValue1
|
||||
FROM item i
|
||||
LEFT JOIN itemTag it ON it.itemFk = i.id
|
||||
AND it.priority = vPriority
|
||||
LEFT JOIN tag t ON t.id = it.tagFk
|
||||
WHERE i.id = vSelf;
|
||||
|
||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated);
|
||||
|
||||
SELECT i.id itemFk,
|
||||
i.longName,
|
||||
i.subName,
|
||||
i.tag5,
|
||||
i.value5,
|
||||
(i.value5 <=> vValue5) match5,
|
||||
i.tag6,
|
||||
i.value6,
|
||||
(i.value6 <=> vValue6) match6,
|
||||
i.tag7,
|
||||
i.value7,
|
||||
(i.value7 <=> vValue7) match7,
|
||||
i.tag8,
|
||||
i.value8,
|
||||
(i.value8 <=> vValue8) match8,
|
||||
a.available,
|
||||
IFNULL(ip.counter, 0) `counter`,
|
||||
IF(b.groupingMode = 1, b.grouping, b.packing) minQuantity,
|
||||
iss.visible located
|
||||
FROM item i
|
||||
JOIN cache.available a ON a.item_id = i.id
|
||||
LEFT JOIN itemProposal ip ON ip.mateFk = i.id
|
||||
AND ip.itemFk = vSelf
|
||||
LEFT JOIN itemTag it ON it.itemFk = i.id
|
||||
AND it.priority = vPriority
|
||||
LEFT JOIN tag t ON t.id = it.tagFk
|
||||
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
|
||||
AND lb.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN buy b ON b.id = lb.buy_id
|
||||
LEFT JOIN itemShelvingStock iss ON iss.itemFk = i.id
|
||||
AND iss.warehouseFk = vWarehouseFk
|
||||
WHERE a.calc_id = vCalcFk
|
||||
AND a.available > 0
|
||||
AND IF(vShowType, i.typeFk = vTypeFk, TRUE)
|
||||
AND i.id <> vSelf
|
||||
ORDER BY `counter` DESC,
|
||||
(t.name = vTag1) DESC,
|
||||
(it.value = vValue1) DESC,
|
||||
(i.tag5 = vTag5) DESC,
|
||||
match5 DESC,
|
||||
(i.tag6 = vTag6) DESC,
|
||||
match6 DESC,
|
||||
(i.tag7 = vTag7) DESC,
|
||||
match7 DESC,
|
||||
(i.tag8 = vTag8) DESC,
|
||||
match8 DESC;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`payment_add`(
|
||||
vDated DATE,
|
||||
vSupplierFk INT,
|
||||
vAmount DOUBLE,
|
||||
vCurrencyFk INT,
|
||||
vForeignValue DOUBLE,
|
||||
vBankFk INT,
|
||||
vPayMethodFk INT,
|
||||
vExpenseFk DOUBLE,
|
||||
vConcept VARCHAR(40),
|
||||
vCompanyFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Registra un pago realizado a un proveedor y
|
||||
* su correspondiente registro en caja.
|
||||
*
|
||||
* @param vDated Fecha del pago
|
||||
* @param vSupplierFk Id del proveedor
|
||||
* @param vAmount Cantidad a pagar
|
||||
* @param vCurrencyFk Id de la moneda
|
||||
* @param vForeignValue Tipo de cambio utilizado
|
||||
* @param vBankFk Id del banco
|
||||
* @param vPayMethodFk Id del método de pago
|
||||
* @param vExpenseFk Id de gasto
|
||||
* @param vConcept Concepto del pago
|
||||
* @param vCompanyFk Id de la empresa
|
||||
* @return paymentFk Id de pago insertado
|
||||
*/
|
||||
INSERT INTO till(
|
||||
concept,
|
||||
serie,
|
||||
`number`,
|
||||
`out`,
|
||||
dated,
|
||||
isAccountable,
|
||||
bankFk,
|
||||
workerFk,
|
||||
companyFk,
|
||||
isConciliate
|
||||
)
|
||||
SELECT CONCAT('n/pago a ', `name`),
|
||||
'R',
|
||||
vSupplierFk,
|
||||
vAmount,
|
||||
vDated,
|
||||
1,
|
||||
vBankFk,
|
||||
account.myUser_getId(),
|
||||
vCompanyFk,
|
||||
1
|
||||
FROM supplier
|
||||
WHERE id = vSupplierFk;
|
||||
|
||||
INSERT INTO payment(
|
||||
received,
|
||||
dueDated,
|
||||
supplierFk,
|
||||
amount,
|
||||
currencyFk,
|
||||
divisa,
|
||||
bankFk,
|
||||
payMethodFk,
|
||||
bankingFees,
|
||||
concept,
|
||||
companyFk
|
||||
)
|
||||
VALUES(
|
||||
vDated,
|
||||
vDated,
|
||||
vSupplierFk,
|
||||
vAmount,
|
||||
vCurrencyFk,
|
||||
IF(NOT vForeignValue, NULL, vForeignValue),
|
||||
vBankFk,
|
||||
vPayMethodFk,
|
||||
vExpenseFk,
|
||||
vConcept,
|
||||
vCompanyFk
|
||||
);
|
||||
|
||||
SELECT LAST_INSERT_ID() paymentFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,70 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`remittance_calc`(
|
||||
vDated DATE
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula los datos de remesa, incluyendo el importe,
|
||||
* el vencimiento, y otros datos relevantes.
|
||||
*
|
||||
* @param vDated Fecha a calcular
|
||||
* @return tmp.remittance
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.remittance
|
||||
SELECT CONCAT(s.nif, REPEAT('0', 12 - LENGTH(s.nif))) cif,
|
||||
c.id clientFk,
|
||||
c.name client,
|
||||
c.fi,
|
||||
sub.paymentDate,
|
||||
0 invoiceAmount,
|
||||
CAST(sub.receipt AS DECIMAL(10,2)) receiptAmount,
|
||||
0 currentAmount,
|
||||
sub.companyFk,
|
||||
c.socialName,
|
||||
CAST(sub.receipt AS DECIMAL(10,2)) totalAmount,
|
||||
CAST(sub.receipt AS DECIMAL(10,2)) balance,
|
||||
s.name company,
|
||||
co.code companyCode,
|
||||
c.accountingAccount,
|
||||
c.iban,
|
||||
c.hasSepaVnl,
|
||||
c.hasCoreVnl,
|
||||
c.hasLcr,
|
||||
be.bic,
|
||||
be.`name` entityName
|
||||
FROM client c
|
||||
JOIN (
|
||||
SELECT risk.companyFk,
|
||||
c.id,
|
||||
SUM(risk.amount) receipt,
|
||||
IF((c.dueDay + graceDays) MOD 30.001 <= DAY(vDated),
|
||||
LAST_DAY(vDated - INTERVAL 1 MONTH) + INTERVAL (c.dueDay + graceDays) MOD 30.001 DAY,
|
||||
LAST_DAY(vDated - INTERVAL 2 MONTH) + INTERVAL (c.dueDay + graceDays) MOD 30.001 DAY
|
||||
) paymentDate
|
||||
FROM client c
|
||||
JOIN payMethod pm ON pm.id = c.payMethodFk
|
||||
JOIN (
|
||||
SELECT cr.companyFk, cr.clientFk, cr.amount
|
||||
FROM client c
|
||||
JOIN clientRisk cr ON cr.clientFk = c.id
|
||||
JOIN payMethod pm ON pm.id = c.payMethodFk
|
||||
WHERE pm.code = 'bankDraft'
|
||||
UNION ALL
|
||||
SELECT io.companyFk, io.clientFk, - io.amount
|
||||
FROM invoiceOut io
|
||||
JOIN client c ON c.id = io.clientFk
|
||||
JOIN payMethod pm ON pm.id = c.payMethodFk
|
||||
WHERE io.dued > vDated
|
||||
AND pm.code = 'bankDraft'
|
||||
AND pm.outstandingDebt
|
||||
AND io.amount > 0
|
||||
|
||||
) risk ON risk.clientFk = c.id
|
||||
GROUP BY risk.companyFk, c.id
|
||||
HAVING receipt > 10
|
||||
) sub ON sub.id = c.id
|
||||
JOIN supplier s ON s.id = sub.companyFk
|
||||
JOIN company co ON co.id = sub.companyFk
|
||||
LEFT JOIN bankEntity be ON be.id = c.bankEntityFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,70 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_checkNoComponents`(vCreatedFrom DATETIME, vCreatedTo DATETIME)
|
||||
BEGIN
|
||||
/**
|
||||
* Comprueba que las ventas creadas entre un rango de fechas tienen componentes
|
||||
*
|
||||
* @param vCreatedFrom inicio del rango
|
||||
* @param vCreatedTo fin del rango
|
||||
*/
|
||||
DECLARE v_done BOOL DEFAULT FALSE;
|
||||
DECLARE vSaleFk INTEGER;
|
||||
DECLARE vTicketFk INTEGER;
|
||||
DECLARE vConcept VARCHAR(50);
|
||||
DECLARE vCur CURSOR FOR
|
||||
SELECT s.id
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType tp ON tp.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
||||
LEFT JOIN tmp.coste c ON c.id = s.id
|
||||
WHERE s.created >= vCreatedFrom AND s.created <= vCreatedTo
|
||||
AND c.id IS NULL
|
||||
AND t.agencyModeFk IS NOT NULL
|
||||
AND t.isDeleted IS FALSE
|
||||
AND t.warehouseFk = 60
|
||||
AND ic.merchandise != FALSE
|
||||
GROUP BY s.id;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||
SET v_done = TRUE;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.coste;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.coste;
|
||||
CREATE TEMPORARY TABLE tmp.coste
|
||||
(PRIMARY KEY (id)) ENGINE = MEMORY
|
||||
SELECT s.id
|
||||
FROM sale s
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType tp ON tp.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
||||
JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
JOIN component c ON c.id = sc.componentFk
|
||||
JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 6
|
||||
WHERE s.created >= vCreatedFrom
|
||||
AND ic.merchandise != FALSE;
|
||||
|
||||
OPEN vCur;
|
||||
|
||||
l: LOOP
|
||||
SET v_done = FALSE;
|
||||
FETCH vCur INTO vSaleFk;
|
||||
|
||||
IF v_done THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
SELECT ticketFk, concept
|
||||
INTO vTicketFk, vConcept
|
||||
FROM sale
|
||||
WHERE id = vSaleFk;
|
||||
|
||||
CALL sale_calculateComponent(vSaleFk, 'renewPrices');
|
||||
END LOOP;
|
||||
|
||||
CLOSE vCur;
|
||||
DROP TEMPORARY TABLE tmp.coste;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -27,7 +27,7 @@ BEGIN
|
|||
s.quantity,
|
||||
MAKETIME(pb.HH,pb.mm,0) etd,
|
||||
pb.routeFk,
|
||||
FLOOR(s.quantity / ish.packing) stickers,
|
||||
FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers,
|
||||
IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing,
|
||||
b.packagingFk
|
||||
FROM sale s
|
||||
|
@ -71,5 +71,3 @@ BEGIN
|
|||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL `vn`.`sale_getBoxPickingList`(1, curdate());
|
|
@ -79,7 +79,10 @@ DECLARE vIsCollection BOOL;
|
|||
IF(SUM(iss.quantity) IS NULL, 0, SUM(iss.quantity)) pickedQuantity,
|
||||
MIN(iss.created) picked,
|
||||
IF(sm.id, TRUE, FALSE) hasMistake,
|
||||
sg.sectorFk
|
||||
sg.sectorFk,
|
||||
b.packing,
|
||||
b.grouping,
|
||||
o.code
|
||||
FROM tmp.ticket t
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN ticket tt ON tt.id = t.id
|
||||
|
|
|
@ -15,7 +15,7 @@ BEGIN
|
|||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN alertLevel al ON al.id = ts.alertLevel
|
||||
WHERE al.code = 'PACKED' OR (am.code = 'refund' AND al.code != 'delivered')
|
||||
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code != 'delivered'))
|
||||
AND t.id = vTicketFk
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY t.id);
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`CalculoRemesas`(IN vFechaRemesa DATE)
|
||||
BEGIN
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS TMP_REMESAS;
|
||||
CREATE TEMPORARY TABLE TMP_REMESAS
|
||||
SELECT
|
||||
CONCAT(p.NIF,REPEAT('0', 12-LENGTH(p.NIF))) as CIF1,
|
||||
cli.Id_Cliente,
|
||||
cli.Cliente,
|
||||
cli.`IF` as NIF,
|
||||
c.PaymentDate as Vencimiento,
|
||||
0 ImporteFac,
|
||||
cast(c.Recibo as decimal(10,2)) as ImporteRec,
|
||||
0 as ImporteActual,
|
||||
c.companyFk empresa_id,
|
||||
cli.RazonSocial,
|
||||
cast(c.Recibo as decimal(10,2)) as ImporteTotal,
|
||||
cast(c.Recibo as decimal(10,2)) as Saldo,
|
||||
p.Proveedor as Empresa,
|
||||
e.abbreviation as EMP,
|
||||
cli.cuenta,
|
||||
iban AS Iban,
|
||||
CONVERT(SUBSTRING(iban,5,4),UNSIGNED INT) AS nrbe,
|
||||
sepavnl as SEPA,
|
||||
corevnl as RecibidoCORE,
|
||||
hasLcr,
|
||||
be.bic,
|
||||
be.`name` entityName
|
||||
FROM Clientes cli
|
||||
JOIN
|
||||
(SELECT risk.companyFk,
|
||||
c.Id_Cliente,
|
||||
sum(risk.amount) as Recibo,
|
||||
IF((c.Vencimiento + graceDays) mod 30.001 <= day(vFechaRemesa)
|
||||
,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-1,vFechaRemesa)))
|
||||
,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-2,vFechaRemesa)))
|
||||
) as PaymentDate
|
||||
FROM Clientes c
|
||||
JOIN pay_met pm on pm.id = pay_met_id
|
||||
JOIN
|
||||
(
|
||||
SELECT companyFk, clientFk, amount
|
||||
FROM Clientes c
|
||||
JOIN vn.clientRisk cr ON cr.clientFk = c.Id_Cliente
|
||||
WHERE pay_met_id = 4
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT io.companyFk, io.clientFk Id_Cliente, - io.amount
|
||||
FROM vn.invoiceOut io
|
||||
JOIN Clientes c ON c.Id_Cliente = io.clientFk
|
||||
JOIN pay_met pm on pm.id = pay_met_id
|
||||
WHERE io.dued > vFechaRemesa
|
||||
AND pay_met_id = 4 AND pm.deudaviva
|
||||
AND io.amount > 0
|
||||
|
||||
) risk ON c.Id_Cliente = risk.clientFk
|
||||
GROUP BY risk.companyFk, Id_Cliente
|
||||
HAVING Recibo > 10
|
||||
) c on c.Id_Cliente = cli.Id_Cliente
|
||||
JOIN Proveedores p on p.Id_Proveedor = c.companyFk
|
||||
JOIN empresa e on e.id = c.companyFk
|
||||
LEFT JOIN vn.bankEntity be ON be.id = cli.bankEntityFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,11 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`cacheReset`(vCacheName VARCHAR(10), vParams VARCHAR(15))
|
||||
BEGIN
|
||||
|
||||
UPDATE cache.cache_calc
|
||||
SET expires = util.VN_NOW()
|
||||
WHERE cacheName = vCacheName collate utf8_unicode_ci
|
||||
AND params = vParams collate utf8_unicode_ci;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,23 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`camiones`(vWarehouse INT, vDate DATE)
|
||||
BEGIN
|
||||
SELECT Temperatura
|
||||
,ROUND(SUM(Etiquetas * volume)) AS cm3
|
||||
,ROUND(SUM(IF(scanned, Etiquetas, 0) * volume)) AS cm3s
|
||||
,ROUND(SUM(Vida * volume)) AS cm3e
|
||||
FROM (
|
||||
SELECT t.Temperatura, c.Etiquetas, b.scanned, c.Vida,
|
||||
IF(cu.Volumen > 0, cu.Volumen, cu.x * cu.y * IF(cu.z > 0, cu.z, a.Medida + 10)) volume
|
||||
FROM Compres c
|
||||
LEFT JOIN buy_edi b ON b.id = c.buy_edi_id
|
||||
JOIN Articles a ON a.Id_Article = c.Id_Article
|
||||
JOIN Tipos t ON t.tipo_id = a.tipo_id
|
||||
JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada
|
||||
JOIN travel tr ON tr.id = e.travel_id
|
||||
JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo
|
||||
WHERE tr.warehouse_id = vWarehouse
|
||||
AND tr.landing = vDate
|
||||
) sub
|
||||
GROUP BY Temperatura;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,79 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`clean`(IN `v_full` TINYINT(1))
|
||||
proc: BEGIN
|
||||
DECLARE vDate DATETIME;
|
||||
DECLARE vDate18 DATETIME;
|
||||
DECLARE vDate26 DATETIME;
|
||||
DECLARE vDate8 DATE;
|
||||
DECLARE vDate6 DATE;
|
||||
DECLARE vDate3 DATE;
|
||||
DECLARE vDate2000 DATE;
|
||||
DECLARE vRangeDeleteTicket INT;
|
||||
DECLARE vStrtable VARCHAR(15) DEFAULT NULL;
|
||||
|
||||
SET vDate = util.VN_CURDATE() - INTERVAL 2 MONTH;
|
||||
SET vDate18 = util.VN_CURDATE() - INTERVAL 18 MONTH;
|
||||
SET vDate26 = util.VN_CURDATE() - INTERVAL 26 MONTH;
|
||||
SET vDate3 = util.VN_CURDATE() - INTERVAL 3 MONTH;
|
||||
SET vDate8 = util.VN_CURDATE() - INTERVAL 8 DAY;
|
||||
SET vDate6 = util.VN_CURDATE() - INTERVAL 6 DAY;
|
||||
SET vDate2000 = util.VN_CURDATE() + INTERVAL (2000 - YEAR(util.VN_CURDATE())) YEAR;
|
||||
SET vRangeDeleteTicket = 60;
|
||||
|
||||
DELETE FROM cdr WHERE calldate < vDate18;
|
||||
DELETE FROM mail WHERE DATE_ODBC < vDate;
|
||||
DELETE FROM Movimientos_mark WHERE odbc_date < vDate;
|
||||
DELETE FROM Splits WHERE Fecha < vDate18;
|
||||
|
||||
DELETE tobs
|
||||
FROM movement_label tobs
|
||||
JOIN Movimientos m ON tobs.Id_Movimiento = m.Id_Movimiento
|
||||
JOIN Tickets t ON m.Id_Ticket = t.Id_Ticket WHERE t.Fecha < vDate;
|
||||
|
||||
DELETE FROM Remesas WHERE `Fecha Remesa` < vDate18;
|
||||
|
||||
DELETE tt.*
|
||||
FROM Tickets_turno tt
|
||||
LEFT JOIN Movimientos m USING(Id_Ticket)
|
||||
WHERE m.Id_Article IS NULL;
|
||||
|
||||
DELETE FROM cl_main WHERE Fecha < vDate18;
|
||||
DELETE FROM hedera.`order` WHERE date_send < vDate18;
|
||||
DELETE FROM vn.message WHERE sendDate < vDate;
|
||||
|
||||
DELETE FROM cache.departure_limit WHERE Fecha < util.VN_CURDATE() - INTERVAL 1 MONTH;
|
||||
|
||||
DELETE cm
|
||||
FROM Compres_mark cm
|
||||
JOIN Compres c ON c.Id_Compra = cm.Id_Compra
|
||||
JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada
|
||||
JOIN travel t ON t.id = e.travel_id
|
||||
WHERE t.landing <= vDate;
|
||||
|
||||
IF v_full THEN
|
||||
CREATE OR REPLACE TEMPORARY TABLE tTicketDelete
|
||||
SELECT DISTINCT tl.originFk ticketFk
|
||||
FROM vn.ticketLog tl
|
||||
JOIN (SELECT MAX(tl.id)ids
|
||||
FROM vn.ticket t
|
||||
JOIN vn.ticketLog tl ON tl.originFk = t.id
|
||||
WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31'
|
||||
AND t.isDeleted
|
||||
GROUP BY t.id
|
||||
)sub ON sub.ids = tl.id
|
||||
WHERE tl.creationDate <= util.VN_CURDATE() - INTERVAL 60 DAY;
|
||||
|
||||
DELETE t
|
||||
FROM vn.ticket t
|
||||
JOIN tTicketDelete tmp ON tmp.ticketFk = t.id;
|
||||
|
||||
DROP TEMPORARY TABLE tTicketDelete;
|
||||
END IF;
|
||||
|
||||
-- Tickets Nulos PAK 11/10/2016
|
||||
UPDATE Tickets
|
||||
SET empresa_id = 965
|
||||
WHERE Id_Cliente = 31
|
||||
AND empresa_id != 965;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,6 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`clean_launcher`()
|
||||
BEGIN
|
||||
CALL clean(TRUE);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,79 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`cobro`(IN datFEC DATE
|
||||
, IN idCLI INT
|
||||
, IN dblIMPORTE DOUBLE
|
||||
, IN idCAJA INT
|
||||
, IN idPAYMET INT
|
||||
, IN strCONCEPTO VARCHAR(40)
|
||||
, IN idEMP INT
|
||||
, IN idWH INT
|
||||
, IN idTRABAJADOR INT)
|
||||
BEGIN
|
||||
|
||||
DECLARE bolCASH BOOLEAN;
|
||||
DECLARE cuenta_banco BIGINT;
|
||||
DECLARE cuenta_cliente BIGINT;
|
||||
DECLARE max_asien INT;
|
||||
-- XDIARIO
|
||||
-- No se asientan los cobros directamente, salvo en el caso de las cajas de CASH
|
||||
SELECT (at2.code = 'cash') INTO bolCASH FROM Bancos b JOIN vn.accountingType at2 ON at2.id = b.cash WHERE b.Id_Banco = idCAJA;
|
||||
IF bolCASH THEN
|
||||
SELECT Cuenta INTO cuenta_banco
|
||||
FROM Bancos
|
||||
WHERE Id_Banco = idCAJA;
|
||||
SELECT Cuenta INTO cuenta_cliente
|
||||
FROM Clientes
|
||||
WHERE Id_Cliente = idCLI;
|
||||
CALL vn.ledger_next(max_asien);
|
||||
INSERT INTO vn.XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id)
|
||||
SELECT max_asien,datFEC,SUBCTA,CONTRA,strCONCEPTO,EURODEBE,EUROHABER,idEMP
|
||||
FROM(SELECT cuenta_banco SUBCTA, cuenta_cliente CONTRA, 0 EURODEBE, dblIMPORTE EUROHABER
|
||||
UNION ALL
|
||||
SELECT cuenta_cliente SUBCTA, cuenta_banco CONTRA, dblIMPORTE EURODEBE, 0 EUROHABER
|
||||
) gf;
|
||||
END IF;
|
||||
|
||||
-- CAJERA
|
||||
INSERT INTO Cajas(Id_Trabajador,
|
||||
Id_Banco,
|
||||
Entrada,
|
||||
Concepto,
|
||||
Cajafecha,
|
||||
Serie,
|
||||
Partida,
|
||||
Numero,
|
||||
empresa_id,
|
||||
warehouse_id
|
||||
)
|
||||
VALUES (idTRABAJADOR,
|
||||
idCAJA,
|
||||
dblIMPORTE,
|
||||
strCONCEPTO,
|
||||
datFEC,
|
||||
'A',
|
||||
TRUE,
|
||||
idCLI,
|
||||
idEMP,
|
||||
idWH
|
||||
);
|
||||
|
||||
-- RECIBO
|
||||
INSERT INTO Recibos(Entregado,
|
||||
Fechacobro,
|
||||
Id_Trabajador,
|
||||
Id_Banco,
|
||||
Id_Cliente,
|
||||
Id_Factura,
|
||||
empresa_id
|
||||
)
|
||||
VALUES ( dblIMPORTE,
|
||||
datFEC,
|
||||
idTRABAJADOR,
|
||||
idCAJA,
|
||||
idCLI,
|
||||
strCONCEPTO,
|
||||
idEMP
|
||||
);
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,105 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`confection_control_source`(vDated DATE, vScopeDays TINYINT)
|
||||
BEGIN
|
||||
|
||||
DECLARE vMidnight DATETIME DEFAULT TIMESTAMP(vDated,'23:59:59');
|
||||
DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,vMidnight);
|
||||
DECLARE maxAlertLevel INT DEFAULT 2;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp.production_buffer
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
date(t.Fecha) as Fecha,
|
||||
hour(t.Fecha) as Hora,
|
||||
hour(t.Fecha) as Departure,
|
||||
t.Id_Ticket,
|
||||
m.Id_Movimiento,
|
||||
m.Cantidad,
|
||||
m.Concepte,
|
||||
ABS(m.Reservado) Reservado,
|
||||
i.Categoria,
|
||||
tp.Tipo,
|
||||
t.Alias as Cliente,
|
||||
wh.name as Almacen,
|
||||
t.warehouse_id,
|
||||
cs.province_id,
|
||||
a.agency_id,
|
||||
ct.description as Taller,
|
||||
stock.visible,
|
||||
stock.available
|
||||
FROM vn2008.Tickets t
|
||||
JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
|
||||
JOIN vn.warehouse wh ON wh.id = t.warehouse_id
|
||||
JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket
|
||||
JOIN vn2008.Articles i ON i.Id_Article = m.Id_Article
|
||||
JOIN vn2008.Tipos tp ON tp.tipo_id = i.tipo_id
|
||||
JOIN vn.confectionType ct ON ct.id = tp.confeccion
|
||||
JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
|
||||
LEFT JOIN vn.ticketState tls on tls.ticketFk = t.Id_Ticket
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT item_id, sum(visible) visible, sum(available) available
|
||||
FROM
|
||||
(
|
||||
SELECT a.item_id, 0 as visible, a.available
|
||||
FROM cache.cache_calc cc
|
||||
LEFT JOIN cache.available a ON a.calc_id = cc.id
|
||||
WHERE cc.cache_id IN (2,8)
|
||||
AND cc.params IN (concat("1/", util.VN_CURDATE()),concat("44/", util.VN_CURDATE()))
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT v.item_id, v.visible, 0 as available
|
||||
FROM cache.cache_calc cc
|
||||
LEFT JOIN cache.visible v ON v.calc_id = cc.id
|
||||
where cc.cache_id IN (2,8) and cc.params IN ("1","44")
|
||||
) sub
|
||||
GROUP BY item_id
|
||||
) stock ON stock.item_id = m.Id_Article
|
||||
WHERE tp.confeccion
|
||||
AND tls.alertLevel < maxAlertLevel
|
||||
AND wh.hasConfectionTeam
|
||||
AND t.Fecha BETWEEN vDated AND vEndingDate
|
||||
AND m.Cantidad > 0;
|
||||
|
||||
-- Entradas
|
||||
|
||||
INSERT INTO tmp.production_buffer(
|
||||
Fecha,
|
||||
Id_Ticket,
|
||||
Cantidad,
|
||||
Concepte,
|
||||
Categoria,
|
||||
Cliente,
|
||||
Almacen,
|
||||
Taller
|
||||
)
|
||||
SELECT
|
||||
tr.shipment AS Fecha,
|
||||
e.Id_Entrada AS Id_Ticket,
|
||||
c.Cantidad,
|
||||
a.Article,
|
||||
a.Categoria,
|
||||
whi.name as Cliente,
|
||||
who.name as Almacen,
|
||||
ct.description as Taller
|
||||
FROM vn2008.Compres c
|
||||
JOIN vn2008.Entradas e ON e.Id_Entrada = c.Id_Entrada
|
||||
JOIN vn2008.travel tr ON tr.id = e.travel_id
|
||||
JOIN vn.warehouse whi ON whi.id = tr.warehouse_id
|
||||
JOIN vn.warehouse who ON who.id = tr.warehouse_id_out
|
||||
JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article
|
||||
JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id
|
||||
JOIN vn.confectionType ct ON ct.id = tp.confeccion
|
||||
WHERE who.hasConfectionTeam
|
||||
AND tp.confeccion
|
||||
AND tr.shipment BETWEEN vDated AND vEndingDate;
|
||||
|
||||
|
||||
SELECT * FROM tmp.production_buffer;
|
||||
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,48 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`nest_child_add`(
|
||||
vTable VARCHAR(45)
|
||||
,vChild VARCHAR(45)
|
||||
,vFatherId INT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE vMyLeft INT;
|
||||
|
||||
SET vTable = util.quoteIdentifier(vTable);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS aux;
|
||||
CREATE TEMPORARY TABLE aux
|
||||
SELECT 0 as lft;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE aux
|
||||
SET lft = (SELECT lft
|
||||
FROM ', vTable,
|
||||
' WHERE id = ?)')
|
||||
USING vFatherId;
|
||||
|
||||
SELECT lft INTO vMyLeft FROM aux;
|
||||
DROP TEMPORARY TABLE aux;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable, '
|
||||
SET rgt = rgt + 2
|
||||
WHERE rgt > ?
|
||||
ORDER BY rgt DESC')
|
||||
USING vMyLeft;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable, '
|
||||
SET lft = lft + 2
|
||||
WHERE lft > ?
|
||||
ORDER BY lft DESC')
|
||||
USING vMyLeft;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'INSERT INTO ', vTable, ' (name, lft, rgt)
|
||||
VALUES(?, ? + 1, ? + 2)')
|
||||
USING vChild,
|
||||
vMyLeft,
|
||||
vMyLeft;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,51 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`nest_delete`(
|
||||
vTable VARCHAR(45)
|
||||
,vNodeId INT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE vMyRight INT;
|
||||
DECLARE vMyLeft INT;
|
||||
DECLARE vMyWidth INT;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS aux;
|
||||
CREATE TEMPORARY TABLE aux
|
||||
SELECT 0 rgt, 0 lft, 0 wdt;
|
||||
|
||||
SET vTable = util.quoteIdentifier(vTable);
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE aux a
|
||||
JOIN ', vTable, ' t
|
||||
SET a.rgt = t.rgt,
|
||||
a.lft = t.lft,
|
||||
a.wdt = t.rgt - t.lft + 1
|
||||
WHERE t.id = ?')
|
||||
USING vNodeId;
|
||||
|
||||
SELECT rgt, lft, wdt
|
||||
INTO vMyRight, vMyLeft, vMyWidth
|
||||
FROM aux;
|
||||
|
||||
DROP TEMPORARY TABLE aux;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'DELETE FROM ', vTable,
|
||||
' WHERE lft BETWEEN ? AND ?')
|
||||
USING vMyLeft, vMyRight;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
' SET rgt = rgt - ?
|
||||
WHERE rgt > ?
|
||||
ORDER BY rgt')
|
||||
USING vMyWidth,vMyRight;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
' SET lft = lft - ?
|
||||
WHERE lft > ?
|
||||
ORDER BY lft')
|
||||
USING vMyWidth, vMyRight;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,108 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`nest_move`(
|
||||
vTable VARCHAR(45)
|
||||
,idNODE INT
|
||||
,idFATHER INT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE myRight INT;
|
||||
DECLARE myLeft INT;
|
||||
DECLARE myWidth INT;
|
||||
DECLARE fatherRight INT;
|
||||
DECLARE fatherLeft INT;
|
||||
DECLARE gap INT;
|
||||
|
||||
SET vTable = util.quoteIdentifier(vTable);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS aux;
|
||||
CREATE TEMPORARY TABLE aux
|
||||
SELECT 0 as rgt, 0 as lft, 0 as wdt, 0 as frg, 0 as flf;
|
||||
|
||||
-- Averiguamos el ancho de la rama
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE aux a
|
||||
JOIN ', vTable, ' t
|
||||
SET a.wdt = t.rgt - t.lft + 1
|
||||
WHERE t.id = ?')
|
||||
USING idNODE;
|
||||
|
||||
-- Averiguamos la posicion del nuevo padre
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE aux a
|
||||
JOIN ', vTable, ' t
|
||||
SET a.frg = t.rgt,
|
||||
a.flf = t.lft
|
||||
WHERE t.id = ?')
|
||||
USING idFATHER;
|
||||
|
||||
SELECT wdt, frg, flf INTO myWidth, fatherRight, fatherLeft
|
||||
FROM aux;
|
||||
|
||||
-- 1º Incrementamos los valores de todos los nodos a la derecha del punto de inserción (fatherRight) , para hacer sitio
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET rgt = rgt + ?
|
||||
WHERE rgt >= ?
|
||||
ORDER BY rgt DESC')
|
||||
USING myWidth,
|
||||
fatherRight;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET lft = lft + ?
|
||||
WHERE lft >= ?
|
||||
ORDER BY lft DESC')
|
||||
USING myWidth,
|
||||
fatherRight;
|
||||
|
||||
-- Es preciso recalcular los valores del nodo en el caso de que estuviera a la derecha del nuevo padre
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE aux a
|
||||
JOIN ', vTable, ' t
|
||||
SET a.rgt = t.rgt,
|
||||
a.lft = t.lft
|
||||
WHERE t.id = ?')
|
||||
USING idNODE;
|
||||
|
||||
SELECT lft, rgt, frg - lft INTO myLeft, myRight, gap
|
||||
FROM aux;
|
||||
|
||||
-- 2º Incrementamos el valor de todos los nodos a trasladar hasta alcanzar su nueva posicion
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET lft = lft + ?
|
||||
WHERE lft BETWEEN ? AND ?
|
||||
ORDER BY lft DESC')
|
||||
USING gap,
|
||||
myLeft,
|
||||
myRight;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET rgt = rgt + ?
|
||||
WHERE rgt BETWEEN ? AND ?
|
||||
ORDER BY rgt DESC')
|
||||
USING gap,
|
||||
myLeft,
|
||||
myRight;
|
||||
|
||||
-- 3º Restaremos a todos los nodos resultantes, a la derecha de la posicion arrancada el ancho de la rama escindida
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET lft = lft - ?
|
||||
WHERE lft > ?
|
||||
ORDER BY lft')
|
||||
USING myWidth,
|
||||
myLeft;
|
||||
|
||||
EXECUTE IMMEDIATE CONCAT(
|
||||
'UPDATE ', vTable,
|
||||
'SET rgt = rgt - ?
|
||||
WHERE rgt > ?
|
||||
ORDER BY rgt')
|
||||
USING myWidth,
|
||||
myRight;
|
||||
|
||||
DROP TEMPORARY TABLE aux;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,67 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`pay`(IN datFEC DATE
|
||||
, IN idPROV INT
|
||||
, IN dblIMPORTE DOUBLE
|
||||
, IN idMONEDA INT
|
||||
, IN dblDIVISA DOUBLE
|
||||
, IN idCAJA INT
|
||||
, IN idPAYMET INT
|
||||
, IN dblGASTOS DOUBLE
|
||||
, IN strCONCEPTO VARCHAR(40)
|
||||
, IN idEMP INT)
|
||||
BEGIN
|
||||
|
||||
-- Registro en la tabla Cajas
|
||||
INSERT INTO Cajas ( Concepto
|
||||
, Serie
|
||||
, Numero
|
||||
, Salida
|
||||
, Cajafecha
|
||||
, Partida
|
||||
, Id_Banco
|
||||
, Id_Trabajador
|
||||
,empresa_id
|
||||
,conciliado)
|
||||
|
||||
SELECT CONCAT('n/pago a ', Proveedor)
|
||||
, 'R'
|
||||
, idPROV
|
||||
, dblIMPORTE
|
||||
, datFEC
|
||||
, 1
|
||||
, idCAJA
|
||||
, account.myUser_getId()
|
||||
, idEMP
|
||||
, 1
|
||||
FROM Proveedores
|
||||
WHERE Id_Proveedor = idPROV;
|
||||
|
||||
-- Registro en la tabla pago
|
||||
INSERT INTO pago(fecha
|
||||
, dueDated
|
||||
, id_proveedor
|
||||
, importe
|
||||
, id_moneda
|
||||
, divisa
|
||||
, id_banco
|
||||
, pay_met_id
|
||||
, g_bancarios
|
||||
, concepte
|
||||
, empresa_id)
|
||||
|
||||
VALUES(datFEC
|
||||
, datFEC
|
||||
, idPROV
|
||||
, dblIMPORTE
|
||||
, idMONEDA
|
||||
, IF(dblDIVISA = 0, NULL, dblDIVISA)
|
||||
, idCAJA
|
||||
, idPAYMET
|
||||
, dblGASTOS
|
||||
, strCONCEPTO
|
||||
, idEMP);
|
||||
|
||||
SELECT LAST_INSERT_ID() as pago_id;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,12 @@
|
|||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||
VALUES
|
||||
('Collection', 'assign', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
||||
('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','production'),
|
||||
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','production'),
|
||||
('SaleTracking','delete','WRITE','ALLOW','ROLE','production'),
|
||||
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','production'),
|
||||
('SaleTracking','setPicked','WRITE','ALLOW','ROLE','production'),
|
||||
('ExpeditionPallet', '*', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('Sale', 'getFromSectorCollection', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('ItemBarcode', 'delete', 'WRITE', 'ALLOW', 'ROLE', 'production');
|
|
@ -0,0 +1,4 @@
|
|||
-- Place your SQL code here
|
||||
RENAME TABLE IF EXISTS vn.claimRma TO vn.claimRma__;
|
||||
ALTER TABLE IF EXISTS vn.claimRma__ COMMENT='kkeada el 2024-02-26 por Pablo';
|
||||
ALTER TABLE vn.claim CHANGE IF EXISTS rma rma__ varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL;
|
|
@ -0,0 +1,6 @@
|
|||
-- Place your SQL code here
|
||||
ALTER TABLE IF EXISTS vn2008.dock__ RENAME vn2008.dock;
|
||||
ALTER TABLE IF EXISTS vn2008.dock COMMENT='';
|
||||
|
||||
ALTER TABLE IF EXISTS vn2008.Tramos__ RENAME vn2008.Tramos;
|
||||
ALTER TABLE IF EXISTS vn2008.Tramos COMMENT='';
|
|
@ -0,0 +1,2 @@
|
|||
DELETE IGNORE FROM bs.nightTask
|
||||
WHERE `procedure` = 'clean_launcher';
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE vn.warehouse AUTO_INCREMENT=92;
|
|
@ -0,0 +1,31 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balanceNestTree_addChild`()
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
GRANT EXECUTE ON PROCEDURE vn.balanceNestTree_addChild TO adminBoss;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balanceNestTree_delete`()
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
GRANT EXECUTE ON PROCEDURE vn.balanceNestTree_delete TO adminBoss;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balanceNestTree_move`()
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
GRANT EXECUTE ON PROCEDURE vn.balanceNestTree_move TO adminBoss;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`payment_add`()
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
GRANT EXECUTE ON PROCEDURE vn.payment_add TO financial;
|
|
@ -0,0 +1,15 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`confection_controlSource`()
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
GRANT EXECUTE ON PROCEDURE vn.confection_controlSource TO handmadeBoss, productionAssi, artificialBoss;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`remittance_calc`()
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
GRANT EXECUTE ON PROCEDURE vn.remittance_calc TO financial;
|
|
@ -0,0 +1,8 @@
|
|||
UPDATE vn.claim c
|
||||
JOIN vn.claimState cs ON cs.id = c.claimStateFk
|
||||
JOIN vn.claimState ns ON ns.code = 'resolved'
|
||||
SET c.claimStateFk = ns.id
|
||||
WHERE cs.code IN ('managed', 'mana', 'lack', 'relocation');
|
||||
|
||||
DELETE FROM vn.claimState
|
||||
WHERE code IN ('managed', 'mana', 'lack', 'relocation');
|
|
@ -0,0 +1,2 @@
|
|||
-- Place your SQL code here
|
||||
ALTER TABLE dipole.expedition_PrintOut MODIFY COLUMN street varchar(42) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT ' ' NOT NULL;
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
ALTER TABLE vn.department
|
||||
ADD COLUMN pbxQueue varchar(128) CHARACTER
|
||||
SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL;
|
||||
|
||||
ALTER TABLE vn.department
|
||||
ADD CONSTRAINT department_queue_FK
|
||||
FOREIGN KEY (pbxQueue) REFERENCES pbx.queue(name) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -21,7 +21,7 @@ describe('Claim edit basic data path', () => {
|
|||
});
|
||||
|
||||
it(`should edit claim state and observation fields`, async() => {
|
||||
await page.autocompleteSearch(selectors.claimBasicData.claimState, 'Gestionado');
|
||||
await page.autocompleteSearch(selectors.claimBasicData.claimState, 'Resuelto');
|
||||
await page.clearInput(selectors.claimBasicData.packages);
|
||||
await page.write(selectors.claimBasicData.packages, '2');
|
||||
await page.waitToClick(selectors.claimBasicData.saveButton);
|
||||
|
@ -48,7 +48,7 @@ describe('Claim edit basic data path', () => {
|
|||
await page.waitForSelector(selectors.claimBasicData.claimState);
|
||||
const result = await page.waitToGetProperty(selectors.claimBasicData.claimState, 'value');
|
||||
|
||||
expect(result).toEqual('Gestionado');
|
||||
expect(result).toEqual('Resuelto');
|
||||
});
|
||||
|
||||
it('should confirm the "is paid with mana" and "Pick up" checkbox are checked', async() => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Are you sure exit without saving?: ¿Seguro que quieres salir sin guardar?
|
||||
Unsaved changes will be lost: Los cambios que no hayas guardado se perderán
|
||||
No changes to save: No hay cambios que guardar
|
||||
Some fields are invalid: Algunos campos no son válidos
|
||||
Some fields are invalid: Algunos campos no son válidos
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// For a detailed explanation regarding each configuration property, visit:
|
||||
// https://jestjs.io/docs/en/configuration.html
|
||||
/* eslint max-len: ["error", { "code": 150 }]*/
|
||||
const cpus = require('os').cpus().length;
|
||||
const maxCpus = Math.floor(cpus * 0.45);
|
||||
|
||||
module.exports = {
|
||||
name: 'front end',
|
||||
|
@ -12,6 +14,7 @@ module.exports = {
|
|||
setupFilesAfterEnv: [
|
||||
'./front/jest-setup.js'
|
||||
],
|
||||
maxWorkers: maxCpus,
|
||||
testMatch: [
|
||||
'**/front/**/*.spec.js',
|
||||
'**/print/**/*.spec.js',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const LoopBackContext = require('loopback-context');
|
||||
async function handleObserve(ctx) {
|
||||
ctx.options.httpCtx = LoopBackContext.getCurrentContext();
|
||||
const httpCtx = LoopBackContext.getCurrentContext();
|
||||
ctx.options.userId = httpCtx?.active?.accessToken?.userId;
|
||||
}
|
||||
module.exports = function(Self) {
|
||||
let Mixin = {
|
||||
|
|
|
@ -209,5 +209,16 @@
|
|||
"You cannot update these fields": "You cannot update these fields",
|
||||
"CountryFK cannot be empty": "Country cannot be empty",
|
||||
"You are not allowed to modify the alias": "You are not allowed to modify the alias",
|
||||
"You already have the mailAlias": "You already have the mailAlias"
|
||||
"You already have the mailAlias": "You already have the mailAlias",
|
||||
"This machine is already in use.": "This machine is already in use.",
|
||||
"the plate does not exist": "The plate {{plate}} does not exist",
|
||||
"We do not have availability for the selected item": "We do not have availability for the selected item",
|
||||
"You are already using a machine": "You are already using a machine",
|
||||
"this state does not exist": "This state does not exist",
|
||||
"The line could not be marked": "The line could not be marked",
|
||||
"The sale cannot be tracked": "The sale cannot be tracked",
|
||||
"Shelving not valid": "Shelving not valid",
|
||||
"printerNotExists": "The printer does not exist",
|
||||
"There are not picking tickets": "There are not picking tickets",
|
||||
"ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)"
|
||||
}
|
||||
|
|
|
@ -333,9 +333,11 @@
|
|||
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}",
|
||||
"This claim has been updated": "La reclamación con Id: {{claimId}}, ha sido actualizada",
|
||||
"This user does not have an assigned tablet": "Este usuario no tiene tablet asignada",
|
||||
"Incorrect pin": "Pin incorrecto",
|
||||
"Field are invalid": "El campo '{{tag}}' no es válido",
|
||||
"Incorrect pin": "Pin incorrecto.",
|
||||
"You already have the mailAlias": "Ya tienes este alias de correo",
|
||||
"The alias cant be modified": "Este alias de correo no puede ser modificado",
|
||||
"No tickets to invoice": "No hay tickets para facturar",
|
||||
"this warehouse has not dms": "El Almacén no acepta documentos",
|
||||
"This ticket already has a cmr saved": "Este ticket ya tiene un cmr guardado",
|
||||
"Name should be uppercase": "El nombre debe ir en mayúscula",
|
||||
|
@ -345,5 +347,5 @@
|
|||
"CountryFK cannot be empty": "El país no puede estar vacío",
|
||||
"Cmr file does not exist": "El archivo del cmr no existe",
|
||||
"You are not allowed to modify the alias": "No estás autorizado a modificar el alias",
|
||||
"No tickets to invoice": "No hay tickets para facturar"
|
||||
"The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas"
|
||||
}
|
||||
|
|
|
@ -275,7 +275,7 @@ class VnMySQL extends MySQL {
|
|||
}
|
||||
|
||||
invokeMethod(method, args, model, ctx, opts, cb) {
|
||||
if (!this.isLoggable(model))
|
||||
if (!this.isLoggable(model) && !opts?.userId)
|
||||
return super[method].apply(this, args);
|
||||
|
||||
this.invokeMethodP(method, [...args], model, ctx, opts)
|
||||
|
@ -287,11 +287,11 @@ class VnMySQL extends MySQL {
|
|||
let tx;
|
||||
if (!opts.transaction) {
|
||||
tx = await Transaction.begin(this, {});
|
||||
opts = Object.assign({transaction: tx, httpCtx: opts.httpCtx}, opts);
|
||||
opts = Object.assign({transaction: tx}, opts);
|
||||
}
|
||||
|
||||
try {
|
||||
const userId = opts.httpCtx && opts.httpCtx.active?.accessToken?.userId;
|
||||
const {userId} = opts;
|
||||
if (userId) {
|
||||
const user = await Model.app.models.VnUser.findById(userId, {fields: ['name']}, opts);
|
||||
await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts);
|
||||
|
|
|
@ -3,7 +3,6 @@ module.exports = function(iban, countryCode) {
|
|||
if (typeof iban != 'string') return false;
|
||||
if (countryCode?.toLowerCase() != 'es') return true;
|
||||
|
||||
iban = iban.toUpperCase();
|
||||
iban = trim(iban);
|
||||
iban = iban.replace(/\s/g, '');
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ describe('claimstate isEditable()', () => {
|
|||
const options = {transaction: tx};
|
||||
|
||||
const ctx = {req: {accessToken: {userId: claimManagerId}}};
|
||||
const result = await app.models.ClaimState.isEditable(ctx, 7, options);
|
||||
const result = await app.models.ClaimState.isEditable(ctx, 5, options);
|
||||
|
||||
expect(result).toEqual(true);
|
||||
|
||||
|
|
|
@ -21,12 +21,13 @@ describe('Update Claim', () => {
|
|||
claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {});
|
||||
});
|
||||
const newDate = Date.vnNew();
|
||||
const claimManagerId = 72;
|
||||
const originalData = {
|
||||
ticketFk: 3,
|
||||
clientFk: 1101,
|
||||
ticketCreated: newDate,
|
||||
workerFk: 18,
|
||||
claimStateFk: 2,
|
||||
claimStateFk: 5,
|
||||
isChargedToMana: true,
|
||||
responsibility: 4,
|
||||
observation: 'observation'
|
||||
|
@ -77,7 +78,6 @@ describe('Update Claim', () => {
|
|||
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
|
||||
|
||||
const pendingState = claimStatesMap.pending;
|
||||
const claimManagerId = 72;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: claimManagerId},
|
||||
|
@ -104,85 +104,7 @@ describe('Update Claim', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it(`should success to update the claimState to 'managed' and send a rocket message`, async() => {
|
||||
const tx = await app.models.Claim.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const newClaim = await app.models.Claim.create(originalData, options);
|
||||
|
||||
const chatModel = app.models.Chat;
|
||||
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
|
||||
|
||||
const managedState = claimStatesMap.managed;
|
||||
const claimManagerId = 72;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: claimManagerId},
|
||||
headers: {origin: url}
|
||||
},
|
||||
args: {
|
||||
observation: 'valid observation',
|
||||
claimStateFk: managedState,
|
||||
hasToPickUp: false
|
||||
}
|
||||
};
|
||||
ctx.req.__ = i18n.__;
|
||||
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
||||
|
||||
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
||||
|
||||
expect(updatedClaim.observation).toEqual(ctx.args.observation);
|
||||
expect(chatModel.sendCheckingPresence).toHaveBeenCalled();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it(`should success to update the claimState to 'resolved' and send a rocket message`, async() => {
|
||||
const tx = await app.models.Claim.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const newClaim = await app.models.Claim.create(originalData, options);
|
||||
|
||||
const chatModel = app.models.Chat;
|
||||
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
|
||||
|
||||
const resolvedState = claimStatesMap.resolved;
|
||||
const claimManagerId = 72;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: claimManagerId},
|
||||
headers: {origin: url}
|
||||
},
|
||||
args: {
|
||||
observation: 'valid observation',
|
||||
claimStateFk: resolvedState,
|
||||
hasToPickUp: false
|
||||
}
|
||||
};
|
||||
ctx.req.__ = i18n.__;
|
||||
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
||||
|
||||
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
||||
|
||||
expect(updatedClaim.observation).toEqual(ctx.args.observation);
|
||||
expect(chatModel.sendCheckingPresence).toHaveBeenCalled();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it(`should success to update the claimState to 'canceled' and send a rocket message`, async() => {
|
||||
it(`should success to update the claimState to 'canceled' and send two rocket message`, async() => {
|
||||
const tx = await app.models.Claim.beginTransaction({});
|
||||
|
||||
try {
|
||||
|
@ -194,7 +116,6 @@ describe('Update Claim', () => {
|
|||
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
|
||||
|
||||
const canceledState = claimStatesMap.canceled;
|
||||
const claimManagerId = 72;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: claimManagerId},
|
||||
|
@ -212,46 +133,7 @@ describe('Update Claim', () => {
|
|||
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
||||
|
||||
expect(updatedClaim.observation).toEqual(ctx.args.observation);
|
||||
expect(chatModel.sendCheckingPresence).toHaveBeenCalled();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it(`should success to update the claimState to 'incomplete' and send a rocket message`, async() => {
|
||||
const tx = await app.models.Claim.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const newClaim = await app.models.Claim.create(originalData, options);
|
||||
|
||||
const chatModel = app.models.Chat;
|
||||
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
|
||||
|
||||
const incompleteState = 5;
|
||||
const claimManagerId = 72;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: claimManagerId},
|
||||
headers: {origin: url}
|
||||
},
|
||||
args: {
|
||||
observation: 'valid observation',
|
||||
claimStateFk: incompleteState,
|
||||
hasToPickUp: false
|
||||
}
|
||||
};
|
||||
ctx.req.__ = i18n.__;
|
||||
await app.models.Claim.updateClaim(ctx, newClaim.id, options);
|
||||
|
||||
let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options);
|
||||
|
||||
expect(updatedClaim.observation).toEqual(ctx.args.observation);
|
||||
expect(chatModel.sendCheckingPresence).toHaveBeenCalled();
|
||||
expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(2);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -21,7 +21,7 @@ describe('Update Claim', () => {
|
|||
clientFk: 1101,
|
||||
ticketCreated: newDate,
|
||||
workerFk: 18,
|
||||
claimStateFk: 2,
|
||||
claimStateFk: 1,
|
||||
isChargedToMana: true,
|
||||
responsibility: 4,
|
||||
observation: 'observation'
|
||||
|
|
|
@ -43,8 +43,5 @@
|
|||
},
|
||||
"ClaimObservation": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ClaimRma": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.observe('before save', async function(ctx) {
|
||||
const changes = ctx.data || ctx.instance;
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
changes.workerFk = loopBackContext.active.accessToken.userId;
|
||||
});
|
||||
};
|
|
@ -45,9 +45,6 @@
|
|||
},
|
||||
"packages": {
|
||||
"type": "number"
|
||||
},
|
||||
"rma": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
@ -56,12 +53,6 @@
|
|||
"model": "ClaimState",
|
||||
"foreignKey": "claimStateFk"
|
||||
},
|
||||
"rmas": {
|
||||
"type": "hasMany",
|
||||
"model": "ClaimRma",
|
||||
"foreignKey": "code",
|
||||
"primaryKey": "rma"
|
||||
},
|
||||
"client": {
|
||||
"type": "belongsTo",
|
||||
"model": "Client",
|
||||
|
|
|
@ -26,23 +26,23 @@ module.exports = Self => {
|
|||
},
|
||||
{
|
||||
arg: 'street',
|
||||
type: 'string'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'postcode',
|
||||
type: 'string'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'city',
|
||||
type: 'string'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'countryFk',
|
||||
type: 'number'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'provinceFk',
|
||||
type: 'number'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'sageTaxTypeFk',
|
||||
|
@ -94,7 +94,7 @@ module.exports = Self => {
|
|||
},
|
||||
{
|
||||
arg: 'despiteOfClient',
|
||||
type: 'number'
|
||||
type: 'any'
|
||||
},
|
||||
{
|
||||
arg: 'hasIncoterms',
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<vn-horizontal>
|
||||
<vn-textfield
|
||||
label="IBAN"
|
||||
ng-keyup="$ctrl.client.iban = $ctrl.client.iban.toUpperCase()"
|
||||
ng-model="$ctrl.client.iban"
|
||||
rule
|
||||
on-change="$ctrl.autofillBic()"
|
||||
|
|
|
@ -37,7 +37,7 @@ describe('Entry filter()', () => {
|
|||
|
||||
const result = await models.Entry.filter(ctx, options);
|
||||
|
||||
expect(result.length).toEqual(8);
|
||||
expect(result.length).toEqual(9);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
@ -81,7 +81,7 @@ describe('Entry filter()', () => {
|
|||
|
||||
const result = await models.Entry.filter(ctx, options);
|
||||
|
||||
expect(result.length).toEqual(7);
|
||||
expect(result.length).toEqual(8);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -80,6 +80,6 @@ module.exports = Self => {
|
|||
|
||||
const content = toCSV(sales);
|
||||
|
||||
return [content, 'text/csv', `inline; filename="doc-${reference}.pdf"`];
|
||||
return [content, 'text/csv', `inline; filename="doc-${reference}.csv"`];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('delete', {
|
||||
description: 'Delete an ItemBarcode by itemFk and code',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'barcode',
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'itemFk',
|
||||
type: 'number',
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: `/delete`,
|
||||
verb: 'DELETE'
|
||||
}
|
||||
});
|
||||
|
||||
Self.delete = async(barcode, itemFk, options) => {
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
await Self.destroyAll({
|
||||
code: barcode,
|
||||
itemFk
|
||||
}, myOptions);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('itemBarcode delete()', () => {
|
||||
it('should delete a record by itemFk and code', async() => {
|
||||
const tx = await models.ItemBarcode.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const itemFk = 1;
|
||||
const code = 1111111111;
|
||||
|
||||
try {
|
||||
const itemsBarcodeBefore = await models.ItemBarcode.find({}, options);
|
||||
await models.ItemBarcode.delete(code, itemFk, options);
|
||||
const itemsBarcodeAfter = await models.ItemBarcode.find({}, options);
|
||||
|
||||
expect(itemsBarcodeBefore.length).toBeGreaterThan(itemsBarcodeAfter.length);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,64 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('getAlternative', {
|
||||
description: 'Returns a list of items and possible alternative locations',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'shelvingFk',
|
||||
type: 'string',
|
||||
required: true,
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getAlternative`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getAlternative = async(shelvingFk, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const filterItemShelvings = {
|
||||
fields: ['id', 'visible', 'itemFk', 'shelvingFk'],
|
||||
where: {shelvingFk},
|
||||
include: [
|
||||
{
|
||||
relation: 'item',
|
||||
scope: {
|
||||
fields: ['longName', 'name', 'size']
|
||||
}
|
||||
},
|
||||
|
||||
]
|
||||
};
|
||||
|
||||
let itemShelvings = await models.ItemShelving.find(filterItemShelvings, myOptions);
|
||||
|
||||
if (itemShelvings) {
|
||||
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)',
|
||||
[shelvingFk], myOptions
|
||||
);
|
||||
return itemShelvings.map(itemShelving => {
|
||||
const item = itemShelving.item();
|
||||
|
||||
const shelvings = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk);
|
||||
|
||||
return {
|
||||
id: itemShelving.id,
|
||||
itemFk: itemShelving.itemFk,
|
||||
name: item.name,
|
||||
size: item.size,
|
||||
longName: item.longName,
|
||||
quantity: itemShelving.visible,
|
||||
shelvings
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('itemShelving getAlternative()', () => {
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
headers: {origin: 'http://localhost'},
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should return a list of items without alternatives', async() => {
|
||||
const shelvingFk = 'HEJ';
|
||||
const itemShelvings = await models.ItemShelving.getAlternative(shelvingFk);
|
||||
|
||||
expect(itemShelvings[0].shelvings.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should return an empty list', async() => {
|
||||
const shelvingFk = 'ZZP';
|
||||
const itemShelvings = await models.ItemShelving.getAlternative(shelvingFk);
|
||||
|
||||
expect(itemShelvings.length).toEqual(0);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('itemShelving updateFromSale()', () => {
|
||||
it('should update the quantity', async() => {
|
||||
const tx = await models.ItemBarcode.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const saleFk = 2;
|
||||
const filter = {where: {itemFk: 4, shelvingFk: 'HEJ'}
|
||||
};
|
||||
try {
|
||||
const {visible: visibleBefore} = await models.ItemShelving.findOne(filter, options);
|
||||
await models.ItemShelving.updateFromSale(saleFk, options);
|
||||
const {visible: visibleAfter} = await models.ItemShelving.findOne(filter, options);
|
||||
|
||||
expect(visibleAfter).toEqual(visibleBefore + 5);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,48 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('updateFromSale', {
|
||||
description: 'Update the visible items',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'saleFk',
|
||||
type: 'number',
|
||||
required: true,
|
||||
}],
|
||||
http: {
|
||||
path: `/updateFromSale`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateFromSale = async(saleFk, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const itemShelvingSale = await models.ItemShelvingSale.findOne({
|
||||
where: {saleFk},
|
||||
include: {relation: 'itemShelving'}
|
||||
}, myOptions);
|
||||
|
||||
const itemShelving = itemShelvingSale.itemShelving();
|
||||
const quantity = itemShelving.visible + itemShelvingSale.quantity;
|
||||
|
||||
await itemShelving.updateAttributes(
|
||||
{visible: quantity},
|
||||
myOptions
|
||||
);
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,48 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('get', {
|
||||
description: 'Get the data from an item',
|
||||
accessType: 'READ',
|
||||
http: {
|
||||
path: `/get`,
|
||||
verb: 'GET'
|
||||
},
|
||||
accepts: [
|
||||
{
|
||||
arg: 'barcode',
|
||||
type: 'number',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'warehouseFk',
|
||||
type: 'number',
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
});
|
||||
|
||||
Self.get = async(barcode, warehouseFk, options) => {
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const models = Self.app.models;
|
||||
|
||||
const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [barcode, warehouseFk], myOptions);
|
||||
|
||||
if (itemInfo) {
|
||||
itemInfo.barcodes = await models.ItemBarcode.find({
|
||||
fields: ['code'],
|
||||
where: {
|
||||
itemFk: itemInfo.id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return itemInfo;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('item get()', () => {
|
||||
const barcode = 1;
|
||||
const warehouseFk = 1;
|
||||
it('should get an item with several barcodes', async() => {
|
||||
const card = await models.Item.get(barcode, warehouseFk);
|
||||
|
||||
expect(card).toBeDefined();
|
||||
expect(card.barcodes.length).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -1,5 +1,6 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/item-barcode/toItem')(Self);
|
||||
require('../methods/item-barcode/delete')(Self);
|
||||
|
||||
Self.validatesUniquenessOf('code', {
|
||||
message: `Barcode must be unique`
|
||||
|
|
|
@ -2,4 +2,6 @@ module.exports = Self => {
|
|||
require('../methods/item-shelving/deleteItemShelvings')(Self);
|
||||
require('../methods/item-shelving/upsertItem')(Self);
|
||||
require('../methods/item-shelving/getInventory')(Self);
|
||||
require('../methods/item-shelving/getAlternative')(Self);
|
||||
require('../methods/item-shelving/updateFromSale')(Self);
|
||||
};
|
||||
|
|
|
@ -54,7 +54,8 @@
|
|||
"shelving": {
|
||||
"type": "belongsTo",
|
||||
"model": "Shelving",
|
||||
"foreignKey": "shelvingFk"
|
||||
}
|
||||
"foreignKey": "shelvingFk",
|
||||
"primaryKey": "code"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ module.exports = Self => {
|
|||
require('../methods/item/buyerWasteEmail')(Self);
|
||||
require('../methods/item/labelPdf')(Self);
|
||||
require('../methods/item/setVisibleDiscard')(Self);
|
||||
require('../methods/item/get')(Self);
|
||||
|
||||
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('addLog', {
|
||||
description: 'Add a new log',
|
||||
accessType: 'WRITE',
|
||||
accepts: {
|
||||
arg: 'code',
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
http: {
|
||||
path: '/addLog',
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
Self.addLog = async(ctx, code, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const $t = ctx.req.__;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const shelving = await Self.findOne({
|
||||
where: {
|
||||
code
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
if (!shelving) throw new UserError($t('Shelving not valid'));
|
||||
|
||||
await models.ShelvingLog.create({
|
||||
changedModel: 'Shelving',
|
||||
originFk: shelving.id,
|
||||
changedModelId: shelving.id,
|
||||
action: 'select',
|
||||
userFk: userId
|
||||
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,46 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('shelving addLog()', () => {
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
headers: {origin: 'http://localhost'},
|
||||
accessToken: {userId: 66},
|
||||
__: value => value
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should add a log', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const code = 'AA6';
|
||||
|
||||
try {
|
||||
const shelvingLogsBefore = await models.ShelvingLog.find(null, options);
|
||||
await models.Shelving.addLog(ctx, code, options);
|
||||
const shelvingLogsAfter = await models.ShelvingLog.find(null, options);
|
||||
|
||||
expect(shelvingLogsAfter.length).toEqual(shelvingLogsBefore.length + 1);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error when the code does not exist', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const code = 'DXI345';
|
||||
|
||||
try {
|
||||
await models.Shelving.addLog(ctx, code, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual('Shelving not valid');
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/shelving/getSummary')(Self);
|
||||
require('../methods/shelving/addLog')(Self);
|
||||
};
|
||||
|
|
|
@ -26,7 +26,8 @@ describe('Supplier newSupplier()', () => {
|
|||
const options = {transaction: tx};
|
||||
ctx.args = {
|
||||
name: 'NEWSUPPLIER',
|
||||
nif: '12345678Z'
|
||||
nif: '12345678Z',
|
||||
city: 'Gotham'
|
||||
};
|
||||
|
||||
const result = await models.Supplier.newSupplier(ctx, options);
|
||||
|
|
|
@ -19,7 +19,7 @@ module.exports = Self => {
|
|||
type: 'any'
|
||||
}, {
|
||||
arg: 'phone',
|
||||
type: 'string'
|
||||
type: 'any'
|
||||
}, {
|
||||
arg: 'sageTaxTypeFk',
|
||||
type: 'any'
|
||||
|
@ -46,10 +46,10 @@ module.exports = Self => {
|
|||
type: 'any'
|
||||
}, {
|
||||
arg: 'supplierActivityFk',
|
||||
type: 'string'
|
||||
type: 'any'
|
||||
}, {
|
||||
arg: 'healthRegister',
|
||||
type: 'string'
|
||||
type: 'any'
|
||||
}, {
|
||||
arg: 'isVies',
|
||||
type: 'boolean'
|
||||
|
|
|
@ -129,10 +129,13 @@ describe('loopback model Supplier', () => {
|
|||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const newSupplier = await models.Supplier.create({name: 'ALFRED PENNYWORTH'}, options);
|
||||
const fetchedSupplier = await models.Supplier.findById(newSupplier.id, null, options);
|
||||
const newSupplier = {
|
||||
name: 'ALFRED PENNYWORTH', nif: '87805752D', city: 'Gotham'
|
||||
};
|
||||
const supplierCreated = await models.Supplier.create(newSupplier, options);
|
||||
const fetchedSupplier = await models.Supplier.findById(supplierCreated.id, null, options);
|
||||
|
||||
expect(Number(fetchedSupplier.account)).toEqual(4100000000 + newSupplier.id);
|
||||
expect(Number(fetchedSupplier.account)).toEqual(4100000000 + supplierCreated.id);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
|
|
|
@ -17,17 +17,13 @@ module.exports = Self => {
|
|||
message: 'The social name cannot be empty'
|
||||
});
|
||||
|
||||
if (this.city) {
|
||||
Self.validatesPresenceOf('city', {
|
||||
message: 'City cannot be empty'
|
||||
});
|
||||
}
|
||||
Self.validatesPresenceOf('city', {
|
||||
message: 'City cannot be empty'
|
||||
});
|
||||
|
||||
if (this.nif) {
|
||||
Self.validatesPresenceOf('nif', {
|
||||
message: 'The nif cannot be empty'
|
||||
});
|
||||
}
|
||||
Self.validatesPresenceOf('nif', {
|
||||
message: 'The nif cannot be empty'
|
||||
});
|
||||
|
||||
Self.validatesUniquenessOf('nif', {
|
||||
message: 'TIN must be unique'
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('delete', {
|
||||
description: 'Delete sale trackings and item shelving sales',
|
||||
accessType: 'READ',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'saleFk',
|
||||
|
@ -10,21 +10,17 @@ module.exports = Self => {
|
|||
description: 'The sale id'
|
||||
},
|
||||
{
|
||||
arg: 'stateCode',
|
||||
type: 'string'
|
||||
}
|
||||
arg: 'stateCodes',
|
||||
type: ['string']
|
||||
},
|
||||
],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/delete`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.delete = async(saleFk, stateCode, options) => {
|
||||
Self.delete = async(saleFk, stateCodes, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
@ -38,20 +34,24 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
if (stateCode === 'PREPARED') {
|
||||
const itemShelvingSales = await models.ItemShelvingSale.find({where: {saleFk: saleFk}}, myOptions);
|
||||
for (let itemShelvingSale of itemShelvingSales)
|
||||
await itemShelvingSale.destroy(myOptions);
|
||||
}
|
||||
const itemShelvingSales = await models.ItemShelvingSale.find({where: {saleFk: saleFk}}, myOptions);
|
||||
|
||||
const state = await models.State.findOne({
|
||||
where: {code: stateCode}
|
||||
for (let itemShelvingSale of itemShelvingSales)
|
||||
await itemShelvingSale.destroy(myOptions);
|
||||
|
||||
const states = await models.State.find({
|
||||
fields: ['id'],
|
||||
where: {
|
||||
code: {inq: stateCodes}
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
const stateIds = states.map(state => state.id);
|
||||
|
||||
const filter = {
|
||||
where: {
|
||||
saleFk: saleFk,
|
||||
stateFk: state.id
|
||||
stateFk: {inq: stateIds}
|
||||
}
|
||||
};
|
||||
const saleTrackings = await models.SaleTracking.find(filter, myOptions);
|
||||
|
@ -59,8 +59,6 @@ module.exports = Self => {
|
|||
await saleTracking.destroy(myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('setPicked', {
|
||||
description: 'Add the sales line of the item and set the tracking.',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'saleFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'originalQuantity',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'code',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'isChecked',
|
||||
type: 'boolean',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'buyFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'isScanned',
|
||||
type: 'boolean',
|
||||
},
|
||||
{
|
||||
arg: 'quantity',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'itemShelvingFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: `/setPicked`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.setPicked = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned, quantity, itemShelvingFk, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
await models.ItemShelvingSale.create({
|
||||
itemShelvingFk,
|
||||
saleFk,
|
||||
quantity,
|
||||
userFk: userId
|
||||
}, myOptions);
|
||||
|
||||
const itemShelving = await models.ItemShelving.findById(itemShelvingFk, null, myOptions);
|
||||
|
||||
await itemShelving.updateAttributes({visible: itemShelving.visible - quantity}, myOptions);
|
||||
|
||||
await Self.updateAll(
|
||||
{saleFk},
|
||||
{isChecked: true},
|
||||
myOptions
|
||||
);
|
||||
|
||||
await Self.updateTracking(ctx, saleFk, originalQuantity, code, isChecked, null, isScanned, myOptions);
|
||||
|
||||
try {
|
||||
const {itemOriginalFk} = await models.Buy.findById(buyFk, {fields: ['itemOriginalFk']}, myOptions);
|
||||
if (itemOriginalFk) await models.SaleBuy.create({saleFk, buyFk}, myOptions);
|
||||
} catch (e) {
|
||||
throw new UserError('The sale cannot be tracked');
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (e.message == 'The sale cannot be tracked') {
|
||||
if (tx) tx.commit();
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (tx) await tx.rollback();
|
||||
throw new UserError('The line could not be marked');
|
||||
}
|
||||
};
|
||||
};
|
|
@ -11,13 +11,12 @@ describe('sale-tracking delete()', () => {
|
|||
const saleTrackingsBefore = await models.SaleTracking.find(null, options);
|
||||
|
||||
const saleFk = 1;
|
||||
const stateCode = 'PREPARED';
|
||||
const result = await models.SaleTracking.delete(saleFk, stateCode, options);
|
||||
const stateCode = ['PREPARED'];
|
||||
await models.SaleTracking.delete(saleFk, stateCode, options);
|
||||
|
||||
const itemShelvingsAfter = await models.ItemShelvingSale.find(null, options);
|
||||
const saleTrackingsAfter = await models.SaleTracking.find(null, options);
|
||||
|
||||
expect(result).toEqual(true);
|
||||
expect(saleTrackingsAfter.length).toBeLessThan(saleTrackingsBefore.length);
|
||||
expect(itemShelvingsAfter.length).toBeLessThan(itemShelvingsBefore.length);
|
||||
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
describe('saleTracking setPicked()', () => {
|
||||
const saleFk = 1;
|
||||
const originalQuantity = 10;
|
||||
const code = 'PREPARED';
|
||||
const isChecked = true;
|
||||
const buyFk = 1;
|
||||
const isScanned = false;
|
||||
const quantity = 1;
|
||||
const itemShelvingFk = 1;
|
||||
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 104},
|
||||
headers: {origin: 'http://localhost'},
|
||||
__: value => value
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should throw an error if the line was not able to be marked', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const code = 'FAKESTATE';
|
||||
try {
|
||||
await models.SaleTracking.setPicked(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
quantity,
|
||||
itemShelvingFk,
|
||||
options
|
||||
);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toEqual('The line could not be marked');
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error if there are duplicate salebuys', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
try {
|
||||
await models.SaleTracking.setPicked(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
quantity,
|
||||
itemShelvingFk,
|
||||
options
|
||||
);
|
||||
|
||||
await models.SaleTracking.setPicked(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
quantity,
|
||||
itemShelvingFk,
|
||||
options
|
||||
);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toEqual('The sale cannot be tracked');
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
it('should add an itemShelvingSale and Modify a saleTracking', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
try {
|
||||
const itemShelvingSaleBefore = await models.ItemShelvingSale.find({}, options);
|
||||
await models.SaleTracking.setPicked(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
quantity,
|
||||
itemShelvingFk,
|
||||
options
|
||||
);
|
||||
const itemShelvingSaleAfter = await models.ItemShelvingSale.find({}, options);
|
||||
const saleTracking = await models.SaleTracking.findOne({where: {saleFk, isChecked: false}}, options);
|
||||
|
||||
expect(itemShelvingSaleAfter.length).toEqual(itemShelvingSaleBefore.length + 1);
|
||||
expect(saleTracking.isChecked).toBeFalse();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,104 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('saleTracking updateTracking()', () => {
|
||||
const saleFk = 1;
|
||||
const originalQuantity = 10;
|
||||
const code = 'PREPARED';
|
||||
const isChecked = true;
|
||||
const buyFk = 1;
|
||||
const isScanned = false;
|
||||
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 104},
|
||||
headers: {origin: 'http://localhost'},
|
||||
__: value => value
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should throw an error if the state does not exist', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const code = 'FAKESTATE';
|
||||
try {
|
||||
await models.SaleTracking.updateTracking(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
options
|
||||
);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toEqual('this state does not exist');
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
it('should add a new saleTracking and saleBuy', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const saleTrackingBefore = await models.SaleTracking.find(null, options);
|
||||
const saleBuyBefore = await models.SaleBuy.find(null, options);
|
||||
await models.SaleTracking.updateTracking(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
options
|
||||
);
|
||||
|
||||
const saleTrackingAfter = await models.SaleTracking.find(null, options);
|
||||
const saleBuyAfter = await models.SaleBuy.find(null, options);
|
||||
|
||||
expect(saleTrackingAfter.length).toEqual(saleTrackingBefore.length + 1);
|
||||
expect(saleBuyAfter.length).toEqual(saleBuyBefore.length + 1);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should only update a saleTracking', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const saleFk = 2;
|
||||
|
||||
try {
|
||||
const saleTrackingBefore = await models.SaleTracking.find(null, options);
|
||||
await models.SaleTracking.updateTracking(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
options
|
||||
);
|
||||
const saleTrackingAfter = await models.SaleTracking.find(null, options);
|
||||
|
||||
expect(saleTrackingAfter.length).toEqual(saleTrackingBefore.length + 1);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,110 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateTracking', {
|
||||
description: 'Modify a saleTracking record and, if applicable, add a corresponding record in saleBuy.',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'saleFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'originalQuantity',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'code',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'isChecked',
|
||||
type: 'boolean',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'buyFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'isScanned',
|
||||
type: 'boolean',
|
||||
},
|
||||
],
|
||||
http: {
|
||||
path: `/updateTracking`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateTracking = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned = null, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {userId};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const state = await models.State.findOne({
|
||||
where: {code},
|
||||
}, myOptions);
|
||||
|
||||
if (!state) throw new UserError('this state does not exist');
|
||||
const uniqueAttributes = {
|
||||
saleFk,
|
||||
workerFk: userId,
|
||||
stateFk: state?.id,
|
||||
};
|
||||
const attributes = {
|
||||
isChecked,
|
||||
originalQuantity,
|
||||
isScanned
|
||||
};
|
||||
|
||||
const saleTracking = await models.SaleTracking.findOne({
|
||||
where: uniqueAttributes,
|
||||
}, myOptions);
|
||||
|
||||
if (!saleTracking) {
|
||||
await models.SaleTracking.create({
|
||||
...uniqueAttributes,
|
||||
...attributes
|
||||
}, myOptions);
|
||||
} else {
|
||||
await saleTracking.updateAttributes({
|
||||
...attributes
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
let isBuy;
|
||||
if (buyFk) {
|
||||
isBuy = await models.Buy.findOne({
|
||||
where: {
|
||||
id: buyFk,
|
||||
itemOriginalFk: {
|
||||
neq: null
|
||||
}
|
||||
}
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
if (isBuy)
|
||||
await models.SaleBuy.create({saleFk, buyFk}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue