Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into puppeteer
This commit is contained in:
commit
e922a05e50
|
@ -3,5 +3,8 @@
|
|||
// Carácter predeterminado de final de línea.
|
||||
"files.eol": "\n",
|
||||
"vsicons.presets.angular": false,
|
||||
"eslint.autoFixOnSave": true
|
||||
"eslint.autoFixOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
}
|
||||
}
|
|
@ -8,19 +8,17 @@ pipeline {
|
|||
environment {
|
||||
PROJECT_NAME = 'salix'
|
||||
REGISTRY = 'registry.verdnatura.es'
|
||||
DOCKER_HOST_1 = 'vch1.verdnatura.es'
|
||||
DOCKER_HOST_2 = 'vch2.verdnatura.es'
|
||||
PORT_MASTER_FRONT = '5002'
|
||||
PORT_MASTER_BACK = '3001-3002'
|
||||
PORT_MASTER_BACK = '3001'
|
||||
PORT_TEST_FRONT = '5001'
|
||||
PORT_TEST_BACK = '4001-4002'
|
||||
PORT_TEST_BACK = '4001'
|
||||
TAG = "${env.BRANCH_NAME}"
|
||||
}
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
script {
|
||||
env.COMPOSE_PROJECT_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
|
||||
env.STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
|
||||
|
||||
if (!env.GIT_COMMITTER_EMAIL) {
|
||||
env.COMMITTER_EMAIL = sh(
|
||||
|
@ -65,18 +63,23 @@ pipeline {
|
|||
}
|
||||
}
|
||||
stage('Test') {
|
||||
when { not { anyOf {
|
||||
branch 'test'
|
||||
branch 'master'
|
||||
}}}
|
||||
environment {
|
||||
NODE_ENV = ""
|
||||
FIREFOX_BIN = "/opt/firefox/firefox-bin"
|
||||
}
|
||||
steps {
|
||||
nodejs('node-lts') {
|
||||
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=1'
|
||||
sh 'gulp backTestDockerOnce --junit --random'
|
||||
parallel {
|
||||
stage('Frontend') {
|
||||
steps {
|
||||
nodejs('node-lts') {
|
||||
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=1'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Backend') {
|
||||
steps {
|
||||
nodejs('node-lts') {
|
||||
sh 'gulp backTestDockerOnce --junit --random'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,32 +106,8 @@ pipeline {
|
|||
branch 'test'
|
||||
branch 'master'
|
||||
}}
|
||||
environment {
|
||||
DOCKER_TLS_VERIFY = 1
|
||||
}
|
||||
parallel {
|
||||
stage('Host 1') {
|
||||
environment {
|
||||
DOCKER_HOST = "tcp://${env.DOCKER_HOST_1}:2376"
|
||||
}
|
||||
steps {
|
||||
withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) {
|
||||
sh 'docker-compose pull'
|
||||
sh 'docker-compose up -d --scale back=2'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Host 2') {
|
||||
environment {
|
||||
DOCKER_HOST = "tcp://${env.DOCKER_HOST_2}:2376"
|
||||
}
|
||||
steps {
|
||||
withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) {
|
||||
sh 'docker-compose pull'
|
||||
sh 'docker-compose up -d --scale back=2'
|
||||
}
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
|
||||
}
|
||||
}
|
||||
stage('Database') {
|
||||
|
@ -147,15 +126,6 @@ pipeline {
|
|||
sh 'db/import-changes.sh -f $NODE_ENV'
|
||||
}
|
||||
}
|
||||
stage('Cleanup') {
|
||||
when { anyOf {
|
||||
branch 'test'
|
||||
branch 'master'
|
||||
}}
|
||||
steps {
|
||||
sh 'docker logout $REGISTRY'
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
|
|
|
@ -31,26 +31,23 @@ module.exports = Self => {
|
|||
const recipient = to.replace('@', '');
|
||||
|
||||
if (sender.name != recipient)
|
||||
return sendMessage(to, `@${sender.name}: ${message}`);
|
||||
return sendMessage(sender, to, `@${sender.name}: ${message} `);
|
||||
};
|
||||
|
||||
async function sendMessage(name, message) {
|
||||
const models = Self.app.models;
|
||||
const chatConfig = await models.ChatConfig.findOne();
|
||||
async function sendMessage(sender, channel, message) {
|
||||
const config = await getConfig();
|
||||
|
||||
if (!Self.token)
|
||||
Self.token = await login();
|
||||
|
||||
const uri = `${chatConfig.uri}/chat.postMessage`;
|
||||
return send(uri, {
|
||||
'channel': name,
|
||||
const avatar = `${config.host}/avatar/${sender.name}`;
|
||||
const uri = `${config.api}/chat.postMessage`;
|
||||
return sendAuth(uri, {
|
||||
'channel': channel,
|
||||
'avatar': avatar,
|
||||
'text': message
|
||||
}).catch(async error => {
|
||||
if (error.statusCode === 401 && !Self.loginAttempted) {
|
||||
Self.token = await login();
|
||||
Self.loginAttempted = true;
|
||||
if (error.statusCode === 401 && !this.resendAttempted) {
|
||||
this.resendAttempted = true;
|
||||
|
||||
return sendMessage(name, message);
|
||||
return sendMessage(sender, channel, message);
|
||||
}
|
||||
|
||||
throw new Error(error.message);
|
||||
|
@ -61,24 +58,51 @@ module.exports = Self => {
|
|||
* Returns a rocketchat token
|
||||
* @return {Object} userId and authToken
|
||||
*/
|
||||
async function login() {
|
||||
const models = Self.app.models;
|
||||
const chatConfig = await models.ChatConfig.findOne();
|
||||
const uri = `${chatConfig.uri}/login`;
|
||||
return send(uri, {
|
||||
user: chatConfig.user,
|
||||
password: chatConfig.password
|
||||
}).then(res => res.data);
|
||||
async function getAuthToken() {
|
||||
if (!this.auth || this.auth && !this.auth.authToken) {
|
||||
const config = await getConfig();
|
||||
const uri = `${config.api}/login`;
|
||||
const res = await send(uri, {
|
||||
user: config.user,
|
||||
password: config.password
|
||||
});
|
||||
|
||||
this.auth = res.data;
|
||||
}
|
||||
|
||||
return this.auth;
|
||||
}
|
||||
|
||||
function send(uri, body) {
|
||||
/**
|
||||
* Returns a rocketchat config
|
||||
* @return {Object} Auth config
|
||||
*/
|
||||
async function getConfig() {
|
||||
if (!this.chatConfig) {
|
||||
const models = Self.app.models;
|
||||
|
||||
this.chatConfig = await models.ChatConfig.findOne();
|
||||
}
|
||||
|
||||
return this.chatConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send unauthenticated request
|
||||
* @param {*} uri - Request uri
|
||||
* @param {*} body - Request params
|
||||
* @param {*} options - Request options
|
||||
*
|
||||
* @return {Object} Request response
|
||||
*/
|
||||
async function send(uri, body, options) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
return new Promise(resolve => {
|
||||
return resolve({statusCode: 200, message: 'Fake notification sent'});
|
||||
});
|
||||
}
|
||||
|
||||
const options = {
|
||||
const defaultOptions = {
|
||||
method: 'POST',
|
||||
uri: uri,
|
||||
body: body,
|
||||
|
@ -86,11 +110,29 @@ module.exports = Self => {
|
|||
json: true
|
||||
};
|
||||
|
||||
if (Self.token) {
|
||||
options.headers['X-Auth-Token'] = Self.token.authToken;
|
||||
options.headers['X-User-Id'] = Self.token.userId;
|
||||
if (options) Object.assign(defaultOptions, options);
|
||||
|
||||
return request(defaultOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send authenticated request
|
||||
* @param {*} uri - Request uri
|
||||
* @param {*} body - Request params
|
||||
*
|
||||
* @return {Object} Request response
|
||||
*/
|
||||
async function sendAuth(uri, body) {
|
||||
const login = await getAuthToken();
|
||||
const options = {
|
||||
headers: {'content-type': 'application/json'}
|
||||
};
|
||||
|
||||
if (login) {
|
||||
options.headers['X-Auth-Token'] = login.authToken;
|
||||
options.headers['X-User-Id'] = login.userId;
|
||||
}
|
||||
|
||||
return request(options);
|
||||
return send(uri, body, options);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -13,7 +13,10 @@
|
|||
"type": "Number",
|
||||
"description": "Identifier"
|
||||
},
|
||||
"uri": {
|
||||
"host": {
|
||||
"type": "String"
|
||||
},
|
||||
"api": {
|
||||
"type": "String"
|
||||
},
|
||||
"user": {
|
||||
|
|
|
@ -14,5 +14,13 @@
|
|||
"description": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
DROP procedure IF EXISTS `vn`.`catalog_calculate`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`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 vClient INT;
|
||||
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
|
||||
|
||||
SELECT clientFk INTO vClient
|
||||
FROM address WHERE id = vAddressFk;
|
||||
|
||||
CALL vn.zoneGetShippedWarehouse(vLanded, vAddressFk, vAgencyModeFk);
|
||||
|
||||
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',
|
||||
KEY `itemFk` (`itemFk`),
|
||||
KEY `item_warehouse` (`itemFk`,`warehouseFk`) USING HASH
|
||||
) 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)
|
||||
SELECT vWarehouseFk,
|
||||
i.item_id,
|
||||
IFNULL(i.available, 0),
|
||||
bu.buyFk
|
||||
FROM `cache`.available i
|
||||
JOIN tmp.item br ON br.itemFk = i.item_id
|
||||
LEFT JOIN item it ON it.id = i.item_id
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.item_id
|
||||
WHERE i.calc_id = vAvailableCalc
|
||||
AND it.id != 100
|
||||
AND i.available > 0;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END LOOP;
|
||||
|
||||
CLOSE cTravelTree;
|
||||
|
||||
CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem;
|
||||
CREATE TEMPORARY TABLE tmp.ticketCalculateItem
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
b.itemFk,
|
||||
SUM(b.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 b
|
||||
JOIN item i ON b.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 MIN(price) price, itemFk, priceKg
|
||||
FROM tmp.ticketComponentPrice
|
||||
GROUP BY itemFk
|
||||
) bl ON bl.itemFk = b.itemFk
|
||||
GROUP BY b.itemFk;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
|
||||
DROP FUNCTION IF EXISTS `vn`.`address_getGeo`;
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`address_getGeo` (vSelf INT)
|
||||
RETURNS INT
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
/**
|
||||
* Returns the geo for the passed address.
|
||||
*
|
||||
* @param vSelf The address id
|
||||
* @return The geo id
|
||||
*/
|
||||
DECLARE vGeoFk INT;
|
||||
|
||||
SELECT p.geoFk INTO vGeoFk
|
||||
FROM address a
|
||||
JOIN town t ON t.provinceFk = a.provinceFk
|
||||
JOIN postCode p ON p.townFk = t.id AND p.`code` = a.postalCode
|
||||
WHERE a.id = vSelf
|
||||
ORDER BY (a.city SOUNDS LIKE t.`name`) DESC
|
||||
LIMIT 1;
|
||||
|
||||
RETURN vGeoFk;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
USE `vn`;
|
||||
|
||||
CREATE TABLE `vn`.`zoneWarehouse` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`zoneFk` int(11) NOT NULL,
|
||||
`warehouseFk` smallint(6) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `zoneFk` (`zoneFk`,`warehouseFk`),
|
||||
KEY `warehouseFk` (`warehouseFk`),
|
||||
CONSTRAINT `zoneWarehouse_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE/*,
|
||||
CONSTRAINT `zoneWarehouse_ibfk_2` FOREIGN KEY (`warehouseFk`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE*/
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `vn`.`zoneEvent` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`zoneFk` int(11) NOT NULL,
|
||||
`from` date DEFAULT NULL,
|
||||
`to` date DEFAULT NULL,
|
||||
`weekDays` set('mon','tue','wed','thu','fri','sat','sun') NOT NULL,
|
||||
`hour` datetime DEFAULT NULL,
|
||||
`travelingDays` int(11) DEFAULT NULL,
|
||||
`price` decimal(10,2) DEFAULT NULL,
|
||||
`bonus` decimal(10,2) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `zoneFk` (`zoneFk`),
|
||||
CONSTRAINT `zoneEvent_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;
|
||||
|
||||
ALTER TABLE `vn`.`zoneEvent`
|
||||
ADD COLUMN `type` ENUM('day', 'indefinitely', 'range') NOT NULL AFTER `zoneFk`,
|
||||
ADD COLUMN `dated` DATE NULL DEFAULT NULL AFTER `type`,
|
||||
CHANGE COLUMN `from` `started` DATE NULL DEFAULT NULL ,
|
||||
CHANGE COLUMN `to` `ended` DATE NULL DEFAULT NULL ;
|
||||
|
||||
CREATE TABLE `vn`.`zoneExclusion` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`zoneFk` int(11) NOT NULL,
|
||||
`day` date NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `zoneFk_2` (`zoneFk`,`day`),
|
||||
KEY `zoneFk` (`zoneFk`),
|
||||
CONSTRAINT `zoneExclusion_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
|
||||
ALTER TABLE `vn`.`zone`
|
||||
DROP FOREIGN KEY `fk_zone_1`;
|
||||
ALTER TABLE `vn`.`zone`
|
||||
CHANGE COLUMN `warehouseFk` `warehouseFk` SMALLINT(6) UNSIGNED NULL DEFAULT NULL ;
|
||||
ALTER TABLE `vn`.`zone`
|
||||
ADD CONSTRAINT `fk_zone_1`
|
||||
FOREIGN KEY (`warehouseFk`)
|
||||
REFERENCES `vn`.`warehouse` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `vn`.`zoneExclusion`
|
||||
CHANGE COLUMN `day` `dated` DATE NOT NULL ;
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
DROP PROCEDURE IF EXISTS `vn`.`zone_getAvailable`;
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zone_getAvailable`(vAddress INT, vLanded DATE)
|
||||
BEGIN
|
||||
CALL zone_getFromGeo(address_getGeo(vAddress));
|
||||
CALL zone_getOptionsForLanding(vLanded);
|
||||
|
||||
SELECT * FROM tmp.zoneOption;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.zone,
|
||||
tmp.zoneOption;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zone_getEvents`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents`(
|
||||
vProvinceFk INT,
|
||||
vPostCode VARCHAR(255),
|
||||
vAgencyModeFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Returns available events for the passed province/postcode and agency.
|
||||
*
|
||||
* @param vAgencyModeFk The agency mode id
|
||||
* @param vProvinceFk The province id
|
||||
* @param vPostCode The postcode or %NULL to use the province
|
||||
*/
|
||||
DECLARE vGeoFk INT;
|
||||
|
||||
IF vPostCode IS NOT NULL THEN
|
||||
SELECT p.geoFk INTO vGeoFk
|
||||
FROM postCode p
|
||||
JOIN town t ON t.id = p.townFk
|
||||
WHERE p.`code` = vPostCode
|
||||
AND t.provinceFk = vProvinceFk;
|
||||
ELSE
|
||||
SELECT geoFk INTO vGeoFk
|
||||
FROM province
|
||||
WHERE id = vProvinceFk;
|
||||
END IF;
|
||||
|
||||
CALL zone_getFromGeo(vGeoFk);
|
||||
|
||||
IF vAgencyModeFk IS NOT NULL THEN
|
||||
DELETE t FROM tmp.zone t
|
||||
JOIN zone z ON z.id = t.id
|
||||
WHERE z.agencyModeFk != vAgencyModeFk;
|
||||
END IF;
|
||||
|
||||
SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays
|
||||
FROM tmp.zone t
|
||||
JOIN zoneEvent e ON e.zoneFk = t.id;
|
||||
|
||||
SELECT e.zoneFk, e.dated
|
||||
FROM tmp.zone t
|
||||
JOIN zoneExclusion e ON e.zoneFk = t.id;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.zone;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
|
||||
DROP PROCEDURE IF EXISTS `vn`.`zone_getFromGeo`;
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zone_getFromGeo`(vGeoFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Returns all zones which have the passed geo included.
|
||||
*
|
||||
* @param vGeoFk The geo id
|
||||
* @return tmp.zone(id) The list of zones
|
||||
*/
|
||||
DECLARE vChildFk INT DEFAULT vGeoFk;
|
||||
DECLARE vParentFk INT;
|
||||
DECLARE vLevel INT DEFAULT 1;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tNodes;
|
||||
CREATE TEMPORARY TABLE tNodes
|
||||
(PRIMARY KEY (id))
|
||||
ENGINE = MEMORY
|
||||
SELECT vGeoFk id, vLevel `level`;
|
||||
|
||||
myLoop: LOOP
|
||||
SELECT parentFk INTO vParentFk
|
||||
FROM zoneGeo
|
||||
WHERE id = vChildFk;
|
||||
|
||||
SET vChildFk = vParentFk;
|
||||
SET vLevel = vLevel + 1;
|
||||
|
||||
INSERT IGNORE INTO tNodes
|
||||
SELECT vChildFk, vLevel
|
||||
FROM DUAL
|
||||
WHERE vChildFk IS NOT NULL;
|
||||
|
||||
IF ROW_COUNT() = 0 THEN
|
||||
LEAVE myLoop;
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.zone;
|
||||
CREATE TEMPORARY TABLE tmp.zone
|
||||
(INDEX (id))
|
||||
ENGINE = MEMORY
|
||||
SELECT id FROM (
|
||||
SELECT zoneFk id, isIncluded
|
||||
FROM (
|
||||
SELECT i.zoneFk, i.isIncluded
|
||||
FROM tNodes n
|
||||
JOIN zoneIncluded i ON i.geoFk = n.id
|
||||
ORDER BY zoneFk, n.`level`
|
||||
) t
|
||||
GROUP BY id HAVING isIncluded
|
||||
) t;
|
||||
|
||||
DROP TEMPORARY TABLE tNodes;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
|
||||
DROP procedure IF EXISTS `vn`.`zone_getLeaves`;
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`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;
|
||||
|
||||
SELECT g.id,
|
||||
g.`name`,
|
||||
g.parentFk,
|
||||
g.sons,
|
||||
isIncluded selected
|
||||
FROM zoneGeo g
|
||||
JOIN tNodes n ON n.id = g.id
|
||||
LEFT JOIN zoneIncluded i
|
||||
ON i.geoFk = g.id AND i.zoneFk = vSelf
|
||||
ORDER BY depth, selected DESC, `name`;
|
||||
|
||||
DROP TEMPORARY TABLE tNodes;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,42 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zone_getAgency`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getAgency`(vAddress INT, vLanded DATE)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve el listado de agencias disponibles para la fecha
|
||||
* y dirección pasadas.
|
||||
*
|
||||
* @param vAddress Id de dirección de envío, %NULL si es recogida
|
||||
* @param vLanded Fecha de recogida
|
||||
* @select Listado de agencias disponibles
|
||||
*/
|
||||
|
||||
CALL zone_getFromGeo(address_getGeo(vAddress));
|
||||
CALL zone_getOptionsForLanding(vLanded);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetAgency;
|
||||
CREATE TEMPORARY TABLE tmp.zoneGetAgency
|
||||
(INDEX (agencyModeFk)) ENGINE = MEMORY
|
||||
SELECT am.name agencyMode,
|
||||
am.description,
|
||||
z.agencyModeFk,
|
||||
am.deliveryMethodFk,
|
||||
TIMESTAMPADD(DAY,-zo.travelingDays, vLanded) shipped,
|
||||
TRUE isIncluded,
|
||||
zo.zoneFk
|
||||
FROM tmp.zoneOption zo
|
||||
JOIN zone z ON z.id = zo.zoneFk
|
||||
JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||
GROUP BY agencyModeFk;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.zone,
|
||||
tmp.zoneOption;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zone_getFirstShipped`;
|
|
@ -1,40 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zone_getLanded`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getLanded`(vShipped DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT)
|
||||
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
|
||||
*/
|
||||
|
||||
CALL zone_getFromGeo(address_getGeo(vAddressFk));
|
||||
CALL zone_getOptionsForLanding(vShipped);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded;
|
||||
CREATE TEMPORARY TABLE tmp.zoneGetLanded
|
||||
ENGINE = MEMORY
|
||||
SELECT vWarehouseFk warehouseFk,
|
||||
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;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.zone,
|
||||
tmp.zoneOption;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zone_getShippedWarehouse`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getShippedWarehouse`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve la mÃnima fecha de envÃo para cada warehouse
|
||||
*
|
||||
* @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);
|
||||
|
||||
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,
|
||||
zw.warehouseFk,
|
||||
z.agencyModeFk
|
||||
FROM tmp.zoneOption zo
|
||||
JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk
|
||||
JOIN zone z ON z.id = zo.zoneFk
|
||||
WHERE z.agencyModeFk = vAgencyModeFk
|
||||
ORDER BY shipped) t
|
||||
GROUP BY warehouseFk;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.zone,
|
||||
tmp.zoneOption;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zone_getWarehouse`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse`(vAddress INT, vLanded DATE, vWarehouse INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve el listado de agencias disponibles para la fecha,
|
||||
* dirección y almacén pasados.
|
||||
*
|
||||
* @param vAddress
|
||||
* @param vWarehouse warehouse
|
||||
* @param vLanded Fecha de recogida
|
||||
* @select Listado de agencias disponibles
|
||||
*/
|
||||
|
||||
CALL zone_getFromGeo(address_getGeo(vAddress));
|
||||
CALL zone_getOptionsForLanding(vLanded);
|
||||
|
||||
SELECT am.id agencyModeFk,
|
||||
am.name agencyMode,
|
||||
am.description,
|
||||
am.deliveryMethodFk,
|
||||
TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped,
|
||||
zw.warehouseFk,
|
||||
z.id zoneFk
|
||||
FROM tmp.zoneOption zo
|
||||
JOIN zone z ON z.id = zo.zoneFk
|
||||
JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||
JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk
|
||||
WHERE zw.warehouseFk
|
||||
GROUP BY z.agencyModeFk
|
||||
ORDER BY agencyMode;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.zone,
|
||||
tmp.zoneOption;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
USE `vn`;
|
||||
DROP procedure IF EXISTS `vn`.`zoneGetAgency`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetAgency`(vAddress INT, vLanded DATE)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve el listado de agencias disponibles para la fecha
|
||||
* y dirección pasadas.
|
||||
*
|
||||
* @param vAddress Id de dirección de envío, %NULL si es recogida
|
||||
* @param vDate Fecha de recogida
|
||||
* @select Listado de agencias disponibles
|
||||
*/
|
||||
|
||||
CALL zone_getAgency(vAddress,vLanded);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
;
|
|
@ -1,3 +0,0 @@
|
|||
|
||||
USE `vn`;
|
||||
DROP procedure IF EXISTS `vn`.`zoneGetFirstShipped`;
|
|
@ -1,20 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zoneGetLanded`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetLanded`(vShipped DATE, vAddress INT, vAgencyMode INT, vWarehouse INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve una tabla temporal con el dia de recepcion para vShipped.
|
||||
*
|
||||
* @param vShipped Fecha de preparacion de mercancia
|
||||
* @param vAddress Id de consignatario, %NULL para recogida
|
||||
* @param vAgencyMode Id agencia
|
||||
* @table tmp.zoneGetLanded Datos de recepción
|
||||
*/
|
||||
CALL zone_getLanded(vShipped,vAddress,vAgencyMode,vWarehouse);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zoneGetShipped`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetShipped`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* OBSOLETO usar zone_getShippedWarehouse
|
||||
* Devuelve la mínima fecha de envía para cada warehouse
|
||||
*
|
||||
* @param vLanded La fecha de recepcion
|
||||
* @param vAddressFk Id del consignatario
|
||||
* @param vAgencyModeFk Id de la agencia
|
||||
* @return tmp.zoneGetShipped
|
||||
*/
|
||||
CALL zone_getShippedWarehouse(vLanded, vAddressFk, vAgencyModeFk);
|
||||
|
||||
SELECT * FROM tmp.zoneGetShipped WHERE warehouseFk <> vWarehouseFk;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zoneGetShippedWarehouse`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetShippedWarehouse`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve la mínima fecha de envío para cada warehouse
|
||||
*
|
||||
* @param vLanded La fecha de recepcion
|
||||
* @param vAddressFk Id del consignatario
|
||||
* @param vAgencyModeFk Id de la agencia
|
||||
* @return tmp.zoneGetShipped
|
||||
*/
|
||||
CALL zone_getShippedWarehouse(vLanded, vAddressFk, vAgencyModeFk);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zone_getOptionsForLanding`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getOptionsForLanding`(vLanded DATE)
|
||||
BEGIN
|
||||
/**
|
||||
* Gets computed options for the passed zones and delivery date.
|
||||
*
|
||||
* @table tmp.zones(id) The zones ids
|
||||
* @param vLanded The delivery date
|
||||
* @return tmp.zoneOption The computed options
|
||||
*/
|
||||
DECLARE vHour TIME DEFAULT TIME(NOW());
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tTemp;
|
||||
CREATE TEMPORARY TABLE tTemp
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id zoneFk,
|
||||
IFNULL(TIME(e.`hour`), TIME(z.`hour`)) `hour`,
|
||||
IFNULL(e.travelingDays, z.travelingDays) travelingDays,
|
||||
IFNULL(e.price, z.price) price,
|
||||
IFNULL(e.bonus, z.bonus) bonus,
|
||||
CASE
|
||||
WHEN e.`type` = 'day'
|
||||
THEN 1
|
||||
WHEN e.`type` = 'range'
|
||||
THEN 2
|
||||
ELSE 3
|
||||
END specificity
|
||||
FROM tmp.zone t
|
||||
JOIN zone z ON z.id = t.id
|
||||
JOIN zoneEvent e ON e.zoneFk = t.id
|
||||
WHERE (
|
||||
e.`type` = 'day'
|
||||
AND e.dated = vLanded
|
||||
) OR (
|
||||
e.`type` != 'day'
|
||||
AND e.weekDays & (1 << WEEKDAY(vLanded))
|
||||
AND (e.`started` IS NULL OR vLanded >= e.`started`)
|
||||
AND (e.`ended` IS NULL OR vLanded <= e.`ended`)
|
||||
);
|
||||
|
||||
DELETE t FROM tTemp t
|
||||
JOIN zoneExclusion e
|
||||
ON e.zoneFk = t.zoneFk AND e.`dated` = vLanded;
|
||||
|
||||
DELETE FROM tTemp
|
||||
WHERE (@shipped := TIMESTAMPADD(DAY, -travelingDays, vLanded)) < CURDATE()
|
||||
OR @shipped = CURDATE() AND vHour > `hour`;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption;
|
||||
CREATE TEMPORARY TABLE tmp.zoneOption
|
||||
ENGINE = MEMORY
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT * FROM tTemp
|
||||
ORDER BY zoneFk, specificity
|
||||
) t
|
||||
GROUP BY zoneFk;
|
||||
|
||||
DROP TEMPORARY TABLE tTemp;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `zone_getOptionsForShipment`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getOptionsForShipment`(vShipped DATE)
|
||||
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
|
||||
*/
|
||||
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;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tTemp;
|
||||
CREATE TEMPORARY TABLE tTemp
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id zoneFk,
|
||||
IFNULL(TIME(e.`hour`), TIME(z.`hour`)) `hour`,
|
||||
IFNULL(e.price, z.price) price,
|
||||
IFNULL(e.bonus, z.bonus) bonus,
|
||||
CASE
|
||||
WHEN e.`type` = 'day'
|
||||
THEN 1
|
||||
WHEN e.`type` = 'range'
|
||||
THEN 2
|
||||
ELSE 3
|
||||
END specificity,
|
||||
l.travelingDays,
|
||||
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`)
|
||||
);
|
||||
|
||||
DELETE t FROM tTemp t
|
||||
JOIN zoneExclusion e
|
||||
ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption;
|
||||
CREATE TEMPORARY TABLE tmp.zoneOption
|
||||
ENGINE = MEMORY
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT * FROM tTemp
|
||||
ORDER BY zoneFk, specificity
|
||||
) t
|
||||
GROUP BY zoneFk;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tTemp,
|
||||
tLandings;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1 +0,0 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Claim', 'updateClaimAction', 'WRITE', 'ALLOW', 'ROLE', 'salesAssistant');
|
|
@ -1,2 +0,0 @@
|
|||
UPDATE `vn`.`claimState` SET `roleFk` = '21' WHERE (`id` = '3');
|
||||
UPDATE `vn`.`claimState` SET `roleFk` = '21' WHERE (`id` = '5');
|
|
@ -1,15 +0,0 @@
|
|||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`component` AS
|
||||
SELECT
|
||||
`t`.`Id_Componente` AS `id`,
|
||||
`t`.`Componente` AS `name`,
|
||||
`t`.`tarifa_componentes_series_id` AS `typeFk`,
|
||||
`t`.`tarifa_class` AS `classRate`,
|
||||
`t`.`tax` AS `tax`,
|
||||
`t`.`is_renewable` AS `isRenewable`,
|
||||
`t`.`code` AS `code`
|
||||
FROM
|
||||
`bi`.`tarifa_componentes` `t`;
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
UPDATE vn.department SET lft = NULL, rgt = NULL;
|
|
@ -1,37 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `department_calcTree`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `department_calcTree`()
|
||||
BEGIN
|
||||
/**
|
||||
* Calculates the #path, #lft, #rgt, #sons and #depth columns of
|
||||
* the #department table. To build the tree, it uses the #parentFk
|
||||
* column.
|
||||
*/
|
||||
DECLARE vIndex INT DEFAULT 0;
|
||||
DECLARE vSons INT;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tNestedTree;
|
||||
CREATE TEMPORARY TABLE tNestedTree
|
||||
SELECT id, path, lft, rgt, depth, sons
|
||||
FROM department LIMIT 0;
|
||||
|
||||
SET max_sp_recursion_depth = 5;
|
||||
CALL department_calcTreeRec(NULL, '/', 0, vIndex, vSons);
|
||||
SET max_sp_recursion_depth = 0;
|
||||
|
||||
UPDATE department z
|
||||
JOIN tNestedTree t ON t.id = z.id
|
||||
SET z.path = t.path,
|
||||
z.lft = t.lft,
|
||||
z.rgt = t.rgt,
|
||||
z.depth = t.depth,
|
||||
z.sons = t.sons;
|
||||
|
||||
DROP TEMPORARY TABLE tNestedTree;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `department_calcTreeRec`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `department_calcTreeRec`(
|
||||
vSelf INT,
|
||||
vPath VARCHAR(255),
|
||||
vDepth INT,
|
||||
INOUT vIndex INT,
|
||||
OUT vSons INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calculates and sets the #path, #lft, #rgt, #sons and #depth
|
||||
* columns for all children of the passed node. Once calculated
|
||||
* the last node rgt index and the number of sons are returned.
|
||||
* To update it's children, this procedure calls itself recursively
|
||||
* for each one.
|
||||
*
|
||||
* @vSelf The node identifier
|
||||
* @vPath The initial path
|
||||
* @vDepth The initial depth
|
||||
* @vIndex The initial lft index
|
||||
* @vSons The number of direct sons
|
||||
*/
|
||||
DECLARE vChildFk INT;
|
||||
DECLARE vLft INT;
|
||||
DECLARE vMySons INT;
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vChildren CURSOR FOR
|
||||
SELECT id FROM department
|
||||
WHERE (vSelf IS NULL AND parentFk IS NULL)
|
||||
OR (vSelf IS NOT NULL AND parentFk = vSelf);
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
SET vSons = 0;
|
||||
|
||||
OPEN vChildren;
|
||||
myLoop: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vChildren INTO vChildFk;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE myLoop;
|
||||
END IF;
|
||||
|
||||
SET vIndex = vIndex + 1;
|
||||
SET vLft = vIndex;
|
||||
SET vSons = vSons + 1;
|
||||
|
||||
CALL department_calcTreeRec(
|
||||
vChildFk,
|
||||
CONCAT(vPath, vChildFk, '/'),
|
||||
vDepth + 1,
|
||||
vIndex,
|
||||
vMySons
|
||||
);
|
||||
|
||||
SET vIndex = vIndex + 1;
|
||||
|
||||
INSERT INTO tNestedTree
|
||||
SET id = vChildFk,
|
||||
path = vPath,
|
||||
lft = vLft,
|
||||
rgt = vIndex,
|
||||
depth = vDepth,
|
||||
sons = vMySons;
|
||||
END LOOP;
|
||||
CLOSE vChildren;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `department_doCalc`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `department_doCalc`()
|
||||
proc: BEGIN
|
||||
/**
|
||||
* Recalculates the department tree.
|
||||
*/
|
||||
DECLARE vIsChanged BOOL;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
DO RELEASE_LOCK('vn.department_doCalc');
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
IF !GET_LOCK('vn.department_doCalc', 0) THEN
|
||||
LEAVE proc;
|
||||
END IF;
|
||||
|
||||
SELECT isChanged INTO vIsChanged
|
||||
FROM department_recalc;
|
||||
|
||||
IF vIsChanged THEN
|
||||
UPDATE department_recalc SET isChanged = FALSE;
|
||||
CALL vn.department_calcTree;
|
||||
END IF;
|
||||
|
||||
DO RELEASE_LOCK('vn.department_doCalc');
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `department_getLeaves`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `department_getLeaves`(
|
||||
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 department LIMIT 0;
|
||||
|
||||
IF vIsSearch THEN
|
||||
SET vIsNumber = vSearch REGEXP '^[0-9]+$';
|
||||
|
||||
INSERT INTO tNodes
|
||||
SELECT id FROM department
|
||||
WHERE (vIsNumber AND `name` = vSearch)
|
||||
OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%'))
|
||||
LIMIT 1000;
|
||||
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 department LIMIT 0;
|
||||
|
||||
myLoop: LOOP
|
||||
DELETE FROM tParents;
|
||||
INSERT INTO tParents
|
||||
SELECT parentFk id
|
||||
FROM department 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 department
|
||||
WHERE parentFk <=> vParentFk;
|
||||
END IF;
|
||||
|
||||
SELECT d.id,
|
||||
d.`name`,
|
||||
d.parentFk,
|
||||
d.sons
|
||||
FROM department d
|
||||
JOIN tNodes n ON n.id = d.id
|
||||
ORDER BY depth, `name`;
|
||||
|
||||
DROP TEMPORARY TABLE tNodes;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
ALTER TABLE `vn`.`route`
|
||||
ADD COLUMN `zoneFk` INT NULL AFTER `description`,
|
||||
ADD INDEX `fk_route_1_idx` (`zoneFk` ASC);
|
||||
;
|
||||
ALTER TABLE `vn`.`route`
|
||||
ADD CONSTRAINT `fk_route_1`
|
||||
FOREIGN KEY (`zoneFk`)
|
||||
REFERENCES `vn`.`zone` (`id`)
|
||||
ON DELETE RESTRICT
|
||||
ON UPDATE CASCADE;
|
|
@ -1 +0,0 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('UserPhone', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
|
@ -1,18 +0,0 @@
|
|||
CREATE TABLE `vn`.`travelLog` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`originFk` int(10) unsigned NOT NULL,
|
||||
`userFk` int(10) unsigned DEFAULT NULL,
|
||||
`action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
|
||||
`creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`description` text CHARACTER SET utf8,
|
||||
`changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`oldInstance` text COLLATE utf8_unicode_ci,
|
||||
`newInstance` text COLLATE utf8_unicode_ci,
|
||||
`changedModelId` int(11) DEFAULT NULL,
|
||||
`changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `originFk` (`originFk`),
|
||||
KEY `userFk` (`userFk`),
|
||||
CONSTRAINT `travelLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn`.`travel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `travelLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
|
@ -1,6 +0,0 @@
|
|||
CREATE TABLE `vn`.`packagingConfig` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`upperGap` INT NOT NULL,
|
||||
PRIMARY KEY (`id`));
|
||||
|
||||
INSERT INTO `vn`.`packagingConfig` (`upperGap`) VALUES ('10');
|
|
@ -1,18 +0,0 @@
|
|||
CREATE TABLE `vn`.`userLog` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`originFk` int(10) unsigned NOT NULL,
|
||||
`userFk` int(10) unsigned DEFAULT NULL,
|
||||
`action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
|
||||
`creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`description` text CHARACTER SET utf8,
|
||||
`changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`oldInstance` text COLLATE utf8_unicode_ci,
|
||||
`newInstance` text COLLATE utf8_unicode_ci,
|
||||
`changedModelId` int(11) DEFAULT NULL,
|
||||
`changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `originFk` (`originFk`),
|
||||
KEY `userFk` (`userFk`),
|
||||
CONSTRAINT `userLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `userLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
|
@ -1,9 +0,0 @@
|
|||
CREATE TABLE `vn`.`userPhoneType` (
|
||||
`code` VARCHAR(45) NOT NULL,
|
||||
`description` VARCHAR(255) NULL,
|
||||
PRIMARY KEY (`code`));
|
||||
|
||||
|
||||
|
||||
INSERT INTO `vn`.`userPhoneType` (`code`, `description`) VALUES ('businessPhone', 'Telefono de empresa del usuario');
|
||||
INSERT INTO `vn`.`userPhoneType` (`code`, `description`) VALUES ('personalPhone', 'Telefono personal del usuario');
|
|
@ -1,23 +0,0 @@
|
|||
CREATE TABLE `vn`.`userPhone` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`userFk` INT(10) UNSIGNED NOT NULL,
|
||||
`typeFk` VARCHAR(45) NOT NULL,
|
||||
`phone` VARCHAR(25) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `UserFk_Phone` (`userFk` ASC, `typeFk` ASC, `phone` ASC));
|
||||
|
||||
|
||||
ALTER TABLE `vn`.`userPhone`
|
||||
ADD CONSTRAINT `fgnTypeFk`
|
||||
FOREIGN KEY (typeFk)
|
||||
REFERENCES `vn`.`userPhoneType` (code)
|
||||
ON DELETE RESTRICT
|
||||
ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE `vn`.`userPhone`
|
||||
ADD CONSTRAINT `fgnUserFk`
|
||||
FOREIGN KEY (userFk)
|
||||
REFERENCES `account`.`user` (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE;
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
|
||||
USE `vn`;
|
||||
DROP procedure IF EXISTS `vn`.`ticketCalculate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculate__`(
|
||||
vLanded DATE,
|
||||
vAddressFk INT,
|
||||
vAgencyModeFk INT)
|
||||
proc: BEGIN
|
||||
-- OBSOLETO utilizar catalog_calculate
|
||||
CALL vn.catalog_calculate(vLanded, vAddressFk, vAgencyModeFk);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
;
|
|
@ -1,63 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `available_calc`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `available_calc`(
|
||||
vDate DATE,
|
||||
vAddress INT,
|
||||
vAgencyMode INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Calculates the available for all available stores
|
||||
* according to the given parameters.
|
||||
*
|
||||
* @param vDate The delivery date
|
||||
* @param vAddress The delivery address id
|
||||
* @param vAgencyMode The shipping agency
|
||||
* @return tmp.availableCalc(calcFk) The available cache ids
|
||||
*/
|
||||
DECLARE vCalcFk INT;
|
||||
DECLARE vShipment DATE;
|
||||
DECLARE vWarehouse INT;
|
||||
DECLARE vDone BOOL;
|
||||
|
||||
DECLARE cWarehouses CURSOR FOR
|
||||
SELECT warehouseFk, shipped FROM tmp.zoneGetShipped;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||
SET vDone = TRUE;
|
||||
|
||||
-- Establecemos los almacenes y las fechas que van a entrar al disponible
|
||||
|
||||
CALL vn.zone_getShippedWarehouse(vDate, vAddress, vAgencyMode);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.availableCalc;
|
||||
CREATE TEMPORARY TABLE tmp.availableCalc(
|
||||
calcFk INT UNSIGNED,
|
||||
PRIMARY KEY (calcFk)
|
||||
)
|
||||
ENGINE = MEMORY;
|
||||
|
||||
OPEN cWarehouses;
|
||||
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH cWarehouses INTO vWarehouse, vShipment;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
CALL `cache`.available_refresh(vCalcFk, FALSE, vWarehouse, vShipment);
|
||||
|
||||
INSERT IGNORE INTO tmp.availableCalc
|
||||
SET calcFk = vCalcFk;
|
||||
END LOOP;
|
||||
|
||||
CLOSE cWarehouses;
|
||||
DROP TEMPORARY TABLE tmp.zoneGetShipped;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `catalog_calculate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` 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 vClient INT;
|
||||
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
|
||||
|
||||
SELECT clientFk INTO vClient
|
||||
FROM address WHERE id = vAddressFk;
|
||||
|
||||
CALL vn.zone_getShippedWarehouse(vLanded, vAddressFk, vAgencyModeFk);
|
||||
|
||||
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',
|
||||
KEY `itemFk` (`itemFk`),
|
||||
KEY `item_warehouse` (`itemFk`,`warehouseFk`) USING HASH
|
||||
) 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)
|
||||
SELECT vWarehouseFk,
|
||||
i.item_id,
|
||||
IFNULL(i.available, 0),
|
||||
bu.buyFk
|
||||
FROM `cache`.available i
|
||||
JOIN tmp.item br ON br.itemFk = i.item_id
|
||||
LEFT JOIN item it ON it.id = i.item_id
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.item_id
|
||||
WHERE i.calc_id = vAvailableCalc
|
||||
AND it.id != 100
|
||||
AND i.available > 0;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END LOOP;
|
||||
|
||||
CLOSE cTravelTree;
|
||||
|
||||
CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem;
|
||||
CREATE TEMPORARY TABLE tmp.ticketCalculateItem
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
b.itemFk,
|
||||
SUM(b.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 b
|
||||
JOIN item i ON b.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 MIN(price) price, itemFk, priceKg
|
||||
FROM tmp.ticketComponentPrice
|
||||
GROUP BY itemFk
|
||||
) bl ON bl.itemFk = b.itemFk
|
||||
GROUP BY b.itemFk;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,244 +0,0 @@
|
|||
USE `hedera`;
|
||||
DROP procedure IF EXISTS `order_confirmWithUser`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `hedera`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `order_confirmWithUser`(IN `vOrder` INT, IN `vUserId` INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Confirms an order, creating each of its tickets on the corresponding
|
||||
* date, store and user.
|
||||
*
|
||||
* @param vOrder The order identifier
|
||||
* @param vUser The user identifier
|
||||
*/
|
||||
DECLARE vOk BOOL;
|
||||
DECLARE vDone BOOL DEFAULT FALSE;
|
||||
DECLARE vWarehouse INT;
|
||||
DECLARE vShipment DATETIME;
|
||||
DECLARE vTicket INT;
|
||||
DECLARE vNotes VARCHAR(255);
|
||||
DECLARE vItem INT;
|
||||
DECLARE vConcept VARCHAR(30);
|
||||
DECLARE vAmount INT;
|
||||
DECLARE vPrice DECIMAL(10,2);
|
||||
DECLARE vSale INT;
|
||||
DECLARE vRate INT;
|
||||
DECLARE vRowId INT;
|
||||
DECLARE vDelivery DATE;
|
||||
DECLARE vAddress INT;
|
||||
DECLARE vIsConfirmed BOOL;
|
||||
DECLARE vClientId INT;
|
||||
DECLARE vCompanyId INT;
|
||||
DECLARE vAgencyModeId INT;
|
||||
|
||||
DECLARE TICKET_FREE INT DEFAULT 2;
|
||||
|
||||
DECLARE cDates CURSOR FOR
|
||||
SELECT zgs.shipped, r.warehouse_id
|
||||
FROM `order` o
|
||||
JOIN order_row r ON r.order_id = o.id
|
||||
LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id
|
||||
WHERE o.id = vOrder AND r.amount != 0
|
||||
GROUP BY r.warehouse_id;
|
||||
|
||||
DECLARE cRows CURSOR FOR
|
||||
SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate
|
||||
FROM order_row r
|
||||
JOIN vn.item i ON i.id = r.item_id
|
||||
WHERE r.amount != 0
|
||||
AND r.warehouse_id = vWarehouse
|
||||
AND r.order_id = vOrder
|
||||
ORDER BY r.rate DESC;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||
SET vDone = TRUE;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
-- Carga los datos del pedido
|
||||
|
||||
SELECT o.date_send, o.address_id, o.note,
|
||||
o.confirmed, a.clientFk, o.company_id, o.agency_id
|
||||
INTO vDelivery, vAddress, vNotes,
|
||||
vIsConfirmed, vClientId, vCompanyId, vAgencyModeId
|
||||
FROM hedera.`order` o
|
||||
JOIN vn.address a ON a.id = o.address_id
|
||||
WHERE o.id = vOrder;
|
||||
|
||||
-- Comprueba que el pedido no está confirmado
|
||||
|
||||
IF vIsConfirmed THEN
|
||||
CALL util.throw ('ORDER_ALREADY_CONFIRMED');
|
||||
END IF;
|
||||
|
||||
-- Comprueba que el pedido no está vacío
|
||||
|
||||
SELECT COUNT(*) > 0 INTO vOk
|
||||
FROM order_row WHERE order_id = vOrder AND amount > 0;
|
||||
|
||||
IF !vOk THEN
|
||||
CALL util.throw ('ORDER_EMPTY');
|
||||
END IF;
|
||||
|
||||
-- Carga las fechas de salida de cada almacén
|
||||
|
||||
CALL vn.zone_getShippedWarehouse (vDelivery, vAddress, vAgencyModeId);
|
||||
|
||||
-- Trabajador que realiza la acción
|
||||
|
||||
IF vUserId IS NULL THEN
|
||||
SELECT employeeFk INTO vUserId FROM orderConfig;
|
||||
END IF;
|
||||
|
||||
-- Crea los tickets del pedido
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
OPEN cDates;
|
||||
|
||||
lDates:
|
||||
LOOP
|
||||
SET vTicket = NULL;
|
||||
SET vDone = FALSE;
|
||||
FETCH cDates INTO vShipment, vWarehouse;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE lDates;
|
||||
END IF;
|
||||
|
||||
-- Busca un ticket existente que coincida con los parametros
|
||||
|
||||
SELECT t.id INTO vTicket
|
||||
FROM vn.ticket t
|
||||
LEFT JOIN vn.ticketState tls on tls.ticket = t.id
|
||||
JOIN `order` o
|
||||
ON o.address_id = t.addressFk
|
||||
AND vWarehouse = t.warehouseFk
|
||||
AND o.agency_id = t.agencyModeFk
|
||||
AND o.date_send = t.landed
|
||||
AND vShipment = DATE(t.shipped)
|
||||
WHERE o.id = vOrder
|
||||
AND t.invoiceOutFk IS NULL
|
||||
AND IFNULL(tls.alertLevel,0) = 0
|
||||
LIMIT 1;
|
||||
|
||||
-- Crea el ticket en el caso de no existir uno adecuado
|
||||
|
||||
IF vTicket IS NULL
|
||||
THEN
|
||||
CALL vn.ticketCreateWithUser(
|
||||
vClientId,
|
||||
IFNULL(vShipment, CURDATE()),
|
||||
vWarehouse,
|
||||
vCompanyId,
|
||||
vAddress,
|
||||
vAgencyModeId,
|
||||
NULL,
|
||||
vDelivery,
|
||||
vUserId,
|
||||
vTicket
|
||||
);
|
||||
ELSE
|
||||
INSERT INTO vncontrol.inter
|
||||
SET Id_Ticket = vTicket,
|
||||
Id_Trabajador = vUserId,
|
||||
state_id = TICKET_FREE;
|
||||
END IF;
|
||||
|
||||
INSERT IGNORE INTO vn.orderTicket
|
||||
SET orderFk = vOrder,
|
||||
ticketFk = vTicket;
|
||||
|
||||
-- Añade las notas
|
||||
|
||||
IF vNotes IS NOT NULL AND vNotes != ''
|
||||
THEN
|
||||
INSERT INTO vn.ticketObservation SET
|
||||
ticketFk = vTicket,
|
||||
observationTypeFk = 4 /* salesperson */ ,
|
||||
`description` = vNotes
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`description` = CONCAT(VALUES(`description`),'. ', `description`);
|
||||
END IF;
|
||||
|
||||
-- Añade los movimientos y sus componentes
|
||||
|
||||
OPEN cRows;
|
||||
|
||||
lRows:
|
||||
LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE lRows;
|
||||
END IF;
|
||||
|
||||
INSERT INTO vn.sale
|
||||
SET
|
||||
itemFk = vItem,
|
||||
ticketFk = vTicket,
|
||||
concept = vConcept,
|
||||
quantity = vAmount,
|
||||
price = vPrice,
|
||||
priceFixed = 0,
|
||||
isPriceFixed = TRUE;
|
||||
|
||||
SET vSale = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO vn.saleComponent
|
||||
(saleFk, componentFk, `value`)
|
||||
SELECT vSale, cm.component_id, cm.price
|
||||
FROM order_component cm
|
||||
JOIN bi.tarifa_componentes tc
|
||||
ON tc.Id_Componente = cm.component_id
|
||||
WHERE cm.order_row_id = vRowId
|
||||
GROUP BY vSale, cm.component_id;
|
||||
|
||||
UPDATE order_row SET Id_Movimiento = vSale
|
||||
WHERE id = vRowId;
|
||||
|
||||
END LOOP;
|
||||
|
||||
CLOSE cRows;
|
||||
|
||||
-- Fija el coste
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tComponents;
|
||||
CREATE TEMPORARY TABLE tComponents
|
||||
(INDEX (saleFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT SUM(sc.`value`) valueSum, sc.saleFk
|
||||
FROM vn.saleComponent sc
|
||||
JOIN bi.tarifa_componentes tc ON tc.Id_Componente = sc.componentFk
|
||||
JOIN bi.tarifa_componentes_series tcs
|
||||
ON tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id
|
||||
AND tcs.base
|
||||
JOIN vn.sale s
|
||||
ON s.id = sc.saleFk
|
||||
WHERE s.ticketFk = vTicket
|
||||
GROUP BY sc.saleFk;
|
||||
|
||||
UPDATE vn.sale s
|
||||
JOIN tComponents mc ON mc.saleFk = s.id
|
||||
SET s.priceFixed = valueSum;
|
||||
|
||||
DROP TEMPORARY TABLE tComponents;
|
||||
END LOOP;
|
||||
|
||||
CLOSE cDates;
|
||||
|
||||
DELETE FROM basketOrder WHERE orderFk = vOrder;
|
||||
UPDATE `order` SET confirmed = TRUE, confirm_date = NOW()
|
||||
WHERE id = vOrder;
|
||||
|
||||
COMMIT;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketCalculateClon`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT)
|
||||
BEGIN
|
||||
/*
|
||||
* @vTicketNew id del nuevo ticket clonado
|
||||
* @vTicketOld id ticket original, a partir del qual se clonara el nuevo
|
||||
* Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo
|
||||
*/
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vClient INT;
|
||||
DECLARE vWarehouse SMALLINT;
|
||||
DECLARE vAgencyMode INT;
|
||||
DECLARE vAddress INT;
|
||||
DECLARE vLanded DATE;
|
||||
DECLARE vAgency INT;
|
||||
DECLARE vZoneFk INT;
|
||||
|
||||
REPLACE INTO orderTicket(orderFk,ticketFk)
|
||||
SELECT orderFk, vTicketNew
|
||||
FROM orderTicket
|
||||
WHERE ticketFk = vTicketOld;
|
||||
|
||||
SELECT t.clientFk, t.warehouseFk, date(t.shipped), t.addressFk, t.agencyModeFk, t.landed, a.agencyFk, t.zoneFk
|
||||
INTO vClient, vWarehouse, vShipped, vAddress, vAgencyMode, vLanded, vAgency, vZoneFk
|
||||
FROM vn.agencyMode a
|
||||
JOIN vn.ticket t ON t.agencyModeFk = a.id
|
||||
WHERE t.id = vTicketNew;
|
||||
|
||||
IF vLanded IS NULL THEN
|
||||
CALL zone_getLanded(vShipped, vAddress, vAgency, vWarehouse);
|
||||
UPDATE ticket t
|
||||
JOIN tmp.zoneGetLanded zgl ON t.warehouseFk = zgl.warehouseFk
|
||||
SET t.landed = zgl.landed,
|
||||
t.zone = zgl.zoneFk
|
||||
WHERE t.id = vTicketNew;
|
||||
|
||||
SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded;
|
||||
END IF;
|
||||
|
||||
-- rellena la tabla tmp.buyUltimate con la ultima compra
|
||||
CALL buyUltimate(vWarehouse, vShipped);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||
CREATE TEMPORARY TABLE tmp.ticketLot
|
||||
SELECT vWarehouse warehouseFk, NULL available, s.itemFk, bu.buyFk
|
||||
FROM sale s
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
WHERE s.ticketFk = vTicketOld GROUP BY s.itemFk;
|
||||
|
||||
CALL catalog_componentCalculate(vZoneFk, vAddress, vAgencyMode);
|
||||
|
||||
-- Bionizamos lineas con Preu = 0
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||
SELECT s.id saleFk, vWarehouse warehouseFk
|
||||
FROM sale s
|
||||
JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew AND s.price = 0;
|
||||
|
||||
CALL ticketComponentUpdateSale(1);
|
||||
|
||||
-- Bionizamos lineas con Preu > 0
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||
SELECT s.id saleFk, vWarehouse warehouseFk
|
||||
FROM sale s
|
||||
JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew
|
||||
AND s.price > 0;
|
||||
|
||||
CALL ticketComponentUpdateSale(6);
|
||||
|
||||
-- Log
|
||||
CALL `logAdd`(vTicketNew, 'update', ' ticket' , 'Bioniza Ticket');
|
||||
|
||||
-- Limpieza
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,262 +0,0 @@
|
|||
|
||||
USE `vn`;
|
||||
DROP procedure IF EXISTS `vn`.`ticketComponentCalculate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentCalculate__`(
|
||||
vAddressFk INT,
|
||||
vAgencyModeFk INT)
|
||||
proc: BEGIN
|
||||
-- OBSOLETO usar catalog_componentCalculate
|
||||
/**
|
||||
* Calcula los componentes de un ticket
|
||||
*
|
||||
* @param vAddressFk Id del consignatario
|
||||
* @param vAgencyModeFk Id del modo de agencia
|
||||
* @return tmp.ticketComponent(itemFk, warehouseFk, available, rate2, rate3, minPrice,
|
||||
* packing, grouping, groupingMode, buyFk, typeFk)
|
||||
* @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, grouping, price)
|
||||
*/
|
||||
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vGeneralInflationCoefficient INT DEFAULT 1;
|
||||
DECLARE vMinimumDensityWeight INT DEFAULT 167;
|
||||
DECLARE vBoxFreightItem INT DEFAULT 71;
|
||||
DECLARE vBoxVolume BIGINT; -- DEFAULT 138000;
|
||||
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;
|
||||
|
||||
|
||||
|
||||
SELECT volume INTO vBoxVolume
|
||||
FROM vn.packaging
|
||||
WHERE id = '94';
|
||||
|
||||
SELECT clientFk INTO vClientFK
|
||||
FROM address
|
||||
WHERE id = vAddressFk;
|
||||
|
||||
SET @rate2 := 0;
|
||||
SET @rate3 := 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,
|
||||
IF((@rate3 := IFNULL(pf.rate3, b.price3)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate3) * 1.0 rate3,
|
||||
IFNULL(pf.rate3, 0) AS minPrice,
|
||||
IFNULL(pf.packing, 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, aho.warehouseFk
|
||||
FROM priceFixed pf
|
||||
JOIN tmp.zoneGetShipped aho ON pf.warehouseFk = aho.warehouseFk OR pf.warehouseFk = 0
|
||||
WHERE aho.shipped 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.display <> 0;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponent (
|
||||
`warehouseFk` INT UNSIGNED NOT NULL,
|
||||
`itemFk` INT NOT NULL,
|
||||
`componentFk` INT UNSIGNED NOT NULL,
|
||||
`cost` DECIMAL(10,4) NOT NULL,
|
||||
INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC),
|
||||
UNIQUE INDEX `itemWarehouseComponent` (`itemFk` ASC, `warehouseFk` ASC, `componentFk` ASC));
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
GROUP BY tc.itemFk, warehouseFk;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(cr.recobro, 0.25), 3)
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN bi.claims_ratio cr ON cr.Id_Cliente = vClientFk
|
||||
WHERE cr.recobro > 0.009;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + prices_modifier_rate), 3) as manaAuto
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN `client` c on c.id = vClientFk
|
||||
JOIN bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador
|
||||
WHERE ms.prices_modifier_activated
|
||||
HAVING manaAuto <> 0;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcb.warehouseFk,
|
||||
tcb.itemFk,
|
||||
cr.id,
|
||||
GREATEST(IFNULL(ROUND(tcb.base * cr.tax, 4), 0), tcc.minPrice - tcc.rate3)
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN componentRate cr
|
||||
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
|
||||
WHERE cr.id = vDiscountLastItemComponent AND cr.tax <> 0 AND tcc.minPrice < tcc.rate3 AND sp.value IS NULL;
|
||||
|
||||
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;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcc.warehouseFK,
|
||||
tcc.itemFk,
|
||||
vDeliveryComponent,
|
||||
vGeneralInflationCoefficient
|
||||
* ROUND((
|
||||
i.compression
|
||||
* r.cm3
|
||||
* IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1)
|
||||
* IFNULL((z.price - z.bonus)
|
||||
* 1/*amz.inflation*/ , 50)) / vBoxVolume, 4
|
||||
) cost
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN item i ON i.id = tcc.itemFk
|
||||
JOIN agencyMode am ON am.id = vAgencyModeFk
|
||||
JOIN `address` a ON a.id = vAddressFk
|
||||
JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = tcc.warehouseFk
|
||||
JOIN zone z ON z.id = zgs.id
|
||||
LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk
|
||||
AND r.Id_Article = tcc.itemFk
|
||||
HAVING cost <> 0;
|
||||
|
||||
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;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcc.warehouseFk,
|
||||
tcc.itemFk,
|
||||
vSpecialPriceComponent,
|
||||
sp.value - SUM(tcc.cost) sumCost
|
||||
FROM tmp.ticketComponentCopy tcc
|
||||
JOIN componentRate cr ON cr.id = tcc.componentFk
|
||||
JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk
|
||||
WHERE cr.classRate IS NULL
|
||||
GROUP BY tcc.itemFk, tcc.warehouseFk
|
||||
HAVING ABS(sumCost) > 0.001;
|
||||
|
||||
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, cr.classRate
|
||||
FROM tmp.ticketComponent tc
|
||||
JOIN componentRate cr ON cr.id = tc.componentFk
|
||||
GROUP BY tc.itemFk, tc.warehouseFk, cr.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) / weightGrouping AS DECIMAL(10,2)) 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;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPrice;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY
|
||||
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 ;
|
||||
;
|
|
@ -1,88 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketCreateWithUser`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` 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;
|
||||
|
||||
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 INTO vZoneFk 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
|
||||
)
|
||||
SELECT
|
||||
vClientId,
|
||||
vShipped,
|
||||
a.id,
|
||||
vAgencyModeFk,
|
||||
a.nickname,
|
||||
vWarehouseFk,
|
||||
IF(vRouteFk,vRouteFk,NULL),
|
||||
vCompanyFk,
|
||||
vlanded,
|
||||
vZoneFk
|
||||
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;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,90 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketCreateWithoutZone`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreateWithoutZone`(
|
||||
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;
|
||||
|
||||
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 NOT vAgencyModeFk OR vAgencyModeFk IS NULL THEN
|
||||
SELECT agencyModeFk INTO vAgencyModeFk
|
||||
FROM address
|
||||
WHERE clientFk = vClientId AND isDefaultAddress;
|
||||
END IF;
|
||||
|
||||
CALL vn.zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk);
|
||||
|
||||
SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetShipped
|
||||
WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1;
|
||||
|
||||
INSERT INTO vn2008.Tickets (
|
||||
Id_Cliente,
|
||||
Fecha,
|
||||
Id_Consigna,
|
||||
Id_Agencia,
|
||||
Alias,
|
||||
warehouse_id,
|
||||
Id_Ruta,
|
||||
empresa_id,
|
||||
landing,
|
||||
zoneFk
|
||||
)
|
||||
SELECT
|
||||
vClientId,
|
||||
vShipped,
|
||||
a.id,
|
||||
IF(vAgencyModeFk, vAgencyModeFk, a.agencyModeFk),
|
||||
a.nickname,
|
||||
vWarehouseFk,
|
||||
IF(vRouteFk,vRouteFk,NULL),
|
||||
vCompanyFk,
|
||||
vlanded,
|
||||
vZoneFk
|
||||
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;
|
||||
|
||||
-- CALL logAddWithUser(vNewTicket, vUserId, 'insert', 'ticket', CONCAT('Ha creado el ticket', ' ', vNewTicket));
|
||||
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;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `catalog_calcFromItem`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `catalog_calcFromItem`(
|
||||
vLanded DATE,
|
||||
vAddressFk INT,
|
||||
vAgencyModeFk INT,
|
||||
vItemFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Calculates available and price for a single item.
|
||||
*
|
||||
* @param vItemFk The item id
|
||||
* @return tmp.ticketCalculateItem
|
||||
* @return tmp.ticketComponentPrice
|
||||
* @return tmp.ticketComponent
|
||||
* @return tmp.ticketLot
|
||||
* @return tmp.zoneGetShipped
|
||||
*/
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.item;
|
||||
CREATE TEMPORARY TABLE tmp.item
|
||||
ENGINE = MEMORY
|
||||
SELECT vItemFk itemFk;
|
||||
|
||||
CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk);
|
||||
DROP TEMPORARY TABLE tmp.item;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,11 +0,0 @@
|
|||
USE `vn`;
|
||||
|
||||
CREATE TABLE `vn`.`chatConfig` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`uri` VARCHAR(255) NOT NULL,
|
||||
`user` VARCHAR(50) NOT NULL,
|
||||
`password` VARCHAR(50) NOT NULL,
|
||||
PRIMARY KEY (`id`));
|
||||
|
||||
|
||||
INSERT INTO `vn`.`chatConfig` (`uri`, `user`, `password`) VALUES ('https://chat.verdnatura.es/api/v1', 'VnBot', 'Ub606cux7op.');
|
|
@ -1,51 +0,0 @@
|
|||
DROP TRIGGER IF EXISTS `vn`.`client_beforeUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`client_beforeUpdate`
|
||||
BEFORE UPDATE ON `client`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vText VARCHAR(255) DEFAULT NULL;
|
||||
-- Comprueba que el formato de los teléfonos es válido
|
||||
|
||||
IF !(NEW.phone <=> OLD.phone) THEN
|
||||
CALL pbx.phone_isValid(NEW.phone);
|
||||
END IF;
|
||||
|
||||
IF !(NEW.mobile <=> OLD.mobile) THEN
|
||||
CALL pbx.phone_isValid(NEW.mobile);
|
||||
END IF;
|
||||
|
||||
IF !(NEW.fax <=> OLD.fax) THEN
|
||||
CALL pbx.phone_isValid(NEW.fax);
|
||||
END IF;
|
||||
|
||||
IF NEW.payMethodFk = 4 AND NEW.dueDay = 0 THEN
|
||||
SET NEW.dueDay = 5;
|
||||
END IF;
|
||||
|
||||
-- Avisar al comercial si ha llegado la documentación sepa/core
|
||||
|
||||
IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN
|
||||
SET vText = 'Sepa de VNL';
|
||||
END IF;
|
||||
|
||||
IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN
|
||||
SET vText = 'Core de VNL';
|
||||
END IF;
|
||||
|
||||
IF vText IS NOT NULL
|
||||
THEN
|
||||
INSERT INTO mail(sender, replyTo, `subject`, body)
|
||||
SELECT
|
||||
CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'),
|
||||
'administracion@verdnatura.es',
|
||||
CONCAT('Cliente ', NEW.id),
|
||||
CONCAT('Recibida la documentación: ', vText)
|
||||
FROM worker w
|
||||
LEFT JOIN account.user u ON w.userFk = u.id AND u.active
|
||||
LEFT JOIN account.account ac ON ac.id = u.id
|
||||
WHERE w.id = NEW.salesPersonFk;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,75 +0,0 @@
|
|||
DROP function IF EXISTS `vn`.`clientGetMana`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`clientGetMana`(vClient INT) RETURNS decimal(10,2)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve el mana del cliente.
|
||||
*
|
||||
* @param vClient Id del cliente
|
||||
* @return Mana del cliente
|
||||
*/
|
||||
DECLARE vMana DECIMAL(10,2);
|
||||
DECLARE vFromDated DATE;
|
||||
DECLARE vHasMana BOOLEAN;
|
||||
DECLARE vManaComponent INT;
|
||||
DECLARE vAutoManaComponent INT;
|
||||
DECLARE vManaBank INT;
|
||||
DECLARE vManaGreugeType INT;
|
||||
|
||||
SELECT id INTO vManaGreugeType FROM greugeType WHERE code = 'mana';
|
||||
SELECT id INTO vManaBank FROM bank WHERE code = 'mana';
|
||||
SELECT id INTO vManaComponent FROM component WHERE code = 'mana';
|
||||
SELECT id INTO vAutoManaComponent FROM component WHERE code = 'autoMana';
|
||||
|
||||
SELECT COUNT(*) INTO vHasMana
|
||||
FROM `client` c
|
||||
WHERE c.id = vClient AND c.typeFk = 'normal';
|
||||
|
||||
IF NOT vHasMana THEN
|
||||
RETURN 0;
|
||||
END IF;
|
||||
|
||||
SELECT max(dated) INTO vFromDated
|
||||
FROM clientManaCache;
|
||||
|
||||
SELECT sum(mana) INTO vMana
|
||||
FROM
|
||||
(
|
||||
SELECT mana
|
||||
FROM clientManaCache
|
||||
WHERE clientFk = vClient
|
||||
AND dated = vFromDated
|
||||
UNION ALL
|
||||
SELECT s.quantity * value
|
||||
FROM ticket t
|
||||
JOIN address a ON a.id = t.addressFk
|
||||
JOIN sale s on s.ticketFk = t.id
|
||||
JOIN saleComponent sc on sc.saleFk = s.id
|
||||
WHERE sc.componentFk IN (vManaComponent, vAutoManaComponent)
|
||||
AND t.shipped > vFromDated
|
||||
AND t.shipped < TIMESTAMPADD(DAY,1,CURDATE())
|
||||
AND a.clientFk = vClient
|
||||
UNION ALL
|
||||
SELECT - amountPaid
|
||||
FROM receipt r
|
||||
JOIN `client` c ON c.id = r.clientFk
|
||||
WHERE r.bankFk = vManaBank
|
||||
AND r.payed > vFromDated
|
||||
AND r.payed <= CURDATE()
|
||||
AND c.id = vClient
|
||||
UNION ALL
|
||||
SELECT g.amount
|
||||
FROM greuge g
|
||||
JOIN `client` c ON c.id = g.clientFk
|
||||
WHERE g.greugeTypeFk = vManaGreugeType
|
||||
AND g.shipped > vFromDated
|
||||
AND g.shipped <= CURDATE()
|
||||
AND c.id = vClient
|
||||
) sub;
|
||||
RETURN IFNULL(vMana,0);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
|
||||
DROP procedure IF EXISTS `vn`.`clientPackagingOverstock`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`clientPackagingOverstock`(vClientFk INT, vGraceDays INT )
|
||||
BEGIN
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.clientPackagingOverstock;
|
||||
CREATE TEMPORARY TABLE tmp.clientPackagingOverstock
|
||||
ENGINE = MEMORY
|
||||
SELECT itemFk,
|
||||
sum(GotfromClient) - sum(SenttoClient) as devueltos,
|
||||
sum(InvoicedtoClient) - sum(InvoicedfromClient) as facturados,
|
||||
LEAST(
|
||||
sum(GotfromClient) - sum(SenttoClient),
|
||||
sum(InvoicedtoClient) - sum(InvoicedfromClient)
|
||||
) as abonables
|
||||
FROM
|
||||
(
|
||||
SELECT t.*,
|
||||
IF(@month = month, 0, 1) monthEnd,
|
||||
@month := month
|
||||
FROM
|
||||
(
|
||||
SELECT x.id as ticketFk,
|
||||
date(x.shipped) as shipped,
|
||||
x.itemFk,
|
||||
IFNULL(cast(sum(x.InvoicedtoClient) as DECIMAL(10,0)),0) InvoicedtoClient,
|
||||
IFNULL(cast(sum(x.InvoicedfromClient) as DECIMAL(10,0)),0) InvoicedfromClient,
|
||||
IFNULL(cast(sum(x.SenttoClient) as DECIMAL(10,0)),0) SenttoClient,
|
||||
IFNULL(cast(sum(x.GotfromClient) as DECIMAL(10,0)),0) GotfromClient,
|
||||
i.name as concept,
|
||||
x.refFk as invoice,
|
||||
month(shipped) month,
|
||||
x.companyFk
|
||||
FROM
|
||||
(
|
||||
SELECT t.id,
|
||||
t.shipped,
|
||||
IFNULL(pe.equivalentFk, s.itemFk) itemFk,
|
||||
IF(s.quantity > 0, s.quantity, NULL) InvoicedtoClient,
|
||||
IF(s.quantity < 0, -s.quantity, NULL) InvoicedfromClient,
|
||||
NULL SenttoClient,
|
||||
NULL GotfromClient,
|
||||
t.refFk,
|
||||
@month := 0 month,
|
||||
t.companyFk
|
||||
FROM sale s
|
||||
JOIN ticket t on t.id = s.ticketFk
|
||||
JOIN packaging p ON p.itemFk = s.itemFk
|
||||
LEFT JOIN packageEquivalentItem pe ON pe.itemFk = s.itemFk
|
||||
WHERE t.clientFk = vClientFk
|
||||
AND t.shipped > '2017-11-30'
|
||||
AND p.isPackageReturnable
|
||||
UNION ALL
|
||||
SELECT NULL,
|
||||
'2017-11-30',
|
||||
IFNULL(pe.equivalentFk, tps.itemFk) itemFk,
|
||||
tps.sent InvoicedtoClient,
|
||||
tps.returned InvoicedfromClient,
|
||||
NULL SenttoClient,
|
||||
NULL GotfromClient,
|
||||
'Histórico',
|
||||
NULL,
|
||||
NULL
|
||||
|
||||
FROM ticketPackagingStartingStock tps
|
||||
LEFT JOIN packageEquivalentItem pe ON pe.itemFk = tps.itemFk
|
||||
WHERE tps.clientFk = vClientFk
|
||||
AND tps.isForgetable = FALSE
|
||||
UNION ALL
|
||||
SELECT t.id,
|
||||
t.shipped,
|
||||
IFNULL(pe.equivalentFk, p.itemFk) itemFk,
|
||||
NULL,
|
||||
NULL,
|
||||
IF(tp.quantity > 0 AND t.shipped <= TIMESTAMPADD(DAY, - vGraceDays, CURDATE()), tp.quantity, NULL) SenttoClient,
|
||||
IF(tp.quantity < 0, -tp.quantity, NULL) GotfromClient,
|
||||
NULL AS refFk,
|
||||
NULL,
|
||||
t.companyFk
|
||||
FROM ticketPackaging tp
|
||||
JOIN ticket t on t.id = tp.ticketFk
|
||||
JOIN packaging p ON p.id = tp.packagingFk
|
||||
LEFT JOIN packageEquivalentItem pe ON pe.itemFk = p.itemFk
|
||||
WHERE t.clientFk = vClientFk
|
||||
AND t.shipped > '2017-11-21' ) x
|
||||
|
||||
JOIN item i ON x.itemFk = i.id
|
||||
GROUP BY x.id, x.itemFk
|
||||
) t
|
||||
ORDER BY itemFk, shipped DESC
|
||||
) t2
|
||||
GROUP BY itemFk;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
DROP procedure IF EXISTS `vn`.`clonTravelComplete`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`clonTravelComplete`(IN `vTravelFk` INT, IN `vDateStart` DATE, IN `vDateEnd` DATE, IN `vRef` VARCHAR(255))
|
||||
BEGIN
|
||||
|
||||
DECLARE vTravelNew INT;
|
||||
DECLARE vEntryNew INT;
|
||||
DECLARE vDone BIT DEFAULT 0;
|
||||
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 vRsBuy CURSOR FOR
|
||||
SELECT b.*
|
||||
FROM buy b
|
||||
JOIN entry e
|
||||
ON b.entryFk = e.id
|
||||
WHERE e.travelFk = vTravelNew and b.entryFk=entryNew
|
||||
ORDER BY e.id;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
INSERT INTO travel (shipped,landed, warehouseInFk, warehouseOutFk, agencyFk, ref, isDelivered, isReceived, m3, kg)
|
||||
SELECT vDateStart, vDateEnd,warehouseInFk, warehouseOutFk, agencyFk, vRef, isDelivered, isReceived, m3, kg
|
||||
FROM travel
|
||||
WHERE id = vTravelFk;
|
||||
|
||||
SET vTravelNew = LAST_INSERT_ID();
|
||||
SET vDone = 0;
|
||||
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,
|
||||
vTravelNew,
|
||||
currencyFk,
|
||||
companyFk,
|
||||
gestDocFk,
|
||||
invoiceInFk
|
||||
FROM entry
|
||||
WHERE id = vAuxEntryFk;
|
||||
|
||||
SET vEntryNew = LAST_INSERT_ID();
|
||||
|
||||
|
||||
INSERT INTO buy (entryFk,
|
||||
itemFk,
|
||||
quantity,
|
||||
buyingValue,
|
||||
packageFk,
|
||||
stickers,
|
||||
freightValue,
|
||||
packageValue,
|
||||
comissionValue,
|
||||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
location,
|
||||
price1,
|
||||
price2,
|
||||
price3,
|
||||
minPrice,
|
||||
producer,
|
||||
printedStickers,
|
||||
isChecked)
|
||||
SELECT vEntryNew,
|
||||
itemFk,
|
||||
quantity,
|
||||
buyingValue,
|
||||
packageFk,
|
||||
stickers,
|
||||
freightValue,
|
||||
packageValue,
|
||||
comissionValue,
|
||||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
location,
|
||||
price1,
|
||||
price2,
|
||||
price3,
|
||||
minPrice,
|
||||
producer,
|
||||
printedStickers,
|
||||
isChecked
|
||||
FROM buy
|
||||
WHERE entryFk = vAuxEntryFk;
|
||||
|
||||
|
||||
FETCH vRsEntry INTO vAuxEntryFk;
|
||||
END WHILE;
|
||||
CLOSE vRsEntry;
|
||||
COMMIT;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
USE `vn`;
|
||||
|
||||
UPDATE `vn`.`country` SET `ibanLength` = '24' WHERE (`id` = 1);
|
||||
UPDATE `vn`.`country` SET `ibanLength` = '27' WHERE (`id` = 2);
|
||||
UPDATE `vn`.`country` SET `ibanLength` = '22' WHERE (`id` = 3);
|
||||
UPDATE `vn`.`country` SET `ibanLength` = '24' WHERE (`id` = 4);
|
||||
UPDATE `vn`.`country` SET `ibanLength` = '18' WHERE (`id` = 5);
|
||||
UPDATE `vn`.`country` SET `ibanLength` = '25' WHERE (`id` = 8);
|
||||
UPDATE `vn`.`country` SET `ibanLength` = '27' WHERE (`id` = 19);
|
||||
UPDATE `vn`.`country` SET `ibanLength` = '24' WHERE (`id` = 30);
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
DELIMITER $$
|
||||
DROP TRIGGER IF EXISTS `vn`.`creditClassification_BEFORE_UPDATE` $$
|
||||
|
||||
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`creditClassification_beforeUpdate` BEFORE UPDATE ON `creditClassification` FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.client <> OLD.client THEN
|
||||
CALL util.throw('NOT_ALLOWED_CHANGE_CLIENT');
|
||||
END IF;
|
||||
IF NEW.dateEnd IS NOT NULL AND OLD.dateEnd IS NULL THEN
|
||||
UPDATE `client` c
|
||||
SET creditInsurance = 0 WHERE c.id = NEW.client;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,13 +0,0 @@
|
|||
|
||||
DELIMITER $$
|
||||
|
||||
DROP TRIGGER IF EXISTS `vn`.`creditInsurance_AFTER_INSERT` $$
|
||||
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`creditInsurance_afterInsert` AFTER INSERT ON `creditInsurance` FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE `client` c
|
||||
JOIN vn.creditClassification cc ON cc.client = c.id
|
||||
SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,3 +0,0 @@
|
|||
USE `vn`;
|
||||
|
||||
CREATE DEFINER=`root`@`%` EVENT `department_doCalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-11-15 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL vn.department_doCalc
|
|
@ -1,74 +0,0 @@
|
|||
|
||||
DROP procedure IF EXISTS `vn`.`duaInvoiceInBooking`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT)
|
||||
BEGIN
|
||||
DECLARE done BOOL DEFAULT FALSE;
|
||||
DECLARE vInvoiceFk INT;
|
||||
DECLARE vASIEN BIGINT DEFAULT 0;
|
||||
DECLARE vCounter INT DEFAULT 0;
|
||||
|
||||
DECLARE rs CURSOR FOR
|
||||
SELECT e.invoiceInFk
|
||||
FROM entry e
|
||||
JOIN duaEntry de ON de.entryFk = e.id
|
||||
JOIN invoiceIn ii ON ii.id = e.invoiceInFk
|
||||
WHERE de.duaFk = vDuaFk
|
||||
AND de.customsValue
|
||||
AND ii.isBooked = FALSE;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
|
||||
|
||||
OPEN rs;
|
||||
|
||||
UPDATE invoiceIn ii
|
||||
JOIN entry e ON e.invoiceInFk = ii.id
|
||||
JOIN duaEntry de ON de.entryFk = e.id
|
||||
JOIN dua d ON d.id = de.duaFk
|
||||
SET ii.isBooked = TRUE,
|
||||
ii.booked = IFNULL(ii.booked,d.booked),
|
||||
ii.operated = IFNULL(ii.operated,d.operated),
|
||||
ii.issued = IFNULL(ii.issued,d.issued),
|
||||
ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried),
|
||||
e.isConfirmed = TRUE
|
||||
WHERE d.id = vDuaFk;
|
||||
|
||||
SELECT IFNULL(ASIEN,0) INTO vASIEN
|
||||
FROM dua
|
||||
WHERE id = vDuaFk;
|
||||
|
||||
FETCH rs INTO vInvoiceFk;
|
||||
|
||||
WHILE NOT done DO
|
||||
|
||||
CALL invoiceInBookingMain(vInvoiceFk);
|
||||
|
||||
IF vCounter > 0 OR vASIEN > 0 THEN
|
||||
|
||||
UPDATE XDiario x
|
||||
JOIN config c ON c.ASIEN = x.ASIEN
|
||||
SET x.ASIEN = vASIEN;
|
||||
|
||||
ELSE
|
||||
|
||||
SELECT ASIEN INTO vASIEN FROM config;
|
||||
|
||||
END IF;
|
||||
|
||||
SET vCounter = vCounter + 1;
|
||||
|
||||
FETCH rs INTO vInvoiceFk;
|
||||
|
||||
END WHILE;
|
||||
|
||||
CLOSE rs;
|
||||
|
||||
UPDATE dua
|
||||
SET ASIEN = vASIEN
|
||||
WHERE id = vDuaFk;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `getItemVisibleAvailable`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `getItemVisibleAvailable`(
|
||||
vItem INT,
|
||||
vDate DATE,
|
||||
vWarehouse TINYINT,
|
||||
vRefresh BOOL)
|
||||
BEGIN
|
||||
-- DEPRECADO - UTILIZAR vn.item_getVisibleAvailable() - JSB - 2019-11-20
|
||||
CALL item_getVisibleAvailable(vItem, vDate, vWarehouse, vRefresh);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `itemGetVisibleAvailable`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `itemGetVisibleAvailable`(
|
||||
vItem INT,
|
||||
vDate DATE,
|
||||
vWarehouse TINYINT,
|
||||
vRefresh BOOL)
|
||||
BEGIN
|
||||
-- DEPRECADO - UTILIZAR vn.item_getVisibleAvailable() - JSB - 2019-11-20
|
||||
CALL item_getVisibleAvailable(vItem, vDate, vWarehouse, vRefresh);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
|
||||
USE `vn`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `item_getVisibleAvailable`(
|
||||
vItem INT,
|
||||
vDate DATE,
|
||||
vWarehouse TINYINT,
|
||||
vRefresh BOOL)
|
||||
BEGIN
|
||||
DECLARE vVisibleCalc INT;
|
||||
DECLARE vAvailableCalc INT;
|
||||
DECLARE vVisibleAltillo INT;
|
||||
|
||||
CALL cache.available_refresh(vAvailableCalc, FALSE /*vRefresh*/ , vWarehouse, vDate);
|
||||
CALL cache.visible_refresh(vVisibleCalc, FALSE,vWarehouse);
|
||||
|
||||
SELECT visible INTO vVisibleAltillo
|
||||
FROM vn.itemShelvingStock
|
||||
WHERE itemFk = vItem
|
||||
AND warehouseFk = vWarehouse;
|
||||
|
||||
IF vRefresh THEN
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS vn2008.tmp_item;
|
||||
CREATE TEMPORARY TABLE vn2008.tmp_item
|
||||
(PRIMARY KEY (item_id))
|
||||
ENGINE = MEMORY
|
||||
SELECT vItem item_id, 0 stock, 0 visible;
|
||||
|
||||
SELECT i.id, i.longName, i.box, i.typeFk,
|
||||
i.tag5,i.value5,i.tag6,i.value6,i.tag7,i.value7,i.tag8,i.value8,
|
||||
ip.code, ip.reserve,
|
||||
vi.visible - IFNULL(vVisibleAltillo,0) AS visible,
|
||||
av.available
|
||||
FROM vn.item i
|
||||
LEFT JOIN vn.itemPlacement ip
|
||||
ON i.id = ip.itemFk AND ip.warehouseFk = vWarehouse
|
||||
LEFT JOIN vn2008.tmp_item v
|
||||
ON v.item_id = i.id
|
||||
LEFT JOIN cache.available av
|
||||
ON av.calc_id = vAvailableCalc AND av.item_id = i.id
|
||||
LEFT JOIN cache.visible vi
|
||||
ON vi.calc_id = vVisibleCalc AND vi.item_id = i.id
|
||||
LEFT JOIN cache.stock st
|
||||
ON st.warehouse_id = vWarehouse AND st.item_id = i.id
|
||||
WHERE (vItem IS NULL OR i.id = vItem);
|
||||
|
||||
ELSE
|
||||
|
||||
SELECT i.id, i.longName, i.box, i.typeFk,
|
||||
i.tag5,i.value5,i.tag6,i.value6,i.tag7,i.value7,i.tag8,i.value8,
|
||||
ip.code, ip.reserve,
|
||||
v.visible - IFNULL(vVisibleAltillo,0) AS visible,
|
||||
av.available
|
||||
FROM vn.item i
|
||||
LEFT JOIN vn.itemPlacement ip
|
||||
ON i.id = ip.itemFk AND ip.warehouseFk = vWarehouse
|
||||
LEFT JOIN cache.visible v
|
||||
ON v.item_id = i.id AND v.calc_id = vVisibleCalc
|
||||
LEFT JOIN cache.available av
|
||||
ON av.item_id = i.id AND av.calc_id = vAvailableCalc
|
||||
WHERE (vItem IS NULL OR i.id = vItem);
|
||||
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
;
|
|
@ -1,7 +0,0 @@
|
|||
USE `vn`;
|
||||
|
||||
ALTER TABLE `vn`.`payMethod`
|
||||
ADD COLUMN `code` VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL AFTER `id`;
|
||||
|
||||
UPDATE `vn`.`payMethod` SET `code` = 'bankDraft' WHERE (`id` = '4');
|
||||
UPDATE `vn`.`payMethod` SET `code` = 'card' WHERE (`id` = '5');
|
|
@ -1,41 +0,0 @@
|
|||
DROP procedure IF EXISTS `vn`.`rangeDateInfo`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE `vn`.`rangeDateInfo` (vStarted DATE, vEnded DATE)
|
||||
BEGIN
|
||||
/**
|
||||
* Crea una tabla temporal con las fechas
|
||||
* desde una fecha inicial a una final
|
||||
* @param vStarted fecha inicial
|
||||
* @param vEnded fecha final
|
||||
*/
|
||||
DECLARE vDated DATE DEFAULT vStarted;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.rangeDate;
|
||||
CREATE TEMPORARY TABLE tmp.rangeDate(
|
||||
`dated` DATE,
|
||||
`period` INT,
|
||||
`month` INT,
|
||||
`year` INT,
|
||||
`day` INT,
|
||||
`week` INT,
|
||||
`yearMonth` INT
|
||||
)
|
||||
ENGINE = MEMORY;
|
||||
|
||||
WHILE vDated <= vEnded DO
|
||||
INSERT INTO tmp.rangeDate
|
||||
SET `dated` = vDated,
|
||||
`period` = YEAR(vDated) * 100 + WEEK(vDated, 1),
|
||||
`month` = MONTH(vDated),
|
||||
`year` = YEAR(vDated),
|
||||
`day` = DAY(vDated),
|
||||
`week` = WEEK(vDated, 1),
|
||||
`yearMonth` = YEAR(vDated) * 100 + MONTH(vDated);
|
||||
|
||||
SET vDated = DATE_ADD(vDated, INTERVAL 1 DAY);
|
||||
END WHILE;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
USE `vn`;
|
||||
|
||||
UPDATE `vn`.`sample` SET `description` = 'Bienvenida como nuevo cliente' WHERE (`id` = '12');
|
||||
UPDATE `vn`.`sample` SET `description` = 'Instalación y configuración de impresora de coronas' WHERE (`id` = '13');
|
||||
UPDATE `vn`.`sample` SET `description` = 'Solicitud de domiciliación bancaria' WHERE (`id` = '14');
|
||||
UPDATE `vn`.`sample` SET `description` = 'Aviso inicial por saldo deudor' WHERE (`id` = '15');
|
||||
UPDATE `vn`.`sample` SET `description` = 'Aviso reiterado por saldo deudor' WHERE (`id` = '16');
|
||||
UPDATE `vn`.`sample` SET `isVisible` = '0' WHERE (`id` = '17');
|
|
@ -1,116 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketClosure`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosure`()
|
||||
BEGIN
|
||||
/**
|
||||
* Realiza el cierre de todos los
|
||||
* tickets de la table ticketClosure.
|
||||
*/
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vIsTaxDataChecked BOOL;
|
||||
DECLARE vCompanyFk INT;
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vPriority INT DEFAULT 1;
|
||||
DECLARE vReportDeliveryNote INT DEFAULT 1;
|
||||
DECLARE vNewInvoiceId INT;
|
||||
DECLARE vHasDailyInvoice BOOL;
|
||||
DECLARE vWithPackage BOOL;
|
||||
|
||||
DECLARE cur CURSOR FOR
|
||||
SELECT ticketFk FROM tmp.ticketClosure;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2;
|
||||
CREATE TEMPORARY TABLE tmp.ticketClosure2
|
||||
SELECT ticketFk FROM tmp.ticketClosure;
|
||||
INSERT INTO tmp.ticketClosure
|
||||
SELECT id FROM stowaway s
|
||||
JOIN tmp.ticketClosure2 tc ON s.shipFk = tc.ticketFk;
|
||||
OPEN cur;
|
||||
|
||||
proc: LOOP
|
||||
SET vDone = FALSE;
|
||||
|
||||
FETCH cur INTO vTicketFk;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE proc;
|
||||
END IF;
|
||||
|
||||
-- ticketClosure start
|
||||
SELECT
|
||||
c.id,
|
||||
c.isTaxDataChecked,
|
||||
t.companyFk,
|
||||
t.shipped,
|
||||
co.hasDailyInvoice,
|
||||
w.isManaged
|
||||
INTO vClientFk,
|
||||
vIsTaxDataChecked,
|
||||
vCompanyFk,
|
||||
vShipped,
|
||||
vHasDailyInvoice,
|
||||
vWithPackage
|
||||
FROM ticket t
|
||||
JOIN `client` c ON c.id = t.clientFk
|
||||
JOIN province p ON p.id = c.provinceFk
|
||||
JOIN country co ON co.id = p.countryFk
|
||||
JOIN warehouse w ON w.id = t.warehouseFk
|
||||
WHERE t.id = vTicketFk;
|
||||
|
||||
INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity)
|
||||
(SELECT vTicketFk, p.id, COUNT(*)
|
||||
FROM expedition e
|
||||
JOIN packaging p ON p.itemFk = e.itemFk
|
||||
WHERE e.ticketFk = vTicketFk AND p.isPackageReturnable
|
||||
AND vWithPackage
|
||||
GROUP BY p.itemFk);
|
||||
|
||||
-- No retornables o no catalogados
|
||||
INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed)
|
||||
(SELECT e.itemFk, vTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1
|
||||
FROM expedition e
|
||||
JOIN item i ON i.id = e.itemFk
|
||||
LEFT JOIN packaging p ON p.itemFk = i.id
|
||||
WHERE e.ticketFk = vTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0
|
||||
AND getSpecialPrice(e.itemFk, vClientFk) > 0
|
||||
GROUP BY e.itemFk);
|
||||
|
||||
IF(vHasDailyInvoice) THEN
|
||||
|
||||
-- Facturacion rapida
|
||||
CALL ticketTrackingAdd(vTicketFk, 'DELIVERED', NULL);
|
||||
-- Facturar si está contabilizado
|
||||
IF vIsTaxDataChecked THEN
|
||||
CALL invoiceOut_newFromClient(
|
||||
vClientFk,
|
||||
(SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')),
|
||||
vShipped,
|
||||
vCompanyFk,
|
||||
NULL,
|
||||
vNewInvoiceId);
|
||||
END IF;
|
||||
ELSE
|
||||
-- Albaran_print
|
||||
CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), NULL);
|
||||
END IF;
|
||||
|
||||
-- ticketClosure end
|
||||
END LOOP;
|
||||
|
||||
CLOSE cur;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
|
||||
ALTER TABLE `vn`.`ticketRequest`
|
||||
DROP FOREIGN KEY `fgnAtender`;
|
||||
ALTER TABLE `vn`.`ticketRequest`
|
||||
CHANGE COLUMN `atenderFk` `attenderFk` INT(11) NULL DEFAULT NULL ;
|
||||
ALTER TABLE `vn`.`ticketRequest`
|
||||
ADD CONSTRAINT `fgnAtender`
|
||||
FOREIGN KEY (`attenderFk`)
|
||||
REFERENCES `vn`.`worker` (`id`)
|
||||
ON UPDATE CASCADE;
|
||||
|
||||
|
||||
|
||||
|
||||
DROP TRIGGER IF EXISTS `vn`.`ticketRequest_beforeInsert`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`ticketRequest_beforeInsert` BEFORE INSERT ON `ticketRequest` FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.ticketFk IS NULL THEN
|
||||
SET NEW.ticketFk = (SELECT s.ticketFk FROM sale s WHERE s.id = NEW.saleFk);
|
||||
END IF;
|
||||
|
||||
IF NEW.requesterFk IS NULL THEN
|
||||
SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode);
|
||||
END IF;
|
||||
|
||||
IF NEW.attenderFk IS NULL THEN
|
||||
SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode);
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
DROP TRIGGER IF EXISTS `vn`.`ticketRequest_beforeUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`ticketRequest_beforeUpdate` BEFORE UPDATE ON `ticketRequest` FOR EACH ROW
|
||||
BEGIN
|
||||
IF NEW.saleFk <> OLD.saleFk THEN
|
||||
SET NEW.ticketFk = (SELECT s.ticketFk FROM sale s WHERE s.id = NEW.saleFk);
|
||||
END IF;
|
||||
|
||||
IF NEW.salesPersonCode <> OLD.salesPersonCode THEN
|
||||
SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode);
|
||||
END IF;
|
||||
|
||||
IF NEW.buyerCode <> OLD.buyerCode THEN
|
||||
SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode);
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticket_recalcComponents`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticket_recalcComponents`(IN vTicketFk BIGINT )
|
||||
proc: BEGIN
|
||||
|
||||
/**
|
||||
* Este procedimiento trata de "rebionizar" un ticket,
|
||||
* eliminando los componentes existentes e insertandolos de nuevo
|
||||
*
|
||||
* @param vTicketFk Id del ticket
|
||||
* @return tmp.buyUltimate
|
||||
*/
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vWarehouseFk SMALLINT;
|
||||
DECLARE vAgencyModeFk INT;
|
||||
DECLARE vAddressFk INT;
|
||||
DECLARE vLanded DATE;
|
||||
DECLARE vIsTicketEditable BOOLEAN;
|
||||
DECLARE vZoneFk INTEGER;
|
||||
|
||||
SELECT (IFNULL(ts.alertLevel,0) >0 or IFNULL(t.refFk,"") != "") = FALSE, t.zoneFk
|
||||
INTO vIsTicketEditable, vZoneFk
|
||||
FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket
|
||||
WHERE id = vTicketFk;
|
||||
|
||||
SELECT warehouseFk, date(shipped), addressFk, agencyModeFk, landed
|
||||
INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded
|
||||
FROM ticket
|
||||
WHERE id = vTicketFk;
|
||||
|
||||
CALL zoneGetShippedWarehouse(vLanded, vAddressFk , vAgencyModeFk);
|
||||
|
||||
CALL vn.buyUltimate (vWarehouseFk, vShipped); -- rellena la tabla buyUltimate con la ultima compra
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||
CREATE TEMPORARY TABLE tmp.ticketLot
|
||||
SELECT vWarehouseFk warehouseFk, NULL available,
|
||||
s.itemFk, bu.buyFk
|
||||
FROM sale s
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
WHERE s.ticketFk = vTicketFk
|
||||
GROUP BY s.itemFk;
|
||||
|
||||
CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped);
|
||||
|
||||
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;
|
||||
|
||||
CALL vn.ticketComponentUpdateSale(IF(vIsTicketEditable,1,6)); -- si el ticket esta facturado, respeta los precios
|
||||
|
||||
IF vLanded IS NULL THEN
|
||||
|
||||
CALL zoneGetLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk);
|
||||
|
||||
UPDATE vn2008.Tickets t
|
||||
SET t.landing = (SELECT landed FROM tmp.zoneGetLanded)
|
||||
WHERE Id_Ticket = vTicketFk;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.zoneGetLanded;
|
||||
|
||||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
DROP TEMPORARY TABLE tmp.ticketComponentPrice;
|
||||
DROP TEMPORARY TABLE tmp.ticketComponent;
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticket_recalcComponentsForcePrice`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticket_recalcComponentsForcePrice`(IN vTicketFk BIGINT, vIsTicketEditable BOOLEAN )
|
||||
proc: BEGIN
|
||||
|
||||
/**
|
||||
* Este procedimiento trata de "rebionizar" un ticket,
|
||||
* eliminando los componentes existentes e insertandolos de nuevo
|
||||
*
|
||||
* @param vTicketFk Id del ticket
|
||||
* @return tmp.buyUltimate
|
||||
*/
|
||||
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 or IFNULL(t.refFk,"") != "") = FALSE, t.zoneFk
|
||||
INTO vIsTicketEditable, vZoneFk
|
||||
FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket
|
||||
WHERE id = vTicketFk;
|
||||
END IF;
|
||||
SELECT warehouseFk, date(shipped), addressFk, agencyModeFk, landed
|
||||
INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded
|
||||
FROM ticket
|
||||
WHERE id = vTicketFk;
|
||||
|
||||
CALL zoneGetShippedWarehouse(vLanded, vAddressFk , vAgencyModeFk);
|
||||
|
||||
CALL vn.buyUltimate (vWarehouseFk, vShipped); -- rellena la tabla buyUltimate con la ultima compra
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||
CREATE TEMPORARY TABLE tmp.ticketLot
|
||||
SELECT vWarehouseFk warehouseFk, NULL available,
|
||||
s.itemFk, bu.buyFk
|
||||
FROM sale s
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
WHERE s.ticketFk = vTicketFk
|
||||
GROUP BY s.itemFk;
|
||||
|
||||
CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped);
|
||||
|
||||
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;
|
||||
|
||||
CALL vn.ticketComponentUpdateSale(IF(vIsTicketEditable,1,6)); -- si el ticket esta facturado, respeta los precios
|
||||
|
||||
IF vLanded IS NULL THEN
|
||||
|
||||
CALL zoneGetLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk);
|
||||
|
||||
UPDATE vn2008.Tickets t
|
||||
SET t.landing = (SELECT landed FROM tmp.zoneGetLanded)
|
||||
WHERE Id_Ticket = vTicketFk;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.zoneGetLanded;
|
||||
|
||||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
DROP TEMPORARY TABLE tmp.ticketComponentPrice;
|
||||
DROP TEMPORARY TABLE tmp.ticketComponent;
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
DROP function IF EXISTS `vn`.`workerTimeControl_add`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`workerTimeControl_add`( vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) RETURNS int(11)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
DECLARE vDirection VARCHAR(6);
|
||||
DECLARE vLastIn DATETIME;
|
||||
DECLARE vDayStayMax INT;
|
||||
DECLARE vHasDirectionOut INT;
|
||||
DECLARE vLastInsertedId INT;
|
||||
|
||||
SELECT dayStayMax INTO vDayStayMax
|
||||
FROM workerTimeControlParams;
|
||||
|
||||
SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection;
|
||||
|
||||
IF vDirection = 'out' THEN
|
||||
|
||||
SELECT MAX(timed) INTO vLastIn
|
||||
FROM workerTimeControl
|
||||
WHERE userFk = vUserFk
|
||||
AND direction = 'in'
|
||||
AND timed < vTimed;
|
||||
|
||||
UPDATE workerTimeControl wtc
|
||||
SET wtc.direction = 'middle'
|
||||
WHERE userFk = vUserFk
|
||||
AND direction = 'out'
|
||||
AND timed BETWEEN vLastIn AND vTimed;
|
||||
|
||||
ELSE IF vDirection = 'in' THEN
|
||||
|
||||
SELECT COUNT(*) INTO vHasDirectionOut
|
||||
FROM workerTimeControl wtc
|
||||
WHERE userFk = vUserFk
|
||||
AND direction = 'out'
|
||||
AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed);
|
||||
|
||||
UPDATE workerTimeControl wtc
|
||||
SET wtc.direction = IF (vHasDirectionOut,'middle','out')
|
||||
WHERE userFk = vUserFk
|
||||
AND direction = 'in'
|
||||
AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed);
|
||||
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual)
|
||||
VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual);
|
||||
|
||||
SET vLastInsertedId = LAST_INSERT_ID();
|
||||
|
||||
CALL workerTimeControlSOWP(vUserFk, vTimed);
|
||||
|
||||
RETURN vLastInsertedId;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
|
||||
DROP procedure IF EXISTS `vn`.`workerTimeControl_add`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`workerTimeControl_add`(IN vUserFk INT, IN vWarehouseFk INT, IN vTimed DATETIME, IN vIsManual BOOL)
|
||||
BEGIN
|
||||
|
||||
|
||||
SELECT workerTimeControl_add(vUserFk,vWarehouseFk,vTimed,vIsManual);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,41 +0,0 @@
|
|||
DROP procedure IF EXISTS `vn`.`timeControl_calculate`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`timeControl_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME)
|
||||
BEGIN
|
||||
SET @vIsOdd := TRUE;
|
||||
SET @vUser := NULL;
|
||||
SET @vDated := NULL;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp.timeControlCalculate
|
||||
SELECT userFk,
|
||||
dated,
|
||||
IF( timeWork >= 18000, @timeWork:=timeWork + 1200, @timeWork:=timeWork) timeWorkSeconds,
|
||||
SEC_TO_TIME(@timeWork ) timeWorkSexagesimal,
|
||||
@timeWork / 3600 timeWorkDecimal
|
||||
FROM (SELECT SUM(timeWork) timeWork,
|
||||
userFk,
|
||||
dated
|
||||
FROM (SELECT IF(@vUser = wtc.userFk, @vUser :=@vUser, @vUser := wtc.userFk ),
|
||||
IF(@vIsOdd, @vIsOdd := FALSE, @vIsOdd := TRUE ),
|
||||
IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd ),
|
||||
IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed:=@vLastTimed),
|
||||
IF(@vIsOdd, 0, UNIX_TIMESTAMP(timed)-@vLastTimed) timeWork,
|
||||
IF(direction='in', @vDated := DATE(wtc.timed), @vDated :=@vDated) dated,
|
||||
wtc.userFk,
|
||||
wtc.timed timed,
|
||||
direction
|
||||
FROM workerTimeControl wtc
|
||||
JOIN tmp.`user` w ON w.userFk = wtc.userFk
|
||||
WHERE wtc.timed BETWEEN vDatedFrom AND vDatedTo
|
||||
ORDER BY userFk, timed
|
||||
) sub
|
||||
GROUP BY userFk, dated
|
||||
ORDER BY userFk, dated
|
||||
)sub2;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,53 +0,0 @@
|
|||
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`Ordenes` AS
|
||||
SELECT
|
||||
`tr`.`id` AS `Id_ORDEN`,
|
||||
`tr`.`description` AS `ORDEN`,
|
||||
`tr`.`requesterFk` AS `requesterFk`,
|
||||
`tr`.`attenderFk` AS `attenderFk`,
|
||||
`tr`.`quantity` AS `CANTIDAD`,
|
||||
`tr`.`itemFk` AS `Id_ARTICLE`,
|
||||
`tr`.`price` AS `PRECIOMAX`,
|
||||
`tr`.`isOk` AS `isOk`,
|
||||
`tr`.`saleFk` AS `Id_Movimiento`,
|
||||
`tr`.`ticketFk` AS `ticketFk`,
|
||||
`tr`.`response` AS `COMENTARIO`,
|
||||
`tr`.`created` AS `odbc_date`,
|
||||
`tr`.`ordered` AS `datORDEN`,
|
||||
`tr`.`shipped` AS `datTICKET`,
|
||||
`tr`.`salesPersonCode` AS `CodVENDEDOR`,
|
||||
`tr`.`buyerCode` AS `CodCOMPRADOR`,
|
||||
`tr`.`price__` AS `PREU`,
|
||||
`tr`.`clientFk` AS `Id_CLIENTE`,
|
||||
`tr`.`ok__` AS `OK`,
|
||||
`tr`.`total` AS `TOTAL`,
|
||||
`tr`.`buyed` AS `datCOMPRA`,
|
||||
`tr`.`ko__` AS `KO`
|
||||
FROM
|
||||
`vn`.`ticketRequest` `tr`;
|
||||
|
||||
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`ticketRequest__` AS
|
||||
SELECT
|
||||
`t`.`Id_ORDEN` AS `id`,
|
||||
`t`.`ORDEN` AS `description`,
|
||||
`t`.`requesterFk` AS `requesterFk`,
|
||||
`t`.`attenderFk` AS `attenderFk`,
|
||||
`t`.`CANTIDAD` AS `quantity`,
|
||||
`t`.`Id_ARTICLE` AS `itemFk`,
|
||||
`t`.`PRECIOMAX` AS `price`,
|
||||
`t`.`isOk` AS `isOk`,
|
||||
`t`.`Id_Movimiento` AS `saleFk`,
|
||||
`t`.`ticketFk` AS `ticketFk`,
|
||||
`t`.`COMENTARIO` AS `response`,
|
||||
`t`.`odbc_date` AS `created`
|
||||
FROM
|
||||
`vn2008`.`Ordenes` `t`;
|
|
@ -1,92 +0,0 @@
|
|||
DROP function IF EXISTS `vn`.`bionicCalcReverse`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`bionicCalcReverse`(vWarehouse INT,
|
||||
vMargin DECIMAL(10,3),
|
||||
vRetailedPrice DECIMAL(10,3),
|
||||
vM3 DECIMAL(10,3),
|
||||
vAddress INT,
|
||||
vAgencyMode INT) RETURNS decimal(10,3)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
DECLARE vGeneralInflationCoeficient INT;
|
||||
DECLARE vVerdnaturaVolumeBox BIGINT;
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vComponentRecovery VARCHAR(50) DEFAULT 'debtCollection';
|
||||
DECLARE vComponentMana VARCHAR(50) DEFAULT 'autoMana';
|
||||
DECLARE vComponentPort VARCHAR(50) DEFAULT 'delivery';
|
||||
DECLARE vComponentMargin VARCHAR(50) DEFAULT 'margin';
|
||||
DECLARE vComponentCost VARCHAR(50) DEFAULT 'purchaseValue';
|
||||
DECLARE vComponentCostValue DECIMAL(10,2);
|
||||
DECLARE vItem INT DEFAULT 98;
|
||||
DECLARE vItemCarryBox INT;
|
||||
|
||||
SELECT generalInflationCoeFicient, verdnaturaVolumeBox, itemCarryBox
|
||||
INTO vGeneralInflationCoeficient, vVerdnaturaVolumeBox, vItemCarryBox
|
||||
FROM bionicConfig;
|
||||
|
||||
SELECT clientFk INTO vClientFk FROM address WHERE id = vAddress;
|
||||
|
||||
-- Creamos la tabla tmp.bionicComponent
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.bionicComponent;
|
||||
CREATE TEMPORARY TABLE tmp.bionicComponent(
|
||||
`warehouseFk` smallint(5) unsigned NOT NULL,
|
||||
`itemFk` int(11) NOT NULL,
|
||||
`componentFk` int(10) unsigned NOT NULL,
|
||||
`value` decimal(10,4) NOT NULL,
|
||||
UNIQUE KEY `itemWarehouseComponent` (`itemFk`,`warehouseFk`,`componentFk`) USING HASH,
|
||||
KEY `itemWarehouse` (`itemFk`,`warehouseFk`) USING BTREE
|
||||
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
-- Margin
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, id, vMargin
|
||||
FROM component
|
||||
WHERE code = vComponentMargin;
|
||||
|
||||
-- Recobro
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, c.id, ROUND(LEAST(cr.recobro,0.25), 3)
|
||||
FROM bi.claims_ratio cr
|
||||
JOIN component c ON c.code = vComponentRecovery
|
||||
WHERE cr.Id_Cliente = vClientFk AND cr.recobro > 0.009;
|
||||
|
||||
-- Componente de maná automático, en función del maná acumulado por el comercial.
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, co.id, ROUND(ms.prices_modifier_rate, 3)
|
||||
FROM client c
|
||||
JOIN bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador
|
||||
JOIN component co ON co.code = vComponentMana
|
||||
WHERE ms.prices_modifier_activated AND c.id = vClientFk LIMIT 1;
|
||||
|
||||
-- Reparto
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, co.id, vGeneralInflationCoeficient
|
||||
* ROUND(
|
||||
vM3
|
||||
* az.price
|
||||
* az.inflation
|
||||
/ vVerdnaturaVolumeBox, 4
|
||||
)
|
||||
FROM agencyMode ag
|
||||
JOIN address a ON a.id = vAddress AND ag.id = vAgencyMode
|
||||
JOIN agencyProvince ap ON ap.agencyFk = ag.agencyFk
|
||||
AND ap.warehouseFk = vWarehouse AND ap.provinceFk = a.provinceFk
|
||||
JOIN agencyModeZone az ON az.agencyModeFk = vAgencyMode
|
||||
AND az.zone = ap.zone AND az.itemFk = 71 AND az.warehouseFk = vWarehouse
|
||||
JOIN component co ON co.code = vComponentPort;
|
||||
|
||||
-- Coste
|
||||
SELECT vRetailedPrice - SUM(`value`) INTO vComponentCostValue
|
||||
FROM tmp.bionicComponent;
|
||||
|
||||
INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`)
|
||||
SELECT vWarehouse, vItem, id,vComponentCostValue
|
||||
FROM component
|
||||
WHERE code = vComponentCost;
|
||||
|
||||
RETURN vComponentCostValue;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
|
||||
DROP procedure IF EXISTS `vn`.`timeBusiness_calculate`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`timeBusiness_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME)
|
||||
BEGIN
|
||||
|
||||
/**
|
||||
* Horas que debe trabajar un empleado según contrato y día.
|
||||
* @param vDatedFrom workerTimeControl
|
||||
* @param vDatedTo workerTimeControl
|
||||
* @table tmp.user(userFk)
|
||||
* @return tmp.timeBusinessCalculate
|
||||
*/
|
||||
DECLARE vHoursFullTime INT DEFAULT 40;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.businessFullTime;
|
||||
|
||||
CALL rangeDateInfo(vDatedFrom, vDatedTo);
|
||||
|
||||
CREATE TEMPORARY TABLE tmp.timeBusinessCalculate
|
||||
SELECT dated,
|
||||
businessFk,
|
||||
userFk,
|
||||
departmentFk,
|
||||
hourStart,
|
||||
hourEnd,
|
||||
timeWorkSeconds,
|
||||
SEC_TO_TIME(timeWorkSeconds) timeWorkSexagesimal,
|
||||
timeWorkSeconds / 3600 timeWorkDecimal,
|
||||
timeWorkSeconds timeBusinessSeconds,
|
||||
SEC_TO_TIME(timeWorkSeconds) timeBusinessSexagesimal,
|
||||
timeWorkSeconds / 3600 timeBusinessDecimal,
|
||||
type,
|
||||
permissionrate,
|
||||
hoursWeek
|
||||
FROM(SELECT rd.dated,
|
||||
b.business_id businessFk,
|
||||
w.userFk,
|
||||
bl.department_id departmentFk,
|
||||
IF(cl.hours_week = vHoursFullTime, NULL, GROUP_CONCAT(DISTINCT LEFT(j.start,2) ORDER BY j.start ASC SEPARATOR '-')) hourStart ,
|
||||
IF(cl.hours_week = vHoursFullTime, NULL, GROUP_CONCAT(DISTINCT LEFT(j.end,2) ORDER BY j.end ASC SEPARATOR '-')) hourEnd,
|
||||
IF(cl.hours_week = vHoursFullTime, 0, IFNULL(SUM(TIME_TO_SEC(j.end)) - SUM(TIME_TO_SEC(j.start)),0)) timeWorkSeconds,
|
||||
cs.type,
|
||||
cs.permissionRate,
|
||||
cl.hours_week hoursWeek
|
||||
FROM tmp.rangeDate rd
|
||||
LEFT JOIN postgresql.business b ON rd.dated BETWEEN b.date_start AND ifnull(b.date_end, vDatedTo )
|
||||
LEFT JOIN postgresql.profile AS pr ON b.client_id = pr.profile_id
|
||||
LEFT JOIN postgresql.person AS p ON pr.person_id = p.person_id
|
||||
LEFT JOIN vn.worker AS w ON p.id_trabajador = w.id
|
||||
JOIN tmp.`user` u ON u.userFK = w.userFK
|
||||
JOIN postgresql.business_labour AS bl ON b.business_id = bl.business_id
|
||||
LEFT JOIN postgresql.business_labour_payroll AS bp ON bl.business_id = bp.business_id
|
||||
LEFT JOIN postgresql.professional_category AS pc ON bl.professional_category_id = pc.professional_category_id
|
||||
LEFT JOIN postgresql.workcenter AS wc ON bl.workcenter_id = wc.workcenter_id
|
||||
LEFT JOIN postgresql.calendar_labour_type AS cl ON bl.calendar_labour_type_id = cl.calendar_labour_type_id
|
||||
LEFT JOIN postgresql.journey AS j ON j.business_id = b.business_id and j.day_id=WEEKDAY(rd.dated)+1
|
||||
LEFT JOIN postgresql.calendar_employee ce ON ce.business_id=b.business_id and ce.date = rd.dated
|
||||
LEFT JOIN postgresql.calendar_state cs ON cs.calendar_state_id = ce.calendar_state_id
|
||||
WHERE rd.dated BETWEEN vDatedFrom AND vDatedTo
|
||||
GROUP BY w.userFk,dated
|
||||
)sub;
|
||||
|
||||
|
||||
UPDATE tmp.timeBusinessCalculate t
|
||||
SET t.timeWorkSeconds = vHoursFullTime / 5 * 3600,
|
||||
t.timeWorkSexagesimal = SEC_TO_TIME( vHoursFullTime / 5 * 3600),
|
||||
t.timeWorkDecimal = vHoursFullTime / 5,
|
||||
t.timeBusinessSeconds = vHoursFullTime / 5 * 3600,
|
||||
t.timeBusinessSexagesimal = SEC_TO_TIME( vHoursFullTime / 5 * 3600),
|
||||
t.timeBusinessDecimal = vHoursFullTime / 5
|
||||
WHERE DAYOFWEEK(t.dated) IN(2,3,4,5,6) AND hoursWeek = vHoursFullTime ;
|
||||
|
||||
UPDATE tmp.timeBusinessCalculate t
|
||||
SET t.timeWorkSeconds = t.timeWorkSeconds - (t.timeWorkSeconds * permissionrate) ,
|
||||
t.timeWorkSexagesimal = SEC_TO_TIME(t.timeWorkSeconds - (t.timeWorkSeconds * permissionrate)),
|
||||
t.timeWorkDecimal = t.timeWorkDecimal - (t.timeWorkDecimal * permissionrate)
|
||||
WHERE permissionrate <> 0;
|
||||
|
||||
UPDATE tmp.timeBusinessCalculate t
|
||||
JOIN postgresql.calendar_labour cl ON cl.day = t.dated
|
||||
JOIN postgresql.business_labour bl ON bl.business_id = t.businessFk AND bl.workcenter_id = cl.workcenter_id
|
||||
SET t.timeWorkSeconds = 0,
|
||||
t.timeWorkSexagesimal = 0,
|
||||
t.timeWorkDecimal = 0,
|
||||
t.permissionrate = 1,
|
||||
t.type = 'Festivo'
|
||||
WHERE t.type IS NULL;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.rangeDate;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
DROP TRIGGER IF EXISTS `vn`.`entry_beforeUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`entry_beforeUpdate`
|
||||
BEFORE UPDATE ON `entry`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vIsVirtual BOOL;
|
||||
DECLARE vPrintedCount INT;
|
||||
DECLARE vHasDistinctWarehouses BOOL;
|
||||
|
||||
IF !(NEW.travelFk <=> OLD.travelFk) THEN
|
||||
SELECT COUNT(*) > 0 INTO vIsVirtual
|
||||
FROM entryVirtual WHERE entryFk = NEW.id;
|
||||
|
||||
SELECT !(o.warehouseInFk <=> n.warehouseInFk)
|
||||
OR !(o.warehouseOutFk <=> n.warehouseOutFk)
|
||||
INTO vHasDistinctWarehouses
|
||||
FROM travel o, travel n
|
||||
WHERE o.id = OLD.travelFk
|
||||
AND n.id = NEW.travelFk;
|
||||
|
||||
IF vIsVirtual AND vHasDistinctWarehouses THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'A cloned entry cannot be moved to a travel with different warehouses';
|
||||
END IF;
|
||||
|
||||
IF NEW.travelFk IS NULL THEN
|
||||
SELECT COUNT(*) INTO vPrintedCount
|
||||
FROM buy
|
||||
WHERE entryFk = OLD.id
|
||||
AND printedStickers > 0;
|
||||
|
||||
IF vPrintedCount > 0 THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'An entry that contains lines with printed labels cannot be deleted';
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF !(NEW.supplierFk <=> OLD.supplierFk) THEN
|
||||
SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk);
|
||||
END IF;
|
||||
|
||||
IF !(NEW.travelFk <=> OLD.travelFk)
|
||||
OR !(NEW.currencyFk <=> OLD.currencyFk) THEN
|
||||
SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk,NEW.supplierFk);
|
||||
END IF;
|
||||
|
||||
IF !(ABS(NEW.isBooked) <=> ABS(OLD.isBooked)) THEN
|
||||
INSERT INTO entryLog SET
|
||||
action = 'update',
|
||||
description = 'Cambia a Contabilizada',
|
||||
userFk = myWorker_getId(),
|
||||
originFk = NEW.id;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,120 +0,0 @@
|
|||
|
||||
DROP procedure IF EXISTS `hedera`.`tpvTransaction_confirm`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`tpvTransaction_confirm`(
|
||||
vAmount INT
|
||||
,vOrder INT
|
||||
,vMerchant INT
|
||||
,vCurrency INT
|
||||
,vResponse INT
|
||||
,vErrorCode VARCHAR(10)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Confirma una transacción previamente iniciada, reescribiendo
|
||||
* sus datos por los confirmados por el banco (solo si estos difieren).
|
||||
* Genera el recibo y su correspondiente entrada en caja.
|
||||
*
|
||||
* @param vAmount Cantidad confirmada
|
||||
* @param vOrder Identificador de transacción
|
||||
* @param vMerchant Identificador de comercio
|
||||
* @param vCurrency Identificador de moneda
|
||||
* @param vResponse Identificador de respuesta del banco
|
||||
* @param vErrorCode Código de error del banco, si lo hubiera
|
||||
*/
|
||||
DECLARE vReceipt INT;
|
||||
DECLARE vStatus VARCHAR(10);
|
||||
DECLARE vCustomer INT;
|
||||
DECLARE vBank INT;
|
||||
DECLARE vCompany INT;
|
||||
DECLARE vEmployee INT;
|
||||
DECLARE vIsDuplicated BOOLEAN;
|
||||
DECLARE vDate DATE;
|
||||
DECLARE vConcept VARCHAR(25) DEFAULT 'Cobro Web';
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
SELECT COUNT(*) > 0 INTO vIsDuplicated
|
||||
FROM tpvTransaction
|
||||
WHERE id = vOrder AND response IS NOT NULL
|
||||
FOR UPDATE;
|
||||
|
||||
IF vIsDuplicated
|
||||
THEN
|
||||
CALL util.throw ('TRANSACTION_DUPLICATED');
|
||||
END IF;
|
||||
|
||||
IF vResponse BETWEEN 0 AND 99
|
||||
THEN
|
||||
SELECT
|
||||
t.clientFk
|
||||
,m.bankFk
|
||||
,m.companyFk
|
||||
,c.employeeFk
|
||||
,DATE(t.created)
|
||||
INTO
|
||||
vCustomer
|
||||
,vBank
|
||||
,vCompany
|
||||
,vEmployee
|
||||
,vDate
|
||||
FROM tpvMerchant m
|
||||
JOIN tpvConfig c
|
||||
LEFT JOIN tpvTransaction t ON t.id = vOrder
|
||||
WHERE m.id = vMerchant;
|
||||
|
||||
INSERT INTO vn.receipt
|
||||
SET
|
||||
amountPaid = vAmount / 100
|
||||
,payed = vDate
|
||||
,workerFk = vEmployee
|
||||
,bankFk = vBank
|
||||
,clientFk = vCustomer
|
||||
,companyFk = vCompany
|
||||
,invoiceFk = vConcept
|
||||
,isConciliate = TRUE;
|
||||
|
||||
SET vReceipt = LAST_INSERT_ID();
|
||||
SET vStatus = 'ok';
|
||||
|
||||
-- Código redundante
|
||||
|
||||
DO vn.till_new
|
||||
(
|
||||
vCustomer
|
||||
,vBank
|
||||
,vAmount / 100
|
||||
,vConcept
|
||||
,vDate
|
||||
,'A'
|
||||
,TRUE
|
||||
,vCustomer
|
||||
,vCompany
|
||||
,vEmployee
|
||||
);
|
||||
ELSE
|
||||
SET vReceipt = NULL;
|
||||
SET vStatus = 'ko';
|
||||
END IF;
|
||||
|
||||
UPDATE tpvTransaction
|
||||
SET
|
||||
merchantFk = vMerchant
|
||||
,receiptFk = vReceipt
|
||||
,amount = vAmount
|
||||
,response = vResponse
|
||||
,errorCode = vErrorCode
|
||||
,status = vStatus
|
||||
WHERE id = vOrder;
|
||||
COMMIT;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
|
||||
DROP procedure IF EXISTS `hedera`.`tpvTransaction_undo`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`tpvTransaction_undo`(vSelf INT)
|
||||
BEGIN
|
||||
DECLARE vCustomer INT;
|
||||
DECLARE vAmount DOUBLE;
|
||||
DECLARE vReceipt INT;
|
||||
DECLARE vDate DATE;
|
||||
DECLARE vBank INT;
|
||||
DECLARE vAccount VARCHAR(12);
|
||||
DECLARE vSubaccount VARCHAR(12);
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
SELECT
|
||||
t.clientFk
|
||||
,t.amount / 100
|
||||
,t.receiptFk
|
||||
,DATE(t.created)
|
||||
,m.bankFk
|
||||
INTO
|
||||
vCustomer
|
||||
,vAmount
|
||||
,vReceipt
|
||||
,vDate
|
||||
,vBank
|
||||
FROM tpvTransaction t
|
||||
JOIN tpvMerchant m ON m.id = t.merchantFk
|
||||
JOIN tpvConfig c
|
||||
WHERE t.id = vSelf
|
||||
FOR UPDATE;
|
||||
|
||||
-- Elimina el recibo
|
||||
|
||||
DELETE FROM vn.receipt
|
||||
WHERE id = vReceipt LIMIT 1;
|
||||
|
||||
-- Elimina la entrada de cajas
|
||||
|
||||
DELETE FROM vn.till
|
||||
WHERE bankFk = vBank
|
||||
AND DATE(dated) = vDate
|
||||
AND `in` = vAmount
|
||||
LIMIT 1;
|
||||
|
||||
-- Elimina los asientos contables
|
||||
|
||||
SELECT accountingAccount INTO vSubaccount
|
||||
FROM vn.`client` WHERE id = vCustomer;
|
||||
|
||||
SELECT account INTO vAccount
|
||||
FROM vn.bank WHERE id = vBank;
|
||||
|
||||
DELETE FROM vn.XDiario
|
||||
WHERE SUBCTA = vSubaccount
|
||||
AND CONTRA = vAccount
|
||||
AND DATE(FECHA) = vDate
|
||||
AND EUROHABER = vAmount
|
||||
LIMIT 1;
|
||||
|
||||
DELETE FROM vn.XDiario
|
||||
WHERE CONTRA = vSubaccount
|
||||
AND SUBCTA = vAccount
|
||||
AND DATE(FECHA) = vDate
|
||||
AND EURODEBE = vAmount
|
||||
LIMIT 1;
|
||||
|
||||
-- Actualiza la transaccion
|
||||
|
||||
UPDATE tpvTransaction
|
||||
SET response = NULL, status = 'started'
|
||||
WHERE id = vSelf;
|
||||
|
||||
COMMIT;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `catalog_componentCalculate`;
|
||||
DROP procedure IF EXISTS `vn`.`catalog_componentCalculate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `catalog_componentCalculate`(
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`catalog_componentCalculate`(
|
||||
vZoneFk INT,
|
||||
vAddressFk INT,
|
||||
vShipped DATE)
|
||||
|
@ -19,7 +17,6 @@ proc: BEGIN
|
|||
* packing, grouping, groupingMode, buyFk, typeFk)
|
||||
* @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, grouping, price)
|
||||
*/
|
||||
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vGeneralInflationCoefficient INT DEFAULT 1;
|
||||
DECLARE vMinimumDensityWeight INT DEFAULT 167;
|
||||
|
@ -118,11 +115,11 @@ proc: BEGIN
|
|||
WHERE cr.recobro > 0.009;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + prices_modifier_rate), 3) as manaAuto
|
||||
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 bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador
|
||||
WHERE ms.prices_modifier_activated
|
||||
JOIN workerMana wm ON c.salesPersonFk = wm.workerFk
|
||||
WHERE wm.isPricesModifierActivated
|
||||
HAVING manaAuto <> 0;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
|
@ -254,6 +251,4 @@ proc: BEGIN
|
|||
tmp.ticketComponentRate,
|
||||
tmp.ticketComponentCopy;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE `vn`.`chatConfig`
|
||||
ADD COLUMN `host` VARCHAR(255) NOT NULL AFTER `id`,
|
||||
CHANGE COLUMN `uri` `api` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL ;
|
||||
|
||||
UPDATE `vn`.`chatConfig` SET `host` = 'https://chat.verdnatura.es' WHERE (`id` = '1');
|
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE `vn`.`greugeConfig` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`freightPickUpPrice` DECIMAL(10,2) NOT NULL,
|
||||
PRIMARY KEY (`id`));
|
||||
|
||||
INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11');
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
DROP procedure IF EXISTS `vn`.`manaSpellersRequery`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`manaSpellersRequery`(vWorkerFk INTEGER)
|
||||
BEGIN
|
||||
|
||||
DECLARE vWorkerIsExcluded BOOLEAN;
|
||||
DECLARE vFromDated DATE;
|
||||
DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,CURDATE());
|
||||
DECLARE vMana INT;
|
||||
DECLARE vAutoMana INT;
|
||||
DECLARE vManaBank INT;
|
||||
DECLARE vManaGreugeType INT;
|
||||
|
||||
SELECT id INTO vMana
|
||||
FROM `component` WHERE code = 'mana';
|
||||
|
||||
SELECT id INTO vAutoMana
|
||||
FROM `component` WHERE code = 'autoMana';
|
||||
|
||||
SELECT id INTO vManaBank
|
||||
FROM `bank` WHERE code = 'mana';
|
||||
|
||||
SELECT id INTO vManaGreugeType
|
||||
FROM `greugeType` WHERE code = 'mana';
|
||||
|
||||
SELECT COUNT(*) INTO vWorkerIsExcluded
|
||||
FROM workerManaExcluded
|
||||
WHERE workerFk = vWorkerFk;
|
||||
|
||||
IF NOT vWorkerIsExcluded THEN
|
||||
|
||||
SELECT max(dated) INTO vFromDated
|
||||
FROM clientManaCache;
|
||||
|
||||
REPLACE workerMana (workerFk, amount)
|
||||
SELECT vWorkerFk, sum(mana) FROM
|
||||
(
|
||||
SELECT s.quantity * sc.value as mana
|
||||
FROM ticket t
|
||||
JOIN address a ON a.id = t.addressFk
|
||||
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)
|
||||
AND t.shipped > vFromDated AND t.shipped < vToDated
|
||||
UNION ALL
|
||||
SELECT - r.amountPaid
|
||||
FROM receipt r
|
||||
JOIN client c ON c.id = r.clientFk
|
||||
WHERE c.salesPersonFk = vWorkerFk AND bankFk = vManaBank
|
||||
AND payed > vFromDated
|
||||
UNION ALL
|
||||
SELECT g.amount
|
||||
FROM greuge g
|
||||
JOIN client c ON c.id = g.clientFk
|
||||
WHERE c.salesPersonFk = vWorkerFk AND g.greugeTypeFk = vManaGreugeType
|
||||
AND g.shipped > vFromDated and g.shipped < CURDATE()
|
||||
UNION ALL
|
||||
SELECT cc.mana
|
||||
FROM clientManaCache cc
|
||||
JOIN client c ON c.id = cc.clientFk
|
||||
WHERE c.salesPersonFk = vWorkerFk AND cc.dated = vFromDated
|
||||
) sub;
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
File diff suppressed because one or more lines are too long
|
@ -20,6 +20,18 @@ INSERT INTO `vn`.`bionicConfig` (`generalInflationCoeficient`, `minimumDensityVo
|
|||
VALUES
|
||||
(1.30, 167.00, 138000, 71);
|
||||
|
||||
INSERT INTO `vn`.`chatConfig` (`host`, `api`)
|
||||
VALUES
|
||||
('https://chat.verdnatura.es', 'https://chat.verdnatura.es/api/v1');
|
||||
|
||||
INSERT IGNORE INTO `vn`.`greugeConfig`(`id`, `freightPickUpPrice`)
|
||||
VALUES
|
||||
('1', '11');
|
||||
|
||||
INSERT INTO `vn`.`packagingConfig`(`upperGap`)
|
||||
VALUES
|
||||
('10');
|
||||
|
||||
UPDATE `account`.`role` SET id = 100 WHERE id = 0;
|
||||
|
||||
INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`, `lang`)
|
||||
|
@ -205,23 +217,23 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`)
|
|||
(4, 'GCN Channel'),
|
||||
(5, 'The Newspaper');
|
||||
|
||||
INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`fax`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`,`mailAddress`,`cplusTerIdNifFk`,`hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`)
|
||||
INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`fax`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`,`mailAddress`,`cplusTerIdNifFk`,`hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`)
|
||||
VALUES
|
||||
(101, 'Bruce Wayne', '84612325V', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1),
|
||||
(102, 'Petter Parker', '87945234L', 'Spider man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1),
|
||||
(103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 19, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1),
|
||||
(104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1),
|
||||
(105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 8, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1),
|
||||
(106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1),
|
||||
(107, 'Hank Pym', '09854837G', 'Ant man', 'Hawk', 'Anthill', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1),
|
||||
(108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1),
|
||||
(109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1),
|
||||
(110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1),
|
||||
(111, 'Missing', NULL, 'Missing man', 'Anton', 'The space', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1),
|
||||
(112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1);
|
||||
(101, 'Bruce Wayne', '84612325V', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 333333333, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1),
|
||||
(102, 'Petter Parker', '87945234L', 'Spider man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 333333333, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1),
|
||||
(103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 333333333, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 19, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1),
|
||||
(104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 333333333, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1),
|
||||
(105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 333333333, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 8, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1),
|
||||
(106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 333333333, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1),
|
||||
(107, 'Hank Pym', '09854837G', 'Ant man', 'Hawk', 'Anthill', 'Silla', 46460, 333333333, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1),
|
||||
(108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 333333333, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1),
|
||||
(109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 333333333, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1),
|
||||
(110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 333333333, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1),
|
||||
(111, 'Missing', NULL, 'Missing man', 'Anton', 'The space', 'Silla', 46460, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1),
|
||||
(112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city', 'Silla', 46460, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1);
|
||||
|
||||
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `phone`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
|
||||
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'SILLA', 46460, 623111111, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, CURDATE(), 1
|
||||
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
|
||||
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'SILLA', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, CURDATE(), 1
|
||||
FROM `account`.`role` `r`
|
||||
WHERE `r`.`hasLogin` = 1;
|
||||
|
||||
|
@ -586,7 +598,8 @@ INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`)
|
|||
(3, 'Mana', 'mana'),
|
||||
(4, 'Reclaim', 'reclaim'),
|
||||
(5, 'Heritage', 'heritage'),
|
||||
(6, 'Miscellaneous', 'miscellaneous');
|
||||
(6, 'Miscellaneous', 'miscellaneous'),
|
||||
(7, 'Freight Pickup', 'freightPickUp');
|
||||
|
||||
INSERT INTO `vn`.`greuge`(`id`, `clientFk`, `description`, `amount`, `shipped`, `created`, `greugeTypeFk`, `ticketFk`)
|
||||
VALUES
|
||||
|
@ -1913,6 +1926,11 @@ INSERT INTO `vn`.`queuePriority`(`id`, `priority`)
|
|||
(2, 'Normal'),
|
||||
(3, 'Baja');
|
||||
|
||||
INSERT INTO `vn`.`userPhoneType` (`code`, `description`)
|
||||
VALUES
|
||||
('businessPhone', 'Telefono de empresa del usuario'),
|
||||
('personalPhone', 'Telefono personal del usuario');
|
||||
|
||||
INSERT INTO `vn`.`userPhone`(`id`, `userFk`, `typeFk`, `phone`)
|
||||
VALUES
|
||||
(1, 101, 'personalPhone', 1111111111),
|
||||
|
@ -1979,3 +1997,4 @@ INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `week
|
|||
VALUES
|
||||
(1, 43200, 129600, 734400, 43200, 50400);
|
||||
|
||||
INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11');
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,6 @@
|
|||
SCHEMAS=(
|
||||
account
|
||||
bi
|
||||
bs
|
||||
cache
|
||||
edi
|
||||
hedera
|
||||
|
|
|
@ -10,6 +10,8 @@ services:
|
|||
- ${PORT_FRONT}:80
|
||||
links:
|
||||
- back
|
||||
deploy:
|
||||
replicas: 3
|
||||
back:
|
||||
image: registry.verdnatura.es/salix-back:${TAG}
|
||||
restart: unless-stopped
|
||||
|
@ -19,6 +21,8 @@ services:
|
|||
environment:
|
||||
- NODE_ENV
|
||||
volumes:
|
||||
- /containers/salix:/etc/salix
|
||||
- /mnt/storage/containers/salix:/etc/salix
|
||||
- /mnt/storage/pdfs:/var/lib/salix/pdfs
|
||||
- /mnt/storage/dms:/var/lib/salix/dms
|
||||
deploy:
|
||||
replicas: 6
|
||||
|
|
|
@ -48,11 +48,11 @@ export default {
|
|||
},
|
||||
clientBasicData: {
|
||||
basicDataButton: 'vn-left-menu a[ui-sref="client.card.basicData"]',
|
||||
nameInput: 'vn-client-basic-data [name="name"]',
|
||||
contactInput: 'vn-client-basic-data [name="contact"]',
|
||||
phoneInput: 'vn-client-basic-data [name="phone"]',
|
||||
mobileInput: 'vn-client-basic-data [name="mobile"]',
|
||||
emailInput: 'vn-client-basic-data [name="email"]',
|
||||
nameInput: 'vn-textfield[ng-model="$ctrl.client.name"]',
|
||||
contactInput: 'vn-textfield[ng-model="$ctrl.client.contact"]',
|
||||
emailInput: 'vn-textfield[ng-model="$ctrl.client.email"]',
|
||||
salesPersonAutocomplete: 'vn-autocomplete[ng-model="$ctrl.client.salesPersonFk"]',
|
||||
channelAutocomplete: 'vn-autocomplete[ng-model="$ctrl.client.contactChannelFk"]',
|
||||
saveButton: `button[type=submit]`
|
||||
|
@ -346,11 +346,11 @@ export default {
|
|||
acceptDeleteTurn: '.vn-confirm.shown button[response="accept"]'
|
||||
},
|
||||
createTicketView: {
|
||||
clientAutocomplete: 'vn-ticket-create vn-autocomplete[ng-model="$ctrl.clientFk"]',
|
||||
addressAutocomplete: 'vn-ticket-create vn-autocomplete[ng-model="$ctrl.addressFk"]',
|
||||
clientAutocomplete: 'vn-ticket-create vn-autocomplete[ng-model="$ctrl.clientId"]',
|
||||
addressAutocomplete: 'vn-ticket-create vn-autocomplete[ng-model="$ctrl.addressId"]',
|
||||
deliveryDateInput: 'vn-ticket-create vn-date-picker[ng-model="$ctrl.landed"]',
|
||||
warehouseAutocomplete: 'vn-ticket-create vn-autocomplete[ng-model="$ctrl.warehouseFk"]',
|
||||
agencyAutocomplete: 'vn-ticket-create vn-autocomplete[ng-model="$ctrl.ticket.agencyModeFk"]',
|
||||
warehouseAutocomplete: 'vn-ticket-create vn-autocomplete[ng-model="$ctrl.warehouseId"]',
|
||||
agencyAutocomplete: 'vn-ticket-create vn-autocomplete[ng-model="$ctrl.agencyModeId"]',
|
||||
createButton: `button[type=submit]`
|
||||
},
|
||||
ticketDescriptor: {
|
||||
|
@ -359,7 +359,7 @@ export default {
|
|||
goBackToModuleIndexButton: 'vn-ticket-descriptor a[ui-sref="ticket.index"]',
|
||||
moreMenu: 'vn-ticket-descriptor vn-icon-menu[icon=more_vert]',
|
||||
moreMenuAddStowaway: '.vn-drop-down.shown li[name="Add stowaway"]',
|
||||
moreMenuDeleteStowawayButton: '.vn-drop-down.shown li[name="Remove stowaway"]',
|
||||
moreMenuDeleteStowawayButton: '.vn-drop-down.shown li[name="Delete stowaway"]',
|
||||
moreMenuAddToTurn: '.vn-drop-down.shown li[name="Add turn"]',
|
||||
moreMenuDeleteTicket: '.vn-drop-down.shown li[name="Delete ticket"]',
|
||||
moreMenuMakeInvoice: '.vn-drop-down.shown li[name="Make invoice"]',
|
||||
|
|
|
@ -14,159 +14,130 @@ describe('Client Edit basicData path', () => {
|
|||
page.close();
|
||||
});
|
||||
|
||||
// describe('as employee', () => {
|
||||
it('should not be able to change the salesPerson', async() => {
|
||||
// await page.wait(selectors.clientBasicData.nameInput);
|
||||
// const result = await page.evaluate(selector => {
|
||||
// return document.querySelector(selector).disabled;
|
||||
// }, `${selectors.clientBasicData.salesPersonAutocomplete} input`);
|
||||
describe('as employee', () => {
|
||||
it('should not be able to change the salesPerson', async() => {
|
||||
const result = await nightmare
|
||||
.wait(selectors.clientBasicData.nameInput)
|
||||
.evaluate(selector => {
|
||||
return document.querySelector(selector).disabled;
|
||||
}, `${selectors.clientBasicData.salesPersonAutocomplete} input`);
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should edit the client basic data but leave salesPerson untainted', async() => {
|
||||
const result = await nightmare
|
||||
.clearInput(selectors.clientBasicData.nameInput)
|
||||
.write(selectors.clientBasicData.nameInput, 'Ptonomy Wallace')
|
||||
.clearInput(selectors.clientBasicData.contactInput)
|
||||
.write(selectors.clientBasicData.contactInput, 'David Haller')
|
||||
.clearInput(selectors.clientBasicData.emailInput)
|
||||
.write(selectors.clientBasicData.emailInput, 'PWallace@verdnatura.es')
|
||||
.autocompleteSearch(selectors.clientBasicData.channelAutocomplete, 'Rumors on the streets')
|
||||
.waitToClick(selectors.clientBasicData.saveButton)
|
||||
.waitForLastSnackbar();
|
||||
|
||||
expect(result).toEqual('Data saved!');
|
||||
});
|
||||
|
||||
it('should confirm the name have been edited', async() => {
|
||||
const result = await nightmare
|
||||
.reloadSection('client.card.basicData')
|
||||
.waitToGetProperty(selectors.clientBasicData.nameInput, 'value');
|
||||
|
||||
expect(result).toEqual('Ptonomy Wallace');
|
||||
});
|
||||
|
||||
it('should confirm the contact name have been edited', async() => {
|
||||
const result = await nightmare
|
||||
.waitToGetProperty(selectors.clientBasicData.contactInput, 'value');
|
||||
|
||||
expect(result).toEqual('David Haller');
|
||||
});
|
||||
|
||||
it('should confirm the email have been edited', async() => {
|
||||
const result = await nightmare
|
||||
.waitToGetProperty(selectors.clientBasicData.emailInput, 'value');
|
||||
|
||||
expect(result).toEqual('PWallace@verdnatura.es');
|
||||
});
|
||||
|
||||
it('should confirm the channel have been selected', async() => {
|
||||
const result = await nightmare
|
||||
.waitToGetProperty(`${selectors.clientBasicData.channelAutocomplete} input`, 'value');
|
||||
|
||||
expect(result).toEqual('Rumors on the streets');
|
||||
});
|
||||
});
|
||||
|
||||
// it('should edit the client basic data but leave salesPerson untainted', async() => {
|
||||
// await page.clearInput(selectors.clientBasicData.nameInput);
|
||||
// await page.write(selectors.clientBasicData.nameInput, 'Ptonomy Wallace');
|
||||
// await page.clearInput(selectors.clientBasicData.contactInput);
|
||||
// await page.write(selectors.clientBasicData.contactInput, 'David Haller');
|
||||
// await page.clearInput(selectors.clientBasicData.phoneInput);
|
||||
// await page.write(selectors.clientBasicData.phoneInput, '987654321');
|
||||
// await page.clearInput(selectors.clientBasicData.mobileInput);
|
||||
// await page.write(selectors.clientBasicData.mobileInput, '123456789');
|
||||
// await page.clearInput(selectors.clientBasicData.emailInput);
|
||||
// await page.write(selectors.clientBasicData.emailInput, 'PWallace@verdnatura.es');
|
||||
// await page.autocompleteSearch(selectors.clientBasicData.channelAutocomplete, 'Rumors on the streets');
|
||||
// await page.waitToClick(selectors.clientBasicData.saveButton);
|
||||
// const result = await page.waitForLastSnackbar();
|
||||
describe('as salesAssistant', () => {
|
||||
beforeAll(() => {
|
||||
nightmare
|
||||
.loginAndModule('salesASsistant', 'client')
|
||||
.accessToSearchResult('Ptonomy Wallace')
|
||||
.accessToSection('client.card.basicData');
|
||||
});
|
||||
|
||||
// expect(result).toEqual('Data saved!');
|
||||
// });
|
||||
it('should be able to change the salesPerson', async() => {
|
||||
const result = await nightmare
|
||||
.wait(selectors.clientBasicData.nameInput)
|
||||
.evaluate(selector => {
|
||||
return document.querySelector(selector).disabled;
|
||||
}, `${selectors.clientBasicData.salesPersonAutocomplete} input`);
|
||||
|
||||
// it('should confirm the name have been edited', async() => {
|
||||
// await page.reloadSection('client.card.basicData');
|
||||
// const result = await page.waitToGetProperty(selectors.clientBasicData.nameInput, 'value');
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
// expect(result).toEqual('Ptonomy Wallace');
|
||||
// });
|
||||
it('should edit the client basic data including salesPerson', async() => {
|
||||
const result = await nightmare
|
||||
.clearInput(selectors.clientBasicData.nameInput)
|
||||
.write(selectors.clientBasicData.nameInput, 'Ororo Munroe')
|
||||
.clearInput(selectors.clientBasicData.contactInput)
|
||||
.write(selectors.clientBasicData.contactInput, 'Black Panther')
|
||||
.clearInput(selectors.clientBasicData.emailInput)
|
||||
.write(selectors.clientBasicData.emailInput, 'Storm@verdnatura.es')
|
||||
.autocompleteSearch(selectors.clientBasicData.salesPersonAutocomplete, 'replenisherNick')
|
||||
.autocompleteSearch(selectors.clientBasicData.channelAutocomplete, 'Metropolis newspaper')
|
||||
.waitToClick(selectors.clientBasicData.saveButton)
|
||||
.waitForLastSnackbar();
|
||||
|
||||
// it('should confirm the contact name have been edited', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(selectors.clientBasicData.contactInput, 'value');
|
||||
expect(result).toEqual('Data saved!');
|
||||
});
|
||||
|
||||
// expect(result).toEqual('David Haller');
|
||||
// });
|
||||
it('should now confirm the name have been edited', async() => {
|
||||
const result = await nightmare
|
||||
.reloadSection('client.card.basicData')
|
||||
.waitToGetProperty(selectors.clientBasicData.nameInput, 'value');
|
||||
|
||||
// it('should confirm the landline phone number have been added', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(selectors.clientBasicData.phoneInput, 'value');
|
||||
expect(result).toEqual('Ororo Munroe');
|
||||
});
|
||||
|
||||
// expect(result).toEqual('987654321');
|
||||
// });
|
||||
it('should now confirm the contact name have been edited', async() => {
|
||||
const result = await nightmare
|
||||
.waitToGetProperty(selectors.clientBasicData.contactInput, 'value');
|
||||
|
||||
// it('should confirm the mobile phone number have been added', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(selectors.clientBasicData.mobileInput, 'value');
|
||||
expect(result).toEqual('Black Panther');
|
||||
});
|
||||
|
||||
// expect(result).toEqual('123456789');
|
||||
// });
|
||||
it('should now confirm the email have been edited', async() => {
|
||||
const result = await nightmare
|
||||
.waitToGetProperty(selectors.clientBasicData.emailInput, 'value');
|
||||
|
||||
// it('should confirm the email have been edited', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(selectors.clientBasicData.emailInput, 'value');
|
||||
expect(result).toEqual('Storm@verdnatura.es');
|
||||
});
|
||||
|
||||
// expect(result).toEqual('PWallace@verdnatura.es');
|
||||
// });
|
||||
it('should confirm the sales person have been selected', async() => {
|
||||
const result = await nightmare
|
||||
.waitToGetProperty(`${selectors.clientBasicData.salesPersonAutocomplete} input`, 'value');
|
||||
|
||||
// it('should confirm the channel have been selected', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(`${selectors.clientBasicData.channelAutocomplete} input`, 'value');
|
||||
expect(result).toEqual('replenisherNick');
|
||||
});
|
||||
|
||||
// expect(result).toEqual('Rumors on the streets');
|
||||
// });
|
||||
// });
|
||||
it('should now confirm the channel have been selected', async() => {
|
||||
const result = await nightmare
|
||||
.waitToGetProperty(`${selectors.clientBasicData.channelAutocomplete} input`, 'value');
|
||||
|
||||
// describe('as salesAssistant', () => {
|
||||
// beforeAll(async() => {
|
||||
// await page.loginAndModule('salesASsistant', 'client');
|
||||
// await page.accessToSearchResult('Ptonomy Wallace');
|
||||
// await page.accessToSection('client.card.basicData');
|
||||
// });
|
||||
|
||||
// it('should be able to change the salesPerson', async() => {
|
||||
// await page.wait(selectors.clientBasicData.nameInput);
|
||||
// const result = await page.evaluate(selector => {
|
||||
// return document.querySelector(selector).disabled;
|
||||
// }, `${selectors.clientBasicData.salesPersonAutocomplete} input`);
|
||||
|
||||
// expect(result).toBeFalsy();
|
||||
// });
|
||||
|
||||
// it('should edit the client basic data including salesPerson', async() => {
|
||||
// await page.clearInput(selectors.clientBasicData.nameInput);
|
||||
// await page.write(selectors.clientBasicData.nameInput, 'Ororo Munroe');
|
||||
// await page.clearInput(selectors.clientBasicData.contactInput);
|
||||
// await page.write(selectors.clientBasicData.contactInput, 'Black Panther');
|
||||
// await page.clearInput(selectors.clientBasicData.phoneInput);
|
||||
// await page.write(selectors.clientBasicData.phoneInput, '123456789');
|
||||
// await page.clearInput(selectors.clientBasicData.mobileInput);
|
||||
// await page.write(selectors.clientBasicData.mobileInput, '987654321');
|
||||
// await page.clearInput(selectors.clientBasicData.emailInput);
|
||||
// await page.write(selectors.clientBasicData.emailInput, 'Storm@verdnatura.es');
|
||||
// await page.autocompleteSearch(selectors.clientBasicData.salesPersonAutocomplete, 'replenisherNick');
|
||||
// await page.autocompleteSearch(selectors.clientBasicData.channelAutocomplete, 'Metropolis newspaper');
|
||||
// await page.waitToClick(selectors.clientBasicData.saveButton);
|
||||
// const result = await page.waitForLastSnackbar();
|
||||
|
||||
// expect(result).toEqual('Data saved!');
|
||||
// });
|
||||
|
||||
// it('should now confirm the name have been edited', async() => {
|
||||
// await page.reloadSection('client.card.basicData');
|
||||
// const result = await page.waitToGetProperty(selectors.clientBasicData.nameInput, 'value');
|
||||
|
||||
// expect(result).toEqual('Ororo Munroe');
|
||||
// });
|
||||
|
||||
// it('should now confirm the contact name have been edited', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(selectors.clientBasicData.contactInput, 'value');
|
||||
|
||||
// expect(result).toEqual('Black Panther');
|
||||
// });
|
||||
|
||||
// it('should now confirm the landline phone number have been added', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(selectors.clientBasicData.phoneInput, 'value');
|
||||
|
||||
// expect(result).toEqual('123456789');
|
||||
// });
|
||||
|
||||
// it('should now confirm the mobile phone number have been added', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(selectors.clientBasicData.mobileInput, 'value');
|
||||
|
||||
// expect(result).toEqual('987654321');
|
||||
// });
|
||||
|
||||
// it('should now confirm the email have been edited', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(selectors.clientBasicData.emailInput, 'value');
|
||||
|
||||
// expect(result).toEqual('Storm@verdnatura.es');
|
||||
// });
|
||||
|
||||
// it('should confirm the sales person have been selected', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(`${selectors.clientBasicData.salesPersonAutocomplete} input`, 'value');
|
||||
|
||||
// expect(result).toEqual('replenisherNick');
|
||||
// });
|
||||
|
||||
// it('should now confirm the channel have been selected', async() => {
|
||||
// const result = await page
|
||||
// .waitToGetProperty(`${selectors.clientBasicData.channelAutocomplete} input`, 'value');
|
||||
|
||||
// expect(result).toEqual('Metropolis newspaper');
|
||||
// });
|
||||
// });
|
||||
expect(result).toEqual('Metropolis newspaper');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -253,7 +253,7 @@ export default class Autocomplete extends Field {
|
|||
}
|
||||
|
||||
showDropDown(search) {
|
||||
if (this.readonly) return;
|
||||
if (!this.editable) return;
|
||||
this.assignDropdownProps();
|
||||
this.$.dropDown.show(this.container, search);
|
||||
}
|
||||
|
|
|
@ -14,8 +14,25 @@ vn-chip {
|
|||
|
||||
&.colored {
|
||||
background-color: $color-main;
|
||||
color: $color-font-dark;
|
||||
color: $color-font-bg;
|
||||
}
|
||||
&.notice {
|
||||
background-color: $color-notice-medium
|
||||
}
|
||||
&.success {
|
||||
background-color: $color-success-medium;
|
||||
}
|
||||
&.warning {
|
||||
background-color: $color-main-medium;
|
||||
}
|
||||
&.alert {
|
||||
background-color: $color-alert-medium;
|
||||
}
|
||||
&.message {
|
||||
color: $color-font-dark;
|
||||
background-color: $color-bg-dark
|
||||
}
|
||||
|
||||
& > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
|
|
@ -6,6 +6,16 @@ export default class Range extends FormInput {
|
|||
constructor($element, $scope) {
|
||||
super($element, $scope);
|
||||
this.input = this.element.querySelector('input');
|
||||
this.input.addEventListener('change', () => this.onValueUpdate());
|
||||
}
|
||||
|
||||
get field() {
|
||||
return super.field;
|
||||
}
|
||||
|
||||
set field(value) {
|
||||
this.input.value = value;
|
||||
super.field = value;
|
||||
}
|
||||
|
||||
get max() {
|
||||
|
@ -35,6 +45,11 @@ export default class Range extends FormInput {
|
|||
refreshTabIndex() {
|
||||
this.input.tabIndex = this.disabled ? -1 : this.tabIndex;
|
||||
}
|
||||
|
||||
onValueUpdate() {
|
||||
this.change(this.input.value);
|
||||
this.$.$applyAsync();
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnRange', {
|
||||
|
|
|
@ -254,7 +254,6 @@ class AutoSearch {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.model.applyFilter(
|
||||
where ? {where} : null,
|
||||
hasParams ? userParams : null
|
||||
|
|
|
@ -7,11 +7,7 @@ server {
|
|||
client_max_body_size 250M;
|
||||
|
||||
root /salix/dist;
|
||||
error_page 404 = @notfound;
|
||||
|
||||
location @notfound {
|
||||
return 302 /;
|
||||
}
|
||||
location / {
|
||||
autoindex on;
|
||||
}
|
||||
|
|
22
gulpfile.js
22
gulpfile.js
|
@ -110,17 +110,27 @@ backTestOnce.description = `Runs the backend tests once, can receive --junit arg
|
|||
|
||||
async function backTestDockerOnce() {
|
||||
let containerId = await docker();
|
||||
await backTestOnce();
|
||||
if (argv['random'])
|
||||
await execP(`docker rm -fv ${containerId}`);
|
||||
try {
|
||||
await backTestOnce();
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (argv['random'])
|
||||
await execP(`docker rm -fv ${containerId}`);
|
||||
}
|
||||
}
|
||||
backTestDockerOnce.description = `Runs backend tests using in site container once`;
|
||||
|
||||
async function backTestDocker() {
|
||||
let containerId = await docker();
|
||||
await backTest();
|
||||
if (argv['random'])
|
||||
await execP(`docker rm -fv ${containerId}`);
|
||||
try {
|
||||
await backTest();
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (argv['random'])
|
||||
await execP(`docker rm -fv ${containerId}`);
|
||||
}
|
||||
}
|
||||
backTestDocker.description = `Runs backend tests restoring fixtures first`;
|
||||
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
@import "variables";
|
||||
|
||||
vn-treeview-child {
|
||||
.content > .vn-check:not(.indeterminate) {
|
||||
color: $color-button;
|
||||
.content > .vn-check:not(.indeterminate):not(.checked) {
|
||||
color: $color-alert;
|
||||
|
||||
& > .btn {
|
||||
border-color: $color-button;
|
||||
border-color: $color-alert;
|
||||
}
|
||||
}
|
||||
.content > .vn-check.checked {
|
||||
color: $color-button;
|
||||
color: $color-notice;
|
||||
|
||||
& > .btn {
|
||||
background-color: $color-notice;
|
||||
border-color: $color-notice
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.regularizeClaim = async(ctx, params) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const resolvedState = 3;
|
||||
|
||||
|
@ -55,11 +54,10 @@ module.exports = Self => {
|
|||
|
||||
if (!ticketFk) {
|
||||
ticketFk = await createTicket(ctx, {
|
||||
clientFk: address.clientFk,
|
||||
addressFk: addressFk,
|
||||
warehouseFk: sale.ticket().warehouseFk,
|
||||
companyFk: sale.ticket().companyFk,
|
||||
userId: userId
|
||||
clientId: address.clientFk,
|
||||
warehouseId: sale.ticket().warehouseFk,
|
||||
companyId: sale.ticket().companyFk,
|
||||
addressId: addressFk
|
||||
}, options);
|
||||
}
|
||||
|
||||
|
@ -140,16 +138,21 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
async function createTicket(ctx, params, options) {
|
||||
let ticket = await Self.app.models.Ticket.new(ctx,
|
||||
{
|
||||
shipped: new Date(),
|
||||
landed: new Date(),
|
||||
clientFk: params.clientFk,
|
||||
warehouseFk: params.warehouseFk,
|
||||
companyFk: params.companyFk,
|
||||
addressFk: params.addressFk,
|
||||
userId: params.userId
|
||||
}, options);
|
||||
params.shipped = new Date();
|
||||
params.landed = new Date();
|
||||
params.agencyModeId = null;
|
||||
params.routeId = null;
|
||||
|
||||
const ticket = await Self.app.models.Ticket.new(ctx,
|
||||
params.clientId,
|
||||
params.shipped,
|
||||
params.landed,
|
||||
params.warehouseId,
|
||||
params.companyId,
|
||||
params.addressId,
|
||||
params.agencyModeId,
|
||||
params.routeId,
|
||||
options);
|
||||
|
||||
return ticket.id;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,13 @@ import ngModule from '../module';
|
|||
import './style.scss';
|
||||
|
||||
class Controller {
|
||||
constructor($stateParams, $scope, $http, $translate, vnApp) {
|
||||
constructor($stateParams, $scope, $http, $translate, vnApp, $httpParamSerializer) {
|
||||
this.$stateParams = $stateParams;
|
||||
this.$ = $scope;
|
||||
this.$http = $http;
|
||||
this.$translate = $translate;
|
||||
this.vnApp = vnApp;
|
||||
this.$httpParamSerializer = $httpParamSerializer;
|
||||
this.filter = {
|
||||
where: {claimFk: $stateParams.id},
|
||||
include: [
|
||||
|
@ -125,31 +126,61 @@ class Controller {
|
|||
let data = {claimFk: this.$stateParams.id};
|
||||
let query = `Claims/regularizeClaim`;
|
||||
return this.$http.post(query, data).then(() => {
|
||||
this.card.reload();
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2)
|
||||
this.$.updateGreuge.show();
|
||||
else
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
|
||||
this.card.reload();
|
||||
});
|
||||
}
|
||||
|
||||
getGreugeTypeId() {
|
||||
const params = {filter: {where: {code: 'freightPickUp'}}};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
const query = `GreugeTypes/findOne?${serializedParams}`;
|
||||
return this.$http.get(query).then(res => {
|
||||
this.greugeTypeFreightId = res.data.id;
|
||||
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
getGreugeConfig() {
|
||||
const query = `GreugeConfigs/findOne`;
|
||||
return this.$http.get(query).then(res => {
|
||||
this.freightPickUpPrice = res.data.freightPickUpPrice;
|
||||
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
onUpdateGreugeResponse(response) {
|
||||
if (response !== 'accept')
|
||||
return;
|
||||
let greugeTypeFreight = 7;
|
||||
let query = `Greuges/`;
|
||||
let data = {
|
||||
clientFk: this.claim.clientFk,
|
||||
description: `claim: ${this.claim.id}`,
|
||||
amount: 11,
|
||||
greugeTypeFk: greugeTypeFreight,
|
||||
ticketFk: this.claim.ticketFk
|
||||
};
|
||||
if (response == 'accept') {
|
||||
const promises = [];
|
||||
promises.push(this.getGreugeTypeId());
|
||||
promises.push(this.getGreugeConfig());
|
||||
|
||||
this.$http.post(query, data).then(() => {
|
||||
this.card.reload();
|
||||
this.vnApp.showSuccess(this.$translate.instant('Greuge inserted!'));
|
||||
});
|
||||
return Promise.all(promises).then(() => {
|
||||
const data = {
|
||||
clientFk: this.claim.clientFk,
|
||||
description: this.$translate.instant('ClaimGreugeDescription', {
|
||||
claimId: this.claim.id
|
||||
}).toUpperCase(),
|
||||
amount: this.freightPickUpPrice,
|
||||
greugeTypeFk: this.greugeTypeFreightId,
|
||||
ticketFk: this.claim.ticketFk
|
||||
};
|
||||
return this.$http.post(`Greuges/`, data).then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
this.vnApp.showMessage(this.$translate.instant('Greuge inserted'));
|
||||
});
|
||||
});
|
||||
} else
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
}
|
||||
|
||||
// Item Descriptor
|
||||
showDescriptor(event, itemFk) {
|
||||
this.$.descriptor.itemFk = itemFk;
|
||||
|
@ -164,6 +195,7 @@ class Controller {
|
|||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
});
|
||||
}
|
||||
|
||||
saveMana(value) {
|
||||
let query = `Claims/${this.$stateParams.id}/updateClaimAction`;
|
||||
|
||||
|
@ -173,7 +205,7 @@ class Controller {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
|
||||
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp', '$httpParamSerializer'];
|
||||
|
||||
ngModule.component('vnClaimAction', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -6,15 +6,19 @@ describe('claim', () => {
|
|||
let controller;
|
||||
let $httpBackend;
|
||||
let $state;
|
||||
let $httpParamSerializer;
|
||||
let $scope;
|
||||
|
||||
beforeEach(ngModule('claim'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
|
||||
beforeEach(angular.mock.inject(($rootScope, $componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$scope = $rootScope.$new();
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
$state = _$state_;
|
||||
$state.params.id = 1;
|
||||
|
||||
controller = $componentController('vnClaimAction', {$state});
|
||||
controller = $componentController('vnClaimAction', {$state, $scope});
|
||||
controller.claim = {ticketFk: 1};
|
||||
controller.$.model = {refresh: () => {}};
|
||||
controller.$.addSales = {
|
||||
|
@ -149,6 +153,8 @@ describe('claim', () => {
|
|||
});
|
||||
|
||||
describe('onUpdateGreugeResponse()', () => {
|
||||
const greugeTypeId = 7;
|
||||
const freightPickUpPrice = 11;
|
||||
it('should do nothing', () => {
|
||||
spyOn(controller.$http, 'post');
|
||||
spyOn(controller.card, 'reload');
|
||||
|
@ -161,24 +167,51 @@ describe('claim', () => {
|
|||
expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Greuge inserted!');
|
||||
});
|
||||
|
||||
it('should perform a insert into greuges', () => {
|
||||
it('should make a query and get the greugeTypeId and greuge config', () => {
|
||||
spyOn(controller.card, 'reload');
|
||||
spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
const greugeTypeParams = $httpParamSerializer({filter: {where: {code: 'freightPickUp'}}});
|
||||
$httpBackend.expect('GET', `GreugeTypes/findOne?${greugeTypeParams}`).respond({id: greugeTypeId});
|
||||
$httpBackend.expect('GET', `GreugeConfigs/findOne`).respond({freightPickUpPrice});
|
||||
controller.onUpdateGreugeResponse('accept');
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.greugeTypeFreightId).toEqual(greugeTypeId);
|
||||
expect(controller.freightPickUpPrice).toEqual(freightPickUpPrice);
|
||||
});
|
||||
|
||||
// #1957 - Investigate how to test nested httpBackend requests
|
||||
xit('should perform a insert into greuges', () => {
|
||||
spyOn(controller.card, 'reload');
|
||||
spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
spyOn(controller, 'getGreugeTypeId').and.returnValue(new Promise(resolve => {
|
||||
return resolve({id: greugeTypeId});
|
||||
}));
|
||||
spyOn(controller, 'getGreugeConfig').and.returnValue(new Promise(resolve => {
|
||||
return resolve({freightPickUpPrice});
|
||||
}));
|
||||
|
||||
controller.claim.clientFk = 101;
|
||||
controller.claim.id = 11;
|
||||
let data = {
|
||||
clientFk: 101,
|
||||
description: `claim: ${controller.claim.id}`,
|
||||
amount: 11,
|
||||
greugeTypeFk: 7,
|
||||
amount: freightPickUpPrice,
|
||||
greugeTypeFk: greugeTypeId,
|
||||
ticketFk: controller.claim.ticketFk
|
||||
};
|
||||
$httpBackend.expect('POST', `Greuges/`, data).respond();
|
||||
controller.onUpdateGreugeResponse('accept');
|
||||
$httpBackend.flush();
|
||||
$httpBackend.expect('POST', `Greuges/`, data).respond(new Promise(resolve => {
|
||||
return resolve({id: freightPickUpPrice});
|
||||
}));
|
||||
controller.onUpdateGreugeResponse('accept').then(res => {
|
||||
console.log('asdas');
|
||||
}).catch(error => {
|
||||
console.log('errorrrr!!');
|
||||
});
|
||||
|
||||
expect(controller.card.reload).toHaveBeenCalledWith();
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Greuge inserted!');
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ClaimGreugeDescription: Claim id {{claimId}}
|
|
@ -9,3 +9,4 @@ Regularize: Regularizar
|
|||
Do you want to insert greuges?: Desea insertar greuges?
|
||||
Insert greuges on client card: Insertar greuges en la ficha del cliente
|
||||
Greuge inserted: Greuge insertado
|
||||
ClaimGreugeDescription: Reclamación id {{claimId}}
|
|
@ -11,7 +11,7 @@
|
|||
</section>
|
||||
<vn-data-viewer
|
||||
model="model"
|
||||
class="vn-w-lg">
|
||||
class="vn-w-xl">
|
||||
<vn-horizontal class="photo-list">
|
||||
<section class="photo" ng-repeat="photo in $ctrl.photos">
|
||||
<section class="image vn-shadow" on-error-src
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue