diff --git a/Jenkinsfile b/Jenkinsfile
index 03ac84de3..4a1f9ba54 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -62,13 +62,13 @@ pipeline {
}
}
}
- // stage('Backend') {
- // steps {
- // nodejs('node-v14') {
- // sh 'gulp launchBackTest --ci'
- // }
- // }
- // }
+ stage('Backend') {
+ steps {
+ nodejs('node-v14') {
+ sh 'npm run test:back:ci'
+ }
+ }
+ }
}
}
stage('Build') {
diff --git a/README.md b/README.md
index 1e3ad5e9e..f73a8551b 100644
--- a/README.md
+++ b/README.md
@@ -54,17 +54,17 @@ $ gulp docker
For client-side unit tests run from project's root.
```
-$ jest
+$ npm run test:front
```
For server-side unit tests run from project's root.
```
-$ gulp backTest
+$ npm run test:back
```
For end-to-end tests run from project's root.
```
-$ gulp e2e
+$ npm run test:e2e
```
## Visual Studio Code extensions
diff --git a/back/methods/account/specs/change-password.spec.js b/back/methods/account/specs/change-password.spec.js
index 9f1130df5..17fadb3c6 100644
--- a/back/methods/account/specs/change-password.spec.js
+++ b/back/methods/account/specs/change-password.spec.js
@@ -1,9 +1,12 @@
-const app = require('vn-loopback/server/server');
+const {models} = require('vn-loopback/server/server');
describe('account changePassword()', () => {
it('should throw an error when old password is wrong', async() => {
- let req = app.models.Account.changePassword(null, 1, 'wrongOldPass', 'newPass');
+ let err;
+ await models.Account.changePassword(1, 'wrongPassword', 'nightmare.9999')
+ .catch(error => err = error.sqlMessage);
- await expectAsync(req).toBeRejected();
+ expect(err).toBeDefined();
+ expect(err).toEqual('Invalid password');
});
});
diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js
index 5c27d72fd..6560240c6 100644
--- a/back/methods/chat/sendCheckingPresence.js
+++ b/back/methods/chat/sendCheckingPresence.js
@@ -46,7 +46,7 @@ module.exports = Self => {
const {data} = await Self.getUserStatus(recipient.name);
if (data) {
- if (data.status === 'offline') {
+ if (data.status === 'offline' || data.status === 'busy') {
// Send message to department room
const workerDepartment = await models.WorkerDepartment.findById(recipientId, {
include: {
@@ -58,6 +58,8 @@ module.exports = Self => {
if (channelName)
return Self.send(ctx, `#${channelName}`, `@${recipient.name} ➔ ${message}`);
+ else
+ return Self.send(ctx, `@${recipient.name}`, message);
} else
return Self.send(ctx, `@${recipient.name}`, message);
}
diff --git a/back/methods/collection/collectionFaults.js b/back/methods/collection/collectionFaults.js
deleted file mode 100644
index 395c7e581..000000000
--- a/back/methods/collection/collectionFaults.js
+++ /dev/null
@@ -1,35 +0,0 @@
-module.exports = Self => {
- Self.remoteMethod('collectionFaults', {
- description: 'Update sale of a collection',
- accessType: 'WRITE',
- accepts: [{
- arg: 'shelvingFk',
- type: 'String',
- required: true,
- description: 'The shalving id'
- }, {
- arg: 'quantity',
- type: 'Number',
- required: true,
- description: 'The quantity to sale'
- }, {
- arg: 'itemFk',
- type: 'Number',
- required: true,
- description: 'The ticket id'
- }],
- returns: {
- type: 'Object',
- root: true
- },
- http: {
- path: `/collectionFaults`,
- verb: 'POST'
- }
- });
-
- Self.collectionFaults = async(shelvingFk, quantity, itemFk) => {
- query = `CALL vn.collection_faults(?,?,?)`;
- return await Self.rawSql(query, [shelvingFk, quantity, itemFk]);
- };
-};
diff --git a/back/methods/collection/setSaleQuantity.js b/back/methods/collection/setSaleQuantity.js
index 82451b8be..95145e9a0 100644
--- a/back/methods/collection/setSaleQuantity.js
+++ b/back/methods/collection/setSaleQuantity.js
@@ -28,7 +28,7 @@ module.exports = Self => {
const args = ctx.args;
const models = Self.app.models;
- const sale = await models.Sale.findById(args.saleId,);
+ const sale = await models.Sale.findById(args.saleId);
return await sale.updateAttribute('quantity', args.quantity);
};
};
diff --git a/back/methods/collection/spec/collectionFauls.spec.js b/back/methods/collection/spec/collectionFauls.spec.js
deleted file mode 100644
index 210dcdf63..000000000
--- a/back/methods/collection/spec/collectionFauls.spec.js
+++ /dev/null
@@ -1,9 +0,0 @@
-const app = require('vn-loopback/server/server');
-describe('collectionFaults()', () => {
- it('return shelving afected', async() => {
- let response = await app.models.Collection.collectionFaults('UXN', 0, 1);
-
- expect(response.length).toBeGreaterThan(0);
- expect(response[0][0].shelvingFk).toEqual('UXN');
- });
-});
diff --git a/back/methods/collection/spec/newCollection.spec.js b/back/methods/collection/spec/newCollection.spec.js
index 88d105b4b..6abe73f8e 100644
--- a/back/methods/collection/spec/newCollection.spec.js
+++ b/back/methods/collection/spec/newCollection.spec.js
@@ -1,8 +1,8 @@
const app = require('vn-loopback/server/server');
-// #3400 analizar que hacer con rutas de back colletion
-xdescribe('newCollection()', () => {
- it('return a new collection', async() => {
+describe('newCollection()', () => {
+ it('should return a new collection', async() => {
+ pending('#3400 analizar que hacer con rutas de back collection');
let ctx = {req: {accessToken: {userId: 1106}}};
let response = await app.models.Collection.newCollection(ctx, 1, 1, 1);
diff --git a/back/methods/dms/deleteTrashFiles.js b/back/methods/dms/deleteTrashFiles.js
new file mode 100644
index 000000000..9d16e9d81
--- /dev/null
+++ b/back/methods/dms/deleteTrashFiles.js
@@ -0,0 +1,57 @@
+const fs = require('fs-extra');
+const path = require('path');
+
+module.exports = Self => {
+ Self.remoteMethod('deleteTrashFiles', {
+ description: 'Deletes files that have trash type',
+ accessType: 'WRITE',
+ returns: {
+ type: 'object',
+ root: true
+ },
+ http: {
+ path: `/deleteTrashFiles`,
+ verb: 'POST'
+ }
+ });
+
+ Self.deleteTrashFiles = async(options) => {
+ const tx = await Self.beginTransaction({});
+ const myOptions = {};
+
+ if (typeof options == 'object')
+ Object.assign(myOptions, options);
+
+ if (!myOptions.transaction)
+ myOptions.transaction = tx;
+
+ try {
+ const models = Self.app.models;
+ const DmsContainer = models.DmsContainer;
+
+ const trashDmsType = await models.DmsType.findOne({
+ where: {code: 'trash'}
+ }, myOptions);
+
+ const dmsToDelete = await models.Dms.find({
+ where: {
+ dmsTypeFk: trashDmsType.id
+ }
+ }, myOptions);
+
+ for (let dms of dmsToDelete) {
+ const pathHash = DmsContainer.getHash(dms.id);
+ const dmsContainer = await DmsContainer.container(pathHash);
+ const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file);
+ await fs.unlink(dstFile);
+ await dms.destroy(myOptions);
+ }
+ if (tx) await tx.commit();
+
+ } catch (e) {
+ if (tx) await tx.rollback();
+
+ throw e;
+ }
+ };
+};
diff --git a/back/methods/docuware/specs/checkFile.spec.js b/back/methods/docuware/specs/checkFile.spec.js
index 2ebde0df4..0d0e4d71a 100644
--- a/back/methods/docuware/specs/checkFile.spec.js
+++ b/back/methods/docuware/specs/checkFile.spec.js
@@ -12,9 +12,9 @@ describe('docuware download()', () => {
}
};
- const fileCabinetName = 'deliveryClientTest';
+ const fileCabinetName = 'deliveryClient';
const dialogDisplayName = 'find';
- const dialogName = 'findTest';
+ const dialogName = 'findTicket';
const gotGetResponse = {
body: JSON.stringify(
diff --git a/back/methods/docuware/specs/download.spec.js b/back/methods/docuware/specs/download.spec.js
index 436063fd8..dc80c67d8 100644
--- a/back/methods/docuware/specs/download.spec.js
+++ b/back/methods/docuware/specs/download.spec.js
@@ -14,9 +14,9 @@ describe('docuware download()', () => {
};
it('should return the downloaded file name', async() => {
- const fileCabinetName = 'deliveryClientTest';
+ const fileCabinetName = 'deliveryClient';
const dialogDisplayName = 'find';
- const dialogName = 'findTest';
+ const dialogName = 'findTicket';
const gotGetResponse = {
body: JSON.stringify(
{
diff --git a/back/models/account.json b/back/models/account.json
index 9150bc1a7..5f0b05f9b 100644
--- a/back/models/account.json
+++ b/back/models/account.json
@@ -47,7 +47,7 @@
"type": "date"
},
"image": {
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/back/models/autonomy.json b/back/models/autonomy.json
index ce9ac0bc6..8c9d82936 100644
--- a/back/models/autonomy.json
+++ b/back/models/autonomy.json
@@ -9,7 +9,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
diff --git a/back/models/bank-entity.json b/back/models/bank-entity.json
index c45cd4336..35d1116bd 100644
--- a/back/models/bank-entity.json
+++ b/back/models/bank-entity.json
@@ -8,15 +8,15 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"bic": {
- "type": "String"
+ "type": "string"
},
"name": {
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/back/models/bank.json b/back/models/bank.json
index 33a2637d6..da73b1141 100644
--- a/back/models/bank.json
+++ b/back/models/bank.json
@@ -8,35 +8,35 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"bank": {
- "type": "String",
+ "type": "string",
"required": true
},
"account": {
- "type": "String",
+ "type": "string",
"required": true
},
"accountingTypeFk": {
- "type": "Number",
+ "type": "number",
"required": true,
"mysql": {
"columnName": "cash"
}
},
"entityFk": {
- "type": "Number",
+ "type": "number",
"required": true
},
"isActive": {
- "type": "Boolean",
+ "type": "boolean",
"required": true
},
"currencyFk": {
- "type": "Number",
+ "type": "number",
"required": true
}
},
diff --git a/back/models/chat-config.json b/back/models/chat-config.json
index d4f708b7a..bdfbeb60d 100644
--- a/back/models/chat-config.json
+++ b/back/models/chat-config.json
@@ -10,20 +10,20 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"host": {
- "type": "String"
+ "type": "string"
},
"api": {
- "type": "String"
+ "type": "string"
},
"user": {
- "type": "String"
+ "type": "string"
},
"password": {
- "type": "String"
+ "type": "string"
}
},
"acls": [{
diff --git a/back/models/collection.js b/back/models/collection.js
index 29a0c4c32..436414f62 100644
--- a/back/models/collection.js
+++ b/back/models/collection.js
@@ -3,5 +3,4 @@ module.exports = Self => {
require('../methods/collection/newCollection')(Self);
require('../methods/collection/getSectors')(Self);
require('../methods/collection/setSaleQuantity')(Self);
- require('../methods/collection/collectionFaults')(Self);
};
diff --git a/back/models/company.json b/back/models/company.json
index eb349477b..a36b43b69 100644
--- a/back/models/company.json
+++ b/back/models/company.json
@@ -10,11 +10,11 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"description": "Identifier"
},
"code": {
- "type": "String"
+ "type": "string"
},
"expired": {
"type": "date"
diff --git a/back/models/country.json b/back/models/country.json
index 8364636fc..8fa25b88e 100644
--- a/back/models/country.json
+++ b/back/models/country.json
@@ -9,7 +9,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
@@ -21,7 +21,7 @@
"type": "string"
},
"isUeeMember": {
- "type": "Boolean"
+ "type": "boolean"
}
},
"relations": {
diff --git a/back/models/delivery.json b/back/models/delivery.json
index 7c3c5c621..65a0eef1b 100644
--- a/back/models/delivery.json
+++ b/back/models/delivery.json
@@ -9,17 +9,17 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"forceId": false
},
"date": {
- "type": "Date"
+ "type": "date"
},
"m3":{
- "type": "Number"
+ "type": "number"
},
"warehouseFk":{
- "type": "Number"
+ "type": "number"
}
}
}
diff --git a/back/models/dms-type.json b/back/models/dms-type.json
index b51c810ac..c7a1815fe 100644
--- a/back/models/dms-type.json
+++ b/back/models/dms-type.json
@@ -9,7 +9,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
diff --git a/back/models/dms.js b/back/models/dms.js
index 91291a0c2..24c072f56 100644
--- a/back/models/dms.js
+++ b/back/models/dms.js
@@ -5,6 +5,7 @@ module.exports = Self => {
require('../methods/dms/uploadFile')(Self);
require('../methods/dms/removeFile')(Self);
require('../methods/dms/updateFile')(Self);
+ require('../methods/dms/deleteTrashFiles')(Self);
Self.checkRole = async function(ctx, id) {
const models = Self.app.models;
diff --git a/back/models/dms.json b/back/models/dms.json
index f517a23ff..0259e5487 100644
--- a/back/models/dms.json
+++ b/back/models/dms.json
@@ -13,7 +13,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
@@ -36,7 +36,7 @@
"type": "boolean"
},
"created": {
- "type": "Date"
+ "type": "date"
}
},
"relations": {
diff --git a/back/models/email-user.json b/back/models/email-user.json
index e983635ce..81c01ab0c 100644
--- a/back/models/email-user.json
+++ b/back/models/email-user.json
@@ -9,7 +9,7 @@
"properties": {
"userFk": {
"id": true,
- "type": "Number",
+ "type": "number",
"required": true
},
"email": {
diff --git a/back/models/image-collection-size.json b/back/models/image-collection-size.json
index adb92d16b..9452456ee 100644
--- a/back/models/image-collection-size.json
+++ b/back/models/image-collection-size.json
@@ -8,20 +8,20 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"width": {
- "type": "Number",
+ "type": "number",
"required": true
},
"height": {
- "type": "Number",
+ "type": "number",
"required": true
},
"crop": {
- "type": "Boolean",
+ "type": "boolean",
"required": true
}
},
diff --git a/back/models/image-collection.json b/back/models/image-collection.json
index fd019ecc3..186ab0208 100644
--- a/back/models/image-collection.json
+++ b/back/models/image-collection.json
@@ -8,32 +8,32 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier"
},
"name": {
- "type": "String",
+ "type": "string",
"required": true
},
"desc": {
- "type": "String",
+ "type": "string",
"required": true
},
"maxWidth": {
- "type": "Number",
+ "type": "number",
"required": true
},
"maxHeight": {
- "type": "Number",
+ "type": "number",
"required": true
},
"model": {
- "type": "String",
+ "type": "string",
"required": true
},
"property": {
- "type": "String",
+ "type": "string",
"required": true
}
},
diff --git a/back/models/postcode.json b/back/models/postcode.json
index e28a77dc4..eadc2c86c 100644
--- a/back/models/postcode.json
+++ b/back/models/postcode.json
@@ -9,7 +9,7 @@
"properties": {
"code": {
"id": true,
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/back/models/sage-withholding.json b/back/models/sage-withholding.json
index dddbcfd74..87f00a01c 100644
--- a/back/models/sage-withholding.json
+++ b/back/models/sage-withholding.json
@@ -11,7 +11,7 @@
},
"properties": {
"id": {
- "type": "Number",
+ "type": "number",
"id": true,
"description": "Identifier",
"mysql": {
diff --git a/back/models/town.json b/back/models/town.json
index 41633fe0a..4ad729791 100644
--- a/back/models/town.json
+++ b/back/models/town.json
@@ -9,10 +9,10 @@
"properties": {
"id": {
"id": true,
- "type": "Number"
+ "type": "number"
},
"name": {
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/back/models/user-config-view.json b/back/models/user-config-view.json
index 8ffbc6f48..f9235725c 100644
--- a/back/models/user-config-view.json
+++ b/back/models/user-config-view.json
@@ -9,18 +9,18 @@
"properties": {
"id": {
"id": true,
- "type": "Number"
+ "type": "number"
},
"userFk": {
- "type": "String",
+ "type": "string",
"required": true
},
"tableCode": {
- "type": "String",
+ "type": "string",
"required": true
},
"configuration": {
- "type": "Object"
+ "type": "object"
}
},
"relations": {
diff --git a/back/models/user-log.json b/back/models/user-log.json
index e3e3a6752..43ccbfa43 100644
--- a/back/models/user-log.json
+++ b/back/models/user-log.json
@@ -9,40 +9,40 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"forceId": false
},
"originFk": {
- "type": "Number",
+ "type": "number",
"required": true
},
"userFk": {
- "type": "Number"
+ "type": "number"
},
"action": {
- "type": "String",
+ "type": "string",
"required": true
},
"changedModel": {
- "type": "String"
+ "type": "string"
},
"oldInstance": {
- "type": "Object"
+ "type": "object"
},
"newInstance": {
- "type": "Object"
+ "type": "object"
},
"creationDate": {
- "type": "Date"
+ "type": "date"
},
"changedModelId": {
- "type": "Number"
+ "type": "number"
},
"changedModelValue": {
- "type": "String"
+ "type": "string"
},
"description": {
- "type": "String"
+ "type": "string"
}
},
"relations": {
diff --git a/back/models/user.json b/back/models/user.json
index 1d8f8f3a5..921362e0e 100644
--- a/back/models/user.json
+++ b/back/models/user.json
@@ -9,7 +9,7 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"forceId": false
},
"username":{
diff --git a/back/models/warehouse.json b/back/models/warehouse.json
index 1d8ca44e3..eb86e2114 100644
--- a/back/models/warehouse.json
+++ b/back/models/warehouse.json
@@ -10,17 +10,17 @@
"properties": {
"id": {
"id": true,
- "type": "Number",
+ "type": "number",
"forceId": false
},
"name": {
- "type": "String"
+ "type": "string"
},
"code": {
- "type": "String"
+ "type": "string"
},
"isInventory": {
- "type": "Number"
+ "type": "number"
},
"isManaged":{
"type": "boolean"
diff --git a/back/nodemonConfig.json b/back/nodemonConfig.json
new file mode 100644
index 000000000..a1c9ca84f
--- /dev/null
+++ b/back/nodemonConfig.json
@@ -0,0 +1,24 @@
+{
+ "verbose": true,
+ "watch": [
+ "back/**/*.js",
+ "modules/**/*.js"
+ ],
+ "ignore": [
+ "modules/account/front/**/*",
+ "modules/claim/front/**/*",
+ "modules/client/front/**/*",
+ "modules/entry/front/**/*",
+ "modules/invoiceIn/front/**/*",
+ "modules/invoiceOut/front/**/*",
+ "modules/item/front/**/*",
+ "modules/monitor/front/**/*",
+ "modules/order/front/**/*",
+ "modules/route/front/**/*",
+ "modules/supplier/front/**/*",
+ "modules/ticket/front/**/*",
+ "modules/travel/front/**/*",
+ "modules/worker/front/**/*",
+ "modules/zone/front/**/*"
+ ]
+}
\ No newline at end of file
diff --git a/back/tests.js b/back/tests.js
index c715c96bf..809906177 100644
--- a/back/tests.js
+++ b/back/tests.js
@@ -1,4 +1,5 @@
-require('require-yaml');
+const Docker = require('../db/docker.js');
+let dataSources = require('../loopback/server/datasources.json');
process.on('warning', warning => {
console.log(warning.name);
@@ -6,34 +7,64 @@ process.on('warning', warning => {
console.log(warning.stack);
});
-let verbose = false;
+async function test() {
+ let isCI = false;
-if (process.argv[2] === '--v')
- verbose = true;
+ if (process.argv[2] === 'ci')
+ isCI = true;
-let Jasmine = require('jasmine');
-let jasmine = new Jasmine();
-let SpecReporter = require('jasmine-spec-reporter').SpecReporter;
+ const container = new Docker();
-let serviceSpecs = [
- `${__dirname}/**/*[sS]pec.js`,
- `${__dirname}/../loopback/**/*[sS]pec.js`,
- `${__dirname}/../modules/*/back/**/*.[sS]pec.js`
-];
+ await container.run(isCI);
+ dataSources = JSON.parse(JSON.stringify(dataSources));
-jasmine.loadConfig({
- spec_dir: '.',
- spec_files: serviceSpecs,
- helpers: []
-});
+ Object.assign(dataSources.vn, {
+ host: container.dbConf.host,
+ port: container.dbConf.port
+ });
-jasmine.addReporter(new SpecReporter({
- spec: {
- // displayStacktrace: 'summary',
- displaySuccessful: verbose,
- displayFailedSpec: true,
- displaySpecDuration: true
+ const bootOptions = {dataSources};
+ const app = require('vn-loopback/server/server');
+ app.boot(bootOptions);
+
+ const Jasmine = require('jasmine');
+ const jasmine = new Jasmine();
+
+ const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
+ jasmine.addReporter(new SpecReporter({
+ spec: {
+ displaySuccessful: isCI,
+ displayPending: isCI
+ },
+ summary: {
+ displayPending: false,
+ }
+ }));
+
+ if (isCI) {
+ const JunitReporter = require('jasmine-reporters');
+ jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
+
+ jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
}
-}));
-jasmine.execute();
+ const backSpecs = [
+ './back/**/*[sS]pec.js',
+ './loopback/**/*[sS]pec.js',
+ './modules/*/back/**/*.[sS]pec.js'
+ ];
+
+ jasmine.loadConfig({
+ spec_dir: '.',
+ spec_files: backSpecs,
+ helpers: [],
+ });
+
+ jasmine.exitOnCompletion = false;
+ await jasmine.execute();
+ if (app) await app.disconnect();
+ if (container) await container.rm();
+ console.log('app disconnected & container removed');
+}
+
+test();
diff --git a/db/changes/10451-april/00-aclExpeditionState.sql b/db/changes/10451-april/00-aclExpeditionState.sql
new file mode 100644
index 000000000..d26117bbf
--- /dev/null
+++ b/db/changes/10451-april/00-aclExpeditionState.sql
@@ -0,0 +1,2 @@
+INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
+VALUES('ExpeditionState', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
\ No newline at end of file
diff --git a/db/changes/10451-april/00-aclExpense.sql b/db/changes/10451-april/00-aclExpense.sql
new file mode 100644
index 000000000..55ca8c389
--- /dev/null
+++ b/db/changes/10451-april/00-aclExpense.sql
@@ -0,0 +1,5 @@
+INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
+ VALUES('Expense', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
+
+INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
+ VALUES('Expense', '*', 'WRITE', 'ALLOW', 'ROLE', 'administrative');
diff --git a/db/changes/10451-april/00-aclSupplierActivity.sql b/db/changes/10451-april/00-aclSupplierActivity.sql
new file mode 100644
index 000000000..bf73a1506
--- /dev/null
+++ b/db/changes/10451-april/00-aclSupplierActivity.sql
@@ -0,0 +1,5 @@
+INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
+VALUES('SupplierActivity', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
+
+INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
+VALUES('SupplierActivity', '*', 'WRITE', 'ALLOW', 'ROLE', 'administrative');
diff --git a/db/changes/10451-april/00-invoiceOut_queue.sql b/db/changes/10451-april/00-invoiceOut_queue.sql
new file mode 100644
index 000000000..f60bcab77
--- /dev/null
+++ b/db/changes/10451-april/00-invoiceOut_queue.sql
@@ -0,0 +1,14 @@
+create table `vn`.`invoiceOut_queue`
+(
+ invoiceFk int(10) unsigned not null,
+ queued datetime default now() not null,
+ printed datetime null,
+ `status` VARCHAR(50) default '' null,
+ constraint invoiceOut_queue_pk
+ primary key (invoiceFk),
+ constraint invoiceOut_queue_invoiceOut_id_fk
+ foreign key (invoiceFk) references invoiceOut (id)
+ on update cascade on delete cascade
+)
+ comment 'Queue for PDF invoicing';
+
diff --git a/db/changes/10460-mother/00-clientConfig.sql b/db/changes/10460-mother/00-clientConfig.sql
new file mode 100644
index 000000000..cd67a5797
--- /dev/null
+++ b/db/changes/10460-mother/00-clientConfig.sql
@@ -0,0 +1,5 @@
+ALTER TABLE `vn`.`clientConfig` ADD `maxCreditRows` int(11) NULL COMMENT 'Máximo número de registros a mantener en la tabla clientCredit';
+
+UPDATE `vn`.`clientConfig`
+ SET `maxCreditRows` = 10
+ WHERE `id` = 1;
\ No newline at end of file
diff --git a/db/changes/10460-mother/00-dmsForeignKey.sql b/db/changes/10460-mother/00-dmsForeignKey.sql
new file mode 100644
index 000000000..6a4736fdd
--- /dev/null
+++ b/db/changes/10460-mother/00-dmsForeignKey.sql
@@ -0,0 +1,8 @@
+ALTER TABLE `vn`.`propertyDms` DROP FOREIGN KEY propertyDms_FK;
+ALTER TABLE `vn`.`propertyDms` ADD CONSTRAINT propertyDms_FK FOREIGN KEY (dmsFk) REFERENCES `vn`.`dms`(id) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE `vn`.`clientDms` DROP FOREIGN KEY clientDms_ibfk_2;
+ALTER TABLE `vn`.`clientDms` ADD CONSTRAINT clientDms_ibfk_2 FOREIGN KEY (dmsFk) REFERENCES `vn`.`dms`(id) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE `vn`.`workerDocument` DROP FOREIGN KEY workerDocument_ibfk_2;
+ALTER TABLE `vn`.`workerDocument` ADD CONSTRAINT workerDocument_ibfk_2 FOREIGN KEY (document) REFERENCES `vn`.`dms`(id) ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/db/changes/10460-mother/01-dmsType.sql b/db/changes/10460-mother/01-dmsType.sql
new file mode 100644
index 000000000..649ffbc71
--- /dev/null
+++ b/db/changes/10460-mother/01-dmsType.sql
@@ -0,0 +1,5 @@
+ALTER TABLE `vn`.`dmsType` ADD monthToDelete INT UNSIGNED DEFAULT NULL NULL;
+ALTER TABLE `vn`.`dmsType` MODIFY COLUMN monthToDelete int(10) unsigned DEFAULT NULL NULL COMMENT 'Meses en el pasado para ir borrando registros, dejar a null para no borrarlos nunca';
+UPDATE `vn`.`dmsType`
+ SET monthToDelete=6
+ WHERE id=20;
diff --git a/db/changes/10460-mother/02-dmsTrigger.sql b/db/changes/10460-mother/02-dmsTrigger.sql
new file mode 100644
index 000000000..d4525440b
--- /dev/null
+++ b/db/changes/10460-mother/02-dmsTrigger.sql
@@ -0,0 +1,18 @@
+
+DELIMITER $$
+$$
+CREATE TRIGGER `vn`.`dms_beforeDelete`
+BEFORE DELETE
+ON dms FOR EACH ROW
+BEGIN
+ DECLARE vCanNotBeDeleted INT;
+ SELECT COUNT(*) INTO vCanNotBeDeleted
+ FROM dmsType dt
+ WHERE NOT (code <=> 'trash')
+ AND dt.id = OLD.dmsTypeFk;
+
+ IF vCanNotBeDeleted THEN
+ CALL util.throw('A dms can not be deleted');
+ END IF;
+END$$
+DELIMITER ;
diff --git a/db/changes/10460-mother/03-clean.sql b/db/changes/10460-mother/03-clean.sql
new file mode 100644
index 000000000..13951394f
--- /dev/null
+++ b/db/changes/10460-mother/03-clean.sql
@@ -0,0 +1,175 @@
+DROP PROCEDURE IF EXISTS vn.clean;
+
+DELIMITER $$
+$$
+CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clean`()
+BEGIN
+ DECLARE vDateShort DATETIME;
+ DECLARE vOneYearAgo DATE;
+ DECLARE vFourYearsAgo DATE;
+ DECLARE v18Month DATE;
+ DECLARE v26Month DATE;
+ DECLARE v3Month DATE;
+ DECLARE vTrashId varchar(15);
+
+ SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE());
+ SET vOneYearAgo = TIMESTAMPADD(YEAR,-1,CURDATE());
+ SET vFourYearsAgo = TIMESTAMPADD(YEAR,-4,CURDATE());
+ SET v18Month = TIMESTAMPADD(MONTH, -18,CURDATE());
+ SET v26Month = TIMESTAMPADD(MONTH, -26,CURDATE());
+ SET v3Month = TIMESTAMPADD(MONTH, -3, CURDATE());
+
+ 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 itemShelving WHERE created < CURDATE() AND visible = 0;
+ DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,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 tobs FROM ticketObservation tobs
+ JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < TIMESTAMPADD(YEAR,-2,CURDATE());
+ 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 tw.* FROM ticketWeekly tw
+ LEFT JOIN sale s ON s.ticketFk = tw.ticketFk WHERE s.itemFk IS NULL;
+ DELETE FROM claim WHERE ticketCreated < vFourYearsAgo;
+ DELETE FROM message WHERE sendDate < vDateShort;
+ -- Robert ubicacion anterior de trevelLog comentario para debug
+ DELETE sc FROM saleChecked sc
+ JOIN sale s ON sc.saleFk = s.id WHERE s.created < vDateShort;
+ DELETE FROM zoneEvent WHERE `type` = 'day' AND dated < v3Month;
+ 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 FROM stowaway WHERE created < v3Month;
+ DELETE FROM vn.buy WHERE created < vDateShort AND entryFk = 9200;
+ DELETE FROM vn.itemShelvingLog WHERE created < vDateShort;
+ DELETE FROM vn.stockBuyed WHERE creationDate < vDateShort;
+
+
+ -- Equipos duplicados
+ DELETE w.*
+ FROM workerTeam w
+ JOIN (SELECT id, team, workerFk, COUNT(*) - 1 as 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;
+
+ 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;
+
+ 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 ETD < v3Month;
+
+ -- borrar travels sin entradas
+ DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete;
+ CREATE TEMPORARY TABLE tmp.thermographToDelete
+ 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, CURDATE()) AND e.travelFk IS NULL;
+
+ SELECT dt.id into vTrashId
+ FROM vn.dmsType dt
+ WHERE dt.code = 'trash';
+
+ UPDATE tmp.thermographToDelete th
+ JOIN vn.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;
+
+ DELETE t
+ FROM vn.travel t
+ LEFT JOIN vn.entry e ON e.travelFk = t.id
+ WHERE t.shipped < TIMESTAMPADD(MONTH, -3, CURDATE()) 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, CURDATE());
+
+ -- borrar entradas sin compras
+ DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete;
+ CREATE TEMPORARY TABLE tmp.entryToDelete
+ 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, CURDATE()) AND b.entryFK IS NULL;
+
+ DELETE e
+ FROM vn.entry e
+ JOIN tmp.entryToDelete 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
+ SELECT *
+ FROM vn.route r
+ WHERE created < TIMESTAMPADD(YEAR,-4,CURDATE());
+
+ UPDATE tmp.routeToDelete tmp
+ JOIN vn.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;
+
+ -- borrar registros de dua y awb menores a 2 años
+ DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete;
+ CREATE TEMPORARY TABLE tmp.duaToDelete
+ SELECT *
+ FROM vn.dua
+ WHERE operated < TIMESTAMPADD(YEAR,-2,CURDATE());
+
+ UPDATE tmp.duaToDelete tm
+ JOIN vn.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;
+
+ DELETE FROM vn.awb WHERE created < TIMESTAMPADD(YEAR,-2,CURDATE());
+
+ -- Borra los ficheros gestDoc
+ INSERT INTO vn.printServerQueue(priorityFk, labelReportFk)VALUES(1,11);
+
+ -- Borra los registros de collection y ticketcollection
+ DELETE FROM vn.collection WHERE created < vDateShort;
+
+ 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;
+
+END$$
+DELIMITER ;
diff --git a/db/changes/10460-mother/04-acl.sql b/db/changes/10460-mother/04-acl.sql
new file mode 100644
index 000000000..c1dc4f6ed
--- /dev/null
+++ b/db/changes/10460-mother/04-acl.sql
@@ -0,0 +1,2 @@
+INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
+ VALUES ('Dms','deleteTrashFiles','WRITE','ALLOW','ROLE','employee')
\ No newline at end of file
diff --git a/db/changes/10470-family/delete.keep b/db/changes/10470-family/delete.keep
new file mode 100644
index 000000000..e69de29bb
diff --git a/db/docker.js b/db/docker.js
index ea9fe8ed1..34026f85f 100644
--- a/db/docker.js
+++ b/db/docker.js
@@ -24,7 +24,10 @@ module.exports = class Docker {
let d = new Date();
let pad = v => v < 10 ? '0' + v : v;
let stamp = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
+
+ log('Building container image...');
await this.execP(`docker build --build-arg STAMP=${stamp} -t salix-db ./db`);
+ log('Image built.');
let dockerArgs;
@@ -39,6 +42,7 @@ module.exports = class Docker {
let runChown = process.platform != 'linux';
+ log('Starting container...');
const container = await this.execP(`docker run --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`);
this.id = container.stdout.trim();
@@ -158,6 +162,7 @@ module.exports = class Docker {
return reject(new Error('Docker exited, please see the docker logs for more info'));
let conn = mysql.createConnection(myConf);
+
conn.on('error', () => {});
conn.connect(err => {
conn.destroy();
diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql
index 60e568e8d..464933607 100644
--- a/db/dump/dumpedFixtures.sql
+++ b/db/dump/dumpedFixtures.sql
@@ -22,9 +22,29 @@ USE `util`;
LOCK TABLES `config` WRITE;
/*!40000 ALTER TABLE `config` DISABLE KEYS */;
-INSERT INTO `config` VALUES (1,'10411',0,'production',NULL);
+INSERT INTO `config` VALUES (1,'10450',0,'production',NULL);
/*!40000 ALTER TABLE `config` ENABLE KEYS */;
UNLOCK TABLES;
+
+--
+-- Dumping data for table `version`
+--
+
+LOCK TABLES `version` WRITE;
+/*!40000 ALTER TABLE `version` DISABLE KEYS */;
+INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL),('vn-database','10129','7ebb66d5a9e47920e2c5ebfdf373bdf9d1bd6221','2022-05-03 13:46:59','10131');
+/*!40000 ALTER TABLE `version` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `versionLog`
+--
+
+LOCK TABLES `versionLog` WRITE;
+/*!40000 ALTER TABLE `versionLog` DISABLE KEYS */;
+INSERT INTO `versionLog` VALUES ('vn-database','00001','00-test.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','00003','00-sage.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10008','00-alterRoleConfig.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10014','00-rolePrefix.sql','jenkins@10.0.2.68','2022-02-11 00:13:25',NULL,NULL),('vn-database','10017','01-firstScript.sql','jenkins@10.0.2.70','2022-03-09 11:36:54',NULL,NULL),('vn-database','10021','00-bankAccount.sql','jenkins@10.0.2.69','2022-03-16 14:11:22',NULL,NULL),('vn-database','10023','00-firstScript.sql','jenkins@10.0.2.69','2022-03-16 15:05:29',NULL,NULL),('vn-database','10026','00-invoiceInIntrastat.sql','jenkins@10.0.2.69','2022-03-21 15:10:53',NULL,NULL),('vn-database','10027','00-Clientes_cedidos.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10028','00-item_last_buy_.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10029','00-bankToViewAccountingToTable.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10030','00-KkejarNiche.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10036','00-updateBuyConfig.sql','jenkins@10.0.2.69','2022-03-29 12:36:54',NULL,NULL),('vn-database','10037','00-firstScript.sql','jenkins@10.0.2.69','2022-03-28 11:14:26',NULL,NULL),('vn-database','10038','00-printServerQueue.sql','jenkins@10.0.2.69','2022-03-29 08:13:24',NULL,NULL),('vn-database','10048','00-firstScript.sql','jenkins@10.0.2.69','2022-03-30 12:29:06',NULL,NULL),('vn-database','10058','00-vehicleAddFields.sql','jenkins@10.0.2.69','2022-04-06 08:48:34',NULL,NULL),('vn-database','10060','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:11',NULL,NULL),('vn-database','10062','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 10:51:45',NULL,NULL),('vn-database','10064','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 13:57:11',NULL,NULL),('vn-database','10066','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:12',NULL,NULL),('vn-database','10067','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 10:18:20',NULL,NULL),('vn-database','10071','00-packingSiteLog.sql','jenkins@10.0.2.69','2022-04-08 09:37:30',NULL,NULL),('vn-database','10072','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 11:01:46',NULL,NULL),('vn-database','10073','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 13:40:56',NULL,NULL),('vn-database','10074','00-firstScript.sql','jenkins@10.0.2.69','2022-04-10 13:15:05',NULL,NULL),('vn-database','10077','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 08:07:15',NULL,NULL),('vn-database','10078','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 07:44:21',NULL,NULL),('vn-database','10079','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 12:01:37',NULL,NULL),('vn-database','10086','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 08:58:34',NULL,NULL),('vn-database','10087','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 09:39:49',NULL,NULL),('vn-database','10088','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 15:05:12',NULL,NULL),('vn-database','10089','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:12:52',NULL,NULL),('vn-database','10090','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:34:46',NULL,NULL),('vn-database','10092','00-firstScript.sql','jenkins@10.0.2.69','2022-04-19 14:45:46',NULL,NULL),('vn-database','10093','00-autoradioConfig.sql','jenkins@10.0.2.69','2022-05-03 09:16:47',NULL,NULL),('vn-database','10094','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 10:57:30',NULL,NULL),('vn-database','10099','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10100','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10101','00-firstScript.sql','jenkins@10.0.2.69','2022-04-21 14:59:31',NULL,NULL),('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL),('vn-database','10114','00-updateConfig.sql','jenkins@10.0.2.69','2022-04-27 13:37:25',NULL,NULL),('vn-database','10116','00-firstScript.sql','jenkins@10.0.2.69','2022-04-28 11:10:14',NULL,NULL),('vn-database','10118','00-firstScript.sql','jenkins@10.0.2.69','2022-04-29 08:10:15',NULL,NULL),('vn-database','10127','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 11:04:46',NULL,NULL),('vn-database','10128','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 13:04:31',NULL,NULL),('vn-database','10129','00-firstScript.sql','jenkins@10.0.2.69','2022-05-03 08:21:01',NULL,NULL);
+/*!40000 ALTER TABLE `versionLog` ENABLE KEYS */;
+UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
@@ -34,7 +54,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:13
+-- Dump completed on 2022-05-04 15:58:27
USE `account`;
-- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64)
--
@@ -120,7 +140,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:14
+-- Dump completed on 2022-05-04 15:58:27
USE `salix`;
-- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64)
--
@@ -144,7 +164,7 @@ USE `salix`;
LOCK TABLES `ACL` WRITE;
/*!40000 ALTER TABLE `ACL` DISABLE KEYS */;
-INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','trainee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','trainee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','trainee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','trainee'),(30,'GreugeType','*','READ','ALLOW','ROLE','trainee'),(31,'Mandate','*','READ','ALLOW','ROLE','trainee'),(32,'MandateType','*','READ','ALLOW','ROLE','trainee'),(33,'Company','*','READ','ALLOW','ROLE','trainee'),(34,'Greuge','*','READ','ALLOW','ROLE','trainee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','trainee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','deleteSales','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','READ','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','claimManager'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','claimManager'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','claimManager'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','trainee'),(111,'ClientLog','*','READ','ALLOW','ROLE','trainee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','trainee'),(114,'Receipt','*','READ','ALLOW','ROLE','trainee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','employee'),(123,'Worker','*','*','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','trainee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','trainee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','*','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'),(151,'Department','*','READ','ALLOW','ROLE','employee'),(152,'Department','*','WRITE','ALLOW','ROLE','hr'),(153,'Route','*','READ','ALLOW','ROLE','employee'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'Calendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'Calendar','absences','READ','ALLOW','ROLE','employee'),(158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'),(160,'TicketServiceType','*','READ','ALLOW','ROLE','employee'),(161,'TicketConfig','*','READ','ALLOW','ROLE','employee'),(162,'InvoiceOut','delete','WRITE','ALLOW','ROLE','invoicing'),(163,'InvoiceOut','book','WRITE','ALLOW','ROLE','invoicing'),(165,'TicketDms','*','*','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(174,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(175,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','trainee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryBoss'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(194,'Postcode','*','WRITE','ALLOW','ROLE','deliveryBoss'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','trainee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'),(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','claimManager'),(203,'UserPhone','*','*','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'),(208,'Sale','recalculatePrice','WRITE','ALLOW','ROLE','employee'),(209,'Ticket','recalculateComponents','WRITE','ALLOW','ROLE','employee'),(211,'TravelLog','*','READ','ALLOW','ROLE','buyer'),(212,'Thermograph','*','*','ALLOW','ROLE','buyer'),(213,'TravelThermograph','*','WRITE','ALLOW','ROLE','buyer'),(214,'Entry','*','*','ALLOW','ROLE','buyer'),(215,'TicketWeekly','*','WRITE','ALLOW','ROLE','buyer'),(216,'TravelThermograph','*','READ','ALLOW','ROLE','employee'),(218,'Intrastat','*','*','ALLOW','ROLE','buyer'),(219,'Account','acl','READ','ALLOW','ROLE','account'),(220,'Account','getCurrentUserData','READ','ALLOW','ROLE','account'),(221,'UserConfig','getUserConfig','READ','ALLOW','ROLE','account'),(222,'Client','*','READ','ALLOW','ROLE','trainee'),(226,'ClientObservation','*','READ','ALLOW','ROLE','trainee'),(227,'Address','*','READ','ALLOW','ROLE','trainee'),(228,'AddressObservation','*','READ','ALLOW','ROLE','trainee'),(230,'ClientCredit','*','READ','ALLOW','ROLE','trainee'),(231,'ClientContact','*','READ','ALLOW','ROLE','trainee'),(232,'ClientSample','*','READ','ALLOW','ROLE','trainee'),(233,'EntryLog','*','READ','ALLOW','ROLE','buyer'),(234,'WorkerLog','*','READ','ALLOW','ROLE','salesAssistant'),(235,'CustomsAgent','*','*','ALLOW','ROLE','employee'),(236,'Buy','*','*','ALLOW','ROLE','buyer'),(237,'WorkerDms','filter','*','ALLOW','ROLE','employee'),(238,'Town','*','WRITE','ALLOW','ROLE','deliveryBoss'),(239,'Province','*','WRITE','ALLOW','ROLE','deliveryBoss'),(240,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(241,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(242,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(244,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(246,'Account','changePassword','*','ALLOW','ROLE','account'),(247,'UserAccount','exists','*','ALLOW','ROLE','account'),(248,'RoleMapping','*','READ','ALLOW','ROLE','account'),(249,'UserPassword','*','READ','ALLOW','ROLE','account'),(250,'Town','*','WRITE','ALLOW','ROLE','deliveryBoss'),(251,'Province','*','WRITE','ALLOW','ROLE','deliveryBoss'),(252,'Supplier','*','READ','ALLOW','ROLE','employee'),(253,'Supplier','*','WRITE','ALLOW','ROLE','administrative'),(254,'SupplierLog','*','READ','ALLOW','ROLE','employee'),(256,'Image','*','WRITE','ALLOW','ROLE','employee'),(257,'FixedPrice','*','*','ALLOW','ROLE','buyer'),(258,'PayDem','*','READ','ALLOW','ROLE','employee'),(259,'Client','createReceipt','*','ALLOW','ROLE','salesAssistant'),(260,'PrintServerQueue','*','WRITE','ALLOW','ROLE','employee'),(261,'SupplierAccount','*','*','ALLOW','ROLE','administrative'),(262,'Entry','*','*','ALLOW','ROLE','administrative'),(263,'InvoiceIn','*','*','ALLOW','ROLE','administrative'),(264,'StarredModule','*','*','ALLOW','ROLE','employee'),(265,'ItemBotanical','*','WRITE','ALLOW','ROLE','logisticBoss'),(266,'ZoneLog','*','READ','ALLOW','ROLE','employee'),(267,'Genus','*','WRITE','ALLOW','ROLE','logisticBoss'),(268,'Specie','*','WRITE','ALLOW','ROLE','logisticBoss'),(269,'InvoiceOut','createPdf','WRITE','ALLOW','ROLE','employee'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'),(272,'InvoiceInLog','*','*','ALLOW','ROLE','employee'),(273,'InvoiceInTax','*','*','ALLOW','ROLE','administrative'),(274,'InvoiceInLog','*','READ','ALLOW','ROLE','administrative'),(275,'InvoiceOut','createManualInvoice','WRITE','ALLOW','ROLE','invoicing'),(276,'InvoiceOut','globalInvoicing','WRITE','ALLOW','ROLE','invoicing'),(277,'Role','*','*','ALLOW','ROLE','it'),(278,'RoleInherit','*','WRITE','ALLOW','ROLE','grant'),(279,'MailAlias','*','*','ALLOW','ROLE','marketing'),(282,'UserAccount','*','WRITE','ALLOW','ROLE','it'),(283,'EntryObservation','*','*','ALLOW','ROLE','buyer'),(284,'LdapConfig','*','*','ALLOW','ROLE','sysadmin'),(285,'SambaConfig','*','*','ALLOW','ROLE','sysadmin'),(286,'ACL','*','*','ALLOW','ROLE','developer'),(287,'AccessToken','*','*','ALLOW','ROLE','developer'),(288,'MailAliasAccount','*','*','ALLOW','ROLE','marketing'),(289,'MailAliasAccount','*','*','ALLOW','ROLE','hr'),(290,'MailAlias','*','*','ALLOW','ROLE','hr'),(291,'MailForward','*','*','ALLOW','ROLE','marketing'),(292,'MailForward','*','*','ALLOW','ROLE','hr'),(293,'RoleInherit','*','*','ALLOW','ROLE','it'),(294,'RoleRole','*','*','ALLOW','ROLE','it'),(295,'AccountConfig','*','*','ALLOW','ROLE','sysadmin'),(296,'Collection','*','READ','ALLOW','ROLE','employee'),(297,'Sale','payBack','WRITE','ALLOW','ROLE','employee'),(298,'InvoiceInDueDay','*','*','ALLOW','ROLE','administrative');
+INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','trainee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','trainee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','trainee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','trainee'),(30,'GreugeType','*','READ','ALLOW','ROLE','trainee'),(31,'Mandate','*','READ','ALLOW','ROLE','trainee'),(32,'MandateType','*','READ','ALLOW','ROLE','trainee'),(33,'Company','*','READ','ALLOW','ROLE','trainee'),(34,'Greuge','*','READ','ALLOW','ROLE','trainee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','trainee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','deleteSales','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','READ','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','claimManager'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','claimManager'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','trainee'),(111,'ClientLog','*','READ','ALLOW','ROLE','trainee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','trainee'),(114,'Receipt','*','READ','ALLOW','ROLE','trainee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','employee'),(123,'Worker','*','*','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','trainee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','trainee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','*','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'),(151,'Department','*','READ','ALLOW','ROLE','employee'),(152,'Department','*','WRITE','ALLOW','ROLE','hr'),(153,'Route','*','READ','ALLOW','ROLE','employee'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'Calendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'Calendar','absences','READ','ALLOW','ROLE','employee'),(158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'),(160,'TicketServiceType','*','READ','ALLOW','ROLE','employee'),(161,'TicketConfig','*','READ','ALLOW','ROLE','employee'),(162,'InvoiceOut','delete','WRITE','ALLOW','ROLE','invoicing'),(163,'InvoiceOut','book','WRITE','ALLOW','ROLE','invoicing'),(165,'TicketDms','*','*','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(174,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(175,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','trainee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryBoss'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(194,'Postcode','*','WRITE','ALLOW','ROLE','deliveryBoss'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','trainee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'),(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','claimManager'),(203,'UserPhone','*','*','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'),(208,'Sale','recalculatePrice','WRITE','ALLOW','ROLE','employee'),(209,'Ticket','recalculateComponents','WRITE','ALLOW','ROLE','employee'),(211,'TravelLog','*','READ','ALLOW','ROLE','buyer'),(212,'Thermograph','*','*','ALLOW','ROLE','buyer'),(213,'TravelThermograph','*','WRITE','ALLOW','ROLE','buyer'),(214,'Entry','*','*','ALLOW','ROLE','buyer'),(215,'TicketWeekly','*','WRITE','ALLOW','ROLE','buyer'),(216,'TravelThermograph','*','READ','ALLOW','ROLE','employee'),(218,'Intrastat','*','*','ALLOW','ROLE','buyer'),(219,'Account','acl','READ','ALLOW','ROLE','account'),(220,'Account','getCurrentUserData','READ','ALLOW','ROLE','account'),(221,'UserConfig','getUserConfig','READ','ALLOW','ROLE','account'),(222,'Client','*','READ','ALLOW','ROLE','trainee'),(226,'ClientObservation','*','READ','ALLOW','ROLE','trainee'),(227,'Address','*','READ','ALLOW','ROLE','trainee'),(228,'AddressObservation','*','READ','ALLOW','ROLE','trainee'),(230,'ClientCredit','*','READ','ALLOW','ROLE','trainee'),(231,'ClientContact','*','READ','ALLOW','ROLE','trainee'),(232,'ClientSample','*','READ','ALLOW','ROLE','trainee'),(233,'EntryLog','*','READ','ALLOW','ROLE','buyer'),(234,'WorkerLog','*','READ','ALLOW','ROLE','salesAssistant'),(235,'CustomsAgent','*','*','ALLOW','ROLE','employee'),(236,'Buy','*','*','ALLOW','ROLE','buyer'),(237,'WorkerDms','filter','*','ALLOW','ROLE','employee'),(238,'Town','*','WRITE','ALLOW','ROLE','deliveryBoss'),(239,'Province','*','WRITE','ALLOW','ROLE','deliveryBoss'),(240,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(241,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(242,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(244,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(246,'Account','changePassword','*','ALLOW','ROLE','account'),(247,'UserAccount','exists','*','ALLOW','ROLE','account'),(248,'RoleMapping','*','READ','ALLOW','ROLE','account'),(249,'UserPassword','*','READ','ALLOW','ROLE','account'),(250,'Town','*','WRITE','ALLOW','ROLE','deliveryBoss'),(251,'Province','*','WRITE','ALLOW','ROLE','deliveryBoss'),(252,'Supplier','*','READ','ALLOW','ROLE','employee'),(253,'Supplier','*','WRITE','ALLOW','ROLE','administrative'),(254,'SupplierLog','*','READ','ALLOW','ROLE','employee'),(256,'Image','*','WRITE','ALLOW','ROLE','employee'),(257,'FixedPrice','*','*','ALLOW','ROLE','buyer'),(258,'PayDem','*','READ','ALLOW','ROLE','employee'),(259,'Client','createReceipt','*','ALLOW','ROLE','salesAssistant'),(260,'PrintServerQueue','*','WRITE','ALLOW','ROLE','employee'),(261,'SupplierAccount','*','*','ALLOW','ROLE','administrative'),(262,'Entry','*','*','ALLOW','ROLE','administrative'),(263,'InvoiceIn','*','*','ALLOW','ROLE','administrative'),(264,'StarredModule','*','*','ALLOW','ROLE','employee'),(265,'ItemBotanical','*','WRITE','ALLOW','ROLE','logisticBoss'),(266,'ZoneLog','*','READ','ALLOW','ROLE','employee'),(267,'Genus','*','WRITE','ALLOW','ROLE','logisticBoss'),(268,'Specie','*','WRITE','ALLOW','ROLE','logisticBoss'),(269,'InvoiceOut','createPdf','WRITE','ALLOW','ROLE','employee'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'),(272,'InvoiceInLog','*','*','ALLOW','ROLE','employee'),(273,'InvoiceInTax','*','*','ALLOW','ROLE','administrative'),(274,'InvoiceInLog','*','READ','ALLOW','ROLE','administrative'),(275,'InvoiceOut','createManualInvoice','WRITE','ALLOW','ROLE','invoicing'),(276,'InvoiceOut','globalInvoicing','WRITE','ALLOW','ROLE','invoicing'),(277,'Role','*','*','ALLOW','ROLE','it'),(278,'RoleInherit','*','WRITE','ALLOW','ROLE','grant'),(279,'MailAlias','*','*','ALLOW','ROLE','marketing'),(282,'UserAccount','*','WRITE','ALLOW','ROLE','it'),(283,'EntryObservation','*','*','ALLOW','ROLE','buyer'),(284,'LdapConfig','*','*','ALLOW','ROLE','sysadmin'),(285,'SambaConfig','*','*','ALLOW','ROLE','sysadmin'),(286,'ACL','*','*','ALLOW','ROLE','developer'),(287,'AccessToken','*','*','ALLOW','ROLE','developer'),(288,'MailAliasAccount','*','*','ALLOW','ROLE','marketing'),(289,'MailAliasAccount','*','*','ALLOW','ROLE','hr'),(290,'MailAlias','*','*','ALLOW','ROLE','hr'),(291,'MailForward','*','*','ALLOW','ROLE','marketing'),(292,'MailForward','*','*','ALLOW','ROLE','hr'),(293,'RoleInherit','*','*','ALLOW','ROLE','it'),(294,'RoleRole','*','*','ALLOW','ROLE','it'),(295,'AccountConfig','*','*','ALLOW','ROLE','sysadmin'),(296,'Collection','*','READ','ALLOW','ROLE','employee'),(297,'Sale','payBack','WRITE','ALLOW','ROLE','employee'),(298,'InvoiceInDueDay','*','*','ALLOW','ROLE','administrative'),(299,'Collection','setSaleQuantity','*','ALLOW','ROLE','employee'),(300,'Docuware','*','*','ALLOW','ROLE','employee'),(301,'Agency','*','READ','ALLOW','ROLE','employee'),(302,'AgencyTerm','*','*','ALLOW','ROLE','administrative'),(303,'ClaimLog','*','READ','ALLOW','ROLE','claimManager'),(304,'Edi','updateData','WRITE','ALLOW','ROLE','employee'),(305,'EducationLevel','*','*','ALLOW','ROLE','employee'),(306,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(307,'SupplierAgencyTerm','*','*','ALLOW','ROLE','administrative'),(308,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee');
/*!40000 ALTER TABLE `ACL` ENABLE KEYS */;
UNLOCK TABLES;
@@ -174,7 +194,7 @@ UNLOCK TABLES;
LOCK TABLES `defaultViewConfig` WRITE;
/*!40000 ALTER TABLE `defaultViewConfig` DISABLE KEYS */;
-INSERT INTO `defaultViewConfig` VALUES ('itemsIndex','{\"intrastat\":false,\"stemMultiplier\":false,\"landed\":false}'),('latestBuys','{\"intrastat\":false,\"description\":false,\"density\":false,\"isActive\":false,\n \"freightValue\":false,\"packageValue\":false,\"isIgnored\":false,\"price2\":false,\"ektFk\":false,\"weight\":false,\n \"size\":false,\"comissionValue\":false,\"landing\":false}'),('ticketsMonitor','{\"id\":false}');
+INSERT INTO `defaultViewConfig` VALUES ('itemsIndex','{\"intrastat\":false,\"stemMultiplier\":false,\"landed\":false,\"producer\":false}'),('latestBuys','{\"intrastat\":false,\"description\":false,\"density\":false,\"isActive\":false,\n \"freightValue\":false,\"packageValue\":false,\"isIgnored\":false,\"price2\":false,\"ektFk\":false,\"weight\":false,\n \"size\":false,\"comissionValue\":false,\"landing\":false}'),('ticketsMonitor','{\"id\":false}');
/*!40000 ALTER TABLE `defaultViewConfig` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
@@ -186,7 +206,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:14
+-- Dump completed on 2022-05-04 15:58:28
USE `vn`;
-- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64)
--
@@ -340,7 +360,7 @@ UNLOCK TABLES;
LOCK TABLES `component` WRITE;
/*!40000 ALTER TABLE `component` DISABLE KEYS */;
-INSERT INTO `component` VALUES (10,'Precios Especiales',4,NULL,NULL,1,'specialPrices',0),(14,'porte extra por dia semana',6,NULL,NULL,1,'extraCostPerWeekDay',0),(15,'reparto',6,NULL,NULL,1,'delivery',1),(17,'recobro',5,NULL,NULL,1,'debtCollection',0),(21,'ajuste',11,NULL,NULL,1,'adjustment',0),(22,'venta por paquete',9,1,NULL,0,'salePerPackage',0),(23,'venta por caja',9,2,NULL,0,'salePerBox',0),(28,'valor de compra',1,NULL,NULL,1,'purchaseValue',1),(29,'margen',4,NULL,NULL,1,'margin',1),(32,'descuento ultimas unidades',9,3,-0.05,0,'lastUnitsDiscount',0),(33,'venta por caja',9,1,NULL,0,'salePerBox',0),(34,'descuento comprador',4,NULL,NULL,1,'buyerDiscount',0),(35,'cartera comprador',10,NULL,NULL,1,NULL,0),(36,'descuadre',12,NULL,NULL,1,'imbalance',0),(37,'maná',7,4,NULL,0,'mana',0),(38,'embolsado',9,NULL,NULL,1,'bagged',0),(39,'maná auto',7,NULL,NULL,1,'autoMana',0),(40,'cambios Santos 2016',4,NULL,NULL,1,NULL,0),(41,'bonificacion porte',6,NULL,NULL,1,'freightCharge',0),(42,'promocion Francia',4,NULL,NULL,1,'frenchOffer',0),(43,'promocion Floramondo',4,NULL,NULL,1,'floramondoPromo',0),(44,'rappel cadena',2,NULL,NULL,1,'rappel',0);
+INSERT INTO `component` VALUES (10,'Precios Especiales',4,NULL,NULL,1,'specialPrices',0),(14,'porte extra por dia semana',6,NULL,NULL,1,'extraCostPerWeekDay',0),(15,'reparto',6,NULL,NULL,1,'delivery',1),(17,'recobro',5,NULL,NULL,1,'debtCollection',0),(21,'ajuste',11,NULL,NULL,1,'adjustment',0),(22,'venta por paquete',9,1,NULL,0,'salePerPackage',0),(23,'venta por caja',9,2,NULL,0,'salePerBox',0),(28,'valor de compra',1,NULL,NULL,1,'purchaseValue',1),(29,'margen',4,NULL,NULL,1,'margin',1),(32,'descuento ultimas unidades',9,3,-0.05,0,'lastUnitsDiscount',0),(33,'venta por caja',9,1,NULL,0,'salePerBox',0),(34,'descuento comprador',4,NULL,NULL,1,'buyerDiscount',0),(35,'cartera comprador',10,NULL,NULL,1,NULL,0),(36,'descuadre',12,NULL,NULL,1,'imbalance',0),(37,'maná',7,4,NULL,0,'mana',0),(38,'embolsado',9,NULL,NULL,1,'bagged',0),(39,'maná auto',7,NULL,NULL,1,'autoMana',0),(40,'cambios Santos 2016',4,NULL,NULL,1,NULL,0),(41,'bonificacion porte',6,NULL,NULL,1,'freightCharge',0),(42,'promocion Francia',4,NULL,NULL,1,'frenchOffer',0),(43,'promocion Floramondo',4,NULL,NULL,1,'floramondoPromo',0),(44,'rappel cadena',2,NULL,NULL,1,'rappel',0),(45,'maná reclamacion',7,4,NULL,0,'manaClaim',0);
/*!40000 ALTER TABLE `component` ENABLE KEYS */;
UNLOCK TABLES;
@@ -370,7 +390,7 @@ UNLOCK TABLES;
LOCK TABLES `department` WRITE;
/*!40000 ALTER TABLE `department` DISABLE KEYS */;
-INSERT INTO `department` VALUES (1,NULL,'VERDNATURA',1,94,763,0,NULL,NULL,NULL,0,0,0,30,NULL,'/',NULL,0,NULL,0,0,0,0),(22,NULL,'COMPRAS',2,3,NULL,72,596,2,5,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0),(23,NULL,'CAMARA',13,14,NULL,72,3758,2,6,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1),(31,'IT','INFORMATICA',4,5,NULL,72,127,3,9,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0),(34,NULL,'CONTABILIDAD',6,7,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0),(35,NULL,'FINANZAS',8,9,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,'finanzas@verdnatura.es',1,0,0,0),(36,NULL,'LABORAL',10,11,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0),(37,NULL,'PRODUCCION',12,27,NULL,72,3758,3,11,1,1,1,7,1,'/1/',NULL,0,NULL,0,1,1,1),(38,NULL,'SACADO',15,16,NULL,72,230,4,14,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0),(39,NULL,'ENCAJADO',17,18,NULL,72,3758,4,12,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0),(41,NULL,'ADMINISTRACION',28,29,NULL,72,599,3,8,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0),(43,NULL,'VENTAS',30,49,NULL,0,NULL,NULL,NULL,0,0,1,9,1,'/1/',NULL,1,'',1,0,0,0),(44,NULL,'GERENCIA',50,51,NULL,72,300,2,7,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(45,NULL,'LOGISTICA',52,53,NULL,72,596,3,19,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0),(46,NULL,'REPARTO',54,55,NULL,72,659,3,10,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0),(48,NULL,'ALMACENAJE',56,57,NULL,0,3758,NULL,NULL,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(49,NULL,'PROPIEDAD',58,59,NULL,72,1008,1,1,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(52,NULL,'CARGA AEREA',60,61,NULL,72,163,4,28,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(53,NULL,'MARKETING Y COMUNICACIÓN',62,63,NULL,72,1238,0,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0),(54,NULL,'ORNAMENTALES',64,65,NULL,72,433,3,21,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(55,NULL,'TALLER NATURAL',66,67,NULL,72,3758,2,23,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0),(56,NULL,'TALLER ARTIFICIAL',68,69,NULL,72,1780,2,24,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0),(58,NULL,'CAMPOS',70,71,NULL,72,3758,2,2,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(59,NULL,'MANTENIMIENTO',72,73,NULL,72,1907,4,16,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(60,NULL,'RECLAMACIONES',74,75,NULL,72,563,3,20,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0),(61,NULL,'VNH',76,77,NULL,73,1297,3,17,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(63,NULL,'VENTAS FRANCIA',31,32,NULL,72,277,2,27,0,0,2,0,43,'/1/43/',NULL,0,NULL,0,0,0,0),(66,NULL,'VERDNAMADRID',78,79,NULL,72,163,3,18,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(68,NULL,'COMPLEMENTOS',19,20,NULL,72,617,3,26,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0),(69,NULL,'VERDNABARNA',80,81,NULL,74,432,3,22,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(80,NULL,'EQUIPO J VALLES',33,34,NULL,72,693,3,4,0,0,2,0,43,'/1/43/','jvp_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0),(86,NULL,'LIMPIEZA',82,83,NULL,72,599,0,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(89,NULL,'COORDINACION',84,85,NULL,0,3758,NULL,NULL,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(90,NULL,'TRAILER',86,87,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0),(91,NULL,'ARTIFICIAL',21,22,NULL,0,3758,NULL,NULL,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0),(92,NULL,'EQUIPO SILVERIO',35,36,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','sdc_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0),(93,NULL,'CONFECCION',88,89,NULL,0,3758,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0),(94,NULL,'EQUIPO J BROCAL',37,38,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','jes_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0),(95,NULL,'EQUIPO C ZAMBRANO',39,40,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','czg_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0),(96,NULL,'EQUIPO C LOPEZ',41,42,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','cla_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0),(115,NULL,'EQUIPO CLAUDI',43,44,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','csr_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0),(123,NULL,'EQUIPO ELENA BASCUÑANA',45,46,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','ebt_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0),(124,NULL,'CONTROL INTERNO',90,91,NULL,72,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0),(125,NULL,'EQUIPO MIRIAM MAR',47,48,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','mir_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0),(126,NULL,'PRESERVADO',92,93,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0),(128,NULL,'PALETIZADO',23,24,NULL,0,NULL,NULL,NULL,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0),(130,NULL,'REVISION',25,26,NULL,0,NULL,NULL,NULL,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0);
+INSERT INTO `department` VALUES (1,NULL,'VERDNATURA',1,94,763,0,NULL,NULL,NULL,0,0,0,30,NULL,'/',NULL,0,NULL,0,0,0,0,NULL),(22,NULL,'COMPRAS',2,3,NULL,72,596,2,5,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(23,NULL,'CAMARA',13,14,NULL,72,3758,2,6,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL),(31,'IT','INFORMATICA',4,5,NULL,72,127,3,9,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL),(34,NULL,'CONTABILIDAD',6,7,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(35,NULL,'FINANZAS',8,9,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(36,NULL,'LABORAL',10,11,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(37,NULL,'PRODUCCION',12,27,NULL,72,3758,3,11,1,1,1,7,1,'/1/',NULL,0,NULL,0,1,1,1,NULL),(38,NULL,'SACADO',15,16,NULL,72,230,4,14,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(39,NULL,'ENCAJADO',17,18,NULL,72,3758,4,12,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(41,NULL,'ADMINISTRACION',28,29,NULL,72,599,3,8,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(43,'VT','VENTAS',30,49,NULL,0,NULL,NULL,NULL,0,0,1,9,1,'/1/',NULL,1,'',1,0,0,0,NULL),(44,NULL,'GERENCIA',50,51,NULL,72,300,2,7,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(45,NULL,'LOGISTICA',52,53,NULL,72,596,3,19,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(46,NULL,'REPARTO',54,55,NULL,72,659,3,10,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL),(48,NULL,'ALMACENAJE',56,57,NULL,0,3758,NULL,NULL,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(49,NULL,'PROPIEDAD',58,59,NULL,72,1008,1,1,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(52,NULL,'CARGA AEREA',60,61,NULL,72,163,4,28,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(53,NULL,'MARKETING Y COMUNICACIÓN',62,63,NULL,72,1238,0,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(54,NULL,'ORNAMENTALES',64,65,NULL,72,433,3,21,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(55,NULL,'TALLER NATURAL',66,67,3366,72,3758,2,23,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0,1118),(56,NULL,'TALLER ARTIFICIAL',68,69,8470,72,1780,2,24,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0,1927),(58,NULL,'CAMPOS',70,71,NULL,72,3758,2,2,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(59,NULL,'MANTENIMIENTO',72,73,NULL,72,1907,4,16,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(60,NULL,'RECLAMACIONES',74,75,NULL,72,563,3,20,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(61,NULL,'VNH',76,77,NULL,73,1297,3,17,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(63,NULL,'VENTAS FRANCIA',31,32,NULL,72,277,2,27,0,0,2,0,43,'/1/43/',NULL,0,NULL,0,0,0,0,NULL),(66,NULL,'VERDNAMADRID',78,79,NULL,72,163,3,18,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(68,NULL,'COMPLEMENTOS',19,20,NULL,72,617,3,26,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(69,NULL,'VERDNABARNA',80,81,NULL,74,432,3,22,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(80,NULL,'EQUIPO J VALLES',33,34,NULL,72,693,3,4,0,0,2,0,43,'/1/43/','jvp_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(86,NULL,'LIMPIEZA',82,83,NULL,72,599,0,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(89,NULL,'COORDINACION',84,85,NULL,0,3758,NULL,NULL,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(90,NULL,'TRAILER',86,87,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(91,NULL,'ARTIFICIAL',21,22,NULL,0,3758,NULL,NULL,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(92,NULL,'EQUIPO SILVERIO',35,36,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','sdc_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(93,NULL,'CONFECCION',88,89,NULL,0,3758,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0,NULL),(94,NULL,'EQUIPO J BROCAL',37,38,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','jes_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(95,NULL,'EQUIPO C ZAMBRANO',39,40,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','czg_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(96,NULL,'EQUIPO C LOPEZ',41,42,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','cla_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(115,NULL,'EQUIPO CLAUDI',43,44,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','csr_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(123,NULL,'EQUIPO ELENA BASCUÑANA',45,46,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','ebt_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(124,NULL,'CONTROL INTERNO',90,91,NULL,72,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(125,NULL,'EQUIPO MIRIAM MAR',47,48,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','mir_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(126,NULL,'PRESERVADO',92,93,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0,NULL),(128,NULL,'PALETIZADO',23,24,NULL,0,NULL,NULL,NULL,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(130,NULL,'REVISION',25,26,NULL,0,NULL,NULL,NULL,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL);
/*!40000 ALTER TABLE `department` ENABLE KEYS */;
UNLOCK TABLES;
@@ -410,7 +430,7 @@ UNLOCK TABLES;
LOCK TABLES `state` WRITE;
/*!40000 ALTER TABLE `state` DISABLE KEYS */;
-INSERT INTO `state` VALUES (1,'Arreglar',2,0,'FIXING',NULL,1,0,0,0,0,0,0,4,1),(2,'Libre',2,0,'FREE',NULL,2,1,0,0,0,1,0,4,1),(3,'OK',3,0,'OK',3,28,1,0,0,0,1,1,3,0),(4,'Impreso',4,0,'PRINTED',2,29,1,0,1,0,0,1,2,0),(5,'Preparación',6,1,'ON_PREPARATION',7,5,0,0,0,2,0,0,2,0),(6,'En Revisión',7,1,'ON_CHECKING',NULL,6,0,1,0,3,0,0,1,0),(7,'Sin Acabar',1,0,'NOT_READY',NULL,7,0,0,0,0,0,0,4,1),(8,'Revisado',8,1,'CHECKED',NULL,8,0,1,0,3,0,0,1,0),(9,'Encajando',9,2,'PACKING',NULL,9,0,1,0,0,0,0,1,0),(10,'Encajado',10,2,'PACKED',NULL,10,0,1,0,0,0,0,0,0),(11,'Facturado',0,3,'INVOICED',NULL,11,0,1,0,0,0,0,0,0),(12,'Bloqueado',0,0,'BLOCKED',NULL,12,0,0,0,0,0,0,4,1),(13,'En Reparto',11,3,'ON_DELIVERY',NULL,13,0,1,0,0,0,0,0,0),(14,'Preparado',6,1,'PREPARED',NULL,14,0,1,0,2,0,0,1,0),(15,'Pte Recogida',12,3,'WAITING_FOR_PICKUP',NULL,15,0,1,0,0,0,0,0,0),(16,'Entregado',13,3,'DELIVERED',NULL,16,0,1,0,0,0,0,0,0),(20,'Asignado',4,0,'PICKER_DESIGNED',NULL,20,1,0,0,0,0,0,2,0),(21,'Retornado',4,1,'PRINTED_BACK',6,21,0,0,0,0,0,0,2,0),(22,'Pte. Ampliar',2,0,'EXPANDABLE',NULL,22,0,0,0,0,0,0,4,1),(23,'URGENTE',5,1,'LAST_CALL',NULL,23,1,0,1,0,0,0,4,1),(24,'Encadenado',4,0,'CHAINED',4,24,0,0,0,0,0,0,3,1),(25,'Embarcando',3,0,'BOARDING',5,25,1,0,0,0,0,0,3,0),(26,'Prep Previa',5,1,'PREVIOUS_PREPARATION',1,28,0,0,0,1,0,0,2,0),(27,'Prep Asistida',5,1,'ASSISTED_PREPARATION',7,27,0,0,0,0,0,0,2,0),(28,'Previa OK',3,1,'OK PREVIOUS',3,28,0,0,0,1,1,1,3,0),(29,'Previa Impreso',4,1,'PRINTED PREVIOUS',2,29,0,0,1,1,0,1,3,0),(30,'Embarcado',4,1,'BOARD',5,30,0,0,0,2,0,0,3,0),(31,'Polizon Impreso',4,1,'PRINTED STOWAWAY',2,29,1,0,1,0,0,1,3,0),(32,'Polizon OK',3,1,'OK STOWAWAY',3,31,1,0,0,1,1,1,3,0),(33,'Auto_Impreso',4,0,'PRINTED_AUTO',2,29,1,0,1,0,0,1,2,0),(34,'Pte Pago',3,0,'WAITING_FOR_PAYMENT',NULL,34,0,0,0,0,0,0,4,1),(35,'Semi-Encajado',9,2,'HALF_PACKED',NULL,10,0,1,0,0,0,0,1,0),(36,'Control Previa',3,1,'PREVIOUS_CONTROL',1,36,0,1,0,4,0,1,3,0);
+INSERT INTO `state` VALUES (1,'Arreglar',2,0,'FIXING',NULL,1,0,0,0,0,0,0,4,1,'alert'),(2,'Libre',2,0,'FREE',NULL,2,1,0,0,0,1,0,4,1,'notice'),(3,'OK',3,0,'OK',3,28,1,0,0,0,1,1,3,0,'success'),(4,'Impreso',4,0,'PRINTED',2,29,1,0,1,0,0,1,2,0,'success'),(5,'Preparación',6,1,'ON_PREPARATION',7,5,0,0,0,2,0,0,2,0,'warning'),(6,'En Revisión',7,1,'ON_CHECKING',NULL,6,0,1,0,3,0,0,1,0,'warning'),(7,'Sin Acabar',1,0,'NOT_READY',NULL,7,0,0,0,0,0,0,4,1,'alert'),(8,'Revisado',8,1,'CHECKED',NULL,8,0,1,0,3,0,0,1,0,'warning'),(9,'Encajando',9,2,'PACKING',NULL,9,0,1,0,0,0,0,1,0,NULL),(10,'Encajado',10,2,'PACKED',NULL,10,0,1,0,0,0,0,0,0,NULL),(11,'Facturado',0,3,'INVOICED',NULL,11,0,1,0,0,0,0,0,0,NULL),(12,'Bloqueado',0,0,'BLOCKED',NULL,12,0,0,0,0,0,0,4,1,'alert'),(13,'En Reparto',11,3,'ON_DELIVERY',NULL,13,0,1,0,0,0,0,0,0,NULL),(14,'Preparado',6,1,'PREPARED',NULL,14,0,1,0,2,0,0,1,0,'warning'),(15,'Pte Recogida',12,3,'WAITING_FOR_PICKUP',NULL,15,0,1,0,0,0,0,0,0,NULL),(16,'Entregado',13,3,'DELIVERED',NULL,16,0,1,0,0,0,0,0,0,NULL),(20,'Asignado',4,0,'PICKER_DESIGNED',NULL,20,1,0,0,0,0,0,2,0,'success'),(21,'Retornado',4,1,'PRINTED_BACK',6,21,0,0,0,0,0,0,2,0,'success'),(22,'Pte. Ampliar',2,0,'EXPANDABLE',NULL,22,0,0,0,0,0,0,4,1,'alert'),(23,'URGENTE',5,1,'LAST_CALL',NULL,23,1,0,1,0,0,0,4,1,'success'),(24,'Encadenado',4,0,'CHAINED',4,24,0,0,0,0,0,0,3,1,'success'),(25,'Embarcando',3,0,'BOARDING',5,25,1,0,0,0,0,0,3,0,'alert'),(26,'Prep Previa',5,1,'PREVIOUS_PREPARATION',1,28,0,0,0,1,0,0,2,0,'warning'),(27,'Prep Asistida',5,1,'ASSISTED_PREPARATION',7,27,0,0,0,0,0,0,2,0,'success'),(28,'Previa OK',3,1,'OK PREVIOUS',3,28,0,0,0,1,1,1,3,0,'warning'),(29,'Previa Impreso',4,1,'PRINTED PREVIOUS',2,29,0,0,1,1,0,1,3,0,'success'),(30,'Embarcado',4,1,'BOARD',5,30,0,0,0,2,0,0,3,0,'success'),(31,'Polizon Impreso',4,1,'PRINTED STOWAWAY',2,29,1,0,1,0,0,1,3,0,'success'),(32,'Polizon OK',3,1,'OK STOWAWAY',3,31,1,0,0,1,1,1,3,0,'warning'),(33,'Auto_Impreso',4,0,'PRINTED_AUTO',2,29,1,0,1,0,0,1,2,0,'success'),(34,'Pte Pago',3,0,'WAITING_FOR_PAYMENT',NULL,34,0,0,0,0,0,0,4,1,'alert'),(35,'Semi-Encajado',9,2,'HALF_PACKED',NULL,10,0,1,0,0,0,0,1,0,NULL),(36,'Control Previa',3,1,'PREVIOUS_CONTROL',1,36,0,1,0,4,0,1,3,0,'warning');
/*!40000 ALTER TABLE `state` ENABLE KEYS */;
UNLOCK TABLES;
@@ -452,7 +472,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:14
+-- Dump completed on 2022-05-04 15:58:28
USE `cache`;
-- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64)
--
@@ -488,7 +508,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:14
+-- Dump completed on 2022-05-04 15:58:28
USE `hedera`;
-- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64)
--
@@ -506,6 +526,16 @@ USE `hedera`;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+--
+-- Dumping data for table `browser`
+--
+
+LOCK TABLES `browser` WRITE;
+/*!40000 ALTER TABLE `browser` DISABLE KEYS */;
+INSERT INTO `browser` VALUES ('Chrome',29),('Firefox',20),('Iceweasel',20),('IE',12),('Opera',12),('Safari',9);
+/*!40000 ALTER TABLE `browser` ENABLE KEYS */;
+UNLOCK TABLES;
+
--
-- Dumping data for table `imageCollection`
--
@@ -516,6 +546,106 @@ INSERT INTO `imageCollection` VALUES (1,'catalog','Artículo',3840,2160,'Item','
/*!40000 ALTER TABLE `imageCollection` ENABLE KEYS */;
UNLOCK TABLES;
+--
+-- Dumping data for table `imageCollectionSize`
+--
+
+LOCK TABLES `imageCollectionSize` WRITE;
+/*!40000 ALTER TABLE `imageCollectionSize` DISABLE KEYS */;
+INSERT INTO `imageCollectionSize` VALUES (2,1,50,50,1),(3,1,200,200,1),(5,5,200,200,1),(6,1,70,70,1),(8,5,50,50,1),(9,1,1600,900,0),(13,6,160,160,1),(14,6,520,520,1),(15,6,1600,1600,1);
+/*!40000 ALTER TABLE `imageCollectionSize` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `language`
+--
+
+LOCK TABLES `language` WRITE;
+/*!40000 ALTER TABLE `language` DISABLE KEYS */;
+INSERT INTO `language` VALUES ('ca','Català','Catalan',1),('en','English','English',1),('es','Español','Spanish',1),('fr','Français','French',1),('mn','Португалий','Mongolian',1),('pt','Português','Portuguese',1);
+/*!40000 ALTER TABLE `language` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `link`
+--
+
+LOCK TABLES `link` WRITE;
+/*!40000 ALTER TABLE `link` DISABLE KEYS */;
+INSERT INTO `link` VALUES (16,'Printing server','Manage the CUPS printing server','http://server.verdnatura.es:631','printer'),(20,'Webmail','Verdnatura webmail','https://webmail.verdnatura.es/','mail'),(23,'Verdnatura Beta','Trial version of the web page','https://test.verdnatura.es/','vn'),(25,'Shared folder','Shared folder','/share','backup'),(29,'phpMyAdmin','Manage MySQL database','https://pma.verdnatura.es/','pma'),(30,'Nagios','Monitoring system','https://nagios.verdnatura.es/','nagios'),(33,'Gitea','Version control system','https://gitea.verdnatura.es/','git'),(34,'Wiknatura','Verdnatura wiki page','https://wiki.verdnatura.es/','wiki'),(35,'phpLDAPadmin','Manage the LDAP database','https://pla.verdnatura.es/','pla'),(36,'Applications','Access applications repository','/vn-access','backup');
+/*!40000 ALTER TABLE `link` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `location`
+--
+
+LOCK TABLES `location` WRITE;
+/*!40000 ALTER TABLE `location` DISABLE KEYS */;
+INSERT INTO `location` VALUES (2,'39.2095886','-0.4173501','Valencia','Calle Fenollar, 2','46680','Algemesi','Valencia','963 242 100','es'),(3,'40.4564969','-3.4875829','Madrid','Avenida de la Constitución, 3 - Nave E','28850','Torrejón de Ardoz','Madrid','916 774 777',NULL),(4,'41.4962045','2.3765504','Barcelona','Camí del crist, 33','08340','Vilassar de Mar','Barcelona','607 562 391','ca'),(5,'52.2612312','4.7818154','Holland','Aalsmeer Flower Auction','1430 BA','Legmeerdijk 313','Aalsmeer','Nederland','nl'),(6,'43.4375416','5.2261456','Marseille','ruben@verdnatura.es','13054','Marigname','Marseille','+33 781 533 900','fr');
+/*!40000 ALTER TABLE `location` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `menu`
+--
+
+LOCK TABLES `menu` WRITE;
+/*!40000 ALTER TABLE `menu` DISABLE KEYS */;
+INSERT INTO `menu` VALUES (1,'Home','cms/home',6,NULL,1),(2,'Orders',NULL,11,NULL,1),(3,'Catalog','ecomerce/catalog',6,NULL,2),(5,'About',NULL,6,NULL,2),(6,'Location','cms/location',6,5,2),(7,'Administration',NULL,1,NULL,2),(8,'Users','admin/users',1,7,2),(9,'Connections','admin/connections',1,7,2),(11,'Agencies','agencies/packages',3,NULL,2),(12,'News','news/news',1,7,3),(14,'Why','cms/why',6,5,2),(15,'Photos','admin/photos',1,7,3),(16,'Training','cms/training',6,NULL,2),(17,'Configuration',NULL,11,NULL,3),(19,'Control panel','admin/links',1,7,1),(20,'About us','cms/about',6,5,1),(21,'Basket','ecomerce/basket',11,NULL,1),(22,'Last orders','ecomerce/orders',11,2,2),(23,'Invoices','ecomerce/invoices',11,2,2),(24,'Account','account/conf',11,17,1),(25,'Addresses','account/address-list',11,17,2),(26,'Shelves','reports/shelves',1,29,1),(27,'Items list','reports/items-form',1,29,1),(28,'Visits','admin/visits',1,7,2),(29,'Reports',NULL,1,NULL,2),(30,'Items','admin/items',1,7,3);
+/*!40000 ALTER TABLE `menu` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `message`
+--
+
+LOCK TABLES `message` WRITE;
+/*!40000 ALTER TABLE `message` DISABLE KEYS */;
+INSERT INTO `message` VALUES (1,'ORDER_DATE_HOLIDAY','No es posible realizar pedidos para días festivos'),(2,'ORDER_EMPTY','El pedido esta vacío'),(3,'ORDER_UNAVAILABLE','Algunos artículos ya no están disponibles, verifica las cantidades resaltadas en rojo'),(4,'SURVEY_MAX_ONE_VOTE','Solo es posible realizar un voto por encuesta'),(5,'ORDER_MAX_EXCEEDED','Has excedido el número máximo de pedidos por confirmar, por favor elimina o confirma los pedidos iniciados'),(6,'LOGIN_INCORRECT','Usuario o contraseña incorrectos. Recuerda que se hace distinción entre mayúsculas y minúsculas.'),(7,'ORDER_DATE_PAST','La fecha de su pedido debe ser mayor o igual al día de hoy'),(8,'ORDER_DATE_LAST','No es posible realizar más para hoy, por favor atrasa la fecha de tu pedido a mañana o días posteriores'),(9,'ORDER_DATE_SUNDAY','No es posible confirmar pedidos para Domingo'),(10,'ORDER_DATE_SATURATED','Estamos saturados de pedidos, por favor selecciona otra fecha de envío o recogida '),(11,'USER_DISCONNECTED','Has sido desconectado del servidor, por favor vuelve a iniciar sesión'),(12,'UNAUTH_ACTION','Acción no permitida'),(13,'ORDER_INVALID_AGENCY','La agencia de envío no es válida'),(14,'ORDER_EMPTY_ADDRESS','Selecciona una dirección de envío'),(15,'ORDER_AMOUNT_ROUNDED','Este artículo se vende agrupado y la cantidad ha sido redondeada'),(16,'ORDER_ALREADY_CONFIRMED','Este pedido ya estaba confirmado');
+/*!40000 ALTER TABLE `message` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `metatag`
+--
+
+LOCK TABLES `metatag` WRITE;
+/*!40000 ALTER TABLE `metatag` DISABLE KEYS */;
+INSERT INTO `metatag` VALUES (2,'title','Verdnatura Levante SL, mayorista de flores, plantas y complementos para floristería y decoración'),(3,'description','Verdnatura Levante SL, mayorista de flores, plantas y complementos para floristería y decoración. Envío a toda España, pedidos por internet o por teléfono.'),(4,'keywords','verdnatura, mayorista, floristería, flores, verdes, plantas, ramos, complementos, artificial, natural, decoración, rosas, helecho, fern, clavel, lilium, orquídea, tulipan, crisantemo, cala, gerbera, hiedra, eucaliptus, cinerea, aralia'),(6,'revisit-after','15 days'),(7,'rating','general'),(8,'author','Juan Ferrer Toribio'),(9,'owner','Verdnatura Levante S.L.'),(10,'robots','index, follow');
+/*!40000 ALTER TABLE `metatag` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `newsTag`
+--
+
+LOCK TABLES `newsTag` WRITE;
+/*!40000 ALTER TABLE `newsTag` DISABLE KEYS */;
+INSERT INTO `newsTag` VALUES ('course','Curso'),('new','Noticia'),('offer','Oferta');
+/*!40000 ALTER TABLE `newsTag` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `restPriv`
+--
+
+LOCK TABLES `restPriv` WRITE;
+/*!40000 ALTER TABLE `restPriv` DISABLE KEYS */;
+INSERT INTO `restPriv` VALUES (1,'tpv/transaction',2),(2,'dms/add',1),(3,'image/upload',1),(4,'misc/sms',1),(5,'core/supplant',1),(6,'core/sync-user',5),(7,'core/set-password',1),(8,'core/change-password',11),(9,'misc/access-version',9);
+/*!40000 ALTER TABLE `restPriv` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Dumping data for table `social`
+--
+
+LOCK TABLES `social` WRITE;
+/*!40000 ALTER TABLE `social` DISABLE KEYS */;
+INSERT INTO `social` VALUES (1,'Blog','https://blog.verdnatura.es/','blog.svg',0),(3,'Facebook','http://www.facebook.com/verdnatura','facebook.svg',2),(4,'YouTube','http://www.youtube.com/user/verdnatura','youtube.svg',2),(5,'Twitter','https://twitter.com/Verdnatura','twitter.svg',1),(6,'Instagram','https://www.instagram.com/verdnatura','instagram.svg',2),(7,'Linkedin','https://www.linkedin.com/company/verdnatura','linkedin.svg',1),(8,'Pinterest','https://es.pinterest.com/verdnatura/','pinterest.svg',1);
+/*!40000 ALTER TABLE `social` ENABLE KEYS */;
+UNLOCK TABLES;
+
--
-- Dumping data for table `tpvError`
--
@@ -535,16 +665,6 @@ LOCK TABLES `tpvResponse` WRITE;
INSERT INTO `tpvResponse` VALUES (101,'Tarjeta Caducada'),(102,'Tarjeta en excepción transitoria o bajo sospecha de fraude'),(104,'Operación no permitida para esa tarjeta o terminal'),(106,'Intentos de PIN excedidos'),(116,'Disponible Insuficiente'),(118,'Tarjeta no Registrada'),(125,'Tarjeta no efectiva'),(129,'Código de seguridad (CVV2/CVC2) incorrecto'),(180,'Tarjeta ajena al servicio'),(184,'Error en la autenticación del titular'),(190,'Denegación sin especificar motivo'),(191,'Fecha de caducidad errónea'),(202,'Tarjeta en excepción transitoria o bajo sospecha de fraude con retirada de tarjeta'),(904,'Comercio no registrado en FUC'),(909,'Error de sistema'),(912,'Emisor no Disponible'),(913,'Pedido repetido'),(944,'Sesión Incorrecta'),(950,'Operación de devolución no permitida'),(9064,'Número de posiciones de la tarjeta incorrecto'),(9078,'No existe método de pago válido para esa tarjeta'),(9093,'Tarjeta no existente'),(9094,'Rechazo servidores internacionales'),(9104,'A petición del usuario se ha cancelado el pago'),(9218,'El comercio no permite op. seguras por entrada /operaciones'),(9253,'Tarjeta no cumple el check-digit'),(9256,'El comercio no puede realizar preautorizaciones'),(9257,'Esta tarjeta no permite operativa de preautorizaciones'),(9261,'Operación detenida por superar el control de restricciones en la entrada al SIS'),(9912,'Emisor no Disponible'),(9913,'Error en la confirmación que el comercio envía al TPV Virtual (solo aplicable en la opción de sincronización SOAP)'),(9914,'Confirmación “KO” del comercio (solo aplicable en la opción de sincronización SOAP)'),(9915,'A petición del usuario se ha cancelado el pago'),(9928,'Anulación de autorización en diferido realizada por el SIS (proceso batch)'),(9929,'Anulación de autorización en diferido realizada por el comercio'),(9998,'Operación en proceso de solicitud de datos de tarjeta'),(9999,'Operación que ha sido redirigida al emisora autenticar');
/*!40000 ALTER TABLE `tpvResponse` ENABLE KEYS */;
UNLOCK TABLES;
-
---
--- Dumping data for table `imageCollectionSize`
---
-
-LOCK TABLES `imageCollectionSize` WRITE;
-/*!40000 ALTER TABLE `imageCollectionSize` DISABLE KEYS */;
-INSERT INTO `imageCollectionSize` VALUES (2,1,50,50,1),(3,1,200,200,1),(5,5,200,200,1),(6,1,70,70,1),(8,5,50,50,1),(9,1,1600,900,0),(13,6,160,160,1),(14,6,520,520,1),(15,6,1600,1600,1);
-/*!40000 ALTER TABLE `imageCollectionSize` ENABLE KEYS */;
-UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
@@ -554,7 +674,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:14
+-- Dump completed on 2022-05-04 15:58:28
USE `postgresql`;
-- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64)
--
@@ -640,7 +760,7 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:14
+-- Dump completed on 2022-05-04 15:58:28
USE `sage`;
-- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64)
--
@@ -696,4 +816,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:14
+-- Dump completed on 2022-05-04 15:58:29
diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql
index 0849e6708..c329e4c6e 100644
--- a/db/dump/fixtures.sql
+++ b/db/dump/fixtures.sql
@@ -54,28 +54,7 @@ INSERT INTO `vn`.`educationLevel` (`id`, `name`)
INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `userFk`, `bossFk`)
SELECT id,UPPER(LPAD(role, 3, '0')), name, name, id, 9
- FROM `vn`.`user`;
-
-ALTER TABLE `vn`.`worker` ADD `originCountryFk` mediumint(8) unsigned NULL COMMENT 'País de origen';
-ALTER TABLE `vn`.`worker` ADD `educationLevelFk` SMALLINT NULL;
-ALTER TABLE `vn`.`worker` ADD `SSN` varchar(15) NULL;
-ALTER TABLE `vn`.`worker` CHANGE `maritalStatus__` `maritalStatus` enum('S','M') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
-ALTER TABLE `vn`.`worker` MODIFY COLUMN `maritalStatus` enum('S','M') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
-ALTER TABLE `vn`.`worker` CHANGE `maritalStatus` maritalStatus enum('S','M') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER sectorFk;
-ALTER TABLE `vn`.`worker` ADD CONSTRAINT `worker_FK_2` FOREIGN KEY (`educationLevelFk`) REFERENCES `vn`.`educationLevel`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-ALTER TABLE `vn`.`worker` ADD CONSTRAINT `worker_FK_1` FOREIGN KEY (`originCountryFk`) REFERENCES `vn`.`country`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-
-UPDATE `vn`.`worker` `w`
- SET `maritalStatus` = 'S';
-
-UPDATE `vn`.`worker` `w`
- SET `originCountryFk` = '1';
-
-UPDATE `vn`.`worker` `w`
- SET `educationLevelFk` = '2';
-
-UPDATE `vn`.`worker` `w`
- SET `SSN` = '123456789123';
+ FROM `vn`.`user`;
UPDATE `vn`.`worker` SET bossFk = NULL WHERE id = 20;
UPDATE `vn`.`worker` SET bossFk = 20 WHERE id = 1 OR id = 9;
@@ -147,15 +126,6 @@ INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`,
(19,'Francia', 1, 'FR', 1, 27, 4, 0, 1),
(30,'Canarias', 1, 'IC', 1, 24, 4, 1, 2);
-INSERT INTO `hedera`.`language` (`code`, `name`, `orgName`, `isActive`)
- VALUES
- ('ca', 'Català' , 'Catalan' , TRUE),
- ('en', 'English' , 'English' , TRUE),
- ('es', 'Español' , 'Spanish' , TRUE),
- ('fr', 'Français' , 'French' , TRUE),
- ('mn', 'Португалий', 'Mongolian' , TRUE),
- ('pt', 'Português' , 'Portuguese', TRUE);
-
INSERT INTO `vn`.`warehouseAlias`(`id`, `name`)
VALUES
(1, 'Main Warehouse'),
@@ -182,8 +152,9 @@ INSERT INTO `vn`.`parking` (`id`, `column`, `row`, `sectorFk`, `code`, `pickingO
INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `parked`, `userFk`)
VALUES
- ('GVC', '1', '0', '1', '0', '1106'),
- ('HEJ', '2', '0', '1', '0', '1106');
+ ('GVC', 1, 0, 1, 0, 1106),
+ ('HEJ', 2, 0, 1, 0, 1106),
+ ('UXN', 1, 0, 1, 0, 1106);
INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`, `maxAmount`)
VALUES
@@ -342,9 +313,9 @@ INSERT INTO `vn`.`clientManaCache`(`clientFk`, `mana`, `dated`)
(1103, 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
(1104, -30, DATE_ADD(CURDATE(), INTERVAL -1 MONTH));
-INSERT INTO `vn`.`clientConfig`(`riskTolerance`)
+INSERT INTO `vn`.`clientConfig`(`riskTolerance`, `maxCreditRows`)
VALUES
- (200);
+ (200, 10);
INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`, `isDefaultAddress`)
VALUES
@@ -422,17 +393,17 @@ DROP TEMPORARY TABLE tmp.address;
INSERT INTO `vn`.`clientCredit`(`id`, `clientFk`, `workerFk`, `amount`, `created`)
VALUES
- (1 , 1101, 5, 300, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
- (2 , 1101, 5, 900, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)),
- (3 , 1101, 5, 800, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)),
- (4 , 1101, 5, 700, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)),
- (5 , 1101, 5, 600, DATE_ADD(CURDATE(), INTERVAL -5 MONTH)),
+ (1 , 1101, 5, 300, DATE_ADD(CURDATE(), INTERVAL -11 MONTH)),
+ (2 , 1101, 5, 900, DATE_ADD(CURDATE(), INTERVAL -10 MONTH)),
+ (3 , 1101, 5, 800, DATE_ADD(CURDATE(), INTERVAL -9 MONTH)),
+ (4 , 1101, 5, 700, DATE_ADD(CURDATE(), INTERVAL -8 MONTH)),
+ (5 , 1101, 5, 600, DATE_ADD(CURDATE(), INTERVAL -7 MONTH)),
(6 , 1101, 5, 500, DATE_ADD(CURDATE(), INTERVAL -6 MONTH)),
- (7 , 1101, 5, 400, DATE_ADD(CURDATE(), INTERVAL -7 MONTH)),
- (8 , 1101, 9, 300, DATE_ADD(CURDATE(), INTERVAL -8 MONTH)),
- (9 , 1101, 9, 200, DATE_ADD(CURDATE(), INTERVAL -9 MONTH)),
- (10, 1101, 9, 100, DATE_ADD(CURDATE(), INTERVAL -10 MONTH)),
- (11, 1101, 9, 50 , DATE_ADD(CURDATE(), INTERVAL -11 MONTH)),
+ (7 , 1101, 5, 400, DATE_ADD(CURDATE(), INTERVAL -5 MONTH)),
+ (8 , 1101, 9, 300, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)),
+ (9 , 1101, 9, 200, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)),
+ (10, 1101, 9, 100, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)),
+ (11, 1101, 9, 50 , DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
(12, 1102, 9, 800, CURDATE()),
(14, 1104, 9, 90 , CURDATE()),
(15, 1105, 9, 90 , CURDATE());
@@ -883,18 +854,35 @@ INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPack
('cc', 1640038.00, 56.00, 220.00, 128.00, 1, CURDATE(), 15, 90.00),
('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, CURDATE(), 16, 0.00);
-INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `checked`, `workerFk`, `externalId`, `packagingFk`)
+INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`)
VALUES
- (1, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 15, 1, 1, 18, 'UR9000006041', 94),
- (2, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 16, 2, 1, 18, 'UR9000006041', 94),
- (3, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 3, 1, 18, 'UR9000006041', 94),
- (4, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 4, 1, 18, 'UR9000006041', 94),
- (5, 1, 2, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94),
- (6, 7, 3, 71, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL, 1, 1, 18, NULL, 94),
- (7, 2, 4, 71, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL, 1, 1, 18, NULL, 94),
- (8, 3, 5, 71, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), NULL, 1, 1, 18, NULL, 94),
- (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94),
- (10, 7, 7, 71, NOW(), NULL, 1, 1, 18, NULL, 94);
+ (1, 'En reparto', 'ON DELIVERY'),
+ (2, 'Entregada', 'DELIVERED'),
+ (3, 'Perdida', 'LOST');
+
+
+INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `checked`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`)
+ VALUES
+ (1, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 15, 1, 1, 18, 'UR9000006041', 94, 1),
+ (2, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 16, 2, 1, 18, 'UR9000006041', 94, 1),
+ (3, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 3, 1, 18, 'UR9000006041', 94, 2),
+ (4, 1, 1, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 4, 1, 18, 'UR9000006041', 94, 2),
+ (5, 1, 2, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94, 3),
+ (6, 7, 3, 71, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), NULL, 1, 1, 18, NULL, 94, 3),
+ (7, 2, 4, 71, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), NULL, 1, 1, 18, NULL, 94, NULL),
+ (8, 3, 5, 71, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), NULL, 1, 1, 18, NULL, 94, 1),
+ (9, 3, 6, 71, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), NULL, 1, 1, 18, NULL, 94, 2),
+ (10, 7, 7, 71, NOW(), NULL, 1, 1, 18, NULL, 94, 3);
+
+
+INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`)
+ VALUES
+ (1, CURDATE(), 1, 1, 1),
+ (2, CURDATE(), 2, 1, 1),
+ (3, CURDATE(), 3, 1, 1),
+ (4, CURDATE(), 3, 2, 1106),
+ (5, CURDATE(), 5, 1, 1106),
+ (6, CURDATE(), 5, 3, 1106);
INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`)
VALUES
@@ -1078,10 +1066,11 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`)
(32, 36, -92.324),
(32, 39, 0.994);
-INSERT INTO `vn`.`itemShelving` (`id`, `itemFk`, `shelvingFk`, `shelve`, `deep`, `quantity`, `visible`, `available`, `grouping`, `packing`, `level`, `userFk`)
+INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `shelve`, `visible`, `grouping`, `packing`, `userFk`)
VALUES
- ('1', '2', 'GVC', 'A', '0', '1', '1', '1', '1', '1', '1', '1106'),
- ('2', '4', 'HEJ', 'A', '0', '2', '1', '1', '1', '1', '1', '1106');
+ (2, 'GVC', 'A', 1, 1, 1, 1106),
+ (4, 'HEJ', 'A', 1, 1, 1, 1106),
+ (1, 'UXN', 'A', 2, 12, 12, 1106);
INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`)
VALUES
@@ -1135,14 +1124,6 @@ INSERT INTO `vn`.`parking` (`column`, `row`, `sectorFk`, `code`, `pickingOrder`)
VALUES
('100', '01', 1, '100-01', 1);
-INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `priority`, `userFk`)
- VALUES
- ('UXN', 1, 1, 1106);
-
-INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `shelve`, `deep`, `quantity`, `visible`, `available`, `grouping`, `packing`, `level`, `userFk`)
- VALUES
- (1, 'UXN', 'A', 2, 12, 12, 12, 12, 12, 1, 1106);
-
INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `level`)
VALUES
(1, 1, 1);
@@ -1332,11 +1313,11 @@ INSERT INTO `vn`.`supplierAddress`(`id`, `supplierFk`, `nickname`, `street`, `pr
(5, 442, 'GCR building', 'Bristol district', 1, '46000', 'Gotham', '111111111', '222222222'),
(6, 442, 'The Gotham Tonight building', 'Bristol district', 1, '46000', 'Gotham', '111111111', '222222222');
-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`)
+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, CURDATE(), 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1),
- (2, 'Farmer King', 'The farmer', 4000020002, 1, '87945234L', 0, CURDATE(), 1, 'supplier address 2', 'SILLA', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1),
- (442, 'Verdnatura Levante SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, CURDATE(), 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'flowerPlants', 1);
+ (1, 'Plants SL', 'Plants nick', 4100000001, 1, '06089160W', 0, 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, CURDATE(), 1, 'supplier address 2', 'SILLA', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'),
+ (442, 'Verdnatura Levante SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, CURDATE(), 1, 'supplier address 3', 'SILLA', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V');
INSERT INTO `vn`.`supplierContact`(`id`, `supplierFk`, `phone`, `mobile`, `email`, `observation`, `name`)
VALUES
@@ -2266,13 +2247,19 @@ INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `c
INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`)
VALUES
- (1, 14, '1.txt', 'text/plain', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()),
- (2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', CURDATE()),
- (3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', CURDATE()),
- (4, 3, '4.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', CURDATE()),
- (5, 5, '5.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'travel: 1', 'dmsForThermograph', CURDATE()),
- (6, 5, '6.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'NotExists', 'DoesNotExists', CURDATE());
+ (1, 14, '1.txt', 'text/plain', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', CURDATE()),
+ (2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', CURDATE()),
+ (3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', CURDATE()),
+ (4, 3, '4.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', CURDATE()),
+ (5, 5, '5.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'travel: 1', 'dmsForThermograph', CURDATE()),
+ (6, 5, '6.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'NotExists', 'DoesNotExists', CURDATE()),
+ (7, 20, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', CURDATE()),
+ (8, 20, '8.mp4', 'video/mp4', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', CURDATE());
+INSERT INTO `vn`.`claimDms`(`claimFk`, `dmsFk`)
+ VALUES
+ (1, 7),
+ (1, 8);
INSERT INTO `vn`.`ticketDms`(`ticketFk`, `dmsFk`)
VALUES
@@ -2532,7 +2519,7 @@ INSERT INTO `bs`.`sale` (`saleFk`, `amount`, `dated`, `typeFk`, `clientFk`)
INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `dialogName` , `find`)
VALUES
- ('deliveryClientTest', 'deliveryClientTest', 'findTest', 'word');
+ ('deliveryClient', 'deliveryClient', 'findTicket', 'word');
INSERT INTO `vn`.`docuwareConfig` (`url`)
VALUES
diff --git a/db/dump/structure.sql b/db/dump/structure.sql
index f317dd7f7..fdd7e1151 100644
--- a/db/dump/structure.sql
+++ b/db/dump/structure.sql
@@ -920,52 +920,52 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `passwordGenerate`() RETURNS text CHARSET utf8 COLLATE utf8_unicode_ci
READS SQL DATA
-BEGIN
-/**
- * Generates a random password that meets the minimum requirements.
- *
- * @return Generated password
- */
- DECLARE vMinLength TINYINT;
- DECLARE vMinAlpha TINYINT;
- DECLARE vMinUpper TINYINT;
- DECLARE vMinDigits TINYINT;
- DECLARE vMinPunct TINYINT;
- DECLARE vAlpha TINYINT DEFAULT 0;
- DECLARE vUpper TINYINT DEFAULT 0;
- DECLARE vDigits TINYINT DEFAULT 0;
- DECLARE vPunct TINYINT DEFAULT 0;
- DECLARE vRandIndex INT;
- DECLARE vPwd TEXT DEFAULT '';
-
- DECLARE vAlphaChars TEXT DEFAULT 'abcdefghijklmnopqrstuvwxyz';
- DECLARE vUpperChars TEXT DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- DECLARE vDigitChars TEXT DEFAULT '1234567890';
- DECLARE vPunctChars TEXT DEFAULT '!$%&()=.';
-
- SELECT length, nAlpha, nUpper, nDigits, nPunct
- INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword;
-
- WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha
- OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO
- SET vRandIndex = FLOOR((RAND() * 4) + 1);
-
- CASE
- WHEN vRandIndex = 1 THEN
- SET vPwd = CONCAT(vPwd, SUBSTRING(vAlphaChars, FLOOR((RAND() * 26) + 1), 1));
- SET vAlpha = vAlpha + 1;
- WHEN vRandIndex = 2 THEN
- SET vPwd = CONCAT(vPwd, SUBSTRING(vUpperChars, FLOOR((RAND() * 26) + 1), 1));
- SET vUpper = vUpper + 1;
- WHEN vRandIndex = 3 THEN
- SET vPwd = CONCAT(vPwd, SUBSTRING(vDigitChars, FLOOR((RAND() * 10) + 1), 1));
- SET vDigits = vDigits + 1;
- WHEN vRandIndex = 4 THEN
- SET vPwd = CONCAT(vPwd, SUBSTRING(vPunctChars, FLOOR((RAND() * LENGTH(vPunctChars)) + 1), 1));
- SET vPunct = vPunct + 1;
- END CASE;
- END WHILE;
- RETURN vPwd;
+BEGIN
+/**
+ * Generates a random password that meets the minimum requirements.
+ *
+ * @return Generated password
+ */
+ DECLARE vMinLength TINYINT;
+ DECLARE vMinAlpha TINYINT;
+ DECLARE vMinUpper TINYINT;
+ DECLARE vMinDigits TINYINT;
+ DECLARE vMinPunct TINYINT;
+ DECLARE vAlpha TINYINT DEFAULT 0;
+ DECLARE vUpper TINYINT DEFAULT 0;
+ DECLARE vDigits TINYINT DEFAULT 0;
+ DECLARE vPunct TINYINT DEFAULT 0;
+ DECLARE vRandIndex INT;
+ DECLARE vPwd TEXT DEFAULT '';
+
+ DECLARE vAlphaChars TEXT DEFAULT 'abcdefghijklmnopqrstuvwxyz';
+ DECLARE vUpperChars TEXT DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ DECLARE vDigitChars TEXT DEFAULT '1234567890';
+ DECLARE vPunctChars TEXT DEFAULT '!$%&()=.';
+
+ SELECT length, nAlpha, nUpper, nDigits, nPunct
+ INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword;
+
+ WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha
+ OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO
+ SET vRandIndex = FLOOR((RAND() * 4) + 1);
+
+ CASE
+ WHEN vRandIndex = 1 THEN
+ SET vPwd = CONCAT(vPwd, SUBSTRING(vAlphaChars, FLOOR((RAND() * 26) + 1), 1));
+ SET vAlpha = vAlpha + 1;
+ WHEN vRandIndex = 2 THEN
+ SET vPwd = CONCAT(vPwd, SUBSTRING(vUpperChars, FLOOR((RAND() * 26) + 1), 1));
+ SET vUpper = vUpper + 1;
+ WHEN vRandIndex = 3 THEN
+ SET vPwd = CONCAT(vPwd, SUBSTRING(vDigitChars, FLOOR((RAND() * 10) + 1), 1));
+ SET vDigits = vDigits + 1;
+ WHEN vRandIndex = 4 THEN
+ SET vPwd = CONCAT(vPwd, SUBSTRING(vPunctChars, FLOOR((RAND() * LENGTH(vPunctChars)) + 1), 1));
+ SET vPunct = vPunct + 1;
+ END CASE;
+ END WHILE;
+ RETURN vPwd;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -1104,23 +1104,23 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `user_getMysqlRole`(vUserName VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
-/**
- * From a username, it returns the associated MySQL wich should be used when
- * using external authentication systems.
- *
- * @param vUserName The user name
- * @return The associated MySQL role
- */
- DECLARE vRole VARCHAR(255);
-
- SELECT CONCAT(IF(r.hasLogin, c.rolePrefix, ''), r.name) INTO vRole
- FROM role r
- JOIN user u ON u.role = r.id
- JOIN roleConfig c
- WHERE u.name = vUserName;
-
- RETURN vRole;
+BEGIN
+/**
+ * From a username, it returns the associated MySQL wich should be used when
+ * using external authentication systems.
+ *
+ * @param vUserName The user name
+ * @return The associated MySQL role
+ */
+ DECLARE vRole VARCHAR(255);
+
+ SELECT CONCAT(IF(r.hasLogin, c.rolePrefix, ''), r.name) INTO vRole
+ FROM role r
+ JOIN user u ON u.role = r.id
+ JOIN roleConfig c
+ WHERE u.name = vUserName;
+
+ RETURN vRole;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -1139,20 +1139,20 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `user_getNameFromId`(vSelf INT) RETURNS varchar(30) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
-/**
- * Gets user name from it's id.
- *
- * @param vSelf The user id
- * @return The user name
- */
- DECLARE vName VARCHAR(30);
-
- SELECT `name` INTO vName
- FROM user
- WHERE id = vSelf;
-
- RETURN vName;
+BEGIN
+/**
+ * Gets user name from it's id.
+ *
+ * @param vSelf The user id
+ * @return The user name
+ */
+ DECLARE vName VARCHAR(30);
+
+ SELECT `name` INTO vName
+ FROM user
+ WHERE id = vSelf;
+
+ RETURN vName;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -2674,22 +2674,6 @@ CREATE TABLE `compradores_evolution` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
---
--- Table structure for table `conveyorStats`
---
-
-DROP TABLE IF EXISTS `conveyorStats`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `conveyorStats` (
- `created` datetime NOT NULL,
- `saturacion` int(11) DEFAULT NULL,
- `velocidad` int(11) DEFAULT NULL,
- `rutas` int(11) DEFAULT NULL,
- PRIMARY KEY (`created`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
--
-- Table structure for table `customerEvolution`
--
@@ -3062,21 +3046,6 @@ CREATE TABLE `nightTaskConfig` (
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
---
--- Table structure for table `novemberSales`
---
-
-DROP TABLE IF EXISTS `novemberSales`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `novemberSales` (
- `ticketFk` int(11) NOT NULL,
- `saleFk` int(11) NOT NULL DEFAULT '0',
- `año` int(4) DEFAULT NULL,
- `importe` decimal(28,8) DEFAULT NULL
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
--
-- Temporary table structure for view `packingSpeed`
--
@@ -3190,32 +3159,6 @@ SET character_set_client = utf8;
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
---
--- Table structure for table `salaries2018`
---
-
-DROP TABLE IF EXISTS `salaries2018`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `salaries2018` (
- `person_id` int(11) NOT NULL DEFAULT '0',
- `sex` enum('M','F') CHARACTER SET utf8 NOT NULL DEFAULT 'F' COMMENT 'M Masculino F Femenino',
- `edad` int(6) DEFAULT NULL,
- `antiguedad` int(6) DEFAULT NULL,
- `Modalidad` varchar(22) CHARACTER SET utf8mb4 NOT NULL DEFAULT '',
- `reason` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- `worker` varchar(82) CHARACTER SET utf8 DEFAULT NULL,
- `totalDays` decimal(32,0) DEFAULT NULL,
- `totalAnual` decimal(16,0) DEFAULT NULL,
- `virtualMonthlySalary` decimal(16,0) DEFAULT NULL,
- `departamento` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `category_name` varchar(50) CHARACTER SET utf8 NOT NULL,
- `level_name` varchar(5) CHARACTER SET utf8 DEFAULT NULL,
- `thisYearDateStart` varchar(10) CHARACTER SET utf8mb4 DEFAULT NULL,
- PRIMARY KEY (`person_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
--
-- Table structure for table `sale`
--
@@ -4149,52 +4092,20 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `carteras_add`()
BEGIN
-
-DELETE FROM bs.carteras
-WHERE Año >= YEAR(CURDATE()) - 1;
-
-INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso)
-SELECT year as Año, month as Mes, CodigoTrabajador, sum(importe) as Peso
-FROM vn2008.time t
-JOIN bs.ventas v on t.date = v.fecha
-JOIN vn2008.Clientes c on c.Id_Cliente = v.Id_Cliente
-JOIN vn2008.Trabajadores tr on tr.Id_Trabajador = c.Id_Trabajador
-WHERE t.year >= YEAR(CURDATE()) - 1
-GROUP BY CodigoTrabajador, Año, Mes;
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `carteras_add2` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `carteras_add2`()
-BEGIN
-/**
- * Inserta en "bs.carteras".
- */
- DELETE FROM bs.carteras
- WHERE Año >= YEAR(CURDATE()) - 1;
-
- INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso)
- SELECT t.year AS Año, t.month AS Mes, w.code AS CodigoTrabajador, SUM(v.importe) AS Peso
- FROM vn.time t
- JOIN bs.ventas v on t.dated = v.fecha
- JOIN vn.client c on c.id = v.Id_Cliente
- JOIN vn.worker w ON w.id = c.salesPersonFk
- WHERE t.year >= YEAR(CURDATE()) - 1
- GROUP BY w.code, t.year , t.month;
+/**
+ * Inserta en @bs.carteras.
+ */
+ DELETE FROM bs.carteras
+ WHERE Año >= YEAR(CURDATE()) - 1;
+
+ INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso)
+ SELECT t.year AS Año, t.month AS Mes, w.code AS CodigoTrabajador, SUM(v.importe) AS Peso
+ FROM vn.time t
+ JOIN bs.ventas v on t.dated = v.fecha
+ JOIN vn.client c on c.id = v.Id_Cliente
+ JOIN vn.worker w ON w.id = c.salesPersonFk
+ WHERE t.year >= YEAR(CURDATE()) - 1
+ GROUP BY w.code, t.year , t.month;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -4215,9 +4126,11 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`()
BEGIN
DECLARE vFourYearsAgo DATETIME;
DECLARE vOneYearAgo DATETIME;
+ DECLARE vTwoYearAgo DATETIME;
- SET vFourYearsAgo = TIMESTAMPADD(YEAR, -4,CURDATE());
SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,CURDATE());
+ SET vTwoYearAgo = TIMESTAMPADD(YEAR, -2,CURDATE());
+ SET vFourYearsAgo = TIMESTAMPADD(YEAR, -4,CURDATE());
DELETE FROM bs.clientNewBorn
WHERE lastShipped < vOneYearAgo;
@@ -4230,6 +4143,12 @@ BEGIN
DELETE FROM payMethodClientEvolution
WHERE dated < vFourYearsAgo;
+
+ DELETE FROM bs.salesByclientSalesPerson
+ WHERE dated < vFourYearsAgo;
+
+ DELETE FROM bs.m3
+ WHERE fecha < vTwoYearAgo;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -4642,51 +4561,14 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `compradores_add`(IN intYEAR INT, IN intWEEK_START INT, IN intWEEK_END INT)
-BEGIN
-
-REPLACE bs.compradores
-
-SELECT tp.Id_Trabajador
- , intYEAR as año
- , tm.week as semana
- , sum(importe) as importe
- , 0 as comision
-
-FROM bs.ventas v
-JOIN vn2008.time tm on tm.date = v.fecha
-JOIN vn2008.Tipos tp using(tipo_id)
-WHERE tm.year = intYEAR and tm.week between intWEEK_START and intWEEK_END
-AND reino_id != 6
-GROUP BY tp.Id_Trabajador, tm.week;
-
-
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `compradores_add2` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `compradores_add2`(IN vYear INT, IN vWeekFrom INT, IN vWeekTo INT)
+CREATE DEFINER=`root`@`localhost` PROCEDURE `compradores_add`(IN vYear INT, IN vWeekFrom INT, IN vWeekTo INT)
BEGIN
/**
* Sustituye los registros de "bs.compradores".
*
* @param vYear: año ventas
* @param vWeekFrom: semana desde
- * @param vWeekTo: semana hastas
+ * @param vWeekTo: semana hasta
*/
REPLACE bs.compradores
SELECT it.workerFk AS Id_Trabajador, vYear AS año, tm.week AS semana, SUM(importe) AS importe, 0 AS comision
@@ -4858,91 +4740,6 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `fondo_evolution_add`()
BEGIN
-/*
-
-Inserta en la tabla fondo_maniobra los saldos acumulados en los ultimos 365 dias
-
-*/
-
-DECLARE datFEC DATE DEFAULT '2015-01-01';
-
-
-SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) INTO datFEC FROM bs.fondo_maniobra;
-
- WHILE datFEC < CURDATE() DO
-
- -- esto solo sirve para no aburrirse mientras esperamos...
-
- IF day(datFEC) mod 28 = 0 then
- SELECT datFEC;
- end if;
-
-
- REPLACE bs.fondo_maniobra(Fecha, clientes_facturas, clientes_cobros,proveedores_facturas,proveedores_pagos, fondo)
- SELECT datFEC as Fecha, Facturas, Cobros,Recibidas,Pagos, Facturas + Cobros + Recibidas + Pagos
- FROM
- (
- SELECT Sum(Facturas.Importe) AS Facturas
- FROM vn2008.Facturas
- INNER JOIN vn2008.Clientes ON Facturas.Id_Cliente = Clientes.Id_cliente
- WHERE Clientes.`real`
- AND empresa_id <>1381
- AND Fecha between '2011-01-01' and datFEC) fac
- JOIN
- (
- SELECT - Sum(Entregado) AS Cobros
- FROM vn2008.Recibos
- INNER JOIN vn2008.Clientes ON Recibos.Id_Cliente = Clientes.Id_cliente
- WHERE Clientes.`real`
- AND empresa_id <> 1381
- AND Fechacobro Between '2011-01-01' and datFEC) cob
- JOIN
- (
- SELECT - Sum(cantidad) AS Recibidas
- FROM vn2008.recibida
- INNER JOIN vn2008.recibida_vencimiento ON recibida.id = recibida_vencimiento.recibida_id
- WHERE empresa_id <> 1381
- AND recibida.fecha Between '2015-01-01' and datFEC) rec
- JOIN
- (
- SELECT Sum(importe) AS Pagos
- FROM vn2008.pago
- WHERE empresa_id <>1381 AND pago.fecha Between '2015-01-01' and datFEC) pag;
-
-
-
- UPDATE bs.fondo_maniobra
- JOIN
- (SELECT avg(fondo) as media
- FROM bs.fondo_maniobra
- WHERE fecha <= datFEC) sub
- SET fondo_medio = media
- WHERE fecha = datFEC;
-
-
- SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
-
- END WHILE;
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `fondo_evolution_add2` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `fondo_evolution_add2`()
-BEGIN
/**
* Inserta en la tabla fondo_maniobra los saldos acumulados en los ultimos 365 dias
*/
@@ -5371,25 +5168,41 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `manaCustomerUpdate`()
BEGIN
-DECLARE vToDated DATE;
+ DECLARE vToDated DATE;
DECLARE vFromDated DATE;
DECLARE vForDeleteDated DATE;
- DECLARE vManaId INT DEFAULT 37;
- DECLARE vManaAutoId INT DEFAULT 39;
- DECLARE vManaBankId INT DEFAULT 66;
- DECLARE vManaGreugeTypeId INT DEFAULT 3;
+ DECLARE vManaId INT;
+ DECLARE vManaAutoId INT;
+ DECLARE vClaimManaId INT;
+ DECLARE vManaBankId INT;
+ DECLARE vManaGreugeTypeId INT;
- SELECT IFNULL(max(dated), '2016-01-01')
- INTO vFromDated
- FROM bs.manaCustomer;
+ SELECT id INTO vManaId
+ FROM vn.component WHERE code = 'mana';
+
+ SELECT id INTO vManaAutoId
+ FROM vn.component WHERE code = 'autoMana';
- DELETE
- FROM bs.manaCustomer
+ SELECT id INTO vClaimManaId
+ FROM vn.component WHERE code = 'manaClaim';
+
+ SELECT id INTO vManaBankId
+ FROM vn.bank WHERE code = 'mana';
+
+ SELECT id INTO vManaGreugeTypeId
+ FROM vn.greugeType WHERE code = 'mana';
+
+ SELECT IFNULL(MAX(dated), '2016-01-01')
+ INTO vFromDated
+ FROM vn.clientManaCache;
+
+ DELETE
+ FROM vn.clientManaCache
WHERE dated = vFromDated;
- SELECT IFNULL(max(dated), '2016-01-01')
+ SELECT IFNULL(MAX(dated), '2016-01-01')
INTO vFromDated
- FROM bs.manaCustomer;
+ FROM vn.clientManaCache;
WHILE timestampadd(DAY,30,vFromDated) < CURDATE() DO
@@ -5400,31 +5213,25 @@ DECLARE vToDated DATE;
vToDated,
vForDeleteDated;
- DELETE FROM bs.manaCustomer
+ DELETE FROM vn.clientManaCache
WHERE dated <= vForDeleteDated;
-
- INSERT INTO bs.manaCustomer(Id_Cliente, Mana, dated)
-
+ INSERT INTO vn.clientManaCache(clientFk, mana, dated)
SELECT
Id_Cliente,
cast(sum(mana) as decimal(10,2)) as mana,
vToDated as dated
FROM
-
(
SELECT cs.Id_Cliente, Cantidad * Valor as mana
FROM vn2008.Tickets t
JOIN vn2008.Consignatarios cs using(Id_Consigna)
JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket
JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento
- WHERE Id_Componente IN (vManaAutoId, vManaId)
+ WHERE Id_Componente IN (vManaAutoId, vManaId, vClaimManaId)
AND t.Fecha > vFromDated
AND date(t.Fecha) <= vToDated
-
-
UNION ALL
-
SELECT r.Id_Cliente, - Entregado
FROM vn2008.Recibos r
WHERE Id_Banco = vManaBankId
@@ -5432,25 +5239,21 @@ DECLARE vToDated DATE;
AND Fechacobro <= vToDated
UNION ALL
-
SELECT g.Id_Cliente, g.Importe
FROM vn2008.Greuges g
WHERE Greuges_type_id = vManaGreugeTypeId
AND Fecha > vFromDated
AND Fecha <= vToDated
-
UNION ALL
-
- SELECT Id_Cliente, mana
- FROM bs.manaCustomer
- WHERE dated = vFromDated
+ SELECT clientFk, mana
+ FROM vn.clientManaCache
+ WHERE dated = vFromDated
) sub
-
GROUP BY Id_Cliente
HAVING Id_Cliente;
SET vFromDated = vToDated;
-
+
END WHILE;
END ;;
@@ -6641,104 +6444,104 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_add`(IN vYear INT, IN vMonth INT)
-BEGIN
-
- /**
- * Reemplaza las ventas contables del último año.
- * Es el origen de datos para el balance de Entradas
- *
- * @param vYear Año a reemplazar
- * @param vMonth Mes a reemplazar
- *
- **/
-
- DECLARE TIPO_PATRIMONIAL INT DEFAULT 188;
-
- DELETE FROM bs.ventas_contables
- WHERE year = vYear
- AND month = vMonth;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
- CREATE TEMPORARY TABLE tmp.ticket_list
- (PRIMARY KEY (Id_Ticket))
- ENGINE = MEMORY
- SELECT Id_Ticket
- FROM vn2008.Tickets t
- JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura
- WHERE year(f.Fecha) = vYear
- AND month(f.Fecha) = vMonth;
-
- INSERT INTO bs.ventas_contables(year
- , month
- , venta
- , grupo
- , reino_id
- , tipo_id
- , empresa_id
- , gasto)
-
- SELECT vYear
- , vMonth
- , round(sum(Cantidad * Preu * (100 - m.Descuento)/100))
- , IF(
- e.empresa_grupo = e2.empresa_grupo
- ,1
- ,IF(e2.empresa_grupo,2,0)
- ) as grupo
- , tp.reino_id
- , a.tipo_id
- , t.empresa_id
- , 7000000000
- + IF(e.empresa_grupo = e2.empresa_grupo
- ,1
- ,IF(e2.empresa_grupo,2,0)
- ) * 1000000
- + tp.reino_id * 10000 as Gasto
- FROM vn2008.Movimientos m
- JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket
- JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
- JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
- JOIN tmp.ticket_list tt on tt.Id_Ticket = t.Id_Ticket
- JOIN vn2008.Articles a on m.Id_Article = a.Id_Article
- JOIN vn2008.empresa e on e.id = t.empresa_id
- LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente
- JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id
- WHERE Cantidad <> 0
- AND Preu <> 0
- AND m.Descuento <> 100
- AND a.tipo_id != TIPO_PATRIMONIAL
- GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto;
-
- INSERT INTO bs.ventas_contables(year
- , month
- , venta
- , grupo
- , reino_id
- , tipo_id
- , empresa_id
- , gasto)
- SELECT vYear
- , vMonth
- , sum(ts.quantity * ts.price)
- , IF(
- c.companyGroupFk = c2.companyGroupFk
- ,1
- ,IF(c2.companyGroupFk, 2, 0)
- ) as grupo
- , NULL
- , NULL
- , t.companyFk
- , 7050000000
- FROM vn.ticketService ts
- JOIN vn.ticket t ON ts.ticketFk = t.id
- JOIN vn.address a on a.id = t.addressFk
- JOIN vn.client cl on cl.id = a.clientFk
- JOIN tmp.ticket_list tt on tt.Id_Ticket = t.id
- JOIN vn.company c on c.id = t.companyFk
- LEFT JOIN vn.company c2 on c2.clientFk = cl.id
- GROUP BY grupo, t.companyFk ;
-
- DROP TEMPORARY TABLE tmp.ticket_list;
+BEGIN
+
+ /**
+ * Reemplaza las ventas contables del último año.
+ * Es el origen de datos para el balance de Entradas
+ *
+ * @param vYear Año a reemplazar
+ * @param vMonth Mes a reemplazar
+ *
+ **/
+
+ DECLARE TIPO_PATRIMONIAL INT DEFAULT 188;
+
+ DELETE FROM bs.ventas_contables
+ WHERE year = vYear
+ AND month = vMonth;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
+ CREATE TEMPORARY TABLE tmp.ticket_list
+ (PRIMARY KEY (Id_Ticket))
+ ENGINE = MEMORY
+ SELECT Id_Ticket
+ FROM vn2008.Tickets t
+ JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura
+ WHERE year(f.Fecha) = vYear
+ AND month(f.Fecha) = vMonth;
+
+ INSERT INTO bs.ventas_contables(year
+ , month
+ , venta
+ , grupo
+ , reino_id
+ , tipo_id
+ , empresa_id
+ , gasto)
+
+ SELECT vYear
+ , vMonth
+ , round(sum(Cantidad * Preu * (100 - m.Descuento)/100))
+ , IF(
+ e.empresa_grupo = e2.empresa_grupo
+ ,1
+ ,IF(e2.empresa_grupo,2,0)
+ ) as grupo
+ , tp.reino_id
+ , a.tipo_id
+ , t.empresa_id
+ , 7000000000
+ + IF(e.empresa_grupo = e2.empresa_grupo
+ ,1
+ ,IF(e2.empresa_grupo,2,0)
+ ) * 1000000
+ + tp.reino_id * 10000 as Gasto
+ FROM vn2008.Movimientos m
+ JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket
+ JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
+ JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
+ JOIN tmp.ticket_list tt on tt.Id_Ticket = t.Id_Ticket
+ JOIN vn2008.Articles a on m.Id_Article = a.Id_Article
+ JOIN vn2008.empresa e on e.id = t.empresa_id
+ LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente
+ JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id
+ WHERE Cantidad <> 0
+ AND Preu <> 0
+ AND m.Descuento <> 100
+ AND a.tipo_id != TIPO_PATRIMONIAL
+ GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto;
+
+ INSERT INTO bs.ventas_contables(year
+ , month
+ , venta
+ , grupo
+ , reino_id
+ , tipo_id
+ , empresa_id
+ , gasto)
+ SELECT vYear
+ , vMonth
+ , sum(ts.quantity * ts.price)
+ , IF(
+ c.companyGroupFk = c2.companyGroupFk
+ ,1
+ ,IF(c2.companyGroupFk, 2, 0)
+ ) as grupo
+ , NULL
+ , NULL
+ , t.companyFk
+ , 7050000000
+ FROM vn.ticketService ts
+ JOIN vn.ticket t ON ts.ticketFk = t.id
+ JOIN vn.address a on a.id = t.addressFk
+ JOIN vn.client cl on cl.id = a.clientFk
+ JOIN tmp.ticket_list tt on tt.Id_Ticket = t.id
+ JOIN vn.company c on c.id = t.companyFk
+ LEFT JOIN vn.company c2 on c2.clientFk = cl.id
+ GROUP BY grupo, t.companyFk ;
+
+ DROP TEMPORARY TABLE tmp.ticket_list;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -7049,33 +6852,33 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `waste_addSales_lastWeek__`()
-BEGIN
- DECLARE vWeek INT;
- DECLARE vYear INT;
-
- SELECT week, year
- INTO vWeek, vYear
- FROM vn.time
- WHERE dated = TIMESTAMPADD(WEEK, -1, CURDATE());
-
- REPLACE bs.waste
- SELECT *, 100 * mermas / total as porcentaje
- FROM (
- SELECT buyer,
- year,
- week,
- family,
- itemFk,
- itemTypeFk,
- floor(sum(value)) as total,
- floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas
- FROM vn.saleValue
- where year = vYear and week = vWeek
-
- GROUP BY family, itemFk
-
- ) sub
- ORDER BY mermas DESC;
+BEGIN
+ DECLARE vWeek INT;
+ DECLARE vYear INT;
+
+ SELECT week, year
+ INTO vWeek, vYear
+ FROM vn.time
+ WHERE dated = TIMESTAMPADD(WEEK, -1, CURDATE());
+
+ REPLACE bs.waste
+ SELECT *, 100 * mermas / total as porcentaje
+ FROM (
+ SELECT buyer,
+ year,
+ week,
+ family,
+ itemFk,
+ itemTypeFk,
+ floor(sum(value)) as total,
+ floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas
+ FROM vn.saleValue
+ where year = vYear and week = vWeek
+
+ GROUP BY family, itemFk
+
+ ) sub
+ ORDER BY mermas DESC;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -7802,146 +7605,147 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `availableNoRaids_refresh`(OUT `vCalc` INT, IN `vRefresh` INT, IN `vWarehouse` INT, IN `vDate` DATE)
-proc: BEGIN
- DECLARE vStartDate DATE;
- DECLARE vEndDate DATETIME;
- DECLARE vReserveDate DATETIME;
- DECLARE vParams CHAR(100);
- DECLARE vInventoryDate DATE;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- CALL cache_calc_unlock (vCalc);
- RESIGNAL;
- END;
-
- IF vDate < CURDATE() THEN
- LEAVE proc;
- END IF;
-
- CALL vn.itemStock (vWarehouse, vDate, NULL);
-
- SET vParams = CONCAT_WS('/', vWarehouse, vDate);
- CALL cache_calc_start (vCalc, vRefresh, 'availableNoRaids', vParams);
-
- IF !vRefresh THEN
- LEAVE proc;
- END IF;
-
- -- Calcula algunos parámetros necesarios
-
- SET vStartDate = TIMESTAMP(vDate, '00:00:00');
- SET vEndDate = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDate), '23:59:59');
-
- SELECT inventoried INTO vInventoryDate FROM vn.config;
-
- SELECT SUBTIME(NOW(), reserveTime) INTO vReserveDate
- FROM hedera.orderConfig;
-
- -- Calcula el ultimo dia de vida para cada producto
-
- DROP TEMPORARY TABLE IF EXISTS item_range;
- CREATE TEMPORARY TABLE item_range
- (PRIMARY KEY (item_id))
- ENGINE = MEMORY
- SELECT c.item_id, IF(it.life IS NULL, NULL,
- TIMESTAMP(TIMESTAMPADD(DAY, it.life, c.landing), '23:59:59')) AS date_end
- FROM (
- SELECT b.itemFk item_id, MAX(t.landed) landing
- FROM vn.buy b
- JOIN vn.entry e ON b.entryFk = e.id
- JOIN vn.travel t ON t.id = e.travelFk
- JOIN vn.warehouse w ON w.id = t.warehouseInFk
- WHERE t.landed BETWEEN vInventoryDate AND vStartDate
- AND t.warehouseInFk = vWarehouse
- AND NOT e.isInventory
- AND NOT e.isRaid
- GROUP BY b.itemFk
- ) c
- JOIN vn.item i ON i.id = c.item_id
- JOIN vn.itemType it ON it.id = i.typeFk
- HAVING date_end >= vStartDate OR date_end IS NULL;
-
- -- Replica la tabla item_range para poder usarla varias veces en la misma consulta
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy1;
- CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range;
- INSERT INTO item_range_copy1
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy2;
- CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range;
- INSERT INTO item_range_copy2
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy3;
- CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range;
- INSERT INTO item_range_copy3
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy4;
- CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range;
- INSERT INTO item_range_copy4
- SELECT * FROM item_range;
-
- -- Calcula el ATP
-
- DELETE FROM availableNoRaids WHERE calc_id = vCalc;
-
- INSERT INTO availableNoRaids (calc_id, item_id, available)
- SELECT vCalc, t.item_id, SUM(stock) amount FROM (
- SELECT il.itemFk AS item_id, stock
- FROM tmp.itemList il
- JOIN item_range ir ON ir.item_id = il.itemFk
- UNION ALL
- SELECT t.item_id, minacum(dt, amount, vDate) AS available FROM (
- SELECT itemFk AS item_id, DATE(dat) dt, SUM(quantity) amount FROM (
- SELECT i.itemFk, i.shipped AS dat, i.quantity
- FROM vn.itemTicketOut i
- JOIN item_range_copy1 ir ON ir.item_id = i.itemFk
- WHERE i.shipped >= vStartDate
- AND (ir.date_end IS NULL OR i.shipped <= ir.date_end)
- AND i.warehouseFk = vWarehouse
- UNION ALL
- SELECT i.itemFk, i.landed AS dat, i.quantity
- FROM vn.itemEntryIn i
- JOIN item_range_copy2 ir ON ir.item_id = i.itemFk
- WHERE i.landed >= vStartDate
- AND (ir.date_end IS NULL OR i.landed <= ir.date_end)
- AND i.warehouseInFk = vWarehouse
- AND i.isVirtualStock = FALSE
- UNION ALL
- SELECT i.itemFk, i.shipped AS dat, i.quantity
- FROM vn.itemEntryOut i
- JOIN item_range_copy3 ir ON ir.item_id = i.itemFk
- WHERE i.shipped >= vStartDate
- AND (ir.date_end IS NULL OR i.shipped <= ir.date_end)
- AND i.warehouseOutFk = vWarehouse
- UNION ALL
- SELECT r.item_id, r.shipment, -r.amount
- FROM hedera.order_row r
- JOIN hedera.`order` o ON o.id = r.order_id
- JOIN item_range_copy4 ir ON ir.item_id = r.item_id
- WHERE r.shipment >= vStartDate
- AND (ir.date_end IS NULL OR r.shipment <= ir.date_end)
- AND r.warehouse_id = vWarehouse
- AND r.created >= vReserveDate
- AND NOT o.confirmed
- ) t
- GROUP BY item_id, dt
- ) t
- GROUP BY t.item_id
- ) t GROUP BY t.item_id;
-
- DROP TEMPORARY TABLE IF EXISTS
- tmp.itemList
- ,item_range
- ,item_range_copy1
- ,item_range_copy2
- ,item_range_copy3
- ,item_range_copy4;
-
- CALL cache_calc_end (vCalc);
+proc: BEGIN
+ DECLARE vStartDate DATE;
+ DECLARE vEndDate DATETIME;
+ DECLARE vReserveDate DATETIME;
+ DECLARE vParams CHAR(100);
+ DECLARE vInventoryDate DATE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ CALL cache_calc_unlock (vCalc);
+ RESIGNAL;
+ END;
+
+ IF vDate < CURDATE() THEN
+ LEAVE proc;
+ END IF;
+
+ CALL vn.itemStock (vWarehouse, vDate, NULL);
+
+ SET vParams = CONCAT_WS('/', vWarehouse, vDate);
+ CALL cache_calc_start (vCalc, vRefresh, 'availableNoRaids', vParams);
+
+ IF !vRefresh THEN
+ LEAVE proc;
+ END IF;
+
+ -- Calcula algunos parámetros necesarios
+
+ SET vStartDate = TIMESTAMP(vDate, '00:00:00');
+ SET vEndDate = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDate), '23:59:59');
+
+ SELECT inventoried INTO vInventoryDate FROM vn.config;
+
+ SELECT SUBTIME(NOW(), reserveTime) INTO vReserveDate
+ FROM hedera.orderConfig;
+
+ -- Calcula el ultimo dia de vida para cada producto
+
+ DROP TEMPORARY TABLE IF EXISTS item_range;
+ CREATE TEMPORARY TABLE item_range
+ (PRIMARY KEY (item_id))
+ ENGINE = MEMORY
+ SELECT c.item_id, IF(it.life IS NULL, NULL,
+ TIMESTAMP(TIMESTAMPADD(DAY, it.life, c.landing), '23:59:59')) AS date_end
+ FROM (
+ SELECT b.itemFk item_id, MAX(t.landed) landing
+ FROM vn.buy b
+ JOIN vn.entry e ON b.entryFk = e.id
+ JOIN vn.travel t ON t.id = e.travelFk
+ JOIN vn.warehouse w ON w.id = t.warehouseInFk
+ JOIN vn.supplier s ON s.id = e.supplierFk
+ WHERE t.landed BETWEEN vInventoryDate AND vStartDate
+ AND t.warehouseInFk = vWarehouse
+ AND s.name != 'INVENTARIO'
+ AND NOT e.isRaid
+ GROUP BY b.itemFk
+ ) c
+ JOIN vn.item i ON i.id = c.item_id
+ JOIN vn.itemType it ON it.id = i.typeFk
+ HAVING date_end >= vStartDate OR date_end IS NULL;
+
+ -- Replica la tabla item_range para poder usarla varias veces en la misma consulta
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy1;
+ CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range;
+ INSERT INTO item_range_copy1
+ SELECT * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy2;
+ CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range;
+ INSERT INTO item_range_copy2
+ SELECT * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy3;
+ CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range;
+ INSERT INTO item_range_copy3
+ SELECT * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy4;
+ CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range;
+ INSERT INTO item_range_copy4
+ SELECT * FROM item_range;
+
+ -- Calcula el ATP
+
+ DELETE FROM availableNoRaids WHERE calc_id = vCalc;
+
+ INSERT INTO availableNoRaids (calc_id, item_id, available)
+ SELECT vCalc, t.item_id, SUM(stock) amount FROM (
+ SELECT il.itemFk AS item_id, stock
+ FROM tmp.itemList il
+ JOIN item_range ir ON ir.item_id = il.itemFk
+ UNION ALL
+ SELECT t.item_id, minacum(dt, amount, vDate) AS available FROM (
+ SELECT itemFk AS item_id, DATE(dat) dt, SUM(quantity) amount FROM (
+ SELECT i.itemFk, i.shipped AS dat, i.quantity
+ FROM vn.itemTicketOut i
+ JOIN item_range_copy1 ir ON ir.item_id = i.itemFk
+ WHERE i.shipped >= vStartDate
+ AND (ir.date_end IS NULL OR i.shipped <= ir.date_end)
+ AND i.warehouseFk = vWarehouse
+ UNION ALL
+ SELECT i.itemFk, i.landed AS dat, i.quantity
+ FROM vn.itemEntryIn i
+ JOIN item_range_copy2 ir ON ir.item_id = i.itemFk
+ WHERE i.landed >= vStartDate
+ AND (ir.date_end IS NULL OR i.landed <= ir.date_end)
+ AND i.warehouseInFk = vWarehouse
+ AND i.isVirtualStock = FALSE
+ UNION ALL
+ SELECT i.itemFk, i.shipped AS dat, i.quantity
+ FROM vn.itemEntryOut i
+ JOIN item_range_copy3 ir ON ir.item_id = i.itemFk
+ WHERE i.shipped >= vStartDate
+ AND (ir.date_end IS NULL OR i.shipped <= ir.date_end)
+ AND i.warehouseOutFk = vWarehouse
+ UNION ALL
+ SELECT r.item_id, r.shipment, -r.amount
+ FROM hedera.order_row r
+ JOIN hedera.`order` o ON o.id = r.order_id
+ JOIN item_range_copy4 ir ON ir.item_id = r.item_id
+ WHERE r.shipment >= vStartDate
+ AND (ir.date_end IS NULL OR r.shipment <= ir.date_end)
+ AND r.warehouse_id = vWarehouse
+ AND r.created >= vReserveDate
+ AND NOT o.confirmed
+ ) t
+ GROUP BY item_id, dt
+ ) t
+ GROUP BY t.item_id
+ ) t GROUP BY t.item_id;
+
+ DROP TEMPORARY TABLE IF EXISTS
+ tmp.itemList
+ ,item_range
+ ,item_range_copy1
+ ,item_range_copy2
+ ,item_range_copy3
+ ,item_range_copy4;
+
+ CALL cache_calc_end (vCalc);
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -8185,27 +7989,27 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_end`(IN `v_calc` INT)
-BEGIN
- DECLARE v_cache_name VARCHAR(255);
- DECLARE v_params VARCHAR(255);
-
- -- Libera el bloqueo y actualiza la fecha de ultimo refresco.
-
- UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id
- SET
- cc.last_refresh = NOW(),
- cc.expires = LEAST(ADDTIME(NOW(), c.lifetime), util.midNight()),
- cc.connection_id = NULL
- WHERE cc.id = v_calc;
-
- SELECT c.name, ca.params INTO v_cache_name, v_params
- FROM cache c
- JOIN cache_calc ca ON c.id = ca.cache_id
- WHERE ca.id = v_calc;
-
- IF v_cache_name IS NOT NULL THEN
- DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
- END IF;
+BEGIN
+ DECLARE v_cache_name VARCHAR(255);
+ DECLARE v_params VARCHAR(255);
+
+ -- Libera el bloqueo y actualiza la fecha de ultimo refresco.
+
+ UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id
+ SET
+ cc.last_refresh = NOW(),
+ cc.expires = LEAST(ADDTIME(NOW(), c.lifetime), util.midNight()),
+ cc.connection_id = NULL
+ WHERE cc.id = v_calc;
+
+ SELECT c.name, ca.params INTO v_cache_name, v_params
+ FROM cache c
+ JOIN cache_calc ca ON c.id = ca.cache_id
+ WHERE ca.id = v_calc;
+
+ IF v_cache_name IS NOT NULL THEN
+ DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -8223,88 +8027,88 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_start`(OUT `v_calc` INT, INOUT `v_refresh` INT, IN `v_cache_name` VARCHAR(50), IN `v_params` VARCHAR(100))
-proc: BEGIN
- DECLARE v_valid BOOL;
- DECLARE v_lock_id VARCHAR(100);
- DECLARE v_cache_id INT;
- DECLARE v_expires DATETIME;
- DECLARE v_clean_time DATETIME;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- IF v_lock_id IS NOT NULL THEN
- DO RELEASE_LOCK(v_lock_id);
- END IF;
-
- RESIGNAL;
- END;
-
- SET v_params = IFNULL(v_params, '');
-
- -- Si el servidor se ha reiniciado invalida todos los calculos.
-
- SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid;
-
- IF !v_valid
- THEN
- DELETE FROM cache_calc;
- INSERT INTO cache_valid (valid) VALUES (TRUE);
- END IF;
-
- -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia.
-
- SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params);
-
- IF !GET_LOCK(v_lock_id, 30)
- THEN
- SET v_calc = NULL;
- SET v_refresh = FALSE;
- LEAVE proc;
- END IF;
-
- -- Comprueba si el calculo solicitado existe y esta actualizado.
-
- SELECT c.id, ca.id, ca.expires
- INTO v_cache_id, v_calc, v_expires
- FROM cache c
- LEFT JOIN cache_calc ca
- ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci'
- WHERE c.name = v_cache_name COLLATE 'utf8_general_ci';
-
- -- Si existe una calculo valido libera el bloqueo y devuelve su identificador.
-
- IF !v_refresh AND NOW() < v_expires
- THEN
- DO RELEASE_LOCK(v_lock_id);
- SET v_refresh = FALSE;
- LEAVE proc;
- END IF;
-
- -- Si el calculo no existe le crea una entrada en la tabla de calculos.
-
- IF v_calc IS NULL
- THEN
- INSERT INTO cache_calc SET
- cache_id = v_cache_id,
- cacheName = v_cache_name,
- params = v_params,
- last_refresh = NULL,
- expires = NULL,
- connection_id = CONNECTION_ID();
-
- SET v_calc = LAST_INSERT_ID();
- ELSE
- UPDATE cache_calc
- SET
- last_refresh = NULL,
- expires = NULL,
- connection_id = CONNECTION_ID()
- WHERE id = v_calc;
- END IF;
-
- -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador.
-
- SET v_refresh = TRUE;
+proc: BEGIN
+ DECLARE v_valid BOOL;
+ DECLARE v_lock_id VARCHAR(100);
+ DECLARE v_cache_id INT;
+ DECLARE v_expires DATETIME;
+ DECLARE v_clean_time DATETIME;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ IF v_lock_id IS NOT NULL THEN
+ DO RELEASE_LOCK(v_lock_id);
+ END IF;
+
+ RESIGNAL;
+ END;
+
+ SET v_params = IFNULL(v_params, '');
+
+ -- Si el servidor se ha reiniciado invalida todos los calculos.
+
+ SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid;
+
+ IF !v_valid
+ THEN
+ DELETE FROM cache_calc;
+ INSERT INTO cache_valid (valid) VALUES (TRUE);
+ END IF;
+
+ -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia.
+
+ SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params);
+
+ IF !GET_LOCK(v_lock_id, 30)
+ THEN
+ SET v_calc = NULL;
+ SET v_refresh = FALSE;
+ LEAVE proc;
+ END IF;
+
+ -- Comprueba si el calculo solicitado existe y esta actualizado.
+
+ SELECT c.id, ca.id, ca.expires
+ INTO v_cache_id, v_calc, v_expires
+ FROM cache c
+ LEFT JOIN cache_calc ca
+ ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci'
+ WHERE c.name = v_cache_name COLLATE 'utf8_general_ci';
+
+ -- Si existe una calculo valido libera el bloqueo y devuelve su identificador.
+
+ IF !v_refresh AND NOW() < v_expires
+ THEN
+ DO RELEASE_LOCK(v_lock_id);
+ SET v_refresh = FALSE;
+ LEAVE proc;
+ END IF;
+
+ -- Si el calculo no existe le crea una entrada en la tabla de calculos.
+
+ IF v_calc IS NULL
+ THEN
+ INSERT INTO cache_calc SET
+ cache_id = v_cache_id,
+ cacheName = v_cache_name,
+ params = v_params,
+ last_refresh = NULL,
+ expires = NULL,
+ connection_id = CONNECTION_ID();
+
+ SET v_calc = LAST_INSERT_ID();
+ ELSE
+ UPDATE cache_calc
+ SET
+ last_refresh = NULL,
+ expires = NULL,
+ connection_id = CONNECTION_ID()
+ WHERE id = v_calc;
+ END IF;
+
+ -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador.
+
+ SET v_refresh = TRUE;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -8322,24 +8126,24 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_unlock`(IN `v_calc` INT)
-proc: BEGIN
- DECLARE v_cache_name VARCHAR(50);
- DECLARE v_params VARCHAR(100);
-
- IF v_calc IS NULL THEN
- LEAVE proc;
- END IF;
-
- SELECT c.name, ca.params INTO v_cache_name, v_params
- FROM cache c
- JOIN cache_calc ca ON c.id = ca.cache_id
- WHERE ca.id = v_calc;
-
- DELETE FROM cache_calc WHERE id = v_calc;
-
- IF v_cache_name IS NOT NULL THEN
- DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
- END IF;
+proc: BEGIN
+ DECLARE v_cache_name VARCHAR(50);
+ DECLARE v_params VARCHAR(100);
+
+ IF v_calc IS NULL THEN
+ LEAVE proc;
+ END IF;
+
+ SELECT c.name, ca.params INTO v_cache_name, v_params
+ FROM cache c
+ JOIN cache_calc ca ON c.id = ca.cache_id
+ WHERE ca.id = v_calc;
+
+ DELETE FROM cache_calc WHERE id = v_calc;
+
+ IF v_cache_name IS NOT NULL THEN
+ DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -8378,13 +8182,13 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`()
-BEGIN
-
- DECLARE vDateShort DATETIME;
-
- SET vDateShort = TIMESTAMPADD(MONTH, -1, CURDATE());
-
- DELETE FROM cache.departure_limit WHERE Fecha < vDateShort;
+BEGIN
+
+ DECLARE vDateShort DATETIME;
+
+ SET vDateShort = TIMESTAMPADD(MONTH, -1, CURDATE());
+
+ DELETE FROM cache.departure_limit WHERE Fecha < vDateShort;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -10198,22 +10002,22 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `imageName`(vPictureReference VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
-
- SET vPictureReference = REPLACE(vPictureReference,'.','');
-
- SET vPictureReference = REPLACE(vPictureReference,'/','');
-
- SET vPictureReference = REPLACE(vPictureReference,'%','');
-
- SET vPictureReference = REPLACE(vPictureReference,':','');
-
- SET vPictureReference = REPLACE(vPictureReference,'?','');
-
- SET vPictureReference = REPLACE(vPictureReference,'=','');
-
- RETURN vPictureReference;
-
+BEGIN
+
+ SET vPictureReference = REPLACE(vPictureReference,'.','');
+
+ SET vPictureReference = REPLACE(vPictureReference,'/','');
+
+ SET vPictureReference = REPLACE(vPictureReference,'%','');
+
+ SET vPictureReference = REPLACE(vPictureReference,':','');
+
+ SET vPictureReference = REPLACE(vPictureReference,'?','');
+
+ SET vPictureReference = REPLACE(vPictureReference,'=','');
+
+ RETURN vPictureReference;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -10263,28 +10067,28 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `deliveryInformation_Delete`()
-BEGIN
-
- DECLARE vID INT;
- DECLARE vGap INT DEFAULT 100;
- DECLARE vTope INT;
-
- SELECT MIN(ID), MAX(ID)
- INTO vID, vTope
- FROM edi.deliveryInformation;
-
- WHILE vID <= vTope DO
-
- SET vID = vID + vGap;
-
- DELETE
- FROM edi.deliveryInformation
- WHERE ID < vID
- AND EarliestDespatchDateTime IS NULL;
-
- END WHILE;
-
-
+BEGIN
+
+ DECLARE vID INT;
+ DECLARE vGap INT DEFAULT 100;
+ DECLARE vTope INT;
+
+ SELECT MIN(ID), MAX(ID)
+ INTO vID, vTope
+ FROM edi.deliveryInformation;
+
+ WHILE vID <= vTope DO
+
+ SET vID = vID + vGap;
+
+ DELETE
+ FROM edi.deliveryInformation
+ WHERE ID < vID
+ AND EarliestDespatchDateTime IS NULL;
+
+ END WHILE;
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -10669,38 +10473,38 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_loadNotBuy`()
-BEGIN
-
- /**
- * Ejecuta ekt_load para aquellos ekt de hoy que no tienen vn.buy
- */
-
- DECLARE vEktFk INTEGER;
- DECLARE done BOOL;
-
-
- DECLARE cursor1 CURSOR FOR SELECT e.id
- FROM edi.ekt e
- LEFT JOIN vn.buy b ON b.ektFk = e.id
- WHERE e.fec >= CURDATE()
- AND ISNULL(b.ektFk);
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-
- OPEN cursor1;
- bucle: LOOP
-
- FETCH cursor1 INTO vEktFk;
-
- IF done THEN
- LEAVE bucle;
- END IF;
-
- CALL edi.ekt_load(vEktFk);
-
- END LOOP bucle;
- CLOSE cursor1;
-
+BEGIN
+
+ /**
+ * Ejecuta ekt_load para aquellos ekt de hoy que no tienen vn.buy
+ */
+
+ DECLARE vEktFk INTEGER;
+ DECLARE done BOOL;
+
+
+ DECLARE cursor1 CURSOR FOR SELECT e.id
+ FROM edi.ekt e
+ LEFT JOIN vn.buy b ON b.ektFk = e.id
+ WHERE e.fec >= CURDATE()
+ AND ISNULL(b.ektFk);
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
+
+ OPEN cursor1;
+ bucle: LOOP
+
+ FETCH cursor1 INTO vEktFk;
+
+ IF done THEN
+ LEAVE bucle;
+ END IF;
+
+ CALL edi.ekt_load(vEktFk);
+
+ END LOOP bucle;
+ CLOSE cursor1;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -12364,56 +12168,56 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_freeAdd`()
-BEGIN
-
- /**
- * Rellena la tabla item_free con los id ausentes en vn.item
- *
- */
-
- DECLARE vCounter INT DEFAULT 400000;
-
- DECLARE vCounterNewItems INT DEFAULT 0;
-
- DECLARE vMaxItem INT;
-
- DECLARE vExists BOOLEAN DEFAULT FALSE;
-
- SELECT MAX(id)
- INTO vMaxItem
- FROM vn.item;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.itemBusy;
- CREATE TEMPORARY TABLE tmp.itemBusy
- (id INT PRIMARY KEY)
- SELECT i.id
- FROM vn.item i
- WHERE id >= 400000
- UNION ALL
- SELECT ifr.id
- FROM edi.item_free ifr;
-
- WHILE vCounter < vMaxItem DO
-
- SET vCounter = vCounter + 1;
-
- SELECT count(*) INTO vExists
- FROM tmp.itemBusy
- WHERE id = vCounter;
-
- IF NOT vExists THEN
-
- SET vCounterNewItems = vCounterNewItems + 1;
-
- INSERT INTO edi.item_free(id)
- VALUES (vCounter);
-
- END IF;
-
- END WHILE;
-
- DROP TEMPORARY TABLE tmp.itemBusy;
-
+BEGIN
+
+ /**
+ * Rellena la tabla item_free con los id ausentes en vn.item
+ *
+ */
+
+ DECLARE vCounter INT DEFAULT 400000;
+
+ DECLARE vCounterNewItems INT DEFAULT 0;
+
+ DECLARE vMaxItem INT;
+
+ DECLARE vExists BOOLEAN DEFAULT FALSE;
+
+ SELECT MAX(id)
+ INTO vMaxItem
+ FROM vn.item;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.itemBusy;
+ CREATE TEMPORARY TABLE tmp.itemBusy
+ (id INT PRIMARY KEY)
+ SELECT i.id
+ FROM vn.item i
+ WHERE id >= 400000
+ UNION ALL
+ SELECT ifr.id
+ FROM edi.item_free ifr;
+
+ WHILE vCounter < vMaxItem DO
+
+ SET vCounter = vCounter + 1;
+
+ SELECT count(*) INTO vExists
+ FROM tmp.itemBusy
+ WHERE id = vCounter;
+
+ IF NOT vExists THEN
+
+ SET vCounterNewItems = vCounterNewItems + 1;
+
+ INSERT INTO edi.item_free(id)
+ VALUES (vCounter);
+
+ END IF;
+
+ END WHILE;
+
+ DROP TEMPORARY TABLE tmp.itemBusy;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -12676,49 +12480,49 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `orderLog__`(vItemFk INT)
-BEGIN
-
- DECLARE vSupplyResponseFk INT;
- DECLARE vDescription VARCHAR(100);
-
- SELECT supplyResponseFk, CONCAT(id, ' ',longName) INTO vSupplyResponseFk, vDescription
- FROM vn.item
- WHERE id = vItemFk;
-
- SELECT * FROM
- (
- SELECT 'Cliente confirma' accion, or2.created hora, amount Cantidad
- FROM hedera.order_row or2
- JOIN vn.item i ON i.id = or2.item_id
- WHERE i.supplyResponseFk = vSupplyResponseFk
-
- UNION ALL
-
- SELECT vDescription, NULL, NULL
-
- UNION ALL
-
- SELECT 'Cliente se conecta' , o.date_make , NULL
- FROM hedera.`order` o
- JOIN hedera.order_row or2 ON or2.order_id = o.id
- JOIN vn.item i ON i.id = or2.item_id
- WHERE i.supplyResponseFk = vSupplyResponseFk
-
- UNION ALL
-
- SELECT DISTINCT 'Subasta cambia cantidad', srl.created, srl.NumberOfUnitsNew * sr.NumberOfItemsPerCask
- FROM edi.supplyResponseLog srl
- JOIN edi.supplyResponse sr ON sr.ID = srl.supplyResponseFk
- WHERE srl.supplyResponseFk = vSupplyResponseFk
-
- UNION ALL
-
- SELECT 'Linea de venta definitiva', s.created, s.quantity
- FROM vn.sale s
- JOIN vn.item i ON i.id = s.itemFk
- WHERE i.supplyResponseFk = vSupplyResponseFk) sub
- ORDER BY hora;
-
+BEGIN
+
+ DECLARE vSupplyResponseFk INT;
+ DECLARE vDescription VARCHAR(100);
+
+ SELECT supplyResponseFk, CONCAT(id, ' ',longName) INTO vSupplyResponseFk, vDescription
+ FROM vn.item
+ WHERE id = vItemFk;
+
+ SELECT * FROM
+ (
+ SELECT 'Cliente confirma' accion, or2.created hora, amount Cantidad
+ FROM hedera.order_row or2
+ JOIN vn.item i ON i.id = or2.item_id
+ WHERE i.supplyResponseFk = vSupplyResponseFk
+
+ UNION ALL
+
+ SELECT vDescription, NULL, NULL
+
+ UNION ALL
+
+ SELECT 'Cliente se conecta' , o.date_make , NULL
+ FROM hedera.`order` o
+ JOIN hedera.order_row or2 ON or2.order_id = o.id
+ JOIN vn.item i ON i.id = or2.item_id
+ WHERE i.supplyResponseFk = vSupplyResponseFk
+
+ UNION ALL
+
+ SELECT DISTINCT 'Subasta cambia cantidad', srl.created, srl.NumberOfUnitsNew * sr.NumberOfItemsPerCask
+ FROM edi.supplyResponseLog srl
+ JOIN edi.supplyResponse sr ON sr.ID = srl.supplyResponseFk
+ WHERE srl.supplyResponseFk = vSupplyResponseFk
+
+ UNION ALL
+
+ SELECT 'Linea de venta definitiva', s.created, s.quantity
+ FROM vn.sale s
+ JOIN vn.item i ON i.id = s.itemFk
+ WHERE i.supplyResponseFk = vSupplyResponseFk) sub
+ ORDER BY hora;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -12736,55 +12540,55 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_calcCompByFloramondo`(vSelf INT)
-BEGIN
-
- /**
- * Recalcula "a pelo" los componentes para un ticket de Floramondo
- *
- * Pendiente de concretar la solución cuando Logiflora conteste.
- *
- * @param vSelf Identificador de vn.ticket
- */
-
- CALL cache.last_buy_refresh(TRUE);
-
- DELETE sc.*
- FROM vn.saleComponent sc
- JOIN vn.sale s ON s.id = sc.saleFk
- WHERE s.ticketFk = vSelf;
-
- UPDATE vn.sale s
- JOIN vn.item i ON i.id = s.itemFk
- JOIN edi.floraHollandConfig fhc
- LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
- LEFT JOIN vn.buy b ON b.id = lb.buy_id
- LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo'
- SET s.price = b.buyingValue * (1 + fhc.floramondoMargin)
- WHERE s.ticketFk = vSelf;
-
- INSERT INTO vn.saleComponent(saleFk, componentFk, value)
- SELECT s.id, c.id, MAX(b.buyingValue)
- FROM vn.sale s
- JOIN vn.item i ON i.id = s.itemFk
- LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
- LEFT JOIN vn.buy b ON b.id = lb.buy_id
- LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo'
- JOIN vn.component c ON c.code = 'purchaseValue'
- WHERE s.ticketFk = vSelf
- GROUP BY s.id;
-
- INSERT INTO vn.saleComponent(saleFk, componentFk, value)
- SELECT s.id, c.id, MAX(b.buyingValue) * fhc.floramondoMargin
- FROM vn.sale s
- JOIN vn.item i ON i.id = s.itemFk
- JOIN edi.floraHollandConfig fhc
- LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
- LEFT JOIN vn.buy b ON b.id = lb.buy_id
- LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo'
- JOIN vn.component c ON c.code = 'margin'
- WHERE s.ticketFk = vSelf
- GROUP BY s.id;
-
+BEGIN
+
+ /**
+ * Recalcula "a pelo" los componentes para un ticket de Floramondo
+ *
+ * Pendiente de concretar la solución cuando Logiflora conteste.
+ *
+ * @param vSelf Identificador de vn.ticket
+ */
+
+ CALL cache.last_buy_refresh(TRUE);
+
+ DELETE sc.*
+ FROM vn.saleComponent sc
+ JOIN vn.sale s ON s.id = sc.saleFk
+ WHERE s.ticketFk = vSelf;
+
+ UPDATE vn.sale s
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN edi.floraHollandConfig fhc
+ LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
+ LEFT JOIN vn.buy b ON b.id = lb.buy_id
+ LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo'
+ SET s.price = b.buyingValue * (1 + fhc.floramondoMargin)
+ WHERE s.ticketFk = vSelf;
+
+ INSERT INTO vn.saleComponent(saleFk, componentFk, value)
+ SELECT s.id, c.id, MAX(b.buyingValue)
+ FROM vn.sale s
+ JOIN vn.item i ON i.id = s.itemFk
+ LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
+ LEFT JOIN vn.buy b ON b.id = lb.buy_id
+ LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo'
+ JOIN vn.component c ON c.code = 'purchaseValue'
+ WHERE s.ticketFk = vSelf
+ GROUP BY s.id;
+
+ INSERT INTO vn.saleComponent(saleFk, componentFk, value)
+ SELECT s.id, c.id, MAX(b.buyingValue) * fhc.floramondoMargin
+ FROM vn.sale s
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN edi.floraHollandConfig fhc
+ LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
+ LEFT JOIN vn.buy b ON b.id = lb.buy_id
+ LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo'
+ JOIN vn.component c ON c.code = 'margin'
+ WHERE s.ticketFk = vSelf
+ GROUP BY s.id;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -13666,24 +13470,24 @@ DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate`
AFTER UPDATE ON `order`
FOR EACH ROW
-BEGIN
- CALL stock.log_add('order', NEW.id, OLD.id);
-
- IF !(OLD.address_id <=> NEW.address_id)
- OR !(OLD.company_id <=> NEW.company_id)
- OR !(OLD.customer_id <=> NEW.customer_id) THEN
- CALL order_requestRecalc(NEW.id);
- END IF;
-
- IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN
- -- Fallo que se actualiza no se sabe como tickets en este cliente
- CALL vn.mail_insert(
- 'jgallego@verdnatura.es',
- 'noreply@verdnatura.es',
- 'Actualizada order al address 2850',
- CONCAT(account.myUserGetName(), ' ha creado la order ',NEW.id)
- );
- END IF;
+BEGIN
+ CALL stock.log_add('order', NEW.id, OLD.id);
+
+ IF !(OLD.address_id <=> NEW.address_id)
+ OR !(OLD.company_id <=> NEW.company_id)
+ OR !(OLD.customer_id <=> NEW.customer_id) THEN
+ CALL order_requestRecalc(NEW.id);
+ END IF;
+
+ IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN
+ -- Fallo que se actualiza no se sabe como tickets en este cliente
+ CALL vn.mail_insert(
+ 'jgallego@verdnatura.es',
+ 'noreply@verdnatura.es',
+ 'Actualizada order al address 2850',
+ CONCAT(account.myUserGetName(), ' ha creado la order ',NEW.id)
+ );
+ END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -15077,30 +14881,30 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_listAllocation`(IN `vWh` TINYINT, IN `vDate` DATE, IN `vType` INT, IN `vPrefix` VARCHAR(255), IN `vUseIds` BOOLEAN)
-BEGIN
-/**
- * Lists visible items and it's box sizes of the specified
- * type at specified date.
- *
- * @param vWh The warehouse id
- * @param vDate The visible date
- * @param vType The type id
- * @param vPrefix The article prefix to filter or %NULL for all
- * @param vUseIds Whether to order the result by item id
- * @select List of visible items with it's box sizes
- */
- CALL item_getVisible(vWh, vDate, vType, vPrefix);
-
- IF vUseIds
- THEN
- SELECT * FROM tmp.itemVisible
- ORDER BY Id_Article;
- ELSE
- SELECT * FROM tmp.itemVisible
- ORDER BY Article, packing;
- END IF;
-
- DROP TEMPORARY TABLE tmp.itemVisible;
+BEGIN
+/**
+ * Lists visible items and it's box sizes of the specified
+ * type at specified date.
+ *
+ * @param vWh The warehouse id
+ * @param vDate The visible date
+ * @param vType The type id
+ * @param vPrefix The article prefix to filter or %NULL for all
+ * @param vUseIds Whether to order the result by item id
+ * @select List of visible items with it's box sizes
+ */
+ CALL item_getVisible(vWh, vDate, vType, vPrefix);
+
+ IF vUseIds
+ THEN
+ SELECT * FROM tmp.itemVisible
+ ORDER BY Id_Article;
+ ELSE
+ SELECT * FROM tmp.itemVisible
+ ORDER BY Article, packing;
+ END IF;
+
+ DROP TEMPORARY TABLE tmp.itemVisible;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -15247,82 +15051,82 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_configure`(
- vDelivery DATE,
- vDeliveryMethod VARCHAR(45),
- vAgency INT,
+CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_configure`(
+ vDelivery DATE,
+ vDeliveryMethod VARCHAR(45),
+ vAgency INT,
vAddress INT)
-BEGIN
-/**
- * Configura la cesta de la compra utilizando los parámetros
- * pasados. Si los parámetros no son válidos devuelve un error.
- *
- * @param vDelivery Fecha de recogida
- * @param vAgency Id de la agencia
- * @param vAddress Id de dirección de envío, @NULL si es recogida
- */
- DECLARE vSelf INT;
- DECLARE vCompany INT;
- DECLARE vDeliveryMethodId INT;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL;
- DECLARE EXIT HANDLER FOR SQLSTATE '45000'
- BEGIN
- ROLLBACK;
- RESIGNAL;
- END;
-
- START TRANSACTION;
-
- SELECT id INTO vDeliveryMethodId
- FROM vn.deliveryMethod
- WHERE code = vDeliveryMethod;
-
- IF vDeliveryMethod = 'PICKUP' AND vAddress IS NULL
- THEN
- SELECT defaultAddressFk INTO vAddress
- FROM myClient;
- END IF;
-
- SET vSelf = myBasket_getId();
-
- IF vSelf IS NULL
- THEN
-
- SELECT defaultCompanyFk INTO vCompany
- FROM orderConfig;
-
- INSERT INTO `order`
- SET
- customer_id = account.userGetId(),
- date_send = vDelivery,
- delivery_method_id = vDeliveryMethodId,
- agency_id = vAgency,
- address_id = vAddress,
- source_app = 'WEB',
- company_id = vCompany;
-
- SET vSelf = LAST_INSERT_ID();
-
- INSERT INTO basketOrder SET
- clientFk = account.userGetId(),
- orderFk = vSelf;
- ELSE
- UPDATE `order`
- SET
- date_send = vDelivery,
- delivery_method_id = vDeliveryMethodId,
- agency_id = vAgency,
- address_id = vAddress
- WHERE
- id = vSelf;
-
- CALL order_update(vSelf);
- END IF;
-
- CALL order_checkConfig(vSelf);
-
- COMMIT;
+BEGIN
+/**
+ * Configura la cesta de la compra utilizando los parámetros
+ * pasados. Si los parámetros no son válidos devuelve un error.
+ *
+ * @param vDelivery Fecha de recogida
+ * @param vAgency Id de la agencia
+ * @param vAddress Id de dirección de envío, @NULL si es recogida
+ */
+ DECLARE vSelf INT;
+ DECLARE vCompany INT;
+ DECLARE vDeliveryMethodId INT;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL;
+ DECLARE EXIT HANDLER FOR SQLSTATE '45000'
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ START TRANSACTION;
+
+ SELECT id INTO vDeliveryMethodId
+ FROM vn.deliveryMethod
+ WHERE code = vDeliveryMethod;
+
+ IF vDeliveryMethod = 'PICKUP' AND vAddress IS NULL
+ THEN
+ SELECT defaultAddressFk INTO vAddress
+ FROM myClient;
+ END IF;
+
+ SET vSelf = myBasket_getId();
+
+ IF vSelf IS NULL
+ THEN
+
+ SELECT defaultCompanyFk INTO vCompany
+ FROM orderConfig;
+
+ INSERT INTO `order`
+ SET
+ customer_id = account.userGetId(),
+ date_send = vDelivery,
+ delivery_method_id = vDeliveryMethodId,
+ agency_id = vAgency,
+ address_id = vAddress,
+ source_app = 'WEB',
+ company_id = vCompany;
+
+ SET vSelf = LAST_INSERT_ID();
+
+ INSERT INTO basketOrder SET
+ clientFk = account.userGetId(),
+ orderFk = vSelf;
+ ELSE
+ UPDATE `order`
+ SET
+ date_send = vDelivery,
+ delivery_method_id = vDeliveryMethodId,
+ agency_id = vAgency,
+ address_id = vAddress
+ WHERE
+ id = vSelf;
+
+ CALL order_update(vSelf);
+ END IF;
+
+ CALL order_checkConfig(vSelf);
+
+ COMMIT;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -15547,62 +15351,62 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_newWithAddress`(
- OUT vSelf INT,
- vLandingDate DATE,
+CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_newWithAddress`(
+ OUT vSelf INT,
+ vLandingDate DATE,
vAddressFk INT)
-BEGIN
-/**
- * Crea una nueva orden para el usuario actual especificando
- * una fecha de entrega.
- *
- * @param vSelf Id de la nueva orden
- * @param vLandingDate Fecha de entrega
- */
- DECLARE vCompany INT;
- DECLARE vDeliveryMethodId INT;
- DECLARE vAgencyMode INT;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL;
- DECLARE EXIT HANDLER FOR SQLSTATE '45000'
- BEGIN
- ROLLBACK;
- SET vSelf = NULL;
- RESIGNAL;
- END;
-
- START TRANSACTION;
-
- SELECT a.agencyModeFk, a.id
- INTO vAgencyMode, vAddressFk
- FROM vn.address a
- WHERE a.id = vAddressFk;
-
- SELECT deliveryMethodFk INTO vDeliveryMethodId
- FROM vn.agencyMode am
- WHERE am.id = vAgencyMode;
-
- IF vCompany IS NULL
- THEN
- SELECT defaultCompanyFk INTO vCompany
- FROM orderConfig;
- END IF;
-
- INSERT INTO `order`
- SET
- customer_id = account.userGetId(),
- date_send = vLandingDate,
- delivery_method_id = vDeliveryMethodId,
- agency_id = vAgencyMode,
- address_id = vAddressFk,
- source_app = 'WEB',
- company_id = vCompany;
-
- SET vSelf = LAST_INSERT_ID();
-
- CALL order_checkConfig(vSelf);
-
- COMMIT;
+BEGIN
+/**
+ * Crea una nueva orden para el usuario actual especificando
+ * una fecha de entrega.
+ *
+ * @param vSelf Id de la nueva orden
+ * @param vLandingDate Fecha de entrega
+ */
+ DECLARE vCompany INT;
+ DECLARE vDeliveryMethodId INT;
+ DECLARE vAgencyMode INT;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL;
+ DECLARE EXIT HANDLER FOR SQLSTATE '45000'
+ BEGIN
+ ROLLBACK;
+ SET vSelf = NULL;
+ RESIGNAL;
+ END;
+
+ START TRANSACTION;
+
+ SELECT a.agencyModeFk, a.id
+ INTO vAgencyMode, vAddressFk
+ FROM vn.address a
+ WHERE a.id = vAddressFk;
+
+ SELECT deliveryMethodFk INTO vDeliveryMethodId
+ FROM vn.agencyMode am
+ WHERE am.id = vAgencyMode;
+
+ IF vCompany IS NULL
+ THEN
+ SELECT defaultCompanyFk INTO vCompany
+ FROM orderConfig;
+ END IF;
+
+ INSERT INTO `order`
+ SET
+ customer_id = account.userGetId(),
+ date_send = vLandingDate,
+ delivery_method_id = vDeliveryMethodId,
+ agency_id = vAgencyMode,
+ address_id = vAddressFk,
+ source_app = 'WEB',
+ company_id = vCompany;
+
+ SET vSelf = LAST_INSERT_ID();
+
+ CALL order_checkConfig(vSelf);
+
+ COMMIT;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -15619,62 +15423,62 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_newWithDate`(
- OUT vSelf INT,
+CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_newWithDate`(
+ OUT vSelf INT,
vLandingDate DATE)
-BEGIN
-/**
- * Crea una nueva orden para el usuario actual especificando
- * una fecha de entrega.
- *
- * @param vSelf Id de la nueva orden
- * @param vLandingDate Fecha de entrega
- */
- DECLARE vCompany INT;
- DECLARE vDeliveryMethodId INT;
- DECLARE vAgencyMode INT;
- DECLARE vAddress INT;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL;
- DECLARE EXIT HANDLER FOR SQLSTATE '45000'
- BEGIN
- ROLLBACK;
- SET vSelf = NULL;
- RESIGNAL;
- END;
-
- START TRANSACTION;
-
- SELECT a.agencyModeFk, a.id
- INTO vAgencyMode, vAddress
- FROM myClient c
- JOIN vn.address a ON a.id = c.defaultAddressFk;
-
- SELECT deliveryMethodFk INTO vDeliveryMethodId
- FROM vn.agencyMode am
- WHERE am.id = vAgencyMode;
-
- IF vCompany IS NULL
- THEN
- SELECT defaultCompanyFk INTO vCompany
- FROM orderConfig;
- END IF;
-
- INSERT INTO `order`
- SET
- customer_id = account.userGetId(),
- date_send = vLandingDate,
- delivery_method_id = vDeliveryMethodId,
- agency_id = vAgencyMode,
- address_id = vAddress,
- source_app = 'WEB',
- company_id = vCompany;
-
- SET vSelf = LAST_INSERT_ID();
-
- CALL order_checkConfig(vSelf);
-
- COMMIT;
+BEGIN
+/**
+ * Crea una nueva orden para el usuario actual especificando
+ * una fecha de entrega.
+ *
+ * @param vSelf Id de la nueva orden
+ * @param vLandingDate Fecha de entrega
+ */
+ DECLARE vCompany INT;
+ DECLARE vDeliveryMethodId INT;
+ DECLARE vAgencyMode INT;
+ DECLARE vAddress INT;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL;
+ DECLARE EXIT HANDLER FOR SQLSTATE '45000'
+ BEGIN
+ ROLLBACK;
+ SET vSelf = NULL;
+ RESIGNAL;
+ END;
+
+ START TRANSACTION;
+
+ SELECT a.agencyModeFk, a.id
+ INTO vAgencyMode, vAddress
+ FROM myClient c
+ JOIN vn.address a ON a.id = c.defaultAddressFk;
+
+ SELECT deliveryMethodFk INTO vDeliveryMethodId
+ FROM vn.agencyMode am
+ WHERE am.id = vAgencyMode;
+
+ IF vCompany IS NULL
+ THEN
+ SELECT defaultCompanyFk INTO vCompany
+ FROM orderConfig;
+ END IF;
+
+ INSERT INTO `order`
+ SET
+ customer_id = account.userGetId(),
+ date_send = vLandingDate,
+ delivery_method_id = vDeliveryMethodId,
+ agency_id = vAgencyMode,
+ address_id = vAddress,
+ source_app = 'WEB',
+ company_id = vCompany;
+
+ SET vSelf = LAST_INSERT_ID();
+
+ CALL order_checkConfig(vSelf);
+
+ COMMIT;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -16363,9 +16167,9 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `order_confirmWithUser`(IN `vOrder` INT, IN `vUserId` INT)
BEGIN
@@ -16490,7 +16294,7 @@ BEGIN
SET vShipment = IFNULL(vShipment, CURDATE());
- CALL vn.ticketCreateWithUser(
+ CALL vn.ticket_add(
vClientId,
vShipment,
vWarehouse,
@@ -16500,6 +16304,7 @@ BEGIN
NULL,
vDelivery,
vUserId,
+ TRUE,
vTicket
);
ELSE
@@ -18764,19 +18569,19 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sip_getExtension`(vUserId INT(10))
-BEGIN
-
- /*
- * Devuelve la extensión pbx del usuario
- *
- * @param vUserId Id del usuario
- *
- */
-
- SELECT extension
- FROM sip s
- WHERE s.user_id = vUserId;
-
+BEGIN
+
+ /*
+ * Devuelve la extensión pbx del usuario
+ *
+ * @param vUserId Id del usuario
+ *
+ */
+
+ SELECT extension
+ FROM sip s
+ WHERE s.user_id = vUserId;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -18988,32 +18793,32 @@ CREATE TABLE `business` (
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `postgresql`.`business_beforeUpdate`
- BEFORE UPDATE ON `business`
- FOR EACH ROW
-BEGIN
- DECLARE isOverlapping BOOL;
-
- IF !(OLD.date_start <=> NEW.date_start AND OLD.date_end <=> NEW.date_end) THEN
-
- SELECT COUNT(*) > 0 INTO isOverlapping
- FROM business b
- WHERE (util.hasDateOverlapped(
- NEW.date_start,
- IFNULL(NEW.date_end,b.date_start),
- b.date_start,
- IFNULL(b.date_end,NEW.date_start))
- OR (NEW.date_end <=> NULL AND b.date_end <=> NULL))
- AND b.business_id <> OLD.business_id
- AND client_id = OLD.client_id
- ;
-
- IF isOverlapping THEN
- CALL util.throw ('IS_OVERLAPPING');
- END IF;
-
- END IF;
-
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `postgresql`.`business_beforeUpdate`
+ BEFORE UPDATE ON `business`
+ FOR EACH ROW
+BEGIN
+ DECLARE isOverlapping BOOL;
+
+ IF !(OLD.date_start <=> NEW.date_start AND OLD.date_end <=> NEW.date_end) THEN
+
+ SELECT COUNT(*) > 0 INTO isOverlapping
+ FROM business b
+ WHERE (util.hasDateOverlapped(
+ NEW.date_start,
+ IFNULL(NEW.date_end,b.date_start),
+ b.date_start,
+ IFNULL(b.date_end,NEW.date_start))
+ OR (NEW.date_end <=> NULL AND b.date_end <=> NULL))
+ AND b.business_id <> OLD.business_id
+ AND client_id = OLD.client_id
+ ;
+
+ IF isOverlapping THEN
+ CALL util.throw ('IS_OVERLAPPING');
+ END IF;
+
+ END IF;
+
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -19066,9 +18871,9 @@ CREATE TABLE `business_labour_payroll` (
`importepactado` decimal(10,2) NOT NULL DEFAULT '0.00',
PRIMARY KEY (`business_id`),
KEY `business_labour_payroll_cod_categoria_idx` (`cod_categoria`),
- KEY `business_labour_payroll_cod_contrato` (`cod_contrato`),
+ KEY `business_labour_payroll_FK` (`cod_contrato`),
+ CONSTRAINT `business_labour_payroll_FK` FOREIGN KEY (`cod_contrato`) REFERENCES `vn`.`workerBusinessType` (`id`) ON UPDATE CASCADE,
CONSTRAINT `business_labour_payroll_cod_categoria` FOREIGN KEY (`cod_categoria`) REFERENCES `vn2008`.`payroll_categorias` (`codcategoria`) ON UPDATE CASCADE,
- CONSTRAINT `business_labour_payroll_cod_contrato` FOREIGN KEY (`cod_contrato`) REFERENCES `vn2008`.`payroll_contratos__` (`CodContrato`) ON UPDATE CASCADE,
CONSTRAINT `business_labour_payroll_fk1` FOREIGN KEY (`business_id`) REFERENCES `business` (`business_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -25109,7 +24914,7 @@ DROP TABLE IF EXISTS `versionLog`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `versionLog` (
- `code` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `code` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`number` char(11) COLLATE utf8_unicode_ci NOT NULL,
`file` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`user` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
@@ -26130,20 +25935,20 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `slowLog_prune`()
-BEGIN
-/**
- * Prunes MySQL slow query log table deleting all records older than one week.
- */
- DECLARE vSlowQueryLog INT DEFAULT @@slow_query_log;
-
- SET GLOBAL slow_query_log = 'OFF';
- RENAME TABLE `mysql`.`slow_log` TO `mysql`.`slow_log_temp`;
-
- DELETE FROM `mysql`.`slow_log_temp`
- WHERE start_time < TIMESTAMPADD(WEEK, -1, NOW());
-
- RENAME TABLE `mysql`.`slow_log_temp` TO `mysql`.`slow_log`;
- SET GLOBAL slow_query_log = vSlowQueryLog;
+BEGIN
+/**
+ * Prunes MySQL slow query log table deleting all records older than one week.
+ */
+ DECLARE vSlowQueryLog INT DEFAULT @@slow_query_log;
+
+ SET GLOBAL slow_query_log = 'OFF';
+ RENAME TABLE `mysql`.`slow_log` TO `mysql`.`slow_log_temp`;
+
+ DELETE FROM `mysql`.`slow_log_temp`
+ WHERE start_time < TIMESTAMPADD(WEEK, -1, NOW());
+
+ RENAME TABLE `mysql`.`slow_log_temp` TO `mysql`.`slow_log`;
+ SET GLOBAL slow_query_log = vSlowQueryLog;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -26668,6 +26473,8 @@ CREATE TABLE `addressFilter` (
`isVNHSupplier` tinyint(1) DEFAULT '0' COMMENT 'corresponde al campo edi.VMPSettings.isVNHSupplier',
`isEarlyBird` tinyint(1) DEFAULT '0' COMMENT 'corresponde al campo edi.marketPlace.isEarlybird',
`warehouseFk` smallint(5) unsigned DEFAULT NULL,
+ `beforeDated` date DEFAULT NULL,
+ `afterDated` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `addressFilter_FK` (`provinceFk`),
KEY `addressFilter_FK_1` (`countryFk`),
@@ -26730,18 +26537,17 @@ CREATE TABLE `agency` (
`isOwn` tinyint(1) NOT NULL DEFAULT '0',
`labelZone` tinyint(4) NOT NULL DEFAULT '0',
`workCenterFk` int(11) DEFAULT NULL,
- `supplierFk` int(11) DEFAULT NULL,
+ `supplierFk__` int(11) DEFAULT NULL,
`isAnyVolumeAllowed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Permite vender productos que tengan vn.itemType.IsUnconventionalSize = TRUE',
PRIMARY KEY (`id`),
KEY `warehouse_id` (`warehouseFk`),
KEY `Id_Banco` (`bankFk`),
KEY `agencias_alias_idx` (`warehouseAliasFk`),
KEY `agency_ibfk_3_idx` (`workCenterFk`),
- KEY `agency_ibfk_4_idx` (`supplierFk`),
+ KEY `agency_ibfk_4_idx` (`supplierFk__`),
CONSTRAINT `agency_ibfk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
CONSTRAINT `agency_ibfk_2` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `agency_ibfk_3` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `agency_ibfk_4` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
+ CONSTRAINT `agency_ibfk_3` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
@@ -26838,23 +26644,38 @@ SET character_set_client = utf8;
SET character_set_client = @saved_cs_client;
--
--- Table structure for table `agencyTerm`
+-- Temporary table structure for view `agencyTerm`
--
DROP TABLE IF EXISTS `agencyTerm`;
+/*!50001 DROP VIEW IF EXISTS `agencyTerm`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE TABLE `agencyTerm` (
+ `agencyFk` tinyint NOT NULL,
+ `minimumPackages` tinyint NOT NULL,
+ `kmPrice` tinyint NOT NULL,
+ `packagePrice` tinyint NOT NULL,
+ `routePrice` tinyint NOT NULL,
+ `minimumKm` tinyint NOT NULL,
+ `minimumM3` tinyint NOT NULL,
+ `m3Price` tinyint NOT NULL
+) ENGINE=MyISAM */;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `agencyTermConfig`
+--
+
+DROP TABLE IF EXISTS `agencyTermConfig`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `agencyTerm` (
- `agencyFk` smallint(5) unsigned NOT NULL,
- `minimumPackages` int(11) NOT NULL DEFAULT '0' COMMENT 'numero minimo de bultos',
- `kmPrice` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'precio extra por km',
- `packagePrice` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'precio extra por bulto',
- `routePrice` decimal(10,2) DEFAULT NULL COMMENT 'precio fijo por ruta',
- `minimumKm` int(11) NOT NULL DEFAULT '0',
- `minimumM3` decimal(10,2) NOT NULL DEFAULT '0.00',
- `m3Price` decimal(10,2) NOT NULL DEFAULT '0.00',
- PRIMARY KEY (`agencyFk`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+CREATE TABLE `agencyTermConfig` (
+ `expenceFk` varchar(10) DEFAULT NULL,
+ `vatAccountSupported` varchar(15) DEFAULT NULL,
+ `vatPercentage` decimal(28,10) DEFAULT NULL,
+ `transaction` varchar(50) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -26927,11 +26748,9 @@ CREATE TABLE `autoRadioConfig` (
`id` int(11) NOT NULL,
`password` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`user` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `port` int(11) DEFAULT NULL,
`url` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL,
- `login` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`client` int(32) DEFAULT NULL,
- `center` int(32) DEFAULT NULL,
+ `center` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -27463,15 +27282,15 @@ CREATE TABLE `budgetNotes` (
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`$manager`@`%`*/ /*!50003 TRIGGER budgetNotes_BeforeInsert
-BEFORE INSERT
-ON budgetNotes FOR EACH ROW
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`budgetNotes_BeforeInsert`
+ BEFORE INSERT ON `budgetNotes`
+ FOR EACH ROW
BEGIN
IF ISNULL(NEW.userFk) THEN
@@ -27598,59 +27417,71 @@ CREATE TABLE `buy` (
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeInsert`
- BEFORE INSERT ON `buy`
- FOR EACH ROW
-trig: BEGIN
- DECLARE vWarehouse INT;
- DECLARE vLanding DATE;
- DECLARE vGrouping INT;
- DECLARE vGroupingMode TINYINT;
- DECLARE vGenericFk INT;
-
- IF @isModeInventory THEN
- LEAVE trig;
- END IF;
-
- CALL buy_checkGrouping(NEW.`grouping`);
-
- SELECT t.warehouseInFk, t.landed INTO vWarehouse, vLanding
- FROM entry e
- JOIN travel t ON t.id = e.travelFk
- WHERE e.id = NEW.entryFk;
-
- SELECT b.`grouping`, b.groupingMode INTO vGrouping, vGroupingMode
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- WHERE t.landed <= vLanding
- AND b.itemFk = NEW.itemFk
- AND !b.isIgnored
- ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC, b.id DESC
- LIMIT 1;
-
- IF NEW.`grouping` IS NULL THEN
- SET NEW.`grouping` = vGrouping;
- END IF;
-
- IF NEW.groupingMode IS NULL THEN
- SET NEW.groupingMode = vGroupingMode;
- END IF;
-
- -- Generics
-
- SELECT i.genericFk INTO vGenericFk
- FROM vn.item i
- WHERE i.id = NEW.itemFk;
-
- IF vGenericFk THEN
-
- SET NEW.itemOriginalFk = NEW.itemFk;
-
- SET NEW.itemFk = vGenericFk;
-
- END IF;
-
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeInsert`
+ BEFORE INSERT ON `buy`
+ FOR EACH ROW
+trig: BEGIN
+ DECLARE vWarehouse INT;
+ DECLARE vLanding DATE;
+ DECLARE vGrouping INT;
+ DECLARE vGroupingMode TINYINT;
+ DECLARE vGenericFk INT;
+ DECLARE vGenericInDate BOOL;
+
+ IF @isModeInventory THEN
+ LEAVE trig;
+ END IF;
+
+ CALL buy_checkGrouping(NEW.`grouping`);
+
+ SELECT t.warehouseInFk, t.landed INTO vWarehouse, vLanding
+ FROM entry e
+ JOIN travel t ON t.id = e.travelFk
+ WHERE e.id = NEW.entryFk;
+
+ SELECT b.`grouping`, b.groupingMode INTO vGrouping, vGroupingMode
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel t ON t.id = e.travelFk
+ WHERE t.landed <= vLanding
+ AND b.itemFk = NEW.itemFk
+ AND !b.isIgnored
+ ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC, b.id DESC
+ LIMIT 1;
+
+ IF NEW.`grouping` IS NULL THEN
+ SET NEW.`grouping` = vGrouping;
+ END IF;
+
+ IF NEW.groupingMode IS NULL THEN
+ SET NEW.groupingMode = vGroupingMode;
+ END IF;
+
+ -- Generics
+
+ SELECT i.genericFk INTO vGenericFk
+ FROM vn.item i
+ WHERE i.id = NEW.itemFk;
+
+ IF vGenericFk THEN
+
+ SELECT COUNT(*) INTO vGenericInDate
+ FROM vn.genericAllocation ga
+ JOIN vn.entry e ON e.id = NEW.entryFk
+ JOIN vn.travel tr on tr.id = e.travelFk
+ WHERE ga.itemFk = vGenericFk
+ AND tr.landed BETWEEN ga.startDated AND ga.endDated;
+
+ IF vGenericInDate THEN
+
+ SET NEW.itemOriginalFk = NEW.itemFk;
+
+ SET NEW.itemFk = vGenericFk;
+
+ END IF;
+
+ END IF;
+
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -27692,37 +27523,47 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeUpdate`
- BEFORE UPDATE ON `buy`
- FOR EACH ROW
-trig:BEGIN
-
- DECLARE vGenericFk INT;
-
- IF @isTriggerDisabled THEN
-
- LEAVE trig;
-
- END IF;
-
- IF !(NEW.`grouping` <=> OLD.`grouping`) THEN
- CALL buy_checkGrouping(NEW.`grouping`);
- END IF;
-
- -- Generics
-
- SELECT i.genericFk INTO vGenericFk
- FROM vn.item i
- WHERE i.id = NEW.itemFk;
-
- IF vGenericFk THEN
-
- SET NEW.itemOriginalFk = NEW.itemFk;
-
- SET NEW.itemFk = vGenericFk;
-
- END IF;
-
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeUpdate`
+ BEFORE UPDATE ON `buy`
+ FOR EACH ROW
+trig:BEGIN
+ DECLARE vGenericFk INT;
+ DECLARE vGenericInDate BOOL;
+
+ IF @isTriggerDisabled THEN
+
+ LEAVE trig;
+
+ END IF;
+
+ IF !(NEW.`grouping` <=> OLD.`grouping`) THEN
+ CALL buy_checkGrouping(NEW.`grouping`);
+ END IF;
+
+ -- Generics
+
+ SELECT i.genericFk INTO vGenericFk
+ FROM vn.item i
+ WHERE i.id = NEW.itemFk;
+
+ IF vGenericFk THEN
+
+ SELECT COUNT(*) INTO vGenericInDate
+ FROM vn.genericAllocation ga
+ JOIN vn.entry e ON e.id = NEW.entryFk
+ JOIN vn.travel tr on tr.id = e.travelFk
+ WHERE ga.itemFk = vGenericFk
+ AND tr.landed BETWEEN ga.startDated AND ga.endDated;
+
+ IF vGenericInDate THEN
+
+ SET NEW.itemOriginalFk = NEW.itemFk;
+
+ SET NEW.itemFk = vGenericFk;
+
+ END IF;
+
+ END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -27746,6 +27587,8 @@ trig: BEGIN
DECLARE vBuyerFk INT;
DECLARE vIsBuyerToBeEmailed BOOL;
DECLARE vItemName VARCHAR(50);
+ DECLARE vIsInventory BOOL;
+ DECLARE vEmail VARCHAR(255);
IF !(NEW.id <=> OLD.id)
OR !(NEW.entryFk <=> OLD.entryFk)
@@ -27797,7 +27640,34 @@ trig: BEGIN
'Este email se ha generado automáticamente'
);
END IF;
+ END IF;
+
+ SELECT e.isInventory INTO vIsInventory
+ FROM entry e
+ WHERE e.id = NEW.entryFk;
+
+ SELECT e.mailToNotify INTO vEmail
+ FROM entryConfig e
+ LIMIT 1;
+
+ IF vIsInventory AND
+ (!(NEW.quantity <=> OLD.quantity)
+ OR !(NEW.price1<=>OLD.price1)
+ OR !(NEW.price2<=>OLD.price2)
+ OR !(NEW.price3<=>OLD.price3)) THEN
+
+ CALL mail_insert(
+ vEmail,
+ NULL,
+ CONCAT('Se ha modificado la entrada ', NEW.entryFk ,' del Artículo ', NEW.itemFk, ' siendo inventario'),
+ CONCAT(
+ 'Antes: Cantidad: ', OLD.quantity, ' Precio1: ', OLD.price1, ' Precio2: ', OLD.price2, ' Precio3: ', OLD.price3,
+ '
',
+ 'Despues: Cantidad: ', NEW.quantity, ' Precio1: ', NEW.price1, ' Precio2: ', NEW.price2, ' Precio3: ', NEW.price3
+ )
+ );
END IF;
+
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -28050,6 +27920,7 @@ CREATE TABLE `claim` (
`created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`ticketFk` int(11) DEFAULT NULL,
`hasToPickUp` tinyint(1) NOT NULL,
+ `packages` smallint(10) unsigned DEFAULT '0' COMMENT 'packages received by the client',
PRIMARY KEY (`id`),
KEY `cl_dep_id` (`claimDepartmentFk__`),
KEY `cl_est_id` (`claimStateFk`),
@@ -28113,6 +27984,20 @@ DELIMITER ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
+--
+-- Table structure for table `claimConfig`
+--
+
+DROP TABLE IF EXISTS `claimConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `claimConfig` (
+ `id` int(11) NOT NULL,
+ `pickupContact` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
--
-- Table structure for table `claimDestination`
--
@@ -28341,6 +28226,7 @@ CREATE TABLE `claimState` (
`description` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`roleFk` int(10) unsigned NOT NULL DEFAULT '1',
`priority` int(11) NOT NULL DEFAULT '1',
+ `hasToNotify` tinyint(4) DEFAULT '0',
PRIMARY KEY (`id`),
KEY `roleFgn_idx` (`roleFk`),
CONSTRAINT `roleFgn` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE
@@ -28736,6 +28622,46 @@ CREATE TABLE `clientDms` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
+--
+-- Table structure for table `clientItemCategory`
+--
+
+DROP TABLE IF EXISTS `clientItemCategory`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `clientItemCategory` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `clientFk` int(11) NOT NULL,
+ `itemCategoryFk` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `clientItemCategory_FK` (`clientFk`),
+ KEY `clientItemCategory_FK_1` (`itemCategoryFk`),
+ CONSTRAINT `clientItemCategory_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `clientItemCategory_FK_1` FOREIGN KEY (`itemCategoryFk`) REFERENCES `itemCategory` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `clientItemType`
+--
+
+DROP TABLE IF EXISTS `clientItemType`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `clientItemType` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `clientFk` int(11) NOT NULL,
+ `itemTypeFk` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `isAllowed` tinyint(1) DEFAULT '0',
+ PRIMARY KEY (`id`),
+ KEY `clientItemType_FK` (`clientFk`),
+ KEY `clientItemType_FK_1` (`itemTypeFk`),
+ CONSTRAINT `clientItemType_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `clientItemType_FK_1` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`code`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='son familias de productos que se quieren sustraer a la oferta del cliente';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
--
-- Table structure for table `clientLog`
--
@@ -29038,6 +28964,7 @@ CREATE TABLE `cmr` (
`merchandiseDetail` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`state` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`landed` datetime DEFAULT NULL COMMENT 'Hora de llegada a destino',
+ `ead` datetime DEFAULT NULL COMMENT 'Estimated Arriving Date',
PRIMARY KEY (`id`),
KEY `cmr_fk1_idx` (`ticketFk`),
KEY `cmr_fk2_idx` (`companyFk`),
@@ -29100,7 +29027,8 @@ DROP TABLE IF EXISTS `cmrConfig`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `cmrConfig` (
- `dayOfMonth` int(11) DEFAULT NULL
+ `dayOfMonth` int(11) DEFAULT NULL,
+ `landingDays` tinyint(4) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -29205,39 +29133,39 @@ CREATE TABLE `collection` (
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collection_BEFORE_UPDATE`
- BEFORE UPDATE ON `collection`
- FOR EACH ROW
-BEGIN
-
- DECLARE vStateFk INT;
- DECLARE vTotalLines INT;
- DECLARE vPickedLines INT;
-
- IF NEW.saleTotalCount <= NEW.salePickedCount
- AND (NEW.saleTotalCount != OLD.saleTotalCount
- OR NEW.salePickedCount != OLD.salePickedCount)
- THEN
-
- SELECT id INTO vStateFk
- FROM vn.state
- WHERE code = 'PREPARED';
-
- SET NEW.stateFk = vStateFk;
-
- END IF;
-
- IF NEW.saleTotalCount > NEW.salePickedCount
- AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN
-
- SELECT id INTO vStateFk
- FROM vn.state
- WHERE code = 'ON_PREPARATION';
-
- SET NEW.stateFk = vStateFk;
-
- END IF;
-
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collection_BEFORE_UPDATE`
+ BEFORE UPDATE ON `collection`
+ FOR EACH ROW
+BEGIN
+
+ DECLARE vStateFk INT;
+ DECLARE vTotalLines INT;
+ DECLARE vPickedLines INT;
+
+ IF NEW.saleTotalCount <= NEW.salePickedCount
+ AND (NEW.saleTotalCount != OLD.saleTotalCount
+ OR NEW.salePickedCount != OLD.salePickedCount)
+ THEN
+
+ SELECT id INTO vStateFk
+ FROM vn.state
+ WHERE code = 'PREPARED';
+
+ SET NEW.stateFk = vStateFk;
+
+ END IF;
+
+ IF NEW.saleTotalCount > NEW.salePickedCount
+ AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN
+
+ SELECT id INTO vStateFk
+ FROM vn.state
+ WHERE code = 'ON_PREPARATION';
+
+ SET NEW.stateFk = vStateFk;
+
+ END IF;
+
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -29826,6 +29754,7 @@ CREATE TABLE `country` (
`isUeeMember` tinyint(4) NOT NULL DEFAULT '0',
`ibanLength` tinyint(4) DEFAULT NULL,
`continentFk` tinyint(4) DEFAULT NULL,
+ `a3Code` int(11) DEFAULT NULL COMMENT 'Código país para a3',
PRIMARY KEY (`id`),
KEY `Id_Paisreal` (`politicalCountryFk`),
KEY `currency_id_fk_idx` (`currencyFk`),
@@ -30351,11 +30280,14 @@ CREATE TABLE `department` (
`hasToSendMail` tinyint(1) DEFAULT '0' COMMENT 'Para el envio de mail en el procedimiento workerTimeControl_sendMail()',
`hasToCheckLogin` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Para comprobar en el login de la app',
`hasToMistake` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Indica si al departamento pueden serles puestos errores',
+ `clientFk` int(11) DEFAULT NULL COMMENT 'Cuenta de cliente que se utiliza para los compras de consumo departamental',
PRIMARY KEY (`id`),
UNIQUE KEY `name_UNIQUE` (`name`),
KEY `fk_department_Trabajadores1_idx` (`workerFk`),
KEY `dep_org_ibfk_3_idx` (`companyFk`),
KEY `lft_rgt_depth_idx` (`lft`,`rgt`,`depth`),
+ KEY `department_FK` (`clientFk`),
+ CONSTRAINT `department_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_department_Trabajadores1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -30709,31 +30641,31 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate`
- BEFORE UPDATE ON `dms`
- FOR EACH ROW
-BEGIN
- DECLARE vHardCopyNumber INT;
-
- IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL)
- OR
- (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN
-
- IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN
- SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi');
- END IF;
-
- SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber
- FROM dms
- WHERE warehouseFk = NEW.warehouseFk;
-
- SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1);
- END IF;
-
- IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN
-
- SET NEW.hasFile = 0;
- END IF;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate`
+ BEFORE UPDATE ON `dms`
+ FOR EACH ROW
+BEGIN
+ DECLARE vHardCopyNumber INT;
+
+ IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL)
+ OR
+ (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN
+
+ IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN
+ SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi');
+ END IF;
+
+ SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber
+ FROM dms
+ WHERE warehouseFk = NEW.warehouseFk;
+
+ SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1);
+ END IF;
+
+ IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN
+
+ SET NEW.hasFile = 0;
+ END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -30795,6 +30727,38 @@ CREATE TABLE `dock` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se utiliza para el panel de grafana: https://grafana.verdnatura.es/d/w9w3Uo-7z/';
/*!40101 SET character_set_client = @saved_cs_client */;
+--
+-- Table structure for table `docuware`
+--
+
+DROP TABLE IF EXISTS `docuware`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `docuware` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `code` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `fileCabinetName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `dialogName` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `find` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `docuwareConfig`
+--
+
+DROP TABLE IF EXISTS `docuwareConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `docuwareConfig` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `url` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `token` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
--
-- Table structure for table `dua`
--
@@ -31322,6 +31286,7 @@ DROP TABLE IF EXISTS `entryConfig`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `entryConfig` (
`defaultEntry` int(11) NOT NULL,
+ `mailToNotify` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`defaultEntry`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -32490,6 +32455,10 @@ CREATE TABLE `genericAllocation` (
`numFlores` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`category` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`productor` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `longName` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `size` int(11) DEFAULT NULL,
+ `startDated` date DEFAULT NULL,
+ `endDated` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `genericAllocation_FK` (`itemFk`),
KEY `genericAllocation_FK_1` (`typeFk`),
@@ -32499,6 +32468,8 @@ CREATE TABLE `genericAllocation` (
KEY `genericAllocation_numFlores_IDX` (`numFlores`) USING BTREE,
KEY `genericAllocation_category_IDX` (`category`) USING BTREE,
KEY `genericAllocation_productor_IDX` (`productor`) USING BTREE,
+ KEY `genericAllocation_longName_IDX` (`longName`) USING BTREE,
+ KEY `genericAllocation_size_IDX` (`size`) USING BTREE,
CONSTRAINT `genericAllocation_FK` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los filtros para asignar códigos genéricos a los items';
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -32702,33 +32673,35 @@ DROP TABLE IF EXISTS `host`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `host` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
`code` varchar(30) CHARACTER SET utf8 NOT NULL,
`description` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`workerFk` int(10) unsigned DEFAULT NULL,
`windowsSerial` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
`printerFk` tinyint(3) unsigned DEFAULT NULL,
- `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
- `packingSite` tinyint(3) unsigned DEFAULT NULL,
+ `itemPackingTypeFk__` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `packingSite__` tinyint(3) unsigned DEFAULT NULL,
`warehouseFk` smallint(5) unsigned DEFAULT '60',
`companyFk` smallint(5) unsigned DEFAULT '442',
`bankFk` int(11) DEFAULT '13',
`routeDaysBefore` smallint(6) DEFAULT '2',
`routeDaysAfter` smallint(6) DEFAULT '1',
`updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`code`),
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `host_UN` (`code`),
KEY `configHost_FK_3` (`companyFk`),
KEY `configHost_FK` (`printerFk`),
- KEY `configHost_FK_1` (`itemPackingTypeFk`),
+ KEY `configHost_FK_1` (`itemPackingTypeFk__`),
KEY `configHost_FK_2` (`warehouseFk`),
KEY `configHost_FK_4` (`bankFk`),
KEY `configHost_FK_5` (`workerFk`),
CONSTRAINT `configHost_FK` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `configHost_FK_1` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON UPDATE CASCADE,
+ CONSTRAINT `configHost_FK_1` FOREIGN KEY (`itemPackingTypeFk__`) REFERENCES `itemPackingType` (`code`) ON UPDATE CASCADE,
CONSTRAINT `configHost_FK_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
CONSTRAINT `configHost_FK_3` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE,
CONSTRAINT `configHost_FK_4` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE,
CONSTRAINT `configHost_FK_5` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -33303,7 +33276,7 @@ CREATE TABLE `invoiceInIntrastat` (
PRIMARY KEY (`id`),
KEY `intrastat_id` (`intrastatFk`),
KEY `invoiceInIntrastat_FK` (`invoiceInFk`),
- CONSTRAINT `invoiceInIntrastat_FK` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`),
+ CONSTRAINT `invoiceInIntrastat_FK` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE,
CONSTRAINT `invoiceInIntrastat_ibfk_1` FOREIGN KEY (`intrastatFk`) REFERENCES `intrastat` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -33838,7 +33811,7 @@ CREATE TABLE `item` (
`upToDown` decimal(10,0) unsigned NOT NULL DEFAULT '0' COMMENT 'Se muestra el precio por kilo ',
`supplyResponseFk` int(11) DEFAULT NULL,
`hasKgPrice` tinyint(1) NOT NULL DEFAULT '0',
- `sectorFk` int(11) DEFAULT '2',
+ `sectorFk` int(11) DEFAULT NULL,
`isFloramondo` tinyint(1) NOT NULL DEFAULT '0',
`isFragile` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'articulos solo para recogidas por su fragilidad',
`numberOfItemsPerCask` int(11) DEFAULT NULL COMMENT 'Campo para Floramondo',
@@ -33867,6 +33840,8 @@ CREATE TABLE `item` (
KEY `item_id12` (`quality`),
KEY `item_family` (`family`),
KEY `item_FK` (`genericFk`),
+ KEY `item_size_IDX` (`size`) USING BTREE,
+ KEY `item_size_IDX2` (`longName`) USING BTREE,
CONSTRAINT `item_FK` FOREIGN KEY (`genericFk`) REFERENCES `item` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `item_expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `expence` (`id`) ON UPDATE CASCADE,
CONSTRAINT `item_family` FOREIGN KEY (`family`) REFERENCES `itemFamily` (`code`) ON UPDATE CASCADE,
@@ -33934,26 +33909,26 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterInsert`
- AFTER INSERT ON `item`
- FOR EACH ROW
-BEGIN
-
- CALL hedera.image_ref('catalog', NEW.image);
-
- INSERT INTO vn.itemTaxCountry(itemFk, countryFk)
- SELECT NEW.id, 1;
-
- INSERT INTO vn.itemTaxCountry(itemFk, countryFk)
- SELECT NEW.id, 5;
-
- INSERT INTO vn.itemTaxCountry(itemFk, countryFk)
- SELECT NEW.id, 30;
-
- DELETE ifr.*
- FROM edi.item_free ifr
- WHERE ifr.id = NEW.id;
-
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterInsert`
+ AFTER INSERT ON `item`
+ FOR EACH ROW
+BEGIN
+
+ CALL hedera.image_ref('catalog', NEW.image);
+
+ INSERT INTO vn.itemTaxCountry(itemFk, countryFk)
+ SELECT NEW.id, 1;
+
+ INSERT INTO vn.itemTaxCountry(itemFk, countryFk)
+ SELECT NEW.id, 5;
+
+ INSERT INTO vn.itemTaxCountry(itemFk, countryFk)
+ SELECT NEW.id, 30;
+
+ DELETE ifr.*
+ FROM edi.item_free ifr
+ WHERE ifr.id = NEW.id;
+
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -34118,10 +34093,13 @@ CREATE TABLE `itemCategory` (
`icon` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`isReclining` tinyint(4) NOT NULL DEFAULT '1',
+ `departmentFk` int(11) DEFAULT NULL COMMENT 'Departamento responsable del manufacturado de esta categoria',
PRIMARY KEY (`id`),
UNIQUE KEY `reino_UNIQUE` (`name`),
KEY `itemCategory_idx3` (`merchandise`),
- KEY `itemCategoryDisplayIdx` (`display`)
+ KEY `itemCategoryDisplayIdx` (`display`),
+ KEY `itemCategory_FK` (`departmentFk`),
+ CONSTRAINT `itemCategory_FK` FOREIGN KEY (`departmentFk`) REFERENCES `department` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
@@ -34191,6 +34169,18 @@ SET character_set_client = utf8;
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
+--
+-- Table structure for table `itemConfig`
+--
+
+DROP TABLE IF EXISTS `itemConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemConfig` (
+ `isItemTagTriggerDisabled` tinyint(1) NOT NULL DEFAULT '1'
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
--
-- Table structure for table `itemConversor__`
--
@@ -34661,16 +34651,16 @@ CREATE TABLE `itemShelving` (
`itemFk` int(11) NOT NULL,
`shelvingFk` varchar(10) CHARACTER SET utf8 NOT NULL,
`shelve` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'A',
- `deep` int(11) unsigned NOT NULL DEFAULT '1',
- `quantity` int(11) NOT NULL DEFAULT '0',
+ `deep__` int(11) unsigned NOT NULL DEFAULT '1',
+ `quantity__` int(11) NOT NULL DEFAULT '0',
`visible` int(11) NOT NULL DEFAULT '0',
- `available` int(11) NOT NULL DEFAULT '0',
+ `available__` int(11) NOT NULL DEFAULT '0',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`priority` int(11) unsigned DEFAULT NULL COMMENT 'El 0 es la mínima prioridad',
`grouping` smallint(5) unsigned DEFAULT NULL,
`packing` int(11) unsigned DEFAULT NULL,
`packagingFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
- `level` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
+ `level__` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
`userFk` int(10) unsigned DEFAULT NULL,
`stars` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
@@ -34718,29 +34708,25 @@ DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_AFTER_INSERT`
AFTER INSERT ON `itemShelving`
FOR EACH ROW
-INSERT INTO vn.itemShelvingLog(itemShelvingFk,
- workerFk,
- accion,
- itemFk,
- shelvingFk,
- quantity,
- available,
- visible,
- `grouping`,
- packing,
- stars)
- VALUES( NEW.id,
- NEW.userFk,
- 'CREA REGISTRO',
- NEW.itemFk,
- NEW.shelvingFk,
- NEW.quantity,
- NEW.available,
- NEW.visible,
- NEW.`grouping`,
- NEW.packing,
- NEW.stars
- ) */;;
+INSERT INTO vn.itemShelvingLog( itemShelvingFk,
+ workerFk,
+ accion,
+ itemFk,
+ shelvingFk,
+ visible,
+ `grouping`,
+ packing,
+ stars)
+ VALUES( NEW.id,
+ NEW.userFk,
+ 'CREA REGISTRO',
+ NEW.itemFk,
+ NEW.shelvingFk,
+ NEW.visible,
+ NEW.`grouping`,
+ NEW.packing,
+ NEW.stars
+ ) */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
@@ -34778,29 +34764,25 @@ DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_AFTER_UPDATE`
AFTER UPDATE ON `itemShelving`
FOR EACH ROW
-INSERT INTO vn.itemShelvingLog(itemShelvingFk,
- workerFk,
- accion,
- itemFk,
- shelvingFk,
- quantity,
- available,
- visible,
- `grouping`,
- packing,
- stars)
- VALUES( NEW.id,
- account.userGetId(),
- 'CAMBIO',
- NEW.itemFk,
- NEW.shelvingFk,
- NEW.quantity,
- NEW.available,
- NEW.visible,
- NEW.`grouping`,
- NEW.packing,
- NEW.stars
- ) */;;
+INSERT INTO vn.itemShelvingLog( itemShelvingFk,
+ workerFk,
+ accion,
+ itemFk,
+ shelvingFk,
+ visible,
+ `grouping`,
+ packing,
+ stars)
+ VALUES( NEW.id,
+ account.userGetId(),
+ 'CAMBIO',
+ NEW.itemFk,
+ NEW.shelvingFk,
+ NEW.visible,
+ NEW.`grouping`,
+ NEW.packing,
+ NEW.stars
+ ) */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
@@ -34952,7 +34934,6 @@ SET character_set_client = utf8;
/*!50001 CREATE TABLE `itemShelvingPlacementSupplyStock` (
`itemShelvingFk` tinyint NOT NULL,
`itemFk` tinyint NOT NULL,
- `quantity` tinyint NOT NULL,
`packing` tinyint NOT NULL,
`stock` tinyint NOT NULL,
`longName` tinyint NOT NULL,
@@ -34967,30 +34948,6 @@ SET character_set_client = utf8;
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
---
--- Temporary table structure for view `itemShelvingPlacementSupplyStock__`
---
-
-DROP TABLE IF EXISTS `itemShelvingPlacementSupplyStock__`;
-/*!50001 DROP VIEW IF EXISTS `itemShelvingPlacementSupplyStock__`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE TABLE `itemShelvingPlacementSupplyStock__` (
- `itemShelvingFk` tinyint NOT NULL,
- `itemFk` tinyint NOT NULL,
- `quantity` tinyint NOT NULL,
- `packing` tinyint NOT NULL,
- `stock` tinyint NOT NULL,
- `longName` tinyint NOT NULL,
- `size` tinyint NOT NULL,
- `subName` tinyint NOT NULL,
- `shelving` tinyint NOT NULL,
- `parking` tinyint NOT NULL,
- `created` tinyint NOT NULL,
- `priority` tinyint NOT NULL
-) ENGINE=MyISAM */;
-SET character_set_client = @saved_cs_client;
-
--
-- Table structure for table `itemShelvingSale`
--
@@ -35032,30 +34989,6 @@ BEGIN
SET isPicked = TRUE
WHERE id = NEW.saleFk;
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelvingSale_AFTER_DELETE`
- AFTER DELETE ON `itemShelvingSale`
- FOR EACH ROW
-BEGIN
-
- UPDATE vn.itemShelving
- SET visible = visible + OLD.quantity
- WHERE itemShelving.id = OLD.itemShelvingFk;
-
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -35221,7 +35154,12 @@ DELIMITER ;;
FOR EACH ROW
trig: BEGIN
DECLARE vItemFk INT;
- IF @isTriggerDisabled THEN
+ DECLARE visTriggerDisabled BOOL;
+
+ SELECT isItemTagTriggerDisabled INTO visTriggerDisabled
+ FROM vn.itemConfig;
+
+ IF @isTriggerDisabled OR visTriggerDisabled THEN
LEAVE trig;
END IF;
@@ -35274,7 +35212,12 @@ DELIMITER ;;
FOR EACH ROW
trig: BEGIN
DECLARE vItemFk INT;
- IF @isTriggerDisabled THEN
+ DECLARE visTriggerDisabled BOOL;
+
+ SELECT isItemTagTriggerDisabled INTO visTriggerDisabled
+ FROM vn.itemConfig;
+
+ IF @isTriggerDisabled OR visTriggerDisabled THEN
LEAVE trig;
END IF;
@@ -35305,7 +35248,12 @@ DELIMITER ;;
FOR EACH ROW
trig: BEGIN
DECLARE vItemFk INT;
- IF @isTriggerDisabled THEN
+ DECLARE visTriggerDisabled BOOL;
+
+ SELECT isItemTagTriggerDisabled INTO visTriggerDisabled
+ FROM vn.itemConfig;
+
+ IF @isTriggerDisabled OR visTriggerDisabled THEN
LEAVE trig;
END IF;
@@ -36158,7 +36106,7 @@ CREATE TABLE `mrw` (
`shipped` date DEFAULT NULL,
`price` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -36478,19 +36426,25 @@ CREATE TABLE `packagingGifts` (
/*!40101 SET character_set_client = @saved_cs_client */;
--
--- Temporary table structure for view `packingSite`
+-- Table structure for table `packingSite`
--
DROP TABLE IF EXISTS `packingSite`;
-/*!50001 DROP VIEW IF EXISTS `packingSite`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE TABLE `packingSite` (
- `hostFk` tinyint NOT NULL,
- `printerFk` tinyint NOT NULL,
- `code` tinyint NOT NULL
-) ENGINE=MyISAM */;
-SET character_set_client = @saved_cs_client;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `packingSite` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `code` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `hostFk` int(11) NOT NULL,
+ `printerFk` tinyint(3) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `packingSite_UN` (`code`),
+ KEY `packingSite_FK_1` (`printerFk`),
+ KEY `packingSite_FK` (`hostFk`),
+ CONSTRAINT `packingSite_FK` FOREIGN KEY (`hostFk`) REFERENCES `host` (`id`),
+ CONSTRAINT `packingSite_FK_1` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`)
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `packingSiteLog`
@@ -36501,8 +36455,7 @@ DROP TABLE IF EXISTS `packingSiteLog`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `packingSiteLog` (
`id` int(11) NOT NULL AUTO_INCREMENT,
- `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
- `packingSite` tinyint(3) unsigned DEFAULT NULL,
+ `packingSiteFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`hostFk` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`workerFk` int(10) unsigned NOT NULL,
`printerModelFk` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
@@ -36512,12 +36465,12 @@ CREATE TABLE `packingSiteLog` (
PRIMARY KEY (`id`),
UNIQUE KEY `packingSiteLog_UN` (`id`),
KEY `packingSiteLog_FK` (`workerFk`),
- KEY `packingSiteLog_FK_3` (`itemPackingTypeFk`),
KEY `packingSiteLog_FK_4` (`typeErrorFk`),
KEY `packingSiteLog_FK_1` (`printerModelFk`),
+ KEY `packingSiteLog_FK_2` (`packingSiteFk`),
CONSTRAINT `packingSiteLog_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`),
CONSTRAINT `packingSiteLog_FK_1` FOREIGN KEY (`printerModelFk`) REFERENCES `printerModel` (`code`) ON UPDATE CASCADE,
- CONSTRAINT `packingSiteLog_FK_3` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON UPDATE CASCADE,
+ CONSTRAINT `packingSiteLog_FK_2` FOREIGN KEY (`packingSiteFk`) REFERENCES `packingSite` (`code`) ON UPDATE CASCADE,
CONSTRAINT `packingSiteLog_FK_4` FOREIGN KEY (`typeErrorFk`) REFERENCES `packingSiteTypeError` (`code`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -36536,25 +36489,6 @@ CREATE TABLE `packingSiteTypeError` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
---
--- Table structure for table `packingSite__`
---
-
-DROP TABLE IF EXISTS `packingSite__`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `packingSite__` (
- `code` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
- `hostFk` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
- `printerFk` tinyint(3) unsigned DEFAULT NULL,
- PRIMARY KEY (`code`),
- KEY `packingSite_FK` (`hostFk`),
- KEY `packingSite_FK_1` (`printerFk`),
- CONSTRAINT `packingSite_FK` FOREIGN KEY (`hostFk`) REFERENCES `vn2008`.`config_host__` (`config_host_id`),
- CONSTRAINT `packingSite_FK_1` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
--
-- Table structure for table `parking`
--
@@ -37454,7 +37388,6 @@ CREATE TABLE `printServerQueue` (
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`reportFk__` tinyint(3) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
- UNIQUE KEY `Id_Impresora_2` (`printerFk`,`priorityFk`,`labelReportFk`,`statusFk`,`param1`,`workerFk`,`param2`),
KEY `Id_estado` (`statusFk`),
KEY `Id_Impresora` (`printerFk`),
KEY `Id_Prioridad` (`priorityFk`),
@@ -37462,7 +37395,7 @@ CREATE TABLE `printServerQueue` (
KEY `printServerQueue_FK` (`labelReportFk`),
CONSTRAINT `printServerQueue_FK` FOREIGN KEY (`labelReportFk`) REFERENCES `labelReport` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `printServerQueue_ibfk_3` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `printServerQueue_ibfk_4` FOREIGN KEY (`printerFk`) REFERENCES `vn2008`.`Impresoras__` (`Id_Impresora`) ON UPDATE CASCADE
+ CONSTRAINT `printServerQueue_printerFk` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -37573,6 +37506,12 @@ CREATE TABLE `productionConfig` (
`rookieDays` int(11) NOT NULL DEFAULT '3' COMMENT 'dias en que se cuida con especial cuidado los pedidos de un cliente por ser nuevo o recuperado',
`notBuyingMonths` int(11) NOT NULL DEFAULT '3' COMMENT 'numero de meses que han de pasar desde su ultima compra para considerar nueva la siguiente compra',
`id` int(11) NOT NULL DEFAULT '1',
+ `isZoneClosedByExpeditionActivated` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'activa el procedimiento vn.zone_getClosed',
+ `maxNotReadyCollections` int(11) NOT NULL DEFAULT '5',
+ `minTicketsToCloseZone` int(11) DEFAULT '15' COMMENT 'mínimo numero de tickets que deben de tener expediciones para cerrar una zona',
+ `movingTicketDelRoute` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Si está activo, al cambiar la fecha de un ticket desde el F11, le quita la ruta',
+ `defaultZone` int(11) NOT NULL DEFAULT '697',
+ `defautlAgencyMode` int(11) NOT NULL DEFAULT '1328' COMMENT 'SENDING',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Recoge los parámetros que condicionan la producción';
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -37815,14 +37754,14 @@ DROP TABLE IF EXISTS `propertyNotes`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `propertyNotes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
- `propertyFk` int(10) unsigned NOT NULL,
+ `propertyFk` int(11) NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`note` text COLLATE utf8_unicode_ci NOT NULL,
`userFk` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `propertyNotes_FK_1` (`userFk`),
KEY `propertyNotes_FK` (`propertyFk`),
- CONSTRAINT `propertyNotes_FK` FOREIGN KEY (`propertyFk`) REFERENCES `account`.`user` (`id`),
+ CONSTRAINT `propertyNotes_FK` FOREIGN KEY (`propertyFk`) REFERENCES `property` (`id`),
CONSTRAINT `propertyNotes_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`)
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -37913,19 +37852,19 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterUpdate`
- AFTER UPDATE ON `province`
- FOR EACH ROW
-BEGIN
- IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN
- CALL zoneGeo_setParent(NEW.geoFk,
- (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk));
- END IF;
-
- IF !(OLD.`name` <=> NEW.`name`) THEN
- UPDATE zoneGeo SET `name` = NEW.`name`
- WHERE id = NEW.geoFk;
- END IF;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterUpdate`
+ AFTER UPDATE ON `province`
+ FOR EACH ROW
+BEGIN
+ IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN
+ CALL zoneGeo_setParent(NEW.geoFk,
+ (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk));
+ END IF;
+
+ IF !(OLD.`name` <=> NEW.`name`) THEN
+ UPDATE zoneGeo SET `name` = NEW.`name`
+ WHERE id = NEW.geoFk;
+ END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -38125,20 +38064,20 @@ CREATE TABLE `receipt` (
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeInsert`
- BEFORE INSERT ON `receipt`
- FOR EACH ROW
-BEGIN
- DECLARE vIsAutoConciliated BOOLEAN;
-
- IF NEW.isConciliate = FALSE THEN
- SELECT isAutoConciliated INTO vIsAutoConciliated
- FROM accounting a
- JOIN accountingType at2 ON at2.id = a.accountingTypeFk
- WHERE a.id = NEW.bankFk;
-
- SET NEW.isConciliate = vIsAutoConciliated;
- END IF;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeInsert`
+ BEFORE INSERT ON `receipt`
+ FOR EACH ROW
+BEGIN
+ DECLARE vIsAutoConciliated BOOLEAN;
+
+ IF NEW.isConciliate = FALSE THEN
+ SELECT isAutoConciliated INTO vIsAutoConciliated
+ FROM accounting a
+ JOIN accountingType at2 ON at2.id = a.accountingTypeFk
+ WHERE a.id = NEW.bankFk;
+
+ SET NEW.isConciliate = vIsAutoConciliated;
+ END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -38194,18 +38133,18 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate`
- AFTER UPDATE ON `receipt`
- FOR EACH ROW
-BEGIN
- IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN
- CALL mail_insert(
- 'finanzas@verdnatura.es',
- NULL,
- CONCAT('Cambios de recibos del cliente: ', NEW.clientFk),
- CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed)
- );
- END IF;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate`
+ AFTER UPDATE ON `receipt`
+ FOR EACH ROW
+BEGIN
+ IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN
+ CALL mail_insert(
+ 'finanzas@verdnatura.es',
+ NULL,
+ CONCAT('Cambios de recibos del cliente: ', NEW.clientFk),
+ CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed)
+ );
+ END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -38893,32 +38832,20 @@ BEGIN
'Este email se ha generado automáticamente' )
);
END IF;
- END IF;
-
- IF !(ABS(NEW.isPicked) <=> ABS(OLD.isPicked)) AND NEW.quantity > 0 THEN
-
- UPDATE vn.collection c
- JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk
- /*JOIN vn.item i ON i.id = NEW.itemFk
- AND (c.itemPackingTypeFk = i.itemPackingTypeFk
- OR ISNULL(c.itemPackingTypeFk))*/
- SET c.salePickedCount = c.salePickedCount + IF(NEW.isPicked != 0, 1, -1);
-
-
- END IF;
-
- IF !(NEW.quantity <=> OLD.quantity) AND (NEW.quantity = 0 OR OLD.quantity = 0) THEN
-
- UPDATE vn.collection c
- JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk
- /*JOIN vn.item i ON i.id = NEW.itemFk
- AND (c.itemPackingTypeFk = i.itemPackingTypeFk
- OR ISNULL(c.itemPackingTypeFk))*/
- SET c.saleTotalCount = c.saleTotalCount + IF(OLD.quantity = 0, 1, -1);
-
- END IF;
-
- IF !(NEW.quantity <=> OLD.quantity) THEN
+ IF (OLD.quantity > NEW.quantity) THEN
+ INSERT INTO saleComponent(saleFk, componentFk, value)
+ SELECT NEW.id, cm.id, sc.value
+ FROM saleComponent sc
+ JOIN component cd ON cd.id = sc.componentFk
+ JOIN component cm ON cm.code = 'mana'
+ WHERE saleFk = NEW.id AND cd.code = 'lastUnitsDiscount'
+ ON DUPLICATE KEY UPDATE value = sc.value + VALUES(value);
+
+ DELETE sc.*
+ FROM vn.saleComponent sc
+ JOIN component c ON c.id = sc.componentFk
+ WHERE saleFk = NEW.id AND c.code = 'lastUnitsDiscount';
+ END IF;
INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`)
SELECT r.id
FROM vn.sale s
@@ -38929,6 +38856,22 @@ BEGIN
AND r.created >= CURDATE()
GROUP BY r.id;
END IF;
+
+ IF !(ABS(NEW.isPicked) <=> ABS(OLD.isPicked)) AND NEW.quantity > 0 THEN
+
+ UPDATE vn.collection c
+ JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk
+ SET c.salePickedCount = c.salePickedCount + IF(NEW.isPicked != 0, 1, -1);
+
+ END IF;
+
+ IF !(NEW.quantity <=> OLD.quantity) AND (NEW.quantity = 0 OR OLD.quantity = 0) THEN
+
+ UPDATE vn.collection c
+ JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk
+ SET c.saleTotalCount = c.saleTotalCount + IF(OLD.quantity = 0, 1, -1);
+
+ END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -39174,8 +39117,8 @@ CREATE TABLE `saleGoal` (
`rank` smallint(6) NOT NULL,
`walletWeightFrom` int(11) NOT NULL,
`walletWeightTo` int(11) DEFAULT NULL,
- `goal` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
- `goalType` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `goal` decimal(10,2) DEFAULT NULL,
+ `goalType` smallint(6) DEFAULT NULL COMMENT 'grado',
PRIMARY KEY (`id`)
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -40447,6 +40390,7 @@ CREATE TABLE `state` (
`isOK` tinyint(4) NOT NULL DEFAULT '0',
`graphCategory` int(11) NOT NULL DEFAULT '0',
`isNotValidated` tinyint(1) DEFAULT '0' COMMENT 'Los tienen que ser validados por un comercial para prepararse',
+ `classColor` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code_UNIQUE` (`code`),
KEY `state_id3` (`semaphore`),
@@ -40470,8 +40414,8 @@ CREATE TABLE `stockBuyed` (
`creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`reserved` decimal(10,2) DEFAULT NULL,
`requested` decimal(10,2) DEFAULT NULL,
+ `description` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
- UNIQUE KEY `date_UNIQUE` (`date`,`user`),
KEY `stockBuyed_user_idx` (`user`),
CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
@@ -40627,23 +40571,23 @@ CREATE TABLE `supplierAccount` (
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER supplierAccount_afterUpdate
- AFTER UPDATE ON supplierAccount
- FOR EACH ROW
-BEGIN
- DECLARE vPayMethodHasVerified BOOL;
-
- SELECT pm.hasVerified INTO vPayMethodHasVerified
- FROM vn.supplier s
- JOIN vn.payMethod pm ON pm.id = s.payMethodFk
- WHERE s.id = OLD.supplierFk;
-
- IF OLD.iban <> NEW.iban OR OLD.bankEntityFk <> NEW.bankEntityFk AND vPayMethodHasVerified THEN
- UPDATE vn.supplier
- SET isPayMethodChecked = FALSE
- WHERE id = OLD.supplierFk;
- END IF;
-
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER supplierAccount_afterUpdate
+ AFTER UPDATE ON supplierAccount
+ FOR EACH ROW
+BEGIN
+ DECLARE vPayMethodHasVerified BOOL;
+
+ SELECT pm.hasVerified INTO vPayMethodHasVerified
+ FROM vn.supplier s
+ JOIN vn.payMethod pm ON pm.id = s.payMethodFk
+ WHERE s.id = OLD.supplierFk;
+
+ IF OLD.iban <> NEW.iban OR OLD.bankEntityFk <> NEW.bankEntityFk AND vPayMethodHasVerified THEN
+ UPDATE vn.supplier
+ SET isPayMethodChecked = FALSE
+ WHERE id = OLD.supplierFk;
+ END IF;
+
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -40688,6 +40632,30 @@ CREATE TABLE `supplierAddress` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
+--
+-- Table structure for table `supplierAgencyTerm`
+--
+
+DROP TABLE IF EXISTS `supplierAgencyTerm`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `supplierAgencyTerm` (
+ `agencyFk` smallint(5) unsigned NOT NULL,
+ `supplierFk` int(11) DEFAULT NULL,
+ `minimumPackages` int(11) NOT NULL DEFAULT '0' COMMENT 'numero minimo de bultos',
+ `kmPrice` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'precio extra por km',
+ `packagePrice` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'precio extra por bulto',
+ `routePrice` decimal(10,2) DEFAULT NULL COMMENT 'precio fijo por ruta',
+ `minimumKm` int(11) NOT NULL DEFAULT '0',
+ `minimumM3` decimal(10,2) NOT NULL DEFAULT '0.00',
+ `m3Price` decimal(10,2) NOT NULL DEFAULT '0.00',
+ PRIMARY KEY (`agencyFk`),
+ KEY `agencyTerm_FK_1` (`supplierFk`),
+ CONSTRAINT `agencyTerm_FK` FOREIGN KEY (`agencyFk`) REFERENCES `agency` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `agencyTerm_FK_1` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
--
-- Table structure for table `supplierContact`
--
@@ -41360,31 +41328,31 @@ CREATE TABLE `ticketCollection` (
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ticketCollection_afterDelete
-AFTER DELETE
-ON ticketCollection FOR EACH ROW
-BEGIN
-
- DECLARE vSalesRemaining INT;
-
- SELECT count(*) INTO vSalesRemaining
- FROM vn.ticketCollection tc
- JOIN sale s ON s.ticketFk = tc.ticketFk
- WHERE collectionFk = OLD.collectionFk
- AND tc.id != OLD.id;
-
- IF NOT vSalesRemaining THEN
-
- DELETE FROM vn.collection WHERE id = OLD.collectionFk;
-
- ELSE
-
- UPDATE vn.collection
- SET saleTotalCount = vSalesRemaining
- WHERE id = OLD.collectionFk;
-
- END IF;
-
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ticketCollection_afterDelete
+AFTER DELETE
+ON ticketCollection FOR EACH ROW
+BEGIN
+
+ DECLARE vSalesRemaining INT;
+
+ SELECT count(*) INTO vSalesRemaining
+ FROM vn.ticketCollection tc
+ JOIN sale s ON s.ticketFk = tc.ticketFk
+ WHERE collectionFk = OLD.collectionFk
+ AND tc.id != OLD.id;
+
+ IF NOT vSalesRemaining THEN
+
+ DELETE FROM vn.collection WHERE id = OLD.collectionFk;
+
+ ELSE
+
+ UPDATE vn.collection
+ SET saleTotalCount = vSalesRemaining
+ WHERE id = OLD.collectionFk;
+
+ END IF;
+
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -41864,6 +41832,89 @@ CREATE TABLE `ticketRecalc` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue of changed tickets to recalc its total';
/*!40101 SET character_set_client = @saved_cs_client */;
+--
+-- Table structure for table `ticketRefund`
+--
+
+DROP TABLE IF EXISTS `ticketRefund`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ticketRefund` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `refundTicketFk` int(11) NOT NULL,
+ `originalTicketFk` int(11) NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `ticketRefund_FK` (`refundTicketFk`),
+ KEY `ticketRefund_FK_1` (`originalTicketFk`),
+ CONSTRAINT `ticketRefund_FK` FOREIGN KEY (`refundTicketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `ticketRefund_FK_1` FOREIGN KEY (`originalTicketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!50003 SET character_set_results = utf8 */ ;
+/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeInsert`
+ BEFORE INSERT ON `ticketRefund`
+ FOR EACH ROW
+BEGIN
+ DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE;
+
+ IF NEW.refundTicketFk = NEW.originalTicketFk THEN
+ CALL util.throw('Original ticket and refund ticket has same id');
+ END IF;
+
+ SELECT COUNT(*) INTO vAlreadyExists
+ FROM ticketRefund
+ WHERE refundTicketFk = NEW.originalTicketFk;
+
+ IF vAlreadyExists > 0 THEN
+ CALL util.throw('This ticket is already a refund');
+ END IF;
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!50003 SET character_set_results = utf8 */ ;
+/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeUpdate`
+ BEFORE UPDATE ON `ticketRefund`
+ FOR EACH ROW
+BEGIN
+ DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE;
+
+ IF NEW.refundTicketFk = NEW.originalTicketFk THEN
+ CALL util.throw('Original ticket and refund ticket has same id');
+ END IF;
+
+ SELECT COUNT(*) INTO vAlreadyExists
+ FROM ticketRefund
+ WHERE refundTicketFk = NEW.originalTicketFk;
+
+ IF vAlreadyExists > 0 THEN
+ CALL util.throw('This ticket is already a refund');
+ END IF;
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+
--
-- Table structure for table `ticketRequest`
--
@@ -42805,7 +42856,7 @@ CREATE TABLE `travelThermograph` (
`created` date NOT NULL,
`warehouseFk` smallint(6) unsigned NOT NULL,
`travelFk` int(10) unsigned DEFAULT NULL,
- `temperature` enum('COOL','WARM','DRY') COLLATE utf8_unicode_ci DEFAULT NULL,
+ `temperature__` enum('COOL','WARM','DRY') COLLATE utf8_unicode_ci DEFAULT NULL,
`result` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`dmsFk` int(11) DEFAULT NULL,
`temperatureFk` varchar(10) CHARACTER SET utf8 DEFAULT 'cool' COMMENT 'En la versión de Agosto de Salix se empezará a usar este campo y se actualizaran los anteriores mirando temperature.',
@@ -42822,30 +42873,6 @@ CREATE TABLE `travelThermograph` (
CONSTRAINT `travelThermographWarehouseFgn` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registra cada termografo que se ha introducido en cada travel';
/*!40101 SET character_set_client = @saved_cs_client */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travelThermograph_beforeInsert`
- BEFORE INSERT ON `travelThermograph`
- FOR EACH ROW
-BEGIN
-
- IF NEW.temperature IS NULL THEN
- SET NEW.temperature = UCASE(NEW.temperatureFk);
- END IF;
-
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
--
-- Table structure for table `trolley`
@@ -42981,11 +43008,18 @@ CREATE TABLE `vehicle` (
`deliveryPointFk` int(11) DEFAULT '6' COMMENT 'Direccion para Buscaman',
`isKmTruckRate` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Computar km como camión en el cálculo de salario de reparto',
`photo` blob,
+ `chassis` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'numero de bastidor',
+ `fuelTypeFk` int(11) DEFAULT NULL,
+ `ppeFk` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `empresa_id` (`companyFk`),
KEY `provinceFk_idx` (`warehouseFk`),
KEY `vehicle_deliveryPointFk_idx` (`deliveryPointFk`),
+ KEY `vehicle_FK` (`fuelTypeFk`),
+ KEY `vehicle_FK_1` (`ppeFk`),
CONSTRAINT `provinceFk` FOREIGN KEY (`warehouseFk`) REFERENCES `province` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
+ CONSTRAINT `vehicle_FK` FOREIGN KEY (`fuelTypeFk`) REFERENCES `fuelType` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT `vehicle_FK_1` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `vehicle_deliveryPointFk` FOREIGN KEY (`deliveryPointFk`) REFERENCES `deliveryPoint` (`id`) ON UPDATE CASCADE,
CONSTRAINT `vehicle_ibfk_1` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
@@ -43071,7 +43105,7 @@ CREATE TABLE `vehicleNotes` (
KEY `vehicleNotes_FK` (`vehicleFk`),
CONSTRAINT `vehicleNotes_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`),
CONSTRAINT `vehicleNotes_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`)
-) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -43318,7 +43352,6 @@ CREATE TABLE `worker` (
`fi__` varchar(9) COLLATE utf8_unicode_ci DEFAULT NULL,
`address__` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`birthed__` date NOT NULL,
- `maritalStatus__` enum('soltero/a','casado/a') COLLATE utf8_unicode_ci NOT NULL,
`phone` varchar(9) COLLATE utf8_unicode_ci NOT NULL,
`clientFk__` int(11) DEFAULT NULL,
`userFk` int(10) unsigned DEFAULT NULL,
@@ -43329,6 +43362,11 @@ CREATE TABLE `worker` (
`isTodayRelative` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Para el F11. Calcula los problemas de visiblidad en funcion del dia actual',
`isF11Allowed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Usuario autorizado para abrir el F11',
`sectorFk` int(11) DEFAULT NULL COMMENT 'Sector que tiene asociado el trabajador.',
+ `maritalStatus` enum('S','M') COLLATE utf8_unicode_ci NOT NULL,
+ `labelerFk` tinyint(3) unsigned DEFAULT NULL,
+ `originCountryFk` mediumint(8) unsigned DEFAULT NULL COMMENT 'País de origen',
+ `educationLevelFk` smallint(6) DEFAULT NULL,
+ `SSN` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `CodigoTrabajador_UNIQUE` (`code`),
UNIQUE KEY `user` (`user__`),
@@ -43336,7 +43374,13 @@ CREATE TABLE `worker` (
UNIQUE KEY `Id_Cliente_Interno` (`clientFk__`),
KEY `sub` (`sub`),
KEY `boss_idx` (`bossFk`),
+ KEY `worker_FK` (`labelerFk`),
+ KEY `worker_FK_2` (`educationLevelFk`),
+ KEY `worker_FK_1` (`originCountryFk`),
CONSTRAINT `Clientes` FOREIGN KEY (`clientFk__`) REFERENCES `client` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `worker_FK` FOREIGN KEY (`labelerFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `worker_FK_1` FOREIGN KEY (`originCountryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `worker_FK_2` FOREIGN KEY (`educationLevelFk`) REFERENCES `educationLevel` (`id`) ON UPDATE CASCADE,
CONSTRAINT `worker_ibfk_1` FOREIGN KEY (`id`) REFERENCES `account`.`user` (`id`)
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -43384,7 +43428,7 @@ DROP TABLE IF EXISTS `workerBusinessType`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `workerBusinessType` (
- `id` int(4) NOT NULL,
+ `id` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`isFullTime` tinyint(1) NOT NULL DEFAULT '1',
`isPermanent` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Contrato fijo',
@@ -45068,16 +45112,16 @@ DELIMITER ;;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;;
/*!50003 SET @saved_time_zone = @@time_zone */ ;;
/*!50003 SET time_zone = 'SYSTEM' */ ;;
-/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `workerTimeControl_sendMail` ON SCHEDULE EVERY 1 WEEK STARTS '2020-11-25 08:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
- DECLARE vWeek,vYear INT;
-
- SELECT week,year INTO vWeek,vYear
- FROM vn.time
- WHERE dated IN (DATE_ADD(CURDATE(), INTERVAL -10 DAY), DATE_ADD(CURDATE(), INTERVAL -4 DAY))
- GROUP BY year,week
- LIMIT 1;
-
- CALL vn.workerTimeControl_sendMail(vWeek, vYear, NULL);
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `workerTimeControl_sendMail` ON SCHEDULE EVERY 1 WEEK STARTS '2020-11-25 08:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
+ DECLARE vWeek,vYear INT;
+
+ SELECT week,year INTO vWeek,vYear
+ FROM vn.time
+ WHERE dated IN (DATE_ADD(CURDATE(), INTERVAL -10 DAY), DATE_ADD(CURDATE(), INTERVAL -4 DAY))
+ GROUP BY year,week
+ LIMIT 1;
+
+ CALL vn.workerTimeControl_sendMail(vWeek, vYear, NULL);
END */ ;;
/*!50003 SET time_zone = @saved_time_zone */ ;;
/*!50003 SET sql_mode = @saved_sql_mode */ ;;
@@ -45630,57 +45674,57 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `clientGetDebt`(`vClient` INT, `vDate` DATE) RETURNS decimal(10,2)
READS SQL DATA
-BEGIN
-/**
- * Devuelve el saldo de un cliente.
- *
- * @param vClient Identificador del cliente
- * @param vDate Fecha hasta la que tener en cuenta
- * @return Saldo del cliente
- */
- DECLARE vDateEnd DATETIME;
- DECLARE vDateIni DATETIME;
- DECLARE vDebt DECIMAL(10,2);
- DECLARE vHasDebt BOOLEAN;
-
- SELECT COUNT(*) INTO vHasDebt
- FROM `client` c
- WHERE c.id = vClient AND c.typeFk = 'normal';
-
- IF NOT vHasDebt THEN
- RETURN 0;
- END IF;
-
- SET vDate = IFNULL(vDate, CURDATE());
-
- SET vDateIni = TIMESTAMPADD(MONTH, -2, CURDATE());
- SET vDateEnd = TIMESTAMP(vDate, '23:59:59');
-
- SELECT IFNULL(SUM(t.amount), 0) INTO vDebt
- FROM (
- SELECT SUM(IFNULL(totalWithVat,0)) amount
- FROM ticket
- WHERE clientFk = vClient
- AND refFk IS NULL
- AND shipped BETWEEN vDateIni AND vDateEnd
- UNION ALL
- SELECT SUM(amountPaid) amount
- FROM receipt
- WHERE clientFk = vClient
- AND payed > vDateEnd
- UNION ALL
- SELECT SUM(amount)
- FROM clientRisk
- WHERE clientFk = vClient
- UNION ALL
- SELECT CAST(-SUM(amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpvTransaction
- WHERE clientFk = vClient
- AND receiptFk IS NULL
- AND `status` = 'ok'
- ) t;
-
- RETURN vDebt;
+BEGIN
+/**
+ * Devuelve el saldo de un cliente.
+ *
+ * @param vClient Identificador del cliente
+ * @param vDate Fecha hasta la que tener en cuenta
+ * @return Saldo del cliente
+ */
+ DECLARE vDateEnd DATETIME;
+ DECLARE vDateIni DATETIME;
+ DECLARE vDebt DECIMAL(10,2);
+ DECLARE vHasDebt BOOLEAN;
+
+ SELECT COUNT(*) INTO vHasDebt
+ FROM `client` c
+ WHERE c.id = vClient AND c.typeFk = 'normal';
+
+ IF NOT vHasDebt THEN
+ RETURN 0;
+ END IF;
+
+ SET vDate = IFNULL(vDate, CURDATE());
+
+ SET vDateIni = TIMESTAMPADD(MONTH, -2, CURDATE());
+ SET vDateEnd = TIMESTAMP(vDate, '23:59:59');
+
+ SELECT IFNULL(SUM(t.amount), 0) INTO vDebt
+ FROM (
+ SELECT SUM(IFNULL(totalWithVat,0)) amount
+ FROM ticket
+ WHERE clientFk = vClient
+ AND refFk IS NULL
+ AND shipped BETWEEN vDateIni AND vDateEnd
+ UNION ALL
+ SELECT SUM(amountPaid) amount
+ FROM receipt
+ WHERE clientFk = vClient
+ AND payed > vDateEnd
+ UNION ALL
+ SELECT SUM(amount)
+ FROM clientRisk
+ WHERE clientFk = vClient
+ UNION ALL
+ SELECT CAST(-SUM(amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction
+ WHERE clientFk = vClient
+ AND receiptFk IS NULL
+ AND `status` = 'ok'
+ ) t;
+
+ RETURN vDebt;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -46105,29 +46149,29 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `collectionExpeditionLacks`(vCollectionFk INT) RETURNS varchar(100) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
-
- DECLARE vExpeditionLacks BOOL;
- DECLARE vAnswer VARCHAR(100) DEFAULT '';
-
- SELECT (COUNT(*) > 0) INTO vExpeditionLacks
- FROM vn.ticketCollection tc
- LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk
- WHERE tc.collectionFk = vCollectionFk
- AND ISNULL(e.id);
-
- IF vExpeditionLacks THEN
-
- SELECT CONCAT('Colección: ',tc.collectionFk,' Tickets: ' , GROUP_CONCAT(tc.ticketFk) ) INTO vAnswer
- FROM vn.ticketCollection tc
- LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk
- WHERE tc.collectionFk = vCollectionFk
- AND ISNULL(e.id);
-
- END IF;
-
- RETURN vAnswer;
-
+BEGIN
+
+ DECLARE vExpeditionLacks BOOL;
+ DECLARE vAnswer VARCHAR(100) DEFAULT '';
+
+ SELECT (COUNT(*) > 0) INTO vExpeditionLacks
+ FROM vn.ticketCollection tc
+ LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk
+ WHERE tc.collectionFk = vCollectionFk
+ AND ISNULL(e.id);
+
+ IF vExpeditionLacks THEN
+
+ SELECT CONCAT('Colección: ',tc.collectionFk,' Tickets: ' , GROUP_CONCAT(tc.ticketFk) ) INTO vAnswer
+ FROM vn.ticketCollection tc
+ LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk
+ WHERE tc.collectionFk = vCollectionFk
+ AND ISNULL(e.id);
+
+ END IF;
+
+ RETURN vAnswer;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -46254,79 +46298,79 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ekt_getEntry`(vEktFk INT) RETURNS int(11)
READS SQL DATA
-BEGIN
-
- /**
- * Devuelve el numero de entrada para el ekt
- *
- * @param vEktFk Identificador de edi.ekt
- */
-
- DECLARE vTravelFk INT;
- DECLARE vEntryFk INT DEFAULT 0;
- DECLARE vEntryAssignFk INT;
-
- SET vTravelFk = vn.ekt_getTravel(vEktFk);
-
- IF vTravelFk THEN
-
- SELECT ea.id INTO vEntryAssignFk
- FROM edi.ekt e
- JOIN vn.travel tr ON tr.id = vTravelFk
- JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk
- AND ea.warehouseInFk = tr.warehouseInFk
- AND ea.agencyModeFk = tr.agencyFk
- AND IFNULL(ea.sub, e.sub) <=> e.sub
- AND IFNULL(ea.kop, e.kop) <=> e.kop
- AND IFNULL(ea.pro, e.pro) <=> e.pro
- WHERE e.id = vEktFk
- ORDER BY ea.sub <=> e.sub AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
- ea.sub <=> e.sub AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
- ea.sub <=> e.sub AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC,
- ea.sub <=> e.sub AND ISNULL(ea.kop) AND ISNULL(ea.pro) DESC,
- ISNULL(ea.sub) AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
- ISNULL(ea.sub) AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
- ISNULL(ea.sub) AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC
- LIMIT 1;
-
- SELECT MAX(e.id) INTO vEntryFk
- FROM vn.entry e
- JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk
- WHERE e.travelFk = vTravelFk
- AND e.sub <=> ea.sub
- AND e.kop <=> ea.kop
- AND e.pro <=> ea.pro;
-
-
- IF IFNULL(vEntryFk,0) = 0 THEN
-
- INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, ref, pro)
- SELECT vTravelFk, ea.supplierFk, c.id, cu.id, ea.kop, ea.sub, ea.ref, ea.pro
- FROM vn.ektEntryAssign ea
- JOIN vn.company c ON c.code = 'VNL'
- JOIN vn.currency cu ON cu.code = 'EUR'
- WHERE ea.id = vEntryAssignFk;
-
- SELECT MAX(id) INTO vEntryFk
- FROM vn.entry
- WHERE travelFk = vTravelFk;
-
- END IF;
-
- UPDATE vn.ektEntryAssign
- SET entryFk = vEntryFk
- WHERE id = vEntryAssignFk;
-
- ELSE
-
- SELECT ec.defaultEntry INTO vEntryFk
- FROM vn.entryConfig ec;
-
- INSERT IGNORE INTO vn.entry(id) VALUES(vEntryFk);
-
- END IF;
-
- RETURN vEntryFk;
+BEGIN
+
+ /**
+ * Devuelve el numero de entrada para el ekt
+ *
+ * @param vEktFk Identificador de edi.ekt
+ */
+
+ DECLARE vTravelFk INT;
+ DECLARE vEntryFk INT DEFAULT 0;
+ DECLARE vEntryAssignFk INT;
+
+ SET vTravelFk = vn.ekt_getTravel(vEktFk);
+
+ IF vTravelFk THEN
+
+ SELECT ea.id INTO vEntryAssignFk
+ FROM edi.ekt e
+ JOIN vn.travel tr ON tr.id = vTravelFk
+ JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk
+ AND ea.warehouseInFk = tr.warehouseInFk
+ AND ea.agencyModeFk = tr.agencyFk
+ AND IFNULL(ea.sub, e.sub) <=> e.sub
+ AND IFNULL(ea.kop, e.kop) <=> e.kop
+ AND IFNULL(ea.pro, e.pro) <=> e.pro
+ WHERE e.id = vEktFk
+ ORDER BY ea.sub <=> e.sub AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
+ ea.sub <=> e.sub AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
+ ea.sub <=> e.sub AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC,
+ ea.sub <=> e.sub AND ISNULL(ea.kop) AND ISNULL(ea.pro) DESC,
+ ISNULL(ea.sub) AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC,
+ ISNULL(ea.sub) AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC,
+ ISNULL(ea.sub) AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC
+ LIMIT 1;
+
+ SELECT MAX(e.id) INTO vEntryFk
+ FROM vn.entry e
+ JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk
+ WHERE e.travelFk = vTravelFk
+ AND e.sub <=> ea.sub
+ AND e.kop <=> ea.kop
+ AND e.pro <=> ea.pro;
+
+
+ IF IFNULL(vEntryFk,0) = 0 THEN
+
+ INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, ref, pro)
+ SELECT vTravelFk, ea.supplierFk, c.id, cu.id, ea.kop, ea.sub, ea.ref, ea.pro
+ FROM vn.ektEntryAssign ea
+ JOIN vn.company c ON c.code = 'VNL'
+ JOIN vn.currency cu ON cu.code = 'EUR'
+ WHERE ea.id = vEntryAssignFk;
+
+ SELECT MAX(id) INTO vEntryFk
+ FROM vn.entry
+ WHERE travelFk = vTravelFk;
+
+ END IF;
+
+ UPDATE vn.ektEntryAssign
+ SET entryFk = vEntryFk
+ WHERE id = vEntryAssignFk;
+
+ ELSE
+
+ SELECT ec.defaultEntry INTO vEntryFk
+ FROM vn.entryConfig ec;
+
+ INSERT IGNORE INTO vn.entry(id) VALUES(vEntryFk);
+
+ END IF;
+
+ RETURN vEntryFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -46705,32 +46749,68 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `expedition_checkRoute`(vPalletFk INT,vExpeditionFk INT) RETURNS tinyint(1)
DETERMINISTIC
-BEGIN
-/**
-* Comprueba si las expediciones del pallet son todas
-* de la misma ruta.
-*
-* @param vExpeditionFk numero de expedition a comprobar
-* @param vPalletFk numero de pallet
-* @return vHasDistinctRoutes
-*/
- DECLARE vRouteFk INT;
- DECLARE vHasDistinctRoutes BOOL;
-
- SELECT t.routeFk INTO vRouteFk
- FROM vn.expedition e
- JOIN vn.ticket t ON e.ticketFk = t.id
- WHERE e.id = vExpeditionFk;
-
- SELECT COUNT(*) > 0 INTO vHasDistinctRoutes
- FROM vn.expeditionScan es
- JOIN vn.expedition e ON es.expeditionFk = e.id
- JOIN vn.ticket t ON e.ticketFk = t.id
- WHERE es.palletFk = vPalletFk
- AND t.routeFk <> vRouteFk;
-
- RETURN vHasDistinctRoutes;
-
+BEGIN
+/**
+* Comprueba si las expediciones del pallet son todas
+* de la misma ruta.
+*
+* @param vExpeditionFk numero de expedition a comprobar
+* @param vPalletFk numero de pallet
+* @return vHasDistinctRoutes
+*/
+ DECLARE vRouteFk INT;
+ DECLARE vHasDistinctRoutes BOOL;
+
+ SELECT t.routeFk INTO vRouteFk
+ FROM vn.expedition e
+ JOIN vn.ticket t ON e.ticketFk = t.id
+ WHERE e.id = vExpeditionFk;
+
+ SELECT COUNT(*) > 0 INTO vHasDistinctRoutes
+ FROM vn.expeditionScan es
+ JOIN vn.expedition e ON es.expeditionFk = e.id
+ JOIN vn.ticket t ON e.ticketFk = t.id
+ WHERE es.palletFk = vPalletFk
+ AND t.routeFk <> vRouteFk;
+
+ RETURN vHasDistinctRoutes;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP FUNCTION IF EXISTS `firstDayOfWeek` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` FUNCTION `firstDayOfWeek`(vYear INT, vWeek INT) RETURNS date
+ DETERMINISTIC
+BEGIN
+/**
+ * Returns the date of the first day of the week
+ *
+ * @param vYear The year
+ * @param vWeek The week number
+ * @return Date of the first day of the week
+ */
+ DECLARE vDate DATE;
+
+ SELECT dated INTO vDate
+ FROM `time`
+ WHERE `year` = vYear
+ AND `week` = vWeek
+ ORDER BY dated
+ LIMIT 1;
+
+ RETURN vDate;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -46977,30 +47057,30 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `getNextDueDate`(vDated DATE, vGapDays INT, vPayDay INT) RETURNS date
NO SQL
-BEGIN
-
- DECLARE vReturn DATE;
- DECLARE vDuaDate DATE;
- DECLARE vDuaDateDay INT;
-
- SELECT TIMESTAMPADD(DAY, vGapDays, vDated) INTO vDuaDate;
-
- IF vDuaDate = CONCAT(YEAR(vDuaDate), '-03-01') THEN
- SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate);
- ELSEIF vDuaDate = CONCAT(YEAR(vDuaDate), '-02-29') THEN
- SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate);
- END IF;
-
- IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN
- IF util.isLeapYear(YEAR(vDuaDate)) THEN
- SET vPayDay = 29;
- ELSE
- SET vPayDay = 28;
- END IF;
- END IF;
-
- SELECT DAY(vDuaDate) INTO vDuaDateDay;
- RETURN TIMESTAMPADD(MONTH, (vDuaDateDay > vPayDay), DATE_FORMAT(vDuaDate, CONCAT('%y/%m/', vPayDay)));
+BEGIN
+
+ DECLARE vReturn DATE;
+ DECLARE vDuaDate DATE;
+ DECLARE vDuaDateDay INT;
+
+ SELECT TIMESTAMPADD(DAY, vGapDays, vDated) INTO vDuaDate;
+
+ IF vDuaDate = CONCAT(YEAR(vDuaDate), '-03-01') THEN
+ SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate);
+ ELSEIF vDuaDate = CONCAT(YEAR(vDuaDate), '-02-29') THEN
+ SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate);
+ END IF;
+
+ IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN
+ IF util.isLeapYear(YEAR(vDuaDate)) THEN
+ SET vPayDay = 29;
+ ELSE
+ SET vPayDay = 28;
+ END IF;
+ END IF;
+
+ SELECT DAY(vDuaDate) INTO vDuaDateDay;
+ RETURN TIMESTAMPADD(MONTH, (vDuaDateDay > vPayDay), DATE_FORMAT(vDuaDate, CONCAT('%y/%m/', vPayDay)));
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -47768,19 +47848,19 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `isLogifloraDay`(vShipped DATE, vWarehouse INT) RETURNS tinyint(1)
DETERMINISTIC
-BEGIN
-
- DECLARE vIsLogifloraDay BOOLEAN;
-
- SELECT COUNT(*) INTO vIsLogifloraDay
- FROM edi.warehouseFloramondo wf
- JOIN vn.floramondoConfig fc
- WHERE wf.warehouseFk = vWarehouse
- AND vShipped BETWEEN DATE(TIMESTAMPADD(DAY, wf.travellingDays , fc.nextLanded))
- AND DATE(TIMESTAMPADD(DAY, wf.travellingDays + wf.dayRange , fc.nextLanded));
-
- RETURN vIsLogifloraDay;
-
+BEGIN
+
+ DECLARE vIsLogifloraDay BOOLEAN;
+
+ SELECT COUNT(*) INTO vIsLogifloraDay
+ FROM edi.warehouseFloramondo wf
+ JOIN vn.floramondoConfig fc
+ WHERE wf.warehouseFk = vWarehouse
+ AND vShipped BETWEEN DATE(TIMESTAMPADD(DAY, wf.travellingDays , fc.nextLanded))
+ AND DATE(TIMESTAMPADD(DAY, wf.travellingDays + wf.dayRange , fc.nextLanded));
+
+ RETURN vIsLogifloraDay;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48018,17 +48098,17 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `item_getFhImage`(itemFk INT) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
- DECLARE vImageUrl VARCHAR(255);
- SELECT sr.PictureReference INTO vImageUrl
- FROM vn.buy b
- JOIN edi.ekt e ON b.ektFk = e.id
- JOIN edi.supplyResponse sr ON sr.Item_ArticleCode =e.`ref`
- JOIN vn.item i ON i.id = b.itemFk
- WHERE b.itemFk = itemFk
- ORDER BY (sr.EmbalageCode = e.package) DESC
- LIMIT 1;
- RETURN vImageUrl;
+BEGIN
+ DECLARE vImageUrl VARCHAR(255);
+ SELECT sr.PictureReference INTO vImageUrl
+ FROM vn.buy b
+ JOIN edi.ekt e ON b.ektFk = e.id
+ JOIN edi.supplyResponse sr ON sr.Item_ArticleCode =e.`ref`
+ JOIN vn.item i ON i.id = b.itemFk
+ WHERE b.itemFk = itemFk
+ ORDER BY (sr.EmbalageCode = e.package) DESC
+ LIMIT 1;
+ RETURN vImageUrl;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48047,30 +48127,30 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `item_getPackage`(vItemFk INT) RETURNS varchar(50) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
-BEGIN
-
- DECLARE vDiameter INT;
- DECLARE vPackageFk VARCHAR(50);
- DECLARE vCoeficient DOUBLE DEFAULT 1.08;
-
- SELECT MAX(LEFT(value,3)) INTO vDiameter
- FROM vn.itemTag it
- JOIN vn.tag t ON t.id = it.tagFk
- WHERE it.itemFk = vItemFk
- AND t.overwrite = 'diameter';
-
- SELECT 8000 + FLOOR(vc.ccLength * vc.ccWidth / (vCoeficient * PI() * (vDiameter / 2) * (vDiameter / 2)))
- INTO vPackageFk
- FROM vn.volumeConfig vc;
-
- INSERT IGNORE INTO vn.packaging(id, width, `depth`)
- SELECT vPackageFk,
- FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)),
- FLOOR(vc.ccLength / FLOOR(vc.ccLength / vDiameter))
- FROM vn.volumeConfig vc;
-
- RETURN vPackageFk;
-
+BEGIN
+
+ DECLARE vDiameter INT;
+ DECLARE vPackageFk VARCHAR(50);
+ DECLARE vCoeficient DOUBLE DEFAULT 1.08;
+
+ SELECT MAX(LEFT(value,3)) INTO vDiameter
+ FROM vn.itemTag it
+ JOIN vn.tag t ON t.id = it.tagFk
+ WHERE it.itemFk = vItemFk
+ AND t.overwrite = 'diameter';
+
+ SELECT 8000 + FLOOR(vc.ccLength * vc.ccWidth / (vCoeficient * PI() * (vDiameter / 2) * (vDiameter / 2)))
+ INTO vPackageFk
+ FROM vn.volumeConfig vc;
+
+ INSERT IGNORE INTO vn.packaging(id, width, `depth`)
+ SELECT vPackageFk,
+ FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)),
+ FLOOR(vc.ccLength / FLOOR(vc.ccLength / vDiameter))
+ FROM vn.volumeConfig vc;
+
+ RETURN vPackageFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48116,6 +48196,42 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP FUNCTION IF EXISTS `lastDayOfWeek` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` FUNCTION `lastDayOfWeek`(vYear INT, vWeek INT) RETURNS date
+ DETERMINISTIC
+BEGIN
+/**
+ * Returns the date of the last day of the week
+ *
+ * @param vYear The year
+ * @param vWeek The week number
+ * @return Date of the first day of the week
+ */
+ DECLARE vDate DATE;
+
+ SELECT dated INTO vDate
+ FROM `time`
+ WHERE `year` = vYear
+ AND `week` = vWeek
+ ORDER BY dated DESC
+ LIMIT 1;
+
+ RETURN vDate;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `machineWorker_Worker` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -48128,23 +48244,23 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `machineWorker_Worker`(vWorkerFk VARCHAR(10)) RETURNS varchar(20) CHARSET utf8 COLLATE utf8_unicode_ci
READS SQL DATA
-BEGIN
-/**
- * Comprueba si existen registros en las últimas 12 horas del trabajador vWorkerFk y si tiene a nulo la hora outTimed (indica la hora que deja el vehículo)
- *
- * @param vWorkerFk id del trabajador
- * @return Devuelve REGISTERED/UNREGISTERED en caso de que haya registros
- */
-
- IF (SELECT COUNT(*)
- FROM machineWorker m
- WHERE m.workerFk = vWorkerFk
- AND m.inTimed >= TIMESTAMPADD(HOUR , -12,NOW()) AND ISNULL(m.outTimed))
- THEN
- RETURN "REGISTERED";
- ELSE
- RETURN "UNREGISTERED";
- END IF;
+BEGIN
+/**
+ * Comprueba si existen registros en las últimas 12 horas del trabajador vWorkerFk y si tiene a nulo la hora outTimed (indica la hora que deja el vehículo)
+ *
+ * @param vWorkerFk id del trabajador
+ * @return Devuelve REGISTERED/UNREGISTERED en caso de que haya registros
+ */
+
+ IF (SELECT COUNT(*)
+ FROM machineWorker m
+ WHERE m.workerFk = vWorkerFk
+ AND m.inTimed >= TIMESTAMPADD(HOUR , -12,NOW()) AND ISNULL(m.outTimed))
+ THEN
+ RETURN "REGISTERED";
+ ELSE
+ RETURN "UNREGISTERED";
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48163,23 +48279,23 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `machine_checkPlate`(vPlate VARCHAR(10)) RETURNS tinyint(1)
READS SQL DATA
-BEGIN
-/**
- * Comprueba si existe matrícula
- *
- * @param vPlate matrícula del vehículo
- * @return Devuelve TRUE en caso de que exista
- *
- */
-
- IF (SELECT COUNT(*)
- FROM machine m
- WHERE m.plate = vPlate
- ) THEN
- RETURN TRUE;
- ELSE
- RETURN FALSE;
- END IF;
+BEGIN
+/**
+ * Comprueba si existe matrícula
+ *
+ * @param vPlate matrícula del vehículo
+ * @return Devuelve TRUE en caso de que exista
+ *
+ */
+
+ IF (SELECT COUNT(*)
+ FROM machine m
+ WHERE m.plate = vPlate
+ ) THEN
+ RETURN TRUE;
+ ELSE
+ RETURN FALSE;
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48662,27 +48778,27 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `specie_IsForbidden`(vItemFk INT, vAddressFk INT) RETURNS tinyint(1)
READS SQL DATA
-BEGIN
-
- DECLARE vIsForbbiden BOOL;
- DECLARE vLeft INT;
-
- SELECT zg.lft INTO vLeft
- FROM vn.address a
- JOIN vn.zoneGeo zg ON zg.name = a.postalCode
- WHERE a.id = vAddressFk;
-
- SELECT sgi.isForbidden INTO vIsForbbiden
- FROM vn.specieGeoInvasive sgi
- JOIN vn.zoneGeo zg ON zg.id = sgi.zoneGeofk
- JOIN vn.itemBotanical ib ON ib.genusFk = sgi.genusFk AND sgi.specieFk IN ('sp.',ib.specieFk)
- WHERE vLeft BETWEEN zg.lft AND zg.rgt
- AND ib.itemFk = vItemFk
- ORDER BY zg.`depth` DESC
- LIMIT 1;
-
- RETURN IFNULL(vIsForbbiden, FALSE);
-
+BEGIN
+
+ DECLARE vIsForbbiden BOOL;
+ DECLARE vLeft INT;
+
+ SELECT zg.lft INTO vLeft
+ FROM vn.address a
+ JOIN vn.zoneGeo zg ON zg.name = a.postalCode
+ WHERE a.id = vAddressFk;
+
+ SELECT sgi.isForbidden INTO vIsForbbiden
+ FROM vn.specieGeoInvasive sgi
+ JOIN vn.zoneGeo zg ON zg.id = sgi.zoneGeofk
+ JOIN vn.itemBotanical ib ON ib.genusFk = sgi.genusFk AND sgi.specieFk IN ('sp.',ib.specieFk)
+ WHERE vLeft BETWEEN zg.lft AND zg.rgt
+ AND ib.itemFk = vItemFk
+ ORDER BY zg.`depth` DESC
+ LIMIT 1;
+
+ RETURN IFNULL(vIsForbbiden, FALSE);
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48786,55 +48902,55 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `testNIE`(vNIE VARCHAR(9)) RETURNS tinyint(1)
DETERMINISTIC
-BEGIN
-
- DECLARE vIndice INT;
- DECLARE vNumero VARCHAR(7);
- DECLARE vOperador VARCHAR(9);
- DECLARE vParteNumerica DECIMAL(8,0);
- DECLARE vLetraInicial VARCHAR(1);
- DECLARE vLetraFinal VARCHAR(1);
- DECLARE vLetrasFinalesPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE";
- DECLARE vLetraInicialEsIncorrecta BOOL DEFAULT FALSE;
-
- SET vLetraInicial = SUBSTR(vNIE, 1, 1);
- SET vLetraFinal = SUBSTR(vNIE, 9, 1);
- SET vNumero = SUBSTR(vNIE, 2, 7);
-
- CASE vLetraInicial
-
- WHEN 'X' THEN
-
- SET vOperador = "0";
-
- WHEN 'Y' THEN
-
- SET vOperador = "1";
-
- WHEN 'Z' THEN
-
- SET vOperador = "2";
-
- ELSE
-
- SET vLetraInicialEsIncorrecta = TRUE;
-
- END CASE;
-
- SET vOperador = CONCAT(vOperador, vNumero);
- SET vParteNumerica = CAST(vOperador AS DECIMAL(8,0));
- SET vIndice = Round(vParteNumerica Mod 23, 0) + 1;
-
- IF SUBSTR(vLetrasFinalesPosibles, vIndice, 1) = vLetraFinal AND vLetraInicialEsIncorrecta = FALSE THEN
-
- RETURN TRUE;
-
- ELSE
-
- RETURN FALSE;
-
- END IF;
-
+BEGIN
+
+ DECLARE vIndice INT;
+ DECLARE vNumero VARCHAR(7);
+ DECLARE vOperador VARCHAR(9);
+ DECLARE vParteNumerica DECIMAL(8,0);
+ DECLARE vLetraInicial VARCHAR(1);
+ DECLARE vLetraFinal VARCHAR(1);
+ DECLARE vLetrasFinalesPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE";
+ DECLARE vLetraInicialEsIncorrecta BOOL DEFAULT FALSE;
+
+ SET vLetraInicial = SUBSTR(vNIE, 1, 1);
+ SET vLetraFinal = SUBSTR(vNIE, 9, 1);
+ SET vNumero = SUBSTR(vNIE, 2, 7);
+
+ CASE vLetraInicial
+
+ WHEN 'X' THEN
+
+ SET vOperador = "0";
+
+ WHEN 'Y' THEN
+
+ SET vOperador = "1";
+
+ WHEN 'Z' THEN
+
+ SET vOperador = "2";
+
+ ELSE
+
+ SET vLetraInicialEsIncorrecta = TRUE;
+
+ END CASE;
+
+ SET vOperador = CONCAT(vOperador, vNumero);
+ SET vParteNumerica = CAST(vOperador AS DECIMAL(8,0));
+ SET vIndice = Round(vParteNumerica Mod 23, 0) + 1;
+
+ IF SUBSTR(vLetrasFinalesPosibles, vIndice, 1) = vLetraFinal AND vLetraInicialEsIncorrecta = FALSE THEN
+
+ RETURN TRUE;
+
+ ELSE
+
+ RETURN FALSE;
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48853,29 +48969,29 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `testNIF`(vNIF VARCHAR(9)) RETURNS tinyint(1)
DETERMINISTIC
-BEGIN
-
- DECLARE vIndice INT;
- DECLARE vParteNumerica DECIMAL(8,0);
- DECLARE vLetra VARCHAR(1);
- DECLARE vLetrasPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE";
-
- SET vLetra = SUBSTRING(vNIF, 9, 1);
-
- SET vParteNumerica = CAST(SUBSTRING(vNIF, 1, 8) AS DECIMAL(8,0));
-
- SET vIndice = Round(vParteNumerica MOD 23, 0) + 1;
-
- If SUBSTRING(vLetrasPosibles, vIndice, 1) = vLetra Then
-
- RETURN TRUE;
-
- ELSE
-
- RETURN FALSE;
-
- END IF;
-
+BEGIN
+
+ DECLARE vIndice INT;
+ DECLARE vParteNumerica DECIMAL(8,0);
+ DECLARE vLetra VARCHAR(1);
+ DECLARE vLetrasPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE";
+
+ SET vLetra = SUBSTRING(vNIF, 9, 1);
+
+ SET vParteNumerica = CAST(SUBSTRING(vNIF, 1, 8) AS DECIMAL(8,0));
+
+ SET vIndice = Round(vParteNumerica MOD 23, 0) + 1;
+
+ If SUBSTRING(vLetrasPosibles, vIndice, 1) = vLetra Then
+
+ RETURN TRUE;
+
+ ELSE
+
+ RETURN FALSE;
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -48937,79 +49053,79 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ticketPositionInPath`(vTicketId INT) RETURNS varchar(10) CHARSET utf8
DETERMINISTIC
-BEGIN
-
- DECLARE vRestTicketsMaxOrder INT;
- DECLARE vRestTicketsMinOrder INT;
- DECLARE vRestTicketsPacking INT;
- DECLARE vMyProductionOrder INT;
- DECLARE vPosition VARCHAR(10) DEFAULT 'MID';
- DECLARE vMyPath INT;
- DECLARE vMyWarehouse INT;
- DECLARE PACKING_ORDER INT;
- DECLARE vExpeditionsCount INT;
- DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE;
-
-SELECT `order`
- INTO PACKING_ORDER
- FROM state
- WHERE code = 'PACKING';
-
-SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0)
- INTO vMyPath, vMyWarehouse, vMyProductionOrder
- FROM ticket t
- LEFT JOIN ticketState ts on ts.ticket = t.id
- WHERE t.id = vTicketId;
-
-SELECT (ag.`name` = 'VN_VALENCIA')
- INTO vIsValenciaPath
- FROM vn2008.Rutas r
- JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
- JOIN vn2008.agency ag on ag.agency_id = a.agency_id
- WHERE r.Id_Ruta = vMyPath;
-
-IF vIsValenciaPath THEN -- Rutas Valencia
-
- SELECT COUNT(*)
- INTO vExpeditionsCount
- FROM expedition e
- JOIN ticket t ON t.id = e.ticketFk
- WHERE t.routeFk = vMyPath;
-
- SELECT MAX(ts.productionOrder), MIN(ts.productionOrder)
- INTO vRestTicketsMaxOrder, vRestTicketsMinOrder
- FROM ticket t
- LEFT JOIN ticketState ts on t.id = ts.ticket
- WHERE t.routeFk = vMyPath
- AND t.warehouseFk = vMyWarehouse
- AND t.id != vTicketid;
-
- SELECT COUNT(*)
- INTO vRestTicketsPacking
- FROM ticket t
- LEFT JOIN ticketState ts on t.id = ts.ticket
- WHERE ts.productionOrder = PACKING_ORDER
- AND t.routeFk = vMyPath
- AND t.warehouseFk = vMyWarehouse
- AND t.id != vTicketid;
-
- IF vExpeditionsCount = 1 THEN
- SET vPosition = 'FIRST';
- ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN
- SET vPosition = 'LAST';
- ELSEIF vRestTicketsPacking THEN
- SET vPosition = 'SHARED';
- ELSE
- SET vPosition = 'MID';
- END IF;
-
-ELSE
- SET vPosition = 'MID';
-
-END IF;
-
-RETURN vPosition;
-
+BEGIN
+
+ DECLARE vRestTicketsMaxOrder INT;
+ DECLARE vRestTicketsMinOrder INT;
+ DECLARE vRestTicketsPacking INT;
+ DECLARE vMyProductionOrder INT;
+ DECLARE vPosition VARCHAR(10) DEFAULT 'MID';
+ DECLARE vMyPath INT;
+ DECLARE vMyWarehouse INT;
+ DECLARE PACKING_ORDER INT;
+ DECLARE vExpeditionsCount INT;
+ DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE;
+
+SELECT `order`
+ INTO PACKING_ORDER
+ FROM state
+ WHERE code = 'PACKING';
+
+SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0)
+ INTO vMyPath, vMyWarehouse, vMyProductionOrder
+ FROM ticket t
+ LEFT JOIN ticketState ts on ts.ticket = t.id
+ WHERE t.id = vTicketId;
+
+SELECT (ag.`name` = 'VN_VALENCIA')
+ INTO vIsValenciaPath
+ FROM vn2008.Rutas r
+ JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
+ JOIN vn2008.agency ag on ag.agency_id = a.agency_id
+ WHERE r.Id_Ruta = vMyPath;
+
+IF vIsValenciaPath THEN -- Rutas Valencia
+
+ SELECT COUNT(*)
+ INTO vExpeditionsCount
+ FROM expedition e
+ JOIN ticket t ON t.id = e.ticketFk
+ WHERE t.routeFk = vMyPath;
+
+ SELECT MAX(ts.productionOrder), MIN(ts.productionOrder)
+ INTO vRestTicketsMaxOrder, vRestTicketsMinOrder
+ FROM ticket t
+ LEFT JOIN ticketState ts on t.id = ts.ticket
+ WHERE t.routeFk = vMyPath
+ AND t.warehouseFk = vMyWarehouse
+ AND t.id != vTicketid;
+
+ SELECT COUNT(*)
+ INTO vRestTicketsPacking
+ FROM ticket t
+ LEFT JOIN ticketState ts on t.id = ts.ticket
+ WHERE ts.productionOrder = PACKING_ORDER
+ AND t.routeFk = vMyPath
+ AND t.warehouseFk = vMyWarehouse
+ AND t.id != vTicketid;
+
+ IF vExpeditionsCount = 1 THEN
+ SET vPosition = 'FIRST';
+ ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN
+ SET vPosition = 'LAST';
+ ELSEIF vRestTicketsPacking THEN
+ SET vPosition = 'SHARED';
+ ELSE
+ SET vPosition = 'MID';
+ END IF;
+
+ELSE
+ SET vPosition = 'MID';
+
+END IF;
+
+RETURN vPosition;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -49151,21 +49267,21 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_CC_volume`(vTicketFk INT) RETURNS decimal(10,1)
READS SQL DATA
-BEGIN
-
- DECLARE vCC DECIMAL(10,1);
-
- SELECT sum(sv.volume * IF(i.itemPackingTypeFk = 'H', vc.dutchCompressionRate, 1)) / (p.volume / 1000000)
- INTO vCC
- FROM vn.saleVolume sv
- JOIN vn.sale s ON s.id = sv.saleFk
- JOIN vn.item i ON i.id = s.itemFk
- JOIN vn.packaging p ON p.id = 'CC'
- JOIN vn.volumeConfig vc
- WHERE sv.ticketFk = vTicketFk;
-
- RETURN vCC;
-
+BEGIN
+
+ DECLARE vCC DECIMAL(10,1);
+
+ SELECT sum(sv.volume * IF(i.itemPackingTypeFk = 'H', vc.dutchCompressionRate, 1)) / (p.volume / 1000000)
+ INTO vCC
+ FROM vn.saleVolume sv
+ JOIN vn.sale s ON s.id = sv.saleFk
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.packaging p ON p.id = 'CC'
+ JOIN vn.volumeConfig vc
+ WHERE sv.ticketFk = vTicketFk;
+
+ RETURN vCC;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -49299,21 +49415,21 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_getWeight`(vTicketFk INT) RETURNS decimal(10,3)
READS SQL DATA
-BEGIN
-/**
- * Devuelve el peso total del ticket
- *
- * @return Total peso
- */
-
- DECLARE vWeight DECIMAL(10,3);
-
- SELECT sum(weight) INTO vWeight
- FROM saleVolume
- WHERE ticketFk = vTicketFk;
-
- RETURN vWeight;
-
+BEGIN
+/**
+ * Devuelve el peso total del ticket
+ *
+ * @return Total peso
+ */
+
+ DECLARE vWeight DECIMAL(10,3);
+
+ SELECT sum(weight) INTO vWeight
+ FROM saleVolume
+ WHERE ticketFk = vTicketFk;
+
+ RETURN vWeight;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -49357,7 +49473,7 @@ BEGIN
LIMIT 1;
IF vTicket IS NULL THEN
- CALL vn.ticketCreateWithUser(
+ CALL vn.ticket_add(
vClientFk,
IFNULL(vShipped, CURDATE()),
vWarehouseFk,
@@ -49367,6 +49483,7 @@ BEGIN
NULL,
vShipped,
`account`.`myUser_getId`(),
+ TRUE,
vTicket
);
END IF;
@@ -49390,18 +49507,18 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_HasUbication`(vTicketFk INT) RETURNS tinyint(1)
READS SQL DATA
-BEGIN
-
- DECLARE hasUbication BOOL;
-
- SELECT COUNT(*) INTO hasUbication
- FROM vn.ticket t
- JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk
- WHERE rm.beachFk
- AND t.id = vTicketFk;
-
- RETURN hasUbication;
-
+BEGIN
+
+ DECLARE hasUbication BOOL;
+
+ SELECT COUNT(*) INTO hasUbication
+ FROM vn.ticket t
+ JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk
+ WHERE rm.beachFk
+ AND t.id = vTicketFk;
+
+ RETURN hasUbication;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -49817,24 +49934,24 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `workerMachinery_isRegistered`(vWorkerFk VARCHAR(10)) RETURNS tinyint(1)
READS SQL DATA
-BEGIN
-/**
- * Comprueba si existen registros en las últimas horas (maxHours de machineWorkerConfig) del trabajador vWorkerFk y si tiene a nulo la hora outTimed (indica la hora que deja el vehículo)
- *
- * @param vWorkerFk id del trabajador
- * @return Devuelve TRUE/FALSE en caso de que haya o no registros
- */
-
- IF (SELECT COUNT(*)
- FROM machineWorker m
- WHERE m.workerFk = vWorkerFk
- AND m.inTimed >= TIMESTAMPADD(HOUR , -(SELECT maxHours from machineWorkerConfig), NOW()) AND ISNULL(m.outTimed))
- THEN
- RETURN TRUE;
- ELSE
- RETURN FALSE;
- END IF;
-
+BEGIN
+/**
+ * Comprueba si existen registros en las últimas horas (maxHours de machineWorkerConfig) del trabajador vWorkerFk y si tiene a nulo la hora outTimed (indica la hora que deja el vehículo)
+ *
+ * @param vWorkerFk id del trabajador
+ * @return Devuelve TRUE/FALSE en caso de que haya o no registros
+ */
+
+ IF (SELECT COUNT(*)
+ FROM machineWorker m
+ WHERE m.workerFk = vWorkerFk
+ AND m.inTimed >= TIMESTAMPADD(HOUR , -(SELECT maxHours from machineWorkerConfig), NOW()) AND ISNULL(m.outTimed))
+ THEN
+ RETURN TRUE;
+ ELSE
+ RETURN FALSE;
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -50453,23 +50570,23 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `agencyVolume__`(vDated DATE, vAgency INT)
-BEGIN
-
- SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') AS Temp,
- CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) *
- vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.carro / 1000000 ,1) AS DECIMAL(10,2)) AS carros ,
- CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) *
- vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.espai / 1000000,1) AS DECIMAL(10,2)) AS espais
- FROM vn.buy b
- INNER JOIN vn.entry e ON e.id = b.entryFk
- INNER JOIN vn.travel tr ON tr.id = e.travelFk
- INNER JOIN vn.volumeConfig vc
- INNER JOIN vn.item i ON i.id = b.itemFk
- INNER JOIN vn.itemType it ON it.id = i.typeFk
- WHERE tr.landed = vDated
- AND tr.agencyFk IN (0, vAgency)
- GROUP BY Temp;
-
+BEGIN
+
+ SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') AS Temp,
+ CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) *
+ vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.carro / 1000000 ,1) AS DECIMAL(10,2)) AS carros ,
+ CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) *
+ vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.espai / 1000000,1) AS DECIMAL(10,2)) AS espais
+ FROM vn.buy b
+ INNER JOIN vn.entry e ON e.id = b.entryFk
+ INNER JOIN vn.travel tr ON tr.id = e.travelFk
+ INNER JOIN vn.volumeConfig vc
+ INNER JOIN vn.item i ON i.id = b.itemFk
+ INNER JOIN vn.itemType it ON it.id = i.typeFk
+ WHERE tr.landed = vDated
+ AND tr.agencyFk IN (0, vAgency)
+ GROUP BY Temp;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -50657,45 +50774,44 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `buyUltimate`(vWarehouseFk SMALLINT, vDated DATE)
-BEGIN
-/**
- * Calcula las últimas compras realizadas hasta una fecha
- *
- * @param vWarehouseFk Id del almacén
- * @param vDated Compras hasta fecha
- * @return tmp.buyUltimate
- */
- CALL cache.last_buy_refresh (FALSE);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate;
- CREATE TEMPORARY TABLE tmp.buyUltimate
- (PRIMARY KEY (itemFk, warehouseFk),
- INDEX(itemFk))
- ENGINE = MEMORY
- SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing
- FROM cache.last_buy
- WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL;
-
- CALL buyUltimateFromInterval(vWarehouseFk, CURDATE(), vDated);
-
- REPLACE INTO tmp.buyUltimate
- SELECT itemFk, buyFk, warehouseFk, landed landing
- FROM tmp.buyUltimateFromInterval
- WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
- AND landed <= vDated;
-
- INSERT IGNORE INTO tmp.buyUltimate
- SELECT itemFk, buyFk, warehouseFk, landed landing
- FROM tmp.buyUltimateFromInterval
- WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
- AND landed > vDated;
-
- DROP TEMPORARY TABLE tmp.buyUltimateFromInterval;
+BEGIN
+/**
+ * Calcula las últimas compras realizadas hasta una fecha
+ *
+ * @param vWarehouseFk Id del almacén
+ * @param vDated Compras hasta fecha
+ * @return tmp.buyUltimate
+ */
+ CALL cache.last_buy_refresh (FALSE);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate;
+ CREATE TEMPORARY TABLE tmp.buyUltimate
+ (PRIMARY KEY (itemFk, warehouseFk),
+ INDEX(itemFk))
+ ENGINE = MEMORY
+ SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing
+ FROM cache.last_buy
+ WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL;
+
+ CALL buyUltimateFromInterval(vWarehouseFk, CURDATE(), vDated);
+
+ REPLACE INTO tmp.buyUltimate
+ SELECT itemFk, buyFk, warehouseFk, landed landing
+ FROM tmp.buyUltimateFromInterval
+ WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
+ AND landed <= vDated;
+
+ INSERT IGNORE INTO tmp.buyUltimate
+ SELECT itemFk, buyFk, warehouseFk, landed landing
+ FROM tmp.buyUltimateFromInterval
+ WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
+ AND landed > vDated;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -50713,126 +50829,126 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE)
-BEGIN
-/**
- * Calcula las últimas compras realizadas
- * desde un rango de fechas.
- *
- * @param vWarehouseFk Id del almacén si es NULL se actualizan todos
- * @param vStarted Fecha inicial
- * @param vEnded Fecha fin
- * @return tmp.buyUltimateFromInterval
- */
- IF vEnded IS NULL THEN
- SET vEnded = vStarted;
- END IF;
-
- IF vEnded < vStarted THEN
- SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded);
- END IF;
-
- -- Item
-
- DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
- CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
- (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk))
- ENGINE = MEMORY
- SELECT
- b.itemFk,
- t.warehouseInFk warehouseFk,
- MULTIMAX(t.landed, b.id) buyFk,
- MAX(t.landed) landed
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- WHERE t.landed BETWEEN vStarted AND vEnded
- AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
- AND b.price2 > 0
- AND NOT b.isIgnored
- AND b.quantity > 0
- GROUP BY itemFk, warehouseInFk;
-
- INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
- SELECT
- b.itemFk,
- t.warehouseInFk warehouseFk,
- b.id buyFk,
- t.landed
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- WHERE t.landed > vEnded
- AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
- AND b.price2 > 0
- AND NOT b.isIgnored
- GROUP BY itemFk, warehouseInFk;
-
- INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
- SELECT
- b.itemFk,
- t.warehouseInFk warehouseFk,
- b.id buyFk,
- t.landed
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- WHERE t.landed BETWEEN vStarted AND vEnded
- AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
- AND b.quantity = 0
- GROUP BY itemFk, warehouseInFk;
-
-
-
- -- ItemOriginal
-
- INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
- SELECT
- b.itemFk,
- t.warehouseInFk warehouseFk,
- MULTIMAX(t.landed, b.id) buyFk,
- MAX(t.landed) landed
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- WHERE t.landed BETWEEN vStarted AND vEnded
- AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
- AND b.price2 > 0
- AND NOT b.isIgnored
- AND b.quantity > 0
- AND itemOriginalFk
- GROUP BY itemOriginalFk, warehouseInFk;
-
- INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
- SELECT
- b.itemFk,
- t.warehouseInFk warehouseFk,
- b.id buyFk,
- t.landed
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- WHERE t.landed > vEnded
- AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
- AND b.price2 > 0
- AND NOT b.isIgnored
- AND itemOriginalFk
- GROUP BY itemOriginalFk, warehouseInFk;
-
- INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
- SELECT
- b.itemFk,
- t.warehouseInFk warehouseFk,
- b.id buyFk,
- t.landed
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- WHERE t.landed BETWEEN vStarted AND vEnded
- AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
- AND b.quantity = 0
- AND itemOriginalFk
- GROUP BY itemOriginalFk, warehouseInFk;
-
+BEGIN
+/**
+ * Calcula las últimas compras realizadas
+ * desde un rango de fechas.
+ *
+ * @param vWarehouseFk Id del almacén si es NULL se actualizan todos
+ * @param vStarted Fecha inicial
+ * @param vEnded Fecha fin
+ * @return tmp.buyUltimateFromInterval
+ */
+ IF vEnded IS NULL THEN
+ SET vEnded = vStarted;
+ END IF;
+
+ IF vEnded < vStarted THEN
+ SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded);
+ END IF;
+
+ -- Item
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
+ CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
+ (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk))
+ ENGINE = MEMORY
+ SELECT
+ b.itemFk,
+ t.warehouseInFk warehouseFk,
+ MULTIMAX(t.landed, b.id) buyFk,
+ MAX(t.landed) landed
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel t ON t.id = e.travelFk
+ WHERE t.landed BETWEEN vStarted AND vEnded
+ AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
+ AND b.price2 > 0
+ AND NOT b.isIgnored
+ AND b.quantity > 0
+ GROUP BY itemFk, warehouseInFk;
+
+ INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
+ SELECT
+ b.itemFk,
+ t.warehouseInFk warehouseFk,
+ b.id buyFk,
+ t.landed
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel t ON t.id = e.travelFk
+ WHERE t.landed > vEnded
+ AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
+ AND b.price2 > 0
+ AND NOT b.isIgnored
+ GROUP BY itemFk, warehouseInFk;
+
+ INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
+ SELECT
+ b.itemFk,
+ t.warehouseInFk warehouseFk,
+ b.id buyFk,
+ t.landed
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel t ON t.id = e.travelFk
+ WHERE t.landed BETWEEN vStarted AND vEnded
+ AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
+ AND b.quantity = 0
+ GROUP BY itemFk, warehouseInFk;
+
+
+
+ -- ItemOriginal
+
+ INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
+ SELECT
+ b.itemFk,
+ t.warehouseInFk warehouseFk,
+ MULTIMAX(t.landed, b.id) buyFk,
+ MAX(t.landed) landed
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel t ON t.id = e.travelFk
+ WHERE t.landed BETWEEN vStarted AND vEnded
+ AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
+ AND b.price2 > 0
+ AND NOT b.isIgnored
+ AND b.quantity > 0
+ AND itemOriginalFk
+ GROUP BY itemOriginalFk, warehouseInFk;
+
+ INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
+ SELECT
+ b.itemFk,
+ t.warehouseInFk warehouseFk,
+ b.id buyFk,
+ t.landed
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel t ON t.id = e.travelFk
+ WHERE t.landed > vEnded
+ AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
+ AND b.price2 > 0
+ AND NOT b.isIgnored
+ AND itemOriginalFk
+ GROUP BY itemOriginalFk, warehouseInFk;
+
+ INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed)
+ SELECT
+ b.itemFk,
+ t.warehouseInFk warehouseFk,
+ b.id buyFk,
+ t.landed
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel t ON t.id = e.travelFk
+ WHERE t.landed BETWEEN vStarted AND vEnded
+ AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
+ AND b.quantity = 0
+ AND itemOriginalFk
+ GROUP BY itemOriginalFk, warehouseInFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -50901,67 +51017,67 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_afterUpsert`(vSelf INT)
-BEGIN
-/**
- * Triggered actions when a buy is updated or inserted.
- *
- * @param vSelf The buy reference
- */
- DECLARE vEntryFk INT;
- DECLARE vItemFk INT;
- DECLARE vPackingOut DECIMAL(10,2);
- DECLARE vWarehouse INT;
- DECLARE vStandardFlowerBox INT;
- DECLARE vWarehouseOut INT;
- DECLARE vIsMerchandise BOOL;
- DECLARE vIsFeedStock BOOL;
-
- SELECT b.entryFk, b.itemFk, i.packingOut, ic.merchandise, vc.standardFlowerBox
- INTO vEntryFk, vItemFk, vPackingOut, vIsMerchandise, vStandardFlowerBox
- FROM buy b
- LEFT JOIN item i ON i.id = b.itemFk
- LEFT JOIN itemType it ON it.id = i.typeFk
- LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
- LEFT JOIN packaging p ON p.id = b.packageFk AND NOT p.isBox
- JOIN volumeConfig vc ON TRUE
- WHERE b.id = vSelf;
-
- SELECT t.warehouseInFk, t.warehouseOutFk
- INTO vWarehouse, vWarehouseOut
- FROM entry e
- JOIN travel t ON t.id = e.travelFk
- WHERE e.id = vEntryFk;
-
- IF vIsMerchandise THEN
-
- REPLACE itemCost SET
- itemFk = vItemFk,
- warehouseFk = vWarehouse,
- cm3 = buy_getUnitVolume(vSelf),
- cm3Delivery = IFNULL((vStandardFlowerBox * 1000) / vPackingOut, buy_getUnitVolume(vSelf));
-
- UPDATE vn.itemCost ic
- JOIN cache.last_buy lb ON lb.item_id = ic.itemFk AND lb.warehouse_id = ic.warehouseFk
- JOIN vn.buy b ON b.id = lb.buy_id
- SET ic.grams = b.weight * 1000 / b.packing
- WHERE ic.itemFk = vItemFk AND
- ic.warehouseFk = vWarehouse;
-
- END IF;
-
- SELECT isFeedStock INTO vIsFeedStock
- FROM warehouse WHERE id = vWarehouseOut AND id <> 13;
-
- IF vIsFeedStock THEN
- INSERT IGNORE INTO producer(`name`)
- SELECT es.company_name
- FROM buy b
- JOIN edi.ekt be ON be.id = b.ektFk
- JOIN edi.supplier es ON es.supplier_id = be.pro
- WHERE b.id = vSelf;
-
- END IF;
-
+BEGIN
+/**
+ * Triggered actions when a buy is updated or inserted.
+ *
+ * @param vSelf The buy reference
+ */
+ DECLARE vEntryFk INT;
+ DECLARE vItemFk INT;
+ DECLARE vPackingOut DECIMAL(10,2);
+ DECLARE vWarehouse INT;
+ DECLARE vStandardFlowerBox INT;
+ DECLARE vWarehouseOut INT;
+ DECLARE vIsMerchandise BOOL;
+ DECLARE vIsFeedStock BOOL;
+
+ SELECT b.entryFk, b.itemFk, i.packingOut, ic.merchandise, vc.standardFlowerBox
+ INTO vEntryFk, vItemFk, vPackingOut, vIsMerchandise, vStandardFlowerBox
+ FROM buy b
+ LEFT JOIN item i ON i.id = b.itemFk
+ LEFT JOIN itemType it ON it.id = i.typeFk
+ LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
+ LEFT JOIN packaging p ON p.id = b.packageFk AND NOT p.isBox
+ JOIN volumeConfig vc ON TRUE
+ WHERE b.id = vSelf;
+
+ SELECT t.warehouseInFk, t.warehouseOutFk
+ INTO vWarehouse, vWarehouseOut
+ FROM entry e
+ JOIN travel t ON t.id = e.travelFk
+ WHERE e.id = vEntryFk;
+
+ IF vIsMerchandise THEN
+
+ REPLACE itemCost SET
+ itemFk = vItemFk,
+ warehouseFk = vWarehouse,
+ cm3 = buy_getUnitVolume(vSelf),
+ cm3Delivery = IFNULL((vStandardFlowerBox * 1000) / vPackingOut, buy_getUnitVolume(vSelf));
+
+ UPDATE vn.itemCost ic
+ JOIN cache.last_buy lb ON lb.item_id = ic.itemFk AND lb.warehouse_id = ic.warehouseFk
+ JOIN vn.buy b ON b.id = lb.buy_id
+ SET ic.grams = b.weight * 1000 / b.packing
+ WHERE ic.itemFk = vItemFk AND
+ ic.warehouseFk = vWarehouse;
+
+ END IF;
+
+ SELECT isFeedStock INTO vIsFeedStock
+ FROM warehouse WHERE id = vWarehouseOut AND id <> 13;
+
+ IF vIsFeedStock THEN
+ INSERT IGNORE INTO producer(`name`)
+ SELECT es.company_name
+ FROM buy b
+ JOIN edi.ekt be ON be.id = b.ektFk
+ JOIN edi.supplier es ON es.supplier_id = be.pro
+ WHERE b.id = vSelf;
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -51227,24 +51343,24 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_updateGrouping`(vWarehouseFk INT, vItemFk INT, vGrouping INT)
-BEGIN
-/**
- * Actualiza el grouping de las últimas compras de un artículo
- *
- * @param vWarehouseFk Id del almacén
- * @param vItemFk Id del Artículo
- * @param vGrouping Cantidad de grouping
- */
-
- CALL vn.buyUltimate(vWarehouseFk, CURDATE());
-
- UPDATE vn.buy b
- JOIN tmp.buyUltimate bu ON b.id = bu.buyFk
- SET b.`grouping` = vGrouping
- WHERE bu.warehouseFk = vWarehouseFk
- AND bu.itemFk = vItemFk;
-
- DROP TEMPORARY TABLE tmp.buyUltimate;
+BEGIN
+/**
+ * Actualiza el grouping de las últimas compras de un artículo
+ *
+ * @param vWarehouseFk Id del almacén
+ * @param vItemFk Id del Artículo
+ * @param vGrouping Cantidad de grouping
+ */
+
+ CALL vn.buyUltimate(vWarehouseFk, CURDATE());
+
+ UPDATE vn.buy b
+ JOIN tmp.buyUltimate bu ON b.id = bu.buyFk
+ SET b.`grouping` = vGrouping
+ WHERE bu.warehouseFk = vWarehouseFk
+ AND bu.itemFk = vItemFk;
+
+ DROP TEMPORARY TABLE tmp.buyUltimate;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -51604,28 +51720,27 @@ DELIMITER ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calculate`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT)
-BEGIN
-
- /**
- * Calcula los articulos disponibles y sus precios
- *
- * @table tmp.item(itemFk) Listado de artÃculos a calcular
- * @param vLanded Fecha de recepcion de mercancia
- * @param vAddressFk Id del consignatario
- * @param vAgencyModeFk Id de la agencia
- * @return tmp.ticketCalculateItem(itemFk, available, producer,
- * item, size, stems, category, inkFk, image, origin, price)
- * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk)
- * @return tmp.ticketComponent
- * @return tmp.ticketComponentPrice
- */
+BEGIN
+/**
+ * Calcula los articulos disponibles y sus precios
+ *
+ * @table tmp.item(itemFk) Listado de artículos a calcular
+ * @param vLanded Fecha de recepcion de mercancia
+ * @param vAddressFk Id del consignatario
+ * @param vAgencyModeFk Id de la agencia
+ * @return tmp.ticketCalculateItem(itemFk, available, producer,
+ * item, size, stems, category, inkFk, image, origin, price)
+ * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk)
+ * @return tmp.ticketComponent
+ * @return tmp.ticketComponentPrice
+ */
DECLARE vAvailableCalc INT;
DECLARE vAvailableNoRaidsCalc INT;
@@ -51668,6 +51783,7 @@ BEGIN
origin VARCHAR(3),
price DECIMAL(10,2),
priceKg DECIMAL(10,2),
+ `grouping` INT(10) UNSIGNED,
PRIMARY KEY `itemFk` (`itemFk`)
) ENGINE = MEMORY DEFAULT CHARSET=utf8;
@@ -51696,8 +51812,11 @@ BEGIN
AND anr.calc_id = vAvailableNoRaidsCalc
JOIN tmp.item i ON i.itemFk = a.item_id
JOIN vn.item it ON it.id = i.itemFk
+ JOIN vn.`zone` z ON z.id = vZoneFk
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id
- LEFT JOIN edi.supplyOffer so ON so.srId = it.supplyResponseFk
+ LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk
+ LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID
+ LEFT JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID
LEFT JOIN (SELECT isVNHSupplier, isEarlyBird, TRUE AS itemAllowed
FROM vn.addressFilter af
JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed
@@ -51708,16 +51827,31 @@ BEGIN
AND sub2.countryFk <=> IFNULL(af.countryFk, sub2.countryFk)
AND sub2.isLogifloraAllowed <=> IFNULL(af.isLogifloraAllowed, sub2.isLogifloraAllowed)
WHERE vWarehouseFk = af.warehouseFk
- ) sub ON sub.isVNHSupplier = so.isVNHSupplier
- AND IFNULL(sub.isEarlyBird, so.isEarlyBird) = so.isEarlyBird
+ AND (vShipped < af.beforeDated
+ OR ISNULL(af.beforeDated)
+ OR vShipped > af.afterDated
+ OR ISNULL(af.afterDated))
+ ) sub ON sub.isVNHSupplier = v.isVNHSupplier
+ AND (sub.isEarlyBird = mp.isEarlyBird OR ISNULL(sub.isEarlyBird))
JOIN vn.agencyMode am ON am.id = vAgencyModeFk
JOIN vn.agency ag ON ag.id = am.agencyFk
JOIN vn.itemType itt ON itt.id = it.typeFk
+ JOIN vn.itemCategory itc on itc.id = itt.categoryFk
+ JOIN vn.address ad ON ad.id = vAddressFk
+ LEFT JOIN vn.clientItemType cit
+ ON cit.clientFk = ad.clientFk
+ AND cit.itemTypeFk = itt.id
+ LEFT JOIN vn.clientItemCategory cic
+ ON cic.clientFk = ad.clientFk
+ AND cic.itemCategoryFk = itc.id
WHERE a.calc_id = vAvailableCalc
AND a.available > 0
AND (sub.itemAllowed OR NOT it.isFloramondo OR anr.available > 0)
- AND (ag.isAnyVolumeAllowed OR NOT itt.isUnconventionalSize);
-
+ AND (ag.isAnyVolumeAllowed OR NOT itt.isUnconventionalSize)
+ AND (itc.isReclining OR ISNULL(it.`size`) OR it.`size` < z.itemMaxSize OR ISNULL(z.itemMaxSize))
+ AND NOT (cit.isAllowed <=> FALSE)
+ AND (ISNULL(cic.itemCategoryFk) OR cit.isAllowed);
+
DROP TEMPORARY TABLE tmp.buyUltimate;
CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
@@ -51734,7 +51868,8 @@ BEGIN
image,
origin,
price,
- priceKg)
+ priceKg,
+ `grouping`)
SELECT
tl.itemFk,
SUM(tl.available) available,
@@ -51747,17 +51882,20 @@ BEGIN
i.image,
o.code origin,
bl.price,
- bl.priceKg
+ bl.priceKg,
+ bl.`grouping`
FROM tmp.ticketLot tl
JOIN item i ON tl.itemFk = i.id
LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible
JOIN origin o ON o.id = i.originFk
JOIN (
- SELECT *
- FROM (SELECT price, itemFk, priceKg
+ SELECT price, itemFk, priceKg, MIN(`grouping`) `grouping`
+ FROM (
+ SELECT price, itemFk, priceKg, `grouping`
FROM tmp.ticketComponentPrice
WHERE warehouseFk = vWarehouseFk
- ORDER BY (rate = 2) DESC) sub
+ ORDER BY (rate = 2) DESC
+ ) sub
GROUP BY itemFk
) bl ON bl.itemFk = tl.itemFk
WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk
@@ -51768,339 +51906,6 @@ BEGIN
CLOSE cTravelTree;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `catalog_calculate_beta` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calculate_beta`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT)
-BEGIN
-
- /**
- * Calcula los articulos disponibles y sus precios
- *
- * @table tmp.item(itemFk) Listado de artÃculos a calcular
- * @param vLanded Fecha de recepcion de mercancia
- * @param vAddressFk Id del consignatario
- * @param vAgencyModeFk Id de la agencia
- * @return tmp.ticketCalculateItem(itemFk, available, producer,
- * item, size, stems, category, inkFk, image, origin, price)
- * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk)
- * @return tmp.ticketComponent
- * @return tmp.ticketComponentPrice
- */
-
- DECLARE vAvailableCalc INT;
- DECLARE vAvailableNoRaidsCalc INT;
- DECLARE vShipped DATE;
- DECLARE vWarehouseFk SMALLINT;
- DECLARE vZoneFk INT;
- DECLARE vDone BOOL;
- DECLARE cTravelTree CURSOR FOR
- SELECT zoneFk, warehouseFk, shipped FROM tmp.zoneGetShipped;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
-
- CALL vn.zone_getShipped (vLanded, vAddressFk, vAgencyModeFk, FALSE);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
- CREATE TEMPORARY TABLE tmp.ticketLot(
- `warehouseFk` smallint(5) unsigned NOT NULL,
- `itemFk` int(11) NOT NULL,
- `available` double DEFAULT NULL,
- `buyFk` int(11) DEFAULT NULL,
- `fix` tinyint(3) unsigned DEFAULT '0', -- este campo parece obsoleto
- `zoneFk` int(11) NOT NULL,
- KEY `itemFk` (`itemFk`),
- KEY `item_warehouse` (`itemFk`,`warehouseFk`) USING HASH
- ) ENGINE=MEMORY DEFAULT CHARSET=utf8;
-
- CALL catalog_componentPrepare();
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem;
- CREATE TEMPORARY TABLE tmp.ticketCalculateItem(
- itemFk INT(11) NOT NULL,
- available INT(11),
- producer VARCHAR(50),
- item VARCHAR(50),
- size INT(10) UNSIGNED,
- stems INT(11),
- category VARCHAR(3),
- inkFk VARCHAR(3),
- image VARCHAR(50),
- origin VARCHAR(3),
- price DECIMAL(10,2),
- priceKg DECIMAL(10,2),
- PRIMARY KEY `itemFk` (`itemFk`)
- ) ENGINE = MEMORY DEFAULT CHARSET=utf8;
-
- OPEN cTravelTree;
-
- l: LOOP
- SET vDone = FALSE;
- FETCH cTravelTree INTO vZoneFk, vWarehouseFk, vShipped;
-
- IF vDone THEN
- LEAVE l;
- END IF;
-
- CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipped);
- CALL `cache`.availableNoRaids_refresh (vAvailableNoRaidsCalc, FALSE, vWarehouseFk, vShipped);
- CALL vn.buyUltimate(vWarehouseFk, vShipped);
-
- INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk, zoneFk)
- SELECT vWarehouseFk,
- a.item_id,
- IFNULL(a.available, 0),
- bu.buyFk,
- vZoneFk
- FROM `cache`.available a
- LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id
- AND anr.calc_id = vAvailableNoRaidsCalc
- JOIN tmp.item i ON i.itemFk = a.item_id
- JOIN vn.item it ON it.id = i.itemFk
- LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id
- LEFT JOIN edi.supplyOffer so ON so.srId = it.supplyResponseFk
- LEFT JOIN (SELECT isVNHSupplier, isEarlyBird, TRUE AS itemAllowed
- FROM vn.addressFilter af
- JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed
- FROM vn.address ad
- JOIN vn.province p ON p.id = ad.provinceFk
- WHERE ad.id = vAddressFk
- ) sub2 ON sub2.provinceFk <=> IFNULL(af.provinceFk, sub2.provinceFk)
- AND sub2.countryFk <=> IFNULL(af.countryFk, sub2.countryFk)
- AND sub2.isLogifloraAllowed <=> IFNULL(af.isLogifloraAllowed, sub2.isLogifloraAllowed)
- WHERE vWarehouseFk = af.warehouseFk
- ) sub ON sub.isVNHSupplier = so.isVNHSupplier
- AND IFNULL(sub.isEarlyBird, so.isEarlyBird) = so.isEarlyBird
- JOIN vn.agencyMode am ON am.id = vAgencyModeFk
- JOIN vn.agency ag ON ag.id = am.agencyFk
- JOIN vn.itemType itt ON itt.id = it.typeFk
- WHERE a.calc_id = vAvailableCalc
- AND a.available > 0
- AND (sub.itemAllowed OR NOT it.isFloramondo OR anr.available > 0)
- AND (ag.isAnyVolumeAllowed OR NOT itt.isUnconventionalSize);
-
- DROP TEMPORARY TABLE tmp.buyUltimate;
-
- CALL vn.catalog_componentCalculate_beta(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
-
- INSERT INTO tmp.ticketCalculateItem (
- itemFk,
- available,
- producer,
- item,
- size,
- stems,
- category,
- inkFk,
- image,
- origin,
- price,
- priceKg)
- SELECT
- tl.itemFk,
- SUM(tl.available) available,
- p.name producer,
- i.name item,
- i.size size,
- i.stems,
- i.category,
- i.inkFk,
- i.image,
- o.code origin,
- bl.price,
- bl.priceKg
- FROM tmp.ticketLot tl
- JOIN item i ON tl.itemFk = i.id
- LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible
- JOIN origin o ON o.id = i.originFk
- JOIN (
- SELECT *
- FROM (SELECT price, itemFk, priceKg
- FROM tmp.ticketComponentPrice
- WHERE warehouseFk = vWarehouseFk
- ORDER BY (rate = 2) DESC) sub
- GROUP BY itemFk
- ) bl ON bl.itemFk = tl.itemFk
- WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk
- GROUP BY tl.itemFk
- ON DUPLICATE KEY UPDATE available = available + VALUES(available);
-
- END LOOP;
-
- CLOSE cTravelTree;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `catalog_calculate__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calculate__`(
- vLanded DATE,
- vAddressFk INT,
- vAgencyModeFk INT)
-proc: BEGIN
-/**
- * Calcula los articulos disponibles y sus precios
- *
- * @table tmp.item(itemFk) Listado de artÃculos a calcular
- * @param vLanded Fecha de recepcion de mercancia
- * @param vAddressFk Id del consignatario
- * @param vAgencyModeFk Id de la agencia
- * @return tmp.ticketCalculateItem(itemFk, available, producer,
- * item, size, stems, category, inkFk, image, origin, price)
- * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk)
- * @return tmp.ticketComponent
- * @return tmp.ticketComponentPrice
- * @return tmp.zoneGetShipped
- */
-
- DECLARE vAvailableCalc INT;
- DECLARE vShipped DATE;
- DECLARE vWarehouseFk SMALLINT;
- DECLARE vZoneFk INT;
- DECLARE vDone BOOL;
- DECLARE cTravelTree CURSOR FOR
- SELECT zoneFk, warehouseFk, shipped FROM tmp.zoneGetShipped;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
-
- -- Establece los almacenes y las fechas que van a entrar al disponible
-
- CALL vn.zone_getShipped (vLanded, vAddressFk, vAgencyModeFk, FALSE);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
- CREATE TEMPORARY TABLE tmp.ticketLot(
- `warehouseFk` smallint(5) unsigned NOT NULL,
- `itemFk` int(11) NOT NULL,
- `available` double DEFAULT NULL,
- `buyFk` int(11) DEFAULT NULL,
- `fix` tinyint(3) unsigned DEFAULT '0',
- `zoneFk` int(11) NOT NULL,
- KEY `itemFk` (`itemFk`),
- KEY `item_warehouse` (`itemFk`,`warehouseFk`) USING HASH
- ) ENGINE=MEMORY DEFAULT CHARSET=utf8;
-
- CALL catalog_componentPrepare();
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem;
- CREATE TEMPORARY TABLE tmp.ticketCalculateItem(
- itemFk INT(11) NOT NULL,
- available INT(11),
- producer VARCHAR(50),
- item VARCHAR(50),
- size INT(10) UNSIGNED,
- stems INT(11),
- category VARCHAR(3),
- inkFk VARCHAR(3),
- image VARCHAR(50),
- origin VARCHAR(3),
- price DECIMAL(10,2),
- priceKg DECIMAL(10,2),
- PRIMARY KEY `itemFk` (`itemFk`)
- ) ENGINE = MEMORY DEFAULT CHARSET=utf8;
-
- OPEN cTravelTree;
-
- l: LOOP
- SET vDone = FALSE;
- FETCH cTravelTree INTO vZoneFk, vWarehouseFk, vShipped;
-
- IF vDone THEN
- LEAVE l;
- END IF;
-
- CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipped);
- CALL buyUltimate (vWarehouseFk, vShipped);
-
- INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk, zoneFk)
- SELECT vWarehouseFk,
- i.item_id,
- IFNULL(i.available, 0),
- bu.buyFk,
- vZoneFk
- FROM `cache`.available i
- JOIN tmp.item br ON br.itemFk = i.item_id
- LEFT JOIN item it ON it.id = i.item_id -- esta linea sobra ?
- LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.item_id
- WHERE i.calc_id = vAvailableCalc
- AND i.available > 0;
-
- CALL util.debugAdd('ticketLot: ', (SELECT COUNT(*) FROM tmp.ticketLot));
-
- DROP TEMPORARY TABLE tmp.buyUltimate;
-
- CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
-
- INSERT INTO tmp.ticketCalculateItem (
- itemFk,
- available,
- producer,
- item,
- size,
- stems,
- category,
- inkFk,
- image,
- origin,
- price,
- priceKg)
- SELECT
- tl.itemFk,
- SUM(tl.available) available,
- p.name producer,
- i.name item,
- i.size size,
- i.stems,
- i.category,
- i.inkFk,
- i.image,
- o.code origin,
- bl.price,
- bl.priceKg
- FROM tmp.ticketLot tl
- JOIN item i ON tl.itemFk = i.id
- LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible
- JOIN origin o ON o.id = i.originFk
- JOIN (
- SELECT *
- FROM (SELECT price, itemFk, priceKg
- FROM tmp.ticketComponentPrice
- WHERE warehouseFk = vWarehouseFk
- ORDER BY (rate = 2) DESC) sub
- GROUP BY itemFk
- ) bl ON bl.itemFk = tl.itemFk
- WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk
- GROUP BY tl.itemFk
- ON DUPLICATE KEY UPDATE available = available + VALUES(available);
-
- END LOOP;
-
- CLOSE cTravelTree;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -52111,11 +51916,11 @@ DELIMITER ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentCalculate`( vZoneFk INT,
vAddressFk INT,
@@ -52135,341 +51940,6 @@ BEGIN
* @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
*/
- DECLARE vClientFk INT;
- DECLARE vIsFrenchVNHBuyer BOOLEAN DEFAULT FALSE;
- DECLARE vVNHWarehouseFk INT DEFAULT 7;
- DECLARE vFrenchDiscount DECIMAL(3,2) DEFAULT 0.12;
-
- SELECT clientFk INTO vClientFK
- FROM address
- WHERE id = vAddressFk;
-
- SELECT (c.country = 'FRANCIA' AND vWarehouseFk = vVNHWarehouseFk)
- INTO vIsFrenchVNHBuyer
- FROM vn.country c
- JOIN vn.province p ON p.countryFk = c.id
- JOIN vn.address a ON a.provinceFk = p.id
- WHERE a.id = vAddressFk;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCalculate;
-
- CREATE TEMPORARY TABLE tmp.ticketComponentCalculate
- (PRIMARY KEY (itemFk, warehouseFk))
- ENGINE = MEMORY
- SELECT
- tl.itemFk,
- tl.warehouseFk,
- tl.available,
- -- IF((@rate2 := IFNULL(pf.rate2, b.price2)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate2) rate2,
- IF(i.hasMinPrice, GREATEST(i.minPrice,IFNULL(pf.rate2, b.price2)),IFNULL(pf.rate2, b.price2)) rate2,
- IF(i.hasMinPrice, GREATEST(i.minPrice,IFNULL(pf.rate3, b.price3)),IFNULL(pf.rate3, b.price3)) rate3,
- -- @minPrice := IF((@rate3 := IFNULL(pf.rate3, b.price3)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate3) rate3,
- -- TRUE AS minPrice,
- IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing,
- IFNULL(pf.`grouping`, b.`grouping`) `grouping`,
- ABS(IFNULL(pf.box, b.groupingMode)) groupingMode,
- tl.buyFk,
- i.typeFk,
- IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping
- FROM tmp.ticketLot tl
- JOIN buy b ON b.id = tl.buyFk
- JOIN item i ON i.id = tl.itemFk
- JOIN itemType it ON it.id = i.typeFk
- JOIN itemCategory ic ON ic.id = it.categoryFk
- LEFT JOIN specialPrice sp ON sp.itemFk = i.id
- AND sp.clientFk = vClientFk
- LEFT JOIN (
- SELECT * FROM (
- SELECT pf.itemFk,
- pf.`grouping`,
- pf.packing,
- pf.box,
- pf.rate2,
- pf.rate3,
- zw.warehouseFk
- FROM priceFixed pf
- JOIN zoneWarehouse zw ON zw.zoneFk = vZoneFk
- AND zw.warehouseFk IN (pf.warehouseFk,0)
- WHERE vShipped BETWEEN pf.started AND pf.ended
- ORDER BY pf.itemFk, pf.warehouseFk DESC
- ) tpf
- GROUP BY tpf.itemFk, tpf.warehouseFk
- ) pf ON pf.itemFk = tl.itemFk
- AND pf.warehouseFk = tl.warehouseFk
- WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01
- AND ic.merchandise
- AND tl.zoneFk = vZoneFk
- AND tl.warehouseFk = vWarehouseFk;
-
- -- Coste
- INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- c2.id,
- b.buyingValue + b.freightValue + b.packageValue + b.comissionValue
- FROM tmp.ticketComponentCalculate tcc
- JOIN vn.component c2 ON c2.code = 'purchaseValue'
- JOIN buy b ON b.id = tcc.buyFk;
-
- -- Margen
- INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- c2.id,
- tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue
- FROM tmp.ticketComponentCalculate tcc
- JOIN vn.component c2 ON c2.code = 'margin'
- JOIN buy b ON b.id = tcc.buyFk;
-
- -- Promo Francia
- IF vIsFrenchVNHBuyer THEN
-
- INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- c2.id,
- - vFrenchDiscount * (b.buyingValue + b.freightValue + b.packageValue + b.comissionValue) / ( 1 - vFrenchDiscount)
- FROM tmp.ticketComponentCalculate tcc
- JOIN vn.component c2 ON c2.code = 'frenchOffer'
- JOIN buy b ON b.id = tcc.buyFk;
-
- END IF;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentBase;
- CREATE TEMPORARY TABLE tmp.ticketComponentBase ENGINE = MEMORY
- SELECT tc.itemFk, ROUND(SUM(tc.cost), 4) AS base, tc.warehouseFk
- FROM tmp.ticketComponent tc
- JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk
- GROUP BY tc.itemFk, warehouseFk;
-
- -- RECOBRO
- INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- SELECT tcb.warehouseFk, tcb.itemFk, c2.id,
- ROUND(tcb.base *
- LEAST(
- MAX(GREATEST(IFNULL(cr.priceIncreasing,0),
- IFNULL(cr1.priceIncreasing,0),
- IFNULL(cr2.priceIncreasing,0))
- ),
- 0.25),
- 3)
- FROM tmp.ticketComponentBase tcb
- JOIN vn.component c2 ON c2.code = 'debtCollection'
- JOIN claimRatio cr ON cr.clientFk = vClientFk
- LEFT JOIN clientYoke cy1 ON cy1.leftOx = cr.clientFk
- LEFT JOIN claimRatio cr1 ON cr1.clientFk = cy1.rightOx
- LEFT JOIN clientYoke cy2 ON cy2.rightOx = cr.clientFk
- LEFT JOIN claimRatio cr2 ON cr2.clientFk = cy2.leftOx
- WHERE GREATEST(IFNULL(cr.priceIncreasing,0), IFNULL(cr1.priceIncreasing,0), IFNULL(cr2.priceIncreasing,0)) > 0.009
- GROUP BY tcb.itemFk;
-
- -- Mana auto
- INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- SELECT tcb.warehouseFk, tcb.itemFk, c2.id, ROUND(base * (0.01 + wm.pricesModifierRate), 3) as manaAuto
- FROM tmp.ticketComponentBase tcb
- JOIN `client` c on c.id = vClientFk
- JOIN workerMana wm ON c.salesPersonFk = wm.workerFk
- JOIN vn.component c2 ON c2.code = 'autoMana'
- WHERE wm.isPricesModifierActivated
- HAVING manaAuto <> 0;
-
- -- Precios especiales
- INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- SELECT tcb.warehouseFk,
- tcb.itemFk,
- c2.id,
- GREATEST(
- IFNULL(ROUND(tcb.base * c2.tax, 4), 0),
- IF(i.hasMinPrice, i.minPrice,0) - tcc.rate3
- ) cost
- FROM tmp.ticketComponentBase tcb
- JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount'
- JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk
- LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
- JOIN vn.item i ON i.id = tcb.itemFk
- WHERE sp.value IS NULL
- AND i.supplyResponseFk IS NULL;
-
- -- Venta por paquetes
- INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3
- FROM tmp.ticketComponentCalculate tcc
- JOIN vn.component c2 ON c2.code = 'salePerPackage'
- JOIN buy b ON b.id = tcc.buyFk
- LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
- WHERE sp.value IS NULL;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.zone;
- CREATE TEMPORARY TABLE IF NOT EXISTS tmp.zone (INDEX (id))
- ENGINE = MEMORY
- SELECT vZoneFk id;
-
- CALL zone_getOptionsForShipment(vShipped, TRUE);
-
- -- Reparto
- INSERT INTO tmp.ticketComponent
- SELECT tcc.warehouseFK,
- tcc.itemFk,
- c2.id,
- z.inflation * ROUND(ic.cm3delivery * (IFNULL(zo.price,5000) - IFNULL(zo.bonus,0)) / (1000 * vc.standardFlowerBox) , 4) cost
- FROM tmp.ticketComponentCalculate tcc
- JOIN item i ON i.id = tcc.itemFk
- JOIN tmp.zoneOption zo ON zo.zoneFk = vZoneFk
- JOIN zone z ON z.id = vZoneFk
- JOIN agencyMode am ON am.id = z.agencyModeFk
- JOIN vn.volumeConfig vc
- JOIN vn.component c2 ON c2.code = 'delivery'
- LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk
- AND ic.itemFk = tcc.itemFk
- HAVING cost <> 0;
-
- DROP TEMPORARY TABLE tmp.zoneOption;
- /*
- -- Extra reparto
- INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- SELECT tcc.warehouseFk, tcc.itemFk, c2.id, ap.packagingValue cost
- FROM tmp.ticketComponentCalculate tcc
- JOIN vn.addressForPackaging ap
- JOIN vn.component c2 ON c2.code = 'bagged'
- WHERE ap.addressFk = vAddressFk;
- */
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCopy;
- CREATE TEMPORARY TABLE tmp.ticketComponentCopy ENGINE = MEMORY
- SELECT * FROM tmp.ticketComponent;
-
- -- Precio especial
- INSERT INTO tmp.ticketComponent
- SELECT tcc.warehouseFk,
- tcc.itemFk,
- c2.id,
- sp.value - SUM(tcc.cost) sumCost
- FROM tmp.ticketComponentCopy tcc
- JOIN component c ON c.id = tcc.componentFk
- JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk
- JOIN vn.component c2 ON c2.code = 'specialPrices'
- WHERE c.classRate IS NULL
- AND tcc.warehouseFk = vWarehouseFk
- GROUP BY tcc.itemFk, tcc.warehouseFk
- HAVING ABS(sumCost) > 0.001;
-
- -- Rappel
- INSERT INTO tmp.ticketComponent
- SELECT tcc.warehouseFk,
- tcc.itemFk,
- IFNULL(c.componentFk ,c2.id),
- SUM(tcc.cost) * ((1/(1-c.rappel/100)) -1) sumCost
- FROM tmp.ticketComponentCopy tcc
- JOIN vn.clientChain cc ON cc.clientFk = vClientFk
- JOIN vn.`chain` c ON c.id = cc.chainFk
- JOIN vn.component c2 ON c2.code = 'rappel'
- WHERE tcc.warehouseFk = vWarehouseFk
- GROUP BY tcc.itemFk, tcc.warehouseFk;
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentSum;
- CREATE TEMPORARY TABLE tmp.ticketComponentSum
- (INDEX (itemFk, warehouseFk))
- ENGINE = MEMORY
- SELECT SUM(cost) sumCost, tc.itemFk, tc.warehouseFk, c.classRate
- FROM tmp.ticketComponent tc
- JOIN component c ON c.id = tc.componentFk
- GROUP BY tc.itemFk, tc.warehouseFk, c.classRate;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentRate;
- CREATE TEMPORARY TABLE tmp.ticketComponentRate ENGINE = MEMORY
- SELECT tcc.warehouseFk,
- tcc.itemFk,
- 1 rate,
- IF(tcc.groupingMode = 1, tcc.`grouping`, 1) `grouping`,
- CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price,
- CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg
- FROM tmp.ticketComponentCalculate tcc
- JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
- AND tcs.warehouseFk = tcc.warehouseFk
- WHERE IFNULL(tcs.classRate, 1) = 1
- AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0)
- GROUP BY tcs.warehouseFk, tcs.itemFk;
-
- INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- 2 rate,
- tcc.packing `grouping`,
- SUM(tcs.sumCost) price,
- SUM(tcs.sumCost) / weightGrouping priceKg
- FROM tmp.ticketComponentCalculate tcc
- JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
- AND tcs.warehouseFk = tcc.warehouseFk
- WHERE tcc.available IS NULL OR (IFNULL(tcs.classRate, 2) = 2
- AND tcc.packing > 0 AND tcc.available >= tcc.packing)
- GROUP BY tcs.warehouseFk, tcs.itemFk;
-
- INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- 3 rate,
- tcc.available `grouping`,
- SUM(tcs.sumCost) price,
- SUM(tcs.sumCost) / weightGrouping priceKg
- FROM tmp.ticketComponentCalculate tcc
- JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
- AND tcs.warehouseFk = tcc.warehouseFk
- WHERE IFNULL(tcs.classRate, 3) = 3
- GROUP BY tcs.warehouseFk, tcs.itemFk;
-
- INSERT INTO tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
- SELECT * FROM (
- SELECT * FROM tmp.ticketComponentRate ORDER BY price
- ) t
- GROUP BY itemFk, warehouseFk, `grouping`;
-
- DROP TEMPORARY TABLE
- tmp.ticketComponentCalculate,
- tmp.ticketComponentSum,
- tmp.ticketComponentBase,
- tmp.ticketComponentRate,
- tmp.ticketComponentCopy;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `catalog_componentCalculate_beta` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentCalculate_beta`( vZoneFk INT,
- vAddressFk INT,
- vShipped DATE,
- vWarehouseFk INT)
-BEGIN
- /**
- * Calcula los componentes de los articulos de tmp.ticketLot
- *
- * @param vZoneFk para calcular el transporte
- * @param vAddressFk Consignatario
- * @param vShipped dia de salida del pedido
- * @param vWarehouseFk warehouse de salida del pedido
- * @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk)
- * @table tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- *
- * @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
- */
-
DECLARE vClientFk INT;
DECLARE vIsFrenchVNHBuyer BOOLEAN DEFAULT FALSE;
DECLARE vVNHWarehouseFk INT DEFAULT 7;
@@ -52797,456 +52267,6 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `catalog_componentCalculate__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentCalculate__`(
- vZoneFk INT,
- vAddressFk INT,
- vShipped DATE,
- vWarehouseFk INT)
-proc: BEGIN
-/**
- * Calcula los componentes de los articulos de tmp.ticketLot
- *
- * @param vZoneFk para calcular el transporte
- * @param vAddressFk Consignatario
- * @param vShipped dia de salida del pedido
- * @param vWarehouseFk warehouse de salida del pedido
- * @param tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk)
- * @table tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- *
- * @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
- */
- DECLARE vClientFk INT;
- DECLARE vMinimumDensityWeight INT DEFAULT 167;
- DECLARE vBoxVolume BIGINT;
- DECLARE vSpecialPriceComponent INT DEFAULT 10;
- DECLARE vDeliveryComponent INT DEFAULT 15;
- DECLARE vRecoveryComponent INT DEFAULT 17;
- DECLARE vSellByPacketComponent INT DEFAULT 22;
- DECLARE vBuyValueComponent INT DEFAULT 28;
- DECLARE vMarginComponent INT DEFAULT 29;
- DECLARE vDiscountLastItemComponent INT DEFAULT 32;
- DECLARE vExtraBaggedComponent INT DEFAULT 38;
- DECLARE vManaAutoComponent INT DEFAULT 39;
- DECLARE vFrenchOffer INT DEFAULT 42;
- DECLARE vIsFrenchVNHBuyer BOOLEAN DEFAULT FALSE;
- DECLARE vVNHWarehouseFk INT DEFAULT 7;
- DECLARE vFloramondoWarehouseFk INT DEFAULT 40;
- DECLARE vIsLogifloraAllowed BOOLEAN DEFAULT 0;
- DECLARE vMaxLogifloraDays INT;
- DECLARE vRangeLogifloraDays INT DEFAULT 3;
- DECLARE vVisibleCache INT;
- DECLARE vRappelComponent INT DEFAULT 44;
- DECLARE vIsZonePremium BOOL;
- DECLARE vFrenchDiscount DECIMAL(3,2) DEFAULT 0.12;
- DECLARE vIsCatalonianBuyer BOOL;
- DECLARE visAnyVolumeAllowed BOOL;
-
- SELECT (COUNT(*) > 0) INTO vIsZonePremium
- FROM vn.zoneFilter zf
- WHERE zf.zoneFk = vZoneFk;
-
- SELECT vc.standardFlowerBox * 1000 INTO vBoxVolume
- FROM vn.volumeConfig vc;
-
- SELECT clientFk, isLogifloraAllowed INTO vClientFK, vIsLogifloraAllowed
- FROM address
- WHERE id = vAddressFk;
-
- SELECT (c.country IN ('Francia','Suiza') AND vWarehouseFk IN (vVNHWarehouseFk, vFloramondoWarehouseFk))
- INTO vIsFrenchVNHBuyer
- FROM vn.country c
- JOIN vn.province p ON p.countryFk = c.id
- JOIN vn.address a ON a.provinceFk = p.id
- WHERE a.id = vAddressFk;
-
- SELECT (p.name = 'Barcelona' AND vWarehouseFk = vVNHWarehouseFk)
- INTO vIsCatalonianBuyer
- FROM vn.province p
- JOIN vn.address a ON a.provinceFk = p.id
- WHERE a.id = vAddressFk; -- PAK 18/10/21
-
- SELECT travellingDays INTO vMaxLogifloraDays
- FROM edi.warehouseFloramondo
- WHERE warehouseFk = vWarehouseFk;
-
- -- Se eliminan los productos de tamaños no convencionales, salvo agencias que lo permitan
- SELECT a.isAnyVolumeAllowed INTO visAnyVolumeAllowed
- FROM vn.agency a
- JOIN vn.agencyMode am ON am.agencyFk = a.id
- JOIN vn.`zone`z ON z.agencyModeFk = am.id
- WHERE z.id = vZoneFk;
-
- IF NOT vIsAnyVolumeAllowed THEN
-
- DELETE tl.*
- FROM tmp.ticketLot tl
- JOIN vn.item i ON i.id = tl.itemFk
- JOIN vn.itemType it ON it.id = i.typeFk
- WHERE it.isUnconventionalSize;
-
- END IF;
-
- -- Esto sirve para que los franceses compren sólo por las cuentas de VNH
- DELETE tl.*
- FROM tmp.ticketLot tl
- JOIN vn.item i ON i.id = tl.itemFk
- JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk
- JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID
- WHERE v.isVNHSupplier != vIsFrenchVNHBuyer;
-
- IF (NOT vIsLogifloraAllowed AND vVNHWarehouseFk != vWarehouseFk)
- OR NOT vn.isLogifloraDay(vShipped, vWarehouseFk)
- -- OR NOT(vIsCatalonianBuyer OR vIsFrenchVNHBuyer)
- THEN
-
- CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk);
-
- DELETE tl FROM tmp.ticketLot tl
- JOIN item i ON i.id = tl.itemFk
- 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
- LEFT JOIN vn.entry e ON e.id = b.entryFk
- LEFT JOIN vn.supplier s ON s.id = e.supplierFk -- PAK 13/10/21
- LEFT JOIN cache.visible v ON v.calc_id = vVisibleCache AND v.item_id = i.id
- LEFT JOIN (SELECT DISTINCT s.itemFk
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- WHERE t.warehouseFk = vWarehouseFk
- AND t.addressFk = vAddressFk
- AND t.shipped = vShipped
- AND t.zoneFk = vZoneFk) sub ON sub.itemFk = i.id
- WHERE (i.supplyResponseFk
- AND (IFNULL(e.isRaid,TRUE)
- OR s.nickname = 'INVENTARIO') -- PAK 13/10/21
- AND ISNULL(sub.itemFk)
- AND IFNULL(v.visible,0) = 0
- AND vWarehouseFk = tl.warehouseFk);
-
- END IF;
-
- -- Eliminem productes de la oferta que no deuen vore els francesos
- IF vIsFrenchVNHBuyer THEN
-
- CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk);
-
- DELETE tl FROM tmp.ticketLot tl
- JOIN item i ON i.id = tl.itemFk
- JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk
- JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID
- LEFT JOIN cache.visible v ON v.calc_id = vVisibleCache AND v.item_id = i.id
- LEFT JOIN (SELECT DISTINCT s.itemFk
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- WHERE t.warehouseFk = vWarehouseFk
- AND t.addressFk = vAddressFk
- AND t.shipped = vShipped
- AND t.zoneFk = vZoneFk) sub ON sub.itemFk = i.id
- WHERE (mp.isEarlyBird = FALSE
- AND IFNULL(sub.itemFk,0) = 0
- AND IFNULL(v.visible ,0) = 0);
-
- END IF;
-
- -- Eliminem productes de la oferta que no deuen vore les zones PREMIUM
- IF vIsZonePremium THEN
-
- DELETE tl.*
- FROM tmp.ticketLot tl
- JOIN item i ON i.id = tl.itemFk
- LEFT JOIN vn.zoneFilter zf ON zf.itemTypeFk = i.typeFk
- AND zf.zoneFk = vZoneFk
- AND i.`size` <= zf.sizeMax
- WHERE zf.id IS NULL ;
-
- END IF;
-
- -- Eliminem productes de la oferta que la zona no pot transportar
- DELETE tl.*
- FROM tmp.ticketLot tl
- JOIN item i ON i.id = tl.itemFk
- JOIN vn.zone z ON z.id = vZoneFk
- WHERE i.size > z.itemMaxSize;
-
- SET @rate2 := 0;
- SET @rate3 := 0;
- SET @minPrice := 0;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCalculate;
- CREATE TEMPORARY TABLE tmp.ticketComponentCalculate
- (PRIMARY KEY (itemFk, warehouseFk))
- ENGINE = MEMORY
- SELECT
- tl.itemFk,
- tl.warehouseFk,
- tl.available,
- IF((@rate2 := IFNULL(pf.rate2, b.price2)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate2) * 1.0 rate2,
- @minPrice := IF((@rate3 := IFNULL(pf.rate3, b.price3)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate3) * 1.0 rate3,
- IFNULL(@minPrice, 0) AS minPrice,
- IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing,
- IFNULL(pf.`grouping`, b.`grouping`) `grouping`,
- ABS(IFNULL(pf.box, b.groupingMode)) groupingMode,
- tl.buyFk,
- i.typeFk,
- IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping
- FROM tmp.ticketLot tl
- JOIN buy b ON b.id = tl.buyFk
- JOIN item i ON i.id = tl.itemFk
- JOIN itemType it ON it.id = i.typeFk
- LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
- LEFT JOIN specialPrice sp ON sp.itemFk = i.id AND sp.clientFk = vClientFk
- LEFT JOIN (
- SELECT * FROM (
- SELECT pf.itemFk, pf.`grouping`, pf.packing, pf.box, pf.rate2, pf.rate3, zw.warehouseFk
- FROM priceFixed pf
- JOIN zoneWarehouse zw ON zw.zoneFk = vZoneFk AND (zw.warehouseFk = pf.warehouseFk OR pf.warehouseFk = 0)
- WHERE vShipped BETWEEN pf.started AND pf.ended ORDER BY pf.itemFk, pf.warehouseFk DESC
- ) tpf
- GROUP BY tpf.itemFk, tpf.warehouseFk
- ) pf ON pf.itemFk = tl.itemFk AND pf.warehouseFk = tl.warehouseFk
- WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 AND ic.merchandise <> 0
- AND tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk;
-
- -- Coste
- INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- vBuyValueComponent,
- b.buyingValue + b.freightValue + b.packageValue + b.comissionValue
- FROM tmp.ticketComponentCalculate tcc
- JOIN buy b ON b.id = tcc.buyFk;
-
- -- Margen
- INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- vMarginComponent,
- tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue
- FROM tmp.ticketComponentCalculate tcc
- JOIN buy b ON b.id = tcc.buyFk;
-
- -- Promo Francia
- IF vIsFrenchVNHBuyer THEN
-
- INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- vFrenchOffer,
- - vFrenchDiscount * (b.buyingValue + b.freightValue + b.packageValue + b.comissionValue) / ( 1 - vFrenchDiscount)
- FROM tmp.ticketComponentCalculate tcc
- JOIN buy b ON b.id = tcc.buyFk;
-
- END IF;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentBase;
- CREATE TEMPORARY TABLE tmp.ticketComponentBase ENGINE = MEMORY
- SELECT tc.itemFk, ROUND(SUM(tc.cost), 4) AS base, tc.warehouseFk
- FROM tmp.ticketComponent tc
- JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk
- GROUP BY tc.itemFk, warehouseFk;
-
- -- RECOBRO
- INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent,
- ROUND(tcb.base * LEAST(MAX(GREATEST(IFNULL(cr.priceIncreasing,0), IFNULL(cr1.priceIncreasing,0), IFNULL(cr2.priceIncreasing,0))), 0.25), 3)
- FROM tmp.ticketComponentBase tcb
- JOIN claimRatio cr ON cr.clientFk = vClientFk
- LEFT JOIN clientYoke cy1 ON cy1.leftOx = cr.clientFk
- LEFT JOIN claimRatio cr1 ON cr1.clientFk = cy1.rightOx
- LEFT JOIN clientYoke cy2 ON cy2.rightOx = cr.clientFk
- LEFT JOIN claimRatio cr2 ON cr2.clientFk = cy2.leftOx
- WHERE GREATEST(IFNULL(cr.priceIncreasing,0), IFNULL(cr1.priceIncreasing,0), IFNULL(cr2.priceIncreasing,0)) > 0.009
- GROUP BY tcb.itemFk;
-
- -- Mana auto
- INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
- SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + wm.pricesModifierRate), 3) as manaAuto
- FROM tmp.ticketComponentBase tcb
- JOIN `client` c on c.id = vClientFk
- JOIN workerMana wm ON c.salesPersonFk = wm.workerFk
- WHERE wm.isPricesModifierActivated
- HAVING manaAuto <> 0;
-
- -- Precios especiales
- INSERT INTO tmp.ticketComponent
- SELECT tcb.warehouseFk,
- tcb.itemFk,
- c.id,
- GREATEST(IFNULL(ROUND(tcb.base * c.tax, 4), 0), tcc.minPrice - tcc.rate3)
- FROM tmp.ticketComponentBase tcb
- JOIN component c
- JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk
- LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
- JOIN vn.item i ON i.id = tcb.itemFk
- WHERE c.id = vDiscountLastItemComponent
- AND c.tax <> 0
- AND tcc.minPrice < tcc.rate3
- AND sp.value IS NULL
- AND i.supplyResponseFk IS NULL; -- FLORAMONDO
-
- -- Venta por paquetes
- INSERT INTO tmp.ticketComponent
- SELECT tcc.warehouseFk, tcc.itemFk, vSellByPacketComponent, tcc.rate2 - tcc.rate3
- FROM tmp.ticketComponentCalculate tcc
- JOIN buy b ON b.id = tcc.buyFk
- LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
- WHERE sp.value IS NULL;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.zone;
- CREATE TEMPORARY TABLE IF NOT EXISTS tmp.zone (INDEX (id))
- ENGINE = MEMORY
- SELECT vZoneFk id;
-
- CALL zone_getOptionsForShipment(vShipped, TRUE);
-
- -- Reparto
- INSERT INTO tmp.ticketComponent
- SELECT tcc.warehouseFK,
- tcc.itemFk,
- vDeliveryComponent,
- z.inflation * ROUND(ic.cm3delivery * (IFNULL(zo.price,5000) - IFNULL(zo.bonus,0)) / vBoxVolume, 4) cost
- FROM tmp.ticketComponentCalculate tcc
- JOIN item i ON i.id = tcc.itemFk
- JOIN tmp.zoneOption zo ON zo.zoneFk = vZoneFk
- JOIN zone z ON z.id = vZoneFk
- JOIN agencyMode am ON am.id = z.agencyModeFk
- LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk
- AND ic.itemFk = tcc.itemFk
- HAVING cost <> 0;
-
- DROP TEMPORARY TABLE tmp.zoneOption;
-
- -- Extra reparto
- IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = vAddressFk) THEN
- INSERT INTO tmp.ticketComponent
- SELECT tcc.warehouseFk, b.itemFk, vExtraBaggedComponent, ap.packagingValue cost
- FROM tmp.ticketComponentCalculate tcc
- JOIN vn.addressForPackaging ap
- WHERE ap.addressFk = vAddressFk;
- END IF;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCopy;
- CREATE TEMPORARY TABLE tmp.ticketComponentCopy ENGINE = MEMORY
- SELECT * FROM tmp.ticketComponent;
-
- -- Precio especial
- INSERT INTO tmp.ticketComponent
- SELECT tcc.warehouseFk,
- tcc.itemFk,
- vSpecialPriceComponent,
- sp.value - SUM(tcc.cost) sumCost
- FROM tmp.ticketComponentCopy tcc
- JOIN component c ON c.id = tcc.componentFk
- JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk
- WHERE c.classRate IS NULL
- AND tcc.warehouseFk = vWarehouseFk
- GROUP BY tcc.itemFk, tcc.warehouseFk
- HAVING ABS(sumCost) > 0.001;
-
- -- Rappel
- INSERT INTO tmp.ticketComponent
- SELECT tcc.warehouseFk,
- tcc.itemFk,
- IFNULL(c.componentFk ,vRappelComponent),
- SUM(tcc.cost) * ((1/(1-c.rappel/100)) -1) sumCost
- FROM tmp.ticketComponentCopy tcc
- JOIN vn.clientChain cc ON cc.clientFk = vClientFk
- JOIN vn.`chain` c ON c.id = cc.chainFk
- WHERE tcc.warehouseFk = vWarehouseFk
- GROUP BY tcc.itemFk, tcc.warehouseFk;
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentSum;
- CREATE TEMPORARY TABLE tmp.ticketComponentSum
- (INDEX (itemFk, warehouseFk))
- ENGINE = MEMORY
- SELECT SUM(cost) sumCost, tc.itemFk, tc.warehouseFk, c.classRate
- FROM tmp.ticketComponent tc
- JOIN component c ON c.id = tc.componentFk
- GROUP BY tc.itemFk, tc.warehouseFk, c.classRate;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentRate;
- CREATE TEMPORARY TABLE tmp.ticketComponentRate ENGINE = MEMORY
- SELECT tcc.warehouseFk,
- tcc.itemFk,
- 1 rate,
- IF(tcc.groupingMode = 1, tcc.`grouping`, 1) `grouping`,
- CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price,
- CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg
- FROM tmp.ticketComponentCalculate tcc
- JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
- AND tcs.warehouseFk = tcc.warehouseFk
- WHERE IFNULL(tcs.classRate, 1) = 1
- AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0)
- GROUP BY tcs.warehouseFk, tcs.itemFk;
-
- INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- 2 rate,
- tcc.packing `grouping`,
- SUM(tcs.sumCost) price,
- SUM(tcs.sumCost) / weightGrouping priceKg
- FROM tmp.ticketComponentCalculate tcc
- JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
- AND tcs.warehouseFk = tcc.warehouseFk
- WHERE tcc.available IS NULL OR (IFNULL(tcs.classRate, 2) = 2
- AND tcc.packing > 0 AND tcc.available >= tcc.packing)
- GROUP BY tcs.warehouseFk, tcs.itemFk;
-
- IF vIsZonePremium THEN
-
- DELETE
- FROM tmp.ticketComponentRate
- WHERE rate = 1;
-
- END IF;
-
- INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
- SELECT
- tcc.warehouseFk,
- tcc.itemFk,
- 3 rate,
- tcc.available `grouping`,
- SUM(tcs.sumCost) price,
- SUM(tcs.sumCost) / weightGrouping priceKg
- FROM tmp.ticketComponentCalculate tcc
- JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
- AND tcs.warehouseFk = tcc.warehouseFk
- WHERE IFNULL(tcs.classRate, 3) = 3
- GROUP BY tcs.warehouseFk, tcs.itemFk;
-
- INSERT INTO tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
- SELECT * FROM (
- SELECT * FROM tmp.ticketComponentRate ORDER BY price
- ) t
- GROUP BY itemFk, warehouseFk, `grouping`;
-
- DROP TEMPORARY TABLE
- tmp.ticketComponentCalculate,
- tmp.ticketComponentSum,
- tmp.ticketComponentBase,
- tmp.ticketComponentRate,
- tmp.ticketComponentCopy;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `catalog_componentPrepare` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -53662,87 +52682,87 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `clean_logiflora`()
-BEGIN
- /* partir en 2 procedimientos, uno que borre compras y otro articulos
- * item_clean, buy_clean
- * */
-
- DECLARE vMaxDated DATE DEFAULT TIMESTAMPADD(DAY, - 7, CURDATE());
- DECLARE vDone INT DEFAULT FALSE;
- DECLARE vBuyFk INT;
- DECLARE cur1 CURSOR FOR SELECT id FROM tmp.buy;
- DECLARE cur2 CURSOR FOR SELECT id FROM tmp.item;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.buy;
-
- CREATE TEMPORARY TABLE tmp.buy
- ENGINE = MEMORY
- SELECT b.id
- FROM vn.buy b
- JOIN vn.entry e ON e.id = b.entryFk
- JOIN vn.travel tr ON tr.id = e.travelFk
- JOIN vn.agencyMode am ON am.id = tr.agencyFk
- WHERE b.quantity = 0
- AND am.name = 'LOGIFLORA'
- AND e.isRaid;
-
- OPEN cur1;
-
- read_loop: LOOP
-
- SET vDone = FALSE;
-
- FETCH cur1 INTO vBuyFk;
-
- IF vDone THEN
- LEAVE read_loop;
- END IF;
-
- DELETE FROM vn.buy WHERE id = vBuyFk;
-
- END LOOP;
-
- CLOSE cur1;
-
- DROP TEMPORARY TABLE tmp.buy;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.item;
-
- CREATE TEMPORARY TABLE tmp.item
- ENGINE = MEMORY
- SELECT DISTINCT i.id
- FROM vn.item i
- LEFT JOIN hedera.orderRow o ON o.itemFk = i.id
- LEFT JOIN vn.sale s ON s.itemFk = i.id
- LEFT JOIN vn.buy b ON b.itemFk = i.id
- WHERE i.supplyResponseFk
- AND o.id IS NULL
- AND b.id IS NULL
- AND s.id IS NULL
- AND i.created < vMaxDated;
-
- OPEN cur2;
-
- read_loop: LOOP
-
- SET vDone = FALSE;
-
- FETCH cur2 INTO vBuyFk;
-
- IF vDone THEN
- LEAVE read_loop;
- END IF;
-
- DELETE FROM vn.item WHERE id = vBuyFk;
-
- END LOOP;
-
- CLOSE cur2;
-
- DROP TEMPORARY TABLE tmp.item;
-
+BEGIN
+ /* partir en 2 procedimientos, uno que borre compras y otro articulos
+ * item_clean, buy_clean
+ * */
+
+ DECLARE vMaxDated DATE DEFAULT TIMESTAMPADD(DAY, - 7, CURDATE());
+ DECLARE vDone INT DEFAULT FALSE;
+ DECLARE vBuyFk INT;
+ DECLARE cur1 CURSOR FOR SELECT id FROM tmp.buy;
+ DECLARE cur2 CURSOR FOR SELECT id FROM tmp.item;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.buy;
+
+ CREATE TEMPORARY TABLE tmp.buy
+ ENGINE = MEMORY
+ SELECT b.id
+ FROM vn.buy b
+ JOIN vn.entry e ON e.id = b.entryFk
+ JOIN vn.travel tr ON tr.id = e.travelFk
+ JOIN vn.agencyMode am ON am.id = tr.agencyFk
+ WHERE b.quantity = 0
+ AND am.name = 'LOGIFLORA'
+ AND e.isRaid;
+
+ OPEN cur1;
+
+ read_loop: LOOP
+
+ SET vDone = FALSE;
+
+ FETCH cur1 INTO vBuyFk;
+
+ IF vDone THEN
+ LEAVE read_loop;
+ END IF;
+
+ DELETE FROM vn.buy WHERE id = vBuyFk;
+
+ END LOOP;
+
+ CLOSE cur1;
+
+ DROP TEMPORARY TABLE tmp.buy;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.item;
+
+ CREATE TEMPORARY TABLE tmp.item
+ ENGINE = MEMORY
+ SELECT DISTINCT i.id
+ FROM vn.item i
+ LEFT JOIN hedera.orderRow o ON o.itemFk = i.id
+ LEFT JOIN vn.sale s ON s.itemFk = i.id
+ LEFT JOIN vn.buy b ON b.itemFk = i.id
+ WHERE i.supplyResponseFk
+ AND o.id IS NULL
+ AND b.id IS NULL
+ AND s.id IS NULL
+ AND i.created < vMaxDated;
+
+ OPEN cur2;
+
+ read_loop: LOOP
+
+ SET vDone = FALSE;
+
+ FETCH cur2 INTO vBuyFk;
+
+ IF vDone THEN
+ LEAVE read_loop;
+ END IF;
+
+ DELETE FROM vn.item WHERE id = vBuyFk;
+
+ END LOOP;
+
+ CLOSE cur2;
+
+ DROP TEMPORARY TABLE tmp.item;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -53782,76 +52802,76 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `clientCreate`(
- vFirstname VARCHAR(50),
- vSurnames VARCHAR(50),
- vFi VARCHAR(9),
- vAddress TEXT,
- vPostcode CHAR(5),
- vCity VARCHAR(25),
- vProvinceFk SMALLINT(5),
- vCompanyFk SMALLINT(5),
- vPhone VARCHAR(11),
- vEmail VARCHAR(255),
+CREATE DEFINER=`root`@`localhost` PROCEDURE `clientCreate`(
+ vFirstname VARCHAR(50),
+ vSurnames VARCHAR(50),
+ vFi VARCHAR(9),
+ vAddress TEXT,
+ vPostcode CHAR(5),
+ vCity VARCHAR(25),
+ vProvinceFk SMALLINT(5),
+ vCompanyFk SMALLINT(5),
+ vPhone VARCHAR(11),
+ vEmail VARCHAR(255),
vUserFk INT)
-BEGIN
-/**
- * Create new client
- *
- */
- DECLARE vPayMethodFk INT DEFAULT 4;
- DECLARE vDueDay INT DEFAULT 5;
- DECLARE vDefaultCredit DECIMAL(10, 2) DEFAULT 300.00;
- DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1;
- DECLARE vHasCoreVnl BOOLEAN DEFAULT TRUE;
- DECLARE vMandateTypeFk INT DEFAULT 2;
-
- INSERT INTO `client` (
- id,
- name,
- street,
- fi,
- phone,
- email,
- provinceFk,
- city,
- postcode,
- socialName,
- payMethodFk,
- dueDay,
- credit,
- isTaxDataChecked,
- hasCoreVnl,
- isEqualizated)
- VALUES (
- vUserFk,
- CONCAT('TR ', vFirstname, ' ', vSurnames),
- vAddress,
- TRIM(vFi),
- vPhone,
- vEmail,
- vProvinceFk,
- vCity,
- vPostcode,
- CONCAT(vSurnames, ' ', vFirstname),
- vPayMethodFk,
- vDueDay,
- vDefaultCredit,
- vIsTaxDataChecked,
- vHasCoreVnl,
- FALSE
- ) ON duplicate key update
- payMethodFk = vPayMethodFk,
- dueDay = vDueDay,
- credit = vDefaultCredit,
- isTaxDataChecked = vIsTaxDataChecked,
- hasCoreVnl = vHasCoreVnl,
- isActive = TRUE;
-
- IF (SELECT COUNT(*) FROM mandate WHERE clientFk = vUserFk AND companyFk = vCompanyFk AND mandateTypeFk = vMandateTypeFk) = 0 THEN
- INSERT INTO mandate (clientFk, companyFk, mandateTypeFk)
- VALUES (vUserFk, vCompanyFk, vMandateTypeFk);
- END IF;
+BEGIN
+/**
+ * Create new client
+ *
+ */
+ DECLARE vPayMethodFk INT DEFAULT 4;
+ DECLARE vDueDay INT DEFAULT 5;
+ DECLARE vDefaultCredit DECIMAL(10, 2) DEFAULT 300.00;
+ DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1;
+ DECLARE vHasCoreVnl BOOLEAN DEFAULT TRUE;
+ DECLARE vMandateTypeFk INT DEFAULT 2;
+
+ INSERT INTO `client` (
+ id,
+ name,
+ street,
+ fi,
+ phone,
+ email,
+ provinceFk,
+ city,
+ postcode,
+ socialName,
+ payMethodFk,
+ dueDay,
+ credit,
+ isTaxDataChecked,
+ hasCoreVnl,
+ isEqualizated)
+ VALUES (
+ vUserFk,
+ CONCAT('TR ', vFirstname, ' ', vSurnames),
+ vAddress,
+ TRIM(vFi),
+ vPhone,
+ vEmail,
+ vProvinceFk,
+ vCity,
+ vPostcode,
+ CONCAT(vSurnames, ' ', vFirstname),
+ vPayMethodFk,
+ vDueDay,
+ vDefaultCredit,
+ vIsTaxDataChecked,
+ vHasCoreVnl,
+ FALSE
+ ) ON duplicate key update
+ payMethodFk = vPayMethodFk,
+ dueDay = vDueDay,
+ credit = vDefaultCredit,
+ isTaxDataChecked = vIsTaxDataChecked,
+ hasCoreVnl = vHasCoreVnl,
+ isActive = TRUE;
+
+ IF (SELECT COUNT(*) FROM mandate WHERE clientFk = vUserFk AND companyFk = vCompanyFk AND mandateTypeFk = vMandateTypeFk) = 0 THEN
+ INSERT INTO mandate (clientFk, companyFk, mandateTypeFk)
+ VALUES (vUserFk, vCompanyFk, vMandateTypeFk);
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -53911,50 +52931,50 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `clientFreeze`()
-BEGIN
-/**
- * Congela diariamente aquellos clientes que son morosos sin recobro,
- * pero que no sean trabajadores,
- * y que el riesgo no sea menor que cero
- * hasta que no se gire la remesa no se congelan a los clientes de giro
- */
-
- DECLARE vIsRemittanced BOOLEAN;
-
- SELECT id into vIsRemittanced
- FROM receipt
- WHERE invoiceFk LIKE 'REMESA%'
- AND payed > util.firstDayOfMonth(CURDATE())
- limit 1;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
- CREATE TEMPORARY TABLE tmp.clientGetDebt
- SELECT clientFk
- FROM bs.defaulter
- WHERE created = CURDATE()
- AND amount;
-
- CALL clientGetDebt(CURDATE());
-
- UPDATE client c
- JOIN bi.defaulters d ON d.client = c.id AND d.date = CURDATE()
- JOIN config ON TRUE
- LEFT JOIN account.`user` u ON u.id = c.id AND u.active
- LEFT JOIN worker w ON w.id = u.id
- LEFT JOIN recovery r ON r.clientFk = c.id AND r.finished IS NULL
- LEFT JOIN payMethod pm ON pm.id = c.payMethodFk
- LEFT JOIN tmp.risk rk ON rk.clientFk = c.id
- SET c.isFreezed = TRUE,
- d.frozened = CURDATE(),
- u.active = FALSE
- WHERE (d.amount > config.defaultersMaxAmount
- AND rk.risk > 0)
- AND c.typeFk = 'normal'
- AND r.id IS NULL
- AND w.id IS NULL
- AND (vIsRemittanced OR pm.code <> 'bankDraft');
-
- DROP TEMPORARY TABLE tmp.clientGetDebt;
+BEGIN
+/**
+ * Congela diariamente aquellos clientes que son morosos sin recobro,
+ * pero que no sean trabajadores,
+ * y que el riesgo no sea menor que cero
+ * hasta que no se gire la remesa no se congelan a los clientes de giro
+ */
+
+ DECLARE vIsRemittanced BOOLEAN;
+
+ SELECT id into vIsRemittanced
+ FROM receipt
+ WHERE invoiceFk LIKE 'REMESA%'
+ AND payed > util.firstDayOfMonth(CURDATE())
+ limit 1;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
+ CREATE TEMPORARY TABLE tmp.clientGetDebt
+ SELECT clientFk
+ FROM bs.defaulter
+ WHERE created = CURDATE()
+ AND amount;
+
+ CALL clientGetDebt(CURDATE());
+
+ UPDATE client c
+ JOIN bi.defaulters d ON d.client = c.id AND d.date = CURDATE()
+ JOIN config ON TRUE
+ LEFT JOIN account.`user` u ON u.id = c.id AND u.active
+ LEFT JOIN worker w ON w.id = u.id
+ LEFT JOIN recovery r ON r.clientFk = c.id AND r.finished IS NULL
+ LEFT JOIN payMethod pm ON pm.id = c.payMethodFk
+ LEFT JOIN tmp.risk rk ON rk.clientFk = c.id
+ SET c.isFreezed = TRUE,
+ d.frozened = CURDATE(),
+ u.active = FALSE
+ WHERE (d.amount > config.defaultersMaxAmount
+ AND rk.risk > 0)
+ AND c.typeFk = 'normal'
+ AND r.id IS NULL
+ AND w.id IS NULL
+ AND (vIsRemittanced OR pm.code <> 'bankDraft');
+
+ DROP TEMPORARY TABLE tmp.clientGetDebt;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -53972,59 +52992,59 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `clientGetDebt`(vDate DATE)
-BEGIN
-/**
- * Calcula el riesgo para los clientes activos
- *
- * @table tmp.clientGetDebt(clientFk)
- * @param vDate Fecha maxima de los registros
- * @return tmp.risk
- */
- DECLARE vStarted DATETIME DEFAULT TIMESTAMPADD(DAY, -35, CURDATE());
- DECLARE vEnded DATETIME;
-
- SET vEnded = TIMESTAMP(IFNULL(vDate, CURDATE()), '23:59:59');
-
- DROP TEMPORARY TABLE IF EXISTS tClientRisk;
- CREATE TEMPORARY TABLE tClientRisk
- ENGINE = MEMORY
- SELECT cr.clientFk, SUM(cr.amount) amount
- FROM clientRisk cr
- JOIN tmp.clientGetDebt c ON c.clientFk = cr.clientFk
- GROUP BY cr.clientFk;
-
- INSERT INTO tClientRisk
- SELECT c.clientFk, SUM(r.amountPaid)
- FROM receipt r
- JOIN tmp.clientGetDebt c ON c.clientFk = r.clientFk
- WHERE r.payed > vEnded
- GROUP BY c.clientFk;
-
- INSERT INTO tClientRisk
- SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpvTransaction t
- JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk
- WHERE t.receiptFk IS NULL
- AND t.status = 'ok'
- GROUP BY t.clientFk;
-
- INSERT INTO tClientRisk
- SELECT t.clientFk, totalWithVat
- FROM ticket t
- JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk
- WHERE refFk IS NULL
- AND shipped BETWEEN vStarted AND vEnded;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.risk;
- CREATE TEMPORARY TABLE tmp.risk
- (PRIMARY KEY (clientFk))
- ENGINE = MEMORY
- SELECT clientFk, SUM(amount) risk
- FROM client c
- JOIN tClientRisk cr ON cr.clientFk = c.id
- GROUP BY c.id;
-
- DROP TEMPORARY TABLE tClientRisk;
+BEGIN
+/**
+ * Calcula el riesgo para los clientes activos
+ *
+ * @table tmp.clientGetDebt(clientFk)
+ * @param vDate Fecha maxima de los registros
+ * @return tmp.risk
+ */
+ DECLARE vStarted DATETIME DEFAULT TIMESTAMPADD(DAY, -35, CURDATE());
+ DECLARE vEnded DATETIME;
+
+ SET vEnded = TIMESTAMP(IFNULL(vDate, CURDATE()), '23:59:59');
+
+ DROP TEMPORARY TABLE IF EXISTS tClientRisk;
+ CREATE TEMPORARY TABLE tClientRisk
+ ENGINE = MEMORY
+ SELECT cr.clientFk, SUM(cr.amount) amount
+ FROM clientRisk cr
+ JOIN tmp.clientGetDebt c ON c.clientFk = cr.clientFk
+ GROUP BY cr.clientFk;
+
+ INSERT INTO tClientRisk
+ SELECT c.clientFk, SUM(r.amountPaid)
+ FROM receipt r
+ JOIN tmp.clientGetDebt c ON c.clientFk = r.clientFk
+ WHERE r.payed > vEnded
+ GROUP BY c.clientFk;
+
+ INSERT INTO tClientRisk
+ SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction t
+ JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk
+ WHERE t.receiptFk IS NULL
+ AND t.status = 'ok'
+ GROUP BY t.clientFk;
+
+ INSERT INTO tClientRisk
+ SELECT t.clientFk, totalWithVat
+ FROM ticket t
+ JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk
+ WHERE refFk IS NULL
+ AND shipped BETWEEN vStarted AND vEnded;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.risk;
+ CREATE TEMPORARY TABLE tmp.risk
+ (PRIMARY KEY (clientFk))
+ ENGINE = MEMORY
+ SELECT clientFk, SUM(amount) risk
+ FROM client c
+ JOIN tClientRisk cr ON cr.clientFk = c.id
+ GROUP BY c.id;
+
+ DROP TEMPORARY TABLE tClientRisk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -54375,7 +53395,7 @@ BEGIN
FROM vn.warehouse
WHERE hasConfectionTeam;
- CALL vn.ticketCreateWithUser(
+ CALL vn.ticket_add(
vClientFk
,CURDATE()
,vWarehouseFk -- Algemesi
@@ -54385,6 +53405,7 @@ BEGIN
,NULL -- route
,CURDATE()
,account.myUser_getId()
+ ,TRUE
,vNewTicket);
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price)
@@ -54825,7 +53846,12 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `cmr_getByTicket`(vTicketFk INT)
BEGIN
+
+ DECLARE vLandingDays INT;
+ SELECT landingDays INTO vLandingDays
+ FROM vn.cmrConfig;
+
IF vTicketFk THEN
IF (SELECT count(ticketFk) FROM vn.cmr WHERE ticketFk = vTicketFk) THEN
@@ -54834,8 +53860,8 @@ BEGIN
ELSE
- INSERT INTO vn.cmr(ticketFk, companyFk, addressFromFk, addressToFk, supplierFk)
- SELECT vTicketFk, t.companyFk, a.id, t.addressFk, ag.supplierFk
+ INSERT INTO vn.cmr(ticketFk, companyFk, addressFromFk, addressToFk, supplierFk, ead)
+ SELECT vTicketFk, t.companyFk, a.id, t.addressFk, ag.supplierFk, vLandingDays
FROM vn.ticket t
JOIN vn.agencyMode am ON am.id = t.agencyModeFk
JOIN vn.agency ag ON ag.id = am.agencyFk
@@ -54849,7 +53875,7 @@ BEGIN
ELSE
- INSERT INTO vn.cmr(created) VALUES(NOW());
+ INSERT INTO vn.cmr(created, ead) VALUES(NOW(), NOW() + INTERVAL vLandingDays DAY);
SELECT LAST_INSERT_ID();
@@ -54991,33 +54017,33 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `collectionOrTicket_printSticker`(vParam INT, vSectorFk INT)
-BEGIN
-
- /*Imprime una etiqueta amarilla a partir de una colección o ticket
- *
- * @param vParam colección o ticket a imprimir
- * @param vSectorFk id del sector
- */
-
- DECLARE vLabelReport INT;
-
- SELECT labelReportFk INTO vLabelReport
- FROM sector
- WHERE id = vSectorFk;
-
- IF vLabelReport THEN
-
- INSERT INTO ticketTrolley(ticket, labelCount)
- SELECT ticketFk, 1
- FROM ticketCollection
- WHERE collectionFk = vParam OR ticketFK = vParam
- ON DUPLICATE KEY UPDATE labelCount = labelCount + 1;
-
- INSERT INTO printServerQueue(labelReportFk, param1, workerFk)
- SELECT vLabelReport, vParam, getUser();
-
- END IF;
-
+BEGIN
+
+ /*Imprime una etiqueta amarilla a partir de una colección o ticket
+ *
+ * @param vParam colección o ticket a imprimir
+ * @param vSectorFk id del sector
+ */
+
+ DECLARE vLabelReport INT;
+
+ SELECT labelReportFk INTO vLabelReport
+ FROM sector
+ WHERE id = vSectorFk;
+
+ IF vLabelReport THEN
+
+ INSERT INTO ticketTrolley(ticket, labelCount)
+ SELECT ticketFk, 1
+ FROM ticketCollection
+ WHERE collectionFk = vParam OR ticketFK = vParam
+ ON DUPLICATE KEY UPDATE labelCount = labelCount + 1;
+
+ INSERT INTO printServerQueue(labelReportFk, param1, workerFk)
+ SELECT vLabelReport, vParam, getUser();
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -55284,54 +54310,6 @@ BEGIN
CALL vn.sale_calculateComponent(vSaleFk, null);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `collection_faults` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_faults`(
- vShelvingFk VARCHAR(10),
- vQuantity INT,
- vItemFk INT)
-BEGIN
- DECLARE vQuantityTotal INT DEFAULT 0;
- DECLARE vshelve VARCHAR(2);
- DECLARE vdeep INT(11);
- DECLARE vpriority INT(11);
- DECLARE vgrouping SMALLINT(5);
- DECLARE vpacking INT(11);
- DECLARE vpackagingFk VARCHAR(10);
- DECLARE vlevel VARCHAR(45);
- DECLARE vuserFk INT(10);
-
-
- SELECT SUM(quantity),shelve,deep,priority,`grouping`,packing,packagingFk,`level`,userFk
- INTO vQuantityTotal,vshelve,vdeep,vpriority,vgrouping,vpacking,vpackagingFk,vlevel,vuserFk
- FROM vn.itemShelving
- WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci AND itemFk = vItemFk
- GROUP BY itemFk;
-
- SELECT vQuantityTotal - vQuantity INTO vQuantityTotal;
-
- DELETE FROM vn.itemShelving WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci AND itemFk = vItemFk;
-
- INSERT INTO vn.itemShelving (itemFk, shelvingFk,shelve,deep,quantity,visible,available,priority,`grouping`,packing,packagingFk,`level`,userFk )
- VALUES (vItemFk,vShelvingFk,vshelve,vdeep,vQuantityTotal,vQuantityTotal,vQuantityTotal,vpriority,vgrouping,vpacking,vpackagingFk,vlevel,vuserFk );
-
- SELECT * FROM vn.itemShelving
- WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci AND itemFk = vItemFk;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -55458,20 +54436,20 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_get_`(vWorkerFk INT)
-BEGIN
-
- /* Obtiene colección del sacador si tiene líneas pendientes
- *
- * @param vWorkerFk id del worker
- */
-
- SELECT c.id AS collectionFk, date(c.created) AS created
- FROM vn.collection c
- LEFT JOIN vn.state s ON c.stateFk = s.id
- WHERE c.workerFk = vWorkerFk AND s.code = 'ON_PREPARATION'
- AND created >= TIMESTAMPADD(HOUR , -6,NOW());
-
-
+BEGIN
+
+ /* Obtiene colección del sacador si tiene líneas pendientes
+ *
+ * @param vWorkerFk id del worker
+ */
+
+ SELECT c.id AS collectionFk, date(c.created) AS created
+ FROM vn.collection c
+ LEFT JOIN vn.state s ON c.stateFk = s.id
+ WHERE c.workerFk = vWorkerFk AND s.code = 'ON_PREPARATION'
+ AND created >= TIMESTAMPADD(HOUR , -6,NOW());
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -55489,21 +54467,21 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_kill`(vSelf INT)
-BEGIN
-
- /* Elimina una coleccion y coloca sus tickets en OK
- *
- */
-
- INSERT INTO vncontrol.inter(state_id, Id_Ticket)
- SELECT s.id, ticketFk
- FROM vn.ticketCollection tc
- JOIN vn.state s ON s.code = 'OK'
- WHERE tc.collectionFk = vSelf;
-
- DELETE FROM vn.collection
- WHERE id = vSelf;
-
+BEGIN
+
+ /* Elimina una coleccion y coloca sus tickets en OK
+ *
+ */
+
+ INSERT INTO vncontrol.inter(state_id, Id_Ticket)
+ SELECT s.id, ticketFk
+ FROM vn.ticketCollection tc
+ JOIN vn.state s ON s.code = 'OK'
+ WHERE tc.collectionFk = vSelf;
+
+ DELETE FROM vn.collection
+ WHERE id = vSelf;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -55551,7 +54529,16 @@ BEGIN
WHERE c.id = vClientFk
LIMIT 1;
- CALL ticketCreateWithUser(vClientFk, NOW(), vWarehouseFk, 442, vConsignatario, NULL, NULL, NULL, account.userGetId(), vTicketFk);
+ CALL ticket_add(vClientFk,
+ NOW(), vWarehouseFk,
+ 442,
+ vConsignatario,
+ NULL,
+ NULL,
+ NULL,
+ account.userGetId(),
+ TRUE,
+ vTicketFk);
SELECT t.id INTO vTicketFk FROM vn.ticket t WHERE t.created > DATE_SUB(NOW(), INTERVAL 1 DAY) AND t.clientFk = vClientFk AND t.warehouseFk = vWarehouseFk LIMIT 1;
@@ -56125,19 +55112,24 @@ proc:BEGIN
DECLARE vMaxTicketPrinted INT;
DECLARE vItemPackingTypeFk VARCHAR(1);
DECLARE hasAssignedTickets BOOLEAN;
- DECLARE vMaxNotReadyCollections INT DEFAULT 0;
+ DECLARE vMaxNotReadyCollections INT;
DECLARE vNotReadyCollections INT;
DECLARE vTrainFk INT DEFAULT 1;
-
- /*IF NOT vn.deviceProductionUser_Exists(vn.getUser()) THEN
+ DECLARE vUserFk INT;
+ DECLARE vHourMatters BOOL DEFAULT TRUE;
+
+ SELECT pc.ticketPrintedMax * vWagons, pc.ticketTrolleyMax * vWagons, pc.maxNotReadyCollections
+ INTO vMaxTicketPrinted, vMaxTickets, vMaxNotReadyCollections
+ FROM vn.productionConfig pc;
+ /*IF NOT vn.deviceProductionUser_Exists(vUserFk) THEN
LEAVE proc;
END IF;*/
- SELECT w.code INTO vWorkerCode
+ SELECT w.code, w.id INTO vWorkerCode, vUserFk
FROM vn.worker w
- WHERE w.id = vn.getUser();
+ WHERE w.id =account.userGetId();
-- Establecemos el almacén y si es un sector de preparación previa, así como el estado para los tickets que se vayan preparando
SELECT isPreviousPrepared, warehouseFk, itemPackingTypeFk
@@ -56148,8 +55140,8 @@ proc:BEGIN
-- Si está habilitado el modo cazador para las motos, y el usuario no esta registrado, se sale.
IF (SELECT isTractorHuntingMode FROM vn.deviceProductionConfig dpc) AND vItemPackingTypeFk = 'H' THEN
- IF (SELECT COUNT(*) FROM vn.workerWithoutTractor wwt WHERE wwt.workerFk = account.userGetId()) THEN
- INSERT INTO tmp.kk(userFk) VALUES(vn.getUser());
+ IF (SELECT COUNT(*) FROM vn.workerWithoutTractor wwt WHERE wwt.workerFk = vUserFk) THEN
+ CALL util.throw('Usuario no registrado con moto');
LEAVE proc;
END IF;
END IF;
@@ -56157,23 +55149,29 @@ proc:BEGIN
-- Si hay colecciones sin terminar, sale del proceso
SELECT count(*) INTO vNotReadyCollections
- FROM vn.collection c
- WHERE c.workerFk = vn.getUser()
- AND c.saleTotalCount > c.salePickedCount + 1
- AND c.created > TIMESTAMPADD(HOUR , -5,NOW());
+ FROM (
+ SELECT count(DISTINCT s.id) totalRow, count(DISTINCT st.id) pickedRow
+ FROM vn.collection c
+ JOIN vn.ticketCollection tc ON tc.collectionFk = c.id
+ JOIN vn.sale s ON s.ticketFk = tc.ticketFk
+ JOIN vn.state ss ON ss.code = 'PREPARED'
+ LEFT JOIN vn.saleTracking st ON st.saleFk = s.id AND st.stateFk = ss.id
+ WHERE c.workerFk = vUserFk
+ AND c.created >= TIMESTAMPADD(HOUR , -6,NOW())
+ AND s.quantity != 0
+ GROUP BY c.id
+ HAVING totalRow > pickedRow) sub;
IF vMaxNotReadyCollections < vNotReadyCollections THEN
-
+
+ CALL util.throw('Hay colecciones pendientes');
LEAVE proc;
END IF;
- SELECT ticketPrintedMax * vWagons, ticketTrolleyMax * vWagons
- INTO vMaxTicketPrinted, vMaxTickets
- FROM vn.productionConfig pc;
-
IF vIsPreviousPrepared THEN
+ CALL util.throw('Es de preparación previa');
LEAVE proc; -- Hasta que tengamos el altillo, vamos a cancelar esta opcion
SELECT id INTO vStateFk
@@ -56194,6 +55192,8 @@ proc:BEGIN
SET vTrainFk = 2;
+ SET vHourMatters = FALSE;
+
DELETE pb.*
FROM tmp.productionBuffer pb
JOIN vn.volumeConfig vc
@@ -56203,7 +55203,7 @@ proc:BEGIN
-- Se obtiene nº de colección y el buffer con los pedidos preparables
INSERT INTO vn.collection
- SET workerFk = account.myUser_getId(),
+ SET workerFk = vUserFk,
itemPackingTypeFk = vItemPackingTypeFk,
trainFk = vTrainFk;
@@ -56283,7 +55283,7 @@ proc:BEGIN
AND (
(pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH))
OR (pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV))
- OR (pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
+ OR (pb.H = 0 AND pb.V = 0 AND pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
)
AND (pc.isPreviousPreparationRequired = FALSE
OR pb.previousWithoutParking = FALSE);
@@ -56293,7 +55293,7 @@ proc:BEGIN
-- AutoPRINT
INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
- SELECT s2.id, pb.ticketFk, vn.getUser()
+ SELECT s2.id, pb.ticketFk, vUserFk
FROM tmp.productionBuffer pb
JOIN vn.agencyMode am ON am.id = pb.agencyModeFk
JOIN vn.agency a ON a.id = am.agencyFk
@@ -56312,7 +55312,7 @@ proc:BEGIN
AND (
(pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH))
OR (pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV))
- OR (pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
+ OR (pb.H = 0 AND pb.V = 0 AND pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
)
AND t.created < TIMESTAMPADD(MINUTE, - tc.pickingDelay , NOW())
AND (pc.isPreviousPreparationRequired = FALSE
@@ -56338,7 +55338,7 @@ proc:BEGIN
WHERE (
(pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH))
OR (pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV))
- OR (pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
+ OR (pb.H = 0 AND pb.V = 0 AND pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
)
AND (pb.ubicacion IS NOT NULL
OR a.isOwn = FALSE )
@@ -56426,11 +55426,15 @@ proc:BEGIN
LIMIT 1;
-- Hay que excluir aquellos que no tengan la misma hora de preparación
- DELETE
- FROM tmp.ticket
- WHERE HH != vHour
- OR mm != vMinute;
+ IF vHourMatters THEN
+ DELETE
+ FROM tmp.ticket
+ WHERE HH != vHour
+ OR mm != vMinute;
+
+ END IF;
+
-- En el caso de pedidos de más volumen de un carro, la colección será monoticket. Pero si el primer pedido
-- no es monoticket, excluimos a los de más de un carro
IF (SELECT (t.shelveLiters > vc.trolleyM3 * 1000)
@@ -56632,7 +55636,7 @@ proc:BEGIN
-- Actualiza el estado de los tickets
INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
- SELECT vStateFk, ticketFk, account.myUser_getId()
+ SELECT vStateFk, ticketFk, vUserFk
FROM vn.ticketCollection tc
WHERE tc.collectionFk = vCollectionFk;
@@ -56662,6 +55666,7 @@ proc:BEGIN
ELSE
+ CALL util.throw('No ha sido posible obtener colección');
DELETE FROM vn.collection WHERE id = vCollectionFk;
END IF;
@@ -56671,7 +55676,8 @@ proc:BEGIN
tmp.ticketShelveLiters,
tmp.ticket,
tmp.wagonsVolumetry,
- tmp.ticketShelve;
+ tmp.ticketShelve,
+ tmp.productionBuffer;
END ;;
DELIMITER ;
@@ -56679,7 +55685,7 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `collection_reject` */;
+/*!50003 DROP PROCEDURE IF EXISTS `collection_newWithWagon_beta` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
@@ -56689,25 +55695,671 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_reject`(vSale INT, vQuantity INT)
+CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_newWithWagon_beta`(vUserFk INT, vSectorFk INT, vWagons INT)
+proc:BEGIN
+
+ DECLARE vIsPreviousPrepared BOOLEAN;
+ DECLARE vCollectionFk INT;
+ DECLARE vWarehouseFk INT;
+ DECLARE vMaxTickets INT;
+ DECLARE vStateFk INT;
+ DECLARE vFirstTicketFk INT;
+ DECLARE vHour INT;
+ DECLARE vMinute INT;
+ DECLARE vWorkerCode VARCHAR(3);
+ DECLARE vWagon INT;
+ DECLARE vWagonCounter INT;
+ DECLARE vShelve INT;
+ DECLARE vTicket INT;
+ DECLARE vTicketToSplit INT;
+ DECLARE vPrintedTickets INT;
+ DECLARE vMaxTicketPrinted INT;
+ DECLARE vItemPackingTypeFk VARCHAR(1);
+ DECLARE hasAssignedTickets BOOLEAN;
+ DECLARE vMaxNotReadyCollections INT DEFAULT 0;
+ DECLARE vNotReadyCollections INT;
+ DECLARE vTrainFk INT DEFAULT 1;
+ DECLARE vNow DATETIME;
+
+ SELECT ticketPrintedMax * vWagons, ticketTrolleyMax * vWagons, pc.maxNotReadyCollections , NOW()
+ INTO vMaxTicketPrinted, vMaxTickets, vMaxNotReadyCollections, vNow
+ FROM vn.productionConfig pc;
+
+ SELECT w.code INTO vWorkerCode
+ FROM vn.worker w
+ WHERE w.id = vUserFk;
+
+ -- Establecemos el almacén y si es un sector de preparación previa, así como el estado para los tickets que se vayan preparando
+ SELECT isPreviousPrepared, warehouseFk, itemPackingTypeFk
+ INTO vIsPreviousPrepared, vWarehouseFk, vItemPackingTypeFk
+ FROM vn.sector
+ WHERE id = vSectorFk; -- Hola
+
+-- Si está habilitado el modo cazador para las motos, y el usuario no esta registrado, se sale.
+
+ IF (SELECT isTractorHuntingMode FROM vn.deviceProductionConfig dpc) AND vItemPackingTypeFk = 'H' THEN
+ IF (SELECT COUNT(*) FROM vn.workerWithoutTractor wwt WHERE wwt.workerFk = vUserFk) THEN
+ CALL util.throw('Usuario no registrado con moto');
+ LEAVE proc;
+ END IF;
+ END IF;
+
+-- Si hay colecciones sin terminar, sale del proceso
+ SELECT count(*) INTO vNotReadyCollections
+ FROM (
+ SELECT count(DISTINCT s.id) totalRow, count(DISTINCT st.id) pickedRow
+ FROM vn.collection c
+ JOIN vn.ticketCollection tc ON tc.collectionFk = c.id
+ JOIN vn.sale s ON s.ticketFk = tc.ticketFk
+ JOIN vn.state ss ON ss.code = 'PREPARED'
+ LEFT JOIN vn.saleTracking st ON st.saleFk = s.id AND st.stateFk = ss.id
+ WHERE c.workerFk = vUserFk
+ AND c.created >= TIMESTAMPADD(HOUR , -6,NOW())
+ AND s.quantity != 0
+ GROUP BY c.id
+ HAVING totalRow > pickedRow) sub;
+
+call util.debugAdd('wargo',CONCAT('vMaxNotReadyCollections ', vMaxNotReadyCollections));
+call util.debugAdd('wargo',CONCAT('vNotReadyCollections ',vNotReadyCollections));
+
+ IF vMaxNotReadyCollections < vNotReadyCollections THEN
+
+ CALL util.throw('Hay colecciones pendientes');
+ LEAVE proc;
+
+ END IF;
+
+ IF vIsPreviousPrepared THEN
+
+ CALL util.throw('Es de preparación previa');
+ LEAVE proc; -- Hasta que tengamos el altillo, vamos a cancelar esta opcion
+
+ SELECT id INTO vStateFk
+ FROM vn.state
+ WHERE `code` = 'PREVIOUS_PREPARATION';
+
+ ELSE
+
+ SELECT id INTO vStateFk
+ FROM vn.state
+ WHERE `code` = 'ON_PREPARATION';
+
+ END IF;
+
+ CALL vn.productionControl(vWarehouseFk, 0);
+
+ -- Esto hay que corregirlo añadiendo un nuevo parámetro al proc. PAK 23/12/21
+ IF vSectorFk = 65 THEN -- Pedidos pequeños
+
+ SET vTrainFk = 2;
+
+ DELETE pb.*
+ FROM tmp.productionBuffer pb
+ JOIN vn.volumeConfig vc
+ WHERE pb.m3 * 1000 > vc.minTicketVolume;
+
+ END IF;
+
+ -- Se obtiene nº de colección y el buffer con los pedidos preparables
+ INSERT INTO vn.collection
+ SET workerFk = vUserFk,
+ itemPackingTypeFk = vItemPackingTypeFk,
+ trainFk = vTrainFk;
+
+ SELECT LAST_INSERT_ID() INTO vCollectionFk;
+
+ -- 05/08/2021 PAK Jose Frau pide que los tickets de recogida en Algemesí sólo se saquen si están asignados.
+ DELETE pb.*
+ FROM tmp.productionBuffer pb
+ JOIN vn.state s ON s.id = pb.state
+ WHERE pb.agency = 'REC_ALGEMESI'
+ AND s.code != 'PICKER_DESIGNED';
+
+ -- 2/3/2022 PAK Se acuerda con Pepe que los pedidos con riesgo no se sacan aunque se asignen.
+ DELETE pb.*
+ FROM tmp.productionBuffer pb
+ WHERE pb.problem LIKE '%RIESGO%';
+
+ -- Comprobamos si hay tickets asignados. En ese caso, nos centramos exclusivamente en esos tickets
+ -- y los sacamos independientemente de problemas o tamaños
+ SELECT COUNT(*) INTO hasAssignedTickets
+ FROM tmp.productionBuffer pb
+ JOIN vn.state s ON s.id = pb.state
+ WHERE s.code = 'PICKER_DESIGNED'
+ AND pb.workerCode = vWorkerCode;
+
+ IF hasAssignedTickets THEN
+
+ UPDATE vn.collection
+ SET itemPackingTypeFk = NULL
+ WHERE id = vCollectionFk;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit;
+ CREATE TEMPORARY TABLE tmp.ticketToSplit
+ SELECT pb.ticketFk
+ FROM tmp.productionBuffer pb
+ JOIN vn.state s ON s.id = pb.state
+ WHERE s.code = 'PICKER_DESIGNED'
+ AND pb.workerCode = vWorkerCode
+ ORDER BY HH,
+ mm,
+ s.`order` DESC,
+ pb.m3 DESC;
+
+ WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO
+
+ SELECT MIN(ticketFk) INTO vTicketToSplit
+ FROM tmp.ticketToSplit;
+
+ CALL vn.ticket_splitItemPackingType(vTicketToSplit);
+
+ INSERT INTO vn.ticketCollection(ticketFk, collectionFk)
+ SELECT ticketFk, vCollectionFk
+ FROM tmp.ticketIPT
+ WHERE (itemPackingTypeFk = vItemPackingTypeFk) ;
+
+ DELETE FROM tmp.ticketToSplit
+ WHERE ticketFk = vTicketToSplit;
+
+ DROP TEMPORARY TABLE tmp.ticketIPT;
+
+ END WHILE;
+
+ CALL vn.productionControl(vWarehouseFk, 0);
+
+ ELSE
+
+ SELECT COUNT(*) INTO vPrintedTickets
+ FROM tmp.productionBuffer pb
+ JOIN vn.state s ON s.id = pb.state
+ JOIN vn.agencyMode am ON am.id = pb.agencyModeFk
+ JOIN vn.agency a ON a.id = am.agencyFk
+ JOIN vn.productionConfig pc
+ WHERE pb.shipped = CURDATE()
+ AND (pb.ubicacion IS NOT NULL
+ OR a.isOwn = FALSE )
+ AND s.isPreparable
+ AND (
+ (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH))
+ OR (pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV))
+ OR (pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
+ )
+ AND (pc.isPreviousPreparationRequired = FALSE
+ OR pb.previousWithoutParking = FALSE);
+
+call util.debugAdd('wargo',CONCAT('vMaxTicketPrinted ', vMaxTicketPrinted));
+call util.debugAdd('wargo',CONCAT('vPrintedTickets ',vPrintedTickets));
+
+ SET vMaxTicketPrinted = vMaxTicketPrinted - vPrintedTickets;
+
+ -- AutoPRINT
+
+ INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
+ SELECT s2.id, pb.ticketFk, vUserFk
+ FROM tmp.productionBuffer pb
+ JOIN vn.agencyMode am ON am.id = pb.agencyModeFk
+ JOIN vn.agency a ON a.id = am.agencyFk
+ JOIN vn.state s ON s.id = pb.state
+ JOIN vn.state s2 ON s2.code = 'PRINTED_AUTO'
+ JOIN vn.ticket t ON t.id = pb.ticketFk
+ JOIN vn.ticketConfig tc
+ JOIN vn.productionConfig pc
+ WHERE pb.shipped = CURDATE()
+ AND (LENGTH(pb.problem) = 0
+ OR (pb.problem = 'PEQUEÑO' AND vTrainFk = 2))
+ AND (pb.ubicacion IS NOT NULL
+ OR a.isOwn = FALSE )
+ AND s.isPrintable
+ AND s.isOK
+ AND (
+ (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH))
+ OR (pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV))
+ OR (pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
+ )
+ AND t.created < TIMESTAMPADD(MINUTE, - tc.pickingDelay , NOW())
+ AND (pc.isPreviousPreparationRequired = FALSE
+ OR pb.previousWithoutParking = FALSE)
+ ORDER BY HH,
+ mm,
+ s.`order` DESC,
+ pb.m3 DESC
+ LIMIT vMaxTicketPrinted;
+
+ -- Se seleccionan los primeros tickets, asignando colección para dejarlos bloqueados a otros sacadores.
+ -- Se splitan los tickets preparables, para que solo tengan un tipo de empaquetado
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit;
+ CREATE TEMPORARY TABLE tmp.ticketToSplit
+ SELECT pb.ticketFk, IFNULL((pb.H + pb.V = 0),TRUE) isNeutral
+ FROM tmp.productionBuffer pb
+ JOIN vn.agencyMode am ON am.id = pb.agencyModeFk
+ JOIN vn.agency a ON a.id = am.agencyFk
+ JOIN vn.ticketStateToday tst ON tst.ticket = pb.ticketFk
+ JOIN vn.state s ON s.id = tst.state
+ JOIN vn.productionConfig pc
+ WHERE (
+ (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH))
+ OR (pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV))
+ OR (pb.H = 0 AND pb.V = 0 AND pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV))
+ )
+ AND (pb.ubicacion IS NOT NULL
+ OR a.isOwn = FALSE )
+ AND LENGTH(pb.problem) = 0
+ AND s.isPreparable
+ AND (pc.isPreviousPreparationRequired = FALSE
+ OR pb.previousWithoutParking = FALSE)
+ ORDER BY pb.HH, pb.mm, s.`order` DESC
+ LIMIT vMaxTickets;
+
+call util.debugAdd('wargo',CONCAT('tmp.ticketToSplit ', (SELECT COUNT(*) FROM tmp.ticketToSplit)));
+
+ WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO
+
+ SELECT MIN(ticketFk) INTO vTicketToSplit
+ FROM tmp.ticketToSplit;
+
+
+ IF (SELECT isNeutral
+ FROM tmp.ticketToSplit
+ WHERE ticketFk = vTicketToSplit) THEN
+
+ INSERT INTO vn.ticketCollection(ticketFk, collectionFk)
+ VALUES(vTicketToSplit, vCollectionFk);
+
+call util.debugAdd('wargo',CONCAT('neutral ', vTicketToSplit));
+
+ ELSE
+
+ CALL vn.ticket_splitItemPackingType(vTicketToSplit);
+
+ INSERT INTO vn.ticketCollection(ticketFk, collectionFk)
+ SELECT ticketFk, vCollectionFk
+ FROM tmp.ticketIPT
+ WHERE itemPackingTypeFk = vItemPackingTypeFk;
+
+call util.debugAdd('wargo',CONCAT('NO neutral ',
+ (SELECT ticketFk FROM tmp.ticketIPT WHERE itemPackingTypeFk = vItemPackingTypeFk)));
+
+ DROP TEMPORARY TABLE tmp.ticketIPT;
+
+ END IF;
+
+ DELETE FROM tmp.ticketToSplit
+ WHERE ticketFk = vTicketToSplit;
+
+ END WHILE;
+
+ END IF;
+
+call util.debugAdd('wargo',CONCAT('vn.ticketCollection ',
+ (SELECT COUNT(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk)));
+
+ -- Creamos una tabla temporal con los datos que necesitamos para depurar la colección
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ SELECT pb.ticketFk,
+ pb.`lines`,
+ pb.m3 * 1000 liters,
+ 0 as height,
+ 0 as shelve,
+ 0 as wagon,
+ 0 AS shelveLiters,
+ pb.productionOrder,
+ pb.HH,
+ pb.mm
+ FROM tmp.productionBuffer pb
+ JOIN vn.ticketCollection tc ON tc.ticketFk = pb.ticketFk
+ WHERE tc.collectionFk = vCollectionFk
+ LIMIT vMaxTickets;
+
+ -- Voumen de las lineas de los pedidos, de acuerdo con el packingShelve establecido por los controladores
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketShelveLiters;
+ CREATE TEMPORARY TABLE tmp.ticketShelveLiters
+ SELECT t.ticketFk, SUM(s.quantity * vc.shelveVolume / i.packingShelve) shelveLiters
+ FROM tmp.ticket t
+ JOIN vn.sale s ON s.ticketFk = t.ticketFk
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.volumeConfig vc
+ WHERE i.packingShelve
+ GROUP BY t.ticketFk;
+
+ UPDATE tmp.ticket t
+ JOIN tmp.ticketShelveLiters tsl ON tsl.ticketFk = t.ticketFk
+ SET t.shelveLiters = tsl.shelveLiters;
+
+ -- Es importante que el primer ticket se coja en todos los casos
+
+ SET vFirstTicketFk = 0;
+
+ SELECT ticketFk, HH, mm
+ INTO vFirstTicketFk, vHour, vMinute
+ FROM tmp.ticket
+ ORDER BY productionOrder DESC, HH, mm
+ LIMIT 1;
+
+call util.debugAdd('wargo',CONCAT('vFirstTicketFk ', vFirstTicketFk));
+call util.debugAdd('wargo',CONCAT('vHour ', vHour));
+call util.debugAdd('wargo',CONCAT('vMinute ', vMinute));
+
+call util.debugAdd('wargo',CONCAT('tmp.ticket ', (SELECT COUNT(*) FROM tmp.ticket)));
+
+ -- Hay que excluir aquellos que no tengan la misma hora de preparación
+ DELETE
+ FROM tmp.ticket
+ WHERE HH != vHour
+ OR mm != vMinute;
+
+call util.debugAdd('wargo',CONCAT('tmp.ticket misma hora ', (SELECT COUNT(*) FROM tmp.ticket)));
+
+ -- En el caso de pedidos de más volumen de un carro, la colección será monoticket. Pero si el primer pedido
+ -- no es monoticket, excluimos a los de más de un carro
+ IF (SELECT (t.shelveLiters > vc.trolleyM3 * 1000)
+ FROM tmp.ticket t
+ JOIN vn.volumeConfig vc
+ WHERE t.ticketFk = vFirstTicketFk) THEN
+
+ DELETE
+ FROM tmp.ticket
+ WHERE ticketFk != vFirstTicketFk;
+
+ ELSE
+
+ DELETE t.*
+ FROM tmp.ticket t
+ JOIN vn.volumeConfig vc
+ WHERE t.shelveLiters > vc.trolleyM3 * 1000;
+
+ END IF;
+
+call util.debugAdd('wargo',CONCAT('tmp.ticket volumen ', (SELECT COUNT(*) FROM tmp.ticket)));
+
+ -- Elimina los tickets bloqueados que no se van a preparar
+ DELETE tc.*
+ FROM vn.ticketCollection tc
+ LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk
+ WHERE tc.collectionFk = vCollectionFk
+ AND t.ticketFk IS NULL;
+
+call util.debugAdd('wargo',CONCAT('vn.ticketCollection ',
+ (SELECT COUNT(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk)));
+
+ -- Construccion del tren
+
+ -- Establece altura máxima por pedido, porque las plantas no se pueden recostar.
+ UPDATE tmp.ticket t
+ JOIN
+ ( SELECT MAX(i.size) maxHeigth,
+ tc.ticketFk
+ FROM vn.ticketCollection tc
+ JOIN vn.sale s ON s.ticketFk = tc.ticketFk
+ JOIN vn.item i ON i.id = s.itemFk
+ WHERE i.itemPackingTypeFk = 'V'
+ AND tc.collectionFk = vCollectionFk
+ GROUP BY tc.ticketFk) sub ON sub.ticketFk = t.ticketFk
+ SET t.height = IFNULL(sub.maxHeigth,0);
+
+ -- Vamos a generar una tabla con todas las posibilidades de asignacion de pedido
+ DROP TEMPORARY TABLE IF EXISTS tmp.wagonsVolumetry;
+ CREATE TEMPORARY TABLE tmp.wagonsVolumetry
+ SELECT cv.`level` as shelve,
+ 1 as wagon,
+ cv.`lines`,
+ cv.liters,
+ cv.height
+ FROM vn.collectionVolumetry cv
+ WHERE cv.itemPackingTypeFk = IFNULL(vItemPackingTypeFk, 'H')
+ AND cv.trainFk = vTrainFk;
+
+ SET vWagonCounter = 1;
+
+ WHILE vWagonCounter < vWagons DO
+
+ SET vWagonCounter = vWagonCounter + 1;
+
+ INSERT INTO tmp.wagonsVolumetry(shelve, wagon, `lines`, liters, height)
+ SELECT cv.`level` as shelve,
+ vWagonCounter as wagon,
+ cv.`lines`,
+ cv.liters,
+ cv.height
+ FROM vn.collectionVolumetry cv
+ WHERE cv.itemPackingTypeFk = IFNULL(vItemPackingTypeFk, 'H')
+ AND cv.trainFk = vTrainFk;
+
+ END WHILE;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketShelve;
+ CREATE TEMPORARY TABLE tmp.ticketShelve
+ SELECT ticketFk, shelve, wagon, linesDif, LitersDif, heightDif
+ FROM (
+ SELECT t.ticketFk,
+ wv.shelve,
+ wv.wagon,
+ t.productionOrder,
+ CAST(wv.`lines` AS SIGNED) - t.`lines` as linesDif,
+ CAST(wv.liters AS SIGNED) - t.shelveLiters as litersDif,
+ CAST(wv.height AS SIGNED) - t.height as heightDif
+ FROM tmp.wagonsVolumetry wv
+ JOIN tmp.ticket t
+ ) sub
+ WHERE linesDif >= 0
+ AND litersDif >= 0
+ AND heightDif >= 0
+ ORDER BY productionOrder DESC, linesDif, LitersDif, heightDif ;
+
+ -- Insertamos una opcion virtual para carro completo. Todo ticket tiene que poder entrar en un carro completo....
+ INSERT INTO tmp.ticketShelve(ticketFk, shelve, wagon, linesDif, LitersDif, heightDif)
+ SELECT t.ticketFk, 0, wv.wagon, 999, 999,999
+ FROM tmp.ticket t
+ JOIN tmp.wagonsVolumetry wv
+ GROUP BY t.ticketFk, wv.wagon;
+
+ SET vWagonCounter = 0;
+
+ WHILE vWagonCounter < vWagons DO
+
+ SET vWagonCounter = vWagonCounter + 1;
+
+ -- Asignamos la primera balda util al primer pedido
+ IF vWagonCounter = 1 THEN
+
+ SELECT shelve INTO vShelve
+ FROM tmp.ticketShelve
+ WHERE ticketFk = vFirstTicketFk
+ AND wagon = vWagonCounter
+ ORDER BY heightDif, litersDif, linesDif
+ LIMIT 1;
+
+ ELSE
+
+ SELECT shelve, ticketFk INTO vShelve, vFirstTicketFk
+ FROM tmp.ticketShelve
+ WHERE wagon = vWagonCounter
+ ORDER BY heightDif, litersDif, linesDif
+ LIMIT 1;
+
+ END IF;
+
+ IF vShelve > 0 THEN
+
+ UPDATE tmp.ticket
+ SET shelve = vShelve,
+ wagon = vWagonCounter
+ WHERE ticketFk = vFirstTicketFk;
+
+ DELETE FROM tmp.ticketShelve
+ WHERE ticketFk = vFirstTicketFk
+ OR (shelve = vShelve AND wagon = vWagonCounter);
+
+ WHILE (SELECT COUNT(*) FROM tmp.ticketShelve WHERE wagon = vWagonCounter) DO
+
+ SELECT ticketFk, shelve
+ INTO vTicket, vShelve
+ FROM tmp.ticketShelve
+ WHERE wagon = vWagonCounter
+ LIMIT 1;
+
+ UPDATE tmp.ticket
+ SET shelve = vShelve,
+ wagon = vWagonCounter
+ WHERE ticketFk = vTicket;
+
+ DELETE FROM tmp.ticketShelve
+ WHERE ticketFk = vTicket
+ OR (shelve = vShelve AND wagon = vWagonCounter);
+
+ END WHILE;
+
+ ELSE
+
+ UPDATE tmp.ticket
+ SET shelve = 1, wagon = vWagonCounter
+ WHERE ticketFk = vFirstTicketFk;
+
+ DELETE FROM tmp.ticketShelve
+ WHERE ticketFk = vFirstTicketFk
+ AND wagon != vWagonCounter;
+
+ END IF;
+
+ END WHILE;
+
+ -- Eliminamos los que se han quedado sin balda
+ DELETE FROM tmp.ticket WHERE shelve = 0;
+
+ -- Elimina los tickets bloqueados que no se van a preparar
+ DELETE tc.*
+ FROM vn.ticketCollection tc
+ LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk
+ WHERE tc.collectionFk = vCollectionFk
+ AND t.ticketFk IS NULL;
+
+call util.debugAdd('wargo',CONCAT('vn.ticketCollection bloqueados ',
+ (SELECT COUNT(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk)));
+
+ -- Elimina los tickets que ya estan en otra coleccion
+ DELETE tc.*
+ FROM vn.ticketCollection tc
+ JOIN vn.ticketCollection tc2 ON tc2.ticketFk = tc.ticketFk
+ WHERE tc.collectionFk = vCollectionFk
+ AND tc2.collectionFk != vCollectionFk;
+
+call util.debugAdd('wargo',CONCAT('vn.ticketCollection otra coleccion ',
+ (SELECT COUNT(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk)));
+
+ -- Actualiza el estado de la colección
+ UPDATE vn.collection c
+ JOIN vn.state st ON st.code = 'ON_PREPARATION'
+ SET c.stateFk = st.id
+ WHERE c.id = vCollectionFk;
+
+ -- Asigna las bandejas
+ UPDATE vn.ticketCollection tc
+ JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk
+ SET tc.level = t.shelve,
+ tc.wagon = t.wagon,
+ tc.itemCount = t.`lines`,
+ tc.liters = t.shelveLiters;
+
+ -- Actualiza el estado de los tickets
+ INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
+ SELECT vStateFk, ticketFk, vUserFk
+ FROM vn.ticketCollection tc
+ WHERE tc.collectionFk = vCollectionFk;
+
+ -- Aviso para la preparacion previa
+ INSERT INTO vn.ticketDown(ticketFk, collectionFk)
+ SELECT tc.ticketFk, tc.collectionFk
+ FROM vn.ticketCollection tc
+ WHERE tc.collectionFk = vCollectionFk;
+
+ SELECT * FROM util.debug
+ where variable = 'wargo'
+ and created >= vNow
+ order by created;
+
+ IF (SELECT count(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk) THEN
+
+ CALL vn.salesMerge_byCollection(vCollectionFk);
+
+ UPDATE vn.collection c
+ JOIN (SELECT count(*) saleTotalCount ,
+ sum(s.isPicked != 0) salePickedCount
+ FROM vn.ticketCollection tc
+ JOIN vn.sale s ON s.ticketFk = tc.ticketFk
+ WHERE tc.collectionFk = vCollectionFk
+ AND s.quantity > 0
+ ) sub
+ SET c.saleTotalCount = sub.saleTotalCount,
+ c.salePickedCount = sub.salePickedCount
+ WHERE c.id = vCollectionFk;
+
+ SELECT vCollectionFk;
+
+ ELSE
+
+ DELETE FROM vn.collection WHERE id = vCollectionFk;
+
+ CALL util.throw('No se ha obtenido colección');
+
+ END IF;
+
+ DROP TEMPORARY TABLE
+ tmp.ticketToSplit,
+ tmp.ticketShelveLiters,
+ tmp.ticket,
+ tmp.wagonsVolumetry,
+ tmp.ticketShelve,
+ tmp.productionBuffer;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `collection_printSticker` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_printSticker`(vCollection INT)
BEGIN
-
- DECLARE vDescription VARCHAR(100);
- DECLARE vOriginalQuantity INT;
- DECLARE vConcept VARCHAR(100);
- DECLARE vOrigin INT;
- SELECT concept INTO vConcept FROM sale WHERE id = vSale;
- SELECT ticketFk INTO vOrigin FROM sale WHERE id = vSale;
- SELECT quantity INTO vOriginalQuantity FROM sale WHERE id = vSale;
- SELECT CONCAT("Cambio cantidad ",vConcept," de ", vOriginalQuantity," a ", vQuantity) INTO vDescription;
+ /*Imprime una etiqueta amarilla a partir de una colección
+ *
+ * @param vCollection colección
+ * @param vPrinterFk id de la impresora
+ */
- INSERT INTO ticketLog (originFk, userFk, action , description)
- VALUES(vOrigin, getUser(), 'update', vDescription);
+ DECLARE vLabelReportFk INT;
+ DECLARE vLabelerFk INT;
- UPDATE sale SET originalQuantity = vOriginalQuantity, quantity = vQuantity WHERE id = vSale;
+ SELECT s.labelReportFk, w.labelerFk INTO vLabelReportFk, vLabelerFk
+ FROM worker w
+ LEFT JOIN sector s ON s.id= w.sectorFk
+ WHERE w.id=account.myUser_getId() ;
+
+ IF vLabelReportFk AND vLabelerFk THEN
+
+ INSERT INTO ticketTrolley(ticket, labelCount)
+ SELECT ticketFk, 1
+ FROM ticketCollection
+ WHERE collectionFk = vCollection
+ ON DUPLICATE KEY UPDATE labelCount = labelCount + 1;
+
+ INSERT INTO printServerQueue(labelReportFk, param1, workerFk,printerFk)
+ SELECT vLabelReportFk, vCollection, getUser(),vLabelerFk;
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -56776,27 +56428,27 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `company_getFiscaldata`(workerFk INT)
-BEGIN
-
-DECLARE vCompanyFk INT;
-
- SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk)
- INTO vCompanyFk
- FROM vn.routeConfig rc
- LEFT JOIN userConfig uc ON uc.userFk = workerFk;
-
-
- SELECT
- s.name AS name ,
- s.NIF AS nif ,
- s.street AS street ,
- s.city AS city ,
- s.postCode AS postCode
-
- FROM vn.company c
- JOIN vn.worker w ON w.id = c.workerManagerFk
- JOIN vn.supplier s ON s.id = c.id
- WHERE c.id = vCompanyFk;
+BEGIN
+
+DECLARE vCompanyFk INT;
+
+ SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk)
+ INTO vCompanyFk
+ FROM vn.routeConfig rc
+ LEFT JOIN userConfig uc ON uc.userFk = workerFk;
+
+
+ SELECT
+ s.name AS name ,
+ s.NIF AS nif ,
+ s.street AS street ,
+ s.city AS city ,
+ s.postCode AS postCode
+
+ FROM vn.company c
+ JOIN vn.worker w ON w.id = c.workerManagerFk
+ JOIN vn.supplier s ON s.id = c.id
+ WHERE c.id = vCompanyFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -57449,18 +57101,18 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `department_getHasMistake`()
-BEGIN
-
-/**
- * Obtiene los sectores a los cuales les ponemos errores
- *
- */
-
- SELECT id, name
- FROM department
- WHERE hasToMistake <> FALSE;
-
-
+BEGIN
+
+/**
+ * Obtiene los sectores a los cuales les ponemos errores
+ *
+ */
+
+ SELECT id, name
+ FROM department
+ WHERE hasToMistake <> FALSE;
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -57569,18 +57221,18 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `deviceLog_add`(vWorkerFk INT, vAppName VARCHAR(45), vAppVersion VARCHAR(45), vAndroid_id VARCHAR(100))
-BEGIN
-/*
- * Inserta registro en tabla devicelog el log del usuario conectado
- * @param vAppName es el nombre de la app
- * @param vAppVersion es la versión de la app
- * @param vAndroid_id es el android_id del dispositivo que se ha logueado
- */
-
- INSERT INTO deviceLog (userFK, nameApp, versionApp, android_id)
- VALUES(vWorkerFk, vAppName, vAppVersion, vAndroid_id);
-
-
+BEGIN
+/*
+ * Inserta registro en tabla devicelog el log del usuario conectado
+ * @param vAppName es el nombre de la app
+ * @param vAppVersion es la versión de la app
+ * @param vAndroid_id es el android_id del dispositivo que se ha logueado
+ */
+
+ INSERT INTO deviceLog (userFK, nameApp, versionApp, android_id)
+ VALUES(vWorkerFk, vAppName, vAppVersion, vAndroid_id);
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -57622,19 +57274,19 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `deviceProductionUser_getWorker`(vAndroid_id VARCHAR(50))
-BEGIN
-/**
- * Selecciona si hay registrado un device con un android_id
- *
- * @param vAndroid_id el número android_id del dispositivo
- *
- */
- SELECT 103;
-/* SELECT account.user_getNameFromId(dpu.userFk)
- FROM deviceProductionUser dpu
- JOIN deviceProduction dp ON dpu.deviceProductionFk = dp.id
- WHERE dp.android_id = vAndroid_id;*/
-
+BEGIN
+/**
+ * Selecciona si hay registrado un device con un android_id
+ *
+ * @param vAndroid_id el número android_id del dispositivo
+ *
+ */
+ SELECT 103;
+/* SELECT account.user_getNameFromId(dpu.userFk)
+ FROM deviceProductionUser dpu
+ JOIN deviceProduction dp ON dpu.deviceProductionFk = dp.id
+ WHERE dp.android_id = vAndroid_id;*/
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -57652,18 +57304,18 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `deviceProduction_getnameDevice`(vAndroid_id VARCHAR(50))
-BEGIN
-/**
- * Selecciona el id del dispositivo que corresponde al vAndroid_id
- *
- * @param vAndroid_id el número android_id del dispositivo
- *
- */
-
- SELECT dp.id
- FROM deviceProduction dp
- WHERE dp.android_id = vAndroid_id;
-
+BEGIN
+/**
+ * Selecciona el id del dispositivo que corresponde al vAndroid_id
+ *
+ * @param vAndroid_id el número android_id del dispositivo
+ *
+ */
+
+ SELECT dp.id
+ FROM deviceProduction dp
+ WHERE dp.android_id = vAndroid_id;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -58485,15 +58137,15 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ediTables_Update`()
-BEGIN
-
- INSERT IGNORE INTO vn.genus(name)
- SELECT latin_genus_name
- FROM edi.genus ;
-
- INSERT IGNORE INTO vn.specie(name)
- SELECT LCASE(latin_species_name)
- FROM edi.specie ;
+BEGIN
+
+ INSERT IGNORE INTO vn.genus(name)
+ SELECT latin_genus_name
+ FROM edi.genus ;
+
+ INSERT IGNORE INTO vn.specie(name)
+ SELECT LCASE(latin_species_name)
+ FROM edi.specie ;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -58636,65 +58288,65 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_add__`(vPutOrderFk INT)
-BEGIN
-
-/**
- * Añade ekt para las ordenes de compra de proveedores que no envian el ekt por email
- *
- * @param vPutOrderFk PutOrderId de donde coger los datos
- **/
-
- INSERT INTO edi.ekt(entryYear,
- deliveryNumber,
- fec,
- hor,
- item,
- pac,
- qty,
- ori,
- cat,
- pro,
- pri,
- package,
- s1,
- s2,
- s3,
- s4,
- s5,
- s6,
- putOrderFk,
- `ref`,
- kop)
- SELECT year(curdate()) entryYear,
- p.id deliveryNumber ,
- CURDATE() fec,
- CURTIME() hor,
- i.longName item,
- sr.NumberOfItemsPerCask pac,
- p.quantity qty,
- o.code ori,
- i.category cat,
- mp.supplierFk pro,
- sr.Price pri,
- sr.EmbalageCode package,
- i.value5 s1,
- i.value6 s2,
- i.value7 s3,
- i.value8 s4,
- i.value9 s5,
- i.value10 s6,
- p.id putOrderFk,
- sr.Item_ArticleCode,
- sr.vmpID
- FROM edi.putOrder p
- JOIN edi.supplyResponse sr ON sr.ID = p.supplyResponseID
- JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID
- JOIN vn.item i ON i.supplyResponseFk = sr.ID
- JOIN vn.origin o ON o.id = i.originFk
- WHERE p.id = vPutOrderFk;
-
- CALL edi.ekt_load(LAST_INSERT_ID());
-
+BEGIN
+
+/**
+ * Añade ekt para las ordenes de compra de proveedores que no envian el ekt por email
+ *
+ * @param vPutOrderFk PutOrderId de donde coger los datos
+ **/
+
+ INSERT INTO edi.ekt(entryYear,
+ deliveryNumber,
+ fec,
+ hor,
+ item,
+ pac,
+ qty,
+ ori,
+ cat,
+ pro,
+ pri,
+ package,
+ s1,
+ s2,
+ s3,
+ s4,
+ s5,
+ s6,
+ putOrderFk,
+ `ref`,
+ kop)
+ SELECT year(curdate()) entryYear,
+ p.id deliveryNumber ,
+ CURDATE() fec,
+ CURTIME() hor,
+ i.longName item,
+ sr.NumberOfItemsPerCask pac,
+ p.quantity qty,
+ o.code ori,
+ i.category cat,
+ mp.supplierFk pro,
+ sr.Price pri,
+ sr.EmbalageCode package,
+ i.value5 s1,
+ i.value6 s2,
+ i.value7 s3,
+ i.value8 s4,
+ i.value9 s5,
+ i.value10 s6,
+ p.id putOrderFk,
+ sr.Item_ArticleCode,
+ sr.vmpID
+ FROM edi.putOrder p
+ JOIN edi.supplyResponse sr ON sr.ID = p.supplyResponseID
+ JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID
+ JOIN vn.item i ON i.supplyResponseFk = sr.ID
+ JOIN vn.origin o ON o.id = i.originFk
+ WHERE p.id = vPutOrderFk;
+
+ CALL edi.ekt_load(LAST_INSERT_ID());
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -58745,216 +58397,216 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entryConverter__`(IN `vEntry` INT)
-BEGIN
-
- DECLARE vWarehouseIn INT;
- DECLARE vWarehouseOut INT;
- DECLARE vTravel INT;
-
- DECLARE done BOOL DEFAULT FALSE;
-
- DECLARE vId_Entrada INT;
- DECLARE vId_Article INT;
- DECLARE vEtiquetas INT;
- DECLARE vId_Cubo VARCHAR(10);
- DECLARE vPacking INT;
- DECLARE vGrouping INT;
- DECLARE vCantidad INT;
- DECLARE vCostefijo DECIMAL(10,3);
- DECLARE vPortefijo DECIMAL(10,3);
- DECLARE vEmbalajefijo DECIMAL(10);
- DECLARE vComisionfija DECIMAL(10,3);
- DECLARE vCaja INT;
- DECLARE vNicho VARCHAR(5);
- DECLARE vTarifa1 DECIMAL(10,2);
- DECLARE vTarifa2 DECIMAL(10,2);
- DECLARE vTarifa3 DECIMAL(10,2);
- DECLARE vPVP DECIMAL(10,2);
- DECLARE vCompra INT;
-
- DECLARE rs CURSOR FOR
- SELECT
- b.Id_Entrada,
- b.Id_Article,
- b.Etiquetas,
- b.Id_Cubo,
- b.Packing,
- b.`grouping`,
- b.Cantidad,
- b.Costefijo,
- b.Portefijo,
- b.Embalajefijo,
- b.Comisionfija,
- b.caja,
- b.Nicho,
- b.Tarifa1,
- b.Tarifa2,
- b.Tarifa3,
- b.PVP
- FROM vn2008.Compres b
- JOIN vn.itemConversor ic ON ic.espItemFk = b.Id_Article
- WHERE Id_Entrada = vEntry;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- SELECT warehouseInFk, warehouseOutFk, tr.id
- INTO vWarehouseIn, vWarehouseOut, vTravel
- FROM travel tr
- JOIN entry e ON e.travelFk = tr.id
- WHERE e.id = vEntry;
-
- UPDATE travel
- SET warehouseInFk = vWarehouseOut,
- warehouseOutFk = vWarehouseIn
- WHERE id = vTravel;
-
- UPDATE vn2008.Compres c
- LEFT JOIN vn.itemConversor ic ON ic.espItemFk = c.Id_Article
- SET Etiquetas = 0, Cantidad = 0
- WHERE c.Id_Entrada = vEntry
- AND ic.espItemFk IS NULL;
-
- OPEN rs;
-
- DELETE FROM vn2008.Compres WHERE Id_Entrada = vEntry;
-
- FETCH rs INTO
- vId_Entrada,
- vId_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP;
-
- WHILE NOT done DO
-
- -- Primero la linea original con las cantidades invertidas
- INSERT INTO vn2008.Compres
- (
- Id_Entrada,
- Id_Article,
- Etiquetas,
- Id_Cubo,
- Packing,
- `grouping`,
- Cantidad,
- Costefijo,
- Portefijo,
- Embalajefijo,
- Comisionfija,
- caja,
- Nicho,
- Tarifa1,
- Tarifa2,
- Tarifa3,
- PVP
- )
- VALUES
- (
- vId_Entrada,
- vId_Article,
- - vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- - vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP);
-
- -- Ahora la linea nueva, con el item genérico
- INSERT INTO vn2008.Compres
- (
- Id_Entrada,
- Id_Article,
- Etiquetas,
- Id_Cubo,
- Packing,
- `grouping`,
- Cantidad,
- Costefijo,
- Portefijo,
- Embalajefijo,
- Comisionfija,
- caja,
- Nicho,
- Tarifa1,
- Tarifa2,
- Tarifa3,
- PVP
- )
- SELECT
- vId_Entrada,
- genItemFk as Id_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP
- FROM itemConversor
- WHERE espItemFk = vId_Article;
-
- SELECT LAST_INSERT_ID()
- INTO vCompra;
-
- REPLACE vn2008.Compres_mark(Id_Compra,`comment`)
- SELECT vCompra, vId_Article;
-
-
- FETCH rs INTO
- vId_Entrada,
- vId_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP;
-
- END WHILE;
-
-
- CLOSE rs;
-
-
-
+BEGIN
+
+ DECLARE vWarehouseIn INT;
+ DECLARE vWarehouseOut INT;
+ DECLARE vTravel INT;
+
+ DECLARE done BOOL DEFAULT FALSE;
+
+ DECLARE vId_Entrada INT;
+ DECLARE vId_Article INT;
+ DECLARE vEtiquetas INT;
+ DECLARE vId_Cubo VARCHAR(10);
+ DECLARE vPacking INT;
+ DECLARE vGrouping INT;
+ DECLARE vCantidad INT;
+ DECLARE vCostefijo DECIMAL(10,3);
+ DECLARE vPortefijo DECIMAL(10,3);
+ DECLARE vEmbalajefijo DECIMAL(10);
+ DECLARE vComisionfija DECIMAL(10,3);
+ DECLARE vCaja INT;
+ DECLARE vNicho VARCHAR(5);
+ DECLARE vTarifa1 DECIMAL(10,2);
+ DECLARE vTarifa2 DECIMAL(10,2);
+ DECLARE vTarifa3 DECIMAL(10,2);
+ DECLARE vPVP DECIMAL(10,2);
+ DECLARE vCompra INT;
+
+ DECLARE rs CURSOR FOR
+ SELECT
+ b.Id_Entrada,
+ b.Id_Article,
+ b.Etiquetas,
+ b.Id_Cubo,
+ b.Packing,
+ b.`grouping`,
+ b.Cantidad,
+ b.Costefijo,
+ b.Portefijo,
+ b.Embalajefijo,
+ b.Comisionfija,
+ b.caja,
+ b.Nicho,
+ b.Tarifa1,
+ b.Tarifa2,
+ b.Tarifa3,
+ b.PVP
+ FROM vn2008.Compres b
+ JOIN vn.itemConversor ic ON ic.espItemFk = b.Id_Article
+ WHERE Id_Entrada = vEntry;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ SELECT warehouseInFk, warehouseOutFk, tr.id
+ INTO vWarehouseIn, vWarehouseOut, vTravel
+ FROM travel tr
+ JOIN entry e ON e.travelFk = tr.id
+ WHERE e.id = vEntry;
+
+ UPDATE travel
+ SET warehouseInFk = vWarehouseOut,
+ warehouseOutFk = vWarehouseIn
+ WHERE id = vTravel;
+
+ UPDATE vn2008.Compres c
+ LEFT JOIN vn.itemConversor ic ON ic.espItemFk = c.Id_Article
+ SET Etiquetas = 0, Cantidad = 0
+ WHERE c.Id_Entrada = vEntry
+ AND ic.espItemFk IS NULL;
+
+ OPEN rs;
+
+ DELETE FROM vn2008.Compres WHERE Id_Entrada = vEntry;
+
+ FETCH rs INTO
+ vId_Entrada,
+ vId_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP;
+
+ WHILE NOT done DO
+
+ -- Primero la linea original con las cantidades invertidas
+ INSERT INTO vn2008.Compres
+ (
+ Id_Entrada,
+ Id_Article,
+ Etiquetas,
+ Id_Cubo,
+ Packing,
+ `grouping`,
+ Cantidad,
+ Costefijo,
+ Portefijo,
+ Embalajefijo,
+ Comisionfija,
+ caja,
+ Nicho,
+ Tarifa1,
+ Tarifa2,
+ Tarifa3,
+ PVP
+ )
+ VALUES
+ (
+ vId_Entrada,
+ vId_Article,
+ - vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ - vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP);
+
+ -- Ahora la linea nueva, con el item genérico
+ INSERT INTO vn2008.Compres
+ (
+ Id_Entrada,
+ Id_Article,
+ Etiquetas,
+ Id_Cubo,
+ Packing,
+ `grouping`,
+ Cantidad,
+ Costefijo,
+ Portefijo,
+ Embalajefijo,
+ Comisionfija,
+ caja,
+ Nicho,
+ Tarifa1,
+ Tarifa2,
+ Tarifa3,
+ PVP
+ )
+ SELECT
+ vId_Entrada,
+ genItemFk as Id_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP
+ FROM itemConversor
+ WHERE espItemFk = vId_Article;
+
+ SELECT LAST_INSERT_ID()
+ INTO vCompra;
+
+ REPLACE vn2008.Compres_mark(Id_Compra,`comment`)
+ SELECT vCompra, vId_Article;
+
+
+ FETCH rs INTO
+ vId_Entrada,
+ vId_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP;
+
+ END WHILE;
+
+
+ CLOSE rs;
+
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59016,62 +58668,62 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entryPrepare__`(IN `idE` BIGINT)
-BEGIN
- SELECT
- b.quantity / b.packing AS Paquetes,
- b.packing AS `Grouping`,
- barcode,
- 'ASEGURADO' AS asegurado,
- ic.name,
- ic.order,
- s.name AS Consignatario,
- e.supplierFk AS Id_Cliente,
- e.isOrdered,
- e.isConfirmed,
- 10 AS Calidad,
- LPAD(IFNULL(cpd.id, ip.code),
- 5,
- '0') AS path,
- b.entryFk AS Id_Ticket,
- t.landed AS Fecha,
- b.itemFk,
- b.quantity,
- i.name AS Concepte,
- i.size,
- i.inkFk,
- i.category,
- o.code AS Origen,
- 0 AS Bultos,
- wIn.`name` AS Tipo,
- 0 AS OK,
- 0 AS Reservado,
- i.stems,
- b.id AS Id_Movimiento,
- ip.code,
- 'PEDIDO ASEGURADO' AS MSG,
- 0 AS Seguro,
- i.image,
- pr.name AS producer
- FROM vn.buy b
- JOIN vn.entry e ON b.entryFk = e.id
- JOIN vn.travel t ON t.id = e.travelFk
- JOIN vn.warehouse wIn ON wIn.id = t.warehouseInFk
- JOIN vn.warehouse wOut ON wOut.id = t.warehouseOutFk
- JOIN vn.item i ON i.id = b.itemFk
- JOIN vn.itemType it ON it.id =i.typeFk
- JOIN vn.itemCategory ic ON ic.id = it.categoryFk
- JOIN vn.packaging pkg ON pkg.id = b.packageFk
- LEFT JOIN vn.itemPlacement ip ON i.id = ip.itemFk AND ip.warehouseFk = wIn.id AND ip.warehouseFk = t.warehouseOutFk
- LEFT JOIN (SELECT itemFk, code AS barcode FROM vn.itemBarcode GROUP BY itemFk) ib ON ib.itemFk = b.itemFk
- LEFT JOIN vn.origin o ON o.id = i.originFk
- LEFT JOIN vn.supplier s ON s.id = e.supplierFk
- LEFT JOIN vn.producer pr on pr.id = i.producerFk
- LEFT JOIN vn.coolerPathDetail cpd ON LEFT(ip.code, 3) = cpd.hallway
- WHERE
- NOT wIn.isFeedStock AND NOT e.isInventory AND NOT e.isRaid
- AND e.id = 158772
- AND i.typeFk IS NOT NULL
- AND ic.display IS NOT FALSE;
+BEGIN
+ SELECT
+ b.quantity / b.packing AS Paquetes,
+ b.packing AS `Grouping`,
+ barcode,
+ 'ASEGURADO' AS asegurado,
+ ic.name,
+ ic.order,
+ s.name AS Consignatario,
+ e.supplierFk AS Id_Cliente,
+ e.isOrdered,
+ e.isConfirmed,
+ 10 AS Calidad,
+ LPAD(IFNULL(cpd.id, ip.code),
+ 5,
+ '0') AS path,
+ b.entryFk AS Id_Ticket,
+ t.landed AS Fecha,
+ b.itemFk,
+ b.quantity,
+ i.name AS Concepte,
+ i.size,
+ i.inkFk,
+ i.category,
+ o.code AS Origen,
+ 0 AS Bultos,
+ wIn.`name` AS Tipo,
+ 0 AS OK,
+ 0 AS Reservado,
+ i.stems,
+ b.id AS Id_Movimiento,
+ ip.code,
+ 'PEDIDO ASEGURADO' AS MSG,
+ 0 AS Seguro,
+ i.image,
+ pr.name AS producer
+ FROM vn.buy b
+ JOIN vn.entry e ON b.entryFk = e.id
+ JOIN vn.travel t ON t.id = e.travelFk
+ JOIN vn.warehouse wIn ON wIn.id = t.warehouseInFk
+ JOIN vn.warehouse wOut ON wOut.id = t.warehouseOutFk
+ JOIN vn.item i ON i.id = b.itemFk
+ JOIN vn.itemType it ON it.id =i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ JOIN vn.packaging pkg ON pkg.id = b.packageFk
+ LEFT JOIN vn.itemPlacement ip ON i.id = ip.itemFk AND ip.warehouseFk = wIn.id AND ip.warehouseFk = t.warehouseOutFk
+ LEFT JOIN (SELECT itemFk, code AS barcode FROM vn.itemBarcode GROUP BY itemFk) ib ON ib.itemFk = b.itemFk
+ LEFT JOIN vn.origin o ON o.id = i.originFk
+ LEFT JOIN vn.supplier s ON s.id = e.supplierFk
+ LEFT JOIN vn.producer pr on pr.id = i.producerFk
+ LEFT JOIN vn.coolerPathDetail cpd ON LEFT(ip.code, 3) = cpd.hallway
+ WHERE
+ NOT wIn.isFeedStock AND NOT e.isInventory AND NOT e.isRaid
+ AND e.id = 158772
+ AND i.typeFk IS NOT NULL
+ AND ic.display IS NOT FALSE;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59162,22 +58814,22 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entryVolume__`(vEntryFk INT)
-BEGIN
-
- SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') AS Temp,
- CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) *
- vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.carro / 1000000 ,1) AS DECIMAL(10,2)) AS carros ,
- CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) *
- vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.espai / 1000000,1) AS DECIMAL(10,2)) AS espais
- FROM vn.buy b
- INNER JOIN vn.entry e ON e.id = b.entryFk
- INNER JOIN vn.travel tr ON tr.id = e.travelFk
- INNER JOIN vn.volumeConfig vc
- INNER JOIN vn.item i ON i.id = b.itemFk
- INNER JOIN vn.itemType it ON it.id = i.typeFk
- WHERE e.id = vEntryFk
- GROUP BY Temp;
-
+BEGIN
+
+ SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') AS Temp,
+ CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) *
+ vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.carro / 1000000 ,1) AS DECIMAL(10,2)) AS carros ,
+ CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) *
+ vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.espai / 1000000,1) AS DECIMAL(10,2)) AS espais
+ FROM vn.buy b
+ INNER JOIN vn.entry e ON e.id = b.entryFk
+ INNER JOIN vn.travel tr ON tr.id = e.travelFk
+ INNER JOIN vn.volumeConfig vc
+ INNER JOIN vn.item i ON i.id = b.itemFk
+ INNER JOIN vn.itemType it ON it.id = i.typeFk
+ WHERE e.id = vEntryFk
+ GROUP BY Temp;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59331,67 +58983,67 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_clone`(vSelf INT)
-BEGIN
-
-/*
- * Clona una entrada
- *
- * @param vSelf Identificador de vn.entry
- */
-
- DECLARE vNewEntryFk INT;
-
- CALL vn.entry_cloneWithoutBuy(vSelf, vNewEntryFk);
-
- INSERT INTO vn.buy( entryFk,
- itemFk,
- quantity,
- buyingValue,
- freightValue,
- isIgnored,
- stickers,
- packing,
- `grouping`,
- groupingMode,
- containerFk,
- comissionValue,
- packageValue,
- packageFk,
- price1,
- price2,
- price3,
- minPrice,
- producer,
- workerFk,
- weight,
- itemOriginalFk)
- SELECT vNewEntryFk,
- itemFk,
- quantity,
- buyingValue,
- freightValue,
- isIgnored,
- stickers,
- packing,
- `grouping`,
- groupingMode,
- containerFk,
- comissionValue,
- packageValue,
- packageFk,
- price1,
- price2,
- price3,
- minPrice,
- producer,
- workerFk,
- weight,
- itemOriginalFk
- FROM vn.buy b
- WHERE b.entryFk = vSelf;
-
- SELECT vNewEntryFk;
-
+BEGIN
+
+/*
+ * Clona una entrada
+ *
+ * @param vSelf Identificador de vn.entry
+ */
+
+ DECLARE vNewEntryFk INT;
+
+ CALL vn.entry_cloneWithoutBuy(vSelf, vNewEntryFk);
+
+ INSERT INTO vn.buy( entryFk,
+ itemFk,
+ quantity,
+ buyingValue,
+ freightValue,
+ isIgnored,
+ stickers,
+ packing,
+ `grouping`,
+ groupingMode,
+ containerFk,
+ comissionValue,
+ packageValue,
+ packageFk,
+ price1,
+ price2,
+ price3,
+ minPrice,
+ producer,
+ workerFk,
+ weight,
+ itemOriginalFk)
+ SELECT vNewEntryFk,
+ itemFk,
+ quantity,
+ buyingValue,
+ freightValue,
+ isIgnored,
+ stickers,
+ packing,
+ `grouping`,
+ groupingMode,
+ containerFk,
+ comissionValue,
+ packageValue,
+ packageFk,
+ price1,
+ price2,
+ price3,
+ minPrice,
+ producer,
+ workerFk,
+ weight,
+ itemOriginalFk
+ FROM vn.buy b
+ WHERE b.entryFk = vSelf;
+
+ SELECT vNewEntryFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59409,45 +59061,45 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_cloneWithoutBuy`(vSelf INT, OUT vNewEntryFk INT)
-BEGIN
-
-/**
- * Clona una entrada sin compras
- *
- * @param vSelf Identificador de vn.entry
- *
- * @return vNewEntryFk Identificador de la nueva entrada
- */
-
- START TRANSACTION;
-
- INSERT INTO vn.entry(supplierFk,
- dated,
- isInventory,
- notes,
- isRaid,
- commission,
- travelFk,
- currencyFk,
- companyFk,
- loadPriority)
- SELECT supplierFk,
- dated,
- isInventory,
- notes,
- isRaid,
- commission,
- travelFk,
- currencyFk,
- companyFk,
- loadPriority
- FROM vn.entry e
- WHERE e.id = vSelf;
-
- SET vNewEntryFk = LAST_INSERT_ID();
-
- COMMIT;
-
+BEGIN
+
+/**
+ * Clona una entrada sin compras
+ *
+ * @param vSelf Identificador de vn.entry
+ *
+ * @return vNewEntryFk Identificador de la nueva entrada
+ */
+
+ START TRANSACTION;
+
+ INSERT INTO vn.entry(supplierFk,
+ dated,
+ isInventory,
+ notes,
+ isRaid,
+ commission,
+ travelFk,
+ currencyFk,
+ companyFk,
+ loadPriority)
+ SELECT supplierFk,
+ dated,
+ isInventory,
+ notes,
+ isRaid,
+ commission,
+ travelFk,
+ currencyFk,
+ companyFk,
+ loadPriority
+ FROM vn.entry e
+ WHERE e.id = vSelf;
+
+ SET vNewEntryFk = LAST_INSERT_ID();
+
+ COMMIT;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59465,64 +59117,62 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_fixMisfit`(vSelf INT)
-BEGIN
-
- /* Arregla el descuadre de una entrada, agregando registros en vn.buy para compensar la diferencia
- * entre las etiquetas impresas y las etiquetas esperadas
- *
- */
-
- INSERT INTO vn.buy(entryFk, itemFk)
- SELECT vSelf, i.id
- FROM vn.item i
- WHERE i.description = 'MISFIT'
- LIMIT 1;
-
- INSERT INTO vn.buy(entryFk,
- itemFk,
- quantity,
- buyingValue,
- freightValue,
- isIgnored,
- stickers,
- packing,
- `grouping`,
- groupingMode,
- containerFk,
- comissionValue,
- packageValue,
- location,
- packageFk,
- price1,
- price2,
- price3,
- minPrice,
- producer)
- SELECT vSelf,
- itemFk,
- (printedStickers - stickers) * packing AS quantity,
- buyingValue,
- freightValue,
- TRUE isIgnored,
- printedStickers - stickers,
- packing,
- `grouping`,
- groupingMode,
- containerFk,
- comissionValue,
- packageValue,
- location,
- packageFk,
- price1,
- price2,
- price3,
- minPrice,
- producer
- FROM vn.buy b
- WHERE b.entryFk = vSelf
- AND b.printedStickers != b.stickers;
-
-
+BEGIN
+/**
+ * Arregla el descuadre de una entrada, agregando registros en vn.buy
+ * para compensar la diferencia * entre las etiquetas impresas y las esperadas
+ *
+ * @param vSelf Identificador de la entrada
+ */
+ INSERT INTO vn.buy(entryFk, itemFk)
+ SELECT vSelf, i.id
+ FROM vn.item i
+ WHERE i.description = 'MISFIT'
+ LIMIT 1;
+
+ INSERT INTO vn.buy(entryFk,
+ itemFk,
+ quantity,
+ buyingValue,
+ freightValue,
+ isIgnored,
+ stickers,
+ packing,
+ `grouping`,
+ groupingMode,
+ containerFk,
+ comissionValue,
+ packageValue,
+ location,
+ packageFk,
+ price1,
+ price2,
+ price3,
+ minPrice,
+ producer)
+ SELECT vSelf,
+ itemFk,
+ (printedStickers - stickers) * packing quantity,
+ buyingValue,
+ freightValue,
+ TRUE isIgnored,
+ printedStickers - stickers,
+ packing,
+ `grouping`,
+ groupingMode,
+ containerFk,
+ comissionValue,
+ packageValue,
+ location,
+ packageFk,
+ price1,
+ price2,
+ price3,
+ minPrice,
+ producer
+ FROM vn.buy b
+ WHERE b.entryFk = vSelf
+ AND b.printedStickers != b.stickers;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59585,23 +59235,21 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_moveNotPrinted`(vSelf INT, vDays INT, vChangeEntry BOOL, OUT vNewEntryFk INT)
BEGIN
-
- /**
- * Crea una entrada a futuro y divide las lineas de vn.buy de la entrada original en función
- * de las etiquetas impresas
- *
- * @param vSelf Identificador de vn.entry
- * @param vDays Número de dias a futuro que se quiere la nueva entrada
- *
- * @return vNewEntryFk Identificador de la nueva entrada
- */
-
+/**
+ * Crea una entrada a futuro y divide las lineas de vn.buy de la entrada original en función
+ * de las etiquetas impresas
+ *
+ * @param vSelf Identificador de vn.entry
+ * @param vDays Número de dias a futuro que se quiere la nueva entrada
+ *
+ * @return vNewEntryFk Identificador de la nueva entrada
+ */
DECLARE vNewTravelFk INT;
DECLARE vTravelFk INT;
@@ -59610,7 +59258,6 @@ BEGIN
WHERE id = vSelf;
CALL vn.travel_clone(vTravelFk, vDays, vNewTravelFk);
-
CALL vn.entry_cloneWithoutBuy(vSelf, vNewEntryFk);
UPDATE vn.entry e
@@ -59618,10 +59265,12 @@ BEGIN
e.evaNotes = CONCAT('No impresas de: ', vSelf, ' ', IFNULL(e.evaNotes,''))
WHERE e.id = vNewEntryFk;
- UPDATE vn.buy b
- SET b.entryFk = vNewEntryFk
- WHERE b.printedStickers = 0
- AND b.entryFk = vSelf;
+ IF vChangeEntry THEN
+ UPDATE vn.buy b
+ SET b.entryFk = vNewEntryFk
+ WHERE b.printedStickers = 0
+ AND b.entryFk = vSelf;
+ END IF;
INSERT INTO vn.buy( entryFk,
itemFk,
@@ -59674,10 +59323,59 @@ BEGIN
IF vChangeEntry THEN
UPDATE vn.buy
SET stickers = printedStickers,
- quantity = printedStickers * packing
+ quantity = printedStickers * packing
WHERE entryFk = vSelf;
+ ELSE
+ INSERT INTO vn.buy(entryFk, itemFk)
+ SELECT vSelf, i.id
+ FROM vn.item i
+ WHERE i.description = 'MISFIT'
+ LIMIT 1;
+
+ INSERT INTO vn.buy(entryFk,
+ itemFk,
+ quantity,
+ buyingValue,
+ freightValue,
+ isIgnored,
+ stickers,
+ packing,
+ `grouping`,
+ groupingMode,
+ containerFk,
+ comissionValue,
+ packageValue,
+ location,
+ packageFk,
+ price1,
+ price2,
+ price3,
+ minPrice,
+ producer)
+ SELECT vSelf,
+ itemFk,
+ (printedStickers - stickers) * packing quantity,
+ buyingValue,
+ freightValue,
+ TRUE isIgnored,
+ printedStickers - stickers,
+ packing,
+ `grouping`,
+ groupingMode,
+ containerFk,
+ comissionValue,
+ packageValue,
+ location,
+ packageFk,
+ price1,
+ price2,
+ price3,
+ minPrice,
+ producer
+ FROM vn.buy
+ WHERE entryFk = vSelf
+ AND printedStickers != stickers;
END IF;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59743,48 +59441,68 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_splitByShelving`(vShelvingFk VARCHAR(3), vFromEntryFk INT, vToEntryFk INT)
BEGIN
- /**
- * Divide las compras entre dos entradas de acuerdo con lo ubicado en una matr�cula
- *
- * @param vShelvingFk Identificador de vn.shelving
- * @param vFromEntryFk Entrada origen
- * @param vToEntryFk Entrada destino
- */
-
- DECLARE vItemFk INT;
- DECLARE vStickers INT;
+/**
+ * Divide las compras entre dos entradas de acuerdo con lo ubicado en una matr�cula
+ *
+ * @param vShelvingFk Identificador de vn.shelving
+ * @param vFromEntryFk Entrada origen
+ * @param vToEntryFk Entrada destino
+ */
DECLARE vBuyFk INT;
- DECLARE vHasSameStickers BOOL;
+ DECLARE ishStickers INT;
+ DECLARE buyStickers INT;
DECLARE vDone BOOLEAN DEFAULT FALSE;
+
DECLARE cur CURSOR FOR
- SELECT itemFk, FLOOR(quantity / packing) AS stickers
- FROM vn.itemShelving WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci ;
+ SELECT bb.id buyFk,
+ FLOOR(ish.visible / ish.packing) AS ishStickers,
+ bb.stickers buyStickers
+ FROM vn.itemShelving ish
+ JOIN (SELECT b.id, b.itemFk, b.stickers
+ FROM vn.buy b
+ WHERE b.entryFk = vFromEntryFk
+ ORDER BY b.stickers DESC) bb ON bb.itemFk = ish.itemFk
+ AND bb.stickers >= FLOOR(ish.visible / ish.packing)
+ WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci
+ GROUP BY ish.id;
+
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+ -- Cantidades de la matrícula que exceden la de las entradas
+ SELECT ish.itemFk,
+ i.longName,
+ FLOOR(ish.visible / ish.packing) AS etiEnMatricula,
+ bb.stickers etiEnEntrada
+ FROM vn.itemShelving ish
+ JOIN vn.item i ON i.id = ish.itemFk
+ LEFT JOIN (SELECT b.id, b.itemFk, b.stickers
+ FROM vn.buy b
+ WHERE b.entryFk = vFromEntryFk
+ ORDER BY b.stickers DESC) bb ON bb.itemFk = ish.itemFk
+ WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci
+ AND IFNULL(bb.stickers,0) < FLOOR(ish.visible / ish.packing)
+ GROUP BY ish.id;
+
OPEN cur;
read_loop: LOOP
-
- FETCH cur INTO vItemFk, vStickers;
-
- IF vDone THEN
- LEAVE read_loop;
- END IF;
+ SET vDone = FALSE;
- SELECT b.id, (stickers = vStickers) INTO vBuyFk, vHasSameStickers
- FROM vn.buy
- WHERE entryFk = vFromEntryFk
- AND itemFk = vItemFk
- AND stickers >= vStickers
- LIMIT 1;
-
- IF vHasSameStickers THEN
-
- UPDATE vn.buy SET entryFk = vToEntryFk WHERE id = vBuyFk;
+ FETCH cur INTO vBuyFk, ishStickers, buyStickers;
+
+ IF vDone THEN
+ LEAVE read_loop;
+ END IF;
+ IF ishStickers = buyStickers THEN
+ UPDATE vn.buy
+ SET entryFk = vToEntryFk
+ WHERE id = vBuyFk;
ELSE
-
- UPDATE vn.buy SET stickers = stickers - vStickers WHERE id = vBuyFk;
+ UPDATE vn.buy
+ SET stickers = stickers - ishStickers,
+ quantity = stickers * packing
+ WHERE id = vBuyFk;
INSERT INTO vn.buy(entryFk,
itemFk,
@@ -59817,11 +59535,11 @@ BEGIN
SELECT
vToEntryFk,
itemFk,
- vStickers * packing,
+ ishStickers * packing,
buyingValue,
freightValue,
isIgnored,
- vStickers,
+ ishStickers,
packing,
`grouping`,
groupingMode,
@@ -59835,7 +59553,7 @@ BEGIN
price3,
minPrice,
producer,
- vStickers,
+ ishStickers,
workerFk,
isChecked,
isPickedOff,
@@ -59847,11 +59565,9 @@ BEGIN
WHERE id = vBuyFk;
END IF;
-
END LOOP;
CLOSE cur;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -59869,36 +59585,36 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_splitMisfit`(vSelf INT)
-BEGIN
-
- /* Divide una entrada, pasando los registros que ha insertado vn.entry_fixMisfit de la entrada original
- * a la nueva
- */
-
- DECLARE vNewEntryFk INT;
- DECLARE vBuyFk INT;
-
- SELECT MAX(b.id) INTO vBuyFk
- FROM vn.buy b
- JOIN vn.item i ON i.id = b.itemFk
- WHERE b.entryFk = vSelf
- AND i.description = 'MISFIT';
-
- INSERT INTO vn.entry(supplierFk, dated, notes, travelFk, currencyFk, companyFk)
- SELECT supplierFk, dated, CONCAT('E:',vSelf), travelFk, currencyFk, companyFk
- FROM vn.entry e
- WHERE e.id = vSelf;
-
- SET vNewEntryFk = LAST_INSERT_ID();
-
- UPDATE vn.buy b
- SET b.entryFk = vNewEntryFk
- WHERE b.entryFk = vSelf
- AND b.id > vBuyFk;
-
- SELECT vNewEntryFk;
-
-
+BEGIN
+
+ /* Divide una entrada, pasando los registros que ha insertado vn.entry_fixMisfit de la entrada original
+ * a la nueva
+ */
+
+ DECLARE vNewEntryFk INT;
+ DECLARE vBuyFk INT;
+
+ SELECT MAX(b.id) INTO vBuyFk
+ FROM vn.buy b
+ JOIN vn.item i ON i.id = b.itemFk
+ WHERE b.entryFk = vSelf
+ AND i.description = 'MISFIT';
+
+ INSERT INTO vn.entry(supplierFk, dated, notes, travelFk, currencyFk, companyFk)
+ SELECT supplierFk, dated, CONCAT('E:',vSelf), travelFk, currencyFk, companyFk
+ FROM vn.entry e
+ WHERE e.id = vSelf;
+
+ SET vNewEntryFk = LAST_INSERT_ID();
+
+ UPDATE vn.buy b
+ SET b.entryFk = vNewEntryFk
+ WHERE b.entryFk = vSelf
+ AND b.id > vBuyFk;
+
+ SELECT vNewEntryFk;
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -60298,6 +60014,39 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `expeditionPallet_printLabel` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_printLabel`(vPalletFk INT)
+BEGIN
+
+ DECLARE vLabel INT;
+ DECLARE vPrinterFk INT;
+
+ UPDATE vn.expeditionPallet
+ SET isPrint = FALSE
+ WHERE id = vPalletFk;
+
+ SELECT s.labelReportFk, w.labelerFk INTO vLabel, vPrinterFK
+ FROM worker w
+ LEFT JOIN sector s ON s.id= w.sectorFk
+ WHERE w.id=account.myUser_getId() ;
+
+ INSERT INTO printServerQueue (printerFk, labelReportFk, statusFk, param1, workerFk)
+ VALUES(vPrinterFK, vLabel, 1, vPalletFk, account.myUser_getId());
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `expeditionPallet_PrintSet` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -60496,33 +60245,33 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_add`(vParam INT, vStateCode VARCHAR(100))
-BEGIN
-
- /**
- * Inserta nuevos registros en la tabla vn.expeditionState, segun el parámetro
- *
- * @param vParam Identificador de vn.expedition o de vn.route
- * @param vStateCode Corresponde a vn.expeditionStateType.code
- */
-
- IF (SELECT COUNT(*) FROM vn.route r WHERE r.id = vParam) THEN
-
- INSERT INTO vn.expeditionState(expeditionFk, typeFk)
- SELECT e.id, est.id
- FROM vn.expedition e
- JOIN vn.ticket t ON t.id = e.ticketFk
- JOIN vn.expeditionStateType est ON est.code = vStateCode
- WHERE t.routeFk = vParam;
-
- ELSE
-
- INSERT INTO vn.expeditionState(expeditionFk, typeFk)
- SELECT vParam, est.id
- FROM vn.expeditionStateType est
- WHERE est.code = vStateCode;
-
- END IF;
-
+BEGIN
+
+ /**
+ * Inserta nuevos registros en la tabla vn.expeditionState, segun el parámetro
+ *
+ * @param vParam Identificador de vn.expedition o de vn.route
+ * @param vStateCode Corresponde a vn.expeditionStateType.code
+ */
+
+ IF (SELECT COUNT(*) FROM vn.route r WHERE r.id = vParam) THEN
+
+ INSERT INTO vn.expeditionState(expeditionFk, typeFk)
+ SELECT e.id, est.id
+ FROM vn.expedition e
+ JOIN vn.ticket t ON t.id = e.ticketFk
+ JOIN vn.expeditionStateType est ON est.code = vStateCode
+ WHERE t.routeFk = vParam;
+
+ ELSE
+
+ INSERT INTO vn.expeditionState(expeditionFk, typeFk)
+ SELECT vParam, est.id
+ FROM vn.expeditionStateType est
+ WHERE est.code = vStateCode;
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -60540,23 +60289,23 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByAdress`(vAdressFk INT, vRouteFk INT, vStateCode VARCHAR(100))
-BEGIN
-
- /**
- * Inserta nuevos registros en la tabla vn.expeditionState
- *
- * @param vAdressFk Identificador de vn.ticket
- * @param vRouteFk Identificador de vn.route
- * @param vStateCode Corresponde a vn.expeditionStateType.code
- */
-
- INSERT INTO vn.expeditionState(expeditionFk, typeFk)
- SELECT e.id, est.id
- FROM vn.expedition e
- JOIN vn.expeditionStateType est ON est.code = vStateCode
- JOIN vn.ticket t ON t.id = e.ticketFk
- WHERE t.addressFk = vAdressFk AND t.routeFk = vRouteFk;
-
+BEGIN
+
+ /**
+ * Inserta nuevos registros en la tabla vn.expeditionState
+ *
+ * @param vAdressFk Identificador de vn.ticket
+ * @param vRouteFk Identificador de vn.route
+ * @param vStateCode Corresponde a vn.expeditionStateType.code
+ */
+
+ INSERT INTO vn.expeditionState(expeditionFk, typeFk)
+ SELECT e.id, est.id
+ FROM vn.expedition e
+ JOIN vn.expeditionStateType est ON est.code = vStateCode
+ JOIN vn.ticket t ON t.id = e.ticketFk
+ WHERE t.addressFk = vAdressFk AND t.routeFk = vRouteFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -60574,20 +60323,56 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByExpedition`(vExpeditionFk INT, vStateCode VARCHAR(100))
-BEGIN
-
- /**
- * Inserta nuevos registros en la tabla vn.expeditionState
- *
- * @param vExpeditionFk Identificador de vn.expedition
- * @param vStateCode Corresponde a vn.expeditionStateType.code
- */
-
- INSERT INTO vn.expeditionState(expeditionFk, typeFk)
- SELECT vExpeditionFk, est.id
- FROM vn.expeditionStateType est
- WHERE est.code = vStateCode;
-
+BEGIN
+
+ /**
+ * Inserta nuevos registros en la tabla vn.expeditionState
+ *
+ * @param vExpeditionFk Identificador de vn.expedition
+ * @param vStateCode Corresponde a vn.expeditionStateType.code
+ */
+
+ INSERT INTO vn.expeditionState(expeditionFk, typeFk)
+ SELECT vExpeditionFk, est.id
+ FROM vn.expeditionStateType est
+ WHERE est.code = vStateCode;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `expeditionState_addByPallet` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByPallet`(vPalletFk INT, vStateCode VARCHAR(100))
+BEGIN
+/**
+ * Inserta nuevos registros en la tabla vn.expeditionState
+ *
+ * @param vPalletFk Identificador de vn.expedition
+ * @param vStateCode Corresponde a vn.expeditionStateType.code
+ */
+ DROP TEMPORARY TABLE IF EXISTS tmp.expeditionScan;
+ CREATE TEMPORARY TABLE tmp.expeditionScan
+ SELECT expeditionFk, est.id typeFk
+ FROM vn.expeditionScan e
+ JOIN vn.expeditionStateType est ON est.code = vStateCode
+ WHERE e.palletFk = vPalletFk;
+
+ INSERT INTO vn.expeditionState(expeditionFk, typeFk)
+ SELECT expeditionFk, typeFk
+ FROM tmp.expeditionScan;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.expeditionScan;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -60605,22 +60390,22 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByRoute`(vRouteFk INT, vStateCode VARCHAR(100))
-BEGIN
-
- /**
- * Inserta nuevos registros en la tabla vn.expeditionState, por rutas
- *
- * @param vRouteFk Identificador de vn.route
- * @param vStateCode Corresponde a vn.expeditionStateType.code
- */
-
- INSERT INTO vn.expeditionState(expeditionFk, typeFk)
- SELECT e.id, est.id
- FROM vn.expedition e
- JOIN vn.ticket t ON t.id = e.ticketFk
- JOIN vn.expeditionStateType est ON est.code = vStateCode
- WHERE t.routeFk = vRouteFk;
-
+BEGIN
+
+ /**
+ * Inserta nuevos registros en la tabla vn.expeditionState, por rutas
+ *
+ * @param vRouteFk Identificador de vn.route
+ * @param vStateCode Corresponde a vn.expeditionStateType.code
+ */
+
+ INSERT INTO vn.expeditionState(expeditionFk, typeFk)
+ SELECT e.id, est.id
+ FROM vn.expedition e
+ JOIN vn.ticket t ON t.id = e.ticketFk
+ JOIN vn.expeditionStateType est ON est.code = vStateCode
+ WHERE t.routeFk = vRouteFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -60707,9 +60492,9 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_getFromRoute`(vRouteFk INT)
BEGIN
@@ -60718,7 +60503,6 @@ BEGIN
* @param vRouteFk Id de la ruta
*/
-
SELECT e.id,
e.ticketFk,
e.checked,
@@ -60729,7 +60513,8 @@ BEGIN
a.postalCode,
t.addressFk,
a.nickname,
- sub2.itemPackingTypeConcat
+ sub2.itemPackingTypeConcat,
+ est.code
FROM expedition e
JOIN ticket t ON t.id = e.ticketFk
JOIN ticketState ts ON ts.ticketFk = e.ticketFk
@@ -60745,9 +60530,9 @@ BEGIN
GROUP BY t.id,i.itemPackingTypeFk)sub
GROUP BY sub.ticketFk
) sub2 ON sub2.ticketFk = t.id
+ LEFT JOIN expeditionStateType est ON est.id = e.stateTypeFk
WHERE t.routeFk = vRouteFk AND e.isBox <> FALSE;
-
-
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -61007,15 +60792,15 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `freelance_getInfo`(workerFk INT)
-BEGIN
- SELECT s.name, s.street, s.city, s.nif, s.postCode
- FROM route r
- JOIN agencyMode am ON r.agencyModeFk = am.id
- JOIN agency a ON am.agencyFk = a.id
- JOIN supplier s ON a.supplierFk = s.id
- WHERE r.workerFk = workerFk
- ORDER BY r.id DESC
- LIMIT 1;
+BEGIN
+ SELECT s.name, s.street, s.city, s.nif, s.postCode
+ FROM route r
+ JOIN agencyMode am ON r.agencyModeFk = am.id
+ JOIN agency a ON am.agencyFk = a.id
+ JOIN supplier s ON a.supplierFk = s.id
+ WHERE r.workerFk = workerFk
+ ORDER BY r.id DESC
+ LIMIT 1;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -61033,81 +60818,81 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `fustControl`(vFromDated DATE, vToDated DATE)
-BEGIN
-
- DECLARE vSijsnerClientFk INT DEFAULT 19752;
-
- DECLARE vDateStart DATETIME;
- DECLARE vDateEnd DATETIME;
-
- SET vDateStart = vFromDated;
- SET vDateEnd = util.Dayend(vToDated);
-
- SELECT p.id FustCode,
- CAST(sent.stucks AS DECIMAL(10,0)) FH,
- CAST(tp.stucks AS DECIMAL(10,0)) Tickets,
- CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner,
- CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo
- FROM vn.packaging p
- LEFT JOIN (
- SELECT FustCode, sum(fustQuantity) stucks
- FROM (
- SELECT IFNULL(pe.equivalentFk ,b.packageFk) FustCode, s.quantity / b.packing AS fustQuantity
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- JOIN vn.warehouse w ON w.id = t.warehouseFk
- JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk
- JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk
- JOIN vn.buy b ON b.id = lb.buy_id
- JOIN vn.packaging p ON p.id = b.packageFk
- LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p2 ON p2.id = a.provinceFk
- JOIN vn.country c ON c.id = p2.countryFk
- WHERE t.shipped BETWEEN vDateStart AND vDateEnd
- AND wa.name = 'VNH'
- AND p.isPackageReturnable
- AND c.country = 'FRANCIA') sub
- GROUP BY FustCode) sent ON sent.FustCode = p.id
- LEFT JOIN (
- SELECT FustCode, sum(quantity) stucks
- FROM (
- SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity
- FROM vn.ticketPackaging tp
- JOIN vn.ticket t ON t.id = tp.ticketFk
- JOIN vn.warehouse w ON w.id = t.warehouseFk
- JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk
- JOIN vn.packaging p ON p.id = tp.packagingFk
- LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p2 ON p2.id = a.provinceFk
- JOIN vn.country c ON c.id = p2.countryFk
- WHERE t.shipped BETWEEN vDateStart AND vDateEnd
- AND wa.name = 'VNH'
- AND p.isPackageReturnable
- AND c.country = 'FRANCIA'
- AND t.clientFk != vSijsnerClientFk
- AND tp.quantity > 0) sub
- GROUP BY FustCode) tp ON tp.FustCode = p.id
- LEFT JOIN (
- SELECT FustCode, sum(quantity) stucks
- FROM (
- SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity
- FROM vn.ticketPackaging tp
- JOIN vn.ticket t ON t.id = tp.ticketFk
- JOIN vn.warehouse w ON w.id = t.warehouseFk
- JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk
- JOIN vn.packaging p ON p.id = tp.packagingFk
- LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id
- WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd )
- AND wa.name = 'VNH'
- AND p.isPackageReturnable
- AND t.clientFk = vSijsnerClientFk) sub
- GROUP BY FustCode) sj ON sj.FustCode = p.id
- WHERE sent.stucks
- OR tp.stucks
- OR sj.stucks;
-
+BEGIN
+
+ DECLARE vSijsnerClientFk INT DEFAULT 19752;
+
+ DECLARE vDateStart DATETIME;
+ DECLARE vDateEnd DATETIME;
+
+ SET vDateStart = vFromDated;
+ SET vDateEnd = util.Dayend(vToDated);
+
+ SELECT p.id FustCode,
+ CAST(sent.stucks AS DECIMAL(10,0)) FH,
+ CAST(tp.stucks AS DECIMAL(10,0)) Tickets,
+ CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner,
+ CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo
+ FROM vn.packaging p
+ LEFT JOIN (
+ SELECT FustCode, sum(fustQuantity) stucks
+ FROM (
+ SELECT IFNULL(pe.equivalentFk ,b.packageFk) FustCode, s.quantity / b.packing AS fustQuantity
+ FROM vn.sale s
+ JOIN vn.ticket t ON t.id = s.ticketFk
+ JOIN vn.warehouse w ON w.id = t.warehouseFk
+ JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk
+ JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk
+ JOIN vn.buy b ON b.id = lb.buy_id
+ JOIN vn.packaging p ON p.id = b.packageFk
+ LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id
+ JOIN vn.address a ON a.id = t.addressFk
+ JOIN vn.province p2 ON p2.id = a.provinceFk
+ JOIN vn.country c ON c.id = p2.countryFk
+ WHERE t.shipped BETWEEN vDateStart AND vDateEnd
+ AND wa.name = 'VNH'
+ AND p.isPackageReturnable
+ AND c.country = 'FRANCIA') sub
+ GROUP BY FustCode) sent ON sent.FustCode = p.id
+ LEFT JOIN (
+ SELECT FustCode, sum(quantity) stucks
+ FROM (
+ SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity
+ FROM vn.ticketPackaging tp
+ JOIN vn.ticket t ON t.id = tp.ticketFk
+ JOIN vn.warehouse w ON w.id = t.warehouseFk
+ JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk
+ JOIN vn.packaging p ON p.id = tp.packagingFk
+ LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id
+ JOIN vn.address a ON a.id = t.addressFk
+ JOIN vn.province p2 ON p2.id = a.provinceFk
+ JOIN vn.country c ON c.id = p2.countryFk
+ WHERE t.shipped BETWEEN vDateStart AND vDateEnd
+ AND wa.name = 'VNH'
+ AND p.isPackageReturnable
+ AND c.country = 'FRANCIA'
+ AND t.clientFk != vSijsnerClientFk
+ AND tp.quantity > 0) sub
+ GROUP BY FustCode) tp ON tp.FustCode = p.id
+ LEFT JOIN (
+ SELECT FustCode, sum(quantity) stucks
+ FROM (
+ SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity
+ FROM vn.ticketPackaging tp
+ JOIN vn.ticket t ON t.id = tp.ticketFk
+ JOIN vn.warehouse w ON w.id = t.warehouseFk
+ JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk
+ JOIN vn.packaging p ON p.id = tp.packagingFk
+ LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id
+ WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd )
+ AND wa.name = 'VNH'
+ AND p.isPackageReturnable
+ AND t.clientFk = vSijsnerClientFk) sub
+ GROUP BY FustCode) sj ON sj.FustCode = p.id
+ WHERE sent.stucks
+ OR tp.stucks
+ OR sj.stucks;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -61125,38 +60910,38 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `fustControlDetail`(vFromDated DATE, vToDated DATE)
-BEGIN
-
- DECLARE vSijsnerClientFk INT DEFAULT 19752;
-
- DECLARE vDateStart DATETIME;
- DECLARE vDateEnd DATETIME;
-
- SET vDateStart = vFromDated;
- SET vDateEnd = util.Dayend(vToDated);
-
- SELECT a.nickname shopName,
- a.city ,
- IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode,
- tp.quantity,
- tp.ticketFk,
- CONCAT('From ', vFromDated,' to ', vToDated) AS dateRange
- FROM vn.ticketPackaging tp
- JOIN vn.ticket t ON t.id = tp.ticketFk
- JOIN vn.warehouse w ON w.id = t.warehouseFk
- JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk
- JOIN vn.packaging p ON p.id = tp.packagingFk
- LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p2 ON p2.id = a.provinceFk
- JOIN vn.country c ON c.id = p2.countryFk
- WHERE t.shipped BETWEEN vFromDated AND util.dayend(vToDated)
- AND wa.name = 'VNH'
- AND p.isPackageReturnable
- AND c.country = 'FRANCIA'
- AND t.clientFk != vSijsnerClientFk
- AND tp.quantity > 0;
-
+BEGIN
+
+ DECLARE vSijsnerClientFk INT DEFAULT 19752;
+
+ DECLARE vDateStart DATETIME;
+ DECLARE vDateEnd DATETIME;
+
+ SET vDateStart = vFromDated;
+ SET vDateEnd = util.Dayend(vToDated);
+
+ SELECT a.nickname shopName,
+ a.city ,
+ IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode,
+ tp.quantity,
+ tp.ticketFk,
+ CONCAT('From ', vFromDated,' to ', vToDated) AS dateRange
+ FROM vn.ticketPackaging tp
+ JOIN vn.ticket t ON t.id = tp.ticketFk
+ JOIN vn.warehouse w ON w.id = t.warehouseFk
+ JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk
+ JOIN vn.packaging p ON p.id = tp.packagingFk
+ LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id
+ JOIN vn.address a ON a.id = t.addressFk
+ JOIN vn.province p2 ON p2.id = a.provinceFk
+ JOIN vn.country c ON c.id = p2.countryFk
+ WHERE t.shipped BETWEEN vFromDated AND util.dayend(vToDated)
+ AND wa.name = 'VNH'
+ AND p.isPackageReturnable
+ AND c.country = 'FRANCIA'
+ AND t.clientFk != vSijsnerClientFk
+ AND tp.quantity > 0;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -61447,25 +61232,25 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `intrastat_data_neto_Update`(IN vInvoiceInFk INT)
-BEGIN
-
- UPDATE vn2008.intrastat_data id
- JOIN (
- SELECT i.intrastatFk,
- LEAST(SUM(b.quantity) * IFNULL(it.gramsMax,100000) / 1000,
- SUM(ic.cm3 * b.quantity) * IF(i.density, i.density, it.density) / 1000000) as neto
- FROM entry e
- JOIN travel tr ON tr.id = e.travelFk
- JOIN buy b ON b.entryFk = e.id
- JOIN item i ON i.id = b.itemFk
- join itemType it ON it.id = i.typeFk
- JOIN itemCost ic ON ic.itemFk = i.id AND tr.warehouseInFk = ic.warehouseFk
- WHERE e.invoiceInFk = vinvoiceInFk
- GROUP BY i.intrastatFk) sub ON sub.intrastatFk = id.intrastat_id
- SET id.neto = ROUND(sub.neto, 1)
- WHERE id.recibida_id = vInvoiceInFk;
-
-
+BEGIN
+
+ UPDATE vn2008.intrastat_data id
+ JOIN (
+ SELECT i.intrastatFk,
+ LEAST(SUM(b.quantity) * IFNULL(it.gramsMax,100000) / 1000,
+ SUM(ic.cm3 * b.quantity) * IF(i.density, i.density, it.density) / 1000000) as neto
+ FROM entry e
+ JOIN travel tr ON tr.id = e.travelFk
+ JOIN buy b ON b.entryFk = e.id
+ JOIN item i ON i.id = b.itemFk
+ join itemType it ON it.id = i.typeFk
+ JOIN itemCost ic ON ic.itemFk = i.id AND tr.warehouseInFk = ic.warehouseFk
+ WHERE e.invoiceInFk = vinvoiceInFk
+ GROUP BY i.intrastatFk) sub ON sub.intrastatFk = id.intrastat_id
+ SET id.neto = ROUND(sub.neto, 1)
+ WHERE id.recibida_id = vInvoiceInFk;
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -63239,46 +63024,46 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInDueDay_calculate`(vInvoiceInFk INT)
-BEGIN
-
- IF !(SELECT COUNT(*)
- FROM invoiceInDueDay iid
- WHERE iid.invoiceInFk = vInvoiceInFk) THEN
-
- INSERT INTO invoiceInDueDay (invoiceInFk,
- dueDated,
- amount,
- foreignValue)
- SELECT vInvoiceInFk,
- IF(payDay,
- IF(vn.getNextDueDate(issued, detail, payDay) < DATE_ADD(created, INTERVAL 2 DAY),
- DATE_ADD(created, INTERVAL 2 DAY),
- vn.getNextDueDate(issued, detail, payDay)),
- GREATEST(TIMESTAMPADD(DAY, 2, created), TIMESTAMPADD(DAY, detail, issued))),
- IF((@cont:=@cont + 1) < cont, TRUNCATE(venc / cont, 2),venc-(TRUNCATE(venc / cont, 2) * (cont - 1))),
- IF(@cont < cont, TRUNCATE(foreignValue / cont, 2), foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1)))
- FROM ( SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100)*(s.countryFk = s2.countryFk)) * iit.taxableBase)/COUNT(DISTINCT(pdd.detail)) venc,
- SUM(iit.foreignValue)/COUNT(DISTINCT(pdd.detail)) foreignValue,
- s.payDemFk,
- ii.companyFk,
- COUNT(DISTINCT(pdd.detail)) cont,
- s.payDay,
- ii.issued,
- DATE(ii.created) created
- FROM invoiceIn ii
- JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id
- LEFT JOIN sage.TiposIva AS ti ON ti.CodigoIva= iit.taxTypeSageFk
- JOIN supplier s ON s.id = ii.supplierFk
- JOIN supplier s2 ON s2.id = ii.companyFk
- JOIN vn.payDemDetail pdd ON pdd.id = s.payDemFk
- WHERE ii.id = vInvoiceInFk
- GROUP BY ii.id
- ) sub
- JOIN (SELECT @cont:=0) sub2
- JOIN vn.payDemDetail pdd ON pdd.id = sub.payDemFk
- GROUP BY detail;
- END IF;
-
+BEGIN
+
+ IF !(SELECT COUNT(*)
+ FROM invoiceInDueDay iid
+ WHERE iid.invoiceInFk = vInvoiceInFk) THEN
+
+ INSERT INTO invoiceInDueDay (invoiceInFk,
+ dueDated,
+ amount,
+ foreignValue)
+ SELECT vInvoiceInFk,
+ IF(payDay,
+ IF(vn.getNextDueDate(issued, detail, payDay) < DATE_ADD(created, INTERVAL 2 DAY),
+ DATE_ADD(created, INTERVAL 2 DAY),
+ vn.getNextDueDate(issued, detail, payDay)),
+ GREATEST(TIMESTAMPADD(DAY, 2, created), TIMESTAMPADD(DAY, detail, issued))),
+ IF((@cont:=@cont + 1) < cont, TRUNCATE(venc / cont, 2),venc-(TRUNCATE(venc / cont, 2) * (cont - 1))),
+ IF(@cont < cont, TRUNCATE(foreignValue / cont, 2), foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1)))
+ FROM ( SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100)*(s.countryFk = s2.countryFk)) * iit.taxableBase)/COUNT(DISTINCT(pdd.detail)) venc,
+ SUM(iit.foreignValue)/COUNT(DISTINCT(pdd.detail)) foreignValue,
+ s.payDemFk,
+ ii.companyFk,
+ COUNT(DISTINCT(pdd.detail)) cont,
+ s.payDay,
+ ii.issued,
+ DATE(ii.created) created
+ FROM invoiceIn ii
+ JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id
+ LEFT JOIN sage.TiposIva AS ti ON ti.CodigoIva= iit.taxTypeSageFk
+ JOIN supplier s ON s.id = ii.supplierFk
+ JOIN supplier s2 ON s2.id = ii.companyFk
+ JOIN vn.payDemDetail pdd ON pdd.id = s.payDemFk
+ WHERE ii.id = vInvoiceInFk
+ GROUP BY ii.id
+ ) sub
+ JOIN (SELECT @cont:=0) sub2
+ JOIN vn.payDemDetail pdd ON pdd.id = sub.payDemFk
+ GROUP BY detail;
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -64185,225 +63970,225 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_new`(
- vSerial VARCHAR(255),
- vInvoiceDate DATETIME,
- vTaxArea VARCHAR(25),
+CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_new`(
+ vSerial VARCHAR(255),
+ vInvoiceDate DATETIME,
+ vTaxArea VARCHAR(25),
OUT vNewInvoiceId INT)
-BEGIN
-
-/* Creación de facturas emitidas.
-* requiere previamente tabla ticketToInvoice(id).
-*
-* @param vSerial serie a la cual se hace la factura
-* @param vInvoiceDate fecha de la factura
-* @param vTaxArea tipo de iva en relacion a la empresa y al cliente
-* @param vNewInvoiceId id de la factura que se acaba de generar
-*
-* @return vNewInvoiceId
-*/
-
- DECLARE vSpainCountryCode INT DEFAULT 1;
- DECLARE vIsAnySaleToInvoice BOOL;
- DECLARE vIsAnyServiceToInvoice BOOL;
- DECLARE vNewRef VARCHAR(255);
- DECLARE vWorker INT DEFAULT account.myUser_getId();
- DECLARE vCompany INT;
- DECLARE vSupplier INT;
- DECLARE vClient INT;
- DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1;
- DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6;
- DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2;
- DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R';
- DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S';
- DECLARE vNewInvoiceInId INT;
- DECLARE vIsInterCompany BOOL;
-
- SET vInvoiceDate = IFNULL(vInvoiceDate,CURDATE());
-
- SELECT t.clientFk, t.companyFk
- INTO vClient, vCompany
- FROM ticketToInvoice tt
- JOIN ticket t ON t.id = tt.id
- LIMIT 1;
-
- -- Eliminem de ticketToInvoice els tickets que no han de ser facturats
- DELETE ti.*
- FROM ticketToInvoice ti
- JOIN ticket t ON t.id = ti.id
- JOIN client c ON c.id = t.clientFk
- WHERE YEAR(t.shipped) < 2001
- OR c.isTaxDataChecked = FALSE
- OR t.isDeleted
- OR c.hasToInvoice = FALSE;
-
- SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id
- INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice
- FROM ticketToInvoice t
- LEFT JOIN sale s ON s.ticketFk = t.id
- LEFT JOIN ticketService ts ON ts.ticketFk = t.id;
-
- IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice)
- AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase())
- THEN
-
- -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial
- INSERT INTO invoiceOut
- (
- ref,
- serial,
- issued,
- clientFk,
- dued,
- companyFk,
- cplusInvoiceType477Fk
- )
- SELECT
- 1,
- vSerial,
- vInvoiceDate,
- vClient,
- getDueDate(vInvoiceDate, dueDay),
- vCompany,
- IF(vSerial = vCorrectingSerial,
- vCplusCorrectingInvoiceTypeFk,
- IF(vSerial = vSimplifiedSerial,
- vCplusSimplifiedInvoiceTypeFk,
- vCplusStandardInvoiceTypeFk))
- FROM client
- WHERE id = vClient;
-
-
- SET vNewInvoiceId = LAST_INSERT_ID();
-
- SELECT `ref`
- INTO vNewRef
- FROM invoiceOut
- WHERE id = vNewInvoiceId;
-
- UPDATE ticket t
- JOIN ticketToInvoice ti ON ti.id = t.id
- SET t.refFk = vNewRef;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
- CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
- SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
- FROM ticketToInvoice ti
- LEFT JOIN vn.ticketState ts ON ti.id = ts.ticket
- JOIN state s
- WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = vn.getAlert3State(ti.id);
-
- INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador)
- SELECT * FROM tmp.updateInter;
-
-
- INSERT INTO ticketLog (action, userFk,originFk, description)
- SELECT 'UPDATE',account.userGetId(),ti.id, CONCAT('Crea factura ',vNewRef)
- FROM ticketToInvoice ti;
-
- CALL invoiceExpenceMake(vNewInvoiceId);
- CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
-
- UPDATE invoiceOut io
- JOIN (
- SELECT SUM(amount) AS total
- FROM invoiceOutExpence
- WHERE invoiceOutFk = vNewInvoiceId
- ) base
- JOIN (
- SELECT SUM(vat) AS total
- FROM invoiceOutTax
- WHERE invoiceOutFk = vNewInvoiceId
- ) vat
- SET io.amount = base.total + vat.total
- WHERE io.id = vNewInvoiceId;
-
- DROP TEMPORARY TABLE tmp.updateInter;
-
- SELECT ios.isCEE INTO vIsInterCompany
- FROM vn.ticket t
- JOIN vn.company c ON c.clientFk = t.clientFk
- JOIN vn.invoiceOut io ON io.`ref` = t.refFk
- JOIN vn.invoiceOutSerial ios ON ios.code = io.serial
- WHERE t.refFk = vNewRef;
-
- IF (vIsInterCompany) THEN
-
- SELECT vCompany INTO vSupplier;
- SELECT id INTO vCompany FROM company WHERE clientFk = vClient;
-
- INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk)
- SELECT vSupplier, vNewRef, vInvoiceDate, vCompany;
-
- SET vNewInvoiceInId = LAST_INSERT_ID();
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
- CREATE TEMPORARY TABLE tmp.ticket
- (KEY (ticketFk))
- ENGINE = MEMORY
- SELECT id ticketFk
- FROM ticketToInvoice;
-
- CALL `ticket_getTax`('NATIONAL');
-
- SET @vTaxableBaseServices := 0.00;
- SET @vTaxCodeGeneral := NULL;
-
- INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk)
- SELECT vNewInvoiceInId, @vTaxableBaseServices, sub.expenceFk, sub.taxTypeSageFk , sub.transactionTypeSageFk
- FROM (
- SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, i.expenceFk, i.taxTypeSageFk , i.transactionTypeSageFk, @vTaxCodeGeneral := i.taxClassCodeFk
- FROM tmp.ticketServiceTax tst
- JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code
- WHERE i.isService
- HAVING taxableBase
- ) sub;
-
- INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk)
- SELECT vNewInvoiceInId, SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, @vTaxableBaseServices, 0) taxableBase, i.expenceFk, i.taxTypeSageFk , i.transactionTypeSageFk
- FROM tmp.ticketTax tt
- JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code
- WHERE !i.isService
- GROUP BY tt.pgcFk
- HAVING taxableBase
- ORDER BY tt.priority;
-
- CALL `vn`.`invoiceInDueDay_calculate`(vNewInvoiceInId);
-
- INSERT INTO vn2008.intrastat_data (recibida_id, intrastat_id, importe, unidades, Paises_Id, neto)
- SELECT
- vNewInvoiceInId,
- i.intrastatFk,
- CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100)) AS DECIMAL(10,2)) importe,
- CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL (10 , 2 )) stems,
- s2.countryFk,
- CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) neto
- FROM vn.sale s
- LEFT JOIN (SELECT ic.itemFk, ic.cm3delivery
- FROM vn.itemCost ic
- WHERE ic.cm3
- GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk
- LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
- LEFT JOIN vn.ticket t ON s.ticketFk = t.id
- LEFT JOIN vn.supplier s2 ON s2.id = t.companyFk
- LEFT JOIN vn.item i ON i.id = s.itemFk
- LEFT JOIN vn.intrastat it ON it.id = i.intrastatFk
- JOIN vn.invoiceOut iOut ON iOut.ref = t.refFk
- WHERE iOut.`ref` = vNewRef
- GROUP BY i.intrastatFk
- ORDER BY i.intrastatFk;
-
-
- DROP TEMPORARY TABLE tmp.ticket;
- DROP TEMPORARY TABLE tmp.ticketAmount;
- DROP TEMPORARY TABLE tmp.ticketTax;
- DROP TEMPORARY TABLE tmp.ticketServiceTax;
-
- END IF;
-
- END IF;
-
- DROP TEMPORARY TABLE `ticketToInvoice`;
+BEGIN
+
+/* Creación de facturas emitidas.
+* requiere previamente tabla ticketToInvoice(id).
+*
+* @param vSerial serie a la cual se hace la factura
+* @param vInvoiceDate fecha de la factura
+* @param vTaxArea tipo de iva en relacion a la empresa y al cliente
+* @param vNewInvoiceId id de la factura que se acaba de generar
+*
+* @return vNewInvoiceId
+*/
+
+ DECLARE vSpainCountryCode INT DEFAULT 1;
+ DECLARE vIsAnySaleToInvoice BOOL;
+ DECLARE vIsAnyServiceToInvoice BOOL;
+ DECLARE vNewRef VARCHAR(255);
+ DECLARE vWorker INT DEFAULT account.myUser_getId();
+ DECLARE vCompany INT;
+ DECLARE vSupplier INT;
+ DECLARE vClient INT;
+ DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1;
+ DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6;
+ DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2;
+ DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R';
+ DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S';
+ DECLARE vNewInvoiceInId INT;
+ DECLARE vIsInterCompany BOOL;
+
+ SET vInvoiceDate = IFNULL(vInvoiceDate,CURDATE());
+
+ SELECT t.clientFk, t.companyFk
+ INTO vClient, vCompany
+ FROM ticketToInvoice tt
+ JOIN ticket t ON t.id = tt.id
+ LIMIT 1;
+
+ -- Eliminem de ticketToInvoice els tickets que no han de ser facturats
+ DELETE ti.*
+ FROM ticketToInvoice ti
+ JOIN ticket t ON t.id = ti.id
+ JOIN client c ON c.id = t.clientFk
+ WHERE YEAR(t.shipped) < 2001
+ OR c.isTaxDataChecked = FALSE
+ OR t.isDeleted
+ OR c.hasToInvoice = FALSE;
+
+ SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id
+ INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice
+ FROM ticketToInvoice t
+ LEFT JOIN sale s ON s.ticketFk = t.id
+ LEFT JOIN ticketService ts ON ts.ticketFk = t.id;
+
+ IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice)
+ AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase())
+ THEN
+
+ -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial
+ INSERT INTO invoiceOut
+ (
+ ref,
+ serial,
+ issued,
+ clientFk,
+ dued,
+ companyFk,
+ cplusInvoiceType477Fk
+ )
+ SELECT
+ 1,
+ vSerial,
+ vInvoiceDate,
+ vClient,
+ getDueDate(vInvoiceDate, dueDay),
+ vCompany,
+ IF(vSerial = vCorrectingSerial,
+ vCplusCorrectingInvoiceTypeFk,
+ IF(vSerial = vSimplifiedSerial,
+ vCplusSimplifiedInvoiceTypeFk,
+ vCplusStandardInvoiceTypeFk))
+ FROM client
+ WHERE id = vClient;
+
+
+ SET vNewInvoiceId = LAST_INSERT_ID();
+
+ SELECT `ref`
+ INTO vNewRef
+ FROM invoiceOut
+ WHERE id = vNewInvoiceId;
+
+ UPDATE ticket t
+ JOIN ticketToInvoice ti ON ti.id = t.id
+ SET t.refFk = vNewRef;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
+ CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
+ SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
+ FROM ticketToInvoice ti
+ LEFT JOIN vn.ticketState ts ON ti.id = ts.ticket
+ JOIN state s
+ WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = vn.getAlert3State(ti.id);
+
+ INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador)
+ SELECT * FROM tmp.updateInter;
+
+
+ INSERT INTO ticketLog (action, userFk,originFk, description)
+ SELECT 'UPDATE',account.userGetId(),ti.id, CONCAT('Crea factura ',vNewRef)
+ FROM ticketToInvoice ti;
+
+ CALL invoiceExpenceMake(vNewInvoiceId);
+ CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
+
+ UPDATE invoiceOut io
+ JOIN (
+ SELECT SUM(amount) AS total
+ FROM invoiceOutExpence
+ WHERE invoiceOutFk = vNewInvoiceId
+ ) base
+ JOIN (
+ SELECT SUM(vat) AS total
+ FROM invoiceOutTax
+ WHERE invoiceOutFk = vNewInvoiceId
+ ) vat
+ SET io.amount = base.total + vat.total
+ WHERE io.id = vNewInvoiceId;
+
+ DROP TEMPORARY TABLE tmp.updateInter;
+
+ SELECT ios.isCEE INTO vIsInterCompany
+ FROM vn.ticket t
+ JOIN vn.company c ON c.clientFk = t.clientFk
+ JOIN vn.invoiceOut io ON io.`ref` = t.refFk
+ JOIN vn.invoiceOutSerial ios ON ios.code = io.serial
+ WHERE t.refFk = vNewRef;
+
+ IF (vIsInterCompany) THEN
+
+ SELECT vCompany INTO vSupplier;
+ SELECT id INTO vCompany FROM company WHERE clientFk = vClient;
+
+ INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk)
+ SELECT vSupplier, vNewRef, vInvoiceDate, vCompany;
+
+ SET vNewInvoiceInId = LAST_INSERT_ID();
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ (KEY (ticketFk))
+ ENGINE = MEMORY
+ SELECT id ticketFk
+ FROM ticketToInvoice;
+
+ CALL `ticket_getTax`('NATIONAL');
+
+ SET @vTaxableBaseServices := 0.00;
+ SET @vTaxCodeGeneral := NULL;
+
+ INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk)
+ SELECT vNewInvoiceInId, @vTaxableBaseServices, sub.expenceFk, sub.taxTypeSageFk , sub.transactionTypeSageFk
+ FROM (
+ SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, i.expenceFk, i.taxTypeSageFk , i.transactionTypeSageFk, @vTaxCodeGeneral := i.taxClassCodeFk
+ FROM tmp.ticketServiceTax tst
+ JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code
+ WHERE i.isService
+ HAVING taxableBase
+ ) sub;
+
+ INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk)
+ SELECT vNewInvoiceInId, SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, @vTaxableBaseServices, 0) taxableBase, i.expenceFk, i.taxTypeSageFk , i.transactionTypeSageFk
+ FROM tmp.ticketTax tt
+ JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code
+ WHERE !i.isService
+ GROUP BY tt.pgcFk
+ HAVING taxableBase
+ ORDER BY tt.priority;
+
+ CALL `vn`.`invoiceInDueDay_calculate`(vNewInvoiceInId);
+
+ INSERT INTO vn2008.intrastat_data (recibida_id, intrastat_id, importe, unidades, Paises_Id, neto)
+ SELECT
+ vNewInvoiceInId,
+ i.intrastatFk,
+ CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100)) AS DECIMAL(10,2)) importe,
+ CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL (10 , 2 )) stems,
+ s2.countryFk,
+ CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) neto
+ FROM vn.sale s
+ LEFT JOIN (SELECT ic.itemFk, ic.cm3delivery
+ FROM vn.itemCost ic
+ WHERE ic.cm3
+ GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk
+ LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
+ LEFT JOIN vn.ticket t ON s.ticketFk = t.id
+ LEFT JOIN vn.supplier s2 ON s2.id = t.companyFk
+ LEFT JOIN vn.item i ON i.id = s.itemFk
+ LEFT JOIN vn.intrastat it ON it.id = i.intrastatFk
+ JOIN vn.invoiceOut iOut ON iOut.ref = t.refFk
+ WHERE iOut.`ref` = vNewRef
+ GROUP BY i.intrastatFk
+ ORDER BY i.intrastatFk;
+
+
+ DROP TEMPORARY TABLE tmp.ticket;
+ DROP TEMPORARY TABLE tmp.ticketAmount;
+ DROP TEMPORARY TABLE tmp.ticketTax;
+ DROP TEMPORARY TABLE tmp.ticketServiceTax;
+
+ END IF;
+
+ END IF;
+
+ DROP TEMPORARY TABLE `ticketToInvoice`;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -64811,84 +64596,84 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `itemCard`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT, IN isBarcode BOOL)
-BEGIN
-
- /*
- * @deprecated: Utilizar item_getInfo
- */
-
- DECLARE vCacheVisibleFk INT;
- DECLARE vCacheAvailableFk INT;
- DECLARE vVisibleAltillo INT;
- DECLARE vItemFk INT;
-
- IF isBarcode THEN
- SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
- ELSE
- SELECT i.id INTO vItemFk
- FROM vn.item i
- WHERE i.name LIKE CONCAT('%',vBarcode,'%')
- ORDER BY i.id ASC
- LIMIT 1;
- END IF;
-
- IF vItemFk IS NULL THEN
- SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
- END IF;
-
- CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk);
- CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, CURDATE());
-
- SELECT SUM(visible) INTO vVisibleAltillo
- FROM vn.itemShelvingStock
- WHERE itemFk = vItemFk AND warehouseFk = vWarehouseFk;
-
- CALL vn.buyUltimate(vWarehouseFk, CURDATE());
-
- SELECT i.id,
- i.longName,
- i.tag5,
- i.value5,
- i.tag6,
- i.value6,
- i.tag7,
- i.value7,
- i.image,
- i.size,
- i.stems,
- i.category,
- i.minimum as min,
- i.upToDown as repo,
- p.name as producer,
- o.code as origin,
- ip.code as nicho,
- ip.reserve as reserva,
- v.visible - IFNULL(vVisibleAltillo,0) as enNicho,
- a.available,
- vVisibleAltillo as enAltillo,
- v.visible as total,
- c.`grouping` as `grouping`,
- c.Packing as packing,
- CONCAT('https://verdnatura.es/vn-image-data/catalog/200x200/', i.image) as urlImage200,
- CONCAT('https://verdnatura.es/vn-image-data/catalog/1600x900/', i.image) as urlImage,
- i.itemPackingTypeFk,
- i.comment as referencia
- FROM vn.item i
- LEFT JOIN vn.producer p ON p.id = i.producerFk
- LEFT JOIN vn.origin o ON o.id = i.originFk
- LEFT JOIN vn.itemPlacement ip ON ip.itemFk = i.id
- LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id
- LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id
- LEFT JOIN (
- SELECT b.itemFk, b2.`grouping`, b2.packing
- FROM tmp.buyUltimate b
- JOIN vn.buy b2 ON b2.id = b.buyFk
- WHERE b.warehouseFk = vWarehouseFk
- ) c ON i.id = c.itemFk
- WHERE i.id = vItemFk;
-
- DROP TEMPORARY TABLE tmp.buyUltimate;
-
+BEGIN
+
+ /*
+ * @deprecated: Utilizar item_getInfo
+ */
+
+ DECLARE vCacheVisibleFk INT;
+ DECLARE vCacheAvailableFk INT;
+ DECLARE vVisibleAltillo INT;
+ DECLARE vItemFk INT;
+
+ IF isBarcode THEN
+ SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
+ ELSE
+ SELECT i.id INTO vItemFk
+ FROM vn.item i
+ WHERE i.name LIKE CONCAT('%',vBarcode,'%')
+ ORDER BY i.id ASC
+ LIMIT 1;
+ END IF;
+
+ IF vItemFk IS NULL THEN
+ SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
+ END IF;
+
+ CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk);
+ CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, CURDATE());
+
+ SELECT SUM(visible) INTO vVisibleAltillo
+ FROM vn.itemShelvingStock
+ WHERE itemFk = vItemFk AND warehouseFk = vWarehouseFk;
+
+ CALL vn.buyUltimate(vWarehouseFk, CURDATE());
+
+ SELECT i.id,
+ i.longName,
+ i.tag5,
+ i.value5,
+ i.tag6,
+ i.value6,
+ i.tag7,
+ i.value7,
+ i.image,
+ i.size,
+ i.stems,
+ i.category,
+ i.minimum as min,
+ i.upToDown as repo,
+ p.name as producer,
+ o.code as origin,
+ ip.code as nicho,
+ ip.reserve as reserva,
+ v.visible - IFNULL(vVisibleAltillo,0) as enNicho,
+ a.available,
+ vVisibleAltillo as enAltillo,
+ v.visible as total,
+ c.`grouping` as `grouping`,
+ c.Packing as packing,
+ CONCAT('https://verdnatura.es/vn-image-data/catalog/200x200/', i.image) as urlImage200,
+ CONCAT('https://verdnatura.es/vn-image-data/catalog/1600x900/', i.image) as urlImage,
+ i.itemPackingTypeFk,
+ i.comment as referencia
+ FROM vn.item i
+ LEFT JOIN vn.producer p ON p.id = i.producerFk
+ LEFT JOIN vn.origin o ON o.id = i.originFk
+ LEFT JOIN vn.itemPlacement ip ON ip.itemFk = i.id
+ LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id
+ LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id
+ LEFT JOIN (
+ SELECT b.itemFk, b2.`grouping`, b2.packing
+ FROM tmp.buyUltimate b
+ JOIN vn.buy b2 ON b2.id = b.buyFk
+ WHERE b.warehouseFk = vWarehouseFk
+ ) c ON i.id = c.itemFk
+ WHERE i.id = vItemFk;
+
+ DROP TEMPORARY TABLE tmp.buyUltimate;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -64996,119 +64781,119 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `itemDiary__`(IN vItemId INT, IN vWarehouse INT)
-BEGIN
- DECLARE vDateInventory DATETIME;
- DECLARE vCurdate DATE DEFAULT CURDATE();
- DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate);
-
- SELECT vn.barcodeToItem(vItemId) INTO vItemId;
-
- -- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance
- SELECT inventoried INTO vDateInventory FROM config;
- SET @a = 0;
- SELECT DATE(date) AS date,
- alertLevel,
- stateName,
- origin,
- reference,
- clientFk,
- name,
- `in`,
- `out`,
- @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance,
- isPicked,
- isTicket,
- `in` as invalue
- FROM
- ( SELECT tr.landed as date,
- b.quantity as `in`,
- NULL as `out`,
- IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel,
- st.name AS stateName,
- s.name as name,
- e.ref as reference,
- e.id as origin,
- s.id as clientFk,
- TRUE isPicked,
- FALSE AS isTicket
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel tr ON tr.id = e.travelFk
- JOIN supplier s ON s.id = e.supplierFk
- JOIN alertLevel al ON al.id =
- CASE
- WHEN tr.isReceived != FALSE THEN 3
- WHEN tr.isDelivered THEN 1
- ELSE 0
- END
- JOIN state st ON st.code = al.code
- WHERE tr.landed >= vDateInventory
- AND vWarehouse = tr.warehouseInFk
- AND b.itemFk = vItemId
- AND e.isInventory = 0
- AND e.isRaid = 0
- UNION ALL
-
- SELECT tr.shipped as date,
- NULL as `in`,
- b.quantity as `out`,
- IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel,
- st.name AS stateName,
- s.name as name,
- e.ref as reference,
- e.id as origin,
- s.id as clientFk,
- TRUE isPicked,
- FALSE AS isTicket
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel tr ON tr.id = e.travelFk
- JOIN warehouse w ON w.id = tr.warehouseOutFk
- JOIN supplier s ON s.id = e.supplierFk
- JOIN alertLevel al ON al.id =
- CASE
- WHEN tr.isReceived != FALSE THEN 3
- WHEN tr.isDelivered THEN 1
- ELSE 0
- END
- JOIN state st ON st.code = al.code
- WHERE tr.shipped >= vDateInventory
- AND vWarehouse =tr.warehouseOutFk
- AND s.id <> 4
- AND b.itemFk = vItemId
- AND e.isInventory = 0
- AND w.isFeedStock = 0
- AND e.isRaid = 0
- UNION ALL
-
- SELECT t.shipped as date,
- NULL as `in`,
- s.quantity as `out`,
- al.id as alertLevel,
- st.name AS stateName,
- t.nickname as name,
- t.refFk as reference,
- t.id as origin,
- t.clientFk,
- stk.id as isPicked, -- TRUE as isPicked
- TRUE as isTicket
- FROM sale s
- JOIN ticket t ON t.id = s.ticketFk
- LEFT JOIN ticketState ts ON ts.ticket = t.id
- LEFT JOIN state st ON st.code = ts.code
- JOIN client c ON c.id = t.clientFk
- JOIN alertLevel al ON al.id =
- CASE
- WHEN t.shipped < vCurdate THEN 3
- WHEN t.shipped > vDayEnd THEN 0
- ELSE IFNULL(ts.alertLevel, 0)
- END
- LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = 14 -- comentar
- WHERE t.shipped >= vDateInventory
- AND s.itemFk = vItemId
- AND vWarehouse =t.warehouseFk
- ) AS itemDiary
- ORDER BY date, isTicket, alertLevel DESC, isPicked DESC, `in` DESC, `out` DESC;
+BEGIN
+ DECLARE vDateInventory DATETIME;
+ DECLARE vCurdate DATE DEFAULT CURDATE();
+ DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate);
+
+ SELECT vn.barcodeToItem(vItemId) INTO vItemId;
+
+ -- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance
+ SELECT inventoried INTO vDateInventory FROM config;
+ SET @a = 0;
+ SELECT DATE(date) AS date,
+ alertLevel,
+ stateName,
+ origin,
+ reference,
+ clientFk,
+ name,
+ `in`,
+ `out`,
+ @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance,
+ isPicked,
+ isTicket,
+ `in` as invalue
+ FROM
+ ( SELECT tr.landed as date,
+ b.quantity as `in`,
+ NULL as `out`,
+ IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel,
+ st.name AS stateName,
+ s.name as name,
+ e.ref as reference,
+ e.id as origin,
+ s.id as clientFk,
+ TRUE isPicked,
+ FALSE AS isTicket
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel tr ON tr.id = e.travelFk
+ JOIN supplier s ON s.id = e.supplierFk
+ JOIN alertLevel al ON al.id =
+ CASE
+ WHEN tr.isReceived != FALSE THEN 3
+ WHEN tr.isDelivered THEN 1
+ ELSE 0
+ END
+ JOIN state st ON st.code = al.code
+ WHERE tr.landed >= vDateInventory
+ AND vWarehouse = tr.warehouseInFk
+ AND b.itemFk = vItemId
+ AND e.isInventory = 0
+ AND e.isRaid = 0
+ UNION ALL
+
+ SELECT tr.shipped as date,
+ NULL as `in`,
+ b.quantity as `out`,
+ IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel,
+ st.name AS stateName,
+ s.name as name,
+ e.ref as reference,
+ e.id as origin,
+ s.id as clientFk,
+ TRUE isPicked,
+ FALSE AS isTicket
+ FROM buy b
+ JOIN entry e ON e.id = b.entryFk
+ JOIN travel tr ON tr.id = e.travelFk
+ JOIN warehouse w ON w.id = tr.warehouseOutFk
+ JOIN supplier s ON s.id = e.supplierFk
+ JOIN alertLevel al ON al.id =
+ CASE
+ WHEN tr.isReceived != FALSE THEN 3
+ WHEN tr.isDelivered THEN 1
+ ELSE 0
+ END
+ JOIN state st ON st.code = al.code
+ WHERE tr.shipped >= vDateInventory
+ AND vWarehouse =tr.warehouseOutFk
+ AND s.id <> 4
+ AND b.itemFk = vItemId
+ AND e.isInventory = 0
+ AND w.isFeedStock = 0
+ AND e.isRaid = 0
+ UNION ALL
+
+ SELECT t.shipped as date,
+ NULL as `in`,
+ s.quantity as `out`,
+ al.id as alertLevel,
+ st.name AS stateName,
+ t.nickname as name,
+ t.refFk as reference,
+ t.id as origin,
+ t.clientFk,
+ stk.id as isPicked, -- TRUE as isPicked
+ TRUE as isTicket
+ FROM sale s
+ JOIN ticket t ON t.id = s.ticketFk
+ LEFT JOIN ticketState ts ON ts.ticket = t.id
+ LEFT JOIN state st ON st.code = ts.code
+ JOIN client c ON c.id = t.clientFk
+ JOIN alertLevel al ON al.id =
+ CASE
+ WHEN t.shipped < vCurdate THEN 3
+ WHEN t.shipped > vDayEnd THEN 0
+ ELSE IFNULL(ts.alertLevel, 0)
+ END
+ LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = 14 -- comentar
+ WHERE t.shipped >= vDateInventory
+ AND s.itemFk = vItemId
+ AND vWarehouse =t.warehouseFk
+ ) AS itemDiary
+ ORDER BY date, isTicket, alertLevel DESC, isPicked DESC, `in` DESC, `out` DESC;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -66353,70 +66138,6 @@ BEGIN
DELETE FROM vn.itemShelving WHERE id = vId;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingEdit__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingEdit__`(vVisible INT,vPacking INT,vId INT)
-BEGIN
-
- /*
- * @deprecated: utilizar itemShelving_update
- */
- UPDATE vn.itemShelving SET available = vVisible, visible = vVisible, packing = vPacking WHERE id = vId;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingList__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingList__`(IN `vShelvingFk` VARCHAR(8))
-BEGIN
-
- /*
- * @deprecated:Utilizar itemShelving_get
- */
-
- /*MODIFICADA POR QUIQUE: OBTENEMOS DEEP Y PARKING*/
- SELECT ish.itemFk as item,
- IFNULL(i.longName, CONCAT(i.name, ' ',i.size)) as description,
- ish.visible as visible,
- ceil(ish.visible/ish.packing) as stickers,
- ish.packing as packing,
- IF (p.`column` IS NULL,"",p.`column`) as col,
- IF (p.`row` IS NULL,"",p.`row`) as `row`,
- IF (p.`code` IS NULL,"",p.`code`) as `code`,
- ish.id,
- s.priority
- FROM vn.itemShelving ish
- JOIN vn.item i ON i.id = ish.itemFk
- INNER JOIN vn.shelving s ON vShelvingFk = s.code COLLATE utf8_unicode_ci
- LEFT JOIN vn.parking p ON s.parkingFk = p.id
- WHERE ish.shelvingFk COLLATE utf8_unicode_ci =vShelvingFk COLLATE utf8_unicode_ci;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -66481,155 +66202,63 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vShelve` VARCHAR(2), IN `vDeep` INT, IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, IN `vLevel` INT,`vCreated` VARCHAR(22))
+CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vShelve` VARCHAR(2), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, `vCreated` VARCHAR(22))
BEGIN
-
-
DECLARE vItemFk INT;
-
-
-
- SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
-
- SELECT itemFk INTO vItemFk
- FROM vn.buy b
+ SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
+
+ SELECT itemFk INTO vItemFk
+ FROM vn.buy b
WHERE b.id = vItemFk;
-
-
- IF (SELECT COUNT(*) FROM vn.shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN
-
- INSERT IGNORE INTO vn.parking(`code`) VALUES(vShelvingFk);
- INSERT INTO vn.shelving(`code`, parkingFk)
- SELECT vShelvingFk, id
- FROM vn.parking
- WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci;
-
- END IF;
-
- IF (SELECT COUNT(*) FROM vn.itemShelving
- WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
- AND itemFk = vItemFk
- AND packing = vPacking) = 1 THEN
- UPDATE vn.itemShelving SET quantity = quantity+vQuantity,visible = visible+vQuantity,available = available+vQuantity, created = vCreated
- WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking;
-
- ELSE
- CALL cache.last_buy_refresh(FALSE);
- INSERT INTO itemShelving( itemFk,
- shelvingFk,
- shelve,
- deep,
- quantity,
- visible,
- available,
- created,
- `grouping`,
- packing,
- packagingFk,
- level)
- SELECT
- vItemFk,
- vShelvingFk,
- vShelve,
- vDeep,
- vQuantity,
- vQuantity,
- vQuantity,
- vCreated,
- IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) as `grouping`,
- IF(vPacking = 0, b.packing, vPacking) as packing,
- IF(vPackagingFk = '', b.packageFk, vPackagingFk) as packaging,
- vLevel
- FROM vn.item i
- LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk
- LEFT JOIN vn.buy b ON b.id = lb.buy_id
- WHERE i.id = vItemFk;
- END IF;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingMake__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMake__`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vShelve` VARCHAR(2), IN `vDeep` INT, IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, IN `vLevel` INT)
-BEGIN
-
-
- /*
- * @deprecated:utilizar itemShelving_add
- */
-
- DECLARE vItemFk INT;
+ IF (SELECT COUNT(*) FROM vn.shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN
- SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
-
- /*SELECT itemFk INTO vItemFk
- FROM vn.buy b
- WHERE b.id = vItemFk;*/
-
- IF (SELECT COUNT(*) FROM vn.shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN
-
- INSERT IGNORE INTO vn.parking(`code`) VALUES(vShelvingFk);
- INSERT INTO vn.shelving(`code`, parkingFk)
- SELECT vShelvingFk, id
- FROM vn.parking
+ INSERT IGNORE INTO vn.parking(`code`) VALUES(vShelvingFk);
+ INSERT INTO vn.shelving(`code`, parkingFk)
+ SELECT vShelvingFk, id
+ FROM vn.parking
WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci;
-
+
END IF;
-
+
IF (SELECT COUNT(*) FROM vn.itemShelving
- WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
- AND itemFk = vItemFk
- AND packing = vPacking) = 1 THEN
+ WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
+ AND itemFk = vItemFk
+ AND packing = vPacking) = 1 THEN
+
+ UPDATE vn.itemShelving
+ SET visible = visible+vQuantity,
+ created = vCreated
+ WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
+ AND itemFk = vItemFk
+ AND packing = vPacking;
- UPDATE vn.itemShelving SET quantity = quantity+vQuantity,visible = visible+vQuantity,available = available+vQuantity
- WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking;
-
ELSE
- CALL cache.last_buy_refresh(FALSE);
- INSERT INTO itemShelving( itemFk,
- shelvingFk,
- shelve,
- deep,
- quantity,
- visible,
- available,
- `grouping`,
- packing,
- packagingFk,
- level)
-
- SELECT
- vItemFk,
- vShelvingFk,
- vShelve,
- vDeep,
- vQuantity,
- vQuantity,
- vQuantity,
- IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) as `grouping`,
- IF(vPacking = 0, b.packing, vPacking) as packing,
- IF(vPackagingFk = '', b.packageFk, vPackagingFk) as packaging,
- vLevel
- FROM vn.item i
- LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk
- LEFT JOIN vn.buy b ON b.id = lb.buy_id
- WHERE i.id = vItemFk;
- END IF;
+ CALL cache.last_buy_refresh(FALSE);
+ INSERT INTO itemShelving( itemFk,
+ shelvingFk,
+ shelve,
+ visible,
+ created,
+ `grouping`,
+ packing,
+ packagingFk)
+ SELECT vItemFk,
+ vShelvingFk,
+ vShelve,
+ vQuantity,
+ vCreated,
+ IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) `grouping`,
+ IF(vPacking = 0, b.packing, vPacking) packing,
+ IF(vPackagingFk = '', b.packageFk, vPackagingFk) packaging
+ FROM vn.item i
+ LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk
+ LEFT JOIN vn.buy b ON b.id = lb.buy_id
+ WHERE i.id = vItemFk;
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -66693,20 +66322,18 @@ DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingPlacementSupplyAdd`(vItemShelvingFk INT, vItemPlacementSupplyFk INT, vQuantity INT)
BEGIN
- INSERT INTO vn.itemShelvingPlacementSupply( itemShelvingFk,
- itemPlacementSupplyFk,
- quantity,
+ INSERT INTO vn.itemShelvingPlacementSupply( itemShelvingFk,
+ itemPlacementSupplyFk,
+ quantity,
userFk)
- VALUES ( vItemShelvingFk,
- vItemPlacementSupplyFk,
- vQuantity,
- getUser());
-
- UPDATE vn.itemShelving
- SET quantity = quantity - vQuantity,
- visible = visible - vQuantity,
- available = available - vQuantity
- WHERE id = vItemShelvingFk;
+ VALUES (vItemShelvingFk,
+ vItemPlacementSupplyFk,
+ vQuantity,
+ getUser());
+
+ UPDATE vn.itemShelving
+ SET visible = visible - vQuantity
+ WHERE id = vItemShelvingFk;
END ;;
@@ -67124,25 +66751,27 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar_Urgent`(vWorkerFk INT)
+CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar_Urgent`()
BEGIN
+/**
+ * Devuelve lo mismo que itemShelving_filterBuyer per sin filtrar
+ */
DECLARE vCalcVisibleFk INT;
DECLARE vWarehouseFk INT DEFAULT 60;
- -- Eliminar cuando tengamos programador de Android
-
CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk);
SELECT * FROM
(SELECT sub.itemFk,
sub.longName,
- CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`,
+ CONCAT(DATE_FORMAT(sub2.etd,'%H:%i'), ' salen ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`,
CONCAT(IF(sub2.itemFk, IF(sub2.pendiente > (sub.upstairs + sub.downstairs),'(1) ','(2) '),'(3) ' ),sub.producer) producer,
sub.upstairs,
sub.downstairs,
sub.visible,
sub.sectorFk,
- CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) nicho
+ CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) nicho,
+ sub2.etd
FROM (SELECT iss.itemFk,
CONCAT(i.longName,' ',i.size,' ',IFNULL(i.subName,'') ) longName,
'' size,
@@ -67150,19 +66779,19 @@ BEGIN
0 upstairs,
SUM(IFNULL(iss.visible,0)) downstairs,
IF(it.isPackaging, null, IFNULL(v.visible,0)) visible,
- 0 sectorFk
+ IFNULL(iss.sectorFk,0) sectorFk
FROM itemShelvingStock iss
JOIN sector s ON s.id = iss.sectorFk
JOIN item i on i.id = iss.itemFk
JOIN itemType it ON it.id = i.typeFk
- LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk
+ LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = @vCalcVisibleFk
WHERE s.warehouseFk = vWarehouseFk
- AND it.workerFk = vWorkerFk
GROUP BY itemFk
- ) sub LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente
+ ) sub LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente, MIN(zc.`hour`) etd
FROM sale s
LEFT JOIN saleTracking st ON st.saleFk = s.id
- JOIN ticket t ON t.id = s.ticketFk
+ JOIN ticket t ON t.id = s.ticketFk
+ LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
JOIN client c on c.id = t.clientFk
JOIN clientType ct ON ct.id = c.clientTypeFk
WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE())
@@ -67173,21 +66802,23 @@ BEGIN
UNION ALL
SELECT v.item_id ,
i.longName,
- CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`,
+ CONCAT(DATE_FORMAT(sub5.etd,'%H:%i'), ' salen ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`,
CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer,
0,
0,
v.visible,
- 0,
- v.visible nicho
+ IFNULL(iss.sectorFk,0),
+ v.visible nicho,
+ sub5.etd
FROM cache.visible v
JOIN item i ON i.id = v.item_id
JOIN itemType it ON it.id = i.typeFk
LEFT JOIN itemShelvingStock iss ON iss.itemFk = v.item_id
- LEFT JOIN (SELECT s.itemFk , SUM(s.quantity) pendiente
+ LEFT JOIN (SELECT s.itemFk , SUM(s.quantity) pendiente, MIN(zc.`hour`) etd
FROM sale s
LEFT JOIN saleTracking st ON st.saleFk = s.id
- JOIN ticket t ON t.id = s.ticketFk
+ JOIN ticket t ON t.id = s.ticketFk
+ LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
JOIN client c on c.id = t.clientFk
JOIN clientType ct ON ct.id = c.clientTypeFk
WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE())
@@ -67195,107 +66826,11 @@ BEGIN
AND ct.code IN ('normal', 'trust')
GROUP BY s.itemFk
) sub5 ON sub5.itemFk = v.item_id
- WHERE v.calc_id = vCalcVisibleFk
+ WHERE v.calc_id = @vCalcVisibleFk
AND ISNULL(iss.itemFk)
- AND it.workerFk = vWorkerFk
) sub3
WHERE nicho
- ORDER BY producer;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingRadar_Urgent__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar_Urgent__`(vWorkerFk INT)
-BEGIN
- DECLARE vCalcVisibleFk INT;
- DECLARE vWarehouseFk INT DEFAULT 60;
- -- DECLARE vSectorFk INt;
- -- DECLARE vFatherSectorFk INT;
-
- -- Eliminar cuando tengamos programador de Android
-
- CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk);
-
- SELECT * FROM (
- SELECT sub.itemFk,
- sub.longName,
- CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`,
- CONCAT(IF(sub2.itemFk, IF(sub2.pendiente > (sub.upstairs + sub.downstairs),'(1) ','(2) '),'(3) ' ),sub.producer) producer,
- sub.upstairs,
- sub.downstairs,
- sub.visible,
- sub.sectorFk,
- CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) AS nicho
- FROM (
- SELECT iss.itemFk,
- CONCAT(i.longName,' ',i.size,' ',IFNULL(i.subName,'') ) longName,
- '' size,
- CONCAT(iss.parkingCode , ' ', iss.shelvingFk) producer,
- 0 upstairs,
- SUM(IFNULL(iss.visible,0)) downstairs,
- IF(it.isPackaging, null, IFNULL(v.visible,0)) as visible,
- 0 as sectorFk
- FROM vn.itemShelvingStock iss
- JOIN vn.sector s ON s.id = iss.sectorFk
- JOIN vn.item i on i.id = iss.itemFk
- JOIN vn.itemType it ON it.id = i.typeFk
- LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk
- WHERE s.warehouseFk = vWarehouseFk
- AND it.workerFk = vWorkerFk
- GROUP BY itemFk
- ) sub
- LEFT JOIN (SELECT s.itemFk , sum(s.quantity) as pendiente
- FROM vn.sale s
- LEFT JOIN vn.saleTracking st ON st.saleFk = s.id
- JOIN vn.ticket t ON t.id = s.ticketFk
- JOIN vn.client c on c.id = t.clientFk
- WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE())
- AND ISNULL(st.saleFk)
- AND (c.clientTypeFk = 1 OR c.clientTypeFk = 5)
- GROUP BY s.itemFk) sub2 ON sub2.itemFk = sub.itemFk
-
- UNION ALL
-
- SELECT v.item_id ,
- i.longName,
- CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`,
- CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer,
- 0,
- 0,
- v.visible,
- 0,
- v.visible AS nicho
- FROM cache.visible v
- JOIN vn.item i ON i.id = v.item_id
- JOIN vn.itemType it ON it.id = i.typeFk
- LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id
- LEFT JOIN (SELECT s.itemFk , sum(s.quantity) as pendiente
- FROM vn.sale s
- LEFT JOIN vn.saleTracking st ON st.saleFk = s.id
- JOIN vn.ticket t ON t.id = s.ticketFk
- JOIN vn.client c on c.id = t.clientFk
- WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE())
- AND ISNULL(st.saleFk)
- AND (c.clientTypeFk = 1 OR c.clientTypeFk = 5)
- GROUP BY s.itemFk) sub5 ON sub5.itemFk = v.item_id
- WHERE v.calc_id = vCalcVisibleFk
- AND ISNULL(iss.itemFk)
- AND it.workerFk = vWorkerFk) sub3
- WHERE nicho
- ORDER BY producer;
+ ORDER BY LEFT(producer,3), etd, producer;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -67315,20 +66850,21 @@ DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSaleAdd`(vItemShelvingFk INT, saleFk INT, vQuantity INT)
BEGIN
-IF saleFk <> 0 THEN
- INSERT INTO vn.itemShelvingSale( itemShelvingFk,
- saleFk,
- quantity,
- userFk)
- VALUES ( vItemShelvingFk,
- saleFk,
+ IF saleFk <> 0 THEN
+ INSERT INTO vn.itemShelvingSale(itemShelvingFk,
+ saleFk,
+ quantity,
+ userFk)
+ VALUES (vItemShelvingFk,
+ saleFk,
vQuantity,
getUser());
-
-END IF;
- UPDATE vn.itemShelving SET quantity = (quantity - vQuantity), available = (available - vQuantity), visible = (visible - vQuantity)
- WHERE id = vItemShelvingFk;
+ END IF;
+
+ UPDATE vn.itemShelving
+ SET visible = (visible - vQuantity)
+ WHERE id = vItemShelvingFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -67341,172 +66877,36 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSaleSupplyAdd`(vItemShelvingFk INT, saleFk INT, vQuantity INT)
-BEGIN
-
-/*
- * Añade línea a itemShelvingSale y regulariza el carro
- *
- * @param vItemShelvingFk Id itemShelving
- * @param saleFk Id de sale
- * @param vQuantity cantidad a regularizar
- *
- */
-
- INSERT INTO itemShelvingSale( itemShelvingFk,
- saleFk,
- quantity,
- userFk)
- VALUES ( vItemShelvingFk,
- saleFk,
- vQuantity,
- getUser());
-
- UPDATE itemShelving
- SET quantity = quantity - vQuantity,
- visible = visible - vQuantity,
- available = available - vQuantity
- WHERE id = vItemShelvingFk;
-
+BEGIN
+/**
+ * Añade línea a itemShelvingSale y regulariza el carro
+ *
+ * @param vItemShelvingFk Id itemShelving
+ * @param saleFk Id de sale
+ * @param vQuantity cantidad a regularizar
+ */
+ INSERT INTO itemShelvingSale(itemShelvingFk,
+ saleFk,
+ quantity,
+ userFk)
+ VALUES (vItemShelvingFk,
+ saleFk,
+ vQuantity,
+ getUser());
+
+ UPDATE itemShelving
+ SET visible = visible - vQuantity
+ WHERE id = vItemShelvingFk;
+
UPDATE vn2008.Movimientos_mark
- SET valor = 1
- WHERE Id_Movimiento = saleFk;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingSaleSupplyAddVoz` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSaleSupplyAddVoz`(vItemShelvingFk VARCHAR(50), saleFk INT, vQuantity INT,idMovimiento INT)
-BEGIN
+ SET valor = 1
+ WHERE Id_Movimiento = saleFk;
-
-/*INSERT INTO `vn`.`errorLogApp` (`error`, `workerFk`) VALUES (CONCAT(vItemShelvingFk," ",saleFk), '14255');*/
-
-DECLARE vItemShelvingFkAux INT;
-DECLARE vItemFk INT;
-
-SELECT itemFk INTO vItemFk FROM vn.sale WHERE id = saleFk;
-
-SELECT id INTO vItemShelvingFkAux FROM vn.itemShelving WHERE shelvingFk = vItemShelvingFk COLLATE utf8_general_ci AND itemFk = vItemFk;
-
-INSERT INTO vn.itemShelvingSale( itemShelvingFk,
- saleFk,
- quantity,
- userFk)
- VALUES ( vItemShelvingFkAux,
- saleFk,
- vQuantity,
- getUser());
-
- UPDATE vn.itemShelving
- SET quantity = quantity - vQuantity,
- visible = visible - vQuantity,
- available = available - vQuantity
- WHERE id = vItemShelvingFkAux;
-
- UPDATE vn2008.Movimientos_mark
- SET valor = 1
- WHERE Id_Movimiento = idMovimiento;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingSaleSupplyAdd_` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSaleSupplyAdd_`(vItemShelvingFk INT, saleFk INT, vQuantity INT,idMovimiento INT)
-BEGIN
-
-INSERT INTO vn.itemShelvingSale( itemShelvingFk,
- saleFk,
- quantity,
- userFk)
- VALUES ( vItemShelvingFk,
- saleFk,
- vQuantity,
- getUser());
-
- UPDATE vn.itemShelving
- SET quantity = quantity - vQuantity,
- visible = visible - vQuantity,
- available = available - vQuantity
- WHERE id = vItemShelvingFk;
-
- UPDATE vn2008.Movimientos_mark
- SET valor = 1
- WHERE Id_Movimiento = idMovimiento;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingTicketSource__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingTicketSource__`(vTicketFk INT)
-BEGIN
- DECLARE vCalcFk INT;
- DECLARE vWarehouseFk INT;
-
- SELECT warehouseFk INTO vWarehouseFk
- FROM vn.ticket
- WHERE id = vTicketFk;
- SET vCalcFk = cache.ticketShippingCalcIdGet(vWarehouseFk);
-
- SELECT
- s.id,
- ubication,
- s.quantity,
- sis.quantity as Reserved,
- s.itemFk,
- s.concept,
- s.ticketFk,
- s.isPicked,
- ish.packing,
- FLOOR(sis.quantity / ish.packing) as stickers,
- sis.quantity MOD ish.packing as rest,
- ts.shippingHour,
- ts.shippingMinute
- FROM vn.saleItemShelving sis
- JOIN vn.itemShelving ish ON ish.id = sis.itemShelvingFk
- JOIN vn.sale s ON s.id = sis.saleFk
- JOIN cache.ticketShipping ts ON ts.calc_id = vCalcFk AND ts.ticketFk = vTicketFk
- WHERE s.ticketFk = vTicketFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -67542,84 +66942,118 @@ DELIMITER ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vShelve VARCHAR(2), IN vDeep INT, IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT, IN vLevel INT)
+CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vShelve VARCHAR(2), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT)
BEGIN
+
/**
* Añade registro o lo actualiza si ya existe.
*
* @param vShelvingFk matrícula del carro
* @param vBarcode el id del registro
* @param vShelve de itemshleving
- * @param vDeep indica profundidad
* @param vQuantity indica la cantidad del producto
* @param vPackagingFk el packaging del producto en itemShelving, NULL para coger el de la ultima compra
* @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra
* @param vPacking el packing del producto, NULL para coger el de la ultima compra
* @param vWarehouseFk indica el sector
- * @param vLevel indica el level
*
**/
-
- DECLARE vItemFk INT;
- SELECT barcodeToItem(vBarcode) INTO vItemFk;
-
+ DECLARE vItemFk INT;
+
+ SELECT barcodeToItem(vBarcode) INTO vItemFk;
+
IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN
-
+
INSERT IGNORE INTO parking(code) VALUES(vShelvingFk);
- INSERT INTO shelving(code, parkingFk)
+ INSERT INTO shelving(code, parkingFk)
SELECT vShelvingFk, id
FROM parking
- WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci;
-
- END IF;
-
- IF (SELECT COUNT(*) FROM itemShelving
+ WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci;
+
+ END IF;
+
+ IF (SELECT COUNT(*) FROM itemShelving
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
AND itemFk = vItemFk
AND packing = vPacking) = 1 THEN
- UPDATE itemShelving SET quantity = quantity+vQuantity,visible = visible+vQuantity,available = available+vQuantity
- WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking;
-
- ELSE
+ UPDATE itemShelving
+ SET visible = visible+vQuantity
+ WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking;
+
+ ELSE
CALL cache.last_buy_refresh(FALSE);
- INSERT INTO itemShelving( itemFk,
- shelvingFk,
- shelve,
- deep,
- quantity,
- visible,
- available,
- grouping,
- packing,
- packagingFk,
- level)
-
- SELECT
- vItemFk,
- vShelvingFk,
- vShelve,
- vDeep,
- vQuantity,
- vQuantity,
- vQuantity,
- IFNULL(vGrouping, b.grouping),
- IFNULL(vPacking, b.packing),
- IFNULL(vPackagingFk, b.packageFk),
- vLevel
- FROM item i
+ INSERT INTO itemShelving( itemFk,
+ shelvingFk,
+ shelve,
+ visible,
+ grouping,
+ packing,
+ packagingFk)
+
+ SELECT vItemFk,
+ vShelvingFk,
+ vShelve,
+ vQuantity,
+ IFNULL(vGrouping, b.grouping),
+ IFNULL(vPacking, b.packing),
+ IFNULL(vPackagingFk, b.packageFk)
+ FROM item i
LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk
LEFT JOIN buy b ON b.id = lb.buy_id
WHERE i.id = vItemFk;
- END IF;
+ END IF;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `itemShelving_addByClaim` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_addByClaim`(vClaimFk INT, vShelvingFk VARCHAR(3))
+BEGIN
+/**
+ * Insert items of claim into itemShelving.
+ *
+ * @param vClaimFk The claim
+ * @param vShelvingFk The shelving
+ * @table tmp.buyUltimate
+ */
+ DECLARE vWarehouseFk INT;
+
+ SELECT t.warehouseFk INTO vWarehouseFk
+ FROM claim c
+ JOIN ticket t ON t.id = c.ticketFk
+ WHERE c.id = vClaimFk;
+
+ CALL buyUltimate (vWarehouseFk, CURDATE());
+
+ INSERT INTO itemShelving (itemFk, shelvingFk, packing, `grouping`, visible)
+ SELECT s.itemFk, vShelvingFk, b.packing, b.`grouping`, cb.quantity AS visible
+ FROM claim c
+ JOIN claimBeginning cb ON c.id = cb.claimFk
+ JOIN sale s ON s.id = cb.saleFk
+ JOIN ticket t ON t.id = s.ticketFk
+ JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk AND bu.warehouseFk = t.warehouseFk
+ JOIN buy b ON b.id = bu.buyFk
+ WHERE c.id = vClaimFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -67707,6 +67141,11 @@ proc:BEGIN
*/
DECLARE vCalcVisibleFk INT;
+ IF vBuyerFk = 103 THEN -- hay que arreglarlo despues de la campaña PAK 23/04/2022
+ CALL vn.itemShelvingRadar_Urgent();
+ LEAVE proc;
+ END IF;
+
CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk);
SELECT * FROM
@@ -67777,7 +67216,6 @@ proc:BEGIN
) sub3
WHERE nicho
ORDER BY producer;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -67838,30 +67276,25 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_getInfo`(vItemFk VARCHAR(22))
BEGIN
-
- /*
- * Muestra información realtiva a la ubicación de un ítem
- *
- * @param vItemFk Id del ítem
- *
- */
-
- SELECT vn.barcodeToItem(vItemFk) INTO vItemFk;
+/**
+ * Muestra información realtiva a la ubicación de un item
+ *
+ * @param vItemFk Id del item
+ */
+ SELECT vn.barcodeToItem(vItemFk)
+ INTO vItemFk;
- SELECT pk.code as Parking,
- sh.code as Matricula,
- ish.visible as visible,
- ish.available as Disponible,
- ish.level as level,
- ish.created as created,
- ish.itemFk as itemFk,
- sh.priority
+ SELECT pk.code Parking,
+ sh.code Matricula,
+ ish.visible visible,
+ ish.created created,
+ ish.itemFk itemFk,
+ sh.priority
FROM vn.itemShelving ish
JOIN vn.shelving sh ON sh.`code` = ish.shelvingFk
JOIN vn.parking pk ON pk.id = sh.parkingFk
WHERE ish.itemFk = vItemFk
ORDER BY sh.priority DESC, created ASC;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -67982,46 +67415,46 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_inventory`(vParkingFromFk INT, vParkingToFk INT)
-BEGIN
-
- /**
- * Devuelve un listado de ubicaciones a revisar
- *
- * @param vParkingFromFk Parking de partida, identificador de vn.parking
- * @param vParkingToFk Parking de llegada, identificador de vn.parking
- */
-
- DECLARE vSectorFk INT;
- DECLARE vPickingOrderFrom INT;
- DECLARE vPickingOrderTo INT;
-
- SELECT p.sectorFk, p.pickingOrder INTO vSectorFk, vPickingOrderFrom
- FROM vn.parking p
- WHERE p.id = vParkingFromFk;
-
- SELECT p.pickingOrder INTO vPickingOrderTo
- FROM vn.parking p
- WHERE p.id = vParkingToFk;
-
- CALL vn.visible_getMisfit(vSectorFk);
-
- SELECT p.code parking ,
- ish.shelvingFk ,
- ish.itemFk,
- i.longName,
- ish.visible ,
- ish.visible / ish.packing packs,
- ish.packing,
- sm.visible - sm.parked faltan
- FROM vn.itemShelving ish
- JOIN vn.item i ON i.id = ish.itemFk
- JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk
- JOIN vn.shelving sh ON sh.code = ish.shelvingFk
- JOIN vn.parking p ON p.id = sh.parkingFk
- WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo
- AND p.sectorFk = vSectorFk
- ORDER BY p.pickingOrder ;
-
+BEGIN
+
+ /**
+ * Devuelve un listado de ubicaciones a revisar
+ *
+ * @param vParkingFromFk Parking de partida, identificador de vn.parking
+ * @param vParkingToFk Parking de llegada, identificador de vn.parking
+ */
+
+ DECLARE vSectorFk INT;
+ DECLARE vPickingOrderFrom INT;
+ DECLARE vPickingOrderTo INT;
+
+ SELECT p.sectorFk, p.pickingOrder INTO vSectorFk, vPickingOrderFrom
+ FROM vn.parking p
+ WHERE p.id = vParkingFromFk;
+
+ SELECT p.pickingOrder INTO vPickingOrderTo
+ FROM vn.parking p
+ WHERE p.id = vParkingToFk;
+
+ CALL vn.visible_getMisfit(vSectorFk);
+
+ SELECT p.code parking ,
+ ish.shelvingFk ,
+ ish.itemFk,
+ i.longName,
+ ish.visible ,
+ ish.visible / ish.packing packs,
+ ish.packing,
+ sm.visible - sm.parked faltan
+ FROM vn.itemShelving ish
+ JOIN vn.item i ON i.id = ish.itemFk
+ JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk
+ JOIN vn.shelving sh ON sh.code = ish.shelvingFk
+ JOIN vn.parking p ON p.id = sh.parkingFk
+ WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo
+ AND p.sectorFk = vSectorFk
+ ORDER BY p.pickingOrder ;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -68071,12 +67504,11 @@ BEGIN
* @param vPacking el packing del del producto en itemShelving
* @param vGrouping el grouping del producto en itemShelving
*/
- UPDATE itemShelving SET
- available = vVisible,
- visible = vVisible,
- packing = vPacking,
- grouping = vGrouping
- WHERE id = vShelf;
+ UPDATE itemShelving
+ SET visible = vVisible,
+ packing = vPacking,
+ grouping = vGrouping
+ WHERE id = vShelf;
END ;;
DELIMITER ;
@@ -68163,105 +67595,73 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemStockUpdate__`(
- vItemFk INT,
- vWarehouseFk INT,
- vNewVisible INT,
+CREATE DEFINER=`root`@`localhost` PROCEDURE `itemStockUpdate__`(
+ vItemFk INT,
+ vWarehouseFk INT,
+ vNewVisible INT,
vIsTrash BOOLEAN)
-BEGIN
-
- DECLARE vTicketFk INT;
- DECLARE vClientFk INT;
- DECLARE vCompanyVnlFk INT DEFAULT 442;
- DECLARE vVisible INT DEFAULT 0;
- DECLARE vCalc INT;
- DECLARE vParkedStuff INT;
-
- SELECT barcodeToItem(vItemFk) INTO vItemFk;
-
- CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
-
- SELECT IFNULL(visible,0) INTO vVisible
- FROM cache.visible
- WHERE calc_id = vCalc
- AND item_id = vItemFk;
-
- SELECT sum(visible) INTO vParkedStuff
- FROM itemShelvingStock
- WHERE warehouseFk = vWarehouseFk
- AND itemFk = vItemFk;
-
- SET vNewVisible = vNewVisible + IFNULL(vParkedStuff,0);
-
- SELECT IF(vIsTrash, 200, 400) INTO vClientFk;
-
- SELECT t.id INTO vTicketFk
- FROM ticket t
- JOIN address a ON a.id=t.addressFk
- WHERE t.warehouseFk = vWarehouseFk
- AND t.clientFk = vClientFk
- AND DATE(t.shipped) = CURDATE()
- AND a.isDefaultAddress
- LIMIT 1;
-
- IF vTicketFk IS NULL THEN
-
- CALL ticket_add(
- vClientFk,
- CURDATE(),
- vWarehouseFk,
- vCompanyVnlFk,
- NULL,
- NULL,
- NULL,
- CURDATE(),
- account.userGetId(),
- FALSE,
- vTicketFk);
-
- END IF;
-
- INSERT INTO sale(ticketFk, itemFk, concept, quantity, price, discount)
- SELECT vTicketFk, vItemFk, CONCAT(longName,' ', getWorkerCode(), ' ',LEFT(CAST(NOW() AS TIME),5)), vVisible - vNewVisible, 0, 0
- FROM item
- WHERE id = vItemFk;
-
- UPDATE cache.visible
- SET visible = vNewVisible
- WHERE calc_id = vCalc
- AND item_id = vItemFk;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemStockVisible_verify` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemStockVisible_verify`(vItemFk INT, vQuantity INT)
BEGIN
- INSERT INTO vn.itemShelving(itemFk,
- shelvingFk,
- quantity,
- visible,
- available,
- packing)
- VALUES( vItemFk,
- 'FAL',
- -vQuantity,
- -vQuantity,
- -vQuantity,
- -vQuantity);
+ DECLARE vTicketFk INT;
+ DECLARE vClientFk INT;
+ DECLARE vCompanyVnlFk INT DEFAULT 442;
+ DECLARE vVisible INT DEFAULT 0;
+ DECLARE vCalc INT;
+ DECLARE vParkedStuff INT;
+
+ SELECT barcodeToItem(vItemFk) INTO vItemFk;
+
+ CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
+
+ SELECT IFNULL(visible,0) INTO vVisible
+ FROM cache.visible
+ WHERE calc_id = vCalc
+ AND item_id = vItemFk;
+
+ SELECT sum(visible) INTO vParkedStuff
+ FROM itemShelvingStock
+ WHERE warehouseFk = vWarehouseFk
+ AND itemFk = vItemFk;
+
+ SET vNewVisible = vNewVisible + IFNULL(vParkedStuff,0);
+
+ SELECT IF(vIsTrash, 200, 400) INTO vClientFk;
+
+ SELECT t.id INTO vTicketFk
+ FROM ticket t
+ JOIN address a ON a.id=t.addressFk
+ WHERE t.warehouseFk = vWarehouseFk
+ AND t.clientFk = vClientFk
+ AND DATE(t.shipped) = CURDATE()
+ AND a.isDefaultAddress
+ LIMIT 1;
+
+ IF vTicketFk IS NULL THEN
+
+ CALL ticket_add(
+ vClientFk,
+ CURDATE(),
+ vWarehouseFk,
+ vCompanyVnlFk,
+ NULL,
+ NULL,
+ NULL,
+ CURDATE(),
+ account.userGetId(),
+ FALSE,
+ vTicketFk);
+
+ END IF;
+
+ INSERT INTO sale(ticketFk, itemFk, concept, quantity, price, discount)
+ SELECT vTicketFk, vItemFk, CONCAT(longName,' ', getWorkerCode(), ' ',LEFT(CAST(NOW() AS TIME),5)), vVisible - vNewVisible, 0, 0
+ FROM item
+ WHERE id = vItemFk;
+
+ UPDATE cache.visible
+ SET visible = vNewVisible
+ WHERE calc_id = vCalc
+ AND item_id = vItemFk;
END ;;
DELIMITER ;
@@ -68565,37 +67965,37 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTag_replace`(vItemFromFk INT, vItemToFk INT, vPicture VARCHAR(100))
-BEGIN
-
- /* Reemplaza los tags de un artículo por los de otro, así como su imagen
- *
- * @param vItemFromFk id de vn.item con el artículo del que se toman los tags
- * @param vItemToFk id de vn.item con el artículo del que se toman los tags
- * @param vPicture imagen del artículo. Opcional. Si no se especifica, hereada la del vItemFromFk
- */
-
- DELETE FROM vn.itemTag
- WHERE itemFk = vItemToFk;
-
- INSERT INTO vn.itemTag(itemFk, tagFk, value, priority)
- SELECT vItemToFk, tagFk, value, priority
- FROM vn.itemTag
- WHERE itemFk = vItemFromFk;
-
- IF ISNULL(vPicture) THEN
-
- SELECT image INTO vPicture
- FROM vn.item
- WHERE id = vItemFromFk;
-
- END IF;
-
- UPDATE vn.item i
- SET i.image = vPicture
- WHERE i.id = vItemToFk;
-
- CALL vn.itemRefreshTags(vItemToFk);
-
+BEGIN
+
+ /* Reemplaza los tags de un artículo por los de otro, así como su imagen
+ *
+ * @param vItemFromFk id de vn.item con el artículo del que se toman los tags
+ * @param vItemToFk id de vn.item con el artículo del que se toman los tags
+ * @param vPicture imagen del artículo. Opcional. Si no se especifica, hereada la del vItemFromFk
+ */
+
+ DELETE FROM vn.itemTag
+ WHERE itemFk = vItemToFk;
+
+ INSERT INTO vn.itemTag(itemFk, tagFk, value, priority)
+ SELECT vItemToFk, tagFk, value, priority
+ FROM vn.itemTag
+ WHERE itemFk = vItemFromFk;
+
+ IF ISNULL(vPicture) THEN
+
+ SELECT image INTO vPicture
+ FROM vn.item
+ WHERE id = vItemFromFk;
+
+ END IF;
+
+ UPDATE vn.item i
+ SET i.image = vPicture
+ WHERE i.id = vItemToFk;
+
+ CALL vn.itemRefreshTags(vItemToFk);
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -68688,62 +68088,62 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTrash`(
- vItemFk INT,
- vWarehouseFk INT,
- vQuantity INT,
+CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTrash`(
+ vItemFk INT,
+ vWarehouseFk INT,
+ vQuantity INT,
vIsTrash BOOLEAN)
-BEGIN
-
- DECLARE vTicketFk INT;
- DECLARE vClientFk INT;
- DECLARE vCompanyVnlFk INT DEFAULT 442;
- DECLARE vCalc INT;
-
- SELECT barcodeToItem(vItemFk) INTO vItemFk;
-
- SELECT IF(vIsTrash, 200, 400) INTO vClientFk;
-
- SELECT t.id INTO vTicketFk
- FROM ticket t
- JOIN address a ON a.id=t.addressFk
- WHERE t.warehouseFk = vWarehouseFk
- AND t.clientFk = vClientFk
- AND DATE(t.shipped) = CURDATE()
- AND a.isDefaultAddress
- LIMIT 1;
-
- CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
-
- IF vTicketFk IS NULL THEN
-
- CALL ticket_add(
- vClientFk,
- CURDATE(),
- vWarehouseFk,
- vCompanyVnlFk,
- NULL,
- NULL,
- NULL,
- CURDATE(),
- account.userGetId(),
- FALSE,
- vTicketFk);
- END IF;
-
- INSERT INTO sale(ticketFk, itemFk, concept, quantity)
- SELECT vTicketFk,
- vItemFk,
- CONCAT(longName,' ',getWorkerCode(), ' ', LEFT(CAST(NOW() AS TIME),5)),
- vQuantity
- FROM item
- WHERE id = vItemFk;
-
- UPDATE cache.visible
- SET visible = visible - vQuantity
- WHERE calc_id = vCalc
- AND item_id = vItemFk;
-
+BEGIN
+
+ DECLARE vTicketFk INT;
+ DECLARE vClientFk INT;
+ DECLARE vCompanyVnlFk INT DEFAULT 442;
+ DECLARE vCalc INT;
+
+ SELECT barcodeToItem(vItemFk) INTO vItemFk;
+
+ SELECT IF(vIsTrash, 200, 400) INTO vClientFk;
+
+ SELECT t.id INTO vTicketFk
+ FROM ticket t
+ JOIN address a ON a.id=t.addressFk
+ WHERE t.warehouseFk = vWarehouseFk
+ AND t.clientFk = vClientFk
+ AND DATE(t.shipped) = CURDATE()
+ AND a.isDefaultAddress
+ LIMIT 1;
+
+ CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
+
+ IF vTicketFk IS NULL THEN
+
+ CALL ticket_add(
+ vClientFk,
+ CURDATE(),
+ vWarehouseFk,
+ vCompanyVnlFk,
+ NULL,
+ NULL,
+ NULL,
+ CURDATE(),
+ account.userGetId(),
+ FALSE,
+ vTicketFk);
+ END IF;
+
+ INSERT INTO sale(ticketFk, itemFk, concept, quantity)
+ SELECT vTicketFk,
+ vItemFk,
+ CONCAT(longName,' ',getWorkerCode(), ' ', LEFT(CAST(NOW() AS TIME),5)),
+ vQuantity
+ FROM item
+ WHERE id = vItemFk;
+
+ UPDATE cache.visible
+ SET visible = visible - vQuantity
+ WHERE calc_id = vCalc
+ AND item_id = vItemFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -68815,126 +68215,126 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_clean`(vItemFrom INT, vItemTo INT)
-BEGIN
-
-/*
- * Elimina todos los items repetidos y los sustituye por el que tiene menor id
- */
-
- START TRANSACTION;
-
- SET @isModeInventory:= TRUE;
-
- -- Deletes
-
- UPDATE IGNORE vn.itemCost ic
- JOIN tmp.itemsToReplace itr ON ic.itemFk = itr.idOld
- SET ic.itemFk = itr.idNew;
-
- DELETE ic.*
- FROM vn.itemCost ic
- JOIN tmp.itemsToReplace itr ON ic.itemFk = itr.idOld;
-
- DELETE rt.*
- FROM vn2008.rec_translator rt
- JOIN tmp.itemsToReplace itr ON rt.Id_Article = itr.idOld;
-
- DELETE w.*
- FROM bs.waste w
- JOIN tmp.itemsToReplace itr ON w.itemFk = itr.idOld;
-
- DELETE pf.*
- FROM vn.priceFixed pf
- JOIN tmp.itemsToReplace itr ON pf.itemFk = itr.idOld;
-
- DELETE imp.*
- FROM vn.itemMatchProperties imp
- JOIN tmp.itemsToReplace itr ON imp.itemFk = itr.idOld;
-
- DELETE ib.*
- FROM vn.itemBotanical ib
- JOIN tmp.itemsToReplace itr ON ib.itemFk = itr.idOld;
-
- DELETE ip.*
- FROM vn.itemProposal ip
- JOIN tmp.itemsToReplace itr ON ip.itemFk = itr.idOld;
-
- DELETE it.*
- FROM vn.itemTag it
- JOIN tmp.itemsToReplace itr ON it.itemFk = itr.idOld;
-
- DELETE ib.*
- FROM vn.itemBarcode ib
- JOIN tmp.itemsToReplace itr ON ib.itemFk = itr.idOld;
-
- DELETE itc.*
- FROM vn.itemTaxCountry itc
- JOIN tmp.itemsToReplace itr ON itc.itemFk = itr.idOld;
-
- DELETE ip.*
- FROM vn.itemPlacement ip
- JOIN tmp.itemsToReplace itr ON ip.itemFk = itr.idOld;
-
- -- Updates
-
- UPDATE vn.buy b
- JOIN tmp.itemsToReplace itr ON b.itemFk = itr.idOld
- SET b.itemFk = itr.idNew;
-
- UPDATE vn.sale s
- JOIN tmp.itemsToReplace itr ON s.itemFk = itr.idOld
- SET s.itemFk = itr.idNew;
-
- UPDATE vn.specialPrice sp
- JOIN tmp.itemsToReplace itr ON sp.itemFk = itr.idOld
- SET sp.itemFk = itr.idNew;
-
- UPDATE vn.packaging p
- JOIN tmp.itemsToReplace itr ON p.itemFk = itr.idOld
- SET p.itemFk = itr.idNew;
-
- UPDATE vn.packaging p
- JOIN tmp.itemsToReplace itr ON p.freightItemFk = itr.idOld
- SET p.freightItemFk = itr.idNew;
-
- UPDATE hedera.orderRow o
- JOIN tmp.itemsToReplace itr ON o.itemFk = itr.idOld
- SET o.itemFk = itr.idNew;
-
- UPDATE vn.itemLog il
- JOIN tmp.itemsToReplace itr ON il.originFk = itr.idOld
- SET il.originFk = itr.idNew;
-
- UPDATE vn.itemShelving ish
- JOIN tmp.itemsToReplace itr ON ish.itemFk = itr.idOld
- SET ish.itemFk = itr.idNew;
-
- UPDATE vn.ticketPackagingStartingStock tpss
- JOIN tmp.itemsToReplace itr ON tpss.itemFk = itr.idOld
- SET tpss.itemFk = itr.idNew;
-
- UPDATE vn.inventoryFailure ifa
- JOIN tmp.itemsToReplace itr ON ifa.itemFk = itr.idOld
- SET ifa.itemFk = itr.idNew;
-
- UPDATE vn.genericAllocation ga
- JOIN tmp.itemsToReplace itr ON ga.itemFk = itr.idOld
- SET ga.itemFk = itr.idNew;
-
- UPDATE vn.itemPlacementSupply ips
- JOIN tmp.itemsToReplace itr ON ips.itemFk = itr.idOld
- SET ips.itemFk = itr.idNew;
-
- -- Eliminamos los items repetidos
-
- DELETE i.*
- FROM vn.item i
- JOIN tmp.itemsToReplace itr ON i.id = itr.idOld;
-
- SET @isModeInventory:= FALSE;
-
- COMMIT;
-
+BEGIN
+
+/*
+ * Elimina todos los items repetidos y los sustituye por el que tiene menor id
+ */
+
+ START TRANSACTION;
+
+ SET @isModeInventory:= TRUE;
+
+ -- Deletes
+
+ UPDATE IGNORE vn.itemCost ic
+ JOIN tmp.itemsToReplace itr ON ic.itemFk = itr.idOld
+ SET ic.itemFk = itr.idNew;
+
+ DELETE ic.*
+ FROM vn.itemCost ic
+ JOIN tmp.itemsToReplace itr ON ic.itemFk = itr.idOld;
+
+ DELETE rt.*
+ FROM vn2008.rec_translator rt
+ JOIN tmp.itemsToReplace itr ON rt.Id_Article = itr.idOld;
+
+ DELETE w.*
+ FROM bs.waste w
+ JOIN tmp.itemsToReplace itr ON w.itemFk = itr.idOld;
+
+ DELETE pf.*
+ FROM vn.priceFixed pf
+ JOIN tmp.itemsToReplace itr ON pf.itemFk = itr.idOld;
+
+ DELETE imp.*
+ FROM vn.itemMatchProperties imp
+ JOIN tmp.itemsToReplace itr ON imp.itemFk = itr.idOld;
+
+ DELETE ib.*
+ FROM vn.itemBotanical ib
+ JOIN tmp.itemsToReplace itr ON ib.itemFk = itr.idOld;
+
+ DELETE ip.*
+ FROM vn.itemProposal ip
+ JOIN tmp.itemsToReplace itr ON ip.itemFk = itr.idOld;
+
+ DELETE it.*
+ FROM vn.itemTag it
+ JOIN tmp.itemsToReplace itr ON it.itemFk = itr.idOld;
+
+ DELETE ib.*
+ FROM vn.itemBarcode ib
+ JOIN tmp.itemsToReplace itr ON ib.itemFk = itr.idOld;
+
+ DELETE itc.*
+ FROM vn.itemTaxCountry itc
+ JOIN tmp.itemsToReplace itr ON itc.itemFk = itr.idOld;
+
+ DELETE ip.*
+ FROM vn.itemPlacement ip
+ JOIN tmp.itemsToReplace itr ON ip.itemFk = itr.idOld;
+
+ -- Updates
+
+ UPDATE vn.buy b
+ JOIN tmp.itemsToReplace itr ON b.itemFk = itr.idOld
+ SET b.itemFk = itr.idNew;
+
+ UPDATE vn.sale s
+ JOIN tmp.itemsToReplace itr ON s.itemFk = itr.idOld
+ SET s.itemFk = itr.idNew;
+
+ UPDATE vn.specialPrice sp
+ JOIN tmp.itemsToReplace itr ON sp.itemFk = itr.idOld
+ SET sp.itemFk = itr.idNew;
+
+ UPDATE vn.packaging p
+ JOIN tmp.itemsToReplace itr ON p.itemFk = itr.idOld
+ SET p.itemFk = itr.idNew;
+
+ UPDATE vn.packaging p
+ JOIN tmp.itemsToReplace itr ON p.freightItemFk = itr.idOld
+ SET p.freightItemFk = itr.idNew;
+
+ UPDATE hedera.orderRow o
+ JOIN tmp.itemsToReplace itr ON o.itemFk = itr.idOld
+ SET o.itemFk = itr.idNew;
+
+ UPDATE vn.itemLog il
+ JOIN tmp.itemsToReplace itr ON il.originFk = itr.idOld
+ SET il.originFk = itr.idNew;
+
+ UPDATE vn.itemShelving ish
+ JOIN tmp.itemsToReplace itr ON ish.itemFk = itr.idOld
+ SET ish.itemFk = itr.idNew;
+
+ UPDATE vn.ticketPackagingStartingStock tpss
+ JOIN tmp.itemsToReplace itr ON tpss.itemFk = itr.idOld
+ SET tpss.itemFk = itr.idNew;
+
+ UPDATE vn.inventoryFailure ifa
+ JOIN tmp.itemsToReplace itr ON ifa.itemFk = itr.idOld
+ SET ifa.itemFk = itr.idNew;
+
+ UPDATE vn.genericAllocation ga
+ JOIN tmp.itemsToReplace itr ON ga.itemFk = itr.idOld
+ SET ga.itemFk = itr.idNew;
+
+ UPDATE vn.itemPlacementSupply ips
+ JOIN tmp.itemsToReplace itr ON ips.itemFk = itr.idOld
+ SET ips.itemFk = itr.idNew;
+
+ -- Eliminamos los items repetidos
+
+ DELETE i.*
+ FROM vn.item i
+ JOIN tmp.itemsToReplace itr ON i.id = itr.idOld;
+
+ SET @isModeInventory:= FALSE;
+
+ COMMIT;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -69117,8 +68517,8 @@ BEGIN
JOIN supplier s ON s.id = e.supplierFk
JOIN alertLevel al ON al.id =
CASE
- WHEN tr.shipped < CURDATE() THEN 3
- WHEN tr.shipped = CURDATE() AND tr.isReceived = TRUE THEN 3
+ WHEN tr.landed < CURDATE() THEN 3
+ WHEN tr.landed = CURDATE() AND tr.isReceived = TRUE THEN 3
ELSE 0
END
JOIN state st ON st.code = al.code
@@ -69218,71 +68618,71 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getInfo`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT)
-BEGIN
-
- /*
- * Devuelve información relativa al item correspondiente del vBarcode pasado
- *
- * @param vBarcode código relativo al ítem
- * @param vWarehouseFk código del almacén
- */
-
- DECLARE vCacheVisibleFk INT;
- DECLARE vCacheAvailableFk INT;
- DECLARE vVisibleItemShelving INT;
- DECLARE vItemFk INT;
-
- SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
-
- CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk);
- CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, CURDATE());
-
- SELECT SUM(visible) INTO vVisibleItemShelving
- FROM vn.itemShelvingStock
- WHERE itemFk = vItemFk AND warehouseFk = vWarehouseFk;
-
- CALL vn.buyUltimate(vWarehouseFk, CURDATE());
-
- SELECT i.id,
- i.longName,
- i.tag5,
- i.value5,
- i.tag6,
- i.value6,
- i.tag7,
- i.value7,
- i.image,
- i.size,
- i.stems,
- i.category,
- i.minimum as min,
- p.name as producer,
- o.code as origin,
- v.visible - IFNULL(vVisibleItemShelving,0) as unlocated,
- a.available,
- vVisibleItemShelving,
- v.visible,
- c.`grouping`,
- c.packing,
- CONCAT('https://verdnatura.es/vn-image-data/catalog/200x200/', i.image) as urlImage200,
- CONCAT('https://verdnatura.es/vn-image-data/catalog/1600x900/', i.image) as urlImage,
- i.itemPackingTypeFk,
- i.comment as reference
- FROM vn.item i
- LEFT JOIN vn.producer p ON p.id = i.producerFk
- LEFT JOIN vn.origin o ON o.id = i.originFk
- LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id
- LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id
- LEFT JOIN (
- SELECT b.itemFk, b2.`grouping`, b2.packing
- FROM tmp.buyUltimate b
- JOIN vn.buy b2 ON b2.id = b.buyFk
- WHERE b.warehouseFk = vWarehouseFk
- ) c ON i.id = c.itemFk
- WHERE i.id = vItemFk;
-
- DROP TEMPORARY TABLE tmp.buyUltimate;
-
+BEGIN
+
+ /*
+ * Devuelve información relativa al item correspondiente del vBarcode pasado
+ *
+ * @param vBarcode código relativo al ítem
+ * @param vWarehouseFk código del almacén
+ */
+
+ DECLARE vCacheVisibleFk INT;
+ DECLARE vCacheAvailableFk INT;
+ DECLARE vVisibleItemShelving INT;
+ DECLARE vItemFk INT;
+
+ SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
+
+ CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk);
+ CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, CURDATE());
+
+ SELECT SUM(visible) INTO vVisibleItemShelving
+ FROM vn.itemShelvingStock
+ WHERE itemFk = vItemFk AND warehouseFk = vWarehouseFk;
+
+ CALL vn.buyUltimate(vWarehouseFk, CURDATE());
+
+ SELECT i.id,
+ i.longName,
+ i.tag5,
+ i.value5,
+ i.tag6,
+ i.value6,
+ i.tag7,
+ i.value7,
+ i.image,
+ i.size,
+ i.stems,
+ i.category,
+ i.minimum as min,
+ p.name as producer,
+ o.code as origin,
+ v.visible - IFNULL(vVisibleItemShelving,0) as unlocated,
+ a.available,
+ vVisibleItemShelving,
+ v.visible,
+ c.`grouping`,
+ c.packing,
+ CONCAT('https://verdnatura.es/vn-image-data/catalog/200x200/', i.image) as urlImage200,
+ CONCAT('https://verdnatura.es/vn-image-data/catalog/1600x900/', i.image) as urlImage,
+ i.itemPackingTypeFk,
+ i.comment as reference
+ FROM vn.item i
+ LEFT JOIN vn.producer p ON p.id = i.producerFk
+ LEFT JOIN vn.origin o ON o.id = i.originFk
+ LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id
+ LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id
+ LEFT JOIN (
+ SELECT b.itemFk, b2.`grouping`, b2.packing
+ FROM tmp.buyUltimate b
+ JOIN vn.buy b2 ON b2.id = b.buyFk
+ WHERE b.warehouseFk = vWarehouseFk
+ ) c ON i.id = c.itemFk
+ WHERE i.id = vItemFk;
+
+ DROP TEMPORARY TABLE tmp.buyUltimate;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -70147,21 +69547,21 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_saveReference`(vBarcode VARCHAR(22), vReference VARCHAR(150))
-BEGIN
-
-/**
- * Actualiza la referencia del item
- *
- * @param vBarcode del item
- * @param vReference referencia a actualizar
- */
-
- DECLARE vItemFk INT;
-
- SELECT barcodeToItem(vBarcode) INTO vItemFk;
-
- UPDATE item SET comment = vReference WHERE id = vItemFk;
-
+BEGIN
+
+/**
+ * Actualiza la referencia del item
+ *
+ * @param vBarcode del item
+ * @param vReference referencia a actualizar
+ */
+
+ DECLARE vItemFk INT;
+
+ SELECT barcodeToItem(vBarcode) INTO vItemFk;
+
+ UPDATE item SET comment = vReference WHERE id = vItemFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -70243,33 +69643,47 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_setGeneric`(vSelf INT)
-BEGIN
-
- /* Asigna el código genérico a un item
- *
- * @param vSelf identificador de vn.item
- */
-
- DECLARE vGenericFk INT;
-
- SELECT ga.itemFk INTO vGenericFk
- FROM vn.genericAllocation ga
- JOIN vn.item i ON (i.typeFk = ga.typeFk OR ISNULL(ga.typeFk))
- JOIN vn.itemTag it1 ON it1.itemFk = i.id AND (it1.value = ga.origin OR ISNULL(ga.origin))
- JOIN vn.itemTag it2 ON it2.itemFk = i.id AND (it2.value = ga.color OR ISNULL(ga.color))
- JOIN vn.itemTag it3 ON it3.itemFk = i.id AND (it3.value = ga.quality OR ISNULL(ga.quality))
- JOIN vn.itemTag it4 ON it4.itemFk = i.id AND (it4.value = ga.numFlores OR ISNULL(ga.numFlores))
- JOIN vn.itemTag it5 ON it5.itemFk = i.id AND (it5.value = ga.category OR ISNULL(ga.category))
- JOIN vn.itemTag it6 ON it6.itemFk = i.id AND (it6.value = ga.productor OR ISNULL(ga.productor))
- WHERE i.id = vSelf
- AND ga.itemFk != vSelf
- AND NOT i.isFloramondo
- LIMIT 1;
-
- UPDATE vn.item
- SET genericFk = vGenericFk
- WHERE id = vSelf;
-
+BEGIN
+/**
+ * Asigna el código genérico a un item, salvo que sea un código de item genérico.
+ *
+ * @param vSelf identificador de vn.item
+ */
+ DECLARE vGenericFk INT;
+
+ SELECT itemFk INTO vGenericFk
+ FROM (
+ SELECT itemFk, (sum(matches) = maxMatches) `match`
+ FROM (
+ SELECT ga.id gaid,
+ ga.itemFk,
+ (it.value <=> ga.origin)
+ + (it.value <=> ga.color)
+ + (it.value <=> ga.quality)
+ + (it.value <=> ga.numFlores)
+ + (it.value <=> ga.category)
+ + (it.value <=> ga.productor) matches,
+ !ISNULL(ga.origin)
+ +!ISNULL(ga.color)
+ +!ISNULL(ga.quality)
+ +!ISNULL(ga.numFlores)
+ +!ISNULL(ga.category)
+ +!ISNULL(ga.productor) maxMatches
+ FROM vn.item i
+ JOIN vn.itemTag it ON it.itemFk = i.id
+ JOIN vn.genericAllocation ga
+ ON (i.typeFk = ga.typeFk OR ga.typeFk IS NULL)
+ AND (i.longName = ga.longName OR ga.longName IS NULL)
+ AND (i.`size` = ga.`size` OR ga.`size` IS NULL)
+ AND i.id != ga.itemFk
+ WHERE i.id = vSelf
+ AND NOT i.isFloramondo) sub
+ GROUP BY gaid
+ HAVING `match`) sub2;
+
+ UPDATE vn.item
+ SET genericFk = vGenericFk
+ WHERE id = vSelf;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -70287,19 +69701,19 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_updatePackingShelve`(vSelf INT, vPacking INT)
-BEGIN
-
+BEGIN
+
/**
- * Actualiza el valor de item.packingShelve
- *
- * @param vSelf Identificador de vn.item
- * @param vPacking Cantidad de unidades de venta que caben en una bandeja
- */
-
- UPDATE vn.item i
- SET i.packingShelve = vPacking
- WHERE i.id = vSelf;
-
+ * Actualiza el valor de item.packingShelve
+ *
+ * @param vSelf Identificador de vn.item
+ * @param vPacking Cantidad de unidades de venta que caben en una bandeja
+ */
+
+ UPDATE vn.item i
+ SET i.packingShelve = vPacking
+ WHERE i.id = vSelf;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -70317,15 +69731,15 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_updatePackingType`(vItem INT, vItemPackingTypeFk VARCHAR(1))
-BEGIN
-/**
- * Update the packing type of an item
- *
- * @param vItem id del item a actualizar
- * @param vItemPackingTypeFk packing type
- */
- UPDATE item SET itemPackingTypeFk = vItemPackingTypeFk WHERE id = vItem;
-
+BEGIN
+/**
+ * Update the packing type of an item
+ *
+ * @param vItem id del item a actualizar
+ * @param vItemPackingTypeFk packing type
+ */
+ UPDATE item SET itemPackingTypeFk = vItemPackingTypeFk WHERE id = vItem;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -71142,22 +70556,22 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `machine_getWorkerPlate`(vWorkerFk INT)
-BEGIN
-/**
- * Selecciona la matrícula del vehículo del workerfk
- *
- * @param vWorkerFk el id del trabajador
- *
- *
- **/
-
- SELECT m.plate
- FROM machine m
- JOIN machineWorker mw ON mw.machineFk = m.id
- WHERE mw.inTimed >= TIMESTAMPADD(HOUR , -12,NOW())
- AND ISNULL(mw.outTimed)
- AND mw.workerFk = vWorkerFk;
-
+BEGIN
+/**
+ * Selecciona la matrícula del vehículo del workerfk
+ *
+ * @param vWorkerFk el id del trabajador
+ *
+ *
+ **/
+
+ SELECT m.plate
+ FROM machine m
+ JOIN machineWorker mw ON mw.machineFk = m.id
+ WHERE mw.inTimed >= TIMESTAMPADD(HOUR , -12,NOW())
+ AND ISNULL(mw.outTimed)
+ AND mw.workerFk = vWorkerFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -71300,11 +70714,11 @@ DELIMITER ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!50003 SET character_set_results = utf8 */ ;
+/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `manaSpellersRequery`(vWorkerFk INTEGER)
BEGIN
@@ -71318,6 +70732,7 @@ BEGIN
DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,CURDATE());
DECLARE vMana INT;
DECLARE vAutoMana INT;
+ DECLARE vClaimMana INT;
DECLARE vManaBank INT;
DECLARE vManaGreugeType INT;
@@ -71332,6 +70747,9 @@ BEGIN
SELECT id INTO vAutoMana
FROM `component` WHERE code = 'autoMana';
+ SELECT id INTO vClaimMana
+ FROM `component` WHERE code = 'manaClaim';
+
SELECT id INTO vManaBank
FROM `bank` WHERE code = 'mana';
@@ -71350,7 +70768,7 @@ BEGIN
JOIN client c ON c.id = a.clientFk
JOIN sale s ON s.ticketFk = t.id
JOIN saleComponent sc ON sc.saleFk = s.id
- WHERE c.salesPersonFk = vWorkerFk AND sc.componentFk IN (vMana, vAutoMana)
+ WHERE c.salesPersonFk = vWorkerFk AND sc.componentFk IN (vMana, vAutoMana, vClaimMana)
AND t.shipped > vFromDated AND t.shipped < vToDated
UNION ALL
SELECT - r.amountPaid
@@ -72075,7 +71493,7 @@ BEGIN
IF vIsInvoiceable THEN
- CALL ticketCreateWithUser(vClient,
+ CALL ticket_add(vClient,
vDateEnd,
vWarehouse,
vCompany,
@@ -72084,6 +71502,7 @@ BEGIN
NULL,
vDateEnd,
account.userGetId(),
+ TRUE,
vNewTicket);
INSERT INTO ticketPackaging(
@@ -72478,29 +71897,29 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_setOrder`(vWarehouseFk INT)
-BEGIN
-
- /*
- * Ordena el orden de preparacion de los parking de acuerdo con la tabla vn.corridor
- */
-
- UPDATE vn.parking p
- JOIN (
- SELECT code,
- @orden := @orden + 10 AS po
- FROM (
- SELECT c.prepOrder,
- p.code,
- @orden := 0,
- IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor ,
- CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication
- FROM vn.parking p
- JOIN vn.sector s ON s.id = p.sectorFk
- JOIN vn.corridor c ON c.code = LEFT(p.code,1) COLLATE utf8_general_ci
- WHERE s.warehouseFk = vWarehouseFk) sub
- ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code
- SET p.pickingOrder = sub2.po;
-
+BEGIN
+
+ /*
+ * Ordena el orden de preparacion de los parking de acuerdo con la tabla vn.corridor
+ */
+
+ UPDATE vn.parking p
+ JOIN (
+ SELECT code,
+ @orden := @orden + 10 AS po
+ FROM (
+ SELECT c.prepOrder,
+ p.code,
+ @orden := 0,
+ IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor ,
+ CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication
+ FROM vn.parking p
+ JOIN vn.sector s ON s.id = p.sectorFk
+ JOIN vn.corridor c ON c.code = LEFT(p.code,1) COLLATE utf8_general_ci
+ WHERE s.warehouseFk = vWarehouseFk) sub
+ ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code
+ SET p.pickingOrder = sub2.po;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -72593,180 +72012,180 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `placement_test`(vParamFk INT(11))
-BEGIN
-
- DECLARE vCalcFk INT;
- DECLARE vWarehouseFk INT;
- DECLARE vWarehouseAliasFk INT;
- DECLARE vCurrentYear INT DEFAULT YEAR(NOW());
-
- DROP TEMPORARY TABLE IF EXISTS tmp.sale;
- CREATE TEMPORARY TABLE tmp.sale
- ENGINE = MEMORY
- SELECT 0000000 as ticketFk,
- 0000000 as saleFk,
- 0000000 as itemFk,
- FALSE as isStowaway,
- 0 as quantity;
-
- INSERT INTO tmp.sale(ticketFk, saleFk, itemFk, isStowaway)
- SELECT s.ticketFk, s.id, s.itemFk, FALSE
- FROM vn.ticketCollection tc
- JOIN vn.collection c ON c.id = tc.collectionFk
- JOIN vn.sale s ON s.ticketFk = tc.ticketFk
- JOIN vn.item i ON i.id = s.itemFk
- WHERE tc.collectionFk = vParamFk
- AND (i.itemPackingTypeFk = c.itemPackingTypeFk OR ISNULL(c.itemPackingTypeFk))
- UNION ALL
- SELECT s.ticketFk, s.id, s.itemFk, FALSE
- FROM vn.sale s
- WHERE s.ticketFk = vParamFk;
-
-
- /* UNION ALL
- SELECT sw.shipFk, s.id, s.itemFk, TRUE
- FROM vn.sale s
- JOIN vn.stowaway sw ON sw.id = s.ticketFk
- JOIN vn.ticketCollection tc ON tc.ticketFk = sw.shipFk
- WHERE tc.collectionFk = vParamFk;
-
- INSERT INTO tmp.sale(ticketFk, saleFk, itemFk, isStowaway)
- SELECT s.ticketFk, s.id, s.itemFk, FALSE
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- WHERE s.ticketFk = vParamFk
- AND t.shipped > '2020-01-01'
- UNION ALL
- SELECT sw.shipFk, s.id, s.itemFk, TRUE
- FROM vn.sale s
- JOIN vn.stowaway sw ON sw.id = s.ticketFk
- WHERE sw.shipFk = vParamFk;
-
- DELETE FROM tmp.sale
- WHERE saleFk = 0;
- */
- SELECT t.warehouseFk, w.aliasFk
- INTO vWarehouseFk, vWarehouseAliasFk
- FROM vn.ticket t
- JOIN tmp.sale ts ON ts.ticketFk = t.id
- JOIN vn.warehouse w ON w.id = t.warehouseFk
- LIMIT 1;
-
- CALL cache.visible_refresh(vCalcFk,FALSE,vWarehouseFk);
-
- UPDATE tmp.sale ts
- JOIN ( SELECT itemFk, sum(visible) as visible
- FROM vn.itemShelvingStock iss
- JOIN vn.warehouse w ON w.id = iss.warehouseFk
- WHERE w.aliasFk = vWarehouseAliasFk
- GROUP BY iss.itemFk ) iss ON iss.itemFk = ts.itemFk
- SET ts.quantity = iss.visible;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.sale2;
- CREATE TEMPORARY TABLE tmp.sale2
- ENGINE = MEMORY
- SELECT * FROM tmp.sale;
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.`grouping`;
- CREATE TEMPORARY TABLE tmp.`grouping`
- (PRIMARY KEY (itemFk))
- ENGINE = MEMORY
- SELECT b.itemFk,
- CASE b.groupingMode
- WHEN 0 THEN 1
- WHEN 2 THEN b.packing
- ELSE b.`grouping`
- END AS `grouping`
- FROM buy b
- JOIN cache.last_buy lb ON lb.buy_id = b.id
- WHERE lb.warehouse_id = vWarehouseFk
- ;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.grouping2;
- CREATE TEMPORARY TABLE tmp.grouping2
- ENGINE = MEMORY
- SELECT * FROM tmp.`grouping`;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList;
- CREATE TEMPORARY TABLE tmp.salePlacementList
- ENGINE = MEMORY
-
- SELECT ts.saleFk,
- ts.itemFk,
- CONCAT(
- IF( iss.id,
- CONCAT('< ', IFNULL(wk.`code`, '---'),' > '),
- ''),
- p.`code`) COLLATE utf8_general_ci as placement ,
- sh.code COLLATE utf8_general_ci as shelving,
- ish.created,
- ish.visible,
- IF(ts.isStowaway, - 100000, IF(ish.visible > 0 OR iss.id, 1, 100000)) * p.pickingOrder as `order`,
- IFNULL(IF(sc.isPreviousPreparedByPacking, ish.packing, g.`grouping`),1) as `grouping`,
- IF(iss.id, TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,iss.created)), TO_SECONDS(TIMESTAMPADD(YEAR,- year(ish.created),ish.created)) + TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,NOW()))) as priority,
- 0 as saleOrder,
- sc.isPreviousPrepared,
- iss.id as itemShelvingSaleFk,
- ts.ticketFk
- ,iss.id
- , st.saleFk as salePreviousPrepared
- , iss.userFk
- FROM tmp.sale ts
- LEFT JOIN (SELECT DISTINCT saleFk
- FROM vn.saleTracking st
- JOIN vn.state s ON s.id = st.stateFk
- WHERE st.isChecked
- AND s.semaphore = 1) st ON st.saleFk = ts.saleFk
- JOIN vn.itemShelving ish ON ish.itemFk = ts.itemFk
- JOIN vn.shelving sh ON sh.code = ish.shelvingFk
- JOIN vn.parking p ON p.id = sh.parkingFk
- JOIN vn.sector sc ON sc.id = p.sectorFk
- JOIN vn.warehouse w ON w.id = sc.warehouseFk
- LEFT JOIN tmp.`grouping` g ON g.itemFk = ts.itemFk
- LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = ts.saleFk AND iss.itemShelvingFk = ish.id
- LEFT JOIN vn.worker wk ON wk.id = iss.userFk
- WHERE w.aliasFk = vWarehouseAliasFk
- HAVING (iss.id AND st.saleFk) OR salePreviousPrepared IS NULL
- ;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList_2;
- CREATE TEMPORARY TABLE tmp.salePlacementList_2
- ENGINE MEMORY
- SELECT saleFk, priority as olderPriority
- FROM (SELECT saleFk, priority
- FROM tmp.salePlacementList
- ORDER BY IF(isPreviousPrepared,2,1), IF(visible > 0 OR itemShelvingSaleFk,1,2), priority
- ) sub
- GROUP BY saleFk;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList_3;
- CREATE TEMPORARY TABLE tmp.salePlacementList_3
- ENGINE MEMORY
- SELECT s1.saleFk, `order`as saleOrder
- FROM tmp.salePlacementList s1
- JOIN tmp.salePlacementList_2 s2 ON s2.saleFk = s1.saleFk AND s2.olderPriority = s1.priority;
-
- UPDATE tmp.salePlacementList s1
- JOIN tmp.salePlacementList_3 s3 ON s3.saleFk = s1.saleFk
- SET s1.saleOrder = s3.saleOrder;
- /*
- -- Anula el orden de antigüedad y ordena por ubicación */
- UPDATE tmp.salePlacementList
- SET saleOrder = `order`;
-
- SELECT *
- FROM tmp.salePlacementList
- ORDER BY visible <> 0 DESC,saleOrder, IF(isPreviousPrepared,2,1), IF(itemShelvingSaleFk,1,2),priority;
-
- DROP TEMPORARY TABLE
- tmp.sale,
- tmp.sale2,
- tmp.`grouping`,
- tmp.grouping2,
- tmp.salePlacementList_2,
- tmp.salePlacementList_3;
-
+BEGIN
+
+ DECLARE vCalcFk INT;
+ DECLARE vWarehouseFk INT;
+ DECLARE vWarehouseAliasFk INT;
+ DECLARE vCurrentYear INT DEFAULT YEAR(NOW());
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.sale;
+ CREATE TEMPORARY TABLE tmp.sale
+ ENGINE = MEMORY
+ SELECT 0000000 as ticketFk,
+ 0000000 as saleFk,
+ 0000000 as itemFk,
+ FALSE as isStowaway,
+ 0 as quantity;
+
+ INSERT INTO tmp.sale(ticketFk, saleFk, itemFk, isStowaway)
+ SELECT s.ticketFk, s.id, s.itemFk, FALSE
+ FROM vn.ticketCollection tc
+ JOIN vn.collection c ON c.id = tc.collectionFk
+ JOIN vn.sale s ON s.ticketFk = tc.ticketFk
+ JOIN vn.item i ON i.id = s.itemFk
+ WHERE tc.collectionFk = vParamFk
+ AND (i.itemPackingTypeFk = c.itemPackingTypeFk OR ISNULL(c.itemPackingTypeFk))
+ UNION ALL
+ SELECT s.ticketFk, s.id, s.itemFk, FALSE
+ FROM vn.sale s
+ WHERE s.ticketFk = vParamFk;
+
+
+ /* UNION ALL
+ SELECT sw.shipFk, s.id, s.itemFk, TRUE
+ FROM vn.sale s
+ JOIN vn.stowaway sw ON sw.id = s.ticketFk
+ JOIN vn.ticketCollection tc ON tc.ticketFk = sw.shipFk
+ WHERE tc.collectionFk = vParamFk;
+
+ INSERT INTO tmp.sale(ticketFk, saleFk, itemFk, isStowaway)
+ SELECT s.ticketFk, s.id, s.itemFk, FALSE
+ FROM vn.sale s
+ JOIN vn.ticket t ON t.id = s.ticketFk
+ WHERE s.ticketFk = vParamFk
+ AND t.shipped > '2020-01-01'
+ UNION ALL
+ SELECT sw.shipFk, s.id, s.itemFk, TRUE
+ FROM vn.sale s
+ JOIN vn.stowaway sw ON sw.id = s.ticketFk
+ WHERE sw.shipFk = vParamFk;
+
+ DELETE FROM tmp.sale
+ WHERE saleFk = 0;
+ */
+ SELECT t.warehouseFk, w.aliasFk
+ INTO vWarehouseFk, vWarehouseAliasFk
+ FROM vn.ticket t
+ JOIN tmp.sale ts ON ts.ticketFk = t.id
+ JOIN vn.warehouse w ON w.id = t.warehouseFk
+ LIMIT 1;
+
+ CALL cache.visible_refresh(vCalcFk,FALSE,vWarehouseFk);
+
+ UPDATE tmp.sale ts
+ JOIN ( SELECT itemFk, sum(visible) as visible
+ FROM vn.itemShelvingStock iss
+ JOIN vn.warehouse w ON w.id = iss.warehouseFk
+ WHERE w.aliasFk = vWarehouseAliasFk
+ GROUP BY iss.itemFk ) iss ON iss.itemFk = ts.itemFk
+ SET ts.quantity = iss.visible;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.sale2;
+ CREATE TEMPORARY TABLE tmp.sale2
+ ENGINE = MEMORY
+ SELECT * FROM tmp.sale;
+
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.`grouping`;
+ CREATE TEMPORARY TABLE tmp.`grouping`
+ (PRIMARY KEY (itemFk))
+ ENGINE = MEMORY
+ SELECT b.itemFk,
+ CASE b.groupingMode
+ WHEN 0 THEN 1
+ WHEN 2 THEN b.packing
+ ELSE b.`grouping`
+ END AS `grouping`
+ FROM buy b
+ JOIN cache.last_buy lb ON lb.buy_id = b.id
+ WHERE lb.warehouse_id = vWarehouseFk
+ ;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.grouping2;
+ CREATE TEMPORARY TABLE tmp.grouping2
+ ENGINE = MEMORY
+ SELECT * FROM tmp.`grouping`;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList;
+ CREATE TEMPORARY TABLE tmp.salePlacementList
+ ENGINE = MEMORY
+
+ SELECT ts.saleFk,
+ ts.itemFk,
+ CONCAT(
+ IF( iss.id,
+ CONCAT('< ', IFNULL(wk.`code`, '---'),' > '),
+ ''),
+ p.`code`) COLLATE utf8_general_ci as placement ,
+ sh.code COLLATE utf8_general_ci as shelving,
+ ish.created,
+ ish.visible,
+ IF(ts.isStowaway, - 100000, IF(ish.visible > 0 OR iss.id, 1, 100000)) * p.pickingOrder as `order`,
+ IFNULL(IF(sc.isPreviousPreparedByPacking, ish.packing, g.`grouping`),1) as `grouping`,
+ IF(iss.id, TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,iss.created)), TO_SECONDS(TIMESTAMPADD(YEAR,- year(ish.created),ish.created)) + TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,NOW()))) as priority,
+ 0 as saleOrder,
+ sc.isPreviousPrepared,
+ iss.id as itemShelvingSaleFk,
+ ts.ticketFk
+ ,iss.id
+ , st.saleFk as salePreviousPrepared
+ , iss.userFk
+ FROM tmp.sale ts
+ LEFT JOIN (SELECT DISTINCT saleFk
+ FROM vn.saleTracking st
+ JOIN vn.state s ON s.id = st.stateFk
+ WHERE st.isChecked
+ AND s.semaphore = 1) st ON st.saleFk = ts.saleFk
+ JOIN vn.itemShelving ish ON ish.itemFk = ts.itemFk
+ JOIN vn.shelving sh ON sh.code = ish.shelvingFk
+ JOIN vn.parking p ON p.id = sh.parkingFk
+ JOIN vn.sector sc ON sc.id = p.sectorFk
+ JOIN vn.warehouse w ON w.id = sc.warehouseFk
+ LEFT JOIN tmp.`grouping` g ON g.itemFk = ts.itemFk
+ LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = ts.saleFk AND iss.itemShelvingFk = ish.id
+ LEFT JOIN vn.worker wk ON wk.id = iss.userFk
+ WHERE w.aliasFk = vWarehouseAliasFk
+ HAVING (iss.id AND st.saleFk) OR salePreviousPrepared IS NULL
+ ;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList_2;
+ CREATE TEMPORARY TABLE tmp.salePlacementList_2
+ ENGINE MEMORY
+ SELECT saleFk, priority as olderPriority
+ FROM (SELECT saleFk, priority
+ FROM tmp.salePlacementList
+ ORDER BY IF(isPreviousPrepared,2,1), IF(visible > 0 OR itemShelvingSaleFk,1,2), priority
+ ) sub
+ GROUP BY saleFk;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList_3;
+ CREATE TEMPORARY TABLE tmp.salePlacementList_3
+ ENGINE MEMORY
+ SELECT s1.saleFk, `order`as saleOrder
+ FROM tmp.salePlacementList s1
+ JOIN tmp.salePlacementList_2 s2 ON s2.saleFk = s1.saleFk AND s2.olderPriority = s1.priority;
+
+ UPDATE tmp.salePlacementList s1
+ JOIN tmp.salePlacementList_3 s3 ON s3.saleFk = s1.saleFk
+ SET s1.saleOrder = s3.saleOrder;
+ /*
+ -- Anula el orden de antigüedad y ordena por ubicación */
+ UPDATE tmp.salePlacementList
+ SET saleOrder = `order`;
+
+ SELECT *
+ FROM tmp.salePlacementList
+ ORDER BY visible <> 0 DESC,saleOrder, IF(isPreviousPrepared,2,1), IF(itemShelvingSaleFk,1,2),priority;
+
+ DROP TEMPORARY TABLE
+ tmp.sale,
+ tmp.sale2,
+ tmp.`grouping`,
+ tmp.grouping2,
+ tmp.salePlacementList_2,
+ tmp.salePlacementList_3;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -72784,18 +72203,18 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `prepareClientList`()
-BEGIN
-
- /*
- * Require la tabla tmp.ticket(id,clientFk)
- */
-
- DROP TEMPORARY TABLE IF EXISTS tmp.client;
- CREATE TEMPORARY TABLE tmp.client
- (PRIMARY KEY (id))
- ENGINE = MEMORY
- SELECT DISTINCT clientFk id
- FROM tmp.ticket;
+BEGIN
+
+ /*
+ * Require la tabla tmp.ticket(id,clientFk)
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.client;
+ CREATE TEMPORARY TABLE tmp.client
+ (PRIMARY KEY (id))
+ ENGINE = MEMORY
+ SELECT DISTINCT clientFk id
+ FROM tmp.ticket;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -72813,25 +72232,25 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `prepareTicketList`(vStartingDate DATETIME, vEndingDate DATETIME)
-BEGIN
-
- DROP TEMPORARY TABLE IF EXISTS tmp.productionTicket;
- CREATE TEMPORARY TABLE tmp.productionTicket
- (PRIMARY KEY (ticketFk))
- ENGINE = MEMORY
- SELECT t.id ticketFk, t.clientFk
- FROM vn.ticket t
- LEFT JOIN vn.ticketState ts ON ts.ticket = t.id
- JOIN vn.client c ON c.id = t.clientFk
- WHERE c.typeFk IN ('normal','handMaking','internalUse')
- AND (
- t.shipped BETWEEN CURDATE() AND vEndingDate
- OR (
- ts.alertLevel < 3
- AND t.shipped >= vStartingDate
- AND t.shipped < CURDATE()
- )
- );
+BEGIN
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.productionTicket;
+ CREATE TEMPORARY TABLE tmp.productionTicket
+ (PRIMARY KEY (ticketFk))
+ ENGINE = MEMORY
+ SELECT t.id ticketFk, t.clientFk
+ FROM vn.ticket t
+ LEFT JOIN vn.ticketState ts ON ts.ticket = t.id
+ JOIN vn.client c ON c.id = t.clientFk
+ WHERE c.typeFk IN ('normal','handMaking','internalUse')
+ AND (
+ t.shipped BETWEEN CURDATE() AND vEndingDate
+ OR (
+ ts.alertLevel < 3
+ AND t.shipped >= vStartingDate
+ AND t.shipped < CURDATE()
+ )
+ );
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -72890,21 +72309,48 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `previousSticker_get`(vSaleGroupFk INT)
BEGIN
-
- /*
- * Devuelve los campos a imprimir en una etiqueta de preparación previa
- *
- * @param vSaleGroupFk Identificador de vn.saleGroup
- */
+/**
+ * Devuelve los campos a imprimir en una etiqueta de preparación previa.
+ * Actualiza el valor de vn.saleGroup.parkingFk en el caso de que exista un saleGroup del mismo ticket
+ * con parking, del mismo sector, para que todos se pongan juntos
+ *
+ * @param vSaleGroupFk Identificador de vn.saleGroup
+ */
+ DECLARE vTicketFk INT;
+ DECLARE vParkingFk INT;
+ DECLARE vSectorFk INT;
- SELECT sgd.saleGroupFk,
+ SELECT s.ticketFk
+ INTO vTicketFk
+ FROM vn.saleGroupDetail sgd
+ JOIN vn.sale s ON s.id = sgd.saleFk
+ WHERE sgd.saleGroupFk = vSaleGroupFk
+ LIMIT 1;
+
+ SELECT sg.parkingFk, sc.sectorFk
+ INTO vParkingFk, vSectorFk
+ FROM vn.saleGroup sg
+ JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id
+ JOIN vn.sectorCollection sc ON sc.id = scsg.sectorCollectionFk
+ JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
+ JOIN vn.sale s ON s.id = sgd.saleFk
+ WHERE s.ticketFk = vTicketFk
+ AND sg.parkingFk IS NOT NULL
+ LIMIT 1;
+
+ UPDATE vn.saleGroup sg
+ SET sg.parkingFk = vParkingFk
+ WHERE sg.id = vSaleGroupFk
+ AND sg.sectorFk = vSectorFk;
+
+ SELECT sgd.saleGroupFk,
t.id ticketFk,
p.code as location,
t.observations,
- IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour,
- IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute ,
- IFNULL(MAX(i.itemPackingTypeFk),'H') itemPackingTypeFk ,
- count(*) items
+ IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour,
+ IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute ,
+ IFNULL(MAX(i.itemPackingTypeFk),'H') itemPackingTypeFk ,
+ count(*) items
FROM vn.sale s
JOIN vn.item i ON i.id = s.itemFk
JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
@@ -72913,7 +72359,6 @@ BEGIN
LEFT JOIN vn.parking p ON p.id = sg.parkingFk
LEFT JOIN vn.`zone` z ON z.id = t.zoneFk
WHERE sgd.saleGroupFk = vSaleGroupFk;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -72979,225 +72424,225 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `prod`(vWarehouseFk INT, vScopeDays INT)
-proc: BEGIN
-
- DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(CURDATE()));
-
- DECLARE vIsTodayRelative BOOLEAN;
-
- SELECT isTodayRelative INTO vIsTodayRelative
- FROM vn.worker
- WHERE userFk = vn.getUser();
-
- CALL vn.prepareTicketList(TIMESTAMPADD(DAY,-1,CURDATE()), vEndingDate);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
- CREATE TEMPORARY TABLE tmp.ticket
- SELECT * FROM tmp.productionTicket;
-
- CALL vn.prepareClientList();
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems;
- CREATE TEMPORARY TABLE tmp.ticketGetProblems
- (INDEX (ticketFk)) ENGINE = MEMORY
- SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped
- FROM tmp.productionTicket tt
- JOIN vn.ticket t ON t.id = tt.ticketFk;
-
- CALL vn.ticketGetProblems(vIsTodayRelative);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.productionBuffer;
- CREATE TEMPORARY TABLE tmp.productionBuffer
- (PRIMARY KEY(ticketFk))
- ENGINE = MEMORY
- SELECT tt.ticketFk
- , tt.clientFk
- , t.warehouseFk
- , t.nickname
- , t.packages
- , IF(HOUR(t.shipped), HOUR(t.shipped), IFNULL(HOUR(zc.hour),HOUR(z.hour))) as HH
- , IFNULL(HOUR(zc.hour),HOUR(z.hour)) as Departure
- , IF(MINUTE(t.shipped), MINUTE(t.shipped), IFNULL(MINUTE(zc.hour), MINUTE(z.hour))) as mm
- , t.routeFk
- , IF(am.deliveryMethodFk = 2,z.`id`,0) as zona
- , t.nickname addressNickname
- , a.postalCode
- , a.city
- , p.name province
- , CONCAT(z.`name`,' ',IFNULL(RIGHT(t.routeFk,3),'')) agency
- , am.id agencyModeFk
- , 0 AS `lines`
- , CAST( 0 AS DECIMAL(5,2)) AS m3
- , CAST( 0 AS DECIMAL(5,2)) AS preparationRate
- , "" as problem
- , IFNULL(tls.state,2) AS state
- , w.code workerCode
- , DATE(t.shipped) shipped
- , wk.code AS salesPersonCode
- , p.id provinceFk
- , tls.productionOrder
- , ifnull(tls.alertLevel,0) alertLevel
- , t.isBoxed as palletized
- , rg.deviceId ubicacion
- , tlu.lastUpdated
- -- , tls.updated lastUpdated
- , ifnull(st.graphCategory,0) graphCategory
- , pk.code as parking
- , 0 AS H
- , 0 AS V
- , 0 AS F
- , 0 AS P
- , st.isOk
- , ag.isOwn
- FROM tmp.productionTicket tt
- JOIN vn.ticket t on tt.ticketFk = t.id
- LEFT JOIN vn.ticketStateToday tst ON tst.ticket = t.id
- LEFT JOIN vn.state st ON st.id = tst.state
- LEFT JOIN vn.client c ON c.id = t.clientFk
- LEFT JOIN vn.worker wk ON wk.id = c.salesPersonFk
- JOIN vn.address a on a.id = t.addressFk
- LEFT JOIN vn.province p on p.id = a.provinceFk
- JOIN vn.agencyMode am ON am.id = t.agencyModeFk
- JOIN vn.agency ag ON ag.id = am.agencyFk
- LEFT JOIN vn.ticketState tls on tls.ticket = tt.ticketFk
- LEFT JOIN vn.ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk
- LEFT JOIN vn.worker w on w.id = tls.worker
- LEFT JOIN vn.routeGate rg ON rg.routeFk = t.routeFk
- LEFT JOIN vn.zone z ON z.id = t.zoneFk
- LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND date(t.shipped) = zc.dated
- LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
- LEFT JOIN vn.parking pk ON pk.id = tp.parkingFk
- WHERE t.warehouseFk = vWarehouseFk
- AND am.deliveryMethodFk IN (1,2,3);
-
- ALTER TABLE tmp.productionBuffer
- CHANGE COLUMN `problem` `problem` VARCHAR(255),
- ADD COLUMN `collectionH` INT,
- ADD COLUMN `collectionV` INT,
- ADD COLUMN `collectionF` INT,
- ADD COLUMN `collectionP` INT;
-
- -- Líneas y volumen por ticket
- UPDATE tmp.productionBuffer pb
- JOIN (
- SELECT tt.ticketFk,
- COUNT(*) as `lines`,
- sum(sv.volume) as m3,
- IFNULL(sum(IF(sv.isPicked,sv.volume,0)) / sum(sv.volume),0) as rate
- FROM tmp.productionTicket tt
- JOIN vn.saleVolume sv on sv.ticketFk = tt.ticketFk
- GROUP BY tt.ticketFk
- ) m on m.ticketFk = pb.ticketFk
- SET pb.`lines` = m.`lines`,
- pb.m3 = m.m3,
- pb.preparationRate = m.rate;
-
- DELETE FROM tmp.productionBuffer
- WHERE `lines`= 0;
-
- -- Lineas por linea de encajado
- UPDATE tmp.productionBuffer pb
- JOIN ( SELECT ticketFk,
- sum(sub.H) H,
- sum(sub.V) V,
- sum(sub.F) F,
- sum(sub.P) P
- FROM (
- SELECT t.ticketFk,
- sum(i.itemPackingTypeFk = 'H') H,
- sum(i.itemPackingTypeFk = 'V') V,
- sum(i.itemPackingTypeFk = 'F') F,
- sum(i.itemPackingTypeFk = 'P') P
- FROM tmp.productionTicket t
- JOIN vn.sale s ON s.ticketFk = t.ticketFk
- JOIN vn.item i ON i.id = s.itemFk
- GROUP BY t.ticketFk, i.itemPackingTypeFk) sub
- GROUP BY ticketFk
- ) sub2 ON sub2.ticketFk = pb.ticketFk
- SET pb.H = sub2.H,
- pb.V = sub2.V,
- pb.F = sub2.F,
- pb.P = sub2.P;
-
- -- Colecciones segun tipo de encajado
- UPDATE tmp.productionBuffer pb
- JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk
- JOIN vn.collection c ON c.id = tc.collectionFk
- SET pb.collectionH = c.id
- WHERE c.itemPackingTypeFk = 'H' OR ISNULL(c.itemPackingTypeFk);
-
- UPDATE tmp.productionBuffer pb
- JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk
- JOIN vn.collection c ON c.id = tc.collectionFk
- SET pb.collectionV = c.id
- WHERE c.itemPackingTypeFk = 'V' OR ISNULL(c.itemPackingTypeFk);
-
- UPDATE tmp.productionBuffer pb
- JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk
- JOIN vn.collection c ON c.id = tc.collectionFk
- SET pb.collectionF = c.id
- WHERE c.itemPackingTypeFk = 'F' OR ISNULL(c.itemPackingTypeFk);
-
- UPDATE tmp.productionBuffer pb
- JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk
- JOIN vn.collection c ON c.id = tc.collectionFk
- SET pb.collectionP = c.id
- WHERE c.itemPackingTypeFk = 'P' OR ISNULL(c.itemPackingTypeFk);
-
- -- Cajas
- ALTER TABLE tmp.productionBuffer
- ADD Cajas DOUBLE DEFAULT NULL;
- /*
- -- Problemas por ticket
- UPDATE tmp.productionBuffer pb
- JOIN tmp.ticketProblems tp ON tp.ticketFk = pb.ticketFk
- SET pb.problem = CAST(CONCAT( IFNULL(tp.itemShortage,''),
- IFNULL(tp.itemDelay,''),
- IF(tp.isFreezed,' CONGELADO',''),
- IF(tp.risk,' RIESGO',''),
- IF(tp.hasTicketRequest, ' COD 100',''),
- IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'),
- IF(tp.componentLack,' COMPONENTES', '')
- ) as char(255));
- */
- -- Refresca la caché para el cierre dinámico de agencias
- -- CALL cache.departure_timing(vWarehouseFk);
-/*
- -- Tickets de recogida
- REPLACE tmp.productionBuffer(
- shipped
- , ticketFk
- , agency
- , clientFk
- , addressNickname
- , state
- , workerCode
- , alertLevel
- , warehouseFk
- )
- SELECT DATE(t.shipped)
- , t.id
- , am.name
- , t.clientFk
- , a.nickname
- , s.id as state
- , w.code
- , ifnull(tls.alertLevel,0) alert_level
- , vWarehouseFk
- FROM vn.ticket t
- JOIN vn.address a on a.id = t.addressFk
- JOIN vn.agencyMode am ON am.id = t.agencyModeFk
- LEFT JOIN vn2008.warehouse_pickup wp ON wp.agency_id = am.id
- LEFT JOIN vn.ticketState tls on tls.ticket = t.id
- LEFT JOIN vn.state s ON s.id = tls.state
- LEFT JOIN vn.worker w on w.id = tls.worker
- WHERE t.shipped between TIMESTAMPADD(WEEK,-1,CURDATE()) AND util.dayend(TIMESTAMPADD(DAY,-1,CURDATE()))
- AND wp.warehouse_id = vWarehouseFk;
-*/
- DROP TEMPORARY TABLE tmp.productionTicket;
- DROP TEMPORARY TABLE tmp.ticket;
- DROP TEMPORARY TABLE IF EXISTS tmp.risk;
-
+proc: BEGIN
+
+ DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(CURDATE()));
+
+ DECLARE vIsTodayRelative BOOLEAN;
+
+ SELECT isTodayRelative INTO vIsTodayRelative
+ FROM vn.worker
+ WHERE userFk = vn.getUser();
+
+ CALL vn.prepareTicketList(TIMESTAMPADD(DAY,-1,CURDATE()), vEndingDate);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ SELECT * FROM tmp.productionTicket;
+
+ CALL vn.prepareClientList();
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems;
+ CREATE TEMPORARY TABLE tmp.ticketGetProblems
+ (INDEX (ticketFk)) ENGINE = MEMORY
+ SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped
+ FROM tmp.productionTicket tt
+ JOIN vn.ticket t ON t.id = tt.ticketFk;
+
+ CALL vn.ticketGetProblems(vIsTodayRelative);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.productionBuffer;
+ CREATE TEMPORARY TABLE tmp.productionBuffer
+ (PRIMARY KEY(ticketFk))
+ ENGINE = MEMORY
+ SELECT tt.ticketFk
+ , tt.clientFk
+ , t.warehouseFk
+ , t.nickname
+ , t.packages
+ , IF(HOUR(t.shipped), HOUR(t.shipped), IFNULL(HOUR(zc.hour),HOUR(z.hour))) as HH
+ , IFNULL(HOUR(zc.hour),HOUR(z.hour)) as Departure
+ , IF(MINUTE(t.shipped), MINUTE(t.shipped), IFNULL(MINUTE(zc.hour), MINUTE(z.hour))) as mm
+ , t.routeFk
+ , IF(am.deliveryMethodFk = 2,z.`id`,0) as zona
+ , t.nickname addressNickname
+ , a.postalCode
+ , a.city
+ , p.name province
+ , CONCAT(z.`name`,' ',IFNULL(RIGHT(t.routeFk,3),'')) agency
+ , am.id agencyModeFk
+ , 0 AS `lines`
+ , CAST( 0 AS DECIMAL(5,2)) AS m3
+ , CAST( 0 AS DECIMAL(5,2)) AS preparationRate
+ , "" as problem
+ , IFNULL(tls.state,2) AS state
+ , w.code workerCode
+ , DATE(t.shipped) shipped
+ , wk.code AS salesPersonCode
+ , p.id provinceFk
+ , tls.productionOrder
+ , ifnull(tls.alertLevel,0) alertLevel
+ , t.isBoxed as palletized
+ , rg.deviceId ubicacion
+ , tlu.lastUpdated
+ -- , tls.updated lastUpdated
+ , ifnull(st.graphCategory,0) graphCategory
+ , pk.code as parking
+ , 0 AS H
+ , 0 AS V
+ , 0 AS F
+ , 0 AS P
+ , st.isOk
+ , ag.isOwn
+ FROM tmp.productionTicket tt
+ JOIN vn.ticket t on tt.ticketFk = t.id
+ LEFT JOIN vn.ticketStateToday tst ON tst.ticket = t.id
+ LEFT JOIN vn.state st ON st.id = tst.state
+ LEFT JOIN vn.client c ON c.id = t.clientFk
+ LEFT JOIN vn.worker wk ON wk.id = c.salesPersonFk
+ JOIN vn.address a on a.id = t.addressFk
+ LEFT JOIN vn.province p on p.id = a.provinceFk
+ JOIN vn.agencyMode am ON am.id = t.agencyModeFk
+ JOIN vn.agency ag ON ag.id = am.agencyFk
+ LEFT JOIN vn.ticketState tls on tls.ticket = tt.ticketFk
+ LEFT JOIN vn.ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk
+ LEFT JOIN vn.worker w on w.id = tls.worker
+ LEFT JOIN vn.routeGate rg ON rg.routeFk = t.routeFk
+ LEFT JOIN vn.zone z ON z.id = t.zoneFk
+ LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND date(t.shipped) = zc.dated
+ LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
+ LEFT JOIN vn.parking pk ON pk.id = tp.parkingFk
+ WHERE t.warehouseFk = vWarehouseFk
+ AND am.deliveryMethodFk IN (1,2,3);
+
+ ALTER TABLE tmp.productionBuffer
+ CHANGE COLUMN `problem` `problem` VARCHAR(255),
+ ADD COLUMN `collectionH` INT,
+ ADD COLUMN `collectionV` INT,
+ ADD COLUMN `collectionF` INT,
+ ADD COLUMN `collectionP` INT;
+
+ -- Líneas y volumen por ticket
+ UPDATE tmp.productionBuffer pb
+ JOIN (
+ SELECT tt.ticketFk,
+ COUNT(*) as `lines`,
+ sum(sv.volume) as m3,
+ IFNULL(sum(IF(sv.isPicked,sv.volume,0)) / sum(sv.volume),0) as rate
+ FROM tmp.productionTicket tt
+ JOIN vn.saleVolume sv on sv.ticketFk = tt.ticketFk
+ GROUP BY tt.ticketFk
+ ) m on m.ticketFk = pb.ticketFk
+ SET pb.`lines` = m.`lines`,
+ pb.m3 = m.m3,
+ pb.preparationRate = m.rate;
+
+ DELETE FROM tmp.productionBuffer
+ WHERE `lines`= 0;
+
+ -- Lineas por linea de encajado
+ UPDATE tmp.productionBuffer pb
+ JOIN ( SELECT ticketFk,
+ sum(sub.H) H,
+ sum(sub.V) V,
+ sum(sub.F) F,
+ sum(sub.P) P
+ FROM (
+ SELECT t.ticketFk,
+ sum(i.itemPackingTypeFk = 'H') H,
+ sum(i.itemPackingTypeFk = 'V') V,
+ sum(i.itemPackingTypeFk = 'F') F,
+ sum(i.itemPackingTypeFk = 'P') P
+ FROM tmp.productionTicket t
+ JOIN vn.sale s ON s.ticketFk = t.ticketFk
+ JOIN vn.item i ON i.id = s.itemFk
+ GROUP BY t.ticketFk, i.itemPackingTypeFk) sub
+ GROUP BY ticketFk
+ ) sub2 ON sub2.ticketFk = pb.ticketFk
+ SET pb.H = sub2.H,
+ pb.V = sub2.V,
+ pb.F = sub2.F,
+ pb.P = sub2.P;
+
+ -- Colecciones segun tipo de encajado
+ UPDATE tmp.productionBuffer pb
+ JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk
+ JOIN vn.collection c ON c.id = tc.collectionFk
+ SET pb.collectionH = c.id
+ WHERE c.itemPackingTypeFk = 'H' OR ISNULL(c.itemPackingTypeFk);
+
+ UPDATE tmp.productionBuffer pb
+ JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk
+ JOIN vn.collection c ON c.id = tc.collectionFk
+ SET pb.collectionV = c.id
+ WHERE c.itemPackingTypeFk = 'V' OR ISNULL(c.itemPackingTypeFk);
+
+ UPDATE tmp.productionBuffer pb
+ JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk
+ JOIN vn.collection c ON c.id = tc.collectionFk
+ SET pb.collectionF = c.id
+ WHERE c.itemPackingTypeFk = 'F' OR ISNULL(c.itemPackingTypeFk);
+
+ UPDATE tmp.productionBuffer pb
+ JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk
+ JOIN vn.collection c ON c.id = tc.collectionFk
+ SET pb.collectionP = c.id
+ WHERE c.itemPackingTypeFk = 'P' OR ISNULL(c.itemPackingTypeFk);
+
+ -- Cajas
+ ALTER TABLE tmp.productionBuffer
+ ADD Cajas DOUBLE DEFAULT NULL;
+ /*
+ -- Problemas por ticket
+ UPDATE tmp.productionBuffer pb
+ JOIN tmp.ticketProblems tp ON tp.ticketFk = pb.ticketFk
+ SET pb.problem = CAST(CONCAT( IFNULL(tp.itemShortage,''),
+ IFNULL(tp.itemDelay,''),
+ IF(tp.isFreezed,' CONGELADO',''),
+ IF(tp.risk,' RIESGO',''),
+ IF(tp.hasTicketRequest, ' COD 100',''),
+ IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'),
+ IF(tp.componentLack,' COMPONENTES', '')
+ ) as char(255));
+ */
+ -- Refresca la caché para el cierre dinámico de agencias
+ -- CALL cache.departure_timing(vWarehouseFk);
+/*
+ -- Tickets de recogida
+ REPLACE tmp.productionBuffer(
+ shipped
+ , ticketFk
+ , agency
+ , clientFk
+ , addressNickname
+ , state
+ , workerCode
+ , alertLevel
+ , warehouseFk
+ )
+ SELECT DATE(t.shipped)
+ , t.id
+ , am.name
+ , t.clientFk
+ , a.nickname
+ , s.id as state
+ , w.code
+ , ifnull(tls.alertLevel,0) alert_level
+ , vWarehouseFk
+ FROM vn.ticket t
+ JOIN vn.address a on a.id = t.addressFk
+ JOIN vn.agencyMode am ON am.id = t.agencyModeFk
+ LEFT JOIN vn2008.warehouse_pickup wp ON wp.agency_id = am.id
+ LEFT JOIN vn.ticketState tls on tls.ticket = t.id
+ LEFT JOIN vn.state s ON s.id = tls.state
+ LEFT JOIN vn.worker w on w.id = tls.worker
+ WHERE t.shipped between TIMESTAMPADD(WEEK,-1,CURDATE()) AND util.dayend(TIMESTAMPADD(DAY,-1,CURDATE()))
+ AND wp.warehouse_id = vWarehouseFk;
+*/
+ DROP TEMPORARY TABLE tmp.productionTicket;
+ DROP TEMPORARY TABLE tmp.ticket;
+ DROP TEMPORARY TABLE IF EXISTS tmp.risk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -73337,8 +72782,10 @@ proc: BEGIN
-- Clientes Nuevos o Recuperados
UPDATE tmp.productionBuffer pb
LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = pb.clientFk
+ JOIN vn.productionConfig pc
SET pb.problem = TRIM(CAST(CONCAT('NUEVO ', pb.problem) AS CHAR(255)))
- WHERE ISNULL(cnb.clientFk) OR cnb.isRookie ;
+ WHERE (ISNULL(cnb.clientFk) OR cnb.isRookie)
+ AND pc.rookieDays;
-- Líneas y volumen por ticket
UPDATE tmp.productionBuffer pb
@@ -74463,104 +73910,57 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `reportLabelCollection_get`(vSelf INT)
-BEGIN
-
-/**
- * Obtiene los datos necesarios de un ticket o colección
- *
- * @param vSelf Ticket/Colección del que sacar los datos
- **/
-
- DECLARE vItemPackingTypeFk VARCHAR(1);
- DECLARE vIsTicket BOOL;
-
- -- Averiguamos si es un ticket o una colección
- SELECT IF(id, TRUE, FALSE) INTO vIsTicket
- FROM vn.ticket
- WHERE created > (CURRENT_DATE() - INTERVAL 1 MONTH)
- AND id = vSelf;
-
- -- Si los sacadores NO son de V, pinta los colores
- SELECT itemPackingTypeFk INTO vItemPackingTypeFk
- FROM vn.collection
- WHERE id = vSelf;
-
- IF !(vItemPackingTypeFk <=> 'V') THEN
-
- SELECT CONCAT(tc.collectionFk, ' ', LEFT(cc.code,4)) `level`,
- tc.ticketFk,
- LEFT(IF(t.routeFk IS NULL, am.name, zo.name ), 12) agencyDescription,
- am.name,
- t.clientFk,
- COUNT(*) notes,
- w.code workerCode,
- tt.labelCount,
- IF(HOUR(t.shipped), TIME(t.shipped), TIME(zo.`hour`)) horaagencia,
- t.shipped,
- COUNT(*) lineas,
- t.nickName,
- CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5,2)) , "m³") m3
- FROM vn.ticket t
- JOIN vn.ticketCollection tc ON tc.ticketFk = t.id
- JOIN vn.collection c ON c.id = tc.collectionFk
- JOIN vn.collectionColors cc ON cc.shelve = tc.`level`
- AND cc.wagon = tc.wagon
- AND cc.trainFk = c.trainFk
- JOIN vn.sale s ON s.ticketFk = t.id
- LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
- JOIN vn.worker w ON w.id = c.workerFk
- JOIN vn.agencyMode am ON am.id = t.agencyModeFk
- LEFT JOIN vn.ticketTrolley tt ON tt.ticket = t.id
- LEFT JOIN vn.address a ON a.id = t.addressFk
- LEFT JOIN vn.route r ON r.id = t.routeFk
- LEFT JOIN vn.zoneEstimatedDelivery ze ON ze.zoneFk = t.zoneFk
- LEFT JOIN vn.agencyMode agm ON r.agencyModeFk =agm.id
- LEFT JOIN vn.zone zo ON t.zoneFk = zo.id
- WHERE IF(vIsTicket, tc.ticketFk = vSelf, tc.collectionFk = vSelf)
- GROUP BY t.id
- ORDER BY cc.code;
-
- ELSE
-
- SELECT CONCAT(tc.collectionFk,' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.`level`) `level`,
- tc.ticketFk,
- LEFT(IF(t.routeFk IS NULL, am.name, zo.name ), 12) agencyDescription,
- am.name,
- t.clientFk,
- CAST(IF(ic.code = 'plant', CONCAT(MAX(i.`size`),' cm'), COUNT(*)) AS CHAR) notes,
- w.code workerCode,
- tt.labelCount,
- IF(HOUR(t.shipped), TIME(t.shipped), TIME(zo.`hour`)) horaagencia,
- t.shipped,
- COUNT(*) lineas,
- t.nickName,
- CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5,2)), "m³") m3
- FROM vn.ticket t
- JOIN vn.ticketCollection tc ON tc.ticketFk = t.id
- JOIN vn.collection c ON c.id = tc.collectionFk
- JOIN vn.sale s ON s.ticketFk = t.id
- LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id
- JOIN vn.item i ON i.id = s.itemFk
- JOIN vn.itemType it ON it.id = i.typeFk
- JOIN vn.itemCategory ic ON ic.id = it.categoryFk
- JOIN vn.worker w ON w.id = c.workerFk
- JOIN vn.agencyMode am ON am.id = t.agencyModeFk
- LEFT JOIN vn.ticketTrolley tt ON tt.ticket = t.id
- LEFT JOIN vn.address a ON a.id = t.addressFk
- LEFT JOIN vn.route r ON r.id = t.routeFk
- LEFT JOIN vn.zoneEstimatedDelivery ze ON ze.zoneFk = t.zoneFk
- LEFT JOIN vn.agencyMode agm ON r.agencyModeFk =agm.id
- LEFT JOIN vn.`zone` zo ON t.zoneFk = zo.id
- WHERE IF(vIsTicket, tc.ticketFk = vSelf, tc.collectionFk = vSelf)
- GROUP BY t.id;
-
- END IF;
-
+CREATE DEFINER=`root`@`localhost` PROCEDURE `reportLabelCollection_get`(vParam INT)
+BEGIN
+/**
+ * Obtiene los datos de etiquetas a partir de de un ticket o colección.
+ *
+ * @param vParam Ticket/Colección del que sacar los datos
+ */
+ DECLARE vIsTicket BOOL;
+
+ SELECT IF(id, TRUE, FALSE) INTO vIsTicket
+ FROM ticket
+ WHERE created > (CURRENT_DATE() - INTERVAL 1 MONTH)
+ AND id = vParam;
+
+ SELECT c.itemPackingTypeFk,
+ CONCAT(tc.collectionFk, ' ', LEFT(cc.code, 4)) color,
+ CONCAT(tc.collectionFk, ' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.`level`) levelV,
+ tc.ticketFk,
+ LEFT(IF(t.routeFk IS NULL, am.name, zo.name ), 12) agencyDescription,
+ am.name,
+ t.clientFk,
+ CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5, 2)), 'm³') m3 ,
+ CAST(IF(ic.code = 'plant', CONCAT(MAX(i.`size`),' cm'), COUNT(*)) AS CHAR) size,
+ w.code workerCode,
+ tt.labelCount,
+ IF(HOUR(t.shipped), TIME(t.shipped), TIME(zo.`hour`)) agencyHour,
+ t.shipped,
+ COUNT(*) lineCount,
+ t.nickName
+ FROM ticket t
+ JOIN ticketCollection tc ON tc.ticketFk = t.id
+ JOIN collection c ON c.id = tc.collectionFk
+ JOIN collectionColors cc ON cc.shelve = tc.`level`
+ AND cc.wagon = tc.wagon
+ AND cc.trainFk = c.trainFk
+ JOIN sale s ON s.ticketFk = t.id
+ LEFT JOIN saleVolume sv ON sv.saleFk = s.id
+ JOIN item i ON i.id = s.itemFk
+ JOIN itemType it ON it.id = i.typeFk
+ JOIN itemCategory ic ON ic.id = it.categoryFk
+ JOIN worker w ON w.id = c.workerFk
+ JOIN agencyMode am ON am.id = t.agencyModeFk
+ LEFT JOIN ticketTrolley tt ON tt.ticket = t.id
+ LEFT JOIN `zone` zo ON t.zoneFk = zo.id
+ WHERE IF(vIsTicket, tc.ticketFk = vParam, tc.collectionFk = vParam)
+ GROUP BY t.id
+ ORDER BY cc.`code`;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -74712,25 +74112,25 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `routeGate_assignDevice`(vDevice VARCHAR(30), vRouteFk INT)
-BEGIN
-/**
- * Asigna el dispositivo la ruta
- *
- * @param vDevice Dispositivo a remplazar
- * @param vRouteFk Ruta a la cual asignarlo
- */
- IF ISNULL(vDevice) THEN
-
- DELETE FROM routeGate
- WHERE routeFk = vRouteFk;
-
- ELSE
-
- REPLACE routeGate(routeFk, deviceId)
- VALUES(vRouteFk, vDevice);
-
- END IF;
-
+BEGIN
+/**
+ * Asigna el dispositivo la ruta
+ *
+ * @param vDevice Dispositivo a remplazar
+ * @param vRouteFk Ruta a la cual asignarlo
+ */
+ IF ISNULL(vDevice) THEN
+
+ DELETE FROM routeGate
+ WHERE routeFk = vRouteFk;
+
+ ELSE
+
+ REPLACE routeGate(routeFk, deviceId)
+ VALUES(vRouteFk, vDevice);
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -75047,64 +74447,64 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `route_getTickets`(vRouteFk INT)
-BEGIN
-/**
- * Pasado un RouteFk devuelve la información
- * de sus tickets.
- *
- * @param vRouteFk
- *
- * @select Información de los tickets
- */
-
- SELECT
- t.id AS Id,
- t.clientFk AS Client,
- a.id AS Address,
- a.nickname AS ClientName,
- t.packages AS Packages,
- a.street AS AddressName,
- a.postalCode AS PostalCode,
- a.city AS City,
- sub2.itemPackingTypeFk AS PackingType,
- c.phone AS ClientPhone,
- c.mobile AS ClientMobile,
- a.phone AS AddressPhone,
- a.mobile AS AddressMobile,
- tl.longitude AS Longitude,
- tl.latitude AS Latitude,
- wm.mediaValue AS SalePersonPhone,
- tob.Note AS Note,
- t.isSigned AS Signed,
- st.id AS Polizon
- FROM ticket t
- JOIN client c ON t.clientFk = c.id
- JOIN address a ON t.addressFk = a.id
- LEFT JOIN ticketLocation tl ON tl.ticketFk = t.id
- LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
- LEFT JOIN
- (SELECT tob.description AS Note, t.id
- FROM ticketObservation tob
- JOIN ticket t ON tob.ticketFk = t.id
- JOIN observationType ot ON ot.id = tob.observationTypeFk
- WHERE t.routeFk = vRouteFk
- AND ot.code = 'delivery'
- )tob ON tob.id = t.id
- LEFT JOIN stowaway st ON st.shipFk = t.id
- LEFT JOIN
- (SELECT sub.ticketFk,
- CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk
- FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items
- FROM ticket t
- JOIN sale s ON s.ticketFk = t.id
- JOIN item i ON i.id = s.itemFk
- WHERE t.routeFk = vRouteFk
- GROUP BY t.id,i.itemPackingTypeFk)sub
- GROUP BY sub.ticketFk
- ) sub2 ON sub2.ticketFk = t.id
- WHERE t.routeFk = vRouteFk
- GROUP BY t.id
- ORDER BY t.priority;
+BEGIN
+/**
+ * Pasado un RouteFk devuelve la información
+ * de sus tickets.
+ *
+ * @param vRouteFk
+ *
+ * @select Información de los tickets
+ */
+
+ SELECT
+ t.id AS Id,
+ t.clientFk AS Client,
+ a.id AS Address,
+ a.nickname AS ClientName,
+ t.packages AS Packages,
+ a.street AS AddressName,
+ a.postalCode AS PostalCode,
+ a.city AS City,
+ sub2.itemPackingTypeFk AS PackingType,
+ c.phone AS ClientPhone,
+ c.mobile AS ClientMobile,
+ a.phone AS AddressPhone,
+ a.mobile AS AddressMobile,
+ tl.longitude AS Longitude,
+ tl.latitude AS Latitude,
+ wm.mediaValue AS SalePersonPhone,
+ tob.Note AS Note,
+ t.isSigned AS Signed,
+ st.id AS Polizon
+ FROM ticket t
+ JOIN client c ON t.clientFk = c.id
+ JOIN address a ON t.addressFk = a.id
+ LEFT JOIN ticketLocation tl ON tl.ticketFk = t.id
+ LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk
+ LEFT JOIN
+ (SELECT tob.description AS Note, t.id
+ FROM ticketObservation tob
+ JOIN ticket t ON tob.ticketFk = t.id
+ JOIN observationType ot ON ot.id = tob.observationTypeFk
+ WHERE t.routeFk = vRouteFk
+ AND ot.code = 'delivery'
+ )tob ON tob.id = t.id
+ LEFT JOIN stowaway st ON st.shipFk = t.id
+ LEFT JOIN
+ (SELECT sub.ticketFk,
+ CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk
+ FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items
+ FROM ticket t
+ JOIN sale s ON s.ticketFk = t.id
+ JOIN item i ON i.id = s.itemFk
+ WHERE t.routeFk = vRouteFk
+ GROUP BY t.id,i.itemPackingTypeFk)sub
+ GROUP BY sub.ticketFk
+ ) sub2 ON sub2.ticketFk = t.id
+ WHERE t.routeFk = vRouteFk
+ GROUP BY t.id
+ ORDER BY t.priority;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -75327,28 +74727,28 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `saleBuy_Add`(vSaleFk INT, vBuyFk INT)
-BEGIN
-
- /* Añade un registro a la tabla saleBuy en el caso de que sea posible mantener la trazabilidad
- *
- * @param vSaleFk clave primaria de vn.sale
- * @param vBuyFk clave primaria de vn.buy
- */
- /*IF (SELECT COUNT(*)
- FROM vn.sale s
- JOIN vn.item i ON i.id = s.itemFk
- JOIN vn.itemType it ON it.id = i.typeFk
- JOIN vn.itemCategory ic ON ic.id = it.categoryFk
- WHERE s.id = vSaleFk
- AND ic.code = 'fruit') THEN */
-
- IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN
-
- INSERT INTO vn.saleBuy (saleFk, buyFk)
- VALUES(vSaleFk, vBuyFk);
-
- END IF;
-
+BEGIN
+
+ /* Añade un registro a la tabla saleBuy en el caso de que sea posible mantener la trazabilidad
+ *
+ * @param vSaleFk clave primaria de vn.sale
+ * @param vBuyFk clave primaria de vn.buy
+ */
+ /*IF (SELECT COUNT(*)
+ FROM vn.sale s
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.itemType it ON it.id = i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ WHERE s.id = vSaleFk
+ AND ic.code = 'fruit') THEN */
+
+ IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN
+
+ INSERT INTO vn.saleBuy (saleFk, buyFk)
+ VALUES(vSaleFk, vBuyFk);
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -75365,18 +74765,17 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `saleGroup_add`()
-BEGIN
-
- /*
- * Añade un nuevo registro a la tabla y devuelve su id
- */
-
- INSERT INTO vn.saleGroup(userFk)
- VALUES (account.myUser_getId());
-
- SELECT LAST_INSERT_ID();
-
+CREATE DEFINER=`root`@`localhost` PROCEDURE `saleGroup_add`(vSectorFk INT)
+BEGIN
+/**
+ * Añade un nuevo registro a la tabla y devuelve su id.
+ *
+ * @param vSectorFk Identificador de vn.sector
+ */
+ INSERT INTO vn.saleGroup(userFk, sectorFk)
+ VALUES (account.myUser_getId(), vSectorFk);
+
+ SELECT LAST_INSERT_ID();
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -75458,77 +74857,77 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `saleItemShelvingMake__`(IN `vTicketFk` INT, IN `vSectorFk` INT)
-BEGIN
-
- SET @rest:= CAST(0 AS DECIMAL(10,0));
- SET @saleFk := CAST(0 AS DECIMAL(10,0));
- SET @reserved := CAST(0 AS DECIMAL(10,0));
-
- UPDATE vn.itemShelving ish
- JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id
- JOIN sale s ON s.id = sis.saleFk
- SET ish.visible = sis.quantity + ish.visible,
- ish.available = sis.quantity + ish.visible
- WHERE s.ticketFk = vTicketFk;
-
- DELETE sis.*
- FROM saleItemShelving sis
- JOIN sale s ON s.id = sis.saleFk
- WHERE s.ticketFk = vTicketFk;
-
- INSERT INTO saleItemShelving( saleFk,
- itemShelvingFk,
- quantity,
- ubication)
- SELECT saleFk,
- itemShelvingFk,
- CAST(Reserved as DECIMAL(10,0)) as Reserved,
- ubication
- FROM
- (SELECT saleFk,
- itemShelvingFk,
- ubication,
- @rest := IF(@saleFk = saleFk, @rest, quantity) as Falta,
- @reserved := IF(available < @rest, available, IF(@rest < packing,0,@rest)) as Reserved,
- @rest := @rest - @reserved,
- @saleFk := saleFk
- FROM
- ( SELECT s.id as saleFk,
- ish.created,
- ish.id as itemShelvingFk,
- ish.available,
- s.quantity,
- ish.packing,
- CONCAT(p.`column`, '-',p.`row`,': ', sh.code ) as ubication
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- JOIN vn.sector sc ON sc.warehouseFk = t.warehouseFk
- JOIN vn.parking p ON p.sectorFk = sc.id
- JOIN vn.shelving sh ON sh.parkingFk = p.id
- JOIN vn.itemShelving ish ON ish.shelvingFk = sh.code AND ish.itemFk = s.itemFk
- WHERE t.id = vTicketFk
- AND sc.id = vSectorFk
- AND s.quantity MOD ish.packing = 0
- AND s.quantity >= ish.packing
- ORDER BY s.id,
- sh.priority DESC,
- ish.packing DESC,
- ish.created
- ) sub
- ) sub2
- WHERE Reserved > 0;
-
- UPDATE vn.itemShelving ish
- JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id
- JOIN vn.sale s ON s.id = sis.saleFk
- SET ish.available = ish.visible - sis.quantity,
- ish.visible = ish.visible - sis.quantity
- WHERE s.ticketFk = vTicketFk
- AND s.isPicked = FALSE;
-
- CALL vn.saleItemShelvingIsPicked(vTicketFk, TRUE);
-
-
+BEGIN
+
+ SET @rest:= CAST(0 AS DECIMAL(10,0));
+ SET @saleFk := CAST(0 AS DECIMAL(10,0));
+ SET @reserved := CAST(0 AS DECIMAL(10,0));
+
+ UPDATE vn.itemShelving ish
+ JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id
+ JOIN sale s ON s.id = sis.saleFk
+ SET ish.visible = sis.quantity + ish.visible,
+ ish.available = sis.quantity + ish.visible
+ WHERE s.ticketFk = vTicketFk;
+
+ DELETE sis.*
+ FROM saleItemShelving sis
+ JOIN sale s ON s.id = sis.saleFk
+ WHERE s.ticketFk = vTicketFk;
+
+ INSERT INTO saleItemShelving( saleFk,
+ itemShelvingFk,
+ quantity,
+ ubication)
+ SELECT saleFk,
+ itemShelvingFk,
+ CAST(Reserved as DECIMAL(10,0)) as Reserved,
+ ubication
+ FROM
+ (SELECT saleFk,
+ itemShelvingFk,
+ ubication,
+ @rest := IF(@saleFk = saleFk, @rest, quantity) as Falta,
+ @reserved := IF(available < @rest, available, IF(@rest < packing,0,@rest)) as Reserved,
+ @rest := @rest - @reserved,
+ @saleFk := saleFk
+ FROM
+ ( SELECT s.id as saleFk,
+ ish.created,
+ ish.id as itemShelvingFk,
+ ish.available,
+ s.quantity,
+ ish.packing,
+ CONCAT(p.`column`, '-',p.`row`,': ', sh.code ) as ubication
+ FROM vn.sale s
+ JOIN vn.ticket t ON t.id = s.ticketFk
+ JOIN vn.sector sc ON sc.warehouseFk = t.warehouseFk
+ JOIN vn.parking p ON p.sectorFk = sc.id
+ JOIN vn.shelving sh ON sh.parkingFk = p.id
+ JOIN vn.itemShelving ish ON ish.shelvingFk = sh.code AND ish.itemFk = s.itemFk
+ WHERE t.id = vTicketFk
+ AND sc.id = vSectorFk
+ AND s.quantity MOD ish.packing = 0
+ AND s.quantity >= ish.packing
+ ORDER BY s.id,
+ sh.priority DESC,
+ ish.packing DESC,
+ ish.created
+ ) sub
+ ) sub2
+ WHERE Reserved > 0;
+
+ UPDATE vn.itemShelving ish
+ JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id
+ JOIN vn.sale s ON s.id = sis.saleFk
+ SET ish.available = ish.visible - sis.quantity,
+ ish.visible = ish.visible - sis.quantity
+ WHERE s.ticketFk = vTicketFk
+ AND s.isPicked = FALSE;
+
+ CALL vn.saleItemShelvingIsPicked(vTicketFk, TRUE);
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -75659,20 +75058,20 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `saleParking_add__`(vSaleFk INT, vParkingCode VARCHAR(10))
-BEGIN
-
- /*
- * Inserta registro en saleParking
- *
- * vSaleFk Identificador de vn.sale
- * vParkingCode Code de vn.parking
- */
-
- INSERT INTO vn.saleParking(saleFk, parkingFk, userFk)
- SELECT vSaleFk, p.id, account.myUser_getId()
- FROM vn.parking p
- WHERE p.code = vParkingCode COLLATE utf8_unicode_ci;
-
+BEGIN
+
+ /*
+ * Inserta registro en saleParking
+ *
+ * vSaleFk Identificador de vn.sale
+ * vParkingCode Code de vn.parking
+ */
+
+ INSERT INTO vn.saleParking(saleFk, parkingFk, userFk)
+ SELECT vSaleFk, p.id, account.myUser_getId()
+ FROM vn.parking p
+ WHERE p.code = vParkingCode COLLATE utf8_unicode_ci;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -75896,28 +75295,28 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_add`(vSaleGroupFk INT)
-BEGIN
-
- /* Inserta en vn.saleTracking las lineas de una previa
- *
- * @param vSaleGroupFk Identificador de vn.saleGroup
- */
-
- REPLACE vn.saleTracking(saleFk,
- isChecked,
- workerFk,
- actionFk,
- stateFk)
- SELECT sgd.saleFk ,
- TRUE,
- account.myUser_getId(),
- a.accion_id,
- s.id
- FROM vn.saleGroupDetail sgd
- JOIN vncontrol.accion a ON a.accion = 'SACAR'
- JOIN vn.state s ON s.code = 'ON_PREPARATION'
- WHERE sgd.saleGroupFk = vSaleGroupFk;
-
+BEGIN
+
+ /* Inserta en vn.saleTracking las lineas de una previa
+ *
+ * @param vSaleGroupFk Identificador de vn.saleGroup
+ */
+
+ REPLACE vn.saleTracking(saleFk,
+ isChecked,
+ workerFk,
+ actionFk,
+ stateFk)
+ SELECT sgd.saleFk ,
+ TRUE,
+ account.myUser_getId(),
+ a.accion_id,
+ s.id
+ FROM vn.saleGroupDetail sgd
+ JOIN vncontrol.accion a ON a.accion = 'SACAR'
+ JOIN vn.state s ON s.code = 'ON_PREPARATION'
+ WHERE sgd.saleGroupFk = vSaleGroupFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -75935,21 +75334,21 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_addPreparedSaleGroup`(vSaleGroupFk INT)
-BEGIN
-
- /**
- * Inserta lineas de vn.saleTracking para un saleGroup (previa) que escanea un sacador
- *
- * @param vSaleGroupFk Identificador de vn.saleGroup
- */
-
- REPLACE vn.saleTracking(saleFk, isChecked, workerFk, actionFk, stateFk)
- SELECT sgd.saleFk, TRUE, account.myUser_getId(), a.accion_id id, s.id
- FROM vn.saleGroupDetail sgd
- JOIN vncontrol.accion a ON a.accion = 'SACAR'
- JOIN vn.state s ON s.code = 'PREPARED'
- WHERE sgd.saleGroupFk = vSaleGroupFk;
-
+BEGIN
+
+ /**
+ * Inserta lineas de vn.saleTracking para un saleGroup (previa) que escanea un sacador
+ *
+ * @param vSaleGroupFk Identificador de vn.saleGroup
+ */
+
+ REPLACE vn.saleTracking(saleFk, isChecked, workerFk, actionFk, stateFk)
+ SELECT sgd.saleFk, TRUE, account.myUser_getId(), a.accion_id id, s.id
+ FROM vn.saleGroupDetail sgd
+ JOIN vncontrol.accion a ON a.accion = 'SACAR'
+ JOIN vn.state s ON s.code = 'PREPARED'
+ WHERE sgd.saleGroupFk = vSaleGroupFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -75967,31 +75366,31 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_addPrevOK`(vSectorCollectionFk INT)
-BEGIN
-
- /**
- * Inserta los registros de la colección de sector con el estado PREVIA OK
- *
- * @param vSectorCollectionFk Identificador de vn.sectorCollection
- */
-
- REPLACE vn.saleTracking(saleFk,
- isChecked,
- workerFk,
- actionFk,
- stateFk)
- SELECT sgd.saleFk,
- TRUE,
- sc.userFk,
- a.accion_id,
- s.id
- FROM vn.sectorCollection sc
- JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
- JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
- JOIN vn.state s ON s.code = 'OK PREVIOUS'
- JOIN vncontrol.accion a ON a.accion = 'PRESACAR'
- WHERE sc.id = vSectorCollectionFk;
-
+BEGIN
+
+ /**
+ * Inserta los registros de la colección de sector con el estado PREVIA OK
+ *
+ * @param vSectorCollectionFk Identificador de vn.sectorCollection
+ */
+
+ REPLACE vn.saleTracking(saleFk,
+ isChecked,
+ workerFk,
+ actionFk,
+ stateFk)
+ SELECT sgd.saleFk,
+ TRUE,
+ sc.userFk,
+ a.accion_id,
+ s.id
+ FROM vn.sectorCollection sc
+ JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
+ JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
+ JOIN vn.state s ON s.code = 'OK PREVIOUS'
+ JOIN vncontrol.accion a ON a.accion = 'PRESACAR'
+ WHERE sc.id = vSectorCollectionFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -76517,42 +75916,42 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getForSijsner__`(vDated DATE)
-BEGIN
-
- /**
- * Devuelve el listado de ventas que tiene que etiquetar Sijsner para la fecha dada
- *
- * @param vDated Fecha de preparación de los tickets
- */
-
- SELECT b.printedStickers OR s.isPicked isPrinted,
- t.shipped ,
- t.nickname ,
- s.ticketFk ,
- s.itemFk ,
- FLOOR(s.quantity / e.pac) stickers,
- CONCAT(FLOOR(s.quantity / e.pac) , ' x ', e.pac ) amount,
- s.concept,
- e.kop,
- e.sub,
- sp.company_name supplier,
- b.id buyFk
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- JOIN vn.warehouse w ON w.id = t.warehouseFk
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p ON p.id = a.provinceFk
- JOIN vn.country c ON c.id = p.countryFk
- JOIN vn.item i ON i.id = s.itemFk
- JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk
- JOIN vn.buy b ON b.id = lb.buy_id
- LEFT JOIN edi.ekt e ON e.id = b.ektFk
- LEFT JOIN edi.supplier sp ON sp.supplier_id = e.pro
- WHERE t.shipped BETWEEN vDated AND TIMESTAMPADD(HOUR,23,vDated)
- AND c.code != 'ES'
- AND w.code IN ('FLM','VNH')
- AND s.quantity ;
-
+BEGIN
+
+ /**
+ * Devuelve el listado de ventas que tiene que etiquetar Sijsner para la fecha dada
+ *
+ * @param vDated Fecha de preparación de los tickets
+ */
+
+ SELECT b.printedStickers OR s.isPicked isPrinted,
+ t.shipped ,
+ t.nickname ,
+ s.ticketFk ,
+ s.itemFk ,
+ FLOOR(s.quantity / e.pac) stickers,
+ CONCAT(FLOOR(s.quantity / e.pac) , ' x ', e.pac ) amount,
+ s.concept,
+ e.kop,
+ e.sub,
+ sp.company_name supplier,
+ b.id buyFk
+ FROM vn.sale s
+ JOIN vn.ticket t ON t.id = s.ticketFk
+ JOIN vn.warehouse w ON w.id = t.warehouseFk
+ JOIN vn.address a ON a.id = t.addressFk
+ JOIN vn.province p ON p.id = a.provinceFk
+ JOIN vn.country c ON c.id = p.countryFk
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk
+ JOIN vn.buy b ON b.id = lb.buy_id
+ LEFT JOIN edi.ekt e ON e.id = b.ektFk
+ LEFT JOIN edi.supplier sp ON sp.supplier_id = e.pro
+ WHERE t.shipped BETWEEN vDated AND TIMESTAMPADD(HOUR,23,vDated)
+ AND c.code != 'ES'
+ AND w.code IN ('FLM','VNH')
+ AND s.quantity ;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -76570,118 +75969,115 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getFromTicketOrCollection`(vParam INT)
-BEGIN
-/*
- * Visualizar lineas de la tabla sale a través del parámetro vParam que puede ser ticket o collection
- *
- * @param vParam Identificador de ticket o collection
- */
-
- DECLARE vItemPackingTypeFk VARCHAR(1);
- DECLARE vIsCollection BOOL;
-
- SELECT COUNT(*) INTO vIsCollection
- FROM collection c
- WHERE c.id = vParam;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
- DROP TEMPORARY TABLE IF EXISTS tmp.ticket2;
-
- IF vIsCollection THEN
-
- CREATE TEMPORARY TABLE tmp.ticket
- (INDEX (id))
- ENGINE = MEMORY
- SELECT tc.ticketFk id
- FROM ticketCollection tc
- JOIN ticket t ON t.id = tc.ticketFk
- WHERE tc.collectionFk = vParam;
-
- CREATE TEMPORARY TABLE tmp.ticket2
- (INDEX (id))
- ENGINE = MEMORY
- SELECT tc.ticketFk id
- FROM ticketCollection tc
- JOIN ticket t ON t.id = tc.ticketFk
- WHERE tc.collectionFk = vParam;
- ELSE
- CREATE TEMPORARY TABLE tmp.ticket
- (INDEX (id))
- ENGINE = MEMORY
- SELECT vParam id;
-
- CREATE TEMPORARY TABLE tmp.ticket2
- (INDEX (id))
- ENGINE = MEMORY
- SELECT vParam id;
- END IF;
-
-
-
- SELECT s.ticketFk,
- sgd.saleGroupFk,
- s.id as saleFk,
- s.itemFk,
- s.quantity,
- i.longName,
- i.size,
- s.reserved,
- MAX(IF(st.semaphore <=> 1, TRUE, FALSE)) as isPreviousPrepared,
- MAX(IF(st.semaphore <=> 2, TRUE, FALSE)) as isPrepared,
- MAX(IF(st.semaphore <=> 3, TRUE, FALSE)) as isControlled,
- MAX(IF(st.semaphore <=> 4, TRUE, FALSE)) as isPreControlled,
- ic.color,
- ip.productor,
- s.discount,
- s.price,
- i.stems,
- i.category,
- o.code origin,
- tt.clientFk,
- s.originalQuantity,
- TRIM(CONCAT(LPAD(s.concept,30,' '), ' ',
- RPAD(IFNULL(i.size,''),5,' '))) line1,
- '' cel1,
- TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2,
- IF(s.quantity MOD IFNULL(b.packing,s.quantity + 1),
- CONCAT(CAST(s.quantity/IFNULL(b.`grouping`,1) AS DECIMAL(10,0)),' x ',IFNULL(b.`grouping`,1)),
- CONCAT(CAST(s.quantity / IFNULL(b.packing,1) AS DECIMAL(10,0)),' pack de ',IFNULL(b.packing,1))) cel2,
- TRIM(CONCAT(ic.color)) line3,
- p.code cel3,
- s.isAdded,
- sub2.originalQuantity as startQuantity, -- eliminar cuando tengamos la nueva apk
- IFNULL(c.workerFk,getUser()) as workerFk,
- IFNULL(SUM(iss.quantity),0) as pickedQuantity,
- i.packingShelve
- FROM tmp.ticket t
- JOIN sale s ON s.ticketFk = t.id
- JOIN ticket tt ON tt.id = t.id
- LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = tt.warehouseFk
- LEFT JOIN buy b ON b.id = lb.buy_id
- JOIN item i ON i.id = s.itemFk
- LEFT JOIN ticketCollection tc ON tc.ticketFk = t.id
- LEFT JOIN collection c ON c.id = tc.collectionFk
- LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity
- FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity
- FROM tmp.ticket2 t
- JOIN sale s ON s.ticketFk = t.id
- JOIN saleTracking st ON st.saleFk = s.id
- ORDER BY st.id DESC) sub
- GROUP BY sub.saleFk, sub.stateFK) sub2 ON sub2.saleFk = s.id AND sub2.isChecked = 1
- LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
- LEFT JOIN state st ON st.id = sub2.stateFk
- LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk
- LEFT JOIN itemProductor ip ON ip.itemFk = s.itemFk
- LEFT JOIN origin o ON o.id = i.originFk
- LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
- LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
- LEFT JOIN parking p ON p.id = sg.parkingFk
- GROUP BY s.id;
-
-
- DROP TEMPORARY TABLE tmp.ticket;
- DROP TEMPORARY TABLE tmp.ticket2;
-
+BEGIN
+/**
+ * Visualizar lineas de la tabla sale a través del parámetro vParam que puede
+ * ser ticket o collection.
+ *
+ * @param vParam Identificador de ticket o collection
+ */
+ DECLARE vItemPackingTypeFk VARCHAR(1);
+ DECLARE vIsCollection BOOL;
+
+ SELECT COUNT(*) INTO vIsCollection
+ FROM collection c
+ WHERE c.id = vParam;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket2;
+
+ IF vIsCollection THEN
+ CREATE TEMPORARY TABLE tmp.ticket
+ (INDEX (id))
+ ENGINE = MEMORY
+ SELECT tc.ticketFk id
+ FROM ticketCollection tc
+ JOIN ticket t ON t.id = tc.ticketFk
+ WHERE tc.collectionFk = vParam;
+
+ CREATE TEMPORARY TABLE tmp.ticket2
+ (INDEX (id))
+ ENGINE = MEMORY
+ SELECT tc.ticketFk id
+ FROM ticketCollection tc
+ JOIN ticket t ON t.id = tc.ticketFk
+ WHERE tc.collectionFk = vParam;
+ ELSE
+ CREATE TEMPORARY TABLE tmp.ticket
+ (INDEX (id))
+ ENGINE = MEMORY
+ SELECT vParam id;
+
+ CREATE TEMPORARY TABLE tmp.ticket2
+ (INDEX (id))
+ ENGINE = MEMORY
+ SELECT vParam id;
+ END IF;
+
+ SELECT s.ticketFk,
+ sgd.saleGroupFk,
+ s.id as saleFk,
+ s.itemFk,
+ s.quantity,
+ i.longName,
+ i.size,
+ s.reserved,
+ MAX(IF(st.semaphore <=> 1, TRUE, FALSE)) as isPreviousPrepared,
+ MAX(IF(st.semaphore <=> 2, TRUE, FALSE)) as isPrepared,
+ MAX(IF(st.semaphore <=> 3, TRUE, FALSE)) as isControlled,
+ MAX(IF(st.semaphore <=> 4, TRUE, FALSE)) as isPreControlled,
+ ic.color,
+ ip.productor,
+ s.discount,
+ s.price,
+ i.stems,
+ i.category,
+ o.code origin,
+ tt.clientFk,
+ s.originalQuantity,
+ TRIM(CONCAT(LPAD(s.concept,30,' '), ' ',
+ RPAD(IFNULL(i.size,''),5,' '))) line1,
+ '' cel1,
+ TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2,
+ IF(s.quantity MOD IFNULL(b.packing,s.quantity + 1),
+ CONCAT(CAST(s.quantity/IFNULL(b.`grouping`,1) AS DECIMAL(10,0)),' x ',IFNULL(b.`grouping`,1)),
+ CONCAT(CAST(s.quantity / IFNULL(b.packing,1) AS DECIMAL(10,0)),' pack de ',IFNULL(b.packing,1))) cel2,
+ TRIM(CONCAT(ic.color)) line3,
+ p.code cel3,
+ s.isAdded,
+ sub2.originalQuantity as startQuantity, -- eliminar cuando tengamos la nueva apk
+ IFNULL(c.workerFk,getUser()) as workerFk,
+ IFNULL(SUM(iss.quantity),0) as pickedQuantity,
+ i.packingShelve,
+ MIN(iss.created) picked
+ FROM tmp.ticket t
+ JOIN sale s ON s.ticketFk = t.id
+ JOIN ticket tt ON tt.id = t.id
+ LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = tt.warehouseFk
+ LEFT JOIN buy b ON b.id = lb.buy_id
+ JOIN item i ON i.id = s.itemFk
+ LEFT JOIN ticketCollection tc ON tc.ticketFk = t.id
+ LEFT JOIN collection c ON c.id = tc.collectionFk
+ LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity
+ FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity
+ FROM tmp.ticket2 t
+ JOIN sale s ON s.ticketFk = t.id
+ JOIN saleTracking st ON st.saleFk = s.id
+ ORDER BY st.id DESC) sub
+ GROUP BY sub.saleFk, sub.stateFK) sub2 ON sub2.saleFk = s.id AND sub2.isChecked = 1
+ LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
+ LEFT JOIN state st ON st.id = sub2.stateFk
+ LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk
+ LEFT JOIN itemProductor ip ON ip.itemFk = s.itemFk
+ LEFT JOIN origin o ON o.id = i.originFk
+ LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
+ LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
+ LEFT JOIN parking p ON p.id = sg.parkingFk
+ GROUP BY s.id;
+
+ DROP TEMPORARY TABLE
+ tmp.ticket,
+ tmp.ticket2;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -76700,15 +76096,13 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getProblems`(IN vIsTodayRelative tinyint(1))
BEGIN
- /**
- * Calcula los problemas de cada venta
- * para un conjunto de tickets.
- *
- * @param vIsTodayRelative Indica si se calcula el disponible como si todo saliera hoy
- * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular
- * @return tmp.sale_problems
- */
-
+/**
+ * Calcula los problemas de cada venta para un conjunto de tickets.
+ *
+ * @param vIsTodayRelative Indica si se calcula el disponible como si todo saliera hoy
+ * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular
+ * @return tmp.sale_problems
+ */
DECLARE vWarehouseFk INT;
DECLARE vDate DATE;
DECLARE vAvailableCache INT;
@@ -76724,6 +76118,13 @@ BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1;
+ DELETE tt.*
+ FROM tmp.sale_getProblems tt
+ JOIN vn.ticketObservation tto ON tto.ticketFk = tt.ticketFk
+ JOIN vn.observationType ot ON ot.id = tto.observationTypeFk
+ WHERE ot.code = 'administrative'
+ AND tto.description = 'Miriam';
+
DROP TEMPORARY TABLE IF EXISTS tmp.sale_problems;
CREATE TEMPORARY TABLE tmp.sale_problems (
ticketFk INT(11),
@@ -76733,10 +76134,10 @@ BEGIN
hasHighRisk TINYINT(1) DEFAULT 0,
hasTicketRequest INTEGER(1) DEFAULT 0,
isAvailable INTEGER(1) DEFAULT 1,
- itemShortage VARCHAR(250),
+ itemShortage VARCHAR(255),
isTaxDataChecked INTEGER(1) DEFAULT 1,
- itemDelay VARCHAR(250),
- itemLost VARCHAR(250),
+ itemDelay VARCHAR(255),
+ itemLost VARCHAR(255),
hasComponentLack INTEGER(1),
isTooLittle BOOL DEFAULT FALSE,
PRIMARY KEY (ticketFk, saleFk)
@@ -76755,20 +76156,23 @@ BEGIN
-- Too Little
INSERT INTO tmp.sale_problems(ticketFk, isTooLittle)
- SELECT sub.ticketFk, TRUE
- FROM (SELECT tl.ticketFk, SUM(sv.litros) litros, t.totalWithoutVat
- FROM tmp.ticket_list tl
- JOIN vn.saleVolume sv ON sv.ticketFk = tl.ticketFk
- JOIN vn.ticket t ON t.id = tl.ticketFk
- JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = CURDATE()
- JOIN vn.agencyMode am ON am.id = t.agencyModeFk
- JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk
- WHERE NOW() < TIMESTAMPADD(MINUTE,MINUTE(zc.`hour`) ,TIMESTAMPADD(HOUR,HOUR(zc.`hour`),CURDATE()))
- AND dm.code IN('AGENCY','DELIVERY','PICKUP')
- GROUP BY tl.ticketFk) sub
+ SELECT tp.ticketFk, TRUE
+ FROM tmp.sale_getProblems tp
+ JOIN vn.ticket t ON t.id = tp.ticketFk
+ JOIN (SELECT t.addressFk, SUM(sv.litros) litros, t.totalWithoutVat
+ FROM tmp.ticket_list tl
+ JOIN vn.saleVolume sv ON sv.ticketFk = tl.ticketFk
+ JOIN vn.ticket t ON t.id = tl.ticketFk
+ JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = CURDATE()
+ JOIN vn.agencyMode am ON am.id = t.agencyModeFk
+ JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk
+ WHERE NOW() < TIMESTAMPADD(MINUTE,MINUTE(zc.`hour`) ,TIMESTAMPADD(HOUR,HOUR(zc.`hour`),CURDATE()))
+ AND dm.code IN('AGENCY','DELIVERY','PICKUP')
+ AND t.shipped BETWEEN CURDATE() AND util.midnight()
+ GROUP BY t.addressFk) sub ON sub.addressFk = t.addressFk
JOIN vn.volumeConfig vc
WHERE sub.litros < vc.minTicketVolume
- AND sub.totalWithoutVat < vc.minTicketValue;
+ AND sub.totalWithoutVat < vc.minTicketValue;
-- Faltan componentes
INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk)
@@ -76857,7 +76261,7 @@ BEGIN
SELECT ticketFk, problem, saleFk
FROM (
SELECT tl.ticketFk,
- CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')) problem,
+ LEFT(CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')),250) problem,
s.id AS saleFk
FROM tmp.ticket_list tl
JOIN vn.ticket t ON t.id = tl.ticketFk
@@ -76885,7 +76289,7 @@ BEGIN
INSERT INTO tmp.sale_problems(ticketFk, itemLost, saleFk)
SELECT ticketFk, problem, saleFk
FROM (
- SELECT tl.ticketFk, GROUP_CONCAT('I: ',i.id, ' ', i.longName, ' ') problem, s.id AS saleFk
+ SELECT tl.ticketFk, LEFT(GROUP_CONCAT('I: ',i.id, ' ', i.longName, ' '),250) problem, s.id AS saleFk
FROM tmp.ticket_list tl
JOIN vn.ticket t ON t.id = tl.ticketFk
JOIN vn.sale s ON s.ticketFk = t.id
@@ -76911,7 +76315,7 @@ BEGIN
INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk)
SELECT ticketFk, problem, saleFk
FROM (
- SELECT tl.ticketFk, GROUP_CONCAT('R: ',i.id, ' ', i.longName, ' ') problem, s.id AS saleFk
+ SELECT tl.ticketFk, LEFT(GROUP_CONCAT('R: ',i.id, ' ', i.longName, ' '),250) problem, s.id AS saleFk
FROM tmp.ticket_list tl
JOIN vn.ticket t ON t.id = tl.ticketFk
JOIN vn.sale s ON s.ticketFk = t.id
@@ -76948,7 +76352,6 @@ BEGIN
DROP TEMPORARY TABLE
tmp.clientGetDebt,
tmp.ticket_list;
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -77224,24 +76627,24 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_PriceFix`(vTicketFk INT)
-BEGIN
-
- DELETE sc.*
- FROM vn.saleComponent sc
- JOIN vn.sale s ON s.id = sc.saleFk
- JOIN vn.component c ON c.id = sc.componentFk
- JOIN vn.componentType ct ON ct.id = c.typeFk
- WHERE s.ticketFk = vTicketFk
- AND ct.`type` = 'otros';
-
- UPDATE vn.sale s
- JOIN (
- SELECT sc.saleFk, sum(sc.value ) price
- FROM vn.saleComponent sc
- JOIN vn.sale s ON s.id = sc.saleFk
- WHERE s.ticketFk = vTicketFk
- GROUP BY sc.saleFk) sub ON sub.saleFk = s.id
- SET s.price = sub.price;
+BEGIN
+
+ DELETE sc.*
+ FROM vn.saleComponent sc
+ JOIN vn.sale s ON s.id = sc.saleFk
+ JOIN vn.component c ON c.id = sc.componentFk
+ JOIN vn.componentType ct ON ct.id = c.typeFk
+ WHERE s.ticketFk = vTicketFk
+ AND ct.`type` = 'otros';
+
+ UPDATE vn.sale s
+ JOIN (
+ SELECT sc.saleFk, sum(sc.value ) price
+ FROM vn.saleComponent sc
+ JOIN vn.sale s ON s.id = sc.saleFk
+ WHERE s.ticketFk = vTicketFk
+ GROUP BY sc.saleFk) sub ON sub.saleFk = s.id
+ SET s.price = sub.price;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -77388,31 +76791,31 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_setQuantity`(vSaleFk INT, vQuantity INT)
-BEGIN
-/*
- * Actualiza la cantidad de la línea de venta
- *
- * @vSaleFk id de la línea de venta
- * @vQuantity cantidad a modificar
- *
- */
-
- DECLARE vDescription VARCHAR(100);
- DECLARE vOrigin INT;
-
- SELECT CONCAT("Cambio cantidad ",concept," de ", quantity," a ", vQuantity) INTO vDescription
- FROM sale
- WHERE id = vSaleFk;
-
- SELECT ticketFk INTO vOrigin FROM sale WHERE id = vSaleFk;
-
- CALL logAdd(vOrigin, 'update', 'ticket', vDescription);
-
- UPDATE sale
- SET originalQuantity = quantity,
- quantity = vQuantity
- WHERE id = vSaleFk;
-
+BEGIN
+/*
+ * Actualiza la cantidad de la línea de venta
+ *
+ * @vSaleFk id de la línea de venta
+ * @vQuantity cantidad a modificar
+ *
+ */
+
+ DECLARE vDescription VARCHAR(100);
+ DECLARE vOrigin INT;
+
+ SELECT CONCAT("Cambio cantidad ",concept," de ", quantity," a ", vQuantity) INTO vDescription
+ FROM sale
+ WHERE id = vSaleFk;
+
+ SELECT ticketFk INTO vOrigin FROM sale WHERE id = vSaleFk;
+
+ CALL logAdd(vOrigin, 'update', 'ticket', vDescription);
+
+ UPDATE sale
+ SET originalQuantity = quantity,
+ quantity = vQuantity
+ WHERE id = vSaleFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -77477,33 +76880,33 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `scanTreeCreate__`()
-BEGIN
- CALL nestTree(
- 'vn2008',
- 'scan',
- 'vn2008',
- 'scanTree'
- );
-
- UPDATE vn2008.scanTree st
- JOIN (
- SELECT sl.scan_id,
- MAX(sl.odbc_date) lastScanned,
- COUNT(DISTINCT t.routeFk) routeCount,
- MIN(t.routeFk) mod 1000 as minRoute,
- MAX(t.routeFk) mod 1000 as maxRoute,
- COUNT(sl.scan_line_id) as scanned
- FROM vn2008.scan_line sl
- JOIN expedition e ON e.id = sl.`code`
- JOIN ticket t ON t.id = e.ticketFk
- WHERE t.routeFk
- GROUP BY sl.scan_id
- ) rs ON rs.scan_id = st.id
- SET st.lastScanned = rs.lastScanned,
- st.routeCount = rs.routeCount,
- st.minRoute = rs.minRoute,
- st.maxRoute = IF(rs.minRoute != rs.maxRoute, rs.maxRoute,NULL),
- st.scanned = rs.scanned;
+BEGIN
+ CALL nestTree(
+ 'vn2008',
+ 'scan',
+ 'vn2008',
+ 'scanTree'
+ );
+
+ UPDATE vn2008.scanTree st
+ JOIN (
+ SELECT sl.scan_id,
+ MAX(sl.odbc_date) lastScanned,
+ COUNT(DISTINCT t.routeFk) routeCount,
+ MIN(t.routeFk) mod 1000 as minRoute,
+ MAX(t.routeFk) mod 1000 as maxRoute,
+ COUNT(sl.scan_line_id) as scanned
+ FROM vn2008.scan_line sl
+ JOIN expedition e ON e.id = sl.`code`
+ JOIN ticket t ON t.id = e.ticketFk
+ WHERE t.routeFk
+ GROUP BY sl.scan_id
+ ) rs ON rs.scan_id = st.id
+ SET st.lastScanned = rs.lastScanned,
+ st.routeCount = rs.routeCount,
+ st.minRoute = rs.minRoute,
+ st.maxRoute = IF(rs.minRoute != rs.maxRoute, rs.maxRoute,NULL),
+ st.scanned = rs.scanned;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -77580,27 +76983,27 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollection_get`(vSectorFk INT)
-BEGIN
-
- /**
- * Devuelve las colecciones del sector que corresponden al usuario conectado, y que estan incompletas
- *
- * @param vSectorFk Identificador de vn.sector
- */
-
- SELECT DISTINCT sc.id collectionFk, sc.created
- FROM vn.sectorCollection sc
- JOIN vn.state s ON s.code = 'PREVIOUS_PREPARATION'
- LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
- LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
+BEGIN
+
+ /**
+ * Devuelve las colecciones del sector que corresponden al usuario conectado, y que estan incompletas
+ *
+ * @param vSectorFk Identificador de vn.sector
+ */
+
+ SELECT DISTINCT sc.id collectionFk, sc.created
+ FROM vn.sectorCollection sc
+ JOIN vn.state s ON s.code = 'PREVIOUS_PREPARATION'
+ LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
+ LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
LEFT JOIN vn.saleTracking st ON st.saleFk = sgd.saleFk AND st.stateFk = s.id AND st.workerFk = sc.userFk
- LEFT JOIN vn.sale sl ON sl.id = st.saleFk
- WHERE sc.userFk = account.myUser_getId()
- AND (ISNULL(scsg.sectorCollectionFk)
+ LEFT JOIN vn.sale sl ON sl.id = st.saleFk
+ WHERE sc.userFk = account.myUser_getId()
+ AND (ISNULL(scsg.sectorCollectionFk)
OR
(NOT st.isChecked AND sl.quantity > 0))
- AND sc.created > CURDATE();
-
+ AND sc.created > CURDATE();
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -77618,36 +77021,36 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollection_getSale`(vSelf INT)
-BEGIN
-
- /**
- * Devuelve las lineas de venta correspondientes a esa coleccion de sector
- *
- * @param vSelf Identificador de vn.sectorCollection
- */
-
- SELECT s.ticketFk,
- s.itemFk,
- i.longName,
- IFNULL(i.itemPackingTypeFk,' ') itemPackingTypeFk,
- IFNULL(i.subName ,' ') subName,
- s.quantity,
- w.code workerCode,
- sgd.saleFk,
- IFNULL(iss.quantity,0) pickedQuantity,
- c.salesPersonFk
- FROM vn.sale s
- JOIN vn.item i ON i.id = s.itemFk
- JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
- JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sgd.saleGroupFk
- JOIN vn.saleTracking st ON st.saleFk = s.id
- JOIN vn.state stt ON stt.id = st.stateFk AND stt.code = 'PREVIOUS_PREPARATION'
- JOIN vn.worker w ON w.id = st.workerFk
- JOIN vn.ticket t ON t.id= s.ticketFk
- JOIN vn.client c ON c.id=t.clientFk
- LEFT JOIN vn.itemShelvingSaleSum iss ON iss.saleFk = s.id
- WHERE scsg.sectorCollectionFk = vSelf;
-
+BEGIN
+
+ /**
+ * Devuelve las lineas de venta correspondientes a esa coleccion de sector
+ *
+ * @param vSelf Identificador de vn.sectorCollection
+ */
+
+ SELECT s.ticketFk,
+ s.itemFk,
+ i.longName,
+ IFNULL(i.itemPackingTypeFk,' ') itemPackingTypeFk,
+ IFNULL(i.subName ,' ') subName,
+ s.quantity,
+ w.code workerCode,
+ sgd.saleFk,
+ IFNULL(iss.quantity,0) pickedQuantity,
+ c.salesPersonFk
+ FROM vn.sale s
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
+ JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sgd.saleGroupFk
+ JOIN vn.saleTracking st ON st.saleFk = s.id
+ JOIN vn.state stt ON stt.id = st.stateFk AND stt.code = 'PREVIOUS_PREPARATION'
+ JOIN vn.worker w ON w.id = st.workerFk
+ JOIN vn.ticket t ON t.id= s.ticketFk
+ JOIN vn.client c ON c.id=t.clientFk
+ LEFT JOIN vn.itemShelvingSaleSum iss ON iss.saleFk = s.id
+ WHERE scsg.sectorCollectionFk = vSelf;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -77658,40 +77061,38 @@ DELIMITER ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollection_new`(vSectorFk INT)
-BEGIN
-
- /**
- * Inserta una nueva colección, si el usuario no tiene ninguna vacia.
- * Esto se hace para evitar que por error se generen colecciones sin sentido.
- *
- * @param vSectorFk Identificador de vn.sector
- */
-
- DECLARE hasEmptyCollections BOOLEAN;
- DECLARE vUserFk INT;
-
- SET vUserFk = account.myUser_getId();
-
- SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections
- FROM vn.sectorCollection sc
- LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
- WHERE ISNULL(scsg.id)
- AND sc.userFk = vUserFk
- AND sc.sectorFk = vSectorFk;
-
- IF NOT hasEmptyCollections THEN
-
- INSERT INTO vn.sectorCollection(userFk, sectorFk)
- VALUES(vUserFk, vSectorFk);
- END IF;
-
+BEGIN
+
+/**
+ * Inserta una nueva colección, si el usuario no tiene ninguna vacia.
+ * Esto se hace para evitar que por error se generen colecciones sin sentido.
+ *
+ * @param vSectorFk Identificador de vn.sector
+ */
+ DECLARE hasEmptyCollections BOOL;
+ DECLARE vUserFk INT;
+
+ SET vUserFk = account.myUser_getId();
+
+ SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections
+ FROM vn.sectorCollection sc
+ LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
+ WHERE ISNULL(scsg.id)
+ AND sc.userFk = vUserFk
+ AND sc.sectorFk = vSectorFk
+ AND sc.created >= CURDATE();
+
+ IF NOT hasEmptyCollections THEN
+ INSERT INTO vn.sectorCollection(userFk, sectorFk)
+ VALUES(vUserFk, vSectorFk);
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -78478,88 +77879,88 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `shelving_getSpam`(vDated DATE, vWarehouseFk INT)
-BEGIN
-
- /**
- * Devuelve las matrículas con productos que no son necesarios para la venta hasta la fecha señalada
- *
- * @param vDated Fecha hasta la que se puede pasar sin esos productos.
- * @param vWarehouse Identificador único de vn.warehouse
- */
-
- DROP TEMPORARY TABLE IF EXISTS tmp.stock;
-
- CALL cache.stock_refresh(FALSE);
-
- CREATE TEMPORARY TABLE tmp.stock
- SELECT i.id itemFk,
- v.amount - IFNULL(fue.reserva,0) as visible,
- fue.reserva,
- sale.venta,
- IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra,
- IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) - IFNULL(fue.reserva,0) as saldo
- FROM vn.item i
- JOIN vn.itemType it ON it.id = i.typeFk
- JOIN vn.itemCategory ic ON ic.id = it.categoryFk
- LEFT JOIN (
- SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS reserva
- 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
- WHERE s.code = 'FUENTES_PICASSE'
- OR sh.isSpam
- GROUP BY ish.itemFk
- ) fue ON fue.itemFk = i.id
- LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk
- LEFT JOIN (
- SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta
- FROM vn2008.item_out
- WHERE dat BETWEEN CURDATE() AND util.dayend(vDated)
- AND warehouse_id = vWarehouseFk
- GROUP BY item_id
- ) sale ON sale.item_id = i.id
- LEFT JOIN (
- SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra
- FROM vn2008.item_entry_in
- WHERE dat BETWEEN CURDATE() AND util.dayend(vDated)
- AND warehouse_id = vWarehouseFk
- AND isVirtualStock = FALSE
- GROUP BY item_id
- ) buy ON buy.item_id = i.id
- LEFT JOIN (
- SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado
- FROM vn2008.item_entry_out
- WHERE dat BETWEEN CURDATE() AND util.dayend(vDated)
- AND warehouse_id = vWarehouseFk
- GROUP BY item_id
- ) mov ON mov.item_id = i.id
- WHERE v.amount;
-
- SELECT ish.shelvingFk matricula,
- i.longName articulo,
- ish.visible,
- count(*) lineas,
- sum(ish.visible <= s.saldo) spam,
- p.code parking,
- s.description sector ,
- w.name AS almacen,
- sh.isSpam
- FROM vn.itemShelving ish
- JOIN vn.item i ON i.id = ish.itemFk
- 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
- LEFT JOIN tmp.stock s ON s.itemFk = ish.itemFk
- WHERE (w.name = 'Algemesi'
- OR (w.name = 'NuncaJamas' AND ish.created < curdate()))
- AND ish.visible
- GROUP BY ish.shelvingFk
- HAVING lineas = spam OR isSpam;
-
- DROP TEMPORARY TABLE tmp.stock;
-
+BEGIN
+
+ /**
+ * Devuelve las matrículas con productos que no son necesarios para la venta hasta la fecha señalada
+ *
+ * @param vDated Fecha hasta la que se puede pasar sin esos productos.
+ * @param vWarehouse Identificador único de vn.warehouse
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.stock;
+
+ CALL cache.stock_refresh(FALSE);
+
+ CREATE TEMPORARY TABLE tmp.stock
+ SELECT i.id itemFk,
+ v.amount - IFNULL(fue.reserva,0) as visible,
+ fue.reserva,
+ sale.venta,
+ IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra,
+ IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) - IFNULL(fue.reserva,0) as saldo
+ FROM vn.item i
+ JOIN vn.itemType it ON it.id = i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ LEFT JOIN (
+ SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS reserva
+ 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
+ WHERE s.code = 'FUENTES_PICASSE'
+ OR sh.isSpam
+ GROUP BY ish.itemFk
+ ) fue ON fue.itemFk = i.id
+ LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk
+ LEFT JOIN (
+ SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta
+ FROM vn2008.item_out
+ WHERE dat BETWEEN CURDATE() AND util.dayend(vDated)
+ AND warehouse_id = vWarehouseFk
+ GROUP BY item_id
+ ) sale ON sale.item_id = i.id
+ LEFT JOIN (
+ SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra
+ FROM vn2008.item_entry_in
+ WHERE dat BETWEEN CURDATE() AND util.dayend(vDated)
+ AND warehouse_id = vWarehouseFk
+ AND isVirtualStock = FALSE
+ GROUP BY item_id
+ ) buy ON buy.item_id = i.id
+ LEFT JOIN (
+ SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado
+ FROM vn2008.item_entry_out
+ WHERE dat BETWEEN CURDATE() AND util.dayend(vDated)
+ AND warehouse_id = vWarehouseFk
+ GROUP BY item_id
+ ) mov ON mov.item_id = i.id
+ WHERE v.amount;
+
+ SELECT ish.shelvingFk matricula,
+ i.longName articulo,
+ ish.visible,
+ count(*) lineas,
+ sum(ish.visible <= s.saldo) spam,
+ p.code parking,
+ s.description sector ,
+ w.name AS almacen,
+ sh.isSpam
+ FROM vn.itemShelving ish
+ JOIN vn.item i ON i.id = ish.itemFk
+ 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
+ LEFT JOIN tmp.stock s ON s.itemFk = ish.itemFk
+ WHERE (w.name = 'Algemesi'
+ OR (w.name = 'NuncaJamas' AND ish.created < curdate()))
+ AND ish.visible
+ GROUP BY ish.shelvingFk
+ HAVING lineas = spam OR isSpam;
+
+ DROP TEMPORARY TABLE tmp.stock;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -78764,105 +78165,6 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `stockBuyed` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `stockBuyed`(vDate DATE)
-BEGIN
- DECLARE vVolume DECIMAL(10,2);
- DECLARE vWarehouse INT DEFAULT 7;
- DECLARE vRuben INT;
- DECLARE vClaudi INT;
- DECLARE vJose INT;
-
- SELECT w.id INTO vRuben
- FROM vn.worker w
- WHERE w.code = 'RET';
-
- SELECT w.id INTO vClaudi
- FROM vn.worker w
- WHERE w.code = 'CSR';
-
- SELECT w.id INTO vJose
- FROM vn.worker w
- WHERE w.code = 'ATJ';
-
- CALL stockTraslation(vDate);
-
- -- SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1;
-
- INSERT INTO stockBuyed(user, buyed, `date`)
- SELECT tr.user_id, SUM(( amount / c.packing ) * vn.buy_getVolume(Id_Compra)) / vc.palletM3 / 1000000 buyed, vDate
- FROM tmp_item i
- JOIN vn2008.Articles a ON a.Id_Article = i.item_id
- JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id
- JOIN vn2008.reinos r ON r.id = t.reino_id
- JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador
- JOIN tmp.buyUltimate bu ON bu.itemFk = Id_Article AND bu.warehouseFk = vWarehouse
- JOIN vn2008.Compres c ON c.Id_compra = bu.buyFk
- JOIN vn.volumeConfig vc
- WHERE r.display <> 0
- GROUP BY tr.Id_Trabajador
- ON DUPLICATE KEY UPDATE buyed = VALUES(buyed);
-
- INSERT INTO stockBuyed(USER, buyed, `date`)
- SELECT vRuben, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate
- FROM vn2008.item_out io
- JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse
- JOIN vn.ticket t ON t.id = io.ticketFk
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p ON p.id = a.provinceFk
- JOIN vn.country c ON c.id = p.countryFk
- JOIN vn.volumeConfig vc
- WHERE dat = vDate
- AND warehouse_id = vWarehouse
- AND c.country = 'Francia'
- ON DUPLICATE KEY UPDATE buyed = buyed + @amount;
-
- INSERT INTO stockBuyed(USER, buyed, `date`)
- SELECT vJose, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate
- FROM vn2008.item_out io
- JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse
- JOIN vn.ticket t ON t.id = io.ticketFk
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p ON p.id = a.provinceFk
- JOIN vn.country c ON c.id = p.countryFk
- JOIN vn.volumeConfig vc
- WHERE dat = vDate
- AND warehouse_id = vWarehouse
- AND c.country = 'Holanda'
- ON DUPLICATE KEY UPDATE buyed = buyed + @amount;
-
- INSERT INTO stockBuyed(USER, buyed, `date`)
- SELECT vClaudi, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate
- FROM vn2008.item_out io
- JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse
- JOIN vn.ticket t ON t.id = io.ticketFk
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p ON p.id = a.provinceFk
- JOIN vn.country c ON c.id = p.countryFk
- JOIN vn.volumeConfig vc
- WHERE dat BETWEEN vDate AND util.dayend(vDate)
- AND warehouse_id = vWarehouse
- AND c.country NOT IN ('Francia','Holanda')
- ON DUPLICATE KEY UPDATE buyed = buyed + @amount;
-
- DROP TEMPORARY TABLE
- tmp.buyUltimate,
- tmp_item;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `stockBuyedByWorker` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -78936,6 +78238,69 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `stockBuyed_add` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `stockBuyed_add`(vDated DATE)
+BEGIN
+/**
+ * Inserta el volumen de compra por comprador en vn.stockBuyed de acuerdo con la fecha
+ *
+ * @param vDated Fecha de compra
+ */
+ CALL vn.stockTraslation(vDated);
+
+ DELETE
+ FROM vn.stockBuyed
+ WHERE `date` = vDated;
+
+ INSERT INTO vn.stockBuyed(`user`, buyed, `date`, description)
+ SELECT it.workerFk,
+ SUM(( ti.amount / b.packing ) * vn.buy_getVolume(b.id)) / vc.palletM3 / 1000000 buyed,
+ vDated,
+ u.name
+ FROM tmp_item ti
+ JOIN vn.item i ON i.id = ti.item_id
+ JOIN vn.itemType it ON it.id = i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ JOIN vn.warehouse wh ON wh.code = 'VNH'
+ JOIN tmp.buyUltimate bu ON bu.itemFk = i.id AND bu.warehouseFk = wh.id
+ JOIN vn.buy b ON b.id = bu.buyFk
+ JOIN vn.volumeConfig vc
+ JOIN account.`user` u ON u.id = it.workerFk
+ WHERE ic.display != 0
+ GROUP BY it.workerFk;
+
+ INSERT INTO stockBuyed(buyed, `date`, description)
+ SELECT SUM(ic.cm3 * ito.quantity / vc.palletM3 / 1000000), vDated, IF(c.country = 'España',p.name,c.country) destiny
+ FROM vn.itemTicketOut ito
+ JOIN vn.ticket t ON t.id = ito.ticketFk
+ JOIN vn.address a ON a.id = t.addressFk
+ JOIN vn.province p ON p.id = a.provinceFk
+ JOIN vn.country c ON c.id = p.countryFk
+ JOIN vn.warehouse wh ON wh.id = t.warehouseFk
+ JOIN vn.itemCost ic ON ic.itemFk = ito.itemFk AND ic.warehouseFk = t.warehouseFk
+ JOIN vn.volumeConfig vc
+ WHERE ito.shipped BETWEEN vDated AND util.dayend(vDated)
+ AND wh.code = 'VNH'
+ GROUP BY destiny;
+
+ DROP TEMPORARY TABLE
+ tmp.buyUltimate,
+ tmp_item;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `stockTraslation` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -80475,19 +79840,19 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCollection_setUsedShelves`(vTicketFk INT, vUsedShelves INT)
-BEGIN
-
- /*
- * Inserta número de baldas que ocupa un ticket
- *
- * @param vTicketFk Identificador de ticket
- * @param vUsedShelves Número de baldas
- */
-
- UPDATE ticketCollection tc
- SET tc.usedShelves = vUsedShelves
- WHERE tc.ticketFk = vTicketFk;
-
+BEGIN
+
+ /*
+ * Inserta número de baldas que ocupa un ticket
+ *
+ * @param vTicketFk Identificador de ticket
+ * @param vUsedShelves Número de baldas
+ */
+
+ UPDATE ticketCollection tc
+ SET tc.usedShelves = vUsedShelves
+ WHERE tc.ticketFk = vTicketFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -80801,11 +80166,11 @@ DELIMITER ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCreateWithUser`(
vClientId INT
@@ -80819,191 +80184,19 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCreateWithUser`(
,vUserId INT
,OUT vNewTicket INT)
BEGIN
--- si se modifica algo avisad a jgallego
- DECLARE vZoneFk INT;
- DECLARE vPrice DECIMAL(10,2);
- DECLARE vBonus DECIMAL(10,2);
-
- IF vClientId IS NULL THEN
- CALL util.throw ('CLIENT_NOT_ESPECIFIED');
- END IF;
-
- IF NOT vAddressFk OR vAddressFk IS NULL THEN
- SELECT id INTO vAddressFk
- FROM address
- WHERE clientFk = vClientId AND isDefaultAddress;
- END IF;
-
- IF vAgencyModeFk IS NOT NULL THEN
-
- CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE);
-
- SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus
- FROM tmp.zoneGetShipped
- WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1;
-
- IF vZoneFk IS NULL OR vZoneFk = 0 THEN
- CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS');
- END IF;
- END IF;
- INSERT INTO ticket (
- clientFk,
- shipped,
- addressFk,
- agencyModeFk,
- nickname,
- warehouseFk,
- routeFk,
- companyFk,
- landed,
- zoneFk,
- zonePrice,
- zoneBonus
- )
- SELECT
- vClientId,
- vShipped,
- a.id,
- vAgencyModeFk,
- a.nickname,
- vWarehouseFk,
- IF(vRouteFk,vRouteFk,NULL),
- vCompanyFk,
- vlanded,
- vZoneFk,
- vPrice,
- vBonus
- FROM address a
- JOIN agencyMode am ON am.id = a.agencyModeFk
- WHERE a.id = vAddressFk;
-
- SET vNewTicket = LAST_INSERT_ID();
-
- INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
- SELECT vNewTicket, ao.observationTypeFk, ao.description
- FROM addressObservation ao
- JOIN address a ON a.id = ao.addressFk
- WHERE a.id = vAddressFk;
-
- IF (SELECT COUNT(*) FROM bs.clientNewBorn cnb
- WHERE cnb.clientFk = vClientId
- AND NOT cnb.isRookie) = 0 THEN
-
- CALL vn.ticketObservation_addNewBorn(vNewTicket);
- END IF;
-
- INSERT INTO vn.ticketLog
- SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket);
-
- IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN
- INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
- SELECT id, vNewTicket, account.myUser_getId()
- FROM state
- WHERE `code` = 'DELIVERED';
- END IF;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `ticketCreateWithUser__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCreateWithUser__`(
- vClientId INT
- ,vShipped DATE
- ,vWarehouseFk INT
- ,vCompanyFk INT
- ,vAddressFk INT
- ,vAgencyModeFk INT
- ,vRouteFk INT
- ,vlanded DATE
- ,vUserId INT
- ,OUT vNewTicket INT)
-BEGIN
-
- DECLARE vZoneFk INT;
- DECLARE vPrice DECIMAL(10,2);
- DECLARE vBonus DECIMAL(10,2);
-
- IF vClientId IS NULL THEN
- CALL util.throw ('CLIENT_NOT_ESPECIFIED');
- END IF;
-
- IF NOT vAddressFk OR vAddressFk IS NULL THEN
- SELECT id INTO vAddressFk
- FROM address
- WHERE clientFk = vClientId AND isDefaultAddress;
- END IF;
-
- IF vAgencyModeFk IS NOT NULL THEN
-
- CALL vn.zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk);
-
- SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus
- FROM tmp.zoneGetShipped
- WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1;
-
- IF vZoneFk IS NULL OR vZoneFk = 0 THEN
- CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS');
- END IF;
- END IF;
- INSERT INTO ticket (
- clientFk,
- shipped,
- addressFk,
- agencyModeFk,
- nickname,
- warehouseFk,
- routeFk,
- companyFk,
- landed,
- zoneFk,
- zonePrice,
- zoneBonus
- )
- SELECT
- vClientId,
- vShipped,
- a.id,
- vAgencyModeFk,
- a.nickname,
- vWarehouseFk,
- IF(vRouteFk,vRouteFk,NULL),
- vCompanyFk,
- vlanded,
- vZoneFk,
- vPrice,
- vBonus
- FROM address a
- JOIN agencyMode am ON am.id = a.agencyModeFk
- WHERE a.id = vAddressFk;
-
- SET vNewTicket = LAST_INSERT_ID();
-
- INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
- SELECT vNewTicket, ao.observationTypeFk, ao.description
- FROM addressObservation ao
- JOIN address a ON a.id = ao.addressFk
- WHERE a.id = vAddressFk;
-
- INSERT INTO vn.ticketLog
- SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket);
-
- IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN
- INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
- SELECT id, vNewTicket, getWorker()
- FROM state
- WHERE `code` = 'DELIVERED';
- END IF;
+ CALL ticket_add(
+ vClientId,
+ vShipped,
+ vWarehouseFk,
+ vCompanyFk,
+ vAddressFk,
+ vAgencyModeFk,
+ vRouteFk,
+ vlanded,
+ vUserId,
+ TRUE,
+ vNewTicket
+ );
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -81639,25 +80832,25 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketManaToPromo`(vTicketFk INT)
-BEGIN
-
- DECLARE vManaComponent INT;
-
- DECLARE vPromoComponent INT;
-
- SELECT id INTO vManaComponent
- FROM vn.component c
- WHERE c.code = 'mana';
-
- SELECT id INTO vPromoComponent
- FROM vn.component c
- WHERE c.code = 'floramondoPromo';
-
- UPDATE vn.saleComponent sc
- JOIN vn.sale s ON s.id = sc.saleFk
- SET componentFk = vPromoComponent
- WHERE componentFk = vManaComponent
- AND s.ticketFk = vTicketFk;
+BEGIN
+
+ DECLARE vManaComponent INT;
+
+ DECLARE vPromoComponent INT;
+
+ SELECT id INTO vManaComponent
+ FROM vn.component c
+ WHERE c.code = 'mana';
+
+ SELECT id INTO vPromoComponent
+ FROM vn.component c
+ WHERE c.code = 'floramondoPromo';
+
+ UPDATE vn.saleComponent sc
+ JOIN vn.sale s ON s.id = sc.saleFk
+ SET componentFk = vPromoComponent
+ WHERE componentFk = vManaComponent
+ AND s.ticketFk = vTicketFk;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -81780,22 +80973,22 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketObservation_addNewBorn`(vTicketFk INT)
-BEGIN
-
- /**
- * Inserta observaciones para los tickets con clientes nuevos o recuperados
- *
- * @param vTicketFk Identificador de vn.ticket
- */
-
- DECLARE vDescription VARCHAR(20) DEFAULT '¡Cliente NUEVO! ';
-
+BEGIN
+
+ /**
+ * Inserta observaciones para los tickets con clientes nuevos o recuperados
+ *
+ * @param vTicketFk Identificador de vn.ticket
+ */
+
+ DECLARE vDescription VARCHAR(20) DEFAULT '¡Cliente NUEVO! ';
+
INSERT INTO vn.ticketObservation(ticketFk, observationTypeFk, description)
SELECT vTicketFk, ot.id, vDescription
FROM vn.observationType ot
WHERE ot.hasNewBornMessage
ON DUPLICATE KEY UPDATE description = CONCAT(vDescription, ticketObservation.description);
-
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -81806,11 +80999,11 @@ DELIMITER ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketPackagingRecovery__`()
BEGIN
@@ -81841,8 +81034,17 @@ BEGIN
WHILE NOT done DO
- CALL vn.ticketCreate(vClientFk,vShipped,vWarehouseFk,vCompanyFk, NULL, NULL, NULL,
- vShipped,vTicketNewFk);
+ CALL vn.ticket_add(vClientFk,
+ vShipped,
+ vWarehouseFk,
+ vCompanyFk,
+ NULL,
+ NULL,
+ NULL,
+ vShipped,
+ account.userGetId(),
+ TRUE,
+ vTicketNewFk);
UPDATE vn.ticketPackaging set ticketFk = vTicketNewFk WHERE ticketFk = vTicketFk;
@@ -81873,66 +81075,66 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketParking_findSkipped`(vTicketFk INT, vItemPackingTypeFk VARCHAR(1))
-BEGIN
-
-/**
- * Averigua los tickets que se han saltado por un error en el proceso encajado
- * @param vTicketFk Ticket
- * @param vItemPackingTypeFk Modo de encajado
- * @return un select con los tickets afectados
- */
-
- DECLARE vParkingFk INT;
- DECLARE vParked DATETIME;
- DECLARE vLevel INT;
- DECLARE vWagon INT;
- DECLARE vCollectionFk INT;
-
- SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0)
- INTO vLevel, vWagon, vCollectionFk
- FROM vn.ticketCollection tc
- JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk
- WHERE ticketFk = vTicketFk
- ORDER BY c.id DESC
- LIMIT 1;
-
- SELECT created, parkingFk
- INTO vParked, vParkingFk
- FROM vn.ticketParking tp
- JOIN vn.parking p ON p.id = tp.parkingFk
- JOIN vn.sector s ON s.id = p.sectorFk
- WHERE ticketFk = vTicketFk
- AND s.itemPackingTypeFk = vItemPackingTypeFk
- AND s.isPackagingArea ;
-
- SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia
- FROM vn.ticketParking tp
- JOIN vn.parking p ON p.id = tp.parkingFk
- JOIN vn.sector sc ON sc.id = p.sectorFk
- LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk
- JOIN vn.ticketStateToday tst ON tst.ticket = tp.ticketFk
- JOIN vn.ticket t ON t.id = tp.ticketFk
- JOIN vn.zone z ON z.id = t.zoneFk
- JOIN vn.agencyMode am ON am.id = z.agencyModeFk
- JOIN vn.state s ON s.id = tst.state
- WHERE (s.alertLevel < 2
- AND tp.parkingFk = vParkingFk
- AND sc.isPackagingArea
- AND (
- ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked )
- OR
- ( tc.collectionFk = vCollectionFk
- AND (LEFT(tc.wagon,1) < LEFT(vWagon,1)
- OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1)))
- )
- )
- ) -- Etiquetas que no se han escaneado y ya estamos con una posterior
- OR
- (s.alertLevel > 1
- AND tp.parkingFk = vParkingFk
- AND sc.isPackagingArea
- AND tp.created < vParked
- AND t.packages <=> 0);
+BEGIN
+
+/**
+ * Averigua los tickets que se han saltado por un error en el proceso encajado
+ * @param vTicketFk Ticket
+ * @param vItemPackingTypeFk Modo de encajado
+ * @return un select con los tickets afectados
+ */
+
+ DECLARE vParkingFk INT;
+ DECLARE vParked DATETIME;
+ DECLARE vLevel INT;
+ DECLARE vWagon INT;
+ DECLARE vCollectionFk INT;
+
+ SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0)
+ INTO vLevel, vWagon, vCollectionFk
+ FROM vn.ticketCollection tc
+ JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk
+ WHERE ticketFk = vTicketFk
+ ORDER BY c.id DESC
+ LIMIT 1;
+
+ SELECT created, parkingFk
+ INTO vParked, vParkingFk
+ FROM vn.ticketParking tp
+ JOIN vn.parking p ON p.id = tp.parkingFk
+ JOIN vn.sector s ON s.id = p.sectorFk
+ WHERE ticketFk = vTicketFk
+ AND s.itemPackingTypeFk = vItemPackingTypeFk
+ AND s.isPackagingArea ;
+
+ SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia
+ FROM vn.ticketParking tp
+ JOIN vn.parking p ON p.id = tp.parkingFk
+ JOIN vn.sector sc ON sc.id = p.sectorFk
+ LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk
+ JOIN vn.ticketStateToday tst ON tst.ticket = tp.ticketFk
+ JOIN vn.ticket t ON t.id = tp.ticketFk
+ JOIN vn.zone z ON z.id = t.zoneFk
+ JOIN vn.agencyMode am ON am.id = z.agencyModeFk
+ JOIN vn.state s ON s.id = tst.state
+ WHERE (s.alertLevel < 2
+ AND tp.parkingFk = vParkingFk
+ AND sc.isPackagingArea
+ AND (
+ ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked )
+ OR
+ ( tc.collectionFk = vCollectionFk
+ AND (LEFT(tc.wagon,1) < LEFT(vWagon,1)
+ OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1)))
+ )
+ )
+ ) -- Etiquetas que no se han escaneado y ya estamos con una posterior
+ OR
+ (s.alertLevel > 1
+ AND tp.parkingFk = vParkingFk
+ AND sc.isPackagingArea
+ AND tp.created < vParked
+ AND t.packages <=> 0);
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82077,25 +81279,25 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setOnchecking__`(vParamFk INT)
-BEGIN
- /*
- * @deprecated:utilizar ticketStateToday_setState
- */
-
- DECLARE vAlertLevel INT;
-
- SELECT s.alertLevel INTO vAlertLevel
- FROM vn.state s
- JOIN vn.ticketStateToday tst ON tst.state = s.id
- WHERE tst.ticket = vParamFk
- LIMIT 1;
-
- IF vAlertLevel < 2 THEN
-
- CALL vn.ticketStateUpdate(vParamFk, 'ON_CHECKING');
-
- END IF;
-
+BEGIN
+ /*
+ * @deprecated:utilizar ticketStateToday_setState
+ */
+
+ DECLARE vAlertLevel INT;
+
+ SELECT s.alertLevel INTO vAlertLevel
+ FROM vn.state s
+ JOIN vn.ticketStateToday tst ON tst.state = s.id
+ WHERE tst.ticket = vParamFk
+ LIMIT 1;
+
+ IF vAlertLevel < 2 THEN
+
+ CALL vn.ticketStateUpdate(vParamFk, 'ON_CHECKING');
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82113,33 +81315,33 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setOnPreviousChecking__`(vParamFk INT)
-BEGIN
-
- /*
- * @deprecated:utilizar ticketStateToday_setState
- */
-
-
- /*
- * Cambia el estado del ticket al estado de "control previa"
- *
- * @param vParamFk ticket a cambiar el estado
- *
- */
- DECLARE vAlertLevel INT;
-
- SELECT s.alertLevel INTO vAlertLevel
- FROM state s
- JOIN ticketStateToday tst ON tst.state = s.id
- WHERE tst.ticket = vParamFk
- LIMIT 1;
-
- IF vAlertLevel < 2 THEN
-
- CALL ticketStateUpdate(vParamFk, 'PREVIOUS_CONTROL');
-
- END IF;
-
+BEGIN
+
+ /*
+ * @deprecated:utilizar ticketStateToday_setState
+ */
+
+
+ /*
+ * Cambia el estado del ticket al estado de "control previa"
+ *
+ * @param vParamFk ticket a cambiar el estado
+ *
+ */
+ DECLARE vAlertLevel INT;
+
+ SELECT s.alertLevel INTO vAlertLevel
+ FROM state s
+ JOIN ticketStateToday tst ON tst.state = s.id
+ WHERE tst.ticket = vParamFk
+ LIMIT 1;
+
+ IF vAlertLevel < 2 THEN
+
+ CALL ticketStateUpdate(vParamFk, 'PREVIOUS_CONTROL');
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82157,29 +81359,29 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setState`(vTicketFk INT, vStateCode VARCHAR(45))
-BEGIN
-
- /* Modifica el estado de un ticket de hoy
- *
- * @param vTicketFk el id del ticket
- * @param vStateCode estado a modificar del ticket
- *
- */
-
- DECLARE vAlertLevel INT;
-
- SELECT s.alertLevel INTO vAlertLevel
- FROM state s
- JOIN ticketStateToday tst ON tst.state = s.id
- WHERE tst.ticket = vTicketFk
- LIMIT 1;
-
- IF vAlertLevel < 2 THEN
-
- CALL vn.ticket_setState(vTicketFk, vStateCode);
-
- END IF;
-
+BEGIN
+
+ /* Modifica el estado de un ticket de hoy
+ *
+ * @param vTicketFk el id del ticket
+ * @param vStateCode estado a modificar del ticket
+ *
+ */
+
+ DECLARE vAlertLevel INT;
+
+ SELECT s.alertLevel INTO vAlertLevel
+ FROM state s
+ JOIN ticketStateToday tst ON tst.state = s.id
+ WHERE tst.ticket = vTicketFk
+ LIMIT 1;
+
+ IF vAlertLevel < 2 THEN
+
+ CALL vn.ticket_setState(vTicketFk, vStateCode);
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82368,63 +81570,63 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketToPrePrepare`(IN vSaleGroupFk INT, IN vSectorFk INT)
-BEGIN
-
-/* Devuelve las lineas de vn.sale para preparación previa según el saleGroup
- *
- *
- * @param vSaleGroupFk Identificador de vn.saleGroup
-*/
- DECLARE vIsResetCode BOOLEAN;
-
- SELECT (vSaleGroupFk = 2000000) INTO vIsResetCode;
-
- IF vIsResetCode THEN
-
- UPDATE vn.saleTracking st
- JOIN vn.state s ON s.code = 'OK PREVIOUS'
- JOIN vn.state s2 ON s2.id = st.stateFk
- SET st.stateFk = s.id
- WHERE workerFk = vn.getUser()
- AND s2.code = 'PREVIOUS_PREPARATION';
-
- ELSE
-
- UPDATE vn.saleTracking st
- JOIN vn.saleGroupDetail sgd ON sgd.saleFk = st.saleFk
- SET workerFk = vn.getUser()
- WHERE sgd.saleGroupFk = vSaleGroupFk;
-
- UPDATE vn.saleGroup sg
- SET sg.userFk = vn.getUser()
- WHERE sg.id = vSaleGroupFk;
-
- SELECT s.ticketFk,
- s.itemFk,
- i.longName,
- IFNULL(i.itemPackingTypeFk,' ') itemPackingTypeFk,
- IFNULL(i.subName ,' ') subName,
- s.quantity originalQuantity ,
- s.quantity,
- w.code workerCode,
- sgd.saleFk,
- IFNULL(iss.quantity,0) pickedQuantity,
- vSectorFk,
- c.salesPersonFk
- FROM vn.sale s
- JOIN vn.item i ON i.id = s.itemFk
- JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
- JOIN vn.saleTracking st ON st.saleFk = s.id
- JOIN vn.state stt ON stt.id = st.stateFk
- JOIN vn.worker w ON w.id = st.workerFk
- LEFT JOIN vn.itemShelvingSaleSum iss ON iss.saleFk = s.id
- JOIN vn.ticket t ON t.id= s.ticketFk
- JOIN vn.client c ON c.id=t.clientFk
- WHERE st.workerFk = account.myUser_getId()
- AND stt.code = 'PREVIOUS_PREPARATION';
-
- END IF;
-
+BEGIN
+
+/* Devuelve las lineas de vn.sale para preparación previa según el saleGroup
+ *
+ *
+ * @param vSaleGroupFk Identificador de vn.saleGroup
+*/
+ DECLARE vIsResetCode BOOLEAN;
+
+ SELECT (vSaleGroupFk = 2000000) INTO vIsResetCode;
+
+ IF vIsResetCode THEN
+
+ UPDATE vn.saleTracking st
+ JOIN vn.state s ON s.code = 'OK PREVIOUS'
+ JOIN vn.state s2 ON s2.id = st.stateFk
+ SET st.stateFk = s.id
+ WHERE workerFk = vn.getUser()
+ AND s2.code = 'PREVIOUS_PREPARATION';
+
+ ELSE
+
+ UPDATE vn.saleTracking st
+ JOIN vn.saleGroupDetail sgd ON sgd.saleFk = st.saleFk
+ SET workerFk = vn.getUser()
+ WHERE sgd.saleGroupFk = vSaleGroupFk;
+
+ UPDATE vn.saleGroup sg
+ SET sg.userFk = vn.getUser()
+ WHERE sg.id = vSaleGroupFk;
+
+ SELECT s.ticketFk,
+ s.itemFk,
+ i.longName,
+ IFNULL(i.itemPackingTypeFk,' ') itemPackingTypeFk,
+ IFNULL(i.subName ,' ') subName,
+ s.quantity originalQuantity ,
+ s.quantity,
+ w.code workerCode,
+ sgd.saleFk,
+ IFNULL(iss.quantity,0) pickedQuantity,
+ vSectorFk,
+ c.salesPersonFk
+ FROM vn.sale s
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
+ JOIN vn.saleTracking st ON st.saleFk = s.id
+ JOIN vn.state stt ON stt.id = st.stateFk
+ JOIN vn.worker w ON w.id = st.workerFk
+ LEFT JOIN vn.itemShelvingSaleSum iss ON iss.saleFk = s.id
+ JOIN vn.ticket t ON t.id= s.ticketFk
+ JOIN vn.client c ON c.id=t.clientFk
+ WHERE st.workerFk = account.myUser_getId()
+ AND stt.code = 'PREVIOUS_PREPARATION';
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82671,102 +81873,102 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_add`(
- vClientId INT
- ,vShipped DATE
- ,vWarehouseFk INT
- ,vCompanyFk INT
- ,vAddressFk INT
- ,vAgencyModeFk INT
- ,vRouteFk INT
- ,vlanded DATE
- ,vUserId INT
- ,vIsRequiredZone INT
+CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_add`(
+ vClientId INT
+ ,vShipped DATE
+ ,vWarehouseFk INT
+ ,vCompanyFk INT
+ ,vAddressFk INT
+ ,vAgencyModeFk INT
+ ,vRouteFk INT
+ ,vlanded DATE
+ ,vUserId INT
+ ,vIsRequiredZone INT
,OUT vNewTicket INT)
-BEGIN
-
- DECLARE vZoneFk INT;
- DECLARE vPrice DECIMAL(10,2);
- DECLARE vBonus DECIMAL(10,2);
-
- IF vClientId IS NULL THEN
- CALL util.throw ('CLIENT_NOT_ESPECIFIED');
- END IF;
-
- IF NOT vAddressFk OR vAddressFk IS NULL THEN
- SELECT id INTO vAddressFk
- FROM address
- WHERE clientFk = vClientId AND isDefaultAddress;
- END IF;
-
- IF vAgencyModeFk IS NOT NULL THEN
-
- CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE);
-
- SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus
- FROM tmp.zoneGetShipped
- WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1;
-
- IF (vZoneFk IS NULL OR vZoneFk = 0) AND vIsRequiredZone THEN
- CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS');
- END IF;
- END IF;
- INSERT INTO ticket (
- clientFk,
- shipped,
- addressFk,
- agencyModeFk,
- nickname,
- warehouseFk,
- routeFk,
- companyFk,
- landed,
- zoneFk,
- zonePrice,
- zoneBonus
- )
- SELECT
- vClientId,
- vShipped,
- a.id,
- vAgencyModeFk,
- a.nickname,
- vWarehouseFk,
- IF(vRouteFk,vRouteFk,NULL),
- vCompanyFk,
- vlanded,
- vZoneFk,
- vPrice,
- vBonus
- FROM address a
- JOIN agencyMode am ON am.id = a.agencyModeFk
- WHERE a.id = vAddressFk;
-
- SET vNewTicket = LAST_INSERT_ID();
-
- INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
- SELECT vNewTicket, ao.observationTypeFk, ao.description
- FROM addressObservation ao
- JOIN address a ON a.id = ao.addressFk
- WHERE a.id = vAddressFk;
-
- IF (SELECT COUNT(*) FROM bs.clientNewBorn cnb
- WHERE cnb.clientFk = vClientId
- AND NOT cnb.isRookie) = 0 THEN
-
- CALL vn.ticketObservation_addNewBorn(vNewTicket);
-
- END IF;
-
- INSERT INTO vn.ticketLog
- SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket);
-
- IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN
- INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
- SELECT id, vNewTicket, account.myUser_getId()
- FROM state
- WHERE `code` = 'DELIVERED';
- END IF;
+BEGIN
+
+ DECLARE vZoneFk INT;
+ DECLARE vPrice DECIMAL(10,2);
+ DECLARE vBonus DECIMAL(10,2);
+
+ IF vClientId IS NULL THEN
+ CALL util.throw ('CLIENT_NOT_ESPECIFIED');
+ END IF;
+
+ IF NOT vAddressFk OR vAddressFk IS NULL THEN
+ SELECT id INTO vAddressFk
+ FROM address
+ WHERE clientFk = vClientId AND isDefaultAddress;
+ END IF;
+
+ IF vAgencyModeFk IS NOT NULL THEN
+
+ CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE);
+
+ SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus
+ FROM tmp.zoneGetShipped
+ WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1;
+
+ IF (vZoneFk IS NULL OR vZoneFk = 0) AND vIsRequiredZone THEN
+ CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS');
+ END IF;
+ END IF;
+ INSERT INTO ticket (
+ clientFk,
+ shipped,
+ addressFk,
+ agencyModeFk,
+ nickname,
+ warehouseFk,
+ routeFk,
+ companyFk,
+ landed,
+ zoneFk,
+ zonePrice,
+ zoneBonus
+ )
+ SELECT
+ vClientId,
+ vShipped,
+ a.id,
+ vAgencyModeFk,
+ a.nickname,
+ vWarehouseFk,
+ IF(vRouteFk,vRouteFk,NULL),
+ vCompanyFk,
+ vlanded,
+ vZoneFk,
+ vPrice,
+ vBonus
+ FROM address a
+ JOIN agencyMode am ON am.id = a.agencyModeFk
+ WHERE a.id = vAddressFk;
+
+ SET vNewTicket = LAST_INSERT_ID();
+
+ INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
+ SELECT vNewTicket, ao.observationTypeFk, ao.description
+ FROM addressObservation ao
+ JOIN address a ON a.id = ao.addressFk
+ WHERE a.id = vAddressFk;
+
+ IF (SELECT COUNT(*) FROM bs.clientNewBorn cnb
+ WHERE cnb.clientFk = vClientId
+ AND NOT cnb.isRookie) = 0 THEN
+
+ CALL vn.ticketObservation_addNewBorn(vNewTicket);
+
+ END IF;
+
+ INSERT INTO vn.ticketLog
+ SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket);
+
+ IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN
+ INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
+ SELECT id, vNewTicket, account.myUser_getId()
+ FROM state
+ WHERE `code` = 'DELIVERED';
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82784,21 +81986,114 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_administrativeCopy`(vOriginalTicket INT, OUT vNewTicket INT)
-BEGIN
-
- INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed)
- SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed
- FROM vn.ticket t
- JOIN vn.warehouse w ON w.name = 'INVENTARIO'
- WHERE t.id = vOriginalTicket;
-
- SELECT LAST_INSERT_ID() INTO vNewTicket;
-
- INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount)
- SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount
- FROM vn.sale s
- WHERE s.ticketFk = vOriginalTicket;
-
+BEGIN
+
+ INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed)
+ SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed
+ FROM vn.ticket t
+ JOIN vn.warehouse w ON w.name = 'INVENTARIO'
+ WHERE t.id = vOriginalTicket;
+
+ SELECT LAST_INSERT_ID() INTO vNewTicket;
+
+ INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount)
+ SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount
+ FROM vn.sale s
+ WHERE s.ticketFk = vOriginalTicket;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `ticket_canAdvance` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_canAdvance`(vDated DATE, vWarehouseFk INT)
+BEGIN
+/**
+ * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar.
+ *
+ * @param vDated Fecha de los tickets que se quieren adelantar.
+ * @param vWarehouseFk Almacén
+ */
+ DECLARE vDateInventory DATE;
+ DECLARE vDateToAdvance DATE;
+
+ SELECT inventoried INTO vDateInventory FROM vn.config;
+
+ SET vDateToAdvance = TIMESTAMPADD(DAY,-1,vDated);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.stock;
+ CREATE TEMPORARY TABLE tmp.stock
+ (itemFk INT PRIMARY KEY,
+ amount INT)
+ ENGINE = MEMORY;
+
+ INSERT INTO tmp.stock(itemFk, amount)
+ SELECT itemFk, SUM(quantity) amount FROM
+ (
+ SELECT itemFk, quantity
+ FROM vn.itemTicketOut
+ WHERE shipped >= vDateInventory
+ AND shipped < vDated
+ AND warehouseFk = vWarehouseFk
+ UNION ALL
+ SELECT itemFk, quantity
+ FROM vn.itemEntryIn
+ WHERE landed >= vDateInventory
+ AND landed < vDated
+ AND isVirtualStock = FALSE
+ AND warehouseInFk = vWarehouseFk
+ UNION ALL
+ SELECT itemFk, quantity
+ FROM vn.itemEntryOut
+ WHERE shipped >= vDateInventory
+ AND shipped < vDated
+ AND warehouseOutFk = vWarehouseFk
+ ) t
+ GROUP BY itemFk HAVING amount != 0;
+
+ SELECT s.ticketFk ticketFuture,
+ sum((s.quantity <= IFNULL(st.amount,0))) hasStock,
+ count(DISTINCT s.id) saleCount,
+ st.name tfState,
+ GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) tfIpt,
+ t2.ticketFk,
+ t2.state,
+ t2.ipt
+ FROM vn.ticket t
+ JOIN vn.ticketState ts ON ts.ticketFk = t.id
+ JOIN vn.state st ON st.id = ts.stateFk
+ LEFT JOIN (SELECT
+ t2.id ticketFk,
+ t2.addressFk,
+ st.name state,
+ GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt
+ FROM vn.ticket t2
+ JOIN vn.sale s ON s.ticketFk = t2.id
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.ticketState ts ON ts.ticketFk = t2.id
+ JOIN vn.state st ON st.id = ts.stateFk
+ WHERE t2.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance)
+ AND t2.warehouseFk = vWarehouseFk
+ GROUP BY t2.id) t2 ON t2.addressFk = t.addressFk
+ JOIN vn.sale s ON s.ticketFk = t.id
+ JOIN vn.item i ON i.id = s.itemFk
+ LEFT JOIN tmp.stock st ON st.itemFk = s.itemFk
+ WHERE t.shipped BETWEEN vDated AND util.dayend(vDated)
+ AND t.warehouseFk = vWarehouseFk
+ GROUP BY t.id;
+
+ DROP TEMPORARY TABLE tmp.stock;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82816,46 +82111,62 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_canMerge`(vDated DATE, vScopeDays INT, vLitersMax INT, vLinesMax INT, vWarehouseFk INT)
-BEGIN
-
- /* Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro
- *
- * @param vDated Fecha en cuestión
- * @param vScopeDays Dias en el futuro a sondear
- * @param vLitersMax Volumen máximo de los tickets a catapultar
- * @param vLinesMax Número máximo de lineas de los tickets a catapultar
- * @param vWarehouseFk Identificador de vn.warehouse
- */
-
- SELECT sv.ticketFk ,
- CAST(sum(litros) AS DECIMAL(10,0)) liters,
- CAST(count(*) AS DECIMAL(10,0)) `lines`,
- sub2.id ticketFuture,
- sub2.shipped
- FROM vn.saleVolume sv
- JOIN vn.ticket t ON t.id = sv.ticketFk
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p ON p.id = a.provinceFk
- JOIN vn.country c ON c.id = p.countryFk
- JOIN vn.ticketState ts ON ts.ticketFk = t.id
- JOIN vn.alertLevel al ON al.id = ts.alertLevel
- LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
- LEFT JOIN (
- SELECT * FROM (
- SELECT t.addressFk , t.id, t.shipped
- FROM vn.ticket t
- WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, vScopeDays,vDated)
- AND util.dayend(TIMESTAMPADD(DAY, vScopeDays,vDated))
- AND t.warehouseFk = vWarehouseFk
- ) sub
- GROUP BY sub.addressFk
- ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id
- WHERE t.shipped BETWEEN vDated AND util.dayend(vDated)
- AND t.warehouseFk = vWarehouseFk
- AND al.code = 'FREE'
- AND tp.ticketFk IS NULL
- GROUP BY sv.ticketFk
- HAVING liters <= vLitersMax AND `lines` <= vLinesMax AND ticketFuture;
+BEGIN
+/**
+ * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro
+ *
+ * @param vDated Fecha en cuestión
+ * @param vScopeDays Dias en el futuro a sondear
+ * @param vLitersMax Volumen máximo de los tickets a catapultar
+ * @param vLinesMax Número máximo de lineas de los tickets a catapultar
+ * @param vWarehouseFk Identificador de vn.warehouse
+ */
+ SELECT sv.ticketFk ,
+ GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt,
+ CAST(sum(litros) AS DECIMAL(10,0)) liters,
+ CAST(count(*) AS DECIMAL(10,0)) `lines`,
+ st.name state,
+ sub2.id ticketFuture,
+ sub2.shipped,
+ sub2.iptd tfIpt,
+ sub2.state tfState
+ FROM vn.saleVolume sv
+ JOIN vn.sale s ON s.id = sv.saleFk
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.ticket t ON t.id = sv.ticketFk
+ JOIN vn.address a ON a.id = t.addressFk
+ JOIN vn.province p ON p.id = a.provinceFk
+ JOIN vn.country c ON c.id = p.countryFk
+ JOIN vn.ticketState ts ON ts.ticketFk = t.id
+ JOIN vn.state st ON st.id = ts.stateFk
+ JOIN vn.alertLevel al ON al.id = ts.alertLevel
+ LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
+ LEFT JOIN (
+ SELECT * FROM (
+ SELECT
+ t.addressFk ,
+ t.id,
+ t.shipped,
+ st.name state,
+ GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd
+ FROM vn.ticket t
+ JOIN vn.ticketState ts ON ts.ticketFk = t.id
+ JOIN vn.state st ON st.id = ts.stateFk
+ JOIN vn.sale s ON s.ticketFk = t.id
+ JOIN vn.item i ON i.id = s.itemFk
+ WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, vScopeDays,vDated)
+ AND util.dayend(TIMESTAMPADD(DAY, vScopeDays,vDated))
+ AND t.warehouseFk = vWarehouseFk
+ GROUP BY t.id
+ ) sub
+ GROUP BY sub.addressFk
+ ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id
+ WHERE t.shipped BETWEEN vDated AND util.dayend(vDated)
+ AND t.warehouseFk = vWarehouseFk
+ AND al.code = 'FREE'
+ AND tp.ticketFk IS NULL
+ GROUP BY sv.ticketFk
+ HAVING liters <= vLitersMax AND `lines` <= vLinesMax AND ticketFuture;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82873,49 +82184,49 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_canMerge__`(vDated DATE, vScopeDays INT, vLitersMax INT, vLinesMax INT, vWarehouseFk INT)
-BEGIN
-
- /* Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro
- *
- * @param vDated Fecha en cuestión
- * @param vScopeDays Dias en el futuro a sondear
- * @param vLitersMax Volumen máximo de los tickets a catapultar
- * @param vLinesMax Número máximo de lineas de los tickets a catapultar
- * @param vWarehouseFk Identificador de vn.warehouse
- */
-
- SELECT sv.ticketFk ,
- CAST(sum(litros) AS DECIMAL(10,0)) liters,
- CAST(count(*) AS DECIMAL(10,0)) `lines`,
- sub2.id ticketFuture,
- sub2.shipped
- FROM vn.saleVolume sv
- JOIN vn.ticket t ON t.id = sv.ticketFk
- JOIN vn.address a ON a.id = t.addressFk
- JOIN vn.province p ON p.id = a.provinceFk
- JOIN vn.country c ON c.id = p.countryFk
- JOIN vn.ticketState ts ON ts.ticketFk = t.id
- JOIN vn.alertLevel al ON al.id = ts.alertLevel
- LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
- LEFT JOIN tmp.routeDayMove ra ON ra.routeFk = t.routeFk
- LEFT JOIN (
- SELECT * FROM (
- SELECT t.addressFk , t.id, t.shipped
- FROM vn.ticket t
- WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, vScopeDays,vDated)
- AND util.dayend(TIMESTAMPADD(DAY, vScopeDays,vDated))
- AND t.warehouseFk = vWarehouseFk
- ) sub
- GROUP BY sub.addressFk
- ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id
- WHERE t.shipped BETWEEN vDated AND util.dayend(vDated)
- AND t.warehouseFk = vWarehouseFk
- AND al.code = 'FREE'
- AND tp.ticketFk IS NULL
- AND ra.routeFk IS NULL
- GROUP BY sv.ticketFk
- HAVING liters <= vLitersMax AND `lines` <= vLinesMax AND ticketFuture;
-
+BEGIN
+
+ /* Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro
+ *
+ * @param vDated Fecha en cuestión
+ * @param vScopeDays Dias en el futuro a sondear
+ * @param vLitersMax Volumen máximo de los tickets a catapultar
+ * @param vLinesMax Número máximo de lineas de los tickets a catapultar
+ * @param vWarehouseFk Identificador de vn.warehouse
+ */
+
+ SELECT sv.ticketFk ,
+ CAST(sum(litros) AS DECIMAL(10,0)) liters,
+ CAST(count(*) AS DECIMAL(10,0)) `lines`,
+ sub2.id ticketFuture,
+ sub2.shipped
+ FROM vn.saleVolume sv
+ JOIN vn.ticket t ON t.id = sv.ticketFk
+ JOIN vn.address a ON a.id = t.addressFk
+ JOIN vn.province p ON p.id = a.provinceFk
+ JOIN vn.country c ON c.id = p.countryFk
+ JOIN vn.ticketState ts ON ts.ticketFk = t.id
+ JOIN vn.alertLevel al ON al.id = ts.alertLevel
+ LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
+ LEFT JOIN tmp.routeDayMove ra ON ra.routeFk = t.routeFk
+ LEFT JOIN (
+ SELECT * FROM (
+ SELECT t.addressFk , t.id, t.shipped
+ FROM vn.ticket t
+ WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, vScopeDays,vDated)
+ AND util.dayend(TIMESTAMPADD(DAY, vScopeDays,vDated))
+ AND t.warehouseFk = vWarehouseFk
+ ) sub
+ GROUP BY sub.addressFk
+ ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id
+ WHERE t.shipped BETWEEN vDated AND util.dayend(vDated)
+ AND t.warehouseFk = vWarehouseFk
+ AND al.code = 'FREE'
+ AND tp.ticketFk IS NULL
+ AND ra.routeFk IS NULL
+ GROUP BY sv.ticketFk
+ HAVING liters <= vLitersMax AND `lines` <= vLinesMax AND ticketFuture;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -82933,36 +82244,36 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_changeClient`(vNewClient INT, vUserFk INT)
-BEGIN
-
-/**
- * Dado un conjunto de tickets
- * cambia el cliente al nuevo cliente dado
- *
- * params @vNewClient nuevo cliente
- * params @vUserFk usuario que realiza el cambio
- *
- * table @tmp.ticket(ticketFk) conjunto de tickets
- */
-
- INSERT INTO ticketLog (originFk, userFk, `action`, changedModel, oldInstance, newInstance)
- SELECT t.id, vUserFk, 'update', 'Ticket', CONCAT('{"clientFk":',t.clientFk,'}'), CONCAT('{"clientFk":',vNewClient,'}')
- FROM ticket t
- JOIN tmp.ticket tt
- ON t.id = tt.ticketFk;
-
- UPDATE ticket t
- JOIN tmp.ticket tt
- ON t.id = tt.ticketFk
- SET t.clientFk = vNewClient;
-
- UPDATE ticket t
- JOIN tmp.ticket tt
- ON t.id = tt.ticketFk
- JOIN stowaway s
- ON s.shipFk = tt.ticketFk
- SET t.clientFk = vNewClient;
-
+BEGIN
+
+/**
+ * Dado un conjunto de tickets
+ * cambia el cliente al nuevo cliente dado
+ *
+ * params @vNewClient nuevo cliente
+ * params @vUserFk usuario que realiza el cambio
+ *
+ * table @tmp.ticket(ticketFk) conjunto de tickets
+ */
+
+ INSERT INTO ticketLog (originFk, userFk, `action`, changedModel, oldInstance, newInstance)
+ SELECT t.id, vUserFk, 'update', 'Ticket', CONCAT('{"clientFk":',t.clientFk,'}'), CONCAT('{"clientFk":',vNewClient,'}')
+ FROM ticket t
+ JOIN tmp.ticket tt
+ ON t.id = tt.ticketFk;
+
+ UPDATE ticket t
+ JOIN tmp.ticket tt
+ ON t.id = tt.ticketFk
+ SET t.clientFk = vNewClient;
+
+ UPDATE ticket t
+ JOIN tmp.ticket tt
+ ON t.id = tt.ticketFk
+ JOIN stowaway s
+ ON s.shipFk = tt.ticketFk
+ SET t.clientFk = vNewClient;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -83301,13 +82612,12 @@ BEGIN
JOIN vn.sale saleClon ON saleOriginal.itemFk = saleClon.itemFk AND saleOriginal.quantity = saleClon.quantity
WHERE saleOriginal.ticketFk = vTicketFk AND saleClon.ticketFk = vNewTicket;
- INSERT INTO ticketRequest (description,ordered,shipped,salesPersonCode,buyerCode,quantity,price,itemFk,clientFk,response,
- total,buyed,saleFk)
- SELECT o.description,o.ordered,vShipment,o.salesPersonCode,o.buyerCode,o.quantity,o.price,o.itemFk,o.clientFk,o.response,
- o.total,o.buyed,s2.id
- FROM sale s JOIN ticketRequest o ON o.saleFk = s.id
- JOIN sale s2 ON s.concept = s2.concept AND s.quantity = s2.quantity AND s.itemFk = s2.itemFk
- WHERE s.ticketFk = vTicketFk AND s2.ticketFk = vNewTicket;
+ INSERT INTO ticketRequest (description,ordered,shipped,quantity,price,itemFk,clientFk,response,
+ total,buyed,requesterFk,attenderFk,ticketFk)
+ SELECT description,ordered,shipped,quantity,price,itemFk,clientFk,response,
+ total,buyed,requesterFk,attenderFk,vNewTicket
+ FROM ticketRequest
+ WHERE ticketFk =vTicketFk;
INSERT INTO ticketObservation(ticketFk,observationTypeFk,description) VALUES(vNewTicket,4,CONCAT('turno desde ticket: ',vTicketFk))
ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' ');
@@ -84049,41 +83359,41 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_DelayTruck`(vWarehouserFk INT, vHour INT, vMinute INT)
-BEGIN
-
- DECLARE done INT DEFAULT FALSE;
- DECLARE vTicketFk INT;
- DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tmp.ticket;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- CALL vn.productionControl(vWarehouserFk,0) ;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
- CREATE TEMPORARY TABLE tmp.ticket
- SELECT ticketFk
- FROM tmp.productionBuffer
- WHERE shipped = curdate()
- AND problem LIKE '%I:%'
- AND (HH <= vHour OR HH = vHour AND mm < vMinute)
- AND alertLevel = 0;
-
- OPEN cur1;
-
- read_loop: LOOP
-
- FETCH cur1 INTO vTicketFk;
-
- IF done THEN
- LEAVE read_loop;
- END IF;
-
- CALL vn.ticket_DelayTruckSplit(vTicketFk);
-
- END LOOP;
-
- CLOSE cur1;
-
+BEGIN
+
+ DECLARE done INT DEFAULT FALSE;
+ DECLARE vTicketFk INT;
+ DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tmp.ticket;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ CALL vn.productionControl(vWarehouserFk,0) ;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ SELECT ticketFk
+ FROM tmp.productionBuffer
+ WHERE shipped = curdate()
+ AND problem LIKE '%I:%'
+ AND (HH <= vHour OR HH = vHour AND mm < vMinute)
+ AND alertLevel = 0;
+
+ OPEN cur1;
+
+ read_loop: LOOP
+
+ FETCH cur1 INTO vTicketFk;
+
+ IF done THEN
+ LEAVE read_loop;
+ END IF;
+
+ CALL vn.ticket_DelayTruckSplit(vTicketFk);
+
+ END LOOP;
+
+ CLOSE cur1;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -84174,6 +83484,7 @@ proc: BEGIN
DECLARE vDone BOOL;
DECLARE vTicketFk INT;
+ DECLARE vError INT;
DECLARE cCur CURSOR FOR
SELECT ticketFk FROM ticketRecalc;
@@ -84185,6 +83496,17 @@ proc: BEGIN
BEGIN
DO RELEASE_LOCK('vn.ticket_doRecalc');
ROLLBACK;
+ GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+ SET vError = IFNULL(@errno, 0) ;
+ IF NOT(vError = 1105 OR vError = 1751) THEN
+ CALL `vn`.`mail_insert`('cau@verdnatura.es',
+ NULL,
+ 'Problema al recalcular el total de ticket',
+ CONCAT('Se ha detectado un problema en ticket_doRecalc al calcular el total del ticket : ',
+ vTicketFk,' el error es el: ',
+ CONCAT('ERROR ', IFNULL(@errno, 0), ': ', ifnull(@text, '')))
+ );
+ END IF;
RESIGNAL;
END;
@@ -84321,7 +83643,10 @@ BEGIN
FETCH vRsMainTicket INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
END WHILE;
- CLOSE vRsMainTicket;
+ CLOSE vRsMainTicket;
+
+ INSERT INTO vn.ticketRefund(refundTicketFk, originalTicketFk)
+ VALUES(vNewTicket, vOriginTicket);
END ;;
DELIMITER ;
@@ -84340,106 +83665,106 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getFromFloramondo`(vDateFrom DATE, vDateTo DATE)
-BEGIN
-
-/**
- * Genera una tabla con la lista de tickets de Floramondo para una fecha determinada
- * @param vDated Fecha de preparación de los pedidos
- * @return tmp.ticketFloramondo(ticketFk, clientName, agencyName, freight, expeditionCount, margin, trolleys, pallets)
- */
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketFloramondo;
- CREATE TEMPORARY TABLE tmp.ticketFloramondo
- (ticketFk INT PRIMARY KEY,
- clientName VARCHAR(50),
- agencyName VARCHAR(50),
- freight DECIMAL(10,2) DEFAULT 0,
- expeditionCount INT,
- margin DECIMAL(10,3) DEFAULT 0,
- trolleys INT DEFAULT 0,
- shipped DATE,
- pallets INT DEFAULT 0)
- ENGINE = MEMORY;
-
- INSERT INTO tmp.ticketFloramondo(ticketFk, clientName, agencyName, shipped)
- SELECT t.id ticketFk, t.nickname , am.name, t.shipped
- FROM vn.ticket t
- JOIN vn.agencyMode am ON am.id = t.agencyModeFk
- JOIN vn.warehouse w ON w.id = t.warehouseFk AND w.code IN ('VNH','FLM')
- AND t.shipped BETWEEN vDateFrom AND TIMESTAMPADD(HOUR, 23, vDateTo);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
- CREATE TEMPORARY TABLE tmp.ticket
- (ticketFk INT(11) PRIMARY KEY)
- SELECT ticketFk
- FROM tmp.ticketFloramondo;
-
- -- Freight
- UPDATE tmp.ticketFloramondo tf
- JOIN (SELECT SUM(sc.value * s.quantity) freight, t.ticketFk
- FROM vn.saleComponent sc
- JOIN vn.component c ON c.id = sc.componentFk
- JOIN vn.componentType ct ON ct.id = c.typeFk
- JOIN vn.sale s ON s.id = sc.saleFk
- JOIN tmp.ticket t ON t.ticketFk = s.ticketFk
- WHERE ct.code = 'FREIGHT'
- GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
- SET tf.freight = sb.freight;
-
- -- Freight service
- UPDATE tmp.ticketFloramondo tf
- JOIN (SELECT SUM(ts.price * ts.quantity) service, t.ticketFk
- FROM vn.ticketService ts
- JOIN tmp.ticket t ON t.ticketFk = ts.ticketFk
- GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
- SET tf.freight = tf.freight + sb.service;
-
- -- Expedition Count
- UPDATE tmp.ticketFloramondo tf
- JOIN (SELECT COUNT(e.id) expeditionCount, t.ticketFk
- FROM vn.expedition e
- RIGHT JOIN tmp.ticket t ON t.ticketFk = e.ticketFk
- GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
- SET tf.expeditionCount = sb.expeditionCount;
-
- -- Margin
- UPDATE tmp.ticketFloramondo tf
- JOIN (SELECT SUM(IF(ct.code = 'COST',sc.value, 0)) cost,
- SUM(IF(ct.isMargin, sc.value, 0)) margin,
- t.ticketFk
- FROM vn.saleComponent sc
- JOIN vn.component c ON c.id = sc.componentFk
- JOIN vn.componentType ct ON ct.id = c.typeFk
- JOIN vn.sale s ON s.id = sc.saleFk
- JOIN tmp.ticket t ON t.ticketFk = s.ticketFk
- GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
- SET tf.margin = sb.margin / sb.cost;
-
- -- Trolleys
- UPDATE tmp.ticketFloramondo tf
- JOIN (SELECT SUM(tp.quantity) trolleys, t.ticketFk
- FROM vn.ticketPackaging tp
- JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk
- JOIN vn.packaging p ON p.id = tp.packagingFk
- WHERE p.isTrolley
- GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
- SET tf.trolleys = sb.trolleys;
-
- -- Pallets
- UPDATE tmp.ticketFloramondo tf
- JOIN (SELECT SUM(tp.quantity) pallets, t.ticketFk
- FROM vn.ticketPackaging tp
- JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk
- JOIN vn.packaging p ON p.id = tp.packagingFk
- WHERE p.isPallet
- GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
- SET tf.pallets = sb.pallets;
-
- SELECT * FROM tmp.ticketFloramondo;
-
- DROP TEMPORARY TABLE tmp.ticket;
- DROP TEMPORARY TABLE tmp.ticketFloramondo;
-
+BEGIN
+
+/**
+ * Genera una tabla con la lista de tickets de Floramondo para una fecha determinada
+ * @param vDated Fecha de preparación de los pedidos
+ * @return tmp.ticketFloramondo(ticketFk, clientName, agencyName, freight, expeditionCount, margin, trolleys, pallets)
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketFloramondo;
+ CREATE TEMPORARY TABLE tmp.ticketFloramondo
+ (ticketFk INT PRIMARY KEY,
+ clientName VARCHAR(50),
+ agencyName VARCHAR(50),
+ freight DECIMAL(10,2) DEFAULT 0,
+ expeditionCount INT,
+ margin DECIMAL(10,3) DEFAULT 0,
+ trolleys INT DEFAULT 0,
+ shipped DATE,
+ pallets INT DEFAULT 0)
+ ENGINE = MEMORY;
+
+ INSERT INTO tmp.ticketFloramondo(ticketFk, clientName, agencyName, shipped)
+ SELECT t.id ticketFk, t.nickname , am.name, t.shipped
+ FROM vn.ticket t
+ JOIN vn.agencyMode am ON am.id = t.agencyModeFk
+ JOIN vn.warehouse w ON w.id = t.warehouseFk AND w.code IN ('VNH','FLM')
+ AND t.shipped BETWEEN vDateFrom AND TIMESTAMPADD(HOUR, 23, vDateTo);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ (ticketFk INT(11) PRIMARY KEY)
+ SELECT ticketFk
+ FROM tmp.ticketFloramondo;
+
+ -- Freight
+ UPDATE tmp.ticketFloramondo tf
+ JOIN (SELECT SUM(sc.value * s.quantity) freight, t.ticketFk
+ FROM vn.saleComponent sc
+ JOIN vn.component c ON c.id = sc.componentFk
+ JOIN vn.componentType ct ON ct.id = c.typeFk
+ JOIN vn.sale s ON s.id = sc.saleFk
+ JOIN tmp.ticket t ON t.ticketFk = s.ticketFk
+ WHERE ct.code = 'FREIGHT'
+ GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
+ SET tf.freight = sb.freight;
+
+ -- Freight service
+ UPDATE tmp.ticketFloramondo tf
+ JOIN (SELECT SUM(ts.price * ts.quantity) service, t.ticketFk
+ FROM vn.ticketService ts
+ JOIN tmp.ticket t ON t.ticketFk = ts.ticketFk
+ GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
+ SET tf.freight = tf.freight + sb.service;
+
+ -- Expedition Count
+ UPDATE tmp.ticketFloramondo tf
+ JOIN (SELECT COUNT(e.id) expeditionCount, t.ticketFk
+ FROM vn.expedition e
+ RIGHT JOIN tmp.ticket t ON t.ticketFk = e.ticketFk
+ GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
+ SET tf.expeditionCount = sb.expeditionCount;
+
+ -- Margin
+ UPDATE tmp.ticketFloramondo tf
+ JOIN (SELECT SUM(IF(ct.code = 'COST',sc.value, 0)) cost,
+ SUM(IF(ct.isMargin, sc.value, 0)) margin,
+ t.ticketFk
+ FROM vn.saleComponent sc
+ JOIN vn.component c ON c.id = sc.componentFk
+ JOIN vn.componentType ct ON ct.id = c.typeFk
+ JOIN vn.sale s ON s.id = sc.saleFk
+ JOIN tmp.ticket t ON t.ticketFk = s.ticketFk
+ GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
+ SET tf.margin = sb.margin / sb.cost;
+
+ -- Trolleys
+ UPDATE tmp.ticketFloramondo tf
+ JOIN (SELECT SUM(tp.quantity) trolleys, t.ticketFk
+ FROM vn.ticketPackaging tp
+ JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk
+ JOIN vn.packaging p ON p.id = tp.packagingFk
+ WHERE p.isTrolley
+ GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
+ SET tf.trolleys = sb.trolleys;
+
+ -- Pallets
+ UPDATE tmp.ticketFloramondo tf
+ JOIN (SELECT SUM(tp.quantity) pallets, t.ticketFk
+ FROM vn.ticketPackaging tp
+ JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk
+ JOIN vn.packaging p ON p.id = tp.packagingFk
+ WHERE p.isPallet
+ GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk
+ SET tf.pallets = sb.pallets;
+
+ SELECT * FROM tmp.ticketFloramondo;
+
+ DROP TEMPORARY TABLE tmp.ticket;
+ DROP TEMPORARY TABLE tmp.ticketFloramondo;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -84452,9 +83777,9 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getMovable`(vTicketFk INT, vDatedNew DATETIME, vWarehouseFk INT)
BEGIN
@@ -84495,7 +83820,8 @@ BEGIN
WHERE t.id = vTicketFk;
DROP TEMPORARY TABLE IF EXISTS tmp.itemList;
- DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum;
+ DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -84646,6 +83972,156 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `ticket_getSplitList` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getSplitList`(vDated DATE, vHour TIME, vWarehouseFk INT)
+BEGIN
+/**
+ * Devuelve un listado con los tickets posibles para splitar HOY.
+ *
+ * @param vDated Fecha a estudiar
+ * @param vHour Hora a partir de la cual todavía se puede enviar, si la fecha es la de hoy
+ * @param vWarehouseFk Almacén
+ */
+ DECLARE vAvailableCache INT;
+ DECLARE vVisibleCache INT;
+
+ CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, CURDATE());
+ CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk);
+ CALL `vn`.`zoneClosure_recalc`();
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.salesToSplit;
+
+ CREATE TEMPORARY TABLE tmp.salesToSplit
+ (saleFk INT PRIMARY KEY,
+ ticketFk INT,
+ problem VARCHAR(1)) ENGINE = MEMORY;
+
+ INSERT INTO tmp.salesToSplit(saleFk, ticketFk, problem)
+ SELECT s.id, s.ticketFk, 'F'
+ FROM vn.ticket t
+ JOIN vn.sale s ON s.ticketFk = t.id
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.itemType it on it.id = i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCache
+ LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache
+ LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk
+ WHERE IFNULL(v.visible,0) < s.quantity
+ AND IFNULL(av.available ,0) < s.quantity
+ AND IFNULL(issw.visible, 0) < s.quantity
+ AND s.isPicked = FALSE
+ AND s.reserved = FALSE
+ AND ic.merchandise = TRUE
+ AND t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE())
+ AND NOT i.generic
+ AND t.warehouseFk = vWarehouseFk;
+
+ INSERT IGNORE INTO tmp.salesToSplit(saleFk, ticketFk, problem)
+ SELECT s.id, s.ticketFk, 'I'
+ FROM vn.ticket t
+ JOIN vn.sale s ON s.ticketFk = t.id
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.itemType it on it.id = i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache
+ LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk
+ WHERE IFNULL(v.visible,0) >= s.quantity
+ AND IFNULL(issw.visible, 0) < s.quantity
+ AND s.quantity > 0
+ AND s.isPicked = FALSE
+ AND s.reserved = FALSE
+ AND ic.merchandise = TRUE
+ AND t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE())
+ AND NOT i.generic
+ AND t.warehouseFk = vWarehouseFk;
+
+ INSERT IGNORE INTO tmp.salesToSplit(saleFk, ticketFk, problem)
+ SELECT s.id, s.ticketFk, 'R'
+ FROM vn.ticket t
+ JOIN vn.sale s ON s.ticketFk = t.id
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.itemType it on it.id = i.typeFk
+ JOIN vn.itemCategory ic ON ic.id = it.categoryFk
+ LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache
+ LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache
+ LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk
+ WHERE IFNULL(v.visible,0) < s.quantity
+ AND IFNULL(av.available ,0) >= s.quantity
+ AND IFNULL(issw.visible, 0) < s.quantity
+ AND s.quantity > 0
+ AND s.isPicked = FALSE
+ AND s.reserved = FALSE
+ AND ic.merchandise = TRUE
+ AND t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE())
+ AND NOT i.generic
+ AND t.warehouseFk = vWarehouseFk;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketsToSplit;
+
+ CREATE TEMPORARY TABLE tmp.ticketsToSplit
+ (ticketFk INT PRIMARY KEY,
+ problems VARCHAR(100),
+ addressFk INT,
+ ipt VARCHAR(10),
+ etd TIME) ENGINE = MEMORY;
+
+ INSERT INTO tmp.ticketsToSplit
+ SELECT
+ ss.ticketFk,
+ GROUP_CONCAT(DISTINCT ss.problem ORDER BY ss.problem) problems,
+ t.addressFk,
+ GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt,
+ zc.`hour` etd
+ FROM tmp.salesToSplit ss
+ JOIN vn.ticket t ON t.id = ss.ticketFk
+ JOIN vn.sale s ON s.id = ss.saleFk
+ JOIN vn.item i ON i.id = s.itemFk
+ LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
+ GROUP BY ss.ticketFk;
+
+ SELECT
+ ts.*,
+ t.id ticketFuture,
+ st.name state,
+ zc.`hour` tfEtd,
+ GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) tfIpt,
+ st2.name tfState
+ FROM tmp.ticketsToSplit ts
+ LEFT JOIN vn.ticketState ts2 ON ts2.ticketFk = ts.ticketFk
+ LEFT JOIN vn.state st ON st.id = ts2.stateFk
+ LEFT JOIN vn.ticket t
+ ON t.id != ts.ticketFk
+ AND t.addressFk = ts.addressFk
+ AND t.shipped BETWEEN vDated AND util.dayend(vDated)
+ LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = vDated
+ LEFT JOIN vn.sale s ON s.ticketFk = t.id
+ LEFT JOIN vn.item i ON i.id = s.itemFk
+ LEFT JOIN vn.ticketState tst ON tst.ticketFk = t.id
+ LEFT JOIN vn.state st2 ON st2.id = tst.stateFk
+ WHERE (t.id IS NULL
+ OR (vDated > CURDATE())
+ OR (vDated = CURDATE() AND vHour >= zc.`hour`))
+ AND ts.etd <= vHour
+ GROUP BY ts.ticketFk, t.id
+ ORDER BY ts.etd, ts.ticketFk;
+
+ DROP TEMPORARY TABLE
+ tmp.ticketsToSplit;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ticket_getTax` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -84928,24 +84404,24 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_merge`(vSelf INT, vTicketTargetFk INT)
-BEGIN
-
- /**
- * Fusiona el primer ticket al segundo
- *
- * @param vSelf Número de ticket a fusionar
- * @param vTicketTargetFk Ticket destino
- *
- */
-
- UPDATE vn.sale s
- SET s.ticketFk = vTicketTargetFk
- WHERE s.ticketFk = vSelf;
-
- UPDATE vn.ticket t
- SET t.shipped = TIMESTAMPADD(YEAR, - YEAR(NOW()) MOD 2000, t.shipped )
- WHERE t.id = vSelf;
-
+BEGIN
+
+ /**
+ * Fusiona el primer ticket al segundo
+ *
+ * @param vSelf Número de ticket a fusionar
+ * @param vTicketTargetFk Ticket destino
+ *
+ */
+
+ UPDATE vn.sale s
+ SET s.ticketFk = vTicketTargetFk
+ WHERE s.ticketFk = vSelf;
+
+ UPDATE vn.ticket t
+ SET t.shipped = TIMESTAMPADD(YEAR, - YEAR(NOW()) MOD 2000, t.shipped )
+ WHERE t.id = vSelf;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -85020,28 +84496,28 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_recalc`(vTicketId INT)
-BEGIN
-/**
- * Calcula y guarda el total con/sin IVA en un ticket.
- *
- * @param vTicketId Identificador del ticket
- */
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
- CREATE TEMPORARY TABLE tmp.ticket
- ENGINE = MEMORY
- SELECT vTicketId ticketFk;
-
- CALL ticketGetTotal;
-
- UPDATE ticket t
- JOIN tmp.ticketTotal tt ON tt.ticketFk = t.id
- SET t.totalWithVat = tt.total,
- t.totalWithoutVat = tt.totalWithoutVat;
-
- DROP TEMPORARY TABLE
- tmp.ticket,
- tmp.ticketTotal;
+BEGIN
+/**
+ * Calcula y guarda el total con/sin IVA en un ticket.
+ *
+ * @param vTicketId Identificador del ticket
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ ENGINE = MEMORY
+ SELECT vTicketId ticketFk;
+
+ CALL ticketGetTotal;
+
+ UPDATE ticket t
+ JOIN tmp.ticketTotal tt ON tt.ticketFk = t.id
+ SET t.totalWithVat = tt.total,
+ t.totalWithoutVat = tt.totalWithoutVat;
+
+ DROP TEMPORARY TABLE
+ tmp.ticket,
+ tmp.ticketTotal;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -85059,91 +84535,91 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_recalcComponents`(IN vTicketFk BIGINT, vIsTicketEditable BOOLEAN)
-proc: BEGIN
-
-/**
- * Este procedimiento recalcula los componentes de un ticket,
- * eliminando los componentes existentes e insertandolos de nuevo
- *
- * @param vTicketFk Id del ticket
- * @param vIsTicketEditable si no se quiere forzar llamar con NULL
- */
- DECLARE vShipped DATE;
- DECLARE vWarehouseFk SMALLINT;
- DECLARE vAgencyModeFk INT;
- DECLARE vAddressFk INT;
- DECLARE vLanded DATE;
- DECLARE vZoneFk INTEGER;
-
- IF vIsTicketEditable IS NULL THEN
- SELECT IFNULL(ts.alertLevel,0) = 0 AND IFNULL(t.refFk,'') = ''
- INTO vIsTicketEditable
- FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket
- WHERE id = vTicketFk;
- END IF;
-
- SELECT t.warehouseFk,
- t.shipped,
- t.addressFk,
- t.agencyModeFk,
- t.landed,
- t.zoneFk
- INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded, vZoneFk
- FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket
- WHERE t.id = vTicketFk;
-
- CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE);
-
- IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) = 0 THEN
- CALL util.throw('There is no zone for these parameters');
- END IF;
-
- IF vLanded IS NULL OR vZoneFk IS NULL THEN
-
- UPDATE ticket t
- SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1)
- WHERE t.id = vTicketFk AND t.landed IS NULL;
-
- IF vZoneFk IS NULL THEN
- SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1;
- UPDATE ticket t
- SET t.zoneFk = vZoneFk
- WHERE t.id = vTicketFk AND t.zoneFk IS NULL;
- END IF;
-
- END IF;
-
- DROP TEMPORARY TABLE tmp.zoneGetLanded;
-
- -- rellena la tabla buyUltimate con la ultima compra
- CALL buyUltimate (vWarehouseFk, vShipped);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
- CREATE TEMPORARY TABLE tmp.ticketLot
- SELECT vWarehouseFk warehouseFk, NULL available,
- s.itemFk, bu.buyFk, vZoneFk zoneFk
- FROM sale s
- LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
- WHERE s.ticketFk = vTicketFk
- GROUP BY s.itemFk;
-
- CALL catalog_componentPrepare();
- CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.sale;
- CREATE TEMPORARY TABLE tmp.sale
- (PRIMARY KEY (saleFk)) ENGINE = MEMORY
- SELECT id saleFk, vWarehouseFk warehouseFk
- FROM sale s
- WHERE s.ticketFk = vTicketFk;
-
- -- si el ticket esta facturado, respeta los precios
- CALL ticketComponentUpdateSale(IF(vIsTicketEditable, 1, 6));
-
- CALL catalog_componentPurge();
- DROP TEMPORARY TABLE
- tmp.buyUltimate,
- tmp.sale;
+proc: BEGIN
+
+/**
+ * Este procedimiento recalcula los componentes de un ticket,
+ * eliminando los componentes existentes e insertandolos de nuevo
+ *
+ * @param vTicketFk Id del ticket
+ * @param vIsTicketEditable si no se quiere forzar llamar con NULL
+ */
+ DECLARE vShipped DATE;
+ DECLARE vWarehouseFk SMALLINT;
+ DECLARE vAgencyModeFk INT;
+ DECLARE vAddressFk INT;
+ DECLARE vLanded DATE;
+ DECLARE vZoneFk INTEGER;
+
+ IF vIsTicketEditable IS NULL THEN
+ SELECT IFNULL(ts.alertLevel,0) = 0 AND IFNULL(t.refFk,'') = ''
+ INTO vIsTicketEditable
+ FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket
+ WHERE id = vTicketFk;
+ END IF;
+
+ SELECT t.warehouseFk,
+ t.shipped,
+ t.addressFk,
+ t.agencyModeFk,
+ t.landed,
+ t.zoneFk
+ INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded, vZoneFk
+ FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket
+ WHERE t.id = vTicketFk;
+
+ CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE);
+
+ IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) = 0 THEN
+ CALL util.throw('There is no zone for these parameters');
+ END IF;
+
+ IF vLanded IS NULL OR vZoneFk IS NULL THEN
+
+ UPDATE ticket t
+ SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1)
+ WHERE t.id = vTicketFk AND t.landed IS NULL;
+
+ IF vZoneFk IS NULL THEN
+ SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1;
+ UPDATE ticket t
+ SET t.zoneFk = vZoneFk
+ WHERE t.id = vTicketFk AND t.zoneFk IS NULL;
+ END IF;
+
+ END IF;
+
+ DROP TEMPORARY TABLE tmp.zoneGetLanded;
+
+ -- rellena la tabla buyUltimate con la ultima compra
+ CALL buyUltimate (vWarehouseFk, vShipped);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
+ CREATE TEMPORARY TABLE tmp.ticketLot
+ SELECT vWarehouseFk warehouseFk, NULL available,
+ s.itemFk, bu.buyFk, vZoneFk zoneFk
+ FROM sale s
+ LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
+ WHERE s.ticketFk = vTicketFk
+ GROUP BY s.itemFk;
+
+ CALL catalog_componentPrepare();
+ CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.sale;
+ CREATE TEMPORARY TABLE tmp.sale
+ (PRIMARY KEY (saleFk)) ENGINE = MEMORY
+ SELECT id saleFk, vWarehouseFk warehouseFk
+ FROM sale s
+ WHERE s.ticketFk = vTicketFk;
+
+ -- si el ticket esta facturado, respeta los precios
+ CALL ticketComponentUpdateSale(IF(vIsTicketEditable, 1, 6));
+
+ CALL catalog_componentPurge();
+ DROP TEMPORARY TABLE
+ tmp.buyUltimate,
+ tmp.sale;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -85356,17 +84832,17 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_requestRecalc`(vSelf INT)
-proc: BEGIN
-/**
- * Adds a request to recalculate the ticket total.
- *
- * @param vSelf The ticket identifier
- */
- IF vSelf IS NULL THEN
- LEAVE proc;
- END IF;
-
- INSERT IGNORE INTO ticketRecalc SET ticketFk = vSelf;
+proc: BEGIN
+/**
+ * Adds a request to recalculate the ticket total.
+ *
+ * @param vSelf The ticket identifier
+ */
+ IF vSelf IS NULL THEN
+ LEAVE proc;
+ END IF;
+
+ INSERT IGNORE INTO ticketRecalc SET ticketFk = vSelf;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -85384,27 +84860,27 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setNextState`(vSelf INT)
-BEGIN
-/**
- * Cambia el estado del ticket al siguiente estado según la tabla state
- *
- * @param vSelf id dle ticket
- */
- DECLARE vStateFk INT;
- DECLARE vNewStateFk INT;
-
- SELECT stateFk INTO vStateFk
- FROM ticketState
- WHERE ticketFk = vSelf;
-
- SELECT nextStateFk INTO vNewStateFk
- FROM state
- WHERE id = vStateFk;
-
- INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
- VALUES (vNewStateFk, vSelf, account.myUser_getId());
-
- SELECT TRUE AS IsUpdated;
+BEGIN
+/**
+ * Cambia el estado del ticket al siguiente estado según la tabla state
+ *
+ * @param vSelf id dle ticket
+ */
+ DECLARE vStateFk INT;
+ DECLARE vNewStateFk INT;
+
+ SELECT stateFk INTO vStateFk
+ FROM ticketState
+ WHERE ticketFk = vSelf;
+
+ SELECT nextStateFk INTO vNewStateFk
+ FROM state
+ WHERE id = vStateFk;
+
+ INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
+ VALUES (vNewStateFk, vSelf, account.myUser_getId());
+
+ SELECT TRUE AS IsUpdated;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -85422,40 +84898,40 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setPreviousState`(vTicketFk INT)
-BEGIN
-
- DECLARE vControlFk INT;
-
- SELECT MAX(inter_id) INTO vControlFk
- FROM vncontrol.inter
- WHERE Id_Ticket = vTicketFk;
-
- IF (SELECT s.code
- FROM vn.state s
- JOIN vncontrol.inter i ON i.state_id = s.id
- WHERE i.inter_id = vControlFk)
- = 'PREVIOUS_PREPARATION' THEN
-
- SELECT inter_id
- INTO vControlFk
- FROM vncontrol.inter i
- JOIN vn.state s ON i.state_id = s.id
- WHERE Id_Ticket = vTicketFk
- AND inter_id < vControlFk
- AND s.code != 'PREVIOUS_PREPARATION'
- ORDER BY inter_id DESC
- LIMIT 1;
-
- INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
- SELECT s.nextStateFk, i.Id_Ticket, account.myUser_getId()
- FROM vncontrol.inter i
- JOIN vn.state s ON i.state_id = s.id
- WHERE inter_id = vControlFk;
-
- END IF;
-
- SELECT TRUE AS IsUpdated;
-
+BEGIN
+
+ DECLARE vControlFk INT;
+
+ SELECT MAX(inter_id) INTO vControlFk
+ FROM vncontrol.inter
+ WHERE Id_Ticket = vTicketFk;
+
+ IF (SELECT s.code
+ FROM vn.state s
+ JOIN vncontrol.inter i ON i.state_id = s.id
+ WHERE i.inter_id = vControlFk)
+ = 'PREVIOUS_PREPARATION' THEN
+
+ SELECT inter_id
+ INTO vControlFk
+ FROM vncontrol.inter i
+ JOIN vn.state s ON i.state_id = s.id
+ WHERE Id_Ticket = vTicketFk
+ AND inter_id < vControlFk
+ AND s.code != 'PREVIOUS_PREPARATION'
+ ORDER BY inter_id DESC
+ LIMIT 1;
+
+ INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
+ SELECT s.nextStateFk, i.Id_Ticket, account.myUser_getId()
+ FROM vncontrol.inter i
+ JOIN vn.state s ON i.state_id = s.id
+ WHERE inter_id = vControlFk;
+
+ END IF;
+
+ SELECT TRUE AS IsUpdated;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -85473,30 +84949,120 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setState`(vTicketFk INT, vStateCode VARCHAR(45))
-BEGIN
-
- /* Modifica el estado de un ticket
- *
- * @param vTicketFk el id del ticket
- * @param vStateCode estado a modificar del ticket
- *
- */
-
- DECLARE vAlertLevel INT;
-
- SELECT s.alertLevel INTO vAlertLevel
- FROM vn.state s
- JOIN vn.ticketState ts ON ts.stateFk = s.id
- WHERE ts.ticketFk = vTicketFk;
-
- IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN
-
- INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
- SELECT id, vTicketFk, account.myUser_getId()
- FROM vn.state
- WHERE `code` = vStateCode collate utf8_unicode_ci;
-
- END IF;
+BEGIN
+
+ /* Modifica el estado de un ticket
+ *
+ * @param vTicketFk el id del ticket
+ * @param vStateCode estado a modificar del ticket
+ *
+ */
+
+ DECLARE vAlertLevel INT;
+
+ SELECT s.alertLevel INTO vAlertLevel
+ FROM vn.state s
+ JOIN vn.ticketState ts ON ts.stateFk = s.id
+ WHERE ts.ticketFk = vTicketFk;
+
+ IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN
+
+ INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
+ SELECT id, vTicketFk, account.myUser_getId()
+ FROM vn.state
+ WHERE `code` = vStateCode collate utf8_unicode_ci;
+
+ END IF;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `ticket_split` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_split`(vTicketFk INT, vTicketFutureFk INT, vDated DATE)
+proc:BEGIN
+/**
+ * Mueve las lineas con problemas a otro ticket existente o a uno nuevo.
+ *
+ * @param vTicketFk Identificador del ticket a splittar
+ * @param vTicketFutureFk Identificador del ticket al que se quieren mover las lineas
+ * @param vDate Fecha a la que se va a mover
+ * @table tmp.salesToSplit(saleFk, ticketFk, problem)
+ */
+ DECLARE vHasFullProblem BOOL;
+ DECLARE vProblemLines INT;
+ DECLARE vTotalLines INT;
+
+ SELECT COUNT(*) INTO vProblemLines
+ FROM tmp.salesToSplit
+ WHERE ticketFk = vTicketFk;
+
+ SELECT count(*) INTO vTotalLines
+ FROM vn.sale s
+ WHERE s.ticketFk = vTicketFk;
+
+ SET vHasFullProblem = (vTotalLines = vProblemLines);
+
+ -- Ticket completo
+ IF vHasFullProblem THEN
+
+ UPDATE vn.ticket
+ SET landed = vDated + 1,
+ shipped = vDated,
+ nickname = CONCAT('(',DAY(curdate()),') ', nickname )
+ WHERE id = vTicketFk;
+
+ SELECT CONCAT("Se ha cambiado el ticket ", vTicketFk, " al dia ", vDated);
+ LEAVE proc;
+
+ END IF;
+
+ -- Ticket a futuro existe
+ IF vTicketFutureFk THEN
+
+ UPDATE vn.sale s
+ JOIN tmp.salesToSplit ss ON s.id = ss.saleFk
+ SET s.ticketFk = vTicketFutureFk,
+ s.concept = CONCAT('(s) ', s.concept)
+ WHERE ss.ticketFk = vTicketFk;
+
+ SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk,
+ " al ticket existente ", vTicketFutureFk,"(", vDated,")");
+ LEAVE proc;
+
+ END IF;
+
+ -- Ticket nuevo
+ CALL vn.ticket_Clone(vTicketFk, vTicketFutureFk);
+
+ UPDATE vn.ticket t
+ JOIN vn.productionConfig pc
+ SET t.landed = vDated + 1,
+ t.shipped = vDated,
+ t.agencyModeFk = pc.defautlAgencyMode,
+ t.zoneFk = pc.defaultZone
+ WHERE t.id = vTicketFutureFk;
+
+ UPDATE vn.sale s
+ JOIN tmp.salesToSplit sts ON sts.saleFk = s.id
+ SET s.ticketFk = vTicketFutureFk,
+ s.concept = CONCAT('(s) ', s.concept)
+ WHERE sts.ticketFk = vTicketFk;
+
+ CALL vn.ticketStateUpdate(vTicketFutureFk, 'FIXING');
+
+ SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk,
+ " al nuevo ticket ", vTicketFutureFk,"(", vDated,")");
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -86513,9 +86079,9 @@ DELIMITER ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!50003 SET character_set_results = utf8 */ ;
+/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
@@ -86540,17 +86106,23 @@ BEGIN
CREATE TEMPORARY TABLE tmp.timeControl
(INDEX(id), INDEX(journeyCounter))
ENGINE = MEMORY
- SELECT wtc.id,
- wtc.direction,
- wtc.timed,
- IF(wtc.direction = 'in' OR @hasOut OR wtc.userFk <> @lastUserFk, @journeyCounter := @journeyCounter + 1, @journeyCounter) journeyCounter,
- @lastUserFk := wtc.userFk workerFk,
- IF(wtc.direction = 'out', @hasOut:= TRUE, @hasOut:= FALSE)
- FROM workerTimeControl wtc
- JOIN tmp.`user` w ON w.userFk = wtc.userFk
- WHERE wtc.timed BETWEEN DATE_SUB(vDatedFrom, INTERVAL 1 DAY) AND DATE_ADD(vDatedTo, INTERVAL 1 DAY)
- ORDER BY wtc.userFk, wtc.timed;
-
+ SELECT sub.id,
+ sub.direction,
+ sub.timed,
+ IF(sub.direction = 'in' OR @hasOut OR sub.userFk <> @lastUserFk, @journeyCounter := @journeyCounter + 1, @journeyCounter) journeyCounter,
+ @lastUserFk := sub.userFk workerFk,
+ IF(sub.direction = 'out', @hasOut:= TRUE, @hasOut:= FALSE)
+ FROM (
+ SELECT DISTINCT wtc.id,
+ wtc.direction,
+ wtc.timed,
+ wtc.userFk
+ FROM workerTimeControl wtc
+ JOIN tmp.`user` w ON w.userFk = wtc.userFk
+ WHERE wtc.timed BETWEEN DATE_SUB(vDatedFrom, INTERVAL 1 DAY) AND DATE_ADD(vDatedTo, INTERVAL 1 DAY)
+ ORDER BY wtc.userFk, wtc.timed
+ ) sub;
+
DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux;
CREATE TEMPORARY TABLE tmp.timeControlAux
(INDEX(id), INDEX(journeyCounter))
@@ -86576,7 +86148,7 @@ BEGIN
OR timeWork >= vDayMaxTime
)sub ON sub.journeyCounter = tca.journeyCounter
WHERE sub.timed BETWEEN vDatedFrom AND vDatedTo;
-
+
DROP TEMPORARY TABLE IF EXISTS tmp.timeControl;
DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux;
@@ -86620,27 +86192,27 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `tpvTransaction_checkStatus`()
-BEGIN
-/**
- *
- * Envia mail con los cobros web no
- * trasladados a la ficha del cliente.
- *
- */
- INSERT INTO mail (receiver,replyTo,subject,body)
- SELECT 'administracion@verdnatura.es',
- 'noreply@verdnatura.es',
- CONCAT('Cobro web no trasladado a la ficha del cliente ', t.clientFk),
- CONCAT('Hay un importe de ', t.amount/100, '€ del cliente ', t.clientFk, ' con fecha ', t.created,
- ', que no se ha trasladado a recibos. Si nos ha llegado el importe al banco confirme el pago en
-
- https://salix.verdnatura.es/#!/client/',t.clientFk,'/web-payment')
- FROM hedera.tpvTransaction t
- WHERE t.receiptFk IS NULL
- AND t.status = 'ok'
- AND t.created < DATE_ADD(NOW(),INTERVAL - 2 DAY)
- GROUP BY t.clientFk;
-
+BEGIN
+/**
+ *
+ * Envia mail con los cobros web no
+ * trasladados a la ficha del cliente.
+ *
+ */
+ INSERT INTO mail (receiver,replyTo,subject,body)
+ SELECT 'administracion@verdnatura.es',
+ 'noreply@verdnatura.es',
+ CONCAT('Cobro web no trasladado a la ficha del cliente ', t.clientFk),
+ CONCAT('Hay un importe de ', t.amount/100, '€ del cliente ', t.clientFk, ' con fecha ', t.created,
+ ', que no se ha trasladado a recibos. Si nos ha llegado el importe al banco confirme el pago en
+
+ https://salix.verdnatura.es/#!/client/',t.clientFk,'/web-payment')
+ FROM hedera.tpvTransaction t
+ WHERE t.receiptFk IS NULL
+ AND t.status = 'ok'
+ AND t.created < DATE_ADD(NOW(),INTERVAL - 2 DAY)
+ GROUP BY t.clientFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -86701,21 +86273,21 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `travelVolume_get`(vFromDated DATE, vToDated DATE, vWarehouseFk INT)
-BEGIN
-
- SELECT tr.landed Fecha,
- a.name Agencia,
- count(DISTINCT e.id) numEntradas,
- FLOOR(sum(item_getVolume(b.itemFk, b.packageFk) * b.stickers / 1000000 )) AS m3
- FROM vn.travel tr
- JOIN vn.agencyMode a ON a.id = tr.agencyFk
- JOIN vn.entry e ON e.travelFk = tr.id
- JOIN vn.buy b ON b.entryFk = e.id
- WHERE tr.landed BETWEEN vFromDated AND vToDated
- AND e.isRaid = FALSE
- AND tr.warehouseInFk = vWarehouseFk
- GROUP BY tr.landed , a.name ;
-
+BEGIN
+
+ SELECT tr.landed Fecha,
+ a.name Agencia,
+ count(DISTINCT e.id) numEntradas,
+ FLOOR(sum(item_getVolume(b.itemFk, b.packageFk) * b.stickers / 1000000 )) AS m3
+ FROM vn.travel tr
+ JOIN vn.agencyMode a ON a.id = tr.agencyFk
+ JOIN vn.entry e ON e.travelFk = tr.id
+ JOIN vn.buy b ON b.entryFk = e.id
+ WHERE tr.landed BETWEEN vFromDated AND vToDated
+ AND e.isRaid = FALSE
+ AND tr.warehouseInFk = vWarehouseFk
+ GROUP BY tr.landed , a.name ;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -86763,54 +86335,54 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_clone`(vSelf INT, vDays INT, OUT vNewTravelFk INT)
-BEGIN
-
- /**
- * Clona un travel el número de dias indicado y devuelve su Id
- *
- * @param vSelf Identificador de vn.travel
- * @param vDays Número de dias a futuro
- *
- * @return vNewTravelFk Nuevo número de travel
- */
-
- SELECT tr.id INTO vNewTravelFk
- FROM vn.travel tr
- JOIN vn.travel tr2 USING(shipped, warehouseInFk, warehouseOutFk, agencyFk, `ref`)
- WHERE tr2.id = vSelf
- AND tr.landed = TIMESTAMPADD(DAY, vDays, tr2.landed);
-
- IF ISNULL(vNewTravelFk) THEN
-
- START TRANSACTION;
-
- INSERT INTO vn.travel( shipped,
- shipmentHour,
- landed,
- landingHour,
- warehouseInFk,
- warehouseOutFk,
- agencyFk,
- `ref`,
- cargoSupplierFk)
- SELECT shipped,
- shipmentHour,
- TIMESTAMPADD(DAY, vDays, landed),
- landingHour,
- warehouseInFk,
- warehouseOutFk,
- agencyFk,
- `ref`,
- cargoSupplierFk
- FROM vn.travel
- WHERE id = vSelf;
-
- SELECT LAST_INSERT_ID() INTO vNewTravelFk;
-
- COMMIT;
-
- END IF;
-
+BEGIN
+
+ /**
+ * Clona un travel el número de dias indicado y devuelve su Id
+ *
+ * @param vSelf Identificador de vn.travel
+ * @param vDays Número de dias a futuro
+ *
+ * @return vNewTravelFk Nuevo número de travel
+ */
+
+ SELECT tr.id INTO vNewTravelFk
+ FROM vn.travel tr
+ JOIN vn.travel tr2 USING(shipped, warehouseInFk, warehouseOutFk, agencyFk, `ref`)
+ WHERE tr2.id = vSelf
+ AND tr.landed = TIMESTAMPADD(DAY, vDays, tr2.landed);
+
+ IF ISNULL(vNewTravelFk) THEN
+
+ START TRANSACTION;
+
+ INSERT INTO vn.travel( shipped,
+ shipmentHour,
+ landed,
+ landingHour,
+ warehouseInFk,
+ warehouseOutFk,
+ agencyFk,
+ `ref`,
+ cargoSupplierFk)
+ SELECT shipped,
+ shipmentHour,
+ TIMESTAMPADD(DAY, vDays, landed),
+ landingHour,
+ warehouseInFk,
+ warehouseOutFk,
+ agencyFk,
+ `ref`,
+ cargoSupplierFk
+ FROM vn.travel
+ WHERE id = vSelf;
+
+ SELECT LAST_INSERT_ID() INTO vNewTravelFk;
+
+ COMMIT;
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -86827,146 +86399,146 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_cloneWithEntries`(
- IN vTravelFk INT,
- IN vDateStart DATE,
- IN vDateEnd DATE,
- IN vWarehouseOutFk INT,
- IN vWarehouseInFk INT,
- IN vRef VARCHAR(255),
- IN vAgencyModeFk INT,
+CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_cloneWithEntries`(
+ IN vTravelFk INT,
+ IN vDateStart DATE,
+ IN vDateEnd DATE,
+ IN vWarehouseOutFk INT,
+ IN vWarehouseInFk INT,
+ IN vRef VARCHAR(255),
+ IN vAgencyModeFk INT,
OUT vNewTravelFk INT)
-BEGIN
-/**
- * Clona un travel junto con sus entradas y compras
- *
- * @param vTravelFk travel plantilla a clonar
- * @param vDateStart fecha del shipment del nuevo travel
- * @param vDateEnd fecha del landing del nuevo travel
- * @param vWarehouseOutFk fecha del salida del nuevo travel
- * @param vWarehouseInFk warehouse de landing del nuevo travel
- * @param vRef referencia del nuevo travel
- * @param vAgencyModeFk del nuevo travel
- * @param vNewTravelFk id del nuevo travel
- */
- DECLARE vEntryNew INT;
- DECLARE vDone BOOLEAN DEFAULT FALSE;
- DECLARE vAuxEntryFk INT;
- DECLARE vRsEntry CURSOR FOR
- SELECT e.id
- FROM entry e
- JOIN travel t
- ON t.id = e.travelFk
- WHERE e.travelFk = vTravelFk;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION/*, 1062 Duplicate key*/
- BEGIN
- ROLLBACK;
-
- END;
-
- START TRANSACTION;
- INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyFk, `ref`, isDelivered, isReceived, m3, kg)
- SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3, kg
- FROM travel
- WHERE id = vTravelFk;
-
- SET vNewTravelFk = LAST_INSERT_ID();
- CALL logAdd(vNewTravelFk, 'insert', 'travel', CONCAT('clona travel ',vTravelFk));
- SET vDone = FALSE;
- SET @isModeInventory = TRUE;
- OPEN vRsEntry ;
- FETCH vRsEntry INTO vAuxEntryFk;
-
- WHILE NOT vDone DO
- INSERT INTO entry (
- supplierFk,
- ref,
- isInventory,
- isConfirmed,
- isOrdered,
- isRaid,
- commission,
- created,
- evaNotes,
- travelFk,
- currencyFk,
- companyFk,
- gestDocFk,
- invoiceInFk)
- SELECT supplierFk,
- ref,
- isInventory,
- isConfirmed,
- isOrdered,
- isRaid,
- commission,
- created,
- evaNotes,
- vNewTravelFk,
- currencyFk,
- companyFk,
- gestDocFk,
- invoiceInFk
- FROM entry
- WHERE id = vAuxEntryFk;
-
- SET vEntryNew = LAST_INSERT_ID();
-
- CALL logAdd(vEntryNew, 'insert', 'entry', CONCAT('clona entrada ',vAuxEntryFk));
- INSERT INTO buy (
- entryFk,
- itemFk,
- quantity,
- buyingValue,
- packageFk,
- stickers,
- freightValue,
- packageValue,
- comissionValue,
- packing,
- `grouping`,
- groupingMode,
- location,
- price1,
- price2,
- price3,
- minPrice,
- producer,
- printedStickers,
- isChecked,
- weight)
- SELECT vEntryNew,
- itemFk,
- quantity,
- buyingValue,
- packageFk,
- stickers,
- freightValue,
- packageValue,
- comissionValue,
- packing,
- `grouping`,
- groupingMode,
- location,
- price1,
- price2,
- price3,
- minPrice,
- producer,
- printedStickers,
- isChecked,
- weight
- FROM buy
- WHERE entryFk = vAuxEntryFk;
-
- FETCH vRsEntry INTO vAuxEntryFk;
- END WHILE;
- SET @isModeInventory = FALSE;
- CLOSE vRsEntry;
- COMMIT;
+BEGIN
+/**
+ * Clona un travel junto con sus entradas y compras
+ *
+ * @param vTravelFk travel plantilla a clonar
+ * @param vDateStart fecha del shipment del nuevo travel
+ * @param vDateEnd fecha del landing del nuevo travel
+ * @param vWarehouseOutFk fecha del salida del nuevo travel
+ * @param vWarehouseInFk warehouse de landing del nuevo travel
+ * @param vRef referencia del nuevo travel
+ * @param vAgencyModeFk del nuevo travel
+ * @param vNewTravelFk id del nuevo travel
+ */
+ DECLARE vEntryNew INT;
+ DECLARE vDone BOOLEAN DEFAULT FALSE;
+ DECLARE vAuxEntryFk INT;
+ DECLARE vRsEntry CURSOR FOR
+ SELECT e.id
+ FROM entry e
+ JOIN travel t
+ ON t.id = e.travelFk
+ WHERE e.travelFk = vTravelFk;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION/*, 1062 Duplicate key*/
+ BEGIN
+ ROLLBACK;
+
+ END;
+
+ START TRANSACTION;
+ INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyFk, `ref`, isDelivered, isReceived, m3, kg)
+ SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3, kg
+ FROM travel
+ WHERE id = vTravelFk;
+
+ SET vNewTravelFk = LAST_INSERT_ID();
+ CALL logAdd(vNewTravelFk, 'insert', 'travel', CONCAT('clona travel ',vTravelFk));
+ SET vDone = FALSE;
+ SET @isModeInventory = TRUE;
+ OPEN vRsEntry ;
+ FETCH vRsEntry INTO vAuxEntryFk;
+
+ WHILE NOT vDone DO
+ INSERT INTO entry (
+ supplierFk,
+ ref,
+ isInventory,
+ isConfirmed,
+ isOrdered,
+ isRaid,
+ commission,
+ created,
+ evaNotes,
+ travelFk,
+ currencyFk,
+ companyFk,
+ gestDocFk,
+ invoiceInFk)
+ SELECT supplierFk,
+ ref,
+ isInventory,
+ isConfirmed,
+ isOrdered,
+ isRaid,
+ commission,
+ created,
+ evaNotes,
+ vNewTravelFk,
+ currencyFk,
+ companyFk,
+ gestDocFk,
+ invoiceInFk
+ FROM entry
+ WHERE id = vAuxEntryFk;
+
+ SET vEntryNew = LAST_INSERT_ID();
+
+ CALL logAdd(vEntryNew, 'insert', 'entry', CONCAT('clona entrada ',vAuxEntryFk));
+ INSERT INTO buy (
+ entryFk,
+ itemFk,
+ quantity,
+ buyingValue,
+ packageFk,
+ stickers,
+ freightValue,
+ packageValue,
+ comissionValue,
+ packing,
+ `grouping`,
+ groupingMode,
+ location,
+ price1,
+ price2,
+ price3,
+ minPrice,
+ producer,
+ printedStickers,
+ isChecked,
+ weight)
+ SELECT vEntryNew,
+ itemFk,
+ quantity,
+ buyingValue,
+ packageFk,
+ stickers,
+ freightValue,
+ packageValue,
+ comissionValue,
+ packing,
+ `grouping`,
+ groupingMode,
+ location,
+ price1,
+ price2,
+ price3,
+ minPrice,
+ producer,
+ printedStickers,
+ isChecked,
+ weight
+ FROM buy
+ WHERE entryFk = vAuxEntryFk;
+
+ FETCH vRsEntry INTO vAuxEntryFk;
+ END WHILE;
+ SET @isModeInventory = FALSE;
+ CLOSE vRsEntry;
+ COMMIT;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -87372,60 +86944,60 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `typeTagMake`(vTypeFk INT)
-BEGIN
-/*
- * Plantilla para modificar reemplazar todos los tags
- * por los valores que tienen los articulos
- *
- * @param vTypeFk tipo a modificar
- *
- */
- DELETE it.*
- FROM itemTag it
- JOIN item i ON i.id = it.itemFk
- WHERE i.typeFk = vTypeFk;
-
- INSERT INTO itemTag(itemFk, tagFk, value, priority)
- SELECT i.id, t.id, CONCAT(i.size,' cm'), 1
- FROM item i
- JOIN tag t ON t.name = 'Longitud' COLLATE utf8_general_ci
- WHERE i.typeFk = vTypeFk;
-
- INSERT INTO itemTag(itemFk, tagFk, value, priority)
- SELECT i.id, t.id, i.category, 5
- FROM item i
- JOIN tag t ON t.name = 'Categoria' COLLATE utf8_general_ci
- WHERE i.typeFk = vTypeFk;
-
- INSERT INTO itemTag(itemFk, tagFk, value, priority)
- SELECT i.id, t.id, ink.name, 2
- FROM item i
- JOIN tag t ON t.name = 'Color' COLLATE utf8_general_ci
- JOIN ink ON ink.id = i.inkFk
- WHERE i.typeFk = vTypeFk;
-
- INSERT INTO itemTag(itemFk, tagFk, value, priority)
- SELECT i.id, t.id, p.name, 3
- FROM item i
- JOIN tag t ON t.name = 'Productor' COLLATE utf8_general_ci
- JOIN producer p ON p.id = i.producerFk
- WHERE i.typeFk = vTypeFk;
-
- INSERT INTO itemTag(itemFk, tagFk, value, priority)
- SELECT i.id, t.id, o.name, 4
- FROM item i
- JOIN tag t ON t.name = 'Origen' COLLATE utf8_general_ci
- JOIN origin o ON o.id = i.originFk
- WHERE i.typeFk = vTypeFk;
- /*
- INSERT INTO itemTag(itemFk, tagFk, value, priority)
- SELECT i.id, t.id, i.stems, 6
- FROM item i
- JOIN tag t ON t.name = 'Tallos' COLLATE utf8_general_ci
- WHERE i.typeFk = vTypeFk;
- */
--- CALL itemTagArrangedUpdate(NULL);
-
+BEGIN
+/*
+ * Plantilla para modificar reemplazar todos los tags
+ * por los valores que tienen los articulos
+ *
+ * @param vTypeFk tipo a modificar
+ *
+ */
+ DELETE it.*
+ FROM itemTag it
+ JOIN item i ON i.id = it.itemFk
+ WHERE i.typeFk = vTypeFk;
+
+ INSERT INTO itemTag(itemFk, tagFk, value, priority)
+ SELECT i.id, t.id, CONCAT(i.size,' cm'), 1
+ FROM item i
+ JOIN tag t ON t.name = 'Longitud' COLLATE utf8_general_ci
+ WHERE i.typeFk = vTypeFk;
+
+ INSERT INTO itemTag(itemFk, tagFk, value, priority)
+ SELECT i.id, t.id, i.category, 5
+ FROM item i
+ JOIN tag t ON t.name = 'Categoria' COLLATE utf8_general_ci
+ WHERE i.typeFk = vTypeFk;
+
+ INSERT INTO itemTag(itemFk, tagFk, value, priority)
+ SELECT i.id, t.id, ink.name, 2
+ FROM item i
+ JOIN tag t ON t.name = 'Color' COLLATE utf8_general_ci
+ JOIN ink ON ink.id = i.inkFk
+ WHERE i.typeFk = vTypeFk;
+
+ INSERT INTO itemTag(itemFk, tagFk, value, priority)
+ SELECT i.id, t.id, p.name, 3
+ FROM item i
+ JOIN tag t ON t.name = 'Productor' COLLATE utf8_general_ci
+ JOIN producer p ON p.id = i.producerFk
+ WHERE i.typeFk = vTypeFk;
+
+ INSERT INTO itemTag(itemFk, tagFk, value, priority)
+ SELECT i.id, t.id, o.name, 4
+ FROM item i
+ JOIN tag t ON t.name = 'Origen' COLLATE utf8_general_ci
+ JOIN origin o ON o.id = i.originFk
+ WHERE i.typeFk = vTypeFk;
+ /*
+ INSERT INTO itemTag(itemFk, tagFk, value, priority)
+ SELECT i.id, t.id, i.stems, 6
+ FROM item i
+ JOIN tag t ON t.name = 'Tallos' COLLATE utf8_general_ci
+ WHERE i.typeFk = vTypeFk;
+ */
+-- CALL itemTagArrangedUpdate(NULL);
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -88975,16 +88547,16 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerMistakeType_get`()
-BEGIN
-
-/**
- * Obtiene los tipos de error para los trabajadores
- */
-
- SELECT code, description
- FROM workerMistakeType
- ORDER BY description;
-
+BEGIN
+
+/**
+ * Obtiene los tipos de error para los trabajadores
+ */
+
+ SELECT code, description
+ FROM workerMistakeType
+ ORDER BY description;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -89002,27 +88574,27 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerMistake_add`(vWorkerFk INT, vWorkerMistakeTypeFk VARCHAR(10), vUserFk INT )
-BEGIN
-
-/**
- * Añade error al trabajador
- *
- * @param vWorkerFk id del trabajador al cual se le va a añadir error
- * @param vWorkerMistakeTypeFk code del tipo de error
- * @param vUserFk id del usuario que pone el error
- *
- */
- DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vUserFk);
-
- IF(account.user_hasRole(vWorkerName,'coolerBoss'))
- THEN
- INSERT INTO vn.workerMistake(userFk, workerMistakeTypeFk)
- VALUES(vWorkerFk, vWorkerMistakeTypeFk);
- ELSE
- CALL util.throw('No tienes permisos para realizar la acción');
-
- END IF;
-
+BEGIN
+
+/**
+ * Añade error al trabajador
+ *
+ * @param vWorkerFk id del trabajador al cual se le va a añadir error
+ * @param vWorkerMistakeTypeFk code del tipo de error
+ * @param vUserFk id del usuario que pone el error
+ *
+ */
+ DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vUserFk);
+
+ IF(account.user_hasRole(vWorkerName,'coolerBoss'))
+ THEN
+ INSERT INTO vn.workerMistake(userFk, workerMistakeTypeFk)
+ VALUES(vWorkerFk, vWorkerMistakeTypeFk);
+ ELSE
+ CALL util.throw('No tienes permisos para realizar la acción');
+
+ END IF;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -89040,28 +88612,28 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerShelving_Add`(vWorkerFk INT, vBarcode VARCHAR(12))
-BEGIN
-/*
- * Inserta en workerShelving asociando los carros al trabajador
- * @Param vWorkerFk es id del trabajador
- * @Param vBarcode se puede pasar tanto el smarttag como el shelving
- */
- DECLARE vIsShelvingFk BOOL;
-
- SELECT COUNT(*) > 0 INTO vIsShelvingFk
- FROM vn.shelving s
- WHERE s.code = vBarcode COLLATE utf8_general_ci;
-
- IF NOT vIsShelvingFk THEN
-
- SELECT st.shelvingFk INTO vBarcode
- FROM vn.smartTag st
- WHERE st.code = vBarcode COLLATE utf8_general_ci;
-
- END IF;
-
- INSERT INTO vn.workerShelving (workerFk, shelvingFk)
- VALUES(vWorkerFk, vBarcode);
+BEGIN
+/*
+ * Inserta en workerShelving asociando los carros al trabajador
+ * @Param vWorkerFk es id del trabajador
+ * @Param vBarcode se puede pasar tanto el smarttag como el shelving
+ */
+ DECLARE vIsShelvingFk BOOL;
+
+ SELECT COUNT(*) > 0 INTO vIsShelvingFk
+ FROM vn.shelving s
+ WHERE s.code = vBarcode COLLATE utf8_general_ci;
+
+ IF NOT vIsShelvingFk THEN
+
+ SELECT st.shelvingFk INTO vBarcode
+ FROM vn.smartTag st
+ WHERE st.code = vBarcode COLLATE utf8_general_ci;
+
+ END IF;
+
+ INSERT INTO vn.workerShelving (workerFk, shelvingFk)
+ VALUES(vWorkerFk, vBarcode);
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -89079,32 +88651,32 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerShelving_delete`(vWorkerFk INT, vBarcode VARCHAR(12))
-BEGIN
-/*
- * Borra de workerShelving el carro o etiqueta insertado por el trabajador
- * @param vWorkerFk es id del trabajador
- * @param vBarcode se puede pasar tanto el smarttag como el shelving
- */
- DECLARE vIsShelvingFk BOOL;
-
-
- SELECT COUNT(*) > 0 INTO vIsShelvingFk
- FROM vn.shelving s
- WHERE s.code = vBarcode COLLATE utf8_general_ci;
-
-
- IF NOT vIsShelvingFk THEN
-
- SELECT st.shelvingFk INTO vBarcode
- FROM vn.smartTag st
- WHERE st.code = vBarcode COLLATE utf8_general_ci;
-
- END IF;
-
- DELETE FROM vn.workerShelving
- WHERE shelvingFk = vBarcode COLLATE utf8_general_ci
- AND workerFk = vWorkerFk ;
-
+BEGIN
+/*
+ * Borra de workerShelving el carro o etiqueta insertado por el trabajador
+ * @param vWorkerFk es id del trabajador
+ * @param vBarcode se puede pasar tanto el smarttag como el shelving
+ */
+ DECLARE vIsShelvingFk BOOL;
+
+
+ SELECT COUNT(*) > 0 INTO vIsShelvingFk
+ FROM vn.shelving s
+ WHERE s.code = vBarcode COLLATE utf8_general_ci;
+
+
+ IF NOT vIsShelvingFk THEN
+
+ SELECT st.shelvingFk INTO vBarcode
+ FROM vn.smartTag st
+ WHERE st.code = vBarcode COLLATE utf8_general_ci;
+
+ END IF;
+
+ DELETE FROM vn.workerShelving
+ WHERE shelvingFk = vBarcode COLLATE utf8_general_ci
+ AND workerFk = vWorkerFk ;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -89382,32 +88954,32 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_calculateOddDays`()
-BEGIN
-/*
- * Calculo de las fichadas impares por empleado y dia
- * @return tmp.workerTimeControlOddDays (userFk, dated)
- */
- SET @cont := FALSE;
- SET @lastUserFk:= NULL;
- DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlOddDays;
- CREATE TEMPORARY TABLE tmp.workerTimeControlOddDays
- SELECT sub2.userFk workerFk, sub2.dated
- FROM (SELECT userFk,
- dated,
- COUNT(*) cont2
- FROM (SELECT DATE(wtc.timed) dated,
- userFk,
- IFNULL(@cont, @cont := TRUE ),
- IF(direction = 'in' OR userFk <> @lastUserFk, @cont := @cont+1, TRUE),
- @cont cont,
- @lastUserFk := userFk
- FROM workerTimeControl wtc
- WHERE wtc.timed BETWEEN TIMESTAMPADD(YEAR,-1,CURDATE()) AND util.dayEnd(CURDATE())
- ORDER BY userFk, timed)sub
- GROUP BY cont
- HAVING cont2 MOD 2 = 1)sub2
- JOIN worker w ON w.userFk = sub2.userFk;
-
+BEGIN
+/*
+ * Calculo de las fichadas impares por empleado y dia
+ * @return tmp.workerTimeControlOddDays (userFk, dated)
+ */
+ SET @cont := FALSE;
+ SET @lastUserFk:= NULL;
+ DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlOddDays;
+ CREATE TEMPORARY TABLE tmp.workerTimeControlOddDays
+ SELECT sub2.userFk workerFk, sub2.dated
+ FROM (SELECT userFk,
+ dated,
+ COUNT(*) cont2
+ FROM (SELECT DATE(wtc.timed) dated,
+ userFk,
+ IFNULL(@cont, @cont := TRUE ),
+ IF(direction = 'in' OR userFk <> @lastUserFk, @cont := @cont+1, TRUE),
+ @cont cont,
+ @lastUserFk := userFk
+ FROM workerTimeControl wtc
+ WHERE wtc.timed BETWEEN TIMESTAMPADD(YEAR,-1,CURDATE()) AND util.dayEnd(CURDATE())
+ ORDER BY userFk, timed)sub
+ GROUP BY cont
+ HAVING cont2 MOD 2 = 1)sub2
+ JOIN worker w ON w.userFk = sub2.userFk;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -89993,314 +89565,314 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_clockIn`(vWorker INT, vTimed DATETIME, vDirection VARCHAR(10))
-BEGIN
-/**
- * Verifica si el empleado puede fichar
- * @param vWorker Identificador del trabajador
- * @param vTimed valor de la fichada, IF vTimed IS NULL vTimed = NOW()
- * @param vDirection solo se pueden pasa los valores del campo workerTimeControl.direction ENUM('in', 'out', 'middle')
- * @return Si todo es correcto, retorna el número de id la tabla workerTimeControl. Si hay algún problema, devuelve el mesaje a que se debe mostrar al usuario
- * Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá fichada a la tabla vn.workerTimeControl
- */
- DECLARE vLastIn DATETIME;
- DECLARE vLastOut DATETIME;
- DECLARE vNextIn DATETIME;
- DECLARE vLastDirection VARCHAR(6);
- DECLARE vNextDirection VARCHAR(6);
- DECLARE vDayBreak INT;
- DECLARE vShortWeekBreak INT;
- DECLARE vLongWeekBreak INT;
- DECLARE vWeekScope INT;
- DECLARE vGap INT;
- DECLARE vMailTo VARCHAR(50) DEFAULT NULL;
- DECLARE vUserName VARCHAR(50) DEFAULT NULL;
- DECLARE vIsError BOOLEAN DEFAULT FALSE;
- DECLARE vErrorMessage VARCHAR(255) DEFAULT NULL;
- DECLARE vErrorCode VARCHAR(50);
- DECLARE vDated DATE;
- DECLARE vIsAllowedToWork VARCHAR(50);
- DECLARE vDepartmentFk INT;
- DECLARE vTimedLoop INT;
- DECLARE vTimedLoopPrevious INT;
- DECLARE vHasBreakWeek BOOLEAN DEFAULT FALSE;
- DECLARE vManual BOOLEAN DEFAULT TRUE;
- DECLARE vDone INT DEFAULT FALSE;
-
- DECLARE vCursor CURSOR FOR
- SELECT UNIX_TIMESTAMP(NOW() - INTERVAL vGap SECOND)
- UNION
- SELECT UNIX_TIMESTAMP(NOW())
- UNION
- (SELECT UNIX_TIMESTAMP(timed)
- FROM workerTimeControl
- WHERE timed BETWEEN (vTimed - INTERVAL vGap SECOND) AND vTimed AND
- userFk = vWorker AND
- direction IN ('in', 'out')
- ORDER BY timed ASC);
-
- DECLARE vCursor2 CURSOR FOR
- SELECT UNIX_TIMESTAMP(NOW() - INTERVAL vGap SECOND)
- UNION
- SELECT UNIX_TIMESTAMP(NOW())
- UNION
- SELECT UNIX_TIMESTAMP(timed)
- FROM workerTimeControl
- WHERE timed BETWEEN vTimed AND (vTimed - INTERVAL vGap SECOND) AND
- userFk = vWorker AND
- direction IN ('in', 'out')
- ORDER BY timed ASC;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
-
- DECLARE EXIT HANDLER FOR SQLSTATE '45000'
- BEGIN
-
- SELECT CONCAT(u.name, '@verdnatura.es'), CONCAT(w.firstName, ' ', w.lastName)
- INTO vMailTo, vUserName
- FROM account.user u
- JOIN worker w ON w.bossFk = u.id
- WHERE w.id = vWorker;
-
- CASE vErrorCode
- WHEN 'IS_NOT_ALLOWED_FUTURE' THEN
- SELECT 'No se permite fichar a futuro' INTO vErrorMessage;
- WHEN 'INACTIVE_BUSINESS' THEN
- SELECT 'No hay un contrato en vigor' INTO vErrorMessage;
- WHEN 'IS_NOT_ALLOWED_WORK' THEN
- SELECT 'No está permitido trabajar' INTO vErrorMessage;
- WHEN 'ODD_WORKERTIMECONTROL' THEN
- SELECT 'Fichadas impares' INTO vErrorMessage;
- WHEN 'BREAK_DAY' THEN
- SELECT CONCAT('Descanso diario ', FORMAT(vDayBreak/3600, 0) , 'h.') INTO vErrorMessage;
- WHEN 'BREAK_WEEK' THEN
- SELECT CONCAT('Descanso semanal ',
- FORMAT(vShortWeekBreak / 3600,0) ,'h. / ',
- FORMAT(vLongWeekBreak / 3600, 0) ,'h.') INTO vErrorMessage;
- WHEN 'WRONG_DIRECTION' THEN
- SELECT 'Dirección incorrecta' INTO vErrorMessage;
- ELSE
- SELECT 'Error sin definir'INTO vErrorMessage;
- END CASE;
-
- SELECT vErrorMessage `error`;
- SELECT CONCAT(vUserName, ' no ha podido fichar por el siguiente problema: ', vErrorMessage) INTO vErrorMessage;
- CALL mail_insert( vMailTo, vMailTo, 'Error al fichar', vErrorMessage);
-
- END;
-
- IF (vTimed IS NULL) THEN
- SET vTimed = NOW();
- SET vManual = FALSE;
- END IF;
-
- SET vDated = DATE(vTimed);
-
- SELECT IF(pc.category_name = 'Conductor +3500kg', wc.dayBreakDriver, wc.dayBreak),
- wc.shortWeekBreak,
- wc.longWeekBreak,
- wc.weekScope
- INTO vDayBreak,
- vShortWeekBreak,
- vLongWeekBreak,
- vWeekScope
- FROM workerLabour w
- JOIN postgresql.business_labour bl ON bl.business_id = w.businessFk
- JOIN postgresql.professional_category pc ON pc.professional_category_id = bl.professional_category_id
- JOIN workerTimeControlConfig wc ON TRUE
- WHERE w.workerFk = vWorker
- AND vDated BETWEEN w.started AND IFNULL(w.ended, vDated);
-
- SELECT timed INTO vLastIn
- FROM workerTimeControl
- WHERE userFk = vWorker
- AND direction = 'in'
- AND timed < vTimed
- ORDER BY timed DESC
- LIMIT 1;
-
- SELECT timed INTO vLastOut
- FROM workerTimeControl
- WHERE userFk = vWorker
- AND direction = 'out'
- AND timed < vTimed
- ORDER BY timed DESC
- LIMIT 1;
-
- SELECT timed INTO vNextIn
- FROM workerTimeControl
- WHERE userFk = vWorker
- AND direction = 'in'
- AND timed > vTimed
- ORDER BY timed ASC
- LIMIT 1;
-
- SELECT direction INTO vNextDirection
- FROM workerTimeControl
- WHERE userFk = vWorker
- AND timed > vTimed
- ORDER BY timed ASC
- LIMIT 1;
-
- SELECT direction INTO vLastDirection
- FROM workerTimeControl
- WHERE userFk = vWorker
- AND timed < vTimed
- ORDER BY timed DESC
- LIMIT 1;
-
- -- FICHADAS A FUTURO
- IF vTimed > DATE_ADD(NOW(), INTERVAL 60 SECOND) THEN
- SET vErrorCode = 'IS_NOT_ALLOWED_FUTURE';
- CALL util.throw(vErrorCode);
- END IF;
-
- -- CONTRATO EN VIGOR
- IF vDayBreak IS NULL THEN
- SET vErrorCode = 'INACTIVE_BUSINESS';
- CALL util.throw(vErrorCode);
- END IF;
-
- -- VERIFICAR SI ESTÁ PERMITIDO TRABAJAR
- CALL timeBusiness_calculateByWorker(vWorker, vDated, vDated);
- SELECT isAllowedToWork INTO vIsAllowedToWork
- FROM tmp.timeBusinessCalculate;
- DROP TEMPORARY TABLE tmp.timeBusinessCalculate;
-
- IF NOT vIsAllowedToWork THEN
- SET vErrorCode = 'IS_NOT_ALLOWED_WORK';
- CALL util.throw(vErrorCode);
- END IF;
-
- -- DIRECCION CORRECTA
- CALL vn.workerTimeControl_direction(vWorker, vTimed);
- IF (SELECT IF(IF(option1 IN ('inMiddle', 'outMiddle'), 'middle', option1) <> vDirection
- AND IF(option2 IN ('inMiddle', 'outMiddle'), 'middle', IFNULL(option2, '')) <> vDirection, TRUE , FALSE)
- FROM tmp.workerTimeControlDirection) THEN
- SET vIsError = TRUE;
- END IF;
-
- DROP TEMPORARY TABLE tmp.workerTimeControlDirection;
- IF vIsError = TRUE THEN
- SET vErrorCode = 'WRONG_DIRECTION';
- CALL util.throw(vErrorCode);
- END IF;
-
- -- FICHADAS IMPARES
- IF (SELECT IF(vDirection = 'in', MOD(COUNT(*), 2) , IF (vDirection = 'out', NOT MOD(COUNT(*), 2), FALSE))
- FROM workerTimeControl
- WHERE userFk = vWorker
- AND timed BETWEEN vLastIn AND vTimed
- ) THEN
- SET vErrorCode = 'ODD_WORKERTIMECONTROL';
- CALL util.throw(vErrorCode);
- END IF;
-
- -- DESCANSO DIARIO
- CASE vDirection
- WHEN 'in' THEN
- IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) <= vDayBreak THEN
- SET vIsError = TRUE;
- END IF;
- WHEN 'out' THEN
- IF UNIX_TIMESTAMP(vNextIn) - UNIX_TIMESTAMP(vTimed) <= vDayBreak THEN
- SET vIsError = TRUE;
- END IF;
- ELSE BEGIN END;
- END CASE;
-
- IF vIsError THEN
- SET vErrorCode = 'BREAK_DAY';
- CALL util.throw(vErrorCode);
- END IF;
-
- -- VERIFICAR DESCANSO SEMANAL
- IF (vDirection IN('in', 'out')) THEN
- -- VERIFICA DESCANSO CORTO EN LA ÚLTIMA SEMANA
- SET vGap = vWeekScope;
- SET vTimedLoopPrevious = UNIX_TIMESTAMP((vTimed - INTERVAL vGap SECOND));
- SET vDone = FALSE;
- OPEN vCursor;
- l:LOOP
- FETCH vCursor INTO vTimedLoop;
- IF vDone THEN
- LEAVE l;
- END IF;
- IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN
- SET vHasBreakWeek = TRUE;
- LEAVE l;
- END IF;
- SET vTimedLoopPrevious = vTimedLoop;
- END LOOP l;
- CLOSE vCursor;
- -- VERIFICA DESCANSO LARGO EN LA ÚLTIMAS 2 SEMANAS
- IF NOT vHasBreakWeek THEN
- SET vGap = vWeekScope * 2;
- SET vTimedLoopPrevious = UNIX_TIMESTAMP((vTimed - INTERVAL vGap SECOND));
- SET vDone = FALSE;
- OPEN vCursor;
- l:LOOP
- FETCH vCursor INTO vTimedLoop;
- IF vDone THEN
- LEAVE l;
- END IF;
- IF vLongWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN
- SET vHasBreakWeek = TRUE;
- LEAVE l;
- END IF;
- SET vTimedLoopPrevious = vTimedLoop;
- END LOOP l;
- CLOSE vCursor;
- END IF;
-
- IF vManual THEN
- -- VERIFICA DESCANSO CORTO EN LA PRÓXIMA SEMANA
- SET vGap = vWeekScope;
- SET vTimedLoopPrevious = vTimed;
- SET vDone = FALSE;
- OPEN vCursor;
- l:LOOP
- FETCH vCursor INTO vTimedLoop;
- IF vDone THEN
- LEAVE l;
- END IF;
- IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN
- SET vHasBreakWeek = TRUE;
- LEAVE l;
- END IF;
- SET vTimedLoopPrevious = vTimedLoop;
- END LOOP l;
- CLOSE vCursor;
- -- VERIFICA DESCANSO LARGO EN LAS PRÓXIMAS 2 SEMANAS
- IF NOT vHasBreakWeek THEN
- SET vGap = vWeekScope * 2;
- SET vTimedLoopPrevious = vTimed;
- SET vDone = FALSE;
- OPEN vCursor;
- l:LOOP
- FETCH vCursor INTO vTimedLoop;
- IF vDone THEN
- LEAVE l;
- END IF;
- IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN
- SET vHasBreakWeek = TRUE;
- LEAVE l;
- END IF;
- SET vTimedLoopPrevious = vTimedLoop;
- END LOOP l;
- CLOSE vCursor;
- END IF;
- END IF;
- IF NOT vHasBreakWeek THEN
- SET vErrorCode = 'BREAK_WEEK';
- CALL util.throw(vErrorCode);
- END IF;
- END IF;
-
- -- SE PERMITE FICHAR
- INSERT INTO workerTimeControl(userFk, timed, direction, manual)
- VALUES(vWorker, vTimed, vDirection, vManual);
-
- SELECT LAST_INSERT_ID() id;
+BEGIN
+/**
+ * Verifica si el empleado puede fichar
+ * @param vWorker Identificador del trabajador
+ * @param vTimed valor de la fichada, IF vTimed IS NULL vTimed = NOW()
+ * @param vDirection solo se pueden pasa los valores del campo workerTimeControl.direction ENUM('in', 'out', 'middle')
+ * @return Si todo es correcto, retorna el número de id la tabla workerTimeControl. Si hay algún problema, devuelve el mesaje a que se debe mostrar al usuario
+ * Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá fichada a la tabla vn.workerTimeControl
+ */
+ DECLARE vLastIn DATETIME;
+ DECLARE vLastOut DATETIME;
+ DECLARE vNextIn DATETIME;
+ DECLARE vLastDirection VARCHAR(6);
+ DECLARE vNextDirection VARCHAR(6);
+ DECLARE vDayBreak INT;
+ DECLARE vShortWeekBreak INT;
+ DECLARE vLongWeekBreak INT;
+ DECLARE vWeekScope INT;
+ DECLARE vGap INT;
+ DECLARE vMailTo VARCHAR(50) DEFAULT NULL;
+ DECLARE vUserName VARCHAR(50) DEFAULT NULL;
+ DECLARE vIsError BOOLEAN DEFAULT FALSE;
+ DECLARE vErrorMessage VARCHAR(255) DEFAULT NULL;
+ DECLARE vErrorCode VARCHAR(50);
+ DECLARE vDated DATE;
+ DECLARE vIsAllowedToWork VARCHAR(50);
+ DECLARE vDepartmentFk INT;
+ DECLARE vTimedLoop INT;
+ DECLARE vTimedLoopPrevious INT;
+ DECLARE vHasBreakWeek BOOLEAN DEFAULT FALSE;
+ DECLARE vManual BOOLEAN DEFAULT TRUE;
+ DECLARE vDone INT DEFAULT FALSE;
+
+ DECLARE vCursor CURSOR FOR
+ SELECT UNIX_TIMESTAMP(NOW() - INTERVAL vGap SECOND)
+ UNION
+ SELECT UNIX_TIMESTAMP(NOW())
+ UNION
+ (SELECT UNIX_TIMESTAMP(timed)
+ FROM workerTimeControl
+ WHERE timed BETWEEN (vTimed - INTERVAL vGap SECOND) AND vTimed AND
+ userFk = vWorker AND
+ direction IN ('in', 'out')
+ ORDER BY timed ASC);
+
+ DECLARE vCursor2 CURSOR FOR
+ SELECT UNIX_TIMESTAMP(NOW() - INTERVAL vGap SECOND)
+ UNION
+ SELECT UNIX_TIMESTAMP(NOW())
+ UNION
+ SELECT UNIX_TIMESTAMP(timed)
+ FROM workerTimeControl
+ WHERE timed BETWEEN vTimed AND (vTimed - INTERVAL vGap SECOND) AND
+ userFk = vWorker AND
+ direction IN ('in', 'out')
+ ORDER BY timed ASC;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+
+ DECLARE EXIT HANDLER FOR SQLSTATE '45000'
+ BEGIN
+
+ SELECT CONCAT(u.name, '@verdnatura.es'), CONCAT(w.firstName, ' ', w.lastName)
+ INTO vMailTo, vUserName
+ FROM account.user u
+ JOIN worker w ON w.bossFk = u.id
+ WHERE w.id = vWorker;
+
+ CASE vErrorCode
+ WHEN 'IS_NOT_ALLOWED_FUTURE' THEN
+ SELECT 'No se permite fichar a futuro' INTO vErrorMessage;
+ WHEN 'INACTIVE_BUSINESS' THEN
+ SELECT 'No hay un contrato en vigor' INTO vErrorMessage;
+ WHEN 'IS_NOT_ALLOWED_WORK' THEN
+ SELECT 'No está permitido trabajar' INTO vErrorMessage;
+ WHEN 'ODD_WORKERTIMECONTROL' THEN
+ SELECT 'Fichadas impares' INTO vErrorMessage;
+ WHEN 'BREAK_DAY' THEN
+ SELECT CONCAT('Descanso diario ', FORMAT(vDayBreak/3600, 0) , 'h.') INTO vErrorMessage;
+ WHEN 'BREAK_WEEK' THEN
+ SELECT CONCAT('Descanso semanal ',
+ FORMAT(vShortWeekBreak / 3600,0) ,'h. / ',
+ FORMAT(vLongWeekBreak / 3600, 0) ,'h.') INTO vErrorMessage;
+ WHEN 'WRONG_DIRECTION' THEN
+ SELECT 'Dirección incorrecta' INTO vErrorMessage;
+ ELSE
+ SELECT 'Error sin definir'INTO vErrorMessage;
+ END CASE;
+
+ SELECT vErrorMessage `error`;
+ SELECT CONCAT(vUserName, ' no ha podido fichar por el siguiente problema: ', vErrorMessage) INTO vErrorMessage;
+ CALL mail_insert( vMailTo, vMailTo, 'Error al fichar', vErrorMessage);
+
+ END;
+
+ IF (vTimed IS NULL) THEN
+ SET vTimed = NOW();
+ SET vManual = FALSE;
+ END IF;
+
+ SET vDated = DATE(vTimed);
+
+ SELECT IF(pc.category_name = 'Conductor +3500kg', wc.dayBreakDriver, wc.dayBreak),
+ wc.shortWeekBreak,
+ wc.longWeekBreak,
+ wc.weekScope
+ INTO vDayBreak,
+ vShortWeekBreak,
+ vLongWeekBreak,
+ vWeekScope
+ FROM workerLabour w
+ JOIN postgresql.business_labour bl ON bl.business_id = w.businessFk
+ JOIN postgresql.professional_category pc ON pc.professional_category_id = bl.professional_category_id
+ JOIN workerTimeControlConfig wc ON TRUE
+ WHERE w.workerFk = vWorker
+ AND vDated BETWEEN w.started AND IFNULL(w.ended, vDated);
+
+ SELECT timed INTO vLastIn
+ FROM workerTimeControl
+ WHERE userFk = vWorker
+ AND direction = 'in'
+ AND timed < vTimed
+ ORDER BY timed DESC
+ LIMIT 1;
+
+ SELECT timed INTO vLastOut
+ FROM workerTimeControl
+ WHERE userFk = vWorker
+ AND direction = 'out'
+ AND timed < vTimed
+ ORDER BY timed DESC
+ LIMIT 1;
+
+ SELECT timed INTO vNextIn
+ FROM workerTimeControl
+ WHERE userFk = vWorker
+ AND direction = 'in'
+ AND timed > vTimed
+ ORDER BY timed ASC
+ LIMIT 1;
+
+ SELECT direction INTO vNextDirection
+ FROM workerTimeControl
+ WHERE userFk = vWorker
+ AND timed > vTimed
+ ORDER BY timed ASC
+ LIMIT 1;
+
+ SELECT direction INTO vLastDirection
+ FROM workerTimeControl
+ WHERE userFk = vWorker
+ AND timed < vTimed
+ ORDER BY timed DESC
+ LIMIT 1;
+
+ -- FICHADAS A FUTURO
+ IF vTimed > DATE_ADD(NOW(), INTERVAL 60 SECOND) THEN
+ SET vErrorCode = 'IS_NOT_ALLOWED_FUTURE';
+ CALL util.throw(vErrorCode);
+ END IF;
+
+ -- CONTRATO EN VIGOR
+ IF vDayBreak IS NULL THEN
+ SET vErrorCode = 'INACTIVE_BUSINESS';
+ CALL util.throw(vErrorCode);
+ END IF;
+
+ -- VERIFICAR SI ESTÁ PERMITIDO TRABAJAR
+ CALL timeBusiness_calculateByWorker(vWorker, vDated, vDated);
+ SELECT isAllowedToWork INTO vIsAllowedToWork
+ FROM tmp.timeBusinessCalculate;
+ DROP TEMPORARY TABLE tmp.timeBusinessCalculate;
+
+ IF NOT vIsAllowedToWork THEN
+ SET vErrorCode = 'IS_NOT_ALLOWED_WORK';
+ CALL util.throw(vErrorCode);
+ END IF;
+
+ -- DIRECCION CORRECTA
+ CALL vn.workerTimeControl_direction(vWorker, vTimed);
+ IF (SELECT IF(IF(option1 IN ('inMiddle', 'outMiddle'), 'middle', option1) <> vDirection
+ AND IF(option2 IN ('inMiddle', 'outMiddle'), 'middle', IFNULL(option2, '')) <> vDirection, TRUE , FALSE)
+ FROM tmp.workerTimeControlDirection) THEN
+ SET vIsError = TRUE;
+ END IF;
+
+ DROP TEMPORARY TABLE tmp.workerTimeControlDirection;
+ IF vIsError = TRUE THEN
+ SET vErrorCode = 'WRONG_DIRECTION';
+ CALL util.throw(vErrorCode);
+ END IF;
+
+ -- FICHADAS IMPARES
+ IF (SELECT IF(vDirection = 'in', MOD(COUNT(*), 2) , IF (vDirection = 'out', NOT MOD(COUNT(*), 2), FALSE))
+ FROM workerTimeControl
+ WHERE userFk = vWorker
+ AND timed BETWEEN vLastIn AND vTimed
+ ) THEN
+ SET vErrorCode = 'ODD_WORKERTIMECONTROL';
+ CALL util.throw(vErrorCode);
+ END IF;
+
+ -- DESCANSO DIARIO
+ CASE vDirection
+ WHEN 'in' THEN
+ IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) <= vDayBreak THEN
+ SET vIsError = TRUE;
+ END IF;
+ WHEN 'out' THEN
+ IF UNIX_TIMESTAMP(vNextIn) - UNIX_TIMESTAMP(vTimed) <= vDayBreak THEN
+ SET vIsError = TRUE;
+ END IF;
+ ELSE BEGIN END;
+ END CASE;
+
+ IF vIsError THEN
+ SET vErrorCode = 'BREAK_DAY';
+ CALL util.throw(vErrorCode);
+ END IF;
+
+ -- VERIFICAR DESCANSO SEMANAL
+ IF (vDirection IN('in', 'out')) THEN
+ -- VERIFICA DESCANSO CORTO EN LA ÚLTIMA SEMANA
+ SET vGap = vWeekScope;
+ SET vTimedLoopPrevious = UNIX_TIMESTAMP((vTimed - INTERVAL vGap SECOND));
+ SET vDone = FALSE;
+ OPEN vCursor;
+ l:LOOP
+ FETCH vCursor INTO vTimedLoop;
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+ IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN
+ SET vHasBreakWeek = TRUE;
+ LEAVE l;
+ END IF;
+ SET vTimedLoopPrevious = vTimedLoop;
+ END LOOP l;
+ CLOSE vCursor;
+ -- VERIFICA DESCANSO LARGO EN LA ÚLTIMAS 2 SEMANAS
+ IF NOT vHasBreakWeek THEN
+ SET vGap = vWeekScope * 2;
+ SET vTimedLoopPrevious = UNIX_TIMESTAMP((vTimed - INTERVAL vGap SECOND));
+ SET vDone = FALSE;
+ OPEN vCursor;
+ l:LOOP
+ FETCH vCursor INTO vTimedLoop;
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+ IF vLongWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN
+ SET vHasBreakWeek = TRUE;
+ LEAVE l;
+ END IF;
+ SET vTimedLoopPrevious = vTimedLoop;
+ END LOOP l;
+ CLOSE vCursor;
+ END IF;
+
+ IF vManual THEN
+ -- VERIFICA DESCANSO CORTO EN LA PRÓXIMA SEMANA
+ SET vGap = vWeekScope;
+ SET vTimedLoopPrevious = vTimed;
+ SET vDone = FALSE;
+ OPEN vCursor;
+ l:LOOP
+ FETCH vCursor INTO vTimedLoop;
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+ IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN
+ SET vHasBreakWeek = TRUE;
+ LEAVE l;
+ END IF;
+ SET vTimedLoopPrevious = vTimedLoop;
+ END LOOP l;
+ CLOSE vCursor;
+ -- VERIFICA DESCANSO LARGO EN LAS PRÓXIMAS 2 SEMANAS
+ IF NOT vHasBreakWeek THEN
+ SET vGap = vWeekScope * 2;
+ SET vTimedLoopPrevious = vTimed;
+ SET vDone = FALSE;
+ OPEN vCursor;
+ l:LOOP
+ FETCH vCursor INTO vTimedLoop;
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+ IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN
+ SET vHasBreakWeek = TRUE;
+ LEAVE l;
+ END IF;
+ SET vTimedLoopPrevious = vTimedLoop;
+ END LOOP l;
+ CLOSE vCursor;
+ END IF;
+ END IF;
+ IF NOT vHasBreakWeek THEN
+ SET vErrorCode = 'BREAK_WEEK';
+ CALL util.throw(vErrorCode);
+ END IF;
+ END IF;
+
+ -- SE PERMITE FICHAR
+ INSERT INTO workerTimeControl(userFk, timed, direction, manual)
+ VALUES(vWorker, vTimed, vDirection, vManual);
+
+ SELECT LAST_INSERT_ID() id;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -90992,29 +90564,19 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_sendMailByDepartment`(IN vWeek int, IN vYear int, IN vWorkerFk int)
+CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_sendMailByDepartment`(IN vDatedFrom DATETIME, IN vDatedTo DATETIME, IN vWorkerFk INT)
BEGIN
-
- /**
- * Inserta el registro de horario semanalmente de PRODUCCION, CAMARA, REPARTO, TALLER NATURAL y TALLER ARTIFICIAL en vn.mail.
- *
- * @param vWeek
- * @param vYear
- * @param vWorkerFk -> En el caso de querer generarlo para todos los empleados deberá de informarse como NULL
- */
-
- DECLARE vDateStart DATETIME;
- DECLARE vDateEnd DATETIME;
-
- SELECT CONCAT (MIN(dated), ' 00:00:00'), CONCAT (MAX(dated), ' 23:59:59') INTO vDateStart, vDateEnd
- FROM time
- WHERE year = vYear AND
- week = vWeek;
-
+/**
+ * Inserta el registro de horario semanalmente de PRODUCCION, CAMARA, REPARTO, TALLER NATURAL y TALLER ARTIFICIAL en vn.mail.
+ *
+ * @param vDatedFrom
+ * @param vDatedTo
+ * @param vWorkerFk -> En el caso de querer generarlo para todos los empleados deberá de pasarse = NULL
+ */
SET session group_concat_max_len = 15000;
DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate;
@@ -91022,15 +90584,15 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp.reportHours;
IF vWorkerFk IS NULL THEN
- CALL timeControl_calculateAll(vDateStart,vDateEnd);
- CALL timeBusiness_calculateAll(vDateStart,vDateEnd);
+ CALL timeControl_calculateAll(vDatedFrom,vDatedTo);
+ CALL timeBusiness_calculateAll(vDatedFrom,vDatedTo);
ELSE
- CALL timeControl_calculateByUser(vWorkerFk,vDateStart,vDateEnd);
- CALL timeBusiness_calculateByUser(vWorkerFk,vDateStart,vDateEnd);
+ CALL timeControl_calculateByUser(vWorkerFk,vDatedFrom,vDatedTo);
+ CALL timeBusiness_calculateByUser(vWorkerFk,vDatedFrom,vDatedTo);
END IF;
CREATE TEMPORARY TABLE tmp.reportHours
- SELECT t.dated,
+ SELECT t.dated,
IF (tm.hoursWeek IS NULL,'', GROUP_CONCAT(DATE_FORMAT(wtc.timed,'%H:%i') ORDER BY wtc.timed ASC SEPARATOR ' ') ) timeWorkDay,
SEC_TO_TIME(IFNULL(tm.timeWorkSeconds, 0)) tm,
SEC_TO_TIME(IFNULL(tc.timeWorkSeconds, 0)) tc,
@@ -91059,12 +90621,11 @@ BEGIN
LEFT JOIN client c ON c.id = w.id
WHERE wc.name NOT IN ('VNH')
AND d.hasToSendMail
- AND (wl.ended >= CURDATE() OR wl.ended IS NULL)
GROUP BY tm.userFk,t.dated
ORDER BY tm.userFk,t.dated;
INSERT INTO vn.mail (receiver, replyTo, subject, body)
- SELECT eu.email, 'laboral@verdnatura.es', CONCAT('Registro de horas semana ', vWeek, ' año ', vYear) ,
+ SELECT eu.email, 'laboral@verdnatura.es', CONCAT('Registro de horas semana ', WEEK(vDatedFrom), ' año ', YEAR(vDatedFrom)) ,
CONCAT('
@@ -91150,16 +90711,12 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_sendMailByDepartmentLauncher`()
BEGIN
- DECLARE vWeek,vYear INT;
+ DECLARE vDatedFrom, vDatedTo DATETIME;
IF (DAYNAME(CURDATE()) = 'miércoles') THEN
- SELECT week,year INTO vWeek,vYear
- FROM vn.time
- WHERE dated IN (DATE_ADD(CURDATE(), INTERVAL -10 DAY), DATE_ADD(CURDATE(), INTERVAL -4 DAY))
- GROUP BY year,week
- LIMIT 1;
-
- CALL vn.workerTimeControl_sendMailByDepartment(vWeek, vYear, NULL);
+ SELECT DATE_SUB(CURDATE(), INTERVAL 9 DAY), CONCAT(DATE_SUB(CURDATE(), INTERVAL 3 DAY), ' 23:59:59') INTO vDatedFrom, vDatedTo;
+
+ CALL vn.workerTimeControl_sendMailByDepartment(vDatedFrom, vDatedTo, NULL);
END IF;
END ;;
DELIMITER ;
@@ -92274,21 +91831,21 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getFromHasMistake`(vDepartmentFk INT)
-BEGIN
-
-/**
- * Obtiene los trabajadores de los departamentos que se les puede poner error
- * @param vDepartmentFk id del departamento
- *
- */
-
- SELECT w.id,w.firstName, w.lastName,d.name
- FROM worker w
- JOIN workerDepartment wd ON wd.workerFk = w.id
- JOIN department d ON d.id = wd.departmentFk
- WHERE d.id = vDepartmentFk
- ORDER BY firstName;
-
+BEGIN
+
+/**
+ * Obtiene los trabajadores de los departamentos que se les puede poner error
+ * @param vDepartmentFk id del departamento
+ *
+ */
+
+ SELECT w.id,w.firstName, w.lastName,d.name
+ FROM worker w
+ JOIN workerDepartment wd ON wd.workerFk = w.id
+ JOIN department d ON d.id = wd.departmentFk
+ WHERE d.id = vDepartmentFk
+ ORDER BY firstName;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -92500,17 +92057,17 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getSector`()
-BEGIN
-
-/**
- * Obtiene el sector del usuario conectado
-*/
-
- SELECT s.id,s.description,s.warehouseFk
- FROM sector s
- JOIN worker w ON w.sectorFk = s.id
- WHERE w.id = account.userGetId();
-
+BEGIN
+
+/**
+ * Obtiene el sector del usuario conectado
+*/
+
+ SELECT s.id,s.description,s.warehouseFk
+ FROM sector s
+ JOIN worker w ON w.sectorFk = s.id
+ WHERE w.id = account.userGetId();
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -92528,18 +92085,18 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_updateSector`(vSectorFk INT)
-BEGIN
-
-/**
- * ACtualiza el sector del usuario conectado
- *
- * @param vSectorFk id del sector
-*/
- UPDATE worker
- SET sectorFk = vSectorFk
- WHERE id = account.userGetId();
-
-
+BEGIN
+
+/**
+ * ACtualiza el sector del usuario conectado
+ *
+ * @param vSectorFk id del sector
+*/
+ UPDATE worker
+ SET sectorFk = vSectorFk
+ WHERE id = account.userGetId();
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -93088,37 +92645,6 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `zonePromo_Make__` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `zonePromo_Make__`()
-BEGIN
-
- INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price)
- SELECT t.id , 98, - packages, '-- DIA DE COMPRA BONIFICADO --', zp.amount
- FROM vn.ticket t
- JOIN vn.zonePromo zp ON zp.zoneFk = t.zoneFk AND zp.dated = DATE(t.shipped)
- WHERE zp.isDone = FALSE
- AND zp.dated < CURDATE()
- AND t.refFk IS NULL;
-
- UPDATE vn.zonePromo
- SET isDone = TRUE
- WHERE dated < CURDATE();
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `zone_doCalcInitialize` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -93193,23 +92719,23 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_ETD_byTime`()
-BEGIN
-
- SET @m := 0;
-
- DROP TEMPORARY TABLE IF EXISTS tmpZone;
- CREATE TEMPORARY TABLE tmpZone
- SELECT remainingVolume,
- hourTheoretical,
- @m := @m + minutesLess totalMinutes
- FROM zoneEstimatedDelivery ze
- WHERE ze.remainingVolume
- ORDER BY ze.hourTheoretical DESC;
-
- SELECT * FROM tmpZone;
-
- DROP TABLE tmpZone;
-
+BEGIN
+
+ SET @m := 0;
+
+ DROP TEMPORARY TABLE IF EXISTS tmpZone;
+ CREATE TEMPORARY TABLE tmpZone
+ SELECT remainingVolume,
+ hourTheoretical,
+ @m := @m + minutesLess totalMinutes
+ FROM zoneEstimatedDelivery ze
+ WHERE ze.remainingVolume
+ ORDER BY ze.hourTheoretical DESC;
+
+ SELECT * FROM tmpZone;
+
+ DROP TABLE tmpZone;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -93290,6 +92816,53 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `zone_getClosed` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getClosed`()
+proc:BEGIN
+/**
+ * Devuelve una tabla con las zonas cerradas para hoy
+ *
+ * @table tmp.closedZones(zoneFk, warehouseFk);
+ */
+ DROP TEMPORARY TABLE IF EXISTS tmp.closedZones;
+
+ CREATE TEMPORARY TABLE tmp.closedZones (
+ `zoneFk` int(11) NOT NULL,
+ `warehouseFk` smallint(6) unsigned NOT NULL,
+ PRIMARY KEY `zoneFk` (`zoneFk`,`warehouseFk`),
+ KEY `warehouseFk` (`warehouseFk`))
+ ENGINE=MEMORY DEFAULT CHARSET=utf8;
+
+ INSERT INTO tmp.closedZones(zoneFk, warehouseFk)
+ SELECT zoneFk, warehouseFk
+ FROM (
+ SELECT t.zoneFk, t.warehouseFk, count(DISTINCT t.id) numTickets, pc.minTicketsToCloseZone
+ FROM vn.ticket t
+ JOIN vn.expedition e ON e.ticketFk = t.id
+ JOIN vn.`zone`z on z.id = t.zoneFk
+ JOIN vn.agencyMode am ON am.id = z.agencyModeFk
+ JOIN vn.agency a ON a.id = am.agencyFk
+ JOIN vn.productionConfig pc
+ WHERE a.isOwn
+ AND pc.isZoneClosedByExpeditionActivated
+ AND e.created >= CURDATE()
+ GROUP BY t.zoneFk, t.warehouseFk
+ HAVING numTickets >= minTicketsToCloseZone) sub;
+ END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `zone_getCollisions` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -93582,34 +93155,42 @@ DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLanded`(vShipped DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT, vShowExpiredZones BOOLEAN)
BEGIN
/**
-* Devuelve una tabla temporal con el dia de recepcion para vShipped.
-*
-* @param vShipped Fecha de preparacion de mercancia
-* @param vAddressFk Id de consignatario, %NULL para recogida
-* @param vAgencyModeFk Id agencia
-* @param vWarehouseFk vWarehouseFk
-* @table tmp.zoneGetLanded Datos de recepción
-*/
+ * Devuelve una tabla temporal con el dia de recepcion para vShipped.
+ * Excluye las que tengan cajas preparadas
+ *
+ * @param vShipped Fecha de preparacion de mercancia
+ * @param vAddressFk Id de consignatario, %NULL para recogida
+ * @param vAgencyModeFk Id agencia
+ * @param vWarehouseFk vWarehouseFk
+ * @table tmp.zoneGetLanded Datos de recepción
+ */
+ CALL vn.zone_getFromGeo(address_getGeo(vAddressFk));
- CALL zone_getFromGeo(address_getGeo(vAddressFk));
- CALL zone_getOptionsForShipment(vShipped, vShowExpiredZones);
+ CALL vn.zone_getOptionsForShipment(vShipped, vShowExpiredZones);
+
+ CALL vn.zone_getClosed();
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded;
CREATE TEMPORARY TABLE tmp.zoneGetLanded
ENGINE = MEMORY
SELECT vWarehouseFk warehouseFk,
- TIMESTAMPADD(DAY,zo.travelingDays, vShipped) landed,
+ TIMESTAMPADD(DAY,zo.travelingDays, vShipped) landed,
zo.zoneFk
FROM tmp.zoneOption zo
- JOIN zone z ON z.id = zo.zoneFk
- JOIN zoneWarehouse zw ON zw.zoneFk = z.id
- WHERE agencyModeFk = vAgencyModeFk
- AND zw.warehouseFk = vWarehouseFk;
-
+ JOIN vn.`zone` z ON z.id = zo.zoneFk
+ JOIN vn.zoneWarehouse zw ON zw.zoneFk = z.id
+ LEFT JOIN tmp.closedZones cz
+ ON cz.warehouseFk = zw.warehouseFk
+ AND cz.zoneFk = zw.zoneFk
+ AND zo.shipped = CURDATE()
+ WHERE z.agencyModeFk = vAgencyModeFk
+ AND zw.warehouseFk = vWarehouseFk
+ AND (ISNULL(cz.zoneFk) OR vShowExpiredZones);
+
DROP TEMPORARY TABLE
- tmp.zone,
- tmp.zoneOption;
-
+ tmp.`zone`,
+ tmp.zoneOption,
+ tmp.closedZones;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -93736,106 +93317,106 @@ DELIMITER ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves2`(vSelf INT, vParentFk INT, vSearch VARCHAR(255))
-BEGIN
-/**
- * Devuelve los geoFk incluidos en la ruta y que sean hijos de parentFk
- * @param vSelf Id de la zona
- * @param vParentFk Id del geo a calcular
- * @param vSearch cadena a buscar
- *
- * @return tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk)
- *
- */
- DECLARE vIsNumber BOOL;
- DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch != '';
-
- DROP TEMPORARY TABLE IF EXISTS tNodes;
- CREATE TEMPORARY TABLE tNodes
- (UNIQUE (id))
- ENGINE = MEMORY
- SELECT id
- FROM zoneGeo
- LIMIT 0;
-
- IF vIsSearch THEN
- SET vIsNumber = vSearch REGEXP '^[0-9]+$';
-
- INSERT INTO tNodes
- SELECT id
- FROM zoneGeo
- WHERE (vIsNumber AND `name` = vSearch)
- OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%'))
- LIMIT 1000;
-
- ELSEIF vParentFk IS NULL THEN
- INSERT INTO tNodes
- SELECT geoFk
- FROM zoneIncluded
- WHERE zoneFk = vSelf;
- END IF;
-
- IF vParentFk IS NULL THEN
- DROP TEMPORARY TABLE IF EXISTS tChilds;
- CREATE TEMPORARY TABLE tChilds
- (INDEX(id))
- ENGINE = MEMORY
- SELECT id
- FROM tNodes;
-
- DROP TEMPORARY TABLE IF EXISTS tParents;
- CREATE TEMPORARY TABLE tParents
- (INDEX(id))
- ENGINE = MEMORY
- SELECT id
- FROM zoneGeo
- LIMIT 0;
-
- myLoop: LOOP
- DELETE FROM tParents;
- INSERT INTO tParents
- SELECT parentFk id
- FROM zoneGeo g
- JOIN tChilds c ON c.id = g.id
- WHERE g.parentFk IS NOT NULL;
-
- INSERT IGNORE INTO tNodes
- SELECT id
- FROM tParents;
-
- IF ROW_COUNT() = 0 THEN
- LEAVE myLoop;
- END IF;
-
- DELETE FROM tChilds;
- INSERT INTO tChilds
- SELECT id
- FROM tParents;
- END LOOP;
-
- DROP TEMPORARY TABLE tChilds, tParents;
- END IF;
-
- IF !vIsSearch THEN
- INSERT IGNORE INTO tNodes
- SELECT id
- FROM zoneGeo
- WHERE parentFk <=> vParentFk;
- END IF;
-
- INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk)
- SELECT g.id,
- g.`name`,
- g.parentFk,
- g.sons,
- NOT g.sons OR type = 'country',
- vSelf
- FROM zoneGeo g
- JOIN tNodes n ON n.id = g.id
- LEFT JOIN zoneIncluded i ON i.geoFk = g.id AND i.zoneFk = vSelf
- WHERE i.isIncluded = TRUE
- OR (i.isIncluded IS NULL AND vParentFk IS NOT NULL);
-
- DROP TEMPORARY TABLE tNodes;
+BEGIN
+/**
+ * Devuelve los geoFk incluidos en la ruta y que sean hijos de parentFk
+ * @param vSelf Id de la zona
+ * @param vParentFk Id del geo a calcular
+ * @param vSearch cadena a buscar
+ *
+ * @return tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk)
+ *
+ */
+ DECLARE vIsNumber BOOL;
+ DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch != '';
+
+ DROP TEMPORARY TABLE IF EXISTS tNodes;
+ CREATE TEMPORARY TABLE tNodes
+ (UNIQUE (id))
+ ENGINE = MEMORY
+ SELECT id
+ FROM zoneGeo
+ LIMIT 0;
+
+ IF vIsSearch THEN
+ SET vIsNumber = vSearch REGEXP '^[0-9]+$';
+
+ INSERT INTO tNodes
+ SELECT id
+ FROM zoneGeo
+ WHERE (vIsNumber AND `name` = vSearch)
+ OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%'))
+ LIMIT 1000;
+
+ ELSEIF vParentFk IS NULL THEN
+ INSERT INTO tNodes
+ SELECT geoFk
+ FROM zoneIncluded
+ WHERE zoneFk = vSelf;
+ END IF;
+
+ IF vParentFk IS NULL THEN
+ DROP TEMPORARY TABLE IF EXISTS tChilds;
+ CREATE TEMPORARY TABLE tChilds
+ (INDEX(id))
+ ENGINE = MEMORY
+ SELECT id
+ FROM tNodes;
+
+ DROP TEMPORARY TABLE IF EXISTS tParents;
+ CREATE TEMPORARY TABLE tParents
+ (INDEX(id))
+ ENGINE = MEMORY
+ SELECT id
+ FROM zoneGeo
+ LIMIT 0;
+
+ myLoop: LOOP
+ DELETE FROM tParents;
+ INSERT INTO tParents
+ SELECT parentFk id
+ FROM zoneGeo g
+ JOIN tChilds c ON c.id = g.id
+ WHERE g.parentFk IS NOT NULL;
+
+ INSERT IGNORE INTO tNodes
+ SELECT id
+ FROM tParents;
+
+ IF ROW_COUNT() = 0 THEN
+ LEAVE myLoop;
+ END IF;
+
+ DELETE FROM tChilds;
+ INSERT INTO tChilds
+ SELECT id
+ FROM tParents;
+ END LOOP;
+
+ DROP TEMPORARY TABLE tChilds, tParents;
+ END IF;
+
+ IF !vIsSearch THEN
+ INSERT IGNORE INTO tNodes
+ SELECT id
+ FROM zoneGeo
+ WHERE parentFk <=> vParentFk;
+ END IF;
+
+ INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk)
+ SELECT g.id,
+ g.`name`,
+ g.parentFk,
+ g.sons,
+ NOT g.sons OR type = 'country',
+ vSelf
+ FROM zoneGeo g
+ JOIN tNodes n ON n.id = g.id
+ LEFT JOIN zoneIncluded i ON i.geoFk = g.id AND i.zoneFk = vSelf
+ WHERE i.isIncluded = TRUE
+ OR (i.isIncluded IS NULL AND vParentFk IS NOT NULL);
+
+ DROP TEMPORARY TABLE tNodes;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -93852,94 +93433,94 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves___`(
- vSelf INT,
- vParentFk INT,
- vSearch VARCHAR(255)
+CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves___`(
+ vSelf INT,
+ vParentFk INT,
+ vSearch VARCHAR(255)
)
-BEGIN
- DECLARE vIsNumber BOOL;
- DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch != '';
-
- DROP TEMPORARY TABLE IF EXISTS tNodes;
- CREATE TEMPORARY TABLE tNodes
- (UNIQUE (id))
- ENGINE = MEMORY
- SELECT id FROM zoneGeo LIMIT 0;
-
- IF vIsSearch THEN
- SET vIsNumber = vSearch REGEXP '^[0-9]+$';
-
- INSERT INTO tNodes
- SELECT id FROM zoneGeo
- WHERE (vIsNumber AND `name` = vSearch)
- OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%'))
- LIMIT 1000;
- ELSEIF vParentFk IS NULL THEN
- INSERT INTO tNodes
- SELECT geoFk FROM zoneIncluded
- WHERE zoneFk = vSelf;
- END IF;
-
- IF vParentFk IS NULL THEN
- DROP TEMPORARY TABLE IF EXISTS tChilds;
- CREATE TEMPORARY TABLE tChilds
- ENGINE = MEMORY
- SELECT id FROM tNodes;
-
- DROP TEMPORARY TABLE IF EXISTS tParents;
- CREATE TEMPORARY TABLE tParents
- ENGINE = MEMORY
- SELECT id FROM zoneGeo LIMIT 0;
-
- myLoop: LOOP
- DELETE FROM tParents;
- INSERT INTO tParents
- SELECT parentFk id
- FROM zoneGeo g
- JOIN tChilds c ON c.id = g.id
- WHERE g.parentFk IS NOT NULL;
-
- INSERT IGNORE INTO tNodes
- SELECT id FROM tParents;
-
- IF ROW_COUNT() = 0 THEN
- LEAVE myLoop;
- END IF;
-
- DELETE FROM tChilds;
- INSERT INTO tChilds
- SELECT id FROM tParents;
- END LOOP;
-
- DROP TEMPORARY TABLE
- tChilds,
- tParents;
- END IF;
-
- IF !vIsSearch THEN
- INSERT IGNORE INTO tNodes
- SELECT id FROM zoneGeo
- WHERE parentFk <=> vParentFk;
- END IF;
-
-
- INSERT IGNORE INTO zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk)
- SELECT g.id,
- g.`name`,
- g.parentFk,
- g.sons,
- NOT g.sons OR type = 'country',
- vSelf
- FROM zoneGeo g
- JOIN tNodes n ON n.id = g.id
- LEFT JOIN zoneIncluded i
- ON i.geoFk = g.id AND i.zoneFk = vSelf
- WHERE (i.isIncluded = TRUE
- OR (i.isIncluded IS NULL AND vParentFk IS NOT NULL))
- ;
-
- DROP TEMPORARY TABLE tNodes;
+BEGIN
+ DECLARE vIsNumber BOOL;
+ DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch != '';
+
+ DROP TEMPORARY TABLE IF EXISTS tNodes;
+ CREATE TEMPORARY TABLE tNodes
+ (UNIQUE (id))
+ ENGINE = MEMORY
+ SELECT id FROM zoneGeo LIMIT 0;
+
+ IF vIsSearch THEN
+ SET vIsNumber = vSearch REGEXP '^[0-9]+$';
+
+ INSERT INTO tNodes
+ SELECT id FROM zoneGeo
+ WHERE (vIsNumber AND `name` = vSearch)
+ OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%'))
+ LIMIT 1000;
+ ELSEIF vParentFk IS NULL THEN
+ INSERT INTO tNodes
+ SELECT geoFk FROM zoneIncluded
+ WHERE zoneFk = vSelf;
+ END IF;
+
+ IF vParentFk IS NULL THEN
+ DROP TEMPORARY TABLE IF EXISTS tChilds;
+ CREATE TEMPORARY TABLE tChilds
+ ENGINE = MEMORY
+ SELECT id FROM tNodes;
+
+ DROP TEMPORARY TABLE IF EXISTS tParents;
+ CREATE TEMPORARY TABLE tParents
+ ENGINE = MEMORY
+ SELECT id FROM zoneGeo LIMIT 0;
+
+ myLoop: LOOP
+ DELETE FROM tParents;
+ INSERT INTO tParents
+ SELECT parentFk id
+ FROM zoneGeo g
+ JOIN tChilds c ON c.id = g.id
+ WHERE g.parentFk IS NOT NULL;
+
+ INSERT IGNORE INTO tNodes
+ SELECT id FROM tParents;
+
+ IF ROW_COUNT() = 0 THEN
+ LEAVE myLoop;
+ END IF;
+
+ DELETE FROM tChilds;
+ INSERT INTO tChilds
+ SELECT id FROM tParents;
+ END LOOP;
+
+ DROP TEMPORARY TABLE
+ tChilds,
+ tParents;
+ END IF;
+
+ IF !vIsSearch THEN
+ INSERT IGNORE INTO tNodes
+ SELECT id FROM zoneGeo
+ WHERE parentFk <=> vParentFk;
+ END IF;
+
+
+ INSERT IGNORE INTO zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk)
+ SELECT g.id,
+ g.`name`,
+ g.parentFk,
+ g.sons,
+ NOT g.sons OR type = 'country',
+ vSelf
+ FROM zoneGeo g
+ JOIN tNodes n ON n.id = g.id
+ LEFT JOIN zoneIncluded i
+ ON i.geoFk = g.id AND i.zoneFk = vSelf
+ WHERE (i.isIncluded = TRUE
+ OR (i.isIncluded IS NULL AND vParentFk IS NOT NULL))
+ ;
+
+ DROP TEMPORARY TABLE tNodes;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -94062,7 +93643,8 @@ BEGIN
l.travelingDays,
IFNULL(e.price, z.price) price,
IFNULL(e.bonus, z.bonus) bonus,
- l.landed
+ l.landed,
+ vShipped shipped
FROM tmp.zone t
JOIN zone z ON z.id = t.id
JOIN zoneEvent e ON e.zoneFk = t.id
@@ -94099,123 +93681,6 @@ BEGIN
WHERE vShipped < CURDATE()
OR (vShipped = CURDATE() AND CURTIME() > `hour`);
END IF;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-/*!50003 DROP PROCEDURE IF EXISTS `zone_getOptionsForShipment_beta` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8mb4 */ ;
-/*!50003 SET character_set_results = utf8mb4 */ ;
-/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
-/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getOptionsForShipment_beta`(vShipped DATE, vShowExpiredZones BOOLEAN)
-BEGIN
-/**
- * Gets computed options for the passed zones and shipping date.
- *
- * @table tmp.zones(id) The zones ids
- * @param vShipped The shipping date
- * @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options
- */
- DECLARE vHour TIME DEFAULT TIME(NOW());
-
- DROP TEMPORARY TABLE IF EXISTS tLandings;
- CREATE TEMPORARY TABLE tLandings
- (INDEX (eventFk))
- ENGINE = MEMORY
- SELECT e.id eventFk,
- @travelingDays := IFNULL(e.travelingDays, z.travelingDays) travelingDays,
- TIMESTAMPADD(DAY, @travelingDays, vShipped) landed
- FROM tmp.zone t
- JOIN zone z ON z.id = t.id
- JOIN zoneEvent e ON e.zoneFk = t.id;
-
- SELECT * FROM tLandings
- JOIN vn.zoneEvent ze ON ze.id = eventFk
- WHERE ze.zoneFk = 25;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption;
- CREATE TEMPORARY TABLE tmp.zoneOption
- ENGINE = MEMORY
- SELECT *
- FROM (
- SELECT t.id zoneFk,
- TIME(IFNULL(e.`hour`, z.`hour`)) `hour`,
- l.travelingDays,
- IFNULL(e.price, z.price) price,
- IFNULL(e.bonus, z.bonus) bonus,
- l.landed
- FROM tmp.zone t
- JOIN zone z ON z.id = t.id
- JOIN zoneEvent e ON e.zoneFk = t.id
- JOIN tLandings l ON l.eventFk = e.id
- WHERE (
- e.`type` = 'day'
- AND e.`dated` = l.landed
- ) OR (
- e.`type` != 'day'
- AND e.weekDays & (1 << WEEKDAY(l.landed))
- AND (e.`started` IS NULL OR l.landed >= e.`started`)
- AND (e.`ended` IS NULL OR l.landed <= e.`ended`)
- )
- ORDER BY
- zoneFk,
- CASE
- WHEN e.`type` = 'day'
- THEN -1
- WHEN e.`type` = 'range'
- THEN 2
- ELSE 3
- END
- ) t
- GROUP BY zoneFk;
-
- SELECT e.id, e.type, (e.`dated` = l.landed), e.`dated` , l.landed, t.id zoneFk,
- TIME(IFNULL(e.`hour`, z.`hour`)) `hour`,
- l.travelingDays,
- IFNULL(e.price, z.price) price,
- IFNULL(e.bonus, z.bonus) bonus,
- l.landed
- FROM tmp.zone t
- JOIN zone z ON z.id = t.id
- JOIN zoneEvent e ON e.zoneFk = t.id
- JOIN tLandings l ON l.eventFk = e.id
- WHERE zoneFk = 25
- ORDER BY
- zoneFk,
- CASE
- WHEN e.`type` = 'day'
- THEN 1
- WHEN e.`type` = 'range'
- THEN 2
- ELSE 3
- END;
-
- SELECT * FROm tmp.zoneOption WHERE zoneFk = 25;
-
- DROP TEMPORARY TABLE tLandings;
-
- DELETE t FROM tmp.zoneOption t
- JOIN zoneExclusion e
- ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed;
-
- SELECT * FROm tmp.zoneOption WHERE zoneFk = 25;
-
- IF NOT vShowExpiredZones THEN
- DELETE FROM tmp.zoneOption
- WHERE vShipped < CURDATE()
- OR (vShipped = CURDATE() AND CURTIME() > `hour`);
- END IF;
-
-
-
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -94236,36 +93701,99 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getShipped`(vLanded DATE, vAdd
BEGIN
/**
* Devuelve la mínima fecha de envío para cada warehouse
- *
+ * Excluye aquellas zonas que ya tienen cajas preparadas en ese almacén
+ *
* @param vLanded La fecha de recepcion
* @param vAddressFk Id del consignatario
* @param vAgencyModeFk Id de la agencia
* @return tmp.zoneGetShipped
- */
- CALL zone_getFromGeo(address_getGeo(vAddressFk));
- CALL zone_getOptionsForLanding(vLanded, vShowExpiredZones);
-
+ */
+ CALL vn.zone_getFromGeo(address_getGeo(vAddressFk));
+ CALL vn.zone_getOptionsForLanding(vLanded, vShowExpiredZones);
+ CALL vn.zone_getClosed();
+
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped;
CREATE TEMPORARY TABLE tmp.zoneGetShipped
ENGINE = MEMORY
SELECT * FROM (
- SELECT zo.zoneFk,
- TIMESTAMPADD(DAY,-zo.travelingDays, vLanded) shipped,
- zo.`hour`,
+ SELECT zo.zoneFk,
+ zo.shipped,
+ zo.`hour`,
zw.warehouseFk,
- z.agencyModeFk,
- zo.price,
- zo.bonus
+ z.agencyModeFk,
+ zo.price,
+ zo.bonus
FROM tmp.zoneOption zo
- JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk
- JOIN zone z ON z.id = zo.zoneFk
+ JOIN vn.zoneWarehouse zw ON zw.zoneFk = zo.zoneFk
+ JOIN vn.`zone` z ON z.id = zo.zoneFk
+ LEFT JOIN tmp.closedZones cz
+ ON cz.warehouseFk = zw.warehouseFk
+ AND cz.zoneFk = zw.zoneFk
+ AND zo.shipped = CURDATE()
WHERE z.agencyModeFk = vAgencyModeFk
- ORDER BY shipped) t
+ AND (ISNULL(cz.zoneFk) OR vShowExpiredZones)
+ ORDER BY shipped) t
GROUP BY warehouseFk;
-
+
DROP TEMPORARY TABLE
- tmp.zone,
- tmp.zoneOption;
+ tmp.`zone`,
+ tmp.zoneOption,
+ tmp.closedZones;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+/*!50003 DROP PROCEDURE IF EXISTS `zone_getState` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8mb4 */ ;
+/*!50003 SET character_set_results = utf8mb4 */ ;
+/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
+/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
+/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getState`(vDated DATE)
+BEGIN
+/**
+ * Devuelve las zonas y el estado para la fecha solicitada
+ *
+ * @param vDated Fecha en cuestión
+ */
+ DROP TEMPORARY TABLE IF EXISTS tmp.zone;
+
+ CREATE TEMPORARY TABLE tmp.zone (
+ id INT PRIMARY KEY)
+ ENGINE=MEMORY;
+
+ INSERT INTO tmp.zone(id)
+ SELECT id
+ FROM vn.zone;
+
+ CALL vn.zone_getOptionsForShipment(vDated, TRUE);
+
+ CALL vn.zone_getClosed();
+
+ SELECT zo.zoneFk,
+ zo.`hour`etd,
+ (zo.`hour` <= TIME(now())) isLate,
+ !ISNULL(cz.zoneFk) isFull,
+ zw.warehouseFk,
+ zo.landed
+ FROM tmp.zoneOption zo
+ JOIN vn.zone z ON z.id = zo.zoneFk
+ JOIN vn.zoneWarehouse zw ON zw.zoneFk = z.id
+ LEFT JOIN tmp.closedZones cz
+ ON cz.warehouseFk = zw.warehouseFk
+ AND cz.zoneFk = zo.zoneFk;
+
+ DROP TEMPORARY TABLE
+ tmp.closedZones,
+ tmp.zoneOption,
+ tmp.zone;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -94522,19 +94050,19 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vncontrol`.`ticketTracking_afterInsert`
- AFTER INSERT ON `inter`
- FOR EACH ROW
-BEGIN
-
- DECLARE vNumTicketsPrepared INT;
-
- REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name)
- SELECT NEW.Id_Ticket, NEW.inter_id, `name`
- FROM vn.state
- WHERE id = NEW.state_id;
-
-
+/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vncontrol`.`ticketTracking_afterInsert`
+ AFTER INSERT ON `inter`
+ FOR EACH ROW
+BEGIN
+
+ DECLARE vNumTicketsPrepared INT;
+
+ REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name)
+ SELECT NEW.Id_Ticket, NEW.inter_id, `name`
+ FROM vn.state
+ WHERE id = NEW.state_id;
+
+
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -95882,6 +95410,25 @@ USE `vn`;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
+--
+-- Final view structure for view `agencyTerm`
+--
+
+/*!50001 DROP TABLE IF EXISTS `agencyTerm`*/;
+/*!50001 DROP VIEW IF EXISTS `agencyTerm`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
+/*!50001 VIEW `agencyTerm` AS select `sat`.`agencyFk` AS `agencyFk`,`sat`.`minimumPackages` AS `minimumPackages`,`sat`.`kmPrice` AS `kmPrice`,`sat`.`packagePrice` AS `packagePrice`,`sat`.`routePrice` AS `routePrice`,`sat`.`minimumKm` AS `minimumKm`,`sat`.`minimumM3` AS `minimumM3`,`sat`.`m3Price` AS `m3Price` from `supplierAgencyTerm` `sat` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
--
-- Final view structure for view `annualAverageInvoiced`
--
@@ -97150,26 +96697,7 @@ USE `vn`;
/*!50001 SET collation_connection = utf8mb4_unicode_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
-/*!50001 VIEW `itemShelvingPlacementSupplyStock` AS select `ish`.`id` AS `itemShelvingFk`,`ish`.`itemFk` AS `itemFk`,`ish`.`quantity` AS `quantity`,`ish`.`packing` AS `packing`,`ish`.`visible` AS `stock`,`i`.`longName` AS `longName`,`i`.`size` AS `size`,`i`.`subName` AS `subName`,`sh`.`code` AS `shelving`,`p`.`code` AS `parking`,`ish`.`created` AS `created`,ifnull(`sh`.`priority`,1) AS `priority`,`p`.`id` AS `parkingFk`,`p`.`sectorFk` AS `sectorFk` from (((`itemShelving` `ish` join `shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) left join `parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) join `item` `i` on((`i`.`id` = `ish`.`itemFk`))) group by `ish`.`id` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `itemShelvingPlacementSupplyStock__`
---
-
-/*!50001 DROP TABLE IF EXISTS `itemShelvingPlacementSupplyStock__`*/;
-/*!50001 DROP VIEW IF EXISTS `itemShelvingPlacementSupplyStock__`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8mb4 */;
-/*!50001 SET character_set_results = utf8mb4 */;
-/*!50001 SET collation_connection = utf8mb4_unicode_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
-/*!50001 VIEW `itemShelvingPlacementSupplyStock__` AS select `ish`.`id` AS `itemShelvingFk`,`ish`.`itemFk` AS `itemFk`,`ish`.`quantity` AS `quantity`,`ish`.`packing` AS `packing`,`ish`.`visible` AS `stock`,`i`.`longName` AS `longName`,`i`.`size` AS `size`,`i`.`subName` AS `subName`,`sh`.`code` AS `shelving`,`p`.`code` AS `parking`,`ish`.`created` AS `created`,ifnull(`sh`.`priority`,1) AS `priority` from (((((`itemShelving` `ish` join `shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) left join `parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) join `item` `i` on((`i`.`id` = `ish`.`itemFk`))) left join `itemShelvingSale` `iss` on((`iss`.`itemShelvingFk` = `ish`.`id`))) left join `itemShelvingPlacementSupply` `isps` on((`isps`.`itemShelvingFk` = `ish`.`id`))) group by `ish`.`id` */;
+/*!50001 VIEW `itemShelvingPlacementSupplyStock` AS select `ish`.`id` AS `itemShelvingFk`,`ish`.`itemFk` AS `itemFk`,`ish`.`packing` AS `packing`,`ish`.`visible` AS `stock`,`i`.`longName` AS `longName`,`i`.`size` AS `size`,`i`.`subName` AS `subName`,`sh`.`code` AS `shelving`,`p`.`code` AS `parking`,`ish`.`created` AS `created`,ifnull(`sh`.`priority`,1) AS `priority`,`p`.`id` AS `parkingFk`,`p`.`sectorFk` AS `sectorFk` from (((`itemShelving` `ish` join `shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) left join `parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) join `item` `i` on((`i`.`id` = `ish`.`itemFk`))) group by `ish`.`id` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
@@ -97535,25 +97063,6 @@ USE `vn`;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
---
--- Final view structure for view `packingSite`
---
-
-/*!50001 DROP TABLE IF EXISTS `packingSite`*/;
-/*!50001 DROP VIEW IF EXISTS `packingSite`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8mb4 */;
-/*!50001 SET character_set_results = utf8mb4 */;
-/*!50001 SET collation_connection = utf8mb4_unicode_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
-/*!50001 VIEW `packingSite` AS select `h`.`code` AS `hostFk`,`h`.`printerFk` AS `printerFk`,concat(`h`.`itemPackingTypeFk`,`h`.`packingSite`) AS `code` from `host` `h` where (`h`.`itemPackingTypeFk` is not null) order by `h`.`itemPackingTypeFk`,`h`.`packingSite` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
--
-- Final view structure for view `payDemDetail__`
--
@@ -98095,11 +97604,11 @@ USE `vn`;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 SET character_set_client = utf8mb4 */;
+/*!50001 SET character_set_results = utf8mb4 */;
+/*!50001 SET collation_connection = utf8mb4_unicode_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`$itBoss`@`%` SQL SECURITY DEFINER */
+/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
/*!50001 VIEW `ticketLocation` AS select `tl`.`Id_Ticket` AS `ticketFk`,`tl`.`longitude` AS `longitude`,`tl`.`latitude` AS `latitude` from `vn2008`.`ticket_location` `tl` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
@@ -98690,4 +98199,4 @@ USE `vncontrol`;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2022-03-28 9:44:10
+-- Dump completed on 2022-05-04 15:56:23
diff --git a/db/export-data.sh b/db/export-data.sh
index 135047f04..900e630f7 100755
--- a/db/export-data.sh
+++ b/db/export-data.sh
@@ -14,6 +14,8 @@ echo "" > "$DUMPED_FILE"
TABLES=(
util
config
+ version
+ versionLog
)
dump_tables ${TABLES[@]}
@@ -74,10 +76,20 @@ dump_tables ${TABLES[@]}
TABLES=(
hedera
+ browser
imageCollection
+ imageCollectionSize
+ language
+ link
+ location
+ menu
+ message
+ metatag
+ newsTag
+ restPriv
+ social
tpvError
tpvResponse
- imageCollectionSize
)
dump_tables ${TABLES[@]}
diff --git a/db/export-structure.sh b/db/export-structure.sh
index d9729879d..388231306 100755
--- a/db/export-structure.sh
+++ b/db/export-structure.sh
@@ -49,6 +49,7 @@ IGNORETABLES=(
--ignore-table=vn.grantGroup
--ignore-table=vn.invoiceCorrection__
--ignore-table=vn.itemTaxCountrySpain
+ --ignore-table=vn.itemShelvingPlacementSupplyStock__
--ignore-table=vn.itemFreeNumber__
--ignore-table=vn.mail__
--ignore-table=vn.manaSpellers
diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js
index 799eb8fe7..29176489c 100644
--- a/e2e/helpers/selectors.js
+++ b/e2e/helpers/selectors.js
@@ -731,7 +731,7 @@ export default {
claimAction: {
importClaimButton: 'vn-claim-action vn-button[label="Import claim"]',
anyLine: 'vn-claim-action vn-tbody > vn-tr',
- firstDeleteLine: 'vn-claim-action vn-tr:nth-child(1) vn-icon-button[icon="delete"]',
+ firstDeleteLine: 'vn-claim-action tr:nth-child(1) vn-icon-button[icon="delete"]',
isPaidWithManaCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.isChargedToMana"]'
},
ordersIndex: {
@@ -982,8 +982,8 @@ export default {
save: 'vn-invoice-in-basic-data button[type=submit]'
},
invoiceInTax: {
- addTaxButton: 'vn-invoice-in-tax vn-icon-button[icon="add_circle"]',
- thirdExpence: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-autocomplete[ng-model="invoiceInTax.expenseFk"]',
+ addTaxButton: 'vn-invoice-in-tax vn-icon-button[vn-tooltip="Add tax"]',
+ thirdExpense: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-autocomplete[ng-model="invoiceInTax.expenseFk"]',
thirdTaxableBase: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-input-number[ng-model="invoiceInTax.taxableBase"]',
thirdTaxType: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-autocomplete[ng-model="invoiceInTax.taxTypeSageFk"]',
thirdTransactionType: 'vn-invoice-in-tax vn-horizontal:nth-child(3) > vn-autocomplete[ng-model="invoiceInTax.transactionTypeSageFk"]',
@@ -1133,7 +1133,7 @@ export default {
entryLatestBuys: {
firstBuy: 'vn-entry-latest-buys tbody > tr:nth-child(1)',
allBuysCheckBox: 'vn-entry-latest-buys thead vn-check',
- secondBuyCheckBox: 'vn-entry-latest-buys tbody tr:nth-child(2) vn-check[ng-model="buy.$checked"]',
+ secondBuyCheckBox: 'vn-entry-latest-buys tbody tr:nth-child(2) vn-check[ng-model="buy.checked"]',
editBuysButton: 'vn-entry-latest-buys vn-button[icon="edit"]',
fieldAutocomplete: 'vn-autocomplete[ng-model="$ctrl.editedColumn.field"]',
newValueInput: 'vn-textfield[ng-model="$ctrl.editedColumn.newValue"]',
diff --git a/e2e/helpers/tests.js b/e2e/helpers/tests.js
new file mode 100644
index 000000000..aac9963dd
--- /dev/null
+++ b/e2e/helpers/tests.js
@@ -0,0 +1,87 @@
+require('@babel/register')({presets: ['@babel/env']});
+require('core-js/stable');
+require('regenerator-runtime/runtime');
+
+const axios = require('axios');
+const Docker = require('../../db/docker.js');
+const e2eConfig = require('./config.js');
+const log = require('fancy-log');
+
+process.on('warning', warning => {
+ console.log(warning.name);
+ console.log(warning.message);
+ console.log(warning.stack);
+});
+
+async function test() {
+ if (process.argv[2] === 'show')
+ process.env.E2E_SHOW = true;
+
+ const container = new Docker('salix-db');
+
+ await container.run();
+
+ const Jasmine = require('jasmine');
+ const jasmine = new Jasmine();
+
+ const specFiles = [
+ `./e2e/paths/01*/*[sS]pec.js`,
+ `./e2e/paths/02*/*[sS]pec.js`,
+ `./e2e/paths/03*/*[sS]pec.js`,
+ `./e2e/paths/04*/*[sS]pec.js`,
+ `./e2e/paths/05*/*[sS]pec.js`,
+ `./e2e/paths/06*/*[sS]pec.js`,
+ `./e2e/paths/07*/*[sS]pec.js`,
+ `./e2e/paths/08*/*[sS]pec.js`,
+ `./e2e/paths/09*/*[sS]pec.js`,
+ `./e2e/paths/10*/*[sS]pec.js`,
+ `./e2e/paths/11*/*[sS]pec.js`,
+ `./e2e/paths/12*/*[sS]pec.js`,
+ `./e2e/paths/13*/*[sS]pec.js`,
+ `./e2e/paths/**/*[sS]pec.js`
+ ];
+
+ jasmine.loadConfig({
+ spec_dir: '.',
+ spec_files: specFiles,
+ helpers: [],
+ random: false,
+ });
+
+ await backendStatus();
+
+ jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
+ await jasmine.execute();
+}
+
+async function backendStatus() {
+ log('Awaiting backend connection...');
+
+ const milliseconds = 1000;
+ const maxAttempts = 10;
+
+ return new Promise(resolve => {
+ let timer;
+ let attempts = 1;
+ timer = setInterval(async() => {
+ try {
+ attempts++;
+ const url = `${e2eConfig.url}/api/Applications/status`;
+ const {data} = await axios.get(url);
+
+ if (data == true) {
+ clearInterval(timer);
+ log('Backend connection stablished!');
+ resolve(attempts);
+ }
+ } catch (error) {
+ if (error && attempts >= maxAttempts) {
+ log('Could not connect to backend');
+ process.exit();
+ }
+ }
+ }, milliseconds);
+ });
+}
+
+test();
diff --git a/e2e/paths/02-client/12_lock_of_verified_data.spec.js b/e2e/paths/02-client/12_lock_of_verified_data.spec.js
index 701531c76..af42e2a4b 100644
--- a/e2e/paths/02-client/12_lock_of_verified_data.spec.js
+++ b/e2e/paths/02-client/12_lock_of_verified_data.spec.js
@@ -111,7 +111,7 @@ describe('Client lock verified data path', () => {
await page.waitToClick(selectors.clientFiscalData.saveButton);
const message = await page.waitForSnackbar();
- expect(message.text).toContain(`You can't make changes on a client with verified data`);
+ expect(message.text).toContain(`Not enough privileges to edit a client with verified data`);
});
});
@@ -123,19 +123,19 @@ describe('Client lock verified data path', () => {
await page.accessToSection('client.card.fiscalData');
}, 20000);
- it('should confirm verified data button is enabled for salesAssistant', async() => {
+ it('should confirm verified data button is disabled for salesAssistant', async() => {
const isDisabled = await page.isDisabled(selectors.clientFiscalData.verifiedDataCheckbox);
- expect(isDisabled).toBeFalsy();
+ expect(isDisabled).toBeTrue();
});
- it('should now edit the social name', async() => {
+ it('should return error when edit the social name', async() => {
await page.clearInput(selectors.clientFiscalData.socialName);
await page.write(selectors.clientFiscalData.socialName, 'new social name edition');
await page.waitToClick(selectors.clientFiscalData.saveButton);
const message = await page.waitForSnackbar();
- expect(message.text).toContain('Data saved!');
+ expect(message.text).toContain(`Not enough privileges to edit a client with verified data`);
});
it('should now confirm the social name have been edited once and for all', async() => {
diff --git a/e2e/paths/09-invoice-in/04_tax.spec.js b/e2e/paths/09-invoice-in/04_tax.spec.js
index 364a25d7e..b1dbe2008 100644
--- a/e2e/paths/09-invoice-in/04_tax.spec.js
+++ b/e2e/paths/09-invoice-in/04_tax.spec.js
@@ -19,7 +19,7 @@ describe('InvoiceIn tax path', () => {
it('should add a new tax', async() => {
await page.waitToClick(selectors.invoiceInTax.addTaxButton);
- await page.autocompleteSearch(selectors.invoiceInTax.thirdExpence, '6210000567');
+ await page.autocompleteSearch(selectors.invoiceInTax.thirdExpense, '6210000567');
await page.write(selectors.invoiceInTax.thirdTaxableBase, '100');
await page.autocompleteSearch(selectors.invoiceInTax.thirdTaxType, '6');
await page.autocompleteSearch(selectors.invoiceInTax.thirdTransactionType, 'Operaciones exentas');
@@ -37,9 +37,9 @@ describe('InvoiceIn tax path', () => {
expect(result).toEqual('Taxable base €1,323.16');
});
- it('should navigate back to the tax section and check the reciently added line contains the expected expense', async() => {
+ it('should navigate back to tax section, check the reciently added line contains the expected expense', async() => {
await page.accessToSection('invoiceIn.card.tax');
- const result = await page.waitToGetProperty(selectors.invoiceInTax.thirdExpence, 'value');
+ const result = await page.waitToGetProperty(selectors.invoiceInTax.thirdExpense, 'value');
expect(result).toEqual('6210000567: Alquiler VNH');
});
diff --git a/front/core/components/multi-check/locale/en.yml b/front/core/components/multi-check/locale/en.yml
new file mode 100644
index 000000000..ea52dcf8f
--- /dev/null
+++ b/front/core/components/multi-check/locale/en.yml
@@ -0,0 +1 @@
+SelectAllRows: Select the {{rows}} row(s)
\ No newline at end of file
diff --git a/front/core/components/multi-check/locale/es.yml b/front/core/components/multi-check/locale/es.yml
new file mode 100644
index 000000000..5365c3392
--- /dev/null
+++ b/front/core/components/multi-check/locale/es.yml
@@ -0,0 +1,3 @@
+SelectAllRows: Seleccionar las {{rows}} fila(s)
+All: Se han seleccionado
+row(s) have been selected.: fila(s).
\ No newline at end of file
diff --git a/front/core/components/multi-check/multi-check.html b/front/core/components/multi-check/multi-check.html
index fb950aaff..fe485e19b 100644
--- a/front/core/components/multi-check/multi-check.html
+++ b/front/core/components/multi-check/multi-check.html
@@ -2,4 +2,25 @@
ng-model="$ctrl.checked"
indeterminate="$ctrl.isIndeterminate"
translate-attr="{title: 'Check all'}">
-
\ No newline at end of file
+
+
+ |
+ Id | +Ticket | +Destination | +Landed | +Quantity | +Description | +Price | +Disc. | +Total | +
---|---|---|---|---|---|---|---|---|---|
+ |
+
+ |
+
|
+ {{::saleClaimed.landed | date: 'dd/MM/yyyy'}} | +{{::saleClaimed.quantity}} | +{{::saleClaimed.concept}} | +{{::saleClaimed.price | currency: 'EUR':2}} | +{{::saleClaimed.discount}} % | +{{saleClaimed.total | currency: 'EUR':2}} | +
|
+