feat(MySQL): Get Many stored procedures created for product variations with variation types and product prices with discounts and delivery options.

This commit is contained in:
2024-10-05 13:20:00 +01:00
parent 005a377ff9
commit 9c2cfac948
146 changed files with 28264 additions and 17091 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -9,8 +9,10 @@ DROP TABLE IF EXISTS tmp_Product_Calc_User;
DROP TABLE IF EXISTS tmp_Product_p_Shop_User_Eval;
DROP TABLE IF EXISTS tmp_Msg_Error;
DROP TABLE IF EXISTS tmp_Currency;
DROP TABLE IF EXISTS tmp_Delivery_Option;
DROP TABLE IF EXISTS tmp_Delivery_Region;
DROP TABLE IF EXISTS tmp_Region;
DROP TABLE IF EXISTS tmp_Price;
DROP TABLE IF EXISTS tmp_Shop_User;
DROP TABLE IF EXISTS tmp_Shop_Order;
DROP TABLE IF EXISTS tmp_Shop_Product;
@@ -38,7 +40,9 @@ DROP TABLE IF EXISTS tmp_Shop_Customer_Sale_Order;
# Delete old tables
DROP TABLE IF EXISTS Shop_Calc_User_Temp;
DROP TABLE IF EXISTS Split_Temp;
DROP TABLE IF EXISTS Shop_User_Eval_Temp;
DROP TABLE IF EXISTS Shop_Calc_User_Temp;
DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Temp;
@@ -111,6 +115,8 @@ DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link;
DROP TABLE IF EXISTS Shop_Discount_Audit;
DROP TABLE IF EXISTS Shop_Discount;
DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit;
DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link;
DROP TABLE IF EXISTS Shop_Product_Delivery_Option_Link_Audit;
DROP TABLE IF EXISTS Shop_Product_Delivery_Option_Link;
@@ -227,6 +233,10 @@ DROP TABLE IF EXISTS Shop_Product_Change_Set;
DROP PROCEDURE IF EXISTS p_split;
DROP PROCEDURE IF EXISTS p_clear_split_temp;
DROP PROCEDURE IF EXISTS p_debug_timing_reporting;
DROP PROCEDURE IF EXISTS p_validate_guid;
DROP PROCEDURE IF EXISTS p_validate_guid_test;
DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name;
DROP PROCEDURE IF EXISTS p_shop_calc_user;
@@ -244,6 +254,8 @@ DROP PROCEDURE IF EXISTS p_shop_save_category;
DROP PROCEDURE IF EXISTS p_shop_save_product_category;
DROP PROCEDURE IF EXISTS p_shop_save_product_category_test;
DROP PROCEDURE IF EXISTS p_shop_save_product;
DROP PROCEDURE IF EXISTS p_shop_calc_product_permutation;
DROP PROCEDURE IF EXISTS p_shop_clear_calc_product_permutation;
DROP PROCEDURE IF EXISTS p_shop_get_many_product;
DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new;
DROP PROCEDURE IF EXISTS p_shop_save_permutation;
@@ -251,7 +263,7 @@ DROP PROCEDURE IF EXISTS p_shop_save_product_permutation;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation;
DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_region;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option;
DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_price_new;
DROP PROCEDURE IF EXISTS p_shop_save_user;
DROP PROCEDURE IF EXISTS p_shop_edit_user;

View File

