1. Logout callback fix.\n 2. Store permutations report improvement for demo.

This commit is contained in:
2024-08-07 09:01:33 +01:00
parent f81abed86e
commit 9de1ccce16
2096 changed files with 381570 additions and 388 deletions

View File

@@ -0,0 +1,27 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_clear_split_temp;
DELIMITER //
CREATE PROCEDURE p_clear_split_temp (
)
BEGIN
START TRANSACTION;
DROP TABLE Split_Temp;
COMMIT;
END //
DELIMITER ;
/*
CALL p_clear_shop_user_eval_temp (
'noods, cheese ' # a_guid
);
SELECT *
FROM Shop_User_Eval_Temp;
*/

View File

@@ -0,0 +1,39 @@
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_clear_shop_user_eval_temp;
DELIMITER //
CREATE PROCEDURE p_clear_shop_user_eval_temp (
IN a_guid BINARY(36)
)
BEGIN
IF ISNULL(a_guid) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'GUID is required.';
ELSE
START TRANSACTION; -- trans_clear
DELETE FROM Shop_User_Eval_Temp
WHERE GUID = a_guid
;
COMMIT;
END IF;
END //
DELIMITER ;
/*
CALL p_clear_shop_user_eval_temp (
'noods, cheese ' # a_guid
);
SELECT *
FROM Shop_User_Eval_Temp;
*/

View File

