diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql index 537f53848..336f3521e 100644 --- a/db/routines/vn/procedures/item_getSimilar.sql +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -24,6 +24,7 @@ BEGIN CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated); CALL cache.visible_refresh(vVisibleCalcFk, FALSE, vWarehouseFk); + CALL buy_getUltimate(NULL, vWarehouseFk, vDated); WITH itemTags AS ( SELECT i.id, @@ -74,14 +75,13 @@ BEGIN AND a.calc_id = vAvailableCalcFk LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCalcFk - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id - AND lb.warehouse_id = vWarehouseFk + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.id LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vSelf LEFT JOIN vn.itemTag it ON it.itemFk = i.id AND it.priority = vPriority LEFT JOIN vn.tag t ON t.id = it.tagFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.buy b ON b.id = bu.buyFk JOIN itemTags its WHERE a.available > 0 AND (i.typeFk = its.typeFk OR NOT vShowType) @@ -98,5 +98,7 @@ BEGIN (i.tag8 = its.tag8) DESC, match8 DESC LIMIT 100; + + DROP TEMPORARY TABLE tmp.buyUltimate; END$$ DELIMITER ; diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql new file mode 100644 index 000000000..28b033b4a --- /dev/null +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -0,0 +1,137 @@ +CREATE TABLE IF NOT EXISTS `vn`.`itemFarmingTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemFarmingTag` (`name`) VALUES ('Enraizado'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemFarmingTag' + WHERE name= 'cultivo'; + +CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Bolsa'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja cartón'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja decorativa'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Celofán'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Papel kraft'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Plástico'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Variable'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemWrappingTag' + WHERE name= 'Envoltorio'; + +CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Castellano'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Catalán'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Euskera'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Francés'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Gallego'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Inglés'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Portugués'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemLanguageTag' + WHERE name= 'Idioma'; + +CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Natural'); +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Seminatural'); +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Sintético'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemStemTag' + WHERE name= 'Tronco'; + + +CREATE TABLE IF NOT EXISTS `vn`.`itemBreederTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemBreederTag` (`name`) VALUES ('David Austin'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemBreederTag' + WHERE name= 'Obtentor'; + +CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Biodegradable'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Caballete'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cerámica'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cristal'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico por inyección'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Madera'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Rígido'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Ruedas'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Sin soporte rígido'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemBaseTag' + WHERE name= 'Soporte'; + +CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General'); +INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemVatRateTag' + WHERE name= 'Tipo de IVA'; + +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBaseTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBreederTag TO logisticAssist; \ No newline at end of file