@@ -12,8 +12,10 @@ CREATE TABLE IF NOT EXISTS Shop_Delivery_Option (
description VARCHAR(4000),
latency_delivery_min INT NOT NULL,
latency_delivery_max INT NOT NULL,
/*
quantity_min INT NOT NULL,
quantity_max INT NOT NULL,
*/
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,

View File

@@ -3,42 +3,44 @@
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Delivery_Option_Link';
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link';
CREATE TABLE IF NOT EXISTS Shop_Product_Delivery_Option_Link (
CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link (
id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_product INT NOT NULL,
CONSTRAINT FK_Shop_Product_Delivery_Option_Link_id_product
CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_product
FOREIGN KEY (id_product)
REFERENCES Shop_Product(id_product)
ON UPDATE RESTRICT,
id_permutation INT,
CONSTRAINT FK_Shop_Product_Delivery_Option_Link_id_permutation
CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_permutation
FOREIGN KEY (id_permutation)
REFERENCES Shop_Product_Permutation(id_permutation)
ON UPDATE RESTRICT,
id_delivery_option INT NOT NULL,
CONSTRAINT FK_Shop_Product_Delivery_Option_Link_id_delivery_option
CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_delivery_option
FOREIGN KEY (id_delivery_option)
REFERENCES Shop_Delivery_Option(id_option)
ON UPDATE RESTRICT,
id_region INT NOT NULL,
CONSTRAINT FK_Shop_Product_Delivery_Option_Link_id_region
CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_region
FOREIGN KEY (id_region)
REFERENCES Shop_Region(id_region)
ON UPDATE RESTRICT,
id_currency INT NOT NULL,
CONSTRAINT FK_Shop_Product_Delivery_Option_Link_id_currency
CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_currency
FOREIGN KEY (id_currency)
REFERENCES Shop_Currency(id_currency)
ON UPDATE RESTRICT,
price_local FLOAT NOT NULL,
quantity_min FLOAT NULL,
quantity_max FLOAT NULL,
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Product_Delivery_Option_Link_id_change_set
CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_change_set
FOREIGN KEY (id_change_set)
REFERENCES Shop_Product_Change_Set(id_change_set)
);

View File

@@ -3,20 +3,20 @@
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Delivery_Option_Link_Audit';
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link_Audit';
CREATE TABLE IF NOT EXISTS Shop_Product_Delivery_Option_Link_Audit (
CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit (
id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_link INT NOT NULL,
CONSTRAINT FK_Shop_Product_Delivery_Option_Link_Audit_id_link
CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_Audit_id_link
FOREIGN KEY (id_link)
REFERENCES Shop_Product_Delivery_Option_Link(id_link)
REFERENCES Shop_Product_Permutation_Delivery_Option_Link(id_link)
ON UPDATE RESTRICT,
name_field VARCHAR(64) NOT NULL,
value_prev VARCHAR(500),
value_new VARCHAR(500),
id_change_set INT NOT NULL,
CONSTRAINT FK_Shop_Product_Delivery_Option_Link_Audit_id_change_set
CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_Audit_id_change_set
FOREIGN KEY (id_change_set)
REFERENCES Shop_Product_Change_Set(id_change_set)
);

View File

@@ -1,40 +0,0 @@
# Product Currency Region link
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Currency_Region_Link';
CREATE TABLE IF NOT EXISTS Shop_Product_Currency_Region_Link (
id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_product INT NOT NULL,
CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_product
FOREIGN KEY (id_product)
REFERENCES Shop_Product(id_product)
ON UPDATE RESTRICT,
id_permutation INT NULL,
CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_permutation
FOREIGN KEY (id_permutation)
REFERENCES Shop_Product_Permutation(id_permutation)
ON UPDATE RESTRICT,
id_currency INT NOT NULL,
CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_currency
FOREIGN KEY (id_currency)
REFERENCES Shop_Currency(id_currency)
ON UPDATE RESTRICT,
id_region_purchase INT NOT NULL,
CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_region_purchase
FOREIGN KEY (id_region_purchase)
REFERENCES Shop_Region(id_region)
ON UPDATE RESTRICT,
price_local_VAT_incl FLOAT NULL,
price_local_VAT_excl FLOAT NULL,
id_stripe_price VARCHAR(200),
active BIT NOT NULL DEFAULT 1,
created_on TIMESTAMP,
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_change_set
FOREIGN KEY (id_change_set)
REFERENCES Shop_Product_Change_Set(id_change_set)
);

View File

@@ -1,22 +0,0 @@
# Product Currency Region Link Audits
SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Currency_Region_Link_Audit';
CREATE TABLE IF NOT EXISTS Shop_Product_Currency_Region_Link_Audit (
id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_link INT NOT NULL,
CONSTRAINT FK_Shop_Product_Currency_Region_Link_Audit_id_link
FOREIGN KEY (id_link)
REFERENCES Shop_Product_Currency_Region_Link(id_link)
ON UPDATE RESTRICT,
name_field VARCHAR(50),
value_prev VARCHAR(500),
value_new VARCHAR(500),
id_change_set INT NOT NULL,
CONSTRAINT FK_Shop_Product_Currency_Region_Link_Audit_id_change_set
FOREIGN KEY (id_change_set)
REFERENCES Shop_Product_Change_Set(id_change_set)
);

View File

@@ -50,6 +50,7 @@ BEGIN
# Changed latency_delivery_max
SELECT NEW.id_option, 'latency_delivery_max', CONVERT(OLD.latency_delivery_max, CHAR), CONVERT(NEW.latency_delivery_max, CHAR), NEW.id_change_set
WHERE NOT OLD.latency_delivery_max <=> NEW.latency_delivery_max
/*
UNION
# Changed quantity_min
SELECT NEW.id_option, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set
@@ -58,6 +59,7 @@ BEGIN
# Changed quantity_max
SELECT NEW.id_option, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set
WHERE NOT OLD.quantity_max <=> NEW.quantity_max
*/
UNION
# Changed active
SELECT NEW.id_option, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set

View File

@@ -3,13 +3,13 @@
DROP TRIGGER IF EXISTS before_insert_Shop_Product_Delivery_Option_Link;
DROP TRIGGER IF EXISTS before_update_Shop_Product_Delivery_Option_Link;
DROP TRIGGER IF EXISTS before_insert_Shop_Product_Permutation_Delivery_Option_Link;
DROP TRIGGER IF EXISTS before_update_Shop_Product_Permutation_Delivery_Option_Link;
DELIMITER //
CREATE TRIGGER before_insert_Shop_Product_Delivery_Option_Link
BEFORE INSERT ON Shop_Product_Delivery_Option_Link
CREATE TRIGGER before_insert_Shop_Product_Permutation_Delivery_Option_Link
BEFORE INSERT ON Shop_Product_Permutation_Delivery_Option_Link
FOR EACH ROW
BEGIN
SET NEW.created_on := IFNULL(NEW.created_on, NOW());
@@ -19,8 +19,8 @@ DELIMITER ;;
DELIMITER //
CREATE TRIGGER before_update_Shop_Product_Delivery_Option_Link
BEFORE UPDATE ON Shop_Product_Delivery_Option_Link
CREATE TRIGGER before_update_Shop_Product_Permutation_Delivery_Option_Link
BEFORE UPDATE ON Shop_Product_Permutation_Delivery_Option_Link
FOR EACH ROW
BEGIN
IF OLD.id_change_set <=> NEW.id_change_set THEN
@@ -28,7 +28,7 @@ BEGIN
SET MESSAGE_TEXT = 'New change Set ID must be provided.';
END IF;
INSERT INTO Shop_Product_Delivery_Option_Link_Audit (
INSERT INTO Shop_Product_Permutation_Delivery_Option_Link_Audit (
id_link,
name_field,
value_prev,
@@ -56,6 +56,16 @@ BEGIN
# Changed price_local
SELECT NEW.id_link, 'price_local', CONVERT(OLD.price_local, CHAR), CONVERT(NEW.price_local, CHAR), NEW.id_change_set
WHERE NOT OLD.price_local <=> NEW.price_local
/*
UNION
# Changed quantity_min
SELECT NEW.id_link, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set
WHERE NOT OLD.quantity_min <=> NEW.quantity_min
UNION
# Changed quantity_max
SELECT NEW.id_link, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set
WHERE NOT OLD.quantity_max <=> NEW.quantity_max
*/
UNION
# Changed active
SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set

View File

@@ -86,7 +86,7 @@ BEGIN
CREATE TEMPORARY TABLE tmp_Product_Calc_User (
-- id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL
id_product INT NOT NULL
id_product INT NULL
, id_access_level_required INT NOT NULL
, priority_access_level_required INT NOT NULL
-- guid BINARY(36) NOT NULL,
@@ -131,8 +131,6 @@ BEGIN
;
END IF;
CALL partsltd_prod.p_validate_guid ( a_guid );
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
IF v_has_filter_access_level THEN
CALL partsltd_prod.p_split(a_guid, a_ids_access_level, ',', a_debug);
@@ -205,7 +203,7 @@ BEGIN
DELETE FROM tmp_Split;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
IF v_has_filter_product THEN
IF v_has_filter_product = 1 THEN
CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug);
INSERT INTO tmp_Split (
@@ -245,56 +243,55 @@ BEGIN
OR P.active = 0
;
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
IF EXISTS (SELECT * FROM tmp_Split) THEN
INSERT INTO tmp_Product_Calc_User (
id_product,
-- id_permutation,
id_access_level_required,
priority_access_level_required
)
SELECT
DISTINCT P.id_product,
-- PP.id_permutation,
CASE WHEN AL_P.priority < AL_C.priority THEN AL_P.id_access_level ELSE AL_C.id_access_level END AS id_access_level_required,
CASE WHEN AL_P.priority < AL_C.priority THEN AL_P.priority ELSE AL_C.priority END AS priority_access_level_required
FROM tmp_Split t_S
INNER JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product # Shop_Product_Permutation PP
INNER JOIN partsltd_prod.Shop_Access_Level AL_P
ON P.id_access_level_required = AL_P.id_access_level
AND AL_P.active
INNER JOIN partsltd_prod.Shop_Product_Category C ON P.id_category = C.id_category
INNER JOIN partsltd_prod.Shop_Access_Level AL_C
ON C.id_access_level_required = AL_C.id_access_level
AND AL_C.active
;
SET v_has_filter_product = EXISTS (SELECT * FROM tmp_Product_Calc_User);
/*
UPDATE tmp_Product_Calc_User t_P
INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product
INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category
INNER JOIN partsltd_prod.Shop_Access_Level AL ON PC.id_access_level_required = AL.id_access_level
SET
t_P.id_access_level_required = CASE WHEN t_P.priority_access_level_required <= AL.priority THEN t_P.id_access_level_required ELSE AL.id_access_level END
, t_P.priority_access_level_required = LEAST(t_P.priority_access_level_required, AL.priority)
;
*/
ELSE
INSERT INTO tmp_Product_Calc_User (
id_product,
-- id_permutation,
id_access_level_required,
priority_access_level_required
)
VALUES (
NULL
, v_id_access_level_view
, v_priority_access_level_view
);
END IF;
END IF;
END IF;
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
IF (v_has_filter_product = 1 AND EXISTS (SELECT * FROM tmp_Split)) THEN
INSERT INTO tmp_Product_Calc_User (
id_product,
-- id_permutation,
id_access_level_required,
priority_access_level_required
)
SELECT
DISTINCT P.id_product,
-- PP.id_permutation,
CASE WHEN AL_P.priority < AL_C.priority THEN AL_P.id_access_level ELSE AL_C.id_access_level END AS id_access_level_required,
CASE WHEN AL_P.priority < AL_C.priority THEN AL_P.priority ELSE AL_C.priority END AS priority_access_level_required
FROM tmp_Split t_S
INNER JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product # Shop_Product_Permutation PP
INNER JOIN partsltd_prod.Shop_Access_Level AL_P
ON P.id_access_level_required = AL_P.id_access_level
AND AL_P.active
INNER JOIN partsltd_prod.Shop_Product_Category C ON P.id_category = C.id_category
INNER JOIN partsltd_prod.Shop_Access_Level AL_C
ON C.id_access_level_required = AL_C.id_access_level
AND AL_C.active
;
SET v_has_filter_product = EXISTS (SELECT * FROM tmp_Product_Calc_User);
/*
UPDATE tmp_Product_Calc_User t_P
INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product
INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category
INNER JOIN partsltd_prod.Shop_Access_Level AL ON PC.id_access_level_required = AL.id_access_level
SET
t_P.id_access_level_required = CASE WHEN t_P.priority_access_level_required <= AL.priority THEN t_P.id_access_level_required ELSE AL.id_access_level END
, t_P.priority_access_level_required = LEAST(t_P.priority_access_level_required, AL.priority)
;
*/
ELSE
INSERT INTO tmp_Product_Calc_User (
id_product,
-- id_permutation,
id_access_level_required,
priority_access_level_required
)
VALUES (
NULL
, v_id_access_level_view
, v_priority_access_level_view
);
END IF;
END IF;
@@ -457,6 +454,8 @@ BEGIN
END IF;
END IF;
DELETE FROM tmp_Split;
-- Calculated fields
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
UPDATE tmp_Calc_User t_U
@@ -530,10 +529,29 @@ CALL partsltd_prod.p_shop_calc_user (
, '1,2,3,4,5'
, 0
);
-- SELECT * FROM partsltd_prod.Shop_Calc_User_Temp;
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips ';
CALL partsltd_prod.p_shop_clear_calc_user ( 'chips ', 0 );
-- SELECT * FROM partsltd_prod.Shop_Calc_User_Temp;
DROP TABLE IF EXISTS tmp_Msg_Error;
CALL p_shop_calc_user(
'chips '
, 1
, FALSE -- a_get_inactive_users
, 2
, 1
, '' -- a_ids_product
, 0 -- a_debug
);
SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips ';
CALL partsltd_prod.p_shop_clear_calc_user ( 'chips ', 0 );
DROP TABLE IF EXISTS tmp_Msg_Error;
SELECT * FROM partsltd_prod.shop_user_role_link;
SELECT * FROM partsltd_prod.shop_role_permission_link;
*/

View File

@@ -1,530 +0,0 @@
-- USE partsltd_prod;
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_calc_product_permutation;
DELIMITER //
CREATE PROCEDURE p_shop_calc_product_permutation (
IN a_id_user INT
, IN a_get_all_product_category BIT
, IN a_get_inactive_product_category BIT
, IN a_ids_product_category TEXT
, IN a_get_all_product BIT
, IN a_get_inactive_product BIT
, IN a_ids_product TEXT
, IN a_get_all_product_permutation BIT
, IN a_get_inactive_permutation BIT
, IN a_ids_permutation TEXT
, IN a_get_products_quantity_stock_below_min BIT
, IN a_guid BINARY(36)
, IN a_debug BIT
)
BEGIN
/*
PROCEDURE p_shop_calc_product_permutation
Shared filtering for product permutations
select * from shop_msg_error_type;
*/
DECLARE v_has_filter_product_category BIT;
DECLARE v_has_filter_product BIT;
DECLARE v_has_filter_permutation BIT;
DECLARE v_id_permission_product INT;
DECLARE v_ids_product_permission TEXT;
DECLARE v_id_access_level_view INT;
DECLARE v_id_minimum INT;
DECLARE v_ids_product_invalid TEXT;
DECLARE v_ids_category_invalid TEXT;
DECLARE v_time_start TIMESTAMP(6);
DECLARE v_time_end TIMESTAMP(6);
DECLARE v_id_type_error_bad_data INT;
DECLARE v_code_type_error_bad_data VARCHAR(50);
SET v_time_start := CURRENT_TIMESTAMP(6);
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW');
SELECT
MET.id_type
, MET.code
INTO
v_id_type_error_bad_data
, v_code_type_error_bad_data
FROM Shop_Msg_Error_Type MET
WHERE MET.code = 'BAD_DATA'
;
SET a_id_user := TRIM(IFNULL(a_id_user, 0));
SET a_get_all_product_category := IFNULL(a_get_all_product_category, 0);
SET a_get_inactive_product_category := IFNULL(a_get_inactive_product_category, 0);
SET a_ids_product_category := TRIM(IFNULL(a_ids_product_category, ''));
SET a_get_all_product := IFNULL(a_get_all_product, 0);
SET a_get_inactive_product := IFNULL(a_get_inactive_product, 0);
SET a_ids_product := TRIM(IFNULL(a_ids_product, ''));
SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0);
SET a_get_inactive_permutation := IFNULL(a_get_inactive_permutation, 0);
SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, ''));
SET a_get_products_quantity_stock_below_min := IFNULL(a_get_products_quantity_stock_below_min, 0);
-- SET a_guid := IFNULL(a_guid, UUID());
SET a_debug := IFNULL(a_debug, 0);
IF a_debug = 1 THEN
SELECT
a_id_user
, a_get_all_product_category, a_ids_product_category, a_get_inactive_product_category
, a_get_all_product, a_get_inactive_product, a_ids_product
, a_get_all_product_permutation, a_get_inactive_permutation, a_ids_permutation
, a_get_products_quantity_stock_below_min
, a_debug
;
END IF;
-- Temporary tables
DROP TEMPORARY TABLE IF EXISTS tmp_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
CREATE TEMPORARY TABLE tmp_Category (
id_category INT NOT NULL
-- , active BIT NOT NULL
-- display_order INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Product (
id_category INT NOT NULL
, id_product INT NOT NULL
-- active BIT NOT NULL
-- display_order INT NOT NULL
, can_view BIT
, can_edit BIT
, can_admin BIT
);
CREATE TEMPORARY TABLE tmp_Permutation (
id_permutation INT NULL
-- id_category INT NOT NULL
, id_product INT NOT NULL
-- , active BIT NOT NULL
-- , display_order INT NOT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT
-- , guid BINARY(36) NOT NULL
, id_type INT NULL
, code VARCHAR(50) NOT NULL
, msg VARCHAR(4000) NOT NULL
);
-- Parse filters
SET v_has_filter_product_category = CASE WHEN a_ids_product_category = '' THEN 0 ELSE 1 END;
SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END;
SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END;
IF ISNULL(a_guid) THEN
INSERT INTO tmp_Msg_Error (
-- guid
id_type
, code
, msg
)
VALUES (
-- NULL
v_id_type_error_bad_data
, v_code_type_error_bad_data
, 'GUID is required.'
);
END IF;
IF a_debug = 1 THEN
SELECT
v_has_filter_product_category
, v_has_filter_product
, v_has_filter_permutation
;
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
INSERT INTO tmp_Category (
id_category
)
SELECT
PC.id_category
FROM Shop_Product_Category PC
WHERE (
a_get_all_product_category = 1
OR (
v_has_filter_product_category = 1
AND FIND_IN_SET(PC.id_category, a_ids_product_category) > 0
)
)
AND (
a_get_inactive_product_category = 1
OR PC.active = 1
)
;
INSERT INTO tmp_Product (
id_category
, id_product
)
SELECT
P.id_category
, P.id_product
FROM Shop_Product P
INNER JOIN tmp_Category t_C ON P.id_category = t_C.id_category
WHERE (
a_get_all_product = 1
OR (
v_has_filter_product = 1
AND FIND_IN_SET(P.id_product, a_ids_product) > 0
)
)
AND (
a_get_inactive_product = 1
OR P.active = 1
)
;
INSERT INTO tmp_Permutation (
id_permutation
-- id_category,
, id_product
)
SELECT
PP.id_permutation
-- P.id_category,
, PP.id_product
FROM Shop_Product_Permutation PP
INNER JOIN tmp_Product t_P ON PP.id_product = t_P.id_product
WHERE (
a_get_all_product_permutation = 1
OR (
v_has_filter_permutation = 1
AND FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0
)
OR (
a_get_products_quantity_stock_below_min = 1
AND PP.quantity_stock < PP.quantity_min
)
)
AND (
a_get_inactive_permutation = 1
OR PP.active = 1
)
;
-- Permissions
IF EXISTS (SELECT * FROM tmp_Product LIMIT 1) THEN
SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product WHERE NOT ISNULL(id_product));
IF a_debug = 1 THEN
SELECT
a_guid AS a_guid
, a_id_user
, false AS a_get_inactive_user
, v_id_permission_product AS a_ids_permission
, v_id_access_level_view AS a_ids_access_level
, v_ids_product_permission AS a_ids_product
;
END IF;
CALL p_shop_calc_user(a_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission);
UPDATE tmp_Product t_P
INNER JOIN Shop_Calc_User_Temp UE_T
ON t_P.id_product = UE_T.id_product
AND UE_T.GUID = a_guid
SET t_P.can_view = UE_T.can_view,
t_P.can_edit = UE_T.can_edit,
t_P.can_admin = UE_T.can_admin
;
IF a_debug = 1 THEN
SELECT *
FROM Shop_Calc_User_Temp
WHERE GUID = a_guid
;
END IF;
SET v_ids_product_invalid := (
SELECT GROUP_CONCAT(t_P.id_product SEPARATOR ',')
FROM tmp_Product t_P
WHERE ISNULL(t_P.can_view)
);
SET v_ids_category_invalid := (
SELECT GROUP_CONCAT(t_P.id_category SEPARATOR ',')
FROM tmp_Product t_P
WHERE ISNULL(t_P.can_view)
);
DELETE
FROM tmp_Category t_C
WHERE FIND_IN_SET(t_C.id_category, v_ids_category_invalid) > 0
;
DELETE
FROM tmp_Product t_P
WHERE FIND_IN_SET(t_P.id_product, v_ids_product_invalid) > 0
;
DELETE
FROM tmp_Permutation t_PP
WHERE FIND_IN_SET(t_PP.id_product, v_ids_product_invalid) > 0
;
CALL p_shop_clear_calc_user(a_guid);
END IF;
END IF;
IF a_debug = 1 THEN
SELECT * FROM tmp_Category;
SELECT * FROM tmp_Product;
SELECT * FROM tmp_Permutation;
END IF;
IF EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
DELETE FROM tmp_Category;
DELETE FROM tmp_Product;
DELETE FROM tmp_Permutation;
ELSE
START TRANSACTION;
# Categories
INSERT INTO Shop_Product_Category_Temp (
id_category
, code
, name
, description
, id_access_level_required
, display_order
, active
, can_view
, can_edit
, can_admin
, guid
)
SELECT
t_C.id_category
, PC.code
, PC.name
, PC.description
, PC.id_access_level_required
, PC.display_order
, PC.active
, MIN(IFNULL(t_P.can_view, 0)) AS can_view
, MIN(IFNULL(t_P.can_edit, 0)) AS can_edit
, MIN(IFNULL(t_P.can_admin, 0)) AS can_admin
, a_guid
FROM tmp_Category t_C
INNER JOIN Shop_Product_Category PC ON t_C.id_category = PC.id_category
LEFT JOIN tmp_Product t_P ON t_C.id_category = t_P.id_product
GROUP BY PC.id_category
;
# Products
INSERT INTO Shop_Product_Temp (
id_product
, id_category
, name
, has_variations
, id_access_level_required
, display_order
, active
, can_view
, can_edit
, can_admin
, guid
)
SELECT
t_P.id_product
, P.id_category
, P.name
, P.has_variations
, P.id_access_level_required
, P.display_order
, P.active
, t_P.can_view
, t_P.can_edit
, t_P.can_admin
, a_guid
FROM tmp_Product t_P
INNER JOIN Shop_Product P ON t_P.id_product = P.id_product
INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category
INNER JOIN Shop_Access_Level AL ON P.id_access_level_required = AL.id_access_level
GROUP BY P.id_product, t_P.can_view, t_P.can_edit, t_P.can_admin
;
# Product Permutations
INSERT INTO Shop_Product_Permutation_Temp (
id_permutation
, id_product
, description
, cost_local
, id_currency_cost
, profit_local_min
, latency_manufacture_days
, id_unit_measurement_quantity
, count_unit_measurement_per_quantity_step
, quantity_min
, quantity_max
, quantity_stock
, is_subscription
, id_unit_measurement_interval_recurrence
, count_interval_recurrence
, id_stripe_product
, does_expire_faster_once_unsealed
, id_unit_measurement_interval_expiration_unsealed
, count_interval_expiration_unsealed
, active
, can_view
, can_edit
, can_admin
, guid
)
SELECT
t_PP.id_permutation
, PP.id_product
, PP.description
, PP.cost_local
, PP.id_currency_cost
, PP.profit_local_min
, PP.latency_manufacture_days
, PP.id_unit_measurement_quantity
, PP.count_unit_measurement_per_quantity_step
, PP.quantity_min
, PP.quantity_max
, PP.quantity_stock
, PP.is_subscription
, PP.id_unit_measurement_interval_recurrence
, PP.count_interval_recurrence
, PP.id_stripe_product
, PP.does_expire_faster_once_unsealed
, PP.id_unit_measurement_interval_expiration_unsealed
, PP.count_interval_expiration_unsealed
, PP.active
, IFNULL(t_P.can_view, 0) AS can_view
, IFNULL(t_P.can_edit, 0) AS can_edit
, IFNULL(t_P.can_admin, 0) AS can_admin
, a_guid
FROM tmp_Permutation t_PP
INNER JOIN Shop_Product_Permutation PP ON t_PP.id_permutation = PP.id_permutation
INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product
INNER JOIN Shop_Product P ON t_PP.id_product = P.id_product
INNER JOIN Shop_Product_Category PC ON P.id_category = PC.id_category
LEFT JOIN Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation
LEFT JOIN Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement
LEFT JOIN Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement
LEFT JOIN Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement
INNER JOIN Shop_Currency C ON PP.id_currency_cost = C.id_currency
GROUP BY PP.id_permutation, t_P.can_view, t_P.can_edit, t_P.can_admin
;
COMMIT;
END IF;
# Errors
SELECT
t_ME.display_order,
t_ME.guid,
t_ME.id_type,
t_ME.msg,
MET.code,
MET.name,
MET.description
FROM tmp_Msg_Error t_ME
INNER JOIN Shop_Msg_Error_Type MET
ON t_ME.id_type = MET.id_type
WHERE guid = a_guid
;
IF a_debug = 1 THEN
SET v_time_end := CURRENT_TIMESTAMP(6);
SELECT
v_time_start
, UNIX_TIMESTAMP(v_time_start)
, MICROSECOND(v_time_start) / 1000
, v_time_end
, UNIX_TIMESTAMP(v_time_end)
, MICROSECOND(v_time_end) / 1000
, v_time_end - v_time_start AS timestamp_delta
, UNIX_TIMESTAMP(v_time_end - v_time_start) AS UNIX_TIMESTAMP_timestamp_delta
, MICROSECOND(v_time_end - v_time_start) AS MICROSECOND_timestamp_delta
-- , TIME_FORMAT(TIMEDIFF(v_time_end, v_time_start), '%H:%i:%s') AS time_difference
, CONCAT(
TIME_FORMAT(TIMEDIFF(v_time_end, v_time_start), '%H hours, %i minutes, %s seconds'),
', ',
TIMESTAMPDIFF(MICROSECOND, v_time_start, v_time_end) % 1000000 / 1000, ' milliseconds'
) AS time_difference
;
SELECT *
FROM Shop_Product_Category_Temp
WHERE GUID = a_guid
;
SELECT *
FROM Shop_Product_Temp
WHERE GUID = a_guid
;
SELECT *
FROM Shop_Product_Permutation_Temp
WHERE GUID = a_guid
;
START TRANSACTION;
DELETE FROM Shop_Product_Category_Temp
WHERE GUID = a_guid
;
DELETE FROM Shop_Product_Temp
WHERE GUID = a_guid
;
DELETE FROM Shop_Product_Permutation_Temp
WHERE GUID = a_guid
;
COMMIT;
END IF;
-- Clean up
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Category;
END //
DELIMITER ;;
/*
CALL partsltd_prod.p_shop_calc_product_permutation (
1 #'auth0|6582b95c895d09a70ba10fef', # a_id_user
, 1 # a_get_all_product_category
, 0 # a_get_inactive_product_category
, '' # a_ids_product_category
, 1 # a_get_all_product
, 0 # a_get_inactive_product
, '' # a_ids_product
, 1 # a_get_all_product_permutation
, 0 # a_get_inactive_permutation
, '' # a_ids_permutation
, 0 # a_get_products_quantity_stock_below_minimum
, 'NIPS' # a_guid
, 1 # a_debug
);
/
DELETE FROM Shop_Product_Category_Temp
WHERE GUID = 'NIPS'
;
DELETE FROM Shop_Product_Temp
WHERE GUID = 'NIPS'
;
DELETE FROM Shop_Product_Permutation_Temp
WHERE GUID = 'NIPS'
;
*/

View File

@@ -1,578 +0,0 @@
-- USE partsltd_prod;
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_get_many_product;
DELIMITER //
CREATE PROCEDURE p_shop_get_many_product (
IN a_id_user INT
, IN a_get_all_product_category BIT
, IN a_get_inactive_product_category BIT
, IN a_ids_product_category VARCHAR(500)
, IN a_get_all_product BIT
, IN a_get_inactive_product BIT
, IN a_ids_product VARCHAR(500)
, IN a_get_all_product_permutation BIT
, IN a_get_inactive_permutation BIT
, IN a_ids_permutation VARCHAR(4000)
, IN a_get_all_image BIT
, IN a_get_inactive_image BIT
, IN a_ids_image VARCHAR(4000)
, IN a_get_products_quantity_stock_below_min BIT
)
BEGIN
-- Argument redeclaration
-- Variable declaration
DECLARE v_has_filter_product_category BIT;
DECLARE v_has_filter_product BIT;
DECLARE v_has_filter_permutation BIT;
DECLARE v_has_filter_image BIT;
DECLARE v_guid BINARY(36);
# DECLARE v_id_user VARCHAR(100);
-- DECLARE v_ids_permutation_unavailable VARCHAR(4000);
DECLARE v_id_permission_product INT;
DECLARE v_ids_product_permission VARCHAR(4000);
-- DECLARE v_ids_permutation_permission VARCHAR(4000);
DECLARE v_id_access_level_view INT;
-- DECLARE v_now TIMESTAMP;
DECLARE v_id_minimum INT;
DECLARE v_ids_product_invalid VARCHAR(4000);
SET v_guid := UUID();
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW');
-- Argument validation + default values
SET a_id_user := TRIM(IFNULL(a_id_user, 0));
SET a_get_all_product_category := IFNULL(a_get_all_product_category, 0);
SET a_get_inactive_product_category := IFNULL(a_get_inactive_product_category, 0);
SET a_ids_product_category := TRIM(IFNULL(a_ids_product_category, ''));
SET a_get_all_product := IFNULL(a_get_all_product, 0);
SET a_get_inactive_product := IFNULL(a_get_inactive_product, 0);
SET a_ids_product := TRIM(IFNULL(a_ids_product, ''));
SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0);
SET a_get_inactive_permutation := IFNULL(a_get_inactive_permutation, 0);
SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, ''));
SET a_get_all_image := IFNULL(a_get_all_image, 0);
SET a_get_inactive_image := IFNULL(a_get_inactive_image, 0);
SET a_ids_image := TRIM(IFNULL(a_ids_image, ''));
SET a_get_products_quantity_stock_below_min := IFNULL(a_get_products_quantity_stock_below_min, 0);
/*
SELECT a_id_user, a_get_all_product_category, a_ids_product_category, a_get_inactive_product_category, a_get_all_product,
a_ids_product, a_get_inactive_product, a_get_first_product_only, a_get_all_product_permutation, a_ids_permutation,
a_get_inactive_permutation, a_get_all_image, a_ids_image, a_get_inactive_image, a_get_first_image_only,
a_get_all_delivery_region, a_ids_delivery_region, a_get_inactive_delivery_region, a_get_all_currency, a_ids_currency,
a_get_inactive_currency, a_get_all_discount, a_ids_discount, a_get_inactive_discount
;
*/
-- Temporary tables
DROP TEMPORARY TABLE IF EXISTS tmp_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Image;
DROP TEMPORARY TABLE IF EXISTS tmp_Image;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Product_2;
DROP TEMPORARY TABLE IF EXISTS tmp_Product_Copy;
CREATE TEMPORARY TABLE tmp_Category (
id_category INT NOT NULL,
active BIT NOT NULL,
display_order INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Product (
id_category INT NOT NULL,
id_product INT NOT NULL,
active BIT NOT NULL,
display_order INT NOT NULL,
can_view BIT,
can_edit BIT,
can_admin BIT
);
CREATE TEMPORARY TABLE tmp_Permutation (
id_permutation INT NULL
-- id_category INT NOT NULL,
, id_product INT NOT NULL
, active BIT NOT NULL
-- , display_order INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Image (
id_image INT NOT NULL,
-- id_product INT NOT NULL,
id_permutation INT NULL,
active BIT NOT NULL,
display_order INT NOT NULL
-- rank_in_product_permutation INT NOT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guid BINARY(36) NOT NULL,
id_type INT NULL,
code VARCHAR(50) NOT NULL,
msg VARCHAR(4000) NOT NULL
);
-- Parse filters
SET v_has_filter_product_category = CASE WHEN a_ids_product_category = '' THEN 0 ELSE 1 END;
SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END;
SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END;
SET v_has_filter_image = CASE WHEN a_ids_image = '' THEN 0 ELSE 1 END;
-- select v_has_filter_product, v_has_filter_permutation;
INSERT INTO tmp_Category (
id_category,
active,
display_order
)
SELECT
PC.id_category,
PC.active,
PC.display_order
FROM Shop_Product_Category PC
WHERE (
a_get_all_product_category = 1
OR (
v_has_filter_product_category = 1
AND FIND_IN_SET(PC.id_category, a_ids_product_category) > 0
)
)
AND (
a_get_inactive_product_category = 1
OR PC.active = 1
)
;
INSERT INTO tmp_Product (
id_category,
id_product,
active,
display_order
)
SELECT
P.id_category,
P.id_product,
P.active,
P.display_order
FROM Shop_Product P
INNER JOIN tmp_Category t_C ON P.id_category = t_C.id_category
WHERE (
a_get_all_product = 1
OR (
v_has_filter_product = 1
AND FIND_IN_SET(P.id_product, a_ids_product) > 0
)
)
AND (
a_get_inactive_product = 1
OR P.active = 1
)
;
INSERT INTO tmp_Permutation (
id_permutation
-- id_category,
, id_product
, active
-- , display_order
)
SELECT
PP.id_permutation
-- P.id_category,
, PP.id_product
, PP.active
-- , RANK() OVER (ORDER BY VT.display_order, V.display_order)
FROM Shop_Product_Permutation PP
INNER JOIN tmp_Product t_P ON PP.id_product = t_P.id_product
WHERE (
a_get_all_product_permutation = 1
OR (
v_has_filter_permutation = 1
AND FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0
)
OR (
a_get_products_quantity_stock_below_min = 1
AND PP.quantity_stock < PP.quantity_min
)
)
AND (
a_get_inactive_permutation = 1
OR PP.active = 1
)
;
# Product Images
-- CREATE TEMPORARY TABLE tmp_Product_Copy SELECT * FROM tmp_Product;
INSERT INTO tmp_Image (
-- id_product
id_permutation
, id_image
, active
, display_order
-- , rank_in_product_permutation
)
/*
WITH CTE_Product AS (
SELECT
t_P.id_product
, t_P.id_permutation
, t_P.product_has_variations
, t_P.rank_permutation
FROM tmp_Product t_P
)
*/
SELECT
-- IPP.id_product
I.id_permutation
, I.id_image
, I.active
, I.display_order
-- , RANK() OVER (PARTITION BY IPP.id_product, IPP.id_permutation ORDER BY IPP.display_order_product_temp, IPP.display_order_image)
FROM Shop_Product_Image I
INNER JOIN tmp_Permutation t_PP ON I.id_permutation = t_PP.id_permutation
INNER JOIN Shop_Product P ON t_PP.id_product = P.id_product
WHERE
P.has_variations = 0
AND (
a_get_all_image = 1 OR
FIND_IN_SET(id_image, a_ids_image) > 0
)
AND (
a_get_inactive_image = 1
OR I.active = 1
)
;
-- Permissions
IF EXISTS (SELECT * FROM tmp_Product LIMIT 1) THEN
# SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER());
SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product WHERE NOT ISNULL(id_product));
-- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Product WHERE NOT ISNULL(id_permutation));
-- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission;
-- select * from Shop_Calc_User_Temp;
CALL p_shop_calc_user(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission);
-- select * from Shop_Calc_User_Temp;
UPDATE tmp_Product t_P
INNER JOIN Shop_Calc_User_Temp UE_T
ON t_P.id_product = UE_T.id_product
AND UE_T.GUID = v_guid
SET t_P.can_view = UE_T.can_view,
t_P.can_edit = UE_T.can_edit,
t_P.can_admin = UE_T.can_admin
;
-- select * from Shop_Calc_User_Temp;
-- select * from tmp_Product;
SET v_ids_product_invalid := (
SELECT GROUP_CONCAT(t_P.id_product SEPARATOR ',')
FROM tmp_Product t_P
WHERE ISNULL(t_P.can_view)
);
DELETE -- t_PC
FROM tmp_Category t_PC
WHERE t_PC.id_category IN (
SELECT PC.id_category
FROM Shop_Product_Category PC
INNER JOIN Shop_Product P ON PC.id_category = P.id_category
WHERE FIND_IN_SET(P.id_product, v_ids_product_invalid) > 0
) -- INVALID ON t_PC.id_category = INVALID.id_category
;
DELETE -- t_P
FROM tmp_Product t_P
WHERE FIND_IN_SET(t_P.id_product, v_ids_product_invalid) > 0
;
DELETE -- t_P
FROM tmp_Permutation t_PP
WHERE FIND_IN_SET(t_PP.id_product, v_ids_product_invalid) > 0
;
CALL p_shop_clear_calc_user(v_guid);
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
/*
DELETE FROM Shop_Calc_User_Temp UE_T
WHERE UE_T.GUID = v_guid
;
*/
END IF;
-- select * from tmp_Product;
-- Returns
-- SET v_now := NOW();
# Categories
SELECT
-- DISTINCT
t_C.id_category
, PC.code
, PC.name
, PC.description
, PC.id_access_level_required
, AL.name AS name_access_level_required
, PC.display_order
, PC.active
, MIN(t_P.can_view) AS can_view
, MIN(t_P.can_edit) AS can_edit
, MIN(t_P.can_admin) AS can_admin
FROM tmp_Category t_C
INNER JOIN Shop_Product_Category PC ON t_C.id_category = PC.id_category
LEFT JOIN tmp_Product t_P ON t_C.id_category = t_P.id_product
INNER JOIN Shop_Access_Level AL ON PC.id_access_level_required = AL.id_access_level
GROUP BY t_C.id_category -- , t_P.id_product
ORDER BY PC.display_order
;
# Products
SELECT
t_P.id_product,
P.id_category,
P.name,
P.has_variations,
P.id_access_level_required,
AL.name AS name_access_level_required,
P.active,
P.display_order,
t_P.can_view,
t_P.can_edit,
t_P.can_admin
FROM tmp_Product t_P
INNER JOIN Shop_Product P ON t_P.id_product = P.id_product
INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category
INNER JOIN Shop_Access_Level AL ON P.id_access_level_required = AL.id_access_level
GROUP BY t_P.id_category, t_C.display_order, t_P.id_product, t_P.can_view, t_P.can_edit, t_P.can_admin
ORDER BY t_C.display_order, P.display_order
;
# Product Permutations
SELECT
t_PP.id_permutation,
PP.id_product,
P.id_category,
PP.description,
PP.cost_local,
PP.id_currency_cost,
C.code AS code_currency_cost,
C.symbol AS symbol_currency_cost,
PP.profit_local_min,
PP.latency_manufacture_days,
PP.id_unit_measurement_quantity,
UM_Q.symbol AS symbol_unit_measurement_quantity,
UM_Q.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_quantity,
UM_Q.name_singular AS name_singular_unit_measurement_quantity,
UM_Q.name_plural AS name_plural_unit_measurement_quantity,
PP.count_unit_measurement_per_quantity_step,
PP.quantity_min,
PP.quantity_max,
PP.quantity_stock,
PP.is_subscription,
PP.id_unit_measurement_interval_recurrence,
UM_R.symbol AS symbol_unit_measurement_interval_recurrence,
UM_R.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence,
UM_R.name_singular AS name_singular_unit_measurement_interval_recurrence,
UM_R.name_plural AS name_plural_unit_measurement_interval_recurrence,
PP.count_interval_recurrence,
PP.id_stripe_product,
PP.does_expire_faster_once_unsealed,
PP.id_unit_measurement_interval_expiration_unsealed,
UM_X.symbol AS symbol_unit_measurement_interval_expiration_unsealed,
UM_X.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_interval_expiration_unsealed,
UM_X.name_singular AS name_singular_unit_measurement_interval_expiration_unsealed,
UM_X.name_plural AS name_plural_unit_measurement_interval_expiration_unsealed,
PP.count_interval_expiration_unsealed,
NOT ISNULL(PPVL.id_permutation) AS has_variations,
PP.active,
-- PP.display_order,
IFNULL(t_P.can_view, 0) AS can_view,
IFNULL(t_P.can_edit, 0) AS can_edit,
IFNULL(t_P.can_admin, 0) AS can_admin
FROM tmp_Permutation t_PP
INNER JOIN Shop_Product_Permutation PP ON t_PP.id_permutation = PP.id_permutation
INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product
INNER JOIN Shop_Product P ON t_PP.id_product = P.id_product
INNER JOIN Shop_Product_Category PC ON P.id_category = PC.id_category
LEFT JOIN Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation
LEFT JOIN Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement
LEFT JOIN Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement
LEFT JOIN Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement
INNER JOIN Shop_Currency C ON PP.id_currency_cost = C.id_currency
GROUP BY PC.id_category, P.id_product, PP.id_permutation, t_P.can_view, t_P.can_edit, t_P.can_admin
ORDER BY PC.display_order, P.display_order -- , t_PP.display_order
;
# Variations
SELECT
V.id_variation
, V.id_type
, V.code AS code_variation
, V.name AS name_variation
, V.display_order AS display_order_variation
, V.active AS active_variation
, VT.code AS code_variation_type
, VT.name AS name_variation_type
, VT.name_plural AS name_plural_variation_type
, VT.display_order AS display_order_variation_type
, VT.active AS active_variation_type
, t_P.id_product
, t_PP.id_permutation
, t_C.id_category
FROM Shop_Variation V
INNER JOIN Shop_Variation_Type VT ON V.id_type = VT.id_type
INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation
INNER JOIN tmp_Permutation t_PP ON PPVL.id_permutation = t_PP.id_permutation
INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product
INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category
WHERE V.active
AND PPVL.active
;
/*
# Permutation variations output
SELECT t_P.id_permutation,
t_P.id_product,
t_P.id_category,
id_variation
FROM Shop_Product_Permutation_Variation_Link PPVL
INNER JOIN tmp_Product t_P
ON t_P.id_permutation = PPVL.id_permutation
ORDER BY t_P.display_order
;
*/
-- select * from Shop_Product_Currency_Region_Link;
-- select * from shop_currency;
/*
select * from tmp_Currency;
select * from tmp_delivery_region;
select * from tmp_product;
*/
# Images
SELECT
t_I.id_image,
t_PP.id_product,
t_I.id_permutation,
t_C.id_category,
I.url,
I.active,
I.display_order
FROM tmp_Image t_I
INNER JOIN Shop_Product_Image I ON t_I.id_image = I.id_image
INNER JOIN tmp_Permutation t_PP ON t_I.id_permutation = t_PP.id_permutation
INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product
INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category
ORDER BY t_C.display_order, t_P.display_order, I.display_order
;
# Errors
SELECT
t_ME.display_order,
t_ME.guid,
t_ME.id_type,
t_ME.msg,
MET.code,
MET.name,
MET.description
FROM tmp_Msg_Error t_ME
INNER JOIN Shop_Msg_Error_Type MET
ON t_ME.id_type = MET.id_type
WHERE guid = v_guid
;
/*
# Return arguments for test
SELECT
a_ids_product_category,
a_get_inactive_product_category,
a_ids_product,
a_get_inactive_product,
a_get_first_product_only,
a_get_all_product,
a_ids_image,
a_get_inactive_image,
a_get_first_image_only,
a_get_all_image
;
*/
# select 'other outputs';
# select * from tmp_Product;
-- Clean up
DROP TEMPORARY TABLE IF EXISTS tmp_Image;
DROP TEMPORARY TABLE IF EXISTS tmp_Image;
DROP TEMPORARY TABLE IF EXISTS tmp_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Product_2;
DROP TEMPORARY TABLE IF EXISTS tmp_Product_Copy;
END //
DELIMITER ;;
CALL partsltd_prod.p_shop_get_many_product (
1 #'auth0|6582b95c895d09a70ba10fef', # a_id_user
, 1 # a_get_all_product_category
, 0 # a_get_inactive_product_category
, '' # a_ids_product_category
, 1 # a_get_all_product
, 0 # a_get_inactive_product
, '' # a_ids_product
, 1 # a_get_all_product_permutation
, 0 # a_get_inactive_permutation
, '' # a_ids_permutation
, 1 # a_get_all_image
, 0 # a_get_inactive_image
, '' # a_ids_image
, 0 # a_get_products_quantity_stock_below_minimum
);
/*
select * FROM Shop_Calc_User_Temp;
select * from Shop_Product_Category;
select * from Shop_Product_Permutation;
select * from shop_product_change_set;
insert into shop_product_change_set ( comment ) values ('set stock quantities below minimum for testing');
update shop_product_permutation
set quantity_stock = 0,
id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1)
where id_permutation < 5
DROP TABLE IF EXISTS tmp_Msg_Error;
select * from shop_image;
select * from shop_product;
select * from TMP_MSG_ERROR;
DROP TABLE TMP_MSG_ERROR;
insert into shop_product_change_set (comment)
values ('set product not subscription - test bool output to python');
update shop_product
set is_subscription = 0,
id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1)
where id_product = 1
select * FROM Shop_Calc_User_Temp;
select distinct guid
-- DELETE
FROM Shop_Calc_User_Temp;
*/