@@ -1,5 +1,4 @@
--
-- USE partsltd_prod;
-- Clear previous proc
DROP PROCEDURE IF EXISTS p_shop_get_many_product;
@@ -165,6 +164,7 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image;
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_Shop_Category;
CREATE TEMPORARY TABLE tmp_Shop_Category (
@@ -319,8 +319,8 @@ BEGIN
PP.quantity_step,
PP.quantity_stock,
PP.is_subscription,
PP.id_recurrence_interval,
PP.count_recurrence_interval,
PP.id_interval_recurrence,
PP.count_interval_recurrence,
PP.id_stripe_product,
P.has_variations
FROM Shop_Product P
@@ -380,7 +380,7 @@ BEGIN
-- select * from tmp_Shop_Product;
IF a_get_first_product_only = 1 THEN
DELETE t_P
DELETE -- t_P
FROM tmp_Shop_Product t_P
WHERE t_P.rank_permutation > 1
;
@@ -412,7 +412,9 @@ BEGIN
*/
# Product Images
INSERT INTO tmp_Shop_Image (
CREATE TEMPORARY TABLE tmp_Shop_Product_2 SELECT * FROM tmp_Shop_Product;
INSERT INTO tmp_Shop_Image (
id_product,
id_permutation,
id_image,
@@ -420,34 +422,47 @@ BEGIN
display_order,
rank_in_product_permutation
)
SELECT id_product,
id_permutation,
id_image,
active,
ROW_NUMBER() OVER (ORDER BY display_order_product_temp, display_order_image),
RANK() OVER (PARTITION BY id_product, id_permutation ORDER BY display_order_product_temp, display_order_image)
/*
WITH CTE_Product AS (
SELECT
t_P.id_product
, t_P.id_permutation
, t_P.product_has_variations
, t_P.rank_permutation
FROM tmp_Shop_Product t_P
)
*/
SELECT
IPP.id_product,
IPP.id_permutation,
IPP.id_image,
IPP.active,
ROW_NUMBER() OVER (ORDER BY IPP.display_order_product_temp, IPP.display_order_image),
RANK() OVER (PARTITION BY IPP.id_product, IPP.id_permutation ORDER BY IPP.display_order_product_temp, IPP.display_order_image)
FROM (
SELECT t_P.id_product,
SELECT
t_P.id_product,
I.id_permutation,
I.id_image,
I.active,
I.display_order AS display_order_image,
t_P.rank_permutation AS display_order_product_temp
FROM Shop_Image I
INNER JOIN tmp_Shop_Product t_P
ON I.id_product = t_P.id_product
AND NOT t_P.product_has_variations
UNION
SELECT t_P.id_product,
I.id_permutation,
I.id_image,
I.active,
I.display_order AS display_order_image,
t_P.rank_permutation AS display_order_product_temp
FROM Shop_Image I
FROM Shop_Product_Image I
INNER JOIN tmp_Shop_Product t_P
ON I.id_permutation = t_P.id_permutation
AND t_P.product_has_variations
AND NOT t_P.product_has_variations
UNION
SELECT
t_P2.id_product,
I.id_permutation,
I.id_image,
I.active,
I.display_order AS display_order_image,
t_P2.rank_permutation AS display_order_product_temp
FROM Shop_Product_Image I
INNER JOIN tmp_Shop_Product_2 t_P2
ON I.id_permutation = t_P2.id_permutation
AND t_P2.product_has_variations
) IPP
WHERE (a_get_all_image OR a_get_first_image_only OR FIND_IN_SET(id_image, a_ids_image) > 0)
AND (a_get_inactive_image OR IPP.active)
@@ -460,6 +475,7 @@ BEGIN
END IF;
/*
select @@version;
IF v_has_filter_image THEN
DELETE FROM tmp_Shop_Product
WHERE id_product NOT IN (SELECT DISTINCT id_product FROM tmp_Shop_Image);
@@ -739,7 +755,7 @@ BEGIN
-- select * from Shop_User_Eval_Temp;
-- select * from tmp_Shop_Product;
DELETE t_P
DELETE -- t_P
FROM tmp_Shop_Product t_P
WHERE
FIND_IN_SET(t_P.id_product, (SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',') FROM Shop_User_Eval_Temp UET)) = 0 # id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_User_Eval_Temp), '%');
@@ -760,11 +776,13 @@ BEGIN
)
;
# CALL p_shop_user_eval_clear_temp(v_guid);
CALL p_clear_shop_user_eval_temp(v_guid);
# DROP TABLE IF EXISTS Shop_User_Eval_Temp;
DELETE FROM Shop_User_Eval_Temp
WHERE GUID = v_guid
/*
DELETE FROM Shop_User_Eval_Temp UE_T
WHERE UE_T.GUID = v_guid
;
*/
END IF;
@@ -807,9 +825,9 @@ BEGIN
t_P.quantity_stock,
t_P.id_stripe_product,
t_P.is_subscription,
RI.name AS name_recurrence_interval,
RI.name_plural AS name_plural_recurrence_interval,
t_P.count_recurrence_interval,
UM.name_singular AS name_recurrence_interval,
UM.name_plural AS name_plural_recurrence_interval,
PP.count_interval_recurrence,
t_P.display_order_category,
t_P.display_order_product,
t_P.display_order_permutation,
@@ -819,7 +837,8 @@ BEGIN
FROM tmp_Shop_Product t_P
INNER JOIN Shop_Product P ON t_P.id_product = P.id_product
INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation
LEFT JOIN Shop_Recurrence_Interval RI ON t_P.id_recurrence_interval = RI.id_interval
-- LEFT JOIN Shop_Recurrence_Interval RI ON t_P.id_interval_recurrence = RI.id_interval
LEFT JOIN Shop_Unit_Measurement UM ON PP.id_interval_recurrence = UM.id_unit_measurement
INNER JOIN Shop_Currency CURRENCY ON PP.id_currency_cost = CURRENCY.id_currency
ORDER BY t_P.rank_permutation
;
@@ -920,7 +939,7 @@ BEGIN
I.active,
I.display_order
FROM tmp_Shop_Image t_I
INNER JOIN Shop_Image I
INNER JOIN Shop_Product_Image I
ON t_I.id_image = I.id_image
INNER JOIN tmp_Shop_Product t_P
ON t_I.id_product = t_P.id_product
@@ -1062,23 +1081,26 @@ BEGIN
# select * from tmp_Shop_Product;
-- Clean up
DROP TABLE IF EXISTS tmp_Discount;
DROP TABLE IF EXISTS tmp_Currency;
DROP TABLE IF EXISTS tmp_Delivery_Region;
DROP TABLE IF EXISTS tmp_Shop_Image;
DROP TABLE IF EXISTS tmp_Shop_Variation;
DROP TABLE IF EXISTS tmp_Shop_Product;
DROP TABLE IF EXISTS tmp_Shop_Category;
DROP TEMPORARY TABLE IF EXISTS tmp_Discount;
DROP TEMPORARY TABLE IF EXISTS tmp_Currency;
DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Product;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2;
DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Category;
END //
DELIMITER ;
/*
CALL partsltd_prod.p_shop_get_many_product (
'auth0|6582b95c895d09a70ba10fef', # a_id_user
1, #'auth0|6582b95c895d09a70ba10fef', # a_id_user
1, # a_get_all_category
0, # a_get_inactive_category
1, # a_get_inactive_category
0, # a_get_first_category_only
'', # a_ids_category
1, # a_get_all_product
@@ -1089,24 +1111,26 @@ CALL partsltd_prod.p_shop_get_many_product (
0, # a_get_inactive_permutation
0, # a_get_first_permutation_only
'', # a_ids_permutation
0, # a_get_all_image
1, # a_get_all_image
0, # a_get_inactive_image
0, # a_get_first_image_only
'', # a_ids_image
0, # a_get_all_delivery_region
1, # a_get_all_delivery_region
0, # a_get_inactive_delivery_region
0, # a_get_first_delivery_region_only
'', # a_ids_delivery_region
0, # a_get_all_currency
1, # a_get_all_currency
0, # a_get_inactive_currency
0, # a_get_first_currency_only
'', # a_ids_currency
0, # a_get_all_discount
1, # a_get_all_discount
0, # a_get_inactive_discount
'', # a_ids_discount
1 # a_get_products_quantity_stock_below_minimum
);
select * FROM Shop_User_Eval_Temp;
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');
@@ -1128,4 +1152,9 @@ insert into shop_product_change_set (comment)
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_User_Eval_Temp;
select distinct guid
-- DELETE
FROM Shop_User_Eval_Temp;
*/

View File

@@ -0,0 +1,302 @@
/*
CALL p_shop_get_many_product_variation (
'', # a_id_user
1, # a_get_all_supplier
0, # a_get_inactive_variation
0, # a_get_first_variation_only
'', # a_ids_variation
);
*/
-- Clear previous proc
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)
)
BEGIN
-- Argument redeclaration
-- Variable declaration
DECLARE v_has_filter_variation BIT;
DECLARE v_has_filter_variation_type BIT;
DECLARE v_guid BINARY(36);
# DECLARE v_id_user VARCHAR(100);
# DECLARE v_ids_permutation_unavailable VARCHAR(4000);
DECLARE v_id_permission_variation 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_code_error_data VARCHAR(50);
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);
-- 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, ''), '|', ','));
-- Temporary tables
DROP TABLE IF EXISTS tmp_Variation;
DROP TABLE IF EXISTS tmp_Variation_Type;
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,
code VARCHAR(50) NOT NULL,
msg VARCHAR(4000) NOT NULL
);
-- Parse filters
SET v_has_filter_variation = CASE WHEN a_ids_variation = '' THEN 0 ELSE 1 END;
SET v_has_filter_variation_type = CASE WHEN a_ids_variation_type = '' THEN 0 ELSE 1 END;
-- 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_ids_variation_type, ',');
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
INSERT INTO tmp_Msg_Error (
guid,
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)))
)
;
CALL p_clear_split_temp;
ELSE
CALL p_clear_split_temp;
CALL p_split(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
)
;
END IF;
CALL p_clear_split_temp;
IF a_get_first_variation_only THEN
DELETE t_V
FROM tmp_Shop_Variation t_V
WHERE t_V.rank_variation > 1
;
END IF;
END IF;
END IF;
-- 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_User_Eval_Temp;
CALL p_shop_user_eval(v_guid, a_id_user, FALSE, v_id_permission_variation, v_id_access_level_view, '');
-- select * from Shop_User_Eval_Temp;
IF NOT EXISTS (SELECT can_view FROM Shop_User_Eval_Temp UE_T WHERE UE_T.GUID = v_guid) THEN
INSERT INTO tmp_Msg_Error (
guid,
code,
msg
)
VALUES (
v_guid,
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))
)
;
END IF;
END IF;
IF EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN
DELETE FROM tmp_Variation;
DELETE FROM tmp_Variation_Type;
END IF;
-- Returns
# Variation Types
SELECT
t_VT.id_type
, VT.code
, VT.name
, VT.name_plural
, VT.active
FROM tmp_Variation_Type t_VT
INNER JOIN Shop_Variation_Type VT ON t_VT.id_type = VT.id_type
;
# Variations
SELECT
t_V.id_variation
, V.code
, V.name
, V.active
FROM tmp_Variation t_V
INNER JOIN Shop_Variation V ON t_V.id_variation = V.id_variation
;
# Errors
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
;
-- Clean up
DROP TABLE IF EXISTS tmp_Variation;
DROP TABLE IF EXISTS tmp_Variation_Type;
END //
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
);
/*
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');
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
INSERT INTO tmp_Variation_Type (
id_type,
active,
rank_type
)
SELECT
VT.id_type,
S.active,
RANK() OVER (ORDER BY id_type ASC) AS rank_type
FROM Shop_Variation_Type VT
LEFT JOIN Split_Temp S_T ON VT.id_type = S_T.substring
WHERE
(
a_get_all_variation_type = 1
OR NOT ISNULL(S_T.substring)
)
AND (
a_get_inactive_variation_type
OR VT.active = 1
)
;
END IF;
IF a_get_first_variation_type_only THEN
DELETE t_VT
FROM tmp_Shop_Variation_Type t_VT
WHERE t_VT.rank_type > 1
;
END IF;
*/

View File

@@ -149,6 +149,12 @@ BEGIN
)
;
END IF;
/*
DELETE FROM Shop_User_Eval_Temp
WHERE GUID = v_guid;
*/
CALL p_clear_shop_user_eval_temp(v_guid);
END IF;
@@ -230,16 +236,12 @@ BEGIN
-- Clean up
DROP TEMPORARY TABLE IF EXISTS tmp_User;
DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error;
DELETE FROM Shop_User_Eval_Temp
WHERE GUID = v_guid
;
END //
DELIMITER ;
/*
/*
CALL p_get_many_user (
NULL # a_id_user
, 'auth0|6582b95c895d09a70ba10fef' # a_id_user_auth0
@@ -249,5 +251,6 @@ CALL p_get_many_user (
, NULL # a_ids_user
, 'auth0|6582b95c895d09a70ba10fef' # a_ids_user_auth0 # ' --
);
select * from shop_user_eval_temp;
delete from shop_user_eval_temp;
*/

View File

@@ -238,10 +238,6 @@ BEGIN
-- Clean up
DROP TABLE IF EXISTS tmp_Supplier;
DELETE FROM Shop_User_Eval_Temp
WHERE GUID = v_guid
;
END //
DELIMITER ;