View File

@@ -208,6 +208,8 @@ BEGIN
END IF;
END IF;
DELETE FROM tmp_Split;
-- Products
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug);
@@ -281,6 +283,8 @@ BEGIN
;
END IF;
END IF;
DELETE FROM tmp_Split;
-- Permutations
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
@@ -362,6 +366,8 @@ BEGIN
END IF;
END IF;
DELETE FROM tmp_Split;
-- Permissions
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF EXISTS (SELECT * FROM tmp_Product_calc LIMIT 1) THEN

View File

@@ -26,9 +26,9 @@ BEGIN
-- Argument redeclaration
-- Variable declaration
DECLARE v_has_filter_product_category BIT;
DECLARE v_has_filter_product BIT;
DECLARE v_has_filter_permutation BIT;
# DECLARE v_has_filter_product_category BIT;
# DECLARE v_has_filter_product BIT;
# DECLARE v_has_filter_permutation BIT;
DECLARE v_has_filter_image BIT;
DECLARE v_guid BINARY(36);
# DECLARE v_id_user VARCHAR(100);
@@ -139,10 +139,9 @@ BEGIN
-- Parse filters
-- CALL p_validate_guid ( v_guid );
SET v_has_filter_product_category = CASE WHEN a_ids_product_category = '' THEN 0 ELSE 1 END;
SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END;
SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END;
-- SET v_has_filter_product_category = CASE WHEN a_ids_product_category = '' THEN 0 ELSE 1 END;
-- SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END;
-- SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END;
SET v_has_filter_image = CASE WHEN a_ids_image = '' THEN 0 ELSE 1 END;
-- select v_has_filter_product, v_has_filter_permutation;
@@ -215,7 +214,7 @@ BEGIN
;
# Product Images
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF (v_has_filter_image = 1 AND NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1)) THEN
CALL partsltd_prod.p_split(v_guid, a_ids_image, ',', a_debug);
INSERT INTO tmp_Split (
@@ -225,7 +224,7 @@ BEGIN
SELECT
substring
, CONVERT(substring, DECIMAL(10,0)) AS as_int
FROM Split_Temp
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
@@ -286,6 +285,8 @@ BEGIN
END IF;
END IF;
DELETE FROM tmp_Split;
-- Outputs
# Categories
SELECT
@@ -446,11 +447,6 @@ BEGIN
-- WHERE guid = v_guid
;
CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid );
IF a_debug = 1 THEN
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
END IF;
-- Clean up
DROP TEMPORARY TABLE IF EXISTS tmp_Split;
@@ -459,6 +455,11 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid );
IF a_debug = 1 THEN
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
END IF;
END //
DELIMITER ;;

View File

@@ -3,15 +3,14 @@ DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation;
DELIMITER //
CREATE PROCEDURE p_shop_get_many_product_variation (
IN a_id_user INT,
IN a_get_all_variation_type BIT,
IN a_get_inactive_variation_type BIT,
IN a_get_first_variation_type_only BIT,
IN a_ids_variation_type VARCHAR(4000),
IN a_get_all_variation BIT,
IN a_get_inactive_variation BIT,
IN a_get_first_variation_only BIT,
IN a_ids_variation VARCHAR(4000)
IN a_id_user INT
, IN a_get_all_variation_type BIT
, IN a_get_inactive_variation_type BIT
, IN a_ids_variation_type VARCHAR(4000)
, IN a_get_all_variation BIT
, IN a_get_inactive_variation BIT
, IN a_ids_variation TEXT
, IN a_debug BIT
)
BEGIN
-- Argument redeclaration
@@ -25,27 +24,38 @@ BEGIN
# DECLARE v_ids_product_permission VARCHAR(4000);
# DECLARE v_ids_permutation_permission VARCHAR(4000);
DECLARE v_id_access_level_view INT;
DECLARE v_now TIMESTAMP;
DECLARE v_time_start TIMESTAMP(6);
DECLARE v_id_minimum INT;
DECLARE v_code_error_data VARCHAR(50);
DECLARE v_id_type_error_data INT;
SET v_time_start := CURRENT_TIMESTAMP(6);
SET v_guid := UUID();
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1);
SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1);
SET v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1);
-- Argument validation + default values
SET a_id_user = IFNULL(a_id_user, 0);
SET a_get_all_variation = IFNULL(a_get_all_variation, 1);
SET a_get_inactive_variation = IFNULL(a_get_inactive_variation, 0);
SET a_get_first_variation_only = IFNULL(a_get_first_variation_only, 0);
SET a_ids_variation = TRIM(REPLACE(IFNULL(a_ids_variation, ''), '|', ','));
SET a_get_all_variation_type = IFNULL(a_get_all_variation_type, 1);
SET a_get_inactive_variation_type = IFNULL(a_get_inactive_variation_type, 0);
SET a_get_first_variation_type_only = IFNULL(a_get_first_variation_type_only, 0);
SET a_ids_variation_type = TRIM(REPLACE(IFNULL(a_ids_variation_type, ''), '|', ','));
IF a_debug = 1 THEN
SELECT
a_id_user
, a_get_all_variation_type
, a_get_inactive_variation_type
, a_ids_variation_type
, a_get_all_variation
, a_get_inactive_variation
, a_ids_variation
, a_debug
;
END IF;
-- Temporary tables
DROP TABLE IF EXISTS tmp_Variation;
@@ -53,25 +63,27 @@ BEGIN
CREATE TEMPORARY TABLE tmp_Variation_Type (
id_type INT NOT NULL
, active BIT NOT NULL
, rank_type INT NULL
);
CREATE TEMPORARY TABLE tmp_Variation (
id_variation INT NOT NULL
, id_type INT NOT NULL
, active BIT NOT NULL
, rank_variation INT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guid BINARY(36) NOT NULL,
id_type INT NOT NULL,
-- guid BINARY(36) NOT NULL,
id_type INT NULL,
code VARCHAR(50) NOT NULL,
msg VARCHAR(4000) NOT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split (
substring VARCHAR(4000) NOT NULL
, as_int INT NULL
);
DELETE FROM tmp_Split;
-- Parse filters
SET v_has_filter_variation = CASE WHEN a_ids_variation = '' THEN 0 ELSE 1 END;
@@ -79,138 +91,205 @@ BEGIN
-- select v_has_filter_product, v_has_filter_permutation;
IF v_has_filter_variation = 1 OR a_get_all_variation = 1 OR v_has_filter_variation_type = 1 OR a_get_all_variation_type = 1 THEN
CALL p_split(a_guid, a_ids_variation_type, ',');
IF v_has_filter_variation_type THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
CALL partsltd_prod.p_split(v_guid, a_ids_variation_type, ',', a_debug);
IF EXISTS (SELECT * FROM Split_Temp S_T LEFT JOIN Shop_Variation_Type VT ON S_T.substring = VT.id_type WHERE ISNULL(VT.id_type)) THEN
DELETE FROM tmp_Split;
INSERT INTO tmp_Split (
substring
, as_int
)
SELECT
substring
, CONVERT(substring, DECIMAL(10,0)) AS as_int
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
AND substring != ''
;
CALL partsltd_prod.p_clear_split_temp( v_guid );
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF EXISTS (
SELECT *
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type
WHERE
ISNULL(t_S.as_int)
OR ISNULL(VT.id_type)
) THEN
INSERT INTO tmp_Msg_Error (
guid,
-- guid,
id_type,
code,
msg
)
VALUES (
v_guid,
v_code_error_data,
CONCAT('Invalid Variation Type IDs: ', (SELECT GROUP_CONCAT(VT.id_type) FROM Split_Temp S_T LEFT JOIN Shop_Variation_Type VT ON S_T.substring = VT.id_type WHERE ISNULL(VT.id_type)))
)
SELECT
-- v_guid,
v_id_type_error_bad_data,
v_code_type_error_bad_data,
CONCAT('Invalid or inactive variation type IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type
WHERE
ISNULL(t_S.as_int)
OR ISNULL(VT.id_type)
;
CALL p_clear_split_temp;
ELSE
CALL p_clear_split_temp;
CALL p_split(a_guid, a_ids_variation, ',');
IF EXISTS (SELECT * FROM Split_Temp S_T LEFT JOIN Shop_Variation V ON S_T.substring = V.id_variation WHERE ISNULL(V.id_variation)) THEN
INSERT INTO tmp_Msg_Error (
guid,
code,
msg
)
VALUES (
v_guid,
v_code_error_data,
CONCAT('Invalid Variation IDs: ', (SELECT GROUP_CONCAT(V.id_variation) FROM Split_Temp S_T LEFT JOIN Shop_Variation V ON S_T.substring = V.id_variation WHERE ISNULL(V.id_variation)))
)
;
ELSE
INSERT INTO tmp_Variation (
id_variation
, id_type
, active
, rank_variation
)
SELECT
V.id_variation
, V.id_type
, V.active
, RANK() OVER (ORDER BY id_variation ASC) AS rank_id_variation
FROM Shop_Variation V
INNER JOIN Shop_Variation_Type VT ON V.id_type = VT.id_type
LEFT JOIN Split_Temp S_T ON V.id_variation = S_T.substring
WHERE
(
a_get_all_variation = 1
OR NOT ISNULL(S_T.substring)
)
AND (
a_get_inactive_variation
OR V.active = 1
)
AND (
a_get_all_variation_type
OR FIND_IN_SET(V.id_type, a_ids_variation_type)
)
AND (
a_get_inactive_variation_type
OR VT.active = 1
)
;
END IF;
CALL p_clear_split_temp;
IF a_get_first_variation_only THEN
DELETE t_V
FROM tmp_Variation t_V
WHERE t_V.rank_variation > 1
;
END IF;
INSERT INTO tmp_Variation_Type (
id_type
, active
, rank_type
)
SELECT
DISTINCT t_V.id_type
, VT.active
, RANK() OVER(ORDER BY t_V.id_type) AS rank_type
FROM tmp_Variation t_V
INNER JOIN Shop_Variation_Type VT ON t_V.id_type = VT.id_type
;
IF a_get_first_variation_type_only THEN
DELETE t_V
FROM tmp_Variation t_V
INNER JOIN tmp_Variation_Type t_VT ON t_V.id_variation = t_VT.id_variation
WHERE t_VT.rank_type > 1
;
DELETE t_VT
FROM tmp_Variation_Type t_VT
WHERE t_VT.rank_type > 1
;
END IF;
DISTINCT VT.id_type
FROM tmp_Split t_S
RIGHT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type
WHERE
(
a_get_all_variation_type = 1
OR (
v_has_filter_variation_type = 1
AND NOT ISNULL(t_S.as_int)
)
)
AND (
a_get_inactive_variation_type = 1
OR VT.active = 1
)
;
END IF;
END IF;
END IF;
DELETE FROM tmp_Split;
IF (v_has_filter_variation AND NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1)) THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
CALL partsltd_prod.p_split(v_guid, a_ids_variation, ',', a_debug);
DELETE FROM tmp_Split;
INSERT INTO tmp_Split (
substring
, as_int
)
SELECT
substring
, CONVERT(substring, DECIMAL(10,0)) AS as_int
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
AND substring != ''
;
CALL partsltd_prod.p_clear_split_temp( v_guid );
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF EXISTS (
SELECT *
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation
WHERE
ISNULL(t_S.as_int)
OR ISNULL(V.id_variation)
) THEN
INSERT INTO tmp_Msg_Error (
-- guid,
id_type,
code,
msg
)
SELECT
-- v_guid,
v_id_type_error_bad_data,
v_code_type_error_bad_data,
CONCAT('Invalid or inactive variation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation
WHERE
ISNULL(t_S.as_int)
OR ISNULL(VT.id_type)
;
ELSE
INSERT INTO tmp_Variation (
id_variation
, id_type
)
SELECT
DISTINCT V.id_variation
, V.id_type
FROM tmp_Split t_S
RIGHT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation
WHERE
(
a_get_all_variation = 1
OR (
v_has_filter_variation = 1
AND NOT ISNULL(t_S.as_int)
)
)
AND (
a_get_inactive_variation = 1
OR V.active = 1
)
;
END IF;
END IF;
DELETE FROM tmp_Split;
-- Permissions
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
# SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER());
SET v_id_permission_variation := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
-- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission;
-- select * from Shop_Calc_User_Temp;
IF a_debug = 1 THEN
SELECT
v_guid
, a_id_user
, FALSE AS a_get_inactive_users
, v_id_permission_variation
, v_id_access_level_view
, '' AS a_ids_product
, 0 AS a_debug
;
-- select * from Shop_Calc_User_Temp;
END IF;
CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_variation, v_id_access_level_view, '');
CALL p_shop_calc_user(
v_guid
, a_id_user
, FALSE -- a_get_inactive_users
, v_id_permission_variation
, v_id_access_level_view
, '' -- a_ids_product
, 0 -- a_debug
);
-- select * from Shop_Calc_User_Temp;
IF a_debug = 1 THEN
select * from Shop_Calc_User_Temp;
END IF;
IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN
INSERT INTO tmp_Msg_Error (
guid,
-- guid,
id_type,
code,
msg
)
VALUES (
v_guid,
-- v_guid,
v_id_type_error_data,
v_code_error_data,
CONCAT('You do not have view permissions for ', (SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_supplier LIMIT 1))
CONCAT('You do not have view permissions for ', (SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_variation LIMIT 1))
)
;
END IF;
CALL p_shop_clear_calc_user(v_guid);
CALL p_shop_clear_calc_user( v_guid, 0 );
END IF;
IF EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
@@ -257,15 +336,20 @@ BEGIN
SELECT
*
FROM tmp_Msg_Error t_ME
INNER JOIN Shop_Msg_Error_Type MET
ON t_ME.id_type = MET.id_type
WHERE guid = v_guid
INNER JOIN Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type
-- WHERE guid = v_guid
;
-- Clean up
DROP TABLE IF EXISTS tmp_Variation;
DROP TABLE IF EXISTS tmp_Variation_Type;
CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid );
IF a_debug = 1 THEN
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
END IF;
END //
DELIMITER ;;
@@ -273,25 +357,25 @@ DELIMITER ;;
/*
CALL p_shop_get_many_product_variation (
1, # 'auth0|6582b95c895d09a70ba10fef', # a_id_user
1, # a_get_all_variation_type
0, # a_get_inactive_variation_type
0, # a_get_first_variation_type_only
'', # a_ids_variation_type
1, # a_get_all_variation
0, # a_get_inactive_variation
0, # a_get_first_variation_only
'' # a_ids_variation
1 # 'auth0|6582b95c895d09a70ba10fef', # a_id_user
, 1 # a_get_all_variation_type
, 0 # a_get_inactive_variation_type
, '' # a_ids_variation_type
, 1 # a_get_all_variation
, 0 # a_get_inactive_variation
, '' # a_ids_variation
, 1 # a_debug
);
select * from TMP_MSG_ERROR;
DROP TABLE TMP_MSG_ERROR;
select * from shop_variation;
select * from shop_variation_type;
*/
/*
select * from shop_supplier;
select * from shop_product;
select * from TMP_MSG_ERROR;
DROP TABLE TMP_MSG_ERROR;
insert into shop_product_change_set (comment)
values ('set product not subscription - test bool output to python');

View File

@@ -1,842 +0,0 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item;
DELIMITER //
CREATE PROCEDURE p_shop_get_many_stock_item (
IN a_id_user INT,
IN a_get_all_category BIT,
IN a_get_inactive_category BIT,
IN a_get_first_category_only BIT,
IN a_ids_category TEXT,
IN a_get_all_product BIT,
IN a_get_inactive_product BIT,
IN a_get_first_product_only BIT,
IN a_ids_product LONGTEXT,
IN a_get_all_product_permutation BIT,
IN a_get_inactive_permutation BIT,
IN a_get_first_permutation_only BIT,
IN a_ids_permutation LONGTEXT,
IN a_get_all_stock_item BIT,
IN a_get_inactive_stock_item BIT,
IN a_get_first_stock_item_only BIT,
IN a_ids_stock_item LONGTEXT,
IN a_get_all_region_storage BIT,
IN a_get_inactive_region_storage BIT,
IN a_get_first_region_storage_only BIT,
IN a_ids_region_storage VARCHAR(4000),
IN a_get_all_plant_storage BIT,
IN a_get_inactive_plant_storage BIT,
IN a_get_first_plant_storage_only BIT,
IN a_ids_plant_storage VARCHAR(4000),
IN a_get_all_location_storage BIT,
IN a_get_inactive_location_storage BIT,
IN a_get_first_location_storage_only BIT,
IN a_ids_location_storage TEXT,
IN a_date_received_to TIMESTAMP,
IN a_get_sealed_stock_item_only BIT,
IN a_get_unsealed_stock_item_only BIT,
IN a_get_expired_stock_item_only BIT,
IN a_get_nonexpired_stock_item_only BIT,
IN a_get_consumed_stock_item_only BIT,
IN a_get_nonconsumed_stock_item_only BIT
)
BEGIN
-- Argument redeclaration
-- Variable declaration
DECLARE v_has_filter_category BIT;
DECLARE v_has_filter_product BIT;
DECLARE v_has_filter_permutation BIT;
DECLARE v_has_filter_stock_item BIT;
DECLARE v_has_filter_region_storage BIT;
DECLARE v_has_filter_plant_storage BIT;
DECLARE v_has_filter_location_storage BIT;
DECLARE v_guid BINARY(36);
-- DECLARE v_ids_permutation_unavailable LONGTEXT;
DECLARE v_id_permission_product INT;
DECLARE v_ids_product_permission LONGTEXT;
-- DECLARE v_ids_permutation_permission VARCHAR(4000);
DECLARE v_id_access_level_view INT;
-- DECLARE v_now TIMESTAMP;
-- DECLARE v_id_minimum INT;
DECLARE v_now TIMESTAMP;
SET v_guid := UUID();
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW');
SET v_now := NOW();
-- Argument validation + default values
SET a_id_user := TRIM(IFNULL(a_id_user, ''));
SET a_get_all_category := IFNULL(a_get_all_category, 0);
SET a_get_inactive_category := IFNULL(a_get_inactive_category, 0);
SET a_get_first_category_only := IFNULL(a_get_first_category_only, 1);
SET a_ids_category := TRIM(IFNULL(a_ids_category, ''));
SET a_get_all_product := IFNULL(a_get_all_product, 0);
SET a_get_inactive_product := IFNULL(a_get_inactive_product, 0);
SET a_get_first_product_only := IFNULL(a_get_first_product_only, 1);
SET a_ids_product := TRIM(IFNULL(a_ids_product, ''));
SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0);
SET a_get_inactive_permutation := IFNULL(a_get_inactive_permutation, 0);
SET a_get_first_permutation_only := IFNULL(a_get_first_permutation_only, 1);
SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, ''));
SET a_get_all_stock_item := IFNULL(a_get_all_stock_item, 0);
SET a_get_inactive_stock_item := IFNULL(a_get_inactive_stock_item, 0);
SET a_get_first_stock_item_only := IFNULL(a_get_first_stock_item_only, 1);
SET a_ids_stock_item := TRIM(IFNULL(a_ids_stock_item, ''));
SET a_get_all_region_storage := IFNULL(a_get_all_region_storage, 0);
SET a_get_inactive_region_storage := IFNULL(a_get_inactive_region_storage, 0);
SET a_get_first_region_storage_only := IFNULL(a_get_first_region_storage_only, 1);
SET a_ids_region_storage := TRIM(IFNULL(a_ids_region_storage, ''));
SET a_get_all_plant_storage := IFNULL(a_get_all_plant_storage, 0);
SET a_get_inactive_plant_storage := IFNULL(a_get_inactive_plant_storage, 0);
SET a_get_first_plant_storage_only := IFNULL(a_get_first_plant_storage_only, 1);
SET a_ids_plant_storage := TRIM(IFNULL(a_ids_plant_storage, ''));
SET a_get_all_location_storage := IFNULL(a_get_all_location_storage, 0);
SET a_get_inactive_location_storage := IFNULL(a_get_inactive_location_storage, 0);
SET a_get_first_location_storage_only := IFNULL(a_get_first_location_storage_only, 1);
SET a_ids_location_storage := TRIM(IFNULL(a_ids_location_storage, ''));
SET a_date_received_to := IFNULL(a_date_received_to, NOW());
SET a_get_sealed_stock_item_only := IFNULL(a_get_sealed_stock_item_only, 0);
SET a_get_unsealed_stock_item_only := IFNULL(a_get_unsealed_stock_item_only, 0);
SET a_get_expired_stock_item_only := IFNULL(a_get_expired_stock_item_only, 0);
SET a_get_nonexpired_stock_item_only := IFNULL(a_get_nonexpired_stock_item_only, 0);
SET a_get_consumed_stock_item_only := IFNULL(a_get_consumed_stock_item_only, 0);
SET a_get_nonconsumed_stock_item_only := IFNULL(a_get_nonconsumed_stock_item_only, 0);
-- Temporary tables
DROP TABLE IF EXISTS tmp_Region_Storage;
DROP TABLE IF EXISTS tmp_Plant_Storage;
DROP TABLE IF EXISTS tmp_Location_Storage;
DROP TABLE IF EXISTS tmp_Stock_Item;
DROP TABLE IF EXISTS tmp_Permutation;
DROP TABLE IF EXISTS tmp_Product;
DROP TABLE IF EXISTS tmp_Category;
DROP TABLE IF EXISTS tmp_Msg_Error;
CREATE TEMPORARY TABLE tmp_Category (
id_category INT NOT NULL
/*
, CONSTRAINT FK_tmp_Category_id_category
FOREIGN KEY (id_category)
REFERENCES Shop_Product_Category(id_category)
/
active BIT NOT NULL,
display_order INT NOT NULL,
can_view BIT,
can_edit BIT,
can_admin BIT
*/
, rank_category INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Product (
/*
id_category INT NOT NULL,
CONSTRAINT FK_tmp_Shop_Product_id_category
FOREIGN KEY (id_category)
REFERENCES Shop_Product_Category(id_category),
*/
id_product INT NOT NULL
/*
, CONSTRAINT FK_tmp_Product_id_product
FOREIGN KEY (id_product)
REFERENCES Shop_Product(id_product)
*/
-- product_has_variations BIT NOT NULL,
/*
id_permutation INT NULL,
CONSTRAINT FK_tmp_Shop_Product_id_permutation
FOREIGN KEY (id_permutation)
REFERENCES Shop_Product_Permutation(id_permutation),
active_category BIT NOT NULL,
active_product BIT NOT NULL,
active_permutation BIT NULL,
display_order_category INT NOT NULL,
display_order_product INT NOT NULL,
display_order_permutation INT NULL,
rank_permutation INT NOT NULL, # _in_category
name VARCHAR(255) NOT NULL,
description VARCHAR(4000) NOT NULL,
/
price_GBP_full FLOAT NOT NULL,
price_GBP_min FLOAT NOT NULL,
*
, latency_manufacture_days INT NOT NULL
, quantity_min FLOAT NOT NULL
, quantity_max FLOAT NOT NULL
, quantity_step FLOAT NOT NULL
, quantity_stock FLOAT NOT NULL
, is_subscription BIT NOT NULL
, id_unit_measurement_interval_recurrence INT
, CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence
FOREIGN KEY (id_unit_measurement_interval_recurrence)
REFERENCES Shop_Interval_Recurrence(id_interval)
, count_interval_recurrence INT
, id_stripe_product VARCHAR(100)
, product_has_variations INT NOT NULL
, can_view BIT
, can_edit BIT
, can_admin BIT
*/
, rank_product INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Permutation (
id_permutation INT NOT NULL
/*
CONSTRAINT FK_tmp_Permutation_id_permutation
FOREIGN KEY (id_permutation)
REFERENCES Shop_Product_Permutation(id_permutation)
*/
, rank_permutation INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Stock_Item (
id_stock INT NOT NULL PRIMARY KEY,
id_permutation INT NOT NULL
/*
CONSTRAINT FK_tmp_Stock_Item_id_permutation
FOREIGN KEY (id_permutation)
REFERENCES Shop_Product_Permutation(id_permutation),
*/
, id_product INT NOT NULL
/*
CONSTRAINT FK_tmp_Stock_Item_id_product
FOREIGN KEY (id_product)
REFERENCES Shop_Product(id_product),
*/
, id_category INT NOT NULL
/*
CONSTRAINT FK_tmp_Stock_Item_id_category
FOREIGN KEY (id_category)
REFERENCES Shop_Product_Category(id_category),
*/
, date_purchased TIMESTAMP NOT NULL
, date_received TIMESTAMP NULL
, id_location_storage INT NOT NULL
/*
CONSTRAINT FK_tmp_Stock_Item_id_location_storage
FOREIGN KEY (id_location_storage)
REFERENCES Shop_Storage_Location(id_location),
*/
, id_currency_cost INT NOT NULL
/*
CONSTRAINT FK_tmp_Stock_Item_id_currency
FOREIGN KEY (id_currency_cost)
REFERENCES Shop_Currency(id_currency),
*/
, cost_local_VAT_incl FLOAT NOT NULL
, cost_local_VAT_excl FLOAT NOT NULL
, is_sealed BIT NOT NULL DEFAULT 1
, date_unsealed TIMESTAMP NULL
, date_expiration TIMESTAMP NOT NULL
, is_consumed BIT NOT NULL DEFAULT 0
, date_consumed TIMESTAMP NULL
, active_stock_item BIT NOT NULL DEFAULT 1
, active_permutation BIT NOT NULL
, active_product BIT NOT NULL
, active_category BIT NOT NULL
, rank_stock_item INT NOT NULL
, display_order_permutation INT NOT NULL
, display_order_product INT NOT NULL
, display_order_category INT NOT NULL
, can_view BIT NULL
, can_edit BIT NULL
, can_admin BIT NULL
);
CREATE TEMPORARY TABLE tmp_Region_Storage (
id_region INT NOT NULL PRIMARY KEY
/*
CONSTRAINT FK_tmp_Region_Storage_id_region
FOREIGN KEY (id_region)
REFERENCES Shop_Region(id_region)
*/
, rank_region INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Plant_Storage (
id_plant INT NOT NULL PRIMARY KEY
/*
CONSTRAINT FK_tmp_Plant_Storage_id_plant
FOREIGN KEY (id_plant)
REFERENCES Shop_Plant(id_plant)
*/
, rank_plant INT NOT NULL
, id_region INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Location_Storage (
id_location INT NOT NULL PRIMARY KEY
/*
CONSTRAINT FK_tmp_Location_Storage_id_location
FOREIGN KEY (id_location)
REFERENCES Shop_Location_Storage(id_location)
*/
, rank_location INT NOT NULL
, id_plant INT NOT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guid BINARY(36) NOT NULL,
id_type INT NOT NULL,
/*
CONSTRAINT FK_tmp_Msg_Error_id_type
FOREIGN KEY (id_type)
REFERENCES Shop_Msg_Error_Type (id_type),
*/
code VARCHAR(50) NOT NULL,
msg VARCHAR(4000) NOT NULL
);
-- Parse filters
SET v_has_filter_category = CASE WHEN a_ids_category = '' THEN 0 ELSE 1 END;
SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END;
SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END;
SET v_has_filter_stock_item = CASE WHEN a_ids_stock_item = '' THEN 0 ELSE 1 END;
SET v_has_filter_region_storage = CASE WHEN a_ids_region_storage = '' THEN 0 ELSE 1 END;
SET v_has_filter_plant_storage = CASE WHEN a_ids_plant_storage = '' THEN 0 ELSE 1 END;
SET v_has_filter_location_storage = CASE WHEN a_ids_location_storage = '' THEN 0 ELSE 1 END;
-- select v_has_filter_product, v_has_filter_permutation;
INSERT INTO tmp_Stock_Item (
id_stock,
id_permutation,
id_product,
id_category,
active_stock_item,
active_permutation,
active_product,
active_category,
display_order_permutation,
display_order_product,
display_order_category,
rank_stock_item,
date_purchased,
date_received,
id_location_storage,
id_currency_cost,
/*
symbol_currency_cost,
code_currency_cost,
*/
cost_local_VAT_incl,
cost_local_VAT_excl,
is_sealed,
date_unsealed,
date_expiration,
is_consumed,
date_consumed
)
SELECT
SI.id_stock,
PP.id_permutation,
P.id_product,
P.id_category,
SI.active AS active_stock_item,
PP.active AS active_permutation,
P.active AS active_product,
C.active AS active_category,
PP.display_order AS display_order_permutation,
P.display_order AS display_order_product,
C.display_order AS display_order_category,
RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order, SI.date_expiration) AS rank_stock_item,
SI.date_purchased,
SI.date_received,
SI.id_location_storage,
SI.id_currency_cost,
/*
CURRENCY.symbol AS symbol_currency_cost,
CURRENCY.code AS code_currency_cost,
*/
SI.cost_local_VAT_incl,
SI.cost_local_VAT_excl,
SI.is_sealed,
SI.date_unsealed,
SI.date_expiration,
SI.is_consumed,
SI.date_consumed
FROM Shop_Stock_Item SI
INNER JOIN Shop_Product_Permutation PP ON SI.id_permutation = PP.id_permutation
INNER JOIN Shop_Product P ON PP.id_product = P.id_product
INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category
WHERE
# stock items
(
(
a_get_all_stock_item
OR (
v_has_filter_stock_item
AND FIND_IN_SET(SI.id_stock, a_ids_stock_item) > 0
)
)
AND (
a_get_inactive_stock_item
OR SI.active
)
AND (
ISNULL(a_date_received_to)
OR SI.date_received <= a_date_received_to
)
AND (
a_get_unsealed_stock_item_only = 0
OR NOT SI.is_sealed
)
AND (
a_get_sealed_stock_item_only = 0
OR SI.is_sealed
)
AND (
a_get_nonexpired_stock_item_only = 0
OR SI.date_expiration > v_now
)
AND (
a_get_expired_stock_item_only = 0
OR SI.date_expiration <= v_now
)
AND (
a_get_consumed_stock_item_only = 0
OR SI.is_consumed
)
AND (
a_get_nonconsumed_stock_item_only = 0
OR NOT SI.is_consumed
)
)
# permutations
AND (
(
a_get_all_product_permutation
OR (
v_has_filter_permutation
AND FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0
)
)
AND (
a_get_inactive_permutation
OR PP.active
)
)
# products
AND (
(
a_get_all_product
OR v_has_filter_product AND FIND_IN_SET(P.id_product, a_ids_product) > 0
)
AND (
a_get_inactive_product
OR P.active
)
)
# categories
AND (
(
a_get_all_category
OR v_has_filter_category AND FIND_IN_SET(P.id_category, a_ids_category) > 0
)
AND (
a_get_inactive_category
OR C.active
)
)
;
IF a_get_first_stock_item_only THEN
DELETE t_SI
FROM tmp_Stock_Item t_SI
WHERE t_SI.rank_stock_item > 1
;
END IF;
-- Permutations
INSERT INTO tmp_Permutation (
id_permutation,
rank_permutation
)
SELECT
DISTINCT t_SI.id_permutation
, RANK() OVER (ORDER BY id_permutation) AS rank_permutation
FROM tmp_Stock_Item t_SI
;
IF a_get_first_product_only THEN
DELETE t_P
FROM tmp_Product t_P
WHERE t_P.rank_permutation > 1
;
END IF;
-- Products
INSERT INTO tmp_Product (
id_product,
rank_product
)
SELECT
DISTINCT t_SI.id_product
, RANK() OVER (ORDER BY id_product) AS rank_product
FROM tmp_Stock_Item t_SI
;
IF a_get_first_product_only THEN
DELETE t_P
FROM tmp_Product t_P
WHERE t_P.rank_product > 1
;
END IF;
-- Categories
INSERT INTO tmp_Category (
id_category,
rank_category
)
SELECT
DISTINCT t_SI.id_category
, RANK() OVER (ORDER BY id_category) AS rank_category
FROM tmp_Stock_Item t_SI
;
IF a_get_first_category_only THEN
DELETE t_P
FROM tmp_Product t_P
INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category
WHERE t_C.rank_category > 1
;
DELETE t_C
FROM tmp_Category t_C
WHERE t_C.rank_category > 1
;
END IF;
-- Storage Regions
INSERT INTO tmp_Region_Storage (
id_region
, rank_region
)
WITH RECURSIVE Recursive_CTE_Region_Storage AS (
SELECT
R.id_region AS id_region_parent,
NULL AS id_region_child
FROM tmp_Stock_Item t_SI
-- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage
INNER JOIN Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location
INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN Shop_Address A ON P.id_address = A.id_address
INNER JOIN Shop_Region R
ON A.id_region = R.id_region
AND (
a_get_all_region_storage
OR FIND_IN_SET(R.id_region, a_ids_region_storage) > 0
)
AND (
a_get_inactive_region_storage
OR R.active = 1
)
UNION
SELECT
RB.id_region_parent,
RB.id_region_child
FROM Shop_Region_Branch RB
INNER JOIN Recursive_CTE_Region_Storage r_RS
ON RB.id_region_parent = r_RS.id_region_child
AND (
a_get_inactive_region_storage
OR RB.active = 1
)
)
SELECT
DISTINCT R.id_region,
RANK() OVER (ORDER BY R.id_region) AS rank_region
FROM Shop_Region R
INNER JOIN Recursive_CTE_Region_Storage r_RS
ON R.id_region = r_RS.id_region_parent
OR R.id_region = r_RS.id_region_child
;
IF a_get_first_region_storage_only THEN
DELETE t_RS
FROM tmp_Region_Storage t_RS
WHERE t_RS.rank_region > 1
;
END IF;
-- Plants
INSERT INTO tmp_Plant_Storage (
id_plant
, rank_plant
, id_region
)
SELECT
DISTINCT P.id_plant
, RANK() OVER (ORDER BY P.id_plant) AS rank_plant
, A.id_region
FROM tmp_Stock_Item t_SI
INNER JOIN Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location
INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN Shop_Address A ON P.id_address = A.id_address
;
IF a_get_first_plant_storage_only THEN
DELETE t_P
FROM tmp_Plant_Storage t_P
WHERE t_P.rank_plant > 1
;
END IF;
-- Storage Locations
INSERT INTO tmp_Location_Storage (
id_location
, rank_location
, id_plant
)
WITH RECURSIVE Recursive_CTE_Location_Storage AS (
SELECT
SL.id_location AS id_location_parent,
NULL AS id_location_child
FROM tmp_Stock_Item t_SI
-- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage
INNER JOIN Shop_Storage_Location SL
ON t_SI.id_location_storage = SL.id_location
AND (
a_get_all_location_storage
OR FIND_IN_SET(SL.id_location, a_ids_location_storage) > 0
)
AND (
a_get_inactive_location_storage
OR SL.active = 1
)
UNION
SELECT
SLB.id_location_parent,
SLB.id_location_child
FROM Shop_Storage_Location_Branch SLB
INNER JOIN Recursive_CTE_Location_Storage r_LS
ON SLB.id_location_parent = r_LS.id_location_child
AND (
a_get_inactive_location_storage
OR SLB.active = 1
)
)
SELECT
DISTINCT SL.id_location
, RANK() OVER (ORDER BY SL.id_location) AS rank_location
, SL.id_plant
FROM Shop_Storage_Location SL
INNER JOIN Recursive_CTE_Location_Storage r_LS
ON SL.id_location = r_LS.id_location_parent
OR SL.id_location = r_LS.id_location_child
;
IF a_get_first_location_storage_only THEN
DELETE t_LS
FROM tmp_Location_Storage t_LS
WHERE t_LS.rank_location > 1
;
END IF;
-- Permissions
IF EXISTS (SELECT * FROM tmp_Stock_Item LIMIT 1) THEN
SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product WHERE NOT ISNULL(id_product));
-- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation));
-- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission;
-- select * from Shop_Calc_User_Temp;
CALL p_shop_calc_user(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission);
-- select * from Shop_Calc_User_Temp;
UPDATE tmp_Stock_Item t_SI
INNER JOIN Shop_Calc_User_Temp UE_T
ON t_SI.id_product = UE_T.id_product
AND UE_T.GUID = v_guid
SET t_SI.can_view = UE_T.can_view,
t_SI.can_edit = UE_T.can_edit,
t_SI.can_admin = UE_T.can_admin
;
DELETE t_SI
FROM tmp_Stock_Item t_SI
/*
LEFT JOIN Shop_Calc_User_Temp UE_T
ON t_SI.id_product = UE_T.id_product
AND UE_T.GUID = v_guid
*/
WHERE
/*
FIND_IN_SET(t_SI.id_product, (
SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',')
FROM Shop_Calc_User_Temp UET)
) = 0 # id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_Calc_User_Temp), '%');
*/
/*
ISNULL(UE_T.id_product)
OR IFNULL(UE_T.can_view, 0) = 0
*/
t_SI.id_product NOT IN (
SELECT id_product
FROM Shop_Calc_User_Temp UE_T
WHERE
GUID = v_guid
AND IFNULL(can_view, 0) = 1
)
;
# CALL p_shop_calc_user_clear_temp(v_guid);
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
DELETE FROM Shop_Calc_User_Temp
WHERE GUID = v_guid
;
END IF;
select * from shop_stock_item;
-- Returns
-- SET v_now := NOW();
# Stock Items
SELECT
t_SI.id_stock,
t_SI.id_permutation,
t_SI.id_product,
t_SI.id_category,
t_SI.date_purchased,
t_SI.date_received,
t_SI.id_location_storage,
SL.name AS name_location_storage,
t_SI.id_currency_cost,
CURRENCY.symbol AS symbol_currency_cost,
CURRENCY.code AS code_currency_cost,
t_SI.cost_local_VAT_incl,
t_SI.cost_local_VAT_excl,
t_SI.is_sealed,
t_SI.date_unsealed,
t_SI.date_expiration,
t_SI.is_consumed,
t_SI.date_consumed,
t_SI.active_stock_item,
/*
t_SI.active_permutation,
t_SI.active_product,
t_SI.active_category,
*/
IFNULL(t_SI.can_view, 0),
IFNULL(t_SI.can_edit, 0),
IFNULL(t_SI.can_admin, 0)
FROM tmp_Stock_Item t_SI
INNER JOIN tmp_Permutation t_PP ON t_SI.id_permutation = t_PP.id_permutation
INNER JOIN tmp_Product t_P ON t_SI.id_product = t_P.id_product
INNER JOIN tmp_Category t_C ON t_SI.id_category = t_C.id_category
INNER JOIN tmp_Location_Storage t_LS ON t_SI.id_location_storage = t_LS.id_location
INNER JOIN tmp_Plant_Storage t_PS ON t_LS.id_plant = t_PS.id_plant
INNER JOIN Shop_Plant P ON t_PS.id_plant = P.id_plant
INNER JOIN Shop_Address A ON P.id_address = A.id_address
INNER JOIN tmp_Region_Storage t_RS ON A.id_region = t_RS.id_region
INNER JOIN Shop_Storage_Location SL ON t_LS.id_location = SL.id_location
INNER JOIN Shop_Currency CURRENCY ON t_SI.id_currency_cost = CURRENCY.id_currency
WHERE
IFNULL(t_SI.can_view, 0) = 1
ORDER BY t_SI.rank_stock_item
;
# Errors
SELECT
t_ME.display_order,
t_ME.guid,
t_ME.id_type,
t_ME.msg,
MET.code,
MET.name,
MET.description
FROM tmp_Msg_Error t_ME
INNER JOIN Shop_Msg_Error_Type MET
ON t_ME.id_type = MET.id_type
WHERE guid = v_guid
;
/*
# Return arguments for test
SELECT
a_ids_category,
a_get_inactive_category,
a_ids_product,
a_get_inactive_product,
a_get_first_product_only,
a_get_all_product,
a_ids_image,
a_get_inactive_image,
a_get_first_image_only,
a_get_all_image
;
*/
-- Clean up
DROP TEMPORARY TABLE IF EXISTS tmp_Region_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Plant_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Location_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
END //
DELIMITER ;;
CALL p_shop_get_many_stock_item (
0, # a_id_user
1, # a_get_all_category
0, # a_get_inactive_category
0, # a_get_first_category_only
'', # a_ids_category
1, # a_get_all_product
0, # a_get_inactive_product
0, # a_get_first_product_only
'', # a_ids_product
1, # a_get_all_product_permutation
0, # a_get_inactive_permutation
0, # a_get_first_permutation_only
'1,2,3,4,5,6', # a_ids_permutation
1, # a_get_all_stock_item
0, # a_get_inactive_stock_item
0, # a_get_first_stock_item_only
'', # a_ids_stock_item
0, # a_get_all_region_storage
0, # a_get_inactive_delivery_region
0, # a_get_first_region_storage_only
'', # a_ids_region_storage
0, # a_get_all_plant_storage
0, # a_get_inactive_plant_storage
0, # a_get_first_plant_storage_only
'', # a_ids_plant_storage
0, # a_get_all_location_storage
0, # a_get_inactive_location_storage
0, # a_get_first_location_storage_only
'', # a_ids_location_storage
NOW(), # a_date_received_to
0, # a_get_sealed_stock_item_only
0, # a_get_unsealed_stock_item_only
0, # a_get_expired_stock_item_only
0, # a_get_nonexpired_stock_item_only
0, # a_get_consumed_stock_item_only
0 # a_get_nonconsumed_stock_item_only
);
/*
DROP TABLE IF EXISTS tmp_Msg_Error;
select * from Shop_Storage_Location;
select * from shop_product;
select * from TMP_MSG_ERROR;
DROP TABLE TMP_MSG_ERROR;
insert into shop_product_change_set (comment)
values ('set product not subscription - test bool output to python');
update shop_product
set is_subscription = 0,
id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1)
where id_product = 1
*/

View File

@@ -1,557 +0,0 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item;
DELIMITER //
CREATE PROCEDURE p_shop_get_many_stock_item (
IN a_id_user INT,
IN a_get_all_product_permutation BIT,
IN a_guid_permutations BINARY(36),
IN a_get_all_stock_item BIT,
IN a_get_inactive_stock_item BIT,
IN a_ids_stock_item LONGTEXT,
IN a_get_all_region_storage BIT,
IN a_get_inactive_region_storage BIT,
IN a_ids_region_storage VARCHAR(4000),
IN a_get_all_plant_storage BIT,
IN a_get_inactive_plant_storage BIT,
IN a_ids_plant_storage VARCHAR(4000),
IN a_get_all_location_storage BIT,
IN a_get_inactive_location_storage BIT,
IN a_ids_location_storage TEXT,
IN a_date_received_to TIMESTAMP,
IN a_get_sealed_stock_item_only BIT,
IN a_get_unsealed_stock_item_only BIT,
IN a_get_expired_stock_item_only BIT,
IN a_get_nonexpired_stock_item_only BIT,
IN a_get_consumed_stock_item_only BIT,
IN a_get_nonconsumed_stock_item_only BIT
)
BEGIN
DECLARE v_has_filter_permutation BIT;
DECLARE v_has_filter_stock_item BIT;
DECLARE v_has_filter_region_storage BIT;
DECLARE v_has_filter_plant_storage BIT;
DECLARE v_has_filter_location_storage BIT;
DECLARE v_guid BINARY(36);
-- DECLARE v_ids_permutation_unavailable LONGTEXT;
DECLARE v_id_permission_product INT;
DECLARE v_ids_product_permission LONGTEXT;
-- DECLARE v_ids_permutation_permission VARCHAR(4000);
DECLARE v_id_access_level_view INT;
-- DECLARE v_now TIMESTAMP;
-- DECLARE v_id_minimum INT;
DECLARE v_now TIMESTAMP;
SET v_guid := UUID();
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW');
SET v_now := NOW();
-- Argument validation + default values
SET a_id_user := TRIM(IFNULL(a_id_user, ''));
SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0);
SET a_guid_permutations := IFNULL(a_guid_permutations, '');
SET a_get_all_stock_item := IFNULL(a_get_all_stock_item, 0);
SET a_get_inactive_stock_item := IFNULL(a_get_inactive_stock_item, 0);
SET a_ids_stock_item := TRIM(IFNULL(a_ids_stock_item, ''));
SET a_get_all_region_storage := IFNULL(a_get_all_region_storage, 0);
SET a_get_inactive_region_storage := IFNULL(a_get_inactive_region_storage, 0);
SET a_ids_region_storage := TRIM(IFNULL(a_ids_region_storage, ''));
SET a_get_all_plant_storage := IFNULL(a_get_all_plant_storage, 0);
SET a_get_inactive_plant_storage := IFNULL(a_get_inactive_plant_storage, 0);
SET a_ids_plant_storage := TRIM(IFNULL(a_ids_plant_storage, ''));
SET a_get_all_location_storage := IFNULL(a_get_all_location_storage, 0);
SET a_get_inactive_location_storage := IFNULL(a_get_inactive_location_storage, 0);
SET a_ids_location_storage := TRIM(IFNULL(a_ids_location_storage, ''));
SET a_date_received_to := a_date_received_to; -- IFNULL(a_date_received_to, NOW());
SET a_get_sealed_stock_item_only := IFNULL(a_get_sealed_stock_item_only, 0);
SET a_get_unsealed_stock_item_only := IFNULL(a_get_unsealed_stock_item_only, 0);
SET a_get_expired_stock_item_only := IFNULL(a_get_expired_stock_item_only, 0);
SET a_get_nonexpired_stock_item_only := IFNULL(a_get_nonexpired_stock_item_only, 0);
SET a_get_consumed_stock_item_only := IFNULL(a_get_consumed_stock_item_only, 0);
SET a_get_nonconsumed_stock_item_only := IFNULL(a_get_nonconsumed_stock_item_only, 0);
-- Temporary tables
DROP TABLE IF EXISTS tmp_Region_Storage;
DROP TABLE IF EXISTS tmp_Plant_Storage;
DROP TABLE IF EXISTS tmp_Location_Storage;
DROP TABLE IF EXISTS tmp_Stock_Item;
DROP TABLE IF EXISTS tmp_Permutation;
DROP TABLE IF EXISTS tmp_Msg_Error;
CREATE TEMPORARY TABLE tmp_Permutation (
id_permutation INT NOT NULL,
id_product INT NOT NULL
/*
CONSTRAINT FK_tmp_Permutation_id_permutation
FOREIGN KEY (id_permutation)
REFERENCES Shop_Product_Permutation(id_permutation)
*/
-- , rank_permutation INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Stock_Item (
id_stock INT NOT NULL PRIMARY KEY
, id_permutation INT NOT NULL
, id_product INT NOT NULL
, id_location_storage INT NOT NULL
-- , id_currency_cost INT NOT NUL
/*
, date_purchased TIMESTAMP NOT NULL
, date_received TIMESTAMP NULL
/
CONSTRAINT FK_tmp_Stock_Item_id_location_storage
FOREIGN KEY (id_location_storage)
REFERENCES Shop_Storage_Location(id_location),
/
/
CONSTRAINT FK_tmp_Stock_Item_id_currency
FOREIGN KEY (id_currency_cost)
REFERENCES Shop_Currency(id_currency),
/
, cost_local_VAT_incl FLOAT NOT NULL
, cost_local_VAT_excl FLOAT NOT NULL
, is_sealed BIT NOT NULL DEFAULT 1
, date_unsealed TIMESTAMP NULL
, date_expiration TIMESTAMP NOT NULL
, is_consumed BIT NOT NULL DEFAULT 0
, date_consumed TIMESTAMP NULL
, active_stock_item BIT NOT NULL DEFAULT 1
, active_permutation BIT NOT NULL
, active_product BIT NOT NULL
, active_category BIT NOT NULL
-- , rank_stock_item INT NOT NULL
, display_order_permutation INT NOT NULL
, display_order_product INT NOT NULL
, display_order_category INT NOT NULL
*/
, can_view BIT NULL
, can_edit BIT NULL
, can_admin BIT NULL
);
CREATE TEMPORARY TABLE tmp_Region_Storage (
id_region INT NOT NULL PRIMARY KEY
/*
CONSTRAINT FK_tmp_Region_Storage_id_region
FOREIGN KEY (id_region)
REFERENCES Shop_Region(id_region)
*/
-- , rank_region INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Plant_Storage (
id_plant INT NOT NULL PRIMARY KEY
/*
CONSTRAINT FK_tmp_Plant_Storage_id_plant
FOREIGN KEY (id_plant)
REFERENCES Shop_Plant(id_plant)
*/
-- , rank_plant INT NOT NULL
, id_region INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Location_Storage (
id_location INT NOT NULL PRIMARY KEY
/*
CONSTRAINT FK_tmp_Location_Storage_id_location
FOREIGN KEY (id_location)
REFERENCES Shop_Location_Storage(id_location)
*/
-- , rank_location INT NOT NULL
, id_plant INT NOT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guid BINARY(36) NOT NULL,
id_type INT NOT NULL,
/*
CONSTRAINT FK_tmp_Msg_Error_id_type
FOREIGN KEY (id_type)
REFERENCES Shop_Msg_Error_Type (id_type),
*/
code VARCHAR(50) NOT NULL,
msg VARCHAR(4000) NOT NULL
);
-- Parse filters
SET v_has_filter_permutation = CASE WHEN a_guid_permutations = '' THEN 0 ELSE 1 END;
SET v_has_filter_stock_item = CASE WHEN a_ids_stock_item = '' THEN 0 ELSE 1 END;
SET v_has_filter_region_storage = CASE WHEN a_ids_region_storage = '' THEN 0 ELSE 1 END;
SET v_has_filter_plant_storage = CASE WHEN a_ids_plant_storage = '' THEN 0 ELSE 1 END;
SET v_has_filter_location_storage = CASE WHEN a_ids_location_storage = '' THEN 0 ELSE 1 END;
-- select v_has_filter_product, v_has_filter_permutation;
INSERT INTO tmp_Permutation (
id_permutation,
id_product
)
SELECT
PP.id_permutation,
PP.id_product
FROM Shop_Product_Permutation PP
LEFT JOIN Shop_Product_Permutation_Temp PPT ON PP.id_permutation = PPT.id_permutation
WHERE
a_get_all_product_permutation = 1
OR PPT.GUID = a_guid_permutations
;
INSERT INTO tmp_Stock_Item (
id_stock,
id_permutation,
id_product,
id_location_storage
)
SELECT
SI.id_stock,
t_PP.id_permutation,
t_PP.id_product,
SI.id_location_storage
FROM Shop_Stock_Item SI
INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation
WHERE
(
a_get_all_stock_item = 1
OR (
v_has_filter_stock_item = 1
AND FIND_IN_SET(SI.id_stock, a_ids_stock_item) > 0
)
)
AND (
a_get_inactive_stock_item = 1
OR SI.active = 1
)
AND (
ISNULL(a_date_received_to)
OR SI.date_received <= a_date_received_to
)
AND (
a_get_unsealed_stock_item_only = 0
OR SI.is_sealed = 0
)
AND (
a_get_sealed_stock_item_only = 0
OR SI.is_sealed = 1
)
AND (
a_get_nonexpired_stock_item_only = 0
OR SI.date_expiration > v_now
)
AND (
a_get_expired_stock_item_only = 0
OR SI.date_expiration <= v_now
)
AND (
a_get_consumed_stock_item_only = 0
OR SI.is_consumed = 1
)
AND (
a_get_nonconsumed_stock_item_only = 0
OR SI.is_consumed = 0
)
;
-- Storage Regions
INSERT INTO tmp_Region_Storage (
id_region
)
WITH RECURSIVE Recursive_CTE_Region_Storage AS (
SELECT
R.id_region AS id_region_parent,
NULL AS id_region_child
FROM tmp_Stock_Item t_SI
-- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage
INNER JOIN Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location
INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN Shop_Address A ON P.id_address = A.id_address
INNER JOIN Shop_Region R
ON A.id_region = R.id_region
AND (
a_get_all_region_storage
OR FIND_IN_SET(R.id_region, a_ids_region_storage) > 0
)
AND (
a_get_inactive_region_storage
OR R.active = 1
)
UNION
SELECT
RB.id_region_parent,
RB.id_region_child
FROM Shop_Region_Branch RB
INNER JOIN Recursive_CTE_Region_Storage r_RS
ON RB.id_region_parent = r_RS.id_region_child
AND (
a_get_inactive_region_storage
OR RB.active = 1
)
)
SELECT
DISTINCT R.id_region
FROM Shop_Region R
INNER JOIN Recursive_CTE_Region_Storage r_RS
ON R.id_region = r_RS.id_region_parent
OR R.id_region = r_RS.id_region_child
;
-- Plants
INSERT INTO tmp_Plant_Storage (
id_plant
, id_region
)
SELECT
DISTINCT P.id_plant
, A.id_region
FROM tmp_Stock_Item t_SI
INNER JOIN Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location
INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN Shop_Address A ON P.id_address = A.id_address
;
-- Storage Locations
INSERT INTO tmp_Location_Storage (
id_location
, id_plant
)
WITH RECURSIVE Recursive_CTE_Location_Storage AS (
SELECT
SL.id_location AS id_location_parent,
NULL AS id_location_child
FROM tmp_Stock_Item t_SI
-- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage
INNER JOIN Shop_Storage_Location SL
ON t_SI.id_location_storage = SL.id_location
AND (
a_get_all_location_storage
OR FIND_IN_SET(SL.id_location, a_ids_location_storage) > 0
)
AND (
a_get_inactive_location_storage
OR SL.active = 1
)
UNION
SELECT
SLB.id_location_parent,
SLB.id_location_child
FROM Shop_Storage_Location_Branch SLB
INNER JOIN Recursive_CTE_Location_Storage r_LS
ON SLB.id_location_parent = r_LS.id_location_child
AND (
a_get_inactive_location_storage
OR SLB.active = 1
)
)
SELECT
DISTINCT SL.id_location
, SL.id_plant
FROM Shop_Storage_Location SL
INNER JOIN Recursive_CTE_Location_Storage r_LS
ON SL.id_location = r_LS.id_location_parent
OR SL.id_location = r_LS.id_location_child
;
-- Permissions
IF EXISTS (SELECT * FROM tmp_Stock_Item LIMIT 1) THEN
SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Permutation WHERE NOT ISNULL(id_product));
-- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation));
-- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission;
-- select * from Shop_Calc_User_Temp;
CALL p_shop_calc_user(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission);
-- select * from Shop_Calc_User_Temp;
UPDATE tmp_Stock_Item t_SI
INNER JOIN Shop_Calc_User_Temp UE_T
ON t_SI.id_product = UE_T.id_product
AND UE_T.GUID = v_guid
SET t_SI.can_view = UE_T.can_view,
t_SI.can_edit = UE_T.can_edit,
t_SI.can_admin = UE_T.can_admin
;
DELETE t_SI
FROM tmp_Stock_Item t_SI
/*
LEFT JOIN Shop_Calc_User_Temp UE_T
ON t_SI.id_product = UE_T.id_product
AND UE_T.GUID = v_guid
*/
WHERE
/*
FIND_IN_SET(t_SI.id_product, (
SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',')
FROM Shop_Calc_User_Temp UET)
) = 0 # id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_Calc_User_Temp), '%');
*/
/*
ISNULL(UE_T.id_product)
OR IFNULL(UE_T.can_view, 0) = 0
*/
t_SI.id_product NOT IN (
SELECT id_product
FROM Shop_Calc_User_Temp UE_T
WHERE
GUID = v_guid
AND IFNULL(can_view, 0) = 1
)
;
# CALL p_shop_calc_user_clear_temp(v_guid);
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
DELETE FROM Shop_Calc_User_Temp
WHERE GUID = v_guid
;
END IF;
/*
select * from shop_stock_item;
select * from tmp_Stock_Item;
select * from tmp_Permutation;
select * from tmp_Location_Storage;
select * from tmp_Plant_Storage;
select * from tmp_Region_Storage;
*/
-- Returns
-- SET v_now := NOW();
# Stock Items
SELECT
t_SI.id_stock,
t_SI.id_permutation,
P.id_product,
P.id_category,
t_SI.id_location_storage,
t_PS.id_plant,
t_RS.id_region,
SI.id_currency_cost,
CURRENCY.symbol AS symbol_currency_cost,
CURRENCY.code AS code_currency_cost,
SI.date_purchased,
SI.date_received,
SI.cost_local_VAT_incl,
SI.cost_local_VAT_excl,
SI.is_sealed,
SI.date_unsealed,
SI.date_expiration,
SI.is_consumed,
SI.date_consumed,
SI.active,
/*
t_SI.active_permutation,
t_SI.active_product,
t_SI.active_category,
*/
IFNULL(t_SI.can_view, 0),
IFNULL(t_SI.can_edit, 0),
IFNULL(t_SI.can_admin, 0)
FROM tmp_Stock_Item t_SI
INNER JOIN Shop_Stock_Item SI ON t_SI.id_stock = SI.id_stock
INNER JOIN tmp_Permutation t_PP ON t_SI.id_permutation = t_PP.id_permutation
INNER JOIN Shop_Product P ON t_PP.id_product = P.id_product
INNER JOIN tmp_Location_Storage t_LS ON t_SI.id_location_storage = t_LS.id_location
INNER JOIN tmp_Plant_Storage t_PS ON t_LS.id_plant = t_PS.id_plant
INNER JOIN Shop_Plant PLANT ON t_PS.id_plant = PLANT.id_plant
INNER JOIN Shop_Address A ON PLANT.id_address = A.id_address
INNER JOIN tmp_Region_Storage t_RS ON A.id_region = t_RS.id_region
INNER JOIN Shop_Storage_Location SL ON t_LS.id_location = SL.id_location
INNER JOIN Shop_Currency CURRENCY ON SI.id_currency_cost = CURRENCY.id_currency
WHERE
IFNULL(t_SI.can_view, 0) = 1
;
# Errors
SELECT
t_ME.display_order,
t_ME.guid,
t_ME.id_type,
t_ME.msg,
MET.code,
MET.name,
MET.description
FROM tmp_Msg_Error t_ME
INNER JOIN Shop_Msg_Error_Type MET
ON t_ME.id_type = MET.id_type
WHERE guid = v_guid
;
/*
# Return arguments for test
SELECT
a_ids_category,
a_get_inactive_category,
a_ids_product,
a_get_inactive_product,
a_get_first_product_only,
a_get_all_product,
a_ids_image,
a_get_inactive_image,
a_get_first_image_only,
a_get_all_image
;
*/
-- Clean up
DROP TEMPORARY TABLE IF EXISTS tmp_Region_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Plant_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Location_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
END //
DELIMITER ;;
CALL p_shop_get_many_stock_item (
1, # a_id_user
1, # a_get_all_product_permutation
'nips', # a_guid_permutations
1, # a_get_all_stock_item
0, # a_get_inactive_stock_item
'', # a_ids_stock_item
1, # a_get_all_region_storage
0, # a_get_inactive_delivery_region
'', # a_ids_region_storage
1, # a_get_all_plant_storage
0, # a_get_inactive_plant_storage
'', # a_ids_plant_storage
1, # a_get_all_location_storage
0, # a_get_inactive_location_storage
'', # a_ids_location_storage
NULL, # a_date_received_to
0, # a_get_sealed_stock_item_only
0, # a_get_unsealed_stock_item_only
0, # a_get_expired_stock_item_only
0, # a_get_nonexpired_stock_item_only
0, # a_get_consumed_stock_item_only
0 # a_get_nonconsumed_stock_item_only
);
/*
DROP TABLE IF EXISTS tmp_Msg_Error;
select * from Shop_Storage_Location;
select * from shop_product;
select * from TMP_MSG_ERROR;
DROP TABLE TMP_MSG_ERROR;
insert into shop_product_change_set (comment)
values ('set product not subscription - test bool output to python');
update shop_product
set is_subscription = 0,
id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1)
where id_product = 1
*/

View File

@@ -29,7 +29,7 @@ CREATE PROCEDURE p_shop_get_many_stock_item (
IN a_get_nonexpired_stock_item_only BIT,
IN a_get_consumed_stock_item_only BIT,
IN a_get_nonconsumed_stock_item_only BIT,
IN a_test BIT
IN a_debug BIT
)
BEGIN
DECLARE v_has_filter_permutation BIT;
@@ -45,11 +45,11 @@ BEGIN
DECLARE v_id_access_level_view INT;
-- DECLARE v_now TIMESTAMP;
-- DECLARE v_id_minimum INT;
DECLARE v_now TIMESTAMP;
DECLARE v_time_start TIMESTAMP(6);
SET v_guid := UUID();
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW');
SET v_now := NOW();
SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW');
SET v_time_start := CURRENT_TIMESTAMP(6);
-- Argument validation + default values
@@ -79,60 +79,40 @@ BEGIN
SET a_get_nonconsumed_stock_item_only := IFNULL(a_get_nonconsumed_stock_item_only, 0);
-- Temporary tables
DROP TABLE IF EXISTS tmp_Region_Storage;
DROP TABLE IF EXISTS tmp_Plant_Storage;
DROP TABLE IF EXISTS tmp_Location_Storage;
DROP TABLE IF EXISTS tmp_Stock_Item;
DROP TABLE IF EXISTS tmp_Permutation;
DROP TABLE IF EXISTS tmp_Msg_Error;
DROP TEMPORARY TABLE IF EXISTS tmp_Region_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Plant_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Location_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
-- DROP TABLE IF EXISTS tmp_Msg_Error;
DROP TEMPORARY TABLE IF EXISTS tmp_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
CREATE TEMPORARY TABLE tmp_Permutation (
id_permutation INT NOT NULL,
id_product INT NOT NULL
/*
CONSTRAINT FK_tmp_Permutation_id_permutation
FOREIGN KEY (id_permutation)
REFERENCES Shop_Product_Permutation(id_permutation)
*/
-- , rank_permutation INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Category (
id_category INT NOT NULL
, display_order INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Product (
id_category INT NOT NULL
, id_product INT NOT NULL
, display_order INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Permutation (
id_permutation INT NULL
, id_product INT NOT NULL
, can_view BIT
, can_edit BIT
, can_admin BIT
);
CREATE TEMPORARY TABLE tmp_Stock_Item (
id_stock INT NOT NULL PRIMARY KEY
, id_permutation INT NOT NULL
, id_product INT NOT NULL
, id_location_storage INT NOT NULL
-- , id_currency_cost INT NOT NUL
/*
, date_purchased TIMESTAMP NOT NULL
, date_received TIMESTAMP NULL
/
CONSTRAINT FK_tmp_Stock_Item_id_location_storage
FOREIGN KEY (id_location_storage)
REFERENCES Shop_Storage_Location(id_location),
/
/
CONSTRAINT FK_tmp_Stock_Item_id_currency
FOREIGN KEY (id_currency_cost)
REFERENCES Shop_Currency(id_currency),
/
, cost_local_VAT_incl FLOAT NOT NULL
, cost_local_VAT_excl FLOAT NOT NULL
, is_sealed BIT NOT NULL DEFAULT 1
, date_unsealed TIMESTAMP NULL
, date_expiration TIMESTAMP NOT NULL
, is_consumed BIT NOT NULL DEFAULT 0
, date_consumed TIMESTAMP NULL
, active_stock_item BIT NOT NULL DEFAULT 1
, active_permutation BIT NOT NULL
, active_product BIT NOT NULL
, active_category BIT NOT NULL
-- , rank_stock_item INT NOT NULL
, display_order_permutation INT NOT NULL
, display_order_product INT NOT NULL
, display_order_category INT NOT NULL
*/
, can_view BIT NULL
, can_edit BIT NULL
, can_admin BIT NULL
@@ -172,17 +152,18 @@ BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guid BINARY(36) NOT NULL,
id_type INT NOT NULL,
/*
CONSTRAINT FK_tmp_Msg_Error_id_type
FOREIGN KEY (id_type)
REFERENCES Shop_Msg_Error_Type (id_type),
*/
-- guid BINARY(36) NOT NULL,
id_type INT NULL,
code VARCHAR(50) NOT NULL,
msg VARCHAR(4000) NOT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split (
substring VARCHAR(4000) NOT NULL
, as_int INT NULL
);
DELETE FROM tmp_Split;
-- Parse filters
SET v_has_filter_permutation = CASE WHEN a_ids_product_permutation = '' THEN 0 ELSE 1 END; -- CASE WHEN a_guid_permutations = '' THEN 0 ELSE 1 END;
@@ -193,125 +174,274 @@ BEGIN
-- select v_has_filter_product, v_has_filter_permutation;
INSERT INTO tmp_Permutation (
id_permutation,
id_product
)
SELECT
PP.id_permutation,
PP.id_product
FROM Shop_Product_Permutation PP
-- LEFT JOIN Shop_Product_Permutation_Temp PPT ON PP.id_permutation = PPT.id_permutation
WHERE
(
a_get_all_product_permutation = 1
-- OR PPT.GUID = a_guid_permutations
OR FIND_IN_SET(PP.id_permutation, a_ids_product_permutation) > 0
)
AND (
a_get_inactive_product_permutation = 1
OR PP.active = 1
)
;
CALL partsltd_prod.p_shop_calc_product_permutation (
a_id_user
, 1 -- a_get_all_product_category
, 0 -- a_get_inactive_product_category
, '' -- a_ids_product_category
, 1 -- a_get_all_product
, 0 -- a_get_inactive_product
, '' -- a_ids_product
, a_get_all_product_permutation
, a_get_inactive_product_permutation
, a_ids_product_permutation
, 0
, v_guid -- a_guid
, 0 -- a_debug
);
INSERT INTO tmp_Stock_Item (
id_stock,
id_permutation,
id_product,
id_location_storage
)
SELECT
SI.id_stock,
t_PP.id_permutation,
t_PP.id_product,
SI.id_location_storage
FROM Shop_Stock_Item SI
INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation
WHERE
(
a_get_all_stock_item = 1
OR (
v_has_filter_stock_item = 1
AND FIND_IN_SET(SI.id_stock, a_ids_stock_item) > 0
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
INSERT INTO tmp_Category (
id_category
, display_order
)
SELECT
PC.id_category
, PC.display_order
FROM (SELECT * FROM partsltd_prod.Shop_Product_Category_Temp WHERE GUID = v_guid) PC_T
INNER JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category
;
INSERT INTO tmp_Product (
id_product
, id_category
, display_order
)
SELECT
P.id_product
, P.id_category
, P.display_order
FROM (SELECT * FROM partsltd_prod.Shop_Product_Temp WHERE GUID = v_guid) P_T
INNER JOIN partsltd_prod.Shop_Product P ON P.id_product = P_T.id_product
;
INSERT INTO tmp_Permutation (
id_permutation
, id_product
, can_view
, can_edit
, can_admin
)
SELECT
PP.id_permutation
, PP.id_product
, PP_T.can_view
, PP_T.can_edit
, PP_T.can_admin
FROM (SELECT * FROM partsltd_prod.Shop_Product_Permutation_Temp WHERE GUID = v_guid) PP_T
INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation
;
# Stock Items
CALL partsltd_prod.p_split(v_guid, a_ids_stock_item, ',', a_debug);
DELETE FROM tmp_Split;
INSERT INTO tmp_Split (
substring
, as_int
)
SELECT
substring
, CONVERT(substring, DECIMAL(10,0)) AS as_int
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
AND substring != ''
;
CALL partsltd_prod.p_clear_split_temp( v_guid );
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF EXISTS (
SELECT *
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock
WHERE
ISNULL(t_S.as_int)
OR ISNULL(SI.id_stock)
) THEN
INSERT INTO tmp_Msg_Error (
-- guid,
id_type,
code,
msg
)
)
AND (
a_get_inactive_stock_item = 1
OR SI.active = 1
)
AND (
ISNULL(a_date_received_to)
OR SI.date_received <= a_date_received_to
)
AND (
a_get_unsealed_stock_item_only = 0
OR SI.is_sealed = 0
)
AND (
a_get_sealed_stock_item_only = 0
OR SI.is_sealed = 1
)
AND (
a_get_nonexpired_stock_item_only = 0
OR SI.date_expiration > v_now
)
AND (
a_get_expired_stock_item_only = 0
OR SI.date_expiration <= v_now
)
AND (
a_get_consumed_stock_item_only = 0
OR SI.is_consumed = 1
)
AND (
a_get_nonconsumed_stock_item_only = 0
OR SI.is_consumed = 0
)
;
SELECT
-- v_guid,
v_id_type_error_bad_data,
v_code_type_error_bad_data,
CONCAT('Invalid or inactive stock item IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock
WHERE
ISNULL(t_S.as_int)
OR ISNULL(SI.id_stock)
;
ELSE
INSERT INTO tmp_Stock_Item (
id_stock
, id_permutation
, id_product
, id_location_storage
)
SELECT
SI.id_stock
, SI.id_permutation
, t_PP.id_product
, SI.id_location_storage
FROM tmp_Split t_S
RIGHT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock
INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation
WHERE
(
a_get_all_stock_item = 1
OR (
v_has_filter_stock_item = 1
AND NOT ISNULL(t_S.as_int)
)
)
AND (
a_get_inactive_stock_item = 1
OR SI.active = 1
)
AND (
ISNULL(a_date_received_to)
OR SI.date_received <= a_date_received_to
)
AND (
a_get_unsealed_stock_item_only = 0
OR SI.is_sealed = 0
)
AND (
a_get_sealed_stock_item_only = 0
OR SI.is_sealed = 1
)
AND (
a_get_nonexpired_stock_item_only = 0
OR SI.date_expiration > v_time_start
)
AND (
a_get_expired_stock_item_only = 0
OR SI.date_expiration <= v_time_start
)
AND (
a_get_consumed_stock_item_only = 0
OR SI.is_consumed = 1
)
AND (
a_get_nonconsumed_stock_item_only = 0
OR SI.is_consumed = 0
)
;
END IF;
END IF;
DELETE FROM tmp_Split;
-- Storage Regions
INSERT INTO tmp_Region_Storage (
id_region
)
WITH RECURSIVE Recursive_CTE_Region_Storage AS (
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
CALL partsltd_prod.p_split(v_guid, a_ids_region_storage, ',', a_debug);
DELETE FROM tmp_Split;
INSERT INTO tmp_Split (
substring
, as_int
)
SELECT
R.id_region AS id_region_parent,
NULL AS id_region_child
FROM tmp_Stock_Item t_SI
-- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage
INNER JOIN Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location
INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN Shop_Address A ON P.id_address = A.id_address
INNER JOIN Shop_Region R
ON A.id_region = R.id_region
AND (
a_get_all_region_storage
OR FIND_IN_SET(R.id_region, a_ids_region_storage) > 0
substring
, CONVERT(substring, DECIMAL(10,0)) AS as_int
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
AND substring != ''
;
CALL partsltd_prod.p_clear_split_temp( v_guid );
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF EXISTS (
SELECT *
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region
WHERE
ISNULL(t_S.as_int)
OR ISNULL(R.id_region)
) THEN
INSERT INTO tmp_Msg_Error (
-- guid,
id_type,
code,
msg
)
AND (
a_get_inactive_region_storage
OR R.active = 1
)
UNION
SELECT
RB.id_region_parent,
RB.id_region_child
FROM Shop_Region_Branch RB
INNER JOIN Recursive_CTE_Region_Storage r_RS
ON RB.id_region_parent = r_RS.id_region_child
AND (
a_get_inactive_region_storage
OR RB.active = 1
)
)
SELECT
DISTINCT R.id_region
FROM Shop_Region R
INNER JOIN Recursive_CTE_Region_Storage r_RS
ON R.id_region = r_RS.id_region_parent
OR R.id_region = r_RS.id_region_child
;
SELECT
-- v_guid,
v_id_type_error_bad_data,
v_code_type_error_bad_data,
CONCAT('Invalid or inactive region IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region
WHERE
ISNULL(t_S.as_int)
OR ISNULL(R.id_region)
;
ELSE
INSERT INTO tmp_Region_Storage (
id_region
)
WITH RECURSIVE Recursive_CTE_Region_Storage AS (
SELECT
R.id_region AS id_region_parent,
NULL AS id_region_child
FROM tmp_Split t_S
RIGHT JOIN partsltd_prod.Shop_Region R
ON t_S.as_int = R.id_region
AND (
a_get_all_region_storage = 1
OR NOT ISNULL(t_S.as_int)
)
AND (
a_get_inactive_region_storage = 1
OR R.active = 1
)
INNER JOIN (
SELECT
A.id_region
FROM tmp_Stock_Item t_SI
-- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage
INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location
INNER JOIN partsltd_prod.Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN partsltd_prod.Shop_Address A ON P.id_address = A.id_address
) A_SI ON R.id_region = A_SI.id_region
UNION
SELECT
RB.id_region_parent,
RB.id_region_child
FROM partsltd_prod.Shop_Region_Branch RB
INNER JOIN Recursive_CTE_Region_Storage r_RS
ON RB.id_region_parent = r_RS.id_region_child
AND (
a_get_inactive_region_storage = 1
OR RB.active = 1
)
)
SELECT
DISTINCT R.id_region
FROM partsltd_prod.Shop_Region R
INNER JOIN Recursive_CTE_Region_Storage r_RS
ON R.id_region = r_RS.id_region_parent
OR R.id_region = r_RS.id_region_child
;
END IF;
END IF;
DELETE FROM tmp_Split;
-- Plants
INSERT INTO tmp_Plant_Storage (
id_plant
@@ -321,69 +451,130 @@ BEGIN
DISTINCT P.id_plant
, A.id_region
FROM tmp_Stock_Item t_SI
INNER JOIN Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location
INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN Shop_Address A ON P.id_address = A.id_address
INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location
INNER JOIN partsltd_prod.Shop_Plant P ON SL.id_plant = P.id_plant
INNER JOIN partsltd_prod.Shop_Address A ON P.id_address = A.id_address
;
-- Storage Locations
INSERT INTO tmp_Location_Storage (
id_location
, id_plant
)
WITH RECURSIVE Recursive_CTE_Location_Storage AS (
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
CALL partsltd_prod.p_split(v_guid, a_ids_location_storage, ',', a_debug);
DELETE FROM tmp_Split;
INSERT INTO tmp_Split (
substring
, as_int
)
SELECT
SL.id_location AS id_location_parent,
NULL AS id_location_child
FROM tmp_Stock_Item t_SI
-- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage
INNER JOIN Shop_Storage_Location SL
ON t_SI.id_location_storage = SL.id_location
AND (
a_get_all_location_storage
OR FIND_IN_SET(SL.id_location, a_ids_location_storage) > 0
substring
, CONVERT(substring, DECIMAL(10,0)) AS as_int
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
AND substring != ''
;
CALL partsltd_prod.p_clear_split_temp( v_guid );
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF EXISTS (
SELECT *
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region
WHERE
ISNULL(t_S.as_int)
OR ISNULL(R.id_region)
) THEN
INSERT INTO tmp_Msg_Error (
-- guid,
id_type,
code,
msg
)
AND (
a_get_inactive_location_storage
OR SL.active = 1
)
UNION
SELECT
SLB.id_location_parent,
SLB.id_location_child
FROM Shop_Storage_Location_Branch SLB
INNER JOIN Recursive_CTE_Location_Storage r_LS
ON SLB.id_location_parent = r_LS.id_location_child
AND (
a_get_inactive_location_storage
OR SLB.active = 1
)
)
SELECT
DISTINCT SL.id_location
, SL.id_plant
FROM Shop_Storage_Location SL
INNER JOIN Recursive_CTE_Location_Storage r_LS
ON SL.id_location = r_LS.id_location_parent
OR SL.id_location = r_LS.id_location_child
;
SELECT
-- v_guid,
v_id_type_error_bad_data,
v_code_type_error_bad_data,
CONCAT('Invalid or inactive region IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region
WHERE
ISNULL(t_S.as_int)
OR ISNULL(R.id_region)
;
ELSE
INSERT INTO tmp_Location_Storage (
id_location
, id_plant
)
WITH RECURSIVE Recursive_CTE_Location_Storage AS (
SELECT
SL.id_location AS id_location_parent,
NULL AS id_location_child
FROM tmp_Split t_S
RIGHT JOIN partsltd_prod.Shop_Storage_Location SL
ON t_S.as_int = SL.id_location
AND (
a_get_all_location_storage = 1
OR NOT ISNULL(t_S.as_int)
)
AND (
a_get_inactive_location_storage = 1
OR SL.active = 1
)
INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage
UNION
SELECT
SLB.id_location_parent,
SLB.id_location_child
FROM partsltd_prod.Shop_Storage_Location_Branch SLB
INNER JOIN Recursive_CTE_Location_Storage r_LS
ON SLB.id_location_parent = r_LS.id_location_child
AND (
a_get_inactive_location_storage
OR SLB.active = 1
)
)
SELECT
DISTINCT SL.id_location
, SL.id_plant
FROM partsltd_prod.Shop_Storage_Location SL
INNER JOIN Recursive_CTE_Location_Storage r_LS
ON SL.id_location = r_LS.id_location_parent
OR SL.id_location = r_LS.id_location_child
;
END IF;
END IF;
DELETE FROM tmp_Split;
/*
-- Permissions
IF EXISTS (SELECT * FROM tmp_Stock_Item LIMIT 1) THEN
SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
SET v_id_permission_product := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1);
SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Permutation WHERE NOT ISNULL(id_product));
-- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation));
-- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission;
-- select * from Shop_Calc_User_Temp;
-- select * FROM partsltd_prod.Shop_Calc_User_Temp;
CALL p_shop_calc_user(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission);
CALL p_shop_calc_user(
v_guid
, a_id_user
, false -- a_get_inactive_users
, v_id_permission_product
, v_id_access_level_view
, v_ids_product_permission
, 0 -- a_debug
);
-- select * from Shop_Calc_User_Temp;
-- select * FROM partsltd_prod.Shop_Calc_User_Temp;
UPDATE tmp_Stock_Item t_SI
INNER JOIN Shop_Calc_User_Temp UE_T
INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T
ON t_SI.id_product = UE_T.id_product
AND UE_T.GUID = v_guid
SET t_SI.can_view = UE_T.can_view,
@@ -393,25 +584,25 @@ BEGIN
DELETE t_SI
FROM tmp_Stock_Item t_SI
/*
LEFT JOIN Shop_Calc_User_Temp UE_T
/ *
LEFT JOIN partsltd_prod.Shop_Calc_User_Temp UE_T
ON t_SI.id_product = UE_T.id_product
AND UE_T.GUID = v_guid
*/
* /
WHERE
/*
/ *
FIND_IN_SET(t_SI.id_product, (
SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',')
FROM Shop_Calc_User_Temp UET)
) = 0 # id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_Calc_User_Temp), '%');
*/
/*
FROM partsltd_prod.Shop_Calc_User_Temp UET)
) = 0 # id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM partsltd_prod.Shop_Calc_User_Temp), '%');
* /
/ *
ISNULL(UE_T.id_product)
OR IFNULL(UE_T.can_view, 0) = 0
*/
* /
t_SI.id_product NOT IN (
SELECT id_product
FROM Shop_Calc_User_Temp UE_T
FROM partsltd_prod.Shop_Calc_User_Temp UE_T
WHERE
GUID = v_guid
AND IFNULL(can_view, 0) = 1
@@ -420,13 +611,14 @@ BEGIN
# CALL p_shop_calc_user_clear_temp(v_guid);
# DROP TABLE IF EXISTS Shop_Calc_User_Temp;
DELETE FROM Shop_Calc_User_Temp
DELETE FROM partsltd_prod.Shop_Calc_User_Temp
WHERE GUID = v_guid
;
END IF;
*/
/*
select * from shop_stock_item;
select * FROM partsltd_prod.Shop_stock_item;
select * from tmp_Stock_Item;
select * from tmp_Permutation;
select * from tmp_Location_Storage;
@@ -463,37 +655,37 @@ BEGIN
t_SI.active_product,
t_SI.active_category,
*/
IFNULL(t_SI.can_view, 0),
IFNULL(t_SI.can_edit, 0),
IFNULL(t_SI.can_admin, 0)
t_PP.can_view,
t_PP.can_edit,
t_PP.can_admin
FROM tmp_Stock_Item t_SI
INNER JOIN Shop_Stock_Item SI ON t_SI.id_stock = SI.id_stock
INNER JOIN partsltd_prod.Shop_Stock_Item SI ON t_SI.id_stock = SI.id_stock
INNER JOIN tmp_Permutation t_PP ON t_SI.id_permutation = t_PP.id_permutation
INNER JOIN Shop_Product P ON t_PP.id_product = P.id_product
INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product
INNER JOIN tmp_Location_Storage t_LS ON t_SI.id_location_storage = t_LS.id_location
INNER JOIN tmp_Plant_Storage t_PS ON t_LS.id_plant = t_PS.id_plant
INNER JOIN Shop_Plant PLANT ON t_PS.id_plant = PLANT.id_plant
INNER JOIN Shop_Address A ON PLANT.id_address = A.id_address
INNER JOIN partsltd_prod.Shop_Plant PLANT ON t_PS.id_plant = PLANT.id_plant
INNER JOIN partsltd_prod.Shop_Address A ON PLANT.id_address = A.id_address
INNER JOIN tmp_Region_Storage t_RS ON A.id_region = t_RS.id_region
INNER JOIN Shop_Storage_Location SL ON t_LS.id_location = SL.id_location
INNER JOIN Shop_Currency CURRENCY ON SI.id_currency_cost = CURRENCY.id_currency
INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_LS.id_location = SL.id_location
INNER JOIN partsltd_prod.Shop_Currency CURRENCY ON SI.id_currency_cost = CURRENCY.id_currency
WHERE
IFNULL(t_SI.can_view, 0) = 1
IFNULL(t_PP.can_view, 0) = 1
;
# Errors
SELECT
t_ME.display_order,
t_ME.guid,
-- t_ME.guid,
t_ME.id_type,
t_ME.msg,
MET.code,
MET.name,
MET.description
FROM tmp_Msg_Error t_ME
INNER JOIN Shop_Msg_Error_Type MET
INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET
ON t_ME.id_type = MET.id_type
WHERE guid = v_guid
-- WHERE guid = v_guid
;
/*
@@ -519,7 +711,13 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp_Location_Storage;
DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
-- DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid );
IF a_debug = 1 THEN
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
END IF;
END //
DELIMITER ;;
@@ -549,6 +747,7 @@ CALL p_shop_get_many_stock_item (
0, # a_get_nonexpired_stock_item_only
0, # a_get_consumed_stock_item_only
0 # a_get_nonconsumed_stock_item_only
, 0 # a_debug
);
/*
@@ -556,8 +755,8 @@ CALL p_shop_get_many_stock_item (
DROP TABLE IF EXISTS tmp_Msg_Error;
select * from Shop_Storage_Location;
select * from shop_product;
select * FROM partsltd_prod.Shop_Storage_Location;
select * FROM partsltd_prod.Shop_product;
select * from TMP_MSG_ERROR;
DROP TABLE TMP_MSG_ERROR;
@@ -565,6 +764,6 @@ insert into shop_product_change_set (comment)
values ('set product not subscription - test bool output to python');
update shop_product
set is_subscription = 0,
id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1)
id_change_set = (select id_change_set FROM partsltd_prod.Shop_product_change_set order by id_change_set desc limit 1)
where id_product = 1
*/

View File

@@ -1,34 +1,42 @@
-- USE partsltd_prod;
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_region;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option;
DELIMITER //
CREATE PROCEDURE p_shop_get_many_product_price_and_discount_and_delivery_region (
IN a_id_user INT,
IN a_get_all_product_permutation BIT,
IN a_get_inactive_permutation BIT,
IN a_ids_permutation VARCHAR(4000),
IN a_get_all_delivery_region BIT,
IN a_get_inactive_delivery_region BIT,
IN a_ids_delivery_region VARCHAR(4000),
IN a_get_all_currency BIT,
IN a_get_inactive_currency BIT,
IN a_ids_currency VARCHAR(4000),
IN a_get_all_discount BIT,
IN a_get_inactive_discount BIT,
IN a_ids_discount VARCHAR(4000)
CREATE PROCEDURE p_shop_get_many_product_price_and_discount_and_delivery_option (
IN a_id_user INT
, IN a_get_all_product_permutation BIT
, IN a_get_inactive_product_permutation BIT
, IN a_ids_product_permutation TEXT
, IN a_get_all_product_price BIT
, IN a_get_inactive_product_price BIT
, IN a_ids_product_price TEXT
, IN a_product_price_min FLOAT
, IN a_product_price_max FLOAT
, IN a_get_all_currency BIT
, IN a_get_inactive_currency BIT
, IN a_ids_currency VARCHAR(4000)
, IN a_get_all_discount BIT
, IN a_get_inactive_discount BIT
, IN a_ids_discount TEXT
, IN a_get_all_delivery_option BIT
, IN a_get_inactive_delivery_option BIT
, IN a_ids_delivery_option TEXT
, IN a_get_all_delivery_region BIT
, IN a_get_inactive_delivery_region BIT
, IN a_ids_delivery_region TEXT
, IN a_debug BIT
)
BEGIN
-- Argument redeclaration
-- Variable declaration
DECLARE v_has_filter_category BIT;
DECLARE v_has_filter_product BIT;
DECLARE v_has_filter_permutation BIT;
DECLARE v_has_filter_image BIT;
DECLARE v_has_filter_delivery_region BIT;
DECLARE v_has_filter_product_permutation BIT;
DECLARE v_has_filter_product_price BIT;
DECLARE v_has_filter_currency BIT;
DECLARE v_has_filter_discount BIT;
DECLARE v_has_filter_delivery_option BIT;
DECLARE v_has_filter_delivery_region BIT;
DECLARE v_guid BINARY(36);
# DECLARE v_id_user VARCHAR(100);
DECLARE v_ids_permutation_unavailable VARCHAR(4000);
@@ -38,7 +46,9 @@ BEGIN
DECLARE v_id_access_level_view INT;
-- DECLARE v_now TIMESTAMP;
DECLARE v_id_minimum INT;
DECLARE v_time_start TIMESTAMP(6);
SET v_time_start := CURRENT_TIMESTAMP(6);
SET v_guid := UUID();
SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW');
@@ -46,8 +56,8 @@ BEGIN
-- Argument validation + default values
SET a_id_user := TRIM(IFNULL(a_id_user, ''));
SET a_get_all_product_permutation := TRIM(IFNULL(a_get_all_product_permutation, 1));
SET a_get_inactive_permutation := TRIM(IFNULL(a_get_inactive_permutation, 0));
SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, ''));
SET a_get_inactive_product_permutation := TRIM(IFNULL(a_get_inactive_product_permutation, 0));
SET a_ids_product_permutation := TRIM(IFNULL(a_ids_product_permutation, ''));
SET a_get_all_delivery_region := TRIM(IFNULL(a_get_all_delivery_region, 1));
SET a_get_inactive_delivery_region := TRIM(IFNULL(a_get_inactive_delivery_region, 0));
SET a_ids_delivery_region := TRIM(IFNULL(a_ids_delivery_region, ''));
@@ -57,6 +67,22 @@ BEGIN
SET a_get_all_discount := TRIM(IFNULL(a_get_all_discount, 1));
SET a_get_inactive_discount := TRIM(IFNULL(a_get_inactive_discount, 0));
SET a_ids_discount := TRIM(IFNULL(a_ids_discount, ''));
SET a_debug := IFNULL(a_debug, 0);
IF a_debug = 1 THEN
SELECT
a_id_user
, a_get_all_variation_type
, a_get_inactive_variation_type
, a_get_first_variation_type_only
, a_ids_variation_type
, a_get_all_variation
, a_get_inactive_variation
, a_get_first_variation_only
, a_ids_variation
, a_debug
;
END IF;
-- Temporary tables
DROP TEMPORARY TABLE IF EXISTS tmp_Discount;
@@ -66,52 +92,237 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2;
DROP TEMPORARY TABLE IF EXISTS tmp_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
CREATE TEMPORARY TABLE tmp_Shop_Product_Permutation (
id_permutation INT NULL,
active_permutation BIT NULL,
display_order_permutation INT NULL,
can_view BIT,
can_edit BIT,
can_admin BIT
CREATE TEMPORARY TABLE tmp_Category (
id_category INT NOT NULL
, display_order INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Delivery_Region (
id_region INT NOT NULL,
active BIT NOT NULL,
display_order INT NOT NULL,
requires_delivery_option BIT NOT NULL DEFAULT 0
CREATE TEMPORARY TABLE tmp_Product (
id_category INT NOT NULL
, id_product INT NOT NULL
, display_order INT NOT NULL
);
CREATE TEMPORARY TABLE tmp_Permutation (
id_permutation INT NULL
, id_product INT NOT NULL
, can_view BIT
, can_edit BIT
, can_admin BIT
);
CREATE TEMPORARY TABLE tmp_Price (
id_price INT
, id_permutation INT
);
CREATE TEMPORARY TABLE tmp_Currency (
id_currency INT NOT NULL,
active BIT NOT NULL,
id_currency INT NOT NULl
/*
active BIT NOT NULL
display_order INT NOT NULL
*/
);
CREATE TEMPORARY TABLE tmp_Discount (
id_discount INT NOT NULL,
id_discount INT NOT NULL
/*
active BIT NOT NULL,
display_order INT NOT NULL
*/
);
CREATE TEMPORARY TABLE tmp_Delivery_Option (
id_option INT NOT NULL
/*
active BIT NOT NULL,
display_order INT NOT NULL,
requires_delivery_option BIT NOT NULL DEFAULT 0
*/
);
CREATE TEMPORARY TABLE tmp_Delivery_Region (
id_region INT NOT NULL
/*
active BIT NOT NULL,
display_order INT NOT NULL,
requires_delivery_option BIT NOT NULL DEFAULT 0
*/
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error (
display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
guid BINARY(36) NOT NULL,
id_type INT NOT NULL,
-- guid BINARY(36) NOT NULL,
id_type INT NULL,
code VARCHAR(50) NOT NULL,
msg VARCHAR(4000) NOT NULL
);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split (
substring VARCHAR(4000) NOT NULL
, as_int INT NULL
);
DELETE FROM tmp_Split;
-- Parse filters
SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END;
SET v_has_filter_delivery_region = CASE WHEN a_ids_delivery_region = '' THEN 0 ELSE 1 END;
SET v_has_filter_product_permutation = CASE WHEN a_ids_product_permutation = '' THEN 0 ELSE 1 END;
SET v_has_filter_product_price = CASE WHEN a_ids_product_price = '' THEN 0 ELSE 1 END;
SET v_has_filter_currency = CASE WHEN a_ids_currency = '' THEN 0 ELSE 1 END;
SET v_has_filter_discount = CASE WHEN a_ids_discount = '' THEN 0 ELSE 1 END;
SET v_has_filter_delivery_option = CASE WHEN a_ids_delivery_option = '' THEN 0 ELSE 1 END;
SET v_has_filter_delivery_region = CASE WHEN a_ids_delivery_region = '' THEN 0 ELSE 1 END;
-- select v_has_filter_product, v_has_filter_permutation;
IF a_debug = 1 THEN
SELECT
v_has_filter_product_permutation
, v_has_filter_product_price
, v_has_filter_currency
, v_has_filter_discount
, v_has_filter_delivery_option
, v_has_filter_delivery_region
;
END IF;
CALL partsltd_prod.p_shop_calc_product_permutation (
a_id_user
, 1 -- a_get_all_product_category
, 0 -- a_get_inactive_product_category
, '' -- a_ids_product_category
, 1 -- a_get_all_product
, 0 -- a_get_inactive_product
, '' -- a_ids_product
, a_get_all_product_permutation
, a_get_inactive_product_permutation
, a_ids_product_permutation
, 0
, v_guid -- a_guid
, 0 -- a_debug
);
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
INSERT INTO tmp_Category (
id_category
, display_order
)
SELECT
PC.id_category
, PC.display_order
FROM (SELECT * FROM partsltd_prod.Shop_Product_Category_Temp WHERE GUID = v_guid) PC_T
INNER JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category
;
INSERT INTO tmp_Product (
id_product
, id_category
, display_order
)
SELECT
P.id_product
, P.id_category
, P.display_order
FROM (SELECT * FROM partsltd_prod.Shop_Product_Temp WHERE GUID = v_guid) P_T
INNER JOIN partsltd_prod.Shop_Product P ON P.id_product = P_T.id_product
;
INSERT INTO tmp_Permutation (
id_permutation
, id_product
, can_view
, can_edit
, can_admin
)
SELECT
PP.id_permutation
, PP.id_product
, PP_T.can_view
, PP_T.can_edit
, PP_T.can_admin
FROM (SELECT * FROM partsltd_prod.Shop_Product_Permutation_Temp WHERE GUID = v_guid) PP_T
INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation
;
# Product Prices
CALL partsltd_prod.p_split(v_guid, a_ids_product_price, ',', a_debug);
DELETE FROM tmp_Split;
INSERT INTO tmp_Split (
substring
, as_int
)
SELECT
substring
, CONVERT(substring, DECIMAL(10,0)) AS as_int
FROM partsltd_prod.Split_Temp
WHERE 1=1
AND GUID = v_guid
AND NOT ISNULL(substring)
AND substring != ''
;
CALL partsltd_prod.p_clear_split_temp( v_guid );
END IF;
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
IF EXISTS (
SELECT *
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price
WHERE
ISNULL(t_S.as_int)
OR ISNULL(PRICE.id_price)
) THEN
INSERT INTO tmp_Msg_Error (
-- guid,
id_type,
code,
msg
)
SELECT
-- v_guid,
v_id_type_error_bad_data,
v_code_type_error_bad_data,
CONCAT('Invalid or inactive product price IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL'))
FROM tmp_Split t_S
LEFT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price
WHERE
ISNULL(t_S.as_int)
OR ISNULL(PRICE.id_price)
;
ELSE
INSERT INTO tmp_Price (
id_price
, id_permutation
)
SELECT
PRICE.id_price
, PRICE.id_permutation
FROM tmp_Split t_S
RIGHT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price
INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation
WHERE
(
a_get_all_stock_item = 1
OR (
v_has_filter_stock_item = 1
AND NOT ISNULL(t_S.as_int)
)
)
AND (
a_get_inactive_stock_item = 1
OR SI.active = 1
)
;
END IF;
END IF;
DELETE FROM tmp_Split;
INSERT INTO tmp_Shop_Product (
id_permutation,
@@ -132,8 +343,8 @@ BEGIN
(
a_get_all_product_permutation
OR (
v_has_filter_permutation
AND FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0
v_has_filter_product_permutation
AND FIND_IN_SET(PP.id_permutation, a_ids_product_permutation) > 0
)
OR (
a_get_products_quantity_stock_below_min = 1
@@ -141,7 +352,7 @@ BEGIN
)
)
AND (
a_get_inactive_permutation
a_get_inactive_product_permutation
OR PP.active
)
;
@@ -208,7 +419,7 @@ BEGIN
)*
FIND_IN_SET(t_P.id_category, a_ids_category) > 0
OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0
;
*/
@@ -226,7 +437,7 @@ BEGIN
)*/
FIND_IN_SET(t_P.id_category, a_ids_category) > 0
OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0
) t_P
LEFT JOIN (
SELECT *
@@ -320,7 +531,7 @@ BEGIN
)*/
FIND_IN_SET(t_P.id_category, a_ids_category) > 0
OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0
) t_P
INNER JOIN (
SELECT *
@@ -432,8 +643,8 @@ BEGIN
OR FIND_IN_SET(t_P.id_product, a_ids_product) = 0
)
AND (
NOT v_has_filter_permutation
OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) = 0
NOT v_has_filter_product_permutation
OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) = 0
)
)
;
@@ -573,7 +784,7 @@ BEGIN
INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region
WHERE (
a_get_inactive_product
AND a_get_inactive_permutation
AND a_get_inactive_product_permutation
AND a_get_inactive_currency
AND a_get_inactive_delivery_region
OR PCRL.active
@@ -631,7 +842,7 @@ BEGIN
PDOL.price_local,
PDOL.display_order
FROM Shop_Delivery_Option _DO
INNER JOIN Shop_Product_Delivery_Option_Link PDOL
INNER JOIN Shop_Product_Permutation_Delivery_Option_Link PDOL
ON _DO.id_option = PDOL.id_delivery_option
AND (
a_get_inactive_delivery_region
@@ -715,37 +926,12 @@ BEGIN
# Errors
SELECT
t_ME.display_order,
t_ME.guid,
t_ME.id_type,
t_ME.msg,
MET.code,
MET.name,
MET.description
*
FROM tmp_Msg_Error t_ME
INNER JOIN Shop_Msg_Error_Type MET
ON t_ME.id_type = MET.id_type
WHERE guid = v_guid
INNER JOIN Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type
-- WHERE guid = v_guid
;
/*
# Return arguments for test
SELECT
a_ids_category,
a_get_inactive_category,
a_ids_product,
a_get_inactive_product,
a_get_first_product_only,
a_get_all_product,
a_ids_image,
a_get_inactive_image,
a_get_first_image_only,
a_get_all_image
;
*/
# select 'other outputs';
# select * from tmp_Shop_Product;
-- Clean up
DROP TEMPORARY TABLE IF EXISTS tmp_Discount;
@@ -757,18 +943,27 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Permutation;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid );
IF a_debug = 1 THEN
CALL partsltd_prod.p_debug_timing_reporting ( v_time_start );
END IF;
END //
DELIMITER ;;
/*
CALL partsltd_prod.p_shop_get_many_product_price_and_discount_and_delivery_region (
CALL partsltd_prod.p_shop_get_many_product_price_and_discount_and_delivery_option (
IN a_id_user INT,
IN a_get_all_product_permutation BIT,
IN a_get_inactive_permutation BIT,
IN a_ids_permutation VARCHAR(4000),
IN a_get_inactive_product_permutation BIT,
IN a_ids_product_permutation VARCHAR(4000),
IN a_get_all_delivery_region BIT,
IN a_get_inactive_delivery_region BIT,
IN a_ids_delivery_region VARCHAR(4000),

View File

@@ -487,24 +487,24 @@ VALUES
# Delivery Options
INSERT INTO Shop_Delivery_Option (
display_order, code, name, latency_delivery_min, latency_delivery_max, quantity_min, quantity_max
display_order, code, name, latency_delivery_min, latency_delivery_max
)
VALUES
(1, 'COLLECT', 'Collection', 0, 0, 0, 1),
(2, 'SIGNED_1', 'First Class Signed-For', 2, 4, 0, 1)
(1, 'COLLECT', 'Collection', 0, 0),
(2, 'SIGNED_1', 'First Class Signed-For', 2, 4)
;
# Product Delivery Option Links
INSERT INTO Shop_Product_Delivery_Option_Link (
display_order, id_product, id_permutation, id_delivery_option, id_region, id_currency, price_local
INSERT INTO Shop_Product_Permutation_Delivery_Option_Link (
display_order, id_product, id_permutation, id_delivery_option, id_region, id_currency, price_local, quantity_min, quantity_max
)
VALUES
(1, 1, 1, 1, 1, 1, 5),
(2, 1, 2, 1, 1, 1, 9),
(3, 2, NULL, 1, 1, 1, 10),
(4, 3, 4, 1, 1, 1, 10),
(5, 4, 5, 1, 1, 1, 10),
(6, 5, 6, 1, 1, 1, 10)
(1, 1, 1, 1, 1, 1, 5, 0, 1),
(2, 1, 2, 1, 1, 1, 9, 0, 1),
(3, 2, 3, 1, 1, 1, 10, 0, 1),
(4, 3, 4, 1, 1, 1, 10, 0, 1),
(5, 4, 5, 1, 1, 1, 10, 0, 1),
(6, 5, 6, 1, 1, 1, 10, 0, 1)
;
# Discounts

View File

@@ -114,8 +114,8 @@ SELECT * FROM Shop_Delivery_Option;
SELECT * FROM Shop_Delivery_Option_Audit;
# Delivery Options
SELECT * FROM Shop_Product_Delivery_Option_Link;
SELECT * FROM Shop_Product_Delivery_Option_Link_Audit;
SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link;
SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link_Audit;
# Discounts
SELECT * FROM Shop_Discount;

View File

@@ -1,5 +1,6 @@
0001_destroy.sql
1000_tbl_Shop_Product_Change_Set.sql
1000_tbl_Split_Temp.sql
1001_tbl_Shop_User_Change_Set.sql
1002_tbl_Shop_Sales_And_Purchasing_Change_Set.sql
1003_tbl_Shop_Access_Level.sql
@@ -61,8 +62,8 @@
1225_tbl_Shop_Product_Image_Audit.sql
1227_tbl_Shop_Delivery_Option.sql
1228_tbl_Shop_Delivery_Option_Audit.sql
1230_tbl_Shop_Product_Delivery_Option_Link.sql
1231_tbl_Shop_Product_Delivery_Option_Link_Audit.sql
1230_tbl_Shop_Product_Permutation_Delivery_Option_Link.sql
1231_tbl_Shop_Product_Permutation_Delivery_Option_Link_Audit.sql
1233_tbl_Shop_Discount.sql
1234_tbl_Shop_Discount_Audit.sql
1236_tbl_Shop_Discount_Region_Currency_Link.sql
@@ -106,6 +107,7 @@
1427_tbl_Shop_Customer_Sales_Order_Product_Link.sql
1428_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql
1429_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql
1500_tbl_Shop_Calc_User_Temp.sql
3000_tri_Shop_Access_Level.sql
3000_tri_Shop_Product_Change_Set.sql
3001_tri_Shop_User_Change_Set.sql
@@ -129,7 +131,7 @@
3221_tri_Shop_Product_Price.sql
3224_tri_Shop_Product_Image.sql
3227_tri_Shop_Delivery_Option.sql
3230_tri_Shop_Product_Delivery_Option_Link.sql
3230_tri_Shop_Product_Permutation_Delivery_Option_Link.sql
3233_tri_Shop_Discount.sql
3236_tri_Shop_Discount_Region_Currency_Link.sql
3300_tri_Shop_Permission_Group.sql
@@ -151,8 +153,10 @@
3421_tri_Shop_Customer.sql
3424_tri_Shop_Customer_Sales_Order.sql
3427_tri_Shop_Customer_Sales_Order_Product_Link.sql
6000_p_debug_timing_reporting.sql
6000_p_split.sql
6001_p_clear_split_temp.sql
6001_p_validate_guid.sql
6206_fn_shop_get_product_permutation_name.sql
6500_p_shop_calc_user.sql
6501_p_shop_clear_calc_user.sql
@@ -162,9 +166,12 @@
7122_p_shop_get_many_unit_measurement.sql
7200_p_shop_save_product_category.sql
7200_p_shop_save_product_category_test.sql
7202_p_shop_clear_calc_product_permutation.sql
7203_p_shop_save_product.sql
7204_p_shop_calc_product_permutation.sql
7204_p_shop_get_many_product.sql
7205_p_shop_get_many_stripe_product_new.sql
7206_p_shop_save_permutation.sql
7206_p_shop_save_product_permutation.sql
7210_p_shop_get_many_product_variation.sql
7219_p_shop_get_many_stock_item.sql
@@ -186,3 +193,4 @@
9000_populate.sql
9001_view.sql
9010_anal.sql
DEPRECATED